1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396

.. _installation:
******************************
Installing and Testing MathJax
******************************
The easiest way to use MathJax is to link directly to the MathJax
distributed network service (see :ref:`Using the MathJax CDN
<mathjaxCDN>`). In that case, there is no need to install MathJax
yourself, and you can begin using MathJax right away; skip this document on
installation and go directly to :ref:`Configuring MathJax <loading>`.
MathJax can be loaded from a public web server or privately from your
hard drive or other local media. To use MathJax in either way, you
will need to obtain a copy of MathJax. There are three ways to do
this: via ``git``, ``svn``, or via a prepackaged archive. We
recommend ``git`` or ``svn``, as it is easier to keep your
installation up to date with these tools.
.. _gettingmathjaxzip:
Obtaining MathJax via an archive
================================
Release versions of MathJax are available in archive files from the
`MathJax GitHub page <https://github.com/mathjax/mathjax/>`_ (via the
"zip" button, or the "downloads" tab), where you can download the archive
that you need.
**Current Version**: `MathJax2.7 <https://github.com/mathjax/MathJax/archive/2.7.2.zip>`_ (33.0MB)
Consult the :ref:`change log <whatsnew2.7>` for what’s new in version 2.7.
For previous versions, see the `release page on GitHub <https://github.com/mathjax/MathJax/releases>`_ or for quick access
 `MathJax2.6 <https://github.com/mathjax/MathJax/archive/v2.6latest.zip>`_ (34.3MB)
 `MathJax2.5 <https://github.com/mathjax/MathJax/archive/v2.5latest.zip>`_ (33.0MB)
 `MathJax2.4 <https://github.com/mathjax/MathJax/archive/v2.4latest.zip>`_ (32.6MB)
 `MathJax2.3 <https://github.com/mathjax/MathJax/archive/v2.3latest.zip>`_ (32.9MB)
 `MathJax2.2 <https://github.com/mathjax/MathJax/archive/v2.2latest.zip>`_ (17.0MB)
 `MathJax2.1 <https://github.com/mathjax/MathJax/archive/v2.1latest.zip>`_ (17.1MB)
 `MathJax2.0 <https://github.com/mathjax/MathJax/archive/v2.0latest.zip>`_ (17.6MB)
 `MathJax1.1a <https://github.com/mathjax/MathJax/archive/v1.1a.zip>`_ (15.4MB)
 `MathJax1.1 <https://github.com/mathjax/MathJax/archive/v1.1.zip>`_ (16.4MB)
 ``MathJax v1.0.1a``
 To install MathJax v1.0.1a, you must download two files: `MathJaxv1.0.1a.zip <https://www.mathjax.org/1.0/MathJaxv1.0.1a.zip>`__ and `MathJaxFontUpdate.zip <https://www.mathjax.org/1.0/MathJaxFontUpdate.zip>`__. First install the `MathJaxv1.01a.zip` distribution. Then replace the ``MathJax/fonts/HTMLCSS/TeX/otf`` directory in the resulting MathJax installation with the `otf` directory contained in the ``MathJaxFontUpdate.zip`` archive.
