MathJax Basic Tutorial and Quick Reference - Mathematics Meta Stack Exchange
MathJax Basic Tutorial and Quick Reference - Mathematics Meta Stack Exchange
MathJax basic tutorial and quick reference
1. To see how any formula was written in any question or answer, including this one, rightclick on the expression it and choose "Show
Math As > TeX Commands". (When you do this, the '$' will not display. Make sure you add these. See the next point.)
2. For inline formulas, enclose the formula in $...$ . For displayed formulas, use $$...$$ .
These render differently. For example, type
$\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}$
2
(n +n)(2n+1)
to show ∑ (which is inline mode) or type
n 2
i =
i=0 6
$$\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}$$
to show
n 2
(n + n)(2n + 1)
2
∑i =
6
i=0
(which is display mode).
3. For Greek letters, use \alpha , \beta , …, \omega : α, β, … ω . For uppercase, use \Gamma , \Delta , …, \Omega : Γ, Δ, … , Ω.
4. For superscripts and subscripts, use ^ and _ . For example, x_i^2 : x , \log_2 x : log 2
i 2
x .
5. Groups. Superscripts, subscripts, and other operations apply only to the next “group”. A “group” is either a single symbol, or any
formula surrounded by curly braces { … } . If you do 10^10 , you will get a surprise: 10 0 . But 10^{10} gives what you probably wanted:
1
√x
These do not scale with the formula in between, so if you write (\frac{\sqrt x}{y^3}) the parentheses will be too small: ( 3
) . Using
y
√x
\left( … \right) will make the sizes adjust automatically to the formula they enclose: \left(\frac{\sqrt x}{y^3}\right) is ( 3
) .
y
\left and \right apply to all the following sorts of parentheses: ( and ) (x) , [ and ] [x], \{ and \} {x} , | |x|, \vert |x|,
\Vert ∥x∥ , \langle and \rangle ⟨x⟩ , \lceil and \rceil ⌈x⌉ , and \lfloor and \rfloor ⌊x⌋ . There are also invisible parentheses,
denoted by . : \left.\frac12\right\rbrace is } . 1
b+1
9. Fonts
Use \mathbb or \Bbb for "blackboard bold": CHNQRZ .
Use \mathbf for boldface: ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdef ghijklmnopqrstuvwxyz .
Use \mathtt for "typewriter" font: ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz .
Use \mathrm for roman font: ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdef ghijklmnopqrstuvwxyz .
Use \mathsf for sansserif font: ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdef ghijklmnopqrstuvwxyz .
Use \mathcal for "calligraphic" letters: ABCDE F GHI J KLMN OP QRS T UVWX YZ
lim
x→0
12. There are a very large number of special symbols and notations, too many to list here; see this shorter listing, or this exhaustive
listing. Some of the most common include:
2k
)
\to \rightarrow \leftarrow \Rightarrow \Leftarrow \mapsto → → ← ⇒ ⇐ ↦
\land \lor \lnot \forall \exists \top \bot \vdash \vDash ∧ ∨ ¬∀∃⊤⊥ ⊢⊨
\star \ast \oplus \circ \bullet ⋆ ∗ ⊕ ∘ ∙
\approx \sim \simeq \cong \equiv \prec \lhd ≈ ∼ ≃ ≅≡ ≺, ⊲ .
\infty \aleph_0 ∞ ℵ \nabla \partial ∇ ∂ \Im \Re I R
0
13. Spaces MathJax usually decides for itself how to space formulas, using a complex set of rules. Putting extra literal spaces into formulas
will not change the amount of space MathJax puts in: a␣b and a␣␣␣␣b are both ab. To add more space, use \, for a thin space a b; \;
for a wider space a b . \quad and \qquad are large spaces: a b, a b.
To set plain text, use \text{…} : {x ∈ s ∣ x is extra large} . You can nest $…$ inside of \text{…} .
14. Accents and diacritical marks Use \hat for a single symbol x
^ , \widehat for a larger formula xy
ˆ . If you make it too wide, it will look
−
→ ←
→
silly. Similarly, there are \bar x̄ and \overline xyz , and \vec x ⃗ and \overrightarrow xy and \overleftrightarrow xy . For dots, as in
¯¯¯¯¯¯¯¯
dx
(Tutorial ends here.)
It is important that this note be reasonably short and not suffer from too much bloat. To include more topics, please create short addenda and
post them as answers instead of inserting them into this post.
edited 2 days ago community wiki
59 revs, 21 users 52%
MJD
12 Some capital Greek letters are the same as the Roman equivalents, so they are not separated in LT
A
EX .
For a capital beta, one must use something like \mathrm{B} : B – robjohn ♦ Aug 28 '12 at 2:06
3 Two related questions: How do I insert a table when asking a question? and How to show the integral
symbol on this site? – Martin Sleziak Aug 28 '12 at 13:26
3 My basic idea is that if a beginner can express a formula clearly, then someone else can come in and
clean up the typesetting afterwards. I am considering getting rid of the section about \big , \left , and
\right for this reason, and trimming the section on spacing. – MJD Aug 30 '12 at 2:06
5 Most of the references to TeX or LaTeX in this and the answers ought to be to MathJaX (the exception
that I can see being the output of Detexify). I know this is a bit pedantic, but would it be alright to correct
this? – Loop Space Sep 11 '12 at 14:13
2 @AndrewStacey Thanks for pointing this out. Let's by all means be as correct as possible, particularly
when there's no extra cost. – MJD Sep 11 '12 at 14:15
2 @MJD Okay, I've had a go (also the answer about arrays). I wonder also whether or not it is worth a
sentence at the end pointing out that whilst MathJaX does its best to emulate TeX, it isn't TeX and so
while knowing how something is done in TeX gives you a starting point, it isn't a guarantee that the same
thing works in MathJaX. (As a case in point, questions about MathJaX are generally offtopic over on TeX
SX.) – Loop Space Sep 11 '12 at 14:22
2 @AndrewStacey I wouldn't. They are close enough that it seems to me to be a needless refinement. I
might even argue that MathJax is TEX , although an alternative implementation. We're willing to accept
that other programming languages (JavaScript, for example) that have slightly incompatible
implementations are nevertheless the same language; why not in this case as well? – MJD Sep 11 '12 at
14:35
4 @MJD Except that this is meant as a tutorial for those who aren't familiar with the distinction (and there
really is a distinction: "slightly incompatible implementations" doesn't really fit the bill here). One thing
tutorials often include is a "Where to find out more" section. This doesn't. Someone who doesn't know the
distinction might be tempted to search for help on TeX or LaTeX instead and wonder why it doesn't work. –
Loop Space Sep 11 '12 at 14:40
3 @axblount But that's precisely the wrong way around to think about it! The likelihood is that someone will
look at this tutorial to figure out how to write something on the MathsSX site: i.e., to use MathJaX. If they
can't find help here, where do they go? If they have the idea that MathJaX is "just a javascript
implementation of TeX" then they might think to look for help with TeX, but that is quite possibly not going
to be helpful. – Loop Space Sep 11 '12 at 15:08
4 @axblount For a start, you've changed the goalposts: "LaTeX math expressions". LaTeX is so much more
than just a way of typesetting maths! Second, I don't really know but it wouldn't take me long to cook one
up. I don't use MathJaX so I haven't explored it. But I know, for example, that it can't handle catcode
changes. Which means that I can't make ( and ) automatically resizeable. I can in LaTeX. –
Loop Space Sep 11 '12 at 16:04
29 I wish I saw this post when I first joined. This post should be a main link on the home page. There should
be a button under each box: NEW TO LATEX, CLICK HERE FOR EXAMPLES. This is extremely useful,
concise. – user1527227 May 31 '13 at 18:09
25 Answers
Matrices
$$
\begin{matrix}
1 & x & x^2 \\
1 & y & y^2 \\
1 & z & z^2 \\
\end{matrix}
$$
produces:
2
1 x x
2
1 y y
2
1 z z
MathJax will adjust the sizes of the rows and columns so that everything fits.
2. To add brackets, either use \left…\right as in section 6 of the tutorial, or replace matrix
1 2 1 2 1 2 ∣ 1 2∣
with pmatrix ( ) , bmatrix [ ] , Bmatrix { } , vmatrix ∣ ∣ , Vmatrix
3 4 3 4 3 4 ∣ 3 4∣
∥1 2∥
∥ ∥ .
∥3 4∥
⎝ 2 n
⎠
1 am am ⋯ am
4. For "augmented" matrices, put parentheses or brackets around a suitablyformatted table;
see arrays below for details. Here is an example:
1 2 3
[ ]
4 5 6
is produced by:
$$ \left[
\begin{array}{cc|c}
1&2&3\\
4&5&6
\end{array}
\right] $$
$\bigl( \begin{smallmatrix} a & b \\ c & d \end{smallmatrix} \bigr)$
edited Jul 3 '15 at 18:06 answered Aug 28 '12 at 4:17
Rory Daulton MJD
26.3k 2 4 39.7k 6 27 53
11 This says "End each matrix row with \\". But there is no reason to end the LAST row of the matrix that
way. The double backslash means: now go on to the next row. But there isn't any next row after the last
one. – Michael Hardy Aug 28 '14 at 5:15
Aligned equations
Often people want a series of equations where the equals signs are aligned. To get this, use
\begin{align}…\end{align} . Each line should end with \\ , and should contain an ampersand
at the point to align at, typically immediately before the equals sign.
For example,
−−−−−−−
2
−− 73 − 1
√37 = √
2
12
−−−−−−−−−−−
2 2
73 73 − 1
= √ ⋅
2 2
12 73
−
− −− −−−−−−−
2 2
73 73 − 1
= √ √
2 2
12 73
−−−−−−−
73 1
= √1 −
2
12 73
73 1
≈ (1 − )
2
12 2 ⋅ 73
is produced by
\begin{align}
\sqrt{37} & = \sqrt{\frac{73^2‐1}{12^2}} \\
& = \sqrt{\frac{73^2}{12^2}\cdot\frac{73^2‐1}{73^2}} \\
& = \sqrt{\frac{73^2}{12^2}}\sqrt{\frac{73^2‐1}{73^2}} \\
& = \frac{73}{12}\sqrt{1 ‐ \frac{1}{73^2}} \\
& \approx \frac{73}{12}\left(1 ‐ \frac{1}{2\cdot73^2}\right)
\end{align}
The usual $$ marks that delimit the display may be omitted here.
edited Apr 22 '15 at 7:36 answered Aug 28 '12 at 4:28
MJD
39.7k 6 27 53
2 Correct me if I'm wrong, but I don't believe the $$ is necessary before and after the \begin{align}. I've
certainly never used it. From experience, the \begin{align} puts you into mathdisplay mode by itself. –
TravisJ Apr 21 '15 at 12:24
1 I sometimes find that one line of this environment is too close to another, making them uncomfortable to
read. The interline spacing can be adjusted by using input such as \\[1ex] instead of \\ . (And of
course the 1 can be changed to another value such as 1.5 or .7 in order to get enough space but not
too much.) – David K Jan 30 at 16:29
Symbols
In general, you have to search in long tables about a specific symbol you're looking for, things
like Ψ , δ , ζ , ≥ , ⊆ ... And it turns out that this operation can be frustrating and time
consuming, which can cause the buddy to abandon writing the complete L TEX sentence in A
his answer, or in some cases, the complete answer itself.
That's why the tool that I will present you in this post was conceived. Basically, it is a L TEX A
handwritten symbol recognition. Example in image:
Here is the website: Detexify² No more frustration.
answered Oct 14 '13 at 20:15 community wiki
user93957
Definitions by cases (piecewise functions)
For example, you get this:
by writing this:
f(n) =
\begin{cases}
n/2, & \text{if $n$ is even} \\
3n+1, & \text{if $n$ is odd}
\end{cases}
The brace can be moved to the right:
by writing this:
\left.
\begin{array}{l}
\text{if $n$ is even:}&n/2\\
\text{if $n$ is odd:}&3n+1
\end{array}
\right\}
=f(n)
3n + 1, if n is odd
by writing this:
f(n) =
\begin{cases}
\frac{n}{2}, & \text{if $n$ is even} \\[2ex]
3n+1, & \text{if $n$ is odd}
\end{cases}
edited Jan 25 at 22:09 answered Aug 28 '12 at 4:34
MichaelChirico MJD
2,841 1 4 39.7k 6 27 53
@jibe In general, the separate cases in this notation should be in text style unless they are very very
complex (and then, the { notation is just wrong anyways). – yo' Aug 25 '14 at 9:53
Arrays
It is often easier to read tables formatted in MathJax rather than plain text or a fixed width
font. Arrays and tables are created with the array environment. Just after \begin{array} the
format of each column should be listed, use c for a center aligned column, r for right
aligned, l for left aligned and a | for a vertical line. Just as with matrices, cells are separated
with & and rows are broken using \\ . A horizontal line spanning the array can be placed
before the current line with \hline .
For example,
1 0.24 1 125
2 −1 189 −8
$$
\begin{array}{c|lcr}
n & \text{Left} & \text{Center} & \text{Right} \\
\hline
1 & 0.24 & 1 & 125 \\
2 & ‐1 & 189 & ‐8 \\
3 & ‐20 & 2000 & 1+10i
\end{array}
$$
Arrays can be nested to make an array of tables.
For example,
min 0 1 2 3 max 0 1 2 3
0 0 0 0 0 0 0 1 2 3
1 0 1 1 1 1 1 1 2 3
2 0 1 2 2 2 2 2 2 3
3 0 1 2 3 3 3 3 3 3
Δ 0 1 2 3
0 0 1 2 3
1 1 0 1 2
2 2 1 0 1
3 3 2 1 0
As the source for the preceding array is long, please rightclick on one of the tables and choose
Show Math As ▶ TeX Commands .
edited Aug 28 '14 at 5:17 community wiki
8 revs, 6 users 47%
robjohn
@RahulNarain: True. I used words just for illustration, but I guess the example was slightly misleading. If
you'd like to modify it please go ahead. – axblount Aug 29 '12 at 22:00
1 Thanks! I like your numeric example better, since the widths of the entries are different enough that the
alignment differences are visually clear. – MJD Aug 30 '12 at 1:37
@robjohn how do you use | while typing , i don't find it in my keyboard...... – ABC Mar 28 '13 at 12:05
@exploringnet: on my keyboard, it is the shifted backslash. It may be in different places (or absent)
depending on your keyboard. On my mobile device (iPhone), it is in the shifted numerics, to the right of the
backslash. In mathmode, \vert gives | and \mid gives ∣ , but neither works in the column spec for an
array. If you cannot type it on your keyboard, you can alwaays copy and paste it from another document. –
robjohn ♦ Mar 28 '13 at 17:39
It should perhaps be mentioned, that in nested arrays there seems to be no option to synchronize column
widths and/or rowheights over the toplevel. I didn't find a solution such that if two arrays are stacked
vertically one could make their columnwidths matching/fit. – Gottfried Helms Aug 26 '13 at 9:16
1 This could also be convenient for some people, althought it destroys the joy of writing tables in LT
A
EX by
hand! – nullgeppetto Jun 3 '14 at 14:18
@Rahul: why did regulars not press developers to enhance HTML formatting instead of doing inconvenient
and resourcedevouring detours through MathJax? When a table contains (mostly) formulæ, the use of a
formulaformatting engine looks determined. But when one wants just a table, why should it run software
with completely different purpose? I once tried to speak about it at meta.SE, but was gagged. – Incnis Mrsi
Dec 3 '14 at 12:11
@IncnisMrsi What kind of pressure could we apply: bribery, threats, kidnapping? A feature request was
made, supported by SE communities, and declined by SE (on technical grounds, as they say). At least we
have the MathJax workaround, with all of its flaws: SO and others have nothing. – ᴡᴏʀᴅs Dec 3 '14 at
15:55
Fussy spacing issues
These are issues that won't affect the correctness of formulas, but might make them look
significantly better or worse. Beginners should feel free to ignore this advice; someone else will
correct it for them, or more likely nobody will care.
Bad Better
π iπ
i iπ/2
e 2 e 2 e
π
π/2
2
∫ π sin x dx ∫ sin x dx
− −π/2
2
The | symbol has the wrong spacing when it is used as a divider, for example in set
comprehensions. Use \mid instead:
Bad Better
2 2
{x|x ∈ Z} {x ∣ x ∈ Z}
Bad Better
∫ ∫ f (x) dy dx ∬ f (x) dy dx
S S
∫ ∫ ∫ f (x) dz dy dx ∭ f (x) dz dy dx
V V
Use \, to insert a thin space before differentials; without this TEX will mash them together:
Bad Better
∭ f (x)dzdydx ∭ f (x) dz dy dx
V V
edited May 6 at 18:50
community wiki
8 revs, 2 users 97%
MJD
2 I think the first adjusted fraction looks better than the original, but I don't like the second. In any case, this
minor spacing imbalance is too peripheral to belong in a basic MathJax tutorial IMO. Too likely to scare
people away rather than make them feel helped. – Henning Makholm Aug 31 '12 at 21:05
1 @Henning Do you mean that the fraction example is too unimportant even to appear in an addendum on
fussy spacing, or that the fussy spacing article is too unimportant to appear as an addendum to the
tutorial? – MJD Aug 31 '12 at 23:57
1 I was talking specifically about the fraction example. Mostly I'm concerned that somebody will come away
thinking, Eeek! Do I have to worry about THAT to use the site? But it's also arguable that the disclaimer at
the top of the answer ought to take care of that. – Henning Makholm Sep 1 '12 at 21:13
1 @MJD I like the less space, but what if we want to list the bounds for multiple integrals? Like if we have
say 3 integrals and we have 3 separate bounds for each how would we list each one? Or do we have to do
\int_bound1^bound2\int_bound3^bound4\int_bound5^bound6?? – TheHopefulActuary Nov 19 '12 at 19:45
Colors
Named colors are browserdependent; if a browser doesn't know a particular color name, it
may render the text as black. The following colors are standard in HTML4 and CSS2 and
should be interpreted the same by most browsers:
\color{black}{text} text
\color{gray}{text} text
\color{silver}{text} text
\color{white}{text} text
\color{maroon}{text} text
\color{red}{text} text
\color{yellow}{text} text
\color{lime}{text} text
\color{olive}{text} text
\color{green}{text} text
\color{teal}{text} text
\color{aqua}{text} text
\color{blue}{text} text
\color{navy}{text} text
\color{purple}{text} text
\color{fuchsia}{text} text
HTML5 and CSS 3 define an additional 124 color names that will be supported on many
browsers.
Math Stack Exchange's default style uses a lightcolored page background, so avoid using light
colors for text. Stick to darker colors like maroon, green, blue, and purple, and remember also
that 7–10% of men are colorblind and have difficulty distinguishing red and green.
You can have a look here for quick reference on colors in HTML.
edited Aug 11 '14 at 18:54 community wiki
6 revs, 3 users 70%
MJD
3 We should add that colors can be used on items other than text, such as variables and operators. The
'\color' command applies to the next item: surround anything longer with braces. – Rory Daulton Feb 21 '15
at 20:30
System of equations
⎧ a1 x + b1 y + c1 z = d 1
⎪
⎨ a2 x + b2 y + c2 z = d 2
⎩
⎪
a3 x + b3 y + c3 z = d 3
by writing this:
$$
\left\{
\begin{array}{c}
a_1x+b_1y+c_1z=d_1 \\
a_2x+b_2y+c_2z=d_2 \\
a_3x+b_3y+c_3z=d_3
\end{array}
\right.
$$
Alternatively we can use \begin{cases}…\end{cases} . The same system
⎧ a1 x + b1 y + c1 z = d 1
⎨ a2 x + b2 y + c2 z = d 2
⎩
a3 x + b3 y + c3 z = d 3
is produced by the following code
$$\begin{cases}
a_1x+b_1y+c_1z=d_1 \\
a_2x+b_2y+c_2z=d_2 \\
a_3x+b_3y+c_3z=d_3
\end{cases}
$$
⎧ a1 x + b1 y + c1 z = d 1 + e1
⎨ a2 x + b2 y = d 2
⎩
a3 x + b3 y + c3 z = d 3
whose code is
$$
\left\{
\begin{aligned}
a_1x+b_1y+c_1z &=d_1+e_1 \\
a_2x+b_2y&=d_2 \\
a_3x+b_3y+c_3z &=d_3
\end{aligned}
\right.
$$
To align the = signs and the terms as in
⎧ a1 x + b1 y + c1 z
⎪
= d 1 + e1
⎨ a2 x + b2 y = d2
⎩
⎪
a3 x + b3 y + c3 z = d3
$$
\left\{
\begin{array}{ll}
a_1x+b_1y+c_1z &=d_1+e_1 \\
a_2x+b_2y &=d_2 \\
a_3x+b_3y+c_3z &=d_3
\end{array}
\right.
$$
Vertical space between equations. As explained in Definition by cases to get a larger
vertical space between equations we can use \\[2ex] instead of \\ . The system
p
1
⎧ a1 x + b1 y + c1 z =
⎪
⎪
⎪
q
1
⎪
⎪
⎪
p
2
⎨ a2 x + b2 y + c2 z =
q
2
⎪
⎪
⎪
⎪
⎪
⎩
⎪
p
3
a3 x + b3 y + c3 z =
q
3
is generated by the following code
$$\begin{cases}
a_1x+b_1y+c_1z=d_1 \\[2ex]
a_2x+b_2y+c_2z=d_2 \\[2ex]
a_3x+b_3y+c_3z=d_3
\end{cases}
$$
in comparison with
p
1
⎧ a1 x + b1 y + c1 z =
⎪
⎪ q
1
p
2
⎨ a2 x + b2 y + c2 z =
q
2
⎪
⎩ p
⎪ 3
a3 x + b3 y + c3 z =
q
3
whose code is
$$\begin{cases}
a_1x+b_1y+c_1z=\frac{p_1}{q_1} \\
a_2x+b_2y+c_2z=\frac{p_2}{q_2} \\
a_3x+b_3y+c_3z=\frac{p_3}{q_3}
\end{cases}
$$
In response to elect's comment. The following code
$$ \left\{ \begin{array}{l}
0 = c_x‐a_{x0}‐d_{x0}\dfrac{(c_x‐a_{x0})\cdot d_{x0}}{\|d_{x0}\|^2} + c_x‐a_{x1}‐
d_{x1}\dfrac{(c_x‐a_{x1})\cdot d_{x1}}{\|d_{x1}\|^2} \\[2ex]
0 = c_y‐a_{y0}‐d_{y0}\dfrac{(c_y‐a_{y0})\cdot d_{y0}}{\|d_{y0}\|^2} + c_y‐a_{y1}‐
d_{y1}\dfrac{(c_y‐a_{y1})\cdot d_{y1}}{\|d_{y1}\|^2} \end{array} \right.
$$
produces
⎨
⎪ (cy − ay0 ) ⋅ d y0 (cy − ay1 ) ⋅ d y1
⎪
⎪
⎪
⎩ 0 = cy − ay0 − d y0
⎪ + cy − ay1 − d y1
2 2
∥d y0 ∥ ∥d y1 ∥
edited Jun 29 '15 at 11:10 community wiki
7 revs, 2 users 94%
Américo Tavares
Continued fractions
Continued fractions are too big to put inline. Display them with $$ … $$ or use a notation like
[a ; a , a , a , …] .
0 1 2 3
answered Aug 31 '12 at 19:46 community wiki
MJD
The RHS of the following continued fraction
a1 a1 a2 a3
=
a2 b1 + b2 + b3 + …
b1 +
a3
b2 +
b3 + ⋱
can be typeset with the \genfrac command '{\genfrac{}{}{}{}{a_1}{b_1}} {\genfrac{}{}{0pt}{}{}{+}} {\genfrac{}{}{}{}
{a_2}{b_2}} {\genfrac{}{}{0pt}{}{}{+}} {\genfrac{}{}{}{}{a_3}{b_3}} {\genfrac{}{}{0pt}{}{}{+\dots}}' – Américo Tavares
Sep 17 '12 at 20:39
1 3
I wonder if something like 2 + 4 would be good enough? It is much simpler.
( \frac12{\vphantom{1}\atop+}\frac34 ) – MJD Sep 17 '12 at 22:30
Yes, it is. I didn't mention it because in User’s Guide for the amsmath Package it is written the following:
"Note. For technical reasons, using the primitive fraction commands \over, \atop, \above in a LATEX
document is not recommended (see, e.g., amsmath.faq)." – Américo Tavares Sep 17 '12 at 22:44
1 Happily, we are not writing LT
A
EX documents here. – MJD Sep 17 '12 at 22:44
4 Or write \underset{j=1}{\overset{\infty}{\LARGE\mathrm K}}\frac{a_j}{b_j}=\cfrac{a_1}
{b_1+\cfrac{a_2}{b_2+\cfrac{a_3}{b_3+\ddots}}} to get
∞
aj a1
K = .
j=1 bj a2
b1 +
a3
b2 +
b3 + ⋱
– Américo Tavares Jan 24 '13 at 9:15
∞
∞
ai
K
i=1 bi
– AlexR Feb 21 '15 at 20:48
@AméricoTavares, Why don't you edit the answer and put this extremely helpful command into there, I
think that would be more helpful. – user249332 Jan 24 at 15:44
Crossing things out
y+\cancel{x} y + x
\cancel{y+x} y + x
y+\bcancel{x} y + x
y+\xcancel{x} y + x
0
y+\cancelto{0}{x} y + x
1 9
1
\frac{1\cancel9}{\cancel95} = \frac15 =
5
9 5
\enclose{horizontalstrike}{x+y} x + y
x
\enclose{verticalstrike}{\frac xy}
y
\enclose{updiagonalstrike}{x+y} x + y
\enclose{downdiagonalstrike}{x+y} x + y
\enclose{horizontalstrike,updiagonalstrike}{x+y} x + y
\enclose can also produce enclosing boxes, circles, and other notations; see MathML
menclose documentation for a complete list.
edited Aug 4 '14 at 15:20 community wiki
4 revs
MJD
2 x
2
x
2+x
x +4
4
I see you can further resolve existing resolutions, 0 – alan2here May 1 at 2:40
Additional decorations
: A AA AAA
¯¯¯¯ ¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯¯¯
\overline
\underline : B
−
BB BBB
−−− −−−−
\widetilde : C̃ C
˜ ˜
C C C C
\widehat : D̂ DD ˆ
ˆ DDD
\fbox : E EE EEE
\underleftarrow : F F F F F F
←←−
−←−−−
\underrightarrow : G GG GGG
→ −
−→−−−→
\underleftrightarrow : H H H H H H
↔←−
→←−−→
\overbrace : (n − 2) + (n − 1) + n + (n + 1) +(n + 2)
Additional accents
\check : Iˇ
\acute : J´
\grave : K
`
edited Jun 9 '14 at 5:10 community wiki
6 revs, 4 users 71%
Américo Tavares
Tags & References
For longer calculations (or referring to other post's results) it is convenient to use the
tagging/labelling/referencing system. To tag an equation use \tag{yourtag} , and if you want
to refer to that tag later on, add \label{somelabel} right after the \tag . It is not necessary that
yourtag and somelabel are the same, but it usually is more convenient to do so:
$$ a := x^2‐y^3 \tag{*}\label{*} $$
2 3
a := x − y (*)
In order to refer to an equation, just use \eqref{somelabel}
$$ a+y^3 \stackrel{\eqref{*}}= x^2 $$
(*)
3 2
a + y = x
or \ref{somelabel}
Equations are usually referred to as $\eqref{*}$, but you can also use $\ref{*}$.
Equations are usually referred to as (*) , but you can also use * .
As you can see, references are even turned into hyperlinks, which you can use externally as
well, e.g. like this. Note that you can also reference labels in other posts as long as they appear
on the same site, which is especially useful when referring to a question with multiple
equations, or when commenting on a post.
edited May 2 at 8:23 community wiki
2 revs
Tobias Kienzler
To enable automatically tagging your queations with incremental numbers, add <script type="text/x
mathjaxconfig"> MathJax.Hub.Config({TeX: { equationNumbers: {autoNumber: "all"} }}); </script> to your
header. – Gerald Senarclens de Grancy Jan 20 at 20:56
@GeraldSenarclensdeGrancy That would however yield a global numbering on all answers to one question,
not peranswer. And it would break the current expectation of by default not having tags despite using
unstarred \begin{align} etc.... Though personally I'd agree with this – Tobias Kienzler Jan 21 at 7:19
Using \newcommand
I would like to remark that it is possible to define LaTeX commands as you do in your TeX
files. I felt so happy when I first discovered it! It's enough to insert something like
$ \newcommand{\SES}[3]{ 0 \to #1 \to #2 \to #3 \to 0 } $
at the top of your post (remember the dollars!). Then you can just use your commands as you
are used to do: in my example typing $$ \SES{A}{B}{C} $$ will produce the following:
0 → A → B → C → 0
It's also possible to use plain \def :
\def\ses#1#2#3{0 \to #1 \to #2 \to #3 \to 0}
3 Be aware that this affects the entire post, possibly even the frontpage, so it should be used with great care.
– AlexR Feb 21 '15 at 20:55
edited Feb 15 at 19:29 community wiki
3 revs, 3 users 75%
leonbloy
10 implies looks nicer as the arrow is longer and \to is quicker to right (and it's also what you say in your head
while typing it). at least that's what I think. – John Salvatierrez Jul 29 '13 at 13:21
x+2 = 4−x ⟹ x = 1.
– Mario Carneiro Feb 2 '15 at 14:22
Commutative diagrams
AMScd diagrams must start with a "require":
$\require{AMScd}$
\begin{CD}
A @>a>> B\\
@V b V V= @VV c V\\
C @>>d> D
\end{CD}
to get this diagram:
a
A −−−−−→ B
⏐ ⏐
b⏐ = ⏐c
↓ ↓
C −−−−−→ D
d
@>>> is used for arrow right
@<<< is used for arrow left
@VVV is used for arrow down
@AAA is used for arrow up
@= is used for horizontal double line
@| is used for vertical double line
@. is used for no arrow
Another example:
\begin{CD}
A @>>> B @>{\text{very long label}}>> C \\
@. @AAA @| \\
D @= E @<<< F
\end{CD}
A −−−−−→ B −−−−−−−−→ C
↑ ∥
⏐ ∥
⏐
D ====== E ←−−−−−−−− F
Long labels increase the length of the arrow and in this version also automatically increase
corresponding arrows.
$\require{AMScd}$
\begin{CD}
RCOHR'SO_3Na @>{\text{Hydrolysis,$\Delta, Dil.HCl$}}>> (RCOR')+NaCl+SO_2+ H_2O
\end{CD}
Hydrolysis,Δ,Dil.H C l
′ ′
RC OH R S O 3 N a −−−−−−−−−−−−→ (RC OR ) + N aC l + S O 2 + H2 O
edited Feb 4 at 15:04 community wiki
9 revs, 4 users 68%
Lehs
\begin{CD} RCOHR'SO_3Na @>{\text{Hydrolysis,\Delta, Dil.HCl}>> (RCOR')+NaCl+SO_2+ H_2O \end{CD}
Why does this code not give the correct output? – Quark Feb 4 at 10:04
@Lehs Thanks. That was a silly mistake :| What if I wanted to write something below the arrow? Also, could
you suggest some online website to learn MathJax? – Quark Feb 4 at 11:58
@Quark: then you move a > sign: @>>{\text{very long label}}> I learn MathJax from the examples i.e. in
this tread. – Lehs Feb 4 at 15:06
@Lehs Why did you rollback my edit...? You removed the formatting from the list, broke again (in Chrome)
the example diagram, and reinserted your duplicate example. Why? – Najib Idrissi Feb 4 at 15:25
@NajibIdrissi: because your edit appeared as a mess in IE. The diagram wasn't even written out. Maybe
there is something wrong in your or in my webprogram. Now it looks good in IE. – Lehs Feb 4 at 15:44
@NajibIdrissi: Now it also looks good in Chrome for Windows and for Android, plus Safari for Androids. I
don't know what the problem is with the current version. – Lehs Feb 4 at 15:56
Big braces
$$
f\left(
\left[
\frac{
1+\left\{x,y\right\}
}{
\left(
\frac{x}{y}+\frac{y}{x}
\right)
\left(u+1\right)
}+a
\right]^{3/2}
\right)
$$
renders as
3/2
⎛⎡ ⎤ ⎞
1 + {x, y}
f ⎜⎢ + a⎥ ⎟ .
⎜ ⎟
x y
⎣( + ) (u + 1) ⎦
⎝ y x ⎠
Note that curly braces need to be escaped as \{ \} .
$$
\begin{aligned}
a=&\left(1+2+3+ \cdots \right. \\
& \cdots+ \left. \infty‐2+\infty‐1+\infty\right)
\end{aligned}
$$
renders as
a =(1 + 2 + 3 + ⋯
⋯ + ∞ − 2 + ∞ − 1 + ∞) .
$$
\left\langle
q
\middle\|
\frac{\frac{x}{y}}{\frac{u}{v}}
\middle|
p
\right\rangle
$$
renders as
x
∥ ∣
y
⟨q ∥ ∣ p⟩ .
u
∥ v ∣
answered Oct 25 '13 at 17:47 community wiki
E.P.
Note: \Big( ... \Big) produces ( … ) but this bracket size is fixed in all situations unlike \left( ...
\right) which varies in size with its contents. \Big can be useful in various situations. – Nick Dec 19 '14
at 6:34
Arbitrary operators
arsinh(x)
This was already mentioned in a comment by Charles Staats. You might consider this an
addition to the FAQ section on \lim , \sin and so on.
1
Res( ) = 1
2
z=1 z − z
edited Sep 16 '15 at 3:13 community wiki
2 revs, 2 users 62%
MvG
Limits
2
To make a limit (like lim x −1
x−1
), use this syntax:
x→1
Lastly, add the function you want to apply the limit to. To make the limit mentioned above,
2
x−1
x→1
And that is how you make a limit using MathJax.
edited Jul 17 '14 at 12:25 community wiki
2 revs, 2 users 94%
JChau
9 Why not just \lim_{x\to 1}
lim ?
x→1
k
k
+ instead of +
i=1
i=1
6 Limits are usually written that way in typeset materials like papers and books when the limit is inline, rather
than a displayed formula, and that's why MathJax typesets it that way. – MJD Feb 26 '14 at 16:41
4 The issue with this answer is that it is trying to "force" display mode on inline code. Doing so makes the
text look less pretty. For example, see how the spacing between the lines change when I force display
1
mode using \lim\limits_{x\mapsto 1}\dfrac1x : lim . On the other hand, when I let TEX do what it
x↦1 x
wants to do, using \lim_{x\mapsto 1}\frac1x , the spacing between the lines stays the same, which is
1
much neater: limx↦1 x . This is much easier on the eyes. If you want to make your math mode more
prominent then take a new line using $$‐$$ – user1729 Jul 17 '14 at 12:30
Part 11 of the "question" shows how to write limits in the way they were meant to be written in LaTeX and
MathJax. – David K Nov 14 '15 at 23:17
Absolute values and norms
And here is the same formula rendered by your browser:
It was typeset as
$$|x|, ||v|| \quad\longrightarrow\quad \lvert x\rvert, \lVert v\rVert$$
edited Aug 13 '14 at 11:59 community wiki
4 revs, 3 users 89%
MvG
@MJD: What's your browser? I included a screenshot to support my claim. – MvG Aug 13 '14 at 11:24
Usually various versions of Firefox on either Linux or Windows. I happen to have Windows 8 booted now,
so here's a screenshot from there: a.pomf.se/jrujkq.PNG The bar height looks good on both pairs of
symbols; the spacing is a little off for the || version. On Linux they looked the same. – MJD Aug 13 '14
at 17:02
1 The difference in output that you are seeing has to do with whether you have the STIX fonts installed
locally on your computer or not. The | in STIX doesn't descend below the baseline, while in the MathJax
TeX fonts it does. – Davide Cervone May 20 at 14:16
Left and Right Implication Arrows
Another way to display the arrows for right and left implication instead
of using
$\Rightarrow$ , $\Leftarrow$ and $\Leftrightarrow$
The latter of which produces longer arrows which may be more desirable
to some.
edited May 6 '14 at 22:15 community wiki
3 revs, 2 users 74%
jnh
Giving reasons on each line of a sequence of equations
To produce this:
v + w = 0 Given (1)
−w + 0 = −w + (v + w) equations (1) and (2)
write this:
\begin{align}
v + w & = 0 &&\text{Given} \tag 1\\
‐w & = ‐w + 0 && \text{additive identity} \tag 2\\
‐w + 0 & = ‐w + (v + w) && \text{equations $(1)$ and $(2)$}
\end{align}
edited Feb 15 at 18:33 community wiki
2 revs
David K
Pack of cards
If you are asking (or answering) a combinatorics question involving packs of cards you can
make it look more elegant by using \spadesuit , \heartsuit , \diamondsuit , \clubsuit in math
mode:
♠ ♡ ♢ ♣
Or if you're really fussy:
\color{red}{\heartsuit} and \color{red}{\diamondsuit}
♡ ♢
edited Feb 1 at 13:10 community wiki
2 revs, 2 users 83%
David
Highlighting equation
$$ \bbox[yellow]
{
e^x=\lim_{n\to\infty} \left( 1+\frac{x}{n} \right)^n
\qquad (1)
}
$$
produces
n
x
x
e = lim (1 + ) (1)
n→∞ n
By default, the bounding box is "tight", so it doesn't extend beyond the characters used in the
formula. You can add a little space around the equation by adding a measurement after the
color. E.g.,
$$ \bbox[yellow,5px]
{
e^x=\lim_{n\to\infty} \left( 1+\frac{x}{n} \right)^n
\qquad (1)
}
$$
produces
n
x
x
e = lim (1 + ) (1)
n→∞ n
To add a border, use
$$ \bbox[5px,border:2px solid red]
{
e^x=\lim_{n\to\infty} \left( 1+\frac{x}{n} \right)^n
\qquad (2)
}
$$
produces
n
x
x
e = lim (1 + ) (2)
n→∞ n
You can do both border and background, as well:
$$ \bbox[yellow,5px,border:2px solid red]
{
e^x=\lim_{n\to\infty} \left( 1+\frac{x}{n} \right)^n
\qquad (1)
}
$$
produces
n
x
x
e = lim (1 + ) (1)
n→∞ n
edited Jul 4 at 11:05 community wiki
4 revs, 3 users 53%
webbertiger
Long division
$$
\require{enclose}
\begin{array}{r}
13 \\[‐3pt]
4 \enclose{longdiv}{52} \\[‐3pt]
\underline{4}\phantom{2} \\[‐3pt]
12 \\[‐3pt]
\underline{12}
\end{array}
$$
13
4 52
4
−
12
12
−−
This is adapted from http://stackoverflow.com/a/22871404/3466415 (which uses slightly
different but not less valid formatting).
edited Jul 27 '15 at 20:19 community wiki
5 revs, 3 users 93%
David K
Degree symbol
If your keyboard doesn't have a ° key, feel free to copy from this post here, or follow these
suggestions.
Note that comments below indicate that on some configurations at least, ° renders inferior to
^\circ . And I recently had a post of mine edited just for the sake of turning ° into ^\circ ,
indicating that someone felt rather strongly about this. So the suggestion above does seem
somewhat controversial at the moment. I maintain that from a semantic point of view, ° is
superior to ^\circ , and if the rendering suffers from this, then it's a bug in MathJax. After all,
LaTeX offers a proper degree symbol in the tex companion fonts, indicating that someone
there, too, decided that ^\circ is not perfect. But if things are broken now, I can't fault people
from pragmatically sticking with the rendering they prefer. Personally I prefer semantics, also
for the sake of screen readers.
edited Jul 4 at 11:06 community wiki
4 revs, 3 users 77%
MvG
If mathjax loads siunitx or gensymb, there is then \degree in latex which is the degree symbol. – dustin Feb
17 '15 at 22:29
@dustin: I couldn't find siunitx or gensymb mentioned anywhere in the MatJax source repository. Are they
available as some kind of thirdparty extension? If so, where? Since MathJax is not LaTeX, packages can't
be loaded unless they have been migrated. By the way, all occurrences of “degree” in the MathJax sources
refer to something else, as far as I can tell, so there really doesn't seem to be a \degree macro. There
should be one, imho. – MvG Feb 17 '15 at 23:39
I am not a mathjax expert. I just know latex. I just gave that suggestion in case they were available. Siunitx
would be a great package to have. If you aren't familiar, you will see the advantage by scanning the
documentation on ctan. – dustin Feb 17 '15 at 23:43
protected by MJD May 28 '15 at 17:18
Thank you for your interest in this question. Because it has attracted lowquality or spam answers that had to be removed, posting an answer now requires 10 reputation on
this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?