This answer is meant as a compliment to @cfr's one.
Observations:
@cfr's answer is more flexible then he's shown for instance one can readily use the following invocation to draw the symbol
\draw pic [rotate=-45, infinity setup={height=2em, line width=2mm, double=blue, draw=green}] {infinity symbol};
Code :
While playing with the code from @cfr code I stumbled upon an alternate way of implementing the same mechanism that he/she provided posted here. Execution wise it does not appear to add but it cleans up the code a little.
\documentclass[tikz]{standalone}
\usetikzlibrary{calc,calligraphy}
\makeatletter
\def\inf@key#1{%
\pgfkeysvalueof{/tikz/infinity dimensions/#1}%
}
The initial part reads the same and simply sets up the dimensions.
\tikzset{
% Dimensions
infinity dimensions/.is family,
%infinity dimensions/.search also={/tikz, /pgf},
infinity dimensions/width/.initial =1 em,
infinity dimensions/height/.initial=1 em,
infinity dimensions/upper target/.initial=0.2,
infinity dimensions/lower target/.initial=0.8,
}
Then we adapt @cfr's code as follows, based upon the other answer. It seems common practice to provide an every KEY
and a corresponding KEY
that sets it. Supposedly this is done every where within tikz but I haven't confirmed this.
\tikzset{
every infinity/.style={pic actions, infinity dimensions/.cd},
infinity/.style={every infinity/.append style={#1}},
}
The use of #1
enables the \draw pic {infinity={...}};
call signature, removing it causes tikz to simply ignore the input. That is one is enforcing the use of \draw pic[infinity={...}] {infinity};
instead. The latter syntax passes the options to every infinity/.style
via infinity/.syle
, providing an interface similar to @cfr's code.
\tikzset{
% Pic/Symbol
infinity symbol/.pic = {
\path[every infinity, #1]
let \p1=(0,0) in
(\p1) .. controls (-\inf@key{upper target}*\inf@key{width}, \inf@key{height}) and (-\inf@key{lower target}*\inf@key{width},-\inf@key{height}) ..
(\p1) .. controls ( \inf@key{lower target}*\inf@key{width}, \inf@key{height}) and ( \inf@key{upper target}*\inf@key{width},-\inf@key{height}) .. cycle;
},
}
\makeatother
\begin{document}
\begin{tikzpicture}
\draw pic[draw] at (0,-0.5em) {infinity symbol};
\draw pic[draw, double,infinity={lower target=1.5,upper target=0.5}] at (0, 0.5em) {infinity symbol};
\draw pic[double,draw] at (0, 1.0em) {infinity symbol={lower target=1.5,upper target=1.5}};
\end{tikzpicture}
\end{document}
The last thing that might be of interest is that I pass pic actions
to the base style, every infinity
, but I do so before the path change. Similarly one might remove it from the base style placing it into the call to draw instead as in \draw[pic actions, every infinity] ...
. The effect is the same either way, the latter being slightly more 'hard coded'. There is a caveat though if pic actions
is placed after the path change as in every infinity={infinity dimensions/.cd, pic actions}
or as \draw[every infinity, pica actions]
then one must enable the line infinity dimensions/.serach also={/tikz, /pgf}
otherwise you will get error messages indicating that the key is unrecognised.
Notes:
It wasn't initially obvious to me that pic actions
really dislikes being under any path other then /tikz
. You can pass it to say infinity dimensions/.style={}
provided that the .search also
handler is correctly set e.g. infinity dimensions/.search also={/tikz}
. As it acts in this root, anything within pic actions
is also bound to this root so upper target=...
in infinity dimensions/.style{upper target=...}
fails as it is now being called within the /tikz
path and not /tikz/infinity dimensions
. So anything contained within pic actions
is executed within the /tikz
path. Originally I thought pic actions
were more like a container that one could pass around and unpack at will which was incorrect.