MathJax startup script. #13147
Unanswered
randolf-scholz
asked this question in
Q&A
Replies: 2 comments 6 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.
0 replies
-
@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.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Is it possible to configure
mathjax3_config
to add a startup script like described here?Beta Was this translation helpful? Give feedback.
All reactions