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.


Suggestions for improving this macro are welcome as well!

  • 3
    Perhaps you might enlighten us as to the aim of all of this.
    – Joseph Wright
    Commented Oct 10, 2011 at 16:55
  • !+foo+! should be an abbreviation for \texttt{foo}. I guess that \let\?\texttt and \?{foo} is quite simpler.
    – egreg
    Commented Oct 10, 2011 at 17:35
  • @JosephWright I am writing a document with a lot of typewriter type (for code samples). I found myself using fancyvrb's "DefineShortVerb" 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{...}. \texttt isn't so burdensome, but I thought it would be fun to figure out how do it "markdown" style, and delimit typewriter text using something "!+ ... +!". Commented Oct 10, 2011 at 19:29

1 Answer 1


The problem is in the definition of \startTTB and \stopTTB with an argument; moreover, the active ! and + should be protected against expansion in write operations:


It's not necessary to do global redefinitions. With the two \@gobble commands, the + or ! characters are swallowed.

A shorter set of macros will do the same:


However, I don't see where this is more efficient than declaring


and writing

  • But the output for !+foo+! yields \texttt{+foo!} instead of \texttt{foo}.
    – Werner
    Commented Oct 10, 2011 at 16:49
  • @Werner Yes, you're right.
    – egreg
    Commented Oct 10, 2011 at 17:03
  • That pretty much worked -- I needed to add a command to gobble the trailing + or ! (on start and stop) to \startTTC and \stopTTA, or extra characters showed up in the output. Thanks very much! Commented Oct 10, 2011 at 18:33
  • "That" in my previous comment refers to the first block of code given by @egreg. While the last macro given does the same thing, I still want to use my silly markdown syntax. Commented Oct 10, 2011 at 20:48
  • @JustinBailey Does the shorter version work? It should, but I've not made extensive testing.
    – egreg
    Commented Oct 10, 2011 at 20:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .