1

Question is as in the title.

Using \href, we will be able to give a "clickable" link along with text. Can we do the same with \ref. Suppose I want to refer an equation with label \label{equation:123}, I usually write Equation \ref{equation:123}. Is there a way to write something like \ref[Equation]{equation:123} or \ref{Equation}{equation:123} similar to \href{00}{00}?

\documentclass[12pt,reqno,a4paper]{amsart}
\usepackage{extsizes}
\usepackage{blindtext}
\textheight 9.3in \textwidth 6.5in
\calclayout
\usepackage{amsmath,amsthm,amsfonts,amssymb}
\theoremstyle{definition}
\newtheorem{theorem}{Theorem} 
\newtheorem{lemma}{Lemma} 
\newtheorem{example}{Example}[section]
\newtheorem{corollary}{Corollary}[section]
\usepackage{hyperref}
\usepackage{mathrsfs}
\usepackage[all]{xy}
\newtheorem*{question}{Question}
\newcommand{\mc}{\mathcal}
\newcommand{\mf}{\mathfrak}
\newtheorem*{solution}{Solution}
\newtheorem{definition}{Definition}
\newtheorem{remark}{Remark}
\newtheorem{proposition}{Proposition}[section]
\newtheorem{exercise}{Exercise}
\newcommand{\og}{\omega}
\newcommand{\tb}{\textbf}
\newcommand{\m}{\mathcal}
\newcommand{\mb}{\mathbb}
\newcommand{\Spec}{\rm Spec}
\usepackage{tikz-cd}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\usepackage{color} \pagestyle{myheadings} \newcommand{\ra}{\rightarrow} \newcommand{\xra}{\xrightarrow} \author{someone} \title{something} \begin{document} \section{qwerty}\label{qwerty} \end{document}

2 Answers2

2

The solution to your problem is to use the cleveref pacakge (note that it's just one r in the name). You will want to load it with the nameinlink option in conjunction with hyperref:

\usepackage{hyperref}
\usepackage[nameinlink]{cleveref}

You can then write \cref{equation:123} in place of equation~\ref{equation:123}. Use \Cref for capitalization. If cleveref inserts abbreviations where you'd prefer it did not, you can add the option noabbrev to prevent abbreviations.

Further information can be had by typing texdoc cleveref at a command line.

Don Hosek
  • 14,078
1

If you don't want to add cleveref to an already bloated preamble...

\documentclass[12pt,reqno,a4paper]{amsart}
\usepackage{hyperref}

\newcommand{\myref}[2]% #1=added text, #2=label name {\hyperlink{\getrefbykeydefault{#2}{anchor}{Doc-Start}}{#1~\ref*{#2}}}

\begin{document} \begin{equation}\label{eq:1} x=a \end{equation}

\myref{Equation}{eq:1}

\end{document}

John Kormylo
  • 79,712
  • 3
  • 50
  • 120