Thanks Dan for your good question. Welcome to the community!
There are many good reasons why we DON’T want people to be editing the USFM files manually during the layout/typesetting process, so the Viewer that shows you the “processed USFM” which gets fed into the typesetting program (XeTeX) is primarily there for diagnostic purposes. It shows the end result of all the pre-processing that has taken place due to the multitude of settings in the App.
HOWEVER, there is good news: There already is a mechanism to do exactly what you’re asking for by automating it completely through clever find and replace rules (called Regular Expressions, or RegEx). On the advanced tab is an option to enable PrintDraftChanges.txt to be applied to the text.
Once you’ve clicked on Edit, you might see a file with a bunch of rules in it, or there may just be an empty file in the editor.
# A rule in this PrintDraftChange.txt file uses this syntax:
"Find what" > "Replace with"
So for this “strip out the duplicate headings” task, you’ll need to add a RegEx rule which will look something like this:
"\\rem (.+?)\r?\n\\s \1\r?\n" > "\\s \1\r\n"
If what I have above doesn’t quite match your needs, then adjust it as needed (for example replace \rem with whatever marker you have in your text). I highly recommend using a site like regex101.com to refine your expression, and test out your Find and Substitution strings on a small subset of your data until it works.
I hope this helps, but if you’re still stranded, please ask for further clarification.