Clearly, the line numbering algorithm is confused by the superscripts and subscripts in the text: one version renders with 4 numbered lines, the other with 5. Moreover, the vertical spacing is all wrong.
That seems like a big problem for using Typst for scientific manuscripts. Is there an obvious solution that I’m missing?
While testing with this I observed that a simpler $X^Y_Z$ does not exhibit the same behavior. The problem, it turns out, are the quotes. I know there has been some discussion that strings in math are kinda hard to interpret, and it seems this is another case this comes up. You can avoid your problem by using upright, at the cost of slightly different typesetting – whether that is acceptable depends on whether your attachments are multiple letters or actual words.
EDIT: I just found a solution for regular text, i.e. one that is appropriate for words in sub/superscript. Included in the examples
It seems the way typst determines what paragraph line is and isn’t numbered is dependent on the size of the paragraph numbering, for some reason.
Setting the numbering to be “tall”
#set par.line(numbering: i => align(bottom, box(height: 20pt)[#i]))
I just updated my original reply – in retrospect, the solution is pretty clear: you can set par.line(numbering: none) for the offending texts, or for “paragraphs” inside inline equations in general!