从LaTeX临时文件写入和读取?

时间:2010-01-22 06:04:50

标签: latex

我正在撰写一份文档,其中包含一系列“任务列表”。我想在最后列出所有任务的单一列表。在我看来,我应该能够使用相同类型的中间文件,用于目录,表格列表和图表列表。但我无法想办法 - 我尝试添加\addtocontents不同的扩展名,但这似乎不起作用。有没有人知道如何做到这一点?

3 个答案:

答案 0 :(得分:25)

你可以这样做:

\newwrite\tempfile

在你的序言中声明一个新的文件编写者。

然后,要在需要时打开文件,可以将编写器分配给文件并打开它:

\immediate\openout\tempfile=lists.txt

要写入文件:

\immediate\write\tempfile{this is interesting}

最后,使用以下命令关闭文件:

\immediate\closeout\tempfile

要阅读文件,可以像\input一样简单,也可以使用\newread\openin\read\closein组合。< / p>

这是你想要做的吗?

编辑:这“对我有用”:

\documentclass{minimal}
\newwrite\tempfile
\begin{document}
\immediate\openout\tempfile=lists.tex
\immediate\write\tempfile{this is interesting}
\immediate\write\tempfile{}
\immediate\write\tempfile{this too}
\immediate\closeout\tempfile
\input{lists}
\end{document}

答案 1 :(得分:3)

我对\addtocontents机制没有太多运气。我有更好的运气将任意LaTeX代码写入.aux文件。这些示例实在太大了,无法在SO答案中发布,但您可以在noweb中找到“子页面标签”处理方式中的一个,您可以在我的技术报告中找到类似的内容Teach Technical Writing in Two Hours Per Week ,它积累了一些原则和实践清单。 noweb来源是公开的(在Debian中),如果有人想要另一个,请给我发电子邮件。

对于这样的事情,我鼓励你强烈地挖掘LaTeX层并研究Donald Knuth的 The TeXbook 。这就是真正解释可用机制的地方。

如果您的任务列表真的要在结束,那么您可以避免所有的废话,只需分配一个全局令牌寄存器,您在该文档中累积了该注册表。您可以在 The TeXbook (脏技巧)的附录D中找到一些有用的想法和示例。

答案 2 :(得分:3)

你想要LaTeX的todonotes包:

\usepackage{todonotes}

\begin{document}

\todo{This will be a note typeset in the margin}
\todo[inline]{This will be an in-line todo}
\missingfigure{This will give me a box indicating a pic should go here}

\listoftodos % will give you all of your todos from the document.

http://www.tex.ac.uk/tex-archive/help/Catalogue/entries/todonotes.html