
Estou tentando implementar a solução para uma pergunta:Dimensione automaticamente o Tikz-Picture E use a externalização
A resposta ajuda e consegui fazer isso, porém gostaria de dar a cada imagem de saída externalizada um nome de arquivo específico, por exemplo, se meu arquivo tikz estiver em path/to/file.tikz
então eu gostaria de ter o arquivo de saída em /ext-tikz/path/to/file.pdf
.
No entanto, assim que eu implemento, \tikzsetnextfilename{...}
a compilação falha.
Aqui está um 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}
Notei dentro dos arquivos de log, que com o ativado tikzsetnextfilename
diz
Uma imagem tikz foi otimizada. Use '/tikz/external/optimize=false' para desativar isso.
Porém quando utilizo esse recurso, a imagem gerada não é mais dimensionada.