8000 Merge pull request #8997 from jfbu/latex_pysigline · sphinx-doc/sphinx@2934aac · GitHub
[go: up one dir, main page]

Skip to content

Commit 2934aac

Browse files
authored
Merge pull request #8997 from jfbu/latex_pysigline
LaTeX: improve behavious of `\pysigline` and `\pysiglinewithargsret` in case of multi-line signature
2 parents 64ad5b5 + 9a4b4b5 commit 2934aac

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ Bugs fixed
9292
* #8915: html theme: The translation of sphinx_rtd_theme does not work
9393
* #8342: Emit a warning if a unknown domain is given for directive or role (ex.
9494
``:unknown:doc:``)
95+
* #7241: LaTeX: No wrapping for ``cpp:enumerator``
9596
* #8711: LaTeX: backticks in code-blocks trigger latexpdf build warning (and font
9697
change) with late TeXLive 2019
9798
* #8253: LaTeX: Figures with no size defined get overscaled (compared to images
@@ -101,6 +102,9 @@ Bugs fixed
101102
Pygments style
102103
* #8925: LaTeX: 3.5.0 ``verbatimmaxunderfull`` setting does not work as
103104
expected
105+
* #8980: LaTeX: missing line break in ``\pysigline``
106+
* #8995: LaTeX: legacy ``\pysiglinewithargsret`` does not compute correctly
107+
available horizontal space and should use a ragged right style
104108
* #8911: C++: remove the longest matching prefix in
105109
:confval:`cpp_index_common_prefix` instead of the first that matches.
106110
* C, properly reject function declarations when a keyword is used

sphinx/texinputs/sphinxlatexobjects.sty

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,14 @@
5858

5959
% {fulllineitems} is the main environment for object descriptions.
6060
%
61-
\newcommand{\py@itemnewline}[1]{%
62-
\kern\labelsep
63-
\@tempdima\linewidth
64-
\advance\@tempdima \labelwidth\makebox[\@tempdima][l]{#1}%
65-
\kern-\labelsep
61+
% With 4.0.0 \pysigline (and \pysiglinewithargsret), used in a fulllineitems
62+
% environment the #1 will already be of the width which is computed here, i.e.
63+
% the available width on line, so the \makebox becomes a bit superfluous
64+
\newcommand{\py@itemnewline}[1]{% macro used as \makelabel in fulllineitems
65+
% Memo: this presupposes \itemindent is 0pt
66+
\kern\labelsep % because \@labels core latex box does \hskip-\labelsep
67+
\makebox[\dimexpr\linewidth+\labelwidth\relax][l]{#1}%
68+
\kern-\labelsep % because at end of \@labels box there is \hskip\labelsep
6669
}
6770

6871
\newenvironment{fulllineitems}{%
@@ -76,13 +79,27 @@
7679
%
7780
\newlength{\py@argswidth}
7881
\newcommand{\py@sigparams}[2]{%
79-
\parbox[t]{\py@argswidth}{#1\sphinxcode{)}#2}}
80-
\newcommand{\pysigline}[1]{\item[{#1}]}
82+
% The \py@argswidth has been computed in \pysiglinewithargsret to make this
83+
% occupy full available width on line.
84+
\parbox[t]{\py@argswidth}{\raggedright #1\sphinxcode{)}#2\strut}%
85+
% final strut is to help get correct vertical separation in case of multi-line
86+
% box with the item contents.
87+
}
88+
\newcommand{\pysigline}[1]{%
89+
% the \py@argswidth is available we use it despite its name (no "args" here)
90+
% the \relax\relax is because \py@argswidth is a "skip" variable and the first
91+
% \relax only ends its "dimen" part
92+
\py@argswidth=\dimexpr\linewidth+\labelwidth\relax\relax
93+
\item[{\parbox[t]{\py@argswidth}{\raggedright #1\strut}}]
94+
% this strange incantation is because at its root LaTeX in fact did not
95+
% imagine a multi-line label, it is always wrapped in a horizontal box at core
96+
% LaTeX level and we have to find tricks to get correct interline distances.
97+
\leavevmode\par\nobreak\vskip-\parskip\prevdepth\dp\strutbox}
8198
\newcommand{\pysiglinewithargsret}[3]{%
8299
\settowidth{\py@argswidth}{#1\sphinxcode{(}}%
83-
\addtolength{\py@argswidth}{-2\py@argswidth}%
84-
\addtolength{\py@argswidth}{\linewidth}%
85-
\item[{#1\sphinxcode{(}\py@sigparams{#2}{#3}}]}
100+
\py@argswidth=\dimexpr\linewidth+\labelwidth-\py@argswidth\relax\relax
101+
\item[{#1\sphinxcode{(}\py@sigparams{#2}{#3}}]
102+
\leavevmode\par\nobreak\vskip-\parskip\prevdepth\dp\strutbox}
86103
\newcommand{\pysigstartmultiline}{%
87104
\def\pysigstartmultiline{\vskip\smallskipamount\parskip\z@skip\itemsep\z@skip}%
88105
\edef\pysigstopmultiline

0 commit comments

Comments
 (0)
0