In my implementation of an automatic word count (adapted from this solution), only the count and nothing else is output to a text file, to be inserted into the tex document with \input. This works fine, but not when combined with siunitx's \num for number formatting, which produces an error. The problem is likely the newline character that \input automatically added. My attempt to circumvent the newline with this solution doesn't help. How can I make this work?
\documentclass{article}
\usepackage[group-minimum-digits=4,group-separator={,}]{siunitx}
\begin{filecontents}{\jobname_wordcount.txt}
1234
\end{filecontents}
\newcommand\minput[1]{% doesn't help
\input{#1}%
\ifhmode\ifnum\lastnodetype=11 \unskip\fi\fi}
\begin{document}
\input{\jobname_wordcount.txt}words % works
% \num\input{\jobname_wordcount.txt}words % causes error
\end{document}

\inputis not expandable). Usually there would be afunctionalanswer, but it doesn't seem to support optional argument yet. – user202729 Jun 21 '22 at 00:32