LaTeX mathematics hacks

September 8, 2014 — September 7, 2022

computers are awful
faster pussycat
LaTeX
plain text
typography
UI
workflow
Figure 1

Tips for LaTeX specific to mathematical typesetting. See also Chris Cheung’s list.

1 Spacing and line breaking

Weird in maths. The breqn package position paper explains many of the issues. NB: the solutions that actually work in the javascript-backed LaTeX maths are multline (nb only one i) and split environments, so in practice I use those to ensure cross-compatibility of copy-pasta.

2 Opt-in equation numbering: \numberthis

The latex macro \numberthis is satisfying. Thanks Russell Tsuchida for showing it to me. It allows me to number only needed lines in multi-line equations. The macro goes like this:

\newcommand\numberthis{\addtocounter{equation}{1}\tag{\theequation}}

A minimal example in context:

\documentclass{article}
\usepackage{amsmath}
\newcommand\numberthis{\addtocounter{equation}{1}\tag{\theequation}}
\begin{document}
\begin{align*}
a &=b \\
  &=c \numberthis \label{eqn}
\end{align*}
Equation \eqref{eqn} shows that $a=c$.
\begin{equation}
d = e
\end{equation}
\end{document}

3 Math size

I forget this all the time. Explained by overleaf, Math font size ordering is

\displaystyle         % Size for equations in display mode
\textstyle          % Size for equations in text mode
\scriptstyle          % Size for first sub/superscripts
\scriptscriptstyle  % Size for subsequent sub/superscripts

4 Arrays

There is an array environment which is good for typesetting equations, but it is too verbose for typesetting arrays of other things like numbers.

Use amsmath matrix for that, e.g.

\begin{pmatrix}
1 & 2 & 3\\
a & b & c
\end{pmatrix}

5 Underbraces

If we want a brace underneath part of an equation, amsmath provides underbrace.

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
$$
\underbrace{u'-P(x)u^2-Q(x)u-R(x)}_{\text{=0, since~$u$ is a particular solution.}}
$$
\end{document}

6 Defining new operators

Without Limits i.e. limits on the side, \({\mathop{\mathrm{arg\,max}}\nolimits}_{x\to\infty} x\). Plain style (works everywhere including old MathJax):

\newcommand{\sech}{\mathop{\mathrm{sech}}\nolimits}

amsmath style (works in AMSMath environments):

\DeclareMathOperator{\sech}{sech}

If we want limits underneath (Does not seem to display correctly on this blog so we will have to use our imaginations)

Vanilla:

\newcommand{\sech}{\mathop{\mathrm sech}\limits}