2

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
3

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

  • thanks a lot @CarLaTeX :) Is there a way to achieve this if I don't want to label each exercise manually. – gaurav gupta Jul 11 '17 at 0:27
  • can someone help me with the follow-up question posted at the following link, please? tex.stackexchange.com/questions/380095/… – gaurav gupta Jul 11 '17 at 4:53
  • 1
    @gauravgupta Thank you for accepting my answer! I'll try to help you with your new question, too. – CarLaTeX Jul 11 '17 at 5:03
  • 1
    @gauravgupta I've already got an answer, Troy's been faster than me :) – CarLaTeX Jul 11 '17 at 6:18
  • yupp - saw Troy's answer. You two are fantastic! Thanks :) – gaurav gupta Jul 11 '17 at 10:13
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}

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.