# Verbatim inside def in eplain

How can I use \verbatim inside my own \def with eplain? The eplain reference suggests to change catcodes to accomplish this, but doesn't provide an example of this.

Crarification: I would like to define \ttcode so that when I would use it (\ttcode{some text which can span several par's}, it would expand thusly:

\bigskip\verbatim some text which can span several par's
|endverbatim\bigskip\noindent

-
Just so that I understand correctly, the argument of \ttcode cannot contain a { or a } or at least an unbalanced { or }? – Aditya Oct 14 '10 at 14:47
If it cannot contain "{" or "}", then I guess I'm better off using \verbatim "manually". – morbusg Oct 15 '10 at 6:30

\def\ttcode{\bigskip\verbatim\ttcodehelper}
\begingroup
\catcode\{12
\catcode\}12
\catcode<1
\catcode>2
\long\gdef\ttcodehelper{#1}<#1\endverbatim\bigskip\noindent>
\endgroup
asdf
\ttcode{Some text

&\$%#||

which can span multiple paragraphs.}
asdf

-
For some reason, it still gave me the "doesn't match its definition" -error. Is it right to use \endverbatim above, as eplain \verbatim changes the "\"-escape to "|" (if I've understood correctly)? – morbusg Oct 15 '10 at 6:24
@morbusg: The above code preceded by \input eplain and followed by \bye gives you an error? It compiles just fine for me. And yes, \endverbatim is correct. You have to consider the category code of \ and | at the time of \ttcodehelper's definition which is when the replacement text gets tokenized. – TH. Oct 15 '10 at 6:59
@TH: I tried it with a blank new document with just the above, and it compiled for me, too. I must have had some typo somewhere or the order of other definitions mattered (I put the ttcode definition right after \input eplain this time). Thank you very much! – morbusg Oct 15 '10 at 7:20
Is it somehow possible to use this inside another macro, ie: \long\def\foo#1{#1} \foo{bar\par\ttcode{baz}} (it gives: "Use of \ttcodehelper doesn't match its definition.")? – morbusg Dec 22 '10 at 19:59
@morbusg: I don't believe so. There are two problems, one general, one specific. The general problem is that the argument gets tokenized when the macro gets expanded. This is a problem with any macro that changes category codes. The specific problem here is that \ttcodehelper is looking for braces with category code 12 to delimit its argument. It's analogous to \def\foo<#1>{...}. The argument to \foo must appear between < and >. The only difference here is that the category codes for {} and <> have been swapped, hence \long\gdef\ttcodehelper{#1}<...>. – TH. Dec 22 '10 at 20:14