[texhax] transport between latex runs; reuse .aux file content

Mathias messagecollector at gmx.net
Sat Aug 13 20:24:19 CEST 2011


Hello,

I want to transport commands and lengths between (pdf)latex runs.
Their values are altered during processing the document and
exactly those at the document's end should be reused from the
document's very beginning of the next run.

My first idea was to use something similar to the TOC generation
via the .aux file.  So I took the sources of the lastpage package
and did some experiments:

--------------------snip--------------------
%\documentclass{article}%
\documentclass{minimal}%

\newcommand{\myCmd}{test123}%

\makeatletter%
\newcommand{\myWriteCmd}{%
  \write\@mainaux{\string\renewcommand{\string\myCmd}{test456}}}%
\makeatother%
\AtEndDocument{\myWriteCmd}%

\newlength{\myLen}\setlength{\myLen}{100pt}%

\makeatletter%
\newcommand{\myWriteLen}{%
  \write\@mainaux{%
%    \string\AtBeginDocument{\string\immediate\string\setlength{\string\myLen}{200pt}}}%
%    \string\immediate\string\setlength{\string\myLen}{200pt}}%
    \string\setlength{\string\myLen}{200pt}}%
}%
\makeatother%
\AtEndDocument{\myWriteLen}%

\typeout{DEBUG: \string\myCmd\space = \myCmd}%
\typeout{DEBUG: \string\myLen\space = \number\myLen}%
\begin{document}
\typeout{DEBUG: \string\myCmd\space = \myCmd}%
\typeout{DEBUG: \string\myLen\space = \number\myLen}%
Command: \myCmd \\
Lengths: \\
\rule{100pt}{1ex} (100pt) \\
\rule{\myLen}{1ex} \\
\rule{200pt}{1ex} (200pt)
\end{document}
--------------------snip--------------------

This writes a correct-looking .aux file:

--------------------snip--------------------
\relax
\renewcommand{\myCmd}{test456}
\setlength{\myLen}{200pt}
--------------------snip--------------------

Unfortunately this doesn't work as expected:  the
\renewcommand... and the \setlength seem not to be executed at
the document's beginning.

My attempts with an additional "\AtBeginDocument{...}"  or with
"\string\immediate" don't work either.  I also took some looks
into LaTeX's source source2e (especially section 18 ltfiles.dtx)
but this didn't help much.

Can you give me some hint concerning the above problem?

What exactly happens while passing from the preamble to the
document?  Where can I find more about this?

Thanks a lot,
Mathias


More information about the texhax mailing list