LaTeX’s mathematical notation syntax has gained widespread adoption for formatting equations and formulas. It is now integrated into numerous digital platforms like markdown editors, web pages, word processing software, and online forums. But as with text, uniform, comprehensible formatting is not a matter of course. Good information is often spread across different documentation and organized according to implementation rather than the problem it solves.
Therefore, I created my own documentation to achieve the following objectives:
- Maximum compatibility: Use macros supported by KaTeX, MathJax, PdfLaTeX, to edit and preview in Obsidian, VSCode, and Overleaf, and to generate websites and PDFs.
- Portability: Emphasis on established packages that are better implemented. No custom macros - Built-in macros might be longer, but they are universally understood.
- Direct representation of values: I prefer seeing and editing the output values in place, rather than jumping through variables, dynamic calculations, or macro definitions.
- On-demand minimal syntax: Add complexity (like
\left
-\right
or extra braces) only when needed to keep the expressions shorter, and visually light weight.
My main resources are Mathematical Typesetting with LaTeX1 and the older LaTeX2 guide The Not So Short Introduction to LATEX2, as well as the official package documentations.
The amsmath package is a LATEX package that provides miscellaneous enhancements for improving the information structure and printed output of documents
that contain mathematical formulas.
- from Introduction p. 5 in AMSmath User’s Guide
Let :
- See examples with source code: Showcase of math equations
Math modes
Inline mode: $
… $
, see example in the paragraph
Display mode, see
- Centered equation(s): Single equation
\[
…\]
, Multiple equations\begin{gather*}
- Alternating right/left-aligned columns: Separated pairs
\begin{align*}
- pairs of touching columns\begin{alignat*}{2}
- Max. spaced-out to line width\begin{flalign*}
- See examples with source code: Array-like environments - Align equations and relation symbol relative to each other
Nested Array: Element inside inline or display mode containing columns aligned to the right, center, or left, see
- Surround with delimiters, see :
\begin{pmatrix}
-\begin{cases}
- Split overlong equations in multiple lines :
\begin{split}
This is an inline math expression within a paragraph, where symbols are smaller to keep the line height consistent within blocks of text.
Symbols
- Operators , Relations , Arrows
- More: Roots, fraction, matrix, operators, relations, accents, greek letter | Limits, super/subscript | escevt for better vectors #34 | Split delimiter | Math in description heading | Breaking (page/column break) | Fonts #23, styles #30
- See examples with source code: LaTeX Symbols - Lookup mathematical symbols, operations, relations, and arrows
Wrap long equation over multiple lines
- Split long fractions in two lines , Indent subsequent lines , Wrap overlong equations
- See examples with source code: Wrap long equation over multiple lines
Comment, explain your calculations
- Comment relations, see : Write short text above/below - Put longer text in a separate paragraph - Write zero-width overlapping text - Write on a extensible arrow
- Span braces under/over expressions, with possible overlap, see start of
- Comment nested array: Describe a case, see end of ; Name matrix columns and rows
- See examples with source code: Comment equation operators
Is equal because the function is symmetrical in the interval .
Reference, highlight equations
- Equation number : Combine arabic, roman alphabet; current section, part numbers; and static delimiters, text to reference the equation elsewhere
- Highlight part of an equation : Bold math
boldsymbol
, Diagonal strikeout\cancel
-\bcancel
-\xcancel
, Draw rectangle around math\boxed
-\begin{array}
- More: color
\textcolor
, boldmath, titlemath, ctagsplit and righttag Mathematical Typesetting with LaTeX p. 69
Follow varying typographic conventions with the same input syntax
- [c] usually not supported in Obsidian (MathJax); VSCode, Quartz (KaTeX)
- [c] less readable source
- [c] depend on package, or project
- [p] formatting in separate from the document
- Auto-scale left-right delimiter pairs :
\delimitershortfall
- Fraction in textstyle :
\frac
-\sfrac
-\nicefrac
- European, American number format :
\num
-\pgfmathprintnumber
- Units, quantities :
\unit
-\qty
- Currencies, money :
\dEUR
-\cJPY
- Dates : pgfcalendar
- See examples with source code: Follow varying typographic conventions with the same input syntax
Use typographic template for appearance of numbers
- Spread math over multiple display columns
- Scale, Placement : Scale delimiters manually/automatically, Scale repeating operators, Force limits, or exponents and indices
\limit
-\nolimit
, Scale equationsexscale
- Spacing : After line breaks
\\[1ex]
-\jot
, fraction styles, 1000 separator, Index (icomma german), smash for inline math,mathrlap
, Matrix spacing #30, styles, Fix delimiter space - everydisplay, everymath, underline, long text → parbox, strikethrough, allowlinebreak, delimitershortfal
Create commutative diagrams
- See examples with source code: Simple commutative diagrams supported by KaTeX, MathJaX - Amscd
- See more complex examples: Networks, Commutative diagrams - Dynamically draw graph networks as a vector graphic
Things to avoid, deprecated, bad syntax
- no
\\
at end of align - put
[]
after subenvironments - How not to typeset math in latex
Deprecated
-
package eqnarray
-
font syntax
-
macro stackrel
-
environments xalignat and xxalignat
-
new operator Mathematical Typesetting with Latex 0.34 2024-02-06, page 41
-
In markdown put display math delimiters
$$
on a separate line -
Don’t leave spaces in front of caret to prevent block reference detection (write
a^2
instead ofa ^2
)
Alternatives
OfficeMath for Microsoft Office
- OfficeMath - Math in Office
- OfficeMath - Create mathematical equations and expressions in Microsoft Office products
Typst Math
Footnotes
-
Mathematical Typesetting with LaTeX by Herbert Voß in 2024 which is an updated version of his 2014 Math mode ↩
-
The Not So Short Introduction to LATEX - Or LATEX in 280 minutes by Tobias Oetiker, Marcin Serwin Hubert Partl, Irene Hyna, and Elisabeth Schlegl in 2023 which in based on the german LATEX 2ε-Kurzbeschreibung by Marco Daniel, Patrick Gundlach, Walter Schmidt, Jörg Knappen, Hubert Partl, and Irene Hyna in 2018 ↩