MathJax reference
What a treasure trove! This page prioritizes what I tend to use or find interesting, mostly in the context of this Obsidian vault. The most complete and useful reference page I've seen is One Mathematical Cat, though sadly it's covers an old version (v2 versus the current, v4). The current docs are at MathJax.org, but show no examples.
See this MathJax SO post for more symbols, this LaTeX quick reference, Alek Sung's, or this PDF or Rice's for the full set. The LibreText MathJax tutorial may also be helpful. If you want to draw a symbol and have an app try to translate it to TeX (and hence MathJax), try Detexify.
However, be warned that MathJax doesn't support all of TeX.
Introduction
- For inline formulas, enclose the MathJax expression in
$…$.- For displayed formulas, use
$$…$$.
- For displayed formulas, use
- Most symbol macros are words prefaced with a backslash, like
\frac, and need a space to delimit them. Examples throughout. - Groups of symbols. Macros apply only to the next "group", one or more characters surrounded by curly braces
{…}.- For example, with superscript
^, if you didx^10, you'd get a surprise:! - But
x^{10}gives what you probably want:. - Braces can also allow you to "double up" a few macros, ex.
x^{2^{n}}to get.
- For example, with superscript
Math
Text
- For plain text as in business formulas, use
\text{after-effect}for normal words →, versus . - Spaces are tricky — MathJax sometimes collapses or ignores them. Use
\, \: \; \quad \qquadgives whitespace in increasing amounts:. - Use
~for a non-breaking space. - Use
\!for a negative thin space to mimic ligatures, like this:\rm a\!e→.
- Use
- Use
\dotsfor ellipses like this… "". \ldotsfor horizontal dots on the line:\cdotsfor horizontal dots above the line:\vdotsfor vertical dots:\ddotsfor diagonal dots:- See
\defbelow if you want ascending diagonal dots.
\daggerand\ddaggerare.
- Spaces are tricky — MathJax sometimes collapses or ignores them. Use
- Unicode is available via the pre-loaded
unicodeextension,\unicode{x2156}→. - For Greek letters, use
\alpha, \beta, …,\omega.- For uppercase letters, use
\Gamma, \Delta, …,\Omega. Ones like Alpha and Beta that look like their Roman equivalents don't have macros. Many letters have italicized variants, like\varGamma. - Some Greek letters have variant forms:
\epsilonvs. \varepsilon\kappavs. \varkappa\phivs. \varphi\pivs. \varpi\rhovs. \varrho\sigmavs. \varsigma\thetavs. \vartheta\digamma
- For uppercase letters, use
- Special typefaces.
- Blackboard bold, for sets:
\mathbb{N} \mathbb{Z}_p→ - Boldface,
\mathbf {a,A}→ - Calligraphy,
\mathcal {A,B}→ - Fraktur,
\mathfrak {a,A}→ - Roman,
\mathrm {a,A}→ - Script,
\mathscr {a,A}→- Lowercase l is
\ell→.
- Lowercase l is
- To turn these on to the end of the block, remove "math", ex:
\scr hello→.
- Blackboard bold, for sets:
- Card suits:
\spadesuit→, also .
Font sizes
\displaystyleis, suitable for separate blocks but not inline \textstyleis, normal use, the default \scriptstyleis\scriptscriptstyleis
For individual items, these adjustments increase the size incrementally: \big, \Big, \bigg, \Bigg. \Biggl(\biggl(\Bigl(\bigl((x)\bigr)\Bigr)\biggr)\Biggr) yields:
Common symbols
- Delimiters.
- You can use normal symbols like
| / ([{ }]).- There's
\backslash, though, because\is reserved for macros. \vertis an alternative for|;\Vertand\parallelboth yield. - You'll find a few other cases of two macros that render the same, where
\Vertis typesetting, but\parallelhas semantic meaning.
- You'll find a few other cases of two macros that render the same, where
- There's
- Angle brackets:
\langle S \rangle→. - Use
\leftand\rightto expand delimiters to fit larger macros like\dfrac, such as:\left| \dfrac xy \right|for, versus . \left(\dfrac{x}{x-1}\right)→
- Floor and ceiling:
\lfloor x\rfloor→, \lceil x\rceil→. \llcorner \lrcorner \ulcorner \urcornergives
- You can use normal symbols like
- For superscripts and subscripts, use
^and_. For example,x_i^2is. - Text decoration.
- Absolute value:
|x|or\vert \frac xy \vert→. - Vector:
\vec a→\overleftarrow{abc} \overrightarrow{abc}→
- Over-line for line segments, repeating decimals:
\overline {AB}makes - Estimated value, cross-product:
\hat afor, \widehat {ab}for, \widetilde{abc}for - Conjugates:
\overline{x} n^{\overline{m}}→ n^{\underline{m}}→
- Absolute value:
- Arrows.
\to \rightarrow \Rightarrow \implies \mapstomakes\gets \leftarrow \Leftarrow \impliedbyyields\leftrightarrow \ifffor\uparrow \Uparrowfor\downarrow \Downarrowfor\nearrow \nwarrow \searrow \swarroware
- Proofs.
\therefore x, \because y→- QED, use
\blacksquare \Boxto end a proof →`
Operations and other symbols
- Equals is just plain
=,\neqis. - Inequalities.
\lt \gt \le \ge \neq \ll \gg. - There's an "n" form of most of these for negation, ex.
\nleq - You can use
\notto put a slash through almost anything:\not\lt, but it often looks bad. - Preceder and successor:
\prec \succ
- There's an "n" form of most of these for negation, ex.
- Approximates.
\approx \sim \simeq \cong - Equivalence.
\equiv \lhd- Let operators:
\triangleq \overset{def}=, \mathrel{:=}→ - Proportions:
\propto
- Let operators:
- Binary operations.
\times \div \pm \mp \sqrt x. \sqrt[3]{x}is the cube root, and so on →x \cdot yis a centered dot →\star \ast \oplus \otimes \circ \bullet \Box→
- Fractions.
x/yworks →. \frac 25applies to the next two items →. - Use braces for grouping:
\frac{a+1}{b+1}is.
- Use braces for grouping:
- If both numerator and denominator need grouping, you may prefer
\over, which splits the group it's in:{x+1\over y+1}is. - Use
\dfracto display the letters normal size in a block, but considered improper when used inline:\dfrac{V_1}{n_1} = \frac{V_2}{n_2}→
- Trigonometric and other named functions are normally set in Roman font, use
\lim,\log,\sinand the like to make these:. - For "mod", you have a few choices:
\bmod,\mod, and\pmod:. bmodis "binary mod", spaced as an operator. - Nonstandard function names can be set with
\operatorname{foo}(x)→. - Use
\mathrmotherwise, as for Euler's constant\mathrm{e}→.
- For "mod", you have a few choices:
- Infinity is
\infty, and also a few Hebrew letters like \aleph_0→. - Sums and integrals.
\sumand\int, ex.\sum_{i=0}^n i^2yields. - Integral:
\int,\int_a^b f(x)→ - Limit:
\lim,\lim_{n\to \infty}→. - Product:
\prod_{i=1}^n a_i→ - Similar to
\dfrac,\displaystylecan expand these in text blocks, see #Font sizes:\displaystyle \lim_{n\to \infty} \sum_{i=1}^n f(x_i)\,\Delta x_i = \int_a^b f(x) \, \mathrm{d}x\→- Note that we're not using the #Physics extension for derivative support here.
- Integral:
- Other Calculus operations.
- Derivative. Lagrange's notation
f'→- or Newton's
\dot xand \ddot x - or Leibniz's
\frac{\mathrm{d}y}{\mathrm{d}x}, but see #Physics below. - Partials:
\frac{\partial f}{\partial x_i}
- Partials:
- or Newton's
- Gradient.
\boldsymbol{\nabla}→
- Derivative. Lagrange's notation
- Set operations.
\cup \cap \setminus \triangle \complement_Ais the set of items that belong to exactly one of and . - Also
\lorand\landfor join and meet operations:.
\subset \subseteq \subsetneq\supset \supseteq \supsetneq\in \notin- Such that:
:,|or\ni
- Such that:
\emptyset \varnothing
- Combinatorial notation.
{n+1 \choose 2k}and\binom{n+1}{2k}both yield\binom n{k_1, k_2, \ldots, k_m}→
- Factorial:
$n!$is - Sterling numbers:
\left[{n \atop k}\right]→\left\{\begin{matrix} n \\ k \end{matrix}\right\}→
- Logic.
\land \lor \lnot- Exclusive or (
XOR):A \veebar B→ \forall \exists \vdash \vDash- True, false:
\top \bot→ - Uniqueness:
\exists! x→
Alignment
% inserts a comment lasting till the next newline.
% quadratic formula
ax^2 + bx + c = 0 % standard format
renders as:
Right align over multiple lines using align, aligned, or align* via \begin and \end, like so:
\begin{align}
x^2 + 2x + 1 = 0 \\
(x+1)^2 &= 0
\end{align}
LaTeX differentiates between these three macros, but MathJax doesn't. I just use align.
An align environment is a table-like structure, with & (ampersand) as a column separator and \\ as a row separator. If you want to include whitespace use \phantom{item}, where item is the expression that has equivalent spacing. Here, we use them together to align equals signs:
\begin{align}
15&=5+4+3+2+1\\
-5+15&=\phantom{5+{}}4+3+2+1\\
-4-5+15&=\phantom{5+4+{}}3+2+1\\
-3-4-5+15&=\phantom{5+4+3+{}}2+1\\
-2-3-4-5+15&=\phantom{5+4+3+2+{}}1\\
\end{align}
The first expression in each line of an align block is right justified, then the expression within each subsequent 'column' alternates between being left-justified and right-justified. So, a 'column' in each line will be right-justified if it is preceded by an even number (0, 2, 4…) of ampersands, and it will be left-justified if preceded by an odd number (1, 3, …) of ampersands.
Thus, you can do achieve multi-column layouts, too, using && instead of &:
\begin{align}
5+4+3+2+1&&5+4+3+2+1\\
4+3+2+1&&4+3+2+1\\
\vdots&&\vdots\\
1&&1
\end{align}
Matrices
These are always at display height.
- With parentheses:
\begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}:. - With brackets, it's
bmatrixinstead:.
More complex example:
\begin{pmatrix}
& Bob & Alice \\
Bob & 0 & 1 \\
Alice & 1 & 0
\end{pmatrix}
Grouping braces
Try \begin{cases}2x+y=1\\3x-y=1\end{cases} to get:
or this:
|x|=\begin{cases}
x & \text{if }x>0 \\
-x & \text{if }x<0
\end{cases}
to get:
This shows under- and over-braces, and also the use of \quad to put items side by side: \underbrace{ (a,b,\ldots,z) }_{26} \quad \overbrace{ (a,b,\ldots,z) }^{26}:
Cancel lines
Obsidian has imported the cancel macros, letting you write:
\cancel: A diagonal line rising to the right\bcancel: A diagonal line falling to the right\xcancel: An 'X'\cancelto: A single-headed arrow rising to the right, with a value indicated at the end of the arrow
Example: \dfrac{x^\bcancel{3}}{\cancel{x^2}} = x →
Custom macros
If all this isn't enough, you can define your own macros with \def:
\def\iddots{
{\kern3mu\raise1mu{.}\kern3mu\raise6mu{.}\kern3mu\raise12mu{.}}}
% … then later on the page
\iddots
yields:
Enclosures
Obsidian has also imported enclosure for you, so you can do:
\enclose{longdiv}{x^2+5}→. \enclose{actuarial}{2x}→A_1\enclose{phasorangle}{\theta_1}→^3\enclose{radical}{x^6} = x^2→\enclose{box}{x = 1 \pm 3}→\enclose{roundedbox}{y = {1\over x}}→\enclose{circle}{f(x)=x^2}→- You may need to play with the spacing using
~, see\enclose{circle}{~~~~f(x)=x^2\phantom{x^2\over 1}}→
- You may need to play with the spacing using
left,right,top,bottom\enclose{bottom}{x+y}\cdots\enclose{right}{x\over y}→
updiagonalstrike,downdiagonalstrike,verticalstrike,horizontalstrike\enclose{circle updiagonalstrike}{a+b^2\over c+d}→, also illustrating that enclosures can be combined
Color
MathJax has already imported color!
It supports the standard colors and the 68 dvips color names:
\color(redefinition, becoming a to-end-of-scope modifier, takes RGB)\definecolor{clay}{rgb}{0.8,0.32,0.0}defines a color "clay" for later usethis\color{clay}{and}that→, note it's lasts until the end of the line - Use
\textcolorfor finer control,this\textcolor{Apricot}{and}that,
\colorbox, set the background color, as shown above with\colorbox{lightgray}{\color{white}{white}}\fcolorbox, similar, but with a frame:\fcolorbox{lime}{lightgray}{\color{white}{white}}→
There's a separate bbox package that lets you do \bbox[10px,cyan]{a+b} to include CSS padding like this: \bbox[lightblue,5px,border-style: solid; border-color:greenyellow; border-width: 4px]{x+y} →
If you specify a border around the text, in order for the MathJax to render correctly you MUST supply at minimum both the border-style and border-width properties. Further, the border-width property must be specified as a pixel value (e.g., 4px).
If you omit border-style, no border will be drawn. If you omit border-width or supply it as a relative-size keyword (e.g., thick), the text will be misaligned to the box and, on some browsers, will mess up the alignment of all following MathJax on the page!
Physics
To import physics, you need to put \require{physics}
However, it gives you Physics items like:
- Derivative:
\ddor\diffd→, such as . In practice, you'll want to preface these expressions with \,to insert a space.\dvdoes "fractions" like\dv{x}→and \dv{y}{x}→. \pdvfor partials,\pdv{y}{x}→- Use
\partialfor complicated stuff, like
- Use
You may need other symbols, but these are defined elsewhere. For example, \hbar →
Chemistry
Obsidian already includes mhchem for Chemistry which gives you:
- Chemical expressions
\ce, from formulas to diagram.^is an up arrow, not shown
- Physical unit
\pu, used for typesetting scientific expressions, units and measures.- Note,
\puis MathJax specific. The equivalent for LaTeX issiunitx.
- Note,
| Type | Results |
|---|---|
\ce{KCr(SO4)2*12H2O} |
|
\ce{^227_90Th+}, \ce{Fe^{II} |
|
\ce{A\bond{-}B\bond{=}C\bond{#}D} |
|
or \ce{A\bond{1}B\bond{2}C\bond{3}D} |
|
\ce{A\bond{~}B\bond{~=}C\bond{-~-}D} |
|
\ce{Ca^2+(aq) + 2 OH-(aq) <=> Ca(OH)2(s)} |
|
\ce{SO4^2- + Ba^2+ -> BaSO4 v} |
|
\ce{A ->[catalyst] B} |
|
\ce{K\overset{+7}{Mn}O4} |
|
\pu{3.4e-8} or \pu{3.4E-8} |
|
\pu{8.314 J K-1 mol-1} |
|
\dfrac{\pu{50 mg}}{\pu{1 L}} \times \dfrac{\pu{1 g}} |
\begin{array}{c}
\ce{\phantom{H_3}CH_3}\\% phantom to get the bond aligned with the C
| \\
\ce{CH_3-C-CH_3}\\
| \\
\ce{Cl}
\end{array}
There also exist packages like hpstatement and rsphrase, for official hazard statements and precautionary statements. For example, \rsphrase{S2} would yield "Keep out of the reach of children".
2D reaction networks
Since Obsidian has imported AMScd, you can also create 2D reaction networks! mhchem is also supported, but you have to apply it to each item in the grid. See the Chemistry Stack Exchange for more.
Arrows
| Type… | To get… | Meaning |
|---|---|---|
-> |
net forward reaction; elementary step | |
<- |
net backward reaction | |
<-> |
resonance structures (not for equilibria) | |
<=> |
equilibrium | |
<=>> |
equilibrium favouring forward reaction | |
<<=> |
equilibrium favouring reverse reaction |