Skip to content

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 10, 2026

Summary

Fixes #14271.

LaTeXFootnoteVisitor.depart_table() unconditionally calls next(node.findall(nodes.tbody)), which raises StopIteration when a table has header rows but no body rows. This happens when external parsers like myst_parser produce a docutils table node tree from Markdown tables that have only a header row (e.g. | Key | P | Summary |\n| --- | --- | --- |).

The fix:

  • Use next(..., None) to safely handle the missing tbody
  • When tbody is present, behavior is unchanged (footnotes are inserted at the head of tbody)
  • When tbody is absent, any collected table footnotes are placed after the table node instead, preserving footnote rendering

Test:

  • Added test_latex_table_empty_body which constructs a table node with thead but no tbody (mirroring what myst_parser produces) and verifies that LaTeXFootnoteVisitor processes it without raising StopIteration
  • Verified the test fails with StopIteration on the unfixed code and passes with the fix
  • All existing LaTeX builder tests continue to pass

Test plan

  • New unit test test_latex_table_empty_body passes
  • All existing LaTeX table tests pass (9/9)
  • All existing LaTeX footnote tests pass (5/5)
  • Full LaTeX test suite passes (82 passed, 11 skipped for missing LaTeX styles)
  • ruff check passes on both modified files

🤖 Generated with Claude Code

The LaTeXFootnoteVisitor.depart_table() method called
next(node.findall(nodes.tbody)) which raises StopIteration when a
table has header rows but no body rows (as produced by e.g. myst_parser
from Markdown). Handle the missing tbody gracefully by placing any
collected footnotes after the table node instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error generating latex from Markdown with empty table

1 participant