Keep a key locally passed from multicols to enumitem using xparse The Next CEO of Stack OverflowDefining a list environment with multiple optional argumentsCommands from xparse inside functions created by cs_new:Npn?xparse and key value argumentsGenerate l3keys meta key from subkeyMix value and key/value with xparseRemove key from styleWhy isn't the resume key working for enumitem packageEnumitem SetEnumitemKey and conflict between multiple key before and afterUsing key value in enumerate to another key valuePrevent xparse from stripping braces?Use value from xparse key-value store in regular expressions
MAZDA 3 2006 (UK) - poor acceleration then takes off at 3250 revs
What makes a siege story/plot interesting?
Increase performance creating Mandelbrot set in python
How do I go from 300 unfinished/half written blog posts, to published posts?
Does it take more energy to get to Venus or to Mars?
What can we do to stop prior company from asking us questions?
How do scammers retract money, while you can’t?
How to count occurrences of text in a file?
How to Reset Passwords on Multiple Websites Easily?
How to write the block matrix in LaTex?
Why here is plural "We went to the movies last night."
Why does standard notation not preserve intervals (visually)
Why did we only see the N-1 starfighters in one film?
Should I tutor a student who I know has cheated on their homework?
Return the Closest Prime Number
How can I get through very long and very dry, but also very useful technical documents when learning a new tool?
Rotate a column
Why do remote companies require working in the US?
When airplanes disconnect from a tanker during air to air refueling, why do they bank so sharply to the right?
Can I equip Skullclamp on a creature I am sacrificing?
Shade part of a Venn diagram
What does this shorthand mean?
Is HostGator storing my password in plaintext?
Visit to the USA with ESTA approved before trip to Iran
Keep a key locally passed from multicols to enumitem using xparse
The Next CEO of Stack OverflowDefining a list environment with multiple optional argumentsCommands from xparse inside functions created by cs_new:Npn?xparse and key value argumentsGenerate l3keys meta key from subkeyMix value and key/value with xparseRemove key from styleWhy isn't the resume key working for enumitem packageEnumitem SetEnumitemKey and conflict between multiple key before and afterUsing key value in enumerate to another key valuePrevent xparse from stripping braces?Use value from xparse key-value store in regular expressions
I have a small problem when trying to keep a key=val
locally defining using xparse
to pass multicols
to enumerate (enumitem
package). I have redefined the environment enumerate
to accept the columns=number
and created commands keyans[...]
, answer...
and showanskey[...]......[...]
to save the multiple choice keys and answers for worksheet exercise , all well except that when activate the columns
in the first level of enumerate
, affects all the levels nested in it.
When using columns=2
in the first level it looks like this:
all nested environments are in two columns.
I hope is that the output is something like this:
I tried to put group_begin:
and group_end:
in different places but I only get errors. The code is adapted from Defining a list environment with multiple optional arguments and MWE:
% arara: pdflatex
% arara: clean: extensions: [ aux, log]
documentclassarticle
usepackageletltxmacro,enumitem,multicol,xparse
usepackage[most]tcolorbox
usepackage[margin=0.6in,noheadfoot,papersize=8.5in,13in]geometry % for mwe
setlengthparindent0pt
pagestyleempty
% Set keys for save-ans and save-key in enumitem
SetEnumitemKeysave-ansbefore=storecurrentid#1beginsaveanswer#1,after=endsaveanswer%
SetEnumitemKeysave-keybefore=storecurrentid#1beginsavekeyans#1,after=endsavekeyans%
% Save a copy enumerate
LetLtxMacrooldenumenumerate
LetLtxMacrooldendenumendenumerate
% Redefine enumerate for multicols
ExplSyntaxOn
RenewDocumentEnvironmentenumerate O
tl_clear:N l_keyanswer_enumitem_tl
keys_set:nn keyanswer #1
int_compare:nT l_keyanswer_columns_tl > 1
setlengthmulticolsep5.0pt plus 2.0pt minus 1.5pt
beginmulticols l_keyanswer_columns_tl
keyanswer_beginenum:V l_keyanswer_enumitem_tl
oldendenum
int_compare:nT l_keyanswer_columns_tl > 1
endmulticols
cs_new_protected:Npn keyanswer_beginenum:n #1
oldenum[#1]
cs_generate_variant:Nn keyanswer_beginenum:n V
tl_new:N l_keyanswer_columns_tl
tl_new:N l_keyanswer_enumitem_tl
keys_define:nn keyanswer
columns .tl_set:N = l_keyanswer_columns_tl,
columns .initial:n = 1,
unknown .code:n = tl_put_right:Nx l_keyanswer_enumitem_tl
l_keys_key_tl tl_if_empty:nF #1 = exp_not:n #1 , ,
% Implementation to save answer... and keyans[...] in lists
prop_new:N g_keyanswer_admin_prop
cs_new:Npn storecurrentid #1%
prop_gput:Nnn g_keyanswer_admin_prop current-id #1
cs_new:Npn retrievecurrentid %
prop_item:Nn g_keyanswer_admin_prop current-id
% environments for save answer... and keyans[...]
NewDocumentEnvironmentsaveanswer m %
setlist[enumerate,2]leftmargin=16pt,nosep,itemsep=0pt,label=(alph*),before=stepdownlevel,after=stepuplevel%
setlist[enumerate,3]leftmargin=20pt,nosep,itemsep=0pt,label=Roman*.,before=stepdownlevel,after=stepuplevel%
seq_if_exist:cF l_keyanswer_data_#1_seq seq_new:c l_keyanswer_data_#1_seq
leavevmode
NewDocumentEnvironmentsavekeyans m %
setlist[enumerate,1]left=0pt,labelsep=5pt,itemsep=1pt,label=arabic*.%
setlist[enumerate,2]leftmargin=16pt,nosep,label=Alph*)%
seq_if_exist:cF l_keyanswer_data_#1_seq %
seq_new:c l_keyanswer_data_#1_seq leavevmode
% commands answer... and keyans[...]
NewDocumentCommandanswer +m %
seq_gput_right:cn l_keyanswer_data_ retrievecurrentid _seq item #1
par%
NewDocumentCommandkeyans !o %
IfNoValueTF#1%
tl_set:Nn l_tmpa_tl protectitem%
tl_put_right:Nx l_tmpa_tl protectspace Alphenumii%
seq_gput_right:cV l_keyanswer_data_ retrievecurrentid _seq l_tmpa_tl%
par%
%
seq_gput_right:cn l_keyanswer_data_ retrievecurrentid _seq item #1%
par%
%
%
% stepdownlevel and stepuplevel for save in nested enumerate
newcommandstepdownlevel%
seq_gput_right:cn l_keyanswer_data_ retrievecurrentid _seq item beginenumerate
newcommandstepuplevel%
seq_gput_right:cn l_keyanswer_data_ retrievecurrentid _seq endenumerate
% Display answer... and keyans[...] in list by id
cs_new:Npn displayseqcontent #1#2 %
seq_if_empty:cF l_keyanswer_data_#1_seq %
seq_log:c l_keyanswer_data_#1_seq
setlist[enumerate,1]labelsep=5pt,label=arabic*.,leftmargin=15pt,labelsep=3pt,font=footnotesize,nosep,widest=80%
setlist[enumerate,2]font=footnotesize,labelsep=5pt,leftmargin=0.6cm,nosep,label=(alph*)%
setlist[enumerate,3]font=footnotesize,labelsep=5pt,leftmargin=0.3cm,nosep,label=Roman*.%
beginenumerate[#2] smallsetlengthcolumnsep0pt
seq_map_inline:cn l_keyanswer_data_#1_seq ##1
endenumerate
ExplSyntaxOff
% showanskey[tcolorbox]titlelist ref[columns]
DeclareTotalTColorBoxshowanskeyO m m O4
colback=white,size=small,top=0mm,bottom=1.5mm, left=0mm,width=columnwidth,title filled,%
fontupper=small,fonttitle=smallsffamily, adjusted title=#2,center title,#1
displayseqcontent#3columns=#4 %
begindocument
sectionMultiple Choice
beginenumerate[save-key=mchoice,left=0pt,columns=2]
item First type of questions
beginenumerate
item value
item value
item value
item correct keyans
item value
endenumerate
item Second type of questions
beginenumerate[leftmargin=2pc,label=Roman*.]
item $2alpha+2delta=90^circ$
item $alpha=delta$
item $angle EDF=45^circ$
endenumerate
beginenumerate[columns=2]%
item I only
item II only keyans
item I and II only
item I and III only
item I, II, and III
endenumerate
%columnbreak %
item Third type of questions
beginenumerate[leftmargin=2pc,label=(arabic*)]
item $2alpha+2delta=90^circ$
item $angle EDF=45^circ$
endenumerate
beginenumerate
item Altenativa A
item Altenativa B
item Altenativa C keyans
item Altenativa D
item Altenativa E
endenumerate
item Fourth type of question, a problem with numerical response keyans[$sqrt2$]
endenumerate
sectionWorksheet
beginenumerate[save-ans=Worksheet,left=0pt,labelsep=5pt,nosep,label=arabic*.,columns=2]
item Factor $x^2-2x+1$ answer$left(x-1right)^2$
item Factor $3x+3y+3z$ answer$3(x+y+z)$
item True False
beginenumerate
item $alpha > delta$ answerFalse
item LaTeX2e is cool? answerVery True!
endenumerate
item Related to Linux
beginenumerate
item You use linux? answerYes
item Usually uses the package manager? answerYes
item Rate the following package managers
beginenumerate
item dnf answergood
item apt answervery good
item yum answerobsolete
endenumerate
endenumerate
endenumerate
sectionAnswers
showanskey[colback=yellow!30!white]Multiple Choice Keysmchoice[5]
showanskey[colback=yellow!30!white]Solution WorksheetWorksheet[2]
sectionNormal enumerate
beginenumerate
item First level
beginenumerate
item Second level
item value
item beginenumerate
item Third level
item value
endenumerate
endenumerate
endenumerate
enddocument
If put in all sublevels columns=1
skip the problem, but, can't do this with showanskey
. If instead of using RenewDocumentEnvironmentenumerate
I use directly
SetEnumitemKeycolumnsbefore=beginmulticols#1,after=endmulticols%
I get the following error:
! LaTeX3 Error: Variable l_keyanswer_data_mchoice_seq undefined.
How can i fix this?
Grateful
enumitem expl3 xparse key-value
add a comment |
I have a small problem when trying to keep a key=val
locally defining using xparse
to pass multicols
to enumerate (enumitem
package). I have redefined the environment enumerate
to accept the columns=number
and created commands keyans[...]
, answer...
and showanskey[...]......[...]
to save the multiple choice keys and answers for worksheet exercise , all well except that when activate the columns
in the first level of enumerate
, affects all the levels nested in it.
When using columns=2
in the first level it looks like this:
all nested environments are in two columns.
I hope is that the output is something like this:
I tried to put group_begin:
and group_end:
in different places but I only get errors. The code is adapted from Defining a list environment with multiple optional arguments and MWE:
% arara: pdflatex
% arara: clean: extensions: [ aux, log]
documentclassarticle
usepackageletltxmacro,enumitem,multicol,xparse
usepackage[most]tcolorbox
usepackage[margin=0.6in,noheadfoot,papersize=8.5in,13in]geometry % for mwe
setlengthparindent0pt
pagestyleempty
% Set keys for save-ans and save-key in enumitem
SetEnumitemKeysave-ansbefore=storecurrentid#1beginsaveanswer#1,after=endsaveanswer%
SetEnumitemKeysave-keybefore=storecurrentid#1beginsavekeyans#1,after=endsavekeyans%
% Save a copy enumerate
LetLtxMacrooldenumenumerate
LetLtxMacrooldendenumendenumerate
% Redefine enumerate for multicols
ExplSyntaxOn
RenewDocumentEnvironmentenumerate O
tl_clear:N l_keyanswer_enumitem_tl
keys_set:nn keyanswer #1
int_compare:nT l_keyanswer_columns_tl > 1
setlengthmulticolsep5.0pt plus 2.0pt minus 1.5pt
beginmulticols l_keyanswer_columns_tl
keyanswer_beginenum:V l_keyanswer_enumitem_tl
oldendenum
int_compare:nT l_keyanswer_columns_tl > 1
endmulticols
cs_new_protected:Npn keyanswer_beginenum:n #1
oldenum[#1]
cs_generate_variant:Nn keyanswer_beginenum:n V
tl_new:N l_keyanswer_columns_tl
tl_new:N l_keyanswer_enumitem_tl
keys_define:nn keyanswer
columns .tl_set:N = l_keyanswer_columns_tl,
columns .initial:n = 1,
unknown .code:n = tl_put_right:Nx l_keyanswer_enumitem_tl
l_keys_key_tl tl_if_empty:nF #1 = exp_not:n #1 , ,
% Implementation to save answer... and keyans[...] in lists
prop_new:N g_keyanswer_admin_prop
cs_new:Npn storecurrentid #1%
prop_gput:Nnn g_keyanswer_admin_prop current-id #1
cs_new:Npn retrievecurrentid %
prop_item:Nn g_keyanswer_admin_prop current-id
% environments for save answer... and keyans[...]
NewDocumentEnvironmentsaveanswer m %
setlist[enumerate,2]leftmargin=16pt,nosep,itemsep=0pt,label=(alph*),before=stepdownlevel,after=stepuplevel%
setlist[enumerate,3]leftmargin=20pt,nosep,itemsep=0pt,label=Roman*.,before=stepdownlevel,after=stepuplevel%
seq_if_exist:cF l_keyanswer_data_#1_seq seq_new:c l_keyanswer_data_#1_seq
leavevmode
NewDocumentEnvironmentsavekeyans m %
setlist[enumerate,1]left=0pt,labelsep=5pt,itemsep=1pt,label=arabic*.%
setlist[enumerate,2]leftmargin=16pt,nosep,label=Alph*)%
seq_if_exist:cF l_keyanswer_data_#1_seq %
seq_new:c l_keyanswer_data_#1_seq leavevmode
% commands answer... and keyans[...]
NewDocumentCommandanswer +m %
seq_gput_right:cn l_keyanswer_data_ retrievecurrentid _seq item #1
par%
NewDocumentCommandkeyans !o %
IfNoValueTF#1%
tl_set:Nn l_tmpa_tl protectitem%
tl_put_right:Nx l_tmpa_tl protectspace Alphenumii%
seq_gput_right:cV l_keyanswer_data_ retrievecurrentid _seq l_tmpa_tl%
par%
%
seq_gput_right:cn l_keyanswer_data_ retrievecurrentid _seq item #1%
par%
%
%
% stepdownlevel and stepuplevel for save in nested enumerate
newcommandstepdownlevel%
seq_gput_right:cn l_keyanswer_data_ retrievecurrentid _seq item beginenumerate
newcommandstepuplevel%
seq_gput_right:cn l_keyanswer_data_ retrievecurrentid _seq endenumerate
% Display answer... and keyans[...] in list by id
cs_new:Npn displayseqcontent #1#2 %
seq_if_empty:cF l_keyanswer_data_#1_seq %
seq_log:c l_keyanswer_data_#1_seq
setlist[enumerate,1]labelsep=5pt,label=arabic*.,leftmargin=15pt,labelsep=3pt,font=footnotesize,nosep,widest=80%
setlist[enumerate,2]font=footnotesize,labelsep=5pt,leftmargin=0.6cm,nosep,label=(alph*)%
setlist[enumerate,3]font=footnotesize,labelsep=5pt,leftmargin=0.3cm,nosep,label=Roman*.%
beginenumerate[#2] smallsetlengthcolumnsep0pt
seq_map_inline:cn l_keyanswer_data_#1_seq ##1
endenumerate
ExplSyntaxOff
% showanskey[tcolorbox]titlelist ref[columns]
DeclareTotalTColorBoxshowanskeyO m m O4
colback=white,size=small,top=0mm,bottom=1.5mm, left=0mm,width=columnwidth,title filled,%
fontupper=small,fonttitle=smallsffamily, adjusted title=#2,center title,#1
displayseqcontent#3columns=#4 %
begindocument
sectionMultiple Choice
beginenumerate[save-key=mchoice,left=0pt,columns=2]
item First type of questions
beginenumerate
item value
item value
item value
item correct keyans
item value
endenumerate
item Second type of questions
beginenumerate[leftmargin=2pc,label=Roman*.]
item $2alpha+2delta=90^circ$
item $alpha=delta$
item $angle EDF=45^circ$
endenumerate
beginenumerate[columns=2]%
item I only
item II only keyans
item I and II only
item I and III only
item I, II, and III
endenumerate
%columnbreak %
item Third type of questions
beginenumerate[leftmargin=2pc,label=(arabic*)]
item $2alpha+2delta=90^circ$
item $angle EDF=45^circ$
endenumerate
beginenumerate
item Altenativa A
item Altenativa B
item Altenativa C keyans
item Altenativa D
item Altenativa E
endenumerate
item Fourth type of question, a problem with numerical response keyans[$sqrt2$]
endenumerate
sectionWorksheet
beginenumerate[save-ans=Worksheet,left=0pt,labelsep=5pt,nosep,label=arabic*.,columns=2]
item Factor $x^2-2x+1$ answer$left(x-1right)^2$
item Factor $3x+3y+3z$ answer$3(x+y+z)$
item True False
beginenumerate
item $alpha > delta$ answerFalse
item LaTeX2e is cool? answerVery True!
endenumerate
item Related to Linux
beginenumerate
item You use linux? answerYes
item Usually uses the package manager? answerYes
item Rate the following package managers
beginenumerate
item dnf answergood
item apt answervery good
item yum answerobsolete
endenumerate
endenumerate
endenumerate
sectionAnswers
showanskey[colback=yellow!30!white]Multiple Choice Keysmchoice[5]
showanskey[colback=yellow!30!white]Solution WorksheetWorksheet[2]
sectionNormal enumerate
beginenumerate
item First level
beginenumerate
item Second level
item value
item beginenumerate
item Third level
item value
endenumerate
endenumerate
endenumerate
enddocument
If put in all sublevels columns=1
skip the problem, but, can't do this with showanskey
. If instead of using RenewDocumentEnvironmentenumerate
I use directly
SetEnumitemKeycolumnsbefore=beginmulticols#1,after=endmulticols%
I get the following error:
! LaTeX3 Error: Variable l_keyanswer_data_mchoice_seq undefined.
How can i fix this?
Grateful
enumitem expl3 xparse key-value
add a comment |
I have a small problem when trying to keep a key=val
locally defining using xparse
to pass multicols
to enumerate (enumitem
package). I have redefined the environment enumerate
to accept the columns=number
and created commands keyans[...]
, answer...
and showanskey[...]......[...]
to save the multiple choice keys and answers for worksheet exercise , all well except that when activate the columns
in the first level of enumerate
, affects all the levels nested in it.
When using columns=2
in the first level it looks like this:
all nested environments are in two columns.
I hope is that the output is something like this:
I tried to put group_begin:
and group_end:
in different places but I only get errors. The code is adapted from Defining a list environment with multiple optional arguments and MWE:
% arara: pdflatex
% arara: clean: extensions: [ aux, log]
documentclassarticle
usepackageletltxmacro,enumitem,multicol,xparse
usepackage[most]tcolorbox
usepackage[margin=0.6in,noheadfoot,papersize=8.5in,13in]geometry % for mwe
setlengthparindent0pt
pagestyleempty
% Set keys for save-ans and save-key in enumitem
SetEnumitemKeysave-ansbefore=storecurrentid#1beginsaveanswer#1,after=endsaveanswer%
SetEnumitemKeysave-keybefore=storecurrentid#1beginsavekeyans#1,after=endsavekeyans%
% Save a copy enumerate
LetLtxMacrooldenumenumerate
LetLtxMacrooldendenumendenumerate
% Redefine enumerate for multicols
ExplSyntaxOn
RenewDocumentEnvironmentenumerate O
tl_clear:N l_keyanswer_enumitem_tl
keys_set:nn keyanswer #1
int_compare:nT l_keyanswer_columns_tl > 1
setlengthmulticolsep5.0pt plus 2.0pt minus 1.5pt
beginmulticols l_keyanswer_columns_tl
keyanswer_beginenum:V l_keyanswer_enumitem_tl
oldendenum
int_compare:nT l_keyanswer_columns_tl > 1
endmulticols
cs_new_protected:Npn keyanswer_beginenum:n #1
oldenum[#1]
cs_generate_variant:Nn keyanswer_beginenum:n V
tl_new:N l_keyanswer_columns_tl
tl_new:N l_keyanswer_enumitem_tl
keys_define:nn keyanswer
columns .tl_set:N = l_keyanswer_columns_tl,
columns .initial:n = 1,
unknown .code:n = tl_put_right:Nx l_keyanswer_enumitem_tl
l_keys_key_tl tl_if_empty:nF #1 = exp_not:n #1 , ,
% Implementation to save answer... and keyans[...] in lists
prop_new:N g_keyanswer_admin_prop
cs_new:Npn storecurrentid #1%
prop_gput:Nnn g_keyanswer_admin_prop current-id #1
cs_new:Npn retrievecurrentid %
prop_item:Nn g_keyanswer_admin_prop current-id
% environments for save answer... and keyans[...]
NewDocumentEnvironmentsaveanswer m %
setlist[enumerate,2]leftmargin=16pt,nosep,itemsep=0pt,label=(alph*),before=stepdownlevel,after=stepuplevel%
setlist[enumerate,3]leftmargin=20pt,nosep,itemsep=0pt,label=Roman*.,before=stepdownlevel,after=stepuplevel%
seq_if_exist:cF l_keyanswer_data_#1_seq seq_new:c l_keyanswer_data_#1_seq
leavevmode
NewDocumentEnvironmentsavekeyans m %
setlist[enumerate,1]left=0pt,labelsep=5pt,itemsep=1pt,label=arabic*.%
setlist[enumerate,2]leftmargin=16pt,nosep,label=Alph*)%
seq_if_exist:cF l_keyanswer_data_#1_seq %
seq_new:c l_keyanswer_data_#1_seq leavevmode
% commands answer... and keyans[...]
NewDocumentCommandanswer +m %
seq_gput_right:cn l_keyanswer_data_ retrievecurrentid _seq item #1
par%
NewDocumentCommandkeyans !o %
IfNoValueTF#1%
tl_set:Nn l_tmpa_tl protectitem%
tl_put_right:Nx l_tmpa_tl protectspace Alphenumii%
seq_gput_right:cV l_keyanswer_data_ retrievecurrentid _seq l_tmpa_tl%
par%
%
seq_gput_right:cn l_keyanswer_data_ retrievecurrentid _seq item #1%
par%
%
%
% stepdownlevel and stepuplevel for save in nested enumerate
newcommandstepdownlevel%
seq_gput_right:cn l_keyanswer_data_ retrievecurrentid _seq item beginenumerate
newcommandstepuplevel%
seq_gput_right:cn l_keyanswer_data_ retrievecurrentid _seq endenumerate
% Display answer... and keyans[...] in list by id
cs_new:Npn displayseqcontent #1#2 %
seq_if_empty:cF l_keyanswer_data_#1_seq %
seq_log:c l_keyanswer_data_#1_seq
setlist[enumerate,1]labelsep=5pt,label=arabic*.,leftmargin=15pt,labelsep=3pt,font=footnotesize,nosep,widest=80%
setlist[enumerate,2]font=footnotesize,labelsep=5pt,leftmargin=0.6cm,nosep,label=(alph*)%
setlist[enumerate,3]font=footnotesize,labelsep=5pt,leftmargin=0.3cm,nosep,label=Roman*.%
beginenumerate[#2] smallsetlengthcolumnsep0pt
seq_map_inline:cn l_keyanswer_data_#1_seq ##1
endenumerate
ExplSyntaxOff
% showanskey[tcolorbox]titlelist ref[columns]
DeclareTotalTColorBoxshowanskeyO m m O4
colback=white,size=small,top=0mm,bottom=1.5mm, left=0mm,width=columnwidth,title filled,%
fontupper=small,fonttitle=smallsffamily, adjusted title=#2,center title,#1
displayseqcontent#3columns=#4 %
begindocument
sectionMultiple Choice
beginenumerate[save-key=mchoice,left=0pt,columns=2]
item First type of questions
beginenumerate
item value
item value
item value
item correct keyans
item value
endenumerate
item Second type of questions
beginenumerate[leftmargin=2pc,label=Roman*.]
item $2alpha+2delta=90^circ$
item $alpha=delta$
item $angle EDF=45^circ$
endenumerate
beginenumerate[columns=2]%
item I only
item II only keyans
item I and II only
item I and III only
item I, II, and III
endenumerate
%columnbreak %
item Third type of questions
beginenumerate[leftmargin=2pc,label=(arabic*)]
item $2alpha+2delta=90^circ$
item $angle EDF=45^circ$
endenumerate
beginenumerate
item Altenativa A
item Altenativa B
item Altenativa C keyans
item Altenativa D
item Altenativa E
endenumerate
item Fourth type of question, a problem with numerical response keyans[$sqrt2$]
endenumerate
sectionWorksheet
beginenumerate[save-ans=Worksheet,left=0pt,labelsep=5pt,nosep,label=arabic*.,columns=2]
item Factor $x^2-2x+1$ answer$left(x-1right)^2$
item Factor $3x+3y+3z$ answer$3(x+y+z)$
item True False
beginenumerate
item $alpha > delta$ answerFalse
item LaTeX2e is cool? answerVery True!
endenumerate
item Related to Linux
beginenumerate
item You use linux? answerYes
item Usually uses the package manager? answerYes
item Rate the following package managers
beginenumerate
item dnf answergood
item apt answervery good
item yum answerobsolete
endenumerate
endenumerate
endenumerate
sectionAnswers
showanskey[colback=yellow!30!white]Multiple Choice Keysmchoice[5]
showanskey[colback=yellow!30!white]Solution WorksheetWorksheet[2]
sectionNormal enumerate
beginenumerate
item First level
beginenumerate
item Second level
item value
item beginenumerate
item Third level
item value
endenumerate
endenumerate
endenumerate
enddocument
If put in all sublevels columns=1
skip the problem, but, can't do this with showanskey
. If instead of using RenewDocumentEnvironmentenumerate
I use directly
SetEnumitemKeycolumnsbefore=beginmulticols#1,after=endmulticols%
I get the following error:
! LaTeX3 Error: Variable l_keyanswer_data_mchoice_seq undefined.
How can i fix this?
Grateful
enumitem expl3 xparse key-value
I have a small problem when trying to keep a key=val
locally defining using xparse
to pass multicols
to enumerate (enumitem
package). I have redefined the environment enumerate
to accept the columns=number
and created commands keyans[...]
, answer...
and showanskey[...]......[...]
to save the multiple choice keys and answers for worksheet exercise , all well except that when activate the columns
in the first level of enumerate
, affects all the levels nested in it.
When using columns=2
in the first level it looks like this:
all nested environments are in two columns.
I hope is that the output is something like this:
I tried to put group_begin:
and group_end:
in different places but I only get errors. The code is adapted from Defining a list environment with multiple optional arguments and MWE:
% arara: pdflatex
% arara: clean: extensions: [ aux, log]
documentclassarticle
usepackageletltxmacro,enumitem,multicol,xparse
usepackage[most]tcolorbox
usepackage[margin=0.6in,noheadfoot,papersize=8.5in,13in]geometry % for mwe
setlengthparindent0pt
pagestyleempty
% Set keys for save-ans and save-key in enumitem
SetEnumitemKeysave-ansbefore=storecurrentid#1beginsaveanswer#1,after=endsaveanswer%
SetEnumitemKeysave-keybefore=storecurrentid#1beginsavekeyans#1,after=endsavekeyans%
% Save a copy enumerate
LetLtxMacrooldenumenumerate
LetLtxMacrooldendenumendenumerate
% Redefine enumerate for multicols
ExplSyntaxOn
RenewDocumentEnvironmentenumerate O
tl_clear:N l_keyanswer_enumitem_tl
keys_set:nn keyanswer #1
int_compare:nT l_keyanswer_columns_tl > 1
setlengthmulticolsep5.0pt plus 2.0pt minus 1.5pt
beginmulticols l_keyanswer_columns_tl
keyanswer_beginenum:V l_keyanswer_enumitem_tl
oldendenum
int_compare:nT l_keyanswer_columns_tl > 1
endmulticols
cs_new_protected:Npn keyanswer_beginenum:n #1
oldenum[#1]
cs_generate_variant:Nn keyanswer_beginenum:n V
tl_new:N l_keyanswer_columns_tl
tl_new:N l_keyanswer_enumitem_tl
keys_define:nn keyanswer
columns .tl_set:N = l_keyanswer_columns_tl,
columns .initial:n = 1,
unknown .code:n = tl_put_right:Nx l_keyanswer_enumitem_tl
l_keys_key_tl tl_if_empty:nF #1 = exp_not:n #1 , ,
% Implementation to save answer... and keyans[...] in lists
prop_new:N g_keyanswer_admin_prop
cs_new:Npn storecurrentid #1%
prop_gput:Nnn g_keyanswer_admin_prop current-id #1
cs_new:Npn retrievecurrentid %
prop_item:Nn g_keyanswer_admin_prop current-id
% environments for save answer... and keyans[...]
NewDocumentEnvironmentsaveanswer m %
setlist[enumerate,2]leftmargin=16pt,nosep,itemsep=0pt,label=(alph*),before=stepdownlevel,after=stepuplevel%
setlist[enumerate,3]leftmargin=20pt,nosep,itemsep=0pt,label=Roman*.,before=stepdownlevel,after=stepuplevel%
seq_if_exist:cF l_keyanswer_data_#1_seq seq_new:c l_keyanswer_data_#1_seq
leavevmode
NewDocumentEnvironmentsavekeyans m %
setlist[enumerate,1]left=0pt,labelsep=5pt,itemsep=1pt,label=arabic*.%
setlist[enumerate,2]leftmargin=16pt,nosep,label=Alph*)%
seq_if_exist:cF l_keyanswer_data_#1_seq %
seq_new:c l_keyanswer_data_#1_seq leavevmode
% commands answer... and keyans[...]
NewDocumentCommandanswer +m %
seq_gput_right:cn l_keyanswer_data_ retrievecurrentid _seq item #1
par%
NewDocumentCommandkeyans !o %
IfNoValueTF#1%
tl_set:Nn l_tmpa_tl protectitem%
tl_put_right:Nx l_tmpa_tl protectspace Alphenumii%
seq_gput_right:cV l_keyanswer_data_ retrievecurrentid _seq l_tmpa_tl%
par%
%
seq_gput_right:cn l_keyanswer_data_ retrievecurrentid _seq item #1%
par%
%
%
% stepdownlevel and stepuplevel for save in nested enumerate
newcommandstepdownlevel%
seq_gput_right:cn l_keyanswer_data_ retrievecurrentid _seq item beginenumerate
newcommandstepuplevel%
seq_gput_right:cn l_keyanswer_data_ retrievecurrentid _seq endenumerate
% Display answer... and keyans[...] in list by id
cs_new:Npn displayseqcontent #1#2 %
seq_if_empty:cF l_keyanswer_data_#1_seq %
seq_log:c l_keyanswer_data_#1_seq
setlist[enumerate,1]labelsep=5pt,label=arabic*.,leftmargin=15pt,labelsep=3pt,font=footnotesize,nosep,widest=80%
setlist[enumerate,2]font=footnotesize,labelsep=5pt,leftmargin=0.6cm,nosep,label=(alph*)%
setlist[enumerate,3]font=footnotesize,labelsep=5pt,leftmargin=0.3cm,nosep,label=Roman*.%
beginenumerate[#2] smallsetlengthcolumnsep0pt
seq_map_inline:cn l_keyanswer_data_#1_seq ##1
endenumerate
ExplSyntaxOff
% showanskey[tcolorbox]titlelist ref[columns]
DeclareTotalTColorBoxshowanskeyO m m O4
colback=white,size=small,top=0mm,bottom=1.5mm, left=0mm,width=columnwidth,title filled,%
fontupper=small,fonttitle=smallsffamily, adjusted title=#2,center title,#1
displayseqcontent#3columns=#4 %
begindocument
sectionMultiple Choice
beginenumerate[save-key=mchoice,left=0pt,columns=2]
item First type of questions
beginenumerate
item value
item value
item value
item correct keyans
item value
endenumerate
item Second type of questions
beginenumerate[leftmargin=2pc,label=Roman*.]
item $2alpha+2delta=90^circ$
item $alpha=delta$
item $angle EDF=45^circ$
endenumerate
beginenumerate[columns=2]%
item I only
item II only keyans
item I and II only
item I and III only
item I, II, and III
endenumerate
%columnbreak %
item Third type of questions
beginenumerate[leftmargin=2pc,label=(arabic*)]
item $2alpha+2delta=90^circ$
item $angle EDF=45^circ$
endenumerate
beginenumerate
item Altenativa A
item Altenativa B
item Altenativa C keyans
item Altenativa D
item Altenativa E
endenumerate
item Fourth type of question, a problem with numerical response keyans[$sqrt2$]
endenumerate
sectionWorksheet
beginenumerate[save-ans=Worksheet,left=0pt,labelsep=5pt,nosep,label=arabic*.,columns=2]
item Factor $x^2-2x+1$ answer$left(x-1right)^2$
item Factor $3x+3y+3z$ answer$3(x+y+z)$
item True False
beginenumerate
item $alpha > delta$ answerFalse
item LaTeX2e is cool? answerVery True!
endenumerate
item Related to Linux
beginenumerate
item You use linux? answerYes
item Usually uses the package manager? answerYes
item Rate the following package managers
beginenumerate
item dnf answergood
item apt answervery good
item yum answerobsolete
endenumerate
endenumerate
endenumerate
sectionAnswers
showanskey[colback=yellow!30!white]Multiple Choice Keysmchoice[5]
showanskey[colback=yellow!30!white]Solution WorksheetWorksheet[2]
sectionNormal enumerate
beginenumerate
item First level
beginenumerate
item Second level
item value
item beginenumerate
item Third level
item value
endenumerate
endenumerate
endenumerate
enddocument
If put in all sublevels columns=1
skip the problem, but, can't do this with showanskey
. If instead of using RenewDocumentEnvironmentenumerate
I use directly
SetEnumitemKeycolumnsbefore=beginmulticols#1,after=endmulticols%
I get the following error:
! LaTeX3 Error: Variable l_keyanswer_data_mchoice_seq undefined.
How can i fix this?
Grateful
enumitem expl3 xparse key-value
enumitem expl3 xparse key-value
edited 12 hours ago
Pablo González L
asked Mar 24 at 6:16
Pablo González LPablo González L
1,0061820
1,0061820
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Once you set the keys, the values remain as stated.
You can simply restore a value by specifying the relevant key, before setting the specified ones:
keys_set:nn keyanswer #1
should become
keys_set:nn keyanswer columns=1, #1
Many thanks again!!!
– Pablo González L
11 hours ago
add a comment |
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');
);
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%2f481155%2fkeep-a-key-locally-passed-from-multicols-to-enumitem-using-xparse%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Once you set the keys, the values remain as stated.
You can simply restore a value by specifying the relevant key, before setting the specified ones:
keys_set:nn keyanswer #1
should become
keys_set:nn keyanswer columns=1, #1
Many thanks again!!!
– Pablo González L
11 hours ago
add a comment |
Once you set the keys, the values remain as stated.
You can simply restore a value by specifying the relevant key, before setting the specified ones:
keys_set:nn keyanswer #1
should become
keys_set:nn keyanswer columns=1, #1
Many thanks again!!!
– Pablo González L
11 hours ago
add a comment |
Once you set the keys, the values remain as stated.
You can simply restore a value by specifying the relevant key, before setting the specified ones:
keys_set:nn keyanswer #1
should become
keys_set:nn keyanswer columns=1, #1
Once you set the keys, the values remain as stated.
You can simply restore a value by specifying the relevant key, before setting the specified ones:
keys_set:nn keyanswer #1
should become
keys_set:nn keyanswer columns=1, #1
answered 11 hours ago
egregegreg
730k8819283242
730k8819283242
Many thanks again!!!
– Pablo González L
11 hours ago
add a comment |
Many thanks again!!!
– Pablo González L
11 hours ago
Many thanks again!!!
– Pablo González L
11 hours ago
Many thanks again!!!
– Pablo González L
11 hours ago
add a comment |
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');
);
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%2f481155%2fkeep-a-key-locally-passed-from-multicols-to-enumitem-using-xparse%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');
);
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');
);
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');
);
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