Skip to content

Fix cropped LaTeX previews and PGF rendering in view() - #42620

Open
cxzhong wants to merge 2 commits into
sagemath:developfrom
cxzhong:agent/gh-41445-corrected-view
Open

Fix cropped LaTeX previews and PGF rendering in view()#42620
cxzhong wants to merge 2 commits into
sagemath:developfrom
cxzhong:agent/gh-41445-corrected-view

Conversation

@cxzhong

@cxzhong cxzhong commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • make preview tight-page cropping work with LuaLaTeX without adding a global luatex85 dependency;
  • capture resized PGF output inside the page environment selected by preview;
  • preserve the existing math-mode rendering path for TikZ expressions;
  • share preview option construction between view() and pdf() and add regression doctests.

Root cause

Recent LuaTeX versions renamed the pdfTeX primitives still used by the preview package, so preview produced a normal full-size page instead of a tightly cropped page. This change defines only the five compatibility aliases that preview uses, and only when LuaTeX exposes the renamed primitives.

Separately, _latex_file_ rendered PGF through a resize box but left that box outside the page environment, so preview did not capture it. The resize box is now enclosed in page when preview mode is active.

This is a revised approach to #41445. It avoids requiring the optional luatex85 package for every generated LaTeX document and does not route ordinary TikZ expressions out of their existing math mode.

Fixes #41413.
Fixes #41443.

Validation

  • git diff --check
  • Python syntax compilation of src/sage/misc/latex.py
  • changed-diff relint with warnings treated as errors
  • focused LaTeX integration checks:
    • LuaLaTeX scalar preview: tightly cropped to 5.981 x 7.42 pt
    • PDFLaTeX PGF preview: nonempty 11.362 x 11.362 pt PDF
    • PDFLaTeX math-mode TikZ preview: nonempty 29.745 x 29.745 pt PDF

The full Sage doctest suite was not run locally because the available environment does not include the GAP executable; GitHub CI will run the repository test matrix.

@cxzhong
cxzhong requested review from fchapoton and kwankyu August 3, 2026 18:59
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

Documentation preview for this PR (built with commit 98c89dd; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@cxzhong
cxzhong marked this pull request as ready for review August 4, 2026 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant