latex

How do I emit the text content of a reference in LaTeX?


I have a section:

\section{Introduction} \label{sec:introduction}

I'd like a link to the section where the link text is the name of the section. I can use hyperref:

The \hyperrf[sec:introduction]{Introduction} introduces the paper.

But that requires repeating the section title ("Introduction"). Is there a way to grab that? ref yields the section number, which isn't right. autoref yields "section " and then the section number, which isn't right, either.


Solution

  • There are a couple of packages that provide this for you. nameref is distributed as part of hyperref to do this:
    https://ctan.org/pkg/nameref

    There is a more general package for cross-referencing basically anything, called zref: https://ctan.org/pkg/zref

    It's by the same author as hyperref, Heiko Oberdiek; it's the one that I would choose. Here's an example:

    \documentclass[oneside,12pt]{article}
    \usepackage[user,titleref]{zref}
    \begin{document}
    \section{Introduction of sorts.}\zlabel{sec:intro}
    Hello
    \subsection{Structure}
    We begin in `\ztitleref{sec:intro}'.
    \end{document}
    

    Note that it even removes the trailing period in the section title.