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

Skip to content

Commit ebcb658

Browse files
committed
Revise some of the PDF support to get at least preliminary outline support.
Rewrite \seemodule (again) to allow an optional argument to support modules which include an underscore in the names. See example in comments.
1 parent 8f9728b commit ebcb658

2 files changed

Lines changed: 102 additions & 12 deletions

File tree

Doc/python.sty

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
%
1313
\RequirePackage[Bjarne]{fncychap}\typeout{Using fancy chapter headings.}
1414

15-
1615
% for PDF output, use maximal compression
1716
\@ifundefined{pdfannotlink}{
1817
\let\LinkColor=\relax
@@ -22,6 +21,10 @@
2221
\let\LinkColor=\NavyBlue
2322
\let\NormalColor=\Black
2423
\pdfcompresslevel=9
24+
%
25+
% This definition allows the entries in the page-view of the ToC to be
26+
% active links. Some work, some don't.
27+
%
2528
\let\OldContentsline=\contentsline
2629
\renewcommand{\contentsline}[3]{%
2730
\OldContentsline{#1}{%
@@ -30,6 +33,14 @@
3033
\pdfendlink%
3134
}{#3}%
3235
}
36+
\renewcommand{\thepage}{\roman{page}}
37+
%
38+
% This is supposed to build the "outline" view of the document; it seems
39+
% quite fragile. The breakages are the same as in the ToC.
40+
%
41+
\AtEndDocument{
42+
\InputIfFileExists{\jobname.bkm}{\pdfcatalog pagemode{/UseOutlines}}{}
43+
}
3344
\let\OldLabel=\label
3445
\renewcommand{\label}[1]{%
3546
\OldLabel{#1}%
@@ -44,11 +55,8 @@
4455
\def\@begindvi{%
4556
\unvbox \@begindvibox
4657
\@hyperfixhead
47-
\global\let \@begindvi \@hyperfixhead
4858
}
49-
\def\hyperpageanchor{%
50-
\hyper@anchorstart{page.\thepage}\hyper@anchorend
51-
}
59+
\def\hyperpageanchor{\pdfdest name{page.\thepage}}
5260
\let\HYPERPAGEANCHOR\hyperpageanchor
5361
\def\@hyperfixhead{%
5462
\let\H@old@thehead\@thehead
@@ -494,12 +502,49 @@
494502
% \begin{seealso}
495503
% \seemodule{rand}{Uniform random number generator}; % Module xref
496504
% \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book
505+
%
506+
% % A funky case: module name contains '_'; have to supply an optional key
507+
% \seemodule[copyreg]{copy_reg}{pickle interface constructor registration}
508+
%
497509
% \end{seealso}
498510

511+
\newif\if@keyedmodule\@keyedmodulefalse
512+
\newcommand{\@modulebadkey}{{--just-some-junk--}}
513+
514+
\@ifundefined{pdfannotlink}{%
515+
\newcommand{\seemodule}[3][\@modulebadkey]{%
516+
\ifx\@modulebadkey#1\def\@modulekey{#2}\else\def\@modulekey{#1}\fi%
517+
\ref{module-\@modulekey}:\quad %
518+
Module \module{#2}%
519+
\quad (#3)%
520+
}
521+
}{\newcommand{\seemodule}[3][\@modulebadkey]{%
522+
\ifx\@modulebadkey#1\def\@modulekey{#2}\else\def\@modulekey{#1}\fi%
523+
\ref{module-\@modulekey}:\quad %
524+
{\pdfannotlink attr{/Border [0 0 0]} goto name{label.module-\@modulekey}%
525+
\LinkColor Module \module{#2} \NormalColor%
526+
\pdfendlink%
527+
}%
528+
\quad (#3)%
529+
}
530+
}
499531
\newenvironment{seealso}[0]{
500532
\strong{See Also:}\par
501533
% These should only be defined within the {seealso} environment:
502-
\def\seemodule##1##2{\ref{module-##1}:\quad Module \module{##1}\quad (##2)}
534+
%\def\see@module##1##2{\ref{module-##1}:\quad Module \module{##1}\quad (##2)}
535+
% \def\@seemodule[##1]##2##3{%
536+
% \ref{module-##2}:\quad %
537+
% \@ifundefined{pdfannotlink}{%
538+
% Module \module{##2}%
539+
% }{\if@keyedmodule\@keyedmodulefalse\fi%
540+
% {\pdfannotlink attr{/Border [0 0 0]} goto name{module.##1}%
541+
% \LinkColor Module \module{##2}\NormalColor\pdfendlink}%
542+
% }%
543+
% \quad (##3)%
544+
% }
545+
% \def\seemodule{%
546+
% \@ifnextchar [\@seemodule{\@keyedmoduletrue \@seemodule[]}%
547+
% }
503548
\def\seetext##1{\par{##1}}
504549
}{\par}
505550

Doc/texinputs/python.sty

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
%
1313
\RequirePackage[Bjarne]{fncychap}\typeout{Using fancy chapter headings.}
1414

15-
1615
% for PDF output, use maximal compression
1716
\@ifundefined{pdfannotlink}{
1817
\let\LinkColor=\relax
@@ -22,6 +21,10 @@
2221
\let\LinkColor=\NavyBlue
2322
\let\NormalColor=\Black
2423
\pdfcompresslevel=9
24+
%
25+
% This definition allows the entries in the page-view of the ToC to be
26+
% active links. Some work, some don't.
27+
%
2528
\let\OldContentsline=\contentsline
2629
\renewcommand{\contentsline}[3]{%
2730
\OldContentsline{#1}{%
@@ -30,6 +33,14 @@
3033
\pdfendlink%
3134
}{#3}%
3235
}
36+
\renewcommand{\thepage}{\roman{page}}
37+
%
38+
% This is supposed to build the "outline" view of the document; it seems
39+
% quite fragile. The breakages are the same as in the ToC.
40+
%
41+
\AtEndDocument{
42+
\InputIfFileExists{\jobname.bkm}{\pdfcatalog pagemode{/UseOutlines}}{}
43+
}
3344
\let\OldLabel=\label
3445
\renewcommand{\label}[1]{%
3546
\OldLabel{#1}%
@@ -44,11 +55,8 @@
4455
\def\@begindvi{%
4556
\unvbox \@begindvibox
4657
\@hyperfixhead
47-
\global\let \@begindvi \@hyperfixhead
4858
}
49-
\def\hyperpageanchor{%
50-
\hyper@anchorstart{page.\thepage}\hyper@anchorend
51-
}
59+
\def\hyperpageanchor{\pdfdest name{page.\thepage}}
5260
\let\HYPERPAGEANCHOR\hyperpageanchor
5361
\def\@hyperfixhead{%
5462
\let\H@old@thehead\@thehead
@@ -494,12 +502,49 @@
494502
% \begin{seealso}
495503
% \seemodule{rand}{Uniform random number generator}; % Module xref
496504
% \seetext{\emph{Encyclopedia Britannica}}. % Ref to a book
505+
%
506+
% % A funky case: module name contains '_'; have to supply an optional key
507+
% \seemodule[copyreg]{copy_reg}{pickle interface constructor registration}
508+
%
497509
% \end{seealso}
498510

511+
\newif\if@keyedmodule\@keyedmodulefalse
512+
\newcommand{\@modulebadkey}{{--just-some-junk--}}
513+
514+
\@ifundefined{pdfannotlink}{%
515+
\newcommand{\seemodule}[3][\@modulebadkey]{%
516+
\ifx\@modulebadkey#1\def\@modulekey{#2}\else\def\@modulekey{#1}\fi%
517+
\ref{module-\@modulekey}:\quad %
518+
Module \module{#2}%
519+
\quad (#3)%
520+
}
521+
}{\newcommand{\seemodule}[3][\@modulebadkey]{%
522+
\ifx\@modulebadkey#1\def\@modulekey{#2}\else\def\@modulekey{#1}\fi%
523+
\ref{module-\@modulekey}:\quad %
524+
{\pdfannotlink attr{/Border [0 0 0]} goto name{label.module-\@modulekey}%
525+
\LinkColor Module \module{#2} \NormalColor%
526+
\pdfendlink%
527+
}%
528+
\quad (#3)%
529+
}
530+
}
499531
\newenvironment{seealso}[0]{
500532
\strong{See Also:}\par
501533
% These should only be defined within the {seealso} environment:
502-
\def\seemodule##1##2{\ref{module-##1}:\quad Module \module{##1}\quad (##2)}
534+
%\def\see@module##1##2{\ref{module-##1}:\quad Module \module{##1}\quad (##2)}
535+
% \def\@seemodule[##1]##2##3{%
536+
% \ref{module-##2}:\quad %
537+
% \@ifundefined{pdfannotlink}{%
538+
% Module \module{##2}%
539+
% }{\if@keyedmodule\@keyedmodulefalse\fi%
540+
% {\pdfannotlink attr{/Border [0 0 0]} goto name{module.##1}%
541+
% \LinkColor Module \module{##2}\NormalColor\pdfendlink}%
542+
% }%
543+
% \quad (##3)%
544+
% }
545+
% \def\seemodule{%
546+
% \@ifnextchar [\@seemodule{\@keyedmoduletrue \@seemodule[]}%
547+
% }
503548
\def\seetext##1{\par{##1}}
504549
}{\par}
505550

0 commit comments

Comments
 (0)