6

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 04 '13 at 21:19
  • 3
    @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 04 '13 at 21:21
  • @Werner DL6ER has exactly what I wanted. – TheRealFakeNews Apr 04 '13 at 21:21

2 Answers2

6

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}
\severb`abc_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).

enter image description here

egreg
  • 1,121,712
3
\usepackage{xcolor}
\colorbox{gray!25}{\texttt{this\_instead}}

Customize for your own needs

MrD
  • 2,716