I'm using the exercise package to write exercises and their corresponding answers. I have hundreds of exercises, each in their own file. The exercises are to be included two separate documents. In the first, each exercise should appear without its answer, and in the second, they should appear with their answer. To do this, I'm using the package option noanswer
in the first document. The problem is that in this first document, any references defined in an answer are reported as undefined even when the only reference to them is also in the answer.
For example:
\documentclass{article}
\usepackage{mwe}
\usepackage{float}
\usepackage[noanswer]{exercise}
\begin{document}
\begin{Exercise}
\label{exe:some_exercise}
\blindtext
\end{Exercise}
\begin{Answer}[ref={exe:some_exercise}]
\begin{figure}[H]
\centering
\includegraphics[width=.48\linewidth]{example-image-a}
\caption{MWE figure}
\label{fig:some_figure}
\end{figure}
\blindtext as shown in Figure~\ref{fig:some_figure}.
\end{Answer}
\end{document}
reports:
LaTeX Warning: Reference `fig:some_figure' on page 1 undefined on input line 20
I've tried other package options like answerdelayed
and then never calling \shipoutAnswer
, but that has the same problem. How can I suppress the undefined reference warnings caused by the exercise answers which are not being included, but still see warnings for undefined references in the parts of the document that are being typeset?
EDIT:
I found this similar question with an answer but I do not know how to apply its answer to the exercise package.