GeneralHow can I write to and read from an AUX file?

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
nderby
Posts: 3
Joined: Thu Jan 31, 2008 2:57 am

How can I write to and read from an AUX file?

Post by nderby »

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

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

How can I write to and read from an AUX file?

Post by Juanjo »

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:

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 \auxcommand
This is the first line of the file: \auxcommand
\immediate\read\inputstream to \auxcommand
This is the second line of the file: \auxcommand
\immediate\read\inputstream to \auxcommand
This is the third line of the file: \auxcommand
\immediate\closein\inputstream
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
You can change the names of \outputstream, \inputstream and \auxcommand by those of your choice.
jpmrst
Posts: 1
Joined: Tue Jan 12, 2010 7:05 pm

How can I write to and read from an AUX file?

Post by jpmrst »

Nate,

This works for me for simple things:

Code: Select all

Code, edit and compile here:
\protected@write\@auxout{}{%
% What's to be written here.
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Note that you'll want to use the \string macro to defer expansion until when the aux-file is loaded, e.g.

Code: Select all

Code, edit and compile here:
\protected@write\@auxout{}{%
\string\@mycommand{arg}{arg}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Hope this helps!
-John
Post Reply