Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

The link produced by \ref{defn:First Defined Term} works fine, but as I would prefer to have text instead of a number so thought \href{defn:First Defined Term}{First Defined Term} should work, but it doesn't:

enter image description here

\documentclass{article}
\usepackage{thmtools}
\usepackage{hyperref}
\usepackage{lipsum}

\declaretheorem[name=Definition]{DefinitionTheorem}

\newenvironment{Definition}[1]{%
    \begin{DefinitionTheorem}
    \label{defn:#1}
}{%
    \end{DefinitionTheorem}
}

\begin{document}
\lipsum[1-7]
\begin{Definition}{First Defined Term}
    \lipsum[1]
\end{Definition}
\lipsum[8-10]

\begin{Definition}{Second Defined Term}
    \lipsum[1]

    \bigskip
     This link works great: \ref{defn:First Defined Term}\par\bigskip
     But this link does not: \href{defn:First Defined Term}{First Defined Term}
\end{Definition}
\end{document}
share|improve this question

2 Answers 2

up vote 12 down vote accepted

As far as I know the \href command is only used to link to URLs.

Use \hyperref instead:

\hyperref[label]{text}

text is made into a link to the same place as \ref{label} would be linked.

Adapted to your example:

\documentclass{article}
\usepackage{thmtools}
\usepackage{hyperref}
\usepackage{lipsum}

\declaretheorem[name=Definition]{DefinitionTheorem}

\newenvironment{Definition}[1]{%
    \begin{DefinitionTheorem}
    \label{defn:#1}
}{%
    \end{DefinitionTheorem}
}

\begin{document}
\lipsum[1-7]
\begin{Definition}{First Defined Term}
    \lipsum[1]
\end{Definition}
\lipsum[8-10]

\begin{Definition}{Second Defined Term}
    \lipsum[1]

    \bigskip
     This link works great: \ref{defn:First Defined Term}\par\bigskip
     But this link does not: \hyperref[defn:First Defined Term]{First Defined Term}
\end{Definition}
\end{document}
share|improve this answer

You can do this with the following hack.

\documentclass{article}

\makeatletter
\newcommand*\mylabel[2]{%
    \immediate\write\@auxout{\string\newlabel%
                             \string{#1\string}%
                             \string{\string{#2\string}%
                                     \string{\thepage\string}\string}}%
}
\makeatother

\makeatletter

\begin{document}
  Wow, \mylabel{super}{supercalifragilisticexpialidocious}
       this is \ref{super}.
\clearpage
  I already told you this is \ref{super} on Page~\pageref{super}.
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.