Sign up ×
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.

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

1 Answer 1

up vote 9 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.