Generating table of contents for multi-file asciidoc book - asciidoc

I am a beginner at asciidoc. I have structured my project into modular files so it is easier to manage. And I am able to generate the pdf using asciidoctor. However, the toc does not include the list of files it gets through the include directive.
Here is the main file:
= Booktitle
Vinay <email>
:sectnums:
:toc:
:toclevels:
:leveloffset: 1
include::chapters/chapter_00.adoc
include::chapters/chapter_01.adoc
include::chapters/chapter_02.adoc
:leveloffset: 0
Index
======
And here is chapter_01.adoc:
= The First Chapter
This is the first chapter.
The table of contents only includes a link to the Index. What am I doing wrong?
The command I used is: asciidoctor-pdf book.adoc

Your include is missing a pair of square brackets. For a book that has a title page, you might want to set the doctype attribute to book. The attribute toclevel should be set to a number indicating the heading levels you want to list in your table of contents. If you leave it empty, the table of contents will be empty.
Tested with Asciidoctor PDF 1.5.3 using Asciidoctor 2.0.10, the following worked for me:
= Booktitle
Vinay <email>
:sectnums:
:toc:
:toclevels: 2
:doctype: book
:leveloffset: 1
include::chapters/chapter_00.adoc[]
include::chapters/chapter_01.adoc[]
include::chapters/chapter_02.adoc[]
:leveloffset: 0
[Index]
= Index

Related

Is there a way to restart figure numbering in Sphinx?

I have a set of three related documents in Sphinx (4.2.0). The top-level table of contents looks like this:
.. toctree::
:maxdepth: 2
Requirements_Specification/index.rst
User_Guide/index.rst
Release_Report/index.rst
In conf.py, I have:
numfig = True
numfig_secnum_depth = 1
This numbers all the figures and tables consecutively across the three documents. For example, if there are 10 figures in each document, then:
the figures in the Requirements Specification doc are numbered 1 to 10
the figures in the User Guide doc are numbered 11 to 20
the figures in the Release Report doc are numbered 21 to 30.
Instead, I would like the numbering to start at 1 in each doc, so in this example each doc would have figures numbered 1 to 10. Is there some way of achieving this?
I've tried putting :numbered: in the toctree directive, but that treats each doc as a chapter (i.e. Requirements Specification is chapter 1, User Guide is chapter 2, Release Report is chapter 3). I need each doc to be able to stand alone. I build the docs both as one set of HTML and also as three separate PDFs.

Issue with xsl-fo :footnote when generating pdf/ua-1 document with fop.: "tagged PDF note id is missing"

I have an issue with <fo:footnote> when generating pdf/ua-1 document with fop.
The resulting pdf displays correctly the footnote in the page but don’t pass the pdf-ua validation. A severe error on pdf tag Note “id is missing” is raised so the document is not conformed. I'm using PAC3 for the conformance test.
In the example below I have extracted the basic <fo:footnote> element which has a unique id.
How can I generate the missing Id attribute in the pdf tagged Note element?
Here is the xsl-fo really simple footnote. Note that I used an id to reference the footnote.
some text...
<fo:footnote id="FNE0001">
<fo:inline font-size="6pt" baseline-shift="super">E0001</fo:inline>
<fo:footnote-body>
<fo:block>
<fo:inline>E0001</fo:inline><fo:inline > JO L 139 du 29.5.2002, p. 9.</fo:inline>
</fo:block>
</fo:footnote-body>
</fo:footnote> some text...
Apache FOP has been set to generate pdf-ua through the conf file as follow:
<renderers>
<renderer mime="application/pdf">
<!-- Before setting the pdf-ua-mode, we must insert metadata Title in FO declaration -->
<pdf-ua-mode>PDF/UA-1</pdf-ua-mode>
....
PAC3 is checking against the failure conditions in the Matterhorn Protocol; latest edition at https://www.pdfa.org/resource/the-matterhorn-protocol/.
PAC3 is probably reporting on failure condition 19-003, ID entry of the tag is not present.
fo:footnote-body can have an id property. You could try adding an ID to that. In the fo:inline for the footnote marker, you might also need to add an fo:basic-link that refers to that ID.
FWIW, your footnote does not cause that error when checking PDF/UA generated by AH Formatter, and I'm only guessing at what FOP would be doing differently. (PAC3 and I generally disagree when it complains about a footnote being a possibly incorrect use of a Note tag, but that's another story: PAC3 tries to automate checking the conditions that should be checked by a human, and it doesn't always get it right.)

