写入和读取 LaTeX 临时文件?

发布于 2024-08-18 23:09:11 字数 1459 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

時窥 2024-08-25 23:09:11

你可以这样做:

\newwrite\tempfile

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

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

\immediate\openout\tempfile=lists.txt

写入文件:

\immediate\write\tempfile{this is interesting}

最后,关闭文件:

\immediate\closeout\tempfile

要读取文件,可以像 一样简单\input,或者您可以使用 \newread\openin\read\closein组合。

这是你想做的吗?

编辑:这“对我有用”:

\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}

You can do:

\newwrite\tempfile

in your preamble to declare a new file writer.

Then, to open a file when you want to, you can assign the writer to a file and open it:

\immediate\openout\tempfile=lists.txt

To write to the file:

\immediate\write\tempfile{this is interesting}

Finally, close the file with:

\immediate\closeout\tempfile

To read a file, it could be as simple as \input, or you can use \newread, \openin, \read and \closein combination.

Is this what you want to do?

Edit: This "works for me":

\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}
生生不灭 2024-08-25 23:09:11

我对 \addtocontents 机制不太感兴趣。我将任意 LaTeX 代码写入 .aux 文件的运气要好得多。这些示例确实太大,无法在 SO 答案中发布,但您可以在 中找到一个noweb 以“子页面标签”的处理方式,您可以在我的技术报告中找到类似的内容每周两小时教授技术写作,其中积累了一些原则和实践的列表。 noweb 源是公开的(并且在 Debian 中),如果有人想要另一个,请给我发电子邮件。

对于这样的东西,我强烈鼓励您深入 LaTeX 层并学习 Donald Knuth 的 The TeXbook。这才是真正解释可用机制的地方。

如果您的任务列表确实要在末尾出现,您可以避免所有废话,只需分配您在整个文档中积累的全局令牌寄存器即可。您将在 The TeXbook 的附录 D(肮脏的技巧)中找到一些有用的想法和示例。

I haven't had much luck with the \addtocontents mechanism. I have much better luck writing arbitrary LaTeX code to the .aux file. The examples are really too big to post in an SO answer, but you can find one in the noweb in the way "subpage labels" are handled, and you can find something similar in my technical report Teach Technical Writing in Two Hours Per Week, which accumulates some lists of principles and practices. The noweb source is public (and in Debian), and if anyone wants to the the other, send me an email.

For stuff like this, I encourage you strongly to dig under the LaTeX layer and study The TeXbook by Donald Knuth. That's the place where the mechanisms available are really explained.

If your list of tasks is really going to come at the end, you can avoid all the nonsense and just allocate a global tokens register which you accumulated throughought the document. You'll find some helpful ideas and examples in Appendix D of The TeXbook (Dirty tricks).

只怪假的太真实 2024-08-25 23:09:11

你需要 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

you would want the todonotes package for LaTeX:

\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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文