I read this thread but I would like to have a pgfmath-function that gives the length of a list like \def\mylist{1,2,3,5,7}, because I need the value for some later calculations.
The following does not work correctly.
I get an output: 112357
It should be: 5
What do I have to do?
\documentclass[a4paper]{article}
\usepackage{tikz}
\begin{document}
\makeatletter
\pgfmathdeclarefunction{Len}{1}{%
\begingroup
\def\templist{#1}
\foreach[count=\mycount] \i in \templist { \xdef\Len{\mycount} }%
\Len%
\endgroup
}
\makeatother
\def\mylist{1,2,3,5,7}
\pgfmathparse{Len(\mylist)}\pgfmathresult
\end{document}

\pgfmathparse{dim(200,1,3)}\pgfmathresultgives 5, but I need 3. – cis Oct 28 '20 at 17:13