0

The example below compiles and makes a clickable link, but in the printed version it is not clear where the link is going.

I suppose to solve that, I could implement some kind of reverse link in a similar way, but I have a feeling there are much more elegant ways (maybe specialized packages?) to tackle this problem, especially if many of this kind of links are involved.

As for how exactly these references look in the document I'm pretty open-minded. Could be line numbers, some kind of colored markers or something else entirely. Best case is the reference works back and forth both digitally and in print. Any suggestions?

\documentclass{article}
\usepackage[colorlinks]{hyperref}
\usepackage{lipsum}
\begin{document}
The most important thing to understand in this course is
that dogs don't like cats \hyperref[ref:DogsCats]{(see here)}.

% rest of the document \lipsum[1-10]

% in appendix: Some wall of text that explains how animals don't always like each other. This text is really long so a reference to the section isn't precise enough, and it can't be changed or reformatted in any way. For example, monkeys don't like bats, crocodiles don't like pangolins, 50 other animals also don't like each other, dogs don't like cats \phantomsection\label{ref:DogsCats}, mice don't like rabbits, and a good 30 more examples. \end{document}

MaxD
  • 1,137
  • 3
    well the standard way (before there was internet) would have been a text "see page 5" or "see note 6 on page 8" (and "see here" is imho never good.) – Ulrike Fischer Apr 24 '23 at 08:11
  • @UlrikeFischer Yes thats always a solid option to fall back on, and shouldnt be too hard even with hyperlinks. But if possible, I'd like more precision than just a page number, as skimming through a full page in a small font can be a little tedious. – MaxD Apr 24 '23 at 08:18
  • Are you searching for \pageref{ref:DogsCats}? Or maybe something like varioref package? – cabohah Apr 24 '23 at 09:40

2 Answers2

1

You can use the \hypertarget{label#1}{sentence in appendix}

To reference this, use the \hyperlink{label#1}{sentence that refers to appendix}

Notice the label is the same.

The latter bracket in both cases, is what will be displayed in the texts

  • 1
    Doesn't work in print, but is a cute idea for the digital document. – MaxD Apr 24 '23 at 08:22
  • You asked for "some kind of reverse link in a similar way"?

    But what do you mean then? Would you like it to state "see line 34 of page 5" or something like that? Otherwise, I'm not sure how it could work on print?

    – Squared2 Apr 24 '23 at 08:30
  • 1
    Yeah, something like that, or "see page 34 marker B" and then theres a fat red "B" somewhere. I just assumed premade solutions for this kind of stuff should already exist and I just don't know how they are called. – MaxD Apr 24 '23 at 08:44
  • Try seeing this. You could maybe make a marker in the left margin, and then ref to that marker if possible. https://tex.stackexchange.com/q/123392/270205 – Squared2 Apr 24 '23 at 09:15
  • That's a great idea, I'll definitely look into this if there aren't more specialized solutions. – MaxD Apr 24 '23 at 09:23
0

Here's what I pieced together using lineno and a few other answers on this site. Doesn't do everything I wanted, but its relatively simple and good enough for me.

\documentclass{article}
\usepackage[colorlinks]{hyperref}
\usepackage[pagewise,right]{lineno}
\usepackage{lipsum}

\newcommand{\llabel}[1]{% \hypertarget{llineno:#1}{\linelabel{#1}}}

\newcommand{\linepageref}[1]{% page~\hyperlink{llineno:#1}{\pageref{#1}}\ % line~\hyperlink{llineno:#1}{\ref{#1}}}

\begin{document} \section{Document} The most important thing to understand in this course is that dogs don't like cats [\linepageref{ref:DogsCats}]. \section{Appendix} \begin{linenumbers} Some wall of text that explains how animals don't always like each other. This text is really long so a reference to the section isn't precise enough, and it can't be changed or reformatted in any way. For example, monkeys don't like bats, crocodiles don't like pangolins, 50 other animals also don't like each other, dogs don't like cats \llabel{ref:DogsCats}, mice don't like rabbits, and a good 30 more examples. \end{linenumbers} \end{document}

Screenshot

MaxD
  • 1,137