Skip to content

Commit aa2aea0

Browse files
committed
\py@linkToName: New macro to consolidate support for most internal
hyperlinking in the PDF version. This also allows many of the macros that do this stuff to be a good bit more readable. Takes the target name and link content as parameters. Use \py@linkToName for all internal links.
1 parent 580f4ab commit aa2aea0

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

Doc/texinputs/python.sty

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,21 @@
3737
% active links. Some work, some don't.
3838
%
3939
\let\py@OldContentsline=\contentsline
40+
%
41+
% Macro that takes two args: the name to link to and the content of
42+
% the link. This takes care of the PDF magic, getting the colors
43+
% the same for each link, and avoids having lots of garbage all over
44+
% this style file.
45+
\newcommand{\py@linkToName}[2]{%
46+
\pdfannotlink attr{/Border [0 0 0]} goto name{#1}%
47+
\py@LinkColor#2\py@NormalColor%
48+
\pdfendlink%
49+
}
4050
% Compute the padded page number separately since we end up with a pair of
4151
% \relax tokens; this gets the right string computed and works.
4252
\renewcommand{\contentsline}[3]{%
4353
\def\my@pageno{\py@targetno{#3}}%
44-
\py@OldContentsline{#1}{%
45-
\pdfannotlink attr{/Border [0 0 0]} goto name{page\my@pageno}%
46-
\py@LinkColor#2\py@NormalColor%
47-
\pdfendlink%
48-
}{#3}%
54+
\py@OldContentsline{#1}{\py@linkToName{page\my@pageno}{#2}}{#3}%
4955
}
5056
\AtEndDocument{
5157
\InputIfFileExists{\jobname.bkm}{\pdfcatalog{/PageMode /UseOutlines}}{}
@@ -232,12 +238,10 @@
232238
% name, at least if we're building PDF:
233239
\@ifundefined{pdfannotlink}{%
234240
\newcommand{\refmodule}[2][\py@modulebadkey]{\module{#2}}
235-
}{\newcommand{\refmodule}[2][\py@modulebadkey]{%
241+
}{%
242+
\newcommand{\refmodule}[2][\py@modulebadkey]{%
236243
\ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
237-
{\pdfannotlink attr{/Border [0 0 0]} goto name{label-module-\py@modulekey}%
238-
\py@LinkColor\module{#2}\py@NormalColor%
239-
\pdfendlink%
240-
}%
244+
\py@linkToName{label-module-\py@modulekey}{\module{#2}}%
241245
}
242246
}
243247

@@ -362,10 +366,9 @@
362366
\@ifundefined{pdfoutput}{
363367
\newcommand{\py@ModSynopsisSummary}[4]{\bfcode{#2} & #4\\}
364368
}{
365-
\newcommand{\py@ModSynopsisSummary}[4]{
366-
{\pdfannotlink attr{/Border [0 0 0]} goto name{label-module-#1}
367-
\py@LinkColor \bfcode{#2} \py@NormalColor
368-
\pdfendlink}& #4\\}
369+
\newcommand{\py@ModSynopsisSummary}[4]{%
370+
\py@linkToName{label-module-#1}{\bfcode{#2}} & #4\\
371+
}
369372
}
370373
\newenvironment{synopsistable}{
371374
% key, name, type, synopsis
@@ -807,10 +810,7 @@
807810
\par%
808811
\ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
809812
\ref{module-\py@modulekey}:\quad %
810-
{\pdfannotlink attr{/Border [0 0 0]} goto name{label-module-\py@modulekey}%
811-
\py@LinkColor Module \module{#2} \py@NormalColor%
812-
\pdfendlink%
813-
}%
813+
\py@linkToName{label-module-\py@modulekey}{ Module \module{#2} }
814814
\quad (#3)%
815815
}
816816
}

0 commit comments

Comments
 (0)