Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More supports of MathJax3 #1378

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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