0

How can I convert a string of a small integer? In my code below, I check whether a string is a member of a list, which returns a string of "0" or "1". I am trying to use this returned value in \fpeval to make a decision using if-statement in the macro \processNum.

Could someone kindly please help me?

\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{\convertStringToInteger}[1]
{
     % I am trying to find a convertor
}

\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{
       \convertStringToInteger{
          \IfStringInList{#1}{1,17,130,109}{1}{0}} ? #3 + 39 + (#4 + #5) + (#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}
7
  • 3
    tex doesn't have strings or integers, just lists of tokens so there isn't really a conversion between strings and integers, 123 is a string if you want to treat it as a string and an integer if you treat it as in integer Commented Jul 27, 2019 at 20:52
  • 3
    @AFP As already said, \fpeval cannot contain unexpandable material such as \def; \IfSubStr is included, because it performs several \def. And it's definitely not allowed in the <test> ? <fp expr> : <fp expr> syntax.
    – egreg
    Commented Jul 27, 2019 at 21:02
  • 4
    @AFP You should first try explaining what your aim is.
    – egreg
    Commented Jul 27, 2019 at 21:16
  • 2
    This question is very similar to this one where you already got an answer. Can we close here?
    – siracusa
    Commented Jul 28, 2019 at 7:00
  • 1
    Note, it IS possible to pass 123 as an argument and parse it one token at a time, assuming you want to convert it to base 8 or something. Or use modulo arithmetic on a \count register. Commented Jul 28, 2019 at 23:58

0

Browse other questions tagged .