Section with answers created automatically
My question is quite similar to this one, but I think a slightly different approach is needed.
I have a document with a lot of exercices and I'd like to add aswers and hints to them in a certain section.
I don't want to do this manually, since, if I add an exercice, I'll have to make that the answers and hints keep the right order. Also, it's possible that not all exercices have an answer and a hint with them, so the numbering of answers and hints should be completely dependent of the numbering of exercices.
I.e, things like
1. Some hint for exercice 1
2. Some hint for exercice 2
4. Some hint for exercice 4
99. Some hint for exercice 99
should be possible.
For example:
documentclass[12pt,a4paper]{article}
usepackage[dutch]{babel}
usepackage{amsthm}
newtheorem{ex}{Exercice}
newtheorem{ans}{} % Abbreviation for answer. No text needed because I just want numbers with the answers next to them.
newtheorem{hi}{} % Same here.
begin{document}
section{Algebra}
begin{ex}What is $1+3$?end{ex}
begin{hi}First consider $1+0$, $1+1$, $1+2$ and try to find a pattern.end{hi}
begin{ans}It's $4$!end{ans}
section{Grammar}
setcounter{ex}{0} % So the counter is set to zero when a new section begins.
begin{ex}The first letter of the alphabet?end{ex}
%No hint given here
begin{ans}Aend{ans}
section*{Answers}
subsection{Section Algebra}
%Answer should be here, but of course it isn't.
subsection{Section Grammar}
%Same.
section*{Hints}
subsection{Section Algebra}
%Hint here.
subsection{Section Grammar}
% No hint because I didn't ask Latex to do so.
end{document}
So in fact I need some magicCommandThatPutsAnswersAndHintsSomewhereElse
. If there's more then one answer in a section, I'd like them to be numbered like theorems.
As you may have noticed in the example, I want the answers and hints in a subsection that refers to their section.
numbering theorems
|
show 2 more comments
My question is quite similar to this one, but I think a slightly different approach is needed.
I have a document with a lot of exercices and I'd like to add aswers and hints to them in a certain section.
I don't want to do this manually, since, if I add an exercice, I'll have to make that the answers and hints keep the right order. Also, it's possible that not all exercices have an answer and a hint with them, so the numbering of answers and hints should be completely dependent of the numbering of exercices.
I.e, things like
1. Some hint for exercice 1
2. Some hint for exercice 2
4. Some hint for exercice 4
99. Some hint for exercice 99
should be possible.
For example:
documentclass[12pt,a4paper]{article}
usepackage[dutch]{babel}
usepackage{amsthm}
newtheorem{ex}{Exercice}
newtheorem{ans}{} % Abbreviation for answer. No text needed because I just want numbers with the answers next to them.
newtheorem{hi}{} % Same here.
begin{document}
section{Algebra}
begin{ex}What is $1+3$?end{ex}
begin{hi}First consider $1+0$, $1+1$, $1+2$ and try to find a pattern.end{hi}
begin{ans}It's $4$!end{ans}
section{Grammar}
setcounter{ex}{0} % So the counter is set to zero when a new section begins.
begin{ex}The first letter of the alphabet?end{ex}
%No hint given here
begin{ans}Aend{ans}
section*{Answers}
subsection{Section Algebra}
%Answer should be here, but of course it isn't.
subsection{Section Grammar}
%Same.
section*{Hints}
subsection{Section Algebra}
%Hint here.
subsection{Section Grammar}
% No hint because I didn't ask Latex to do so.
end{document}
So in fact I need some magicCommandThatPutsAnswersAndHintsSomewhereElse
. If there's more then one answer in a section, I'd like them to be numbered like theorems.
As you may have noticed in the example, I want the answers and hints in a subsection that refers to their section.
numbering theorems
3
I've done this for my book. I could show you the code (email me if you want) but basically: to output answers to somewhere else I used the answers package and to refer to things in the main text from the answers file I used the xr package. (Also, there is a counter giving the current exercise number and you can define the environment ans to start with textbf{that counter} so your answer file is not just taking the answer numbers in ascending order.)
– Jim Hefferon
Aug 21 '13 at 11:31
@JimHefferon that sounds useful - and also suggests a possible solution for non-broken hyperref endnotes...
– Joe Corneli
Aug 21 '13 at 13:18
@JimHefferon thanks, I'll first try myself to fix it using answers and xr, and I'll report back when I have some results.
– rabota
Aug 21 '13 at 15:26
@JimHefferon I'm just wondering: what exactly did you need the xr package for? It seems like I can freely refer to labels in the main text from the answers. When I refer from the main text to the answers, it seems that the answers are simply numbered continuously, but the number that is displayed is the same as the corresponding exercise. For example if I number the answers per sections like 1.1, 1.2, 2.1, 2.2 the answers are 'labeled' 1, 2, 3, 4 while the displayed numbering is really 1.1, 1.2, 2.1, 2.2.
– rabota
Jun 25 '14 at 13:01
I allow for something more complicated that sequentially numbered exercises. For instance, I allow for the publication of a list of answers of the questions that are checkmarked. (I also number the exercises in sequence with the theorems.)
– Jim Hefferon
Jun 25 '14 at 19:54
|
show 2 more comments
My question is quite similar to this one, but I think a slightly different approach is needed.
I have a document with a lot of exercices and I'd like to add aswers and hints to them in a certain section.
I don't want to do this manually, since, if I add an exercice, I'll have to make that the answers and hints keep the right order. Also, it's possible that not all exercices have an answer and a hint with them, so the numbering of answers and hints should be completely dependent of the numbering of exercices.
I.e, things like
1. Some hint for exercice 1
2. Some hint for exercice 2
4. Some hint for exercice 4
99. Some hint for exercice 99
should be possible.
For example:
documentclass[12pt,a4paper]{article}
usepackage[dutch]{babel}
usepackage{amsthm}
newtheorem{ex}{Exercice}
newtheorem{ans}{} % Abbreviation for answer. No text needed because I just want numbers with the answers next to them.
newtheorem{hi}{} % Same here.
begin{document}
section{Algebra}
begin{ex}What is $1+3$?end{ex}
begin{hi}First consider $1+0$, $1+1$, $1+2$ and try to find a pattern.end{hi}
begin{ans}It's $4$!end{ans}
section{Grammar}
setcounter{ex}{0} % So the counter is set to zero when a new section begins.
begin{ex}The first letter of the alphabet?end{ex}
%No hint given here
begin{ans}Aend{ans}
section*{Answers}
subsection{Section Algebra}
%Answer should be here, but of course it isn't.
subsection{Section Grammar}
%Same.
section*{Hints}
subsection{Section Algebra}
%Hint here.
subsection{Section Grammar}
% No hint because I didn't ask Latex to do so.
end{document}
So in fact I need some magicCommandThatPutsAnswersAndHintsSomewhereElse
. If there's more then one answer in a section, I'd like them to be numbered like theorems.
As you may have noticed in the example, I want the answers and hints in a subsection that refers to their section.
numbering theorems
My question is quite similar to this one, but I think a slightly different approach is needed.
I have a document with a lot of exercices and I'd like to add aswers and hints to them in a certain section.
I don't want to do this manually, since, if I add an exercice, I'll have to make that the answers and hints keep the right order. Also, it's possible that not all exercices have an answer and a hint with them, so the numbering of answers and hints should be completely dependent of the numbering of exercices.
I.e, things like
1. Some hint for exercice 1
2. Some hint for exercice 2
4. Some hint for exercice 4
99. Some hint for exercice 99
should be possible.
For example:
documentclass[12pt,a4paper]{article}
usepackage[dutch]{babel}
usepackage{amsthm}
newtheorem{ex}{Exercice}
newtheorem{ans}{} % Abbreviation for answer. No text needed because I just want numbers with the answers next to them.
newtheorem{hi}{} % Same here.
begin{document}
section{Algebra}
begin{ex}What is $1+3$?end{ex}
begin{hi}First consider $1+0$, $1+1$, $1+2$ and try to find a pattern.end{hi}
begin{ans}It's $4$!end{ans}
section{Grammar}
setcounter{ex}{0} % So the counter is set to zero when a new section begins.
begin{ex}The first letter of the alphabet?end{ex}
%No hint given here
begin{ans}Aend{ans}
section*{Answers}
subsection{Section Algebra}
%Answer should be here, but of course it isn't.
subsection{Section Grammar}
%Same.
section*{Hints}
subsection{Section Algebra}
%Hint here.
subsection{Section Grammar}
% No hint because I didn't ask Latex to do so.
end{document}
So in fact I need some magicCommandThatPutsAnswersAndHintsSomewhereElse
. If there's more then one answer in a section, I'd like them to be numbered like theorems.
As you may have noticed in the example, I want the answers and hints in a subsection that refers to their section.
numbering theorems
numbering theorems
edited Apr 13 '17 at 12:34
Community♦
1
1
asked Aug 21 '13 at 10:48
rabotarabota
619715
619715
3
I've done this for my book. I could show you the code (email me if you want) but basically: to output answers to somewhere else I used the answers package and to refer to things in the main text from the answers file I used the xr package. (Also, there is a counter giving the current exercise number and you can define the environment ans to start with textbf{that counter} so your answer file is not just taking the answer numbers in ascending order.)
– Jim Hefferon
Aug 21 '13 at 11:31
@JimHefferon that sounds useful - and also suggests a possible solution for non-broken hyperref endnotes...
– Joe Corneli
Aug 21 '13 at 13:18
@JimHefferon thanks, I'll first try myself to fix it using answers and xr, and I'll report back when I have some results.
– rabota
Aug 21 '13 at 15:26
@JimHefferon I'm just wondering: what exactly did you need the xr package for? It seems like I can freely refer to labels in the main text from the answers. When I refer from the main text to the answers, it seems that the answers are simply numbered continuously, but the number that is displayed is the same as the corresponding exercise. For example if I number the answers per sections like 1.1, 1.2, 2.1, 2.2 the answers are 'labeled' 1, 2, 3, 4 while the displayed numbering is really 1.1, 1.2, 2.1, 2.2.
– rabota
Jun 25 '14 at 13:01
I allow for something more complicated that sequentially numbered exercises. For instance, I allow for the publication of a list of answers of the questions that are checkmarked. (I also number the exercises in sequence with the theorems.)
– Jim Hefferon
Jun 25 '14 at 19:54
|
show 2 more comments
3
I've done this for my book. I could show you the code (email me if you want) but basically: to output answers to somewhere else I used the answers package and to refer to things in the main text from the answers file I used the xr package. (Also, there is a counter giving the current exercise number and you can define the environment ans to start with textbf{that counter} so your answer file is not just taking the answer numbers in ascending order.)
– Jim Hefferon
Aug 21 '13 at 11:31
@JimHefferon that sounds useful - and also suggests a possible solution for non-broken hyperref endnotes...
– Joe Corneli
Aug 21 '13 at 13:18
@JimHefferon thanks, I'll first try myself to fix it using answers and xr, and I'll report back when I have some results.
– rabota
Aug 21 '13 at 15:26
@JimHefferon I'm just wondering: what exactly did you need the xr package for? It seems like I can freely refer to labels in the main text from the answers. When I refer from the main text to the answers, it seems that the answers are simply numbered continuously, but the number that is displayed is the same as the corresponding exercise. For example if I number the answers per sections like 1.1, 1.2, 2.1, 2.2 the answers are 'labeled' 1, 2, 3, 4 while the displayed numbering is really 1.1, 1.2, 2.1, 2.2.
– rabota
Jun 25 '14 at 13:01
I allow for something more complicated that sequentially numbered exercises. For instance, I allow for the publication of a list of answers of the questions that are checkmarked. (I also number the exercises in sequence with the theorems.)
– Jim Hefferon
Jun 25 '14 at 19:54
3
3
I've done this for my book. I could show you the code (email me if you want) but basically: to output answers to somewhere else I used the answers package and to refer to things in the main text from the answers file I used the xr package. (Also, there is a counter giving the current exercise number and you can define the environment ans to start with textbf{that counter} so your answer file is not just taking the answer numbers in ascending order.)
– Jim Hefferon
Aug 21 '13 at 11:31
I've done this for my book. I could show you the code (email me if you want) but basically: to output answers to somewhere else I used the answers package and to refer to things in the main text from the answers file I used the xr package. (Also, there is a counter giving the current exercise number and you can define the environment ans to start with textbf{that counter} so your answer file is not just taking the answer numbers in ascending order.)
– Jim Hefferon
Aug 21 '13 at 11:31
@JimHefferon that sounds useful - and also suggests a possible solution for non-broken hyperref endnotes...
– Joe Corneli
Aug 21 '13 at 13:18
@JimHefferon that sounds useful - and also suggests a possible solution for non-broken hyperref endnotes...
– Joe Corneli
Aug 21 '13 at 13:18
@JimHefferon thanks, I'll first try myself to fix it using answers and xr, and I'll report back when I have some results.
– rabota
Aug 21 '13 at 15:26
@JimHefferon thanks, I'll first try myself to fix it using answers and xr, and I'll report back when I have some results.
– rabota
Aug 21 '13 at 15:26
@JimHefferon I'm just wondering: what exactly did you need the xr package for? It seems like I can freely refer to labels in the main text from the answers. When I refer from the main text to the answers, it seems that the answers are simply numbered continuously, but the number that is displayed is the same as the corresponding exercise. For example if I number the answers per sections like 1.1, 1.2, 2.1, 2.2 the answers are 'labeled' 1, 2, 3, 4 while the displayed numbering is really 1.1, 1.2, 2.1, 2.2.
– rabota
Jun 25 '14 at 13:01
@JimHefferon I'm just wondering: what exactly did you need the xr package for? It seems like I can freely refer to labels in the main text from the answers. When I refer from the main text to the answers, it seems that the answers are simply numbered continuously, but the number that is displayed is the same as the corresponding exercise. For example if I number the answers per sections like 1.1, 1.2, 2.1, 2.2 the answers are 'labeled' 1, 2, 3, 4 while the displayed numbering is really 1.1, 1.2, 2.1, 2.2.
– rabota
Jun 25 '14 at 13:01
I allow for something more complicated that sequentially numbered exercises. For instance, I allow for the publication of a list of answers of the questions that are checkmarked. (I also number the exercises in sequence with the theorems.)
– Jim Hefferon
Jun 25 '14 at 19:54
I allow for something more complicated that sequentially numbered exercises. For instance, I allow for the publication of a list of answers of the questions that are checkmarked. (I also number the exercises in sequence with the theorems.)
– Jim Hefferon
Jun 25 '14 at 19:54
|
show 2 more comments
1 Answer
1
active
oldest
votes
I face the same issue as you do. I create my exercises lists with two features: I can print it with the answers (for students) or with the solutions (for me; in this case, the answers disappear).
I will show you here pieces of my code (it is too huge and, believe me, is not worth to paste it as a whole here). So, let's start...
I created the commands problem
where I state the problem and answer
where I store the answer to each problem, as well as the environment solution
where I store the solution to the problem (with the argument, I can set the number of columns to arrange the solution in order to make it more compact):
%-> Defining COUNTERS:
newcounter{problem}
%-> Defining the numbered environment for QUESTIONS, TESTS, EXERCISES, PROBLEMS, and CHALLENGES:
newcommand{problem}{%
parbigskip
refstepcounter{problem}
noindenttextbf{theproblem}
}
%-> Defining the environment for the ANSWERS to QUESTIONS
newcommand{answer}[1]{%
letthefootnoterelax %... suppresses the footnote numbering
footnote{textbf{theproblem-} #1}%
}
newififcols
%-> Defining the environment for the SOLUTIONS:
newenvironment{solution}[1]{%
setlength{parindent}{0cm}
vspace{-2.5mm}
textbf{footnotesize Solution:}par
vspace{-3mm}
footnotesize
ifnum #1 > 1
colstrue
begin{multicols}{#1}
fi
}{%
ifcols
end{multicols}
fi
colsfalse
}
Lattar on, I create the Boolean ifshowans
for which showanstrue
can be commented out whenever I want to hide the solution and show the answer (in case I want to prin material for the students). Otherwise, it will print the solution and hide the answers:
%-> Defining the MATERIAL TYPE:
newififshowans
showanstrue
ifshowans
renewcommandanswer[1]{}
else
letsolutioncomment
letendsolutionendcomment
fi
Up to here, you can observe that in my case, I preferred to show the solutions in the footnotes. Since you want to display them at the end of the document, you should modify the answer
command to something like this:
%-> Defining the environment for the ANSWERS to QUESTIONS
newcommand{answer}[1]{%
lettheendnoterelax %... suppresses the endnote numbering
endnote{textbf{ptype mnumber.theproblem-} #1}%
}
I hope this helps you.
Edit:
This is an example of use (my students are Brazilian, so the problems are stated in Portuguese... sorry for that):
problem
O dia 21 de dezembro marca o solstício de verão no hemisfério sul. Nesse dia do ano, as sombras das pessoas em São Paulo (SP) têm comprimento nulo. Em uma viagem a Brasília nesse dia, a sombra projetada no chão de uma pessoa em pé ao meio-dia local tem um comprimento de 23,7 cm. Sabendo que a altura da pessoa é de 1,73 m e que uma volta à Terra tem comprimento $C = 40 v{mil km}$, calcule a distância entre São Paulo e Brasília.
answer{870 km}
%---------- SOLUTION ----------%
begin{solution}{2}
Do triângulo formado pela pessoa, sua sombra e o raio de luz do Sol, tem-se
$$
tantheta = frac{23,7}{173} = 0,137
Rightarrow
theta = 7,80deg
$$
Por regra de três simples,
$$
begin{array}{rcl}
360deg & rightarrow & 40 000 v{km}
\
7,80deg & rightarrow & d
end{array}
Rightarrow
d = 870 v{km}
$$
end{solution}
Edit 2: I just removed some undefined (and meaningless) commands
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%2f129364%2fsection-with-answers-created-automatically%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
I face the same issue as you do. I create my exercises lists with two features: I can print it with the answers (for students) or with the solutions (for me; in this case, the answers disappear).
I will show you here pieces of my code (it is too huge and, believe me, is not worth to paste it as a whole here). So, let's start...
I created the commands problem
where I state the problem and answer
where I store the answer to each problem, as well as the environment solution
where I store the solution to the problem (with the argument, I can set the number of columns to arrange the solution in order to make it more compact):
%-> Defining COUNTERS:
newcounter{problem}
%-> Defining the numbered environment for QUESTIONS, TESTS, EXERCISES, PROBLEMS, and CHALLENGES:
newcommand{problem}{%
parbigskip
refstepcounter{problem}
noindenttextbf{theproblem}
}
%-> Defining the environment for the ANSWERS to QUESTIONS
newcommand{answer}[1]{%
letthefootnoterelax %... suppresses the footnote numbering
footnote{textbf{theproblem-} #1}%
}
newififcols
%-> Defining the environment for the SOLUTIONS:
newenvironment{solution}[1]{%
setlength{parindent}{0cm}
vspace{-2.5mm}
textbf{footnotesize Solution:}par
vspace{-3mm}
footnotesize
ifnum #1 > 1
colstrue
begin{multicols}{#1}
fi
}{%
ifcols
end{multicols}
fi
colsfalse
}
Lattar on, I create the Boolean ifshowans
for which showanstrue
can be commented out whenever I want to hide the solution and show the answer (in case I want to prin material for the students). Otherwise, it will print the solution and hide the answers:
%-> Defining the MATERIAL TYPE:
newififshowans
showanstrue
ifshowans
renewcommandanswer[1]{}
else
letsolutioncomment
letendsolutionendcomment
fi
Up to here, you can observe that in my case, I preferred to show the solutions in the footnotes. Since you want to display them at the end of the document, you should modify the answer
command to something like this:
%-> Defining the environment for the ANSWERS to QUESTIONS
newcommand{answer}[1]{%
lettheendnoterelax %... suppresses the endnote numbering
endnote{textbf{ptype mnumber.theproblem-} #1}%
}
I hope this helps you.
Edit:
This is an example of use (my students are Brazilian, so the problems are stated in Portuguese... sorry for that):
problem
O dia 21 de dezembro marca o solstício de verão no hemisfério sul. Nesse dia do ano, as sombras das pessoas em São Paulo (SP) têm comprimento nulo. Em uma viagem a Brasília nesse dia, a sombra projetada no chão de uma pessoa em pé ao meio-dia local tem um comprimento de 23,7 cm. Sabendo que a altura da pessoa é de 1,73 m e que uma volta à Terra tem comprimento $C = 40 v{mil km}$, calcule a distância entre São Paulo e Brasília.
answer{870 km}
%---------- SOLUTION ----------%
begin{solution}{2}
Do triângulo formado pela pessoa, sua sombra e o raio de luz do Sol, tem-se
$$
tantheta = frac{23,7}{173} = 0,137
Rightarrow
theta = 7,80deg
$$
Por regra de três simples,
$$
begin{array}{rcl}
360deg & rightarrow & 40 000 v{km}
\
7,80deg & rightarrow & d
end{array}
Rightarrow
d = 870 v{km}
$$
end{solution}
Edit 2: I just removed some undefined (and meaningless) commands
add a comment |
I face the same issue as you do. I create my exercises lists with two features: I can print it with the answers (for students) or with the solutions (for me; in this case, the answers disappear).
I will show you here pieces of my code (it is too huge and, believe me, is not worth to paste it as a whole here). So, let's start...
I created the commands problem
where I state the problem and answer
where I store the answer to each problem, as well as the environment solution
where I store the solution to the problem (with the argument, I can set the number of columns to arrange the solution in order to make it more compact):
%-> Defining COUNTERS:
newcounter{problem}
%-> Defining the numbered environment for QUESTIONS, TESTS, EXERCISES, PROBLEMS, and CHALLENGES:
newcommand{problem}{%
parbigskip
refstepcounter{problem}
noindenttextbf{theproblem}
}
%-> Defining the environment for the ANSWERS to QUESTIONS
newcommand{answer}[1]{%
letthefootnoterelax %... suppresses the footnote numbering
footnote{textbf{theproblem-} #1}%
}
newififcols
%-> Defining the environment for the SOLUTIONS:
newenvironment{solution}[1]{%
setlength{parindent}{0cm}
vspace{-2.5mm}
textbf{footnotesize Solution:}par
vspace{-3mm}
footnotesize
ifnum #1 > 1
colstrue
begin{multicols}{#1}
fi
}{%
ifcols
end{multicols}
fi
colsfalse
}
Lattar on, I create the Boolean ifshowans
for which showanstrue
can be commented out whenever I want to hide the solution and show the answer (in case I want to prin material for the students). Otherwise, it will print the solution and hide the answers:
%-> Defining the MATERIAL TYPE:
newififshowans
showanstrue
ifshowans
renewcommandanswer[1]{}
else
letsolutioncomment
letendsolutionendcomment
fi
Up to here, you can observe that in my case, I preferred to show the solutions in the footnotes. Since you want to display them at the end of the document, you should modify the answer
command to something like this:
%-> Defining the environment for the ANSWERS to QUESTIONS
newcommand{answer}[1]{%
lettheendnoterelax %... suppresses the endnote numbering
endnote{textbf{ptype mnumber.theproblem-} #1}%
}
I hope this helps you.
Edit:
This is an example of use (my students are Brazilian, so the problems are stated in Portuguese... sorry for that):
problem
O dia 21 de dezembro marca o solstício de verão no hemisfério sul. Nesse dia do ano, as sombras das pessoas em São Paulo (SP) têm comprimento nulo. Em uma viagem a Brasília nesse dia, a sombra projetada no chão de uma pessoa em pé ao meio-dia local tem um comprimento de 23,7 cm. Sabendo que a altura da pessoa é de 1,73 m e que uma volta à Terra tem comprimento $C = 40 v{mil km}$, calcule a distância entre São Paulo e Brasília.
answer{870 km}
%---------- SOLUTION ----------%
begin{solution}{2}
Do triângulo formado pela pessoa, sua sombra e o raio de luz do Sol, tem-se
$$
tantheta = frac{23,7}{173} = 0,137
Rightarrow
theta = 7,80deg
$$
Por regra de três simples,
$$
begin{array}{rcl}
360deg & rightarrow & 40 000 v{km}
\
7,80deg & rightarrow & d
end{array}
Rightarrow
d = 870 v{km}
$$
end{solution}
Edit 2: I just removed some undefined (and meaningless) commands
add a comment |
I face the same issue as you do. I create my exercises lists with two features: I can print it with the answers (for students) or with the solutions (for me; in this case, the answers disappear).
I will show you here pieces of my code (it is too huge and, believe me, is not worth to paste it as a whole here). So, let's start...
I created the commands problem
where I state the problem and answer
where I store the answer to each problem, as well as the environment solution
where I store the solution to the problem (with the argument, I can set the number of columns to arrange the solution in order to make it more compact):
%-> Defining COUNTERS:
newcounter{problem}
%-> Defining the numbered environment for QUESTIONS, TESTS, EXERCISES, PROBLEMS, and CHALLENGES:
newcommand{problem}{%
parbigskip
refstepcounter{problem}
noindenttextbf{theproblem}
}
%-> Defining the environment for the ANSWERS to QUESTIONS
newcommand{answer}[1]{%
letthefootnoterelax %... suppresses the footnote numbering
footnote{textbf{theproblem-} #1}%
}
newififcols
%-> Defining the environment for the SOLUTIONS:
newenvironment{solution}[1]{%
setlength{parindent}{0cm}
vspace{-2.5mm}
textbf{footnotesize Solution:}par
vspace{-3mm}
footnotesize
ifnum #1 > 1
colstrue
begin{multicols}{#1}
fi
}{%
ifcols
end{multicols}
fi
colsfalse
}
Lattar on, I create the Boolean ifshowans
for which showanstrue
can be commented out whenever I want to hide the solution and show the answer (in case I want to prin material for the students). Otherwise, it will print the solution and hide the answers:
%-> Defining the MATERIAL TYPE:
newififshowans
showanstrue
ifshowans
renewcommandanswer[1]{}
else
letsolutioncomment
letendsolutionendcomment
fi
Up to here, you can observe that in my case, I preferred to show the solutions in the footnotes. Since you want to display them at the end of the document, you should modify the answer
command to something like this:
%-> Defining the environment for the ANSWERS to QUESTIONS
newcommand{answer}[1]{%
lettheendnoterelax %... suppresses the endnote numbering
endnote{textbf{ptype mnumber.theproblem-} #1}%
}
I hope this helps you.
Edit:
This is an example of use (my students are Brazilian, so the problems are stated in Portuguese... sorry for that):
problem
O dia 21 de dezembro marca o solstício de verão no hemisfério sul. Nesse dia do ano, as sombras das pessoas em São Paulo (SP) têm comprimento nulo. Em uma viagem a Brasília nesse dia, a sombra projetada no chão de uma pessoa em pé ao meio-dia local tem um comprimento de 23,7 cm. Sabendo que a altura da pessoa é de 1,73 m e que uma volta à Terra tem comprimento $C = 40 v{mil km}$, calcule a distância entre São Paulo e Brasília.
answer{870 km}
%---------- SOLUTION ----------%
begin{solution}{2}
Do triângulo formado pela pessoa, sua sombra e o raio de luz do Sol, tem-se
$$
tantheta = frac{23,7}{173} = 0,137
Rightarrow
theta = 7,80deg
$$
Por regra de três simples,
$$
begin{array}{rcl}
360deg & rightarrow & 40 000 v{km}
\
7,80deg & rightarrow & d
end{array}
Rightarrow
d = 870 v{km}
$$
end{solution}
Edit 2: I just removed some undefined (and meaningless) commands
I face the same issue as you do. I create my exercises lists with two features: I can print it with the answers (for students) or with the solutions (for me; in this case, the answers disappear).
I will show you here pieces of my code (it is too huge and, believe me, is not worth to paste it as a whole here). So, let's start...
I created the commands problem
where I state the problem and answer
where I store the answer to each problem, as well as the environment solution
where I store the solution to the problem (with the argument, I can set the number of columns to arrange the solution in order to make it more compact):
%-> Defining COUNTERS:
newcounter{problem}
%-> Defining the numbered environment for QUESTIONS, TESTS, EXERCISES, PROBLEMS, and CHALLENGES:
newcommand{problem}{%
parbigskip
refstepcounter{problem}
noindenttextbf{theproblem}
}
%-> Defining the environment for the ANSWERS to QUESTIONS
newcommand{answer}[1]{%
letthefootnoterelax %... suppresses the footnote numbering
footnote{textbf{theproblem-} #1}%
}
newififcols
%-> Defining the environment for the SOLUTIONS:
newenvironment{solution}[1]{%
setlength{parindent}{0cm}
vspace{-2.5mm}
textbf{footnotesize Solution:}par
vspace{-3mm}
footnotesize
ifnum #1 > 1
colstrue
begin{multicols}{#1}
fi
}{%
ifcols
end{multicols}
fi
colsfalse
}
Lattar on, I create the Boolean ifshowans
for which showanstrue
can be commented out whenever I want to hide the solution and show the answer (in case I want to prin material for the students). Otherwise, it will print the solution and hide the answers:
%-> Defining the MATERIAL TYPE:
newififshowans
showanstrue
ifshowans
renewcommandanswer[1]{}
else
letsolutioncomment
letendsolutionendcomment
fi
Up to here, you can observe that in my case, I preferred to show the solutions in the footnotes. Since you want to display them at the end of the document, you should modify the answer
command to something like this:
%-> Defining the environment for the ANSWERS to QUESTIONS
newcommand{answer}[1]{%
lettheendnoterelax %... suppresses the endnote numbering
endnote{textbf{ptype mnumber.theproblem-} #1}%
}
I hope this helps you.
Edit:
This is an example of use (my students are Brazilian, so the problems are stated in Portuguese... sorry for that):
problem
O dia 21 de dezembro marca o solstício de verão no hemisfério sul. Nesse dia do ano, as sombras das pessoas em São Paulo (SP) têm comprimento nulo. Em uma viagem a Brasília nesse dia, a sombra projetada no chão de uma pessoa em pé ao meio-dia local tem um comprimento de 23,7 cm. Sabendo que a altura da pessoa é de 1,73 m e que uma volta à Terra tem comprimento $C = 40 v{mil km}$, calcule a distância entre São Paulo e Brasília.
answer{870 km}
%---------- SOLUTION ----------%
begin{solution}{2}
Do triângulo formado pela pessoa, sua sombra e o raio de luz do Sol, tem-se
$$
tantheta = frac{23,7}{173} = 0,137
Rightarrow
theta = 7,80deg
$$
Por regra de três simples,
$$
begin{array}{rcl}
360deg & rightarrow & 40 000 v{km}
\
7,80deg & rightarrow & d
end{array}
Rightarrow
d = 870 v{km}
$$
end{solution}
Edit 2: I just removed some undefined (and meaningless) commands
edited 3 hours ago
answered 3 hours ago
BrasilBrasil
4142412
4142412
add a comment |
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%2f129364%2fsection-with-answers-created-automatically%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
3
I've done this for my book. I could show you the code (email me if you want) but basically: to output answers to somewhere else I used the answers package and to refer to things in the main text from the answers file I used the xr package. (Also, there is a counter giving the current exercise number and you can define the environment ans to start with textbf{that counter} so your answer file is not just taking the answer numbers in ascending order.)
– Jim Hefferon
Aug 21 '13 at 11:31
@JimHefferon that sounds useful - and also suggests a possible solution for non-broken hyperref endnotes...
– Joe Corneli
Aug 21 '13 at 13:18
@JimHefferon thanks, I'll first try myself to fix it using answers and xr, and I'll report back when I have some results.
– rabota
Aug 21 '13 at 15:26
@JimHefferon I'm just wondering: what exactly did you need the xr package for? It seems like I can freely refer to labels in the main text from the answers. When I refer from the main text to the answers, it seems that the answers are simply numbered continuously, but the number that is displayed is the same as the corresponding exercise. For example if I number the answers per sections like 1.1, 1.2, 2.1, 2.2 the answers are 'labeled' 1, 2, 3, 4 while the displayed numbering is really 1.1, 1.2, 2.1, 2.2.
– rabota
Jun 25 '14 at 13:01
I allow for something more complicated that sequentially numbered exercises. For instance, I allow for the publication of a list of answers of the questions that are checkmarked. (I also number the exercises in sequence with the theorems.)
– Jim Hefferon
Jun 25 '14 at 19:54