Tuesday, August 19, 2008

Building MATLAB images from Makefiles

Recently I beefed up my LaTeX Makefiles to make image generation more automatic. These implicit rules have worked very well for me (note that the indentation is done with TABS — that's important).
%.pdf : %.eps
epstopdf $*.eps

%.eps : %.m
matlab -nosplash -nodesktop -r "$*;quit"

%.eps : %.png
convert -density $(RESOLUTION) $*.png $*.eps

%.eps : %.jpg
convert -density $(RESOLUTION) $*.jpg $*.eps

%.eps : %.dvi
dvips $* -D $(RESOLUTION) -E -o $*.eps

%.dvi : %.tex
latex -interaction=nonstopmode $*.tex
rm -f $*.log
rm -f $*.aux
That if, if I need a file called FILENAME.eps or FILENAME.pdf, the Makefile will look for FILENAME.m, FILENAME.png, FILENAME.jpg, or FILENAME.tex. Depending on which one it finds, it will run the appropriate command to generate the image I need. Note that I define RESOLUTION=1500 in the top of my Makefile.

I want to point out the MATLAB build line:
matlab -nosplash -nodesktop -r "$*;quit"
That handy line starts up as little of MATLAB as possible and runs a script that contains something like:
% First, generate a figure somehow

% Next, setup the figure's print proportions
set( gcf, 'PaperType', 'usletter', ...
'PaperOrientation', 'portrait', ...
'PaperPosition', [0.0 3.5 11 3.5] );

% Finally, save the figure as a (color) EPS
saveas( gcf, 'FILENAME.eps', 'epsc2' );
After the script finishes, MATLAB exits. It won't get started on any subsequent makes so long as the script file doesn't change or the image isn't deleted.

Getting back to the more general case, up high in my Makefile, I have something like
RESOLUTION=1500
BASETEXIMAGES=$(shell perl -ne \
'/\\includegraphics\s*(?:\[.*?\]|)\s*{\s*(.*?)\s*}/ \
&& do { print "$$1 " \
if (-e "$${1}.tex" || \
-e "$${1}.png" || \
-e "$${1}.jpg" || \
-e "$${1}.m"); };' *.tex)
TEXIMAGES=$(addsuffix .eps,$(BASETEXIMAGES))
and a little later I make $(TEXIMAGES) a dependency for my document (or something equivalent to that).

Those lines have saved me a lot of time, and I'm pretty happy about them.

Wednesday, August 13, 2008

"Don't Be Upset" by Jeffrey and Jack Lewis

Great lyrics and a fun little song...
i took my darling out to the aquarium
sea creatures stared at us and we stared back at them
my baby freaked when she peeked at that 8-legged blob with a beak
she was too scared to speak
i said don't be upset it's only an octopus
don't bother it and i'm sure it won't bother us
please don't be upset my darling, please don't get upset
my baby came riding to meet me one time
on the crowed last car of the downtown-bound 9
she was brave but she caved
when the train was delayed
it was just the last straw in her hard busy day
i said don't get upset 'cuz it's not a catastrophe
nothing will happen and soon you'll be back with me
please don't be upset my darling , please don't be upset
my gal's got a headhache, her ankle is hurting too
boots she bought gave her a rash & her winsdom tooth
is coming in and it's damp out and she's having cramps and she's so mad at me cuz i didn't shave
i said don't be upset i know you're feeling sensitive
i'll try to be kinder and be more attentive
please don't be upset my darling please don't get upset
darling i said, i'm gonna be 27 soon
i've only got rejection letters and a sense of impending doom
i think it's too late for me
all the comic companies hate me
and i try but it's always the same
i guess my art is just lame and it's strange but still somehow i'm
always not suiting their needs at this time
and she said ........don't be upset,
you know that you're wonderful
just keep on trying ...(actually what she really said was)
all you ever wanna talk about is your self and your comic books and your album and your tour
and everytime i see your friends they just ask me where you are again and it hurts
it makes me feel like dirt
i'm just gonna write where you are on my shirt
and i said don't be upset, don't be in a bad mood
let's just go to a show and hang out and feel good
come on please don't be upset my darling, please don't be upset, i'll do anything baby, just don't be upset