4

Minimal (non-)working example:

\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}

The \nulx command is defined exactly as I have it in my original document; everything else is as stripped down as possible.

This file stops compilation at \end{document} with Package pgf Error: No shape named letter is known. Removing [baseline=(letter.base)] eliminates the error (but typesets with the wrong baseline). How do I fix this?

  • 1
    That really isn't minimal. All the hyperref stuff is irrelevant. – cfr May 8 '16 at 20:55
3

Your problem is that by using

\begin{tikzpicture}
    \begin{tikzfadingfrompicture}
    \end{tikzfadingfrompicture}
\end{tikzpicture}

you do nothing else than nesting two tikzpicture environments, which is known to be a source of trouble. However, it is not necessary to do this, since you name the tikzfadingfrompicture to reuse it. When putting both tikzpicture environments in separate places, hence another problem occurs in connection with the standalone class. I simply resolve it here, by not passing tikz as an option to the class, but by declaring its use within \usepackage.

enter image description here

\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}
3

The example is not minimal. I've minimised it a bit further just by removing all the hyperref stuff. (I checked that this all has no relevance.)

The basic problem involves the use of nested tikzpictures which are known to cause problems. Although not guaranteed to fail, failure is to be expected.

Nesting should therefore (very nearly almost) always be avoided. In this case, simply define the fading outside the main tikzpicture environment.

I would also tidy up the key-value schema a bit, just for clarity and convenience. But this is probably personal preference in the end.

\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}

fading outside picture

EDIT

Here's an alternative way of solving the problem JMP mentioned using an answer by John Kormylo.

I played with this partly to test out John's solution (because it sounded neat!) and partly because I wanted to experiment with a version of \nulx which could handle an additional optional argument specifying a letter other than x. In the course of doing this, I realised my original code above didn't work (so I'm correcting that, too).

The changes mean that

  \nulx[red]
  \nulx
  \nulx[][A]
  \nulx[extension=1pt][a]

produces the following output:

4 fadings

As can be seen \nulx does just the same as ever, \nulx[<something>] behaves as I assume the original was intended to behave and \nulx[<something>][<text>] uses <text> in place of x.

The additional spacing is required for a to avoid the letter itself being cropped.

Though whether any of this is of any use to anybody is an open question.

\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}
  • 1
    Looks like I was a little faster :-P – JMP May 8 '16 at 21:07
  • 1
    @JMP Speed isn't everything. But your solution is different and may be closer to what the OP wants. – cfr May 8 '16 at 21:17
  • 1
    No, of course speed isn't everything, but the main problem actually was the nesting of the tikz environments... – JMP May 8 '16 at 21:25
  • 1
    @Ptharien'sFlame Note that my original changes didn't work. So I've corrected the code and added a fancy version I created just because I wanted to experiment with a couple of things. – cfr May 8 '16 at 22:19
  • 1
    @Ptharien'sFlame I didn't think you would ;). I just wanted to try something out and this was as good a tweak as any to do it with. I didn't think the enhancement itself would be useful. I really posted it to demonstrate John's \wrapper thing. For my purposes, the point was just to try that out. For that reason, I wanted a case where the fading should be different from case to case. Changing the letter seemed the simplest option. Since I didn't expect anybody to use the letter thing itself, how it got passed to TikZ seemed irrelevant ;). – cfr May 8 '16 at 22:44

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.