## A Latex Tutorial

Anything that doesn't fit anywhere else below.

### A Latex Tutorial

This thread is meant as a small Latex manual to help the Equations thread and its discussion. In its current form the MathJax editor doesn't allow every standard Latex command, so I will also explore some workarounds and tricks.
To view any source code, right-click on the formula. Make sure that Settings, Math Renderer is set to HTML-CSS.

Font styles
Latex's default font in mathematical equations is a form of italics. But different styles are available; for instance, if you want a normal upright character a, type \mathrm{a} (rm stands for Roman). The most common styles are the following:

Note that you need the command \boldsymbol{} to type a bold math symbol; \mathbf{} renders a bold upright character. If you want to include normal text inside an equation, use the \text{} command. Unfortunately, MathJax doesn't seem to like Latex commands inside the \text{} environment.

Spaces

There are various commands for horizontal spaces: a backslash follow by a blank space, \ , inserts a normal space. For smaller spaces, use one of these \, \; \: For larger, there is \quad and \qquad . For a space of any length, there's the \hspace{} command: just insert a unit between the brackets.
For instance, \hspace{1cm} will render a 1cm space. Other units are available as well, such as mm, in (inch), or pt (point).

There is also a command for a tiny negative space, to place two characters closer together: \!
And the \phantom{} commands provides a neat trick to insert a space with the length of the characters inside the brackets.

In standard Latex, a vertical line-break can be inserted by two backslashes: \\, and a line space of any length can be achieved by e.g. \\[1cm]. Unfortunately, MathJax is more limited: I only managed to get \\ to work inside a \begin{align}\end{align} environment (see below). In standard Latex, there's also the \vspace{} command, but that doesn't seem to work either. Here are a few examples:

Accents

Here are a few common accents and over- and underlines:

Sub- and superscript

To add a subscript to a character, use an underscore _, or _{} if you want to add more than one subscript character. For superscript, use ^ or ^{}. If you want a standalone sub- or superscript (i.e. not preceded by a normal character), you have to precede _ or ^ by empty brackets; see the example for a hypergeometric function.

Note the \circ for degrees. It's also common practice to use upright text for units, like km and s in the last example.

To be continued...
Last edited by Pulsar on Feb 16, 2012 3:29 am, edited 1 time in total.
"The longer I live the more I see that I am never wrong about anything, and that all the pains that I have so humbly taken to verify my notions have only wasted my time." - George Bernard Shaw

Pulsar

Posts: 4615
Age: 40

Country: Belgium
Print view this post

### Re: A Latex Tutorial

Greek letters

Miscellaneous symbols

Standard function names

And various others.

Binary symbols

Dots
Last edited by Pulsar on Feb 16, 2012 4:34 am, edited 1 time in total.
"The longer I live the more I see that I am never wrong about anything, and that all the pains that I have so humbly taken to verify my notions have only wasted my time." - George Bernard Shaw

Pulsar

Posts: 4615
Age: 40

Country: Belgium
Print view this post

### Re: A Latex Tutorial

Arrows

If you want an arrow with additional text, use \xleftarrow or \xrightarrow. Be aware of the precise format: text below is placed between square brackets [] and can be omitted, while text above is placed between mandatory curly brackets {}.

In combination with the \lim operator, you can write something like this:

This doesn't look very pretty, but it can be tidied up by enclosing the equation by a \displaystyle{} environment:

Various operators

Again, use \displaystyle{} for nice results:

Note the \substack{} command in the third sum, to stack multiple limits. Fractions and binomials looks as follows, without and with \displaystyle{}:

Brackets

Note the backslash in \{ and \} to produce curly brackets. The size of these delimiters can be increased manually by preceding them with \big, \Big, \bigg or \Bigg. You can also let Latex determine an appropriate size, by using \left and \right. However, every \left delimiter has to be followed by a similar \right delimiter; in case you want only one delimiter, use a dot for the other, i.e. \left. or \right. to generate an empty delimiter. See the examples:

The \underbrace{} and \overbrace{} commands produce

Last edited by Pulsar on Feb 16, 2012 4:47 am, edited 1 time in total.
"The longer I live the more I see that I am never wrong about anything, and that all the pains that I have so humbly taken to verify my notions have only wasted my time." - George Bernard Shaw

Pulsar

Posts: 4615
Age: 40

Country: Belgium
Print view this post

### Re: A Latex Tutorial

Equations

I've used the \begin{align} \end{align} environment several times already, without discussing its use: with align, you can type multiple, aligned equations. The ampersand & serves as a tab stop; usually, you want the lines to be aligned on the equation sign:

You can also align two sets of equation side by side, as follows:

If you want even more, use the alignat environment. It has a parameter denoting the amount of aligned columns. Here's an example with three:

Alternatively, you can centre equations rather than align them. To do this, use the gather environment.

Long equations can be split with the multline environment. In the example below, you see that the \left( bracket has to be followed by a \right. (an invisible right bracket) at the end of the first line, otherwise Latex will raise an error. Likewise, the second line starts with \left. (an invisible left bracket) and ends with \right).

