Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!linus!agate!ucbvax!bloom-beacon!eru!hagbard!sunic!mcsun!hp4nl!alchemy!piet From: piet@cs.ruu.nl (Piet van Oostrum) Newsgroups: comp.text.tex Subject: Re: LaTeX: How to include \end{document} in a macro? Message-ID: <1991Apr17.091436.19094@cs.ruu.nl> Date: 17 Apr 91 09:14:36 GMT References: <29996@cs.yale.edu> Sender: piet@cs.ruu.nl (Piet van Oostrum) Reply-To: piet@cs.ruu.nl (Piet van Oostrum) Organization: Dept of Computer Science, Utrecht University, The Netherlands Lines: 34 In-Reply-To: guzman-juan@cs.yale.edu (Juan Carlos Guzman) >>>>> guzman-juan@cs.yale.edu (Juan Carlos Guzman) (JCG) writes: JCG> I have defined the environment `file', which should work essentially JCG> like `document', except that I can have nested file environments, in JCG> which case the nested ones behave as noop. JCG> The environment works fine, but when it's time to close the JCG> document, LaTeX complains: JCG> % latex myfile JCG> LaTeX error. See LaTeX manual for explanation. JCG> Type H for immediate help. JCG> ! \begin{file} ended by \end{document}. JCG> ... JCG> l.123 \end{file} JCG> ? Apparently \begin{document} and \end{document} are hard to use in another environment. However, the following works (but strictly speaking it is an undocumented feature): \newenvironment{file}[1] {\ifnum\value{FileCounter}=0\document\fi \addtocounter{FileCounter}{1}}% {\addtocounter{FileCounter}{-1} \ifnum\value{FileCounter}=0\enddocument\fi} Note: The % must also be given to get rid of a space token. -- Piet* van Oostrum, Dept of Computer Science, Utrecht University, Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands. Telephone: +31 30 531806 Uucp: uunet!mcsun!ruuinf!piet Telefax: +31 30 513791 Internet: piet@cs.ruu.nl (*`Pete')