Skip to content

Commit

Permalink
Extend testing to cover usage of booktabs
Browse files Browse the repository at this point in the history
  • Loading branch information
jfbu committed Aug 7, 2022
1 parent dcc70dd commit a3498c6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 3 additions & 3 deletions sphinx/writers/latex.py
Expand Up @@ -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:
Expand Down
17 changes: 16 additions & 1 deletion tests/test_build_latex.py
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit a3498c6

Please sign in to comment.