18 Add Mathematical Notation

Pressbooks

Pressbooks offers two different methods for rendering mathematical equations in your books: via a native MathJax integration and through the WP QuickLaTeX plugin. 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 renders math expressions with MathJax in the webbook and creates accessible image versions of equations and other mathematical markup for its EPUB and PDF exports.

Display LaTeX with MathJax

NOTE: MathJax is not available on Pressbooks.pub. All books published on Pressbooks.pub have the WP QuickLaTeX plugin enabled by default.

There are two ways to use LaTeX syntax in MathJax:

Shortcode syntax: 
[la​tex]e^{i \pi} + 1 = 0[/lat​ex]

Dollar sign syntax: 
$latex e^{i \pi} + 1 = 0$

You can click the LaTeX button in the visual editor to input LaTeX directly or 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.

Display AsciiMath with MathJax

MathJax is capable of rendering AsciiMath, an client-side markeup language for mathematics. There are two ways to use AsciiMath syntax in MathJax:

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.

Display MathML with MathJax

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>
Learn more about MathML from the W3C’s documentation page.

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.

MathJax settings menu from webbook

Render LaTeX with WP QuickLaTeX

WP QuickLaTeX is a plugin that allows you to write native LaTeX syntax directly into your books without wrapping shortcodes around every part of every equation.

Note: WP QuickLaTeX is the default mathematics rendering option for Pressbooks.com users and can be used as an optional replacement for MathJax within individual books on other networks.

 

To enable the WP QuickLaTeX plugin:

  1. Click ‘Plugins’ from left-hand menu of your screen
  2. Click ‘Activate‘ for WP QuickLaTeX

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:

  1. Use the [la​tex] shortcode. A sample expression would look like this: [la​tex]x^2 + y^2 = z^3[/lat​ex].
  2. Add a [latexpage] shortcode to the top of your chapter. 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:

Example of QuickLaTeX

There are a few places in your book where you should not use [latex][/latex] shortcodes:

  • Shortcode elements generally cannot be nested within other shortcodes. [latex][/latex] shortcodes can be used inside of  and shortcodes, but [asciimath][/asciimath] and [latex][/latex] shortcodes cannot be nested inside of other shortcode elements. If you're trying to render LaTeX inside of an 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:

  1. Activate the H5P plugin
  2. Download H5P's mathematics library to your device
  3. Click H5P Content > Libraries from the left sidebar menu
  4. Click Choose File and select the H5P mathematics library file you downloaded in step 2.
  5. Click Upload

Learn more about using Mathematical expressions in H5P activities from their documentation.

Use Math in TablePress

You can use MathML or LaTeX to create equations and formulas in the tables you make in TablePress. To render MathML, write your markup directly into the table cells in TablePress as you would in the text editor.

To render LaTeX expressions in TablePress tables, activate the WP QuickLaTeX plugin and enable the "Use LaTeX Syntax Sitewide" setting (available under Settings -> QuickLaTeX -> Advanced). Once you've enabled this setting, you can use any supported QuickLaTeX syntax to create your equation within the table's cells. All content can be edited from within the TablePress interface.

License

Icon for the Creative Commons Attribution 4.0 International License

Add Mathematical Notation Copyright © by Pressbooks is licensed under a Creative Commons Attribution 4.0 International License, except where otherwise noted.

Share This Book