[comp.text.tex] Tex challenge: improve CenterVerbatim

al@ee.pitt.edu (Alan Martello) (10/05/90)

I need to center some verbatim text in latex which is part of the
running text of my paper.

Some stipulations:
1  - can't float (i.e. can't use figures / tables)
2  - must NOT require addition of hard spaces anywhere or
     explicit CR's
3  - must not require knowing the length of the longest line
4  - MUST work within latex, optionally within plain tex
5  - must not necesarily generate space above/below (optionally ok)

Here is what I have so far -- its deficits are that it needs
hard spaces for lines starting with a space (or blank 
lines) and it must be told how long the line is.  This second
problem is particularly annoying if the line length isn't easy
to compute (i.e. if there are special - math, etc. - characters
in the longest line).

Its advantage is that it is not totally verbatim but allows
the inclusion of TEX commands (although I do rebind '\' to
'@' since my text had lots of '\' characters).

improvements from the guru's or something better in the archives?

*******************************************************************
       Alan R. Martello        Electrical Engineering Dept.
        al@ee.pitt.edu           University of Pittsburgh
*******************************************************************

%
%  Environment to typeset something verbatim and center it within the'
%  normal text stream
%  NOTES: 
%	1 argument required: the longest line used to compute centering info
%
\newenvironment{CenterVerbatim}[1]{
\catcode`\@=0\catcode`\\=12%
\begin{center}\obeylines\obeyspaces\tt\setbox0=\hbox{#1}\begin{minipage}
}[t]{\wd0}}{\end{minipage}\end{center}}

\begin{CenterVerbatim}{------------------------------------------}
This is a test
~
~  of how it works \ just fine $@rightarrow$ to the end
@end{CenterVerbatim}

------------------------------  end of message  ------------------------------