Interference between atbegshi and hyperref when producing table of contents headings on every page of TOC

Beuthe, Thomas thomas.beuthe at
Mon Feb 10 15:58:01 CET 2020

Up front statement: this is not a bug report or a request to solve a problem since I've already come up with a solution to my problem.
It's more of a "please wade in on this with an opinion" request on the solution.
To be able to comment you would probably have to have a deeper knowledge of both the atbegshi and the hyperref packages (in particular the backref option).

The problem I was trying to solve is as follows: produce "TABLE OF CONTENTS" or "LIST OF TABLES" or "LIST OF FIGURES" headers over every page with these elements.
A search leads to discussion of this topic and suggested solutions involving the atbegshi package.
For example, the discussion suggests the following solution:

\newcommand{\AtBeginShipoutClear}{\gdef\AtBegShi at Hook{}}  <-defines a "clearing" definition
And pairs of
\AtBeginShipout{header stuff in here}
to nullify things again.

This seemed to work well, but then I noticed that all of the backrefs produced the hyperref package broke and now only pointed to the first page of the document.
So I grimly sat down, determined to see what was going on because we make active use of backrefs.
It took a while for me to track it down since I was wading through a larger template of my own, but the culprit was definitely the \AtBeginShipoutClear command.
This puzzled me a bit at first, but looking a little deeper into the bowels of the hyperref package I realized that it was already using the atbegshi package
for its own purposes so it sort of made sense that a clash was possible.

Delving further into other suggested solutions to my TOC, LOT, and LOF header quest, I found one that seems to do the trick.
See for example here:

This solution involves using a
and then defining
And merrily redefining and then blanking out \MyShipoutHook with \renewcommand to control the action of \AtBeginShipout throughout the document.
Interestingly, my first attempt with multiple uses of \AtBeginShipout{\MyShipoutHook} cumulated the shipout actions and produced multiple stacked identical headers,
so I figured this was just cumulating the action of the \AtBeginShipout (not sure?).
In the end, a single definition of \AtBeginShipout and subsequent redefinitions and final blanking out of \MyShipoutHook seemed to do the trick and the backrefs were back in action!

I have to admit though that I'm only a "part time apprentice" (not a wizard!) at this stuff, so although my actions have produced the desired result for me, I still have this uneasy feeling that perhaps I'm abusing something, and maybe even unintentionally messing the hyperref or backref package somehow or misunderstanding how things work.
The atbegshi documentation is rather technical and there's no clear indication (at least for me) of how the "do" action of the \AtBeginShipout
command should be nullified or un-done properly.
Is my solution realistic? Is this really the way it should be done? I really don't know for sure...
Can someone with intimate knowledge (Ulrike Fischer?) perhaps comment on this?
I would appreciate any guidance you might have to offer!


This email is confidential between the sender and the intended recipient specified in the message, and may contain proprietary or otherwise protected information of the intended parties. If you received this email in error, please notify the sender immediately and confirm you have deleted this message. Any unauthorized review, disclosure, retransmission, dissemination or other use of or reliance on this information may be unlawful and is strictly prohibited.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the texhax mailing list.