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
\def\tikzwidth{\textwidth}
\def\tikzheight{\textheight}
\newsavebox{\measure@tikzpicture}
\NewEnviron{tikzsize}[2]{%
\def\tikzscale{1}%
\tikzifexternalizingnext{%
\def\tikz@width{#1}%
\def\tikz@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/\wd\measure@tikzpicture}%
\edef\tikzscalewidth{\pgfmathresult}%
\pgfmathparse{#2/\ht\measure@tikzpicture}%
\edef\tikzscaleheight{\pgfmathresult}%
\pgfmathparse{min(\tikzscalewidth, \tikzscaleheight)}%
\edef\tikzscale{\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.
includegraphicsif a *.pdf version of the file exists. I have a lot of tikz images for my dissertation. With ShareLatex I regularly run in a timeout (also for a single chapter). – TillLeiden Sep 06 '20 at 08:35*.tikzfile name from there. Then I simply change the filename so that it is easy to copy the*.pdffiles into Sharelatex. But I would like to know if I am doing something wrong with my upper approach, in this case I want to learn from my mistakes, or maybe it is a bug, in this case I want to help others. – TillLeiden Sep 08 '20 at 06:36