Use the Editor
Add Mathematical Notation
Pressbooks offers two different methods for rendering mathematical equations and scientific notation in your books: via a native MathJax integration and through the WP QuickLaTeX plugin. MathJax is highly accessible and sufficiently capable for most users. WP QuickLaTeX allows authors to display more complex math and science notation but comes with some drawbacks.
Display Math with MathJax
MathJax is an open source JavaScript display engine that translates mathematical markup into accessible equations on the web. Pressbooks features a native integration with MathJax that uses MathJax to render LaTeX expressions, AsciiMath and MathML input in the webbook and creates accessible image versions of these expressions in EPUB and PDF exports.
Use LaTeX Syntax
There are four ways to use LaTeX syntax with our native MathJax solution:
Shortcode syntax:
[latex]e^{i \pi} + 1 = 0[/latex]
Inline math delimiter:
\( e^{i \pi} + 1 = 0 \)
Display math delimiter (centers math on its own line):
\[ e^{i \pi} + 1 = 0 \]
Dollar sign syntax (centers math on its own line):
$$ e^{i \pi} + 1 = 0 $$
There are two ways to add LaTeX:
- You can use the Insert LaTeX button in the visual editor. This will add LaTeX with the shortcode syntax.
- You can add the syntax delimiters to an expression manually.
Note that equations will not display fully formatted in the editor. However, you can view the webbook or export your files at any time to see how the equations appear. Learn more about LaTeX from their documentation.
Our default solution includes support for the following LaTeX packages:
Package | Name | Description | Example Code | Rendered SVG |
---|---|---|---|---|
ams | Advanced Math Support | Provides support for multi-line equations, matrices, and special functions. | \[ |
\[ \begin{align} a &= b + c \\ x &= y – z \end{align} \] |
bbox | Boxed Expressions | Allows you to box expressions for emphasis. | \[ \bbox[red]{E = mc^2} \] |
\[ \bbox[red]{E = mc^2} \] |
boldsymbol | Bold Symbols in Math | Enables bold math symbols. | \[ \boldsymbol{F} = m \boldsymbol{a} \] |
\[ \boldsymbol{F} = m \boldsymbol{a} \] |
braket | Quantum Mechanics Notation | Enables Dirac bra-ket notation for quantum mechanics. | \[ \bra{\psi} H \ket{\psi} \] |
\[ \bra{\psi} H \ket{\psi} \] |
cancel | Canceling Terms in Equations | Allows terms to be crossed out in simplifications. | \[ x + \cancel{y} = x \] |
\[ x + \cancel{y} = x \] |
color | Colored Text & Math | Allows color formatting in equations. | \[ \textcolor{blue}{E} = mc^2 \] |
\[ \textcolor{blue}{E} = mc^2 \] |
mhchem | Complex Nested Chemistry | Allows rendering of chemical equations. | \[ \ce{SO4^2- + Ba^2+ -> BaSO4 v} \] |
\[ \ce{SO4^2- + Ba^2+ -> BaSO4 v} \] |
physics | Physics Symbols & Commands | Provides shortcuts for physics notation. | \[ \dv[2]{x}{t} = a \] |
\[ \dv[2]{x}{t} = a \] |
unicode | Unicode Math Support | Supports various Unicode symbols inside MathJax. | \[ \forall x \in \mathbb{R}, \exists y \] |
\[ \forall x \in \mathbb{R}, \exists y \] |
If there are additional LaTeX packages that are important to your project, please let us know by filing a ticket in our GitHub repo.
Use AsciiMath Syntax
The native Pressbooks solution is also capable of rendering AsciiMath, a client-side markup language for mathematics. There are two ways to use AsciiMath syntax with the built-in Pressbooks MathJax renderer:
Shortcode syntax:
[asciimath]e^{i \pi} + 1 = 0[/asciimath]
Dollar sign syntax:
$asciimath e^{i \pi} + 1 = 0$
AsciiMath can be drafted directly in the visual editor. Learn more about AsciiMath from their website.
Use MathML Syntax
MathML is an XML-based mathematical markup language. To render MathML with MathJax, input the relevant expression using the Text Editor:
Example:
<math><mrow><mrow><msup> <mi>x</mi> <mn>2</mn> </msup> <mo>+</mo><mrow><mn>4</mn><mo></mo><mi>x</mi></mrow><mo>+</mo><mn>4</mn></mrow><mo>=</mo><mn>0</mn></mrow></math>
Configure MathJax Settings
Click Settings > MathJax to access your MathJax settings page. If you do not see a MathJax settings option, this usually means that your book is using the WP QuickLaTeX plugin.
The MathJax settings page provides examples of support syntax and allows you to to change the text color of all equations in your book and select the font used when generating images for use in EPUB and PDF exports.
Use MathJax’s Accessibility Features
Within the webbook, readers can right click any equation rendered in MathJax to access additional display options and accessibility features. Options include the ability to magnify any equation on click or hover, the ability to display the math in HTML, SVG, and other formats, and more. Learn more about MathJax’s accessibility features from their documentation.
Render LaTeX with WP QuickLaTeX
WP QuickLaTeX is a plugin that can be activated as an optional replacement for Pressbooks’ native LaTeX/MathJax rendering solution. When active, this plugin replaces the native solution described previously in this guide chapter. WP QuickLaTeX provides authors with additional options for customizing their LaTeX preamble and defining packages, but generates images for all detected LaTeX expressions, in both the webbook and export files. If WP QuickLaTeX is activated in your book, MathJax will not be used to render expressions anywhere.
To enable the WP QuickLaTeX plugin:
- Click Plugins from left-hand menu of your book’s dashboard
- Click Activate in the WP QuickLaTeX section
If you do not see this option, please contact your Network Manager.
Once WP QuickLaTeX has been activated for your book, there are two recommended methods for rendering LaTeX expressions:
[latex]
shortcode
A sample expression would look like this: [latex]x^2 + y^2 = z^3[/latex]
.
[latexpage]
shortcode
Adding [latexpage]
to the top of a chapter will ensure that everything written in LaTeX syntax will be rendered by WP QuickLaTeX without additional LaTeX syntax delimiters. For example, if you were to input the following:
[latexpage] At first, we sample $f(x)$ in the $N$ ($N$ is odd) equidistant points around $x^*$: \[ f_k = f(x_k),\: x_k = x^*+kh,\: k=-\frac{N-1}{2},\dots,\frac{N-1}{2} \] where $h$ is some step. Then we interpolate points $\{(x_k,f_k)\}$ by polynomial \begin{equation} \label{eq:poly} P_{N-1}(x)=\sum_{j=0}^{N-1}{a_jx^j} \end{equation} Its coefficients $\{a_j\}$ are found as a solution of system of linear equations: \begin{equation} \label{eq:sys} \left\{ P_{N-1}(x_k) = f_k\right\},\quad k=-\frac{N-1}{2},\dots,\frac{N-1}{2} \end{equation} Here are references to existing equations: (\ref{eq:poly}), (\ref{eq:sys}). Here is reference to non-existing equation (\ref{eq:unknown}).
WP QuickLaTeX would render something which looks like this:
⚠️ There are a few places in your book where you should not uselatex
shortcodes:
- Shortcode elements generally cannot be nested within other shortcodes.
[latex]
shortcodes can be used inside of[footnote]
and[blockquote]
shortcodes as well as glossary terms. But[asciimath]
and[latex]
shortcodes cannot be nested inside of other shortcode elements. If you’re trying to render LaTeX inside of a shortcode which does not permit nested shortcodes, we recommend using the non-shortcode based syntax delimiters. - Titles. Equations won’t look good inside of a title because the style of the math will override the style of the heading. The code used to create the equation may also display in the table of contents.
- Running content. Similar to titles, the code used to create the equation may display in the running content.
Configure WP QuickLaTeX’s Settings
To customize the settings for WP QuickLaTeX, click Settings > QuickLaTeX from the left-hand menu of your book’s dashboard.
QuickLaTeX provides both Basic Settings and Advanced settings through different tabs in their settings page. Learn more about using WP QuickLaTeX from its documention.
Render LaTeX in H5P Activities
You can render LaTeX inside of H5P activities you’ve created in Pressbooks, but you’ll first need to add the mathematics library to your book’s H5P libraries page. To do this:
- Activate the H5P plugin.
- Download H5P’s mathematics library to your device.
- Click H5P Content > Libraries from the left sidebar menu in your book’s dashboard.
- Click Choose File and select the H5P mathematics library file you downloaded in step 2.
- Click Upload.
Learn more about using Mathematical expressions in H5P activities from their documentation.
Use Math in TablePress
With our native solution, you can use LaTeX or MathML to create equations and formulas in the tables you make in TablePress. To render LaTeX expressions, use any of the supported delimiters listed above, writing them directly into the table cells in TablePress as you would in the text editor. Likewise, to render MathML, write your markup directly into the table cells.
If you have chosen to enable WP QuickLaTeX in your book, any supported QuickLaTeX syntax can also be used in table cells in TablePress.