5

In the following MWE

\documentclass{article}
\usepackage{tikz}
\begin{document}

\color{gray}
Gray point \(X\)
\[ A = B\]

\normalcolor
Black point \(Y\)
\[ C = D\]

\begin{tikzpicture}
  \node at (0,0) {Test};
\end{tikzpicture}
\end{document}

I use the \color command to change the color to gray and \normalcolor to change back to the default color. This works for text and equations but not for nodes in tikzpicture for some reason. I expected the default color in tikzpictures to change back to black.

Is this behavior expected? How can I reset the default color of tikz?

I know that I can surround the \color statement with a \begingroup -- \endgroup, but I don't want to do that because adding groups breaks things in my particular application.

1 Answer 1

6

As Ulrike Fisher points out in a comment below, it is a bug in xcolor (its definition of \normalcolor is faulty, it doesn't update the . color.).

Here is a workaround:

\documentclass{article}
\usepackage{tikz}
\AtBeginDocument{\colorlet{normalcolor}{.}\def\normalcolor{\color{normalcolor}}} % workaround
\begin{document}

\color{gray}
Gray point \(X\)
\[ A = B\]

\normalcolor
Black point \(Y\)
\[ C = D\]

\begin{tikzpicture}
  \node at (0,0) {Test};
\end{tikzpicture}
\end{document}
2
  • 8
    it is not a bug in tikz but in xcolor. Its definition of \normalcolor is faulty, it doesn't update the . color. Aug 6, 2021 at 17:47
  • 1
    @UlrikeFischer Thanks for this information. Aug 7, 2021 at 5:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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