My question is a follow-up to this question.
I want to write variables to aux file and also declare them there because the number of variables varies and their csnames are defined in the document body automatically during build process. I have a control sequence that iterates through generated variables and writes declare and store commands (using c-type argument instead of N) to aux file. Everything works well except that I get errors similar to this:
Control sequence \g_test_int already defined.
The aux file itself looks correct (this is from MWE):
\relax
\ExplSyntaxOn
\int_new:N \g_test_int
\ExplSyntaxOff
MWE:
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\AtEndDocument{
\iow_now:cx{@auxout}{
\token_to_str:N \ExplSyntaxOn
^^J
\int_new:N\g_test_int
^^J
\token_to_str:N \ExplSyntaxOff
}
}
\ExplSyntaxOff
\begin{document}
Hello
\end{document}