Why cannot I compile the most minimal code below?

\documentclass{minimal}\document . \enddocument
link|improve this question

feedback

1 Answer

up vote 14 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

\documentclass{minimal}
\begingroup
\document
a 
\enddocument
\endgroup

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

link|improve this answer
2  
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
6  
@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
show 1 more comment
feedback

Your Answer

 
or
required, but never shown

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