A nice way to incorporate macros for use in math mode with MathJax should be available in the next version of Sphinx thanks to this pull request through the use The Sphinx options for MathJax configuration (Master) has already been updated
Given a mathCmds.tex
command in the same folder as conf.py
, adding the following lines to conf.py
should make the macros in mathCmds.tex
available in any document
import re
mathjax_config = {'Tex':{'Macros':{}}} # Create empty
with open('mathCmds.tex', 'r') as f:
for line in f:
macros = re.findall(r'\\newcommand{\\(.*?)}(\[(\d)\])?{(.+)}', line)
for macro in macros:
if len(macro[1]) == 0:
mathjax_config['Tex']['Macros'][macro[0]] = "{"+macro[3]+"}"
else:
mathjax_config['Tex']['Macros'][macro[0]] = ["{"+macro[3]+"}", int(macro[2])]
- Add support for optional arguments in Regex (regex ref)