From f3ff862cfb7ad8f1f1037575fe259b6550aa0244 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Tue, 30 Oct 2018 20:47:28 +0800 Subject: [PATCH] MathJax: support euqation number http://docs.mathjax.org/en/latest/tex.html#automatic-equation-numbering --- src/resources/hoedown.js | 3 ++- src/resources/markdown-it.js | 6 +++-- src/resources/marked.js | 3 ++- src/resources/mathjax_preview.js | 3 ++- src/resources/showdown.js | 3 ++- src/utils/vutils.cpp | 43 +++++++++++++++++++------------- 6 files changed, 38 insertions(+), 23 deletions(-) diff --git a/src/resources/hoedown.js b/src/resources/hoedown.js index 8d7e8249..943db60c 100644 --- a/src/resources/hoedown.js +++ b/src/resources/hoedown.js @@ -85,7 +85,8 @@ var updateHtml = function(html) { // MathJax may be not loaded for now. if (VEnableMathjax && (typeof MathJax != "undefined")) { try { - MathJax.Hub.Queue(["Typeset", MathJax.Hub, contentDiv, postProcessMathJax]); + MathJax.Hub.Queue(["resetEquationNumbers",MathJax.InputJax.TeX], + ["Typeset", MathJax.Hub, contentDiv, postProcessMathJax]); } catch (err) { content.setLog("err: " + err); finishOneAsyncJob(); diff --git a/src/resources/markdown-it.js b/src/resources/markdown-it.js index 675c2333..16318f2a 100644 --- a/src/resources/markdown-it.js +++ b/src/resources/markdown-it.js @@ -169,7 +169,8 @@ var updateText = function(text) { } try { - MathJax.Hub.Queue(["Typeset", MathJax.Hub, eles, postProcessMathJax]); + MathJax.Hub.Queue(["resetEquationNumbers",MathJax.InputJax.TeX], + ["Typeset", MathJax.Hub, eles, postProcessMathJax]); } catch (err) { content.setLog("err: " + err); finishOneAsyncJob(); @@ -254,7 +255,8 @@ var handleMathjaxReady = function() { } try { - MathJax.Hub.Queue(["Typeset", MathJax.Hub, eles, postProcessMathJaxWhenMathjaxReady]); + MathJax.Hub.Queue(["resetEquationNumbers",MathJax.InputJax.TeX], + ["Typeset", MathJax.Hub, eles, postProcessMathJaxWhenMathjaxReady]); } catch (err) { content.setLog("err: " + err); finishOneAsyncJob(); diff --git a/src/resources/marked.js b/src/resources/marked.js index da7a8815..e8583d28 100644 --- a/src/resources/marked.js +++ b/src/resources/marked.js @@ -72,7 +72,8 @@ var updateText = function(text) { // finishLoading logic. if (VEnableMathjax) { try { - MathJax.Hub.Queue(["Typeset", MathJax.Hub, contentDiv, postProcessMathJax]); + MathJax.Hub.Queue(["resetEquationNumbers",MathJax.InputJax.TeX], + ["Typeset", MathJax.Hub, contentDiv, postProcessMathJax]); } catch (err) { content.setLog("err: " + err); finishOneAsyncJob(); diff --git a/src/resources/mathjax_preview.js b/src/resources/mathjax_preview.js index 77e4a3bc..736588a5 100644 --- a/src/resources/mathjax_preview.js +++ b/src/resources/mathjax_preview.js @@ -72,7 +72,8 @@ var previewMathJax = function(identifier, id, timeStamp, text, isHtml) { } try { - MathJax.Hub.Queue(["Typeset", + MathJax.Hub.Queue(["resetEquationNumbers",MathJax.InputJax.TeX], + ["Typeset", MathJax.Hub, p, [postProcessMathJax, identifier, id, timeStamp, p, isBlock]]); diff --git a/src/resources/showdown.js b/src/resources/showdown.js index dd4fbb14..52887f19 100644 --- a/src/resources/showdown.js +++ b/src/resources/showdown.js @@ -117,7 +117,8 @@ var updateText = function(text) { // finishLoading logic. if (VEnableMathjax) { try { - MathJax.Hub.Queue(["Typeset", MathJax.Hub, contentDiv, postProcessMathJax]); + MathJax.Hub.Queue(["resetEquationNumbers",MathJax.InputJax.TeX], + ["Typeset", MathJax.Hub, contentDiv, postProcessMathJax]); } catch (err) { content.setLog("err: " + err); finishOneAsyncJob(); diff --git a/src/utils/vutils.cpp b/src/utils/vutils.cpp index 16acc43a..d79412bc 100644 --- a/src/utils/vutils.cpp +++ b/src/utils/vutils.cpp @@ -796,6 +796,9 @@ QString VUtils::generateHtmlTemplate(const QString &p_template, " TeX: {\n" " Macros: {\n" " bm: [\"\\\\boldsymbol{#1}\", 1]\n" + " },\n" + " equationNumbers: {\n" + " autoNumber: \"AMS\"\n" " }\n" " },\n" " messageStyle: \"none\"});\n" @@ -884,29 +887,32 @@ QString VUtils::generateExportHtmlTemplate(const QString &p_renderBg, QString extra; if (p_includeMathJax) { extra += "\n"; QString mj = g_config->getMathjaxJavascript(); @@ -969,6 +975,9 @@ QString VUtils::generateMathJaxPreviewTemplate() " TeX: {\n" " Macros: {\n" " bm: [\"\\\\boldsymbol{#1}\", 1]\n" + " },\n" + " equationNumbers: {\n" + " autoNumber: \"AMS\"\n" " }\n" " },\n" " messageStyle: \"none\"});\n"