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

Skip to content

Commit e59feb5

Browse files
committed
Revise the PDF support in the LaTeX style sheet. This still isn't quite
right, but the tests for whether we are generating PDF are a bit more readable, and some unnecessary indirection has been removed.
1 parent 8e26b52 commit e59feb5

1 file changed

Lines changed: 47 additions & 24 deletions

File tree

Doc/texinputs/python.sty

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
\newif\ifpy@doing@page@targets
2727
\py@doing@page@targetsfalse
2828

29+
\newif\ifpdf\pdffalse
2930
\ifx\pdfoutput\undefined\else\ifcase\pdfoutput
3031
\else
32+
\pdftrue
3133
\input{pdfcolor}
3234
\let\py@LinkColor=\NavyBlue
3335
\let\py@NormalColor=\Black
@@ -253,14 +255,14 @@
253255

254256
% Refer to a module's documentation using a hyperlink of the module's
255257
% name, at least if we're building PDF:
256-
\@ifundefined{pdfannotlink}{%
257-
\newcommand{\refmodule}[2][\py@modulebadkey]{\module{#2}}
258-
}{%
258+
\ifpdf
259259
\newcommand{\refmodule}[2][\py@modulebadkey]{%
260260
\ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
261261
\py@linkToName{label-module-\py@modulekey}{\module{#2}}%
262262
}
263-
}
263+
\else
264+
\newcommand{\refmodule}[2][\py@modulebadkey]{\module{#2}}
265+
\fi
264266

265267
% support for the module index
266268
\newif\ifpy@UseModuleIndex
@@ -434,13 +436,13 @@
434436
}{}
435437
}
436438

437-
\@ifundefined{pdfoutput}{
438-
\newcommand{\py@ModSynopsisSummary}[4]{\bfcode{#2} & #4\\}
439-
}{
439+
\ifpdf
440440
\newcommand{\py@ModSynopsisSummary}[4]{%
441441
\py@linkToName{label-module-#1}{\bfcode{#2}} & #4\\
442442
}
443-
}
443+
\else
444+
\newcommand{\py@ModSynopsisSummary}[4]{\bfcode{#2} & #4\\}
445+
\fi
444446
\newenvironment{synopsistable}{
445447
% key, name, type, synopsis
446448
\let\modulesynopsis=\py@ModSynopsisSummary
@@ -784,18 +786,17 @@
784786

785787
% Use this def/redef approach for \url{} since hyperref defined this already,
786788
% but only if we actually used hyperref:
787-
\@ifundefined{pdfannotlink}{
788-
\newcommand{\py@url}[1]{\mbox{\small\textsf{#1}}}
789-
}{
790-
\newcommand{\py@url}[1]{{%
789+
\ifpdf
790+
\newcommand{\url}[1]{{%
791791
\pdfannotlink attr{/Border [0 0 0]} user{/S /URI /URI (#1)}%
792792
\py@LinkColor% color of the link text
793-
\mbox{\small\textsf{#1}}%
793+
\small\sf #1%
794794
\py@NormalColor% Turn it back off; these are declarative
795795
\pdfendlink}% and don't appear bound to the current
796796
}% formatting "box".
797-
}
798-
\let\url=\py@url
797+
\else
798+
\newcommand{\url}[1]{\mbox{\small\textsf{#1}}}
799+
\fi
799800
\newcommand{\email}[1]{{\small\textsf{#1}}}
800801
\newcommand{\newsgroup}[1]{{\small\textsf{#1}}}
801802

@@ -843,7 +844,7 @@
843844
}}
844845
\newcommand{\envvar}[1]{%
845846
#1%
846-
\index{#1@{#1}}%
847+
\index{#1}%
847848
\index{environment variables!{#1}}%
848849
}
849850
\newcommand{\makevar}[1]{#1} % variable in a Makefile
@@ -859,12 +860,32 @@
859860
\newcommand{\programopt}[1]{\strong{#1}}
860861
% Note that \longprogramopt provides the '--'!
861862
\newcommand{\longprogramopt}[1]{\strong{-{}-#1}}
863+
862864
% \ulink{link text}{URL}
863-
\newcommand{\ulink}[2]{#1}
865+
\ifpdf
866+
% The \noindent here is a hack -- we're forcing pdfTeX into
867+
% horizontal mode since \pdfannotlink requires that.
868+
\newcommand{\ulink}[2]{\noindent{%
869+
\pdfannotlink attr{/Border [0 0 0]} user{/S /URI /URI (#2)}%
870+
\py@LinkColor% color of the link text
871+
#1%
872+
\py@NormalColor% Turn it back off; these are declarative
873+
\pdfendlink}% and don't appear bound to the current
874+
}% formatting "box".
875+
\else
876+
\newcommand{\ulink}[2]{#1}
877+
\fi
864878

865879
% cited titles: \citetitle{Title of Work}
866880
% online: \citetitle[url-to-resource]{Title of Work}
867-
\newcommand{\citetitle}[2][URL]{\emph{#2}}
881+
\ifpdf
882+
\newcommand{\citetitle}[2][\py@modulebadkey]{%
883+
\ifx\py@modulebadkey#1\emph{#2}\else\ulink{\emph{#2}}{#1}\fi%
884+
}
885+
\else
886+
\newcommand{\citetitle}[2][URL]{#1}
887+
\fi
888+
868889

869890

870891
\newcommand{\grammartoken}[1]{\texttt{#1}}
@@ -1019,25 +1040,27 @@
10191040
% Note that the last parameter for \seemodule and \seetext should be complete
10201041
% sentences and be terminated with the proper punctuation.
10211042

1022-
\@ifundefined{pdfannotlink}{%
1043+
\ifpdf
10231044
\newcommand{\py@seemodule}[3][\py@modulebadkey]{%
10241045
\par%
10251046
\ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
10261047
\begin{fulllineitems}
1027-
\item[Module \module{#2} (section \ref{module-\py@modulekey}):]
1048+
\item[\py@linkToName{label-module-\py@modulekey}{Module \module{#2}}
1049+
(section \ref{module-\py@modulekey}):]
10281050
#3
10291051
\end{fulllineitems}
10301052
}
1031-
}{\newcommand{\py@seemodule}[3][\py@modulebadkey]{%
1053+
\else
1054+
\newcommand{\py@seemodule}[3][\py@modulebadkey]{%
10321055
\par%
10331056
\ifx\py@modulebadkey#1\def\py@modulekey{#2}\else\def\py@modulekey{#1}\fi%
10341057
\begin{fulllineitems}
1035-
\item[\py@linkToName{label-module-\py@modulekey}{Module \module{#2}}
1036-
(section \ref{module-\py@modulekey}):]
1058+
\item[Module \module{#2} (section \ref{module-\py@modulekey}):]
10371059
#3
10381060
\end{fulllineitems}
10391061
}
1040-
}
1062+
\fi
1063+
10411064
% \seetitle[url]{title}{why it's interesting}
10421065
\newcommand{\py@seetitle}[3][\py@modulebadkey]{%
10431066
\par

0 commit comments

Comments
 (0)