Getting really fast at LaTeX
- 6 minutes read - 1078 wordsTaking LaTeX notes in real time is one of my favorite useless party tricks. I started developing my techniques during the last year or two of undergraduate work at University of Washington, and was extremely good at it by the end of coursework at Northwestern. There are several keys to taking LaTeX notes in real time:
- Know LaTeX.
- Shortcut appropriately.
- Type keystrokes quickly.
- One keystroke re-renders.
- Type fewer keystrokes.
- Type fewer “strange” keystrokes (backslashes, curly braces, etc)
- Re-renders should scroll to your current location in the text.
- Extremely rapid debugging of LaTeX expressions.
Before I get started, one other note: I mention TextMate a few places, but in principle there is no reason you couldn’t configure all the same things in Vim, Emacs, or Sublime Text. If I was starting over, I might use Sublime Text instead.
Know LaTeX
Obviously, you must know LaTeX. You can start before you know everything, but you must know the basics of the document format, different sections, and the math you will use while taking class notes. One good way to do this is by typing homework solutions or personal notes on the subject material. This has the further benefit of producing typed homework solutions, which is definitely noticed and appreciated by the grader. This also has the benefit of telling you what things you do so commonly that they should be implemented as a macro.
Shortcut appropriately
If you can’t remember the LaTeX keyword for something, leave a placeholder in the code and a TODO in the comment. For example, if I forgot the command for an integral symbol, I might compose something like this:
\begin{equation}
% TODO: fix integral!
INTEGRAL from 0 to \infty f(x)dx
\end{equation}
The trick is remembering to come back and fix it later, but at least the TODO is easy to grep for.
Type keystrokes quickly
One of my professors actually didn’t believe that I was taking notes, because he didn’t think a random graduate student could type fast enough. I offered to do a typing speed test on the spot, and hit about 85 words per minute. I do not “type properly”, so I am not advocating strict adherence to home row or anything, but typing must be completely natural and fluid or you will fall behind when trying to write LaTeX. This is critical because of:
One keystroke re-renders
I have TextMate set up so that Command-R recompiles the LaTeX source, displays any errors, then (if there are no errors) switches to a display of the rendered PDF. This is critical, because comparing the rendered formulas in the PDF with the formulas on the chalkboard is crucial to ensuring their accuracy. Infrequent renders makes for unintelligible notes, which defeats the purpose of taking them in the first place.
Type fewer keystrokes
Typing “egin{equation}ENTER ENTER\end{equation}” is a massive waste of time. One (extremely poor) solution to this problem is to define macros, like the following:
\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}
This does lower the keystroke count considerably but is the wrong way to solve this problem, because:
- You now have a psuedo-LaTeX document.
- You have broken the syntax highlighting of every editor in existence.
- You have made your code less readable to any coauthors or contributors you might share documents with later.
- Your aliases make your code more difficult to debug, because if a line with a LaTeX macro causes an error, you must look in the vicinity of that line AND in the vicinity of the macro definition.
A much better alternative is to teach your text editor the macros. TextMate comes pre-loaded with an excellent macro system: I can type “eq” and it will expand to the begin/end equation constellation above, properly indented, with the cursor on an empty line between them. I can type “tab” and it will expand to
\begin{tabular}{c}
[cursor here]
\end{tabular}
A final note: While I despise LaTeX macros as shortcuts, I do believe in LaTeX macros as abstractions.
Type fewer “strange” keystrokes
As noted above, TextMate’s macro completion does not require me to type backslashes or curly braces. This has a tremendous speed and accuracy benefit.
Re-renders should scroll to your current location in the text For far too long, I used TextMate and the built-in PDF previewer. The trouble with this approach is that it does not scroll to your current position. I mostly sidestepped this problem by packing a lot into a single page, and using a new LaTeX document for every class session. The trouble with that approach was that at the end of the quarter, I had a collection of documents that I would have preferred to be separated by logical topics, instead of by dates.
A more logical approach is to keep longer documents but have the PDF viewer scroll to your current position in the text. This does require the use of Skim, and setting the Skim sync support to TextMate Preset, as described on How and Why to use TextMate for LaTeX.
Extremely rapid debugging of LaTeX expressions.
Eventually, you will mistype an equation and spend far too long debugging it. The professor will continue talking, and you will be counting curly braces, trying desperately to find the mismatch. Or the render will fail, because you used an invalid command, but it isn’t giving a good enough error message to figure out exactly what one. Here is one approach: LaTeX is whitespace insensitive. So split the equation at some logical point, comment half of it, compile that. If it compiles, repeat the process on the commented part, otherwise, switch which part is commented. This should help you zero in on the error very quickly. If you try this and don’t seem to be getting anywhere, leave it as is, add a TODO, and move on. It’s not worth getting behind to get the equation perfectly rendered. Write it down on a scratch paper, catch up with a classmate afterward, or snap a picture of the chalkboard (if you can do it without disrupting your classmates.)
Again, the most important part is probably to not get too hung up on making a particular LaTeX equation render.
BONUS: My LaTeX template
I like my notes to be filled to the brim. In particular, I use a two column format and the savetrees package. This is occasionally too narrow for long equations. In those instances, I use a figure to float it to the top or bottom of a page.
The template itself is at Github: traviscj/latex-notes-template.