🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.text.tex
Article #10439

Re: Looking for flexible verbatim mode

#10439
From: Victor Eijkhout
Date: Sun, 23 Jun 1991 21:28
54 lines
2673 bytes
ferguson@cs.rochester.edu (George Ferguson) writes:

>I often include small chunks of code or output as displays in my text.
>The standard verbatim mode forces these to be aligned flush with the
>lefthand side of the page. In addition, an attempt to fbox the result
>shows that the lines stretch to the right side of the page, presumably
>due to the way the linebreaks are "obeyed". Furthermore, various
>attempts to wrap verbartim displays in other constructs, such as fbox
>and centerline, usually result in an error.

You're contradicting yourself: if fbox results in an error, how
can the above described attempt to fbox 'show that the lines stretch
to the right side o the page'?

Anyways. Your problems derive partly from the fact that
fbox is (silly enough) dfined as \def\fbox#1...
and verbatim text can intrinsically not be enclosed in an argument
(catcodes are frozen when the argument is read, and verbatim mode
works by changing catcodes). The way out is to use the regular
TeX boxes, and not that syntactic sugar that LL made around them.
For instance,
    \vbox{\begin{verbatim} ... \end{verbatim}}
will work fine.

Your problem about lines that are as wide as the page is more
difficult. I once wanted to display input and output next
to each other (for certain parts of my TeX book, to appear later
this year with Addison-Wesley), and I wrote the following macros
for that.

\def\snugbox{\setbox\z@\vbox\bgroup
    \leftskip\z@
    \bgroup\aftergroup\make@snug
    \let\next=}
\def\make@snug{\par\sn@gify\egroup \box\z@}
\def\sn@gify
   {\skip\z@=\lastskip \unskip
    \advance\skip\z@\lastskip \unskip
    \unpenalty
    \setbox\z@\lastbox
    \ifvoid\z@ \nointerlineskip \else {\sn@gify} \fi
    \hbox{\unhbox\z@}\nointerlineskip
    \vskip\skip\z@
    }
\endinput

This should be inserted in an environment where \makeatletter
holds; you can use this as
    \snugbox{ ... whatever, including verbatim ... }
and the result is a box that is as wide as the widest line
in it. This is not totally foolproof, but I've tried to foresee
some abuse.

Victor.
Technical Details
Message-ID: <1991Jun23.212832.2137@csrd.uiuc.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!news.cs.indiana.edu!ux1.cso.uiuc.edu!csrd.uiuc.edu!s41.csrd.uiuc.edu!eijkhout
References: <1991Jun23.200116.23478@cs.rochester.edu>

Show Full Headers
Complete Article Headers
Newsgroups: comp.text.tex
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!news.cs.indiana.edu!ux1.cso.uiuc.edu!csrd.uiuc.edu!s41.csrd.uiuc.edu!eijkhout
From: eijkhout@s41.csrd.uiuc.edu (Victor Eijkhout)
Subject: Re: Looking for flexible verbatim mode
Message-ID: <1991Jun23.212832.2137@csrd.uiuc.edu>
Sender: news@csrd.uiuc.edu (news)
Organization: UIUC Center for Supercomputing Research and Development
References: <1991Jun23.200116.23478@cs.rochester.edu>
Date: Sun, 23 Jun 91 21:28:32 GMT
Lines: 54