[Tex/LaTex] Highlight \verb in inline text

backgroundshighlightingverbatim

I'm new in LaTeX and I'm searching for solution to highlight verbatim text inside paragraph (for example, it is like on this page, where code is highlighted). Can anyone help me with this?

Let say, that I have a paragraph and inside is some words where I use \verb|| to show some code parts, but I'd like that this is highlighted or it has background color, juts like it is highlighted in this page. For normal text I can use \newcommand{\hilight}[1]{\colorbox{gray!10}{some text}}, but this command doesn't work with \verb, so I can't use it. I'm trying to find solution and searching over the internet, but I didn't fid so far.

Thanks for your help.

Best Answer

It's as simple as

\documentclass{article}
\usepackage{xcolor}
\usepackage{newverbs}
\newverbcommand{\cverb}{\color{red}}{}

\begin{document}
Text \cverb|&*}| and more text
\end{document}

enter image description here

Version with a macro for having a background text:

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

\newverbcommand{\cverb}{\color{red}}{}
\newverbcommand{\bverb}
  {\begin{lrbox}{\verbbox}}
  {\end{lrbox}\colorbox{gray!30}{\box\verbbox}}

\begin{document}
Text \cverb|&*}| and more text

Text \bverb|&*}| and more text
\end{document}

enter image description here