Getting Started: Using The Mathjax Content Delivery Network (CDN)
Getting Started: Using The Mathjax Content Delivery Network (CDN)
Getting Started
MathJax allows you to include mathematics in your web pages, either using TeX and LaTeX notation, or as MathML, and you can even use both in the same document. There are two ways to access MathJax: the easiest way is to use the copy of MathJax available from our distributed network service atcdn.mathjax.org, but you can also download and install a copy of MathJax on your own server, or for use locally on your own hard disk (with no need for network access). Both of these are described below, with links to more detailed explanations. This page gives the quickest and easiest ways to get MathJax up and running on your web site, but you may want to read the details in order to customize the setup for your pages.
Currently, the Amazon Cloudfront service used by the MathJax CDN does not support the use of a human-friendly name like cdn.mathjax.org for secure connections. However, this address is stable and safe to use.
4. Put mathematics into your web pages so that MathJax can display it.
in your documents <head> block. Here, path-to-MathJax should be replaced by the URL for the main MathJax directory, so if you have put the MathJax directory at the top level of you servers web site, you could use <script type="text/javascript" src="/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script
to load MathJax in your page. For example, your page could look like <html> <head> ... <script type="text/javascript" src="/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </head> <body> ... </body> </html>
If you have installed MathJax on a server that is in a different domain from the one serving the page that loads MathJax, be sure to read the Notes About Shared Servers for more details. In that case, you may wish to consider using theMathJax CDN rather than installing your own copy of MathJax.
See the config/default.js file, or the tex2jax configuration options page, for additional configuration parameters that you can specify for the tex2jax preprocessor, which is the component of MathJax that identifies TeX notation within the page. See the TeX and LaTeX page for more on MathJaxs support for TeX. Here is a complete sample page containing TeX mathematics (also available in the test/sample-tex.html file): <!DOCTYPE html> <html> <head> <title>MathJax TeX Test Page</title> <script type="text/x-mathjax-config"> MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}}); </script> <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script> </head> <body> When $a \ne 0$, there are two solutions to \(ax^2 + bx + c = 0\) and they are $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$ </body> </html> Since the TeX notation is part of the text of the page, there are some caveats that you must keep in mind when you enter your mathematics. In particular, you need to be careful about the use of less-than signs, since those are what the browser uses to indicate the start of a tag in HTML. Putting a space on both sides of the less-than sign should be sufficient, but see TeX and LaTeX support for details. There are a number of extensions for the TeX input processor that are loaded by the TeX-AMS-MML_HTMLorMML configuration. These include: TeX/AMSmath.js, which defines the AMS math environments and macros, TeX/AMSsymbols.js, which defines the macros for the symbols in the msam10 and msbm10 fonts,
TeX/noErrors.js, which shows the original TeX code rather than an error message when there is a problem processing the TeX, and TeX/noUndefined.js, which prevents undefined macros from producing an error message, and instead shows the macro name in red. Other extensions may be loaded automatically when needed.
MathML input
For mathematics written in MathML notation, you mark your mathematics using standard <math> tags, where <mathdisplay="block"> represents displayed mathematics and <mathdisplay="inline"> or just <math> represents in-line mathematics. Note that this will work in HTML files, not just XHTML files (MathJax works with both), and that the web page need not be served with any special MIME-type. Also note that, unless you are using XHTML rather than HTML, you should not include a namespace prefix for your<math> tags; for example, you should not use <m:math> except in a file where you have tied the m namespace to the MathML DTD. Here is a complete sample page containing MathML mathematics (also available in the test/sample-mml.html file): <!DOCTYPE html> <html> <head> <title>MathJax MathML Test Page</title> <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script> </head> <body> When <math><mi>a</mi><mo>≠</mo><mn>0</mn></math>, there are two solutions to <math> <mi>a</mi><msup><mi>x</mi><mn>2</mn></msup> <mo>+</mo> <mi>b</mi><mi>x</mi> <mo>+</mo> <mi>c</mi> <mo>=</mo> <mn>0</mn> </math> and they are <math mode="display"> <mi>x</mi> <mo>=</mo> <mrow> <mfrac> <mrow> <mo>−</mo> <mi>b</mi> <mo>±</mo> <msqrt> <msup><mi>b</mi><mn>2</mn></msup> <mo>−</mo> <mn>4</mn><mi>a</mi><mi>c</mi> </msqrt> </mrow> <mrow> <mn>2</mn><mi>a</mi> </mrow> </mfrac> </mrow> <mtext>.</mtext> </math> </body> </html> When entering MathML notation in an HTML page (rather than an XHTML page), you should not use self-closing tags, but should use explicit open and close tags for all your math elements. For example, you should use <mspace width="thinmathspace"></mspace> rather than <mspace width="5pt" /> in an HTML document. If you use the self-closing form, some browsers will not build the math tree properly, and MathJax will receive a damaged math structure, which will not be rendered as the original notation would have been. Unfortunately, there is nothing MathJax can do about that, since the browser has incorrectly interpreted the tags long before MathJax has a chance to work with them.
The component of MathJax that recognizes MathML notation is called themml2jax extension, and it has only a few configuration options; see theconfig/default.js file or the mml2jax configuration options page for more details. See the MathML page for more on MathJaxs MathML support.