Mentor
Blog Entries: 10

## LaTeX FAQ

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

Code:
$y = a x^2 + bx + c$
the result will be $y = a x^2 + bx + c$.

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

Code:
$$\Delta \theta = \omega_0 t + \frac{1}{2} \alpha t^2.$$
the result will be $$\Delta \theta = \omega_0 t + \frac{1}{2} \alpha t^2.$$ 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 Code: 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. Code: Let $f:\mathbb R\rightarrow\mathbb R$ be the function defined by $$f(x)=x^2,$$ for all $x\in\mathbb R$. Let $f:\mathbb R\rightarrow\mathbb R$ be the function defined by $$f(x)=x^2,$$ for all $x\in\mathbb R$. 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 LaTeX The 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 end-of-line characters you type. For example

Code:
$$x y z$$
will produce $$x y z$$ 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,

Code:
$$a\!b\,c\ d~e\quad f\qquad g\ \ \ \ h~~~~i\hspace{20mm}j$$
gives $$a\!b\,c\ d~e\quad f\qquad g\ \ \ \ h~~~~i\hspace{20mm}j$$

To get the result $f(x)=1\ \text{if} \ x>0$, you can't just type

Code:
$f(x)=1 if x>0$
The result will be ugly: $f(x)=1 if x>0$. Any of these codes will do a better job:

Code:
$f(x)=1\ \text{if}\ x>0$
$f(x)=1~\text{if}~x>0$
$f(x)=1\text{ if }x>0$
These are the results:

$f(x)=1\ \text{if}\ x>0$
$f(x)=1~\text{if}~x>0$
$f(x)=1\text{ if }x>0$

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

Code:
$x_y,\ x^y$
the result is $x_y,\ x^y$. 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.

Code:
$$\Lambda^\mu_\nu,\ \Lambda_\nu^\mu,\ \Lambda^\mu{}_\nu,\ \Lambda_\nu{}^\mu$$
$$\Lambda^\mu_\nu,\ \Lambda_\nu^\mu,\ \Lambda^\mu{}_\nu,\ \Lambda_\nu{}^\mu$$ Subscripts and superscripts work with integrals, limits, summations, and several other symbols. For example,
Code:
$$\lim_{n\rightarrow +\infty} {\frac{\sin(x)}{x}}$$
will give us $$\lim_{n\rightarrow +\infty} {\frac{\sin(x)}{x}}$$ If you do the same thing between itex tags, then you get $\lim_{n\rightarrow +\infty} {\frac{\sin(x)}{x}}$. 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,

Code:
$\displaystyle\lim_{n\rightarrow +\infty} {\frac{\sin(x)}{x}}$
will give $\displaystyle\lim_{n\rightarrow +\infty} {\frac{\sin(x)}{x}}$.

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

Code:
$x^{10}+x^10$
gives $x^{10}+x^10$. If you want to limit the scope of a \displaystyle command, place the curly brackets as in this example

Code:
$\lim_n x_n={\displaystyle\lim_n x_n}=\lim_n x_n$
The result is $\lim_n x_n={\displaystyle\lim_n x_n}=\lim_n x_n$.

You can nest brackets within brackets as deeply as you want to build up a complicated expression. For example

Code:
$\sqrt{1+\sqrt{1+\sqrt{1+x}}}$
gives $\sqrt{1+\sqrt{1+\sqrt{1+x}}}$.

Delimiters: The delimiters $(~),[~], \{~\}$ 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

Code:
$$xe^x = x \Big( \sum_{n=0}^\infty\frac{x^n}{n!} \Big)$$
will give $$xe^x = x \Big( \sum_{n=0}^\infty\frac{x^n}{n!} \Big)$$ 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

Code:
$$xe^x = x \left( \sum_{n=0}^\infty\frac{x^n}{n!} \right)$$
will give $$xe^x = x \left( \sum_{n=0}^\infty\frac{x^n}{n!} \right)$$ 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.

Code:
$$\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$$
$$\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$$ 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. \begin{align} &\mathbb{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\ &\mathcal{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\ &\mathfrak{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\ &\mathsf{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\ &\mathrm{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\ &\mathbf{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\ &\mathtt{ABCDEFGHIJKLMNOPQRSTUVWXYZ} \end{align} The codes
Code:
$\mathbb A$
$\mathcal A$
$\mathfrak A$
$\mathsf A$
$\mathrm A$
$\mathbf A$
$\mathtt A$
give the results $\mathbb A$, $\mathcal A$, $\mathfrak A$, $\mathsf A$, $\mathrm A$, $\mathbf A$ and $\mathtt A$ 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:
$$\begin{array}{l|c|c} \hline \text{Infinity} & \text{\infty} & \infty \\ \text{Reduced Planck's Constant} & \text{\hbar} & \hbar \\ \text{Plus-minus} & \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}$$
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.

Code:
\begin{align} (1+x)^n &\geq 1+nx\\ &= \sqrt{(1+nx)^2}\\ &= \sqrt{1+2nx+n^2x^2} \end{align}
This yields \begin{align} (1+x)^n &\geq 1+nx\\ &= \sqrt{(1+nx)^2}\\ &= \sqrt{1+2nx+n^2x^2} \end{align}
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:

Code:
$$\begin{pmatrix} 1 & 2 & 3 & 4\\ a & b & c & d\\ x & y & z & w \end{pmatrix}$$
This yields $$\begin{pmatrix} 1 & 2 & 3 & 4\\ a & b & c & d\\ x & y & z & w \end{pmatrix}$$
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 $$\begin{cases} 2x+y+z & = 0\\ 3x+4y+5z & = 0\\ x+2y+8z & = 0 \end{cases}$$ 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

Code:
$$\begin{cases} 2x+y+z & = 0\\ 3x+4y+5z & = 0\\ x+2y+8z & = 0 \end{cases}$$
Another example is

Code:
$$u(x) = \begin{cases} \exp{x} & \text{if } x \geq 0 \\ 1 & \text{if } x < 0 \end{cases}$$
which gives $$u(x) = \begin{cases} \exp{x} & \text{if } x \geq 0 \\ 1 & \text{if } x < 0 \end{cases}$$ More information about cases, align and similar environments can be found here.

Sandbox
If you wish to practice writing LaTeX or test some code, a sandbox is available here. Please do not create threads just to practice LaTeX.

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 left-click on a LaTeX image will by default display a box with a larger version of the same image. Try it on this one: $$x_{j_{2^k}}$$ A right-click 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 right-click to bring up the menu, because a right-click 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 right-click 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 non-LaTeX options
If you just want a subscript or a superscript, you can use vBulletin's sub and sup tags. For example, x[sub]1[/sub] yields x1, and x[sup]2[/sup] yields x2. If you don't want to type these tags, you can use the X2 and X2 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).

Acknowledgements
We 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 currently-used 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