Escale automáticamente Tikz-Picture y use la externalización y configuración del nombre del archivo

Escale automáticamente Tikz-Picture y use la externalización y configuración del nombre del archivo

Estoy intentando implementar la solución a una pregunta:Escale automáticamente Tikz-Picture Y use la externalización

La respuesta ayuda y logré hacer esto, sin embargo, me gustaría darle a cada imagen de salida externalizada un nombre de archivo específico, por ejemplo, si mi archivo tikz está en path/to/file.tikzentonces me gustaría tener el archivo de salida en /ext-tikz/path/to/file.pdf.

Sin embargo, tan pronto como implemento, \tikzsetnextfilename{...}la compilación falla.

Aquí hay un 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}

Noté dentro de los archivos de registro que con el activado tikzsetnextfilenamedice

Se ha optimizado una imagen tikz. Utilice '/tikz/external/optimize=false' para desactivar esto.

Sin embargo, cuando uso esta función, la imagen generada ya no se escala.

información relacionada