是的,TeX 可以读取文件中的一行并将其用作输入。下面的示例工作代码现在实现了 Willie Wong 的接受答案。对于新用户:“\inputL”和“\inputR”不是 TeX 命令。Wong 先生的回答指出它们是宏。TeX 宏类似于在第一次使用宏名称时声明的变量,并将字符串值读入其中。它类似于函数,因为当第二次使用宏名称时,它将返回字符串值。源文件、所需输出和示例代码如下。
请假设源文件包含这些内容。
LeftPageParagraphs.tex:
This is paragraph 1 from LeftPageParagraphs.tex file.
This is paragraph 2 from LeftPageParagraphs.tex file.
RightPageParagraphs.tex:
This is paragraph 1 from RightPageParagraphs.tex file.
This is paragraph 2 from RightPageParagraphs.tex file.
所需的输出文档应该有左页和右页。
左页应该已经阅读并输入了一段话:
This is paragraph 1 from LeftPageParagraphs.tex file.
右页应该读入一段话:
This is paragraph 1 from RightPageParagraphs.tex file.
带注释的解决方案最小工作示例:
\documentclass[openany]{book}
\usepackage{paracol} % Parallel columns package
% The \chunks command outputs a pair of parallel paragraphs to
% the left and right columns on facing pages.
\newcommand\chunks[2]{%
\begin{leftcolumn*}
{#1}%
\end{leftcolumn*}%
\begin{rightcolumn}
{#2}%
\end{rightcolumn}%
}
\begin{document}
% Open *.tex files in input streams 0 and 1).
\openin0 = {LeftPageParagraphs}
\openin1 = {RightPageParagraphs}
\begin{paracol}[1]*{2} % Open parallel columns "environment".
\read0 to \inputL % <-- Reads first line from first file.
\read1 to \inputR % <-- Reads first line from second file.
\chunks % <-- Pass: Adds line from each file as paragraph.
{\inputL}
{\inputR}
\end{paracol}
% Close files (input streams 0 and 1).
\closein0
\closein1
\end{document}
答案1
(从评论转换而来)
该命令\read<stream> to<macro>
存储下一行输入<stream>
并将其存储为<macro>
。
因此,如果你正在阅读的文件开始
Hello World!
Hi There.
然后
\read0 to\InPutWorld
\read0 to\InPutThere
效果与
\def\InPutWorld{Hello World!}
\def\InPutThere{Hi There.}
因此,为了实现您的目标,您可能应该:
\read0 to \inputL
\read1 to \inputR
\chunks{\inputL}{\inputR}