Skip to content

Commit 8e3faf2

Browse files
committed
Support Mathjax version 4
Added support for Mathjax version 4 and updated documentation
1 parent 853133e commit 8e3faf2

File tree

3 files changed

+107
-24
lines changed

3 files changed

+107
-24
lines changed

src/config.xml

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2800,14 +2800,16 @@ obfuscate email addresses.
28002800
</docs>
28012801
<value name="MathJax_2"/>
28022802
<value name="MathJax_3"/>
2803+
<value name="MathJax_4"/>
28032804
</option>
28042805
<option type='enum' id='MATHJAX_FORMAT' defval='HTML-CSS' depends='USE_MATHJAX'>
28052806
<docs>
28062807
<![CDATA[
28072808
When MathJax is enabled you can set the default output format to be used for
28082809
the MathJax output.
2809-
For more details about the output format see <a href="http://docs.mathjax.org/en/v2.7-latest/output.html">MathJax version 2</a>
2810-
and <a href="http://docs.mathjax.org/en/latest/web/components/output.html">MathJax version 3</a>.
2810+
For more details about the output format see <a href="https://docs.mathjax.org/en/v2.7/output.html">MathJax version 2</a>,
2811+
<a href="https://docs.mathjax.org/en/v3.2/output/index.html">MathJax version 3</a>
2812+
and <a href="https://docs.mathjax.org/en/v4.0/output/index.htm">MathJax version 4</a>.
28112813
]]>
28122814
</docs>
28132815
<value name="HTML-CSS" desc="(which is slower, but has the best compatibility. This is the name for Mathjax version 2, for MathJax version 3 this will be translated into \c chtml)"/>
@@ -2819,33 +2821,42 @@ obfuscate email addresses.
28192821
<docs>
28202822
<![CDATA[
28212823
When MathJax is enabled you need to specify the location relative to the
2822-
HTML output directory using the \c MATHJAX_RELPATH option. The destination
2824+
HTML output directory using the \c MATHJAX_RELPATH option. For Mathjax version 2 the destination
28232825
directory should contain the `MathJax.js` script. For instance, if the \c mathjax
28242826
directory is located at the same level as the HTML output directory, then
2825-
\c MATHJAX_RELPATH should be <code>../mathjax</code>. The default value points to
2827+
\c MATHJAX_RELPATH should be <code>../mathjax</code>.s
2828+
For Mathjax versions 3 and 3 the destination directory should contain the
2829+
`tex-<format>.js` script (where `<format>` is either `chtml` or `svg`).
2830+
The default value points to
28262831
the MathJax Content Delivery Network so you can quickly see the result without
28272832
installing MathJax. However, it is strongly recommended to install a local
28282833
copy of MathJax from https://www.mathjax.org before deployment.
28292834
28302835
The default value is:
2831-
- in case of MathJax version 2: https://cdn.jsdelivr.net/npm/mathjax@2
2832-
- in case of MathJax version 3: https://cdn.jsdelivr.net/npm/mathjax@3
2836+
- in case of MathJax version 2: https://cdn.jsdelivr.net/npm/mathjax@2
2837+
- in case of MathJax version 3: https://cdn.jsdelivr.net/npm/mathjax@3
2838+
- in case of MathJax version 4: https://cdn.jsdelivr.net/npm/mathjax@4
28332839
]]>
28342840
</docs>
28352841
</option>
28362842
<option type='list' id='MATHJAX_EXTENSIONS' format='string' depends='USE_MATHJAX'>
28372843
<docs>
28382844
<![CDATA[
28392845
The \c MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax extension
2840-
names that should be enabled during MathJax rendering. For example for MathJax version 2
2841-
(see https://docs.mathjax.org/en/v2.7-latest/tex.html#tex-and-latex-extensions):
2846+
names that should be enabled during MathJax rendering.
2847+
For example for MathJax version 2 (see https://docs.mathjax.org/en/v2.7/tex.html):
28422848
\verbatim
28432849
MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols
28442850
\endverbatim
2845-
For example for MathJax version 3 (see http://docs.mathjax.org/en/latest/input/tex/extensions/index.html):
2851+
For example for MathJax version 3 (see https://docs.mathjax.org/en/v3.2/input/tex/extensions/):
28462852
\verbatim
28472853
MATHJAX_EXTENSIONS = ams
28482854
\endverbatim
2855+
For example for MathJax version 4 (see https://docs.mathjax.org/en/v4.0/input/tex/extensions/):
2856+
\verbatim
2857+
MATHJAX_EXTENSIONS = units
2858+
\endverbatim
2859+
Note that for Matjax version 4 quite a few extensions are already automatically loaded.
28492860
]]>
28502861
</docs>
28512862
</option>
@@ -2854,9 +2865,10 @@ MATHJAX_EXTENSIONS = ams
28542865
<![CDATA[
28552866
The \c MATHJAX_CODEFILE tag can be used to specify a file with JavaScript
28562867
pieces of code that will be used on startup of the MathJax code.
2857-
See
2858-
<a href="http://docs.mathjax.org/en/v2.7-latest/output.html">the MathJax site</a>
2859-
for more details.
2868+
See the Mathjax site for more details:
2869+
- <a href="https://docs.mathjax.org/en/v2.7/">MathJax version 2</a>
2870+
- <a href="https://docs.mathjax.org/en/v3.2/">MathJax version 3</a>
2871+
- <a href="https://docs.mathjax.org/en/v4.0/">MathJax version 4</a>
28602872
]]>
28612873
</docs>
28622874
<docs doxywizard='0' doxyfile='0'>

src/configimpl.l

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,19 +1839,26 @@ void Config::checkAndCorrect(bool quiet, const bool check)
18391839
{
18401840
auto mathJaxFormat = Config_getEnum(MATHJAX_FORMAT);
18411841
auto mathjaxVersion = Config_getEnum(MATHJAX_VERSION);
1842-
if (mathjaxVersion == MATHJAX_VERSION_t::MathJax_2)
1842+
switch (mathjaxVersion)
18431843
{
1844-
if (mathJaxFormat==MATHJAX_FORMAT_t::chtml)
1845-
{
1846-
Config_updateEnum(MATHJAX_FORMAT,MATHJAX_FORMAT_t::HTML_CSS);
1847-
}
1848-
}
1849-
else
1850-
{
1851-
if (mathJaxFormat==MATHJAX_FORMAT_t::HTML_CSS || mathJaxFormat==MATHJAX_FORMAT_t::NativeMML)
1852-
{
1853-
Config_updateEnum(MATHJAX_FORMAT,MATHJAX_FORMAT_t::chtml);
1854-
}
1844+
case MATHJAX_VERSION_t::MathJax_2:
1845+
if (mathJaxFormat==MATHJAX_FORMAT_t::chtml)
1846+
{
1847+
Config_updateEnum(MATHJAX_FORMAT,MATHJAX_FORMAT_t::HTML_CSS);
1848+
}
1849+
break;
1850+
case MATHJAX_VERSION_t::MathJax_3:
1851+
if (mathJaxFormat==MATHJAX_FORMAT_t::HTML_CSS || mathJaxFormat==MATHJAX_FORMAT_t::NativeMML)
1852+
{
1853+
Config_updateEnum(MATHJAX_FORMAT,MATHJAX_FORMAT_t::chtml);
1854+
}
1855+
break;
1856+
case MATHJAX_VERSION_t::MathJax_4:
1857+
if (mathJaxFormat==MATHJAX_FORMAT_t::HTML_CSS || mathJaxFormat==MATHJAX_FORMAT_t::NativeMML)
1858+
{
1859+
Config_updateEnum(MATHJAX_FORMAT,MATHJAX_FORMAT_t::chtml);
1860+
}
1861+
break;
18551862
}
18561863

18571864
QCString mathJaxCodefile = Config_getString(MATHJAX_CODEFILE);
@@ -1872,6 +1879,7 @@ void Config::checkAndCorrect(bool quiet, const bool check)
18721879
{
18731880
case MATHJAX_VERSION_t::MathJax_2: path += "2"; break;
18741881
case MATHJAX_VERSION_t::MathJax_3: path += "3"; break;
1882+
case MATHJAX_VERSION_t::MathJax_4: path += "4"; break;
18751883
}
18761884
}
18771885

src/htmlgen.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,69 @@ static QCString substituteHtmlKeywords(const QCString &file,
464464

465465
switch (mathJaxVersion)
466466
{
467+
case MATHJAX_VERSION_t::MathJax_4:
468+
{
469+
mathJaxJs += "<script type=\"text/javascript\">\n"
470+
"window.MathJax = {\n"
471+
" options: {\n"
472+
" ignoreHtmlClass: 'tex2jax_ignore',\n"
473+
" processHtmlClass: 'tex2jax_process'\n"
474+
" }";
475+
// MACRO / EXT
476+
const StringVector &mathJaxExtensions = Config_getList(MATHJAX_EXTENSIONS);
477+
if (!mathJaxExtensions.empty() || !g_latex_macro.isEmpty())
478+
{
479+
mathJaxJs+= ",\n";
480+
if (!mathJaxExtensions.empty())
481+
{
482+
bool first = true;
483+
mathJaxJs+= " loader: {\n"
484+
" load: [";
485+
for (const auto &s : mathJaxExtensions)
486+
{
487+
if (!first) mathJaxJs+= ",";
488+
mathJaxJs+= "'[tex]/"+QCString(s.c_str())+"'";
489+
first = false;
490+
}
491+
mathJaxJs+= "]\n"
492+
" },\n";
493+
}
494+
mathJaxJs+= " tex: {\n"
495+
" macros: {";
496+
if (!g_latex_macro.isEmpty())
497+
{
498+
mathJaxJs += g_latex_macro+" ";
499+
}
500+
mathJaxJs+="},\n"
501+
" packages: {\n";
502+
bool first = true;
503+
for (const auto &s : mathJaxExtensions)
504+
{
505+
if (!first) mathJaxJs+= ",";
506+
mathJaxJs+= "\n";
507+
mathJaxJs+= " '[+]': ['"+QCString(s.c_str())+"']";
508+
first = false;
509+
}
510+
mathJaxJs += "\n }\n";
511+
mathJaxJs += " }\n";
512+
}
513+
else
514+
{
515+
mathJaxJs += "\n";
516+
}
517+
mathJaxJs += "};\n";
518+
// MATHJAX_CODEFILE
519+
if (!g_mathjax_code.isEmpty())
520+
{
521+
mathJaxJs += g_mathjax_code;
522+
mathJaxJs += "\n";
523+
}
524+
mathJaxJs+="</script>\n";
525+
mathJaxJs += "<script type=\"text/javascript\" id=\"MathJax-script\" async=\"async\" src=\"" +
526+
path + "tex-" + mathJaxFormat.lower() + ".js\">";
527+
mathJaxJs+="</script>\n";
528+
}
529+
break;
467530
case MATHJAX_VERSION_t::MathJax_3:
468531
{
469532
mathJaxJs += // "<script src=\"https://polyfill.io/v3/polyfill.min.js?features=es6\"></script>\n" // needed for IE11 only, see #10354

0 commit comments

Comments
 (0)