Skip to content

Render TeX math spans via JLaTeXMath#7

Merged
koppor merged 1 commit into
mainfrom
render-tex-math
Jul 7, 2026
Merged

Render TeX math spans via JLaTeXMath#7
koppor merged 1 commit into
mainfrom
render-tex-math

Conversation

@koppor

@koppor koppor commented Jul 7, 2026

Copy link
Copy Markdown
Member

What

Adds TeX math rendering to html-to-node. When HtmlRenderOptions.renderMath is enabled, $…$ / \(…\) (inline) and $$…$$ / \[…\] (display) spans in text runs are recognized and typeset with JLaTeXMath into baseline-aligned, color-matched image nodes; unparseable TeX falls back to its verbatim source.

Details

  • MathSegmenter splits math out of the parsed model using Pandoc's delimiter heuristics (currency like $5 and $10 stays text; \$ is a literal dollar; code, links and <pre> are never scanned).
  • MathRendering rasterizes via JLaTeXMath (2× supersampling for glyph quality) and tracks the surrounding text color through the html-text CSS class.
  • Wired into both renderers (FxRenderer, RichTextRenderer), PlainText (round-trips the source for copy), and BlockCollector.
  • JLaTeXMath 1.0.7 ships no module descriptor and splits its optional Greek/Cyrillic fonts into resource-only companion jars, so it is turned into one proper module (fonts merged) via the extra-java-module-info plugin — the same approach JabRef's own build uses.

Tests

  • MathSegmenterTest (headless): delimiters, Pandoc heuristics, \$ escaping, code/link exclusion, plain-text round-trip, isRenderable.
  • MathRenderingTest (gui): real end-to-end rendering plus the unparseable-TeX fallback.

All existing tests pass.

🤖 Generated with Claude Code

Recognize $…$ / \(…\) (inline) and $$…$$ / \[…\] (display) math in text
runs when HtmlRenderOptions#renderMath is enabled, and typeset them with
JLaTeXMath into baseline-aligned image nodes — falling back to the source
text when the TeX does not parse. Delimiter recognition follows Pandoc's
heuristics (currency like "$5 and $10" stays text; code, links and <pre>
are never scanned); an escaped \$ is a literal dollar.

jlatexmath ships no module descriptor and splits its optional fonts into
resource-only companion jars, so it is turned into one proper module (fonts
merged in) via the extra-java-module-info Gradle plugin, matching JabRef's
own build.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@koppor koppor merged commit 4ec2303 into main Jul 7, 2026
2 checks passed
@koppor koppor deleted the render-tex-math branch July 7, 2026 23:37
koppor added a commit that referenced this pull request Jul 7, 2026
The click handler resolves a link via getStyleAttributeMap(...).get(HREF).
Node segments (embedded images, tables) have no character attributes, so
the model returns a null attribute map at their position — clicking a
book-cover image therefore lands on a null map. The inline guard added in
#7 already tolerates this; extracting it into a public
hrefAt(model, position) helper makes the guard unit-testable without the
JavaFX toolkit and gives callers that install their own click handler a
supported way to resolve the target at a position.

Adds headless regression tests: hrefAt returns null (no throw) at an
inline image's position, and still resolves the target for a real link run.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Siedlerchr Siedlerchr restored the render-tex-math branch July 8, 2026 10:52
Siedlerchr added a commit that referenced this pull request Jul 8, 2026
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