However, to ensure that the closing \right) is as big as the opening \left( , we need another trick: the command \vphantom{} inserts an invisible vertical space, given by the text inside the brackets - analogous to the horizontal \phantom{}. On the first line, the summation \sum_{i<j} is the largest symbol, so \vphantom{\sum_{i<j}} inserts an equally large, but invisible symbol on the second line, which guarantees that \left( and \right) are of the same size.

"The longer I live the more I see that I am never wrong about anything, and that all the pains that I have so humbly taken to verify my notions have only wasted my time." - George Bernard Shaw

Pulsar

Posts: 4615
Age: 40

Country: Belgium
Print view this post

### Re: A Latex Tutorial

Math styles

Symbols can be displayed in one the following styles: \displaystyle{} (for standalone equations), \textstyle{} (for equations in a sentence), \scriptstyle{} (for e.g. sub- and superscripts), and \scriptscriptstyle{} (for e.g. subsub- and supersuperscripts). Latex scales sub- and superscripts automatically, but occasionally the explicit commands \scriptstyle{} and \scriptscriptstyle{} are handy in other situations.

Text and Symbol size

The above styles define relative symbol sizes, which depend on the environment in which they are used. Latex also allows to manually change text font sizes, with the \tiny{}, \scriptsize{}, \small{}, \normalsize{}, \large{}, \Large{}, \LARGE{}, \huge{}, and \Huge{} commands. Surprisingly, MathJax also allows the use of these commands inside formulae.

Text boxes

Normal text can be written inside \text{}. Alternatively, there is the \mbox{} environment, which is almost the same as \text{}. However, unlike the \text{} command, text inside an \mbox{} does not scale when it is part of a sub- or superscript. Math symbols can be used inside a box by putting it between signs; unfortunately MathJax doesn't seem to allow any commands inside a textbox. \fbox{} is similar to \mbox, but draws a frame around the text. A more general command to draw frames is \boxed{}, which can be used around any formula. Unfortunately, MathJax does not support more advanced text boxes, like \makebox{} and \parbox{}. This makes it difficult to write multi-line text; possible tricks are stacking text, or using arrays (see below) Stacking symbols and text There are various ways to stack two lines of symbols or text on top of each other. The \substack{} command was used before, but there's also the slightly different { \atop } command. The size of the symbols is automatically decreased; to change these sizes to normal, put the symbols inside \displaystyle{}. With the \underset{}{} and \overset{}{} commands, you can put smaller-sized symbols or text below/above a normal line: A similar command is \stackrel{}{}, which puts normal-sized symbols/text on top of a normal line. \stackrel might help to define new symbols. For instance, MathJax does not support the Angstrom symbol, so we could create one as follows: This doesn't look very pretty. Fortunately, there's the \mathring{} command, which I forgot to mention among the accents: I've mentioned the fraction command \frac{}{} before, but the related \tfrac{}{} and \dfrac{}{} are also worth pointing out: they set the font size to small and normal, respectively: "The longer I live the more I see that I am never wrong about anything, and that all the pains that I have so humbly taken to verify my notions have only wasted my time." - George Bernard Shaw Pulsar THREAD STARTER Posts: 4615 Age: 40 Country: Belgium Print view this post ### Re: A Latex Tutorial Colors MathJax allows different colors, with the command \color{color}{text} (this syntax is different from standard Latex). I don't know which colors are permitted, but all of these work, and probably more: Arrays The \begin{array}{} \end{array} environment is very useful to create content in several rows and columns. Each column can be left-, right- or center- aligned, which has to be specified with l,r,c respectively inside the brackets following \begin{array}. For example, \begin{array}{l r c} starts an array with three columns; column 1 is left-aligned, column 2 is right-aligned and column 3 is center-aligned. Columns are separated with the ampersand & symbol, and a row is ended by a linebreak \\. Two common examples are and matrices In fact, these examples are so common that Latex contains special commands for them: the first example can be written with the \begin{cases} \end{cases} environment, which also takes care of the initial left bracket (and notice that the lines are slightly closer to each other). No column format specification is needed: cases always defines two left-aligned columns. Matrices can be defined with the \begin{pmatrix} \end{pmatrix} environment, which includes the parentheses, and defines every column as center-aligned: Apart from pmatrix, there are also matrix, bmatrix, vmatrix, Bmatrix, Vmatrix, and smallmatrix. With the array environment, one can simulate multi-line text: This example also contains the \textit{} and \textbf{} commands, to write italics and bold text. Finally, the array environment can serve to create a simple table. One can add vertical lines by adding | symbols in the column format header, and horizontal lines with the \hline command inside the array. ------------------------------------------------------------------------- I think I have now covered most of the Latex formatting that is currently possible with MathJax. A full overview of Latex commands supported by MathJax can be found here: http://www.mathjax.org/docs/1.1/tex.html#supported-latex-commands If you have any comments, questions or additions, feel free to post! "The longer I live the more I see that I am never wrong about anything, and that all the pains that I have so humbly taken to verify my notions have only wasted my time." - George Bernard Shaw Pulsar THREAD STARTER Posts: 4615 Age: 40 Country: Belgium Print view this post ### Re: A Latex Tutorial Under the section ' A LATEX Tutorial, part 1 > accents' , the 'a' with vector symbol is not loading properly in Chrome. Its displayed as small box. I'm using this in one of my applications and have the same issue. So how can we fix it? This issue is seen only with Chrome browser - ver 17.0.963.83 m. OS is Win XP. Thanks, Gifcy gifcy Posts: 1 Print view this post ### Ads by Google ### Re: A Latex Tutorial gifcy wrote:Under the section ' A LATEX Tutorial, part 1 > accents' , the 'a' with vector symbol is not loading properly in Chrome. Its displayed as small box. I'm using this in one of my applications and have the same issue. So how can we fix it? This issue is seen only with Chrome browser - ver 17.0.963.83 m. OS is Win XP. Thanks, Gifcy It looks fine in my version of Chrome. Are your settings correct? If you right-click on the formula, and go to Settings -> Math Renderer, you have to set it to HTML-CSS instead of MathML. "The longer I live the more I see that I am never wrong about anything, and that all the pains that I have so humbly taken to verify my notions have only wasted my time." - George Bernard Shaw Pulsar THREAD STARTER Posts: 4615 Age: 40 Country: Belgium Print view this post ### Re: A Latex Tutorial I thought this thread was going to be about something else... Let's try for peace in 2018, shall we? orpheus Posts: 7270 Age: 53 Country: New York, USA Print view this post ### Re: A Latex Tutorial orpheus wrote:I thought this thread was going to be about something else... That might be why it has 233 views and one comment.... Wish I understood it Pulsar, sorry. The problem with fantasies is you can't really insist that everyone else believes in yours, the other problem with fantasies is that most believers of fantasies eventually get around to doing exactly that. Onyx8 Moderator Posts: 17520 Age: 61 Print view this post ### Re: A Latex Tutorial orpheus wrote:I thought this thread was going to be about something else... Same here. I thought the topic was going to be on writing code for calculations in LaTeX. SeriousCat Name: Mr Taylor Posts: 39 Age: 29 Country: New Zealand Print view this post ### Re: A Latex Tutorial Muhuhuhuhahahahahaaaaaaaaa! I saw some of the frustration on threads asking for the math tag back. So I used Thwoth's excellent suggestion and circumvented the problem, at least as far as this part of Pulsar's Latex Tutorial goes. Pulsar wrote:This thread is meant as a small Latex manual to help the Equations thread and its discussion. In its current form the MathJax editor doesn't allow every standard Latex command, so I will also explore some workarounds and tricks. To view any source code, right-click on the formula. Make sure that Settings, Math Renderer is set to HTML-CSS. Code: Select all $\textbf{A }\mathbf{\LaTeX\ }\textbf{Tutorial, part 1}$ Font styles Latex's default font in mathematical equations is a form of italics. But different styles are available; for instance, if you want a normal upright character a, type \mathrm{a} (rm stands for Roman). The most common styles are the following: Code: Select all \begin{align}\text{(default)}\hspace{1cm} & ABCDEFGHIJKLMNOPQRSTUVWXYZ\\& abcdefghijklmnopqrstuvwxyz\\\backslash\text{mathrm}\hspace{1cm} & \mathrm{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\& \mathrm{abcdefghijklmnopqrstuvwxyz}\\\backslash\text{mathbf}\hspace{1cm} & \mathbf{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\& \mathbf{abcdefghijklmnopqrstuvwxyz}\\\backslash\text{mathcal}\hspace{1cm} & \mathcal{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\\backslash\text{mathtt}\hspace{1cm} & \mathtt{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\& \mathtt{abcdefghijklmnopqrstuvwxyz}\\\backslash\text{mathbb}\hspace{1cm} & \mathbb{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\\backslash\text{boldsymbol}\hspace{1cm} & \boldsymbol{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\& \boldsymbol{abcdefghijklmnopqrstuvwxyz}\end{align} Note that you need the command \boldsymbol{} to type a bold math symbol; \mathbf{} renders a bold upright character. If you want to include normal text inside an equation, use the \text{} command. Unfortunately, MathJax doesn't seem to like Latex commands inside the \text{} environment. Spaces There are various commands for horizontal spaces: a backslash follow by a blank space, \ , inserts a normal space. For smaller spaces, use one of these \, \; \: For larger, there is \quad and \qquad . For a space of any length, there's the \hspace{} command: just insert a unit between the brackets. For instance, \hspace{1cm} will render a 1cm space. Other units are available as well, such as mm, in (inch), or pt (point). There is also a command for a tiny negative space, to place two characters closer together: \! And the \phantom{} commands provides a neat trick to insert a space with the length of the characters inside the brackets. In standard Latex, a vertical line-break can be inserted by two backslashes: \\, and a line space of any length can be achieved by e.g. \\[1cm]. Unfortunately, MathJax is more limited: I only managed to get \\ to work inside a \begin{align}\end{align} environment (see below). In standard Latex, there's also the \vspace{} command, but that doesn't seem to work either. Here are a few examples: Code: Select all \begin{align}&ab \quad a\,b \quad a\;b \quad a\: b \quad a\ b \qquad a\!b \\&a\hspace{34pt}b \qquad c\phantom{abc} d\end{align} Accents Here are a few common accents and over- and underlines: Code: Select all $a' \quad a'' \quad \dot{a} \quad \ddot{a} \quad \dddot{a} \quad \vec{a} \quad \hat{a} \quad \tilde{a} \quad \widetilde{a} \quad \bar{a} \quad \overline{a} \quad \underline{a} \quad \overbrace{a} \quad \underbrace{a}$ Sub- and superscript To add a subscript to a character, use an underscore _, or _{} if you want to add more than one subscript character. For superscript, use ^ or ^{}. If you want a standalone sub- or superscript (i.e. not preceded by a normal character), you have to precede _ or ^ by empty brackets; see the example for a hypergeometric function. Code: Select all $a_i \quad a_{ij} \quad M_\text{tot} \quad a^2 \quad a^{-3/2} \quad {}_2 F_1 \qquad {} 15^\circ 02'15''\qquad 2\times 10^{15}\;\text{km}\,\text{s}^{-2}$ Note the \circ for degrees. It's also common practice to use upright text for units, like km and s in the last example. To be continued... “Government is the Entertainment division of the military-industrial complex.” Frank Zappa chango369 Name: Chris Posts: 1178 Age: 58 Country: Dumbfuckistan Print view this post ### Re: A Latex Tutorial Pulsar's Latex Tutorial part 2 - reboot Pulsar wrote: Code: Select all $\textbf{A }\mathbf{\LaTeX\ }\textbf{Tutorial, part 2}$ Greek letters Code: Select all \begin{align}& \alpha \beta \gamma \delta \epsilon \varepsilon \zeta \eta \theta \vartheta \iota \kappa \varkappa \lambda \mu \nu \xi \omicron \pi \varpi \rho \varrho \sigma \varsigma \tau \upsilon \phi \varphi \chi \psi \omega\\& \Gamma \Delta \Theta \Lambda \Xi \Pi \Sigma \Upsilon \Phi \Psi \Omega\end{align} Miscellaneous symbols Code: Select all $\aleph \quad \hbar \quad \infty \quad \partial \quad \nabla \quad \Im \quad \Re \quad \forall \quad \exists \quad \nexists \quad \emptyset \quad \varnothing \quad \square \quad \triangle \quad \triangledown \quad \prime \quad \backprime \quad \sphericalangle$ Code: Select all $\& \quad \_ \quad \# \quad \ \quad \%$ Standard function names Code: Select all \begin{align}&\sin \quad \cos \quad \tan \quad \exp \quad \lim \quad \min \quad \max \quad \sinh \quad \arcsin \quad\\&\deg \quad \log \quad \ln \quad \sup \quad \inf \quad \arg \quad \cot \quad \det \quad \gcd \quad \mod\end{align} And various others. Binary symbols Code: Select all $\leq \quad \leqslant \quad \geq \quad \geqslant \quad \neq \quad \sim \quad \simeq \quad \approx \quad \propto \quad \cong \quad \equiv \quad \ll \quad \gg \quad \perp$ Code: Select all $\times \quad \div \quad \pm \quad \mp \quad \cdot \quad \ast \quad \star \quad \odot \quad \oplus \quad \ominus \quad \otimes \quad \Box \quad \lhd \quad \rhd$ Code: Select all $\wedge \quad \vee \quad \subset \quad \supset \quad \in \quad \ni \quad \notin \quad \cup\quad \cap \quad \setminus \quad \backslash \quad \therefore \quad \because \quad \bullet \quad \diamond$ Dots Code: Select all $1,2,\ldots,10 \qquad a_1 + a_2 + \cdots + a_n \qquad\vdots \qquad \ddots$ “Government is the Entertainment division of the military-industrial complex.” Frank Zappa chango369 Name: Chris Posts: 1178 Age: 58 Country: Dumbfuckistan Print view this post ### Re: A Latex Tutorial Pulsar's Latex Tutorial Part 3 - reboot Pulsar wrote: Code: Select all $\textbf{A }\mathbf{\LaTeX\ }\textbf{Tutorial, part 3}$ Arrows Code: Select all \begin{align}&\leftarrow \quad \longleftarrow \quad \Leftarrow \quad \Longleftarrow \quad \rightarrow \quad \longrightarrow \quad \Rightarrow \quad \Longrightarrow \quad\overleftarrow{abc} \quad \overrightarrow{abc} \\&\leftrightarrow \quad \longleftrightarrow \quad \Leftrightarrow \quad \Longleftrightarrow \quad \leftrightarrows \quad \leftleftarrows \quad \rightrightarrows \quad \uparrow \quad \Uparrow \quad \downarrow \quad \Downarrow \quad \updownarrow \quad \Updownarrow\end{align} If you want an arrow with additional text, use \xleftarrow or \xrightarrow. Be aware of the precise format: text below is placed between square brackets [] and can be omitted, while text above is placed between mandatory curly brackets {}. Code: Select all $\xrightarrow{\text{above the arrow}} \qquad \xleftarrow[\text{below}]{}\qquad \xrightarrow[\text{below}]{\text{above the arrow}}$ In combination with the \lim operator, you can write something like this: Code: Select all $\lim_{x \rightarrow +\infty} f(x) = 0$ This doesn't look very pretty, but it can be tidied up by enclosing the equation by a \displaystyle{} environment: Code: Select all $\displaystyle{\lim_{x \rightarrow +\infty} f(x) = 0}$ Various operators Again, use \displaystyle{} for nice results: Code: Select all $\displaystyle{\sum \quad \sum_{i=1}^{n} \quad \sum_{\substack{i,j \\ i > j}} \quad \prod \quad \prod_{n=0}^{\infty} \quad \coprod\quad \int \quad \int_0^1 \quad \oint \quad \iint \quad \iiint \quad \sqrt{x} \quad \sqrt[3]{26}}$ Note the \substack{} command in the third sum, to stack multiple limits. Fractions and binomials looks as follows, without and with \displaystyle{}: Code: Select all $\frac{1}{2} \quad \binom{n}{k}\qquad\displaystyle{\frac{1}{2} \quad \binom{n}{k}}$ Brackets Code: Select all $\displaystyle{() \quad [] \quad \{ \} \quad | \quad \langle \rangle \quad \lfloor \rfloor \quad \lceil \rceil \quad \Vert}$ Note the backslash in \{ and \} to produce curly brackets. The size of these delimiters can be increased manually by preceding them with \big, \Big, \bigg or \Bigg. You can also let Latex determine an appropriate size, by using \left and \right. However, every \left delimiter has to be followed by a similar \right delimiter; in case you want only one delimiter, use a dot for the other, i.e. \left. or \right. to generate an empty delimiter. See the examples: Code: Select all $\displaystyle{\Bigg( \bigg( \Big( \big( () \big) \Big) \bigg) \Bigg)\qquad \left(\frac{a}{b}\right) \qquad \left[\frac{A}{B} + \left( C + \sqrt{D}\right) \right]\qquad \left\langle\left. \psi_1 \right. \right|}$ The \underbrace{} and \overbrace{} commands produce Code: Select all $\underbrace{\underbrace{a + b}_\text{brace 1} +\overbrace{c + d}^\text{brace 2}}_\text{brace 3}= e$ “Government is the Entertainment division of the military-industrial complex.” Frank Zappa chango369 Name: Chris Posts: 1178 Age: 58 Country: Dumbfuckistan Print view this post ### Re: A Latex Tutorial Pulsar's Latex Tutorial Part 4 - reboot Pulsar wrote: Code: Select all $\textbf{A }\mathbf{\LaTeX\ }\textbf{Tutorial, part 4}$ Equations I've used the \begin{align} \end{align} environment several times already, without discussing its use: with align, you can type multiple, aligned equations. The ampersand & serves as a tab stop; usually, you want the lines to be aligned on the equation sign: Code: Select all \begin{align}\binom{5}{3} &= \frac{5!}{2!\; 3!}\\&= \frac{5\cdot 4 \cdot 3 \cdot 2}{3 \cdot 2 \cdot 2}\\&= 10\end{align} You can also align two sets of equation side by side, as follows: Code: Select all \begin{align}y & =d & z & =1\\y & =cx+d & z & =x+1 \end{align} If you want even more, use the alignat environment. It has a parameter denoting the amount of aligned columns. Here's an example with three: Code: Select all \begin{alignat}{3}i_{11} & =0.25 & i_{12} & =i_{21} & i_{13} & =i_{23}\\i_{21} & =-i_{11} & i_{22} & =0.5\,i_{12}& i_{23} & =i_{31}\\i_{31} & =0.33\,i_{22}\qquad & i_{32} & =0.15\,i_{32}\qquad & i_{33} & =i_{11}\end{alignat} Alternatively, you can centre equations rather than align them. To do this, use the gather environment. NOTE: I couldn't get the original code to generate an image. Original code: Code: Select all $\begin{gather}\displaystyle{\Gamma(x) = \int_0^{+\infty} t^{x-1} \, \text{e}^{-t} \, \text{d}t\\B(x,y) = \int_0^1 t^{x-1}\,(1-t)^{y-1}\,\text{d}t} \end{gather}$ So I switched the way the gather and displaystyle were nested with respect to one another. Code: Select all \begin{gather}\displaystyle{\Gamma(x) = \int_0^{+\infty} t^{x-1} \, \text{e}^{-t} \, \text{d}t\\B(x,y) = \int_0^1 t^{x-1}\,(1-t)^{y-1}\,\text{d}t} \end{gather} Long equations can be split with the multline environment. In the example below, you see that the \left( bracket has to be followed by a \right. (an invisible right bracket) at the end of the first line, otherwise Latex will raise an error. Likewise, the second line starts with \left. (an invisible left bracket) and ends with \right). However, to ensure that the closing \right) is as big as the opening \left( , we need another trick: the command \vphantom{} inserts an invisible vertical space, given by the text inside the brackets - analogous to the horizontal \phantom{}. On the first line, the summation \sum_{i<j} is the largest symbol, so \vphantom{\sum_{i<j}} inserts an equally large, but invisible symbol on the second line, which guarantees that \left( and \right) are of the same size. I had a similar problem with the original code. Code: Select all $\displaystyle{\begin{multline}\frac{1}{2}\Delta(f_{ij}f^{ij}) = 2\left( \sum_{i<j}\chi_{ij}(\sigma_{i} -\sigma_{j})^{2} + f^{ij}\nabla_{j}\nabla_{i} (\Delta f) + \right.\\\left. + \nabla_{k}f_{ij}\nabla^{k}f^{ij} + f^{ij}f^{k}\left[2\nabla_{i}R_{jk} -\nabla_{k}R_{ij}\right] \vphantom{\sum_{i<j}}\right)\end{multline}}$ So I reversed the nesting order of multline and displaystyle Code: Select all $\begin{multline}\displaystyle{\frac{1}{2}\Delta(f_{ij}f^{ij}) = 2\left( \sum_{i<j}\chi_{ij}(\sigma_{i} -\sigma_{j})^{2} + f^{ij}\nabla_{j}\nabla_{i} (\Delta f) + \right.\\\left. + \nabla_{k}f_{ij}\nabla^{k}f^{ij} + f^{ij}f^{k}\left[2\nabla_{i}R_{jk} -\nabla_{k}R_{ij}\right] \vphantom{\sum_{i<j}}\right)}\end{multline}$ “Government is the Entertainment division of the military-industrial complex.” Frank Zappa chango369 Name: Chris Posts: 1178 Age: 58 Country: Dumbfuckistan Print view this post ### Ads by Google ### Re: A Latex Tutorial Pulsar's Latex Tutorial Part 5 - reboot Pulsar wrote: Code: Select all $\textbf{A }\mathbf{\LaTeX\ }\textbf{Tutorial, part 5}$ Math styles Symbols can be displayed in one the following styles: \displaystyle{} (for standalone equations), \textstyle{} (for equations in a sentence), \scriptstyle{} (for e.g. sub- and superscripts), and \scriptscriptstyle{} (for e.g. subsub- and supersuperscripts). Latex scales sub- and superscripts automatically, but occasionally the explicit commands \scriptstyle{} and \scriptscriptstyle{} are handy in other situations. Code: Select all $\displaystyle{\int_0^1 f}\qquad \textstyle{\int_0^1 f} \qquad\scriptstyle{aA} \qquad \scriptscriptstyle{aA}$ Text and Symbol size The above styles define relative symbol sizes, which depend on the environment in which they are used. Latex also allows to manually change text font sizes, with the \tiny{}, \scriptsize{}, \small{}, \normalsize{}, \large{}, \Large{}, \LARGE{}, \huge{}, and \Huge{} commands. Surprisingly, MathJax also allows the use of these commands inside formulae. Code: Select all $\tiny{a}\scriptsize{a}\small{a}\normalsize{a}\large{a}\Large{a}\LARGE{a}\huge{a}\Huge{a}$ Text boxes Normal text can be written inside \text{}. Alternatively, there is the \mbox{} environment, which is almost the same as \text{}. However, unlike the \text{} command, text inside an \mbox{} does not scale when it is part of a sub- or superscript. Math symbols can be used inside a box by putting it between signs; unfortunately MathJax doesn't seem to allow any commands inside a textbox.

Code: Select all
$\mbox{this works \forall n \in \mathbb{N} \backslash \{ 0 \}, I think}$

NOTE: I'm not sure the image below is being rendered correctly!

\fbox{} is similar to \mbox, but draws a frame around the text.

Code: Select all
$f_\text{sim} \qquad f_\mbox{sim} \qquad \fbox{text inside a frame}$

A more general command to draw frames is \boxed{}, which can be used around any formula.

Code: Select all
$\boxed{\displaystyle{ f(x) = \int \frac{\sin x}{x}\,\text{d}x} }$

Unfortunately, MathJax does not support more advanced text boxes, like \makebox{} and \parbox{}. This makes it difficult to write multi-line text; possible tricks are stacking text, or using arrays (see below)

Stacking symbols and text

There are various ways to stack two lines of symbols or text on top of each other. The \substack{} command was used before, but there's also the slightly different { \atop } command.

Code: Select all
$\text{stacking }\substack{a \\ b}\qquad {a \atop b}$

The size of the symbols is automatically decreased; to change these sizes to normal, put the symbols inside \displaystyle{}. With the \underset{}{} and \overset{}{} commands, you can put smaller-sized symbols or text below/above a normal line:

A similar command is \stackrel{}{}, which puts normal-sized symbols/text on top of a normal line.

Code: Select all
$a \stackrel{\text{def}}{=} b$

\stackrel might help to define new symbols. For instance, MathJax does not support the Angstrom symbol, so we could create one as follows:

Code: Select all
$\text{an ugly }\stackrel{\scriptsize{\circ}}{\text{A}}\text{ symbol}$

This doesn't look very pretty. Fortunately, there's the \mathring{} command, which I forgot to mention among the accents:

Code: Select all
$\text{this is better: } \mathring{\text{A}}$

Code: Select all
$\text{this is better: } \dot{\text{A}}$

I've mentioned the fraction command \frac{}{} before, but the related \tfrac{}{} and \dfrac{}{} are also worth pointing out: they set the font size to small and normal, respectively:

Code: Select all
$\frac{a}{b} \qquad \tfrac{a}{b} \qquad \dfrac{a}{b} \qquad T^\frac{a}{b} \qquad T^\tfrac{a}{b} \qquad T^\dfrac{a}{b}$

Code: Select all
$\displaystyle{ \frac{a}{b} \qquad \tfrac{a}{b} \qquad \dfrac{a}{b} \qquad T^\frac{a}{b} \qquad T^\tfrac{a}{b} \qquad T^\dfrac{a}{b} }$

“Government is the Entertainment division of the military-industrial complex.”

Frank Zappa

chango369

Name: Chris
Posts: 1178
Age: 58

Country: Dumbfuckistan
Print view this post

### Re: A Latex Tutorial

Pulsar's Latex Tutorial Part 6 - reboot

Pulsar wrote:

Code: Select all
$\textbf{A }\mathbf{\LaTeX\ }\textbf{Tutorial, part 6}$

Colors

MathJax allows different colors, with the command \color{color}{text} (this syntax is different from standard Latex). I don't know which colors are permitted, but all of these work, and probably more:

Code: Select all
$\color{red}{b} \color{darkred}{b} \color{pink}{b} \color{blue}{b} \color{lightblue}{b} \color{green}{b} \color{darkgreen}{b} \color{yellow}{b} \color{orange}{b} \color{cyan}{b} \color{magenta}{b} \color{violet}{b} \color{purple}{b} \color{brown}{b} \color{white}{b} \color{grey}{b} \color{black}{b}$

NOTE: Some of colors didn't render.

Arrays

The \begin{array}{} \end{array} environment is very useful to create content in several rows and columns. Each column can be left-, right- or center- aligned, which has to be specified with l,r,c respectively inside the brackets following \begin{array}. For example, \begin{array}{l r c} starts an array with three columns; column 1 is left-aligned, column 2 is right-aligned and column 3 is center-aligned. Columns are separated with the ampersand & symbol, and a row is ended by a linebreak \\. Two common examples are

Code: Select all
$f(n) = \left\{ \begin{array}{l l} n/2 & \quad \mbox{if n is even}\\ -(n+1)/2 & \quad \mbox{if n is odd}\end{array}\right.$

and matrices

Code: Select all
$A_{m,n} = \left(\begin{array}{cccc} a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\ a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m,1} & a_{m,2} & \cdots & a_{m,n} \end{array}\right)$

In fact, these examples are so common that Latex contains special commands for them: the first example can be written with the \begin{cases} \end{cases} environment, which also takes care of the initial left bracket (and notice that the lines are slightly closer to each other). No column format specification is needed: cases always defines two left-aligned columns.

Code: Select all
$f(n) =\begin{cases} n/2 & \quad \mbox{if n is even}\\ -(n+1)/2 & \quad \mbox{if n is odd}\end{cases}$

Matrices can be defined with the \begin{pmatrix} \end{pmatrix} environment, which includes the parentheses, and defines every column as center-aligned:

Code: Select all
$A_{m,n} = \begin{pmatrix} a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\ a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m,1} & a_{m,2} & \cdots & a_{m,n} \end{pmatrix}$

