I'd like to highlight code with a gray
background like StackExchange does.
I know that I can set bgcolor
in minted
to put a solid background color on inline code.
However, this makes minted
use colorbox
which doesn't wrap across long lines like markdown does:
Here is a normal sentence that is short.
here_is_a_very_long + code_snippet + that_ends_up + wrapped
. The box does not extend into the right margin.
My understanding is that the soul
package provides exactly this type of highlighting. My naive attempt to use it, building off the approach in https://tex.stackexchange.com/a/276750/41112, was something like:
\documentclass{article}
\usepackage{xpatch}
\usepackage{minted}
\usepackage{xcolor}
\usepackage{soul}
\definecolor{bg}{rgb}{0.95,0.95,0.95}
\setminted{breaklines=true}
\newmintinline[python]{python}{bgcolor=bg}
% this is the bit of code in question
\makeatletter
\xpatchcmd{\minted@inputpyg@inline}{%
\colorbox%
}{%
\long\def\color@b@x##1##2##3%
{\sethlcolor{##2}\hl{##3}}%
\colorbox%
}{\typeout{Success}}{\typeout{Failure}}
\makeatother
\begin{document}
Here is a normal sentence that is short.
\python{here_is_a_very_long + code_snippet + that_ends_up + wrapped}.
The box should not extend into the right margin.
\end{document}
Unfortunately, this appears to send LaTeX into an infinite loop; presumably because hl
is using colorbox
under the hood complains about a missing.
Does this approach look possible? Is there a way to restore the old meaning of \color@b@x
inside its replacement, so that this recursion is avoided?
Unfortunately, this complains about an extra }
. Does this approach look possible? What is going wrong here?
breakable
library fortcolorbox
doesn't appear to handle breaking across lines of text, but only breaking vertically across columns. Is there another feature oftcolorbox
I'm missing?