Compare commits

...
3 Commits
  • Merge pull request #1831 from LoveApple14434/fix/mathjax4-inline-linebreak
    fix(mathjax): keep MathJax 4 inline formulas on one line
  • fix(mathjax): cover all block containers for inline formula overflow
    Once mjx-container is forced to display: inline, its own max-width and
    overflow-x no longer apply to a non-replaced inline box, so the formula
    width escapes to the document. The previous rule only covered p and li.
    
    - cover headings (h1-h6) too, otherwise a long inline formula in a
      heading widens the page (measured 395px of horizontal page scroll at a
      420px viewport)
    - li becomes a scroll container, which clips its outside-positioned
      ::marker, so switch those items to list-style-position: inside
    - fall back to the previous inline-grid when :has() is unsupported,
      since the container rules are then dropped while display: inline still
      applies, which is worse than before
  • fix(mathjax): keep MathJax 4 inline formulas on one line
    MathJax 4 emits an inline formula as several <svg> chunks separated by
    <mjx-break> elements. The theme renders every non-display container as
    `display: inline-grid`, which turns each chunk into a grid item, so the
    chunks are stacked into 2-4 rows instead of flowing inline.
    
    Neither column flow nor flex keeps the MathJax layout: grid/flex ignore the
    per-chunk `vertical-align` (all chunks get top-aligned) and drop the space
    provided by <mjx-break>; `inline-block` would turn the scroll container's
    baseline into the bottom margin edge and inflate the line box.
    
    Keep the container inline -- the only layout that preserves chunk spacing,
    per-chunk vertical-align and the text baseline -- and use `white-space:
    nowrap` so MathJax's own inline line breaking cannot split it. Horizontal
    scrolling moves to the enclosing paragraph/list item, which only becomes a
    scroll container when it actually holds an inline formula, so overlong
    formulas scroll instead of widening the page. MathJax 3 output (a single
    <svg>) and display math are unaffected.
    
    Verified with the real theme CSS + hexo-filter-mathjax 0.11.1 output in
    headless Edge at 1280/430 px, against MathJax 3.2.2 as a regression check.
+29 -2
View File
@@ -270,7 +270,8 @@ if hexo-config('math.use')
if hexo-config('math.hide_scrollbar')
.katex-display,
mjx-container
mjx-container,
#article-container :is(p, li):has(mjx-container:not([display]))
scrollbar-width: none
&::-webkit-scrollbar
@@ -287,8 +288,34 @@ if hexo-config('math.use')
display: block !important
min-width: auto !important
// MathJax 4 splits an inline formula into several <svg> + <mjx-break>.
// Inline layout keeps the line spacing and each part's vertical-align,
// and nowrap keeps these parts on one line.
&:not([display])
display: inline-grid !important
display: inline !important
white-space: nowrap
// Let the block-level parent scroll instead of overflowing the page.
// p / li alone is not enough: headings and note bodies overflow too,
// because max-width no longer applies once mjx-container is inline.
#article-container :is(p, h1, h2, h3, h4, h5, h6):has(mjx-container:not([display]))
overflow-x: auto
// A scrolling li clips its outside-positioned ::marker.
#article-container li:has(mjx-container:not([display]))
overflow-x: auto
list-style-position: inside
// Without :has() the rules above are dropped while inline still applies.
// Fall back to the previous inline-grid rather than an unclipped inline.
@css {
@supports not selector(:has(a)) {
mjx-container:not([display]) {
display: inline-grid !important;
white-space: normal;
}
}
}
mjx-assistive-mml
right: 0