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

Skip to content

Commit ff031cf

Browse files
committed
Define abstract way to get the normal and smaller font sizes that work
even in the footnote context.
1 parent 8612a43 commit ff031cf

1 file changed

Lines changed: 28 additions & 16 deletions

File tree

Doc/texinputs/python.sty

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,23 @@
134134
% Use this to set the font family for headers and other decor:
135135
\newcommand{\py@HeaderFamily}{\sffamily}
136136

137+
% Set up abstract ways to get the normal and smaller font sizes that
138+
% work even in footnote context.
139+
\newif\ifpy@infootnote \py@infootnotefalse
140+
\let\py@oldfootnotetext\@footnotetext
141+
\def\@footnotetext#1{%
142+
\bgroup%
143+
\py@infootnotetrue
144+
\py@oldfootnotetext{#1}%
145+
\egroup%
146+
}
147+
\def\py@defaultsize{%
148+
\ifpy@infootnote\footnotesize\else\normalsize\fi%
149+
}
150+
\def\py@smallsize{%
151+
\ifpy@infootnote\scriptsize\else\small\fi%
152+
}
153+
137154
% Redefine the 'normal' header/footer style when using "fancyhdr" package:
138155
\@ifundefined{fancyhf}{}{
139156
% Use \pagestyle{normal} as the primary pagestyle for text.
@@ -817,24 +834,19 @@
817834
\newcommand{\csimplemacro}[1]{\code{#1}}
818835
\newcommand{\kbd}[1]{\code{#1}}
819836
\newcommand{\samp}[1]{`\code{#1}'}
820-
% This weird definition of \var{} allows it to always appear in roman
821-
% italics, and won't get funky in code fragments when we play around
822-
% with fonts. This also works directly in math mode.
823-
% XXX \normalsize is bad in footnotes, though; we need a way to
824-
% determine when we're in a footnote.
825837
\newcommand{\var}[1]{%
826838
\ifmmode%
827-
\hbox{\normalsize\textrm{\textit{#1\/}}}%
839+
\hbox{\py@defaultsize\textrm{\textit{#1\/}}}%
828840
\else%
829-
\normalsize\textrm{\textit{#1\/}}%
841+
\py@defaultsize\textrm{\textit{#1\/}}%
830842
\fi%
831843
}
832844
\renewcommand{\emph}[1]{{\em #1}}
833845
\newcommand{\dfn}[1]{\emph{#1}}
834846
\newcommand{\strong}[1]{{\bf #1}}
835847
% let's experiment with a new font:
836-
\newcommand{\file}[1]{`{\small\textsf{#1}}'}
837-
\newcommand{\filenq}[1]{{\small\textsf{#1}}}
848+
\newcommand{\file}[1]{`\filenq{#1}'}
849+
\newcommand{\filenq}[1]{{\py@smallsize\textsf{#1}}}
838850

839851
% Use this def/redef approach for \url{} since hyperref defined this already,
840852
% but only if we actually used hyperref:
@@ -843,15 +855,15 @@
843855
\noindent%
844856
\pdfstartlink attr{/Border [0 0 0]} user{/S /URI /URI (#1)}%
845857
\py@LinkColor% color of the link text
846-
\small\sf #1%
858+
\py@smallsize\sf #1%
847859
\py@NormalColor% Turn it back off; these are declarative
848860
\pdfendlink}% and don't appear bound to the current
849861
}% formatting "box".
850862
\else
851-
\newcommand{\url}[1]{\mbox{\small\textsf{#1}}}
863+
\newcommand{\url}[1]{\mbox{\py@smallsize\textsf{#1}}}
852864
\fi
853-
\newcommand{\email}[1]{{\small\textsf{#1}}}
854-
\newcommand{\newsgroup}[1]{{\small\textsf{#1}}}
865+
\newcommand{\email}[1]{{\py@smallsize\textsf{#1}}}
866+
\newcommand{\newsgroup}[1]{{\py@smallsize\textsf{#1}}}
855867

856868
\newcommand{\py@varvars}[1]{{%
857869
{\let\unspecified=\py@unspecified%
@@ -887,12 +899,12 @@
887899
\newcommand{\ctype}[1]{\texttt{#1}} % C struct or typedef name
888900
\newcommand{\cdata}[1]{\texttt{#1}} % C variable, typically global
889901

890-
\newcommand{\mailheader}[1]{{\small\textsf{#1:}}}
891-
\newcommand{\mimetype}[1]{{\small\textsf{#1}}}
902+
\newcommand{\mailheader}[1]{{\py@smallsize\textsf{#1:}}}
903+
\newcommand{\mimetype}[1]{{\py@smallsize\textsf{#1}}}
892904
% The \! is a "negative thin space" in math mode.
893905
\newcommand{\regexp}[1]{%
894906
{\tiny$^{^\lceil}\!\!$%
895-
{\normalsize\code{#1}}% XXX should use \footnotesize in footnotes
907+
{\py@defaultsize\code{#1}}%
896908
$\!\rfloor\!$%
897909
}}
898910
\newcommand{\envvar}[1]{%

0 commit comments

Comments
 (0)