“vi hw1.tex” is 10 keypresses; you can shave 1 off if you tab-complete after the “t” in “.tex.” “pdflatex hw1.tex” is 4 + 1 + 3 + 1 (“pdfl” + tab + “hw1” + tab) = 9 keypresses.
Suppose you substituted “make edit” for “vi hw1.tex” and “make compile” for “pdflatex hw1.tex.” You don’t save substantially on keystrokes, even with tab completion in play. However, in automating things, I prize mindlessness over brevity. If my brain poops out and I forgot that I’m working on homework 2, the irritation overhead invoked in having to watch vim pour the source file across the screen and having to quite and then vim homework 1 is substantial.
I’m a clumsy person. With leftovers in my right hand and garbage in my left, I have to think very carefully when I walk up to the bin to avoid strolling home with garbage in hand. Therefore, as a general rule, I prefer automated mindlessness over potential brevity. Chances are, I can script any actions I would take on this week’s homework better than I could expend idle brainpower making sure I act on the correct set of files.
The methodology is so simple that it’s laughable – I’m amazed I didn’t think of this in past years. In my homework folder I have a template file in LaTeX with all the boilerplate already in place. When I want to start on a new assignment – let’s say it’s homework no. 13 – I do:
cp -nv ./template.tex ./hw13.tex
and as a handy side effect, that file is now the most recently modified LaTeX file in the directory.
The magic follows – if I want to edit it, I can
and if I want to compile it, I can
… for which “compile” is actually the default target.
The top of the makefile makes everything clear:
CC=pdflatex EDIT=vim VIEW=pview TARGET_SRC=$(shell ls -t *.tex | head -n 1) TARGET_PDF=$(shell ls -t *.pdf | head -n 1)
This is evil; I’m sure of it. However, my files are (almost) never named with anything but alphanumerics, underscores, and dashes – so this hack works just fine for me.
I have previously dabbled in writing external (Perl) scripts for the make process to call. I was halfway through writing a new one for this term’s assignments when I realized I could make shell calls in Make. This setup is overall quite compact and extraordinarily easy to use.
A note: “pview” is a convenience script that backgrounds my PDF viewer (zathura as of today) so that Make can return without waiting for me to close the viewer:
zathura "$@" > /dev/null 2>&1 &
It’s enormously useful shorthand for launching my PDF reader straight out of the terminal.