From 8eebe920dc3e8eda5a79a15011e2c81512b5b1da Mon Sep 17 00:00:00 2001 From: ascholer Date: Thu, 20 Jun 2024 15:19:05 -0700 Subject: [PATCH 1/7] Never need type on scripts --- xsl/pretext-html.xsl | 7 ------- 1 file changed, 7 deletions(-) diff --git a/xsl/pretext-html.xsl b/xsl/pretext-html.xsl index d0b7ecdb7..d23f04663 100644 --- a/xsl/pretext-html.xsl +++ b/xsl/pretext-html.xsl @@ -12346,13 +12346,6 @@ TODO: - - - - - text/javascript - - From 628adb6a7a92701534fc504a14f65ab0023eda62 Mon Sep 17 00:00:00 2001 From: ascholer Date: Thu, 20 Jun 2024 15:19:33 -0700 Subject: [PATCH 2/7] Add file with right MathJax startup recipe for v4 --- js/mathjax_startup.js | 123 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 js/mathjax_startup.js diff --git a/js/mathjax_startup.js b/js/mathjax_startup.js new file mode 100644 index 000000000..a7b80adae --- /dev/null +++ b/js/mathjax_startup.js @@ -0,0 +1,123 @@ +/*************************************************************** + * Implements startup of MathJax v4 + ***************************************************************/ + +// Let's Runestone know that MathJax is ready +const runestoneMathReady = new Promise((resolve) => window.rsMathReady = resolve); + +window.MathJax = { + "tex": { + "inlineMath": [ + [ + "\\(", + "\\)" + ] + ], + "tags": "none", + "tagSide": "right", + "tagIndent": ".8em", + "packages": { + "[+]": [ + "base", + "ams", + "amscd", + "color", + "newcommand", + "knowl" + ] + } + }, + "options": { + "ignoreHtmlClass": "tex2jax_ignore|ignore-math", + "processHtmlClass": "process-math", + "renderActions": { + "findScript": [ + 10, + function (doc) { + document.querySelectorAll('script[type^="math/tex"]').forEach(function (node) { + var display = !!node.type.match(/; *mode=display/); + var math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display); + var text = document.createTextNode(''); + node.parentNode.replaceChild(text, node); + math.start = { node: text, delim: '', n: 0 }; + math.end = { node: text, delim: '', n: 0 }; + doc.math.push(math); + }); + }, + "" + ] + } + }, + "chtml": { + "scale": 0.98, + "mtextInheritFont": true + }, + "loader": { + "load": [ + "input/asciimath", + "[tex]/extpfeil", + "[tex]/amscd", + "[tex]/color", + "[tex]/newcommand", + ], + "paths": { + "pretext": "_static/pretext/js/lib" + } + }, + "startup": { + ready() { + const { Configuration } = MathJax._.input.tex.Configuration; + const configuration = Configuration.create("knowl", { + handler: { + macro: ["knowl"] + } + }); + + function GetArgumentMML(parser, name) { + const NodeUtil = MathJax._.input.tex.NodeUtil.default; + const arg = parser.ParseArg(name); + if (!NodeUtil.isInferred(arg)) { + return arg; + } + const children = NodeUtil.getChildren(arg); + if (children.length === 1) { + return children[0]; + } + const mrow = parser.create("node", "mrow"); + NodeUtil.copyChildren(arg, mrow); + NodeUtil.copyAttributes(arg, mrow); + return mrow; + }; + + let mathjaxKnowl = {}; + /** + * Implements \knowl{url}{math} + * @param {TexParser} parser The calling parser. + * @param {string} name The TeX string + */ + mathjaxKnowl.Knowl = function (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); + }; + + const CommandMap = MathJax._.input.tex.TokenMap.CommandMap; + new CommandMap( + "knowl", + { + knowl: ["Knowl"] + }, + mathjaxKnowl + ); + + MathJax.startup.defaultReady(); + }, + pageReady() { + return MathJax.startup.defaultPageReady().then(function () { + rsMathReady(); + } + ) + }, + } +}; \ No newline at end of file From 74a6237c4ecebd990aae17c8e4d4ced9f7ca310c Mon Sep 17 00:00:00 2001 From: ascholer Date: Thu, 20 Jun 2024 15:19:55 -0700 Subject: [PATCH 3/7] Conditionally use new file --- xsl/pretext-html.xsl | 221 ++++++++++++++++++++++--------------------- 1 file changed, 114 insertions(+), 107 deletions(-) diff --git a/xsl/pretext-html.xsl b/xsl/pretext-html.xsl index d23f04663..109ecfeb2 100644 --- a/xsl/pretext-html.xsl +++ b/xsl/pretext-html.xsl @@ -12232,118 +12232,125 @@ TODO: - - - var runestoneMathReady = new Promise((resolve) => window.rsMathReady = resolve); - window.MathJax = - - - - - - - \( - \) - - - none - right - .8em - - - base - - - - extpfeil - - ams - amscd - color - newcommand - knowl - - - - - tex2jax_ignore|ignore-math - process-math - - - - 10 - - function (doc) { - document.querySelectorAll('script[type^="math/tex"]').forEach(function(node) { - var display = !!node.type.match(/; *mode=display/); - var math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display); - var text = document.createTextNode(''); - node.parentNode.replaceChild(text, node); - math.start = {node: text, delim: '', n: 0}; - math.end = {node: text, delim: '', n: 0}; - doc.math.push(math); - }); - } - - + + + + + + + + var runestoneMathReady = new Promise((resolve) => window.rsMathReady = resolve); + window.MathJax = + + + + + + + \( + \) + + none + right + .8em + + + base + + + + extpfeil + + ams + amscd + color + newcommand + knowl + + - - - - 0.98 - true - - - - input/asciimath - [tex]/extpfeil - [tex]/amscd - [tex]/color - [tex]/newcommand - [pretext]/mathjaxknowl3.js - - - - - - - - - - - false - - - - - pageReady() { - return MathJax.startup.defaultPageReady().then(function () { - console.log("in ready function"); - rsMathReady(); - } - )} - - - - - - - - - - Click - 300% + + tex2jax_ignore|ignore-math + process-math + + + + 10 + + function (doc) { + document.querySelectorAll('script[type^="math/tex"]').forEach(function(node) { + var display = !!node.type.match(/; *mode=display/); + var math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display); + var text = document.createTextNode(''); + node.parentNode.replaceChild(text, node); + math.start = {node: text, delim: '', n: 0}; + math.end = {node: text, delim: '', n: 0}; + doc.math.push(math); + }); + } + + + + + + + + 0.98 + true + + + + input/asciimath + [tex]/extpfeil + [tex]/amscd + [tex]/color + [tex]/newcommand + [pretext]/mathjaxknowl3.js + + + + + + + + + false + + + + + pageReady() { + return MathJax.startup.defaultPageReady().then(function () { + console.log("in ready function"); + rsMathReady(); + } + )} + + + + + + + + + + Click + 300% + + + + - - - - - ; - - + + + ; + + + + From 2b413fb310e47538d1b1022fbffbc6aab7ce9f28 Mon Sep 17 00:00:00 2001 From: ascholer Date: Thu, 20 Jun 2024 15:42:15 -0700 Subject: [PATCH 4/7] Lazy loading test Lazy loading makes above the fold content appear much quicker. Breaks parsing of embedded knowls --- js/mathjax_startup.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/mathjax_startup.js b/js/mathjax_startup.js index a7b80adae..f3d1ad19e 100644 --- a/js/mathjax_startup.js +++ b/js/mathjax_startup.js @@ -54,6 +54,7 @@ window.MathJax = { }, "loader": { "load": [ + //"ui/lazy", // Vastly speeds up time to visible content. But breaks embedded knowl parsing "input/asciimath", "[tex]/extpfeil", "[tex]/amscd", From 07307cf7fe3d3ea9999e3c5ea6c3adf94efafb8c Mon Sep 17 00:00:00 2001 From: ascholer Date: Mon, 15 Jul 2024 21:34:52 -0700 Subject: [PATCH 5/7] options config --- js/mathjax_startup.js | 178 +++++++++++++++++++++++++----------------- xsl/pretext-html.xsl | 11 ++- 2 files changed, 115 insertions(+), 74 deletions(-) diff --git a/js/mathjax_startup.js b/js/mathjax_startup.js index f3d1ad19e..adf3216a6 100644 --- a/js/mathjax_startup.js +++ b/js/mathjax_startup.js @@ -2,10 +2,8 @@ * Implements startup of MathJax v4 ***************************************************************/ -// Let's Runestone know that MathJax is ready -const runestoneMathReady = new Promise((resolve) => window.rsMathReady = resolve); - -window.MathJax = { +// Base config options. Will be supplemented by optional parts later +let mathJaxOpts = { "tex": { "inlineMath": [ [ @@ -30,23 +28,6 @@ window.MathJax = { "options": { "ignoreHtmlClass": "tex2jax_ignore|ignore-math", "processHtmlClass": "process-math", - "renderActions": { - "findScript": [ - 10, - function (doc) { - document.querySelectorAll('script[type^="math/tex"]').forEach(function (node) { - var display = !!node.type.match(/; *mode=display/); - var math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display); - var text = document.createTextNode(''); - node.parentNode.replaceChild(text, node); - math.start = { node: text, delim: '', n: 0 }; - math.end = { node: text, delim: '', n: 0 }; - doc.math.push(math); - }); - }, - "" - ] - } }, "chtml": { "scale": 0.98, @@ -64,61 +45,112 @@ window.MathJax = { "paths": { "pretext": "_static/pretext/js/lib" } - }, - "startup": { - ready() { - const { Configuration } = MathJax._.input.tex.Configuration; - const configuration = Configuration.create("knowl", { - handler: { - macro: ["knowl"] - } - }); - - function GetArgumentMML(parser, name) { - const NodeUtil = MathJax._.input.tex.NodeUtil.default; - const arg = parser.ParseArg(name); - if (!NodeUtil.isInferred(arg)) { - return arg; - } - const children = NodeUtil.getChildren(arg); - if (children.length === 1) { - return children[0]; - } - const mrow = parser.create("node", "mrow"); - NodeUtil.copyChildren(arg, mrow); - NodeUtil.copyAttributes(arg, mrow); - return mrow; - }; + } +}; - let mathjaxKnowl = {}; - /** - * Implements \knowl{url}{math} - * @param {TexParser} parser The calling parser. - * @param {string} name The TeX string - */ - mathjaxKnowl.Knowl = function (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); - }; - const CommandMap = MathJax._.input.tex.TokenMap.CommandMap; - new CommandMap( - "knowl", - { - knowl: ["Knowl"] +export function startMathJax(opts) { + if(opts.hasWebworkReps || opts.hasSage) { + mathJaxOpts['renderActions'] = { + "findScript": [ + 10, + function (doc) { + document.querySelectorAll('script[type^="math/tex"]').forEach(function (node) { + var display = !!node.type.match(/; *mode=display/); + var math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display); + var text = document.createTextNode(''); + node.parentNode.replaceChild(text, node); + math.start = { node: text, delim: '', n: 0 }; + math.end = { node: text, delim: '', n: 0 }; + doc.math.push(math); + }); }, - mathjaxKnowl - ); + "" + ] + } + } - MathJax.startup.defaultReady(); - }, - pageReady() { - return MathJax.startup.defaultPageReady().then(function () { - rsMathReady(); + if(opts.isReact) { + mathJaxOpts['startup'] = { + typeset: false, + } + } else { + mathJaxOpts['startup'] = { + ready() { + const { Configuration } = MathJax._.input.tex.Configuration; + const configuration = Configuration.create("knowl", { + handler: { + macro: ["knowl"] + } + }); + + function GetArgumentMML(parser, name) { + const NodeUtil = MathJax._.input.tex.NodeUtil.default; + const arg = parser.ParseArg(name); + if (!NodeUtil.isInferred(arg)) { + return arg; + } + const children = NodeUtil.getChildren(arg); + if (children.length === 1) { + return children[0]; + } + const mrow = parser.create("node", "mrow"); + NodeUtil.copyChildren(arg, mrow); + NodeUtil.copyAttributes(arg, mrow); + return mrow; + }; + + let mathjaxKnowl = {}; + /** + * Implements \knowl{url}{math} + * @param {TexParser} parser The calling parser. + * @param {string} name The TeX string + */ + mathjaxKnowl.Knowl = function (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); + }; + + const CommandMap = MathJax._.input.tex.TokenMap.CommandMap; + new CommandMap( + "knowl", + { + knowl: ["Knowl"] + }, + mathjaxKnowl + ); + + MathJax.startup.defaultReady(); + }, + pageReady() { + return MathJax.startup.defaultPageReady().then(function () { + rsMathReady(); + } + ) + }, + } + } + + if(opts.htmlPresentation) { + mathJaxOpts['options']['menuOptions'] = { + "settings": { + "zoom": "Click", + "zscale": "300%" } - ) - }, + } } -}; \ No newline at end of file + + // Apply the options + window.MathJax = mathJaxOpts; + + // Lets Runestone know that MathJax is ready + const runestoneMathReady = new Promise((resolve) => window.rsMathReady = resolve); + window.runestoneMathReady = runestoneMathReady; +} + + + + + diff --git a/xsl/pretext-html.xsl b/xsl/pretext-html.xsl index 109ecfeb2..45a184feb 100644 --- a/xsl/pretext-html.xsl +++ b/xsl/pretext-html.xsl @@ -12234,7 +12234,15 @@ TODO: - + @@ -12378,6 +12386,7 @@ TODO: + true From 608c80a8aaec7f7f9045cc5656c039bb25c9c1a7 Mon Sep 17 00:00:00 2001 From: ascholer Date: Tue, 16 Jul 2024 07:43:34 -0700 Subject: [PATCH 6/7] Remove backwards compatability? If not need to pass a param to set this --- js/mathjax_startup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/mathjax_startup.js b/js/mathjax_startup.js index adf3216a6..9639bfd0e 100644 --- a/js/mathjax_startup.js +++ b/js/mathjax_startup.js @@ -37,7 +37,7 @@ let mathJaxOpts = { "load": [ //"ui/lazy", // Vastly speeds up time to visible content. But breaks embedded knowl parsing "input/asciimath", - "[tex]/extpfeil", + //"[tex]/extpfeil", //remove backwards compatibility? "[tex]/amscd", "[tex]/color", "[tex]/newcommand", From 565679c788036c883323aa57f177d65896fcb5aa Mon Sep 17 00:00:00 2001 From: ascholer Date: Tue, 16 Jul 2024 07:38:42 -0700 Subject: [PATCH 7/7] Defer runestone to wait on mathjax --- xsl/pretext-runestone.xsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xsl/pretext-runestone.xsl b/xsl/pretext-runestone.xsl index 1c72599dd..6da210e4d 100644 --- a/xsl/pretext-runestone.xsl +++ b/xsl/pretext-runestone.xsl @@ -310,7 +310,7 @@ along with PreTeXt. If not, see . *** Runestone Services *** -