1

I amm having issues with \nameref and \ref not returning the desired output. I would like to have definitions referred to by Definition 0.0.1 (see below). I do not want the result of \nameref{defn1} to be bold and I would like the "Definition" to appear. More precisely, here is the output (via overleaf):

enter image description here

Here is the relevant TeX code:

\documentclass[11pt, reqno,openany]{amsbook}
\setlength{\parindent}{0pt}
\usepackage[colorlinks, linkcolor=black, citecolor=magenta, linktocpage]{hyperref}
\usepackage{amsmath}
\numberwithin{equation}{section}
\usepackage{scrextend}
\makeatletter
\numberwithin{section}{chapter}
\def\@secnumfont{\mdseries}
\def\section{\@startsection{section}{1}%
  \z@{.7\linespacing\@plus\linespacing}{.5\linespacing}%
  {\normalfont\scshape\centering}}
\def\subsection{\@startsection{subsection}{2}%\
  \z@{.5\linespacing\@plus.7\linespacing}{-.5em}%
  {\normalfont\bfseries}}
\patchcmd{\@thm}{\let\thm@indent\indent}{\let\thm@indent\noindent}{}{}
\patchcmd{\@thm}{\thm@headfont{\scshape}}{\thm@headfont{\bfseries}}{}{}
\usepackage{lipsum}
\makeatletter
\theoremstyle{plain}
\theoremstyle{definition}
\newtheorem{thm}{\textbf{Theorem}}[section]
\newtheorem{defn}[thm]{\textbf{Definition}}
\newtheorem{conv}[thm]{\textbf{Convention}}
\newtheorem{rmk}[thm]{\textbf{Remark}}
\newtheorem{crmk}[thm]{\textbf{Cautionary Remark}}
\newtheorem{notn}[thm]{\textbf{Notation}}
\newtheorem{ex}[thm]{\text{Example}}
\newtheorem{cor}[thm]{\textbf{Corollary}}
\newtheorem{prop}[thm]{\textbf{Proposition}}
\newtheorem{lem}[thm]{\textbf{Lemma}}
\newtheorem{q}[thm]{\textbf{Question}}
\renewcommand\thesubsection{\Alph{subsection}}
\renewcommand{\thedefn}{\textbf{\thesection.\thesubsection \arabic{defn}}}
\renewcommand{\thethm}{\textbf{\thesection.\thesubsection \arabic{thm}}}
\renewcommand{\theconv}{\textbf{\thesection.\thesubsection \arabic{conv}}}
\renewcommand{\thermk}{\textbf{\thesection.\thesubsection \arabic{rmk}}}
\renewcommand{\thecrmk}{\textbf{\thesection.\thesubsection \arabic{crmk}}}
\renewcommand{\thenotn}{\textbf{\thesection.\thesubsection \arabic{notn}}}
\renewcommand{\theex}{\thesection.\thesubsection \arabic{ex}}
\renewcommand{\theprop}{\textbf{\thesection.\thesubsection \arabic{prop}}}
\renewcommand{\thecor}{\textbf{\thesection.\thesubsection \arabic{cor}}}
\renewcommand{\thelem}{\textbf{\thesection.\thesubsection \arabic{lem}}}
\renewcommand{\theq}{\textbf{\thesection.\thesubsection \arabic{q}}}
\begin{document}

Consider the following:

\begin{ex}\label{example1}
Here is an example.
\end{ex}

Hence, define:

\begin{defn}\label{defn1}
We make the following definition.
\end{defn}

If I want to refer back to these, nameref does not yield anything: \nameref{example1} (Package hyperref warning: suppressing empty link).  On the other hand, ref simply returns the number, e.g., \ref{defn1}. \\

I would like the reference to the example (respectively, definition) to appear as Example 0.0.1 (respectively, Definition 0.0.2).

\end{document}


5
  • Perhaps the answer in this question could help you set up a custom label for references (also: your LaTeX code is missing a \documentclass).
    – Miyase
    Commented Jul 26, 2022 at 23:08
  • @Miyase Thank you for your comment. I'll look at the answer to that question. Thanks for pointing out the absence of the document class, that should be fixed now :-)
    – AmorFati
    Commented Jul 26, 2022 at 23:16
  • \nameref returns the title, not the number. So with \begin{defn}[Famous definition] you get Famous definition from it. Commented Jul 27, 2022 at 8:02
  • @UlrikeFischer Thank you for your comment. This produces the undesired "Famous definition" next to Definition 1.1.1., however.
    – AmorFati
    Commented Jul 31, 2022 at 1:17
  • @Miyase I've looked over that example in that answer that you reference, but I'm still not seeing how this gives the desired result. I'm only getting the label without the definition or number component.
    – AmorFati
    Commented Aug 1, 2022 at 21:21

