Skip to content

Commit fae68d2

Browse files
committed
Fix a coding error and extend table testing
1 parent fdf6081 commit fae68d2

File tree

9 files changed

+18
-5
lines changed

9 files changed

+18
-5
lines changed

sphinx/writers/latex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ def visit_table(self, node: Element) -> None:
880880
(self.curfilestack[-1], node.line or ''))
881881

882882
self.tables.append(Table(node))
883-
if not self.table.colsep:
883+
if self.table.colsep == None:
884884
self.table.colsep = '' if (
885885
'booktabs' in self.builder.config.latex_table_style or
886886
'borderless' in self.builder.config.latex_table_style

tests/roots/test-latex-table/complex.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ complex tables
44
grid table
55
----------
66

7+
.. rst-class:: nocolorrows
8+
79
+---------+---------+---------+
810
| header1 | header2 | header3 |
911
+=========+=========+=========+
@@ -26,6 +28,8 @@ table having ...
2628
* consecutive multirow at top of row (1-1 and 1-2)
2729
* consecutive multirow at end of row (1-4 and 1-5)
2830

31+
.. rst-class:: standard
32+
2933
+-----------+-----------+-----------+-----------+-----------+
3034
| | | cell1-3 | | |
3135
| | +-----------+ | cell1-5 |

tests/roots/test-latex-table/expects/complex_spanning_cell.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
\begin{savenotes}\sphinxattablestart
1717
\sphinxthistablewithglobalstyle
18+
\sphinxthistablewithstandardstyle
1819
\centering
1920
\begin{tabulary}{\linewidth}[t]{|T|T|T|T|T|}
2021
\sphinxtoprule

tests/roots/test-latex-table/expects/gridtable.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
\begin{savenotes}\sphinxattablestart
44
\sphinxthistablewithglobalstyle
5+
\sphinxthistablewithnocolorrowsstyle
56
\centering
67
\begin{tabulary}{\linewidth}[t]{|T|T|T|}
78
\sphinxtoprule

tests/roots/test-latex-table/expects/longtable.tex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
\begin{savenotes}
44
\sphinxatlongtablestart
55
\sphinxthistablewithglobalstyle
6-
\begin{longtable}[c]{|l|l|}
6+
\sphinxthistablewithborderlessstyle
7+
\begin{longtable}[c]{ll}
78
\sphinxtoprule
89
\sphinxstyletheadfamily
910
\sphinxAtStartPar

tests/roots/test-latex-table/expects/table_having_widths.tex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
\begin{savenotes}\sphinxattablestart
44
\sphinxthistablewithglobalstyle
5+
\sphinxthistablewithbooktabsstyle
6+
\sphinxthistablewithcolorrowsstyle
57
\centering
68
\phantomsection\label{\detokenize{tabular:namedtabular}}\label{\detokenize{tabular:mytabular}}\nobreak
7-
\begin{tabular}[t]{|\X{30}{100}|\X{70}{100}|}
9+
\begin{tabular}[t]{\X{30}{100}\X{70}{100}}
810
\sphinxtoprule
911
\sphinxstyletheadfamily
1012
\sphinxAtStartPar

tests/roots/test-latex-table/longtable.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ longtable
55
---------
66

77
.. table::
8-
:class: longtable
8+
:class: longtable, borderless
99

1010
======= =======
1111
header1 header2

tests/roots/test-latex-table/tabular.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ table having :widths: option
2020
.. table::
2121
:widths: 30,70
2222
:name: namedtabular
23+
:class: booktabs, colorrows
2324

2425
======= =======
2526
header1 header2

tests/test_build_latex.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,10 @@ def test_latex_table_with_booktabs(app, status, warning):
13271327
result = (app.outdir / 'python.tex').read_text(encoding='utf8')
13281328
assert r'\PassOptionsToPackage{booktabs}{sphinx}' in result
13291329
assert r'\PassOptionsToPackage{colorrows}{sphinx}' in result
1330-
assert r'\begin{tabulary}{\linewidth}[t]{TTTTT}' in result
1330+
# tabularcolumns
1331+
assert r'\begin{tabulary}{\linewidth}[t]{|c|c|}' in result
1332+
# class: standard
1333+
assert r'\begin{tabulary}{\linewidth}[t]{|T|T|T|T|T|}' in result
13311334
assert r'\begin{longtable}[c]{ll}' in result
13321335
assert r'\begin{tabular}[t]{*{2}{\X{1}{2}}}' in result
13331336
assert r'\begin{tabular}[t]{\X{30}{100}\X{70}{100}}' in result

0 commit comments

Comments
 (0)