Add a rule (line) at the end of the introduction

I’d like to have a horizontal rule (line) at the end of the introduction.
Adding this to changes.txt adds a rule before chapter 1 in each book:
'(\\c 1 ?\r?\n)' > '\\zrule |width=".6"\\*\r\n\1 '

Alas, I’m publishing a collection of OT portions in which chapter 1 is frequently omitted. So, I’ve written a series of rules like this to changes.txt, one for each book:

at NUM 0 '(\\c )'	>	'\\zrule |width=".6"\\*\r\n\1 '
at JDG 0 '(\\c )'	>	'\\zrule |width=".6"\\*\r\n\1 '
at 2SA 0 '(\\c )'	>	'\\zrule |width=".6"\\*\r\n\1 '

This adds a rule before the first \c to occur in “chapter 0”. Is there a way to write a rule which would do this in all books, so I don’t need to specify the book names and I could replace my \c 1 rule above?

Wouldn’t this be a nice feature to add to the PTXprint UI?

I can’t think of something that would catch all the “other first chapters” of each book. I wonder if the TeX guys could use some kind of a (only-used-once) hook to achieve the same thing.

But one shorthand for your rule is to put multiple refs on the same line:

at NUM 0 JDG 0 2SA 0 '(\\c )' > '\\zrule |width=".6"\\*\r\n\1 '

I think I’m missing something. Are you asking for something to fire on the first transition from introductory material to chapter? Or for any such transition?

Some kind of \sethook{first}{c}{code} (i.e. code that fires when the implicit \c 0 at the start of a book ends?)

Yes, almost… We need to insert a \zrule just before the first \c of a book (regardless if it is chapter 1 or chapter 99).

Seems to work (current github):

\sethook{first}{c}{\zrule|width="0.6" \*}

\id sets the chapter number to 0 (zero). When \c is reached then if the chapter number is zero, the above hook code is executed, just before the new chapter number gets set.

Thanks Mark, you saying “before the first \c of a book” gave me an idea of how to do this in RegEx. This changes.txt rule seems to work for all books:

'(?s)(\\id .+?)(?=\\c)' > '\1\\zrule |width=".6"\\*\r\n '

  • (?s) causes . to match line breaks too
  • (\id .+?) finds \id followed by any other stream of characters.
  • (?=\c) is a positive lookahead which finds \c
    So, this expression captures into group \1 everything from \id up to the last character before the first occurrence of \c.

The right side of the rule “replaces” everything before \c with what was there (\1) followed by a rule and a new line.

Nice work @EricP! Just to make it clear for anyone else following this thread, the RegEx rule above would go into the changes.txt file. (BTW, is there a stray space after the final \n and if so, you might want to take it away. Or perhaps I’m missing something about why it is needed.)

But if you want to use the \sethook method instead, then that would go into the ptxprint-mods.tex file instead.