Google Groups Home
Help | Sign in
Message from discussion (low priority) Hyperref & pdflatex: links to frontmatter pages (i, ii, ...) don't work
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Anthony Williams  
View profile
 More options Nov 9 2001, 5:31 am
Newsgroups: comp.text.tex
From: "Anthony Williams" <anth...@nortelnetworks.com>
Date: Fri, 9 Nov 2001 10:30:47 -0000
Local: Fri, Nov 9 2001 5:30 am
Subject: Re: (low priority) Hyperref & pdflatex: links to frontmatter pages (i, ii, ...) don't work
"Frank Stajano" <frank.staj...@glb.toshiba.co.jp> wrote in message

news:256cb69d.0111082129.204bbdc@posting.google.com...
> Back to that same thread...

> "Anthony Williams" <anth...@nortelnetworks.com> wrote in message

<news:9roegm$umpp3$1@ID-49767.news.dfncis.de>...

> > "Heiko Oberdiek" <oberd...@uni-freiburg.de> wrote in message
> > news:9rmm6f$csj$3@n.ruf.uni-freiburg.de...
> > > On Tue, 30 Oct 2001 14:05:31 -0000, "Anthony Williams"
> > > <anth...@nortelnetworks.com> wrote:

> > > > "Heiko Oberdiek" <oberd...@uni-freiburg.de> wrote in message
> > > > news:9rm8bv$83k$2@n.ruf.uni-freiburg.de...
> > > > > There is no place where a counter is "refstepcounted".
> > > > > So \label points to the beginning of the document,
> > > > > where hyperref had set an anchor.

> > > > > Put an \phantomsection in front of the \label command:

> > > > > \mainmatter
> > > > > \phantomsection
> > > > > \label{bookstart}
> > > > > % the last two commands should be on the same page

> Please don't misunderstand me, because I am very grateful for all the
> work that is going into those tools and for the prompt help I receive
> in this newsgroup. However someone should stand up and point out the
> following:

> All this stuff is just gobbledygook to an *author* (as opposed to a
> latex programmer)!

> Latex by itself is already a festival of special cases. It would be
> desirable to curb this tendency instead of adding to it. As an author
> I understand the commands for placing an anchor, namely \label{}, and
> for referring to it, namely \ref{} and \pageref{}, and it would be
> nice if I could stick to that instead of having to understand the
> insides of the processor to ensure that these simple commands do what
> is reasonable to expect that they might do.

> Since I happen to be a computer person I am in fact interested in
> understanding the insides, but if this becomes a precondition for
> making things work then I believe that it will always be hard for
> Latex to spread outside the hacker community. Even people who might
> otherwise value its qualities over a wysiwyg system would be put off
> by these arcane inconsistencies.

> > > > Why doesn't hyperref do this automatically? If I have multiple
labels in
> >  a
> > > > section, I want the pageref hyperlinks to take me to the correct
pages
> >  for
> > > > their location, not for the section anchor, just as the page number
> >  given is
> > > > that of the label, not that of the section start.

> Indeed so.

> > > The LaTeX system is designed for _two_ kinds of informations:
> > > (a) current active counter number (section, equation, ...)
> > > (b) page number

> > > But hyperref has to add a third information:
> > > (c) link anchor

> > > Without redesigning LaTeX this is not possible for all cases.

> One possible logical design would appear to be an anchor object, that
> one could place anywhere in a document, and
> methods/properties/call-them-what-you-like for it that would give you
> its page number, its section number, its equation and so on. Then you
> would be able to have a label inside a figure and say "figure 2.5 in
> section 2.3.8 on page 47", which I don't think you can now (if I
> understand correctly, the figure number masks out the section number).
> But ok, I'll take your word for it that this can't be done without a
> major redesign.

> > > So hyperref tries a compromise:
> > > * In most cases (a) and (b) are unchanged.
> > > * Sometimes (a) is overwritten. For example, if a
> > >    label is set after a section, and a footnote occurs
> > >    between, then (a) shows the footnote counter, not
> > >    the section counter.

> This I would rank as a bug (this was mentioned in another thread),
> because the footnote counter "spills out" of the footnote.

