0

This is the code that fails to compile:

\documentclass{article}
\usepackage{fancyvrb}
\NewDocumentCommand\foo{v}{\texttt{#1}}
\catcode`\|\active
\AtBeginDocument{\catcode`\|\active\def|{\foo|}}
\catcode`\| 12 %
\begin{document}
\section{Hello, |world|!}
\end{document}

Is it at all possible to fix it, having in mind that ltxdoc also fails with similar code (but with a different error message):

\documentclass{ltxdoc}
\begin{document}
\section{Hello, |world|!}
\end{document}
yegor256
  • 12,021

1 Answers1

2
\documentclass{article}
\usepackage{fancyvrb}
\NewDocumentCommand\foo{v}{\texttt{#1}}
\catcode`\|\active
\AtBeginDocument{\catcode`\|\active\protected\def|{\foo|}}
\catcode`\| 12 %
\begin{document}
\section{Hello, |world|!}
\end{document}
David Carlisle
  • 757,742
  • 1
    like the last question, this is adding literally a single token. I'm not sure writing code at a rate of one question per token is a useful way to proceed. – David Carlisle Nov 15 '22 at 23:25
  • On the other hand, this shows how difficult it is to write bullet-proof code and to understand/fix other people's code when it doesn't work as expected. Unless OP wants to learn how TeX works (most users understandably don't want to), they will be stuck with having to ask a new question every time something goes wrong. – user202729 Nov 16 '22 at 07:01