You should download the archive of the branch corresponding to the version
you need then simply unzip it.
Once the MathJax directory is unpacked, you should move it to the
desired location on your server (or your hard disk, if you are using
it locally rather then through a web server). One natural location is
to put it at the top level of your web server's hierarchy. That would
let you refer to the main MathJax file as ``/MathJax/MathJax.js`` from
within any page on your server.
From the `MathJax GitHub download link
<https://github.com/mathjax/mathjax/downloads>`_, you can also select
the ``Download .tar.gz`` or ``Download .zip`` buttons to get a copy of
the current development version of MathJax that contains all the
latest changes and bugfixes.
If a packaged release receives any important updates, then those
updates will be part of the `branch` for that version. The link to
the ``.zip`` file in the download list will be the original release
version, not the patched version. To obtain the patched version, use
the `Branches` drop down menu (at the far left of the menus within the
page) to select the release branch that you want (for example
``v2.1latest``), and then use the "zip" button just above it to get
the latest patched version of that release.
.. _gettingmathjaxgit:
Obtaining MathJax via Git
=========================
The easiest way to get MathJax and keep it up to date is to use the `Git
<http://gitscm.com/>`_ version control system to access our `GitHub repository
<https://github.com/mathjax/MathJax>`_. Use the command
.. codeblock:: sh
git clone https://github.com/mathjax/MathJax.git MathJax
to obtain and set up a copy of MathJax. (Note that there is no longer
a ``fonts.zip`` file, as there was in v1.0, and that the ``fonts``
directory is now part of the repository itself.)
Whenever you want to update MathJax, you can now use
.. codeblock:: sh
cd MathJax
git remote show origin
to check if there are updates to MathJax (this will print several
lines of data, but the last line should tell you if your copy is up to
date or out of date). If MathJax needs updating, use
.. codeblock:: sh
cd MathJax
git pull origin
to update your copy of MathJax to the current release version. If you
keep MathJax updated in this way, you will be sure that you have the
latest bug fixes and new features as they become available.
This gets you the current development copy of MathJax, which is the version
that contains all the latest changes to MathJax. Although we try to make
sure this version is a stable and usable version of MathJax, it is under
active development, and at times it may be less stable than the "release"
version. If you prefer to use the most stable version (that may not
include all the latest patches and features), you will want to get one
of the tagged releases. Use
.. codeblock:: sh
cd MathJax
git tag l
to see all tagged versions, and use
.. codeblock:: sh
cd MathJax
git checkout <tag_name>
to checkout the indicated version of MathJax, where ``<tag_name>`` is
the name of the tagged version you want to use. When you want to
upgrade to a new release, you will need to repeat this for the latest
release tag.
Each of the main releases also has a branch in which critical updates
are applied (we try hard not to patch the stable releases, but sometimes
there is a crucial change that needs to be made). If you want to use the
patched version of a release, then check out the branch rather than the
tag. Use
.. codeblock:: sh
cd MathJax
git branch
to get a list of the available branches. There are separate branches
for the main releases, but with ``latest`` appended. These contain
all the patches for that particular release. You can check out one of
the branches just as you would a tagged copy. For example, the branch
for the ``v2.1`` tagged release is ``v2.1latest``. To get this
release, use
.. codeblock:: sh
cd MathJax
git checkout v2.1latest
and to update it when changes occur, use
.. codeblock:: sh
cd MathJax
git pull origin v2.1latest
.. _gettingmathjaxsvn:
Obtaining MathJax via SVN
=========================
If you are more comfortable with the `subversion
<http://subversion.apache.org/>`_ source control system, you may want
to use GitHub's ``svn`` service to obtain MathJax. If you want to get the
latest revision using ``svn``, use the command
.. codeblock:: sh
svn checkout http://github.com/mathjax/MathJax/trunk MathJax
to obtain and set up a copy of MathJax. (Note that there is no longer
a ``fonts.zip`` file as of v1.1, and that the ``fonts`` directory is
now part of the repository itself.)
Whenever you want to update MathJax, you can now use
.. codeblock:: sh
cd MathJax
svn status u
to check if there are updates to MathJax. If MathJax needs updating,
use
.. codeblock:: sh
cd MathJax
svn update
to update your copy of MathJax to the current release version. If you
keep MathJax updated in this way, you will be sure that you have the
latest bug fixes and new features as they become available.
This gets you the current development copy of MathJax, which is the version
that contains all the latest changes to MathJax. Although we try to make
sure this version is a stable and usable version of MathJax, it is under
active development, and at times it may be less stable than the "release"
version. If you prefer to use one of the tagged releases instead,
then use
.. codeblock:: sh
svn checkout https://github.com/mathjax/MathJax/branches/[name] MathJax
where ``[name]`` is replaced by the name of the branch you want to
check out; e.g., ``2.1latest``. The branch names can be found on the
`GitHub MathJax page <https://github.com/mathjax/MathJax/>`_ under the
`branches <https://github.com/mathjax/MathJax/branches>`_ tab.
Obtaining MathJax via npm
=========================
Starting with version 2.6, it is possible to use `npm
<http://npmjs.com/>`_ to install MathJax. Assuming ``npm`` is installed
on your system, just execute the following command:
.. codeblock:: sh
npm install mathjax
.. note::
The distribution on ``npm`` does not contain the PNG fonts
Obtaining MathJax via Composer
==============================
Starting with version 2.5, it is possible to use `Composer
<http://getcomposer.org//>`_ to install MathJax. See the `Composer
documentation <https://getcomposer.org/doc/00intro.md>`_ to get started.
Obtaining MathJax via Bower
===========================
Starting with version 2.3, it is possible to use `Bower
<http://bower.io/>`_ to install MathJax. Assuming Bower is installed
on your system, just execute the following command:
.. codeblock:: sh
bower install MathJax
For a slim copy without PNG fonts use
.. codeblock:: sh
bower install components/MathJax
Testing your installation
=========================
Use the HTML files in the ``test`` directory to see if your
installation is working properly::
test/
index.html # Tests default configuration
indeximages.html # Tests imagefont fallback display
sample.html # Sample page with lots of pretty equations
examples.html # Page with links to all sample pages
Open these files in your browser to see that they appear to be working
properly. If you have installed MathJax on a server, use the web
address for those files rather than opening them locally. When you
view the ``index.html`` file, you should see (after a few moments) a
message that MathJax appears to be working. If not, you should check
that the files have been transferred to the server completely, and that
the permissions allow the server to access the files and folders that
are part of the MathJax directory (be sure to verify the MathJax
folder's permissions as well). Checking the server logs may help
locate problems with the installation.
.. _crossdomainlinking:
Notes about shared installations
================================
Typically, you want to have MathJax installed on the same server as
your web pages that use MathJax. There are times, however, when that
may be impractical, or when you want to use a MathJax installation at
a different site. For example, a departmental server at
``www.math.yourcollege.edu`` might like to use a collegewide
installation at ``www.yourcollege.edu`` rather than installing a
separate copy on the departmental machine. MathJax can certainly
be loaded from another server, but there is one important caveat 
Firefox's and IE9's sameorigin security policy for crossdomain scripting.
Firefox's interpretation of the sameorigin policy is more strict than most
other browsers, and it affects how fonts are loaded with the `@fontface`
CSS directive. MathJax uses this directive to load webbased math fonts
into a page when the user doesn't have them installed locally on their own
computer. Firefox's security policy, however, only allows this when the
fonts come from the same server as the web page itself, so if you load
MathJax (and hence its web fonts) from a different server, Firefox won't be
able to access those web fonts. In this case, MathJax will pause while
waiting for the font to download (which will never happen); it will time
out after about 5 seconds and switch to image fonts as a fallback.
Similarly, IE9 has a similar sameorigin policy in its `IE9 standards
mode`, so it exhibits this same behavior.
There is a solution to this, however, if you manage the server where
MathJax is installed, and if that server is running the `Apache web
server <http://www.apache.org/>`_. In the remote server's
``MathJax/fonts/`` folder, create a file called
``.htaccess`` that contains the following lines:
::
<FilesMatch "\.(ttfotfeotwoff)$">
<IfModule mod_headers.c>
Header set AccessControlAllowOrigin "*"
</IfModule>
</FilesMatch>
and make sure the permissions allow the server to read this file. (The
file's name starts with a period, which causes it to be an "invisible" file
on unixbased operating systems. Some systems, particularly those with
graphical user interfaces, may not allow you to create such files, so you
might need to use the commandline interface to accomplish this.)
This file should make it possible for pages at other sites to load MathJax
from this server in such a way that Firefox and IE9 will be able to
download the webbased fonts. If you want to restrict the sites that can
access the web fonts, change the ``AccessControlAllowOrigin`` line to
something like::
Header set AccessControlAllowOrigin "http://www.math.yourcollege.edu"
so that only pages at ``www.math.yourcollege.edu`` will be able to
download the fonts from this site. See the open font library
discussion of `webfont linking
<http://openfontlibrary.org/wiki/Web_Font_linking_and_CrossOrigin_Resource_Sharing>`_
for more details.
.. _fflocalfonts:
Firefox and local fonts
=======================
Firefox's sameorigin security policy affects its ability to load
webbased fonts, as described above. This has implications not only
to crossdomain loading of MathJax, but also to using MathJax locally
from your hard disk. Firefox's interpretation of the sameorigin
policy for local files is that the "same domain" for a page is the
directory where that page exists, or any of its subdirectories. So if
you use MathJax in a page with a ``file://`` URL, and if MathJax is
loaded from a directory other than the one containing the original
page, then MathJax will not be able to access the webbased fonts in
Firefox. In that case, MathJax will fall back on image fonts to
display the mathematics.
In order for Firefox to be able to load the fonts properly for a local
file, your MathJax installation must be in a subdirectory of the one
containing the page that uses MathJax. This is an unfortunate
restriction, but it is a limitiation imposed by Firefox's security
model that MathJax can not circumvent. Currently, this is not a
problem for other browsers.
One solution to this problem is to install the MathJax fonts locally, so
that Firefox will not have to use webbased fonts in the first place. To
do that, either install the `STIX fonts <http://stixfonts.org>`_, or copy
the fonts from ``MathJax/fonts/HTMLCSS/TeX/otf`` into your systems fonts
directory and restart your browser.
.. _ie9localfontssolution:
IE9 and remote fonts
====================
IE9's sameorigin policy affects its ability to load webbased fonts, as
described above. This has implications not ony to crossdomain loading of
MathJax, but also to the case where you view a local page (with a
``file://`` URL) that accesses MathJax from a remote site such as the MathJax
CDN service. In this case, IE9 does **not** honor the
``AccessControlAllowOrigin`` setting of the remote server (as it would
if the web page came from an ``http://`` URL), and so it **never** allows the
font to be accessed.
One solution to this problem is to install the MathJax fonts locally so
that MathJax doesn't have to use webbased fonts in the first place. Your
best bet is to install the `STIX fonts`_ on your system (see the `MathJax
fonts help page <fontsupport>`_ for details).
