最小(非)工作示例:
\documentclass[tikz,border=2pt]{standalone}
\usepackage{accsupp,xparse,hyperref}
\usetikzlibrary{calc,fadings}
\pgfkeys{/SS/nulx/size/.initial=0.25ex,/SS/nulx/size/.value required}
\pgfkeys{/SS/nulx/thickness/.initial=0.125ex,/SS/nulx/thickness/.value required}
\pgfkeys{/SS/nulx/shift/.initial={(0ex,0ex)},/SS/nulx/shift/.value required}
\pgfkeys{/SS/nulx/extension/.initial=0ex,/SS/nulx/extension/.value required}
\pgfkeys{/SS/nulx/extrusion/.initial=0ex,/SS/nulx/extrusion/.value required}
\NewDocumentCommand\nulx{ s +O{} }{\texorpdfstring{%
\pgfqkeys{/SS/nulx}{#2}%
\BeginAccSupp{method=escape,unicode,ActualText={x⃘}}%
\begin{tikzpicture}[baseline=(letter.base)]
\begin{tikzfadingfrompicture}[name=x circle fading]
\node[inner xsep=\pgfkeysvalueof{/SS/nulx/extension},inner ysep=\pgfkeysvalueof{/SS/nulx/extrusion},white,fill=white] (letterFade) {x};
\draw[line width=\pgfkeysvalueof{/SS/nulx/thickness},white,fill=black] let \p{shift} = \pgfkeysvalueof{/SS/nulx/shift} in ($ (letterFade.center) + (\x{shift},\y{shift}) $) circle (\pgfkeysvalueof{/SS/nulx/size});
\end{tikzfadingfrompicture}
\node[inner xsep=\pgfkeysvalueof{/SS/nulx/extension},inner ysep=\pgfkeysvalueof{/SS/nulx/extrusion},scope fading=x circle fading,fit fading=false,use as bounding box] (letter) {x};
\draw[line width=\pgfkeysvalueof{/SS/nulx/thickness},.] let \p{shift} = \pgfkeysvalueof{/SS/nulx/shift} in ($ (letter.center) + (\x{shift},\y{shift}) $) circle (\pgfkeysvalueof{/SS/nulx/size});
\end{tikzpicture}%
\EndAccSupp{}%
\IfBooleanT{#1}{\xspace}%
}{x⃘}}
\hypersetup{unicode}
\begin{document}
\nulx
\end{document}
该\nulx
命令的定义与我在原始文档中完全一样;其他所有内容都尽可能地精简。
此文件在 处停止编译\end{document}
。Package pgf Error: No shape named letter is known
删除[baseline=(letter.base)]
可消除错误(但排版基线错误)。我该如何修复此问题?
答案1
你的问题是使用
\begin{tikzpicture}
\begin{tikzfadingfrompicture}
\end{tikzfadingfrompicture}
\end{tikzpicture}
你只需要嵌套两个 tikzpicture 环境,这通常会导致麻烦。但是,没有必要这样做,因为你命名了 tikzfadingfrompicture 以重复使用它。当将两个 tikzpicture 环境放在不同的地方时,因此另一个问题发生在与独立类相关的问题上。我在这里只是简单地解决了这个问题,通过不tikz
作为选项传递给类,而是在 中声明它的使用\usepackage
。
\documentclass[border=2pt]{standalone}
\usepackage{tikz,accsupp,xparse,hyperref}
\usetikzlibrary{calc,fadings}
\pgfkeys{/SS/nulx/size/.initial=0.25ex,/SS/nulx/size/.value required}
\pgfkeys{/SS/nulx/thickness/.initial=0.125ex,/SS/nulx/thickness/.value required}
\pgfkeys{/SS/nulx/shift/.initial={(0ex,0ex)},/SS/nulx/shift/.value required}
\pgfkeys{/SS/nulx/extension/.initial=0ex,/SS/nulx/extension/.value required}
\pgfkeys{/SS/nulx/extrusion/.initial=0ex,/SS/nulx/extrusion/.value required}
\NewDocumentCommand\nulx{ s +O{} }{\texorpdfstring{%
\pgfqkeys{/SS/nulx}{#2}%
\BeginAccSupp{method=escape,unicode,ActualText={x⃘}}%
\tikzset{every node/.style={
inner xsep=\pgfkeysvalueof{/SS/nulx/extension},
inner ysep=\pgfkeysvalueof{/SS/nulx/extrusion}
},
every path/.style={line width=\pgfkeysvalueof{/SS/nulx/thickness}}
}
%
\begin{tikzfadingfrompicture}[name=x circle fading]
\node[,white,fill=white] (letterFade) {x};
\draw[white,fill=black] let \p{shift} = \pgfkeysvalueof{/SS/nulx/shift} in ($ (letterFade.center) + (\x{shift},\y{shift}) $) circle (\pgfkeysvalueof{/SS/nulx/size});
\end{tikzfadingfrompicture}
%
\begin{tikzpicture}[baseline=(letter.base)]
\node[scope fading=x circle fading,fit fading=false,use as bounding box] (letter) {x};
\draw let \p{shift} = \pgfkeysvalueof{/SS/nulx/shift} in ($ (letter.center) + (\x{shift},\y{shift}) $) circle (\pgfkeysvalueof{/SS/nulx/size});
\end{tikzpicture}%
\EndAccSupp{}%
\IfBooleanT{#1}{\xspace}%
}{x⃘}}
\hypersetup{unicode}
\begin{document}
\nulx
\end{document}
答案2
这个例子并不简单。我通过删除所有内容将其进一步最小化hyperref
。(我检查过,这一切都没有相关性。)
基本问题涉及使用嵌套的tikzpicture
s,这已知会导致问题。虽然不能保证会失败,但失败是可以预料到的。
因此,应(几乎)始终避免嵌套。在这种情况下,只需在主tikzpicture
环境之外定义淡入淡出即可。
我还会稍微整理一下键值模式,只是为了清晰和方便。但这可能最终还是取决于个人喜好。
\documentclass[tikz,border=10pt,multi]{standalone}
% responding to Ptharien's Flame's question at https://tex.stackexchange.com/questions/308546/tikz-cannot-find-a-node-for-use-as-a-baseline
\usepackage{xparse}
\usetikzlibrary{calc,fadings}
\tikzset{%
nulx/.code={%
\tikzset{%
/SS/nulx/.cd,
#1
}
},
/SS/nulx/.search also={/tikz},
/SS/nulx/.cd,
size/.initial=0.25ex,
size/.value required,
thickness/.store in=\nulxthickness,
thickness=0.125ex,
shift/.initial={(0ex,0ex)},
shift/.value required,
extension/.store in=\nulxextension,
extension=0ex,
extrusion/.store in=\nulxextrusion,
extrusion=0ex,
node/.style={inner xsep=\nulxextrusion, inner ysep=\nulxextension},
line/.style={line width=\nulxthickness},
}
\begin{tikzfadingfrompicture}[name=x circle fading]
\node [nulx=node, white, fill=white] (letterFade) {x};
\draw [nulx=line, white, fill=black] let \p{shift} = \pgfkeysvalueof{/SS/nulx/shift} in ($ (letterFade.center) + (\x{shift},\y{shift}) $) circle (\pgfkeysvalueof{/SS/nulx/size});
\end{tikzfadingfrompicture}
\NewDocumentCommand\nulx{ s +O{} }{%
\pgfqkeys{/SS/nulx}{#2}%
\begin{tikzpicture}[baseline=(letter.base)]
\node [nulx=node, scope fading=x circle fading, fit fading=false, use as bounding box] (letter) {x};
\draw [nulx=line] let \p{shift} = \pgfkeysvalueof{/SS/nulx/shift} in ($ (letter.center) + (\x{shift},\y{shift}) $) circle (\pgfkeysvalueof{/SS/nulx/size});
\end{tikzpicture}%
\IfBooleanT{#1}{\xspace}%
}
\begin{document}
\nulx
\end{document}
编辑
我玩这个部分是为了测试 John 的解决方案(因为它听起来很棒!),部分是因为我想尝试一个版本,该版本\nulx
可以处理指定除 之外的字母的附加可选参数x
。在此过程中,我意识到上面的原始代码不起作用(所以我也在纠正它)。
这些变化意味着
\nulx[red]
\nulx
\nulx[][A]
\nulx[extension=1pt][a]
产生以下输出:
正如所见,\nulx
它的作用与以往完全一样,\nulx[<something>]
其行为正如我所假设的原来所期望的那样,并且\nulx[<something>][<text>]
代替<text>
了x
。
需要额外的间距以a
避免字母本身被裁剪。
尽管这些是否对任何人都有用仍是一个悬而未决的问题。
\documentclass[tikz,border=10pt,multi={tikzpicture,wrapper}]{standalone}% wrapper trick is from John Kormylo's answer at https://tex.stackexchange.com/a/277790/
% responding to Ptharien's Flame's question at https://tex.stackexchange.com/questions/308546/tikz-cannot-find-a-node-for-use-as-a-baseline
\usepackage{xparse}
\usetikzlibrary{calc,fadings}
\tikzset{%
nulx/.code={%
\tikzset{%
/SS/nulx/.cd,
#1
}
},
/SS/nulx/.search also={/tikz},
/SS/nulx/.cd,
size/.initial=0.25ex,
size/.value required,
thickness/.store in=\nulxthickness,
thickness=0.125ex,
shift/.initial={(0ex,0ex)},
shift/.value required,
extension/.store in=\nulxextension,
extension=0ex,
extrusion/.store in=\nulxextrusion,
extrusion=0ex,
node/.style={inner xsep=\nulxextrusion, inner ysep=\nulxextension},
line/.style={line width=\nulxthickness},
}
\NewDocumentCommand\nulx{ s +O{} +O{x} }{%
\begin{wrapper}%
\tikzset{nulx={#2}}%
\begin{tikzfadingfrompicture}[name=#3 circle fading]
\node [nulx=node, white, fill=white] (letterFade) {#3};
\draw [nulx=line, white, fill=black] let \p{shift} = \pgfkeysvalueof{/SS/nulx/shift} in ($ (letterFade.center) + (\x{shift},\y{shift}) $) circle (\pgfkeysvalueof{/SS/nulx/size});
\end{tikzfadingfrompicture}%
\begin{tikzpicture}[baseline=(letter.base)]
\node [nulx=node, scope fading=#3 circle fading, fit fading=false, use as bounding box] (letter) {#3};
\draw [nulx=line] let \p{shift} = \pgfkeysvalueof{/SS/nulx/shift} in ($ (letter.center) + (\x{shift},\y{shift}) $) circle (\pgfkeysvalueof{/SS/nulx/size});
\end{tikzpicture}%
\IfBooleanT{#1}{\xspace}%
\end{wrapper}%
}
\newenvironment{wrapper}{\parindent=0pt\ignorespaces}{\ignorespaces}
\begin{document}
\nulx[red]
\nulx
\nulx[][A]
\nulx[extension=1pt][a]
\end{document}