Over the course of the LaTeX-typeset papers I’ve written during grad school, there are some tricks and macros I’ve carried with me all throughout. Here’s a small catalogue of some of the generally applicable ones.
Contents
- Correct package ordering
- Correct spacing after abbreviations
- Correct spacing after italics
- Stacking footnotes on top of punctuation
- Spacing before and after math environments
- More spacing adjustments
- Theorem statements on the next line
- Custom QED symbol
- Math and newlines in titles
- Custom equation tags
- Fixing theorem environments in LLNCS
- Appeasing arXiv
Correct package ordering
\RequirePackage{mathtools}
\documentclass[acmsmall,screen,review,nonacm]{acmart}
\settopmatter{printacmref=false, printccs=false, printfolios=false}
\usepackage{thmtools} % fix cref lemma/corollary names
\usepackage[capitalize,nameinlink,noabbrev]{cleveref}
\usepackage{ottalt}
\let\newlist\relax
\let\renewlist\relax
\usepackage{enumitem}
Some packages are particular about when they’re loaded:
mathtoolsmust be loaded beforeunicode-math, which is loaded byacmartthmtoolsmust be loaded beforecleverefhyperref, which is loaded byacmart, must be loaded beforecleverefottalt, which defines\newlistand\renewlist, must be loaded before undefining these macros, then loadingenumitem, which also defines them
Correct spacing after abbreviations
requires xspace package
\newcommand{\eg}{e.g.\@\xspace}
\eg, an example, or \eg an example.
In \nonfrenchspacing mode, where mid-sentence post-punctuation spacing is smaller than sentence-final spacing,
\@ after the last full stop in an abbreviation fixes the spacing to be mid-sentence spacing.
As with all text macros, adding \xspace at the very end inserts a space as needed without having to write \eg{}.
In \frenchspacing mode, word spacing and sentence spacing are the same size,
so this macro wouldn’t be needed.
I like this explanation of \@
on StackExchange, which explains what it actually does better than I could.
Correct spacing after italics
\begin{proof}
If \/ $\vdash \Gamma$ and $x : A \in \Gamma$ then $\Gamma \vdash x : A$.
\end{proof}
This isn’t a custom macro, but something I always forget to add: Sometimes upright text or mathematics collides with preceding italic text (italic f is a frequent culprit), requiring manually inserting an “italic correction” in between. This macro is described in the unofficial reference manual.
Stacking footnotes on top of punctuation
\newlength{\punctwidth}
\newcommand{\punctstack}[1]{#1%
\settowidth{\punctwidth}{#1}%
\kern-\punctwidth
}
Here's a sentence\punctstack{.}%
\footnote{Here's a footnote.}
Forget the footnote-before-or-after-punctuation debate!
I want footnotes directly above punctuation.
\punctstack will adjust the kerning between its argument and subsequent text
to be exactly negative the width of the argument.
Spacing before and after math environments
affects acmart documents
\begin{document}
\setlength{\abovedisplayskip}{0.25\baselineskip}
\setlength{\belowdisplayskip}{0.25\baselineskip}
This is a paragraph,
\begin{equation*}
0 + 1 = 1 = 1 + 0,
\end{equation*}
interspersed by an equation.
\end{document}
If you want to adjust the spacing between displaymath environments and surrounding paragraphs, setting the displayskip lengths needs to come after beginning the document.
More spacing adjustments
Here’s a table of the lengths I usually adjust for spacing,
set using e.g. \setlength{\fboxsep}{0pt}.
| length | of what | default |
|---|---|---|
jot |
space between lines in math environment | 3pt |
fboxsep |
distance from box to frame in \fbox |
3pt |
abovecaptionskip |
space above caption | 10pt |
belowcaptionskip |
space below caption | 0pt |
floatsep |
space between floats | 12.0pt plus 2.0pt minus 2.0pt |
textfloatsep |
space between top/bottom floats and text | 20.0pt plus 2.0pt minus 4.0pt |
intextsep |
space between in-text floats and text | 12.0pt plus 2.0pt minus 2.0pt |
The following are for the enumitem package specifically,
set using e.g. \setlist[enumerate]{topsep=0pt}.
The margins and horizontal spacing is rather complicated,
so I usually refer to the enumitem documentation
to figure out what I specifically want.
| length | of what |
|---|---|
topsep |
distance from top of list to previous paragraph |
parsep |
distance between paragraphs within a list item |
itemsep |
distance between list items |
As for the differences among
\mathord, \mathop, \mathbin, \mathrel, \mathopen, \mathclose, and \mathpunct,
I like this StackExchange answer,
which I probably wouldn’t need to reference if I had a real copy of the TeXBook.
Theorem statements on the next line
\begin{theorem}[A really long theorem name that leaves little room] \leavevmode \\
0 + 1 = 1 = 1 + 0.
\end{theorem}
If you need to shunt some math to the next line in a theorem environment,
use \leavevmode so that you can end the line.
Custom QED symbol
requires LuaLaTeX and fontspec package
\newfontfamily{\qedfont}{dejavu-sans}
\renewcommand{\qedsymbol}{\qedfont \char"220E}
\begin{proof}
A proof. \qedhere
\end{proof}
I like to set the QED symbol to the actual Unicode tombstone U+220E ∎. This does require that you use a font that supports it.
Math and newlines in titles
requires hyperref package
\newcommand{\titlelinebreak}{\textorpdfstring{//}{}}
\newcommand{\titlealpha}{\textorpdfstring{$\alpha$}{alpha}}
\title{A Title With \titlelinebreak A Line Break}
\subtitle{All about \titlealpha-conversion}
Hyperref generates metadata about the titles of your document and sections in a PDF,
and complains if you use macros that don’t generate text characters.
\textorpdfstring lets you specify what should be generated in their place within titles.
Custom equation tags
requires mathtools package
\mathtoolsset{showmanualtags}
\newtagform{brack}{[}{]}
\usetagform{brack}
\begin{gather}
0 + 1 = 1 \nonumber \\
1 + 1 = 2 \tag{fib3} \\
1 + 2 = 3 \tag{fib4} \\
2 + 3 = 5 \tag{fib5}
\end{gather}
\usetagform{default}
Instead of automatically tagging equations by an increasing count,
you can manually write the desired \tag by setting showmanualtags.
You can also set and reset the tag delimiters with \newtagform and \usetagform.
The last three equations above are tagged as [fib3], [fib4], and [fib5].
Fixing theorem environments in LLNCS
affects llncs documents
\makeatletter
\let\ORIGINAL@spythm\@spythm
\def\@spythm#1#2#3#4[#5]{
\NR@gettitle{#5}
\ORIGINAL@spythm{#1}{#2}{#3}{#4}[#5]
}
\makeatother
LLNCS does something peculiar with theorem environments that breaks \nameref.
This solution is lifted directly from the StackExchange answer.
\makeatletter
\def\axiomname{axiom}
\spn@wtheorem{axiom}{Axiom}{\bfseries}{\itshape}
\makeatother
While LLNCS already defines a ton of theorem environments (namely theorem, corollary, definition, lemma, proposition, case, conjecture, example, exercise, note, problem, property, question, remark, and solution), defining your own requires some finagling. In the macro above, the first field is the environment name, the second field is header text, the third field is the style of the theorem name, and the fourth field is the style of the theorem text.
Appeasing arXiv
\pdfoutput=1
Back in the day, there used to be a lot of incantations required to satsify arXiv’s demands,
from weird 00README.XXX files with nohypertex to the occasional Undefined control sequence.
Nowadays, setting \pdfoutput seems to be the only thing required.