Asciidoctor-pdf: Table of contents clashes with following content

Created on 31 Aug 2019  路  10Comments  路  Source: asciidoctor/asciidoctor-pdf

It seems that there is a page break missing on the last toc page if the toc span multiple pages and the last page contains just a few lines:

Bildschirmfoto 2019-08-31 um 09 48 15

bug

All 10 comments

I tried to create a simple example so you can reproduce the issue but everything I came up with just worked fine.

Here is the original file:
phpspec.adoc.gz

The pdf was generated using this version of asciidoctor-pdf:

Asciidoctor PDF 1.5.0.alpha.18 using Asciidoctor 2.0.10 [https://asciidoctor.org]
Runtime Environment (ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux-musl]) (lc:UTF-8 fs:UTF-8 in:UTF-8 ex:UTF-8)

Can you please try beta.3?

Seems like it's still an issue with beta.3.

The problem appears to be that when a toc entry wraps, those wrapped lines are not being accounted for in the computation of the toc height. Therefore, it can end up not reserving enough pages (i.e., space) to insert the toc.

I can reproduce by cutting the document off at "==== Generating the private constructor". That should give me enough of a test case to work with to debug.

Ah. It's a bit of a chicken egg problem. We don't know how much space to reserve for the page number until the toc is rendered, and once we know it, it could cause the title to wrap. As a result, the toc needs more space than we reserved.

I think the solution here would be to reserve 4 characters for the page number. I can't image a document being more than 9999 pages. Though, just to safe, we could make that number configurable (and thus allow you to achieve the space you want either way).

You can workaround the problem temporarily by adding the following after the doctitle.

ifdef::backend-pdf[]
{zwsp}

<<<
endif::[]

However, the page numbers will then be off by 1.

This problem is only going to come up with documents that have extremely long section titles and very large sections.

Okay, I think I have a quick fix. It's not perfect, but it will ensure there will never be a page shortage.

Wow, thanks for taking your time and immediately coming up with a fix.

Was this page helpful?
0 / 5 - 0 ratings