2

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}
0

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

\newbox\allanswers
\setbox\allanswers\hbox{}

\renewenvironment{solution}{\noindent\global\setbox\allanswers=\hbox\bgroup\unhbox\allanswers{\egroup}

\newcommand{\showallanswers}{\noindent\unhbox\allanswers}


\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}
2
  • I still have some minor issues that make this code not entirely automatic. You still have to label manually the labels of the question and the parts in the solution environment. Anyways, it works. – Fábio José de Jesus Aug 7 '20 at 0:40
  • Thanks for your answer. I resolved the problem differently, but putting the exercise at the end, and just include a reference to the exercise in the margin. For larger exercises that works better. – nicky Oct 14 '20 at 18:34
0

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.