0

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[utf8]{inputenc}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsbsy}

\usepackage{hyperref}
\usepackage[capitalize,nameinlink,noabbrev]{cleveref}

\theoremstyle{definition}
\newtheorem{theorem}{Theorem}[chapter]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{conjecture}[theorem]{Conjecture}
\newtheorem{example}[theorem]{Example}
\newtheorem{definition}[theorem]{Definition}

\usepackage{answers, xpatch}
\newtheorem{problem}[theorem]{%
\hyperlink{problem:\theproblem}{Problem}\hypertarget{probsol:\theproblem}{}}
\Newassociation{probsol}{Solution}{ans}
\renewenvironment{Solution}[1]
{\par\bigskip\noindent{\bfseries \hyperlink{probsol:#1}{Solution #1.}\hypertarget{problem:#1}{}}\quad}
{\par\bigskip}


\newcommand{\lemmaautorefname}{Lemma}
\newcommand{\corollaryautorefname}{Corollary}
\newcommand{\conjectureautorefname}{Conjecture}
\newcommand{\problemautorefname}{Problem}
\newcommand{\exampleautorefname}{Example}
\newcommand{\definitionautorefname}{Definition}

\begin{document}

\Opensolutionfile{ans}[ans1]

\chapter{First}

\begin{problem}\label{prb:example-prob}
This is a problem.
    \begin{probsol}
    This is a solution.
    \end{probsol}
\end{problem}

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

\Closesolutionfile{ans}
\chapter*{Solutions}
\addcontentsline{toc}{chapter}{Solutions}
\input{ans1}

\end{document}
11
  • 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

0

You must log in to answer this question.

Browse other questions tagged .