Skip to content

Fix block LaTeX rendering with SwiftMath display mode - #153

Open
manemajef wants to merge 1 commit into
nodes-app:mainfrom
manemajef:fix/block-latex-display-style
Open

Fix block LaTeX rendering with SwiftMath display mode#153
manemajef wants to merge 1 commit into
nodes-app:mainfrom
manemajef:fix/block-latex-display-style

Conversation

@manemajef

@manemajef manemajef commented Aug 12, 2026

Copy link
Copy Markdown

Summary

SwiftMathBridge currently renders both inline $ … $ and block $$ … $$
formulas using SwiftMath's text mode.

That gives block formulas inline typography: limits sit beside large operators,
fractions remain small, and operators do not scale as expected.

Comparison of inline and display LaTeX rendering

What changed

The parser already distinguishes inline and block LaTeX. This PR carries that
information through LatexRenderer:

  • inline and table formulas use .inline
  • block formulas use .display
  • SwiftMathBridge maps the mode to SwiftMath's labelMode
  • the render mode is part of the cache key, preventing inline and display
    results for the same formula from colliding

The Markdown source remains unchanged; no \displaystyle injection or content
transformation is involved.

Compatibility

Existing LatexRenderer conformers remain source-compatible. The new
mode-aware overload defaults to the original renderer method, so renderers that
do not distinguish the two modes continue working unchanged.

Direct calls to render(latex:fontSize:theme:) retain inline behavior.

Validation

  • swift build
  • swift test --parallel — 473 core tests and the SwiftMath regression test pass

@manemajef
manemajef marked this pull request as ready for review August 12, 2026 23:41
@manemajef
manemajef force-pushed the fix/block-latex-display-style branch from 439cc81 to b8cb75b Compare September 9, 2026 15:27
@manemajef manemajef changed the title Typeset block $$…$$ math in display style, not text style Fix block LaTeX rendering with SwiftMath display mode Sep 9, 2026
@manemajef

manemajef commented Sep 9, 2026

Copy link
Copy Markdown
Author

I rebased this onto the current main and tightened the patch after another
compatibility review. The original LatexRenderer method remains required, and
the new mode-aware overload has a one-way fallback to it, so existing conformers
continue to compile and behave as before.

I also removed unrelated documentation churn, reduced the SwiftMath regression
tests, added the required changelog entry, and reran swift build plus the full
test suite successfully. @luca-chen198, when you have a chance, could you take
another look?

The parser already distinguishes block and inline formulas, but that information was discarded before rendering. Carry the mode through the renderer boundary so block formulas use display typesetting, while legacy renderers continue to receive the existing call.

Include the mode in SwiftMath cache keys so an inline result cannot be reused for the same formula in display mode.
@manemajef
manemajef force-pushed the fix/block-latex-display-style branch from b8cb75b to 6051966 Compare September 9, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant