1

I would like to check whether a number is in a list and make a decision in the calculation of a macro. I found a neat solution to check the membership of a number, here and it works as long as I don't use it inside my decision macro.

However, I have not been able to use it in the macro \processNum in the code below.

\documentclass[tikz, border=0mm]{standalone}
\usepackage{tikz,xfp}

\usepackage{xstring}
\newcommand\IfStringInList[2]{\IfSubStr{,#2,}{,#1,}} % Adapted from https://tex.stackexchange.com/a/260909/23594

\newcommand{\singleBox}[4]{%
    \fill(\fpeval{#1}mm,\fpeval{#2}mm) rectangle
    (\fpeval{#1} mm + \fpeval{#3} mm,\fpeval{#2} mm - \fpeval{#4} mm);
}

\newcommand{\processNum}[5] %
{
    \fpeval{
        \IfStringInList{#1}{1,17,130,109}{1}{0} ? #3 + 39 + (#4 + #5)   + (#2-1) : 
        \IfStringInList{#1}{4,11,100,189}{1}{0} ? #3 + 39 + (#4 + #5)*2 + (#2-1) : 
        \IfStringInList{#1}{9,19,124,167}{1}{0} ? #3 + 39 + (#4 + #5)*3 + (#2-1) : 
        0 }
}

\begin{document}
    \IfStringInList{17}{1,17,130,109}{1}{0} % Works just fine. [for debugging purposes].
    \IfStringInList{16}{1,17,130,109}{1}{0} % Works just fine. [for debugging purposes].

    \begin{tikzpicture}
        \draw[draw=black] (0mm,0mm) rectangle (300 mm, 400 mm);
        \singleBox{100}{200}{24}{13} % This works just fine. [for debugging purposes]
        \singleBox{\processNum{1}{1}{0}{2}{1.46}}{200}{24}{13} % Fails at this line.
    \end{tikzpicture}

\end{document}

The error message is:

Undefined control sequence. ...convertNum{1}{1}{0}{2}{1.46}}{200}{24}{13}

0 Answers0