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

Large SVGs are rendered incorrectly in latex output #9660

Open
ChrisJefferson opened this issue Apr 16, 2024 · 4 comments · May be fixed by #9666
Open

Large SVGs are rendered incorrectly in latex output #9660

ChrisJefferson opened this issue Apr 16, 2024 · 4 comments · May be fixed by #9666
Labels

Comments

@ChrisJefferson
Copy link

ChrisJefferson commented Apr 16, 2024

Explain the problem.

Firstly, I just want to mention this is not an issue with pandoc's internal translation of svgs to pdf. That works fine! The issue here is when svgs are outputted into 'latex'.

Consider the following one line markdown document, using this svg:

bubbleup

![](bubbleup.svg)

If we build this by doing:

pandoc pan.md --to latex -o pan.tex -s

pdflatex --shell-escape pan.tex (--shell-escape is required as we have an svg inside the tex file. The latex svg package will invoke inkscape to render the svg).

Then the output is badly corrupted.

This happens (I think) because the SVG needs to be resized, and the resizing doesn't work correctly due to the setting of Gin in the \setkeys{Gin}{...} line of the latex template. I raised this issue with the svg latex package here: mrpiggi/svg#60 , where I was told setting Gin in this way isn't supported.

The reason the bad rendering happens at all is by default the latex svg package extracts text from the svg and renders it using the latex engine. The resizing is messing up the placement of this text.

This could be fixed by setting inkscapelatex in the svg package to false. This makes the svg latex package just render the svg to a single PDF and everything works fine. This would stop text in SVGs being rendered as latex, if anyone was using that functionality (they can of course get it back by editing the template).

The other option would be to disable auto-resizing, but that would effect all images (not just svg), and be much worse (as large pictures would overflow the page).

This problem was originally found as an issue in quarto, which does this two-step pass of using pandoc to turn markdown -> tex, then compiling the resulting tex.

Pandoc version?
Ubuntu 23.04

pandoc 3.1.13
Features: +server +lua
Scripting engine: Lua 5.4
User data directory: /home/caj/.local/share/pandoc
@jgm
Copy link
Owner

jgm commented Apr 16, 2024

This could be fixed by setting inkscapelatex in the svg package to false. This makes the svg latex package just render the svg to a single PDF and everything works fine. This would stop text in SVGs being rendered as latex, if anyone was using that functionality (they can of course get it back by editing the template).

This seems the best solution. I'll do that.

@jgm
Copy link
Owner

jgm commented Apr 16, 2024

OK, I tried this, and with \usepackage[inkscapelatex=false]{svg} I get an incredibly small image (about 1em?). Without the option I get a big image, but corrupted as you say.

@mrpiggi
Copy link

mrpiggi commented Apr 16, 2024

See mrpiggi/svg#60 (comment), especially the last two paragraphs.

@jgm
Copy link
Owner

jgm commented Apr 16, 2024

Quoting from that comment:

it needs to be ensured, that $if(graphics)$ is set in case $if(svg)$ is required ...

This is already ensured.

But I guess the main point is that we need to always specify an explicit size with an SVG. I think we should just be able to read size information from the SVG and add the size attribute if it's missing....

jgm added a commit that referenced this issue Apr 18, 2024
Remove old method of scaling images so they don't overflow.
This relied on graphicx internals and made global changes that
caused problems with includesvg (see #9660).

Instead, add a macro `\pandocbounded` that will do this on
a local basis.  We will have to modify the writer to add
this explicitly when images lack explicit size information.
jgm added a commit that referenced this issue Apr 18, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants