3

When using David Carlisle's stylesheet to convert MathML to LaTeX, for some reasons, the subscript on an integral symbol seems to display noticeably farther from the integral as shown below:

MathML:

<math xmlns:mml="http://www.w3.org/1998/Math/MathML">
    <mrow>
        <msubsup>
            <mo stretchy="false">∫</mo>
            <mn>0</mn>
            <mi>1</mi>
        </msubsup>
        <mrow>
            <msup>
                <mi>x</mi>
                <mi>3</mi>
            </msup>
            <mi>d</mi>
            <mi>x</mi>
        </mrow>
    </mrow>
</math>

LaTeX generated by David's stylesheet [I added the preamble to the tex file for testing]:

\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{enumitem}
\usepackage[parfill]{parskip}
\usepackage{pmml-new}
\begin{document}

\par
\[\let\par\empty
{{{{\mo{\unicode{8747}}}}\sb{{{0}}}\sp{{1}}}{{\msup{{x}}{{3}}}dx}}
\]\par

\[\let\par\empty
{{{\mathop{{\mo{\unicode{8747}}}}\sb{{{0}}}}\sp{{1}}}{{\msup{{x}}{{3}}}dx}}

\]\par

\[\int_0^1x^3dx\]

\end{document}

Remarks:

  1. First typesetting above is generated from above MathML using David's stylesheet. Here you notice (as shown in first integral below) that the subscript 0 is quite far away from the integral
  2. Second typesetting above is the same as the first one but here I manually surrounded {\mo{\unicode{8747}}}}\sb{{{0}}} with \mathop{...}. And now you see (in the second integral below) that the subscript 0 is very close to the integral as it should be.
  3. Third typesetting above is just a plain LaTeX for comparison.

Screenshot of PDF generated from above LaTeX:

enter image description here

My failed attempt:

It seems the following portions of David's pmm-nw.sty and pmm2texfrag.xsl files are playing some role here for displaying these upper/lower limits and subscript/superscript. I dared to modify them but had no luck. Maybe, someone has a better idea/suggestion.

Possible relevant portion of pmm-nw.sty file:

......
\def\msub#1#2{%
  \mathop{#1}\nolimits\sb{#2}}
\def\mosub#1#2{%
  #1\nolimits\sb{#2}}
\def\msup#1#2{%
  \mathop{#1}\nolimits\sp{#2}}
\def\msubsup#1#2#3{%
  \mathop{#1}\nolimits\sb{#2}\sp{#3}}
\def\mosubsup#1#2#3{%
  #1\nolimits\sb{#2}\sp{#3}}

\def\munder#1#2{%
  \mathop{#1}\sb{#2}}
\def\mover#1#2{%
  \mathop{#1}\sp{#2}}
\def\munderover#1#2#3{%
  \mathop{#1}\sb{#2}\sp{#3}}
.....

Possible relevant portion of pmm2texfrag.xsl file:

<xsl:template mode="pmml2tex" match="m:mover">
 <xsl:text>{</xsl:text>
 <xsl:text>\mathop{</xsl:text>
 <xsl:apply-templates mode="pmml2tex" select="*[1]"/>
 <xsl:text>}\limits</xsl:text>
 <xsl:text>\sp{</xsl:text>
 <xsl:apply-templates mode="pmml2tex" select="*[2]"/>
 <xsl:text>}</xsl:text>
 <xsl:text>}</xsl:text>
</xsl:template>

.....

<xsl:template mode="pmml2tex" match="m:munder">
 <xsl:text>{</xsl:text>
 <xsl:text>\mathop{</xsl:text>
 <xsl:apply-templates mode="pmml2tex" select="*[1]"/>
 <xsl:text>}\limits</xsl:text>
 <xsl:text>\sb{</xsl:text>
 <xsl:apply-templates mode="pmml2tex" select="*[2]"/>
 <xsl:text>}</xsl:text>
 <xsl:text>}</xsl:text>
</xsl:template>


<xsl:template mode="pmml2tex" match="m:munderover">
 <xsl:text>{</xsl:text>
 <xsl:text>\mathop{</xsl:text>
 <xsl:apply-templates mode="pmml2tex" select="*[1]"/>
 <xsl:text>}\limits</xsl:text>
 <xsl:text>\sb{</xsl:text>
 <xsl:apply-templates mode="pmml2tex" select="*[2]"/>
 <xsl:text>}</xsl:text>
 <xsl:text>\sp{</xsl:text>
 <xsl:apply-templates mode="pmml2tex" select="*[3]"/>
 <xsl:text>}</xsl:text>
 <xsl:text>}</xsl:text>
</xsl:template>

1 Answer 1

2

It's all so long ago....

But

enter image description here

Firstly you need to correct the namespace declaration in your source, or nothing matches at all

    <math xmlns="http://www.w3.org/1998/Math/MathML">

Then, really pmml2tex adds too many brace groups (which makes it less likely to generate tex errors but more than likely to generate poor spacing) Here you can get rid of some of them with a custom template for integral, adding

<xsl:template mode="pmml2tex" match="m:msubsup[*[1]/self::m:mo='&#x222b;']">
 <xsl:text>\int\sb{</xsl:text>
 <xsl:apply-templates mode="pmml2tex" select="*[2]"/>
 <xsl:text>}</xsl:text>
 <xsl:text>\sp{</xsl:text>
 <xsl:apply-templates mode="pmml2tex" select="*[3]"/>
 <xsl:text>}</xsl:text>
</xsl:template>

to pmml2texfrag.xsl produces

\[\let\par\empty


{
\int\sb{{0}}\sp{1}
{
{\msup{x}{3}}
d
x
}
}


\]

which makes the above output.

3
  • Your suggestion worked like a charm. Thank you for coming to my rescue.
    – nam
    Mar 21, 2020 at 17:24
  • Some slight changes - to your suggested custom temple above - resolved the issue of my this SO post as well. For summation case, I made another copy/paste of your custom template to pmm2texfrag.xsl and just replaced &#x222b; with &#x2211; and \int with \sum. And now the upper/lower limits are displaying correctly above and below the summation symbol. I hope I'm doing it right for summation case.
    – nam
    Mar 21, 2020 at 19:18
  • @nam yes ideally it would automatically detect the nature of the base and do it right automatically, but not today, adding templates for the cases that you need is all I can offer today:-) Mar 21, 2020 at 19:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .