A Latex Tutorial

Anything that doesn't fit anywhere else below.

Moderators: Calilasseia, ADParker

A Latex Tutorial

#1  Postby Pulsar » Feb 15, 2012 9:38 pm

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.

[math]

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:

[math]

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:

[math]

Accents

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

[math]

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.

[math]

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
User avatar
Pulsar
THREAD STARTER
 
Posts: 4615
Age: 40
Male

Country: Belgium
Belgium (be)
Print view this post

Ads by Google


Re: A Latex Tutorial

#2  Postby Pulsar » Feb 15, 2012 10:36 pm

[math]

Greek letters

[math]

Miscellaneous symbols

[math]

[math]

Standard function names

[math]

And various others.

Binary symbols

[math]

[math]

[math]

Dots
[math]
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
User avatar
Pulsar
THREAD STARTER
 
Posts: 4615
Age: 40
Male

Country: Belgium
Belgium (be)
Print view this post

Re: A Latex Tutorial

#3  Postby Pulsar » Feb 16, 2012 12:14 am

[math]

Arrows

[math]

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 {}.

[math]

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

[math]

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

[math]

Various operators

Again, use \displaystyle{} for nice results:

[math]

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

[math]

Brackets

[math]

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:

[math]

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

[math]
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
User avatar
Pulsar
THREAD STARTER
 
Posts: 4615
Age: 40
Male

Country: Belgium
Belgium (be)
Print view this post

Re: A Latex Tutorial

#4  Postby Pulsar » Feb 16, 2012 3:28 am

[math]

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:

[math]

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

[math]

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:

[math]

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

[math]

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.

[math]
"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
User avatar
Pulsar
THREAD STARTER
 
Posts: 4615
Age: 40
Male

Country: Belgium
Belgium (be)
Print view this post

Re: A Latex Tutorial

#5  Postby Pulsar » Feb 20, 2012 4:59 am

[math]

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.

[math]

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.

[math]

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.

[math]

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

[math]

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

[math]

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.

[math]

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:

[math]

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

[math]

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

[math]

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

[math]

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:

[math]

[math]
"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
User avatar
Pulsar
THREAD STARTER
 
Posts: 4615
Age: 40
Male

Country: Belgium
Belgium (be)
Print view this post

Re: A Latex Tutorial

#6  Postby Pulsar » Feb 20, 2012 7:00 am

[math]

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:

[math]

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

[math]

and matrices

[math]

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.

[math]

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

[math]

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

[math]

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

[math]

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.

[math]

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

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
User avatar
Pulsar
THREAD STARTER
 
Posts: 4615
Age: 40
Male

Country: Belgium
Belgium (be)
Print view this post

Re: A Latex Tutorial

#7  Postby gifcy » Apr 02, 2012 6:54 am

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

#8  Postby Pulsar » Apr 02, 2012 6:53 pm

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
User avatar
Pulsar
THREAD STARTER
 
Posts: 4615
Age: 40
Male

Country: Belgium
Belgium (be)
Print view this post

Re: A Latex Tutorial

#9  Postby orpheus » Apr 02, 2012 8:06 pm

I thought this thread was going to be about something else...

:shifty:
Let's try for peace in 2017, shall we?
User avatar
orpheus
 
Posts: 7270
Age: 53
Male

Country: New York, USA
United States (us)
Print view this post

Re: A Latex Tutorial

#10  Postby Onyx8 » Apr 03, 2012 1:42 am

orpheus wrote:I thought this thread was going to be about something else...

:shifty:



That might be why it has 233 views and one comment.... 8-)

Wish I understood it Pulsar, sorry. :thumbup:
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.
User avatar
Onyx8
Moderator
 
Posts: 17520
Age: 61
Male

Canada (ca)
Print view this post

Re: A Latex Tutorial

#11  Postby SeriousCat » May 26, 2012 8:45 am

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.
User avatar
SeriousCat
 
Name: Mr Taylor
Posts: 39
Age: 28
Male

Country: New Zealand
United Kingdom (uk)
Print view this post

Re: A Latex Tutorial

#12  Postby chango369 » Jun 27, 2015 7:08 pm

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
[latex]\textbf{A }\mathbf{\LaTeX\ }\textbf{Tutorial, part 1}[/latex]


Image

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


Image

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


Image

Accents

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

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


Image

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


Image

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
User avatar
chango369
 
Name: Chris
Posts: 1175
Age: 58
Male

Country: Dumbfuckistan
Cuba (cu)
Print view this post

Re: A Latex Tutorial

#13  Postby chango369 » Jun 27, 2015 7:24 pm

Pulsar's Latex Tutorial part 2 - reboot

Pulsar wrote:

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


Image

Greek letters

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


Image

Miscellaneous symbols

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


Image

Code: Select all
[latex]\& \quad \_ \quad \#  \quad \$ \quad  \%[/latex]


Image

Standard function names

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


Image

And various others.

Binary symbols

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


Image

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


Image

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


Image

Dots

Code: Select all
[latex]1,2,\ldots,10 \qquad
a_1 + a_2 + \cdots + a_n \qquad
\vdots \qquad \ddots[/latex]


Image

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

Frank Zappa
User avatar
chango369
 
Name: Chris
Posts: 1175
Age: 58
Male

Country: Dumbfuckistan
Cuba (cu)
Print view this post

Re: A Latex Tutorial

#14  Postby chango369 » Jun 27, 2015 7:39 pm

Pulsar's Latex Tutorial Part 3 - reboot


Pulsar wrote:

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


Image

Arrows

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


Image

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
[latex]\xrightarrow{\text{above the arrow}} \qquad
\xleftarrow[\text{below}]{}\qquad
\xrightarrow[\text{below}]{\text{above the arrow}}[/latex]


Image

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

Code: Select all
[latex]\lim_{x \rightarrow +\infty} f(x) = 0[/latex]


Image

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

Code: Select all
[latex]\displaystyle{
\lim_{x \rightarrow +\infty} f(x) = 0}[/latex]


Image

Various operators

Again, use \displaystyle{} for nice results:

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


Image

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
[latex]\frac{1}{2} \quad \binom{n}{k}
\qquad
\displaystyle{\frac{1}{2} \quad \binom{n}{k}}[/latex]


Image

Brackets

Code: Select all
[latex]\displaystyle{
() \quad [] \quad \{ \} \quad | \quad \langle \rangle \quad \lfloor \rfloor \quad \lceil \rceil \quad \Vert
}[/latex]


Image

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


Image

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

Code: Select all
[latex]\underbrace{\underbrace{a + b}_\text{brace 1} +\overbrace{c + d}^\text{brace 2}}_\text{brace 3}= e[/latex]


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

Frank Zappa
User avatar
chango369
 
Name: Chris
Posts: 1175
Age: 58
Male

Country: Dumbfuckistan
Cuba (cu)
Print view this post

Re: A Latex Tutorial

#15  Postby chango369 » Jun 27, 2015 8:06 pm

Pulsar's Latex Tutorial Part 4 - reboot

Pulsar wrote:

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


Image

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


Image

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

Code: Select all
[latex]\begin{align}
y & =d & z & =1\\
y & =cx+d & z & =x+1
\end{align}[/latex]


Image

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


Image

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


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}


Image

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


So I reversed the nesting order of multline and displaystyle

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



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

Frank Zappa
User avatar
chango369
 
Name: Chris
Posts: 1175
Age: 58
Male

Country: Dumbfuckistan
Cuba (cu)
Print view this post

Ads by Google


Re: A Latex Tutorial

#16  Postby chango369 » Jun 27, 2015 8:46 pm

Pulsar's Latex Tutorial Part 5 - reboot

Pulsar wrote:

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


Image

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
[latex]\displaystyle{\int_0^1 f}\qquad \textstyle{\int_0^1 f} \qquad
\scriptstyle{aA} \qquad \scriptscriptstyle{aA}[/latex]


Image

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
[latex]\tiny{a}\scriptsize{a}\small{a}\normalsize{a}\large{a}\Large{a}\LARGE{a}\huge{a}\Huge{a}[/latex]


Image

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
[latex]\mbox{this works $\forall n \in \mathbb{N} \backslash \{ 0 \}$, I think}[/latex]


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

Image

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

Code: Select all
[latex]f_\text{sim} \qquad f_\mbox{sim} \qquad \fbox{text inside a frame}[/latex]


Image

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

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


Image

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
[latex]\text{stacking }\substack{a \\ b}\qquad {a \atop b}[/latex]


Image

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:

[math]


Image

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

Code: Select all
[latex]a \stackrel{\text{def}}{=} b[/latex]


Image

\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
[latex]\text{an ugly }\stackrel{\scriptsize{\circ}}{\text{A}}\text{ symbol}[/latex]


Image

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

Code: Select all
[latex]\text{this is better: } $\mathring{\text{A}}$[/latex]


Image

NOTE: Adding in \dot example

Code: Select all
[latex]\text{this is better: } \dot{\text{A}}[/latex]


Image

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


Image

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


Image

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

Frank Zappa
User avatar
chango369
 
Name: Chris
Posts: 1175
Age: 58
Male

Country: Dumbfuckistan
Cuba (cu)
Print view this post

Re: A Latex Tutorial

#17  Postby chango369 » Jun 27, 2015 9:05 pm

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!
“Government is the Entertainment division of the military-industrial complex.”

Frank Zappa
User avatar
chango369
 
Name: Chris
Posts: 1175
Age: 58
Male

Country: Dumbfuckistan
Cuba (cu)
Print view this post

Re: A Latex Tutorial

#18  Postby Pulsar » Jun 29, 2015 9:42 am

What sorcery is this? :shock:

Well done indeed! :cheers:
"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
User avatar
Pulsar
THREAD STARTER
 
Posts: 4615
Age: 40
Male

Country: Belgium
Belgium (be)
Print view this post

Re: A Latex Tutorial

#19  Postby Greyman » Jun 29, 2015 10:33 am

Pulsar wrote:What sorcery is this? :shock:

Well done indeed! :cheers:

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

Image
"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.
User avatar
Greyman
 
Name: Graham
Posts: 441
Age: 49

Country: Australia
Australia (au)
Print view this post

Re: A Latex Tutorial

#20  Postby chango369 » Aug 16, 2015 1:50 am

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
[latex]\textbf{A }\mathbf{\LaTeX\ }\textbf{Tutorial, part 1}[/latex]


Image

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


Image

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


Image

Accents

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

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


Image

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


Image

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
User avatar
chango369
 
Name: Chris
Posts: 1175
Age: 58
Male

Country: Dumbfuckistan
Cuba (cu)
Print view this post

Next

Return to General Science & Technology

Who is online

Users viewing this topic: No registered users and 1 guest