I would like to create a ToC for a Bible Modules. Ideally I’d like the ToC to be automatically generated for each \s marker, so that each section title is a line in the ToC and the corresponding page number shows up.
If PTXprint can’t create that automatically based on \s, then I’d like to be able to add extra tags throughout the modules with information in each to state “add a ToC entry here”. I tried something like
\toc1 entry_name but that didn’t work (which isn’t entirely unexpected, since generally you don’t want more than one \toc1 entry in a given book).
The thing is, I could swear I had this working a couple of weeks ago but I can’t recreate my work. Does anyone know how to create such a ToC which isn’t simply based on \toc1/2/3 entries from different books?
Have you received any response to this?
A TOC based on \s would work very well for Song books as well.
I did not receive a reply.
At that time I was working with a few different modules each of which had around 100 section titles. So the amount of manual labor which would have been necessary to create the contents by hand was massive, and subsequent revisions would have been difficult.
I ended up writing a few Python scripts which allowed me to create or populate the underlying
context.xml file manually. It was confusing to work with and required remember when things needed to be updated externally, but at least it was quick.
The easiest way to add an index of songs is to duplicate the contents of the \s Song Titles using a Changes.txt rule like this:
'(\\s )([^\\]+)( ?\r?\n)' > '\\toc1 \2\3\1\2\3'
This says, look for a \s section heading and call that match-group 1.
Then grab the content/text of that heading, calling that match-group 2.
Grab the end of line (which needs at least an \n but might have a space and/or \r before the final \n) and call that match-group 3.
Then, on the replace-with side, put in the new marker \toc1 followed by the contents of 2 and the end of line piece. Then put everything else back as you found it (1,2,3).
These \toc1 fields should now get picked up and used in the Table of Contents.
Note that you can also generate a sorted (table of contents) from these same \toc1 markers for an index at the back of the song book. Just use \ztoc|sorta\* instead of \ztoc|main\*
Argh, sorry about that. I was thinking this question was in reference to SAB (where this is still an open problem).
Yes, this problem was ‘easily’ solved using regex similar to what @mjpenny states above.
One point where you’ll probably want to check things carefully. When I originally used a regex like the one above, in cases where \s markers fell at the top of the page the page numbers in the ToC were off by one (they were for the previous page). You can see the bug report here, along with a solution using a more complicated regex expression.