Render TeX math in the entry preview - #16198
Closed
koppor wants to merge 1 commit into
Closed
Conversation
Enable html-to-node's math rendering (HtmlRenderOptions#renderMath) in PreviewViewer so $…$/$$…$$ in fields such as the abstract and comment are typeset as equations instead of shown as raw TeX. The default preview layout runs those fields through HTMLChars, whose LaTeX-command handling would otherwise strip or mangle math delimiters. A new opt-in HTMLChars(preserveMath) argument lifts $…$ / $$…$$ / \(…\) / \[…\] spans out before conversion and splices them back verbatim (only <>& escaped), leaving the shared default behaviour used by exports untouched. The default preview layout and a preferences migration switch the abstract to HTMLChars(preserveMath) and the comment to HTMLChars(keepCurlyBraces,preserveMath). jlatexmath (pulled in transitively via html-to-node) is registered as a proper module with its font companion jars merged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Member
|
Math was already rendered. Only subscribt and superscript were not properly rendered |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issues and pull requests
Depends on JabRef/html-to-node#7 (adds the
renderMathsupport this PR turns on). Originates from the math-in-preview request in #16145.PR Description
🤖 Enables TeX math rendering in the entry preview.
PreviewViewerturns on html-to-node'srenderMath, and the default preview layout runs the abstract and comment through a new opt-inHTMLChars(preserveMath)argument. That argument lifts$…$/$$…$$/\(…\)/\[…\]spans out before the formatter's LaTeX-command handling (which otherwise strips or mangles them, e.g.$\sigma$→$$) and splices them back verbatim — only<,>,&escaped — so the renderer receives intact TeX. The sharedHTMLCharsbehaviour used by exports is unchanged. A preferences migration applies the same switch to existing custom preview styles, and JLaTeXMath (pulled in transitively via html-to-node) is registered as a proper JPMS module with its font companion jars merged.This is a draft: it depends on JabRef/html-to-node#7 being merged and its
0.1.0-SNAPSHOTrepublished before CI can resolvewithRenderMath; until then the build only succeeds locally with-PuseMavenLocal. Remaining steps once #7 lands: add aCHANGELOG.mdentry and requirements doc, attach the required screenshots, and run the fullcheck/checkstyle/modernizer/javadocsuite.Analogies
Like honey, this change is sweet in small amounts — a crisp equation where raw
$…$used to sit. Like chocolate, it melts the delimiters away cleanly, but only if handled with care, or it smears (hence the deliberate span-protection instead of letting the formatter chew the TeX). And like the moon, the math was always there in the field text, orbiting unseen; this PR just turns the preview to face it so it finally shows.jabref-contrib-policy:4.2:reviewed:ok
Steps to test
abstract(orcomment) contains TeX math, for example:The relation $E=mc^2$ and the integral $$\int_{-\infty}^{\infty} e^{-x^2}\,dx = \sqrt{\pi}$$, with a fraction $\frac{a}{b}$. Prices like \$5 stay literal.$…$and$$…$$spans render as typeset equations,\$5shows as a literal$(not math), and non-math LaTeX such as accents still converts as before.Screenshot of the rendered preview to be attached (the layout → html-to-node pipeline renders
$E=mc^2$, the Gaussian integral,$\frac{a}{b}$, and a literal$5).AI usage
Claude Code (model claude-opus-4-8).
AI CHECKLIST.md walkthrough
1. Code self-review
Nullability and control flow
== null/!= nullchecks — none added in this diff.Objects.requireNonNull(...)— none added.@NullMarked— no new classes added (only methods/fields on existingHTMLChars).Optionalconsumed withifPresent/… — noOptionalin the diff.StringUtil.isBlank(...)— no blank checks in the diff.Exceptions
catch (Exception e)— no catches added.throw new RuntimeException(...)/IllegalStateException(...)— none added.Style and idioms
BibEntryobjects built with withers — noBibEntryconstruction.Patternconstant; no legacy idioms introduced.Pattern.compile(...)constant —MATH_SPANis astatic final Pattern.BackgroundTask— no background work.///) uses Markdown syntax (`code`,[Type]), not{@code}/{@link}.User-facing text
!/ no trailing:— n/a.Security
<,>,&viaescapeHtmlSpecialsbefore entering the HTML preview.Tests
logichave added/updated tests —HTMLCharsTest(preserveMath, combined argument) andGuiPreferencesMigrationsTest.assertEquals, no@DisplayName, do not catch exceptions, no manual temp dirs.2. Verification commands
./gradlew :jablib:check— not yet run (draft); ran targetedHTMLCharsTest+GuiPreferencesMigrationsTest+:jabgui:compileJava, all green (with-PuseMavenLocal)../gradlew checkstyleMain checkstyleTest checkstyleJmh— not yet run (draft)../gradlew modernizer— not yet run (draft)../gradlew rewriteRunreports no changes — ran, clean../gradlew javadoc— not yet run (draft).markdownlint— no Markdown changed.idea formatapplied locally against.idea/codeStyles/Project.xml.3. Documentation
CHANGELOG.mdentry — TODO (draft; user-visible change).closes.docs/requirements/— TODO (draft; new feature).4. Pull request
.github/PULL_REQUEST_TEMPLATE.md, every section filled.gh pr create --body-file.CHANGELOG.mdTODOplaceholder replaced with the PR number — no CHANGELOG entry yet (draft).Checklist
CHANGELOG.mdin a way that can be understood by the average user (if change is visible to the user)🤖 Generated with Claude Code