Math Typesetting: LaTeX

LaTeX is a powerful typesetting markup language that is mainly used for representing math expressions in our Pressbooks OERs. Pressbooks supports the use of LaTeX and even includes a button in the Visual Editor toolbar to automatically insert LaTeX shortcode tags ([latex] and [/latex]) around selected text (it is the button that looks like a calculator, located on the bottom row second from the end). LaTeX code appears like this in Pressbooks:

[latex]\begin{align*}\left(\frac{a_i^{n-i}}{2}\right)\$1,000\left[\frac{1-\frac{1}{\left\{1+\left(\frac{0.08}{2}\right)\right\}^{16}}}{\left(\frac{0.08}{2}\right)}\right]\times\overset{\rightarrow}{\Delta y}\end{align*}[/latex]

. . . which, when rendered in the preview or in a live book, produces this:

[latex]\begin{align*}\left(\frac{a_i^{n-i}}{2}\right)\$1,000\left[\frac{1-\frac{1}{\left\{1+\left(\frac{0.08}{2}\right)\right\}^{16}}}{\left(\frac{0.08}{2}\right)}\right]\times\overset{\rightarrow}{\Delta y}\end{align*}[/latex]

The table below shows some of the more common LaTeX symbols. Remember that LaTeX must be enclosed by the shortcode tags [latex] and [/latex] to be rendered by Pressbooks.

Common LaTeX Symbols. Source: “Standard Practices and Workarounds” from BCcampus Open Education Publishing Style Guide by BCcampus OER Production Team, CC-BY 4.0.
Symbol Name LaTeX
[latex]\times[/latex] Multiplication \times
[latex]\div[/latex] Division \div
[latex]x^2[/latex] Superscript x^2
[latex]=[/latex] Equals =
[latex]+[/latex] Plus +
[latex]-[/latex] Minus -
[latex]\%[/latex] Percent \%
[latex]:[/latex] ratio :
[latex]\text{metres}[/latex] Text \text{metres}
[latex]\frac{1}{2}[/latex] Fractions \frac{1}{2}
[latex]\longrightarrow[/latex] Long Right Arrow \longrightarrow
[latex]\cancel{41}[/latex] Strike through a number or word \cancel{41}
[latex]\$[/latex] Dollar sign \$
[latex]1\hspace{0.50cm}2[/latex] Space (variable width) 1\hspace{0.50cm}2
[latex]1\;2[/latex] Space (em) 1\;2

A list of resources for learning how to use LaTeX can be found at the end of this page, as this subject is too broad to cover in depth here. However, before implementing any LaTeX yourself, please become familiar with the known issues and best practices detailed below.

Should I Be Using LaTeX for Expressions?

Not necessarily. If the numbers, symbols, and letters needed for an equation are available on a standard keyboard and can be entered in a clear manner, then LaTeX is not required. Instead, LaTeX can be reserved for complex formulas and equations, including fractions.

Best Practices and Known Issues

Some issues have been encountered when exporting Pressbooks containing LaTeX to Print PDF format.

Use of Colour in LaTeX

The PDF parser will not process the [rgb] colour codes. It only plays well with the semantic (eg. “\color{red}”) colour code. Here is the valid syntax for colour code (note the placement of the curly braces):

{\color{colourName}{text to be colourized}}

LaTeX containing colour codes (even the valid ones) needs to start with a LaTeX element or ‘{‘ (for example, expressions starting with \text or \begin, or {2+3} will display properly in PDF exports, but an expression starting with -42 will not).

For repairing colourized LaTeX that will not parse, there is a software tool available: Pressbooks PDF Latex Fixer. Note that you may still have the edit the results obtained from this tool in cases involving especially complex LaTeX (expressions with nested arrays, for examples) and that this tool focuses on resolving colour issues, and may not fix all of the problems with your LaTeX code.

Avoid using editors that automatically generate LaTeX code when you need to include colours.

Line Breaks at the End of Expressions

Line-breaks (\\) directly before \end tags or closing [/latex] shortcode tags sometimes do NOT parse — for example:

[latex]\begin{align*}x+2&=3\\x&=3-2\\x&=1\\\end{align*}[/latex]

 Note that line breaks are unnecessary in this position and can have no effect on the generated output, and so should be avoided.

Excess Space

Excess spaces in LaTeX sometimes cause it NOT to parse in PDF exports. This appears to be especially true around certain formatting symbols. For example the following will not display properly in PDF export:

[latex]\begin{eqnarray*} x \times 5 & = & 15 \end{eqnarray*}[/latex]

Spaces are usually not required between elements in LaTeX expressions, with the exception that raw values (with no leading backslash) must be separated from the end of a preceding LaTeX element by a space or by using curly braces. For example, here is the above expression properly formatted:

[latex]\begin{eqnarray*}x\times 5&=&15\end{eqnarray*}[/latex]

LaTeX in Captions

LaTeX in captions will NOT parse in PDF exports. For example:

 

Shows a triangle with the values I, P, r, and t arranged in their relationship.
Figure 1. [latex]I=Prt[/latex]

Leading/Trailing Spaces in Text Elements

Leading or trailing spaces inside \text or \mbox elements will NOT parse in PDF exports. For example:

[latex]\text{hello! }42\text{ hello!}[/latex]

Spacing before or after text elements should be achieved by using the \; LaTeX space element:

[latex]\text{hello!}\;42\;\text{hello!}[/latex]

Math in H5P

Download the Math Display Library and add to H5P

Mathematical expressions in H5Ps | H5P

LaTeX Resources

Here is a list of resources about LaTeX. Note when consulting these materials that in Pressbooks you do not perform the steps for setting up a LaTeX document. Moreover, the use of the LaTeX shortcode tags automatically creates a math environment (no need to use dollar signs or brackets to open and close math mode).


Should LaTeX be used for all expressions, including simple ones?” from Pressbooks Guide by OER Production Team is licensed under a Creative Commons Attribution 4.0 International License, except where otherwise noted.

License

Icon for the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License

Fanshawe OER Training Guide Copyright © 2024 by Fanshawe College is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License, except where otherwise noted.

Share This Book