I have a macro that stores some text. I'd like to print the text of that macro as it was at the start of the page in the header, and as it is at the end of the page in the footer. I can do this for counters like so:
\documentclass{article}
\usepackage{scrpage2,lipsum}
\pagestyle{scrheadings}
\makeatletter
\newcounter{ctr}
\newcounter{@ctr}
\chead{\arabic{@ctr}\setcounter{@ctr}{\value{ctr}}}
\cfoot{\arabic{ctr}}
\setcounter{ctr}{1}
\setcounter{@ctr}{1}
\makeatother
When the header is set, (at the end of the page) it outputs the value of the internal counter @ctr and then sets that counter to be the value of the counter used by the user ctr. It sets it to the value at the end of the page (which will be the value at the beginning of the new page (which is what I want)).
When I try the "analogous" process for a macro that contains text rather than for a counter, I don't get what I want: the header is set with the value of the macro as it is at the end of the page. How can I fix this?
The following MWE shows the problem. The counter and the text should always refer to the same number, but they don't.
\documentclass{article}
\usepackage{scrpage2,lipsum}
\pagestyle{scrheadings}
\ohead{}
\makeatletter
\newcounter{ctr}
\newcounter{@ctr}
\chead{\arabic{@ctr}\setcounter{@ctr}{\value{ctr}}}
\cfoot{\arabic{ctr}}
\setcounter{ctr}{1}
\setcounter{@ctr}{1}
\def\thetext{First text}
\def\@thetext{\thetext}
\ihead{\@thetext\def\@thetext{\thetext}}
\ifoot{\thetext}
\makeatother
\begin{document}
\lipsum[1-4]
{\Large Becoming Second text}\stepcounter{ctr}
\def\thetext{Second text}
\lipsum[5-7]
{\Large Becoming Third text}\stepcounter{ctr}
\def\thetext{Third text}
\lipsum[8-11]
{\Large Becoming Fourth text}\stepcounter{ctr}
\def\thetext{Fourth text}
\lipsum[12]
\end{document}
This looks to me like it's probably some sort of expansion problem. I tried playing with \edef instead of \def but if I couldn't get the desired result. What am I doing wrong?
\mark-command. – Ulrike Fischer Jul 20 '11 at 09:43