Skip to content

Commit f1ec8b7

Browse files
committed
Merge branch 'albert-github-feature/bug_mathjax_4'
2 parents bfa2d67 + 07f0177 commit f1ec8b7

File tree

3 files changed

+134
-88
lines changed

3 files changed

+134
-88
lines changed

src/config.xml

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2813,14 +2813,16 @@ obfuscate email addresses.
28132813
</docs>
28142814
<value name="MathJax_2"/>
28152815
<value name="MathJax_3"/>
2816+
<value name="MathJax_4"/>
28162817
</option>
28172818
<option type='enum' id='MATHJAX_FORMAT' defval='HTML-CSS' depends='USE_MATHJAX'>
28182819
<docs>
28192820
<![CDATA[
28202821
When MathJax is enabled you can set the default output format to be used for
28212822
the MathJax output.
2822-
For more details about the output format see <a href="http://docs.mathjax.org/en/v2.7-latest/output.html">MathJax version 2</a>
2823-
and <a href="http://docs.mathjax.org/en/latest/web/components/output.html">MathJax version 3</a>.
2823+
For more details about the output format see <a href="https://docs.mathjax.org/en/v2.7/output.html">MathJax version 2</a>,
2824+
<a href="https://docs.mathjax.org/en/v3.2/output/index.html">MathJax version 3</a>
2825+
and <a href="https://docs.mathjax.org/en/v4.0/output/index.htm">MathJax version 4</a>.
28242826
]]>
28252827
</docs>
28262828
<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)"/>
@@ -2832,33 +2834,42 @@ obfuscate email addresses.
28322834
<docs>
28332835
<![CDATA[
28342836
When MathJax is enabled you need to specify the location relative to the
2835-
HTML output directory using the \c MATHJAX_RELPATH option. The destination
2837+
HTML output directory using the \c MATHJAX_RELPATH option. For Mathjax version 2 the destination
28362838
directory should contain the `MathJax.js` script. For instance, if the \c mathjax
28372839
directory is located at the same level as the HTML output directory, then
2838-
\c MATHJAX_RELPATH should be <code>../mathjax</code>. The default value points to
2840+
\c MATHJAX_RELPATH should be <code>../mathjax</code>.s
2841+
For Mathjax versions 3 and 4 the destination directory should contain the
2842+
`tex-<format>.js` script (where `<format>` is either `chtml` or `svg`).
2843+
The default value points to
28392844
the MathJax Content Delivery Network so you can quickly see the result without
28402845
installing MathJax. However, it is strongly recommended to install a local
28412846
copy of MathJax from https://www.mathjax.org before deployment.
28422847
28432848
The default value is:
2844-
- in case of MathJax version 2: https://cdn.jsdelivr.net/npm/mathjax@2
2845-
- in case of MathJax version 3: https://cdn.jsdelivr.net/npm/mathjax@3
2849+
- in case of MathJax version 2: https://cdn.jsdelivr.net/npm/mathjax@2
2850+
- in case of MathJax version 3: https://cdn.jsdelivr.net/npm/mathjax@3
2851+
- in case of MathJax version 4: https://cdn.jsdelivr.net/npm/mathjax@4
28462852
]]>
28472853
</docs>
28482854
</option>
28492855
<option type='list' id='MATHJAX_EXTENSIONS' format='string' depends='USE_MATHJAX'>
28502856
<docs>
28512857
<![CDATA[
28522858
The \c MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax extension
2853-
names that should be enabled during MathJax rendering. For example for MathJax version 2
2854-
(see https://docs.mathjax.org/en/v2.7-latest/tex.html#tex-and-latex-extensions):
2859+
names that should be enabled during MathJax rendering.
2860+
For example for MathJax version 2 (see https://docs.mathjax.org/en/v2.7/tex.html):
28552861
\verbatim
28562862
MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols
28572863
\endverbatim
2858-
For example for MathJax version 3 (see http://docs.mathjax.org/en/latest/input/tex/extensions/index.html):
2864+
For example for MathJax version 3 (see https://docs.mathjax.org/en/v3.2/input/tex/extensions/):
28592865
\verbatim
28602866
MATHJAX_EXTENSIONS = ams
28612867
\endverbatim
2868+
For example for MathJax version 4 (see https://docs.mathjax.org/en/v4.0/input/tex/extensions/):
2869+
\verbatim
2870+
MATHJAX_EXTENSIONS = units
2871+
\endverbatim
2872+
Note that for Mathjax version 4 quite a few extensions are already automatically loaded.
28622873
]]>
28632874
</docs>
28642875
</option>
@@ -2867,9 +2878,10 @@ MATHJAX_EXTENSIONS = ams
28672878
<![CDATA[
28682879
The \c MATHJAX_CODEFILE tag can be used to specify a file with JavaScript
28692880
pieces of code that will be used on startup of the MathJax code.
2870-
See
2871-
<a href="http://docs.mathjax.org/en/v2.7-latest/output.html">the MathJax site</a>
2872-
for more details.
2881+
See the Mathjax site for more details:
2882+
- <a href="https://docs.mathjax.org/en/v2.7/">MathJax version 2</a>
2883+
- <a href="https://docs.mathjax.org/en/v3.2/">MathJax version 3</a>
2884+
- <a href="https://docs.mathjax.org/en/v4.0/">MathJax version 4</a>
28732885
]]>
28742886
</docs>
28752887
<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: 90 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ static QCString substituteHtmlKeywords(const QCString &file,
341341
bool searchEngine = Config_getBool(SEARCHENGINE);
342342
bool serverBasedSearch = Config_getBool(SERVER_BASED_SEARCH);
343343
bool mathJax = Config_getBool(USE_MATHJAX);
344-
QCString mathJaxFormat = Config_getEnumAsString(MATHJAX_FORMAT);
345344
bool disableIndex = Config_getBool(DISABLE_INDEX);
346345
bool hasProjectName = !projectName.isEmpty();
347346
bool hasProjectNumber = !Config_getString(PROJECT_NUMBER).isEmpty();
@@ -462,80 +461,107 @@ static QCString substituteHtmlKeywords(const QCString &file,
462461
path.prepend(relPath);
463462
}
464463

465-
switch (mathJaxVersion)
464+
auto writeMathJax3Packages = [&mathJaxJs](const StringVector &mathJaxExtensions)
466465
{
467-
case MATHJAX_VERSION_t::MathJax_3:
466+
mathJaxJs += " packages: ['base','configmacros'";
467+
if (!g_latex_macro.isEmpty())
468+
{
469+
mathJaxJs+= ",'newcommand'";
470+
}
471+
for (const auto &s : mathJaxExtensions)
472+
{
473+
mathJaxJs+= ",'"+QCString(s.c_str())+"'";
474+
}
475+
mathJaxJs += "]\n";
476+
};
477+
478+
auto writeMathJax4Packages = [&mathJaxJs](const StringVector &mathJaxExtensions)
479+
{
480+
mathJaxJs += " packages: {\n";
481+
bool first = true;
482+
for (const auto &s : mathJaxExtensions)
483+
{
484+
if (!first) mathJaxJs+= ",";
485+
mathJaxJs+= "\n '[+]': ['"+QCString(s.c_str())+"']";
486+
first = false;
487+
}
488+
mathJaxJs += "\n }\n";
489+
};
490+
491+
auto writeMathJaxScript = [&path,&mathJaxJs](const QCString &pathPostfix,
492+
std::function<void(const StringVector&)> writePackages)
493+
{
494+
QCString mathJaxFormat = Config_getEnumAsString(MATHJAX_FORMAT);
495+
mathJaxJs += "<script type=\"text/javascript\">\n"
496+
"window.MathJax = {\n"
497+
" options: {\n"
498+
" ignoreHtmlClass: 'tex2jax_ignore',\n"
499+
" processHtmlClass: 'tex2jax_process'\n"
500+
" }";
501+
// MACRO / EXT
502+
const StringVector &mathJaxExtensions = Config_getList(MATHJAX_EXTENSIONS);
503+
if (!mathJaxExtensions.empty() || !g_latex_macro.isEmpty())
504+
{
505+
mathJaxJs+= ",\n";
506+
if (!mathJaxExtensions.empty())
468507
{
469-
mathJaxJs += // "<script src=\"https://polyfill.io/v3/polyfill.min.js?features=es6\"></script>\n" // needed for IE11 only, see #10354
470-
"<script type=\"text/javascript\">\n"
471-
"window.MathJax = {\n"
472-
" options: {\n"
473-
" ignoreHtmlClass: 'tex2jax_ignore',\n"
474-
" processHtmlClass: 'tex2jax_process'\n"
475-
" }";
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: ['base','configmacros'";
502-
if (!g_latex_macro.isEmpty())
503-
{
504-
mathJaxJs+= ",'newcommand'";
505-
}
506-
for (const auto &s : mathJaxExtensions)
507-
{
508-
mathJaxJs+= ",'"+QCString(s.c_str())+"'";
509-
}
510-
mathJaxJs += "]\n"
511-
" }\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 + "es5/tex-" + mathJaxFormat.lower() + ".js\">";
527-
mathJaxJs+="</script>\n";
508+
bool first = true;
509+
mathJaxJs+= " loader: {\n"
510+
" load: [";
511+
for (const auto &s : mathJaxExtensions)
512+
{
513+
if (!first) mathJaxJs+= ",";
514+
mathJaxJs+= "'[tex]/"+QCString(s.c_str())+"'";
515+
first = false;
516+
}
517+
mathJaxJs+= "]\n"
518+
" },\n";
528519
}
520+
mathJaxJs+= " tex: {\n"
521+
" macros: {";
522+
if (!g_latex_macro.isEmpty())
523+
{
524+
mathJaxJs += g_latex_macro+" ";
525+
}
526+
mathJaxJs+="},\n";
527+
writePackages(mathJaxExtensions);
528+
mathJaxJs += " }\n";
529+
}
530+
else
531+
{
532+
mathJaxJs += "\n";
533+
}
534+
mathJaxJs += "};\n";
535+
// MATHJAX_CODEFILE
536+
if (!g_mathjax_code.isEmpty())
537+
{
538+
mathJaxJs += g_mathjax_code;
539+
mathJaxJs += "\n";
540+
}
541+
mathJaxJs+="</script>\n";
542+
mathJaxJs += "<script type=\"text/javascript\" id=\"MathJax-script\" async=\"async\" src=\"" +
543+
path + pathPostfix + "tex-" + mathJaxFormat.lower() + ".js\">";
544+
mathJaxJs+="</script>\n";
545+
};
546+
547+
switch (mathJaxVersion)
548+
{
549+
case MATHJAX_VERSION_t::MathJax_4:
550+
writeMathJaxScript("",writeMathJax4Packages);
551+
break;
552+
case MATHJAX_VERSION_t::MathJax_3:
553+
writeMathJaxScript("es5/",writeMathJax3Packages);
529554
break;
530555
case MATHJAX_VERSION_t::MathJax_2:
531556
{
557+
QCString mathJaxFormat = Config_getEnumAsString(MATHJAX_FORMAT);
532558
mathJaxJs = "<script type=\"text/x-mathjax-config\">\n"
533559
"MathJax.Hub.Config({\n"
534560
" extensions: [\"tex2jax.js\"";
535561
const StringVector &mathJaxExtensions = Config_getList(MATHJAX_EXTENSIONS);
536562
for (const auto &s : mathJaxExtensions)
537563
{
538-
mathJaxJs+= ", \""+QCString(s.c_str())+".js\"";
564+
mathJaxJs+= ", \""+QCString(s)+".js\"";
539565
}
540566
if (mathJaxFormat.isEmpty())
541567
{
@@ -3291,7 +3317,7 @@ void HtmlGenerator::writeExternalSearchPage()
32913317
const StringVector &extraSearchMappings = Config_getList(EXTRA_SEARCH_MAPPINGS);
32923318
for (const auto &ml : extraSearchMappings)
32933319
{
3294-
QCString mapLine = ml.c_str();
3320+
QCString mapLine(ml);
32953321
int eqPos = mapLine.find('=');
32963322
if (eqPos!=-1) // tag command contains a destination
32973323
{

0 commit comments

Comments
 (0)