TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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'm trying to define shorthand macros for \texttt that are a bit like the \verb ones. The end result is to do +asdf+ and this have the same effect as \texttt{asdf}. This is like the DefineShortVerb command in the fancyvrb package, but instead of verbatim I want texttt as the underlying command.

First, I can obtain a macro like \ttt+asdf+ via the xparse package:

% want \ttt[delimiter]#1[delimiter] for \texttt{#1}:

This works.

Is there some way to take the next step and use [delimiter]asdf[delimiter] to mean \texttt{asdf}?

For example, if I were using fancyvrb I'd use DefineShortVerb:

+asdf+ % typesets a verbatim 'asdf'

My question is: Is there any way I can emulate this behaviour but using \texttt as the base command as opposed to \verb?.

It doesn't have to be as sophisticated as providing a DefineShortVerb macro; I'd just like the [delmiter]text[delimiter] functionality.

(Another way to go about it - is there some way I can override a fancyvrb command to use \texttt instead of \verb as the base command?)


share|improve this question
up vote 4 down vote accepted

You can make + (or whatever symbol you choose) into a command character and then use \def to have it do whatever you want:



+abc def+

Here \catcode`+=\active makes + an “active” character and then \def+#1+{\texttt{#1}} defines + as a macro that takes one parameter that is delineated by another + and passed to \texttt.

share|improve this answer
This is exactly what I'm after - thanks a lot! I had a look at the source for the shortvrb package but it's a bit too complicated for me at my current level of TeX mastery. Thanks for the explanation too. – mathematical.coffee Mar 28 '12 at 4:37
you defined in '+'. When we use + sign in math mode "+" sign clashing. Check it. – Mu30 Mar 28 '12 at 5:51
I know. I just chose '+' as an example for the delimiter - I can make it anything I like. – mathematical.coffee Mar 28 '12 at 6:01
@S.Murugan: That happens with any symbol you use for this purpose. – Caramdir Mar 28 '12 at 15:26

Check this will work fine:


\verb+asdf+  typesets a verbatim 'asdf' $a+b+c$
share|improve this answer
That's not what I was after. I know about fancyvrb and \verb+asdf+, but what I want is to achieve the affects of \DefineShortVerb{\+} with +asdf+ (or any delimiter of my choosing really), but instead using \texttt intead of verbatim. – mathematical.coffee Mar 28 '12 at 6:02

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.