I created a macro to easily shift into typewriter mode, ala markdown or fancyvrb's "short verbatim" command. It works everywhere but in \captions. In that case, TeX fails saying I've exceeded capacity. Is my approach untenable? Below is a MWE. The example outside \caption, !+foo+!, works fine. The example inside \caption fails.
\chardef\plus=`+\chardef\bang=`!
\catcode`!=\active\catcode`+=\active
\def\startTTA{\futurelet\next\startTTB}
\long\def\startTTB#1{\ifx\next+\expandafter\startTTC\else\bang\expandafter#1\fi}
\def\startTTC{\begingroup\ttfamily\global\let+=\stopTTA\global\let!=\bang}
\def\stopTTA{\futurelet\next\stopTTB}
\long\def\stopTTB#1{\ifx\next!\expandafter\stopTTC\else\plus\expandafter#1\fi}
\def\stopTTC{\endgroup\global\let+=\plus\global\let!=\startTTA}
\let!=\startTTA\let+=\plus
\documentclass{article}
\begin{document}
!+foo+!
\begin{figure}
\tracingmacros=1\tracingcommands=2
\caption{!+foo.+!}
\tracingmacros=0\tracingcommands=0
\end{figure}
\end{document}
Suggestions for improving this macro are welcome as well!
!+foo+!should be an abbreviation for\texttt{foo}. I guess that\let\?\textttand\?{foo}is quite simpler. – egreg Oct 10 '11 at 17:35DefineShortVerb" command with the hash symbol (#) so I could write things like "#int x = 0#" and have it come out in typewriter. That breaks in captions, though, and I have to resort to\texttt{...}.\textttisn't so burdensome, but I thought it would be fun to figure out how do it "markdown" style, and delimit typewriter text using something "!+ ... +!". – Justin Bailey Oct 10 '11 at 19:29