I'm working on applying the answer to my question about color and ligatures and have run into a problem when the color change is supposed to happen inside a discretionary. Boiled down to a MWE and it looks like this:
\documentclass[12pt]{article} % use larger type; default would be 10pt
\usepackage{xcolor}
\usepackage{luacolor}
\definecolor{grebackgroundcolor}{RGB}{255,200,0}
\listfiles
\def\foobar#1#2{%
\hbox to 0pt{%
{\color{grebackgroundcolor}#2}%
}%
#1%
\relax %
}%
\begin{document}
\noindent\foobar{test}{\rule[-2pt]{36pt}{12pt}}
\noindent\discretionary{}{}{\foobar{test}{\rule[-2pt]{36pt}{12pt}}}
\end{document}
If you compile the MWE, you'll see that the first instance of \foobar
works fine, but in the second, the rule ends up being black instead of orange. Remove the loading of luacolor
and both instances work fine. How do I change color such that the color change will happen inside a \discretionary
when luacolor
loaded?
{\color{grebackgroundcolor}#2\hss}
would probably be better inside\foobar
to avoid an overfull\hbox
(you don't even need the outer braces since\hbox
defines a group).\hss
. It got stripped out during the reduction to MWE.\textcolor
) otherwise the colour restore will be outside the box.sbox
so I ought to know the difference:-)