2

Consider the following example, in which it (globally) adds an element TEST to the sequence \g__mymodule_test_seq in the .aux file. Then if it is asked to show the sequence content immediately in the aux file, the result is correct (this is the commented code). However, if later asked to show in the document, it shows that the sequence is empty. Why would this happen, considering that the \seq_gput_right:Nn is indeed the global version? What is the correct way to do this?

\documentclass{article}

\begin{document}

\makeatletter
\ExplSyntaxOn

\seq_new:N \g__mymodule_test_seq

\iow_now:cx { @auxout }
  {
    \token_to_str:N \ExplSyntaxOn
    ^^J
    \token_to_str:N \seq_gput_right:Nn \token_to_str:N \g__mymodule_test_seq {TEST}
    ^^J
    \token_to_str:N \ExplSyntaxOff
  }


%% This shows empty
\seq_show:N \g__mymodule_test_seq

%% This shows "TEST"
% \iow_now:cx { @auxout }
%   {
%     \token_to_str:N \ExplSyntaxOn
%     ^^J
%     \token_to_str:N \seq_show:N \token_to_str:N \g__mymodule_test_seq
%     ^^J
%     \token_to_str:N \ExplSyntaxOff
%   }

\ExplSyntaxOff

\end{document}

The content of the .aux file is:

\relax 
\ExplSyntaxOn
\seq_gput_right:Nn\g__mymodule_test_seq{TEST}
\ExplSyntaxOff
\gdef \@abspage@last{1}
2
  • I don't think that it is good idea to write lots of \ExplSyntaxON/Off to the aux. Write a command \jin@gput@seq and push \jin@gput@seq{TEST} to the aux. Commented Mar 20 at 23:38
  • @UlrikeFischer Thank you for this advice. In my package I am doing this, it's just in this MWE I would like to keep things simpler.
    – Jinwen
    Commented Mar 20 at 23:40

1 Answer 1

1
  1. The allocation of the variable should be done in the preamble, before the .aux file is read in.

  2. At the first run, you get empty, because the .aux file is empty.

  3. At the next run, you get

    The sequence \g__mymodule_test_seq contains the items (without outer braces):
    >  {TEST}.
    

Full code, where \seq_show:N can be before or after the \iow_now:ce instruction (nowadays preferred to \iow_now:cx)

\documentclass{article}

\ExplSyntaxOn
\seq_new:N \g__mymodule_test_seq
\ExplSyntaxOff

\begin{document}

\ExplSyntaxOn

\iow_now:ce { @auxout }
  {
    \token_to_str:N \ExplSyntaxOn
    ^^J
    \token_to_str:N \seq_gput_right:Nn \token_to_str:N \g__mymodule_test_seq {TEST}
    ^^J
    \token_to_str:N \ExplSyntaxOff
  }

\seq_show:N \g__mymodule_test_seq

\ExplSyntaxOff

\end{document}
8
  • Thank you for this. However, with your given code, I am still getting The sequence \g__mymodule_test_seq is empty, no matter how many times I compile.
    – Jinwen
    Commented Mar 20 at 23:23
  • 1
    @Jinwen I get exactly what I described. So you're doing something else you're not telling. By the way, if you use \iow_now:cn you can dispense with \token_to_str:N.
    – egreg
    Commented Mar 20 at 23:26
  • Oh, I understand. It seems to be my editor, whenever I am using \seq_show:N, it interprets the result as a compilation failure, so the next time it shall delete the temporary files, as a result, the aux file content is lost in the process.
    – Jinwen
    Commented Mar 20 at 23:36
  • Please allow me to ask a follow-up question. I was being told that with TeX Live 2023 on overleaf, \iow_now:ce would lead to "Undefined control sequence" error. Thus would it be possible to use \iow_now:cx in this case? I was a bit concerned about this since \iow_now:cx does not seem to have appeared in interface3.pdf.
    – Jinwen
    Commented Mar 24 at 14:33
  • 1
    @Jinwen You can alwasy do \cs_generate_variant:Nn \iow_now:Nn { ce } and it will work in several previous releases, starting from 2018.
    – egreg
    Commented Mar 24 at 15:01

You must log in to answer this question.

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