This is the code:
\documentclass{article}
\NewDocumentCommand\foo{v}{\texttt{#1}}
\AtBeginDocument{\catcode`\|\active\def|{\foo|}}
\begin{document}
Hello, \foo{world}, |world|!
\end{document}
It doesn't compile:
! Missing control sequence inserted.
<inserted text>
\inaccessible
l.12 \begin{document}
How to fix this? I want to be able to call either \foo{world}
or |world|
and make them arrive to the same \foo
command.
\def|
is wrong. I've also shown how to make the catcode context correct here.\foo{world}
and|world|
both read the argument verbatim. The error is from\AtBeginDocument{\catcode`\|\active\def|{\foo|}}
as you need to make | active outside the macro, as always.shortvrb
.