假设您在代码的某个部分中有一些命令。我想在稍后执行该命令,以便可以在稍后设置它。例如,标题,您想在处理完其他内容后设置边距。也许这个例子解释得更好。在这个版本中,这pbagemark
是\evaluateAtMark
我正在寻找的神奇命令。
\documentclass{article}
\begin{document}
% The below would set a mark at this position on the page
\pagemark\SomeMark%
{\Large\bfseries Header}\newline
Lot's of text here, and this stuff along the way on this page
would deside e.g the new margin for the header, and now it should go back
to insert it.
% Now evaluate the following code at the aforementioned point
\evaluateAtMark\SomeMark{\hspace*-4em {\Large\bfseries Some header}}
% Now I want the \someAction to be evaluated by \triggerSomeActionLater
\end{document}
当然,这不会运行。这就是我想要的代码:
当\evaluateAtMark\SomeMark
运行时,那么在运行页面的位置\pagemark\SomeMark
,应该评估代码\hspace*-4em {\Large\bfseries Some header}
。有没有办法以相当通用的方式做到这一点?
请随意为这个问题添加标签。我甚至不知道该用谷歌搜索什么(我试过很多方法,但没有找到相关的东西)。
答案1
正如@DavidCarlisle 所建议的,使用.aux
-file 将解决问题:
\documentclass{article}
\makeatletter
\let\ea\expandafter
\def\get@mname#1{\ea\@gobble\string#1}
\def\pagemark#1{%
\edef\mname{\get@mname#1}%
\ifcsname pagemark@\mname\endcsname%
\csname pagemark@\mname\endcsname%
\fi%
}
\def\evaluateAtMark#1#2{%
\edef\mname{\get@mname#1}%
\immediate\write\@auxout{\string\gdef\string\pagemark@\mname{\unexpanded{#2}}}%
}
\makeatother
\begin{document}
% The below would set a mark at this position on the page
\pagemark\SomeMark\newline%
Lot's of text here, and this stuff along the way on this page
would deside e.g the new margin for the header, and now it should go back
to insert it.
% Now evaluate the following code at the aforementioned point
\evaluateAtMark\SomeMark{\hspace*{-4em}{\Large\bfseries Some header}}
\end{document}