Note:
This question is similar to \textcolor{}{} behaves differently within a \node. The difference here is that
- The problem occurs inside an
\href(within a\node) and - The workaround hack solution I posted there does not work here?
Thus, I suspect that the problem is related but not identical. Would be nice to have a single solution that works for both cases.
I would expect that using the \MyText (containing an \href) macro defined as
\newcommand*{\MyText}{%
before \href{https://tex.stackexchange.com}{\textcolor{red}{{TeX.SE}}} after%
}
should always yield the same color for the text "before" and "after". But it appears that when I use it within a \node (third line), it results in different colors:
It seems as if the \textcolor{red}{TeX.SE} restores the color to black at the end if it is used within a \node.
Question: How do I get \textcolor{}{} within a \node to yield the same results as it does outside of a \node.
Notes:
- Using
\textcolor{}{}outside of the\hrefdoes allow the hack solution to work, but, then this won't overridecolorlinks=true(in case it is used)
Listfiles
article.cls 2014/09/29 v1.4h Standard LaTeX document class
size10.clo 2014/09/29 v1.4h Standard LaTeX file (size option)
etoolbox.sty 2018/02/11 v2.5e e-TeX tools for LaTeX (JAW)
xcolor.sty 2016/05/11 v2.12 LaTeX color extensions (UK)
color.cfg 2016/01/02 v1.6 sample color configuration
pdftex.def 2018/01/08 v1.0l Graphics/color driver for pdftex
tikz.sty 2015/08/07 v3.0.1a (rcs-revision 1.151)
pgf.sty 2015/08/07 v3.0.1a (rcs-revision 1.15)
pgfrcs.sty 2015/08/07 v3.0.1a (rcs-revision 1.31)
everyshi.sty 2001/05/15 v3.00 EveryShipout Package (MS)
pgfrcs.code.tex
pgfcore.sty 2010/04/11 v3.0.1a (rcs-revision 1.7)
graphicx.sty 2017/06/01 v1.1a Enhanced LaTeX Graphics (DPC,SPQR)
keyval.sty 2014/10/28 v1.15 key=value parser (DPC)
graphics.sty 2017/06/25 v1.2c Standard LaTeX Graphics (DPC,SPQR)
trig.sty 2016/01/03 v1.10 sin cos tan (DPC)
graphics.cfg 2016/06/04 v1.11 sample graphics configuration
pgfsys.sty 2014/07/09 v3.0.1a (rcs-revision 1.48)
pgfsys.code.tex
pgfsyssoftpath.code.tex 2013/09/09 (rcs-revision 1.9)
pgfsysprotocol.code.tex 2006/10/16 (rcs-revision 1.4)
pgfcore.code.tex
pgfcomp-version-0-65.sty 2007/07/03 v3.0.1a (rcs-revision 1.7)
pgfcomp-version-1-18.sty 2007/07/23 v3.0.1a (rcs-revision 1.1)
pgffor.sty 2013/12/13 v3.0.1a (rcs-revision 1.25)
pgfkeys.sty
pgfkeys.code.tex
pgfmath.sty
pgfmath.code.tex
pgffor.code.tex
tikz.code.tex
xspace.sty 2014/10/28 v1.13 Space after command names (DPC,MH)
hyperref.sty 2018/02/06 v6.86b Hypertext links for LaTeX
hobsub-hyperref.sty 2016/05/16 v1.14 Bundle oberdiek, subset hyperref (HO)
hobsub-generic.sty 2016/05/16 v1.14 Bundle oberdiek, subset generic (HO)
hobsub.sty 2016/05/16 v1.14 Construct package bundles (HO)
infwarerr.sty 2016/05/16 v1.4 Providing info/warning/error messages (HO)
ltxcmds.sty 2016/05/16 v1.23 LaTeX kernel commands for general use (HO)
ifluatex.sty 2016/05/16 v1.4 Provides the ifluatex switch (HO)
ifvtex.sty 2016/05/16 v1.6 Detect VTeX and its facilities (HO)
intcalc.sty 2016/05/16 v1.2 Expandable calculations with integers (HO)
ifpdf.sty 2017/03/15 v3.2 Provides the ifpdf switch
etexcmds.sty 2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO)
kvsetkeys.sty 2016/05/16 v1.17 Key value parser (HO)
kvdefinekeys.sty 2016/05/16 v1.4 Define keys (HO)
pdftexcmds.sty 2018/01/30 v0.27 Utility functions of pdfTeX for LuaTeX (HO)
pdfescape.sty 2016/05/16 v1.14 Implements pdfTeX's escape features (HO)
bigintcalc.sty 2016/05/16 v1.4 Expandable calculations on big integers (HO)
bitset.sty 2016/05/16 v1.2 Handle bit-vector datatype (HO)
uniquecounter.sty 2016/05/16 v1.3 Provide unlimited unique counter (HO)
letltxmacro.sty 2016/05/16 v1.5 Let assignment for LaTeX macros (HO)
hopatch.sty 2016/05/16 v1.3 Wrapper for package hooks (HO)
xcolor-patch.sty 2016/05/16 xcolor patch
atveryend.sty 2016/05/16 v1.9 Hooks at the very end of document (HO)
atbegshi.sty 2016/06/09 v1.18 At begin shipout hook (HO)
refcount.sty 2016/05/16 v3.5 Data extraction from label references (HO)
hycolor.sty 2016/05/16 v1.8 Color options for hyperref/bookmark (HO)
ifxetex.sty 2010/09/12 v0.6 Provides ifxetex conditional
auxhook.sty 2016/05/16 v1.4 Hooks for auxiliary files (HO)
kvoptions.sty 2016/05/16 v3.12 Key value format for package options (HO)
pd1enc.def 2018/02/06 v6.86b Hyperref: PDFDocEncoding definition (HO)
hyperref.cfg 2002/06/06 v1.2 hyperref configuration of TeXLive
url.sty 2013/09/16 ver 3.4 Verb mode for urls, etc.
hpdftex.def 2018/02/06 v6.86b Hyperref driver for pdfTeX
rerunfilecheck.sty 2016/05/16 v1.8 Rerun checks for auxiliary files (HO)
supp-pdf.mkii
epstopdf-base.sty 2016/05/15 v2.6 Base part for package epstopdf
grfext.sty 2016/05/16 v1.2 Manage graphics extensions (HO)
epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Live
nameref.sty 2016/05/21 v2.44 Cross-referencing by name of section
gettitlestring.sty 2016/05/16 v1.5 Cleanup title references (HO)
TeX-SE.out
TeX-SE.out
***********
Code:
\documentclass{article}
\usepackage{etoolbox}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage{xspace}
%%
%% The "colorlinks" here to show that moving the `\textcolor{}{}` to
%% be outside of the \href is not a viable solution.
\usepackage[colorlinks]{hyperref}
%% Hack solution from https://tex.stackexchange.com/a/448043/4301
%% does not seem to work here?
\makeatletter
\let\OldTextcolor\textcolor
\newcommand*{\MyTextColor}[2]{%
\colorlet{@SavedColor}{.}%
\OldTextcolor{#1}{#2}%
\color{@SavedColor}%
\xspace%
}
\makeatother
\AtBeginEnvironment{tikzpicture}{\let\textcolor\MyTextColor}%
\newcommand*{\MyText}{%
before \href{https://tex.stackexchange.com}{\textcolor{red}{{TeX.SE}}} after%
}%
\listfiles
\begin{document}
\noindent
Outside of \verb|\node|: \MyText
\begingroup
\noindent
Outside of \verb|\node|: \color{green}\MyText
\endgroup
\noindent
\begin{tikzpicture}%
\node [text=green, draw=blue, fill=yellow!20, inner sep=2pt] at (0,0) {Inside node: \MyText};
\end{tikzpicture}%
\end{document}


\tikzoptions. – Peter Grill Aug 27 '18 at 18:54\tikstyleis the way to go, but since my styles are often built up over layers, I need to be careful about the order. I suspect it will work just fine with perhaps a few issues that can be tweaked. – Peter Grill Aug 27 '18 at 19:16\tikzset... Thanks for correcting that. – Peter Grill Aug 28 '18 at 03:36