# Defining font color inside highlight fails

Since I wanted a better readability of highlights of a would be black & white-printed document, I needed to change both the highlighting color (gray) AND the font color (white).

Depending which command you implement inside the other will compile or not: \hl{\textcolor{white}{Fail}} does not work, compiling returns Package xcolor Error: Undefined color '{white}'.

Here's the mwe:

\documentclass{article}
\usepackage{xcolor}
\usepackage{color}
\usepackage{soul} % Enables highlighting
\sethlcolor{gray}

\begin{document}

\textcolor{white}{\hl{Success}}
%% Error:
%% Package xcolor Error: Undefined color {white}'.
\hl{\textcolor{white}{Fail}}

\end{document}


So, in the end, the problem is sorta solved but I thought you might have an answer as to what happens.

-

The error message is the one you get from

  \textcolor{{white}}{Fail}


with spurious doubled braces, and that is in fact the command that is executed.

\hl makes a pre-scan of its argument in order to do whatever it does and then re-constructs the argument to be evaluated. In this instance its reconstruction is not perfect and it inserts extra braces.

You can hide the construct from the scan inside an extra pair of braces

    \hl{{\textcolor{white}{Fail}}}
`

works

-