[comp.text.tex] LaTex pseudo-verbatim wanted

jvc@aero.aero.org (Jeff Cook) (09/14/90)

To some latex hacker out there:  I need an environment which is identical to
\begin{verbatim}...\end{verbatim}, except that the "\" character is recognized
and processed inside of this environment.  This is so I can generate examples
of computer-generated text, interspersed with either special characters or 
commentary in a different font.  I want the new environment to be in the 
typewriter font, not fill, to produce a linefeed at the end of each line, 
and to accept other latex commands.  Is this too much to ask?  Jeff

duchier@cs.yale.edu (Denys Duchier) (09/15/90)

In article <85603@aerospace.AERO.ORG> jvc@aero.aero.org (Jeff Cook) writes:
 >   To some latex hacker out there:  I need an environment which is identical to
 >   \begin{verbatim}...\end{verbatim}, except that the "\" character is recognized
 >   and processed inside of this environment.  This is so I can generate examples
 >   of computer-generated text, interspersed with either special characters or 
 >   commentary in a different font.  I want the new environment to be in the 
 >   typewriter font, not fill, to produce a linefeed at the end of each line, 
 >   and to accept other latex commands.  Is this too much to ask?  Jeff

Here are 3 files: verbalist.sty, ruled.sty, verbaruled.sty; delimited
by lines of the form ***BEGIN: filename, and ***END: filename.  The
difficulty was mostly in getting this to work inside other list
environments; in particular, as the first thing in an item.
\verbalist is like \verbatim but takes an argument (see below) and
leaves \, {, and } alone. \verbaruled is similar, but takes no
argument and puts a rule above the text and one below.

--Denys

***BEGIN: verbalist.sty
% Denys Duchier, Yale University, September 1990
%
% \begin{verbalist}{DECLS} ... \end{verbalist}
%
% This is like verbatim but leaves \, {, and } alone so that control
% sequences may appear in otherwise verbatim text. DECLS is a list of
% declarations for a list environment (in particular, you can set
% \leftmargin to indent verbatim text).
%
\@ifundefined{verbalist}{}{\endinput}

\def\verbalistdospecials
  {\do\ \do\$\do\&\do\#\do\^\do\^^K\do\_\do\^^A\do\%\do\~}

\def\@verbalistdo#1{\noexpand\catcode`\noexpand#1\the\catcode`#1\relax}

\def\@verbalistsave{%
  \let\do\@verbalistdo
  \edef\verbalistrestore{\verbalistdospecials}%
  \let\do\relax}

\newif\ifverbalistbar \verbalistbarfalse

\def\@verbalistbar{\ifverbalistbar\strut\vrule\fi}

\newenvironment{verbalist}[1]
  {\ifnum\@listdepth>5\relax\advance\@listdepth\m@ne\fi
   \begin{list}{}{%
     \itemsep\z@
     \parsep\z@
     \leftmargin\z@
     \rightmargin\z@
     \listparindent\z@
     \itemindent\z@
     \labelsep\z@
     \labelwidth\z@
     #1}%
     \advance\@listdepth\m@ne
     \@verbalistsave
     \let\do\@makeother
     \verbalistdospecials
     \let\do\relax
     \let\@oldpar\par
     \@tempswafalse
     \def\par{\if@tempswa\null\fi
       \@tempswatrue\@oldpar}%
     \obeylines\tt\catcode``=13 \@noligs
     \frenchspacing\@vobeyspaces
     \item[]}%
  {\end{list}}
***END: verbalist.sty

***BEGIN: ruled.sty
% Denys Duchier, Yale University, September 1990
%
% \begin{ruled}{DECLS} ... \end{ruled}
%
% This is a list environment that puts a rule before and after its
% contents. The height of the rule is controled by \ruledheight. DECLS
% is a list of declarations for a list environment (in particular, you
% can set \leftmargin to offset the whole thing, including the rules).
%
\@ifundefined{ruled}{}{\endinput}
\newdimen\ruledheight \ruledheight=0.2pt

\newenvironment{ruled}[1]
  {\ifnum\@listdepth>5\relax\advance\@listdepth\m@ne\fi
   \begin{list}{}{%
     \listparindent\parindent
     \parsep\parskip
     \leftmargin\z@
     \rightmargin\z@
     \itemindent\z@
     \labelsep\z@
     \labelwidth\z@
     #1}%
     \advance\@listdepth\m@ne
     \item[]%
     \vskip-\ht\strutbox
     \expandafter\everypar
     \expandafter{\the\everypar
       \vrule\@height\ruledheight\@width\linewidth\@depth\z@
       \penalty\z@}%
     \ignorespaces}%
  {\ifvmode\else{\unskip\par}\fi
   \vskip-\dp\strutbox
   \moveright\@totalleftmargin
     \hbox{\vrule\@height\ruledheight\@width\linewidth}%
   \end{list}}
***END: ruled.sty

***BEGIN: verbaruled.sty
% Denys Duchier, Yale University, September 1990
%
% \begin{verbaruled}{DECLS} ... \end{verbaruled}
%
% This is a combination of `verbalist' and `ruled' and displays
% verbatim text enclosed by rules. DECLS are declarations for a list
% environment (in particular, you can set \leftmargin to offset the
% whole display).
%
\@ifundefined{verbaruled}{}{\endinput}

\input verbalist.sty
\input ruled.sty

\newenvironment{verbaruled}
  {\begin{verbalist}{}\begin{ruled}}%==> trick! `ruled' takes an argument
  {\end{ruled}\end{verbalist}}
***END: verbaruled.sty