jgm/pandoc

Large SVGs are rendered incorrectly in latex output

ChrisJefferson opened this issue · 6 comments

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 commented

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 commented

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.

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

jgm commented

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....

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.

I found this issue from a Google search for the error message

Error producing PDF.
! Undefined control sequence.
l.452 \pandocbounded

If anyone else wants to see what template updates are needed, here is the commit: jgm/pandoc-templates@6c0e7b0#diff-f218051b4ca8f740a9f585a149101d4a3025037c568b391b5216edf7b14cfadc