From 13d81f9561f87b5fa0fd09da06001b0f57c5ae7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20B?= <2589111+jfbu@users.noreply.github.com> Date: Wed, 10 Aug 2022 23:43:36 +0200 Subject: [PATCH] Fix a coding error and extend table testing --- sphinx/writers/latex.py | 2 +- tests/roots/test-latex-table/complex.rst | 4 ++++ .../roots/test-latex-table/expects/complex_spanning_cell.tex | 1 + tests/roots/test-latex-table/expects/gridtable.tex | 1 + tests/roots/test-latex-table/expects/longtable.tex | 3 ++- tests/roots/test-latex-table/expects/table_having_widths.tex | 4 +++- tests/roots/test-latex-table/longtable.rst | 2 +- tests/roots/test-latex-table/tabular.rst | 1 + tests/test_build_latex.py | 5 ++++- 9 files changed, 18 insertions(+), 5 deletions(-) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 74d37d2ab5f..03501554926 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -880,7 +880,7 @@ def visit_table(self, node: Element) -> None: (self.curfilestack[-1], node.line or '')) self.tables.append(Table(node)) - if not self.table.colsep: + if self.table.colsep is None: self.table.colsep = '' if ( 'booktabs' in self.builder.config.latex_table_style or 'borderless' in self.builder.config.latex_table_style diff --git a/tests/roots/test-latex-table/complex.rst b/tests/roots/test-latex-table/complex.rst index fa84f8266cf..06a4eaaf5e6 100644 --- a/tests/roots/test-latex-table/complex.rst +++ b/tests/roots/test-latex-table/complex.rst @@ -4,6 +4,8 @@ complex tables grid table ---------- +.. rst-class:: nocolorrows + +---------+---------+---------+ | header1 | header2 | header3 | +=========+=========+=========+ @@ -26,6 +28,8 @@ table having ... * consecutive multirow at top of row (1-1 and 1-2) * consecutive multirow at end of row (1-4 and 1-5) +.. rst-class:: standard + +-----------+-----------+-----------+-----------+-----------+ | | | cell1-3 | | | | | +-----------+ | cell1-5 | diff --git a/tests/roots/test-latex-table/expects/complex_spanning_cell.tex b/tests/roots/test-latex-table/expects/complex_spanning_cell.tex index 7dac533f9d5..b511b88dad0 100644 --- a/tests/roots/test-latex-table/expects/complex_spanning_cell.tex +++ b/tests/roots/test-latex-table/expects/complex_spanning_cell.tex @@ -15,6 +15,7 @@ \begin{savenotes}\sphinxattablestart \sphinxthistablewithglobalstyle +\sphinxthistablewithstandardstyle \centering \begin{tabulary}{\linewidth}[t]{|T|T|T|T|T|} \sphinxtoprule diff --git a/tests/roots/test-latex-table/expects/gridtable.tex b/tests/roots/test-latex-table/expects/gridtable.tex index 76ad0783f87..8e37575c9df 100644 --- a/tests/roots/test-latex-table/expects/gridtable.tex +++ b/tests/roots/test-latex-table/expects/gridtable.tex @@ -2,6 +2,7 @@ \begin{savenotes}\sphinxattablestart \sphinxthistablewithglobalstyle +\sphinxthistablewithnocolorrowsstyle \centering \begin{tabulary}{\linewidth}[t]{|T|T|T|} \sphinxtoprule diff --git a/tests/roots/test-latex-table/expects/longtable.tex b/tests/roots/test-latex-table/expects/longtable.tex index 17096973c61..7809aef464a 100644 --- a/tests/roots/test-latex-table/expects/longtable.tex +++ b/tests/roots/test-latex-table/expects/longtable.tex @@ -3,7 +3,8 @@ \begin{savenotes} \sphinxatlongtablestart \sphinxthistablewithglobalstyle -\begin{longtable}[c]{|l|l|} +\sphinxthistablewithborderlessstyle +\begin{longtable}[c]{ll} \sphinxtoprule \sphinxstyletheadfamily \sphinxAtStartPar diff --git a/tests/roots/test-latex-table/expects/table_having_widths.tex b/tests/roots/test-latex-table/expects/table_having_widths.tex index d5225ede3e0..fe5f4c44d72 100644 --- a/tests/roots/test-latex-table/expects/table_having_widths.tex +++ b/tests/roots/test-latex-table/expects/table_having_widths.tex @@ -2,9 +2,11 @@ \begin{savenotes}\sphinxattablestart \sphinxthistablewithglobalstyle +\sphinxthistablewithbooktabsstyle +\sphinxthistablewithcolorrowsstyle \centering \phantomsection\label{\detokenize{tabular:namedtabular}}\label{\detokenize{tabular:mytabular}}\nobreak -\begin{tabular}[t]{|\X{30}{100}|\X{70}{100}|} +\begin{tabular}[t]{\X{30}{100}\X{70}{100}} \sphinxtoprule \sphinxstyletheadfamily \sphinxAtStartPar diff --git a/tests/roots/test-latex-table/longtable.rst b/tests/roots/test-latex-table/longtable.rst index bace9d4d2d8..da6fa5c5cec 100644 --- a/tests/roots/test-latex-table/longtable.rst +++ b/tests/roots/test-latex-table/longtable.rst @@ -5,7 +5,7 @@ longtable --------- .. table:: - :class: longtable + :class: longtable, borderless ======= ======= header1 header2 diff --git a/tests/roots/test-latex-table/tabular.rst b/tests/roots/test-latex-table/tabular.rst index 7f090954004..e02ae920549 100644 --- a/tests/roots/test-latex-table/tabular.rst +++ b/tests/roots/test-latex-table/tabular.rst @@ -20,6 +20,7 @@ table having :widths: option .. table:: :widths: 30,70 :name: namedtabular + :class: booktabs, colorrows ======= ======= header1 header2 diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 1c0b311ee8c..85546724a3c 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -1327,7 +1327,10 @@ def test_latex_table_with_booktabs(app, status, warning): result = (app.outdir / 'python.tex').read_text(encoding='utf8') assert r'\PassOptionsToPackage{booktabs}{sphinx}' in result assert r'\PassOptionsToPackage{colorrows}{sphinx}' in result - assert r'\begin{tabulary}{\linewidth}[t]{TTTTT}' in result + # tabularcolumns + assert r'\begin{tabulary}{\linewidth}[t]{|c|c|}' in result + # class: standard + assert r'\begin{tabulary}{\linewidth}[t]{|T|T|T|T|T|}' in result assert r'\begin{longtable}[c]{ll}' in result assert r'\begin{tabular}[t]{*{2}{\X{1}{2}}}' in result assert r'\begin{tabular}[t]{\X{30}{100}\X{70}{100}}' in result