1

I'm trying to add footnotes to the solution of an exam I write using the exam class.

The following code displays the footnote mark but not the footnote:

 \documentclass[12pt,a4paper,answers]{exam}
    
    \begin{document}
    
    How are you today?
    
    \begin{solution}
    Fine really\footnote{Except for this footnote issue.}.
    \end{solution}
    
    \end{document}

This code displays both footmark and footnote, but the footnote persists even without the option answers in the exam class:

\documentclass[12pt,a4paper,answers]{exam}
\usepackage{footnote}
\makesavenoteenv{solution}

\begin{document}

How are you today?

\begin{solution}
Fine really\footnote{Except for this footnote issue.}.
\end{solution}

\end{document}

I'd like to have everything displayed when option answers is on, and nothing when it isn't.

Any idea?

1
  • Welcome to tex.sx. Commented Oct 27, 2020 at 17:14

1 Answer 1

1

The following seems to work:

  • Replace \footnote with an updated version that issues a \footnotetext[<num>]{<footnote>} after the closing of the solution environment.

  • Some trickery is used to expand the value associated with the footnote to allow multiple footnotes within the same solution.

enter image description here

%\documentclass{exam}
\documentclass[answers]{exam}

% Just for this example
\setlength{\textheight}{10\baselineskip}

\usepackage{etextools,etoolbox}

\AtBeginEnvironment{solution}{%
  \let\oldfootnote\footnote% Store original footnote
  \renewcommand{\footnote}[1]{% Update \footnote
    \oldfootnote{#1}% Original footnote
    \ifprintanswers
      \begingroup\edef\x{\endgroup\AfterGroup{\noexpand\footnotetext[\thefootnote]{#1}}}\x%
    \fi
  }%
}

\begin{document}

How are you today?

\begin{solution}
Fine really\footnote{Except for this footnote issue.}.
Or just okay\footnote{No more footnote issues.}.
\end{solution}

\end{document}
4
  • Thank you very much! It works perfectly.
    – Piotr
    Commented Oct 27, 2020 at 18:08
  • Oh, with this solution it turns out that \mathbb{R} is not compiled anymore when inside footnotes, as if the amssymb package was disactivated within footnotes. Do you have a fix for this?
    – Piotr
    Commented Oct 28, 2020 at 11:09
  • @Piotr: This happens as a result of the expansion trick. Since I'm loading etoolbox, adding \robustify\mathbb in your preamble will avoid expansion of \mathbb and make it usable within footnotes. Alternatively, use \noexpand\mathbb explicitly.
    – Werner
    Commented Oct 28, 2020 at 16:15
  • Thank you Werner.
    – Piotr
    Commented Oct 28, 2020 at 18:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .