对于 robust-externalize 库,在新文件中写入类似以下内容:
\newsavebox\boxRobExt%
\savebox{\boxRobExt}{%
my content
}%
\usebox{\boxRobExt}%
% some code to write `\the\dp\boxRobExt` into an auxiliary file
为了测量的深度my content
。这很好用,但由于my content
是宏,它会对其进行标记,并使 tikz matrices 等命令失败。因此,我需要使用ampersand replacement
可能不太实用的。
有没有一种解决方案可以测量内容的深度而不会出现此问题?重要的是:我希望代码尽可能通用,特别是如果它使它适用于 tikz 但破坏其他东西,那就不是很好(但可能仍然比没有好)。
梅威瑟:
\documentclass[,margin=30cm]{standalone}
\usepackage {tikz}
% most packages must be loaded before hyperref
% so we typically want to load hyperref here
% some packages must be loaded after hyperref
\begin{document}%
%% We save the height/depth of the content by using a savebox:
\newwrite\writeRobExt%
\immediate\openout\writeRobExt=\jobname-out.tex%
%
\newsavebox\boxRobExt%
\savebox{\boxRobExt}{%
\begin{tikzpicture}
\node [matrix,fill=red!20,draw=blue,very thick] (my matrix) at (2,1)
{
\draw (0,0) circle (4mm); & \node[rotate=10] {Hello}; \\
\draw (0.2,0) circle (2mm); & \fill[red] (0,0) circle (3mm); \\
};
\end{tikzpicture}
}%
\usebox{\boxRobExt}%
\immediate\write\writeRobExt{%
\string\def\string\robExtWidth{\the\wd\boxRobExt}%
\string\def\string\robExtHeight{\the\ht\boxRobExt}%
\string\def\string\robExtDepth{\the\dp\boxRobExt}%
}%
%
\end{document}
答案1
\savebox
、\usebox
、lrbox
是 LaTeX 的宏。如果不想使用宏,则可以直接使用 TeX 基元。即\setbox
和。因为基元会清空 TeX 内存中的框,所以在 之后\box
使用。\box\boxRobExt
\write
\box
\begin{document}%
\newwrite\writeRobExt%
\immediate\openout\writeRobExt=\jobname-out.tex%
\newbox\boxRobExt
\setbox\boxRobExt=\hbox{%
\begin{tikzpicture}
\node [matrix,fill=red!20,draw=blue,very thick] (my matrix) at (2,1)
{
\draw (0,0) circle (4mm); & \node[rotate=10] {Hello}; \\
\draw (0.2,0) circle (2mm); & \fill[red] (0,0) circle (3mm); \\
};
\end{tikzpicture}%
}
\immediate\write\writeRobExt{%
\string\def\string\robExtWidth{\the\wd\boxRobExt}%
\string\def\string\robExtHeight{\the\ht\boxRobExt}%
\string\def\string\robExtDepth{\the\dp\boxRobExt}%
}%
\box\boxRobExt
\end{document}
答案2
解决方案是使用\begin{lrbox}{\boxRobExt}<stuff with &>\end{lrbox}
,感谢 Qrrbrbirlbel!