# Latex: how to get question number in exam package

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
\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).

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}%
\else{??}%
\fi
}

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

\question
\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}


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:

## 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}
\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}


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
\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