wkhtmltopdf from list of files generates wrong TOC based on H tags

I am using python-pdfkit as follows to generate a PDF:
pdfkit.from_file(list_of_files, toc=toc, cover=cover, cover_first=True, options=default_options)
My problem is regarding the table of contents that is generated:
The table of contents is generated based on the H tags in the input
documents
If my html files are like:
index1.html
<h1>Title</h1>
...
[content]
index2.html
<h2>Subtitle</h2>
...
[content]
index3.html
<h3>Sub-subtitle</h3>
...
[content]
Since they are 3 different files, then the generated TOC is:
Title --------------------- Page x
Subtitle ------------------ Page y
Sub-subtitle -------------- Page z
Instead of
Title--------------------- Page x
Subtitle -------------- Page y
Sub-subtitle ------- Page z
I have tried merging all html files together but it is giving me a lot of problems with the internal links... linking to files instead to HTML #IDs gets tricky with a single HTML file all merged.
Any idea how to tell wkhtmltopdf to respect the H tags hierarchy without resetting it per file?
Thanks!
Edit:
After some discussion in the wkhtmltopdf github issues section, the only easy way of achieving this result is pre-parsing the HTML files to merge them all together.
See the following link for more details:https://github.com/wkhtmltopdf/wkhtmltopdf/issues/4310

How to number code listings in asciidoc?

I'm writing a blog in ascidoc and would like the code listings to be automatically numbered, e.g.
Listing 1.3 The Hello World code
...
Listing 1.4 Some other code sample
Is there an attribute that I can set for the entire text so asciidoc would automatically number code listings?
It is not that clear in the asciidoctor user-manual (Listing Blocks), but in order for asciidoctor to number the listing you need to:
add a caption to each block
set the listing-caption attribute at the begining of your document
Example:
:listing-caption: Listing
.The Hello World code
----
//TODO: add hello world code
----
.Some other code sample
----
//TODO: Some other code sample
----
Controlling the way the listing blocks are numbered (1.1, 1.2 in your example) is not that easy. There is a discussion on GitHub for that.

Can Sphinx Section Numbering Skip Certain Sections (like a title)?

I am making a series of design documents in Sphinx and I would like to include them together in a toctree and have the sections within the documents numbered. I know that I can use .. sectnum:: to number all sections in the child pages. However, Sphinx/rst numbers the title of the page (which is really just the first section) and the table of contents ends up looking like:
Table of Contents
1 Design the First
2 Design the Second
and each child page looks like:
1 Design the First
1.1 First Section
1.2 Second Section
What I want is a table of contents on my index page that just lists the title
Table of Contents
Design The First
Design the Second
and child page that look like
Design the First
1 First Section
2 Second Section
Is there a way to have a title that shows up in the TOC as well as on the top of a child page which does not end up being a numbered section?
I don't know what you ended up doing, but I wanted to do the exact same thing! I had the following setup:
index.rst
.. toctree::
assignment
library_api
I only wanted the assignment part to have numbers, so either could have done two separate toctree with one using :numbered:, or put at the top of the file
.. sectnum::
:start: 0
Giving of course the exact problem you mention -- my top-level title was Assignment Writeup, so that was 0 and everything below it in subsections was 0.x e.g.
Assignment Writeup
==================
First Task
----------
Second Task
-----------
gives
0. Assignment Writeup
0.1 First Task
0.2 Second Task
as it turns out, there's an easy hack you can do. It makes things more modular than probably desired, but "add a layer of indirection".
So now I have assignment.rst and assignment_writeup.rst. assignment.rst just basically has a title and a toctree:
Assignment Writeup
==================
.. toctree::
:maxdepth: 4
assignment_writeup
then take all sub-sections and put them in assignment_writeup and "upcast" their heading level. So I now take all subsections and make them sections, and subsub and make them sub.
.. sectnum::
:start: 0
First Task
==========
^^^ === instead of --- now
Second Task
===========
and we now finally have
Assignment Writeup
0. First Task
1. Second Task
kind of dubious, but this was the only way I could achieve it x0 I wonder what you did between asking this and now? Hopefully somebody will see this and benefit one day!
Note: this has undesireable side-effects. The Assignment Writeup shows up on its own page, with just Links to the indirect document. Not sure which is worse honestly...

Resources