A value is saved in a file (value.txt, let's say).
The command
\SI{\input{value.txt}}{\someunit}
gives the error:
Argument of \input has an extra }
How can I read numbers from an external file and use them with \SI?
A value is saved in a file (value.txt, let's say).
The command
\SI{\input{value.txt}}{\someunit}
gives the error:
Argument of \input has an extra }
How can I read numbers from an external file and use them with \SI?
You have to read the file with TeX commands:
\documentclass{article}
\usepackage{siunitx}
\def\inputval{0}
\newread\inputFile
\let\oldSI\SI
\renewcommand*{\SI}[3][]{%
\IfFileExists{#2}{
\openin\inputFile=#2
\read\inputFile to \inputval
\closein\inputFile
\oldSI[#1]{\inputval}{#3}
}{\oldSI[#1]{#2}{#3}}
}
\begin{document}
\SI{value.txt}{\metre} % use \SI like always, but with input file
\oldSI{5}{\metre} % \oldSI does work like the old \SI ;)
\end{document}
Of course, this could be heavily improved (check if the format is correct, etc.), but that's the way to go.
\newcommand*{\readNumber} [1] {here the code}, where the only argument is the file to be read.
– Foo Bar
Apr 11 '13 at 08:42
\newread line outside the definition, where it's wrong.
– egreg
Apr 11 '13 at 09:24
% at the end of each line of the command to prevent extra spaces before and after the number
– Marcel
Apr 23 '21 at 17:05
\inputis not the correct approach: look atdatatoolorpgfplotstable. – Joseph Wright Apr 11 '13 at 08:42