> > > * The anchor points to the last place, where the
> > >    counter for (a) is changed:
> > >      \section{foo}
> > >      ...
> > >      \label{bar}
> > >    Then a link \ref{bar} will jump to the beginning of
> > >    the section, not to the place of the \label command.
> > >    The user will more confused, if clicks on
> > >    "see section 2.1" and he will be guided somewhere
> > >    after or even some pages after.

> This is IMHO a bad design decision---a classical case of trying to
> outguess/outsmart the user and author. If I (author) put an anchor
> somewhere, I damn well expect the link to take me just there! If I
> really wanted to take the reader to the beginning of the section, I
> would explicitly place the anchor at the beginning of the section (or,
> in the ideal system discussed above, I'd say, in the appropriate
> computerese syntax, "beginning of section of anchor xxx").

> If I have a section that's 15 pages long and does not have any
> subsections (that's not my style of writing, but it's just for the
> sake of the example), and I want to refer to a topic discussed down
> there somewhere, I want to be able to say "as discussed in (or: near
> the end of) section 5.4", with the link taking me to the right place,
> and not at the beginning of the section. Otherwise what's the point of
> being able to put the anchor next to the material to which it refers?

> > likewise, if I see "see page 23" I expect the hyperlink to go to page
23,
> > not several pages earlier, where the section started.

> Exactly (though in this case that's already what happens, thankfully).

> > > * It is easy to overwrite the current hyperref behaviour
> > >    (for example with the help of \phantomsection. But not
> > >    vice versa.

> > The user has to remember to use \phantomsection, which is more typing.
For
> > vice-versa, why not just move the label? Or define a \sectionref{}
command?

> > It seems to me that the obvious place for the link anchor is the actual
> > location of the \label, anything else is counterintuitive.

> Yes yes yes.

I agree with you, so I have written the following package:

Save the following as realref.sty. You can then use it with
\usepackage{realref}

\ProvidesPackage{realref}
\RequirePackage[plainpages=false,pdfpagelabels=true]{hyperref}
\def\realref@anchorname{}
\AtBeginDocument{%
% ensure every label is a possible hyperlink target
\let\realref@oldrefstepcounter\refstepcounter%
\DeclareRobustCommand{\refstepcounter}[1]{\realref@oldrefstepcounter{#1}
\edef\realref@anchorname{\string #1.\@currentlabel}%

}%

\let\realref@oldlabel\label%
\DeclareRobustCommand{\label}[1]{\realref@oldlabel{#1}\hypertarget{#1}{}%
\@bsphack\protected@write\@auxout{}{%
    \string\expandafter\gdef\protect\csname
    page@num.#1\string\endcsname{\thepage}%
    \string\expandafter\gdef\protect\csname
    ref@num.#1\string\endcsname{\@currentlabel}%
    \string\expandafter\gdef\protect\csname
    sectionref@name.#1\string\endcsname{\realref@anchorname}%
}\@esphack}%

\DeclareRobustCommand\pageref[1]{{\edef\a{\csname
            page@num.#1\endcsname}\expandafter\hyperlink{page.\a}{\a}}}%
\DeclareRobustCommand\ref[1]{{\edef\a{\csname
            ref@num.#1\endcsname}\hyperlink{#1}{\a}}}%
\DeclareRobustCommand\sectionref[1]{{\edef\a{\csname
            ref@num.#1\endcsname}\edef\b{\csname
            sectionref@name.#1\endcsname}\hyperlink{\b}{\a}}}%

}

This has \pageref jumping to the page on which the ref appears, \ref jumping
to the point of the anchor, and \sectionref jumping to the start of the
section.

> Moreover, from the author's point of view: what on Earth is
> \phantomsection anyway? (This is not a rethorical question BTW.) It's
> not in the index of the Latex book, of the Companion or even of the
> Tex book. The latter two list a \phantom command which appears to have
> to do with leaving spaces in mathematical formulae, so that's probably
> unrelated...

\phantomsection is a hyperref command that adds a section-like anchor at the
current position. All labels after a \phantomsection then refer to that
point, rather than the start of the section.

> It's not just remembering, it's understanding when and why to use it.
> Unintelligible black magic fixes are good to restart the engine and
> get you going again, but are hardly The Right Way for someone who
> needs to depend on this software to produce some important document.

Agreed.

Anthony
--
Anthony Williams
Software Engineer, Nortel Networks Optical Components Ltd
The opinions expressed in this message are not necessarily those of my
employer


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google