I'm trying to add background color to \texttt text, and defining a command for that like this:
\newcommand{\code}[1]{\texttt{\hl{#1}}}
. Sometimes those lines span more than a few words (with or without spaces), and I use \allowbreak
to make it break without hyphenation on some places (somewhere it's before punctuation such as .
, somewhere it's after space, somewhere it's before capital letter). Without \hl, it worked like expected.
However, when I put \hl, first it complains about I came across hyphenatable material enclosed in group braces, which I can't handle. Either drop the braces or make the material unbreakable using an \mbox (\hbox).
on a few places where I do have spaces, followed by \allowbreak
(e.g. \code{CREATE \allowbreak TABLE}
). Second, I've noticed it broke text before \allowbreak
instead of after on a few places and dropped last character or five, without reporting any error. It also seems to struggle with coloring text after breaking on a few places, so highlight spans into the right margin, but skips beginning of the next line.
I'm using soulutf8
if it makes any difference, and highlighted text is sometimes in Cyrillic, sometimes in Latin, sometimes in both.
Am I using the right tool for the job? If so, how to set background color on tt text with custom break points?
Here's the MWE for some of the issues, with (unexpected) result in comment after each paragraph. I'm not including \allowbreak after space part, because as pointed out it's practically useless (though I'd expect it to be ignored, and not throw an error):
\documentclass[11pt]{book}
\usepackage[serbianc]{babel}
\usepackage{xcolor, soulutf8}
\usepackage{vmargin}
\begin{document}
\newcommand{\code}[1]{\texttt{\hl{#1}}}
\setmargrb{0.8in}{1in}{1.6in}{1.6in}
Омотач за податке прикупљене пре 2017. године је дефинисан класом
\code{rs.lukaj\allowbreak.upisstats\allowbreak.scraper\allowbreak.obrada\allowbreak.UcenikWrapper},
унутар које се налазе класе. %highlight goes over margin and cut off
Омотач за податке прикупљене 2017. године је дефинисан класом
\code{rs\allowbreak.lukaj\allowbreak.upisstats\allowbreak.scraper\allowbreak.obrada2017\allowbreak.UcenikW},
и за разлику од %text broke in the middle and cut off
Унутар \code{conf/} директоријума се налазе конфигурацијски фајлови.
Најважнији део \code{conf/\allowbreak application\allowbreak.conf}
фајла су параметри % text cut off even when not broken
ће се метода позвати за сваку путању. Нпр. ако корисник посети
\code{\{адреса\_сервера\}\allowbreak/query\allowbreak?initial=asdf},
позваће се % text broken before allowbreak and cut off
\end{document}
And as a result I'm getting this
CREATE \allowbreak TABLE
is rather strange input as line breaking is allowed anyway at the space.