In https://github.com/lilypond/lilypond/blob/master/ly/titling-init.ly there are predicates that detect if the current page is the first or last one of a book, or of a bookpart. But it's not clear to me how to generalize from there. How would I detect if the current page was the first or last page of a score?