基于这里,下面的代码应该可以工作,但是却不行。为什么?我只想将一个或两个值从一个.tex
文件复制到另一个文件:12
从复制A.tex
到B.tex
。有没有简单的方法可以做到这一点?谢谢
% % A.tex =============================
\documentclass[12pt]{article}
\usepackage{xfp}
\begin{document}
% % File write
\xdef\exportedvalue{12}
\exportedvalue % prints 12
\newwrite\file
\immediate\openout\file=myfilename.txt
% \immediate\write\file{Column}
\immediate\write\file{\fpeval{\exportedvalue}}
\closeout\file
% \end{document}
% % B.tex =============================
% \documentclass[12pt]{article}
% \usepackage{xfp}
% \begin{document}
% % File read
\newread\file
\openin\file=myfilename.txt
\loop\unless\ifeof\file
\read\file to\fileline % Reads a line of the file into \fileline
\xdef\importedvalue{\fpeval{\fileline}} % Do something with \fileline % when I commenting out this line (and \importedvalue), it compiles, but does not import the number
\repeat
\closein\file
\importedvalue %does not print 12 that I can reuse elsewhere in the document % when I commenting out this line (and \xdef\importedvalue{\fpeval{\fileline}}), it compiles, but does not import the number
\end{document}
答案1
我认为你可以安排简单地输入文件
\documentclass[12pt]{article}
\begin{document}
% % File write
\xdef\exportedvalue{12}
\exportedvalue % prints 12
\newwrite\file
\immediate\openout\file=myfilename.txt
% \immediate\write\file{Column}
\immediate\write\file{\def\noexpand\importedvalue{\fpeval{\exportedvalue}}}
\immediate\closeout\file
% \end{document}
% % B.tex =============================
% \documentclass[12pt]{article}
% \usepackage{xfp}
% \begin{document}
% % File read
\input{myfilename.txt}
\importedvalue
\end{document}