# How can I output before the final clearpage using AtEndDocument or similar?

I would like to output a single line of text at the end of all the documents generated using a particular coustom package file. I assumed \AtEndDocument would do the trick as I have used it before to do things like closing environments that were automatically opened at the start of the document, etc. Si I tried this:

\AtEndDocument{%
\textit{my note here}
}


But this seems to output after a final \clearpage or similar has been run on the document and the line appears on a page of it's own. This is now what I want.

To my surprise trying to search for this, several questions around this site and the net seem to be asking for just the opposite: how to issue commands after the clear-page. It seems the behaviour I'm seing is what other people want and vise versa.

How can I add a snippet to the end of a document that ends on the same page with the rest of the content?

• It doesn't happen for me. The text is not on a page of its own. Make a complete example. – Ulrike Fischer Nov 14 '14 at 14:16
• @UlrikeFischer In trying to put together a MWE I found the culprit, see my answer. Thanks for forcing me to try this outside of my full environment. – Caleb Nov 14 '14 at 14:30
• There's also atveryend which provides a host of hooks for the end-of-document area. – Werner Nov 15 '14 at 2:50

The problem has nothing to do with \AtEndDocument itself, the problem is a package that has messed with that hook.
In my case I was using the package lastpage. Moving the \usepackage{lastpage} declaration to the end of my package file after I had declared what I wanted to have in that hook caused my snippet to appear on the proper page.
• Thanks, that's my issue too. The same happens with the newer (?) pageslts as well. Since I can't (in good conscience) move the package load to the end of my preamble (I have modular documents), I opted for a manual \AtEndDocument{\label{LastPage}} -- now it's fine. (There may be corner cases in which the label does not end up on the last page -- I guess I'll deal with that when I encounter it.) – Raphael Nov 18 '14 at 12:00