
我正在嘗試實施一個問題的解決方案:自動縮放 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' 停用此功能。
但是,當我使用此功能時,生成的圖像不再縮放。