[comp.text.tex] Help with verbatim in TeX

dundas@granite.jpl.nasa.gov (John Dundas) (11/20/90)

(Warning: novice user ahead...)  I am using the following macros in order
to typeset code listings (taken from WEB book, p. 243):

\chardef\other=12
\def\ttverbatim{\begingroup
	\catcode`\|=\other
	\catcode`\\=\other
	\catcode`\{=\other
	\catcode`\}=\other
	\catcode`\$=\other
	\catcode`\&=\other
	\catcode`\#=\other
	\catcode`\%=\other
	\catcode`\~=\other
	\catcode`\_=\other
	\catcode`\^=\other
	\obeyspaces \obeylines \tt}
{\obeyspaces\global\let =\ } % from TeXbook, p. 381
\outer\def\verbatimcode{\par\ttverbatim\leftskip=0em\parskip=0pt
	\baselineskip=12pt\ttfinishcode}
{\catcode`\|=0 |catcode`|\=\other % | is temporary escape character
	|obeylines % end of line is active
	|gdef|ttfinishcode#1^^M#2\endverbatimcode{#1#2|endgroup}}

These macros generally work well except that blank lines are discarded.
Can anyone suggest what to change to make blank lines appear as intended?

Thanks in advance, please reply directly.

John Dundas
dundas@sapphire.jpl.nasa.gov

eijkhout@s41.csrd.uiuc.edu (Victor Eijkhout) (11/20/90)

dundas@granite.jpl.nasa.gov (John Dundas) writes:

>(Warning: novice user ahead...)  

Nothing to be ashamed of. And this is a tricky subject you're attacking.

>I am using the following macros in order
>to typeset code listings (taken from WEB book, p. 243):

[verbatim macros deleted]

>These macros generally work well except that blank lines are discarded.
>Can anyone suggest what to change to make blank lines appear as intended?

What happens is that a blank line generates a par, which doesn't do
anything as the previous line end was also a \par.
The remedy is to redefine \obeylines slightly:
somewhere in \obeylines it says
\def^^M{\par}
Change this into
\def^^M{\par\leavevmode}

>Thanks in advance, please reply directly.

Oops.

>John Dundas
>dundas@sapphire.jpl.nasa.gov

Victor.