Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.2k
Beautiful and accessible math in all browsers
License
mathjax/MathJax
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Note: MathJax code development is performed in theMathJax-src repository. This repository holds the packaged version of MathJax, along with the main issue tracker for MathJax bugs.
MathJax is an open-source JavaScript display engine for LaTeX, MathML,and AsciiMath notation that works in all modern browsers, withbuilt-in support for assistive technology like screen readers,including automatic speech generation and an expression explorer thatcan be used to investigate typeset mathematics on a more granularlevel than the complete expression. It requires no setup on the partof the user (no plugins to download or software to install), so thepage author can write web documents that include mathematics and beconfident that users will be able to view it naturally and easily.Simply include MathJax and some mathematics in a web page, and MathJaxdoes the rest.
Some of the main features of MathJax include:
High-quality display of LaTeX, MathML, and AsciiMath notation in HTML pages
Supported in most browsers with no plug-ins, extra fonts, or specialsetup for the reader
Easy for authors, flexible for publishers, extensible for developers
Supports math accessibility, cut-and-paste interoperability, and otheradvanced functionality
Powerful API for integration with other web applications
Seehttp://www.mathjax.org/ for additional details about MathJax,andhttps://docs.mathjax.org for the MathJax documentation.
MathJax uses files calledcomponents that contain thevarious MathJax modules that you can include in your web pages oraccess on a server through NodeJS. Some components combine all thepieces you need to run MathJax with one or more input formats and aparticular output format, while other components are pieces that canbe loaded on demand when needed, or by a configuration that specifiesthe pieces you want to combine in a custom way. For usageinstructions, see theMathJax documentation.
Components provide a convenient packaging of MathJax's modules, but itis possible for you to form your own custom components, or to useMathJax's modules directly in a node application on a server. Thereareweb examplesshowing how to use MathJax in web pages and how to build your owncomponents, andnodeexamples illustratinghow to use components in node applications or call MathJax modulesdirectly.
This repository contains only the component files for MathJax, not thesource code for MathJax (which are available in a separateMathJaxsource repository). Thesecomponent files are the ones served by the CDNs that offer MathJax tothe web. In version 2, the files used on the web were also the sourcefiles for MathJax, but in version 3 and above, the source files are nolonger on the CDN, as they are not what are run in the browser.
The components are ES6 format as CommonJS modules.
If you are loading MathJax from a CDN into a web page, there is noneed to install anything. Simply use ascript tag that loadsMathJax from the CDN. E.g.,
<scriptsrc="https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js"defer></script>
See theMathJaxdocumentationand theMathJax Web Demos, and theMathJaxNode Demos for moreinformation.
If you want to host MathJax from your own server, you can do so byinstalling themathjax package usingnpm and moving the contentsto an appropriate location on your server:
npm install mathjax@4mv node_modules/mathjax <path-to-server-location>/mathjaxAlternatively, you can get the files via GitHub:
git clone https://github.com/mathjax/MathJax.git mathjaxmv mathjax <path-to-server-location>/mathjaxThen (in either case) you can use a script tag like the following:
<scriptsrc="<url-to-your-site>/mathjax/tex-chtml.js"defer></script>
where<url-to-your-site> is replaced by the URL to the locationwhere you moved the MathJax files above.
See thedocumentationfor details.
To use MathJax components in a node application, install themathjaxpackage:
npm install mathjax@4
Then importmathjax within your application and initialize it:
importMathJaxfrom'mathjax';awaitMathJax.init({ ...});
where{ ... } is the MathJax configuration you want to use. E.g.,
importMathJaxfrom'mathjax';awaitMathJax.init({loader:{load:['input/tex','output/svg']}});constsvg=awaitMathJax.tex2svgPromise('\\frac{1}{x^2-1}',{display:true});console.log(MathJax.startup.adaptor.serializeXML(svg));
Alternatively, in an ES5 node application, you can use
constMathJax=require('mathjax');MathJax.init({ ...}).then(()=>{ ...});
where the first{ ... } is a MathJax configuration, and the second{ ... } is the code to run after MathJax has been loaded. E.g.
constMathJax=require('mathjax');MathJax.init({loader:{load:['input/tex','output/svg']}}).then(()=>{constsvg=MathJax.tex2svg('\\frac{1}{x^2-1}',{display:true});console.log(MathJax.startup.adaptor.serializeXML(svg));}).catch((err)=>console.log(err.message));
Note: the technique in the two examples above is for node-basedapplication only, not for browser applications. This method sets upan alternative DOM implementation, which you don't need in thebrowser, and it depends on node and the local file system in otherways. This setup will not work properly in the browser, even if youwebpack it or use some other bundler.
See thedocumentationand theMathJax NodeRepository for more details.
Since the MathJax package containsall the component files, so ifyou are only planning one use one configuration, you can reduce thesize of the MathJax directory by removing unused components. Forexample, if you are using thetex-chtml.js component, then you canremove thetex-mml-chtml.js,tex-svg.js,tex-mml-svg.js, and thefiles ending in-nofont.js, which will save considerable space.Indeed, you should be able to remove everything other thantex-chtml.js, and theinput/tex/extensions,adaptors,a11y,andsre directories. If you are using the results only on the web,you can removeadaptors as well. If you are using MathML inputrather than TeX (e.g.,mml-chtml.js rather thantex-chtml.js),then you can removeinput/tex/extensions as well.
If you are using a font other than the defaultmathjax-newcm font ina node application, then you will need to install that font as well.E.g.,
npm install @mathjax/mathjax-stix2-font@4
to install themathjax-stix2 font locally. On the web, MathJax willlook for the font and its dynamic ranges on thecdn.jsdelivr.net CDNservice, so if you want to use the font from your own server, you willneed to configure the path to the font. For example:
MathJax={loader:{paths:{'mathjax-stix2':'<url-to-your-server>/mathjax-stix2-font'}}};
to set the location for themathjax-stix2 font to a URL on your server.
The contents of this repository are generated automatically, so youshould not submit pull requests that modify this repository. If youwish to submit a modification to MathJax, you should make a pullrequest in theMathJax sourcerepository.
The main MathJax website ishttp://www.mathjax.org, and it includesannouncements and other important information. AMathJax userforum for askingquestions and getting assistance is hosted at Google, and theMathJaxbug tracker is hostedat GitHub.
Before reporting a bug, please check that it has not already beenreported. Also, please use the bug tracker (rather than the helpforum) for reporting bugs, and use the user's forum (rather than thebug tracker) for questions about how to use MathJax.
About
Beautiful and accessible math in all browsers
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.