A little more LaTeX

While I’m on the topic of LaTeX, I might as well throw in another post on how I’m writing my reports for work nowadays. It’s based strongly on TextExpander, because that’s the best way I know to make automations that work on both macOS and iOS.

Although my writing workflow does change occasionally, it tends to stay stable for years at a time. In the mid-90s, after learning HTML, I began using a system based on SGML and troff. That lasted until 2000 or so, when I started writing in LaTeX. After discovering Markdown (and MultiMarkdown), I began using a Markdown-to-LaTeX-to-paper workflow that changed to Markdown-to-LaTeX-to-PDF when my client base got a little more computer savvy. This system served me well for 10–12 years, starting in 2005. I wrote about it here, including a fun diagram.

A few years ago, though, I found myself writing more reports that needed extra care in formatting. I would start by writing in Markdown, as before, but too often had to edit the intermediate LaTeX to get the pages of the PDF looking the way I wanted. I decided it was best to just switch back to writing LaTeX directly. Coincidentally, this happened at about the time I bought my 9.7″ iPad Pro and wanted to start writing on it.

For the bulk of a report, writing in LaTeX isn’t much different from writing in Markdown. You’re basically just writing in plain text, with blank lines separating the paragraphs. The big differences come at the beginning of the text, where LaTeX requires a long header, and in the inclusion of figures, where LaTeX requires a lot of formatting to get the figures where you want them.1

Luckily, this extra writing needed by LaTeX is mostly boilerplate, and there’s a good system for automating the insertion of boilerplate on both the Mac and the iPad: TextExpander. I went through some of my LaTeX source files, pulled out the text fragments that I use frequently or are verbose, and built a set of TextExpander snippets with them. If you’re a LaTeX user, you can download them.

Fair warning: the longest snippet, the one that generates the LaTeX header, won’t work as-is for you because it relies on a style file (not included) that’s heavily customized for my company. But you can edit it to fit your needs.

LaTeX TextExpander snippets

One thing you’ll notice right away is that the abbreviations start with ll. That’s how the whole set is defined.

LaTeX snippet prefix definition

All of my snippets use a double letter prefix on the home row, and ll is a natural for LaTeX.

Many of the snippets are self-explanatory, but some are worth discussing, especially those for figures.

The llfig snippet is sort of the baseline snippet for figures that aren’t special in any particular way. The snippet definition is

\begin{figure}[htbp]
\begin{center}
\includegraphics[width=5.5in]{%clipboard%fillpopup:name=extension:default=.pdf:.jpg%}
\caption{%|}
\label{%clipboard}
\end{center}
\end{figure}

and it looks like this when invoked:

Figure fill-in snippet

It assumes the name of the figure file (sans extension) is on the clipboard and uses that in both the \includegraphics command and as the figure’s label for reference in the text. It provides a popup button to select whether the figure is a PDF or a JPEG, and it puts the cursor between the braces of the \caption command. I used to have a fill-in field for the caption, but I find it generally more convenient to type in a real text editor than in a field in a dialog box.

The [width=5.5in] specifier is something I often change after the fact to make for a better looking page. I don’t define it as a fill-in field because I don’t know the best width until I’ve seen the rendered page.

The llland snippet is specifically for figures that are photographs taken in landscape orientation. It’s similar to the llfig snippet, except the image will always be a JPEG and the size of the graphic is set to a height of 3.25 inches. This height works well for fitting two photos on a page.

\begin{figure}[htbp]
\begin{center}
\includegraphics[height=3.25in]{%clipboard.jpg}
\caption{%| (%clipboard).}
\label{%clipboard}
\end{center}
\end{figure}

Note also that the clipboard, which is supposed to be the filename sans extension when the snippet is invoked, is put in parentheses after the caption. I do this because I usually have dozens of photos associated with a project, and this makes it easier to identify the which photos are in the report.

The llport snippet is for photographs taken in landscape orientation. It’s more complicated than the llland, because I want the caption to show up next to the photo, not below it. It accomplishes this by creating two minipage environments, one on the left for the photo and one on the right for the caption.

\begin{figure}[htbp]
\begin{center}
\begin{minipage}[c]{0.55\linewidth}
\includegraphics[height=4.25in]{%clipboard.jpg}
\end{minipage}\hfill
\begin{minipage}[c]{0.40\linewidth}
\caption{%| (%clipboard).}
\label{%clipboard}
\end{minipage}
\end{center}
\end{figure}

Like the llland snippet, this allows two photos to fit together on the same page. Both can be landscape, both portrait, or one of each.

Example of landscape and portrait photographs

Finally, there is the llsfig snippet, which is just like llfig except that it uses the sidewaysfigure float defined in the rotating package. As you can guess from the name, this meant for large, wide figures that are best displayed rotated 90° on a page of their own.

\begin{sidewaysfigure}
\begin{center}
\includegraphics[width=8in]{%clipboard%fillpopup:name=extension:default=.pdf:.jpg%}
\end{center}
\hspace{1.5in}\parbox{6in}{\caption{%|}\label{%clipboard}}
\end{sidewaysfigure}

I wrote about using sidewaysfigure over a decade ago. Time flies.

All these snippets assume that the clipboard contains the filename without the extension because it’s easier on both platforms to copy the filename without the extension than with it. On a Mac, two slow clicks (not a double click) on a file in the Finder selects the filename without the extension, so a quick ⌘C puts that onto the clipboard. On an iPad, choosing Rename from a file’s popup menu in the Dropbox app puts the cursor just before the dot that starts the extension, so it’s easy to type ⇧⌘← to select and ⌘C to copy. Using the Files app is similar.

There are some compromises in these snippets that I wouldn’t have made back when I did all my writing on Macs. In those days, I would have avoided contaminating the clipboard and used AppleScript instead to get the name of the selected file in the Finder. But I want the portability of the iPad and consistency across platforms, so the small loss in productivity is worth it.


  1. This formatting was also required in my Markdown-LaTeX-PDF workflow, but it was handled by the XSLT that converted from Markdown to LaTeX.