-
Notifications
You must be signed in to change notification settings - Fork 111
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
Incorrect tikzpicture size when using dvisvgm output driver (PGF/TikZ) #1275
Comments
I attach the TEX and SVG files ziped |
XDV is not DVI and dvisvgm does not support XDV. |
It seems the problem is reproducible with pdflatex + % test5.tex
\documentclass[dvisvgm,tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\node[draw, rectangle, minimum size=20mm] {xxx};
\end{tikzpicture}
\begin{tikzpicture}
\node[draw, rectangle, minimum size=20mm] {xxx xxx};
\end{tikzpicture}
\end{document} Run
The stdout of
PS: I'm still on dvisvgm 3.0.3 (poor macOS users). PS2: |
Here is a possible fix. The issue has to do with forced bbox adjustment by the For comparison: SVG with driver fix and SVG without driver fix. \def\pgfsysdriver{pgfsys-dvisvgm.def}
\documentclass{article}
%\usepackage[usenames]{color}
\pagestyle{empty}
\usepackage{tikz}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% fix bounding box setting of inserted tikz objects %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\def\pgfsys@typesetpicturebox#1{%
\pgf@ya=\pgf@shift@baseline\relax%
\advance\pgf@ya by-\pgf@picminy\relax%
%
%
\advance\pgf@picmaxy by-\pgf@picminy\relax% maxy is now the height
\advance\pgf@picmaxx by-\pgf@picminx\relax% maxx is now the width
\setbox#1=\hbox{\hskip-\pgf@picminx\lower\pgf@picminy\box#1}%
\ht#1=\pgf@picmaxy%
\wd#1=\pgf@picmaxx%
\dp#1=0pt%
\leavevmode%
\pgf@xa=\pgf@trimleft@final\relax \ifdim\pgf@xa=0pt \else\kern\pgf@xa\fi%
\raise-\pgf@ya\hbox{\ifpgf@sys@svg@inpicture\box#1\else\special{dvisvgm:bbox \pgf@sys@tonumber\pgf@picmaxx\space\pgf@sys@tonumber\pgf@picmaxy}\special{dvisvgm:bbox lock}\box#1\special{dvisvgm:bbox unlock}\fi}%
\pgf@xa=\pgf@trimright@final\relax \ifdim\pgf@xa=0pt \else\kern\pgf@xa\fi%
}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\usetikzlibrary{shapes.geometric}
\begin{document}
\pagecolor{white}%
\begin{tikzpicture}
\node (start) [draw, rectangle, minimum width=24mm, minimum height=16mm] {How are you?};
\end{tikzpicture}
\end{document} Should I prepare a pull request? The problem is, I don't know how to run the tests. |
@agrahn It's always welcome, despite the whole processing is blocked by #1116 for (quite) a while. You can run |
Thank you, @muzimuzhi !
This is what I get: $ l3build check
Running l3build with target "check" with configuration build
Running checks on
gh-issue-1102 (1/4)
gh-issue-1131 (2/4)
pgf001 (3/4)
pgf002 (4/4)
All checks passed
Running l3build with target "check" with configuration config-gd
Running checks on
tikz-gd-gh1087 (1/1)
All checks passed |
Also I wonder if this is a long-existing problem. For now what I found is, the new specials Update: These two new specials were then used in |
Yes, these specials were once added on my request. I needed them for the correct working of the |
I wondered if this affected |
I made use of them when working on |
@muzimuzhi Did this with a |
@muzimuzhi : Sorry, I had loaded the wrong TL (last year's one). Will try again with TL-23. |
@muzimuzhi : I think it is ok now. Would you please check? |
fixes pgf-tikz#1275 Signed-off-by: Alexander Grahn <[email protected]>
Right, yes - I'll need to think about that, as the 'native' |
I replaced |
As for testing, perhaps for some cases we need svg-based tests. Currently [1] https://github.com/latex3/latex2e/tree/develop/required/graphics/testfiles |
fixes pgf-tikz#1275 Signed-off-by: Alexander Grahn <[email protected]>
This patch is applied in the docker build. It can be applied on your server with the command `sudo patch -p1 -d / < /opt/webwork/webwork2/docker-config/pgfsys-dvisvmg-bbox-fix.patch.patch` Note this patch is specific to Ubuntu 22.04, so don't try it on other versions of Ubuntu or other linux distributions. This was the change made in pgf-tikz/pgf#1276 that was merged into the master branch of the to the pgf-tikz latex package on October 23, 2023 that fixes the issue reported in pgf-tikz/pgf#1275.
This patch is applied in the docker build. It can be applied on your server with the command `sudo patch -p1 -d / < /opt/webwork/webwork2/docker-config/pgfsys-dvisvmg-bbox-fix.patch.patch` Note this patch is specific to Ubuntu 22.04, so don't try it on other versions of Ubuntu or other linux distributions. This was the change made in pgf-tikz/pgf#1276 that was merged into the master branch of the to the pgf-tikz latex package on October 23, 2023 that fixes the issue reported in pgf-tikz/pgf#1275.
fixes pgf-tikz#1275 Signed-off-by: Alexander Grahn <[email protected]>
Brief outline of the bug
I want to produce an SVG file with a node shape, e.g. rectangle. I use the following LaTeX code:
and then I use xelatex and then dvisvgm to produce the SVG file:
Unfortunately, the produced SVG file has a background object with larger width than the width of the rectangle, resulting in a TikZ picture with larger width. The width is depended on the text width, i.e., if the text is short, the resulting background object width is not longer than the rectangle width, and there is no problem. But when the text width is longer than some critical length, the tikzpicture width is not the same as the drawn object width. Also, I noticed the same problem with the height. In the following example, the problem appears on the top of the tikzpicture:
with the following command to be executed:
I am using: Windows 11 MiKTeX-XeTeX 4.10 (MiKTeX 23.5) dvisvgm 3.0.4 pgf 3.1.10
Minimal working example (MWE)
The text was updated successfully, but these errors were encountered: