Skip to content

LaTeX: Bug if a table is inside a multi-row/column cell of another table #13597

@fournier-p

Description

@fournier-p

Describe the bug

As indicated in the title, if a table is defined in a multi-row or multi-column (or both) cell of another table, then the produce latex file will not be valid.

How to Reproduce

This minimal rst is enough to trigger the problem:
(The + at the middle of the first line is intended to trigger a multi-column cell)

+---+---+
| +---+ |
| |   | |
| +---+ |
+-------+

Environment Information

Platform:              linux; (Linux-5.10.0-18-amd64-x86_64-with-glibc2.31)
Python version:        3.12.8 (main, Apr 10 2025, 17:00:17) [GCC 10.2.1 20210110])
Python implementation: CPython
Sphinx version:        8.2.3
Docutils version:      0.20.1
Jinja2 version:        3.1.2
Pygments version:      2.19.1

Sphinx extensions

No extension needed.

Additional context

I could dig a bit more into the issue and from what I found it seems that the needs_linetrimming value of the LatexTranslator class is not properly used.

With the example I gave above, we enter visit_entry and depart_entry both twice:

  • First we go into visit_entry for the outer table, in which we set self.needs_linetrimming to 1
    • Then we go into visit_entry a second time, this time for the inner table. In this case we wouldn't be setting self.needs_linetrimming to 1 but in any case it is already set.
    • Then we go into depart_entry for the inner table, and since self.needs_linetrimming == 1 we then call popbody even though it was needed for the entry of the outer table.
  • Finally, we go into depart_entry a second time, for the outer table, in which we will not call popbody because self.needs_linetrimming was set to 0 in the previous call of depart_entry

One way to fix this would be to use node attributes to set it on the entry node which actually needs line trimming.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions