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 4 '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 4 '13 at 21:21
  • @Werner DL6ER has exactly what I wanted. – AlanH Apr 4 '13 at 21:21
3
\usepackage{xcolor}
\colorbox{gray!25}{\texttt{this\_instead}}

Customize for your own needs

  • 3
    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
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.