[comp.text] ewenvironment in LaTeX

masini@crin.UUCP (Gerald MASINI) (07/23/87)

I'm now just a beginner (no more absolute) with LaTeX, and I would like to
define an environment of my own, including some verbatim. Something like
that:

------------------------------------------------------------------------
\newenvironment{myenv}{\begin{verbatim}}{\end{verbatim}}
\documentstyle{book}
\pagestyle{headings}
\begin{document}

\chapter{Hi}

Here it comes:

\begin{myenv}
    Try and try
                ... again !
\end{myenv}

This is the end.

\end{document}
------------------------------------------------------------------------


But it doesn't work. This is the most important part of the log file:

This is TeX, Version 2.0 for Berkeley UNIX (preloaded format=lplain 86.12.16)  23 JUL 1987 18:45
(es.tex
LaTeX Version 2.09 - Released 27 October 1986
(/usr/lib/tex/macros/book.sty
Document Style `book'. Released 4 September 1986.
(/usr/lib/tex/macros/bk10.sty)
) (es.aux)
Chapter 1.
)
Runaway argument?
^^M    Try and try^^M                ... again !^^M\end{myenv}^^M^^MT\ETC.
! File ended while scanning use of \@xverbatim.
<inserted text> 
                \par 
<*> es.tex 

?


What happened ?
Thanks for the help.
-- 
Ge'rald MASINI        CRIN (Centre de Recherche en Informatique de Nancy)
uucp:  masini@crin.crin.fr
post:  CRIN   B.P. 239   54506 Vandoeuvre-les-Nancy Cedex   FRANCE
phone: +33  83.91.21.45

mecklen@utah-gr.UUCP (Robert Mecklenburg) (07/25/87)

In article <311@crin.UUCP> masini@crin.UUCP (Gerald MASINI) writes:
> I would like to
> define an environment of my own, including some verbatim. 
>
>Ge'rald MASINI        CRIN (Centre de Recherche en Informatique de Nancy)

I don't know why this fails, but I have never been able to include a
verbatim environment inside a \newenvironment command.  I have tried
several times with different "clever" hacks and it always fails. 

Robert Mecklenburwi

seindal@diku.UUCP (Rene Seindal) (07/27/87)

In article <311@crin.UUCP> masini@crin.UUCP (Gerald MASINI) writes:
>I'm now just a beginner (no more absolute) with LaTeX, and I would like to
>define an environment of my own, including some verbatim.

The LaTeX-book says (page 168) 

	"A verbatim or verbatim* environment may not appear in the 
	 argument of any command"

The same applies to the \verb and \verb* macros.

>What happened ?

Rene' Seindal (seindal@diku.uucp)
The Computer Department, Institute of Datalogy, University of Copenhagen

wtho@cgcha.UUCP (Tom Hofmann) (07/30/87)

in article <311@crin.UUCP>, masini@crin.UUCP (Gerald MASINI) says:
> 
> I'm now just a beginner (no more absolute) with LaTeX, and I would like to
> define an environment of my own, including some verbatim. Something like
> that:
> 
> ------------------------------------------------------------------------
> \newenvironment{myenv}{\begin{verbatim}}{\end{verbatim}}
> ...

I suppose you find the solution on page 66 of the LaTeX book:

    o  A verbatim environment ... may not appear within an argument of
       any other command.

In your case the verbatim environment is the argument of the command
\newenvironment, and that's why it doesn't work.

Tom Hofmann                       uucp: ...!cernvax!cgcha!wtho
CIBA-GEIGY AG
Scientific Computer Center
Basel, Switzerland

tla@kaiser.UUCP (T Anderson) (08/06/87)

A related (but not the same) problem I had with verbatim was to
include a file inside a verbatim environment.  I wanted to have
a file of sample LaTeX code that could be LaTeXed alone correctly
and then include that file verbatim as an appendix in another
document.  Of course, I could have copied the file in with my
editor, but I wanted changes in the sample file to be automatically
changed in the version in the appendix.  

The problem of course is that
\begin{verbatim}
\input examplefile
\end{verbatim}

only prints `\input examplefile'.  One can place the verbatim
commands in the examplefile, but then one can not use the example
file directly to generate the example.  A solution:

\def\bv{\begin{verbatim}}% necessary to use expandafter
\def\infil{\input examplefile}
\expandafter\bv\infil
\end{verbatim}

There may be a similar solution with more expandafters that avoids
the def's but at least this worked.


			     --	Terry L Anderson
				AT&T Bell Laboratories -- Liberty Corners
				UUCP:     ...!ihnp4!kaiser!tla
				TeleMail: Terry.Anderson
				(201) 580-4428