Skip to content

feat(export): add a table of contents page to the PDF - #204

Merged
gnacho merged 2 commits into
masterfrom
feat/195-pdf-toc
Nov 19, 2026
Merged

gnacho merged 2 commits into
masterfrom
feat/195-pdf-toc

Conversation

@gnacho

@gnacho gnacho commented Nov 18, 2026

Copy link
Copy Markdown
Owner

The PDF can now start with a table of contents listing the h1 to h3 headings with the page where each one falls.

How it works, without new dependencies:

  • The body is paginated exactly as before and the index pages are prepended, so a number is body page + 1 + index pages and it is the real page by construction.
  • paginar_indice flows the rows onto as many pages as needed, the first one discounting the heading height, and the numbering shifts with them.
  • The index heading is measured and drawn as a real h1 block, so it follows the page template, the theme and the user stylesheet. The rows use a dotted leader drawn with cairo instead of glyphs, to keep the extracted text clean.
  • The option is a switch in Preferences > Export, stored in export-toc.

Also in here: the image menu labels from #194 (Small, Medium, Large, Align centre) now go through a literal gettext() call, so regenerating the .pot no longer loses them.

Verified: make check green (221 unit tests) and the new ignored end to end test exports real PDFs and checks every entry against the page the heading is really on: 5 pages with a one page index, 11 pages with a two page index (70 headings) and the Manuscript template with its title block. I checked those numbers again with pdftotext -layout outside the test.

Out of scope, as the issue said: PDF bookmarks and clickable internal links, which need post-processing the written file.

The READMEs no longer claim that the PDF has no table of contents.

Closes #195

@gnacho
gnacho merged commit 9d299df into master Nov 19, 2026
3 checks passed
@gnacho
gnacho deleted the feat/195-pdf-toc branch November 19, 2026 06:45
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.

PDF: table of contents page with real page numbers

1 participant