2

Consider this document:

\documentclass{article}
\usepackage{amsmath}
\usepackage{texpower}
\usepackage{picture}
\usepackage{atbegshi}
\setbox0\hbox{\textbf{TEXT}}
\AtBeginShipout{%
\AtBeginShipoutUpperLeft{%
\put(0,-\ht0){\usebox0}
}}
\begin{document}
This is a test
\end{document}

TEXT appears in the upper left of the page. But as soon as you use align environment of amsmath, the TEXT disappears:

\documentclass{article}
\usepackage{amsmath}
\usepackage{texpower}
\usepackage{picture}
\usepackage{atbegshi}
\setbox0\hbox{\textbf{TEXT}}
\AtBeginShipout{%
\AtBeginShipoutUpperLeft{%
\put(0,-\ht0){\usebox0}
}}
\begin{document}
This is a test
\begin{align}
x&=1+2\\
&=2+1
\end{align}
\end{document}

What's wrong?

2
  • You shouldn't use a scratch register such as \box0 for non temporary purposes.
    – egreg
    Commented Sep 18, 2014 at 17:14
  • @egreg: Oh, I see. It was not actually my example. Someone sent it to me and I just panicked. Your suggestion fixes the problem. If you feel like making your comment into an answer, please do and I will accept it. Thanks.
    – Aditya
    Commented Sep 18, 2014 at 17:21

1 Answer 1

3

No packages are necessary to show the behavior.

Consider this Plain TeX example:

\setbox0=\hbox{Hello} % the same as \sbox0{Hello}
\copy0 % the same as \usebox0
{\box0}
\copy0
\bye

Once \box0 is executed, the most recent incarnation is destroyed, so you see only two copies of “Hello” even if \box0 is executed in a group.

It's true that amsmath doesn't manage temporary boxes in a very coherent way, but scratch registers should be used as soon as they are defined, not procrastinated to a future moment.

\documentclass{article}
\usepackage{amsmath}
\usepackage{texpower}
\usepackage{picture}
\usepackage{atbegshi}

\newsavebox\vafabox
\sbox\vafabox{\textbf{TEXT}}
\AtBeginShipout{%
  \AtBeginShipoutUpperLeft{%
    \put(0,-\ht\vafabox){\usebox\vafabox}%
}}
\begin{document}
This is a test
\end{document}

You must log in to answer this question.

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