TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Why cannot I compile the most minimal code below?

\documentclass{minimal}\document . \enddocument
share|improve this question
up vote 15 down vote accepted

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.)

share|improve this answer
Is there any reason why document should not form a group? – Caramdir Jan 8 '11 at 19:52
@Joseph, thank for answering. – xport Jan 8 '11 at 19:52
@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
@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
@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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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