I'm trying to find a way for mathjax to not use STIX fonts for math in my iPython notebook. Instead, I'd much rather have it use the 'TeX' fonts. According to the documentation for Mathjax I should use:
MathJax.Hub.Config({
"HTML-CSS": {
preferredFont: "TeX"
}
});
That being said, I'm not sure where to put this. I've already tried putting this chunk of code into my custom.js file pertaining to my own ipython profile, but it doesn't work. Ideally, I'd like to make ipython profile specific adjustments for mathjax.
I've tweaked @Stefan Shi's answer to something a little easier, at least if you have the command-line
svn
installed.Put the following into a script file called
install_tex_fonts
(install_tex_fonts.bat
in Windows-land):Move the script file into
{PYTHON}/Lib/site-packages/notebook/static/components/MathJax
where{PYTHON}
is the root directory where you installed Pythoninstall_tex_fonts
(or./install_tex_fonts
on *nix systems; I guess you also have tochmod a+x
it)Add the following section in your
~/.jupyter/custom/custom.js
file (the$([IPython.events]).on('app_initialized.NotebookApp')
line should already be there):A simple test to make sure that you're getting the configuration correct is to change
preferredFont: "TeX"
toscale: 200
. Then save and reload a notebook. The math should be obviously way bigger than before. So assuming that worked, it means yourconfig.js
is doing what it needs to.Now, more to the point, try adding another line so that your configuration looks like
Don't forget to fully refresh the notebook page after you've saved that. This overrides (what I'm guessing is) the default value of that
availableFonts
variable, which would allow STIX if mathjax can't find TeX. I'm not sure why it seems to ignore the preferred font, but this seems more like a mathjax issue than an ipython issue.So now, if it still isn't in TeX font (which mathjax seems to call
MathJax_Math-Italic.otf
, or similar), I would guess that mathjax just can't find that font, and may have fallen back on something else. If that is the case, there's something messed up about your mathjax installation.Take a look at some of the numericalmooc lessons such as this one where the MathJax configuration is included through a
css
file which is imported at some point in the notebook.I recently had the exact problem. I really don't like the default
STIX-Web
font to render equation. After experimenting for a little while, I found a way to change the MathJax font in Jupyter Notebook. My Jupyter Notebook version is 4.3.1 and it is shipped with Anaconda. I assume the solutions for other versions should be similar.I tried to edit
custom.js
both in/notebook/static/custom/custom.js
and~/.jupyter/custom/custom.js
. Doesn't work. I also tried to editmathjaxutils.js
. It does nothing. Finaly I saw this post https://github.com/jupyter/help/issues/109. I realize Jupyter usesmain.min.js
to readMathJax
configuration. So here is the solutions:MathJax
(https://github.com/mathjax/MathJax) fromGithub
.MathJax
file and go into the folderjax/output/HTML-CSS/fonts/TeX
into directoy../notebook/static/components/MathJax/jax/output/HTML-CSS/fonts/
fonts/HTML-CSS/TeX
into../notebook/static/components/MathJax/fonts/HTML-CSS/
open
../notebook/static/notebook/js/main.min.js
, search foravailableFonts
. It should be around line 14894. Change it toJupyter ships with its own (smaller) version of MathJax. This is why it is not able to find the (Computer Modern) 'TeX' font -- there only is the STIX font.
To fix this, I was able to do the following:
jax
directory.jax
directory with the copied one:~/anaconda3/lib/python3.7/site-packages/notebook/static/components/MathJax/jax
~/anaconda3/envs/<ENVIRONMENT>/lib/python3.7/site-packages/notebook/static/components/MathJax/jax
(Adjust python version in path if yours is not 3.7)