For typesetting short snippets of music notation within TeX, you can use the MusixTeX package <https://ctan.org/pkg/musixtex>.
Following a few links, I found a great overview:
MusiXTEX - Using TEX to write polyphonic instrumental music
http://icking-music-archive.org/software/musixtex/musixdoc.p... (pdf)
For Lilypond, here's an introduction that demonstrates how to "write music by typing text":
Lilypond: "Compiling" Music
It's well worth reading for that and other fascinating stuff: [pdf link](https://drive.google.com/file/d/10TAOEgIL--CmzqOl0fkdP-cagjS...).
I started with the section on Music Typesetting, good stuff: Oxford Music Processor, his Philip's Music Writer, the language syntax to encode notation information.. This is right up my alley, thank you for the link.
So much of it is relevant to our current time, it's still not a solved problem and there's room for innovation.
I'll enjoy reading the rest of his memoir.
Totally different needs than mathematical notation, but seems to share common issues, like specialized symbols, placements and spacings.