While trying to answer this question, I proposed this solution, which obviously does not work as expected, otherwise we would not be here.

The solution works for explicit strings but not for strings stemming from a siunitx macro such as \num, which is the behavior expected by the OP, so if you find a solution, feel free to propose it in the original question.

So my question is, how to force latex to expand the result of \num{xxx} before a macro using it as an argument ?

It probably can be solved with \expandafter and related functions, but I just managed to mess everything while trying these.


    \tikz[overlay,remember picture]{\draw[stealth-] (tempnode) --++ (0,-2em);}

    \item  \addbelowarrow{123456789}{4} % works fine
    \item  \addbelowarrow{\num{123456789}}{4} % does not work

  • you can't, \num is not expandable. But if you only want the number you could read it from the argument and ignore the \num. – Ulrike Fischer Apr 19 '20 at 21:29
  • @UlrikeFischer I do not know how to react to that. Could you explain a bit why ? You mean there is no way to store the string output from \num ? I know it may seem a really dumb question to ask, but I just don't understand at the moment. – BambOo Apr 19 '20 at 21:37
  • 2
    \num doesn't make strings it is a typesetting command, you would have similar issues if you used \textbf{12}textit{245}\hspace{2pt}678 you can't use string operations on such a thing – David Carlisle Apr 19 '20 at 21:43
  • 1
    Here is an analogous hack. That probably buries the idea. – user194703 Apr 20 '20 at 0:27
  • 2
    @BambOo Yes, you cannot store the result of \pgfmathprintnumber in a macro AFAIK. – user194703 Apr 20 '20 at 12:25

This is merely a collection of the above comments (thanks for the kind remarks to Ulrike Fischer, David Carlisle and Schrödinger's cat

  • \num is a typesetting command, it does not assemble strings per se, so there is not expandable output of this function. As an example it makes as much sense to try to expand \num{1.234} than \textbf{12}textit{245}\hspace{2pt}678 to a string
  • \pgfmathprintnumber seems to work in the same fashion, so here again, the result is not expandable.

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.