stencil
stencil copied to clipboard
Refreshing Table of Contents after document generation
Is your feature request related to a problem? Please describe. You can create a document with multiple headings and then use a docx feature called "Table of Contents" which will display table of contents based on those headings.
In LIbreOffice it's located here: Insert -> Table of Contents and Index -> Table of Contents, Index or Bibliography... If you change the headings, you can regenerate table of contents in with Tools -> Update -> Update all
Some headings & sections in stencil can be hidden with if clause, which means table of contents becomes outdated.
Describe the solution you'd like It would be nice to make stencil refresh table of contents after document gets compiled.
Describe alternatives you've considered It's possible to resolve this issue manually by introducing additional step in the rendering process, by running virtualized libreoffice and asking it to refresh the contents.
Also, I've noticed that when I trigger Table of Contents update for generated document it adds additional symbol before each heading.
I zoomed document a bit to make it more prominent

Also, I've noticed that when I trigger Table of Contents update for generated document it adds additional symbol before each heading.
hello @achempion, could you please attach an example document with this effect?
Hello @achempion, thank you for the detailed issue and the example and sorry for the late answer.
About the original issue:
The problem with TOC generation is that apart from parsing the structure of the document, it also needs to calculate page numbers. Page numbers depend on many factors: the layout of the document, spacing and even the font used. You can check it yourself: If you open a large docx document (like a long book with hundreds of pages) in Word and in LibreOffice, it is likely that the total number count will not match in the two programs, despite the standardization of the OOXML format and the decades of engineering work put in improving compatibility.
Therefore, correct TOC generation is not in the scope for this small library.
About regenerating TOC in virtualized LibreOffice:
I think this should be the correct solution to your problem. The TOC should be generated in the last step (immediately preceding printing or exporting to PDF) so the page numbers in the table will be in sync with the actual page numbers.
The bug you found about the extra / character is quite concerning though, I will take a look at that soon.
hello @achempion, how do you trigger refresh of Table Of Contents?
I am in LibreOffice 7.2.5.2 and both Right Click on TOC> Update Index and Tools menu > Update > Update All produce a correct TOC to me without the extra / characters. Could you describe your process?
I'm triggering update with Tools menu > Update > Update All
https://user-images.githubusercontent.com/1409852/153071139-ca6df1a3-61c4-4af8-8288-0c5518c44200.mov