使用 readarray 中的值进行数学运算

使用 readarray 中的值进行数学运算

我使用包从文件中读取了一些数字readarray。但现在我需要将这两个数字相加,并将它们的总和输出到文件中。有没有办法在 LaTeX 中做到这一点?如果可能的话,我宁愿避免使用 TikZ 和其他重量级包。

\documentclass{article}

\usepackage{filecontents}
\usepackage{readarray}

\begin{filecontents}{testdata.dat}
1 2
3 4
\end{filecontents}

\readdef{testdata.dat}{\mydata}
\readarray\mydata\myarray[-,\ncols]

\newcommand{\plustwo}[1]{\number\numexpr#1+2\relax}

\begin{document}
I want the following to display as a number: \plustwo{\myarray[2,2]}.
\end{document}

答案1

显然被在书面文件中添加序言readarray所彻底搞糊涂了filecontents

%% LaTeX2e file `testdata.dat'
%% generated by the `filecontents' environment
%% from source `draconis' on 2018/10/23.
%%
1 2
3 4

并发出错误。

! Package listofitems Error: Empty list ignored, nothing to do.

序言filecontents*没有写出来,一切都按预期进行。

相关内容