Thanks to Sašo Živanović for helping to identify the problem which arises as a result of my trying to apply options such as blue
or text=blue
to nodes within Forest trees which include turnstiles from the turnstile package.
Normally, if I apply a colour option such as blue
to a TikZ node, the content of the node is coloured, whether it be text or maths.
However, if the node includes a turnstile provided by the turnstile package, then the colouration only affects content before and after the turnstile. The turnstile itself is not affected.
If I use text=blue
, only the content prior to the turnstile is coloured. Neither the turnstile nor anything after it is affected.
Outside the tikzpicture
environment, however, turnstiles are coloured normally, along with their surrounding text or maths.
For example,
{\color{blue}
\[
p \leftrightarrow q \sststile{}{} p \rightarrow q
\]
}
\centering
TikZ/blue:
\tikz{\node [blue] {$p \leftrightarrow q \sststile{}{} p \rightarrow q$}; }
TikZ/blue text:
\tikz{\node [text=blue] {$p \leftrightarrow q \sststile{}{} p \rightarrow q$}; }
produces
Sašo Živanović has established that the issue here is not specific to turnstiles but applies to any content which uses \sbox{}
in a similar way. For example:
\newsavebox\mybox
{\color{blue} This is in blue. \sbox{\mybox}{This is in a box.}\usebox{\mybox} This is in blue.}
\tikz{\node[blue]{This is in blue. \sbox{\mybox}{This is in a box.}\usebox{\mybox} This is in blue.};}
produces
This question, to which I am also indebted to Sašo Živanović for directing me, seems related.
I am guessing from the discussion there that the \sbox{}
is executed before the option blue
or text=blue
is applied to the node content, so that the active colour at the point when the box is saved is not sensitive to the options applied to the node.
Is this correct? Is the effect avoidable? And why does text=blue
do something different? Shouldn't the effect of the \sbox{}
be limited to its group, so that even if its contents remains black, following content should be appropriately coloured?
Complete MWE:
\documentclass{article}
\usepackage{turnstile,tikz}
\begin{document}
{\color{blue}
\[
p \leftrightarrow q \sststile{}{} p \rightarrow q
\]
}
\centering
TikZ/blue:
\tikz{\node [blue] {$p \leftrightarrow q \sststile{}{} p \rightarrow q$}; }
TikZ/blue text:
\tikz{\node [text=blue] {$p \leftrightarrow q \sststile{}{} p \rightarrow q$}; }
\newsavebox\mybox
{\color{blue} This is in blue. \sbox{\mybox}{This is in a box.}\usebox{\mybox} This is in blue.}
\tikz{\node[blue]{This is in blue. \sbox{\mybox}{This is in a box.}\usebox{\mybox} This is in blue.};}
\end{document}
Best Answer
This seems to be a failing in the pgf colour support which isn't setting the current colour as understood by latex.
produces a log of
showing that when
\color{blue}
was used,\current@color
is (the pdf for) blue however in thenode[blue]
case, although the text is blue,\current@color
is (the pdf for) black.This is important as
\sbox
does not "know" the state of the color stack maintained by the pdf backend or dvi driver it just sets the colour of the saved text to\current@color
The
\resetcurrentcolor
command doesn't actually set the colour (it issues no\special
or\pdfliteral
) it just redefines\current@color
to use the stroke colour as last set by PGF.