Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!mintaka!yale!quasi-eli!cs.yale.edu!guzman-juan From: guzman-juan@cs.yale.edu (Juan Carlos Guzman) Newsgroups: comp.text.tex Subject: LaTeX: How to include \end{document} in a macro? Message-ID: <29996@cs.yale.edu> Date: 12 Apr 91 15:39:12 GMT Sender: news@cs.yale.edu Organization: Yale University, Dept. of Computer Science, New Haven, CT Lines: 51 Nntp-Posting-Host: monad.systemsz.cs.yale.edu Originator: guzman@monad.CS.Yale.Edu Hi, I have defined the environment `file', which should work essentially like `document', except that I can have nested file environments, in which case the nested ones behave as noop. \newenvironment{file}[1] {\ifnum\value{FileCounter}=0\begin{document}\fi \addtocounter{FileCounter}{1}} {\addtocounter{FileCounter}{-1} \ifnum\value{FileCounter}=0\end{document}\fi} The environment works fine, but when it's time to close the document, LaTeX complains: % latex myfile LaTeX error. See LaTeX manual for explanation. Type H for immediate help. ! \begin{file} ended by \end{document}. ... l.123 \end{file} ? After hitting , the file is closed with no problem, except that \end{file} does not seem to have been closed properly (note complaining about \ifnum not being complete): [3] (myfile.aux) ) (\end occurred inside a group at level 1) (\end occurred when \ifnum on line 123 was incomplete) Output written on .dvi (3 pages, 7200 bytes). Transcript written on myfile.log. From this I gather that when LaTeX processes \end{document}, it immediately stops further processing of the input. So my question is: How can I do to `delay' LaTeX's processing of \end{document} until it has completely expanded \end{file}? On a related note, How should I change the macro so that when LaTeX reaches a recursive \end{file} it ignores further input from this file, and returns processing its parent? Thanks a lot, Juan Carlos Guzman guzman-juan@cs.yale.edu -- Juan in a million