This is a follow-on question from here. Things are almost working but something strange is going on with my \band command. It renders the first band correctly, but then the second band causes things to go haywire.
\documentclass[]{scrartcl}
\usepackage{tikz}
\usepackage{listofitems}
\begin{document}
\newtoks\pathtoks
\newcommand\addpathtoks[1]{%
\pathtoks\expandafter{\the\pathtoks#1}}
\newcommand\xaddpathtoks[1]{%
\expandafter\addpathtoks\expandafter{#1}}
\newcommand\xxaddpathtoks[1]{%
\expandafter\xaddpathtoks\expandafter{#1}}
\newcommand{\band}[2]{
\readlist*\valuelist{#2}
\pathtoks{}
\foreachitem\x\in\valuelist[]{%
\ifnum\xcnt=1\relax \addpathtoks{\draw[#1]}\else
\addpathtoks{--}
\fi
\addpathtoks{(360/}\xxaddpathtoks{\listlen\valuelist[]*}%
\xaddpathtoks{\x:}\xaddpathtoks{\x)}
\ifnum\xcnt=\listlen\valuelist[]\relax\addpathtoks{--cycle;}\fi
}
\the\pathtoks
}
\begin{tikzpicture}
% This is what I expect the below \band invocations to produce, and this renders correctly.
\draw[red] (360/3:1) -- (360/3*2:2) -- (360/3*3:3) --cycle;
\draw[blue] (360/3:3) -- (360/3*2:2) -- (360/3*3:1) --cycle;
\end{tikzpicture}
\vspace{1cm}
\begin{tikzpicture}
% These bands, which should be equivalent to the above are not rendering correctly.
\band{red}{1,2,3};
\band{blue}{3,2,1};
\end{tikzpicture}
\end{document}
This renders like this:
The top picture is what I'd expect, but the bottom seems to re-render the same shape over the top of the existing one.
Weirder still, if two values are the same:
\band{red}{2,3,3};
It renders a straight line:
And if all three values are the same, it renders nothing at all! It's like it's de-duplicating the list...?
So my questions are:
- Why does my repro above render the same triangle twice instead of the expected triangles?
- Why do duplicate values cause weird things to happen?
Update
My requirements are:
- Being able to specify any number of values in the band and having the band automatically place those values that distance from the center of a circle, with each value being placed an equal number of degrees apart.
- Being able to invoke this
bandcommand/environment/whatever it is with varying numbers of values and with different styles for the band. - Be able to compose whatever this
bandthing ends up being into an environment so I can do something like:
\begin{thething}
\band{red}{1,3,2}
\band{blue}{1,2,4}
\end{thething}
\begin{thething}
\band{green}{5,3,4,1}
\band{yellow}{1,1,4,5}
\end{thething}
The thething environment (which I believe I already have working) adds the requisite tikzpicture along with some default rendering. In reality, thething takes a list of labels to render - one for each value in the bands. The band calls then add to that rendering.




#1because I am trying to use it inside an environment and that seems not to work. – me-- Jun 13 '19 at 04:29#. This has nothing to do with the solution here. And you can define a new command\newcommand{\band}[2][]{\draw[#1,band={#2}]}so if newcommand works this will wor. – Jun 13 '19 at 04:32