Equation alignment in PDF output

This forum is for all Flare issues related to PDF, eBook, Microsoft Word, Adobe FrameMaker, XPS, and XHTML book targets.
Post Reply
mscaroline
Jr. Propeller Head
Posts: 5
Joined: Fri May 14, 2021 9:02 am

Equation alignment in PDF output

Post by mscaroline »

I'm in the process of moving some very math-heavy books into Flare from a mediawiki source, which is pure agony. The equations appear to be coming in as MathML; during output generation, Flare converts them to svg images. It's all working pretty well, except for the inline math. I just can't figure out how to get it to (even mostly) align with the text.

A sample bit of code brought in from a wiki page:
<p>That is, the probability that <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle X\,\!}"><semantics><mrow class="MJX-TeXAtom-ORD"><mstyle displaystyle="true" scriptlevel="0"><mi>X</mi><mspace width="thinmathspace" /><mspace width="negativethinmathspace" /></mstyle></mrow><annotation encoding="application/x-tex">{\displaystyle X\,\!}</annotation></semantics></math></span><img src="https://en.wikipedia.org/api/rest_v1/media/math/render/svg/98c6c570e3a2c130fc8d968160962b5e0fe4b0e0" class="mwe-math-fallback-image-inline" aria-hidden="true" style="vertical-align: -0.338ex;margin-right: -0.387ex;width: 2.367ex;height: 2.176ex;" alt="{\displaystyle X\,\!}" /></span> takes on a value in the interval ... </p>

In the PDF output, the "X" created there sits a bit above the rest of the text. (Yes, I know there's a lot of other weirdness going on there, not the least of which is the live consultation of the wikipedia api for the image that's used in my HTML5 output. I considered getting rid of that, but mediawiki did such a nice job with alignment of those images, I hate to lose them.) I've been attempting to create a style in my stylesheet that will just reposition the mwe-math-element span a bit lower, thereby fixing all 3900+ instances in my project... but no luck. Undoubtedly I just don't know what I'm doing. I'm hoping maybe somebody here will have some insight.

I'm so far over my head here that I don't even really know how to ask this, so if I've left out crucial information, please let me know!
Psider
Propellus Maximus
Posts: 811
Joined: Wed Jul 06, 2011 1:32 am

Re: Equation alignment in PDF output

Post by Psider »

It could be the inline style on the img. It sets a vertical-align, so you could try removing that or adjusting the number to see what happens.
mscaroline
Jr. Propeller Head
Posts: 5
Joined: Fri May 14, 2021 9:02 am

Re: Equation alignment in PDF output

Post by mscaroline »

That vertical-align is on the image generated by the wikipedia API, actually, and those don't show up in the PDF. The images that are used in the PDF are the ones generated by Flare, which happens upon generation of the target.

I've had some success, actually. In my print stylesheet, I've modified the .mwe-math-element class to have a relative position and fiddled about until I found a vertical alignment that sort of works for most cases. It's far from beautiful, but it's largely readable without confusion. The images generated from equations vary widely in terms of their vertical dimensions, and I have yet to find a way to just get them so that their middle aligns with the middle of the text line, but I'll take what I can get.

Figured I'd document that here in case anyone is ever in a similar boat.

.mwe-math-element
{
position: relative;
top: 0.3em;
}
Post Reply