Apart from pmatrix, there are also matrix, bmatrix, vmatrix, Bmatrix, Vmatrix, and smallmatrix.

Code: Select all
$\begin{matrix} a & b \\ c & d \end{matrix}\qquad \begin{bmatrix} a & b \\ c & d \end{bmatrix}\qquad \begin{vmatrix} a & b \\ c & d \end{vmatrix}\qquad \begin{Bmatrix} a & b \\ c & d \end{Bmatrix}\qquad \begin{Vmatrix} a & b \\ c & d \end{Vmatrix}\qquad \begin{smallmatrix} a & b \\ c & d \end{smallmatrix}$

With the array environment, one can simulate multi-line text:

Code: Select all
\begin{array}{r}\text{Right-aligned}\\\text{text, nothing}\\\text{really important}\end{array}\quad \textit{and} \quad \begin{array}{c}\text{Center-aligned}\\\text{text, nothing}\\\text{really important}\end{array}\quad \textbf{and} \quad \begin{array}{l}\text{Left-aligned}\\\text{text, nothing}\\\text{really important}\end{array}

This example also contains the \textit{} and \textbf{} commands, to write italics and bold text.

Finally, the array environment can serve to create a simple table. One can add vertical lines by adding | symbols in the column format header, and horizontal lines with the \hline command inside the array.

