## A Latex Tutorial

Anything that doesn't fit anywhere else below.

Moderators: kiore, The_Metatron, Blip

### Re: A Latex Tutorial

chango369 wrote: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: 1868
Age: 63

Country: думфукистан
Print view this post

### Re: A Latex Tutorial

chango369 wrote: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: 1868
Age: 63

Country: думфукистан
Print view this post

### Re: A Latex Tutorial

chango369 wrote: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{split}\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{split}$

NOTE TO PULSAR: I had to replace multline with split in order to get the effect I think you were looking for.

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

Frank Zappa

chango369

Name: Chris
Posts: 1868
Age: 63

Country: думфукистан
Print view this post

### Re: A Latex Tutorial

chango369 wrote: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}$

NOTE TO PULSAR: I had a problem with the \textstyle that was part of your original code, so I took it out

Code: Select all
$\displaystyle{\int_0^1 f}\qquad {\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:

Code: Select all
$a = \underset{below}{base}\qquad \overset{above}{base} = b$

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: 1868
Age: 63

Country: думфукистан
Print view this post

### Re: A Latex Tutorial

chango369 wrote: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 ( NO THEY DON'T ), 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}$

[img]http://latex.numberempire.com/render?A_%7Bm%2Cn%7D%20%3D%20%5Cbegin%7Bpmatrix%7D%20%20a_%7B1%2C1%7D%20%26%20a_%7B1%2C2%7D%20%26%20%5Ccdots%20%26%20a_%7B1%2Cn%7D%20%5C%5C%20%20a_%7B2%2C1%7D%20%26%20a_%7B2%2C2%7D%20%26%20%5Ccdots%20%26%20a_%7B2%2Cn%7D%20%5C%5C%20%20%5Cvdots%20%20%26%20%5Cvdots%20%20%26%20%5Cddots%20%26%20%5Cvdots%20%20%5C%5C%20%20a_%7Bm%2C1%7D%20%26%20a_%7Bm%2C2%7D%20%26%20%5Ccdots%20%26%20a_%7Bm%2Cn%7D%20%5Cend%7Bpmatrix%7D&sig=a25bb9b35dfe77e3a6cb1f2113be1fc0/img]

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: 1868
Age: 63

Country: думфукистан
Print view this post

### Re: A Latex Tutorial

Damn, I thought this was going to be about getting into a gimp suit. Imagine my disappointment.
A man who carries a cat by the tail learns something he can learn in no other way. - Mark Twain
The sky is falling! The sky is falling! - Chicken Little
I never go without my dinner. No one ever does, except vegetarians and people like that - Oscar Wilde

laklak
RS Donator

Name: Florida Man
Posts: 20878
Age: 68

Country: The Great Satan
Print view this post

### Re: A Latex Tutorial

Surely you know how to do that already, lak?
How extremely stupid not to have thought of that - T.H. Huxley

Evolving

Name: Serafina Pekkala
Posts: 12241

Country: Luxembourg
Print view this post

### Re: A Latex Tutorial

I visited my late ex yesterday evening, in the concrete below the basement.
How extremely stupid not to have thought of that - T.H. Huxley

Evolving

Name: Serafina Pekkala
Posts: 12241

Country: Luxembourg
Print view this post

### Re: A Latex Tutorial

X marks the spot, Jim lad, aargh.
A man who carries a cat by the tail learns something he can learn in no other way. - Mark Twain
The sky is falling! The sky is falling! - Chicken Little
I never go without my dinner. No one ever does, except vegetarians and people like that - Oscar Wilde

laklak
RS Donator

Name: Florida Man
Posts: 20878
Age: 68

Country: The Great Satan
Print view this post

### Re: A Latex Tutorial

It is good tutorial
Andycraydoll

Name: Benedict Camberpruff
Posts: 4

Country: Unated States
Print view this post

### Re: A Latex Tutorial

Does it not work anymore? Oh well. You can still use the CodeCogs equation editor.

Azaghal
Banned Sockpuppet

Posts: 157

Print view this post

### Re: A Latex Tutorial

That's very cool: thank you for the recommendation!

Only thing: it doesn't seem to want to let me move to the next line. This was supposed to be two formulae on separate lines:

CodeCogsEqn.gif (444 Bytes) Viewed 87 times

But obviously I can save a separate GIF for each line.

It's a great improvement on not being able to use Latex at all!
How extremely stupid not to have thought of that - T.H. Huxley

Evolving

Name: Serafina Pekkala
Posts: 12241

Country: Luxembourg
Print view this post

### Re: A Latex Tutorial

How extremely stupid not to have thought of that - T.H. Huxley

Evolving

Name: Serafina Pekkala
Posts: 12241

Country: Luxembourg
Print view this post

### Re: A Latex Tutorial

Evolving wrote:That's very cool: thank you for the recommendation!

Only thing: it doesn't seem to want to let me move to the next line. This was supposed to be two formulae on separate lines:

CodeCogsEqn.gif

But obviously I can save a separate GIF for each line.

It's a great improvement on not being able to use Latex at all!

I've used MathJaX for my math / logic puzzle blog and have used it to show an equation getting solved step-by-step on a number of occasions. You can set it up on Blogger pretty easily and screenshot posts then get rid of them or whatever. It's janky but it works.

A more complete solution is described here but it requires installing the TeX / LaTeX suite on your system:

https://tex.stackexchange.com/questions ... s-possible

Azaghal
Banned Sockpuppet

Posts: 157

Print view this post

Previous