Fix #125: TeX/LaTeX formula rendering in chart titles, axis titles, tick labels, and legend entries#952
Closed
timmolter wants to merge 1 commit into
Closed
Conversation
5842f0b to
edd14d1
Compare
… tick labels, and legend entries Add JLatexMath (org.scilab.forge:jlatexmath:1.0.7) as an optional dependency. Any string wrapped in $...$ is rendered as a LaTeX math formula using JLatexMath. All other strings continue to use the existing TextLayout rendering path — no behaviour change for existing charts. If JLatexMath is not on the classpath the TeX strings fall back gracefully to plain-text display. ### Licensing — fully clear JLatexMath is GPL v2 with the Classpath Exception (linking exception). This exception permits JLatexMath to be linked from software distributed under any licence, including XChart's Apache 2.0. The exception was added in commit f173337015d89e29b8b2fa05de2c1f0e03ff8e3f on 2026-01-19, with the commit message: "Change licence by adding linking exception. Discussed here: https://forge.scilab.org/index.php/p/jlatexmath/issues/1566/" That scilab issue (#1566) is exactly the one that timmolter referenced in XChart issue #125 on 2016-01-07 when he said: "They need to add the part about 'GPL with classpath exception' to their LICENSE… Until that exists, the license is incompatible with XChart's." The condition was met ten years ago, and JLatexMath 1.0.7 has been on Maven Central ever since. ### Changes * pom.xml — add jlatexmath 1.0.7 to dependencyManagement (optional) * xchart/pom.xml — declare jlatexmath optional dependency * TexRenderer.java — new utility: isTeX(), getBounds(), render(), renderRotated() with Class.forName guard for graceful runtime fallback * ChartTitle.java — delegate title sizing + paint to TexRenderer * AxisTitle.java — delegate X and Y axis title sizing + paint to TexRenderer; Y-axis rotation handled via BufferedImage intermediate * AxisTickLabels.java — delegate per-tick sizing + paint to TexRenderer for both X and Y axes (Y-axis uses a parallel String map alongside TextLayout map) * Legend_.java — delegate getSeriesTextBounds() + paintSeriesText() to TexRenderer * TestForIssue125.java — demo: XY chart with TeX title/axis-titles/legend entries + category chart with TeX tick labels * TexRendererTest.java — 10 unit tests covering detection, bounds, and fallback Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
edd14d1 to
f213dce
Compare
Member
Author
|
Closing to rethink integration approach before re-opening. TexRenderer utility and demo are working; need to reconsider the minimal-footprint integration into core rendering classes. |
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.
Summary
Adds LaTeX math formula rendering to all chart text elements via JLatexMath.
Any string wrapped in
$...$is rendered as a display-mode LaTeX formula. Strings without the$wrapper continue to use the existingTextLayoutpath unchanged — no behaviour change for existing charts.Licensing — why this is safe now
JLatexMath is GPL v2. The original blocker (noted in this issue in 2016) was that the GPL licence is incompatible with XChart's Apache 2.0 without the Classpath Exception (linking exception).
That exception was added to JLatexMath in commit
f173337on 2016-01-19 with the message:That scilab issue #1566 is exactly the thread @timmolter referenced in his 2016 comment when he wrote:
The condition was met ~ten years ago. JLatexMath 1.0.7 has been on Maven Central since then with the Classpath Exception present.
Optional dependency
JLatexMath is declared
<optional>true</optional>inxchart/pom.xml— exactly likeVectorGraphics2D. Users who don't need TeX rendering do not need to add anything to their build.If JLatexMath is not on the classpath,
TexRenderer.isAvailable()returnsfalseand$...$strings fall back to plain text (no exceptions).To opt in, add to your own
pom.xml:Implementation details
pom.xmljlatexmath 1.0.7to<dependencyManagement>xchart/pom.xmljlatexmathas optional depTexRenderer.java(new)isTeX(),getBounds(),render(),renderRotated()with runtime guardChartTitle.javaTexRendererAxisTitle.javaBufferedImageintermediateAxisTickLabels.javaLegend_.javagetSeriesTextBounds()+paintSeriesText()TestForIssue125.java(new)TexRendererTest.java(new)Coordinate system note
TeXIconuses top-left origin whileTextLayoutuses a baseline origin.TexRenderercompensates so TeX and plain-text elements align consistently.Rotated Y-axis title
JLatexMath's
paintIcondoesn't compose cleanly with pre-appliedAffineTransformrotations. The Y-axis title is therefore rendered to an off-screenBufferedImage, then drawn with a −90° rotation — correct orientation with no rendering artefacts.Tests
mvn fmt:checkpasses with no violations.Closes #125