Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,19 @@ math:
enable: false
# See: https://mhchem.github.io/MathJax-mhchem/
mhchem: false
# For hexo-renderer-marked, the default renderer of Hexo, some math equations with
# multiple subscribe mark of LaTeX (say, the underscore `_`) might cause problems.
# Enable this flag could bypass this problem by wrap your math codes in the inline-math_in_verbatim
# marks of Markdown, say, the backquote pair.
# For example,
# ```
# $ E = mc^2 $.
# ```
# could be replaced by
# ```
# `$ E = mc^2 $`.
# ```
math_in_verbatim: false

# hexo-renderer-markdown-it-plus (or hexo-renderer-markdown-it with markdown-it-katex plugin) required for full Katex support.
katex:
Expand Down
28 changes: 22 additions & 6 deletions layout/_third-party/math/mathjax.swig
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
{%- set mathjax_uri = theme.vendors.mathjax or '//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js' %}

<script>
{%- if theme.math.mathjax.math_in_verbatim %}
document.querySelectorAll('code').forEach(code => {
const text = code.innerHTML;
// is_inline_math = /^\$(.*)\$$/.exec(text) || /^\\\((.*)\\\)$/.exec(text);
// is_display_math = /^\$\$(.*)\$\$$/ms.exec(text) || /^\\begin\{.+\}(.*)\\end\{.+\}/ms.exec(text);
if (/^\$\$(.*)\$\$$/ms.exec(text) || /^\\begin\{.+\}(.*)\\end\{.+\}/ms.exec(text)) {
code.outerHTML = "<span class='theme_next_mathjax_display has-jax'>" + text + "</span>";
} else if (/^\$(.*)\$$/.exec(text) || /^\\\((.*)\\\)$/.exec(text)) {
code.outerHTML = "<span class='theme_next_mathjax_inline has-jax'>" + text + "</span>";
}
});
{%- endif %}
if (typeof MathJax === 'undefined') {
window.MathJax = {
{%- if theme.math.mathjax.mhchem %}
loader: {
load: ['[tex]/mhchem']
},
{%- endif %}
loader: {
{%- if theme.math.mathjax.mhchem %}
load: ['[tex]/ams', '[tex]/mhchem'],
{%- else %}
load: ['[tex]/ams'],
{%- endif %}
},
tex: {
inlineMath: {'[+]': [['$', '$']]},
{%- if theme.math.mathjax.mhchem %}
packages: {'[+]': ['mhchem']},
packages: {'[+]': ['ams', 'mhchem']},
{%- else %}
packages: {'[+]': ['ams']},
{%- endif %}
tags: 'ams'
},
Expand Down