0

Say you have some command in a part of the code. I want to execute that command at a later point, so that it can be set at a later point. E.g. a header, and you want to set the margin after some other stuff have been processed. Maybe this example explains it better. In this version pbagemark and \evaluateAtMark is the magic commands I'm looking for.

\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}

This doesn't run of course. This is what I want the code to do:

When \evaluateAtMark\SomeMark is run, then at the point of the page where \pagemark\SomeMark is run, the code \hspace*-4em {\Large\bfseries Some header} should be evaluated. Is there any way to do this in a fairly general way?


Please feel free to add tags to this question. I have no idea what to even google (I've tried quite a few things, but nothing related showed up).

1 Answers1

1

As @DavidCarlisle suggested, using the .aux-file will solve the problem:

\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}