Last active
February 13, 2023 12:59
-
-
Save newville/8c1759a295e93fef984f to your computer and use it in GitHub Desktop.
rendering Angstrom Symbol with Mathjax and sphinx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MathJax doesn't directly support the Angstrom symbol, TeX's \AA. This is painful in many | |
fields, notably those that work with X-rays. | |
To use mathjax with the Sphinx documentation system, one would put | |
extensions = ['sphinx.ext.mathjax', ...] | |
in conf.py. But this will not understand \AA as the Angstrom symbol. | |
The solution is to add a Mathjax configuration script to each HTML file produced by sphinx. | |
To do this, put the following code in _templates/layout.html: | |
{% extends "default/layout.html" %} | |
{%- block extrahead %} | |
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ | |
"TeX": {Macros: {AA : "{\\unicode{x212B}}"}}, "HTML-CSS": {scale: 90}}); | |
</script> | |
{% endblock %} | |
This will tell mathjax to use the unicode (version 6.0? ISO Latin?) symbol for Angstrom. |
If I put this code into the docstring for my .py file prior to the first use of \AA, MathJax now has Å in the HTML output:
Did you mean that we should write in conf.py the following snippet?
extensions = [ 'sphinx.ext.mathjax', ...]
rst_prolog = u"""\
.. only:: html
:math:`\\require{mediawiki-texvc}`
"""
I tried it, but the
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@briantoby Hm, this trick still works for me for HTML docs build on my own machine. I sort of gave up trying to build tex/pdf from sphinx. But I guess I have not tried this with a simple test case and RTD.