TeX - LaTeX Asked by TillLeiden on May 13, 2021
I am trying to implement the solution to a question: Automagically scale Tikz-Picture AND use Externalization
The answer helps and I managed to do this, however I would like to give each externalized output image a specific file name, e.g. if my tikz file is at path/to/file.tikz
then I would like to have the output file at /ext-tikz/path/to/file.pdf
.
However, as soon as I implement tikzsetnextfilename{...}
the build fails.
Here is a MWE:
documentclass{article}%
%
usepackage{tikz}
usetikzlibrary{external}
tikzexternalize
%
% from https://tex.stackexchange.com/a/29145/221484
usepackage{environ}
makeatletter
deftikzwidth{textwidth}
deftikzheight{textheight}
newsavebox{measure@tikzpicture}
NewEnviron{tikzsize}[2]{%
deftikzscale{1}%
tikzifexternalizingnext{%
deftikz@width{#1}%
deftikz@height{#2}%
begin{lrbox}{measure@tikzpicture}%
tikzset{external/export next=false,external/optimize=false}% force translation of this BODY (and do not optimize it away as it would usually do):
BODY
end{lrbox}%
pgfmathparse{#1/wdmeasure@tikzpicture}%
edeftikzscalewidth{pgfmathresult}%
pgfmathparse{#2/htmeasure@tikzpicture}%
edeftikzscaleheight{pgfmathresult}%
pgfmathparse{min(tikzscalewidth, tikzscaleheight)}%
edeftikzscale{pgfmathresult}%
BODY
}{% this will re-use an existing external graphics:
BODY
}
}
makeatother
%
%
begin{document}
%
% tikzsetnextfilename{output} %<-- if activated it fail's
%
begin{tikzsize}{tikzwidth}{tikzheight}
begin{tikzpicture}[scale=tikzscale]
draw (0,0)--(1,1);
end{tikzpicture}
end{tikzsize}
%
end{document}
I noteced inside the log files, that with the activated tikzsetnextfilename
it says
A tikzpicture has been optimized away. Use ‘/tikz/external/optimize=false’ to disable this.
However when I use this feature, the generated image is not scaled anymore.
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP