I have some problems related to the application of an answer that I received to a previous question of mine, that can be found here.
Below there is a MWE, where I used \clearpage
extensively, because I noticed that when \hypertarget
does not work properly, it links to the first page of the document.
Problem:
When I use[\hypertarget{...}{...}]
along with\begin{proof}
or\begin{namedtheorem}
, no additional round braces appear in the text.However, when I use it along with
\begin{step}
,\begin{claim}
, or\begin{myclaim}
, there two additional round braces appear.Is there a way to get rid of those round braces?
\documentclass[12pt]{article}
\usepackage{amsthm,xcolor}
\usepackage[colorlinks, linkcolor=red]{hyperref}
\usepackage[noabbrev,nameinlink]{cleveref}
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
\theoremstyle{remark}
\newtheorem{claim}{Claim}
\newtheorem*{myclaim}{Claim}
\newtheorem{step}{Step}
\newtheoremstyle{named}%
{}{}{\itshape}{}{\bfseries}{.}{.5em}{\thmnote{#3}}
\theoremstyle{named}
\newtheorem*{namedtheorem}{Theorem}
\newcommand{\aref}[2][blue]{%
\begingroup%
\hypersetup{linkcolor=#1}%
\cref{#2}%
\endgroup}
\newcommand\bref[3][blue]{%
\begingroup%
\hypersetup{linkcolor=#1}%
\hyperlink{#2}{#3}%
\endgroup}
\begin{document}
\section{One}
LaTeX Problems.
\clearpage
\section{Two} \label{section:two}
\begin{theorem}[Bla]\label{thm:bla}
Bla.
\end{theorem}
\begin{proof}[\hypertarget{proof:1}{Proof.}]
Bla
\end{proof}
\begin{namedtheorem}[\hypertarget{thm:mystery}{Mystery theorem}]
A mysterious theorem
\end{namedtheorem}
\begin{proof}
\begin{step}[\hypertarget{step1}{}]
Here step 1.
\end{step}
\begin{step}
Here step 2.
\end{step}
\begin{claim}[\hypertarget{claim1}{}]
A numbered claim.
\end{claim}
\end{proof}
\clearpage
\begin{theorem}
Bla bla
\end{theorem}
\begin{proof}
\begin{myclaim}[\hypertarget{myclaim}{}]
An unnumbered claim.
\end{myclaim}
\end{proof}
\clearpage
\section{Three}
In \cref{section:two}, we have both a \aref{thm:bla}, a \bref{proof:1}{proof}, \bref{step1}{step 1}, a numbered \bref{claim1}{claim 1}, and a single \bref{myclaim}{claim}.
\end{document}
Thank you for your time.
Best Answer
You wrote:
Don't surround the corresponding
\hypertarget{...}{}
statements with square brackets ([
and]
). Otherwise,amsthm
will interpret the material as indicating the optional "title" of the corresponding theorem-like environments. Expressed differently, only use square brackets if the second argument of\hypertarget
is nonempty.Another way to understand this better is to consider the two cases in your code where the second argument of
\hypertarget
is nonempty:and
In these cases, the square brackets indicate to LaTeX that "Proof." and "Mystery theorem", respectively, should be used as the titles of the corresponding environments. That's not the case with
and that's why you shouldn't provide square brackets.
You also wrote:
When that happens, try inserting
\phantomsection
directives immediately ahead of the environments or other items being cross-referenced via\hypertarget
and\hyperlink
.