# MathJax

## Questions answered by this recipe

- How can I embed math in a wiki page using MathJax which is the successor of jsMath?

## Description

Embed math in wiki pages using scalable fonts.

## Notes

Disable the jsMath plugin (if you are already using it) before using the MathJax plugin below.

## Installation

- Download MathJax.phpΔ into the
`cookbook/`

directory. - Add the following line to a local customization file:

include_once("$FarmD/cookbook/MathJax.php");

You now have two options: **installing MathJax locally on your server** (the default), or **linking to a CDN**.

### Installing MathJax locally

- Download MathJax from http://www.mathjax.org/. Install the MathJax package into your PmWiki's pub/ directory, as pub/MathJax/ . Or, you can install MathJax wherever you wish, and set $MathJaxURL to the url of the MathJax directory.
- Unless backward compatibility with old browsers is a must, consider removing the
`MathJax/fonts/HTML-CSS/TeX/png`

directory since it has too many files and may slow down the server.

### Using MathJax via a CDN

If you don’t want to download and install the MathJax package locally, you can link to a CDN (content distribution network). **Before** including `MathJax.php`

in your `config.php`

, add this line:

$MathJaxUseCDN = true;

### Conditionally including the recipe

If you don't want the MathJax recipe (with all its associated JavaScript overhead) loaded for every page on your wiki, use the following code in `config.php`

, **instead of** the `include_once`

line given above:

## MathJax gets loaded if the directive (:mathjax:) is anywhere on the page. Markup('include-mathjax', 'directives', '/\\(:mathjax:\\)/i', "IncludeMathJax"); function IncludeMathJax($m) { global $FarmPubDirUrl, $FarmD, $MathJaxUrl; $MathJaxUrl = "$FarmPubDirUrl/MathJax"; include_once("$FarmD/cookbook/MathJax.php"); } # The graphic is available from # http://www.pmichaud.com/pmwiki/pub/guiedit/math.gif . SDV($GUIButtons['math'], [ 1000, '{$ ', ' $}', '\\\\sqrt{n}', '$GUIButtonDirUrlFmt/math.gif"$[Math formula (LaTeX/MimeTeX)]"' ]);

*(Note that if you have GUIEdit enabled, you must also copy the code that includes a GUIEdit button for equations into config.php—as shown in the above code snippet—or else it will never show up in the editor!)*

This way, MathJax doesn't get loaded, unless there's a `(:mathjax:)`

directive anywhere on the page. (You only need to include the directive once, no matter how many equations the page contains. Having the directive on a page multiple times does not cause any problems, though.)

## Configuration

In addition to the settings described above, the following options are available. (All must be set **before** including `MathJax.php`

in your `config.php`

.)

`$MathJaxConfigJS`

The `$MathJaxConfigJS`

variable holds the MathJax configuration block. The default value is as follows (note the single quotes around the value):

$MathJaxConfigJS = 'MathJax.Hub.Config({ extensions: [ "tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js" ], jax: [ "input/TeX", "output/HTML-CSS" ], tex2jax: { inlineMath: [ [ "{$", "$}" ] ], displayMath: [ [ "{$$", "$$}" ] ] } });';

`$MathJaxCDNURL`

The `$MathJaxCDNURL`

variable holds the URL of the MathJax distribution. (It’s used only if `$MathJaxUseCDN`

is set to `true`

; see **Using MathJax via a CDN**, above.)

The default value is:

$MathJaxCDNURL = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-MML-AM_CHTML';

## Additional MathJax settings

The MathJax settings file `MathJax/config/MathJax.js`

has many more settings to play around with, including setting the HTML tags (e.g. script, pre, etc) within which MathJax will not translate the text to mathematics. Take a look there.

## Release notes

**2019-03-28**: Added option to use MathJax from CDN instead of local install. (Thanks to Walter Keller for suggestion and code.) Said Achmiz**2019-03-27**: Fixed problem with un-quoted callback names on some systems. Said Achmiz**2019-03-04**: Updated for PHP 5 compatibility (fixed "/e modifier" errors). Said Achmiz**20101218**: Took Domingo Redal's suggestion into account, simplifying installation and MathJax upgrades.**20110307**: Support for equation`\label`

and`\eqref`

added by Richard Shaw.

## See also

- Cookbook /
- AMmathjax Add markup to embed math using ASCII MATH by MathJax. (Stable)
- ASCIIMath Display MathML rendered ascii formula into PmWiki 2.x pages (Stable)
- Formula Lightweight rendering of mathematical formulas in wiki pages (Beta)
- FractionsPlus Adds simple markup to write fractions. (Maintained)
- JsMath Add markup to display and embed mathematical formulas in wiki pages using TeX. (Obsolete - use MathJax)
- LaTeXMathJax MathJax support for PmWiki (stable)
- LaTeXMathML Translating LaTeX math notation dynamically to Presentation MathML (Stable)
- LinuxTex Enable TeX markup
- LuaExecute Lets Lua scripts dynamically generate parts of your wiki page (Beta)
- Mathtex Add markup to display and embed several lines of mathematical formulas in wiki pages (testing)
- MimeTeX Add markup to display and embed mathematical formulas in wiki pages (Stable)
- SageCell This allows you to embed an interactive SageCell into your webpage. Sage is an open source alternative to MathLab, Mathematica, and Maple. (Stable)
- SimpleJsMath Notes on modifying the jsMath for a skin (not a complete recipe)
- TrueLatex Enables interpretation and rendering of real LaTeX markups in PmWiki. Support for XeLaTex included in v1.8. (Working perfectly. Very simple to use, customizable and comes with lots of options.)

## Contributors

## Comments

See discussion at MathJax-Talk

**User notes** +2 -1: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.