
질문에 대한 솔루션을 구현하려고 합니다.자동으로 Tikz-Picture 크기를 조정하고 외부화 사용
답변이 도움이 되었고 이 작업을 수행할 수 있었지만 각 외부화된 출력 이미지에 특정 파일 이름을 지정하고 싶습니다. 예를 들어 tikz 파일이 에 있는 경우 path/to/file.tikz
출력 파일을 /ext-tikz/path/to/file.pdf
.
그러나 구현하자마자 \tikzsetnextfilename{...}
빌드가 실패합니다.
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}
로그 파일 내부에서 활성화된 tikzsetnextfilename
내용을 확인했습니다.
tikzpicture가 최적화되었습니다. 이를 비활성화하려면 '/tikz/external/optimize=false'를 사용하십시오.
그러나 이 기능을 사용하면 생성된 이미지의 크기가 더 이상 조정되지 않습니다.