笔记:
这个问题类似于\textcolor{}{} 在 \node 中的行为不同. 这里的区别在于
- 问题发生在一个
\href
(在\node
)和 - 解决方法黑客我发布的解决方案在这里不起作用?
因此,我怀疑这个问题是相关的,但并不完全相同。最好有一个单身的适用于两种情况的解决方案。
我希望使用\MyText
(包含\href
)定义为的宏
\newcommand*{\MyText}{%
before \href{https://tex.stackexchange.com}{\textcolor{red}{{TeX.SE}}} after%
}
应该总是为“之前”和“之后”的文本生成相同的颜色。但是当我在\node
(第三行)中使用它时,它会产生不同的颜色:
如果在 内使用,则似乎会在最后\textcolor{red}{TeX.SE}
恢复颜色。black
\node
问题:如何使\textcolor{}{}
内部\node
产生与 外部相同的结果\node
。
笔记:
- 使用
\textcolor{}{}
外部\href
做允许黑客解决方案有效,但,则不会覆盖colorlinks=true
(如果使用的话)
列表文件
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
***********
代码:
\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}
答案1
这是一个丑陋的解决方法,在这里和合作伙伴问题:首先使用 设置文本颜色green
,然后设置其他颜色然后比如说,我知道这不是真正的解决方案,只是一种变通方法,但这似乎有效。此外,业务相当微妙,即真正的解决方案可能会破坏迄今为止运行良好的其他代码draw=blue
。fill=yellow
\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}%
\noindent
\begin{tikzpicture}%
\node [green, draw=blue, fill=yellow!20, inner sep=2pt] at (0,0) {Inside node: \MyText};
\end{tikzpicture}%
\end{document}