Code: Select all
$\begin{array}{|c|r|}\text{symbol} & \quad\text{value} \\\hline\pi & 3.1415 \\e & 2.7182\end{array}$

-------------------------------------------------------------------------

I think I have now covered most of the Latex formatting that is currently possible with MathJax.

A full overview of Latex commands supported by MathJax can be found here:

http://www.mathjax.org/docs/1.1/tex.html#supported-latex-commands

If you have any comments, questions or additions, feel free to post!
“Government is the Entertainment division of the military-industrial complex.”

Frank Zappa

chango369

Name: Chris
Posts: 1178
Age: 58

Country: Dumbfuckistan
Print view this post

### Re: A Latex Tutorial

What sorcery is this?

Well done indeed!
"The longer I live the more I see that I am never wrong about anything, and that all the pains that I have so humbly taken to verify my notions have only wasted my time." - George Bernard Shaw

Pulsar

Posts: 4615
Age: 40

Country: Belgium
Print view this post

### Re: A Latex Tutorial

Pulsar wrote:What sorcery is this?

Well done indeed!

Indeed. Bookmarked! : http://maru.bonyari.jp/

"And, isn't sanity really just a one-trick pony anyway? I mean all you get is one trick, rational thinking, but when you're good and crazy, oooh, oooh, oooh, the sky is the limit." - T. Tick.

Greyman

Name: Graham
Posts: 453
Age: 50

Country: Australia
Print view this post

### Re: A Latex Tutorial

chango369 wrote:Muhuhuhuhahahahahaaaaaaaaa! I saw some of the frustration on threads asking for the math tag back. So I used Thwoth's excellent suggestion and circumvented the problem, at least as far as this part of Pulsar's Latex Tutorial goes.

Pulsar wrote:This thread is meant as a small Latex manual to help the Equations thread and its discussion. In its current form the MathJax editor doesn't allow every standard Latex command, so I will also explore some workarounds and tricks.
To view any source code, right-click on the formula. Make sure that Settings, Math Renderer is set to HTML-CSS.

Code: Select all
$\textbf{A }\mathbf{\LaTeX\ }\textbf{Tutorial, part 1}$

Font styles
Latex's default font in mathematical equations is a form of italics. But different styles are available; for instance, if you want a normal upright character a, type \mathrm{a} (rm stands for Roman). The most common styles are the following:

Code: Select all
\begin{align}\text{(default)}\hspace{1cm} & ABCDEFGHIJKLMNOPQRSTUVWXYZ\\& abcdefghijklmnopqrstuvwxyz\\\backslash\text{mathrm}\hspace{1cm} & \mathrm{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\& \mathrm{abcdefghijklmnopqrstuvwxyz}\\\backslash\text{mathbf}\hspace{1cm} & \mathbf{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\& \mathbf{abcdefghijklmnopqrstuvwxyz}\\\backslash\text{mathcal}\hspace{1cm} & \mathcal{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\\backslash\text{mathtt}\hspace{1cm} & \mathtt{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\& \mathtt{abcdefghijklmnopqrstuvwxyz}\\\backslash\text{mathbb}\hspace{1cm} & \mathbb{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\\backslash\text{boldsymbol}\hspace{1cm} & \boldsymbol{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\& \boldsymbol{abcdefghijklmnopqrstuvwxyz}\end{align}

Note that you need the command \boldsymbol{} to type a bold math symbol; \mathbf{} renders a bold upright character. If you want to include normal text inside an equation, use the \text{} command. Unfortunately, MathJax doesn't seem to like Latex commands inside the \text{} environment.

Spaces

There are various commands for horizontal spaces: a backslash follow by a blank space, \ , inserts a normal space. For smaller spaces, use one of these \, \; \: For larger, there is \quad and \qquad . For a space of any length, there's the \hspace{} command: just insert a unit between the brackets.
For instance, \hspace{1cm} will render a 1cm space. Other units are available as well, such as mm, in (inch), or pt (point).

There is also a command for a tiny negative space, to place two characters closer together: \!
And the \phantom{} commands provides a neat trick to insert a space with the length of the characters inside the brackets.

In standard Latex, a vertical line-break can be inserted by two backslashes: \\, and a line space of any length can be achieved by e.g. \\[1cm]. Unfortunately, MathJax is more limited: I only managed to get \\ to work inside a \begin{align}\end{align} environment (see below). In standard Latex, there's also the \vspace{} command, but that doesn't seem to work either. Here are a few examples:

Code: Select all
\begin{align}&ab \quad a\,b \quad a\;b \quad a\: b \quad a\ b \qquad a\!b \\&a\hspace{34pt}b \qquad c\phantom{abc} d\end{align}

Accents

Here are a few common accents and over- and underlines:

Code: Select all
$a' \quad a'' \quad \dot{a} \quad \ddot{a} \quad \dddot{a} \quad \vec{a} \quad \hat{a} \quad \tilde{a} \quad \widetilde{a} \quad \bar{a} \quad \overline{a} \quad \underline{a} \quad \overbrace{a} \quad \underbrace{a}$

Sub- and superscript

To add a subscript to a character, use an underscore _, or _{} if you want to add more than one subscript character. For superscript, use ^ or ^{}. If you want a standalone sub- or superscript (i.e. not preceded by a normal character), you have to precede _ or ^ by empty brackets; see the example for a hypergeometric function.

Code: Select all
$a_i \quad a_{ij} \quad M_\text{tot} \quad a^2 \quad a^{-3/2} \quad {}_2 F_1 \qquad {} 15^\circ 02'15''\qquad 2\times 10^{15}\;\text{km}\,\text{s}^{-2}$

Note the \circ for degrees. It's also common practice to use upright text for units, like km and s in the last example.

To be continued...
“Government is the Entertainment division of the military-industrial complex.”

Frank Zappa

chango369

Name: Chris
Posts: 1178
Age: 58

Country: Dumbfuckistan
Print view this post

Next