MkDocs and MathJax

后端 未结 5 1358
粉色の甜心
粉色の甜心 2020-12-25 13:54

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

5条回答
  •  孤独总比滥情好
    2020-12-25 14:22

    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:

    1. Put a text file called mathjaxhelper.js in the /docs folder, and it should contain only the following:
    
    MathJax.Hub.Config({
      config: ["MMLorHTML.js"],
      jax: ["input/TeX", "output/HTML-CSS", "output/NativeMML"],
      extensions: ["MathMenu.js", "MathZoom.js"]
    });
    
    
    1. The project.yml file should contain the following. (replace project.yml with your actual yml file)
    
    markdown_extensions:
        - extra
        - tables
        - mdx_math:
            enable_dollar_delimiter: True
        - fenced_code
    theme: readthedocs
    extra_javascript: 
        - https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS-MML_HTMLorMML
    
    

    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.

提交回复
热议问题