What is the maximum limit of elements in a list (expl3/xparse)?Avoid passing an empty [optional argument] an...

Critique of timeline aesthetic

can anyone help me with this awful query plan?

'regex' and 'name' directives in find

Does tea made with boiling water cool faster than tea made with boiled (but still hot) water?

How do I reattach a shelf to the wall when it ripped out of the wall?

bldc motor, esc and battery draw, nominal vs peak

Why did C use the -> operator instead of reusing the . operator?

Checks user level and limit the data before saving it to mongoDB

How did Captain America manage to do this?

"The cow" OR "a cow" OR "cows" in this context

Why must Chinese maps be obfuscated?

'It addicted me, with one taste.' Can 'addict' be used transitively?

a sore throat vs a strep throat vs strep throat

"Whatever a Russian does, they end up making the Kalashnikov gun"? Are there any similar proverbs in English?

Why does nature favour the Laplacian?

Pulling the rope with one hand is as heavy as with two hands?

What term is being referred to with "reflected-sound-of-underground-spirits"?

Minor Revision with suggestion of an alternative proof by reviewer

How can I get this effect? Please see the attached image

Thesis on avalanche prediction using One Class SVM

How to have a sharp product image?

Multiple options vs single option UI

What are the steps to solving this definite integral?

"Hidden" theta-term in Hamiltonian formulation of Yang-Mills theory



What is the maximum limit of elements in a list (expl3/xparse)?


Avoid passing an empty [optional argument] an environment (with verbatim content) using xparse?













0















I have a query with the maximum number of items that can be saved in an expl3 list. Thanks to the response that @egreg gave me in Avoid passing an empty [optional argument] an environment (with verbatim content) using xparse? I was able to finish the implementation of an environment capable of saving valid LaTeX code (including verbatim) in expl3lists ... something like a "fake ConTextbuffers".



Let me explain a bit, I have many question/answer files in which I have abused the use of filecontents to record temporary files and included them in environment based on environ (which did not support verbatim) and then use them in different parts of the documents.



With the new version of filecontentsdef it is not necessary to write the external files (included verbatim) to have them in a macro, thus the things and gathering ideas I have managed to create a listcontents environment which encapsulates filecontentsdefmacro, what run and save in a list, which I can access with usecontents[index]{list name}, the environment works perfectly.



My question is this, as the environment saves the content in one (or more lists), at some point the list will have a limit. What is the limit on the number of items I can save?



I have tested some files, but, I convert all my old files using a script to pass them to the new listcontents environment.



I leave here the example code (for sure it is not written in the perfect way, but it works)



