2

I am using a stylesheet to convert MathML to LaTeX. When I try to convert:

<mrow>
    <mo>|</mo>
    <mi>a</mi>
    <mo>|</mo>
</mrow>

In latex that should be written as:

\left\vert a \right\vert

Now the problem. I could easily write:

\vert a \vert

But in case when instead of 'a' there is some large expression, the vertical lines will not be tall as the expression, but stay the small. That is what \left and \right are for. Is there any easy way to do this that I don't see here, or do I need to parse the MathML in a way so I would know which vertical line is left and which is right? Thanks.

3
  • 1
    It's wrong to say that the text should be written \left\vert a\right\vert. The correct way (with amsmath) is \lvert a\rvert; \left and \right may be added (but in many cases \bigl or \bigr would suffice, or other similar pairs). The MathML input is wrong to begin with, in my opinion.
    – egreg
    Nov 23 '18 at 13:32
  • Thanks for the fast response. When I try to write just \lvert {some equation} \rvert, vertical bars are not scaled. \bigl and \bigr does not help either. I need to write \left and \right. As for mathML input, yes, some examples are wrong, there is nothing I can do about that.
    – trnavac
    Nov 23 '18 at 13:41
  • your question is about the conversion software you are using not about, so it isn't clearly on topic here, but as you have not said what convertor you are using then it is impossible to answer. but it is true that |a| is better latex for the absolute value than \left\vert \a\right\vert Nov 23 '18 at 14:21
1

OK, I solved it by writing a template:

<xsl:template match="m:mrow">
    <xsl:choose>
        <xsl:when test="count(./*)=3 and ./*[1]/m:mo = '|' and ./*[3]/m:mo = '|'">
            <xsl:text>\left\vert</xsl:text>
            <xsl:apply-templates select="./*[2]"/>
            <xsl:text>\right\vert</xsl:text>
        </xsl:when>
        <xsl:otherwise>
            <xsl:apply-templates/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

It may not be the perfect, but it works for the cases I need it to work for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.