How to expand a macro (or a copy) to save in a list at end of environment in xparse (expl3)?How can I create an oddly-delimited macro, using xparse?How do I pass an expanded optional argument using expl3/xparse?Expand macro into xparse SplitList macroWhen defining a new macro inside a new macro (in xparse) how do I make the internal map long?How to expand control sequence in argument of a macroHow to expand macro in a macro callXparse k argument to parse options at end of environmentHow to embed a command in an environment using Expl3?How can expand a counter of auxiliary file and save in list with xparse?How to use exp_not:N and exp_after:wN to prevent the expansion of input in a expl3 list?
Can the Produce Flame cantrip be used to grapple, or as an unarmed strike, in the right circumstances?
Copycat chess is back
Is this food a bread or a loaf?
How to make payment on the internet without leaving a money trail?
How is it possible for user's password to be changed after storage was encrypted? (on OS X, Android)
Was there ever an axiom rendered a theorem?
What do you call something that goes against the spirit of the law, but is legal when interpreting the law to the letter?
"My colleague's body is amazing"
Re-submission of rejected manuscript without informing co-authors
Are objects structures and/or vice versa?
Hosting Wordpress in a EC2 Load Balanced Instance
How can I add custom success page
Prime joint compound before latex paint?
Unbreakable Formation vs. Cry of the Carnarium
Is domain driven design an anti-SQL pattern?
Can a planet have a different gravitational pull depending on its location in orbit around its sun?
I see my dog run
Where else does the Shulchan Aruch quote an authority by name?
What is the meaning of "of trouble" in the following sentence?
aging parents with no investments
Could a US political party gain complete control over the government by removing checks & balances?
Is there a way to make member function NOT callable from constructor?
Does the average primeness of natural numbers tend to zero?
How would photo IDs work for shapeshifters?
How to expand a macro (or a copy) to save in a list at end of environment in xparse (expl3)?
How can I create an oddly-delimited macro, using xparse?How do I pass an expanded optional argument using expl3/xparse?Expand macro into xparse SplitList macroWhen defining a new macro inside a new macro (in xparse) how do I make the internal map long?How to expand control sequence in argument of a macroHow to expand macro in a macro callXparse k argument to parse options at end of environmentHow to embed a command in an environment using Expl3?How can expand a counter of auxiliary file and save in list with xparse?How to use exp_not:N and exp_after:wN to prevent the expansion of input in a expl3 list?
I am trying to encapsulate a couple of environments to pass them to lists using xparse/expl3
.
I have defined a one command and two environments and I have had a problem with one of them.
I use the environments to save notes type question/answer where the answers are stored in a list to show them at the end of the file or elsewhere in it, the issue is that sometimes need to use verbatim.
The scontent
environment uses the +b
argument of xparse
and only Verb[...]...
(from fvextra
) can be used (you can not use the verbatim environment for example).
The scontent*
environment is based on filecontentsdef
and can use verb|...|
in a line or beginverbatim
environment, this generates an external file but has the facility of saving the content in a macro
.
When executing beginscontent*
pass the following:
- Save the current content in
macro
- Copy the current contents of
macro
inl_my_macro_copy_tl
- Pass the contents of
l_my_macro_copy_tl
to list usingexpanddafterenvtolistexpanddafter content save in l_my_macro_copy_tl
- If this is the key
[show-env = true]
runusecontent[-1]l_scontent_env_save_tl
The problem is in the execution of
expanddafterenvtolistexpanddafterl_my_macro_copy_tl
at end of environment scontent*
, I tried with the following (ugly and incorrect) lines:
% beginscontent*[...] verbatim env save in macro
% Copy a current content of macro in l_my_macro_copy_tl and pass to list
tl_new:N l_my_macro_copy_tl
NewDocumentEnvironmentscontent* !O
group_begin:
filecontentsdefjobname.tscmacro % save in macro
endfilecontentsdef %
group_end:
IfNoValueF #1 keys_set:nn scontent #1
tl_set:Nx l_my_macro_copy_tl macro
exp_after:wN envtolist exp_after:wN exp_not:N tex_newlinechar:D = 13 exp_not:N scantokens exp_after:wN l_my_macro_copy_tl %
IfBooleanT l_scontent_env_show_tl usecontent[-1] l_scontent_env_save_tl
with this I eliminate the errors when compiling, but, the content is not saved in the list...How can i fix this?
My idea is not to occupy directly showme...
and only use usecontent[index]list name
in document.
I know that the command showme...
and usecontent[index]list name
works if you execute it out of the environment, but my idea is automate this when run scontent*
.
This is my example file (MWE), the comments should be removed to see the error that occurs.
documentclassarticle
usepackagefilecontentsdef,etoolbox,xparse,fvextra,xcolor
usepackage[margin=0.6in,noheadfoot,papersize=8.5in,13in]geometry
setlengthparindent0pt
pagestyleempty
ExplSyntaxOn
% show content save in macro
tl_new:N l_temp_argument_tl
NewDocumentCommandshowme +m %
tl_set:Nx l_temp_argument_tl #1
tex_newlinechar:D = 13
exp_not:N scantokens exp_after:wN l_temp_argument_tl
% elementinlistname and clearlistlistname
cs_new:Npn elementin #1 seq_count:c l_savecontent_content_#1_seq
cs_new:Npn clearlist #1 seq_clear_new:c l_savecontent_content_#1_seq
% addcontentlistname#1 ...need double ...
NewDocumentCommandaddcontent m +m savecontent_add_content:nn #1 #2
% usecontent[index]listname
DeclareExpandableDocumentCommandusecontentO1m savecontent_use_content:nn #1 #2
cs_new_protected:Npn savecontent_add_content:nn #1 #2
seq_if_exist:cF l_savecontent_content_#1_seq
seq_new:c l_savecontent_content_#1_seq
__savecontent_add_content:nn #1 #2
cs_new_protected:Npn __savecontent_add_content:nn #1 #2
tl_map_inline:nn #2
seq_gput_right:cn l_savecontent_content_#1_seq ##1
cs_new:Npn savecontent_use_content:nn #1 #2 seq_item:cn l_savecontent_content_#2_seq #1
keys_define:nn scontent
save-cmd .tl_set:N = l_scontent_cmd_save_tl, save-cmd .initial:n = content,%
save-env .tl_set:N = l_scontent_env_save_tl, save-env .initial:n = content, %
show-cmd .bool_set:N = l_scontent_cmd_show_tl, show-cmd .initial:n = false, show-cmd .value_required:n = true,%
show-env .bool_set:N = l_scontent_env_show_tl, show-env .initial:n = false, show-env .value_required:n = true,%
show-all .meta:n = show-env = true , show-cmd = true ,%
NewDocumentCommandSetscontent +m keys_set:nn scontent #1
% pass to list
newrobustcmdenvtolist[1]addcontent l_scontent_env_save_tl #1
% Scontent[...]... NO verbatim env support, but Verb[...]... yes
NewDocumentCommandScontent O +m
group_begin:
IfNoValueF#1 keys_set:nn scontent #1
addcontent l_scontent_cmd_save_tl #2 % pass direct to list
IfBooleanT l_scontent_cmd_show_tl usecontent[-1] l_scontent_cmd_save_tl
group_end:
% beginscontent[...] NO verbatim env suport, but Verb[...]... yes
NewDocumentEnvironmentscontent !o +b
group_begin:
IfNoValueF #1 keys_set:nn scontent #1
expandafterenvtolistexpandafter#2
IfBooleanT l_scontent_env_show_tl usecontent[-1] l_scontent_env_save_tl
group_end:
% beginscontent*[...] verbatim env save in macro
tl_new:N l_my_macro_copy_tl % tl_var to copy macro at definition time
NewDocumentEnvironmentscontent* !O
group_begin:
IfNoValueF #1 keys_set:nn scontent #1
filecontentsdefjobname.tscmacro
endfilecontentsdef %
group_end:
% Copy macro every time in tl_var (at definition time) and pass to list
%cs_set_eq:NN l_my_macro_copy_tl macro
%expandafterenvtolistexpandaftershowmel_my_macro_copy_tl
%IfBooleanT l_scontent_env_show_tl usecontent[-1] l_scontent_env_save_tl
ExplSyntaxOff
% set name of lists
Setscontent save-env=test-env, save-cmd=test-cmd
begindocument
sectionUsing textttscontent environment whit new texttt+b argument from textttxparse
subsectionWhit texttt[show-env=false]
Text save in verb|beginscontent[show-env=false]| (hidden)
beginscontent[show-env=false]
Some first text whit verbatim inline saved in Verbusecontent[1]test-env par
We have coded this in LaTeX: both $E=mc^2$.
endscontent
OK
subsectionWhit texttt[show-env=true]
Text save in verb|beginscontent[show-env=true]| (Not hidden)
beginscontent[show-env=true]
Some second text whit verbatim inline saved in Verbusecontent[2]test-env...more text par
We have coded this in LaTeX: both $E=mc^2$.
endscontent
OK
subsectionUsing Verbusecontent[1]test-env
Now see saved text in list:par
usecontent[2]test-envpar
usecontent[1]test-env
sectionUsing Verb*Scontent[...]...
Text save whit verb|Scontent....| (hidden)par
Scontent
using a Verb*Scontent[...]... textcolorredwhit verbatim Verb*Verb[...]...par
(by Verb*fvextra) textcolormagentainline
par
And see saved text in list using verb|usecontent[1]test-cmd| par
usecontent[1]test-cmdpar
OK
sectionUsing textttscontent* environment wraped textttfilecontentsdef using textttxparse
subsectionWhit texttt[show-env=false]
Some Text save using verb|beginscontent*[show-env=false]| save in verb|macro| (hidden)
beginscontent*[show-env=false]
Some text in whit verbatim environment ¿saved in list ...verb+usecontent[3]test-env+?(not get for now).par
beginVerbatim
This is from the verbatim environment: &%_"`´~
xxxxx
endVerbatim
endscontent*par
OK...it's posible to see verb|macro| whit verb|showmemacro|:par
showmemacropar
or pass to list using verb|Scontentshowmemacro| and see in list whit verb+usecontent[2]test-cmd+:par
Scontentshowmemacro
usecontent[2]test-cmd
subsectionThe idea whit texttt[show-env=true]
Setscontent save-cmd=test-other
XXXXXXXXXpar
beginscontent*[show-env=false]
Some text in whit verbatim A
beginVerbatim
verbatim environment A: &%_"`´~
endVerbatim
endscontent*
Scontent[show-cmd=true]showmemacropar
XXXXXXXXXpar
beginscontent*[show-env=false]
Some text in whit verbatim B
beginVerbatim
verbatim environment B: &%_"`´~
endVerbatim
endscontent*
Scontent[show-cmd=true]showmemacro
XXXXXXXXXpar
And see in reverse order:par
usecontent[2]test-otherpar
usecontent[1]test-otherpar
NOT OK,...
subsectionThe problem whit texttt[show-env=true]
beginscontent*[show-env=true]
Some text in whit verbatim C
beginVerbatim
verbatim environment C: &%_"`´~
endVerbatim
endscontent*
enddocument
An image to complement
regards
macros expansion expl3 xparse
add a comment |
I am trying to encapsulate a couple of environments to pass them to lists using xparse/expl3
.
I have defined a one command and two environments and I have had a problem with one of them.
I use the environments to save notes type question/answer where the answers are stored in a list to show them at the end of the file or elsewhere in it, the issue is that sometimes need to use verbatim.
The scontent
environment uses the +b
argument of xparse
and only Verb[...]...
(from fvextra
) can be used (you can not use the verbatim environment for example).
The scontent*
environment is based on filecontentsdef
and can use verb|...|
in a line or beginverbatim
environment, this generates an external file but has the facility of saving the content in a macro
.
When executing beginscontent*
pass the following:
- Save the current content in
macro
- Copy the current contents of
macro
inl_my_macro_copy_tl
- Pass the contents of
l_my_macro_copy_tl
to list usingexpanddafterenvtolistexpanddafter content save in l_my_macro_copy_tl
- If this is the key
[show-env = true]
runusecontent[-1]l_scontent_env_save_tl
The problem is in the execution of
expanddafterenvtolistexpanddafterl_my_macro_copy_tl
at end of environment scontent*
, I tried with the following (ugly and incorrect) lines:
% beginscontent*[...] verbatim env save in macro
% Copy a current content of macro in l_my_macro_copy_tl and pass to list
tl_new:N l_my_macro_copy_tl
NewDocumentEnvironmentscontent* !O
group_begin:
filecontentsdefjobname.tscmacro % save in macro
endfilecontentsdef %
group_end:
IfNoValueF #1 keys_set:nn scontent #1
tl_set:Nx l_my_macro_copy_tl macro
exp_after:wN envtolist exp_after:wN exp_not:N tex_newlinechar:D = 13 exp_not:N scantokens exp_after:wN l_my_macro_copy_tl %
IfBooleanT l_scontent_env_show_tl usecontent[-1] l_scontent_env_save_tl
with this I eliminate the errors when compiling, but, the content is not saved in the list...How can i fix this?
My idea is not to occupy directly showme...
and only use usecontent[index]list name
in document.
I know that the command showme...
and usecontent[index]list name
works if you execute it out of the environment, but my idea is automate this when run scontent*
.
This is my example file (MWE), the comments should be removed to see the error that occurs.
documentclassarticle
usepackagefilecontentsdef,etoolbox,xparse,fvextra,xcolor
usepackage[margin=0.6in,noheadfoot,papersize=8.5in,13in]geometry
setlengthparindent0pt
pagestyleempty
ExplSyntaxOn
% show content save in macro
tl_new:N l_temp_argument_tl
NewDocumentCommandshowme +m %
tl_set:Nx l_temp_argument_tl #1
tex_newlinechar:D = 13
exp_not:N scantokens exp_after:wN l_temp_argument_tl
% elementinlistname and clearlistlistname
cs_new:Npn elementin #1 seq_count:c l_savecontent_content_#1_seq
cs_new:Npn clearlist #1 seq_clear_new:c l_savecontent_content_#1_seq
% addcontentlistname#1 ...need double ...
NewDocumentCommandaddcontent m +m savecontent_add_content:nn #1 #2
% usecontent[index]listname
DeclareExpandableDocumentCommandusecontentO1m savecontent_use_content:nn #1 #2
cs_new_protected:Npn savecontent_add_content:nn #1 #2
seq_if_exist:cF l_savecontent_content_#1_seq
seq_new:c l_savecontent_content_#1_seq
__savecontent_add_content:nn #1 #2
cs_new_protected:Npn __savecontent_add_content:nn #1 #2
tl_map_inline:nn #2
seq_gput_right:cn l_savecontent_content_#1_seq ##1
cs_new:Npn savecontent_use_content:nn #1 #2 seq_item:cn l_savecontent_content_#2_seq #1
keys_define:nn scontent
save-cmd .tl_set:N = l_scontent_cmd_save_tl, save-cmd .initial:n = content,%
save-env .tl_set:N = l_scontent_env_save_tl, save-env .initial:n = content, %
show-cmd .bool_set:N = l_scontent_cmd_show_tl, show-cmd .initial:n = false, show-cmd .value_required:n = true,%
show-env .bool_set:N = l_scontent_env_show_tl, show-env .initial:n = false, show-env .value_required:n = true,%
show-all .meta:n = show-env = true , show-cmd = true ,%
NewDocumentCommandSetscontent +m keys_set:nn scontent #1
% pass to list
newrobustcmdenvtolist[1]addcontent l_scontent_env_save_tl #1
% Scontent[...]... NO verbatim env support, but Verb[...]... yes
NewDocumentCommandScontent O +m
group_begin:
IfNoValueF#1 keys_set:nn scontent #1
addcontent l_scontent_cmd_save_tl #2 % pass direct to list
IfBooleanT l_scontent_cmd_show_tl usecontent[-1] l_scontent_cmd_save_tl
group_end:
% beginscontent[...] NO verbatim env suport, but Verb[...]... yes
NewDocumentEnvironmentscontent !o +b
group_begin:
IfNoValueF #1 keys_set:nn scontent #1
expandafterenvtolistexpandafter#2
IfBooleanT l_scontent_env_show_tl usecontent[-1] l_scontent_env_save_tl
group_end:
% beginscontent*[...] verbatim env save in macro
tl_new:N l_my_macro_copy_tl % tl_var to copy macro at definition time
NewDocumentEnvironmentscontent* !O
group_begin:
IfNoValueF #1 keys_set:nn scontent #1
filecontentsdefjobname.tscmacro
endfilecontentsdef %
group_end:
% Copy macro every time in tl_var (at definition time) and pass to list
%cs_set_eq:NN l_my_macro_copy_tl macro
%expandafterenvtolistexpandaftershowmel_my_macro_copy_tl
%IfBooleanT l_scontent_env_show_tl usecontent[-1] l_scontent_env_save_tl
ExplSyntaxOff
% set name of lists
Setscontent save-env=test-env, save-cmd=test-cmd
begindocument
sectionUsing textttscontent environment whit new texttt+b argument from textttxparse
subsectionWhit texttt[show-env=false]
Text save in verb|beginscontent[show-env=false]| (hidden)
beginscontent[show-env=false]
Some first text whit verbatim inline saved in Verbusecontent[1]test-env par
We have coded this in LaTeX: both $E=mc^2$.
endscontent
OK
subsectionWhit texttt[show-env=true]
Text save in verb|beginscontent[show-env=true]| (Not hidden)
beginscontent[show-env=true]
Some second text whit verbatim inline saved in Verbusecontent[2]test-env...more text par
We have coded this in LaTeX: both $E=mc^2$.
endscontent
OK
subsectionUsing Verbusecontent[1]test-env
Now see saved text in list:par
usecontent[2]test-envpar
usecontent[1]test-env
sectionUsing Verb*Scontent[...]...
Text save whit verb|Scontent....| (hidden)par
Scontent
using a Verb*Scontent[...]... textcolorredwhit verbatim Verb*Verb[...]...par
(by Verb*fvextra) textcolormagentainline
par
And see saved text in list using verb|usecontent[1]test-cmd| par
usecontent[1]test-cmdpar
OK
sectionUsing textttscontent* environment wraped textttfilecontentsdef using textttxparse
subsectionWhit texttt[show-env=false]
Some Text save using verb|beginscontent*[show-env=false]| save in verb|macro| (hidden)
beginscontent*[show-env=false]
Some text in whit verbatim environment ¿saved in list ...verb+usecontent[3]test-env+?(not get for now).par
beginVerbatim
This is from the verbatim environment: &%_"`´~
xxxxx
endVerbatim
endscontent*par
OK...it's posible to see verb|macro| whit verb|showmemacro|:par
showmemacropar
or pass to list using verb|Scontentshowmemacro| and see in list whit verb+usecontent[2]test-cmd+:par
Scontentshowmemacro
usecontent[2]test-cmd
subsectionThe idea whit texttt[show-env=true]
Setscontent save-cmd=test-other
XXXXXXXXXpar
beginscontent*[show-env=false]
Some text in whit verbatim A
beginVerbatim
verbatim environment A: &%_"`´~
endVerbatim
endscontent*
Scontent[show-cmd=true]showmemacropar
XXXXXXXXXpar
beginscontent*[show-env=false]
Some text in whit verbatim B
beginVerbatim
verbatim environment B: &%_"`´~
endVerbatim
endscontent*
Scontent[show-cmd=true]showmemacro
XXXXXXXXXpar
And see in reverse order:par
usecontent[2]test-otherpar
usecontent[1]test-otherpar
NOT OK,...
subsectionThe problem whit texttt[show-env=true]
beginscontent*[show-env=true]
Some text in whit verbatim C
beginVerbatim
verbatim environment C: &%_"`´~
endVerbatim
endscontent*
enddocument
An image to complement
regards
macros expansion expl3 xparse
1
Could you please state clearly at the beginning what the aim is?
– egreg
2 days ago
@egreg Thanks for the comment, I added the clarification, apologies for the writing, (myenglish base + google translator
sometimes fails). Can you give me a hand with this?
– Pablo González L
2 days ago
add a comment |
I am trying to encapsulate a couple of environments to pass them to lists using xparse/expl3
.
I have defined a one command and two environments and I have had a problem with one of them.
I use the environments to save notes type question/answer where the answers are stored in a list to show them at the end of the file or elsewhere in it, the issue is that sometimes need to use verbatim.
The scontent
environment uses the +b
argument of xparse
and only Verb[...]...
(from fvextra
) can be used (you can not use the verbatim environment for example).
The scontent*
environment is based on filecontentsdef
and can use verb|...|
in a line or beginverbatim
environment, this generates an external file but has the facility of saving the content in a macro
.
When executing beginscontent*
pass the following:
- Save the current content in
macro
- Copy the current contents of
macro
inl_my_macro_copy_tl
- Pass the contents of
l_my_macro_copy_tl
to list usingexpanddafterenvtolistexpanddafter content save in l_my_macro_copy_tl
- If this is the key
[show-env = true]
runusecontent[-1]l_scontent_env_save_tl
The problem is in the execution of
expanddafterenvtolistexpanddafterl_my_macro_copy_tl
at end of environment scontent*
, I tried with the following (ugly and incorrect) lines:
% beginscontent*[...] verbatim env save in macro
% Copy a current content of macro in l_my_macro_copy_tl and pass to list
tl_new:N l_my_macro_copy_tl
NewDocumentEnvironmentscontent* !O
group_begin:
filecontentsdefjobname.tscmacro % save in macro
endfilecontentsdef %
group_end:
IfNoValueF #1 keys_set:nn scontent #1
tl_set:Nx l_my_macro_copy_tl macro
exp_after:wN envtolist exp_after:wN exp_not:N tex_newlinechar:D = 13 exp_not:N scantokens exp_after:wN l_my_macro_copy_tl %
IfBooleanT l_scontent_env_show_tl usecontent[-1] l_scontent_env_save_tl
with this I eliminate the errors when compiling, but, the content is not saved in the list...How can i fix this?
My idea is not to occupy directly showme...
and only use usecontent[index]list name
in document.
I know that the command showme...
and usecontent[index]list name
works if you execute it out of the environment, but my idea is automate this when run scontent*
.
This is my example file (MWE), the comments should be removed to see the error that occurs.
documentclassarticle
usepackagefilecontentsdef,etoolbox,xparse,fvextra,xcolor
usepackage[margin=0.6in,noheadfoot,papersize=8.5in,13in]geometry
setlengthparindent0pt
pagestyleempty
ExplSyntaxOn
% show content save in macro
tl_new:N l_temp_argument_tl
NewDocumentCommandshowme +m %
tl_set:Nx l_temp_argument_tl #1
tex_newlinechar:D = 13
exp_not:N scantokens exp_after:wN l_temp_argument_tl
% elementinlistname and clearlistlistname
cs_new:Npn elementin #1 seq_count:c l_savecontent_content_#1_seq
cs_new:Npn clearlist #1 seq_clear_new:c l_savecontent_content_#1_seq
% addcontentlistname#1 ...need double ...
NewDocumentCommandaddcontent m +m savecontent_add_content:nn #1 #2
% usecontent[index]listname
DeclareExpandableDocumentCommandusecontentO1m savecontent_use_content:nn #1 #2
cs_new_protected:Npn savecontent_add_content:nn #1 #2
seq_if_exist:cF l_savecontent_content_#1_seq
seq_new:c l_savecontent_content_#1_seq
__savecontent_add_content:nn #1 #2
cs_new_protected:Npn __savecontent_add_content:nn #1 #2
tl_map_inline:nn #2
seq_gput_right:cn l_savecontent_content_#1_seq ##1
cs_new:Npn savecontent_use_content:nn #1 #2 seq_item:cn l_savecontent_content_#2_seq #1
keys_define:nn scontent
save-cmd .tl_set:N = l_scontent_cmd_save_tl, save-cmd .initial:n = content,%
save-env .tl_set:N = l_scontent_env_save_tl, save-env .initial:n = content, %
show-cmd .bool_set:N = l_scontent_cmd_show_tl, show-cmd .initial:n = false, show-cmd .value_required:n = true,%
show-env .bool_set:N = l_scontent_env_show_tl, show-env .initial:n = false, show-env .value_required:n = true,%
show-all .meta:n = show-env = true , show-cmd = true ,%
NewDocumentCommandSetscontent +m keys_set:nn scontent #1
% pass to list
newrobustcmdenvtolist[1]addcontent l_scontent_env_save_tl #1
% Scontent[...]... NO verbatim env support, but Verb[...]... yes
NewDocumentCommandScontent O +m
group_begin:
IfNoValueF#1 keys_set:nn scontent #1
addcontent l_scontent_cmd_save_tl #2 % pass direct to list
IfBooleanT l_scontent_cmd_show_tl usecontent[-1] l_scontent_cmd_save_tl
group_end:
% beginscontent[...] NO verbatim env suport, but Verb[...]... yes
NewDocumentEnvironmentscontent !o +b
group_begin:
IfNoValueF #1 keys_set:nn scontent #1
expandafterenvtolistexpandafter#2
IfBooleanT l_scontent_env_show_tl usecontent[-1] l_scontent_env_save_tl
group_end:
% beginscontent*[...] verbatim env save in macro
tl_new:N l_my_macro_copy_tl % tl_var to copy macro at definition time
NewDocumentEnvironmentscontent* !O
group_begin:
IfNoValueF #1 keys_set:nn scontent #1
filecontentsdefjobname.tscmacro
endfilecontentsdef %
group_end:
% Copy macro every time in tl_var (at definition time) and pass to list
%cs_set_eq:NN l_my_macro_copy_tl macro
%expandafterenvtolistexpandaftershowmel_my_macro_copy_tl
%IfBooleanT l_scontent_env_show_tl usecontent[-1] l_scontent_env_save_tl
ExplSyntaxOff
% set name of lists
Setscontent save-env=test-env, save-cmd=test-cmd
begindocument
sectionUsing textttscontent environment whit new texttt+b argument from textttxparse
subsectionWhit texttt[show-env=false]
Text save in verb|beginscontent[show-env=false]| (hidden)
beginscontent[show-env=false]
Some first text whit verbatim inline saved in Verbusecontent[1]test-env par
We have coded this in LaTeX: both $E=mc^2$.
endscontent
OK
subsectionWhit texttt[show-env=true]
Text save in verb|beginscontent[show-env=true]| (Not hidden)
beginscontent[show-env=true]
Some second text whit verbatim inline saved in Verbusecontent[2]test-env...more text par
We have coded this in LaTeX: both $E=mc^2$.
endscontent
OK
subsectionUsing Verbusecontent[1]test-env
Now see saved text in list:par
usecontent[2]test-envpar
usecontent[1]test-env
sectionUsing Verb*Scontent[...]...
Text save whit verb|Scontent....| (hidden)par
Scontent
using a Verb*Scontent[...]... textcolorredwhit verbatim Verb*Verb[...]...par
(by Verb*fvextra) textcolormagentainline
par
And see saved text in list using verb|usecontent[1]test-cmd| par
usecontent[1]test-cmdpar
OK
sectionUsing textttscontent* environment wraped textttfilecontentsdef using textttxparse
subsectionWhit texttt[show-env=false]
Some Text save using verb|beginscontent*[show-env=false]| save in verb|macro| (hidden)
beginscontent*[show-env=false]
Some text in whit verbatim environment ¿saved in list ...verb+usecontent[3]test-env+?(not get for now).par
beginVerbatim
This is from the verbatim environment: &%_"`´~
xxxxx
endVerbatim
endscontent*par
OK...it's posible to see verb|macro| whit verb|showmemacro|:par
showmemacropar
or pass to list using verb|Scontentshowmemacro| and see in list whit verb+usecontent[2]test-cmd+:par
Scontentshowmemacro
usecontent[2]test-cmd
subsectionThe idea whit texttt[show-env=true]
Setscontent save-cmd=test-other
XXXXXXXXXpar
beginscontent*[show-env=false]
Some text in whit verbatim A
beginVerbatim
verbatim environment A: &%_"`´~
endVerbatim
endscontent*
Scontent[show-cmd=true]showmemacropar
XXXXXXXXXpar
beginscontent*[show-env=false]
Some text in whit verbatim B
beginVerbatim
verbatim environment B: &%_"`´~
endVerbatim
endscontent*
Scontent[show-cmd=true]showmemacro
XXXXXXXXXpar
And see in reverse order:par
usecontent[2]test-otherpar
usecontent[1]test-otherpar
NOT OK,...
subsectionThe problem whit texttt[show-env=true]
beginscontent*[show-env=true]
Some text in whit verbatim C
beginVerbatim
verbatim environment C: &%_"`´~
endVerbatim
endscontent*
enddocument
An image to complement
regards
macros expansion expl3 xparse
I am trying to encapsulate a couple of environments to pass them to lists using xparse/expl3
.
I have defined a one command and two environments and I have had a problem with one of them.
I use the environments to save notes type question/answer where the answers are stored in a list to show them at the end of the file or elsewhere in it, the issue is that sometimes need to use verbatim.
The scontent
environment uses the +b
argument of xparse
and only Verb[...]...
(from fvextra
) can be used (you can not use the verbatim environment for example).
The scontent*
environment is based on filecontentsdef
and can use verb|...|
in a line or beginverbatim
environment, this generates an external file but has the facility of saving the content in a macro
.
When executing beginscontent*
pass the following:
- Save the current content in
macro
- Copy the current contents of
macro
inl_my_macro_copy_tl
- Pass the contents of
l_my_macro_copy_tl
to list usingexpanddafterenvtolistexpanddafter content save in l_my_macro_copy_tl
- If this is the key
[show-env = true]
runusecontent[-1]l_scontent_env_save_tl
The problem is in the execution of
expanddafterenvtolistexpanddafterl_my_macro_copy_tl
at end of environment scontent*
, I tried with the following (ugly and incorrect) lines:
% beginscontent*[...] verbatim env save in macro
% Copy a current content of macro in l_my_macro_copy_tl and pass to list
tl_new:N l_my_macro_copy_tl
NewDocumentEnvironmentscontent* !O
group_begin:
filecontentsdefjobname.tscmacro % save in macro
endfilecontentsdef %
group_end:
IfNoValueF #1 keys_set:nn scontent #1
tl_set:Nx l_my_macro_copy_tl macro
exp_after:wN envtolist exp_after:wN exp_not:N tex_newlinechar:D = 13 exp_not:N scantokens exp_after:wN l_my_macro_copy_tl %
IfBooleanT l_scontent_env_show_tl usecontent[-1] l_scontent_env_save_tl
with this I eliminate the errors when compiling, but, the content is not saved in the list...How can i fix this?
My idea is not to occupy directly showme...
and only use usecontent[index]list name
in document.
I know that the command showme...
and usecontent[index]list name
works if you execute it out of the environment, but my idea is automate this when run scontent*
.
This is my example file (MWE), the comments should be removed to see the error that occurs.
documentclassarticle
usepackagefilecontentsdef,etoolbox,xparse,fvextra,xcolor
usepackage[margin=0.6in,noheadfoot,papersize=8.5in,13in]geometry
setlengthparindent0pt
pagestyleempty
ExplSyntaxOn
% show content save in macro
tl_new:N l_temp_argument_tl
NewDocumentCommandshowme +m %
tl_set:Nx l_temp_argument_tl #1
tex_newlinechar:D = 13
exp_not:N scantokens exp_after:wN l_temp_argument_tl
% elementinlistname and clearlistlistname
cs_new:Npn elementin #1 seq_count:c l_savecontent_content_#1_seq
cs_new:Npn clearlist #1 seq_clear_new:c l_savecontent_content_#1_seq
% addcontentlistname#1 ...need double ...
NewDocumentCommandaddcontent m +m savecontent_add_content:nn #1 #2
% usecontent[index]listname
DeclareExpandableDocumentCommandusecontentO1m savecontent_use_content:nn #1 #2
cs_new_protected:Npn savecontent_add_content:nn #1 #2
seq_if_exist:cF l_savecontent_content_#1_seq
seq_new:c l_savecontent_content_#1_seq
__savecontent_add_content:nn #1 #2
cs_new_protected:Npn __savecontent_add_content:nn #1 #2
tl_map_inline:nn #2
seq_gput_right:cn l_savecontent_content_#1_seq ##1
cs_new:Npn savecontent_use_content:nn #1 #2 seq_item:cn l_savecontent_content_#2_seq #1
keys_define:nn scontent
save-cmd .tl_set:N = l_scontent_cmd_save_tl, save-cmd .initial:n = content,%
save-env .tl_set:N = l_scontent_env_save_tl, save-env .initial:n = content, %
show-cmd .bool_set:N = l_scontent_cmd_show_tl, show-cmd .initial:n = false, show-cmd .value_required:n = true,%
show-env .bool_set:N = l_scontent_env_show_tl, show-env .initial:n = false, show-env .value_required:n = true,%
show-all .meta:n = show-env = true , show-cmd = true ,%
NewDocumentCommandSetscontent +m keys_set:nn scontent #1
% pass to list
newrobustcmdenvtolist[1]addcontent l_scontent_env_save_tl #1
% Scontent[...]... NO verbatim env support, but Verb[...]... yes
NewDocumentCommandScontent O +m
group_begin:
IfNoValueF#1 keys_set:nn scontent #1
addcontent l_scontent_cmd_save_tl #2 % pass direct to list
IfBooleanT l_scontent_cmd_show_tl usecontent[-1] l_scontent_cmd_save_tl
group_end:
% beginscontent[...] NO verbatim env suport, but Verb[...]... yes
NewDocumentEnvironmentscontent !o +b
group_begin:
IfNoValueF #1 keys_set:nn scontent #1
expandafterenvtolistexpandafter#2
IfBooleanT l_scontent_env_show_tl usecontent[-1] l_scontent_env_save_tl
group_end:
% beginscontent*[...] verbatim env save in macro
tl_new:N l_my_macro_copy_tl % tl_var to copy macro at definition time
NewDocumentEnvironmentscontent* !O
group_begin:
IfNoValueF #1 keys_set:nn scontent #1
filecontentsdefjobname.tscmacro
endfilecontentsdef %
group_end:
% Copy macro every time in tl_var (at definition time) and pass to list
%cs_set_eq:NN l_my_macro_copy_tl macro
%expandafterenvtolistexpandaftershowmel_my_macro_copy_tl
%IfBooleanT l_scontent_env_show_tl usecontent[-1] l_scontent_env_save_tl
ExplSyntaxOff
% set name of lists
Setscontent save-env=test-env, save-cmd=test-cmd
begindocument
sectionUsing textttscontent environment whit new texttt+b argument from textttxparse
subsectionWhit texttt[show-env=false]
Text save in verb|beginscontent[show-env=false]| (hidden)
beginscontent[show-env=false]
Some first text whit verbatim inline saved in Verbusecontent[1]test-env par
We have coded this in LaTeX: both $E=mc^2$.
endscontent
OK
subsectionWhit texttt[show-env=true]
Text save in verb|beginscontent[show-env=true]| (Not hidden)
beginscontent[show-env=true]
Some second text whit verbatim inline saved in Verbusecontent[2]test-env...more text par
We have coded this in LaTeX: both $E=mc^2$.
endscontent
OK
subsectionUsing Verbusecontent[1]test-env
Now see saved text in list:par
usecontent[2]test-envpar
usecontent[1]test-env
sectionUsing Verb*Scontent[...]...
Text save whit verb|Scontent....| (hidden)par
Scontent
using a Verb*Scontent[...]... textcolorredwhit verbatim Verb*Verb[...]...par
(by Verb*fvextra) textcolormagentainline
par
And see saved text in list using verb|usecontent[1]test-cmd| par
usecontent[1]test-cmdpar
OK
sectionUsing textttscontent* environment wraped textttfilecontentsdef using textttxparse
subsectionWhit texttt[show-env=false]
Some Text save using verb|beginscontent*[show-env=false]| save in verb|macro| (hidden)
beginscontent*[show-env=false]
Some text in whit verbatim environment ¿saved in list ...verb+usecontent[3]test-env+?(not get for now).par
beginVerbatim
This is from the verbatim environment: &%_"`´~
xxxxx
endVerbatim
endscontent*par
OK...it's posible to see verb|macro| whit verb|showmemacro|:par
showmemacropar
or pass to list using verb|Scontentshowmemacro| and see in list whit verb+usecontent[2]test-cmd+:par
Scontentshowmemacro
usecontent[2]test-cmd
subsectionThe idea whit texttt[show-env=true]
Setscontent save-cmd=test-other
XXXXXXXXXpar
beginscontent*[show-env=false]
Some text in whit verbatim A
beginVerbatim
verbatim environment A: &%_"`´~
endVerbatim
endscontent*
Scontent[show-cmd=true]showmemacropar
XXXXXXXXXpar
beginscontent*[show-env=false]
Some text in whit verbatim B
beginVerbatim
verbatim environment B: &%_"`´~
endVerbatim
endscontent*
Scontent[show-cmd=true]showmemacro
XXXXXXXXXpar
And see in reverse order:par
usecontent[2]test-otherpar
usecontent[1]test-otherpar
NOT OK,...
subsectionThe problem whit texttt[show-env=true]
beginscontent*[show-env=true]
Some text in whit verbatim C
beginVerbatim
verbatim environment C: &%_"`´~
endVerbatim
endscontent*
enddocument
An image to complement
regards
macros expansion expl3 xparse
macros expansion expl3 xparse
edited 18 mins ago
Pablo González L
asked Apr 6 at 1:45
Pablo González LPablo González L
1,0061820
1,0061820
1
Could you please state clearly at the beginning what the aim is?
– egreg
2 days ago
@egreg Thanks for the comment, I added the clarification, apologies for the writing, (myenglish base + google translator
sometimes fails). Can you give me a hand with this?
– Pablo González L
2 days ago
add a comment |
1
Could you please state clearly at the beginning what the aim is?
– egreg
2 days ago
@egreg Thanks for the comment, I added the clarification, apologies for the writing, (myenglish base + google translator
sometimes fails). Can you give me a hand with this?
– Pablo González L
2 days ago
1
1
Could you please state clearly at the beginning what the aim is?
– egreg
2 days ago
Could you please state clearly at the beginning what the aim is?
– egreg
2 days ago
@egreg Thanks for the comment, I added the clarification, apologies for the writing, (my
english base + google translator
sometimes fails). Can you give me a hand with this?– Pablo González L
2 days ago
@egreg Thanks for the comment, I added the clarification, apologies for the writing, (my
english base + google translator
sometimes fails). Can you give me a hand with this?– Pablo González L
2 days ago
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f483453%2fhow-to-expand-a-macro-or-a-copy-to-save-in-a-list-at-end-of-environment-in-xp%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
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f483453%2fhow-to-expand-a-macro-or-a-copy-to-save-in-a-list-at-end-of-environment-in-xp%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
Could you please state clearly at the beginning what the aim is?
– egreg
2 days ago
@egreg Thanks for the comment, I added the clarification, apologies for the writing, (my
english base + google translator
sometimes fails). Can you give me a hand with this?– Pablo González L
2 days ago