HTML: upgrade to MathJax 4 for browser rendering#2818
HTML: upgrade to MathJax 4 for browser rendering#2818rbeezer wants to merge 4 commits intoPreTeXtBook:masterfrom
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Now available:
See #1841 for new ideas and for things to test. |
|
@ascholerChemeketa should be moving here from his good work on #2180. @bnmnetp - can you take this for a drive on Runestone Academy? I've built the sample book for local hosting and math in RS components seems to be working pretty well. |
|
@bnmnetp - there are some new |
|
I have no recollection of why I added the MJ4 script tag has I would recommend starting with getting rid of the |
MathJax v3 recommended
You will want to use either |
dpvc
left a comment
There was a problem hiding this comment.
A few recommendation for streamlining the configuration.
js/mathjax_startup.js
Outdated
| "base", | ||
| "ams", | ||
| "amscd", | ||
| "color", | ||
| "newcommand", | ||
| "knowl" |
There was a problem hiding this comment.
The base, ams, and newcommend packages are already in the packages list (you are loading tex-mml-chtml.js, which already includes them and several others), so there is not need to include them here. The [+] is saying add these to the existing package list, but they are already there. It doesn't care any errors, but is redundant.
js/mathjax_startup.js
Outdated
| }); | ||
|
|
||
| function GetArgumentMML(parser, name) { | ||
| const NodeUtil = MathJax._.input.tex.NodeUtil.default; |
There was a problem hiding this comment.
You could move this line outside the GetAargumentMML() function, as it is a value that doesn't change. That would avoid having to look it up each time GetArgumentMML() is called.
| new CommandMap( | ||
| "knowl", | ||
| { | ||
| knowl: ["Knowl"] | ||
| }, | ||
| mathjaxKnowl | ||
| ); |
There was a problem hiding this comment.
Version 4 has a more compact format for defining a CommandMap. You don't have to have a separate mathjaxKnowl object, but can just put the Knowl() function as the value for the knowl entry in the CommandMap:
new CommandMap(
"knowl",
{
knowl: (parser, name) => {
const url = parser.GetArgument(name);
const arg = GetArgumentMML(parser, name);
const mrow = parser.create("node", "mrow", [arg], { tabindex: '0', "data-knowl": url });
parser.Push(mrow);
}
}
);In fact, you can probably just do
new CommandMap(
"knowl",
{
knowl(parser, name) {
const url = parser.GetArgument(name);
const arg = GetArgumentMML(parser, name);
const mrow = parser.create("node", "mrow", [arg], { tabindex: '0', "data-knowl": url });
parser.Push(mrow);
}
}
);| pageReady() { | ||
| return MathJax.startup.defaultPageReady().then(function () { | ||
| rsMathReady(); | ||
| } | ||
| ) | ||
| }, |
There was a problem hiding this comment.
This can be simplified to
pageReady() {
return MathJax.startup.defaultPageReady().then(rsMathReady);
}or even
pageReady: () => MathJax.startup.defaultPageReady().then(rsMathReady);| if(opts.htmlPresentation) { | ||
| mathJaxOpts['options']['menuOptions'] = { | ||
| "settings": { | ||
| "zoom": "Click", |
There was a problem hiding this comment.
I would not recommend using Click for this unless you also include one of the modifier keys, as clicking (and double clicking) is used with the expression explorer, and this will cause it to both start the explorer and show the zoom.
|
Thanks very much @dpvc! I'll see about getting those in place. You are right about "Click". We also support knowls inside display math, which are activated/opened by a mouse click. We will need to think more carefully about how we want to separate that from the Explorer functions. |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Latest commit applies David Cervone's configuration recommendations from the PR discussion:
Did not change Claude Opus 4.6, acting as a coding assistant for Rob Beezer |
|
Changes seem fine visually. Thanks again, @dpvc. I made you the author of the commit, I can walk that back once we merge, if you prefer. And likely I'll rotate this down to immediately follow Andrew's original version. |
Upgrade HTML output from MathJax 3 to MathJax 4 (CDN stable release 4.1.1).
mathjax_startup.jsmodule from MathJax 4 knowl fix #2180, which inlines the knowl extension and exports a configuration functionpretext-html.xslwith a module import callingstartMathJax(), plus the MathJax 4 CDN script withdeferdeferto Runestone service script tags for correct load orderingmathjaxknowl3.js(superseded by the startup module)debug.mathjax4parameter and$mathjax4-testingvariable (no longer needed since MJ4 is now the only path)The
textmacrosextension, added to the MJ3 configuration in #2817, is loaded by default in MathJax 4 and does not need to be listed explicitly.This is Phase 1 of the MJ4 migration (issue #1841), covering browser-side rendering only. The offline Node.js processing in
mj-sre-page.js(used for EPUB and braille) is independent and unchanged.Claude Opus 4.6, acting as a coding assistant for Rob Beezer