The problem: the internal cross-references (hyperclickable links) that
refer to pages in the frontmatter, i.e. pages numbered with roman
letters, don't point to the correct page but to some other page. The
log will say something such as
! pdfTeX warning (dest): name{page.xiii} has been referenced but does
not exist
, replaced by a fixed one
! pdfTeX warning (dest): name{page.xix} has been referenced but does
not exist,
replaced by a fixed one
Needless to say, the pages in question do exist. What is one supposed
to do?
Frank
Isn't there an ISO standard that all electronic documents should have the
first page numbered 1, and page numbers should just increase without jumps
or changes? For the electronic behaviour, you could educate your users...
--
Lucian Wischik, Queens' College, Cambridge CB3 9ET. www.wischik.com/lu
> Isn't there an ISO standard that all electronic documents should have the
> first page numbered 1, and page numbers should just increase without jumps
> or changes? For the electronic behaviour, you could educate your users...
Regardless of any nice standard, it is often necessary to make two
identical versions of a document, printed and digital. There are very
strict old rules and traditions about the page numbering in printed
documents, and they do not change overnight, however strange those
rules might be.
- Ville
--
Ville Voipio, M.Sc. (EE)
> The problem: the internal cross-references (hyperclickable links) that
> refer to pages in the frontmatter, i.e. pages numbered with roman
> letters, don't point to the correct page but to some other page.
hyperref option "plainpages=false" will help.
Yours sincerely
Heiko <ober...@uni-freiburg.de>
Unfortunately it does not. The following stripped-down code
demonstrates. The output, on physical page 5 (numbered 1 and following
pages i--iv), has the correct text on it (i.e. it refers to the title
page as being iii) but the hyperlink on iii takes you to page i.
NB: I get this same result with and without the "plainpages=false".
Frank
\documentclass{book}
\usepackage[
pdftex,
pdfpagemode=None,
plainpages=false,
]{hyperref}
\begin{document}
\frontmatter
{\LARGE Half-title page}
\newpage
Half-title verso
\newpage
\label{title}
{\Huge Title page}
\newpage
Title verso
\newpage
% -----------------------------------------------------
\mainmatter
\label{bookstart}
The actual book starts here, on page \pageref{bookstart}. It also
refers to the title page, numbered \pageref{title}, in the front
matter.
\backmatter
\end{document}
I definitely agree with you in principle; indeed, the original version
of this text had its pages numbered from 1, breaking with tradition,
and I explained in the introduction that that was because I felt that
having to think "hmm, so to get pages 30--38 I must actually print
pages 42--50 because of the first xii non-pages" was only an
anachronistic homage to the days when the table of contents was not
compiled by computer.
However, now that it's going to be printed as a book, Ville's comment
applies:
> Regardless of any nice standard, it is often necessary to make two
> identical versions of a document, printed and digital. There are very
> strict old rules and traditions about the page numbering in printed
> documents, and they do not change overnight, however strange those
> rules might be.
Indeed so. My publisher sent me a booklet with their house rules and
they specify very precisely what has to go on page i, what else has to
go on page ii, and so on. The front matter has a very well-defined
format, and I have no freedom to change it.
Quite apart from the ideal desirability of having pages numbered from
1, if there are instances in which latex can produce front matter
pages with roman numbering, I believe that there ought to be a way for
hyperref and friends to get correct references to such pages, which is
what I'm after right now.
Frank
Put the following in your Preamble
\makeatletter
\AtBeginDocument{%
\let\old@label\label%
\renewcommand\label[1]{\old@label{#1}\write\@auxout{%
\noexpand\expandafter\noexpand\gdef\noexpand\csname
pagenum.#1\noexpand\endcsname{\thepage}}}%
\renewcommand\pageref[1]{\edef\a{\csname
pagenum.#1\endcsname}\expandafter\hyperlink{page.\a}{page \a}}%
}
\makeatother
BTW, you can use PDF Page Labels to have the front matter pages labelled in
roman, and the main pages labelled in decimal, so choosing "Goto Page" from
the Acrobat Reader menu, and typing "3" goes to page 3 and not page iii. I
have some code for that too.
Anthony
--
Anthony Williams
Software Engineer, Nortel Networks Optoelectronics
The opinions expressed in this message are not necessarily those of my
employer
Sorry, this line should be
\renewcommand\pageref[1]{\edef\a{\csname
pagenum.#1\endcsname}\expandafter\hyperlink{page.\a}{\a}}%
> }
> \makeatother
I don't agree in principle. That makes the stupidity of some
tools for viewing and printing electronic documents standard! :-)
-David
> > hyperref option "plainpages=false" will help.
>
> Unfortunately it does not. The following stripped-down code
> demonstrates. The output, on physical page 5 (numbered 1 and following
> pages i--iv), has the correct text on it (i.e. it refers to the title
> page as being iii) but the hyperlink on iii takes you to page i.
>
> \documentclass{book}
> \usepackage[
> pdftex,
> pdfpagemode=None,
> plainpages=false,
> ]{hyperref}
>
> \begin{document}
>
> \frontmatter
>
> {\LARGE Half-title page}
> \newpage
>
> Half-title verso
> \newpage
>
> \label{title}
> {\Huge Title page}
> \newpage
>
> Title verso
> \newpage
>
>
> % -----------------------------------------------------
>
> \mainmatter
>
> \label{bookstart}
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
Yours sincerely
Heiko <ober...@uni-freiburg.de>
> "Frank Stajano" <frank....@glb.toshiba.co.jp> wrote in message
> news:256cb69d.01102...@posting.google.com...
> > Quite apart from the ideal desirability of having pages numbered from
> > 1, if there are instances in which latex can produce front matter
> > pages with roman numbering, I believe that there ought to be a way for
> > hyperref and friends to get correct references to such pages, which is
> > what I'm after right now.
>
> Put the following in your Preamble
>
> \makeatletter
> \AtBeginDocument{%
> \let\old@label\label%
> \renewcommand\label[1]{\old@label{#1}\write\@auxout{%
> \noexpand\expandafter\noexpand\gdef\noexpand\csname
> pagenum.#1\noexpand\endcsname{\thepage}}}%
> \renewcommand\pageref[1]{\edef\a{\csname
dangerously, \a is overwritten. Better to put this in a group.
> pagenum.#1\endcsname}\expandafter\hyperlink{page.\a}{page \a}}%
> }
> \makeatother
??? With option "plainpages=false" \thepage instead of the value
of the page counter is used for the internal page anchor names.
> BTW, you can use PDF Page Labels to have the front matter pages labelled in
> roman, and the main pages labelled in decimal, so choosing "Goto Page" from
> the Acrobat Reader menu, and typing "3" goes to page 3 and not page iii. I
> have some code for that too.
It is already in hyperref: option "pdfpagelabels" activates it (the
current value of \thepage is used).
Yours sincerely
Heiko <ober...@uni-freiburg.de>
Agreed. I wrote this in a hurry.
> > pagenum.#1\endcsname}\expandafter\hyperlink{page.\a}{page \a}}%
> > }
> > \makeatother
>
> ??? With option "plainpages=false" \thepage instead of the value
> of the page counter is used for the internal page anchor names.
I know. My code should work OK with plainpages=false, or plainpages=true
> > BTW, you can use PDF Page Labels to have the front matter pages labelled
in
> > roman, and the main pages labelled in decimal, so choosing "Goto Page"
from
> > the Acrobat Reader menu, and typing "3" goes to page 3 and not page iii.
I
> > have some code for that too.
>
> It is already in hyperref: option "pdfpagelabels" activates it (the
> current value of \thepage is used).
It's not documented in hyperref 6.71e (is there a later version?), though it
does work.
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.
But it only works with plainpages=false
Yes. Why is it that in WordPerfect I can specify page ranges as
v-xii,4-10
and obtain correct result, and I cannot do this in Acrobat (nor
GSView, nor YaP, nor any other previewer I know of).
That is, why do electonic document viewers *not* support 'logical'
page ranges?
--
Giuseppe "Oblomov" Bilotta
Axiom I of the Giuseppe Bilotta
theory of IT:
Anything is better than MS
because electronic document formats don't support them. dvi (as used
by plain) has negative page numbers for roman-numbered pages, but
otherwise the representation of page numbers only appears in typeset
output. this is not an uncommon failing (though i don't know the pdf
spec well enough to know whether there's something there not being
used...).
--
Robin Fairbairns, Cambridge -- rf10 at cam dot ac dot uk
> "Heiko Oberdiek" <ober...@uni-freiburg.de> wrote in message
> news:9rm8bv$83k$1...@n.ruf.uni-freiburg.de...
> > It is already in hyperref: option "pdfpagelabels" activates it (the
> > current value of \thepage is used).
>
> It's not documented in hyperref 6.71e (is there a later version?), though it
> does work.
The current version is 6.71s
(http://www.tug.org/applications/hyperref/hyperref.zip).
It is not very well documented (ChangeLog entry of
1999/11/04 6.67b or hyperref.dtx). But I consider
the option as stable. (Perhaps I will stop answering
questions in newsgroups and will invest the time in
writing some kind of documentation.)
Yours sincerely
Heiko <ober...@uni-freiburg.de>
> "Heiko Oberdiek" <ober...@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
>
> 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.
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.
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.
* 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.
* It is easy to overwrite the current hyperref behaviour
(for example with the help of \phantomsection. But not
vice versa.
Yours sincerely
Heiko <ober...@uni-freiburg.de>
> Giuseppe Bilotta <obl...@freemail.it> wrote:
> >That is, why do electonic document viewers *not* support 'logical'
> >page ranges?
>
> because electronic document formats don't support them. dvi (as used
> by plain) has negative page numbers for roman-numbered pages, but
> otherwise the representation of page numbers only appears in typeset
> output.
The DVI format does provide for 10 "page number" counters which could
probably be used to much greater effect than is currently practiced.
For example, it would be possible to have count0 indicate global page
number starting from 1 and running through the whole document, count1
giving "current major division" (0 meaning frontmatter, 1 meaning main
body, 2 meaning backmatter), and count2 giving page number within the
current division. It would be relatively simple for the macro package to
produce a suitable roman or arabic numeral once the convention has been
established. Another interesting possibility might be to use one of the
page number registers to indicate the current color when doing color
separations.
i used (in days of yore) to make wide use of the "other" page
counters. this was when i was a co-maintainer (with brian hamilton
kelly) of dvitoln03: back then, if my dvi driver didn't do what i
wanted, i made it do it. right now, i've no real feel for the inner
workings of dvips, and i've not got the time to invest...
>For example, it would be possible to have count0 indicate global page
>number starting from 1 and running through the whole document, count1
>giving "current major division" (0 meaning frontmatter, 1 meaning main
>body, 2 meaning backmatter), and count2 giving page number within the
>current division. It would be relatively simple for the macro package to
>produce a suitable roman or arabic numeral once the convention has been
>established. Another interesting possibility might be to use one of the
>page number registers to indicate the current color when doing color
>separations.
this is all very fine: i could imagine that, with a little honing, it
could become the basis of a good tight standard. however, getting
such a standard adopted as "the way tex behaves" seems pretty far out
to me: who's going to listen to the proselytising? who's going to
code the required changes to a dozen or more dvi drivers and myriad
packages?
that the registers are "available" in dvi isn't enough to claim that
the facilities are there. it takes standardisation, and acceptance of
the standards ... and that doesn't come easy in the tex world.
Unless the footnote counter is in a group, in which case the footnote ref
shows the section counter, not the footnote counter. The must be a way to
get use the footnote counter for footnotes, and the section counter for
sections.
> * 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.
likewise, if I see "see page 23" I expect the hyperlink to go to page 23,
not several pages earlier, where the section started.
> * 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.
Anthony
--
Anthony Williams
Software Engineer, Nortel Networks Optical Components Ltd
Sorry, this was a fault of my \ref-hacking. Footnotes in groups show the
correct footnote counter, and subsequent labels in the section still use the
section counter.
Are there any consequences for always putting footnotes in a group?
thank you for your interesting and instructive messages. I have
something to say about all this, but the book deadline is looming so
I'll have to get back to you a little later.
Frank
> > * 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.
>
> likewise, if I see "see page 23" I expect the hyperlink to go to page 23,
> not several pages earlier, where the section started.
Then you can use the \hyperpage feature that is
normally used for the index links. So the page
information of a label can be extracted and
can be given \hyperpage:
\label{page:foo}
...
\hyperpage{\GetPageRef{page:foo}}
For this purpose I have started to write a package,
but it is not yes finished.
Currently you can try \hypergetpageref for \GetPageRef
(but there can be problems with undefined labels).
Or another possibility is the use of \phantomsection:
\newcommand*{\setpagelabel}{\phantomsection\label}
...
\setpagelabel{page:foo}
...
\pageref{page:foo}
But \ref{page:foo} should not be used then.
> > * 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?
No, that is bad, for example:
\section executes \refstepcounter{section}, here the anchor
is made, then the title of the section follows.
After this the user writes \label{foo}.
With the current behaviour \ref{foo} points to the section
title as expected. But if all \label commands executes
also \phantomsection, then the \ref does not point to
the section title but to the place of the \label. And there is
no way back using \label or \ref.
> It seems to me that the obvious place for the link anchor is the actual
> location of the \label, anything else is counterintuitive.
No, perhaps for \pageref, not for \ref. Using a link such as
"see section 1.2" should point to the beginning of the section,
not to the \label command that perhaps comes at the end
of the section.
Yours sincerely
Heiko <ober...@uni-freiburg.de>
"Anthony Williams" <ant...@nortelnetworks.com> wrote in message news:<9rmbr9$umubi$1...@ID-49767.news.dfncis.de>...
> "Heiko Oberdiek" <ober...@uni-freiburg.de> wrote in message
> news:9rm8bv$83k$1...@n.ruf.uni-freiburg.de...
> > On Tue, 30 Oct 2001 10:00:38 -0000, "Anthony Williams"
> > <ant...@nortelnetworks.com> wrote:
> >
> > > "Frank Stajano" <frank....@glb.toshiba.co.jp> wrote in message
> > > news:256cb69d.01102...@posting.google.com...
> > > > Quite apart from the ideal desirability of having pages numbered from
> > > > 1, if there are instances in which latex can produce front matter
> > > > pages with roman numbering, I believe that there ought to be a way for
> > > > hyperref and friends to get correct references to such pages, which is
> > > > what I'm after right now.
> > >
> > > Put the following in your Preamble
> > >
> > > \makeatletter
> > > \AtBeginDocument{%
> > > \let\old@label\label%
> > > \renewcommand\label[1]{\old@label{#1}\write\@auxout{%
> > > \noexpand\expandafter\noexpand\gdef\noexpand\csname
> > > pagenum.#1\noexpand\endcsname{\thepage}}}%
> > > \renewcommand\pageref[1]{\edef\a{\csname
> >
> > dangerously, \a is overwritten. Better to put this in a group.
>
> Agreed. I wrote this in a hurry.
So, what would be the cleaner version with the group? The above is
totally beyond my comprehension, I just trust you guys to get it
right. By the way, Anthony, I tried your code on a short test document
and it behaved as intended, thanks. I haven't tried it on the whole
book yet.
Heiko explains that it's dangerous to overwrite \a. (What's \a
anyway?) What could happen? What should I watch out for to see if it's
happening to me?
> > ??? With option "plainpages=false" \thepage instead of the value
> > of the page counter is used for the internal page anchor names.
>
> I know. My code should work OK with plainpages=false, or plainpages=true
What is the difference between this option and the pdfpagelabels
mentioned below?
> > > BTW, you can use PDF Page Labels to have the front matter pages labelled
> in
> > > roman, and the main pages labelled in decimal, so choosing "Goto Page"
> from
> > > the Acrobat Reader menu, and typing "3" goes to page 3 and not page iii.
> I
> > > have some code for that too.
> >
> > It is already in hyperref: option "pdfpagelabels" activates it (the
> > current value of \thepage is used).
I tried this on the test document and it worked too, thank you.
Frank
"Anthony Williams" <ant...@nortelnetworks.com> wrote in message news:<9roegm$umpp3$1...@ID-49767.news.dfncis.de>...
> "Heiko Oberdiek" <ober...@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"
> > <ant...@nortelnetworks.com> wrote:
> >
> > > "Heiko Oberdiek" <ober...@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.
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...
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.
Once again, I mean no offense or disrespect, and I hope this will be
taken in the spirit in which it is written. Sarcasm along the lines of
"why don't you use m$ word then" would demonstrate having missed the
point of the message, which is to point out ways in which Latex and
its packages could become more author-friendly, for their own good.
Frank
Here is the version with the group to protect \a
\makeatletter
\AtBeginDocument{%
\let\old@label\label%
\renewcommand\label[1]{\old@label{#1}\write\@auxout{%
\noexpand\expandafter\noexpand\gdef\noexpand\csname
pagenum.#1\noexpand\endcsname{\thepage}}}%
% the difference is an extra { on the following line
% and a } on the one after
\renewcommand\pageref[1]{{\edef\a{\csname
pagenum.#1\endcsname}\expandafter\hyperlink{page.\a}{\a}}}%
}
\makeatother
In short --- it redefines \label to write commands to the .aux file which
define a macro \pagenum.###, where ### is the name of the label. It then
redefines \pageref to use this new macro to get the correct page number and
target in the hyperlink.
> Heiko explains that it's dangerous to overwrite \a. (What's \a
> anyway?) What could happen? What should I watch out for to see if it's
> happening to me?
\a is just a macro. There is no standard definition of it, so someone might
therefore reasonably expect to be able to use it in his own macro code.
However, my original code would overwrite their definition, and may
therefore cause their macros to work incorrectly.
> > > ??? With option "plainpages=false" \thepage instead of the value
> > > of the page counter is used for the internal page anchor names.
> >
> > I know. My code should work OK with plainpages=false, or plainpages=true
It only works if plainpages=false (otherwise their are two page.1 targets,
one for page "i", and one for the real page 1)
> What is the difference between this option and the pdfpagelabels
> mentioned below?
plainpages affects the link names for hyperlinks. pdfpagelabels sets the
page numbering for Acrobat Reader, so you can Goto Page "iii" from the menu.
Anthony
--
Anthony Williams
Software Engineer, Nortel Networks Optical Components Ltd
> Latex by itself is already a festival of special cases. It would be
> desirable to curb this tendency instead of adding to it.
> [...]
> 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.
Complaining does not help, but writing and providing better code,
generation of documentation, translation of documentations ...
> > > 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.
It is a limitation (not all aims can be gained together).
But feel free to write better code.
> 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!
see below.
> 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").
That's the problem, _you_ expect this behaviour, _other_
expect another behaviour. LaTeX's \label-\ref commands
do not say, there is a link in \ref that points to \label!
It says that there is a reference to a structure in \ref
to a structure _before_ \ref on page with the \label.
This are _two_ locations! But hyperref cannot implement
_one_ link that jumps to _two_ places.
The solution of this problem in hyperref is currently:
* Providing of extra link commands: \hypertarget, \hyperlink
* Guessing one of the link targets in \ref, that users probably want.
* Selecting one of the possible link target of \ref due to
implementation restrictions.
> Moreover, from the author's point of view: what on Earth is
> \phantomsection anyway?
Yes, the hyperref documentation should be improved and extended.
But I do not have time for this until my main implementation todos
are done.
So currently some issues are only explained in
* hyperref.dtx
* ChangeLog
* newsgroups, mailing lists
Yours sincerely
Heiko <ober...@uni-freiburg.de>
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.
I see---at least in spirit ;-)
> > Heiko explains that it's dangerous to overwrite \a. (What's \a
> > anyway?) What could happen? What should I watch out for to see if it's
> > happening to me?
>
> \a is just a macro. There is no standard definition of it, so someone might
> therefore reasonably expect to be able to use it in his own macro code.
> However, my original code would overwrite their definition, and may
> therefore cause their macros to work incorrectly.
Got it.
> > > > ??? With option "plainpages=false" \thepage instead of the value
> > > > of the page counter is used for the internal page anchor names.
> > >
> > > I know. My code should work OK with plainpages=false, or plainpages=true
>
> It only works if plainpages=false (otherwise their are two page.1 targets,
> one for page "i", and one for the real page 1)
>
> > What is the difference between this option and the pdfpagelabels
> > mentioned below?
>
> plainpages affects the link names for hyperlinks. pdfpagelabels sets the
> page numbering for Acrobat Reader, so you can Goto Page "iii" from the menu.
Thanks for this explanation too. If I understand correctly,
plainpages = false
the internal hyperlinks are i ii iii 1 2 3 4
plainpages = true
the internal hyperlinks are 1 2 3 1 2 3 4
pdfpagelabels = false
the pdf page labels are 1 2 3 4 5 6 7
pdfpagelabels = true
the pdf page labels are i ii iii 1 2 3 4
Somehow it is a bit confusing that the matching behaviour of
i ii iii 1 2 3 4
is obtained in one case with false and in the other with true. Maybe a
little more clarity for the user of the package might come from a
renaming along the lines of
useprintedpagenumberforanchors
useprintedpagenumberforpdf
where the first option would correspond to the NOT of plainpages.
Frank
Wow---I am damn impressed! Thank you very much!!!
> 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.
Sounds like exactly what I was after. I am very grateful.
> \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.
I see. That's useful to know, and the previous tips now seem much clearer.
Frank
You misunderstand my intention if you label the above as
"complaining". The reason why I reported those and other misbehaviours
of the software I am (gratefully) using to produce my book is because
I cared enough about it that I thought its authors/maintainers would
appreciate any input that might help them improve it.
For my book I have been blessed by the kindness of 17 competent people
who accepted to read it (10 of them cover-to-cover) and give me
detailed comments on what they perceived as shortcomings or areas
where I could do something a little better. Sometimes it wasn't easy
to have to put in all the extra work required by having to address
their comments, but I feel the book now is a lot better for having
gone through this. I didn't rank their feedback as annoying
complaints, but as valuable help. My comments here were written in
exactly the same spirit of cooperation. Rest assured that I have
better things to do with my time than complaining on newsgroups.
> > > > 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.
>
> It is a limitation (not all aims can be gained together).
> But feel free to write better code.
It is an unwanted side effect that transforms correct references such
as "see section 1.5.4" (which you would get without hyperref) into
incorrect ones such as "see section 17". I do not have the slightest
intention to attack you personally by writing this---I am only
pointing it out as a problem. I see no point in euphemistically
calling "limitation" a bug just because it may be less fun than others
to fix.
I also see no point in the "don't bother reporting problems unless you
also supply fixes", or "let's see if you can do any better than me"
attitude. There is no intention for confrontation here. I appreciate
the work that you and countless others put into making this system
work, and it is because of this that I try to give precise and
reproducible feedback about any problems (I have been a programmer
too). I hope not to have done so in an offensive way, but I apologize
to you if you feel I have (please tell me when).
> > Moreover, from the author's point of view: what on Earth is
> > \phantomsection anyway?
>
> Yes, the hyperref documentation should be improved and extended.
This might point to a general scoping problem in Latex. If at least I
had a way to find out which component defines this \phantomsection
command, then I'd know where to look it up. Up to now I searched
Lamport etc because I didn't even *know* that I was supposed to look
for it in the hyperref documentation, never mind the fact that I
wouldn't have found it in there.
Frank
> plainpages = false
> the internal hyperlinks are i ii iii 1 2 3 4
No, page.i page.ii page.iii page.1 page.2 page.3 page.4
> plainpages = true
> the internal hyperlinks are 1 2 3 1 2 3 4
No, page.1 page.2 page.3 page.1 page.2 page.3 page.4
> pdfpagelabels = false
> the pdf page labels are 1 2 3 4 5 6 7
AR only shows absolute page numbers ("1 of 7")
> pdfpagelabels = true
> the pdf page labels are i ii iii 1 2 3 4
AR (>=4) shows page labels and absolute page numbers:
"i (1 of 7)"
Yours sincerely
Heiko <ober...@uni-freiburg.de>
Thanks!
Stepwise refinement at its best: after three messages (Anthony's, mine
and now yours), here is the clearest explanation of these two options
that I have ever seen so far. Worth cutting and pasting in the
official docs.
Frank