In my program below, I defined a function \checklist that takes to optional arguments and one compulsory argument. The function works as expected.
Then, I would like to define another function \othercheck that calls \checklist:
- e.g.,
\othercheck[10]{blah}should call\checklist[1][0]{blah}. - e.g.,
\othercheck[11]{blah}should call\checklist[1][1]{blah}.
Why does it return the following error? I understand that it is probably because a string is fed instead of a number but I did not manage to overcome that using some conversion strategies (etoolbox, etc).
! Missing number, treated as zero. \let l.39 ...check[01]{Second square should be checked}
\documentclass{article}
\usepackage{etoolbox}
\usepackage{wasysym}
\usepackage{xparse}
\usepackage{xargs}
\newcommandx{\checklist}[3][1=0, 2=0]{
\ifnumcomp{#1}{=}{0}{\Square}{\XBox}%
\ifnumcomp{#2}{=}{0}{\Square}{\XBox}%
#3%
}%
\usepackage{xstring}
\newcommandx{\othercheck}[2][1=]{%
% if no optional argument
\ifstrempty{#1}{\checklist{#2}}%
{%
% if optional argument
\def\varA{\StrMid{#1}{1}{1}}
\def\varB{\StrMid{#1}{2}{2}}
\checklist[\varA][\varB]{#2}
}%
}%
\begin{document}
\checklist{Check this} % OK
\checklist[1][0]{Check that} % OK
\othercheck{Default: nothing checked} % OK
%\othercheck[01]{Second square should be checked} % <---- crashes
\end{document}


\checklistsay using\typeout{\meaning #1}etc. You'll notice that\ifnumcompis given\StrMid {01}{1}{1}which in it self is not a number and thus cannot be compared using\ifnumcomp. Remember that many of these macros does not expand their input. Perhaps you should start over and explain what exactly the end goal is? Then people can suggest modern solutions.