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?)



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.

  • 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 murugans2katgmail 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$
  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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