[l2h] \verbatim and \endverbatim

Ross Moore ross at ics.mq.edu.au
Sat Jan 3 11:18:40 CET 2004


Hi Jens,

On Fri, 2 Jan 2004, Jens Lehmann wrote:

> > Verbatim-like environments are always tricky, because they do not obey
> > the rules/style of normal LaTeX syntax for their content.
> >
> > However, a definition such as:
> > \newenvironment{myspecialenv}
> >  {\textbf{This is mine}
> >   \begin{verbatim}
> >  }
> >  {\end{verbatim}
> > }
> >
> > should work with LaTeX2HTML, even if it doesn't work with LaTeX
> > itself.
>
> It doesn't work for me. The output is not correct and I get the
> following warning:
>
> ? brace missing for \newedenvironment

Yes; this is what I get too.

I've done a lot more experimenting and fiddling around with the code.
First of all, let me explain an undocumented feature:

  any environment, whose name ends in  verbatim  or  Verbatim
  is automatically treated as a  \begin{verbatim}...\end{verbatim}

Try it out, define an environment:
   \newenvironment{myverbatim}
     {\begin{center}\color{red}}
     {\end{center}}

What do you expect to get from:

 \begin{myverbatim}
  Hello world!
 \end{myverbatim}



In fact you get just plain unformatted {verbatim} text.
                           ^^^^^^^^^^^

That's why it's undocumented, because we should be able to
do a lot better, and have red, centered verbatim text.

>
> This is probably because the }-brace and the {-brace after
> \begin{verbatim} are not recognized.

No. It's deeper than that.

> A testcase can be found in my Debian bug report for this at the bottom:
> http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=218834
>
> I attach it here additionally.

Today I made a few simple edits in the  latex2html  script,
and renamed your environment to   {codeblockverbatim} in test5.tex .

Here's the result:

   http://www-texdev.ics.mq.edu.au:LEHMANN/test5/

(source at http://www-texdev.ics.mq.edu.au:LEHMANN/test5.tex )


My edits to  latex2html  (5 simple edits) effect the following.


Environments with names ending:   ....verbatim  or  ....Verbatim
have
  1.  their contents placed 'verbatim'  (ie. in <PRE>....</PRE> tags)
       (as at present)

as well as

  2.  their  \newenvironment  replacements interpreted, both before
      and after;
  3.  occurrences of  \verbatim  and  \endverbatim  are ignored.


Thus the following kind of definition works as expected:

\newenvironment{\myverbatim}
  {... some stuff before ..  e.g., for stylish purposes ...
   \verbatim }
  {\endverbatim
   ... and closing stuff afterwards ... }


However, the following is not quite right:

\newenvironment{\myverbatim}
  {... some stuff before ..  e.g., for stylish purposes ...
   \verbatim
   Start the verbatim with this:}
  { Finish it with this.
   \endverbatim
   ... and closing stuff afterwards ... }

In this case, the constant phrases 'Start the verbatim with this:'
and 'Finish it with this.' are in fact *not* treated as part of
the {verbatim} text. They are styled along with the 'stuff before',
since only the contents of the environment are treated {verbatim}.



The 5 short edits are not yet committed to the repository
at  www.latex2html.org ,  but I'll send them to you if you
are prepared to implement them yourself.

Within the next few weeks (maybe as many as 6 or 7 !)
I'll be announcing a new version of LaTeX2HTML, which will
have numerous small bug-fixes and improvements, and other
extended functionality (e.g. support for .jpg images/icons
thanks to coding contributed by Shigeharu TAKENO).

It will have this extended support for {...verbatim} environments.
But if you don't want to wait that long, you can have that coding
earlier, and perhaps test it and suggest improvements.


>
> I need the environment for generating the sourcecode-boxes in this
> document: http://www.xith.org/tutes/GettingStarted/html/simple_header.html
>
> Currently I use a workaround, by  putting
>
> \begin{codeblock} % adds HTML for starting a codeblock
> \begin{verbatim}
> [... code ...]
> \end{verbatim}
> \end{codeblock} % adds HTML for ending a codeblock
>
> I'm not the only one working on this document (but the maintainer) and
> using only \begin{codeblock} and \end{codeblock} would be more intuitive
> and save some time.

Sure.
Change this to
  \begin{codeblockverbatim} ... \end{codeblockverbatim}
or
  \begin{codeverbatim} ... \end{codeverbatim}

and the new feature will 'just work' without regard for
any special packages (such as {fancyvrb}), once you've
implemented those 5 small changes.


>
> As said before I'm happy to answer your questions, if something is not
> clear.

You tell me if you want to test a preview of this new feature.


Best regards,

	Ross Moore

>
> Jens
>
> --
> PGP Public Key: http://studenten-dresden.de/public_key.asc
>


More information about the latex2html mailing list