I am trying to parse arrays of strings, but when I create an array of containing a single string (say the string contains n characters), it is not parsed correctly, instead it's parsed as containing n items, with each item an individual character. can anyone shed some light on why does this happen? thanks in advance! Code and output below:
\documentclass{article}
\usepackage{pgfmath,pgffor}
\begin{document}
\noindent Array 1 is \{"this","is","cool"\}
\def\myArray{{"this","is","cool"}}
\pgfmathparse{dim(\myArray)}
\edef\myArrayLength{\pgfmathresult}
\pgfmathparse{\myArrayLength-1}
\edef\lastIndex{\pgfmathresult}
\foreach \i in {0,...,\lastIndex}
{
\noindent Array 1, item \i: \pgfmathparse{\myArray[\i]}\pgfmathresult \newline
}
\noindent Array 2 is \{"not cool"\}
\def\singleItemArray{{"not cool"}}
\pgfmathparse{dim(\singleItemArray)}
\edef\singleItemArrayLength{\pgfmathresult}
\pgfmathparse{\singleItemArrayLength-1}
\edef\lastIndex{\pgfmathresult}
\foreach \i in {0,...,\lastIndex}
{
\noindent Array 2, item \i: \pgfmathparse{\singleItemArray[\i]}\pgfmathresult \newline
}
\end{document}





{{"notcool"}}produces the same issue. Length one arrays seem to be invalid, as{{12}}turns out to have length two as well. – egreg Oct 21 '17 at 22:38\def\myArray{{{"this"},{"is"},{"cool"}}},\def\myArray{{{"not cool"}}}... – Paul Gaborit Oct 22 '17 at 07:29