Take the 2-minute tour ×
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.

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.

share|improve this question
    
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
add comment

2 Answers 2

up vote 3 down vote accepted
\usepackage{xcolor}
\colorbox{gray!25}{\texttt{this\_instead}}

Customize for your own needs

share|improve this answer
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
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

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.