Can I have a delimited macro with a literal # in the parameter text?

The TeXbook, page 203, says in the first doubly dangerous paragraph

Now that we have seen a number of examples, let’s look at the precise rules that govern TeX macros. Definitions have the general form

\def⟨control sequence⟩⟨parameter text⟩{⟨replacement text⟩}

where the ⟨parameter text⟩ contains no braces, and where all occurrences of { and } in the ⟨replacement text⟩ are properly nested. Furthermore the # symbol has a special significance: In the ⟨parameter text⟩, the first appearance of # must be followed by 1, the next by 2, and so on; up to nine #’s are allowed.

There is no way for the parameter text to contain a (category code 6) #, because of the rule stated above.

As usual in the TeXbook, this is not the complete truth; in the second doubly dangerous bend on page 204 one reads

A special extension is allowed to these rules: If the very last character of the ⟨parameter text⟩ is #, so that this # is immediately followed by {, TeX will behave as if the { had been inserted at the right end of both the parameter text and the replacement text. For example, if you say ‘\def\a#1#{\hbox to #1}’, the subsequent text ‘\a3pt{x}’ will expand to ‘\hbox to 3pt{x}’, because the argument of \a is delimited by a left brace.

However, this special extension has no favorable consequence towards your aim.


You can't really do what you ask, but you can ignore the # while parsing the arguments, then get rid of it:

enter image description here

\def\test#1#{\def\tmp##1{#11}\zz}
\def\zz#1{(\tmp{})[#1]}

\test hello#{world}

\bye