1

I'm trying to make siunitx interpret a number stored in a separate file on disk, but \num{\input{number.txt}} fails with the following error message: Argument of \@iinput has an extra }. Is there another way to do this?


MWE (assuming a file called "number.txt" exists on disk and its content is a number such as 1 in my case):

\documentclass{article}
\usepackage{siunitx}

\begin{document} \num{\input{number.txt}} \end{document}

  • What is your need? – projetmbc May 10 '23 at 20:42
  • The greater context of my problem is that I have lots of numbers stored individually in tiny files that I would like to typeset into tables using the tabularray package and align to their decimal points. Decimal alignment in tabularray tables is discussed in https://tex.stackexchange.com/q/672546/182557, however, the only solution is based on siunitx and doesn't work in my case because I am inputting my numbers from files on disk. I know decimal alignment is easy with tabular(x) environments, but I already have my tables in place, so I prefer solutions that work with tabularray. – Thomas Fritz May 10 '23 at 21:16
  • You should use S column not \num. – Clara May 11 '23 at 01:20

2 Answers2

2

You can read the file contents to a macro (\tmp in the example above) and then use it as a macro argument (but \tmp must be expanded by \expandafter).

\documentclass{article}
\usepackage{siunitx}

{\catcode`@=11 \gdef\readfile#1{{\endlinechar=-1 \everyeof={\end}\expandafter\readfileA@@input{#1}}} \gdef\readfileA#1\end{\gdef\tmp{#1}} }

\begin{document} \readfile{number.txt}\expandafter\num\expandafter{\tmp} \end{document}

wipet
  • 74,238
1

There is a simple example. You should read the doc of tabularray and siunitx.

num.txt:

6.618    & 287.1854 & 998.7116 & 163.1364 & 512.8064 & 291.2459 \\
518.5163 & 853.7523 & 80.038   & 94.076   & 271.9311 & 268.8729 \\
563.1559 & 20.6741  & 491.2001 & 665.8677 & 386.862  & 2.2473   \\
316.0299 & 614.1185 & 23.327   & 964.3642 & 238.9255 & 65.4116  \\
923.5761 & 944.643  & 155.7276 & 973.4626 & 951.6755 & 891.3304 \\
\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}
\UseTblrLibrary{functional}
\begin{document}
\begin{tblr}
[evaluate=\fileInput]
{
colspec={*{6}{Q[si={table-format=3.4},c,m]}},
hlines,vlines,
}
\fileInput{num.txt}
\end{tblr}
\end{document}

enter image description here

Clara
  • 6,012