3

The everypage package was last changed in June 2007 (https://www.ctan.org/pkg/everypage). And yet, in the last few months, since I upgraded my LaTeX installation, it behaves differently. The only logical conclusion is that something has changed in the underlying TeX to bring about this behavior.

I noticed it with regard to my answer at What are the ways to position things absolutely on the page?. I have since "fixed" that answer to account for the changes, though I am still unnerved by them. In that revised answer, the definition for \atxy is given as

\newcommand\atxy[3]{%
 \AddThispageHook{\hspace*{\dimexpr-\PageLeftMargin-\hoffset+#1\relax}\smash{%
  \raisebox{\dimexpr\PageTopMargin+\voffset-#2\relax}{\textcolor{red}{#3}}}%
  \setbox0=\hbox{#3}%
  \hspace*{-\dimexpr\wd0-\PageLeftMargin-\hoffset+#1\relax}%
}}

But, originally, the definition was simpler:

\newcommand\atxy[3]{%
 \AddThispageHook{\smash{\hspace*{\dimexpr-\PageLeftMargin-\hoffset+#1\relax}%
  \raisebox{\dimexpr\PageTopMargin+\voffset-#2\relax}{\textcolor{red}{#3}}}}}

But, using the original definition of \atxy, the output changed from

enter image description here

to this:

enter image description here

What was going on? I eventually figured out that what was happening is that, previously, each \AddThispageHook began typeset relative to the left margin. Now, what was happening is that each \AddThispageHook was being typeset relative to the left/right marginal position where the prior \AddThispageHook left off.

You can see in the example that (6,4) is the initial \atxy and is typeset correctly. The next one is (0,1). Now, instead of being set relative to the paper edge, it is set relative to (6,4). By the time I get to the third invocation, \textbullet(5,6), I have already fallen off the right edge of the paper, never to be seen again.

My eventual revision of \atxy that you see above fixed the behavior by using \hspace to shift leftward back to the starting point on the left margin, following the typeset. In this way, both older and newer LaTeX installations behave identically.

This revision, however, was my 2nd attempt. My first attempt was to add a \\ to the end of the \AddThispageHook to return the "cursor" to the left margin. While that fixed the "newer" LaTeX behavior, it actually broke the behavior for "older" LaTeX installations, which then complained that there was no line to end (the standard error when attempting \\ on a line with no text).

So, on one hand, I've answered my question by rewriting \atxy to account for the new everypage behavior. But since the package hasn't been upgraded in years, I worry that something has changed under the hood of TeX, that may come back to bite me in other ways.

It would be nice to have a definitive diagnosis on what changed under the hood of TeX to produce the behavior in everypage and what circumstances does one have to look out for where this unexpected change could affect other pieces of code. I tried contacting the package author, without success.

Here's an MWE, if you want to play with it

\documentclass{article}
\usepackage{everypage}
\usepackage{xcolor}
\usepackage{lipsum}
% THESE ARE LaTeX DEFAULTS; CAN CHANGE IF NEEDED.
\def\PageTopMargin{1in}
\def\PageLeftMargin{1in}
% REVISED DEFINITION
\newcommand\atxy[3]{%
 \AddThispageHook{\hspace*{\dimexpr-\PageLeftMargin-\hoffset+#1\relax}\smash{%
  \raisebox{\dimexpr\PageTopMargin+\voffset-#2\relax}{\textcolor{red}{#3}}}%
  \setbox0=\hbox{#3}%
  \hspace*{-\dimexpr\wd0-\PageLeftMargin-\hoffset+#1\relax}%
}}
% ORIGINAL DEFINITION
\renewcommand\atxy[3]{%
 \AddThispageHook{\smash{\hspace*{\dimexpr-\PageLeftMargin-\hoffset+#1\relax}%
  \raisebox{\dimexpr\PageTopMargin+\voffset-#2\relax}{\textcolor{red}{#3}}}}}
% VERIFIED THAT SETTING \hoffset AND \voffset DO NOT BREAK SOLUTION.
%\hoffset=0.4in
%\voffset=0.2in
\begin{document}
\atxy{6in}{4in}{(6,4)}
\lipsum[1]
\atxy{0in}{1in}{(0,1)}
\atxy{5in}{6in}{\textbullet(5,6)}
\atxy{5in}{6.2in}{\makebox[0pt]{centered at (5,6.2)}}
\end{document}

1 Answer 1

5

Your code was implictly exploiting the fact that \smash acted like an \hbox in older systems. That means it didn't switch to horizontal mode:

\documentclass{article}

\begin{document}
\smash{abc}
\smash{xyz}
\end{document}

Output in texlive 2017:

enter image description here

Output now

enter image description here

If you add an \hbox around the smash you get back to the old behaviour:

\documentclass{article}
\usepackage{everypage}
\usepackage{xcolor}
\usepackage{lipsum}
% THESE ARE LaTeX DEFAULTS; CAN CHANGE IF NEEDED.
\def\PageTopMargin{1in}
\def\PageLeftMargin{1in}

% ORIGINAL DEFINITION
\newcommand\atxy[3]{%
 \AddThispageHook{\hbox{\smash{\hspace*{\dimexpr-\PageLeftMargin-\hoffset+#1\relax}%
  \raisebox{\dimexpr\PageTopMargin+\voffset-#2\relax}{\textcolor{red}{#3}}}}}}
% VERIFIED THAT SETTING \hoffset AND \voffset DO NOT BREAK SOLUTION.
%\hoffset=0.4in
%\voffset=0.2in
\begin{document}
\atxy{6in}{4in}{(6,4)}
\lipsum[1]
\atxy{0in}{1in}{(0,1)}
\atxy{5in}{6in}{\textbullet(5,6)}
\atxy{5in}{6.2in}{\makebox[0pt]{centered at (5,6.2)}}
\end{document}
2

You must log in to answer this question.

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