1 Answer 1

1

Here is a way with cleveref:

\documentclass[11pt, reqno,openany]{amsbook}
\setlength{\parindent}{0pt}
\usepackage[colorlinks, linkcolor=black, citecolor=magenta, linktocpage]{hyperref}
\usepackage{amsmath}
\usepackage{xpatch}
\usepackage[noabbrev, nameinlink]{cleveref}
% From @egreg : https://tex.stackexchange.com/a/609191/120578
\makeatletter
\xpatchcmd{\@cref}{\begingroup}{\begingroup\bfseries}{}{}
\makeatother
\numberwithin{equation}{section}
\usepackage{scrextend}
\makeatletter
\numberwithin{section}{chapter}
\def\@secnumfont{\mdseries}
\def\section{\@startsection{section}{1}%
  \z@{.7\linespacing\@plus\linespacing}{.5\linespacing}%
  {\normalfont\scshape\centering}}
\def\subsection{\@startsection{subsection}{2}%\
  \z@{.5\linespacing\@plus.7\linespacing}{-.5em}%
  {\normalfont\bfseries}}
\patchcmd{\@thm}{\let\thm@indent\indent}{\let\thm@indent\noindent}{}{}
\patchcmd{\@thm}{\thm@headfont{\scshape}}{\thm@headfont{\bfseries}}{}{}
\usepackage{lipsum}
\makeatletter
\theoremstyle{plain}
\theoremstyle{definition}
\newtheorem{thm}{Theorem}[section]
\newtheorem{defn}[thm]{Definition}
\newtheorem{conv}[thm]{Convention}
\newtheorem{rmk}[thm]{Remark}
\newtheorem{crmk}[thm]{Cautionary Remark}
\newtheorem{notn}[thm]{Notation}
\newtheorem{ex}[thm]{Example}
\newtheorem{cor}[thm]{Corollary}
\newtheorem{prop}[thm]{Proposition}
\newtheorem{lem}[thm]{Lemma}
\newtheorem{q}[thm]{Question}
\renewcommand\thesubsection{\Alph{subsection}}
\renewcommand{\thedefn}{\textbf{\thesection.\thesubsection \arabic{defn}}}
\renewcommand{\thethm}{\textbf{\thesection.\thesubsection \arabic{thm}}}
\renewcommand{\theconv}{\textbf{\thesection.\thesubsection \arabic{conv}}}
\renewcommand{\thermk}{\textbf{\thesection.\thesubsection \arabic{rmk}}}
\renewcommand{\thecrmk}{\textbf{\thesection.\thesubsection \arabic{crmk}}}
\renewcommand{\thenotn}{\textbf{\thesection.\thesubsection \arabic{notn}}}
\renewcommand{\theex}{\thesection.\thesubsection \arabic{ex}}
\renewcommand{\theprop}{\textbf{\thesection.\thesubsection \arabic{prop}}}
\renewcommand{\thecor}{\textbf{\thesection.\thesubsection \arabic{cor}}}
\renewcommand{\thelem}{\textbf{\thesection.\thesubsection \arabic{lem}}}
\renewcommand{\theq}{\textbf{\thesection.\thesubsection \arabic{q}}}
\begin{document}

Consider the following:

\begin{ex}\label{example1}
Here is an example.
\end{ex}

Hence, define:

\begin{defn}\label{defn1}
We make the following definition.
\end{defn}

If I want to refer back to these, nameref does not yield anything: \Cref{example1} %[NOW IT WORKS] 
(Package hyperref warning: suppressing empty link).  On the other hand, ref simply returns the number, e.g., \ref{defn1}. \\

I would like the reference to the example (respectively, definition) to appear as Example 0.0.1 (respectively, Definition 0.0.2).

\end{document}

I have removed all the \textbf{}s (I used @egregs way for making bold) from the newtheorem commands and I used just \Crefcommand from the package cleveref...

Output:

enter image description here

1
  • 1
    Feel free to remove all the \textbf{}s ...
    – koleygr
    Commented Aug 7, 2022 at 8:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .