# Highlighting code like one would in a SE post

When posting on SE, users can "highlight" code by using the  symbol. Is there any way to get that in LaTeX?

My intention is to highlight segments of code or particular functions. To be clear, I'm not speaking of something like Syntax highlighting for different programming languages. I want to be able output this_instead (no magic wizardry involved).

I'm not sure what this is called, so I didn't know how to search for it. I'll delete it if it's a duplicate though.

• Perhaps others share my thoughts, but I'm definitely not clear on what you're after... – Werner Apr 4 '13 at 21:19
• @Werner I think the OP would like the output from \lstinline!this_instead! but without typing \lstinline! and only typing backticks.... sounds like some category code wizardry would be needed, and a very dangerous path... – cmhughes Apr 4 '13 at 21:21
• @Werner DL6ER has exactly what I wanted. – AlanH Apr 4 '13 at 21:21

\usepackage{xcolor}


• You ought to mention that you need color package for \colorbox and if you use the ! color syntax you need xcolor – David Carlisle Apr 4 '13 at 21:22

Using Martin Scharrer's newverbs package:

\documentclass{article}
\usepackage{newverbs,xcolor}

\newverbcommand{\severb}
{\begin{lrbox}{\verbbox}}
{\end{lrbox}\colorbox{gray!25}{\box\verbbox}}

\begin{document}
\severbabc_def
\end{document}


Note that the save bin \verbbox is provided by the package.

The usage of \severb is identical to \verb` (including the *-variant).