Skip to content

Commit 9bb9adf

Browse files
authored
Merge branch 'master' into untyped-call
2 parents 7901b72 + d73f02d commit 9bb9adf

File tree

48 files changed

+1433
-992
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1433
-992
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Contributors
103103
* Stefan Seefeld -- toctree improvements
104104
* Stefan van der Walt -- autosummary extension
105105
* Steve Piercy -- documentation improvements
106+
* Szymon Karpinski -- intersphinx improvements
106107
* \T. Powers -- HTML output improvements
107108
* Taku Shimizu -- epub3 builder
108109
* Thomas Lamb -- linkcheck builder

CHANGES.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,22 @@ Features added
6262
Bugs fixed
6363
----------
6464

65+
* #1327: LaTeX: tables using longtable raise error if
66+
:rst:dir:`tabularcolumns` specifies automatic widths
67+
(``L``, ``R``, ``C``, or ``J``).
68+
Patch by Jean-François B.
69+
* #3447: LaTeX: when assigning longtable class to table for PDF, it may render
70+
"horizontally" and overflow in right margin.
71+
Patch by Jean-François B.
72+
* #8828: LaTeX: adding a footnote to a longtable cell causes table to occupy
73+
full width.
74+
Patch by Jean-François B.
6575
* #11498: LaTeX: Table in cell fails to build if it has many rows.
6676
Patch by Jean-François B.
6777
* #11515: LaTeX: longtable does not allow nested table.
6878
Patch by Jean-François B.
79+
* #11973: LaTeX: links in table captions do not work in PDF.
80+
Patch by Jean-François B.
6981
* #12821: LaTeX: URLs/links in section titles should render in PDF.
7082
Patch by Jean-François B.
7183
* #13369: Correctly parse and cross-reference unpacked type annotations.
@@ -83,6 +95,8 @@ Bugs fixed
8395
Patch by Jean-François B.
8496
* #13685: gettext: Correctly ignore trailing backslashes.
8597
Patch by Bénédikt Tran.
98+
* #13712: intersphinx: Don't add "v" prefix to non-numeric versions.
99+
Patch by Szymon Karpinski.
86100

87101
Testing
88102
-------

doc/changes/5.3.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ Release 5.3.0 (released Oct 16, 2022)
88

