[comp.text.tex] boxing verbatim in latex

lubkt@spectrum.CC.Lehigh.EDU (Binod K. Taterway) (05/15/91)

I want to place a box around the verbatim environment. Unfortunately,
when I do the following,

	% Make boxes. Inspired from Exercise 21.3 from TeXbook.
	\def\boxit#1{\vbox{\hrule\hbox{\vrule \kern1.2pt
	 \vbox{\kern1.2pt{ \parindent 0pt
	 \tt #1}\kern1.2pt}\kern1.2pt\vrule}
	 \hrule}}
	
	\boxit{
	\begin{verbatim}
	this better come out in boxed verbatim mode ...
	\end{verbatim}
	}

I get the following error message:

	
	! Argument of \@xverbatim has an extra }.
	<inserted text>
	                \par
	<to be read again>
	                   }
	\boxit ...vbox {\kern 1.2pt{ \parindent 0pt \tt #1
	                                                  }\kern 1.2pt}\kern 1.2pt\v...
	
	\boxed ...t}{\boxit {\vbox {\hsize \textwidth #1}}
	                                                  } \end {flushleft}
	l.523 }
	
	? h
	I've run across a `}' that doesn't seem to match anything.
	For example, `\def\a#1{...}' and `\a}' would produce
	this error. If you simply proceed now, the `\par' that
	I've just inserted will cause me to report a runaway
	argument that might be the root of the problem. But if
	your `}' was spurious, just type `2' and it will go away.
	
Well, I have tried many other ways. I actually tried using the
definition of verbatim in boxit, but that didn't work either. Do you
know a way to do this? Doesn't matter if it is simple or complicated.

BTW, I want the box to be the same size as textwidth, i.e., from the
global leftmargin to the global rightmargin, and not the current
left margin. For example,

	if my left margin is here ..
+-----------------------------------------------------------------------+
| I want the boxed environment like this.				|
+-----------------------------------------------------------------------+
	any clues?

Thanks in advance.


--

Binod Taterway                     |    lubkt@spectrum.CC.Lehigh.EDU
Sr. User Consultant                |    bt00@lehigh.BITNET
Lehigh University Computing Center |    (215) 758-3984 (off)
Bethlehem, PA 18015                |    (215) 758-4983 (fax)

anita@brahms.udel.edu (Anita Marie Hoover) (05/16/91)

In article <LUBKT.91May15092725@spectrum.CC.Lehigh.EDU> lubkt@spectrum.CC.Lehigh.EDU (Binod K. Taterway) writes:
=>
=>I want to place a box around the verbatim environment. Unfortunately,
=>when I do the following,
=>
=> [stuff deleted]	
=>
=>	if my left margin is here ..
=>+-----------------------------------------------------------------------+
=>| I want the boxed environment like this.				|
=>+-----------------------------------------------------------------------+
=>	any clues?
=>

Just to point out that you must make sure that the text inside the
verbatim environment does not exceed the defined width.  Here is an
example file.  It defines a new environment called ``boxverbatim''.
It calculates the width by subtracting the space between columns (in
this case, the beginning and ending extra space) and the width of
the rule.  Try it out and see if this helps.

------------------ boxedverb.tex --------------------------
\documentstyle {article}
\newlength{\verbboxwidth}
\setlength{\verbboxwidth}{\textwidth}
\addtolength{\verbboxwidth}{-2\arrayrulewidth}
\addtolength{\verbboxwidth}{-2\tabcolsep}
\newenvironment{boxverbatim}%
   {\begin{flushleft}%
    \begin{tabular}{|l|}\hline%
    \\%
    \begin{minipage}{\verbboxwidth}}%
   {\vspace*{.5\baselineskip}%
    \end{minipage}%
    \\\hline%
    \end{tabular}%
    \end{flushleft}}
\begin{document}
A paragraph before we try to box some verbatim text.  It is quite
easy, especially if you use the tools provided with \LaTeX.

\begin{boxverbatim}
\begin{verbatim}
\begin{description}
\item [Attributive Predicate:] {\em The electron has
      both a mass and a charge.}
\item [Renaming Predicate:] {\em The negative electrode
      is called the cathode.}
\item [Conclusion Predicate:] {\em From the experiment,
      it was concluded that the electron had a charge
      that was negative.}
\end{description}
\begin{equation}
x = y + z
\end{equation}
\end{verbatim}
\end{boxverbatim}
 
A paragraph after we try to box some verbatim text.  It is quite
easy, especially if you use the tools provided with \LaTeX.
\end{document}