Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 6 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.