# LaTeX pet peeves

🕑 12 min • 👤 Thomas Graf • 📆 July 07, 2020 in Tutorials • 🏷 student advice, LaTeX

Somehow I wound up with five students writing their theses this Spring semester, and you know what this means: lots and lots of reading. And when reading, I can’t help but get riled up every time I see one of my LaTeX pet peeves. I also like to read the source files in parallel with the PDF, and over the years I’ve come across some nightmare-fuel coding in those files.

So, in a (futile?) attempt to save my future self’s sanity, here’s a list of all my LaTeX pet peeves. Many of them are covered in your average LaTeX tutorial, but people rarely read those cover to cover and instead just go to specific parts that they need to solve whatever problem they’re wrestling with. Compiling it all into a single list might make for a more useful reference. Future students of mine, read this and adhere to it. You have been warned!

# Using LaTeX where it isn’t needed

Alright, let’s start with the most important one: only use LaTeX if it’s the best tool for the job. LaTeX is the unrivaled champion when you have to do a lot of heavy lifting: bibliographies, references, multi-part documents, math, trees, autosegmental tiers, automata, glossed examples, data plotting, a single document for producing both handouts and slides; LaTeX handles all of that, um, perhaps not well, but better than any other solution on the market. Beware, though: with great power comes great responsibility, and a lot of my pet peeves are actually examples of the writer not paying attention to the subtle details of LaTeX that are the source of its power.

Great power also means a certain degree of clunkyness. For simple jobs, simpler tools are more efficient. If all you have to show me is a todo list, write that in a markdown dialect and convert it to PDF with pandoc. If it’s powerful enough for an outdex post, it’s probably powerful enough for whatever collection of notes you want to show me in our meeting.

# Not using labels and references

If I see a hardcoded reference like Section 1 in the source code, my blood pressure spikes. The whole point of LaTeX is that you don’t have to do these things. Liberally assign labels, and then use them, e.g. Section~\ref{sec:some_section}.

Be systematic with your labels. For instance, I like the format \label{type:container_name}, where type could be

• cha for chapters,
• sec for sections,
• ssec for subsections,
• fig for figure,
• tab for table,
• ex for example.

And container is the name of the containing unit. If a thesis contains a subsection in a chapter with label \label{cha:foo}, then the subsection would get the label \label{ssec:foo_bar}. That system isn’t perfect as it creates quite a hassle when I decide to make a subsection its own section, but it provides a rudimentary typing system for the document.

And if you reference a section that doesn’t exist and/or doesn’t have a label yet, don’t just omit the reference. Use \ref{type:container_name} based on what the label should be. That way, you won’t forget to insert the reference later on, and when you finally get around to writing that section, you already have a record of which other sections tie into it.

Oh, and because I’ve seen this mistake an estimated 328 times by now: labels in a float (figures, tables) must be specified after \caption, not before.

# Not using macros

The whole point of LaTex is to separate content from presentation. Don’t write something like $\text{the} :: =\mathrm{N} \mathrm{D} -\mathrm{nom}$. It’s tedious, prone to errors, and lacks semantics. Just define a bunch of custom macros:

\newcommand{\featfont}[1]{\ensuremath{\mathrm{#1}}}
\newcommand{\fsel}[1]{\ensuremath{=\featfont{#1}}}
\newcommand{\fcat}[1]{\ensuremath{\featfont{#1}}}
\newcommand{\flcr}[1]{\ensuremath{+\featfont{#1}}}
\newcommand{\flce}[1]{\ensuremath{-\featfont{#1}}}
\newcommand{\mlex}[2]{\ensuremath{\text{#1} :: #2}}

With those macros, you can rewrite the code above as \mlex{the}{\fsel{N} \fcat{D} \flce{nom}}. That’s easier to read, and it conveys clearly that you’re defining a lexical item with selector feature N, category feature D, and licensee feature nom. And if you decide later on that you want to use a different notation for features, you only have to change the macros.

\newcommand{\featfont}[1]{\ensuremath{\mathrm{#1}}}
\newcommand{\fsel}[1]{\ensuremath{\featfont{#1}^+}}
\newcommand{\fcat}[1]{\ensuremath{\featfont{#1}^-}}
\newcommand{\flcr}[1]{\ensuremath{\featfont{#1}^+}}
\newcommand{\flce}[1]{\ensuremath{\featfont{#1}^-}}
\newcommand{\mlex}{2}{\ensuremath{\text{#1} :: #2}}

# Subscripts

One quirk of LaTeX is that it only provides subscripts in math mode. So a writer that desires, say, labeled bracketing with subscripts, might try the following code:

John [$_{VP}$ arrived $t$]

This is wrong, wrong, wrong. In math mode, LaTeX treats each character as a separate mathematical variable and inserts some white space between them. So $_{VP}$ is actually interpreted as $_{V P}$. Instead of a single subscript VP, you get two subscripts V and P.

The difference is pretty blatant once you’re aware of it. Here’s the output produced from the code above.

And here’s what it should look like:

Notice the decreased spacing between V and P.

The second output is produced by replacing $_{VP}$ with $_\mathit{VP}$:

John [$_\mathit{VP}$ arrived $t$]

This now typesets VP as a single variable in math italics.

Alternatively, you could also use $_\text{VP}$ or $_\textrm{VP}$ to have the label typeset as normal text.

John [$_\text{VP}$ arrived $t$]

Quite generally, may I suggest you define a custom macro for the subscripts of labeled brackets?

\newcommand{\labsub}[1]{\ensuremath{_\text{#1}}}

This way, you can change the definition of the macro to fit the layout of your paper. This separation of code and output is exactly what makes LaTeX so powerful, so make generous use of it! In fact, why don’t you just use the following macro for your labeled bracketing:

\newcommand{\labbrack}[2][\unskip]{[\ensuremath{_\text{#1}} #2]}

This macro allows you to produce the output above from \labbrack{CP}{John \labbrack{VP}{arrived $t$}}.

# Ensure math with, well, \ensuremath

Some of the macros above use a command you might not have seen before: \ensuremath. The name tells you exactly what it does: it ensures that its argument is typeset in math mode. When you need math mode inside a macro, you should always use \ensuremath.

Crucially, don’t try to do something like the following:

\newcommand{\labsub}[1]{${_\text{#1}}$}


I like to even add spaces around the super-wide ---, and every single copy editor tried to dissuade me from that. I like the extra space, but I’m sure it’s somebody’s pet peeve, so, sorry about that.

# Bibtex capitalization

As you might know, your bibtex style automatically handles the capitalization of your references. But it only works well if

1. your bibtex references are in Sentence Case Title Case (thanks to Matthew Gotham for spotting this), and
2. you explicitly indicate which characters should not be lowercased.

So don’t write something like this:

title = {Some paper on MGs}

There is no easy way to convert this to Title Case if that’s what the publisher wants. And if the publisher want’s lowercase, you’ll get mgs instead of MGs.

title = {Some Paper on {MG}s}
This way, you will get the correct lowercase or Title Case depending on the publisher’s stylesheet, and either way MGs will stay MGs and won’t be lowercased to mgs.