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

Extension of 2-adic valuation to the real numbers

Can an Area of Effect spell cast outside a Prismatic Wall extend inside it?

Which big number is bigger?

Does a large simulator bay have standard public address announcements?

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

Was there a Viking Exchange as well as a Columbian one?

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

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

How to stop co-workers from teasing me because I know Russian?

What is the smallest unit of eos?

Why does nature favour the Laplacian?

Retract an already submitted recommendation letter (written for an undergrad student)

How to denote matrix elements succinctly?

Elements that can bond to themselves?

Can SQL Server create collisions in system generated constraint names?

A ​Note ​on ​N!

Discriminated by senior researcher because of my ethnicity

How can I print the prosodic symbols in LaTeX?

Why was the Spitfire's elliptical wing almost uncopied by other aircraft of World War 2?

How to limit Drive Letters Windows assigns to new removable USB drives

Can we say “you can pay when the order gets ready”?

Implications of cigar-shaped bodies having rings?

How to not starve gigantic beasts

Map of water taps to fill bottles



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?How do I register the prefix of my expl3 package?How to output sequence elements and total in expl3Writing a token list conditional with expl3expl3 empty token listImplementation of property list in expl3Using property list from expl3What is the relation of expl3 to xparse?expl3: what is group_insert_after:N for?expl3 read a comma list from fileHow to expand a macro (or a copy) to save in a list at end of environment in xparse (expl3)?













2















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|improve this question


















  • 2





    I didn't read you whole code so I don't know precisely what it does. But an expl3 seq variable is a macro deep down, so if you are inserting contents in a seq variable you are basically doing a very large def. In this case, your limit will probably be the words of memory memory, where in the (my) log there is XX words of memory out of 5000000. But the amount of items in a seq variable is probably unlimited. The amount you can actually store will depend on the “size” of each element.

    – Phelype Oleinik
    1 hour ago






  • 2





    The coding is quite bizarre. Please, avoid @ as much as possible and also scantokens: you should be aware of tl_rescan:nn. The maximum limit of items in a list/sequence is “what can be stored in memory”.

    – egreg
    1 hour ago













  • @egreg The @ is an old habit..Try to use tl_rescan: nn instead of scantokens, but, it did not work for me (verbatim code disappear), and I did not find any examples in the forum that I could adapt....has ... the code of the lists take it from one of your answers and adapt it :)

    – Pablo González L
    1 hour ago


















2















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|improve this question


















  • 2





    I didn't read you whole code so I don't know precisely what it does. But an expl3 seq variable is a macro deep down, so if you are inserting contents in a seq variable you are basically doing a very large def. In this case, your limit will probably be the words of memory memory, where in the (my) log there is XX words of memory out of 5000000. But the amount of items in a seq variable is probably unlimited. The amount you can actually store will depend on the “size” of each element.

    – Phelype Oleinik
    1 hour ago






  • 2





    The coding is quite bizarre. Please, avoid @ as much as possible and also scantokens: you should be aware of tl_rescan:nn. The maximum limit of items in a list/sequence is “what can be stored in memory”.

    – egreg
    1 hour ago













  • @egreg The @ is an old habit..Try to use tl_rescan: nn instead of scantokens, but, it did not work for me (verbatim code disappear), and I did not find any examples in the forum that I could adapt....has ... the code of the lists take it from one of your answers and adapt it :)

    – Pablo González L
    1 hour ago
















2












2








2


1






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|improve this question














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|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 hours ago









Pablo González LPablo González L

1,0631921




1,0631921








  • 2





    I didn't read you whole code so I don't know precisely what it does. But an expl3 seq variable is a macro deep down, so if you are inserting contents in a seq variable you are basically doing a very large def. In this case, your limit will probably be the words of memory memory, where in the (my) log there is XX words of memory out of 5000000. But the amount of items in a seq variable is probably unlimited. The amount you can actually store will depend on the “size” of each element.

    – Phelype Oleinik
    1 hour ago






  • 2





    The coding is quite bizarre. Please, avoid @ as much as possible and also scantokens: you should be aware of tl_rescan:nn. The maximum limit of items in a list/sequence is “what can be stored in memory”.

    – egreg
    1 hour ago













  • @egreg The @ is an old habit..Try to use tl_rescan: nn instead of scantokens, but, it did not work for me (verbatim code disappear), and I did not find any examples in the forum that I could adapt....has ... the code of the lists take it from one of your answers and adapt it :)

    – Pablo González L
    1 hour ago
















  • 2





    I didn't read you whole code so I don't know precisely what it does. But an expl3 seq variable is a macro deep down, so if you are inserting contents in a seq variable you are basically doing a very large def. In this case, your limit will probably be the words of memory memory, where in the (my) log there is XX words of memory out of 5000000. But the amount of items in a seq variable is probably unlimited. The amount you can actually store will depend on the “size” of each element.

    – Phelype Oleinik
    1 hour ago






  • 2





    The coding is quite bizarre. Please, avoid @ as much as possible and also scantokens: you should be aware of tl_rescan:nn. The maximum limit of items in a list/sequence is “what can be stored in memory”.

    – egreg
    1 hour ago













  • @egreg The @ is an old habit..Try to use tl_rescan: nn instead of scantokens, but, it did not work for me (verbatim code disappear), and I did not find any examples in the forum that I could adapt....has ... the code of the lists take it from one of your answers and adapt it :)

    – Pablo González L
    1 hour ago










2




2





I didn't read you whole code so I don't know precisely what it does. But an expl3 seq variable is a macro deep down, so if you are inserting contents in a seq variable you are basically doing a very large def. In this case, your limit will probably be the words of memory memory, where in the (my) log there is XX words of memory out of 5000000. But the amount of items in a seq variable is probably unlimited. The amount you can actually store will depend on the “size” of each element.

– Phelype Oleinik
1 hour ago





I didn't read you whole code so I don't know precisely what it does. But an expl3 seq variable is a macro deep down, so if you are inserting contents in a seq variable you are basically doing a very large def. In this case, your limit will probably be the words of memory memory, where in the (my) log there is XX words of memory out of 5000000. But the amount of items in a seq variable is probably unlimited. The amount you can actually store will depend on the “size” of each element.

– Phelype Oleinik
1 hour ago




2




2





The coding is quite bizarre. Please, avoid @ as much as possible and also scantokens: you should be aware of tl_rescan:nn. The maximum limit of items in a list/sequence is “what can be stored in memory”.

– egreg
1 hour ago







The coding is quite bizarre. Please, avoid @ as much as possible and also scantokens: you should be aware of tl_rescan:nn. The maximum limit of items in a list/sequence is “what can be stored in memory”.

– egreg
1 hour ago















@egreg The @ is an old habit..Try to use tl_rescan: nn instead of scantokens, but, it did not work for me (verbatim code disappear), and I did not find any examples in the forum that I could adapt....has ... the code of the lists take it from one of your answers and adapt it :)

– Pablo González L
1 hour ago







@egreg The @ is an old habit..Try to use tl_rescan: nn instead of scantokens, but, it did not work for me (verbatim code disappear), and I did not find any examples in the forum that I could adapt....has ... the code of the lists take it from one of your answers and adapt it :)

– Pablo González L
1 hour ago












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

Why does my Macbook overheat and use so much CPU and energy when on YouTube?Why do so many insist on using...

How to prevent page numbers from appearing on glossaries?How to remove a dot and a page number in the...

Puerta de Hutt Referencias Enlaces externos Menú de navegación15°58′00″S 5°42′00″O /...