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).

7
  • 3
    your question is not at all clear. Firstly what do you mean by "header" here, the page head or a section heading? Your example has neither so i can't really guess what effect you want to make Jun 24, 2018 at 12:30
  • @DavidCarlisle I was hoping that the example would clarify that. I'll reformulate. Jun 24, 2018 at 12:31
  • actually I think I can guess what you mean, just write a definition to the aux file at the end so it is in scope at the start of the document. (and you mean \hspace not \hskip) Jun 24, 2018 at 12:32
  • @DavidCarlisle Is this clearer? Jun 24, 2018 at 12:39
  • Of course! The .aux-file Jun 24, 2018 at 12:40

1 Answer 1

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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .