From abd6a790ba8f03b379cacea43eaa06cb409889fb Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Wed, 5 Aug 2026 11:07:25 +0800 Subject: [PATCH] Configure MathJax overflow handling (#986) --- _config.yml | 2 ++ source/css/_common/components/third-party/math.styl | 2 +- source/js/third-party/math/mathjax.js | 12 ++++++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/_config.yml b/_config.yml index 6e7789d..1876bae 100644 --- a/_config.yml +++ b/_config.yml @@ -572,6 +572,8 @@ math: enable: false # Available values: none | ams | all tags: none + # Available values: overflow | scroll | scale | truncate | linebreak + display_overflow: scroll katex: enable: false diff --git a/source/css/_common/components/third-party/math.styl b/source/css/_common/components/third-party/math.styl index 7837b3d..a8e3701 100644 --- a/source/css/_common/components/third-party/math.styl +++ b/source/css/_common/components/third-party/math.styl @@ -1,5 +1,5 @@ if (hexo-config('math.mathjax.enable')) { - mjx-container[jax='CHTML'][display='true'], .has-jax { + .has-jax { overflow: auto hidden; } diff --git a/source/js/third-party/math/mathjax.js b/source/js/third-party/math/mathjax.js index 486f18c..93fd5ec 100644 --- a/source/js/third-party/math/mathjax.js +++ b/source/js/third-party/math/mathjax.js @@ -4,6 +4,12 @@ document.addEventListener('page:loaded', () => { if (!CONFIG.enableMath) return; if (typeof MathJax === 'undefined') { + const output = { + displayOverflow: CONFIG.mathjax.display_overflow + }; + if (CONFIG.mathjax.font_path) { + output.fontPath = CONFIG.mathjax.font_path; + } window.MathJax = { tex: { inlineMath: { '[+]': [['$', '$']] }, @@ -12,7 +18,7 @@ document.addEventListener('page:loaded', () => { options: { renderActions: { insertedScript: [200, () => { - document.querySelectorAll('mjx-container').forEach(node => { + document.querySelectorAll('mjx-container:not([display])').forEach(node => { const target = node.parentNode; if (target.nodeName.toLowerCase() === 'li') { target.parentNode.classList.add('has-jax'); @@ -21,9 +27,7 @@ document.addEventListener('page:loaded', () => { }, '', false] } }, - output: CONFIG.mathjax.font_path ? { - fontPath: CONFIG.mathjax.font_path - } : {} + output }; NexT.utils.getScript(CONFIG.mathjax.js, { attributes: {