3

I'm trying to get this basic functionality to work. I've got an array of commands (that I've defined using \edef) that I'm using essentially as counters. I want to write these commands in an expanded form to the aux-file. Here is what I've got so far:

\documentclass{article}
\usepackage{etoolbox}
\usepackage{forloop}

\AtEndDocument{%
    \newcounter{tempsection}%
    \forloop{tempsection}{1}{\value{tempsection} < 3}{%
        \immediate\write\@mainaux{%
            \string\expandafter\string\edef\string\csname pointcount@\thetempsection\string\endcsname{\csname pointcount@\thetempsection\endcsname}%
        }%
    }%
}%

\begin{document}
\expandafter\edef\csname pointcount@1\endcsname{3}
\expandafter\edef\csname pointcount@2\endcsname{4}
\end{document}

In this example, I would like exactly this to be written to the aux-file so the commands would be available in the next compilation of the file:

\expandafter\edef\csname pointcount@1\endcsname{3}
\expandafter\edef\csname pointcount@2\endcsname{4}
0

1 Answer 1

3

You could do

\documentclass{article}
\usepackage{etoolbox}
\usepackage{forloop}
\makeatletter
\AtEndDocument{%
    \newcounter{tempsection}%
    \forloop{tempsection}{1}{\value{tempsection} < 3}{%
        \immediate\write\@mainaux{%
            \string\expandafter\gdef\noexpand\csname pointcount@\thetempsection\string\endcsname{\csname pointcount@\thetempsection\endcsname}%
        }%
    }%
}%
\makeatother

\begin{document}
\expandafter\edef\csname pointcount@1\endcsname{3}
\expandafter\edef\csname pointcount@2\endcsname{4}
\end{document}

Note you need \gdef so the setting escapes the local group used when reading the aux file.

the aux file is written as

\relax 
\expandafter\gdef \csname pointcount@1\endcsname{3}
\expandafter\gdef \csname pointcount@2\endcsname{4}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .