LaTeX mathematics hacks



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

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.

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}

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

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}

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}

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 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}

No comments yet. Why not leave one?

GitHub-flavored Markdown & a sane subset of HTML is supported.