Skip to content

Commit

Permalink
Optimized MathJax HTML output and made the template output the same.
Browse files Browse the repository at this point in the history
  • Loading branch information
doxygen committed May 24, 2021
1 parent 8fa6f9c commit 9822bab
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 63 deletions.
20 changes: 15 additions & 5 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,13 @@ class DoxygenContext::Private
{
return dateToString(TRUE);
}
TemplateVariant maxJaxCodeFile() const
TemplateVariant mathJaxCodeFile() const
{
return m_cache.maxJaxCodeFile;
return m_cache.mathJaxCodeFile;
}
TemplateVariant mathJaxMacros() const
{
return m_cache.mathJaxMacros;
}
Private()
{
Expand All @@ -409,7 +413,9 @@ class DoxygenContext::Private
//%% string date
s_inst.addProperty("date", &Private::date);
//%% string maxJaxCodeFile
s_inst.addProperty("mathJaxCodeFile", &Private::maxJaxCodeFile);
s_inst.addProperty("mathJaxCodeFile", &Private::mathJaxCodeFile);
//%% string maxJaxMacros
s_inst.addProperty("mathJaxMacros", &Private::mathJaxMacros);
init=TRUE;
}
}
Expand All @@ -424,8 +430,12 @@ class DoxygenContext::Private
private:
struct Cachable
{
Cachable() { maxJaxCodeFile=fileToString(Config_getString(MATHJAX_CODEFILE)); }
QCString maxJaxCodeFile;
Cachable() {
mathJaxCodeFile=fileToString(Config_getString(MATHJAX_CODEFILE));
mathJaxMacros=HtmlGenerator::getMathJaxMacros();
}
QCString mathJaxCodeFile;
QCString mathJaxMacros;
};
mutable Cachable m_cache;
static PropertyMapper<DoxygenContext::Private> s_inst;
Expand Down
91 changes: 41 additions & 50 deletions src/htmlgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,19 +449,25 @@ static QCString substituteHtmlKeywords(const QCString &str,

if (mathJaxVersion == "MathJax_3")
{
mathJaxJs += "<script src=\"https://polyfill.io/v3/polyfill.min.js?features=es6\"></script>\n";
mathJaxJs += "<script>\n"
" window.MathJax = {\n"
" options: {\n"
" ignoreHtmlClass: 'tex2jax_ignore',\n"
" processHtmlClass: 'tex2jax_process'\n"
" },\n";
mathJaxJs += "<script src=\"https://polyfill.io/v3/polyfill.min.js?features=es6\"></script>\n"
"<script type=\"text/javascript\">\n"
"window.MathJax = {\n"
" options: {\n"
" ignoreHtmlClass: 'tex2jax_ignore',\n"
" processHtmlClass: 'tex2jax_process'\n"
" }";
const StringVector &mathJaxExtensions = Config_getList(MATHJAX_EXTENSIONS);
if (!mathJaxExtensions.empty() || !g_latex_macro.isEmpty())
{
mathJaxJs+= " tex: {\n"
" macros: {},\n"
" packages: ['base','configmacros'";
mathJaxJs+= ",\n"
" tex: {\n"
" macros: {";
if (!g_latex_macro.isEmpty())
{
mathJaxJs += g_latex_macro+" ";
}
mathJaxJs+="},\n"
" packages: ['base','configmacros'";
if (!g_latex_macro.isEmpty())
{
mathJaxJs+= ",'newcommand'";
Expand All @@ -471,46 +477,30 @@ static QCString substituteHtmlKeywords(const QCString &str,
mathJaxJs+= ",'"+QCString(s.c_str())+"'";
}
mathJaxJs += "]\n"
" }\n";
" }\n";
}
mathJaxJs += " };\n";
mathJaxJs += "</script>\n";

if (!g_latex_macro.isEmpty())
else
{
mathJaxJs += "<script>\n"
" Object.assign(MathJax.tex.macros, {\n";
mathJaxJs += g_latex_macro;
mathJaxJs += "\n"
" });\n"
"</script>\n";
mathJaxJs += "\n";
}

mathJaxJs += "};\n";
// MATHJAX_CODEFILE
if (!g_mathjax_code.isEmpty())
{
mathJaxJs += "<script>\n";
mathJaxJs += g_mathjax_code;
mathJaxJs += "\n";
mathJaxJs += "</script>\n";
}
mathJaxJs += "</script>\n";


mathJaxJs += "<script type=\"text/javascript\" id=\"MathJax-script\" async=\"async\" src=\"" + path;
if (mathJaxFormat == "chtml")
{
mathJaxJs += "es5/tex-chtml.js\"></script>\n" ;
}
else if (mathJaxFormat == "SVG")
{
mathJaxJs += "es5/tex-svg.js\"></script>\n" ;
}
mathJaxJs += "<script type=\"text/javascript\" id=\"MathJax-script\" async=\"async\" src=\"" +
path + "es5/tex-" + mathJaxFormat.lower() + ".js\">";
mathJaxJs+="</script>\n";
}
else
else // MathJax v2
{
mathJaxJs = "<script type=\"text/x-mathjax-config\">\n"
" MathJax.Hub.Config({\n"
" extensions: [\"tex2jax.js\"";
"MathJax.Hub.Config({\n"
" extensions: [\"tex2jax.js\"";
const StringVector &mathJaxExtensions = Config_getList(MATHJAX_EXTENSIONS);
for (const auto &s : mathJaxExtensions)
{
Expand All @@ -521,25 +511,21 @@ static QCString substituteHtmlKeywords(const QCString &str,
mathJaxFormat = "HTML-CSS";
}
mathJaxJs += "],\n"
" jax: [\"input/TeX\",\"output/"+mathJaxFormat+"\"],\n"
"});\n";
" jax: [\"input/TeX\",\"output/"+mathJaxFormat+"\"],\n";
if (!g_latex_macro.isEmpty())
{
mathJaxJs += " TeX: { Macros: {\n";
mathJaxJs += g_latex_macro;
mathJaxJs += "\n"
" } }\n";
}
mathJaxJs += "});\n";
if (!g_mathjax_code.isEmpty())
{
mathJaxJs += g_mathjax_code;
mathJaxJs += "\n";
}
mathJaxJs += "</script>\n";
if (!g_latex_macro.isEmpty())
{
mathJaxJs += "<script type=\"text/x-mathjax-config\">\n"
" MathJax.Hub.Config({\n"
" TeX: { Macros: {\n";
mathJaxJs += g_latex_macro;
mathJaxJs += "\n"
" } }\n"
"});\n"
"</script>\n";
}
mathJaxJs += "<script type=\"text/javascript\" async=\"async\" src=\"" + path + "MathJax.js\"></script>\n";
}
}
Expand Down Expand Up @@ -3066,3 +3052,8 @@ void HtmlGenerator::addWord(const QCString &word,bool hiPriority)
Doxygen::searchIndex->addWord(word,hiPriority);
}
}

