TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question
Perhaps you might enlighten us as to the aim of all of this. – Joseph Wright Oct 10 '11 at 16:55
!+foo+! should be an abbreviation for \texttt{foo}. I guess that \let\?\texttt and \?{foo} is quite simpler. – egreg Oct 10 '11 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 "!+ ... +!". – Justin Bailey Oct 10 '11 at 19:29
up vote 5 down vote accepted

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

share|improve this answer
But the output for !+foo+! yields \texttt{+foo!} instead of \texttt{foo}. – Werner Oct 10 '11 at 16:49
@Werner Yes, you're right. – egreg Oct 10 '11 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! – Justin Bailey Oct 10 '11 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. – Justin Bailey Oct 10 '11 at 20:48
@JustinBailey Does the shorter version work? It should, but I've not made extensive testing. – egreg Oct 10 '11 at 20:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.