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}
\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.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.