Skip to content

Commit 88cf9be

Browse files
committed
Define \sphinxliteraltext and \sphinxcodestyle for flexibility
This addresses the \sphinxcode usage issue in context of styling of declarations, as discussed in parent commit message.
1 parent cc632ba commit 88cf9be

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

sphinx/texinputs/sphinx.sty

+11-6
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@
229229
\@namedef{PYG@tok@k-cpp}{%
230230
\def\PYG@tc##1{\textcolor[RGB]{0,0,"FF}{##1}}%
231231
}%
232+
\@namedef{PYG@tok@d}{% default desc style uses \sphinxcodestyle (i.e. \texttt)
233+
\def\PYG@ff##1{\sphinxcodestyle{##1}}%
234+
}%
232235

233236
%% OPTIONS
234237
%
@@ -1443,13 +1446,13 @@
14431446
%
14441447
\newlength{\py@argswidth}
14451448
\newcommand{\py@sigparams}[2]{%
1446-
\parbox[t]{\py@argswidth}{#1\sphinxcode{)}#2}}
1449+
\parbox[t]{\py@argswidth}{#1\sphinxcodestyle{)}#2}}
14471450
\newcommand{\pysigline}[1]{\item[{#1}]}
14481451
\newcommand{\pysiglinewithargsret}[3]{%
1449-
\settowidth{\py@argswidth}{#1\sphinxcode{(}}%
1452+
\settowidth{\py@argswidth}{#1\sphinxcodestyle{(}}%
14501453
\addtolength{\py@argswidth}{-2\py@argswidth}%
14511454
\addtolength{\py@argswidth}{\linewidth}%
1452-
\item[{#1\sphinxcode{(}\py@sigparams{#2}{#3}}]}
1455+
\item[{#1\sphinxcodestyle{(}\py@sigparams{#2}{#3}}]}
14531456
\newcommand{\pysigstartmultiline}{%
14541457
\def\pysigstartmultiline{\vskip\smallskipamount\parskip\z@skip\itemsep\z@skip}%
14551458
\edef\pysigstopmultiline
@@ -1551,7 +1554,7 @@
15511554
% breakable at non-escaped . , ; ? ! / using \sphinxbreaksviaactive.
15521555
% the macro must be protected if it ends up used in moving arguments,
15531556
% in 'alltt' \@noligs is done already, and the \scantokens must be avoided.
1554-
\protected\def\sphinxcode#1{{\def\@tempa{alltt}%
1557+
\protected\def\sphinxliteraltext#1{{\def\@tempa{alltt}%
15551558
\ifx\@tempa\@currenvir\else
15561559
\ifspx@opt@inlineliteralwraps
15571560
\sphinxbreaksviaactive\let\sphinxafterbreak\empty
@@ -1562,12 +1565,14 @@
15621565
\let\do@noligs\sphinx@do@noligs
15631566
\@noligs\endlinechar\m@ne\everyeof{}% (<- in case inside \sphinxhref)
15641567
\expandafter\scantokens
1565-
\fi {\texttt{#1}}}}
1568+
\fi {#1}}}
15661569
\def\sphinx@do@noligs #1{\catcode`#1\active\begingroup\lccode`\~`#1\relax
15671570
\lowercase{\endgroup\def~{\leavevmode\kern\z@\char`#1 }}}
15681571
\def\sphinx@literal@nolig@list {\do\`\do\<\do\>\do\'\do\-}%
15691572
1570-
\protected\def\sphinxbfcode#1{\sphinxcode{\bfseries{}#1}}
1573+
\protected\def\sphinxcodestyle#1{\texttt{#1}}
1574+
\protected\def\sphinxcode#1{\sphinxcodestyle{\sphinxliteraltext{#1}}}
1575+
\protected\def\sphinxbfcode#1{\textbf{\sphinxcode{#1}}}
15711576
\protected\def\sphinxemail#1{\textsf{#1}}
15721577
\protected\def\sphinxtablecontinued#1{\textsf{#1}}
15731578
\protected\def\sphinxtitleref#1{\emph{#1}}

sphinx/writers/latex.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ def depart_desc_signature_line(self, node):
12161216

12171217
def visit_desc_element(self, node):
12181218
# type: (nodes.Node) -> None
1219-
self.body.append('\\PYG{%s}{\\sphinxcode{' % '+'.join(node['classes']))
1219+
self.body.append('\\PYG{%s}{\\sphinxliteraltext{' % '+'.join(node['classes']))
12201220
self.literal_whitespace += 1
12211221

12221222
def depart_desc_element(self, node):

0 commit comments

Comments
 (0)