I'm new to MkDocs and am writing some technical documentation that requires latex. I've successfully built a small website with one of the MkDocs themes, however it won't properly display the latex equations. I followed the instructions at:
http://www.vlfeat.org/matconvnet/developers/
as well as the instructions following the python-markdown-mathjax link from that page. I have also tinkered with adding appropriate lines to my mkdocs.yaml file, similar to:
https://github.com/EdyJ/vehicle-physics-docs/blob/master/mkdocs.yml
However, issuing the command 'mkdocs build' still results in a site that doesn't render the equations. I've also tried adding a -x mathjax flag with the mkdocs build command.
I've scoured the web and have been tinkering for quite a bit of time now. Can anyone shed light on what I need to do to get these two playing together?
I am no expert on any of this but the below is what worked for me. One of my needs was to have the $...$ notation work for inline Latex, instead of \(..\) because the $ notation works directly in Jupyter notebooks and you can see what your text will look like without first running mkdocs.
For both $..$ and $$..$$ styles to work, first install
pip install --upgrade python-markdown-math
. Then do the following:I will admit I am no expert and really only cared about what worked. It took me several hours to figure out what combination of things in the .yml and the mathjaxhelper.js file will get both $ and $$ to work. Hope this helps someone else.
You will need to install the extension as indicated in the github README. It sounds as if you have already done that.
Then you need to tell Mkdocs that you are using this Python Markdown extension. You would do this by having a line such as this in your mkdocs.yaml:
markdown_extensions: [mathjax]
The YAML configuration documentation can be found at:
Here is a way to get LaTeX in MkDocs with the extension arithmatex.
I'm answering again because I want to document a solution that doesn't link to third party sites like Cloudflare and Google.
I'm going the way with the theme named mkdocs-material but you can replace
theme: ...school
withtheme: readthedocs
.First install MkDocs and create a project: https://www.mkdocs.org/#installation.
Then install mkdocs-material and MathJax as follows. Say the project is called my-project. Use downloads and not pip because you want to change the CDN to Cloudflare and the link to google.
Edit
mkdocs.yml
like described under "Usage", for example:You can insert some TeX in
index.md
, build the site (mkdocs build
) and open theindex.html
to check that MathJax works. Because it doesn't work withmkdocs serve
I uploaded the MathJax folder and linking to it instead of the link to the local path.To activate TeX inline with
$...$
you have to create an extra JS-fileInsert the following text into
extra.js
:and link to it in
mkdocs.yml
. Finaly the extra_javascript section can like this:Because we don't want to use CDN you can edit
mkdocs-material/material/base.html
and delete/uncomment the line with<link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
. Font-awesome and material-icons are already on board within mkdocs-material.It looks like be that this extension is not required:
docs/mathjaxhelper.js
mkdocs.yml
Seems to do the trick.
This is actually easier than I expected. First I installed the Python-Markdown-Math Extension:
Then I created a new MkDocs project:
Next I edited the
test_math/docs/index.md
file to be as follows (sample borrowed from the MathJax documentation):Finally, I edited the
test_math/config.yaml
file to be as follows:I was unsure if this would work, but I ran the test server to see:
I then opened my browser and loaded http://127.0.0.1:8000/. The page displayed with the sample equations properly formatted:
Then I remembered that the OP asked for this to work with ReadTheDocs, so I added the following line to the config:
My browser reloaded and the following (properly formatted equations) displayed:
I should note that I'm getting some weird error about fontawesome not loading. With the MkdDocs' theme, the equations disappear after a minute (when the error appears in the browser's console). However, in the ReadTheDocs theme, the equations display properly, even with the error. Either way, I believe this error is related to some other issue on my local machine.
Finally, the Bounty is...
I don't normally advertise this, but since you asked, I am the lead developer of Python-Markdown, I work regularly with
mitya57
(the creator of Python-Markdown-Math Extension) as he is one of two other developers with commit access to Python-Markdown, and I am a contributor to MkDocs (one of those contributions being support for Python-Markdown Extensions).