3

i am creating an exercise book using the exercise package.

i understand that i can add a label to a question to link an answer to a specific question.

however, i'd like to add a link to the answer under the question. so it looks something like:

Current tex source:

\usepackage[answerdelayed]{exercise}
\begin{Exercise}
What is the value of 2+5?
\end{Exercise}
\begin{Answer}
7
\end{Answer}
<rest of the document>
\shipoutaAnswer

Current output:

Exercise 1: What is the value of 2 + 5?

<rest of the document>

Solution 1: 7

Desired output:

Exercise 1: What is the value of 2 + 5?
<Link to Solution at the end of the document>

<rest of the document>

Solution 1: 7

2 Answers2

4

The exercise package has a specific way to manage the label.

See the package documentation subsection 2.4.

\documentclass{article}
\usepackage{hyperref}% you must load it before the exercise package
\usepackage[answerdelayed]{exercise}

\begin{document}
    \begin{Exercise}[label={mylabel}]
        What is the value of 2+5? (To see the answer click here: \refAnswer{\ExerciseLabel})
    \end{Exercise}
    \begin{Answer}[ref=\ExerciseLabel]
        7
    \end{Answer}

    rest of the document
    \newpage % I've added a new page only to clearly show the hyperlink. Of course, you don't need it in your document.

    \shipoutAnswer
\end{document}

enter image description here

enter image description here

CarLaTeX
  • 62,716
1

Like this:

\documentclass{article}
\usepackage{exercise}
\usepackage{hyperref}
\begin{document}
\begin{Exercise}
    Some introductory text.
    \Question The first question
\end{Exercise}

See the answer \hyperref[one]{here}.
\newpage
\begin{Answer}[ref=first]
    The answer to question~\ref{first}.\label{one}
\end{Answer}
\end{document}