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.

However, be warned that MathJax doesn't support all of TeX.

Introduction

Math

Text

Font sizes

For individual items, these adjustments increase the size incrementally: \big, \Big, \bigg, \Bigg. \Biggl(\biggl(\Bigl(\bigl((x)\bigr)\Bigr)\biggr)\Biggr) yields:

(((((x)))))

Common symbols

Operations and other symbols

Alignment

% inserts a comment lasting till the next newline.

% quadratic formula
ax^2 + bx + c = 0  % standard format

renders as:

ax2+bx+c=0

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}
x2+2x+1=0(x+1)2=0
Note

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}
15=5+4+3+2+15+15=5+4+3+2+145+15=5+4+3+2+1345+15=5+4+3+2+12345+15=5+4+3+2+1

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}
5+4+3+2+15+4+3+2+14+3+2+14+3+2+111

Matrices

These are always at display height.

More complex example:

\begin{pmatrix}
 &  Bob & Alice \\
Bob & 0 & 1 \\
Alice & 1 & 0
\end{pmatrix}
(BobAliceBob01Alice10)

Grouping braces

Try \begin{cases}2x+y=1\\3x-y=1\end{cases} to get:

{2x+y=13xy=1

or this:

|x|=\begin{cases}
x & \text{if }x>0 \\
-x & \text{if }x<0
\end{cases}

to get:

|x|={xif x>0xif x<0

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

(a,b,,z)26(a,b,,z)26

Cancel lines

Obsidian has imported the cancel macros, letting you write:

Example: \dfrac{x^\bcancel{3}}{\cancel{x^2}} = xx3x2=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:

Color

MathJax has already imported color!

It supports the standard colors and the 68 dvips color names:

blackblue,browncyan,darkgraygray,green,lightgray,lime,magenta,olive,orange,pink,purple,red,teal,violet,whiteyellow

There's a separate bbox package that lets you do \bbox[10px,cyan]{a+b} to include CSS padding like this: a+b. You can really go bananas: \bbox[lightblue,5px,border-style: solid; border-color:greenyellow; border-width: 4px]{x+y}x+y

Important

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} \requirephysics before your MathJax expression somewhere on the page. It's not enabled by default because it overwrites a number of standard macros!

However, it gives you Physics items like:

You may need other symbols, but these are defined elsewhere. For example, \hbar for Planck's constant.

Chemistry

Obsidian already includes mhchem for Chemistry which gives you:

Type Results
\ce{KCr(SO4)2*12H2O} KCr(SOA4)A212HA2O
\ce{^227_90Th+}, \ce{Fe^{II} A90227A2902227ThA+, FeAII
\ce{A\bond{-}B\bond{=}C\bond{#}D} AB=CD
or \ce{A\bond{1}B\bond{2}C\bond{3}D} AB=CD
\ce{A\bond{~}B\bond{~=}C\bond{-~-}D} A---B---C---D
\ce{Ca^2+(aq) + 2 OH-(aq) <=> Ca(OH)2(s)} CaA2+(aq)+2OHA(aq)Ca(OH)A2(s)
\ce{SO4^2- + Ba^2+ -> BaSO4 v} SOA4A2+BaA2+BaSOA4
\ce{A ->[catalyst] B} AcatalystB
\ce{K\overset{+7}{Mn}O4} KMn+7OA4
\pu{3.4e-8} or \pu{3.4E-8} 3.4108 or 3.4×108
\pu{8.314 J K-1 mol-1} 8.314 JK1mol1
\dfrac{\pu{50 mg}}{\pu{1 L}} \times \dfrac{\pu{1 g}} 50 mg1 L×1 g1000 mg
\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}
H3CHA3|CHA3CCHA3|Cl

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.

Ak1B k2k4Ck3Dk5Ek7k6GF 

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