5

I am using exam package and I would like to add an extension to some solution in the form of a footnote with the same number of the question, as in

\documentclass[12pt, answers]{exam}
\renewcommand{\solutiontitle}{\noindent\textbf{Risposta:}\enspace}
\checkboxchar{$\Box$}


\begin{document}
\begin{questions}
\section{Capitolo 1}
\question
which question am I?
\begin{solution}One \end{solution}

\question
which question am I, instead?
\begin{solution}Two \end{solution}

\question
How do I get the question current number?
    \begin{solution} Three \footnote[\questionnumber]{I would like this footnote to be numbered the same as the question} \end{solution}

\end{questions}


\end{document}

Unfortunately, the footnote would not show up at all (as noticed in Latex: \footnote command not working in solution environment of exam package).

3 Answers 3

5

Exam uses the counter question for questions.

\documentclass[12pt, answers]{exam}
\renewcommand{\solutiontitle}{\noindent\textbf{Risposta:}\enspace}
\checkboxchar{$\Box$}

\newcommand*\countoff[1]% #1 = counter name
{\ifcase\value{#1}{??}\or{One}\or{Two}\or{Three}\or{Four}\or{Five}%
   \or{Six}\or{Seven}\or{Eight}\or{Nine}\or{Ten}% ad infinitum
 \else{??}%
 \fi
}

\begin{document}
\begin{questions}
\section{Capitolo 1}
\question
which question am I?
\begin{solution}\thequestion \end{solution}

\question
which question am I, instead?
\begin{solution}\arabic{question} \end{solution}

\question
How do I get the question current number?
    \begin{solution}\countoff{question} \footnote[\thequestion]{I would like this footnote to be numbered the same as the question} \end{solution}

\end{questions}
\end{document}
4

You can use the usual \label/\ref mechanism. Since it is being used in a \footnote you need to expand it first. I do this with an \xdef below:

enter image description here

Code:

\documentclass[12pt, answers]{exam}
\renewcommand{\solutiontitle}{\noindent\textbf{Risposta:}\enspace}
\checkboxchar{$\Box$}

%% Need this to get footnote from within the exam class.
%% https://tex.stackexchange.com/a/392622/4301
\usepackage{footnote}
\makesavenoteenv{solution}

\newcommand{\ExamFootnote}[2]{%
    %% https://tex.stackexchange.com/q/50111/4301
    \xdef\currentQuestion{\ref{#1}}%
    \ifnum0<0\currentQuestion\else
        \def\currentQuestion{0}%
    \fi
    \footnote[\currentQuestion]{#2}%
}


\begin{document}
\begin{questions}
\section{Capitolo 1}
\question
    which question am I?
\begin{solution}
One 
\end{solution}

\question\label{question:This Question}
which question am I, instead?
\begin{solution}
    Two\ExamFootnote{question:This Question}{foot note for 2}
\end{solution}

\question\label{question:That Question}
How do I get the question current number?
\begin{solution} 
    Three \ExamFootnote{question:That Question}{I would like this footnote to be numbered the same as the question} 
\end{solution}

\end{questions}
\end{document}
2
  • Your answer is exactly the solution to my problem... But compiling your code generates errors : Illegal parameter number in definition of \currentQuestion :/
    – JeT
    Nov 5, 2020 at 22:56
  • Without a complete MWE that reproduces the error it is difficlut to diagnose. I suggest you post a new question including a MWE. You can reference this question if it is relevant. Nov 7, 2020 at 5:36
2

A friend of mine gave me a quicker and simpler solution "live", so I'm reporting it:

\documentclass[12pt, answers]{exam}
\renewcommand{\solutiontitle}{\noindent\textbf{Risposta:}\enspace}
\usepackage{footnote}
\makesavenoteenv{solution}

\begin{document}
\begin{questions}
\section{Capitolo 1}
\question
which question am I?
\begin{solution}One \end{solution}

\question
which question am I, instead?
\begin{solution}Two \end{solution}

\question
How do I get the question current number?
    \begin{solution} Three \footnote[\thequestiontitle]{I would like this footnote to be numbered the same as the question} \end{solution}

\end{questions}

\end{document}

According to package documentation (http://www-math.mit.edu/~psh/exam/examdoc.pdf) at page 31

\thequestiontitle (see section 4.5.2), which expands to

...

– the number of the question, if this question was defined using a \question command

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.