Posted: Jun 27, 2015 9:05 pm
by chango369
Pulsar's Latex Tutorial Part 6 - reboot

Pulsar wrote:

Code: Select all
[latex]\textbf{A }\mathbf{\LaTeX\ }\textbf{Tutorial, part 6}[/latex]


Image

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
[latex]\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}[/latex]


NOTE: Some of colors didn't render.

Image

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
[latex]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.[/latex]


Image

and matrices

Code: Select all
[latex]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)[/latex]


Image

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
[latex]f(n) =
\begin{cases}
n/2 & \quad \mbox{if $n$ is even}\\ 
-(n+1)/2 & \quad \mbox{if $n$ is odd}
\end{cases}[/latex]


Image

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
[latex]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}[/latex]


Image

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

Code: Select all
[latex]\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}[/latex]


Image

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

Code: Select all
[latex]\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}[/latex]


Image

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
[latex]\begin{array}{|c|r|}
\text{symbol} & \quad\text{value} \\
\hline
\pi & 3.1415 \\
e & 2.7182
\end{array}[/latex]


Image

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

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!