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

Added whitespace around tikz picture when svg is made using standalone class with dvisvgm option and a node #274

Open
stertooy opened this issue Sep 4, 2024 · 2 comments
Assignees
Labels
TikZ issue TikZ issue must be fixed upstream

Comments

@stertooy
Copy link

stertooy commented Sep 4, 2024

I'm not certain whether this is a bug with dvisvgm or with the standalone class, apologies if this does not belong here.

When using dvisvgm to make an SVG from the tex-code below, something odd happens: the svg gains a lot of whitespace to the left and to the bottom - as if dvisvgm draws it from the (0,0)-coordinate in TikZ, instead of where the actual image starts.

\documentclass[dvisvgm]{standalone}

\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\begin{document}
	
\begin{tikzpicture}
    \draw (4,4) rectangle (8,6);
    \draw (6,5) node {a};
\end{tikzpicture}

\end{document}

tikz-faulty

This does not happen when the [dvisvgm] option is omitted from the standalone document class:

tikz-correct

Unfortunately, I've also run into instances before where this option is required to create a correct svg, so I can't just omit it entirely. Curiously enough, this only happens when a node is present in the TikZ-figure. If I comment out the line with the node, it works correctly whether or not the dvisvgm-option is present.

@mgieseki
Copy link
Owner

mgieseki commented Sep 4, 2024

First of all, there's no need to apologize. Feel free to report any problems regarding dvisvgm here.

But in this case it's actually an issue with TikZ. It's the same as in #272. The letter a is positioned with DVI commands but also wrapped by literal SVG elements that shift it to the lower left. Since dvisvgm doesn't evaluate literal SVG fragments embedded in the DVI file, it doesn't know the final position and doesn't adapt the bounding box either. That's why it's too big.

When omitting option dvisvgm, TikZ embeds PostScript code which dvisvgm evaluates and therefore allows to compute a thight bounding box.

Long story short, this issue has to be fixed by the TikZ team.

@mgieseki mgieseki self-assigned this Sep 4, 2024
@mgieseki mgieseki added the TikZ issue TikZ issue must be fixed upstream label Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TikZ issue TikZ issue must be fixed upstream
Projects
None yet
Development

No branches or pull requests

3 participants
@mgieseki @stertooy and others