Mentor
P: 12,064

Using LaTeX at Physics Forums
Getting started: Those fancy mathematical symbols are being made with something called LaTeX. It's easy to include LaTeX code in your posts at Physics Forums. You just need to type the LaTeX code that produces the formula you want between [itеx] and [/itеx]. For example, if you type
[itex]y = a x^2 + bx + c[/itex]
the result will be [itex]y = a x^2 + bx + c[/itex].
Alternatively, you can type LaTeX code between [tеx] and [/tеx]. These tags do essentially the same thing as the itex tags, but the formula will be displayed indented on a separate line. So if you type
[tex]\Delta \theta = \omega_0 t + \frac{1}{2} \alpha t^2.[/tex]
the result will be [tex]\Delta \theta = \omega_0 t + \frac{1}{2} \alpha t^2.[/tex] For the ones already familiar with LaTeX: itex tags are analogous to $, and tex tags are analogous to $$.
The easiest way to learn LaTeX is to see what others have done. If you see a post with a nice equation in it, just click QUOTE (at the bottom of the post) to see what the author did.
Simplified tags: Instead of typing [itеx] and [/itеx], you can type ## and ##. Instead of typing [tеx] and [/tеx], you can type $$ and $$.
For example
The equation ##x+2=3## implies $$x=1.$$
Will yield:
The equation ##x+2=3## implies $$x=1.$$
Punctuation: If you're using tex tags and you want a comma or a period after your formula, you should put it before the closing tex tag. If you're using itex tags, it doesn't matter if you put it before or after the closing itex tag. Also, when you use tex tags, the software will put a blank line before and after the formula. So you don't have to type any line breaks before the opening tex tag or after the closing tex tag. However, you can type a single line break before a tex tag without changing the output. The following example illustrates these ideas.
Let [itex]f:\mathbb R\rightarrow\mathbb R[/itex] be the function defined by
[tex]f(x)=x^2,[/tex] for all [itex]x\in\mathbb R[/itex].
Let [itex]f:\mathbb R\rightarrow\mathbb R[/itex] be the function defined by
[tex]f(x)=x^2,[/tex] for all [itex]x\in\mathbb R[/itex].
Important bug: vBulletin (the forum software) has a feature that will sometimes break correct LaTeX code. If you type more than 50 characters without a space, vBulletin will insert one for you after the 50th character. This will break the code unless you're lucky enough to have the space end up before a LaTeX command rather than in the middle of it. To prevent this from happening, you will have to make sure that your code contains a space at least once every 50 characters. If you often write long pieces of LaTeX code, you may want to start to routinely type extra spaces that will be ignored by the LaTeX processor, for example before equality signs and LaTeX commands that aren't arguments of other LaTeX commands.
Another bug is that if you edit a post that contains LaTeX code without going to advanced edit mode, the code will not be parsed when you view the thread immediately after saving the changes. The math looks fine to everyone else, but you will need to refresh the page (in your browser) to see the math again.
A very short introduction to LaTeXThe previous section explains how to include LaTeX code in posts, but it doesn't explain LaTeX. So in this section, we will explain how to type common mathematical formulas in LaTeX.
Special characters: The following characters have a special meaning in LaTeX: # $ % { } _ ^ \ ~
So if you want one of these characters to be displayed, you must type the code for the symbol rather than the symbol itself. The LaTeX codes for the first six of these symbols are: \# \$ \% \{ \} \_
Spacing: LaTeX ignores most of the spaces and endofline characters you type. For example
will produce [tex]x y
z[/tex] There is a number of LaTeX commands that you can use to control the horizontal distance between characters. \ (followed by a space) or ~ inserts a space. The difference is that ~ ensures that LaTeX will not break the line at that space. \, inserts a small space. \! inserts a small negative space (moves the cursor a little to the left). \quad and \qquad insert larger spaces. You can also use the \hspace command to explicitly specify the width of the space. For example,
[tex]
a\!b\,c\ d~e\quad f\qquad g\ \ \ \ h~~~~i\hspace{20mm}j
[/tex]
gives [tex]a\!b\,c\ d~e\quad f\qquad g\ \ \ \ h~~~~i\hspace{20mm}j[/tex]
To get the result [itex]f(x)=1\ \text{if} \ x>0[/itex], you can't just type
[itex]
f(x)=1 if x>0
[/itex]
The result will be ugly: [itex]f(x)=1 if x>0[/itex]. Any of these codes will do a better job:
[itex]f(x)=1\ \text{if}\ x>0[/itex]
[itex]f(x)=1~\text{if}~x>0[/itex]
[itex]f(x)=1\text{ if }x>0[/itex]
These are the results:
[itex]f(x)=1\ \text{if}\ x>0[/itex]
[itex]f(x)=1~\text{if}~x>0[/itex]
[itex]f(x)=1\text{ if }x>0[/itex]
The \text command tells LaTeX to interpret what comes next as text, instead of as variables.
Subscripts and superscripts: To put a subscript on a variable, use the _ symbol. To put a superscript on a variable, use the ^ symbol. For example, if you type
the result is [itex]x_y,\ x^y[/itex]. If you want to display just the subscript or the superscript, and not the variable, type {} where the variable would normally be. This trick is also useful when the horizontal positioning of the indices is important, as in the following example.
[tex]
\Lambda^\mu_\nu,\ \Lambda_\nu^\mu,\ \Lambda^\mu{}_\nu,\ \Lambda_\nu{}^\mu
[/tex]
[tex]
\Lambda^\mu_\nu,\ \Lambda_\nu^\mu,\ \Lambda^\mu{}_\nu,\ \Lambda_\nu{}^\mu
[/tex] Subscripts and superscripts work with integrals, limits, summations, and several other symbols. For example,
[tex]
\lim_{n\rightarrow +\infty} {\frac{\sin(x)}{x}}
[/tex]
will give us [tex]\lim_{n\rightarrow +\infty} {\frac{\sin(x)}{x}}[/tex] If you do the same thing between itex tags, then you get [itex]\lim_{n\rightarrow +\infty} {\frac{\sin(x)}{x}}[/itex]. The subscript is written next to the limit instead of beneath it. If you don't like this, you can use the \displaystyle command. For example,
[itex]
\displaystyle\lim_{n\rightarrow +\infty} {\frac{\sin(x)}{x}}
[/itex]
will give [itex]\displaystyle\lim_{n\rightarrow +\infty} {\frac{\sin(x)}{x}}[/itex].
Grouping: By default, most LaTeX commands act only on the first character or command on its right. (\displaystyle is one of the exceptions). To make them act on longer pieces of input, use curly brackets { }. For example
[itex]
x^{10}+x^10
[/itex]
gives [itex]x^{10}+x^10[/itex]. If you want to limit the scope of a \displaystyle command, place the curly brackets as in this example
[itex]
\lim_n x_n={\displaystyle\lim_n x_n}=\lim_n x_n
[/itex]
The result is [itex]\lim_n x_n={\displaystyle\lim_n x_n}=\lim_n x_n[/itex].
You can nest brackets within brackets as deeply as you want to build up a complicated expression. For example
[itex]
\sqrt{1+\sqrt{1+\sqrt{1+x}}}
[/itex]
gives [itex]
\sqrt{1+\sqrt{1+\sqrt{1+x}}}
[/itex].
Delimiters: The delimiters [itex](~),[~], \{~\}[/itex] are typed as ( ), [ ], \{ \}. Note that a curly bracket must be preceded by a backslash. If you want larger delimiters, then you can use the \big, \Big, \bigg and \Bigg commands. For example
[tex]
xe^x = x \Big( \sum_{n=0}^\infty\frac{x^n}{n!} \Big)
[/tex]
will give [tex]xe^x = x \Big( \sum_{n=0}^\infty\frac{x^n}{n!} \Big)[/tex] You can also let LaTeX choose the size of your delimiters. This can be done by typing \left or \right in front of the delimiter. For example
[tex]
xe^x = x \left( \sum_{n=0}^\infty\frac{x^n}{n!} \right)
[/tex]
will give [tex]
xe^x = x \left( \sum_{n=0}^\infty\frac{x^n}{n!} \right)
[/tex] The size of the delimiters is determined by the size of what's between them. Because of this, there must be a \right for each \left and vice versa. So if you only want one of the delimiters to be displayed, you still have to tell LaTeX where the region that determines the size begins or ends, by typing "\left." or "\right." (i.e. you type a period instead of a delimiter), as in the following example.
[tex]
\left\{
\begin{array}{l}
x=r\cos\theta\\
y=r\sin\theta
\end{array}
\right.
~~\Rightarrow~~ x^2+y^2
=r^2(\underbrace{\cos^2\theta+\sin^2\theta}_{=1})=r^2
[/tex]
[tex]
\left\{\begin{array}{l}
x=r\cos\theta\\
y=r\sin\theta
\end{array}\right.
~~\Rightarrow~~ x^2+y^2
=r^2(\underbrace{\cos^2\theta+\sin^2\theta}_{=1})=r^2
[/tex] The array environment is explained in one of the documents linked to after the table of common symbols below.
Different fonts: Sometimes we wish to type things in a different font. For example Blackboard bold, Calligraphic, Fraktur, Sans serif, Roman (upright), bold and typewriter. [tex]
\begin{align}
&\mathbb{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\
&\mathcal{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\
&\mathfrak{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\
&\mathsf{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\
&\mathrm{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\
&\mathbf{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\
&\mathtt{ABCDEFGHIJKLMNOPQRSTUVWXYZ}
\end{align}
[/tex] The codes
[itex]\mathbb A[/itex]
[itex]\mathcal A[/itex]
[itex]\mathfrak A[/itex]
[itex]\mathsf A[/itex]
[itex]\mathrm A[/itex]
[itex]\mathbf A[/itex]
[itex]\mathtt A[/itex]
give the results [itex]\mathbb A[/itex], [itex]\mathcal A[/itex], [itex]\mathfrak A[/itex], [itex]\mathsf A [/itex], [itex]\mathrm A [/itex], [itex]\mathbf A[/itex] and [itex]\mathtt A[/itex] respectively.
Note: The blackboard bold font only works with capital letters.
Frequently used symbols: This is a list of some of the most useful symbols and their LaTeX codes:
[tex]
\begin{array}{lcc}
\hline
\text{Infinity} & \text{\infty} & \infty \\
\text{Reduced Planck's Constant} & \text{\hbar} & \hbar \\
\text{Plusminus} & \text{\pm, \mp} & \pm, \mp \\
\text{Parallel} & \text{\parallel} & \parallel \\
\text{Perpendicular} & \text{\perp} & \perp \\
\text{For all} & \text{\forall} & \forall \\
\text{There exists} & \text{\exists} & \exists \\
\text{Ellipsis} & \text{\cdots, \vdots, \ddots, \dots} & \cdots, \vdots, \ddots, \dots \\
\hline
\text{Arrows} & \text{\rightarrow, \leftarrow, \leftrightarrow} & \rightarrow, \leftarrow, \leftrightarrow \\
& \text{\Rightarrow, \Leftarrow, \Leftrightarrow} & \Rightarrow, \Leftarrow, \Leftrightarrow \\
& \text{\mapsto, \to} & \mapsto, \to \\
& \text{\uparrow, \downarrow} & \uparrow, \downarrow \\
\hline
\text{Relations} & \text{\geq, \leq, \neq} & \geq, \leq, \neq \\
& \text{\gg, \ll, \equiv} & \gg, \ll, \equiv \\
& \text{\approx, \cong, \sim} & \approx, \cong, \sim \\
\hline
\text{Superscript} & \text{x^n} & x^n \\
\text{Subscript} & \text{x_i} & x_i \\
\text{Tensor indices} & \text{R_{ab}{}^{cd}} & R_{ab}{}^{cd} \\
\text{Fraction} & \text{\frac{1}{2}} & \frac{1}{2} \\
\text{Square root} & \text{\sqrt{16}} & \sqrt{16} \\
\text{Nth root} & \text{\sqrt[4]{16}} & \sqrt[4]{16} \\
\text{Absolute value} & \text{x} & x \\
\text{Norm} & \text{\\vec{x}\} & \\vec{x}\ \\
\text{Accents} & \text{\hat{p}, \vec{r}, \tilde{z}} & \hat{p}, \vec{r}, \tilde{z} \\
\text{Complex conjugate} & \text{z^*, \bar{z}, z^\dagger} & z^*, \bar{z}, z^\dagger \\
\text{Dirac notation} & \text{\langle \phi  \psi \rangle} & \langle \phi  \psi \rangle \\
\text{Multiplication} & \text{A \cdot B, A \times B} & A\cdot B, A\times B \\
\text{Direct Sum} & \text{V \oplus W} & V \oplus W \\
\text{Tensor Product} & \text{S \otimes T} & S \otimes T \\
\text{Function composition} & \text{f \circ g} & f\circ g \\
\text{Element of} & \text{x \in A} & x \in A \\
\text{Not in} & \text{x \not\in A} & x \not\in A \\
\text{Subset} & \text{A \subset B, B \subseteq C} & A \subset B, B \subseteq C \\
\text{Set Union} & \text{A \cup B} & A \cup B \\
\text{Set Intersection} & \text{A \cap B} & A \cap B \\
\text{Set Subtraction} & \text{A \setminus B} & A \setminus B \\
\hline
\text{Binomial coefficient} & \text{\binom{n}{k}, {_nC_r}} & \binom{n}{k}, {_nC_r} \\
\hline
\text{Big stuff} & \text{\bigcup_i A_i} & \bigcup_i A_i \\
& \text{\bigcap_i A_i} & \bigcap_i A_i \\
& \text{\sum_{n=0}^\infty a_n x^n} & \sum_{n=0}^\infty a_n x^n \\
& \text{\prod_{n=0}^\infty a_n} & \prod_{n=0}^\infty a_n \\
\hline
\text{Derivatives} & \text{y', y'', y^{(n)}} & y', y'', y^{(n)} \\
& \text{\dot{x}, \ddot{x}} & \dot{x}, \ddot{x} \\
& \text{\frac{\partial f}{\partial x}} & \frac{\partial f}{\partial x} \\
& \text{\nabla f} & \nabla f\\
& \text{\Box^2 \phi} & \Box^2 \phi \\
\hline
\text{Integrals} & \text{\int e^x\,dx} & \int e^x\,dx \\
& \text{\oint \vec{E}\cdot d\vec{A}} & \oint \vec{E}\cdot d\vec{A} \\
& \text{\iint, \iiint} & \iint, \iiint \\
\hline
\text{Elementary Functions} & \text{\sin x, \cos x, \log (x+y), ...} & \sin x, \cos x, \log(x+y), \dots \\
\hline
\end{array}
[/tex]
Another nice list of frequently used symbols can be found here. This PDF file contains another one. It also contains a brief explanation of the array environment, which was used in one of the examples above. If you don't see the symbol you need in any of these lists, try The comprehensive LaTeX symbol list (also a PDF file).
Sadly, not all LaTeX commands are being supported by MathJax. This is the full list of supported commands.
Formulas that span multiple lines: Longer formulas and systems of equations can be typed using the align environment. An environment is a piece of code that begins with a \begin statement and ends with an \end statement. The align environment begins with \bеgin{align} and ends with \еnd{align}. Inside an align environment (and several other environments), the code \\ ends a line and starts a new one. The & symbol is used to indicate where rows are to be aligned, as in the following example.
[tex]
\begin{align}
(1+x)^n &\geq 1+nx\\
&= \sqrt{(1+nx)^2}\\
&= \sqrt{1+2nx+n^2x^2}
\end{align}
[/tex]
This yields [tex]
\begin{align}
(1+x)^n &\geq 1+nx\\
&= \sqrt{(1+nx)^2}\\
&= \sqrt{1+2nx+n^2x^2}
\end{align}
[/tex]
Note: The \\ code only works in some environments.
Matrices: A matrix can easily be typed using the matrix, pmatrix, bmatrix or vmatrix environments. For example, the pmatrix environment is started with \bеgin{pmatrix} and ended with \еnd{pmatrix}. Columns are separated by & and rows are separated by \\ . Here is an example:
[tex]
\begin{pmatrix}
1 & 2 & 3 & 4\\
a & b & c & d\\
x & y & z & w
\end{pmatrix}
[/tex]
This yields [tex]
\begin{pmatrix}
1 & 2 & 3 & 4\\
a & b & c & d\\
x & y & z & w
\end{pmatrix}
[/tex]
The matrix, bmatrix and vmatrix environments produce similar results. Only the delimiters are different. See this web page for more examples.
The cases environment: Something like [tex]
\begin{cases}
2x+y+z & = 0\\
3x+4y+5z & = 0\\
x+2y+8z & = 0
\end{cases}
[/tex] can be easily typed using the cases environment. It is started with \bеgin{cases} and ended with \еnd{cases}. Rows must be separated by \\ and & is used to indicate where rows are to be aligned. The example above is produced by
[tex]
\begin{cases}
2x+y+z & = 0\\
3x+4y+5z & = 0\\
x+2y+8z & = 0
\end{cases}
[/tex]
Another example is
[tex]
u(x) =
\begin{cases}
\exp{x} & \text{if } x \geq 0 \\
1 & \text{if } x < 0
\end{cases}
[/tex]
which gives [tex]
u(x) =
\begin{cases}
\exp{x} & \text{if } x \geq 0 \\
1 & \text{if } x < 0
\end{cases}
[/tex] More information about cases, align and similar environments can be found here.
SandboxIf you wish to practice writing LaTeX or test some code, a sandbox is available here. Please do not create threads just to practice LaTeX.
Additional information If you have questions, you can ask them in the Math & Science Software subforum.
If you go to advanced edit mode in one of the technical subforums (this doesn't work in the Forum Feedback & Announcements forum for example), you will see a button with a Σ symbol on it, above the input field. If you click on it, a menu with mathematical symbols will appear. When you select a symbol, its LaTeX code will be typed automatically, along with a pair of itex tags.
A leftclick on a LaTeX image will by default display a box with a larger version of the same image. Try it on this one: [tex]x_{j_{2^k}}[/tex] A rightclick will display a menu where you can choose to view the LaTeX source code.
 change the factor by which the larger image is larger than the default size.
 always scale all LaTeX images to a larger or smaller size.
 change the zoom trigger, i.e. change what you have to do to make the larger image appear.
 go to the MathJax help page.
If you change the zoom trigger to "hover", you will only have to hold the mouse pointer over the LaTeX image for the larger version to appear. However, this will also make it harder to rightclick to bring up the menu, because a rightclick on the larger image does nothing. So if you want to change it back, you have to be fast. Move the mouse pointer over the image, and rightclick before the larger image appears.
Another way to see the LaTeX source code is of course to just click the QUOTE button next to the post. This is usually a better way, since it also shows the itex or tex tags, and the text around them, but it doesn't work in locked threads, or when the LaTeX image is in a quote box.
Simple nonLaTeX optionsIf you just want a subscript or a superscript, you can use vBulletin's sub and sup tags. For example, x[sub]1[/sub] yields x_{1}, and x[sup]2[/sup] yields x^{2}. If you don't want to type these tags, you can use the X_{2} and X^{2} buttons above the input field when you're in advanced edit mode.
If you just want to insert a Greek letter or a mathematical symbol in your post, the easiest way is to just click on the symbol you want in the box of symbols to the right of the input field when you're in advanced edit mode. If you need a symbol that you don't see in that box, you can try to find it in this blog post by Redbelly98, or on this web page.
Do not use these symbols, the sub/sup tags, or any other vBulletin tags in LaTeX mode (i.e. between tex or itex tags).
AcknowledgementsWe are indebted to member and former admin chroot, whose efforts brought LaTeX to Physics Forums in the first place, and forum admin and owner Greg Bernhardt for updating to the currentlyused MathJax processor. Numerous other members have provided valuable feedback and helped with the debugging process.
The authors of this FAQ are Fredrik
 micromass
 Redbelly98
 vela

