Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New approach to preventing image overflow in LaTeX (fixes #9660) #9666

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jgm
Copy link
Owner

@jgm jgm commented Apr 18, 2024

Instead of relying on graphicx internals, we now define a macro that gets used with images when explicit size information is not provided. This macro prevents the image from overflowing vertically or horizontally.

Templates will have to be updated to include the new macro.

Closes #9660.

The macro should be credited to @mrpiggi. See mrpiggi/svg#60 for discussion.

Previously we relied on graphicx internals and made global
changes to Gin to force images to be resized if they exceed
textwidth.  This approach is brittle and caused problems
with `\includesvg` (see #9660).

The new approach uses a new macro `\pandocbounded` that is
now defined in the LaTeX template. (Thanks here to Falk Hanisch in
mrpiggi/svg#60.)

The LaTeX writer has been changed to enclose `\includegraphics`
and `\includesvg` commands in this macro when they don't explicitly
specify a width or height.

Compatibility issues:  if custom templates are used with the
new LaTeX writer, they will have to be updated to include the
new `\pandocbounded` macro, or an error will be raised because
of the undefined macro.

Closes #9660.
@tarleb
Copy link
Collaborator

tarleb commented May 10, 2024

An approach like this might make it necessary to reconsider #8249. Or maybe to publish a pandoc CTAN package, as the growing number of custom commands makes it increasingly difficult to maintain custom LaTeX templates.

@jgm
Copy link
Owner Author

jgm commented May 11, 2024

@tarleb I think I'd rather not publish a pandoc CTAN package; that's one more maintenance step required in every release. Big changes like this are relatively rare, but in general one does have to keep an eye on template changes if one uses custom templates.

I don't remember why I haven't merged this yet. I suppose it's because I'm worried about people who will use custom templates with the new pandoc and get errors about undefined \pandocbounded. Do you think we should hold off or merge it? It does solve a real problem.

#8249 is still a cool idea and would largely avoid issues like this; I just haven't gotten around to exploring it.

@tarleb
Copy link
Collaborator

tarleb commented May 11, 2024

I'm torn. On one hand I worry about how much this would impact the usefulness of LaTeX snippets, and how the snippets are becoming more pandoc-specific. On the other hand, I fully agree that this solves a real problem, and I'm aware that some people, all of whom know much more about LaTeX than I do, have been complaining about the current image scaling method.

Adding a plain flag will certainly lead to discussions about what exactly clean LaTeX output looks like, so that's a risky step, too. But I think it would currently be my favored approach.

@jgm
Copy link
Owner Author

jgm commented May 11, 2024

We're already using some pandoc-specific things in our output, e.g. \tightlist.

@jgm
Copy link
Owner Author

jgm commented May 11, 2024

In principle, we could omit the \pandocbounded when writerTemplate is Nothing.
This would make fragments more "plain," at the cost of introducing a potentially confusing mismatch between fragment and standalone output.

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.

Large SVGs are rendered incorrectly in latex output
4 participants