I'm trying to highlight text using the \texttt
font and a background color (pretty much like the highlighting on StackExchange [i.e., this
]. I already tried it using a colorbox
, it doesn't support line breaks though, resulting in:
Alternatively, I found a package called soul
for highlighting, but in my opinion it's visually not as appealing as the colorbox because of the missing padding, it will look like this:
On the left is the colorbox, on the right is the soul
package.
My coding:
\usepackage{color}
\usepackage{soul}
\definecolor{lightgrey}{rgb}{0.925, 0.925, 0.925}
\sethlcolor{lightgrey}
\newcommand{\codebox}[1]{\texttt{\colorbox{lightgrey}{#1}}}
\newcommand{\codebox2}[1]{\texttt{\hl{#1}}}
Any ideas how to overcome these caveats?
UPDATE: As mentioned in the comments below \texttt
doesn't support line breaks as well which makes the problem even worse.
\texttt{}
does not break anyway, this is twice worsed idea to use\colorbox
and\texttt