Extra line break below math block

Summary

When there is some text in a line immediately following a math block, it produces more space than if there was a blank line between the math block and the text.

Steps to reproduce

Case 1

$$1 + 1 = 2$$
Text

Case 2

$$1 + 1 = 2$$

Text

Expected result

Because case 2 has a blank line in between, one would expect that case 2 should produce equal or more space between the math block and the text compared to case 1.

Actual result

Case 1 produces more space between the math block and the text compared to case 2.


Additional information

Inspecting the HTML, I noticed that in case 1 there is a line break <br> between the math block and the text. I initially tried hiding the line break but this caused a problem:
Case 3

$$1 + 1 = 2$$ is true.
Text

If a math block was followed by some text in the same line, the subsequent “Text” appeared on the same line as the first part because of the missing line break.

Proposed solution

A solution would be to hide the line break when it immediately follows a math block. In case 3, " is true." appears between the math block and the line break, and in this case the line break should be present to separate " is true." and “Text”. However, in case 1 there is nothing between the math block and the line break, and in this case the line break takes up extra space before “Text” so it should be hidden.

This JavaScript code fixes it in preview mode. However, this is temporary and does not work for exporting to PDF.

for (a of document.querySelectorAll("span.math.math-block.is-loaded")) {
    if (a.nextSibling && a.nextSibling.nodeName === "BR") {
        a.nextSibling.style.setProperty("display", "none");
    }
}

A post was merged into an existing topic: Extra newline between Latex equation blocks/a Latex equation block and a paragraph