paragraph break not rendered when formulas end in spaces

In a comment under this answer, the author complained that he or she was unable to split a paragraph in two. I edited and found that there were already two line breaks between the two parts of the paragraph, and yet they were being rendered as one paragraph. By experimenting, I found that if I removed one of the many spaces at the ends of the formulas (right before the closing dollar sign), the paragraphs were rendered separately as intended.

-
This seems closely related to this bug found by Jack Schmidt. The offending piece seems to be related to the closing parenthesis right after the dollar sign here: (so $|\gamma'| = 1$). Add a space after the dollar sign or remove the space before the dollar sign, and the desired paragraph appears magically. Also, this is the only portion of the source where the removal of a space has an effect. –  t.b. Jul 10 '11 at 22:58
Which shows that "Trapped in the code" is not a useful title for a bug report :-) –  joriki Jul 10 '11 at 23:05
@Theo: About your last sentence: No, I tried removing several different spaces, and several (around half) made the paragraph break appear. –  joriki Jul 10 '11 at 23:06
Which makes it even stranger: I tried all of them (in the second paragraph) and this was the only one that had effect. But I copied the source to a new answer window, so maybe... –  t.b. Jul 10 '11 at 23:07
The other ones that worked for me may well have been in the first paragraph -- I vaguely remember that at least one that worked was in the first paragraph. –  joriki Jul 10 '11 at 23:15
@Theo: I went through all the spaces before dollar signs and checked whether deleting them makes the paragraph break appear. In the first paragraph, a consecutive group of them starting with $f$ before "values very similarly" and ending with $\int_\gamma f(z) dz$ before "represents almost the very same idea" works. In the second paragraph, the one you mention works, but also the following $f$ (the last formula in that paragraph). Are you sure that last one doesn't work for you? (Not too surprisingly, none of the ones in the last paragraph make a difference.) –  joriki Jul 10 '11 at 23:23
Right: I overlooked the last $f$ and that one works for me too. Here's a pattern: There are five formulae in which the dollar sign is immediately followed by a punctuation sign in the first two paragraphs: $f$'s, $(a,b)$;, $f$'s, $w(x)$. and $|\gamma'| = 1$). Adding a space after the 2nd dollar sign makes the paragraph break appear after the first, the third and the fifth formula, this looks suspicious... However, I can't make out a simple pattern in which cases deletion leads to breaking the paragraph, but it seems somewhat related. Aaah what a waste of time ;-) –  t.b. Jul 10 '11 at 23:47
Let me just get this right: so in all these cases, the math rendered properly, but sometimes the paragraph breaks following the math expressions get eaten? –  Willie Wong Jul 11 '11 at 0:11
Not all paragraph breaks. There are two paragraph breaks (i.e. three paragraphs) in the source, but only the second paragraph break disappears. It can be made to reappear by deleting the above-listed spaces, some of which are in the first paragraph and some in the second; in all cases, the break that reappears is the one between the second and third paragraphs. Yes, the math rendered properly in all cases. –  joriki Jul 11 '11 at 0:13
Hum, looks like an issue with the code sanitizing. If you look at the HTML source for the originals, the line breaks are still there. My guess is that there is some glob that is used to replace double line breaks with </p><p> chunks, but to prevent math expressions from breaking from extraneous inserts of HTML markup, it also globs against  pairs. But somehow the pairing becomes ambiguous when you have excessive spaces in the TeX. –  Willie Wong Jul 11 '11 at 0:20
Wait, changing something in the first paragraph helps? There goes that theory... well, we'd have to wait for someone from SE to look at this. It is rather mysterious. –  Willie Wong Jul 11 '11 at 0:28