How can I configure Sphinx to use dollar signs as a math delimiter with the MathJax extension?
I tried adding
mathjax_config = {
'tex2jax': {
'inlineMath': [ ['$','$']],
'displayMath': [ ['$$','$$']],
},
}
to conf.py
, but that has two issues:
$\\sin(x)$
. It seems Sphinx strips single backslashes. ..math
directive on the page somewhere, it doesn't load the MathJax Javascript. I want to exclusively use $
and $$
to delimit math.I've written a Sphinx extension that lets you do this https://www.sympy.org/sphinx-math-dollar/
To use it, install the extension
pip install sphinx-math-dollar
and add it to your conf.py
extensions = ['sphinx_math_dollar', 'sphinx.ext.mathjax']
As a technical note, trying to do this correctly without using this extension will be quite difficult. You have to do the replacement at just the right place in the Sphinx processing. If you do it too late in the processing (e.g., by setting the JavaScript config), it won't work because Sphinx will have already stripped all backslashes from the math at that point. If you do it too soon (e.g., by doing a regex replacement on the input text), it will also fail because you will end up replacing math in things that you don't want to, for instance, in doctests or in code.