I am using the following packages in a math textbook that I am writing:

  • The answers package to be able to put solutions to problems at the end of the book
  • The hyperref package to be able to link problems to solutions and vice versa, and to refer to different components of the book, such as theorems.
  • The cleveref package to conveniently refer to parts of the document, specifically having the "Lemma" or "Theorem" part automatically put in.

There are two issues:

  1. References to problems are showing up as, for example, "problem:1.14Problem 1.13" whereas I only want the second part. This might be related to the error "Argument of \hyperlink has an extra }." whenever I internally reference a problem with \cref
  2. The hyperlink that goes from problems to solutions does not cover the counter of the Problem environment.

Here are the relevant parts of the code. Please help me to rectify the issues.

\documentclass[openany, 12pt]{book}




\usepackage{answers, xpatch}
{\par\bigskip\noindent{\bfseries \hyperlink{probsol:#1}{Solution #1.}\hypertarget{problem:#1}{}}\quad}





This is a problem.
    This is a solution.

I am referring to \cref{prb:example-prob}.


  • don't show only snippets. Always show a small but complete example. That makes it much easier to test your issue. May 26, 2022 at 16:05
  • Please follow Ulrike‘s request. Thanks
    – MS-SPO
    May 26, 2022 at 16:21
  • @UlrikeFischer got it, I have added a minimum working example.
    – Favst
    May 26, 2022 at 16:39
  • don't put hyper-commands (and other complicated commands) in the second argument of newtheorem. cleveref uses the text to create the references. May 26, 2022 at 17:09
  • 1
    define the names explicitly: \crefname{problem}{Problem}{Problems} \Crefname{problem}{Problem}{Problems} May 26, 2022 at 17:59


You must log in to answer this question.

Browse other questions tagged .