Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!cbmvax!kevin From: kevin@cbmvax.commodore.com (Kevin Klop) Newsgroups: comp.text.tex Subject: Re: 'code' environment with caption Keywords: environment verbatim caption Message-ID: <12542@cbmvax.commodore.com> Date: 11 Jun 90 18:28:29 GMT References: <10133@chaph.usc.edu> <1990Jun11.091343.10487@hod.uit.no> Reply-To: kevin@cbmvax (Kevin Klop) Distribution: comp.text.tex Organization: Commodore, West Chester, PA Lines: 61 In article <1990Jun11.091343.10487@hod.uit.no> asbjorns@sfd.uit.no (Asbjorn Saetran) writes: >I'm writing a paper in which I need an environment for short (<20 lines) >code fragments. The code should be typeset in \tt, just like in the verbatim >environment. But in addition I would to be able to add a caption, for example >to give a short explanation to the code. An example: > >text text text text text text > > > /* > * Fill InitBlock > */ >#ifdef MONA > E->ed_ib.ib_mode = bit(15); /* promiscues mode */ >#endif > E->ed_ib.ib_padr[0] = etheraddr[1]; > E->ed_ib.ib_padr[1] = etheraddr[0]; > > > Code fragment 1. Code for setting the mode bit in the Lande chip. > > >more text text text text text text > Funny you should ask. It was for this prticular type of operation that I asked about the indenting earlier. Here's how I solved it in plain TeX: \def\Listing{ \interspace % A macro that places a reasonable amount of blank space on the page $$\ast\ast\ast\ast$$ \halfinterspace \begingroup \tt \advance\leftskip by 36pt \obeylines } \def\EndListing#1{ \endgroup \halfinterspace \centerline{Listing \the\ListingNo. #1} \advance\ListingNo by 1 } \countdef\ListingNo = 127 So, to typeset your code, I would have used: \Listing /* * Fill InitBlock */ #ifdef MONA E->ed_ib.ib_mode = bit(15); /* promiscues mode */ #endif E->ed_ib.ib_padr[0] = etheraddr[1]; E->ed_ib.ib_padr[1] = etheraddr[0]; \EndListing{Code for setting the mode bit in the Lande chip.} -- Kevin --