Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
fournier-p opened this issue May 27, 2025 · 1 comment
Open
Labels

Comments

@fournier-p
Copy link

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.

@jfbu
Copy link
Contributor

jfbu commented May 28, 2025

Thanks for report. Other "nested tables" issues include #11498 and #11515. The latex table rendering code is complex particularly for rendering merged cells especially when they involve both multiple rows and multiple columns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants