# How to include/mark code in the middle of the text line

I want to include short code for in a single line that is marked by a grey background. Here is an example:

I want to include code of this form that is in the middle of the text.

• Do you mean find the middle of a line and then mark it or just mark some text that may be in the middle ? – Hafid Boukhoulda Sep 26 '18 at 10:51

Here is an example built from the tcolorbox package. You can get all relevant information and customisation options from the well detailed manual

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{xparse}
\begin{document}
An example with the \tcboxverb{tcolorbox} package with its \tcboxverb{\tcboxverb} command from the \tcboxverb{xparse} library
\end{document}


This is perhaps somewhat fragile, but works:

\documentclass{article}

\usepackage{xcolor}

\colorlet{codecolor}{black!30}
\newcommand{\codebox}[1]{%
\colorbox{codecolor}{\ttfamily \detokenize{#1}}%
}

\begin{document}

I want to include \codebox{code of this form} that is in the middle of the text.

I want to include \codebox{code_ of^ this\ form} that is in the middle of the text.

\end{document}