# 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 which shows this in context:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
a &=b \\
&=c \numberthis \label{eqn}
\end{align*}
Equation \eqref{eqn} shows that $a=c$.
$$d = e$$
\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}

## Defining new operators

### Without Limits

i.e. limits on the side, $${\mathop{\mathrm{sech}}\nolimits}^2 x.$$.

Plain style (works everywhere including old MathJax):

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

amsmath style (works in AMSMath environments):

\DeclareMathOperator{\sech}{sech}

### With Limits

i.e. limits underneath $${\mathop{\rm arg\,max}}_{x\to\infty} x$$.

Vanilla:

\newcommand{\sech}{\mathop{\rm sech}\limits}

amsmath style:

\DeclareMathOperator*{\argmin}{arg\,min}

### No comments yet. Why not leave one?

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