# nameref With Arbitrary Text

This is a follow-up question to: Cross-referencing within text

@Werner gave a good cross-referencing MWE to return to a certain point of the text in a section and not at the beginning of that section. The 'back' link, however, still contains the name of the section where the return is to happen. How can one place arbitrary text in that 'back' link or, better yet, how can the referenced section title be made into a 'back' link (without it showing in the 'referencing' link)? Something like this:

\documentclass[onecolumn,twoside]{revtex4}

\usepackage{xpatch}% http://ctan.org/pkg/xpatch
\makeatletter
\xpatchcmd{\@ssect@ltx}{\@xsect}{\protected@edef\@currentlabelname{#8}\@xsect}{}{}%    Patch \<section>*
\xpatchcmd{\@sect@ltx}{\@xsect}{\protected@edef\@currentlabelname{#8}\@xsect}{}{}% Patch \<section>
\makeatother
\usepackage{hyperref}% http://ctan.org/pkg/hyperref

\hypersetup{pdfstartview=FitH,pdfpagemode=UseNone}

\begin{document}

\title{Title}
\author{Author}
\affiliation{Affiliation}

\maketitle

\section*{\texorpdfstring{FirstSection}{}}
text text text text text text text text text text text text text text text text text   text text text text text text text text text text text text text text text text   text text text text text text text text text text text text text text text text text text   text text text text text text text text text text text text text text text text   text text text text
\bf I want to return here, not at the beginning of FirstSection \rm      \nameref{sec:marker2} \phantomsection   \label{sec:marker1} (\bf the text CLICK HERE TO GO  BACK shouldn't show up here \rm)
text text text text text text text text text text text text text text text text text     text text text text text text text text text text text text text text text text     text text text text text text text text text text text text

You can also see in \nameref{sec:marker1} that \ldots
\end{document}

-
Arbitrary text is something you do NOT want to do. Basically that would make the reference useless. If anything changes (section number, title, page...etc) you'd be in deep s**t –  Ayman Elmasry Feb 19 '12 at 21:28
Suppose you have three places in the text where you're referencing an Addendum. How would you return to the one (of the three) where you started and not to another one (of the three)? At that, without seeing the text of the section title in the 'back' link. –  ganzewoort Feb 19 '12 at 22:13

For this you would use the \hyperref[<label>]{<text>} macro and supply the alternative text in <text>. So, in your case, you would use

\hyperref[sec:marker2]{SecondSection}


\documentclass[onecolumn,twoside]{revtex4}

\usepackage{xpatch}% http://ctan.org/pkg/xpatch
\makeatletter
\xpatchcmd{\@ssect@ltx}{\@xsect}{\protected@edef\@currentlabelname{#8}\@xsect}{}{}%    Patch \<section>*
\xpatchcmd{\@sect@ltx}{\@xsect}{\protected@edef\@currentlabelname{#8}\@xsect}{}{}% Patch \<section>
\makeatother
\usepackage{hyperref}% http://ctan.org/pkg/hyperref

\hypersetup{pdfstartview=FitH,pdfpagemode=UseNone}

\begin{document}

\title{Title}
\author{Author}
\affiliation{Affiliation}

\maketitle

\section*{\texorpdfstring{FirstSection}{}}
text text text text text text text text text text text text text text text text text   text text text text text text text text text text text text text text text text   text text text text text text text text text text text text text text text text text text   text text text text text text text text text text text text text text text text   text text text text
\bf I want to return here, not at the beginning of FirstSection \rm      \hyperref[sec:marker2]{SecondSection} \phantomsection   \label{sec:marker1} (\bf the text CLICK HERE TO GO  BACK shouldn't show up here \rm)
text text text text text text text text text text text text text text text text text     text text text text text text text text text text text text text text text text     text text text text text text text text text text text text

You can also see in \nameref{sec:marker1} that \ldots
\end{document}

-
This does work as far as forcing arbitrary text but returns you to the last of several points of reference. What if the referencing was done earlier and I want to return there and not at the last reference point? Don't know if I'm allowed to change the initial MWE to show you what I mean. –  ganzewoort Feb 20 '12 at 13:50
@ganzewoort: For every hyperlink that has a different location in your document, you would need a separate \label. Also, there is no problem with having multiple \labels in the same section - LaTeX doesn't care - just as long as they are named differently/uniquely. So, please clarify: You want to have (say) 3 different points that you want to jump back to (via hyperlink) in (say) section FirstSection from anywhere in the document? Say, one should jump back to the start of the section, another should jump back to the middle (as in your MWE), and another to the end? –  Werner Feb 20 '12 at 15:17
I was windering if it's at all possible to have, say, three places in the main text referencing one and the same, say, Addendum but the return to occur to the particular point of referencing and not to last one of these three referencing points, as the MWE does. In other words, when referencing, there should be some kind of memory indicating which of the three equivalently labeled points but positioned at different parts of the text the return should be to. –  ganzewoort Feb 20 '12 at 22:28
@ganzewoort: No, this is not possible, as far as I know. Hyperlinks within the document do not have dynamic memory allocation for use of references. Ideally you are after something equivalent to a browser's "back" button. If such support existed, it would be viewer-dependent, rather than (La)TeX dependent. –  Werner Feb 21 '12 at 7:16
Thanks @Werner for all your help. –  ganzewoort Feb 21 '12 at 7:28