
Ich kann die Abmessungen nicht richtig erfassen, wenn „ savebox
while“ tikzexternalize
eingeschaltet ist.
Hier ist das MWE:
\documentclass {article}
\RequirePackage {tikz}
\RequirePackage {expl3}
\usetikzlibrary {shapes}
\usetikzlibrary {external}
% Make every {tikzpicture} block as separate *.png image.
\tikzexternalize [prefix = tests/]
\tikzsetfigurename {test_}
\tikzset{export as png/.style={external/system call/.add = {}{; convert -density 300 -resize 800x600 "\image.pdf" "\image.png"}}}
\tikzset{export as png}
\ExplSyntaxOn
\tikzset{external/export~next = false} % This is needed for savebox to work.
\newsavebox \sandbox
\savebox \sandbox
{
\begin {tikzpicture}
\node [ellipse, minimum~size = 10pt] { };
\end {tikzpicture}
}
\dim_const:Nn \c_ellipse_width {\the\wd\sandbox\space}
\dim_const:Nn \c_something {16pt}
\ExplSyntaxOff
\begin {document}
\ExplSyntaxOn
\dim_log:N \c_ellipse_width
\dim_log:N \c_something
\begin {tikzpicture}
\dim_log:N \c_ellipse_width
\dim_log:N \c_something
\node [ellipse, align = center] {\the\c_ellipse_width \\ \the\c_something};
\end {tikzpicture}
\ExplSyntaxOff
\end {document}
Wenn es auf diese Weise kompiliert wird, zeigt das Haupt-*.log korrekte Werte an:
> \c_ellipse_width=10.0pt.
> \c_something=16.0pt.
Während tests/test_0.log die Breite ändert und anzeigt:
> \c_ellipse_width=405.83112pt.
> \c_something=16.0pt.
Es ist unnötig zu erwähnen, dass das Bild tests/test_0.png
falsche Werte darstellt.
Wenn Teile des entsprechenden Codes tikzexternalize
auskommentiert sind, wird im Hauptprotokoll Folgendes angezeigt:
> \c_ellipse_width=10.0pt.
> \c_something=16.0pt.
Der *.pdf-Inhalt weist in diesem Szenario korrekte Werte auf.
Wie kann ich die Abmessungen von richtig messen, tikzpicture
während es tikzexternalize
eingeschaltet ist?
Antwort1
Wie sich herausstellt, hängt das Problem mit Tikz-Optimierungen zusammen.
Um dieses Problem zu vermeiden, deaktivieren Sie Optimierungen einfach mit \tikzset{external/optimize = false}
.
Lösung:
\documentclass {article}
\RequirePackage {tikz}
\RequirePackage {expl3}
\usetikzlibrary {shapes}
\usetikzlibrary {external}
% Make every {tikzpicture} block as separate *.png image.
\tikzexternalize [prefix = tests/]
\tikzsetfigurename {test_}
\tikzset{export as png/.style={external/system call/.add = {}{; convert -density 300 -resize 800x600 "\image.pdf" "\image.png"}}}
\tikzset{export as png}
\tikzset{external/optimize = false} % <--------------------------------
\ExplSyntaxOn
\tikzset{external/export~next = false} % This is needed for savebox to work.
\newsavebox \sandbox
\savebox \sandbox
{
\begin {tikzpicture}
\node [ellipse, minimum~size = 10pt] { };
\end {tikzpicture}
}
\dim_const:Nn \c_ellipse_width {\the\wd\sandbox\space}
\dim_const:Nn \c_something {16pt}
\ExplSyntaxOff
\begin {document}
\ExplSyntaxOn
\dim_log:N \c_ellipse_width
\dim_log:N \c_something
\begin {tikzpicture}
\dim_log:N \c_ellipse_width
\dim_log:N \c_something
\node [ellipse, align = center] {\the\c_ellipse_width \\ \the\c_something};
\end {tikzpicture}
\ExplSyntaxOff
\end {document}