This topic is following my previous question, which was marvelously answered by BambOo yesterday.
Now for a step beyond into this project.
Let's admit I want to put a list of letters (or words) on a 6 columns grid and stylize them depending on their content.
In the following example, I displayed a simple alphabet, and a [count=\i] into the loop, but I'd like to be able to compare directly the node content, i.e. something like ifthenelse(\l<"J", nodeone, nodetwo).
Is there any simple way to do that?
\documentclass[a4paper, 11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usepackage{ifthen}
\begin{document}
\begin{center}
\begin{tikzpicture}
\tikzstyle{nodeone}=[circle, fill=cyan!50!yellow,text=purple,opacity=1,minimum height=30]
\tikzstyle{nodetwo}=[regular polygon,regular polygon sides=5, fill=orange!50!red,text=cyan,opacity=1,minimum height=30]
\tikzstyle{nodethree}=[star,star points=7,star point ratio=0.8, fill=red!50!blue,text=orange,opacity=1,minimum height=30]
\def\LX{2} \def\LY{3} \def\ncol{6} % dimensions of the grid
\def\firstlim{8} \def\secondlim{17}
\foreach \l [count=\i from 0] in {A,...,Z}
{
\pgfmathsetmacro{\nodestyl}
{
ifthenelse(\i<\firstlim,"nodeone",
ifthenelse(\i<\secondlim,"nodetwo","nodethree")
}%
\pgfmathtruncatemacro\result{\i/\ncol}
\node[\nodestyl] at ({Mod(\i,\ncol)*\LX},-\result*\LY) {\sf \Large \textbf{\l}};
}
\end{tikzpicture}
\end{center}
\end{document}
I already looked into etoolbox to find something that could help, and I found a way to test if strings are equal : \expandafter\ifstrequal\expandafter{\l}{A}{\nodeone}{nodetwo}, but not yet a way to test if string1 is inferior to string2.


\theand\stringare not macros (they are primitives) but they expand to other tokens. Expansion occurs recursively in several contexts. One of these ...\ifnum, and that's what we rely on in\mystrcmp.\expandaftertriggers one expansion step after skipping over the next token. It doesn't trigger execution. Execution happens when unexpandable tokens such as\hboxor\def, or\edef, etc. reach TeX's stomach. 2) On string manipulation. LaTeX doesn't deal with “strings” like Python. It deals with token lists. A character token not only has a charcode but also a catcode. This is like a second dimension. – frougon Apr 27 '20 at 16:13abcall-in-catcode-11 toabcall-in-catcode 12 or to\textit{abc}?). One of the reasons is as you said: not the original purpose of TeX. Other reasons are probably age, the second dimension I mentioned (catcodes) + the fact that TeX is a macro language. But if you understand TeX well enough,expl3provides great high-level tools that allow programming more or less like in a “traditional” programming language. – frougon Apr 27 '20 at 16:13expl3has a very impressive regular expression library (l3regex) that allows one to match (a) control sequence tokens and (b) character tokens not only based on their charcodes but also on their catcodes (the “second dimension” I mentioned). The last time I used it wasn't earlier than today (see Alternate implementation). – frougon Apr 27 '20 at 16:29