I would like to write some code inline with other text. The code should match other code I write in the document though. So it should be highlighted (let's say yellow), should be in typewriter font and should not need any escaping of special characters. Also, it should be able to break at the end of the line. I can do the individual things but cannot combine them together.
This post seems to do similar things and is where I got the idea to use the soul package but didn't solve the problem of escaping special characters and just putting it into \verb doesn't work: Colorbox does not linebreak
MWE:
\documentclass{minimal}
\usepackage {color}
\usepackage {soul}
\usepackage {listings}
\lstset{breaklines=true, basicstyle=\ttfamily}
\begin{document}
text \colorbox{yellow}{\texttt{Code which cannot break lines and needs special characters escaped \_ bla bla bla very long line of code}} text
\sethlcolor{yellow}
text \texttt{\hl{Code which can break very long lines and is highlighted but needs escaping of special characters \_ }} text
text \lstinline[language={}]{Code which can break lines of very long code and can escape special characters such as \ and & but cannot be highlighted} text
\end{document}