QCString HtmlGenerator::getMathJaxMacros()
{
return getConvertLatexMacro();
}
1 change: 1 addition & 0 deletions src/htmlgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class HtmlGenerator : public OutputGenerator
static void writeExternalSearchPage();
static QCString writeLogoAsString(const QCString &path);
static QCString writeSplitBarAsString(const QCString &name,const QCString &relpath);
static QCString getMathJaxMacros();

// ---- CodeOutputInterface
void codify(const QCString &text)
Expand Down
31 changes: 27 additions & 4 deletions templates/html/htmlbase.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,37 @@
{% endif %}
{% endif %}
{% if config.USE_MATHJAX %}
{% if config.MATHJAX_VERSION=="MathJax_3" %}
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script type="text/javascript">
window.MathJax = {
options: {
ignoreHtmlClass: 'tex2jax_ignore',
processHtmlClass: 'tex2jax_process'
},
tex: {
{% if doxygen.mathJaxMacros %}
macros: { {{ doxygen.mathJaxMacros|raw }} },
{% endif %}
packages: ['base','configmacros'{% if doxygen.mathJaxMacros %},'newcommand'{% endif %}{% for ext in config.MATHJAX_EXTENSIONS %},'{{ ext }}'{% endfor %}]
}
};
{{ doxygen.mathJaxCodeFile }}
</script>
<script type="text/javascript" id="MathJax-script" async="async" src="{{ config.MATHJAX_RELPATH }}{% if config.MATHJAX_RELPATH|relative %}{{ page.relPath }}{% endif %}es5/tex-{{ config.MATHJAX_FORMAT|lower }}.js"></script>
{% else %}{# MathJax_2 #}
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js"{% for ext in config.MATHJAX_EXTENSIONS %}, "{{ ext }}"{% endfor %}],
jax: ["input/TeX","output/{{ config.MATHJAX_FORMAT|default:'HTML-CSS' }}"],
MathJax.Hub.Config({
extensions: ["tex2jax.js"{% for ext in config.MATHJAX_EXTENSIONS %}, "{{ ext }}.js"{% endfor %}],
jax: ["input/TeX","output/{{ config.MATHJAX_FORMAT|default:'HTML-CSS' }}"],
{% if doxygen.mathJaxMacros %}
TeX: { Macros: { {{ doxygen.mathJaxMacros|raw }} } }
{% endif %}
});
{{ doxygen.mathJaxCodeFile }}
</script>
<script type="text/javascript" src="{{ config.MATHJAX_RELPATH }}{% if config.MATHJAX_RELPATH|relative %}{{ page.relPath }}{% endif %}MathJax.js"></script>
<script type="text/javascript" async="async" src="{{ config.MATHJAX_RELPATH }}{% if config.MATHJAX_RELPATH|relative %}{{ page.relPath }}{% endif %}MathJax.js"></script>
{% endif %}{# MathJax_3 #}
{% endif %}{# MathJax #}
<link href="{{ page.relPath }}{{ config.HTML_STYLESHEET|default:'doxygen.css' }}" rel="stylesheet" type="text/css" />
{% if config.HTML_EXTRA_STYLESHEET %}
Expand Down
2 changes: 1 addition & 1 deletion templates/html/htmljsmenudata.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var menudata={children:[
,{text:"{{ tr.classes }}",url:"annotated{{ config.HTML_FILE_EXTENSION }}",children:[
{text:"{{ tr.classList }}",url:"annotated{{ config.HTML_FILE_EXTENSION }}"}
,{text:"{{ tr.classIndex }}",url:"classes{{ config.HTML_FILE_EXTENSION }}"}
{% if classHierarchy.tree %}
{% if classHierarchy.tree and classHierarchy.maxDepth>1 %}
,{text:"{{ tr.classHierarchy }}",url:"hierarchy{{ config.HTML_FILE_EXTENSION }}"}
{% endif %}
{% if classMembersIndex.all %}
Expand Down
4 changes: 3 additions & 1 deletion templates/html/htmllayout.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
{% resource 'nav_f.lum' %}
{% resource 'nav_g.png' %}
{% resource 'nav_h.lum' %}
{% if config.GENERATE_TREEVIEW %}
{% resource 'navtree.css' %}
{% resource 'navtree.js' %}
{% resource 'resize.js' %}
{% endif %}
{% resource 'menu.js' %}
{% resource 'doc.luma' %}
{% resource 'folderopen.luma' %}
Expand Down Expand Up @@ -221,7 +223,7 @@
{% endif %}
{# write the class inheritance hierarchy #}
{% if classHierarchy.tree %}
{% if classHierarchy.tree and classHierarchy.maxDepth>1 %}
{% with page=classHierarchy %}
{% create classHierarchy.fileName|append:config.HTML_FILE_EXTENSION from 'htmlhierarchy.tpl' %}
{% if config.HAVE_DOT and config.GRAPHICAL_HIERARCHY %}
Expand Down
2 changes: 1 addition & 1 deletion templates/html/htmlpage.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<ul>
<li><a href="{{ page.relPath }}annotated{{ config.HTML_FILE_EXTENSION }}"><span>{{ tr.classList }}</span></a></li>
<li><a href="{{ page.relPath }}classes{{ config.HTML_FILE_EXTENSION }}"><span>{{ tr.classIndex }}</span></a></li>
{% if classHierarchy.tree %}
{% if classHierarchy.tree and classHierarchy.maxDepth>1 %}
<li><a href="{{ page.relPath }}hierarchy{{ config.HTML_FILE_EXTENSION }}"><span>{{ tr.classHierarchy }} </span></a></li>
{% endif %}
{% if classMembersIndex.all %}
Expand Down
2 changes: 1 addition & 1 deletion templates/html/htmltabs.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
{% if page.highlight=='classes' %}
<li{% if page.subhighlight=='classlist' %} class="current"{% endif %}><a href="{{ page.relPath }}annotated{{ config.HTML_FILE_EXTENSION }}"><span>{{ tr.classList|nowrap }}</span></a></li>
<li{% if page.subhighlight=='classindex' %} class="current"{% endif %}><a href="{{ page.relPath }}classes{{ config.HTML_FILE_EXTENSION }}"><span>{{ tr.classIndex|nowrap }}</span></a></li>
{% if classHierarchy.tree %}
{% if classHierarchy.tree and classHierarchy.maxDepth>1 %}
<li{% if page.subhighlight=='classhierarchy' %} class="current"{% endif %}><a href="{{ page.relPath }}hierarchy{{ config.HTML_FILE_EXTENSION }}"><span>{{ tr.classHierarchy|nowrap }}</span></a></li>
{% endif %}
{% if classMembersIndex.all %}
Expand Down

0 comments on commit 9822bab

Please sign in to comment.