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 the add a grey highlight to the \texttt command to essentially achieve the same effect as the code blocks on here.

This is something I attempted to do when I first started writing my current document. I don't remember how I got there but the renew command I wrote looks like this:



This gives me the grey highlight, but the font it no longer monospace.

Can anyone help me?

share|improve this question
See this answer for verbatim mode, but it could be what you want – egreg Jan 31 '12 at 19:10
up vote 10 down vote accepted

You need to make a small tweak:


to get normal text \texttt{foo bar} normal text to yield:

enter image description here

Alternative Solution:

Note that the above solution will effect all uses of \texttt{}. If that is not desired, an alternative solution would be to define a custom macro:


and then use \hltexttt{} when you want both the \hl and \texttt effect.




\renewcommand{\texttt}[1]{\OldTexttt{\hl{#1}}}% will affect all \texttt
%\newcommand{\hltexttt}[1]{\texttt{\hl{#1}}}% comment above \renewcommand if want this

normal text \texttt{foo bar} normal text 
share|improve this answer
Great, thanks a lot! – Jivings Jan 31 '12 at 19:48

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.