Interesting. A couple of observations (it's always easy after someone else has done all the hard work!)...
The rule for 'p_chapter' has code starting:
$DisplayExpression = $Name + " \( A- " + collect_if(descendants, $Prototype="p_kindA",$Name).replace(";","-") + " )" + " \( B- " +...
For equality tests in queries, such as used in the
== and not
You don't need to escape the '(' characters that are inside literal strings.
+ " )" + " \( B- " can be written more simply as
+ " )( B- ".
.replace() call is just formatting a list but using a contains-like regex to do this. My understanding is that
.format() would be more efficient here - MB may correct me. Efficiency comes into play as the document grows in size/complexity, rather than at the size of a demo.
Putting the above together we get:
$DisplayExpression = $Name + " ( A- " + collect_if(descendants, $Prototype=="p_kindA",$Name).format("-") + " )( B- " +...
Some further edge case issues.
collect_if() returns a List-type. Lists allow duplicates. Now you probably won't use the same named character note, e.g. "Donec", twice in a chapter but if you were to you, you'd get 'Donec' twice in the list output via your rule. Also lists built in the order items are interrogated with (I assume) is $OutlineOder. If you want the items in alphabetical order use a chained
.isort and not
.sort will sort all capital letters separately from lower case ones (Ant;Bee;ant), whereas
.isort returns a more 'human' sort result (Ant;ant;Bee).
Below I've added both these to the above but omit either both these latter as your own project's needs demand:
$DisplayExpression = $Name + " \( A- " + collect_if(descendants, $Prototype=="p_kindA",$Name).unique.isort.format("-") + " )( B- " +...
The output can get quite long. On my 13" MBAir it didn't take much to make the $DisplayName string wrap to a new line. This you might consider putting the data into $HoweverExpression, which works in outline view.