I insert the name and licence with the command \nameofcompany at the end of my document like this:


Now, I want to generalize it to some documents, for that I found \AtEndDocument{\nameofcompany} but it doesn't have exactly the same result than \nameofcompany \end{document}. It seems that with \AtEndDocument, the command is only executed after \end{document}, while I want it to be executed before.

I also try to redefine the document environment like this


but it doesn't work either.

Is there a command like \beforTheEndDocument?

  • What is the problem? The output for your personal command is not shown? Please, post a minimal example with the problem.
    – Sigur
    Commented Jan 25, 2015 at 22:15
  • Please, correct those lot of typos on your post.
    – Sigur
    Commented Jan 25, 2015 at 22:16
  • 1
    Insert \AtEndDocument{} on preamble not on the body.
    – Sigur
    Commented Jan 25, 2015 at 22:17
  • 1
    @Sigur I've done some of them. :) Commented Jan 25, 2015 at 22:17
  • Sigur, I’ll fix it. Yes, i put \AtEndDocument{} on the preamble. I prepare the minimal example.
    – fauve
    Commented Jan 25, 2015 at 22:19

1 Answer 1


is a shorthand equivalent to


Why? Look at the definition of \enddocument (from latex.ltx):

       \makeatletter \@@input\jobname.aux
     \ifdim \font@submax >\fontsubfuzz\relax
       \@font@warning{Size substitutions with differences\MessageBreak
                  up to \font@submax\space have occurred.\@gobbletwo}%
       \ifx \@multiplelabels \relax
           \@latex@warning@no@line{Label(s) may have changed.
               Rerun to get cross-references right}%

\@enddocumenthook is the hook that is updated by \AtEndDocument:


You may consider alternative end-of-document hooks by looking into the atveryend package. It provides the following hooks, all of which are executed after the \AtEndDocument hook, except the first:


The code is called before the final \clearpage in \enddocument. However it is unknown, whether the last page is already shipped out or if this will be triggered by the final \clearpage.


The code is called after the final \clearpage of \enddocument before the main .aux file is closed. This is the right place to remember the last page in the .aux file, for instance.


The code is called after the .aux file is closed and read in again. It is the place for final checks, rerun hints, final messages.


After the .aux file closing and reading LaTeX prints the file list if requested by \listfiles. Then this hook is executed.


This code is called right before the final \@@end.

Refer to the definition of \enddocument in order to see an approximate location where the above hooks are placed.

You must log in to answer this question.

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