From a3498c6a28ecc5083bf0501043c6e892dd582311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20B?= <2589111+jfbu@users.noreply.github.com> Date: Sun, 7 Aug 2022 21:42:10 +0200 Subject: [PATCH] Extend testing to cover usage of booktabs --- sphinx/writers/latex.py | 6 +++--- tests/test_build_latex.py | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 638f65b7624..7b21d6fd6cd 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -872,9 +872,9 @@ def visit_table(self, node: Element) -> None: logger.info(__('both tabularcolumns and :widths: option are given. ' ':widths: is ignored.'), location=node) if '|' in self.table.colspec and self.table.booktabs: - logger.info(__('tabularcolumns argument contains | which conflicts with' - 'latex_use_booktabs = True. This may cause layout problems' - 'in PDF output.'), location=node) + logger.info(__('tabularcolumns argument contains | and ' + 'latex_use_booktabs is True. Expect gaps between vertical ' + 'and horizontal rules in this table.'), location=node) self.next_table_colspec = None def depart_table(self, node: Element) -> None: diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 4581d637684..cf6b40d9756 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -22,7 +22,8 @@ DOCCLASSES = ['howto', 'manual'] STYLEFILES = ['article.cls', 'fancyhdr.sty', 'titlesec.sty', 'amsmath.sty', 'framed.sty', 'color.sty', 'fancyvrb.sty', - 'fncychap.sty', 'geometry.sty', 'kvoptions.sty', 'hyperref.sty'] + 'fncychap.sty', 'geometry.sty', 'kvoptions.sty', 'hyperref.sty', + 'booktabs.sty'] LATEX_WARNINGS = ENV_WARNINGS + """\ %(root)s/index.rst:\\d+: WARNING: unknown option: '&option' @@ -90,6 +91,8 @@ def skip_if_stylefiles_notfound(testfunc): def test_build_latex_doc(app, status, warning, engine, docclass): app.config.latex_engine = engine app.config.latex_documents = [app.config.latex_documents[0][:4] + (docclass,)] + if engine == 'xelatex': + app.config.latex_use_booktabs = True app.builder.init() LaTeXTranslator.ignore_missing_images = True @@ -1315,6 +1318,18 @@ def get_expected(name): assert actual == expected +@pytest.mark.sphinx('latex', testroot='latex-table', + confoverrides={'latex_use_booktabs': True}) +def test_latex_table_with_booktabs(app, status, warning): + app.builder.build_all() + result = (app.outdir / 'python.tex').read_text(encoding='utf8') + assert r'\PassOptionsToPackage{booktabs}{sphinx}' in result + assert r'\begin{tabulary}{\linewidth}[t]{TTTTT}' 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 + + @pytest.mark.sphinx('latex', testroot='latex-table', confoverrides={'templates_path': ['_mytemplates/latex']}) def test_latex_table_custom_template_caseA(app, status, warning):