MathJax startup script. #13147
-
|
Is it possible to configure |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
|
I don't know, there aren't many posts giving examples on advanced MathJax usage with Sphinx on Stack Overflow. I wish more users were using MathJax+Sphinx and showing how to do it. |
Beta Was this translation helpful? Give feedback.
-
|
@randolf-scholz The below is untested but should work: # conf.py
mathjax3_config = ''
def setup(app):
app.add_js_file('', body="""\
window.MathJax = {
// whatever was previously in mathjax3_config
startup: {
ready() {
//
// Do usual setup
//
MathJax.startup.defaultReady();
//
// The pseudoscript numbers 0 through 9, and a pattern for plus-or-minus a number
//
const scripts = '\u2070\u00B9\u00B2\u00B3\u2074\u2075\u2076\u2077\u2078\u2079';
const scriptRE = /([\u207A\u207B])?([\u2070\u00B9\u00B2\u00B3\u2074-\u2079]+)/g;
//
// Add a TeX prefilter to convert pseudoscript numbers to actual superscripts
//
MathJax.startup.document.inputJax[0].preFilters.add((data) => {
data.math.math = data.math.math.replace(scriptRE, (match, pm, n) => {
const N = n.split('').map(c => scripts.indexOf(c)); // convert digits
pm === '\u207A' && N.unshift('+'); // add plus, if given
pm === '\u207B' && N.unshift('-'); // add minus, if given
return '^{' + N.join('') + '}'; // make it an actual power
});
});
}
}
};
""")A |
Beta Was this translation helpful? Give feedback.
-
|
#14025 has been merged, adding a new A |
Beta Was this translation helpful? Give feedback.
#14025 has been merged, adding a new
mathjax_config_pathoption.A