I am interested in the basic mechanism behind writing stuff to the .aux
file. (Or some other auxiliary file).
Let's say I want to write myself a basic package for making notes on my files. (I know packages already exist for doing this. The point of this question is not to work out how to get comments on my paper, it is to learn about an aspect of the basics of TeX/LaTeX.)
So I have something like this in my preamble:
\usepackage{xcolor}
\newif\ifcomments
\commentstrue
\newcommand\comment[1]{%
\ifcomments
\textcolor{red}{\textsf{#1}}
\else
\fi
}
This means I have comments I can turn on and off. Now, the next stage is I want a list of comments to appear in an itemize
at the end of the document, each comment listed along with its page number. To achieve this, it seems like the easiest way would be to write each comment (plus its page number) to an auxiliary file, and then have a command \writecomments
that prints the contents of that file. (Or something of that sort).
How, in simple terms, could I achieve this?
NB this question is designed to help me learn about the basics of TeX/LaTeX, so solutions that involve packages doing a lot of the work will be frowned upon.
Edit I've had two very interesting answers offering different ways to achieve what I want in my example. Neither answer, however, really gets to the real answer I wanted, which would be a, accessible introduction to TeX's/LaTeX's "write to auxiliary file" mechanism.
What I'd like is a more basic answer that someone newer to TeX/LaTeX could read and understand. I feel the current answers are a little too high level.