这是编译失败的代码:
\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}
是否有可能修复它,考虑到ltxdoc
类似的代码也会失败(但错误消息不同):
\documentclass{ltxdoc}
\begin{document}
\section{Hello, |world|!}
\end{document}
答案1
\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}