# Xelatex, and strange textcolor behavior in tikz

Here is a minimal working example:

\documentclass{beamer}
\usepackage{tikz}

\setbeamercolor{background canvas}{bg=black}
\setbeamercolor{normal text}{fg=white}

\begin{document}

\begin{frame}
\frametitle{Test}

Normal \textcolor{red}{Red} Normal

\begin{tikzpicture}
\node at (0,0) {Normal \textcolor{red}{Red} Normal};
\end{tikzpicture}

\end{frame}

\end{document}


Compiling this in pdflatex gives the expected output:

But compiling this in xelatex gives the following strange behaviour:

The text following the \textcolor{red}{Red} seems to be defaulting back to black in xelatex. Is there a way to fix this?

• Not sure, but try {\textcolor{red} Red}. – Karlo Jun 9 '16 at 9:03
• That only changes the first letter ('R') to red. Again, xelatex makes 'ed Normal' in black. – Ramprasad Jun 9 '16 at 9:06
• This is a bug reported already in sourceforge.net/p/pgf/bugs/362 and regardless of XeTeX if I remember correctly. – percusse Jun 9 '16 at 10:13
• Ah. Thanks! Until it is resolved, I'll resort to using a macro \Normal{..} or something. – Ramprasad Jun 9 '16 at 10:48

There are similar questions around, for example:

The main question is that at the end of \textcolor there is a \reset@color which does not know what is the proper color to restore.

The problem evolves when comes in. Basically the story is as follows:

1. loads pdftex.def or xetex.def according to the current compiler.
2. pdftex.def will define \reset@color;
xetex.def will define \reset@color@nostack and \reset@color@stack.
3. redefines \reset@color.
4. xetex.def will decide whether \reset@color@nostack or \reset@color@stack will be the \reset@color.

Here 1, 2, 3 happens at \documentclass{beamer} and 4 happens at \begin{document}.

Now you can see a problem: for XeLaTeX, since 4 happens after 3, reset@color is redefined to be a non-beamer version.

The following code illustrate the difference more clearly

\documentclass{beamer}
\usepackage{tikz}

\setbeamercolor{background canvas}{bg=teal}
\setbeamercolor{normal text}{fg=white}

\begin{document}

\frame{
\tikz{
\node[text=yellow]{
Yellow
\textcolor{red}{Red}
What?
};
}
}

\end{document}


LaTeX gives

and XeLaTeX gives

Neither of them is expected. What we want is yellow. But reluctantly, white is better than black. And white is indeed done by the beamer version of \reset@color and black is done by the xetex.def version.