I want to highlight code inline with a gray background. Preferably with listings
.
This question is related to Colored background in inline listings.
But as my MWE shows it doesn't work with line breaks. Is there a way to fix this? I also tried the soul package, but this produces a lot of errors (comments in MWE):
\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{soul}
\lstdefinestyle{ShellCmd}{
language=bash,
basicstyle=\small\ttfamily,
backgroundcolor=\color{gray!10},
linewidth=0.9\linewidth,
breaklines=true
}
\def\ownstrut{\vrule height5.5pt depth0.8pt width0pt}
\newcommand\shellcmd[1]{\colorbox{gray!10}{\lstinline[style=ShellCmd,mathescape]`#1`}}
%\newcommand\shelltwo[1]{\hl{\lstinline[style=ShellCmd,mathescape]`#1`}} % this produces error
\begin{document}
\shellcmd{command}, some text \shellcmd{a very long command which should not destroy the whole layout when a line break occurs! Maybe it is possible to make even three or more lines}, and here it continues.
%\shelltwo{a very long command which should not destroy the whole layout when a line break occurs! Maybe it is possible to make even three or more lines}
\end{document}