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.

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 

\section*{SecondSection--CLICK HERE TO GO BACK} \label{sec:marker2} 
You can also see in \nameref{sec:marker1} that \ldots
\end{document} 
share|improve this question
    
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
add comment

1 Answer

up vote 4 down vote accepted

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}

Here's your minimal example with the modified hyperlink:

enter image description here

\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 

\section*{SecondSection--CLICK HERE TO GO BACK} \label{sec:marker2} 
You can also see in \nameref{sec:marker1} that \ldots
\end{document} 
share|improve this answer
    
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
add comment

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.