# How to expand the result of a siunitx macro to use it as an argument for another marco

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.

\documentclass{article}
\usepackage{xstring}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\newcommand{\addbelowarrow}[2]{%
\pgfmathtruncatemacro{\charbefore}{#2-1}
\pgfmathtruncatemacro{\charafter}{#2+1}
\StrMid{#1}{1}{\charbefore}%
\tikzmarknode{tempnode}{\StrChar{#1}{#2}}%
\StrMid{#1}{\charafter}{100}%
\tikz[overlay,remember picture]{\draw[stealth-] (tempnode) --++ (0,-2em);}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{itemize}
\item  \addbelowarrow{123456789}{4} % works fine
\item  \addbelowarrow{\num{123456789}}{4} % does not work
\end{itemize}

\end{document}

• 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
• \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
• Here is an analogous hack. That probably buries the idea. – user194703 Apr 20 '20 at 0:27
• @BambOo Yes, you cannot store the result of \pgfmathprintnumber in a macro AFAIK. – user194703 Apr 20 '20 at 12:25

## 1 Answer

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.