Why cannot I compile the most minimal code below?

\documentclass{minimal}\document . \enddocument

The usual LaTeX \begin ... \end construct forms a group. However, this is not the case for the document environment. To do this, \document closes the group that \begin has opened, and \enddocument starts a group which \end then closes. So


does compile (though I would not recommend it!).

(LaTeX3 note: environments generated by xparse include a proper internal macro for the two ends, and so a LaTeX3 kernel will not expose the start and end macros in this way.)

  • 2
    Is there any reason why document should not form a group?
    – Caramdir
    Jan 8 '11 at 19:52
  • 7
    @Caramdir: The reason is efficiency. If an assignment happens inside a group, TeX has to remember the previous value in order to restore it after the group ends, which consumes time and memory. Since nothing happens after \end{document}, it makes sense to make the document body global.
    – Philipp
    Jan 8 '11 at 21:29
  • 1
    @Joseph: Can you elaborate a bit on your final parenthetical? What do you mean by a proper internal macro?
    – TH.
    Jan 8 '11 at 23:50
  • 1
    @TH. Seems like a separate item to the question here: see my blog post at texdev.net/2011/01/09/latex3-and-document-environments
    – Joseph Wright
    Jan 9 '11 at 11:22
  • @Joseph: Ah ha, now I understand what you mean, thanks. I'm curious how that will interact with the situations in LaTeX2e that require one to use \foo and \endfoo directly. Hopefully those situations won't arise in LaTeX3.
    – TH.
    Jan 9 '11 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.