99
* #10759: LaTeX: add :confval:`latex_table_style` and support the
1010
``'booktabs'``, ``'borderless'``, and ``'colorrows'`` styles.
11-
(thanks to Stefan Wiehler for initial pull requests #6666, #6671)
11+
(thanks to Stefan Wiehler for initial pull requests #6666, #6671).
12+
Using the ``'booktabs'`` style solves #6740 (Removing LaTeX
13+
column borders for automatic colspec).
14+
Patch by Jean-François B.
1215
* #10840: One can cross-reference including an option value like
1316
``:option:`--module=foobar```, ``:option:`--module[=foobar]```,
1417
or ``:option:`--module foobar```.

doc/usage/restructuredtext/directives.rst

Lines changed: 66 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,60 +1483,95 @@ Check the :confval:`latex_table_style`.
14831483

14841484
.. rst:directive:: .. tabularcolumns:: column spec
14851485
1486-
This directive influences only the LaTeX output for the next table in
1487-
source. The mandatory argument is a column specification (known as an
1488-
"alignment preamble" in LaTeX idiom). Please refer to a LaTeX
1486+
This directive influences only the LaTeX output, and only for the next
1487+
table in source. The mandatory argument is a column specification (known
1488+
as an "alignment preamble" in LaTeX idiom). Please refer to a LaTeX
14891489
documentation, such as the `wiki page`_, for basics of such a column
14901490
specification.
14911491

14921492
.. _wiki page: https://en.wikibooks.org/wiki/LaTeX/Tables
14931493

14941494
.. versionadded:: 0.3
14951495

1496+
Sphinx renders tables with at most 30 rows using ``tabulary`` (or
1497+
``tabular`` if at least one cell contains either a code-block or a nested
1498+
table), and those with more rows with ``longtable``. The advantage of
1499+
using ``tabulary`` is that it tries to compute automatically (internally to
1500+
LaTeX) suitable column widths.
1501+
1502+
The ``tabulary`` algorithm often works well, but in some cases when a cell
1503+
contains long paragraphs, the column will be given a large width and other
1504+
columns whose cells contain only single words may end up too narrow. The
1505+
:rst:dir:`tabularcolumns` can help solve this via providing to LaTeX a
1506+
custom "alignment preamble" (aka "colspec"). For example ``lJJ`` will be
1507+
suitable for a three-columns table whose first column contains only single
1508+
words and the other two have cells with long paragraphs.
1509+
14961510
.. note::
14971511

1498-
:rst:dir:`tabularcolumns` conflicts with ``:widths:`` option of table
1499-
directives. If both are specified, ``:widths:`` option will be ignored.
1512+
Of course, a fully automated solution would be better, and it is still
1513+
hoped for, but it is an intrinsic aspect of ``tabulary``, and the latter
1514+
is in use by Sphinx ever since ``0.3``... It looks as if solving the
1515+
problem of squeezed columns could require substantial changes to that
1516+
LaTeX package. And no good alternative appears to exist, as of 2025.
1517+
1518+
.. hint::
1519+
1520+
A way to solve the issue for all tables at once, is to inject in the
1521+
LaTeX preamble (see :confval:`latex_elements`) a command such as
1522+
``\setlength{\tymin}{1cm}`` which causes all columns to be at least
1523+
``1cm`` wide (not counting inter-column whitespace). Currently, Sphinx
1524+
configures ``\tymin`` to allow room for three characters at least.
15001525

1501-
Sphinx renders tables with at most 30 rows using ``tabulary``, and those
1502-
with more rows with ``longtable``.
1526+
Here is a more sophisticated "colspec", for a 4-columns table:
15031527

1504-
``tabulary`` tries to compute automatically (internally to LaTeX) suitable
1505-
column widths. However, cells are then not allowed to contain
1506-
"problematic" elements such as lists, object descriptions,
1507-
blockquotes... Sphinx will fall back to using ``tabular`` if such a cell is
1508-
encountered (or a nested ``tabulary``). In such a case the table will have
1509-
a tendency to try to fill the whole available line width.
1528+
.. code-block:: latex
15101529

1511-
:rst:dir:`tabularcolumns` can help in coercing the usage of ``tabulary`` if
1512-
one is careful to not employ the ``tabulary`` column types (``L``, ``R``,
1513-
``C`` or ``J``) for those columns with at least one "problematic" cell, but
1514-
only LaTeX's ``p{<width>}`` or Sphinx ``\X`` and ``\Y`` (described next).
1530+
.. tabularcolumns:: >{\raggedright}\Y{.4}>{\centering}\Y{.1}>{\sphinxcolorblend{!95!red}\centering\noindent\bfseries\color{red}}\Y{.12}>{\raggedright\arraybackslash}\Y{.38}
15151531

1516-
Literal blocks do not work at all with ``tabulary``. Sphinx will fall back
1517-
to ``tabular`` or ``longtable`` environments depending on the number of
1518-
rows. It will employ the :rst:dir:`tabularcolumns` specification only if it
1519-
contains no usage of the ``tabulary`` specific types.
1532+
This is used in Sphinx own PDF docs at :ref:`dev-deprecated-apis`.
1533+
Regarding column widths, this "colspec" achieves the same as would
1534+
``:widths:`` option set to ``40 10 12 38`` but it injects extra effects.
1535+
1536+
.. note::
1537+
1538+
In case both :rst:dir:`tabularcolumns` and ``:widths:`` option of table
1539+
directives are used, ``:widths:`` option will be ignored by the LaTeX
1540+
builder. Of course it is obeyed by other builders.
1541+
1542+
Literal blocks do not work at all with ``tabulary`` and Sphinx will then
1543+
fall back to ``tabular`` LaTeX environment. It will employ the
1544+
:rst:dir:`tabularcolumns` specification in that case only if it contains no
1545+
usage of the ``tabulary`` specific column types (which are ``L``, ``R``,
1546+
``C`` and ``J``).
15201547

15211548
Besides the LaTeX ``l``, ``r``, ``c`` and ``p{width}`` column specifiers,
1522-
one can also use ``\X{a}{b}`` which configures the column width to be a
1523-
fraction ``a/b`` of the total line width and ``\Y{f}`` where ``f`` is a
1524-
decimal: for example ``\Y{0.2}`` means that the column will occupy ``0.2``
1525-
times the line width.
1549+
and the ``tabulary`` specific ``L``, ``R``, ``C`` and ``J``, one can also
1550+
use (with all table types) ``\X{a}{b}`` which configures the column width
1551+
to be a fraction ``a/b`` of the total line width and ``\Y{f}`` where ``f``
1552+
is a decimal: for example ``\Y{0.2}`` means that the column will occupy
1553+
``0.2`` times the line width.
15261554

15271555
.. versionchanged:: 1.6
15281556

1529-
Use ``J`` (justified) by default with ``tabulary``, not ``L``
1557+
Sphinx uses ``J`` (justified) by default with ``tabulary``, not ``L``
15301558
(flushed-left). To revert, include ``\newcolumntype{T}{L}`` in the LaTeX
15311559
preamble, as in fact Sphinx uses ``T`` and sets it by default to be an
15321560
alias of ``J``.
15331561

1534-
.. hint::
1562+
.. versionchanged:: 8.3.0
15351563

1536-
A frequent issue with ``tabulary`` is that columns with little contents
1537-
appear to be "squeezed". One can add to the LaTeX preamble for example
1538-
``\setlength{\tymin}{40pt}`` to ensure a minimal column width of ``40pt``,
1539-
the ``tabulary`` default of ``10pt`` being too small.
1564+
Formerly, Sphinx did not use ``tabulary`` if the table had at least one
1565+
cell containing "problematic" elements such as lists, object descriptions,
1566+
blockquotes (etc...) because such contents are not out-of-the-box
1567+
compatible with ``tabulary``. At ``8.3.0`` a technique, which was already
1568+
in use for merged cells, was extended to such cases, and the sole
1569+
"problematic" contents are code-blocks and nested tables. So tables
1570+
containing (only) cells with mutliple paragraphs, bullet or enumerated
1571+
lists, or line blocks, will now better fit to their contents (if not
1572+
rendered by ``longtable``). Cells with object descriptions or admonitions
1573+
will still have a tendency to induce the table to fill the full text area
1574+
width, but columns in that table with no such contents will be tighter.
15401575

15411576
.. hint::
15421577

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ lint = [
9797
"mypy==1.16.1",
9898
"sphinx-lint>=0.9",
9999
"types-colorama==0.4.15.20240311",
100-
"types-defusedxml==0.7.0.20250516",
100+
"types-defusedxml==0.7.0.20250708",
101101
"types-docutils==0.21.0.20250525",
102102
"types-Pillow==10.2.0.20240822",
103103
"types-Pygments==2.19.0.20250516",
@@ -166,7 +166,7 @@ types = [
166166
type-stubs = [
167167
# align with versions used elsewhere
168168
"types-colorama==0.4.15.20240311",
169-
"types-defusedxml==0.7.0.20250516",
169+
"types-defusedxml==0.7.0.20250708",
170170
"types-docutils==0.21.0.20250525",
171171
"types-Pillow==10.2.0.20240822",
172172
"types-Pygments==2.19.0.20250516",
@@ -257,7 +257,6 @@ module = [
257257
"tests.test_builders.test_build_html_assets",
258258
"tests.test_builders.test_build_html_maths",
259259
"tests.test_builders.test_build_html_numfig",
260-
"tests.test_builders.test_build_html_tocdepth",
261260
"tests.test_builders.test_build_html_toctree",
262261
"tests.test_builders.test_build_linkcheck",
263262
"tests.test_builders.test_build_warnings",

sphinx/ext/intersphinx/_resolve.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ def _create_element_from_result(
4646
# get correct path in case of subdirectories
4747
uri = (_relative_path(Path(), Path(node['refdoc']).parent) / uri).as_posix()
4848
if inv_item.project_version:
49-
reftitle = _('(in %s v%s)') % (inv_item.project_name, inv_item.project_version)
49+
if not inv_item.project_version[0].isdigit():
50+
# Do not append 'v' to non-numeric version
51+
version = inv_item.project_version
52+
else:
53+
version = f'v{inv_item.project_version}'
54+
reftitle = _('(in %s %s)') % (inv_item.project_name, version)
5055
else:
5156
reftitle = _('(in %s)') % (inv_item.project_name,)
5257

sphinx/texinputs/sphinxlatextables.sty

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
%% TABLES (WITH SUPPORT FOR MERGED CELLS OF GENERAL CONTENTS)
22
%
33
% change this info string if making any custom modification
4-
\ProvidesPackage{sphinxlatextables}[2025/06/09 v8.3.0 tables]%
4+
\ProvidesPackage{sphinxlatextables}[2025/06/30 v8.3.0 tables]%
55

66
% Provides support for this output mark-up from Sphinx latex writer
77
% and table templates:
@@ -42,6 +42,22 @@
4242
% - \sphinxthistablewithnocolorrowsstyle
4343
% - \sphinxthistablewithvlinesstyle
4444
% - \sphinxthistablewithnovlinesstyle
45+
% - \sphinxbeforeendvarwidth
46+
47+
% At 8.3.0, ALL table cell contents are wrapped into a varwidth environment.
48+
% This helps solve issues such as #3447, #8828, and helps use tabulary
49+
% in many more cases hence obtain better looking tables.
50+
\def\sphinxbeforeendvarwidth{\par\vskip-\baselineskip\hbox{\strut}}
51+
% MEMO: Mark-up uses the above macro right before all \end{varwdith} so that
52+
% if the cell in a row extends lower than the others, its last line acquires
53+
% standard "depth". Else it may lack any depth if without descenders such as
54+
% "p" or "q" letters and the horizontal line or color panel will look strange.
55+
% It originates in PR #3435 from 2017 which solved *many* table issues for
56+
% merged cells (and injected the varwidth technique now at 8.3.0 applied to
57+
% all cells). The original used \vbox{\hbox{\strut}} but that \vbox appears
58+
% to do nothing, and it was decided after some testing (July 2025) to remove
59+
% it, the original rationale for it being now lost.
60+
4561
% These conditionals added at 8.3.0 for nested tables not to break row colors
4662
% (#13635). Nested tables are only partially supported by Sphinx LaTeX.
4763
% The method here is with no changes to neither writer nor templates.
@@ -251,7 +267,32 @@
251267
%
252268
% configuration of tabulary
253269
\setlength{\tymin}{3\fontcharwd\font`0 }% minimal width of "squeezed" columns
254-
\setlength{\tymax}{10000pt}% allow enough room for paragraphs to "compete"
270+
\setlength{\tymax}{3000pt}% allow enough room for paragraphs to "compete"
271+
%
272+
% MEMO: tabulary initially renders cell contents "horizontally" to measure
273+
% them and compare their relative importance. Its goal is to choose the
274+
% column width so that, roughly, all columns will look about evenly
275+
% filled. "Horizontal" rendering is incompatible with many LaTeX
276+
% structures such as lists, so prior to Sphinx 8.3.0 cells with such
277+
% "problematic" contents caused Sphinx to use tabular not tabulary; the
278+
% tabular would then render each column in absence of :widths: option or
279+
% tabularcolumns directive the same width equal to available text width
280+
% divided by number of columns. At 8.3.0, "problematic" contents is
281+
% wrapped into a "varwidth" environment, as was already done formerly
282+
% for merged cells, and this avoids tabulary causing errors such as
283+
% "incompatible with LR mode"; \sphinxcolwidth is used which sets
284+
% the initial horizontal width for "varwidth". In the first tabulary
285+
% pass, \sphinxcolwidth is configured (by us) to use \tymax.
286+
%
287+
% During testing, it was determined that the former 10000pt setting for
288+
% \tymax would cause "Dimension too large" TeX error if two columns or
289+
% more had cells containing admonitions (such contents does not allow
290+
% "varwidth" to reduce the width automatically). So we use now 3000pt
291+
% which allows up to 5 such columns while being large enough for
292+
% tabulary algorithm to give good results for cells containing a few
293+
% dozen words. The tabulary default of 2\textwidth proves to be too
294+
% small for that.
295+
%
255296
% we need access to tabulary's final computed width. \@tempdima is too volatile
256297
% to hope it has kept tabulary's value when \sphinxcolwidth needs it.
257298
\newdimen\sphinx@TY@tablewidth
@@ -302,9 +343,7 @@
302343
% **** TODO: clarify if next paragraph means we must raise an
303344
% **** if LaTeX writer detects a merged cell inside nested table.
304345
% MEMO about nesting: if sphinxmulticolumn is encountered in a nested tabular
305-
% inside a tabulary it will think to be at top level in the tabulary. But
306-
% Sphinx generates no nested tables, and if some LaTeX macro uses internally a
307-
% tabular this will not have a \sphinxstartmulticolumn within it!
346+
% inside a tabulary it will think to be at top level in the tabulary.
308347
%
309348
% 5.3.0 adds a check for multirow as single-row multi-column will allow a row
310349
% colour but multi-row multi-column should not.
@@ -407,8 +446,7 @@
407446
}%
408447
\newcommand*\sphinxcolwidth[2]{%
409448
% this dimension will always be used for varwidth, and serves as maximum
410-
% width when cells are merged either via multirow or multicolumn or both,
411-
% as always their contents is wrapped in varwidth environment.
449+
% width for cells whose contents are wrapped in varwidth environment.
412450
\ifnum#1>\@ne % multi-column (and possibly also multi-row)
413451
% we wrote our own multicolumn code especially to handle that (and allow
414452
% verbatim contents)

0 commit comments

Comments
 (0)