|
118 | 118 | % now restore \itemsep and \parskip |
119 | 119 | \pysig@restore@itemsep@and@parskip |
120 | 120 | } |
| 121 | +% Each signature is rendered as NAME<SPACE>[TPLIST]<SPACE>(ARGLIST) where the |
| 122 | +% size of <SPACE> is parametrized by \sphinxsignaturelistskip (0pt by default). |
| 123 | +\newlength\sphinxsignaturelistskip |
| 124 | +\setlength\sphinxsignaturelistskip{0pt} |
| 125 | +\newcommand{\pysigtplistopen}{\hskip\sphinxsignaturelistskip\sphinxcode{[}} |
| 126 | +\newcommand{\pysigtplistclose}{\sphinxcode{]}} |
| 127 | +\newcommand{\pysigarglistopen}{\hskip\sphinxsignaturelistskip\sphinxcode{(}} |
| 128 | +\newcommand{\pysigarglistclose}{\sphinxcode{)}} |
121 | 129 | % |
122 | 130 | % Use a \parbox to accommodate long argument list in signatures |
123 | 131 | % LaTeX did not imagine that an \item label could need multi-line rendering |
124 | 132 | \newlength{\py@argswidth} |
125 | 133 | \newcommand{\py@sigparams}[2]{% |
126 | 134 | % The \py@argswidth has been computed in \pysiglinewithargsret to make the |
127 | 135 | % argument list use full available width |
128 | | - \parbox[t]{\py@argswidth}{\raggedright #1\sphinxcode{)}#2\strut}% |
| 136 | + \parbox[t]{\py@argswidth}{\raggedright #1\pysigarglistclose#2\strut}% |
129 | 137 | % final strut is to help get correct vertical separation |
130 | 138 | } |
131 | 139 | \newcommand{\py@sigparamswithtplist}[3]{% |
132 | 140 | % similar to \py@sigparams but with different delimiters and an additional |
133 | 141 | % type parameters list given as #1, the argument list as #2 and the return |
134 | 142 | % annotation as #3 |
135 | | - \parbox[t]{\py@argswidth}{\raggedright #1\sphinxcode{]}\sphinxcode{(}#2\sphinxcode{)}#3\strut}% |
| 143 | + \parbox[t]{\py@argswidth}{% |
| 144 | + \raggedright #1\pysigtplistclose% |
| 145 | + \pysigarglistopen#2\pysigarglistclose% |
| 146 | + #3\strut}% |
136 | 147 | } |
137 | 148 |
|
138 | 149 | \newcommand{\pysigline}[1]{% |
|
147 | 158 | % as #1 may contain a footnote using \label we need to make \label |
148 | 159 | % a no-op here to avoid LaTeX complaining about duplicates |
149 | 160 | \let\spx@label\label\let\label\@gobble |
150 | | - \settowidth{\py@argswidth}{#1\sphinxcode{(}}% |
| 161 | + \settowidth{\py@argswidth}{#1\pysigarglistopen}% |
151 | 162 | \let\label\spx@label |
152 | 163 | \py@argswidth=\dimexpr\linewidth+\labelwidth-\py@argswidth\relax\relax |
153 | | - \item[{#1\sphinxcode{(}\py@sigparams{#2}{#3}\strut}] |
| 164 | + \item[{#1\pysigarglistopen\py@sigparams{#2}{#3}\strut}] |
154 | 165 | \pysigadjustitemsep |
155 | 166 | } |
156 | 167 | \newcommand{\pysiglinewithargsretwithtplist}[4]{ |
157 | 168 | % #1 = name, #2 = tplist, #3 = arglist, #4 = retann |
158 | 169 | \let\spx@label\label\let\label\@gobble |
159 | | - \settowidth{\py@argswidth}{#1\sphinxcode{[}}% |
| 170 | + \settowidth{\py@argswidth}{#1\pysigtplistopen}% |
160 | 171 | \let\label\spx@label |
161 | 172 | \py@argswidth=\dimexpr\linewidth+\labelwidth-\py@argswidth\relax\relax |
162 | | - \item[{#1\sphinxcode{[}\py@sigparamswithtplist{#2}{#3}{#4}\strut}] |
| 173 | + \item[{#1\pysigtplistopen\py@sigparamswithtplist{#2}{#3}{#4}\strut}] |
163 | 174 | \pysigadjustitemsep |
164 | 175 | } |
165 | 176 |
|
166 | 177 | \def\sphinxoptionalextraspace{0.5mm} |
167 | 178 | \newcommand{\pysigwithonelineperarg}[3]{% |
168 | 179 | % render each argument on its own line |
169 | | - \item[#1\sphinxcode{(}\strut] |
| 180 | + \item[#1\pysigarglistopen\strut] |
170 | 181 | \leavevmode\par\nopagebreak |
171 | 182 | % this relies on \pysigstartsignatures having set \parskip to zero |
172 | 183 | \begingroup |
|
180 | 191 | \endgroup |
181 | 192 | \global\let\sphinxparam\spx@sphinxparam |
182 | 193 | % fulllineitems sets \labelwidth to be like \leftmargin |
183 | | - \nopagebreak\noindent\kern-\labelwidth\sphinxcode{)}{#3} |
| 194 | + \nopagebreak\noindent\kern-\labelwidth\pysigarglistclose{#3} |
184 | 195 | \pysigadjustitemsep |
185 | 196 | } |
186 | 197 | \newcommand{\pysigwithonelineperargwithonelinepertparg}[4]{ |
187 | 198 | % #1 = name, #2 = tplist, #3 = arglist, #4 = retann |
188 | | - % render each type parameters and argument lists on its own line |
189 | | - \item[#1\sphinxcode{[}\strut] |
| 199 | + % render each type parameter and argument on its own line |
| 200 | + \item[#1\pysigtplistopen\strut] |
190 | 201 | \leavevmode\par\nopagebreak |
191 | 202 | \begingroup |
192 | 203 | \let\sphinxparamcomma\sphinxparamcommaoneperline |
|
197 | 208 | \def\sphinxtypeparam{\def\sphinxtypeparam{\par\spx@sphinxtypeparam}\spx@sphinxtypeparam}% |
198 | 209 | #2\par |
199 | 210 | \endgroup |
200 | | - \nopagebreak\noindent\kern-\labelwidth\sphinxcode{]} |
| 211 | + \nopagebreak\noindent\kern-\labelwidth\pysigtplistclose% |
201 | 212 | % render the rest of the signature like in \pysigwithonelineperarg |
202 | | - \sphinxcode{(}\strut\leavevmode\par\nopagebreak |
| 213 | + \pysigarglistopen\strut\par\nopagebreak |
203 | 214 | \begingroup |
204 | 215 | \let\sphinxparamcomma\sphinxparamcommaoneperline |
205 | 216 | \def\sphinxoptionalhook{\ifvmode\else\kern\sphinxoptionalextraspace\relax\fi}% |
|
208 | 219 | #3\par |
209 | 220 | \endgroup |
210 | 221 | \global\let\sphinxparam\spx@sphinxparam |
211 | | - \nopagebreak\noindent\kern-\labelwidth\sphinxcode{)}{#4} |
| 222 | + \nopagebreak\noindent\kern-\labelwidth\pysigarglistclose{#4} |
212 | 223 | \pysigadjustitemsep |
213 | 224 | } |
214 | 225 | \newcommand{\pysiglinewithargsretwithonelinepertparg}[4]{ |
215 | 226 | % #1 = name, #2 = tplist, #3 = arglist, #4 = retann |
216 | | - % render each type parameters on its own line but the argument list is rendered inline |
217 | | - \item[#1\sphinxcode{[}\strut] |
| 227 | + % render each type parameter on its own line but the arguments list inline |
| 228 | + \item[#1\pysigtplistopen\strut] |
218 | 229 | \leavevmode\par\nopagebreak |
219 | 230 | \begingroup |
220 | 231 | \let\sphinxparamcomma\sphinxparamcommaoneperline |
|
225 | 236 | \def\sphinxtypeparam{\def\sphinxtypeparam{\par\spx@sphinxtypeparam}\spx@sphinxtypeparam}% |
226 | 237 | #2\par |
227 | 238 | \endgroup |
228 | | - \nopagebreak\noindent\kern-\labelwidth\sphinxcode{]} |
| 239 | + \nopagebreak\noindent\kern-\labelwidth\pysigtplistclose% |
229 | 240 | % render the arguments list on one line |
230 | | - \settowidth{\py@argswidth}{\sphinxcode{]}\sphinxcode{()}}% |
231 | | - \py@argswidth=\dimexpr\linewidth+\labelwidth-\py@argswidth\relax\relax |
232 | | - \sphinxcode{(}\parbox[t]{\py@argswidth}{\raggedright #3\sphinxcode{)}#4\strut}% |
| 241 | + \pysigarglistopen#3\pysigarglistclose#4\strut |
233 | 242 | \pysigadjustitemsep |
234 | 243 | } |
235 | 244 | \newcommand{\pysigwithonelineperargwithtplist}[4]{ |
236 | 245 | % #1 = name, #2 = tplist, #3 = arglist, #4 = retann |
237 | 246 | % render the type parameters list on one line, but each argument is rendered on its own line |
238 | 247 | \let\spx@label\label\let\label\@gobble |
239 | | - \settowidth{\py@argswidth}{#1\sphinxcode{[}}% |
| 248 | + \settowidth{\py@argswidth}{#1\pysigtplistopen}% |
240 | 249 | \let\label\spx@label |
241 | 250 | \py@argswidth=\dimexpr\linewidth+\labelwidth-\py@argswidth\relax\relax |
242 | | - \item[{#1\sphinxcode{[}\parbox[t]{\py@argswidth}{\raggedright #2\sphinxcode{]}\sphinxcode{(}\strut}\strut}] |
| 251 | + \item[{#1\pysigtplistopen\parbox[t]{\py@argswidth}{% |
| 252 | + \raggedright #2\pysigtplistclose\pysigarglistopen\strut}\strut}] |
243 | 253 | % render the rest of the signature like in \pysigwithonelineperarg |
244 | 254 | \begingroup |
245 | 255 | \let\sphinxparamcomma\sphinxparamcommaoneperline |
|
249 | 259 | #3\par |
250 | 260 | \endgroup |
251 | 261 | \global\let\sphinxparam\spx@sphinxparam |
252 | | - \nopagebreak\noindent\kern-\labelwidth\sphinxcode{)}{#4} |
| 262 | + \nopagebreak\noindent\kern-\labelwidth\pysigarglistclose{#4} |
253 | 263 | \pysigadjustitemsep |
254 | 264 | } |
255 | 265 |
|
|
0 commit comments