Thank you for the questions, James.
First, the effect of an opening Nemeth Code indicator continues until it is terminated by a Nemeth Code terminator. A braille page break does NOT end the effect of an opening Nemeth Code indicator.
Second, it is alright to include your variables in italicized passages. Part of the intent of the Nemeth Code rule to ignore typeface for variables is to cut down on typeform switches. For both of your print examples, your first proposed transcription treats typeforms and variables correctly.
Last but not least, I suspect that "dist" in dist(A, B) is an abbreviated function name, and so in braille a space should be inserted between "dist" and its argument "(A, B)".
Thank you for your time and attention!