2

I want to include this library in my document. Using it standalone works fine. But when I include I get an error in the Ball.sty package which looks like this:

\ProvidesPackage{Ball}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%This Block can draw small Ball
%Elementwise or reduction operations can be drawn with this
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\tikzset{Ball/.pic={\tikzset{/sphere/.cd,#1}        

\pgfmathsetmacro{\r}{\radius*\scale}

\shade[ball color=\fill,opacity=\opacity] (0,0,0) circle (\r);
\draw (0,0,0) circle [radius=\r] node[scale=4*\r] {\logo};

\coordinate (\name-anchor) at ( 0 , 0  , 0) ;
\coordinate (\name-east)   at ( \r, 0  , 0) ;
\coordinate (\name-west)   at (-\r, 0  , 0) ;
\coordinate (\name-north)  at ( 0 , \r , 0) ;
\coordinate (\name-south)  at ( 0 , -\r, 0) ;

\coordinate (\name-southwest)  at ( -0.70710678118 * \r , -0.70710678118 * \r, 0) ;
\coordinate (\name-northeast)  at ( 0.70710678118 * \r , 0.70710678118 * \r, 0) ;

\path (\name-south) + (0,-20pt) coordinate (caption-node) 
edge ["\textcolor{black}{\bf \caption}"'] (caption-node); %Ball caption

},
/sphere/.search also={/tikz},
/sphere/.cd,
radius/.store       in=\radius,
scale/.store        in=\scale,
caption/.store      in=\caption,
name/.store         in=\name,
fill/.store         in=\fill,
logo/.store         in=\logo,
opacity/.store      in=\opacity,
logo=$\Sigma$,
fill=green,
opacity=0.10,
scale=0.2,
radius=0.5,
caption=,
name=,
}

The critical lines are fill/.store in=\fill, and fill=green,. For some reason I get the error

Missing number, treated as zero.

<to be read again> 
                   g
l.55 \newskip\LTleft       \LTleft=\fill

A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

And some follow up errors, resting upon the first error.

After some hours of debugging I have absolutely no clue what could lead to this error. Maybe someone else has a guess?

0

1 Answer 1

3

You should not store keys in a macro that coincide with the TikZ command \fill. It is IMHO much better not to store anything in explicit macros, but to use \pgfkeysvalueof{...} instead. So you may want to use this for Ball.sty.

\ProvidesPackage{Ball}
\tikzset{Ball/.pic={\tikzset{/sphere/.cd,#1}        
\def\skv##1{\pgfkeysvalueof{/sphere/##1}}
\pgfmathsetmacro{\r}{\skv{radius}*\skv{scale}}

\shade[ball color=\skv{fill},opacity=\skv{opacity}] (0,0,0) circle (\r);
\draw (0,0,0) circle [radius=\r] node[scale=4*\r] {\skv{logo}};

\coordinate (\skv{name}-anchor) at ( 0 , 0  , 0) ;
\coordinate (\skv{name}-east)   at ( \r, 0  , 0) ;
\coordinate (\skv{name}-west)   at (-\r, 0  , 0) ;
\coordinate (\skv{name}-north)  at ( 0 , \r , 0) ;
\coordinate (\skv{name}-south)  at ( 0 , -\r, 0) ;

\coordinate (\skv{name}-southwest)  at ( -0.70710678118 * \r , -0.70710678118 * \r, 0) ;
\coordinate (\skv{name}-northeast)  at ( 0.70710678118 * \r , 0.70710678118 * \r, 0) ;

\path (\skv{name}-south) + (0,-20pt) coordinate (caption-node) 
edge ["\textcolor{black}{\bfseries\skv{caption}}"'] (caption-node); %Ball caption

},
/sphere/.search also={/tikz},
/sphere/.cd,
radius/.initial=0.5,
scale/.initial=0.2,
caption/.initial={},
name/.initial={},
fill/.initial=green,
logo/.initial={$\Sigma$},
opacity/.initial=0.1}
\endinput

As you can see, it works:

\documentclass[border=3mm,tikz]{standalone}
\usetikzlibrary{quotes}
\begin{document}
\tikzset{Ball/.pic={\tikzset{/sphere/.cd,#1}        
\def\skv##1{\pgfkeysvalueof{/sphere/##1}}
\pgfmathsetmacro{\r}{\skv{radius}*\skv{scale}}

\shade[ball color=\skv{fill},opacity=\skv{opacity}] (0,0,0) circle (\r);
\draw (0,0,0) circle [radius=\r] node[scale=4*\r] {\skv{logo}};

\coordinate (\skv{name}-anchor) at ( 0 , 0  , 0) ;
\coordinate (\skv{name}-east)   at ( \r, 0  , 0) ;
\coordinate (\skv{name}-west)   at (-\r, 0  , 0) ;
\coordinate (\skv{name}-north)  at ( 0 , \r , 0) ;
\coordinate (\skv{name}-south)  at ( 0 , -\r, 0) ;

\coordinate (\skv{name}-southwest)  at ( -0.70710678118 * \r , -0.70710678118 * \r, 0) ;
\coordinate (\skv{name}-northeast)  at ( 0.70710678118 * \r , 0.70710678118 * \r, 0) ;

\path (\skv{name}-south) + (0,-20pt) coordinate (caption-node) 
edge ["\textcolor{black}{\bfseries\skv{caption}}"'] (caption-node); %Ball caption

},
/sphere/.search also={/tikz},
/sphere/.cd,
radius/.initial=0.5,
scale/.initial=0.2,
caption/.initial={},
name/.initial={},
fill/.initial=green,
logo/.initial={$\Sigma$},
opacity/.initial=0.1}

\begin{tikzpicture}
 \path (0,0,0) pic{Ball} (3,0,0) pic{Ball={fill=blue,radius=4}}; 
\end{tikzpicture}
\end{document}

enter image description here

12
  • Could you say why it is better not to store things in macros (but all right to \def a macro to retrieve things stored in keys)? I've never got the hang of PGF keys and always store things in macros, though I've heard before it is better not to do this. (Basically, I understand this way of doing it, whereas it never seems to work quite as I expect otherwise.)
    – cfr
    Commented Nov 7, 2019 at 2:30
  • @cfr I think this example shows why you may not want to use macros, at least not macros which are called \fill or \caption. If you store these things in pgf keys, they will end up also being macros internally, but first of all you have only one of them, and then due to the directory structure of pgf you can be almost sure that they do not collide with macros others use, unless of course some one else calls their directory sphere and has a key radius under it. Still better than just using \radius IMHO.
    – user194703
    Commented Nov 7, 2019 at 2:37
  • Yes, but is there any other reason? The naming issue is not fundamentally different from that in other contexts. (I would never use \fill or \caption or \radius. I might use \llenwi or \testun or \cath@llenwi. Usually something like the latter in a library, though it does depend.)
    – cfr
    Commented Nov 7, 2019 at 3:58
  • @cfr To me this is the most important reason. You can create rather unique names which may not be accidentally overwritten by others. Also caption/.initial={}, is shorter than caption/.store in=\mycaption,caption={},. It would be good to know for which one the performance is better.
    – user194703
    Commented Nov 7, 2019 at 4:00
  • 1
    If you use another macro that coincides up to @ it does no longer seem to work: \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture}[annus/horriblus/.store in=\annus@horriblus, annus/horriblus=horror, annus/stupidus/.store in=\annus@stupidus, annus/stupidus=stupidus ] \node {\annus@horriblus}; \end{tikzpicture} \end{document}
    – user194703
    Commented Nov 7, 2019 at 4:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .