Keep a key locally passed from multicols to enumitem using xparse
What prevents the use of a multi-segment ILS for non-straight approaches?
Delivering sarcasm
Is it safe to use olive oil to clean the ear wax?
Start making guitar arrangements
Removing files under particular conditions (number of files, file age)
Is it possible to have a strip of cold climate in the middle of a planet?
Closed-form expression for certain product
GraphicsGrid with a Label for each Column and Row
250 Floor Tower
Can someone explain how this makes sense electrically?
How can Trident be so inexpensive? Will it orbit Triton or just do a (slow) flyby?
Non-trope happy ending?
Is there a single word describing earning money through any means?
Count the occurrence of each unique word in the file
Why did the HMS Bounty go back to a time when whales are already rare?
Why did the EU agree to delay the Brexit deadline?
Longest common substring in linear time
How to implement a feedback to keep the DC gain at zero for this conceptual passive filter?
Is it better practice to read straight from sheet music rather than memorize it?
Multiplicative persistence
Why is so much work done on numerical verification of the Riemann Hypothesis?
How do I color the graph in datavisualization?
How can "mimic phobia" be cured or prevented?
A social experiment. What is the worst that can happen?
Keep a key locally passed from multicols to enumitem using xparse
I have a small problem when trying to keep a key locally using enumerate from the enumitem
package. I have redefined the environment enumerate
to accept the key columns
and I have created commands that are of my interest keyans[...]
, answer{...}
and showanskey[...]{...}{...}[...]
which I use to save the multiple choice keys and worksheet exercise , all well except that when activate the columns
in the first level of enumerate
, it affects all the levels nested in it.
If I put in all sublevels columns=1
I can skip the problem, but, I can not do this within the showanskey
.
When using columns=1
in the first level it looks like this:
and when using columns=2
in the first level it looks like this:
What 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 MWE:
% arara: pdflatex
% arara: clean: { extensions: [ aux, log] }
documentclass{article}
usepackage{letltxmacro,enumitem,multicol,xparse}
usepackage[most]{tcolorbox}
usepackage[margin=0.6in,noheadfoot,papersize={8.5in,13in}]{geometry} % for mwe
setlength{parindent}{0pt}
pagestyle{empty}
% Set keys for save-ans, save-key and columns for enumitem
SetEnumitemKey{save-ans}{before={storecurrentid{#1}begin{saveanswer}{#1}},after=end{saveanswer}}%
SetEnumitemKey{save-key}{before={storecurrentid{#1}begin{savekeyans}{#1}},after=end{savekeyans}}%
% Save a copy enumerate
LetLtxMacrooldenumenumerate
LetLtxMacrooldendenumendenumerate
% Redefine enumerate for multicols
ExplSyntaxOn
RenewDocumentEnvironment{enumerate}{ O{} }
{
tl_clear:N l_keyanswer_enumitem_tl
keys_set:nn { keyanswer } { #1 }
int_compare:nT { l_keyanswer_columns_tl > 1 }
{
setlength{multicolsep}{5.0pt plus 2.0pt minus 1.5pt}
begin{multicols}{ l_keyanswer_columns_tl }
}
keyanswer_beginenum:V l_keyanswer_enumitem_tl
}
{
oldendenum
int_compare:nT { l_keyanswer_columns_tl > 1 }
{ end{multicols} }
}
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[...]
NewDocumentEnvironment{saveanswer}{ 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 }
NewDocumentEnvironment{savekeyans}{ 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[...]
NewDocumentCommand{answer}{ +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 Alph{enumii}}%
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
newcommand{stepdownlevel}{%
seq_gput_right:cn {l_keyanswer_data_ retrievecurrentid _seq} {item begin{enumerate}}
}
newcommand{stepuplevel}{%
seq_gput_right:cn {l_keyanswer_data_ retrievecurrentid _seq} {end{enumerate}}
}
% 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*.}%
begin{enumerate}[#2] smallsetlength{columnsep}{0pt}
seq_map_inline:cn { l_keyanswer_data_#1_seq } { ##1 }
end{enumerate}
}
}
ExplSyntaxOff
% showanskey[tcolorbox]{title}{list ref}[columns]
DeclareTotalTColorBox{showanskey}{O{} m m O{4}}
{ 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{#3}{columns=#4} }%
begin{document}
section{Multiple Choice}
begin{enumerate}[save-key=mchoice,left=0pt]
item First type of questions
begin{enumerate}
item value
item value
item value
item correct keyans
item value
end{enumerate}
item Second type of questions
begin{enumerate}[leftmargin=2pc,label=Roman*.]
item $2alpha+2delta=90^{circ}$
item $alpha=delta$
item $angle EDF=45^{circ}$
end{enumerate}
begin{enumerate}[columns=2]%
item I only
item II only keyans
item I and II only
item I and III only
item I, II, and III
end{enumerate}
%columnbreak %
item Third type of questions
begin{enumerate}[leftmargin=2pc,label=(arabic*)]
item $2alpha+2delta=90^{circ}$
item $angle EDF=45^{circ}$
end{enumerate}
begin{enumerate}
item Altenativa A
item Altenativa B
item Altenativa C keyans
item Altenativa D
item Altenativa E
end{enumerate}
item Fourth type of question, a problem with numerical response keyans[$sqrt{2}$]
end{enumerate}
section{Worksheet}
begin{enumerate}[save-ans=Worksheet,left=0pt,labelsep=5pt,nosep,label=arabic*.]
item Factor $x^{2}-2x+1$ answer{$left(x-1right)^{2}$}
item Factor $3x+3y+3z$ answer{$3(x+y+z)$}
item True False
begin{enumerate}
item $alpha > delta$ answer{False}
item LaTeX2e is cool? answer{Very True!}
end{enumerate}
item Related to Linux
begin{enumerate}
item You use linux? answer{Yes}
item Usually uses the package manager? answer{Yes}
item Rate the following package managers
begin{enumerate}
item dnf answer{good}
item apt answer{very good}
item yum answer{obsolete}
end{enumerate}
end{enumerate}
end{enumerate}
section{Answers}
showanskey[colback=yellow!30!white]{Multiple Choice Keys}{mchoice}[5]
showanskey[colback=yellow!30!white]{Solution Worksheet}{Worksheet}[2]
section{Normal enumerate}
begin{enumerate}
item First level
begin{enumerate}
item Second level
item value
item begin{enumerate}
item Third level
item value
end{enumerate}
end{enumerate}
end{enumerate}
end{document}
How can i fix this?
Grateful
enumitem xparse grouping key-value
add a comment |
I have a small problem when trying to keep a key locally using enumerate from the enumitem
package. I have redefined the environment enumerate
to accept the key columns
and I have created commands that are of my interest keyans[...]
, answer{...}
and showanskey[...]{...}{...}[...]
which I use to save the multiple choice keys and worksheet exercise , all well except that when activate the columns
in the first level of enumerate
, it affects all the levels nested in it.
If I put in all sublevels columns=1
I can skip the problem, but, I can not do this within the showanskey
.
When using columns=1
in the first level it looks like this:
and when using columns=2
in the first level it looks like this:
What 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 MWE:
% arara: pdflatex
% arara: clean: { extensions: [ aux, log] }
documentclass{article}
usepackage{letltxmacro,enumitem,multicol,xparse}
usepackage[most]{tcolorbox}
usepackage[margin=0.6in,noheadfoot,papersize={8.5in,13in}]{geometry} % for mwe
setlength{parindent}{0pt}
pagestyle{empty}
% Set keys for save-ans, save-key and columns for enumitem
SetEnumitemKey{save-ans}{before={storecurrentid{#1}begin{saveanswer}{#1}},after=end{saveanswer}}%
SetEnumitemKey{save-key}{before={storecurrentid{#1}begin{savekeyans}{#1}},after=end{savekeyans}}%
% Save a copy enumerate
LetLtxMacrooldenumenumerate
LetLtxMacrooldendenumendenumerate
% Redefine enumerate for multicols
ExplSyntaxOn
RenewDocumentEnvironment{enumerate}{ O{} }
{
tl_clear:N l_keyanswer_enumitem_tl
keys_set:nn { keyanswer } { #1 }
int_compare:nT { l_keyanswer_columns_tl > 1 }
{
setlength{multicolsep}{5.0pt plus 2.0pt minus 1.5pt}
begin{multicols}{ l_keyanswer_columns_tl }
}
keyanswer_beginenum:V l_keyanswer_enumitem_tl
}
{
oldendenum
int_compare:nT { l_keyanswer_columns_tl > 1 }
{ end{multicols} }
}
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[...]
NewDocumentEnvironment{saveanswer}{ 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 }
NewDocumentEnvironment{savekeyans}{ 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[...]
NewDocumentCommand{answer}{ +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 Alph{enumii}}%
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
newcommand{stepdownlevel}{%
seq_gput_right:cn {l_keyanswer_data_ retrievecurrentid _seq} {item begin{enumerate}}
}
newcommand{stepuplevel}{%
seq_gput_right:cn {l_keyanswer_data_ retrievecurrentid _seq} {end{enumerate}}
}
% 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*.}%
begin{enumerate}[#2] smallsetlength{columnsep}{0pt}
seq_map_inline:cn { l_keyanswer_data_#1_seq } { ##1 }
end{enumerate}
}
}
ExplSyntaxOff
% showanskey[tcolorbox]{title}{list ref}[columns]
DeclareTotalTColorBox{showanskey}{O{} m m O{4}}
{ 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{#3}{columns=#4} }%
begin{document}
section{Multiple Choice}
begin{enumerate}[save-key=mchoice,left=0pt]
item First type of questions
begin{enumerate}
item value
item value
item value
item correct keyans
item value
end{enumerate}
item Second type of questions
begin{enumerate}[leftmargin=2pc,label=Roman*.]
item $2alpha+2delta=90^{circ}$
item $alpha=delta$
item $angle EDF=45^{circ}$
end{enumerate}
begin{enumerate}[columns=2]%
item I only
item II only keyans
item I and II only
item I and III only
item I, II, and III
end{enumerate}
%columnbreak %
item Third type of questions
begin{enumerate}[leftmargin=2pc,label=(arabic*)]
item $2alpha+2delta=90^{circ}$
item $angle EDF=45^{circ}$
end{enumerate}
begin{enumerate}
item Altenativa A
item Altenativa B
item Altenativa C keyans
item Altenativa D
item Altenativa E
end{enumerate}
item Fourth type of question, a problem with numerical response keyans[$sqrt{2}$]
end{enumerate}
section{Worksheet}
begin{enumerate}[save-ans=Worksheet,left=0pt,labelsep=5pt,nosep,label=arabic*.]
item Factor $x^{2}-2x+1$ answer{$left(x-1right)^{2}$}
item Factor $3x+3y+3z$ answer{$3(x+y+z)$}
item True False
begin{enumerate}
item $alpha > delta$ answer{False}
item LaTeX2e is cool? answer{Very True!}
end{enumerate}
item Related to Linux
begin{enumerate}
item You use linux? answer{Yes}
item Usually uses the package manager? answer{Yes}
item Rate the following package managers
begin{enumerate}
item dnf answer{good}
item apt answer{very good}
item yum answer{obsolete}
end{enumerate}
end{enumerate}
end{enumerate}
section{Answers}
showanskey[colback=yellow!30!white]{Multiple Choice Keys}{mchoice}[5]
showanskey[colback=yellow!30!white]{Solution Worksheet}{Worksheet}[2]
section{Normal enumerate}
begin{enumerate}
item First level
begin{enumerate}
item Second level
item value
item begin{enumerate}
item Third level
item value
end{enumerate}
end{enumerate}
end{enumerate}
end{document}
How can i fix this?
Grateful
enumitem xparse grouping key-value
add a comment |
I have a small problem when trying to keep a key locally using enumerate from the enumitem
package. I have redefined the environment enumerate
to accept the key columns
and I have created commands that are of my interest keyans[...]
, answer{...}
and showanskey[...]{...}{...}[...]
which I use to save the multiple choice keys and worksheet exercise , all well except that when activate the columns
in the first level of enumerate
, it affects all the levels nested in it.
If I put in all sublevels columns=1
I can skip the problem, but, I can not do this within the showanskey
.
When using columns=1
in the first level it looks like this:
and when using columns=2
in the first level it looks like this:
What 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 MWE:
% arara: pdflatex
% arara: clean: { extensions: [ aux, log] }
documentclass{article}
usepackage{letltxmacro,enumitem,multicol,xparse}
usepackage[most]{tcolorbox}
usepackage[margin=0.6in,noheadfoot,papersize={8.5in,13in}]{geometry} % for mwe
setlength{parindent}{0pt}
pagestyle{empty}
% Set keys for save-ans, save-key and columns for enumitem
SetEnumitemKey{save-ans}{before={storecurrentid{#1}begin{saveanswer}{#1}},after=end{saveanswer}}%
SetEnumitemKey{save-key}{before={storecurrentid{#1}begin{savekeyans}{#1}},after=end{savekeyans}}%
% Save a copy enumerate
LetLtxMacrooldenumenumerate
LetLtxMacrooldendenumendenumerate
% Redefine enumerate for multicols
ExplSyntaxOn
RenewDocumentEnvironment{enumerate}{ O{} }
{
tl_clear:N l_keyanswer_enumitem_tl
keys_set:nn { keyanswer } { #1 }
int_compare:nT { l_keyanswer_columns_tl > 1 }
{
setlength{multicolsep}{5.0pt plus 2.0pt minus 1.5pt}
begin{multicols}{ l_keyanswer_columns_tl }
}
keyanswer_beginenum:V l_keyanswer_enumitem_tl
}
{
oldendenum
int_compare:nT { l_keyanswer_columns_tl > 1 }
{ end{multicols} }
}
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[...]
NewDocumentEnvironment{saveanswer}{ 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 }
NewDocumentEnvironment{savekeyans}{ 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[...]
NewDocumentCommand{answer}{ +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 Alph{enumii}}%
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
newcommand{stepdownlevel}{%
seq_gput_right:cn {l_keyanswer_data_ retrievecurrentid _seq} {item begin{enumerate}}
}
newcommand{stepuplevel}{%
seq_gput_right:cn {l_keyanswer_data_ retrievecurrentid _seq} {end{enumerate}}
}
% 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*.}%
begin{enumerate}[#2] smallsetlength{columnsep}{0pt}
seq_map_inline:cn { l_keyanswer_data_#1_seq } { ##1 }
end{enumerate}
}
}
ExplSyntaxOff
% showanskey[tcolorbox]{title}{list ref}[columns]
DeclareTotalTColorBox{showanskey}{O{} m m O{4}}
{ 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{#3}{columns=#4} }%
begin{document}
section{Multiple Choice}
begin{enumerate}[save-key=mchoice,left=0pt]
item First type of questions
begin{enumerate}
item value
item value
item value
item correct keyans
item value
end{enumerate}
item Second type of questions
begin{enumerate}[leftmargin=2pc,label=Roman*.]
item $2alpha+2delta=90^{circ}$
item $alpha=delta$
item $angle EDF=45^{circ}$
end{enumerate}
begin{enumerate}[columns=2]%
item I only
item II only keyans
item I and II only
item I and III only
item I, II, and III
end{enumerate}
%columnbreak %
item Third type of questions
begin{enumerate}[leftmargin=2pc,label=(arabic*)]
item $2alpha+2delta=90^{circ}$
item $angle EDF=45^{circ}$
end{enumerate}
begin{enumerate}
item Altenativa A
item Altenativa B
item Altenativa C keyans
item Altenativa D
item Altenativa E
end{enumerate}
item Fourth type of question, a problem with numerical response keyans[$sqrt{2}$]
end{enumerate}
section{Worksheet}
begin{enumerate}[save-ans=Worksheet,left=0pt,labelsep=5pt,nosep,label=arabic*.]
item Factor $x^{2}-2x+1$ answer{$left(x-1right)^{2}$}
item Factor $3x+3y+3z$ answer{$3(x+y+z)$}
item True False
begin{enumerate}
item $alpha > delta$ answer{False}
item LaTeX2e is cool? answer{Very True!}
end{enumerate}
item Related to Linux
begin{enumerate}
item You use linux? answer{Yes}
item Usually uses the package manager? answer{Yes}
item Rate the following package managers
begin{enumerate}
item dnf answer{good}
item apt answer{very good}
item yum answer{obsolete}
end{enumerate}
end{enumerate}
end{enumerate}
section{Answers}
showanskey[colback=yellow!30!white]{Multiple Choice Keys}{mchoice}[5]
showanskey[colback=yellow!30!white]{Solution Worksheet}{Worksheet}[2]
section{Normal enumerate}
begin{enumerate}
item First level
begin{enumerate}
item Second level
item value
item begin{enumerate}
item Third level
item value
end{enumerate}
end{enumerate}
end{enumerate}
end{document}
How can i fix this?
Grateful
enumitem xparse grouping key-value
I have a small problem when trying to keep a key locally using enumerate from the enumitem
package. I have redefined the environment enumerate
to accept the key columns
and I have created commands that are of my interest keyans[...]
, answer{...}
and showanskey[...]{...}{...}[...]
which I use to save the multiple choice keys and worksheet exercise , all well except that when activate the columns
in the first level of enumerate
, it affects all the levels nested in it.
If I put in all sublevels columns=1
I can skip the problem, but, I can not do this within the showanskey
.
When using columns=1
in the first level it looks like this:
and when using columns=2
in the first level it looks like this:
What 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 MWE:
% arara: pdflatex
% arara: clean: { extensions: [ aux, log] }
documentclass{article}
usepackage{letltxmacro,enumitem,multicol,xparse}
usepackage[most]{tcolorbox}
usepackage[margin=0.6in,noheadfoot,papersize={8.5in,13in}]{geometry} % for mwe
setlength{parindent}{0pt}
pagestyle{empty}
% Set keys for save-ans, save-key and columns for enumitem
SetEnumitemKey{save-ans}{before={storecurrentid{#1}begin{saveanswer}{#1}},after=end{saveanswer}}%
SetEnumitemKey{save-key}{before={storecurrentid{#1}begin{savekeyans}{#1}},after=end{savekeyans}}%
% Save a copy enumerate
LetLtxMacrooldenumenumerate
LetLtxMacrooldendenumendenumerate
% Redefine enumerate for multicols
ExplSyntaxOn
RenewDocumentEnvironment{enumerate}{ O{} }
{
tl_clear:N l_keyanswer_enumitem_tl
keys_set:nn { keyanswer } { #1 }
int_compare:nT { l_keyanswer_columns_tl > 1 }
{
setlength{multicolsep}{5.0pt plus 2.0pt minus 1.5pt}
begin{multicols}{ l_keyanswer_columns_tl }
}
keyanswer_beginenum:V l_keyanswer_enumitem_tl
}
{
oldendenum
int_compare:nT { l_keyanswer_columns_tl > 1 }
{ end{multicols} }
}
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[...]
NewDocumentEnvironment{saveanswer}{ 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 }
NewDocumentEnvironment{savekeyans}{ 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[...]
NewDocumentCommand{answer}{ +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 Alph{enumii}}%
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
newcommand{stepdownlevel}{%
seq_gput_right:cn {l_keyanswer_data_ retrievecurrentid _seq} {item begin{enumerate}}
}
newcommand{stepuplevel}{%
seq_gput_right:cn {l_keyanswer_data_ retrievecurrentid _seq} {end{enumerate}}
}
% 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*.}%
begin{enumerate}[#2] smallsetlength{columnsep}{0pt}
seq_map_inline:cn { l_keyanswer_data_#1_seq } { ##1 }
end{enumerate}
}
}
ExplSyntaxOff
% showanskey[tcolorbox]{title}{list ref}[columns]
DeclareTotalTColorBox{showanskey}{O{} m m O{4}}
{ 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{#3}{columns=#4} }%
begin{document}
section{Multiple Choice}
begin{enumerate}[save-key=mchoice,left=0pt]
item First type of questions
begin{enumerate}
item value
item value
item value
item correct keyans
item value
end{enumerate}
item Second type of questions
begin{enumerate}[leftmargin=2pc,label=Roman*.]
item $2alpha+2delta=90^{circ}$
item $alpha=delta$
item $angle EDF=45^{circ}$
end{enumerate}
begin{enumerate}[columns=2]%
item I only
item II only keyans
item I and II only
item I and III only
item I, II, and III
end{enumerate}
%columnbreak %
item Third type of questions
begin{enumerate}[leftmargin=2pc,label=(arabic*)]
item $2alpha+2delta=90^{circ}$
item $angle EDF=45^{circ}$
end{enumerate}
begin{enumerate}
item Altenativa A
item Altenativa B
item Altenativa C keyans
item Altenativa D
item Altenativa E
end{enumerate}
item Fourth type of question, a problem with numerical response keyans[$sqrt{2}$]
end{enumerate}
section{Worksheet}
begin{enumerate}[save-ans=Worksheet,left=0pt,labelsep=5pt,nosep,label=arabic*.]
item Factor $x^{2}-2x+1$ answer{$left(x-1right)^{2}$}
item Factor $3x+3y+3z$ answer{$3(x+y+z)$}
item True False
begin{enumerate}
item $alpha > delta$ answer{False}
item LaTeX2e is cool? answer{Very True!}
end{enumerate}
item Related to Linux
begin{enumerate}
item You use linux? answer{Yes}
item Usually uses the package manager? answer{Yes}
item Rate the following package managers
begin{enumerate}
item dnf answer{good}
item apt answer{very good}
item yum answer{obsolete}
end{enumerate}
end{enumerate}
end{enumerate}
section{Answers}
showanskey[colback=yellow!30!white]{Multiple Choice Keys}{mchoice}[5]
showanskey[colback=yellow!30!white]{Solution Worksheet}{Worksheet}[2]
section{Normal enumerate}
begin{enumerate}
item First level
begin{enumerate}
item Second level
item value
item begin{enumerate}
item Third level
item value
end{enumerate}
end{enumerate}
end{enumerate}
end{document}
How can i fix this?
Grateful
enumitem xparse grouping key-value
enumitem xparse grouping key-value
asked 30 secs ago
Pablo González LPablo González L
9991720
9991720
add a comment |
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');
});
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
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');
});
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