.. _loading:
*******************************
Loading and Configuring MathJax
*******************************
You load MathJax into a web page by including its main JavaScript file
into the page. That is done via a ``
where ``path-to-MathJax`` is replaced by the URL of the MathJax
directory on your server, or (if you are using MathJax locally rather
than through a server) the location of that directory on your hard
disk. For example, if the MathJax directory is at the top level of
your web server's directory hierarchy, you might use
.. code-block:: html
to load MathJax.
Although it is possible to load MathJax from a site other than your
own web server, there are issues involved in doing so that you need to
take into consideration. See the :ref:`Notes About Shared Servers
` for more details. Please do **not** link to
the copy of MathJax at ``www.mathjax.org``, as we do not have the
resources to act as a web service for all the sites on the web that
would like to display mathematics. If you are able to run MathJax
from your own server, please do so (this will probably give you better
response time in any case).
It is best to load MathJax in the document's ```` block, but it
is also possible to load MathJax into the ```` section, if
needed. If you do this, load it as early as possible, as
MathJax will begin to load its components as soon as it is included in
the page, and that will help speed up the processing of the
mathematics on your page. MathJax does expect there to be a
```` section to the document, however, so be sure there is one
if you are loading MathJax in the ````.
It is also possible to load MathJax dynamically after the page has
been prepared, for example, via a `GreaseMonkey
`_ script, or using a specially prepared
`bookmarklet `_. This is an
advanced topic, however; see :ref:`Loading MathJax Dynamically
` for more details.
Configuring MathJax
===================
There are several ways to configure MathJax, but the easiest is to use
the ``config/MathJax.js`` file that comes with MathJax. See the
comments in that file, or the :ref:`configuration details
` section, for explanations of the meanings of the various
configuration options. You can edit the ``config/MathJax.js`` file to
change any of the settings that you want to customize. When you
include MathJax in your page via
.. code-block:: html
it will load ``config/MathJax.js`` automatically as one of its
first actions.
Alternatively, you can configure MathJax efficiently by calling
:meth:`MathJax.Hub.Config()` when you include MathJax in your page, as
follows:
.. code-block:: html
This example includes the ``tex2jax`` preprocessor and configures it
to use both the standard TeX and LaTeX math delimiters. It uses the
TeX input processor and the HTML-CSS output processor, and forces the
HTML-CSS processor to use the TeX fonts rather that other locally
installed fonts (e.g., :term:`STIX` fonts). See the
:ref:`configuration options ` section (or the comments
in the ``config/MathJax.js`` file) for more information about the
configuration options that you can include in the
:meth:`MathJax.Hub.Config()` call. Note that if you configure MathJax
using this in-line approach, the ``config/MathJax.js`` file is **not**
loaded.
Finally, if you would like to use several different configuration
files (like ``config/MathJax.js``, but with different settings in each
one), you can copy ``config/MathJax.js`` to ``config/MathJax-2.js``,
or some other convenient name, and use
.. code-block:: html
to load the alternative configuration file ``config/MathJax-2.js``
from the MathJax ``config`` directory. In this way, you can have as
many distinct configuration files as you need.
.. _common-configurations:
Common Configurations
=====================
The following examples show configurations that are useful for some
common situations. This is certainly not an exhaustive list, and
there are variations possible for any of them. Again, the comments in
the ``config/MathJax.js`` file can help you decide what settings to
include, even if you are using the in-line configuration method.
The TeX setup
-------------
This example calls the ``tex2jax`` preprocessor to identify
mathematics in the page by looking for TeX and LaTeX math delimiters.
It uses ``$...$`` and ``\(...\)`` for in-line mathematics, while
``$$...$$`` and ``\[...\]`` mark displayed equations. Because dollar
signs are used to mark mathematics, if you want to produce an actual
dollar sign in your document, you must "escape" it using a slash:
``\$``. This configuration also loads the ``AMSmath`` and
``AMSsymbols`` extensions so that the macros and environments they
provide are defined for use on the page.
.. code-block:: javascript
MathJax.Hub.config({
extensions: ["tex2jax.js","TeX/AMSmath.js","TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
tex2jax: {
inlineMath: [['$','$'],["\\(","\\)"]],
processEscapes: true,
},
});
Other extensions that you may consider adding to the `extensions`
array include: ``TeX/noErrors.js``, which shows the original TeX code
if an error occurs while processing the mathematics (rather than an
error message), ``TeX/noUndefined.js``, which shows undefined
macros names in red (rather than producing an error), and
``TeX/autobold.js``, which automatically inserts ``\boldsymbol{...}``
around your mathematics when it appears in a section of your page that
is in bold. Most of the other TeX extensions are loaded automatically
when needed, and so do not need to be included explicitly in your
`extensions` array.
See the :ref:`tex2jax configuration ` section for
other configuration options for the ``tex2jax`` preprocessor, and the
:ref:`TeX input jax configuration ` section for options
that control the TeX input processor.
The MathML setup
----------------
This example calls the ``mml2jax`` preprocessor to identify
mathematics in the page that is in :term:`MathML` format, which uses
``