Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure mathjax for iPython notebooks?

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.

like image 612
Black Milk Avatar asked Mar 07 '15 00:03

Black Milk


People also ask

How do you add mathematical formulas to a Jupyter Notebook?

To insert in-line math use the $ symbol within a Markdown cell. For example, the text $this_{is}^{inline}$ will produce: t h i s i s i n l i n e .

How do I use LaTeX code in Jupyter Notebook?

One of the most popular is Jupyter Notebook that uses MathJax to render the Latex syntax inside the markdown/HTML. To use LaTeX in the Jupyter notebook, put the Latex math content inside the '$ … $' double '$$ … $$' symbols.

How do I open a DB file in Jupyter Notebook?

Start Jupyter by running the command jupyter notebook. You should see browser open up and load the homepage for Jupyter. Under Files tab, go to New -> Python Notebook (default or conda root), which will open a new notebook. To connect to your database and fetch some data, run the following sample script.

How do you write Mu in Jupyter Notebook?

If you want to typeset (short) formulas like μ, you should use the inline-math mode, i.e. This is an example text containing the greek letter $\mu$.


1 Answers

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 edit mathjaxutils.js. It does nothing. Finaly I saw this post https://github.com/jupyter/help/issues/109. I realize Jupyter uses main.min.js to read MathJax configuration. So here is the solutions:

  • Download MathJax(https://github.com/mathjax/MathJax) from Github.
  • Unzip the MathJax file and go into the folder
    • copy jax/output/HTML-CSS/fonts/TeX into directoy ../notebook/static/components/MathJax/jax/output/HTML-CSS/fonts/
    • copy fonts/HTML-CSS/TeX into ../notebook/static/components/MathJax/fonts/HTML-CSS/
  • open ../notebook/static/notebook/js/main.min.js, search for availableFonts. It should be around line 14894. Change it to

    ...
    availableFonts: ["STIX-Web","TeX"],
    imageFont: null;
    preferredFont: "TeX",
    webFont: "TeX"
    ...
    
  • Refresh the notebook.
like image 152
Stefan Shi Avatar answered Oct 07 '22 16:10

Stefan Shi