# How to use MathJax Optentype fonts with XeLaTeX?

I want to use MathJax opentype text and math fonts in my document. All the following fonts can be downloaded from the MathJax GitHub page.

MathJax_AMS-Regular.otf          MathJax_SansSerif-Bold.otf
MathJax_Caligraphic-Bold.otf     MathJax_SansSerif-Italic.otf
MathJax_Caligraphic-Regular.otf  MathJax_SansSerif-Regular.otf
MathJax_Fraktur-Bold.otf         MathJax_Script-Regular.otf
MathJax_Fraktur-Regular.otf      MathJax_Size1-Regular.otf
MathJax_Main-Bold.otf            MathJax_Size2-Regular.otf
MathJax_Main-Italic.otf          MathJax_Size3-Regular.otf
MathJax_Main-Regular.otf         MathJax_Size4-Regular.otf
MathJax_Math-BoldItalic.otf      MathJax_Typewriter-Regular.otf
MathJax_Math-Italic.otf          MathJax_WinChrome-Regular.otf
MathJax_Math-Regular.otf         MathJax_WinIE6-Regular.otf


For text, I was able to get things working, but for math it is too tricky. I tried mathspec and unicode-math without success. I used XeLaTeX before with other math fonts successfully, but it doesn't work properly with this font. Some people went even farther and succeeded in compiling the MathJax fonts with pdfLaTeX and got awesome results. It will be fine for me to just make it work with XeLaTeX.

Here is my attempt with unsatisfying output:

\documentclass[a4paper,12pt]{article}

\usepackage{amsmath}
\usepackage{mathspec}

\setmainfont{MathJax_Main-Regular.otf}[
UprightFont = MathJax_Main-Regular,
ItalicFont = MathJax_Main-Italic,
BoldFont = MathJax_Main-Bold
]

\setmathrm{MathJax_Main-Regular.otf} % for sin cos ln max ..
\setmathsfont(Digits){MathJax_Main-Regular.otf}
\setmathsfont(Latin,Greek){MathJax_Math-Italic.otf}
\setboldmathrm{MathJax_Math-BoldItalic.otf}

\usepackage{bm}

\begin{document}

\section{Mathjax fonts}

\subsection{Main fonts}
Roman:  The quick brown fox jumps over the lazy dog.' 0123456789\\
Italic: \textit{The quick brown fox jumps over the lazy dog.' 0123456789}\\
Bold:   \textbf{The quick brown fox jumps over the lazy dog.' 0123456789}

\subsection{Math}
Numbers: $123,456.7890$\\
Alphabet: $abcdefghijklmnopqrstuvwxyz$ $ABCDEFGHIJKLMNOPQRSTUVWXYZ$\\
Calligraphic: $\mathcal{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$\\
Accents: $\hat f \vec f \ddot f \dot f \bar f\check f \tilde f \acute f \grave f \breve f$\\
Greek: $\alpha \beta \gamma \delta \epsilon \varepsilon \zeta \eta \theta \vartheta \iota \kappa \lambda \mu \nu \xi \pi \varpi \rho \varrho \sigma \varsigma \tau \upsilon \phi \varphi \chi \psi \omega$
$\Gamma \Delta \Theta \Lambda \Xi \Pi \Sigma \Upsilon \Phi \Psi \Omega$\\
Operators: $\cos\theta$, $\ln x$, $a \bmod n$, etc.\\
Big operators:
$f(x) = \sum_{n = -\infty}^\infty c_{n}e^{jnx}$
$c_{n} = \frac{1}{2}\int_{-\pi}^{\pi}f(x)e^{-jnx}\,\mathrm dx$
%
Bold italic: $\bm{abcdefghijklmnopqrstuvwxyz}$\\
Bold rm: $\mathbf{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$\\
Bold italic: $\bm{\alpha \beta \gamma \delta \epsilon \varepsilon \zeta \eta \theta \vartheta \iota \kappa \lambda \mu \nu \xi \pi \varpi \rho \varrho \sigma \varsigma \tau \upsilon \phi \varphi \chi \psi \omega \Gamma \Delta \Theta \Lambda \Xi \Pi \Sigma \Upsilon \Phi \Psi \Omega}$

\end{document}


• The fonts lack a MATH table. – egreg Apr 12 '19 at 10:45

The fonts lack a MATH table and the Math script.

You can use letters, but not symbols and accents, with

\documentclass{article}
\usepackage{unicode-math}

\setmainfont{MathJax_Main}[
Extension=.otf,
Path=./MathJax-otf/,
UprightFont=*-Regular,
ItalicFont=*-Italic,
BoldFont=*-Bold,
]

\setmathfont{Latin Modern Math} % base

\setmathfont{MathJax_Math-Regular}[
Extension=.otf,
Path=./MathJax-otf/,
range={
up,it,bb,bbit,scr,cal,bfcal,frak,tt,sfup,sfit,bfup,bfit,bfscr,bffrak,bfsfup,bfsfit,
},
]
\setmathfont{MathJax_Main-Regular}[
Extension=.otf,
Path=./MathJax-otf/,
range=up/num,
]

\begin{document}

Numbers: $123,456.7890$\\
Alphabet: $abcdefghijklmnopqrstuvwxyz$ $ABCDEFGHIJKLMNOPQRSTUVWXYZ$\\
Calligraphic: $\mathcal{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$\\
Accents: $\hat{a} \vec{a} \ddot{a} \dot{a} \bar{a}\check{a} \tilde{a} \acute{a} \grave{a} \breve{a}$\\
Greek: $\alpha \beta \gamma \delta \epsilon \varepsilon \zeta \eta \theta \vartheta \iota \kappa \lambda \mu \nu \xi \pi \varpi \rho \varrho \sigma \varsigma \tau \upsilon \phi \varphi \chi \psi \omega$
$\Gamma \Delta \Theta \Lambda \Xi \Pi \Sigma \Upsilon \Phi \Psi \Omega$\\
Operators: $\cos\theta$, $\ln x$, $a \bmod n$, etc.\\
Big operators:
$f(x) = \sum_{n = -\infty}^\infty c_{n}e^{jnx}$
$c_{n} = \frac{1}{2}\int_{-\pi}^{\pi}f(x)e^{-jnx}\,\mathrm dx$
%
Bold italic: $\symbfit{abcdefghijklmnopqrstuvwxyz}$\\
Bold rm: $\mathbf{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$\\
Bold italic: $\symbfit{\alpha \beta \gamma \delta \epsilon \varepsilon \zeta \eta \theta \vartheta \iota \kappa \lambda \mu \nu \xi \pi \varpi \rho \varrho \sigma \varsigma \tau \upsilon \phi \varphi \chi \psi \omega \Gamma \Delta \Theta \Lambda \Xi \Pi \Sigma \Upsilon \Phi \Psi \Omega}$

\showoutput
\end{document}


If you examine the log file, you'll discover that the symbols and the accents are from Latin Modern Math, but all letters are from MathJax_Math-Regular.

• Thanks @egreg, your answer inspired me and I was able to define several \setmathfont`s to cover almost all the available glyphs in the font. And yes, I knew that the fonts don't have a proper MATH table, very few fonts do actually. – AboAmmar Apr 12 '19 at 23:01
• @AboAmmar On the other hand, the fonts seem very akin to Latin Modern. – egreg Apr 12 '19 at 23:04
• Yes, but the main problem with Latin Modern is that they are too lite in print, otherwise, I'd use them without thinking! – AboAmmar Apr 12 '19 at 23:15