Misplaced equation - Possible bug

I’m converting a markdown document to ODT with pandoc (pandoc test.md -s --self-contained -o test.odt) and although the XML structure of the document stays the same and seems correct, in some cases the equation is wrongly placed (depending on its height) in between the text, while it should be placed after the text.

The markdown document with which the issue show up is

### Title title title title

Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text:

$$\frac{1^2}{2^A}$$

while if you use the following equation

$$\frac{1}{2}$$

the issue does NOT show up.

Please find attached the ODT of the 2 cases.

test_issue.odt (9.5 KB)
test_no-issue.odt (9.5 KB)

As a general rule, never trust all these “automatic” converters. ODF is a complex format which has updates from time to time. Some subtleties may not be understood by the converter.

In your case, the position of the anchor is not obvious. In both cases, it looks like the anchor is the last (empty) paragraph. The formula is anchored To paragraph which is not the usual default mode (As character) but this is not an error per se. It only tells that some direct formatting has been applied above the Formula frame style.

In both cases, horizontal and vertical positioning is Center relative to Paragraph text area and in both cases, the formula is not where it is requested. Horizontal position is OK, but vertical position is wrong, though less problematic in test_no-issue.odt.

Also, wrap mode Wrap off will accentuate “extreme” behaviour.

As I don’t know exactly what you expect for your formulas, I applied Frame style then reapplied Formala style to get rid of all manual settings. This leaves the formula inline in the last paragraph.

If you want it “isolated” from the paragraph, change anchor to To paragraph and change position settings. It looks like vertical Center in this particular case offsets up too much the frame. I tried all variations and the frame is always too high up, eventually interfering with the preceding paragraph.

If I copy the fformula frame and paste it into another empty paragraph, everything works fine.

I suspect some “glitch” with the conversion but I am unable to tell exactly what happens.

Forget about automatic converter, what I’m asking is why and ODT document with the same XML structure and parameters (specifically, the equation paragraph placed after the text) is rendered in LibreOffice in two different ways, of which one seems wrong (the equation before end of text).

Also, I know that there are many ways to fix the issue playing inside LibreOffice but what I’m looking for is an appropriate modification to the XML code that would make LibreOffice to place the equation after the text in both cases.

To be even clearer, here is the portion of XML code in question (“content.xml”), the same in both cases:

<text:p text:style-name="First_20_paragraph">Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text:</text:p>
<text:p text:style-name="Text_20_body"><draw:frame draw:style-name="fr2" text:anchor-type="paragraph"><draw:object xlink:href="Formula-0/" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" /></draw:frame></text:p>

If there is no bug, there should be a way, changing the above XML code, to obtain the equation placed after the end of text in both cases.

I always advocate against playing with the XML code directly. As I am no developer and have only a partial knowledge of ODF, I never fiddle with it for fear of introducing a very subtle misbehaviour.
I had a look at the XML of both files, just to see exactly where the anchor is. Once done, I went back to Writer and saw that frame styles were stained with some direct formatting (probably created by the converter).
Trying to revert to some neat and pure style formatting, I saw that anchoring a frame to an empty paragraph may be problematic. Probably because a frame is not supposed to be “stand-alone”. Information in a frame is always related to something in the text. Consequently it should be anchored to this bit of text. When the anchoring paragraph is empty, I noticed that the frame is somewhat offset upwards, which creates the issue.
This might be the bug, but as I wrote above this is a semantic deviation. There is technically no objection to anchoring to an empty paragraph but this semantically makes no sense (i.e. a “nothing” can’t be significant and therefore cannot be logically annotated with a frame).
As soon as the paragraph has some content, frame position behaves nominal.

Possible easy fix:
Revert to “usual” inline insertion of formula. It will behave like a text character. To get it horizontally centered, choose center alignment for the paragraph. Of course, create a dedicated paragraph style, this will make it easier to fix all formulas in the document. Vertical alignment is no longer an issue because your formula is now part of the flow (as beign a “character” in the paragraph).

A more elaborate fix would be to change the anchor to attach the formula to the paragraph where it is referenced in the text. Ideally, you caption it so that it gets a number which is mentioned (with a cross-reference) in the text. You then play (through an adequate frame style) to position it on a side.