Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Why cannot I compile the most minimal code below?

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

1 Answer 1

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

share|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
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

Your Answer

 
discard

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.