In two previous questions (i.e. Distinguishing \ref and \cref through different colors, and ''Proof of Theorem x'' header trough modification of \ref) I addressed some problems I had with hyperref
and cleverref
. Here there is a new problem I have, that can be exemplified by the following MWE:
\documentclass[12pt]{article}%
\usepackage{amsmath}%
\usepackage{amsthm}%
\usepackage{amsfonts}%
\usepackage{amssymb}%
\usepackage[usenames,dvipsnames]{xcolor}%
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
\newtheoremstyle{named}{}{}{\itshape}{}{\bfseries}{.}{.5em}{\thmnote{#3}}
\theoremstyle{named}
\newtheorem*{namedtheorem}{Theorem}
\usepackage{varioref}
\usepackage{hyperref}
\usepackage[noabbrev,nameinlink]{cleveref}
\hypersetup{colorlinks={true},linkcolor={red},citecolor={green}}
\newcommand{\aref}[2][blue]{%
\hypersetup{linkcolor=#1}%
\cref{#2}%
\hypersetup{linkcolor=red}%
}
\begin{document}
\section{Bla}
\label{section:bla}
\begin{theorem}[Bla]
\label{th:bla}
Bla.
\end{theorem}
\begin{namedtheorem}[Bla Bla]
\label{thm:blabla}
Bla bla
\end{namedtheorem}
\section{Bla Bla}
In section \ref{section:bla}, we get \aref{th:bla}, but we also get \aref{thm:blabla}.
\end{document}
Thus, the all problem is that when I use \aref
(the modification of \cref
) applied to namedtheorem
, instead of giving me the name of the theorem (e.g. "Bla Bla" in blue), it gives me "section 1" in Blue.
Is there a way to fix it?
Thank you for your time.
Edit after comment:
A user as kindly provided an attempt to fix the problem. Namely, to substitute \newtheorem*
with \newtheorem
and then use \crefname{namedtheorem}{theorem}{theorems}
after loading cleverref
. By doing this, the hyperlink doesn't show up anymore as section
, but still there are two problems:
I don't get the name of the theorem in blue (e.g.
Bla Bla
in blue), but ratherTheorem 1
in blue;If there is another theorem, no matter what is the label, when I called them, in both cases I get
theorem 1
.
\newtheorem*
with\newtheorem
and then use\crefname{namedtheorem}{theorem}{theorems}
after loadingcleverref
.\label
(thm:blabla
). However, since the "named" theorem style (by design!) does not increment a counter (via\refstepcounter
), LaTeX associates the\label
with a recently-incremented counter, which in the present case happens to be thesection
counter. Note that this problem is not specific tocleveref
: You're somehow trying to generate a link, but there's no hook to link to via the\label
-\ref
mechanism.\hypertarget
/\hyperlink
mechanism to generate cross-references to unnumbered entities (e.g., unnumbered theorems) that are also hyperlinks.