TeX - LaTeX Asked on September 30, 2021
I use the answers package to put questions in the text and hints and solutions at the end of the doc. Now I like to use the Tufte book style, and put small exercises in the margin and still have hints and solutions at the end of the doc. I tried to put an exercise in a marginpar, but that does not work. The MWE below explains the point in detail.
usepackage{answers}
Newassociation{solution}{Solution}{ans}
Newassociation{hint}{Hint}{hint}
newtheorem{exercise}{Ex.}
renewcommand{Hintlabel}[1]{textbf{h.#1.}}
renewcommand{Solutionlabel}[1]{textbf{s.#1.}}
begin{document}
Opensolutionfile{hint}
Opensolutionfile{ans}
section{Test}
label{sec:sec-1}
With the answer package we can put hints and answers at the end of the doc, see below.
begin{exercise}
What is $2+2$?
begin{hint}
Why is this the same as $1+1+1+1$?
end{hint}
begin{solution}
4
end{solution}
end{exercise}
Now I like to use the Tufte book style, and put the number and text of an exercise in the margin, and have the hints and answers at the end of the doc, just as the $2+2$ example above.
For example:
Let us practice with division. sidenote{textbf{Ex. 2} What is $21/7$?}`. More text, blah blah blah blah blah sidenote{textbf{Ex. 3} what is $48/6$?}.
This, however, does not work with the answer package, because using it requires to put the hint and the solution within the exercise environment.
And marginpar does not to support this. In other words, this does not work:
begin{verbatim}
marginpar{
begin{exercise}
What is $2+2$?
begin{solution}
4
end{solution}
end{exercise}
}
end{verbatim}
So, is there another way to obtain the feature as demonstrated by my exercises 2 and 3? Any help is much appreciated.
Closesolutionfile{hint}
Closesolutionfile{ans}
subsection*{Hints}
input{hint}
subsection*{Solutions}
input{ans}
end{document}
I found this trick, but I am still curious to see a better answer.
begin{exercise}label{ex:1}
marginpar{{cref{ex:1} What is $2+2$?}
begin{hint}
Why is this the same as $1+1$?
end{hint}
begin{solution}
4
end{solution}
end{exercise}
Answered by nicky on September 30, 2021
You could try this old trick. I assembled this code here in stack exchange.
I'm no expert, but I do my list of exercises with key answers successfully.
documentclass{exam}
usepackage{multicol}
usepackage{amsmath}
printanswers
unframedsolutions
newboxallanswers
setboxallanswershbox{}
renewenvironment{solution}{noindentglobalsetboxallanswers=hboxbgroupunhboxallanswers{egroup}
newcommand{showallanswers}{noindentunhboxallanswers}
begin{document}
begin{multicols}{2}
setlength{columnsep}{20pt}
setlength{columnseprule}{0.01pt}
begin{questions}
question this is question 1
begin{parts}
item item a
begin{solution}
solution of item a
end{solution}
item item b
begin{solution}
solution of item b
end{solution}
item item c
begin{solution}
solution of item c
end{solution}
item item d
begin{solution}
~solution of item d
end{solution}
end{parts}
question this is question 2
begin{solution}
$dfrac{1}{2}$
end{solution}
question this is question 3
begin{parts}
item item a
begin{solution}
solution of item a
end{solution}
item item b
begin{solution}
solution of item b
end{solution}
item item c
begin{solution}
solution of item c
end{solution}
item item d
begin{solution}
solution of item d
end{solution}
end{parts}
question this is question 4
begin{solution}
this is a long long long long long long long long long long long long long solution for question 4
end{solution}
end{questions}
end{multicols}
vskip20pt
begin{center}
{Huge textsc{Answer Key}}
end{center}
begin{multicols}{2}
setlength{columnsep}{20pt}
setlength{columnseprule}{0.01pt}
showallanswers
end{multicols}
end{document}
Answered by Fábio José de Jesus on September 30, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP