nameref、ref 和其他引用反向的问题

nameref、ref 和其他引用反向的问题

我遇到了问题\nameref,无法\ref返回所需的输出。我希望有由 Definition 0.0.1 引用的定义(见下文)。我不希望 \nameref{defn1} 的结果为粗体,我希望显示“定义”。更准确地说,这是输出(通过 overleaf):

在此处输入图片描述

以下是相关的 TeX 代码:

\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}


答案1

以下是使用 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}

我已经从 newtheorem 命令中删除了所有\textbf{}s(我使用@egregs 方式将其加粗)并且我只使用了\Cref包中的命令cleveref...

输出:

在此处输入图片描述

相关内容