# Multiline code listings in CWEB

Perhaps this is insane, but I would like to include code listings in a CWEB program, because the program is processing source code in another language. But how do I create multiline verbatim code listings in CWEB?

@ Let's say we want to write a \.{CWEB} program that manipulates \.{bibtex} files.
How can we do a multiline verbatim code listing?
This doesn't work:

\.{@Book{Author:2000,
author={Last,First},
title={Title},
year=2000,
}}

This almost outputs the code correctly, but is not verbatim and defeats the purpose:

\halign{#\cr
\.{@@Book\{Author:2000,}\cr
\.{  author= \{Last, First\},}\cr
\.{  title=  \{Title\},}\cr
\.{  year= 2000,}\cr
\.{\}}\cr
}

Using an \.{eplain} macro makes it impossible to compile:

\let\ifpdf\undefined
\input eplain
\pdffalse

\verbatim|code|endverbatim

% only compiles if you enter |endverbatim\bye afterward at command line
% the output is still erroneous


@ Let's say we want to write a \.{CWEB} program that manipulates \.{bibtex} files.
How can we do a multiline verbatim code listing?

Like this?

\begingroup\tt\obeylines\catcode\{12 \catcode\}12
@@Book{Author:2000,
author={Last,First},
title={Title},
year=2000,
}
\endgroup


Based on David Carlisle's answer, I defined these macros, which allow almost verbatim input (I still have to escape a few characters).

\def\beginlisting{%
\par\vskip\baselineskip%
\begingroup%
\tt\obeylines\obeyspaces%
\catcode\{12\catcode\}12%
}
\def\endlisting{%
\endgroup\par%
\vskip\baselineskip%
}

@ Let's say we want to write a \.{CWEB} program that manipulates \.{bibtex} files.
How can we do a multiline verbatim code listing?

\beginlisting
@@Book{Author:2000,
\  author = {Last,First},
\  title  = {Title},
\  year   = 2000,
}
\endlisting

Thank you, David Carlisle!