[Tex/LaTex] How to get fontspec to work with text color white in XeLaTeX

colorfontspecxetex

In a previous question ( How do I globally set the text color in XeLaTeX ), I've asked how to globally set a text colour in XeLaTeX and got some excellent answers.

However, while the proposed mechanisms seem to work in most cases, they also seem to fail consistently for the colour white. I'm not sure if this is a bug or if I'm doing something wrong here, but please consider the following example:

\documentclass{report}
\usepackage{xcolor}
\usepackage{fontspec}
\setmainfont[Color=white]{Linux Libertine O}
\setsansfont[Color=white]{Linux Biolinum O}
\setmonofont[Color=white]{Inconsolata}

\pagecolor{darkgray}

\begin{document}
\chapter{A chapter}
\section{A section}
\texttt{Some mono text}
The text above is invisible as it is all black and not white.

{\addfontfeature{Color=yellow} Some yellow text showing up on the dark page.}
{\addfontfeature{Color=white} Some white text invisible on the dark page.}

\end{document}

The example follows @AlanMunn s suggestion on the other question. The result is:

White text is black

The white text is printed in black. Other colours (like yellow in the example) work well.

If I use @Herbert s suggestion of adding

\AtBeginDocument{\color{white}}

\addtokomafont{sectioning}{\color{white}}


to the document, I keep stumbling over environments that are still black, like the captions of figures for example. In any case, the \color command seems to be stronger than the fontspec setting.

Any thoughts or solutions to this?

Best Answer

It seems to be a bug in XeTeX, as

\font\x="Linux Libertine O:color=FFFFFF"
\x ABC\bye

prints ABC in black, while

\font\x="Linux Libertine O:color=FFFFFE"
\x ABC\bye

prints ABC in "almost white".

So the answer might be

\setmainfont[Color=FFFFFE]{Linux Libertine O}

This "explains" Alan's suggestion.

Related Question