Here is a problem that has been puzzling me for a few days. Basically, I try to parse strings and test their symbols one by one to define whether they are or not numbers (in order to achieve some more complicated treatment, beyond this topic).

The macros \@neByOne, \aux@neByOne, \c@untunlessnil and \gobblechar split the string. For each symbol, the macro \testSymbol is called and is meant to tell if it is a number.

The problem: when called directly, \testSymbol returns the expected result. But when called by \c@untunlessnil, the test fails. In fact, the parameter #1 is not seen as a number by \ifnum. Below are my files and the results I get.

Thank you for your help.

Content of myExtension.sty

        <<#1>> is a number\\
        <<#1>> is a NOT number\\

\def\gobblechar{\let\ch@r= }


Content of myMainFile.tex :



The output I get:

«1» is a NOT number
«2» is a NOT number
«3» is a NOT number
«1» is a number
«2» is a number
«3» is a number
  • Do you have to test individual numbers in 123, or can you just test 123 as a whole? – Werner Dec 28 '16 at 19:12
  • Easy: if you say \let\next=1, then \ifnum0<0\next returns false, because \next is not expandable. – egreg Dec 28 '16 at 19:13
  • @Werner: I have to test individual characters as some of them may not be numeric. – zigma12 Dec 28 '16 at 19:16
  • @egreg: I am sorry but I do not understand what you mean. I have to admit that the "splitting" macros are not from me thus I do not get exactly how they work. Thank you – zigma12 Dec 28 '16 at 19:19
  • @egreg: I thought that #1 was \ch@r which expands well... – zigma12 Dec 28 '16 at 19:23

You can use a test such as the following

enter image description here


      IS NOT
    IS NOT
a number\par

  • Looks good! I didn't know the \@tfor command. – zigma12 Dec 29 '16 at 8:18
  • Now, what if I want to use something like that? : \def\myString{a123b}\test\myString – zigma12 Dec 29 '16 at 8:20
  • @zigma12 \expandafter\test\expandafter{\mystring} – David Carlisle Dec 29 '16 at 12:30
  • Many thanks. I tried to put some \expandafter but not the right way. Please, tell me if I get it right: the 2nd \expandafter applies to the opening (and so closing) brace? – zigma12 Dec 29 '16 at 13:05
  • @zigma12 no the second \expandafter expands \mystring, the first \expandafter expands the second \expandafter. – David Carlisle Dec 29 '16 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.