documentclass{article}
usepackage{xparse}
usepackage{filecontentsdef}[2019/04/20] % last version 1.4 (ctan)
makeatletter
ExplSyntaxOn
% elementin{listname}
cs_new:Npn elementin #1
{
seq_count:c { l_listcontents_contents_#1_seq }
}

% clearlist{listname}
cs_new:Npn clearlist #1
{
seq_clear_new:c { l_listcontents_contents_#1_seq }
}

% @add@contents{listname}{{#1}}
NewDocumentCommand{@add@contents}{ m +m }
{
listcontents_add_contents:nn { #1 } { #2 }
}

% usecontents[index]{listname}
DeclareExpandableDocumentCommand{usecontents}{ O{1} m }
{
listcontents_use_contents:nn { #1 } { #2 }
}

cs_new_protected:Npn listcontents_add_contents:nn #1 #2
{
seq_if_exist:cF { l_listcontents_contents_#1_seq }
{ seq_new:c { l_listcontents_contents_#1_seq } }
__listcontents_add_contents:nn { #1 } { #2 }
}

cs_new_protected:Npn __listcontents_add_contents:nn #1 #2
{
tl_map_inline:nn { #2 }
{
seq_gput_right:cn { l_listcontents_contents_#1_seq } { ##1 }
}
}

cs_new:Npn listcontents_use_contents:nn #1 #2
{
seq_item:cn { l_listcontents_contents_#2_seq } { #1 }
}

% tl vars and bool
tl_new:N l_add@tmpa@contents_tl
tl_new:N l_add@file@@contents_tl
bool_new:N l_write_file_bool
bool_new:N l_add_macro_bool
bool_set_true:N l_add_macro_bool

% [key=val] implementation
keys_define:nn { listcontents }
{
save-cmd .tl_set:N = l_listcontents_cmd_save_tl,
save-cmd .initial:n = contents,
save-env .tl_set:N = l_listcontents_env_save_tl,
save-env .initial:n = contents,
show-cmd .bool_set:N = l_listcontents_cmd_show_tl,
show-cmd .initial:n = false,
show-cmd .value_required:n = true,
show-env .bool_set:N = l_listcontents_env_show_tl,
show-env .initial:n = false,
show-env .value_required:n = true,
name-tmp .tl_set:N = l_tmp_name_output_tl,
file-out .code:n = {
bool_set_true:N l_write_file_bool
keys_set:nn { listcontents }
{
name-tmp = { #1 }
}
} ,
file-out .value_required:n = true,
file-use .code:n = {
bool_set_false:N l_add_macro_bool
bool_set_true:N l_write_file_bool
keys_set:nn { listcontents }
{
name-tmp = { #1 } ,
}
} ,
file-out .value_required:n = true,
show-all .meta:n = { show-env = true , show-cmd = true },
}

keys_define:nn { listcontents / scontents }
{
show-cmd .code:n = { keys_set:nn { listcontents } { show-cmd = { #1 } } } ,
save-cmd .code:n = { keys_set:nn { listcontents } { save-cmd = { #1 } } } ,
}

NewDocumentCommand{Setlistcontents}{ +m }
{
keys_set:nn { listcontents } { #1 }
}

% scontents[...]{...} NO verbatim and par support
NewDocumentCommand{scontents}{ O{} m }
{
group_begin:
IfNoValueF { #1 } { keys_set:nn { listcontents / scontents } { #1 } }
@add@contents{ l_listcontents_cmd_save_tl }{ { #2 } } % pass direct to list
IfBooleanT { l_listcontents_cmd_show_tl } { usecontents[-1]{ l_listcontents_cmd_save_tl} }
group_end:
}

% begin{listcontents}[key val in one line] verbatim env suport in macro
NewDocumentEnvironment{ listcontents }{}
{
char_set_catcode_active:N ^^M
listcontents_start_listcontents:w
}
{
IfBooleanTF{ l_write_file_bool } { endfilecontentsdef } { endfilecontentsdefmacro }
group_end:
IfBooleanTF{ l_add_macro_bool }
{
tl_put_right:Nx l_tmpb_tl {
tex_newlinechar:D = 13 tex_everyeof:D = {noexpand}
exp_not:N scantokens exp_after:wN { l_tmpa_tl }
tex_newlinechar:D = 10relax
}
tl_put_right:Nx l_add@tmpa@contents_tl {
exp_not:N @add@contents { exp_not:V l_listcontents_env_save_tl } { {exp_not:V l_tmpb_tl } }
}
l_add@tmpa@contents_tl
}
{
tl_put_right:Nx l_add@file@@contents_tl {
exp_not:N @add@contents { exp_not:V l_listcontents_env_save_tl } { { exp_not:N input { exp_not:V l_tmp_name_output_tl } } }
}
l_add@file@@contents_tl
}
IfBooleanT{ l_listcontents_env_show_tl } { usecontents[-1]{ l_listcontents_env_save_tl} }
}

cs_new_protected:Npn listcontents_listcontents_set:w [#1]
{
keys_set:nn { listcontents } { #1 }
}

group_begin:
char_set_catcode_active:N ^^M
cs_new_protected:Npn listcontents_start_listcontents:w #1 ^^M
{
tl_if_blank:nF { #1 } { listcontents_listcontents_set:w #1 }
group_begin:
IfBooleanTF{ l_write_file_bool }
{ use:c { filecontentsdef* } { l_tmp_name_output_tl } { l_tmpa_tl } ^^M }
{ use:c { filecontentsdefmacro } { l_tmpa_tl } ^^M }
}
group_end:
ExplSyntaxOff
makeatother
% only for example
usepackage[margin=0.5in,noheadfoot,papersize={8.5in,11in}]{geometry}
usepackage{pgffor}
setlength{parindent}{0pt}
pagestyle{empty}
begin{document}
section{Test begin{listcontents}[key=val]}
Test verb+begin{listcontents}+ no verb+[key=val]+par

begin{listcontents}
Using verb+listcontents+ env no verb+[key=val]+, save in list verb+contents+ with index 1.par
We have coded this in LaTeX: $E=mc^2$.par
begin{verbatim}
(A) verbatim environment
end{verbatim}
end{listcontents}

Test verb+begin{listcontents}[file-out=jobname.tsc]+par

begin{listcontents}[file-out=jobname.tsc]
Using verb+listcontents+ env with verb+[file-out=jobname.tsc]+, save in list verb+contents+ with index 2.
We have coded this in LaTeX: $E=mc^2$.par
begin{verbatim*}
(B) verbatim environment
end{verbatim*}
end{listcontents}

Test verb+begin{listcontents}[file-use=jobname.tsc]+par

begin{listcontents}[file-use=jobname-1.tsc]
Using verb+listcontents+ env with verb+[file-use=jobname-1.tsc]+, pass verb+input{jobname-1.tsc}+
to list verb+contents+ with index 3. We have coded this in LaTeX: $E=mc^2$.par
begin{verbatim}
(C) verbatim environment
end{verbatim}
end{listcontents}

Test verb+begin{listcontents}[show-env=true]+par

begin{listcontents}[show-env=true]
Using verb+listcontents+ env with verb+[show-env=true]+, save in list verb+contents+ with index 4.
We have coded this in LaTeX: $E=mc^2$.par
begin{verbatim*}
(D) verbatim environment
end{verbatim*}
end{listcontents}

Test verb+scontents{...}+par
scontents{Using texttt{scontents} command (no verbatim and par suport), save in list texttt{contents} with index 5}

section{Execution in reverse}
The total verb+contents saved+ (environment and command) saved in verb+contents+ list are elementin{contents}.par

usecontents[5]{contents}par
usecontents{contents}

section{Using a loop (pgffor)}

foreach i in {1,...,elementin{contents}} {usecontents[i]{contents}}

section{A simple aplication}

newcounter{exeNr}
newenvironment{exercise}
{refstepcounter{exeNr}parnoindent This is exercise~theexeNr}
{par}
subsection{Exercises}
begin{exercise}
end{exercise}
begin{listcontents}[save-env=myansewer]
This is the answer to exercise 1, the shebang line for a Perl script

begin{verbatim}
#!/usr/bin/env perl
end{verbatim}
end{listcontents}

begin{exercise}
end{exercise}
begin{listcontents}[save-env=myansewer]
This is the answer to exercise 2
end{listcontents}

begin{exercise}
end{exercise}
scontents[save-cmd=myansewer]{This is the answer to exercise 3}

subsection{Answers}
newcounter{ansNr}
newenvironment{answer}
{refstepcounter{ansNr}parnoindent Answer~theansNr:}
{par}

foreach i in {1,...,elementin{myansewer}} {
begin{answer}
usecontents[i]{myansewer}
end{answer}
}
end{document}


An image of what the output is like:
output example
Comments are welcome



regards









share



























    0















    I have a query with the maximum number of items that can be saved in an expl3 list. Thanks to the response that @egreg gave me in Avoid passing an empty [optional argument] an environment (with verbatim content) using xparse? I was able to finish the implementation of an environment capable of saving valid LaTeX code (including verbatim) in expl3lists ... something like a "fake ConTextbuffers".



    Let me explain a bit, I have many question/answer files in which I have abused the use of filecontents to record temporary files and included them in environment based on environ (which did not support verbatim) and then use them in different parts of the documents.



    With the new version of filecontentsdef it is not necessary to write the external files (included verbatim) to have them in a macro, thus the things and gathering ideas I have managed to create a listcontents environment which encapsulates filecontentsdefmacro, what run and save in a list, which I can access with usecontents[index]{list name}, the environment works perfectly.



    My question is this, as the environment saves the content in one (or more lists), at some point the list will have a limit. What is the limit on the number of items I can save?



    I have tested some files, but, I convert all my old files using a script to pass them to the new listcontents environment.



    I leave here the example code (for sure it is not written in the perfect way, but it works)



    documentclass{article}
    usepackage{xparse}
    usepackage{filecontentsdef}[2019/04/20] % last version 1.4 (ctan)
    makeatletter
    ExplSyntaxOn
    % elementin{listname}
    cs_new:Npn elementin #1
    {
    seq_count:c { l_listcontents_contents_#1_seq }
    }

    % clearlist{listname}
    cs_new:Npn clearlist #1
    {
    seq_clear_new:c { l_listcontents_contents_#1_seq }
    }

    % @add@contents{listname}{{#1}}
    NewDocumentCommand{@add@contents}{ m +m }
    {
    listcontents_add_contents:nn { #1 } { #2 }
    }

    % usecontents[index]{listname}
    DeclareExpandableDocumentCommand{usecontents}{ O{1} m }
    {
    listcontents_use_contents:nn { #1 } { #2 }
    }

    cs_new_protected:Npn listcontents_add_contents:nn #1 #2
    {
    seq_if_exist:cF { l_listcontents_contents_#1_seq }
    { seq_new:c { l_listcontents_contents_#1_seq } }
    __listcontents_add_contents:nn { #1 } { #2 }
    }

    cs_new_protected:Npn __listcontents_add_contents:nn #1 #2
    {
    tl_map_inline:nn { #2 }
    {
    seq_gput_right:cn { l_listcontents_contents_#1_seq } { ##1 }
    }
    }

    cs_new:Npn listcontents_use_contents:nn #1 #2
    {
    seq_item:cn { l_listcontents_contents_#2_seq } { #1 }
    }

    % tl vars and bool
    tl_new:N l_add@tmpa@contents_tl
    tl_new:N l_add@file@@contents_tl
    bool_new:N l_write_file_bool
    bool_new:N l_add_macro_bool
    bool_set_true:N l_add_macro_bool

    % [key=val] implementation
    keys_define:nn { listcontents }
    {
    save-cmd .tl_set:N = l_listcontents_cmd_save_tl,
    save-cmd .initial:n = contents,
    save-env .tl_set:N = l_listcontents_env_save_tl,
    save-env .initial:n = contents,
    show-cmd .bool_set:N = l_listcontents_cmd_show_tl,
    show-cmd .initial:n = false,
    show-cmd .value_required:n = true,
    show-env .bool_set:N = l_listcontents_env_show_tl,
    show-env .initial:n = false,
    show-env .value_required:n = true,
    name-tmp .tl_set:N = l_tmp_name_output_tl,
    file-out .code:n = {
    bool_set_true:N l_write_file_bool
    keys_set:nn { listcontents }
    {
    name-tmp = { #1 }
    }
    } ,
    file-out .value_required:n = true,
    file-use .code:n = {
    bool_set_false:N l_add_macro_bool
    bool_set_true:N l_write_file_bool
    keys_set:nn { listcontents }
    {
    name-tmp = { #1 } ,
    }
    } ,
    file-out .value_required:n = true,
    show-all .meta:n = { show-env = true , show-cmd = true },
    }

    keys_define:nn { listcontents / scontents }
    {
    show-cmd .code:n = { keys_set:nn { listcontents } { show-cmd = { #1 } } } ,
    save-cmd .code:n = { keys_set:nn { listcontents } { save-cmd = { #1 } } } ,
    }

    NewDocumentCommand{Setlistcontents}{ +m }
    {
    keys_set:nn { listcontents } { #1 }
    }

    % scontents[...]{...} NO verbatim and par support
    NewDocumentCommand{scontents}{ O{} m }
    {
    group_begin:
    IfNoValueF { #1 } { keys_set:nn { listcontents / scontents } { #1 } }
    @add@contents{ l_listcontents_cmd_save_tl }{ { #2 } } % pass direct to list
    IfBooleanT { l_listcontents_cmd_show_tl } { usecontents[-1]{ l_listcontents_cmd_save_tl} }
    group_end:
    }

    % begin{listcontents}[key val in one line] verbatim env suport in macro
    NewDocumentEnvironment{ listcontents }{}
    {
    char_set_catcode_active:N ^^M
    listcontents_start_listcontents:w
    }
    {
    IfBooleanTF{ l_write_file_bool } { endfilecontentsdef } { endfilecontentsdefmacro }
    group_end:
    IfBooleanTF{ l_add_macro_bool }
    {
    tl_put_right:Nx l_tmpb_tl {
    tex_newlinechar:D = 13 tex_everyeof:D = {noexpand}
    exp_not:N scantokens exp_after:wN { l_tmpa_tl }
    tex_newlinechar:D = 10relax
    }
    tl_put_right:Nx l_add@tmpa@contents_tl {
    exp_not:N @add@contents { exp_not:V l_listcontents_env_save_tl } { {exp_not:V l_tmpb_tl } }
    }
    l_add@tmpa@contents_tl
    }
    {
    tl_put_right:Nx l_add@file@@contents_tl {
    exp_not:N @add@contents { exp_not:V l_listcontents_env_save_tl } { { exp_not:N input { exp_not:V l_tmp_name_output_tl } } }
    }
    l_add@file@@contents_tl
    }
    IfBooleanT{ l_listcontents_env_show_tl } { usecontents[-1]{ l_listcontents_env_save_tl} }
    }

    cs_new_protected:Npn listcontents_listcontents_set:w [#1]
    {
    keys_set:nn { listcontents } { #1 }
    }

    group_begin:
    char_set_catcode_active:N ^^M
    cs_new_protected:Npn listcontents_start_listcontents:w #1 ^^M
    {
    tl_if_blank:nF { #1 } { listcontents_listcontents_set:w #1 }
    group_begin:
    IfBooleanTF{ l_write_file_bool }
    { use:c { filecontentsdef* } { l_tmp_name_output_tl } { l_tmpa_tl } ^^M }
    { use:c { filecontentsdefmacro } { l_tmpa_tl } ^^M }
    }
    group_end:
    ExplSyntaxOff
    makeatother
    % only for example
    usepackage[margin=0.5in,noheadfoot,papersize={8.5in,11in}]{geometry}
    usepackage{pgffor}
    setlength{parindent}{0pt}
    pagestyle{empty}
    begin{document}
    section{Test begin{listcontents}[key=val]}
    Test verb+begin{listcontents}+ no verb+[key=val]+par

    begin{listcontents}
    Using verb+listcontents+ env no verb+[key=val]+, save in list verb+contents+ with index 1.par
    We have coded this in LaTeX: $E=mc^2$.par
    begin{verbatim}
    (A) verbatim environment
    end{verbatim}
    end{listcontents}

    Test verb+begin{listcontents}[file-out=jobname.tsc]+par

    begin{listcontents}[file-out=jobname.tsc]
    Using verb+listcontents+ env with verb+[file-out=jobname.tsc]+, save in list verb+contents+ with index 2.
    We have coded this in LaTeX: $E=mc^2$.par
    begin{verbatim*}
    (B) verbatim environment
    end{verbatim*}
    end{listcontents}

    Test verb+begin{listcontents}[file-use=jobname.tsc]+par

    begin{listcontents}[file-use=jobname-1.tsc]
    Using verb+listcontents+ env with verb+[file-use=jobname-1.tsc]+, pass verb+input{jobname-1.tsc}+
    to list verb+contents+ with index 3. We have coded this in LaTeX: $E=mc^2$.par
    begin{verbatim}
    (C) verbatim environment
    end{verbatim}
    end{listcontents}

    Test verb+begin{listcontents}[show-env=true]+par

    begin{listcontents}[show-env=true]
    Using verb+listcontents+ env with verb+[show-env=true]+, save in list verb+contents+ with index 4.
    We have coded this in LaTeX: $E=mc^2$.par
    begin{verbatim*}
    (D) verbatim environment
    end{verbatim*}
    end{listcontents}

    Test verb+scontents{...}+par
    scontents{Using texttt{scontents} command (no verbatim and par suport), save in list texttt{contents} with index 5}

    section{Execution in reverse}
    The total verb+contents saved+ (environment and command) saved in verb+contents+ list are elementin{contents}.par

    usecontents[5]{contents}par
    usecontents{contents}

    section{Using a loop (pgffor)}

    foreach i in {1,...,elementin{contents}} {usecontents[i]{contents}}

    section{A simple aplication}

    newcounter{exeNr}
    newenvironment{exercise}
    {refstepcounter{exeNr}parnoindent This is exercise~theexeNr}
    {par}
    subsection{Exercises}
    begin{exercise}
    end{exercise}
    begin{listcontents}[save-env=myansewer]
    This is the answer to exercise 1, the shebang line for a Perl script

    begin{verbatim}
    #!/usr/bin/env perl
    end{verbatim}
    end{listcontents}

    begin{exercise}
    end{exercise}
    begin{listcontents}[save-env=myansewer]
    This is the answer to exercise 2
    end{listcontents}

    begin{exercise}
    end{exercise}
    scontents[save-cmd=myansewer]{This is the answer to exercise 3}

    subsection{Answers}
    newcounter{ansNr}
    newenvironment{answer}
    {refstepcounter{ansNr}parnoindent Answer~theansNr:}
    {par}

    foreach i in {1,...,elementin{myansewer}} {
    begin{answer}
    usecontents[i]{myansewer}
    end{answer}
    }
    end{document}


    An image of what the output is like:
    output example
    Comments are welcome



    regards









    share

























      0












      0








      0








      I have a query with the maximum number of items that can be saved in an expl3 list. Thanks to the response that @egreg gave me in Avoid passing an empty [optional argument] an environment (with verbatim content) using xparse? I was able to finish the implementation of an environment capable of saving valid LaTeX code (including verbatim) in expl3lists ... something like a "fake ConTextbuffers".



      Let me explain a bit, I have many question/answer files in which I have abused the use of filecontents to record temporary files and included them in environment based on environ (which did not support verbatim) and then use them in different parts of the documents.



      With the new version of filecontentsdef it is not necessary to write the external files (included verbatim) to have them in a macro, thus the things and gathering ideas I have managed to create a listcontents environment which encapsulates filecontentsdefmacro, what run and save in a list, which I can access with usecontents[index]{list name}, the environment works perfectly.



      My question is this, as the environment saves the content in one (or more lists), at some point the list will have a limit. What is the limit on the number of items I can save?



      I have tested some files, but, I convert all my old files using a script to pass them to the new listcontents environment.



      I leave here the example code (for sure it is not written in the perfect way, but it works)



      documentclass{article}
      usepackage{xparse}
      usepackage{filecontentsdef}[2019/04/20] % last version 1.4 (ctan)
      makeatletter
      ExplSyntaxOn
      % elementin{listname}
      cs_new:Npn elementin #1
      {
      seq_count:c { l_listcontents_contents_#1_seq }
      }

      % clearlist{listname}
      cs_new:Npn clearlist #1
      {
      seq_clear_new:c { l_listcontents_contents_#1_seq }
      }

      % @add@contents{listname}{{#1}}
      NewDocumentCommand{@add@contents}{ m +m }
      {
      listcontents_add_contents:nn { #1 } { #2 }
      }

      % usecontents[index]{listname}
      DeclareExpandableDocumentCommand{usecontents}{ O{1} m }
      {
      listcontents_use_contents:nn { #1 } { #2 }
      }

      cs_new_protected:Npn listcontents_add_contents:nn #1 #2
      {
      seq_if_exist:cF { l_listcontents_contents_#1_seq }
      { seq_new:c { l_listcontents_contents_#1_seq } }
      __listcontents_add_contents:nn { #1 } { #2 }
      }

      cs_new_protected:Npn __listcontents_add_contents:nn #1 #2
      {
      tl_map_inline:nn { #2 }
      {
      seq_gput_right:cn { l_listcontents_contents_#1_seq } { ##1 }
      }
      }

      cs_new:Npn listcontents_use_contents:nn #1 #2
      {
      seq_item:cn { l_listcontents_contents_#2_seq } { #1 }
      }

      % tl vars and bool
      tl_new:N l_add@tmpa@contents_tl
      tl_new:N l_add@file@@contents_tl
      bool_new:N l_write_file_bool
      bool_new:N l_add_macro_bool
      bool_set_true:N l_add_macro_bool

      % [key=val] implementation
      keys_define:nn { listcontents }
      {
      save-cmd .tl_set:N = l_listcontents_cmd_save_tl,
      save-cmd .initial:n = contents,
      save-env .tl_set:N = l_listcontents_env_save_tl,
      save-env .initial:n = contents,
      show-cmd .bool_set:N = l_listcontents_cmd_show_tl,
      show-cmd .initial:n = false,
      show-cmd .value_required:n = true,
      show-env .bool_set:N = l_listcontents_env_show_tl,
      show-env .initial:n = false,
      show-env .value_required:n = true,
      name-tmp .tl_set:N = l_tmp_name_output_tl,
      file-out .code:n = {
      bool_set_true:N l_write_file_bool
      keys_set:nn { listcontents }
      {
      name-tmp = { #1 }
      }
      } ,
      file-out .value_required:n = true,
      file-use .code:n = {
      bool_set_false:N l_add_macro_bool
      bool_set_true:N l_write_file_bool
      keys_set:nn { listcontents }
      {
      name-tmp = { #1 } ,
      }
      } ,
      file-out .value_required:n = true,
      show-all .meta:n = { show-env = true , show-cmd = true },
      }

      keys_define:nn { listcontents / scontents }
      {
      show-cmd .code:n = { keys_set:nn { listcontents } { show-cmd = { #1 } } } ,
      save-cmd .code:n = { keys_set:nn { listcontents } { save-cmd = { #1 } } } ,
      }

      NewDocumentCommand{Setlistcontents}{ +m }
      {
      keys_set:nn { listcontents } { #1 }
      }

      % scontents[...]{...} NO verbatim and par support
      NewDocumentCommand{scontents}{ O{} m }
      {
      group_begin:
      IfNoValueF { #1 } { keys_set:nn { listcontents / scontents } { #1 } }
      @add@contents{ l_listcontents_cmd_save_tl }{ { #2 } } % pass direct to list
      IfBooleanT { l_listcontents_cmd_show_tl } { usecontents[-1]{ l_listcontents_cmd_save_tl} }
      group_end:
      }

      % begin{listcontents}[key val in one line] verbatim env suport in macro
      NewDocumentEnvironment{ listcontents }{}
      {
      char_set_catcode_active:N ^^M
      listcontents_start_listcontents:w
      }
      {
      IfBooleanTF{ l_write_file_bool } { endfilecontentsdef } { endfilecontentsdefmacro }
      group_end:
      IfBooleanTF{ l_add_macro_bool }
      {
      tl_put_right:Nx l_tmpb_tl {
      tex_newlinechar:D = 13 tex_everyeof:D = {noexpand}
      exp_not:N scantokens exp_after:wN { l_tmpa_tl }
      tex_newlinechar:D = 10relax
      }
      tl_put_right:Nx l_add@tmpa@contents_tl {
      exp_not:N @add@contents { exp_not:V l_listcontents_env_save_tl } { {exp_not:V l_tmpb_tl } }
      }
      l_add@tmpa@contents_tl
      }
      {
      tl_put_right:Nx l_add@file@@contents_tl {
      exp_not:N @add@contents { exp_not:V l_listcontents_env_save_tl } { { exp_not:N input { exp_not:V l_tmp_name_output_tl } } }
      }
      l_add@file@@contents_tl
      }
      IfBooleanT{ l_listcontents_env_show_tl } { usecontents[-1]{ l_listcontents_env_save_tl} }
      }

      cs_new_protected:Npn listcontents_listcontents_set:w [#1]
      {
      keys_set:nn { listcontents } { #1 }
      }

      group_begin:
      char_set_catcode_active:N ^^M
      cs_new_protected:Npn listcontents_start_listcontents:w #1 ^^M
      {
      tl_if_blank:nF { #1 } { listcontents_listcontents_set:w #1 }
      group_begin:
      IfBooleanTF{ l_write_file_bool }
      { use:c { filecontentsdef* } { l_tmp_name_output_tl } { l_tmpa_tl } ^^M }
      { use:c { filecontentsdefmacro } { l_tmpa_tl } ^^M }
      }
      group_end:
      ExplSyntaxOff
      makeatother
      % only for example
      usepackage[margin=0.5in,noheadfoot,papersize={8.5in,11in}]{geometry}
      usepackage{pgffor}
      setlength{parindent}{0pt}
      pagestyle{empty}
      begin{document}
      section{Test begin{listcontents}[key=val]}
      Test verb+begin{listcontents}+ no verb+[key=val]+par

      begin{listcontents}
      Using verb+listcontents+ env no verb+[key=val]+, save in list verb+contents+ with index 1.par
      We have coded this in LaTeX: $E=mc^2$.par
      begin{verbatim}
      (A) verbatim environment
      end{verbatim}
      end{listcontents}

      Test verb+begin{listcontents}[file-out=jobname.tsc]+par

      begin{listcontents}[file-out=jobname.tsc]
      Using verb+listcontents+ env with verb+[file-out=jobname.tsc]+, save in list verb+contents+ with index 2.
      We have coded this in LaTeX: $E=mc^2$.par
      begin{verbatim*}
      (B) verbatim environment
      end{verbatim*}
      end{listcontents}

      Test verb+begin{listcontents}[file-use=jobname.tsc]+par

      begin{listcontents}[file-use=jobname-1.tsc]
      Using verb+listcontents+ env with verb+[file-use=jobname-1.tsc]+, pass verb+input{jobname-1.tsc}+
      to list verb+contents+ with index 3. We have coded this in LaTeX: $E=mc^2$.par
      begin{verbatim}
      (C) verbatim environment
      end{verbatim}
      end{listcontents}

      Test verb+begin{listcontents}[show-env=true]+par

      begin{listcontents}[show-env=true]
      Using verb+listcontents+ env with verb+[show-env=true]+, save in list verb+contents+ with index 4.
      We have coded this in LaTeX: $E=mc^2$.par
      begin{verbatim*}
      (D) verbatim environment
      end{verbatim*}
      end{listcontents}

      Test verb+scontents{...}+par
      scontents{Using texttt{scontents} command (no verbatim and par suport), save in list texttt{contents} with index 5}

      section{Execution in reverse}
      The total verb+contents saved+ (environment and command) saved in verb+contents+ list are elementin{contents}.par

      usecontents[5]{contents}par
      usecontents{contents}

      section{Using a loop (pgffor)}

      foreach i in {1,...,elementin{contents}} {usecontents[i]{contents}}

      section{A simple aplication}

      newcounter{exeNr}
      newenvironment{exercise}
      {refstepcounter{exeNr}parnoindent This is exercise~theexeNr}
      {par}
      subsection{Exercises}
      begin{exercise}
      end{exercise}
      begin{listcontents}[save-env=myansewer]
      This is the answer to exercise 1, the shebang line for a Perl script

      begin{verbatim}
      #!/usr/bin/env perl
      end{verbatim}
      end{listcontents}

      begin{exercise}
      end{exercise}
      begin{listcontents}[save-env=myansewer]
      This is the answer to exercise 2
      end{listcontents}

      begin{exercise}
      end{exercise}
      scontents[save-cmd=myansewer]{This is the answer to exercise 3}

      subsection{Answers}
      newcounter{ansNr}
      newenvironment{answer}
      {refstepcounter{ansNr}parnoindent Answer~theansNr:}
      {par}

      foreach i in {1,...,elementin{myansewer}} {
      begin{answer}
      usecontents[i]{myansewer}
      end{answer}
      }
      end{document}


      An image of what the output is like:
      output example
      Comments are welcome



      regards









      share














      I have a query with the maximum number of items that can be saved in an expl3 list. Thanks to the response that @egreg gave me in Avoid passing an empty [optional argument] an environment (with verbatim content) using xparse? I was able to finish the implementation of an environment capable of saving valid LaTeX code (including verbatim) in expl3lists ... something like a "fake ConTextbuffers".



      Let me explain a bit, I have many question/answer files in which I have abused the use of filecontents to record temporary files and included them in environment based on environ (which did not support verbatim) and then use them in different parts of the documents.



      With the new version of filecontentsdef it is not necessary to write the external files (included verbatim) to have them in a macro, thus the things and gathering ideas I have managed to create a listcontents environment which encapsulates filecontentsdefmacro, what run and save in a list, which I can access with usecontents[index]{list name}, the environment works perfectly.



      My question is this, as the environment saves the content in one (or more lists), at some point the list will have a limit. What is the limit on the number of items I can save?



      I have tested some files, but, I convert all my old files using a script to pass them to the new listcontents environment.



      I leave here the example code (for sure it is not written in the perfect way, but it works)



      documentclass{article}
      usepackage{xparse}
      usepackage{filecontentsdef}[2019/04/20] % last version 1.4 (ctan)
      makeatletter
      ExplSyntaxOn
      % elementin{listname}
      cs_new:Npn elementin #1
      {
      seq_count:c { l_listcontents_contents_#1_seq }
      }

      % clearlist{listname}
      cs_new:Npn clearlist #1
      {
      seq_clear_new:c { l_listcontents_contents_#1_seq }
      }

      % @add@contents{listname}{{#1}}
      NewDocumentCommand{@add@contents}{ m +m }
      {
      listcontents_add_contents:nn { #1 } { #2 }
      }

      % usecontents[index]{listname}
      DeclareExpandableDocumentCommand{usecontents}{ O{1} m }
      {
      listcontents_use_contents:nn { #1 } { #2 }
      }

      cs_new_protected:Npn listcontents_add_contents:nn #1 #2
      {
      seq_if_exist:cF { l_listcontents_contents_#1_seq }
      { seq_new:c { l_listcontents_contents_#1_seq } }
      __listcontents_add_contents:nn { #1 } { #2 }
      }

      cs_new_protected:Npn __listcontents_add_contents:nn #1 #2
      {
      tl_map_inline:nn { #2 }
      {
      seq_gput_right:cn { l_listcontents_contents_#1_seq } { ##1 }
      }
      }

      cs_new:Npn listcontents_use_contents:nn #1 #2
      {
      seq_item:cn { l_listcontents_contents_#2_seq } { #1 }
      }

      % tl vars and bool
      tl_new:N l_add@tmpa@contents_tl
      tl_new:N l_add@file@@contents_tl
      bool_new:N l_write_file_bool
      bool_new:N l_add_macro_bool
      bool_set_true:N l_add_macro_bool

      % [key=val] implementation
      keys_define:nn { listcontents }
      {
      save-cmd .tl_set:N = l_listcontents_cmd_save_tl,
      save-cmd .initial:n = contents,
      save-env .tl_set:N = l_listcontents_env_save_tl,
      save-env .initial:n = contents,
      show-cmd .bool_set:N = l_listcontents_cmd_show_tl,
      show-cmd .initial:n = false,
      show-cmd .value_required:n = true,
      show-env .bool_set:N = l_listcontents_env_show_tl,
      show-env .initial:n = false,
      show-env .value_required:n = true,
      name-tmp .tl_set:N = l_tmp_name_output_tl,
      file-out .code:n = {
      bool_set_true:N l_write_file_bool
      keys_set:nn { listcontents }
      {
      name-tmp = { #1 }
      }
      } ,
      file-out .value_required:n = true,
      file-use .code:n = {
      bool_set_false:N l_add_macro_bool
      bool_set_true:N l_write_file_bool
      keys_set:nn { listcontents }
      {
      name-tmp = { #1 } ,
      }
      } ,
      file-out .value_required:n = true,
      show-all .meta:n = { show-env = true , show-cmd = true },
      }

      keys_define:nn { listcontents / scontents }
      {
      show-cmd .code:n = { keys_set:nn { listcontents } { show-cmd = { #1 } } } ,
      save-cmd .code:n = { keys_set:nn { listcontents } { save-cmd = { #1 } } } ,
      }

      NewDocumentCommand{Setlistcontents}{ +m }
      {
      keys_set:nn { listcontents } { #1 }
      }

      % scontents[...]{...} NO verbatim and par support
      NewDocumentCommand{scontents}{ O{} m }
      {
      group_begin:
      IfNoValueF { #1 } { keys_set:nn { listcontents / scontents } { #1 } }
      @add@contents{ l_listcontents_cmd_save_tl }{ { #2 } } % pass direct to list
      IfBooleanT { l_listcontents_cmd_show_tl } { usecontents[-1]{ l_listcontents_cmd_save_tl} }
      group_end:
      }

      % begin{listcontents}[key val in one line] verbatim env suport in macro
      NewDocumentEnvironment{ listcontents }{}
      {
      char_set_catcode_active:N ^^M
      listcontents_start_listcontents:w
      }
      {
      IfBooleanTF{ l_write_file_bool } { endfilecontentsdef } { endfilecontentsdefmacro }
      group_end:
      IfBooleanTF{ l_add_macro_bool }
      {
      tl_put_right:Nx l_tmpb_tl {
      tex_newlinechar:D = 13 tex_everyeof:D = {noexpand}
      exp_not:N scantokens exp_after:wN { l_tmpa_tl }
      tex_newlinechar:D = 10relax
      }
      tl_put_right:Nx l_add@tmpa@contents_tl {
      exp_not:N @add@contents { exp_not:V l_listcontents_env_save_tl } { {exp_not:V l_tmpb_tl } }
      }
      l_add@tmpa@contents_tl
      }
      {
      tl_put_right:Nx l_add@file@@contents_tl {
      exp_not:N @add@contents { exp_not:V l_listcontents_env_save_tl } { { exp_not:N input { exp_not:V l_tmp_name_output_tl } } }
      }
      l_add@file@@contents_tl
      }
      IfBooleanT{ l_listcontents_env_show_tl } { usecontents[-1]{ l_listcontents_env_save_tl} }
      }

      cs_new_protected:Npn listcontents_listcontents_set:w [#1]
      {
      keys_set:nn { listcontents } { #1 }
      }

      group_begin:
      char_set_catcode_active:N ^^M
      cs_new_protected:Npn listcontents_start_listcontents:w #1 ^^M
      {
      tl_if_blank:nF { #1 } { listcontents_listcontents_set:w #1 }
      group_begin:
      IfBooleanTF{ l_write_file_bool }
      { use:c { filecontentsdef* } { l_tmp_name_output_tl } { l_tmpa_tl } ^^M }
      { use:c { filecontentsdefmacro } { l_tmpa_tl } ^^M }
      }
      group_end:
      ExplSyntaxOff
      makeatother
      % only for example
      usepackage[margin=0.5in,noheadfoot,papersize={8.5in,11in}]{geometry}
      usepackage{pgffor}
      setlength{parindent}{0pt}
      pagestyle{empty}
      begin{document}
      section{Test begin{listcontents}[key=val]}
      Test verb+begin{listcontents}+ no verb+[key=val]+par

      begin{listcontents}
      Using verb+listcontents+ env no verb+[key=val]+, save in list verb+contents+ with index 1.par
      We have coded this in LaTeX: $E=mc^2$.par
      begin{verbatim}
      (A) verbatim environment
      end{verbatim}
      end{listcontents}

      Test verb+begin{listcontents}[file-out=jobname.tsc]+par

      begin{listcontents}[file-out=jobname.tsc]
      Using verb+listcontents+ env with verb+[file-out=jobname.tsc]+, save in list verb+contents+ with index 2.
      We have coded this in LaTeX: $E=mc^2$.par
      begin{verbatim*}
      (B) verbatim environment
      end{verbatim*}
      end{listcontents}

      Test verb+begin{listcontents}[file-use=jobname.tsc]+par

      begin{listcontents}[file-use=jobname-1.tsc]
      Using verb+listcontents+ env with verb+[file-use=jobname-1.tsc]+, pass verb+input{jobname-1.tsc}+
      to list verb+contents+ with index 3. We have coded this in LaTeX: $E=mc^2$.par
      begin{verbatim}
      (C) verbatim environment
      end{verbatim}
      end{listcontents}

      Test verb+begin{listcontents}[show-env=true]+par

      begin{listcontents}[show-env=true]
      Using verb+listcontents+ env with verb+[show-env=true]+, save in list verb+contents+ with index 4.
      We have coded this in LaTeX: $E=mc^2$.par
      begin{verbatim*}
      (D) verbatim environment
      end{verbatim*}
      end{listcontents}

      Test verb+scontents{...}+par
      scontents{Using texttt{scontents} command (no verbatim and par suport), save in list texttt{contents} with index 5}

      section{Execution in reverse}
      The total verb+contents saved+ (environment and command) saved in verb+contents+ list are elementin{contents}.par

      usecontents[5]{contents}par
      usecontents{contents}

      section{Using a loop (pgffor)}

      foreach i in {1,...,elementin{contents}} {usecontents[i]{contents}}

      section{A simple aplication}

      newcounter{exeNr}
      newenvironment{exercise}
      {refstepcounter{exeNr}parnoindent This is exercise~theexeNr}
      {par}
      subsection{Exercises}
      begin{exercise}
      end{exercise}
      begin{listcontents}[save-env=myansewer]
      This is the answer to exercise 1, the shebang line for a Perl script

      begin{verbatim}
      #!/usr/bin/env perl
      end{verbatim}
      end{listcontents}

      begin{exercise}
      end{exercise}
      begin{listcontents}[save-env=myansewer]
      This is the answer to exercise 2
      end{listcontents}

      begin{exercise}
      end{exercise}
      scontents[save-cmd=myansewer]{This is the answer to exercise 3}

      subsection{Answers}
      newcounter{ansNr}
      newenvironment{answer}
      {refstepcounter{ansNr}parnoindent Answer~theansNr:}
      {par}

      foreach i in {1,...,elementin{myansewer}} {
      begin{answer}
      usecontents[i]{myansewer}
      end{answer}
      }
      end{document}


      An image of what the output is like:
      output example
      Comments are welcome



      regards







      tex-core expl3 latex3





      share












      share










      share



      share










      asked 3 mins ago









      Pablo González LPablo González L

      1,0511921




      1,0511921






















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "85"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f487828%2fwhat-is-the-maximum-limit-of-elements-in-a-list-expl3-xparse%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f487828%2fwhat-is-the-maximum-limit-of-elements-in-a-list-expl3-xparse%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          IEEEtran - How to include ORCID in TeX/PDF with PdfLatexIs there a standard way to include ORCID in TeX /...

          Cicindela nigrior Przypisy | Menu nawigacyjneCicindela varians unicolorManual for the Identification of the...

          Glossaries-extra: Adding glossaries package to “Clas­sicTh­e­sis” template by Dr. André Miede v. 4.6 ...