How to fix an Answer Key code in a particular case of random answer exam? (See more)
The essentials of the code below have been suggested at link.
As you can see, the command set to answerkey is working cumulatively. How to fix it?
documentclass{article}
usepackage{xparse,environ,enumitem}
ExplSyntaxOn
NewEnviron{randomList}[1]
{
keys_set:nn { lucas/randomlist } { #1 }
lucas_randomlist:V BODY
}
NewDocumentCommand{answerkey}{}
{
subsubsection*{Answer ~ key}
begin{enumerate}[nosep]
seq_map_inline:Nn g_lucas_randomlist_answers_seq { item ##1 }
end{enumerate}
}
NewDocumentCommand{correct}{}
{
seq_gput_right:Nx g_lucas_randomlist_answers_seq { use:c { @currentlabel } }
}
keys_define:nn { lucas/randomlist }
{
environment .tl_set:N = l__lucas_randomlist_env_tl,
seed .code:n = sys_gset_rand_seed:n { #1 },
}
seq_new:N g_lucas_randomlist_answers_seq
cs_new_protected:Nn lucas_randomlist:n
{
seq_set_split:Nnn l__lucas_randomlist_items_seq { item } { #1 }
% discard the empty first item
seq_pop_left:NN l__lucas_randomlist_items_seq l_tmpa_tl
seq_shuffle:N l__lucas_randomlist_items_seq
begin{l__lucas_randomlist_env_tl}
item seq_use:Nn l__lucas_randomlist_items_seq { item }
end{l__lucas_randomlist_env_tl}
}
cs_generate_variant:Nn lucas_randomlist:n { V }
ExplSyntaxOff
newlist{Testlist}{enumerate}{1}
setlist[Testlist]{label*=alph*.}
setlist{nosep}parindent=0pt% for more compact output
usepackage{pgfplotstable}
% from https://tex.stackexchange.com/a/445369/121799
newcommand*{ReadOutElement}[4]{%
pgfplotstablegetelem{#2}{#3}of{#1}%
let#4pgfplotsretval
}
usepackage{filecontents}
begin{filecontents*}{students.csv}
name
{Student 1}
{Student 2}
{Student 3}
end{filecontents*}
begin{document}
pgfplotstableread{students.csv}loadedtable
pgfplotstablegetrowsof{loadedtable}
pgfmathtruncatemacro{rownum}{pgfplotsretval-1}
foreach X in {0,...,rownum}
{ReadOutElement{loadedtable}{X}{name}{tmpname}
xdefmyname{tmpname}
begin{center}
myname
end{center}
begin{enumerate} % outer list of exercises
item First exercise
begin{randomList}[environment=Testlist]
itemcorrect 1
item 2
item 3
item 4
item 5
end{randomList}
item Second exercise
begin{randomList}[environment=Testlist]
item 1
itemcorrect 2
item 3
item 4
item 5
end{randomList}
answerkey
}
end{document}
enumerate random
New contributor
add a comment |
The essentials of the code below have been suggested at link.
As you can see, the command set to answerkey is working cumulatively. How to fix it?
documentclass{article}
usepackage{xparse,environ,enumitem}
ExplSyntaxOn
NewEnviron{randomList}[1]
{
keys_set:nn { lucas/randomlist } { #1 }
lucas_randomlist:V BODY
}
NewDocumentCommand{answerkey}{}
{
subsubsection*{Answer ~ key}
begin{enumerate}[nosep]
seq_map_inline:Nn g_lucas_randomlist_answers_seq { item ##1 }
end{enumerate}
}
NewDocumentCommand{correct}{}
{
seq_gput_right:Nx g_lucas_randomlist_answers_seq { use:c { @currentlabel } }
}
keys_define:nn { lucas/randomlist }
{
environment .tl_set:N = l__lucas_randomlist_env_tl,
seed .code:n = sys_gset_rand_seed:n { #1 },
}
seq_new:N g_lucas_randomlist_answers_seq
cs_new_protected:Nn lucas_randomlist:n
{
seq_set_split:Nnn l__lucas_randomlist_items_seq { item } { #1 }
% discard the empty first item
seq_pop_left:NN l__lucas_randomlist_items_seq l_tmpa_tl
seq_shuffle:N l__lucas_randomlist_items_seq
begin{l__lucas_randomlist_env_tl}
item seq_use:Nn l__lucas_randomlist_items_seq { item }
end{l__lucas_randomlist_env_tl}
}
cs_generate_variant:Nn lucas_randomlist:n { V }
ExplSyntaxOff
newlist{Testlist}{enumerate}{1}
setlist[Testlist]{label*=alph*.}
setlist{nosep}parindent=0pt% for more compact output
usepackage{pgfplotstable}
% from https://tex.stackexchange.com/a/445369/121799
newcommand*{ReadOutElement}[4]{%
pgfplotstablegetelem{#2}{#3}of{#1}%
let#4pgfplotsretval
}
usepackage{filecontents}
begin{filecontents*}{students.csv}
name
{Student 1}
{Student 2}
{Student 3}
end{filecontents*}
begin{document}
pgfplotstableread{students.csv}loadedtable
pgfplotstablegetrowsof{loadedtable}
pgfmathtruncatemacro{rownum}{pgfplotsretval-1}
foreach X in {0,...,rownum}
{ReadOutElement{loadedtable}{X}{name}{tmpname}
xdefmyname{tmpname}
begin{center}
myname
end{center}
begin{enumerate} % outer list of exercises
item First exercise
begin{randomList}[environment=Testlist]
itemcorrect 1
item 2
item 3
item 4
item 5
end{randomList}
item Second exercise
begin{randomList}[environment=Testlist]
item 1
itemcorrect 2
item 3
item 4
item 5
end{randomList}
answerkey
}
end{document}
enumerate random
New contributor
add a comment |
The essentials of the code below have been suggested at link.
As you can see, the command set to answerkey is working cumulatively. How to fix it?
documentclass{article}
usepackage{xparse,environ,enumitem}
ExplSyntaxOn
NewEnviron{randomList}[1]
{
keys_set:nn { lucas/randomlist } { #1 }
lucas_randomlist:V BODY
}
NewDocumentCommand{answerkey}{}
{
subsubsection*{Answer ~ key}
begin{enumerate}[nosep]
seq_map_inline:Nn g_lucas_randomlist_answers_seq { item ##1 }
end{enumerate}
}
NewDocumentCommand{correct}{}
{
seq_gput_right:Nx g_lucas_randomlist_answers_seq { use:c { @currentlabel } }
}
keys_define:nn { lucas/randomlist }
{
environment .tl_set:N = l__lucas_randomlist_env_tl,
seed .code:n = sys_gset_rand_seed:n { #1 },
}
seq_new:N g_lucas_randomlist_answers_seq
cs_new_protected:Nn lucas_randomlist:n
{
seq_set_split:Nnn l__lucas_randomlist_items_seq { item } { #1 }
% discard the empty first item
seq_pop_left:NN l__lucas_randomlist_items_seq l_tmpa_tl
seq_shuffle:N l__lucas_randomlist_items_seq
begin{l__lucas_randomlist_env_tl}
item seq_use:Nn l__lucas_randomlist_items_seq { item }
end{l__lucas_randomlist_env_tl}
}
cs_generate_variant:Nn lucas_randomlist:n { V }
ExplSyntaxOff
newlist{Testlist}{enumerate}{1}
setlist[Testlist]{label*=alph*.}
setlist{nosep}parindent=0pt% for more compact output
usepackage{pgfplotstable}
% from https://tex.stackexchange.com/a/445369/121799
newcommand*{ReadOutElement}[4]{%
pgfplotstablegetelem{#2}{#3}of{#1}%
let#4pgfplotsretval
}
usepackage{filecontents}
begin{filecontents*}{students.csv}
name
{Student 1}
{Student 2}
{Student 3}
end{filecontents*}
begin{document}
pgfplotstableread{students.csv}loadedtable
pgfplotstablegetrowsof{loadedtable}
pgfmathtruncatemacro{rownum}{pgfplotsretval-1}
foreach X in {0,...,rownum}
{ReadOutElement{loadedtable}{X}{name}{tmpname}
xdefmyname{tmpname}
begin{center}
myname
end{center}
begin{enumerate} % outer list of exercises
item First exercise
begin{randomList}[environment=Testlist]
itemcorrect 1
item 2
item 3
item 4
item 5
end{randomList}
item Second exercise
begin{randomList}[environment=Testlist]
item 1
itemcorrect 2
item 3
item 4
item 5
end{randomList}
answerkey
}
end{document}
enumerate random
New contributor
The essentials of the code below have been suggested at link.
As you can see, the command set to answerkey is working cumulatively. How to fix it?
documentclass{article}
usepackage{xparse,environ,enumitem}
ExplSyntaxOn
NewEnviron{randomList}[1]
{
keys_set:nn { lucas/randomlist } { #1 }
lucas_randomlist:V BODY
}
NewDocumentCommand{answerkey}{}
{
subsubsection*{Answer ~ key}
begin{enumerate}[nosep]
seq_map_inline:Nn g_lucas_randomlist_answers_seq { item ##1 }
end{enumerate}
}
NewDocumentCommand{correct}{}
{
seq_gput_right:Nx g_lucas_randomlist_answers_seq { use:c { @currentlabel } }
}
keys_define:nn { lucas/randomlist }
{
environment .tl_set:N = l__lucas_randomlist_env_tl,
seed .code:n = sys_gset_rand_seed:n { #1 },
}
seq_new:N g_lucas_randomlist_answers_seq
cs_new_protected:Nn lucas_randomlist:n
{
seq_set_split:Nnn l__lucas_randomlist_items_seq { item } { #1 }
% discard the empty first item
seq_pop_left:NN l__lucas_randomlist_items_seq l_tmpa_tl
seq_shuffle:N l__lucas_randomlist_items_seq
begin{l__lucas_randomlist_env_tl}
item seq_use:Nn l__lucas_randomlist_items_seq { item }
end{l__lucas_randomlist_env_tl}
}
cs_generate_variant:Nn lucas_randomlist:n { V }
ExplSyntaxOff
newlist{Testlist}{enumerate}{1}
setlist[Testlist]{label*=alph*.}
setlist{nosep}parindent=0pt% for more compact output
usepackage{pgfplotstable}
% from https://tex.stackexchange.com/a/445369/121799
newcommand*{ReadOutElement}[4]{%
pgfplotstablegetelem{#2}{#3}of{#1}%
let#4pgfplotsretval
}
usepackage{filecontents}
begin{filecontents*}{students.csv}
name
{Student 1}
{Student 2}
{Student 3}
end{filecontents*}
begin{document}
pgfplotstableread{students.csv}loadedtable
pgfplotstablegetrowsof{loadedtable}
pgfmathtruncatemacro{rownum}{pgfplotsretval-1}
foreach X in {0,...,rownum}
{ReadOutElement{loadedtable}{X}{name}{tmpname}
xdefmyname{tmpname}
begin{center}
myname
end{center}
begin{enumerate} % outer list of exercises
item First exercise
begin{randomList}[environment=Testlist]
itemcorrect 1
item 2
item 3
item 4
item 5
end{randomList}
item Second exercise
begin{randomList}[environment=Testlist]
item 1
itemcorrect 2
item 3
item 4
item 5
end{randomList}
answerkey
}
end{document}
enumerate random
enumerate random
New contributor
New contributor
edited 44 secs ago
New contributor
asked 7 mins ago
Lucas Martins
975
975
New contributor
New contributor
add a comment |
add a comment |
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
});
}
});
Lucas Martins is a new contributor. Be nice, and check out our Code of Conduct.
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%2f467110%2fhow-to-fix-an-answer-key-code-in-a-particular-case-of-random-answer-exam-see-m%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Lucas Martins is a new contributor. Be nice, and check out our Code of Conduct.
Lucas Martins is a new contributor. Be nice, and check out our Code of Conduct.
Lucas Martins is a new contributor. Be nice, and check out our Code of Conduct.
Lucas Martins is a new contributor. Be nice, and check out our Code of Conduct.
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f467110%2fhow-to-fix-an-answer-key-code-in-a-particular-case-of-random-answer-exam-see-m%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