Home > Tools > Make Rules!

## Make Rules!

I have just completed a task of reorganizing some of my work to flow better. Flow through Unix pipes, that is. I just did a talk in my main study area, and after all the work that I put into the figures I did not want to copy them back into the .tex file that holds all my equations and other stuff. So I decided to create a hierarchical system for this project where I will separate the work according to specific tools. At the top level I have

(root)
├── c
├── latex
│ ├── bibtex
│ ├── eqns
│ ├── figures
│ └── talk
│ └── img
└── python


Basically my C code is in one branch, my LaTeX stuff in another, and the Python version (of the simulation done in C) in another. The subdirectories of ./latex” show that I have a directory for bibliography files, one for equations, one for figures and one for talks. “Talks” will eventually include both a fifteen-minute talk and a 45-minute talk. I should do the work now, right? Before I have to actually give the talk?

Here’s the really cool part: using the pst-eps package in TeXLive 2009, I can extract the figures (made using pstricks) from a LaTeX document, then process them with dvips to make stand-alone Encapsulated Postscript figures. Then I can include them either in a manuscript or a talk. I can edit the figures themselves without worrying about the captions and all that jazz.

So each “figure” is in its own .tex file that includes a pspicture environment. Then I used the following shell script to construct a LaTeX document on the fly:
 #!/bin/sh

cat <<EOF
\documentclass{article}
\usepackage{mypkg}
\pagestyle{empty}
\begin{document}
\begin{TeXtoEPS}
\input $1 \end{TeXtoEPS} \end{document} EOF I call this “texput.sh”. The package “mypkg.sty” just includes macros and package inclusions of my own. This is in the parent directory of the makefile, and so I have to specify TEXINPUTS on the latex command-line. Then I use the following Makefile: BASE = figures LATEX = /usr/bin/latex LATEXFLAGS = -interaction=nonstopmode "\input" TEXINPUTS=".:..:" EPSFILES=*.eps FIGFILES=*.tex all: eps figs:$(FIGFILES)

texput.dvi:
for file in $(FIGFILES) ; do \ ./texput.sh $$file \ | TEXINPUTS=(TEXINPUTS) (LATEX); \ dvips -E texput.dvi -o$${file/tex/eps} ; \ done && rm texput.dvi texput.log eps: texput.dvi clean: rm$(EPSFILES)


Hit “C-cc” in Emacs and BOOM! I have all my figures as .eps files.

(for those of you who are not Make-heads, the title is a pun: each of those lines with a colon at the end is a “make rule”)

Categories: Tools
1. April 21, 2010 at 21:45

I have since updated the structure of the latex directory to reflect the TeX Directory Structure standard, and things work even better.

Like

2. June 25, 2010 at 19:59

Another cool thing I did successfully for the first time today is defining make rules in a Makefile.am. After processing with autoreconf and running configure, the customized make rules are in the new Makefile. I created custom rules in the Makefile.am of the simulation based on the project I described above; the targets were sorted and pruned output data (with cut and sort) so I could create plots using pstricks.

	# Specific targets
graphs: ppby pptheta ptby pcby
ppby: sort
printf "%% Fields:\n%% 1. b_y 2. P(P)_final\n" > ppby.data
cut -d' ' -f2,13 age_dep.sort| sed -n '1~10p' >> ppby.data
pptheta: sort
printf "%% Fields:\n%% 1. theta 2. P(P)_final\n" > pptheta.data
cut -d' ' -f5,13 age_dep.sort| sed -n '1~10p' >> pptheta.data
ptby: sort
printf "%% Fields:\n%% 1. by 2. P(T)_final\n" > ptby.data
cut -d' ' -f2,12 age_dep.sort| sed -n '1~10p' >> ptby.data
pcby: sort
printf "%% Fields:\n%% 1. by 2. P(C)_final\n" > pcby.data
cut -d' ' -f2,11 age_dep.sort| sed -n '1~10p' >> pcby.data

sort: age_dep.sort
age_dep.sort: age_dep.out
sort -k2 @
age_dep.out: age_dep.sh
./$< | tee$@ | mail \$(USER)


So “make graphs” produces nifty data files with ordered pairs for graphing purposes.

Like

1. August 11, 2010 at 10:29