Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a2c2a83

Browse files
committed
Fix the broken PDF links, really this time!
"." cannot be part of the target names either. Appending a junk char to the end doesn't quite do it, or doesn't seem to at any rate. Instead, pad the page numbers to always be 3 charaters wide, with leading zeros.
1 parent a88d681 commit a2c2a83

1 file changed

Lines changed: 36 additions & 22 deletions

File tree

Doc/texinputs/python.sty

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,22 @@
2727
\let\NormalColor=\Black
2828
\pdfcompresslevel=9
2929
%
30+
% Pad the number with '0' to 3 digits wide so no page name is a prefix
31+
% of any other.
32+
%
33+
\def\py@targetno#1{\ifnum#1<100 0\fi\ifnum#1<10 0\fi#1}
34+
\def\py@pageno{\py@targetno\thepage}
35+
%
3036
% This definition allows the entries in the page-view of the ToC to be
3137
% active links. Some work, some don't.
3238
%
3339
\let\OldContentsline=\contentsline
40+
% Compute the padded page number separately since we end up with a pair of
41+
% \relax tokens; this gets the right string computed and works.
3442
\renewcommand{\contentsline}[3]{%
43+
\def\my@pageno{\py@targetno{#3}}%
3544
\OldContentsline{#1}{%
36-
\pdfannotlink attr{/Border [0 0 0]} goto name{page.#3}%
45+
\pdfannotlink attr{/Border [0 0 0]} goto name{page\my@pageno}%
3746
\LinkColor#2\NormalColor%
3847
\pdfendlink%
3948
}{#3}%
@@ -45,12 +54,17 @@
4554
\AtEndDocument{
4655
\InputIfFileExists{\jobname.bkm}{\pdfcatalog{/PageMode /UseOutlines}}{}
4756
}
57+
\newcommand{\py@target}[1]{%
58+
\if@doing@page@targets%
59+
{\pdfdest name{#1} fit}%
60+
\fi%
61+
}
4862
\let\OldLabel=\label
4963
\renewcommand{\label}[1]{%
5064
\OldLabel{#1}%
51-
{\pdfdest name{label.#1} fit}%
65+
\py@target{label-#1}%
5266
}
53-
% This stuff adds a page.# destination to every PDF page, where # has
67+
% This stuff adds a page# destination to every PDF page, where # has
5468
% the same formatting as the displayed page number. This doesn't really
5569
% help with the frontmatter, but does fine with the body.
5670
%
@@ -62,7 +76,7 @@
6276
}
6377
\def\@hyperfixhead{%
6478
\let\H@old@thehead\@thehead
65-
\gdef\@foo{\if@doing@page@targets\pdfdest name{page.\thepage x} fit\fi}%
79+
\global\def\@foo{\py@target{page\py@pageno}}%
6680
\expandafter\ifx\expandafter\@empty\H@old@thehead
6781
\def\H@old@thehead{\hfil}\fi
6882
\def\@thehead{\@foo\relax\H@old@thehead}%
@@ -191,26 +205,26 @@
191205
% Augment the sectioning commands used to get our own font family in place,
192206
% and reset some internal data items:
193207
\renewcommand{\section}{\reset@python%
194-
\@startsection {section}{1}{\z@}%
195-
{-3.5ex \@plus -1ex \@minus -.2ex}%
196-
{2.3ex \@plus.2ex}%
197-
{\reset@font\Large\HeaderFamily}}
208+
\@startsection{section}{1}{\z@}%
209+
{-3.5ex \@plus -1ex \@minus -.2ex}%
210+
{2.3ex \@plus.2ex}%
211+
{\reset@font\Large\HeaderFamily}}
198212
\renewcommand{\subsection}{\@startsection{subsection}{2}{\z@}%
199-
{-3.25ex\@plus -1ex \@minus -.2ex}%
200-
{1.5ex \@plus .2ex}%
201-
{\reset@font\large\HeaderFamily}}
213+
{-3.25ex\@plus -1ex \@minus -.2ex}%
214+
{1.5ex \@plus .2ex}%
215+
{\reset@font\large\HeaderFamily}}
202216
\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{\z@}%
203-
{-3.25ex\@plus -1ex \@minus -.2ex}%
204-
{1.5ex \@plus .2ex}%
205-
{\reset@font\normalsize\HeaderFamily}}
217+
{-3.25ex\@plus -1ex \@minus -.2ex}%
218+
{1.5ex \@plus .2ex}%
219+
{\reset@font\normalsize\HeaderFamily}}
206220
\renewcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}%
207-
{3.25ex \@plus1ex \@minus.2ex}%
208-
{-1em}%
209-
{\reset@font\normalsize\HeaderFamily}}
221+
{3.25ex \@plus1ex \@minus.2ex}%
222+
{-1em}%
223+
{\reset@font\normalsize\HeaderFamily}}
210224
\renewcommand{\subparagraph}{\@startsection{subparagraph}{5}{\parindent}%
211225
{3.25ex \@plus1ex \@minus .2ex}%
212226
{-1em}%
213-
{\reset@font\normalsize\HeaderFamily}}
227+
{\reset@font\normalsize\HeaderFamily}}
214228

215229

216230
% Underscore hack (only act like subscript operator if in math mode)
@@ -518,17 +532,17 @@
518532
% Use this def/redef approach for \url{} since hyperref defined this already,
519533
% but only if we actually used hyperref:
520534
\@ifundefined{pdfannotlink}{
521-
\newcommand{\pythonurl}[1]{\mbox{\small\textsf{#1}}}
535+
\newcommand{\py@url}[1]{\mbox{\small\textsf{#1}}}
522536
}{
523-
\newcommand{\pythonurl}[1]{{%
537+
\newcommand{\py@url}[1]{{%
524538
\pdfannotlink attr{/Border [0 0 0]} user{/S /URI /URI (#1)}%
525539
\LinkColor% color of the link text
526540
{\small\textsf{#1}}%
527541
\NormalColor% Turn it back off; these are declarative
528542
\pdfendlink}% and don't appear bound to the current
529543
}% formatting "box".
530544
}
531-
\let\url=\pythonurl
545+
\let\url=\py@url
532546
\newcommand{\email}[1]{{\small\textsf{#1}}}
533547
\newcommand{\newsgroup}[1]{{\small\textsf{#1}}}
534548

@@ -643,7 +657,7 @@
643657
}{\newcommand{\seemodule}[3][\@modulebadkey]{%
644658
\ifx\@modulebadkey#1\def\@modulekey{#2}\else\def\@modulekey{#1}\fi%
645659
\ref{module-\@modulekey}:\quad %
646-
{\pdfannotlink attr{/Border [0 0 0]} goto name{label.module-\@modulekey}%
660+
{\pdfannotlink attr{/Border [0 0 0]} goto name{label-module-\@modulekey}%
647661
\LinkColor Module \module{#2} \NormalColor%
648662
\pdfendlink%
649663
}%

0 commit comments

Comments
 (0)