Follow-up Comment #11, bug #62825 (project groff): That's a good workaround. A couple of conceptually simple refinements could reduce some of the tedium of the process.
First, instead of redefining $h throughout the document, define it once at the top, but include in it logic to handle the special-needs pages, by using stacked .ie/.el statements as an ersatz "switch" statement. (An example of this was very recently added to the groff manual, in commit 41477bb4 <http://git.savannah.gnu.org/cgit/groff.git/commit/?id=41477bb4>.) Here is how you could generate the same output you got in your comment #10 example: .hx .ll 6.5i .de $h . ie \\n%=2 .tl 'Chapter \\n(ch'Section 1.2'Page \\n%' .el \{.ie \\n%=3 .tl 'Chapter \\n(ch'Section 1.3'Page \\n%' .el .tl 'Chapter \\n(ch'Section \\*($n'Page \\n%' .\} .hl .. .+c "" .sh 2 "Section 1.1" .lp This is the first section. .bp .sh 2 "Section 1.2" .lp This is the second section. .bp .sh 2 "Section 1.3" .lp This is the third section. Another fairly straightforward refinement would be to automate your step 2: -me providing plug-in macros that are called at the top and bottom of every page simplifies this immensely. And if you're not using any footers (as in your example output), and thus don't care about preserving -me's default definition of .$f, it's even more straightforward. You can send this data to stderr (using groff's .tm request), so that it doesn't interfere with your normal output. Your first iteration of the document could look something like this: .hx .ll 6.5i .de $H .nr chapter_number_at_page_top \\n(ch .ds section_string_at_page_top \\*($n .. .de $f .if !\\n[chapter_number_at_page_top]=\\n(ch .tm Page \\n% starts with chapter \\n[chapter_number_at_page_top] and ends with chapter \\n(ch .if !'\\*[section_string_at_page_top]'\\*($n' .tm Page \\n% starts with section \\*[section_string_at_page_top] and ends with section \\*($n .. .de $h .tl 'Chapter \\n(ch'Section \\*($n'Page \\n%' .hl .. .+c "" .sh 2 "Section 1.1" .lp This is the first section. .bp .sh 2 "Section 1.2" .lp This is the second section. .bp .sh 2 "Section 1.3" .lp This is the third section. Then on the first pass, you don't even care about the output, only what appears on stderr: $ nroff -me section_test_first_pass.me > /dev/null Page 2 starts with section \&1.1 and ends with section \&1.2 Page 3 starts with section \&1.2 and ends with section \&1.3 $ This makes it simple to populate the .ie block in your $h macro. If you want to get extra fancy, you could even craft your .tm statements to output lines in .ie format that would then only need to be pasted back into the code to give you your second pass. Once you're at that stage, you could write a driver script to run the first pass, capture stderr, put that back into the document in the right place, and groff the revised document. Implementation of this is left as an exercise to the reader. (-: Whether it's worth the development and debugging time to write such a script depends on how many documents you have and how long they are. _______________________________________________________ Reply to this item at: <https://savannah.gnu.org/bugs/?62825> _______________________________________________ Message sent via Savannah https://savannah.gnu.org/