Hello all,
How can I write to and read from an AUX file? I'm using LaTeX from NiKTeX 2.5, and I've tried this simple example to start, which gives me an error message:
\documentclass{article}
\begin{document}
\makeatletter
\immediate\write\@auxout{foo}
\end{document}
Can someone help me out?
Alternatively, is there some online tutorial somewhere about how to write to and read from an AUX file? I can't seem to find one.
Thanks so much,
Nate
General ⇒ How can I write to and read from an AUX file?
How can I write to and read from an AUX file?
You may try to read the documented code of LaTeX, i.e. the file source2e.pdf, to figure out how it works. In TeX Live, this file is at texmf-dist/doc/latex/base. You may also read The TeXbook, by D. Knuth, or TeX by Topic, by Victor Eijkhout, that you can download here. I also provide you a simple example. It does not consider the aux file, but a a custom file. Anyway, it may be heplpful:
You can change the names of \outputstream, \inputstream and \auxcommand by those of your choice.
Code: Select all
Code, edit and compile here:
\documentclass{article}\begin{document}% This writes the file myfile.tmp.% It will contain three lines\newwrite\outputstream\immediate\openout\outputstream=myfile.tmp\immediate\write\outputstream{foo 1}\immediate\write\outputstream{foo 2}\immediate\write\outputstream{\string\textbf{foo 3}}\immediate\closeout\outputstream% This reads myfile.tmp and writes its contents\newread\inputstream\immediate\openin\inputstream=myfile.tmp\immediate\read\inputstream to \auxcommandThis is the first line of the file: \auxcommand\immediate\read\inputstream to \auxcommandThis is the second line of the file: \auxcommand\immediate\read\inputstream to \auxcommandThis is the third line of the file: \auxcommand\immediate\closein\inputstream\end{document}
How can I write to and read from an AUX file?
Nate,
This works for me for simple things:
Note that you'll want to use the \string macro to defer expansion until when the aux-file is loaded, e.g.
Hope this helps!
-John
This works for me for simple things:
Code: Select all
Code, edit and compile here:
\protected@write\@auxout{}{%% What's to be written here.}
Code: Select all
Code, edit and compile here:
\protected@write\@auxout{}{%\string\@mycommand{arg}{arg}}
-John