mathjaxasciimath

Second derivative in AsciiMath


I'd like to express "the second derivative of f(x)" in AsciiMath.

In LaTeX, it's simply f''(x):

2nd derivative in LaTeX

The same in AsciiMath results in single quotes instead prime symbols:

2nd derivative in AsciiMath

I can get a perfect first derivative in AsciiMath using f^'(x)

1st derivative in AsciiMath

But the same approach doesn't work for second derivative: f^('')(x):

enter image description here

Is there a syntax in AsciiMath that results in the same output as LaTeX, with prime symbols and not single quotes?


Solution

  • As you point out, AsciiMath doesn't handle this situation very well. The approaches suggested so far produce poor quality MathML, and while MathJax's output handles even this awkward MathML, native MathML rendered (like Firefox's) will produce poorer results. Here is f^'text()^'(x) rendered by Firefox's native MathML:

    f''(x)

    This is badly rendered because the underlying MathML has two separate <msup> elements, and the bases for the two superscripts are not the same height:

    <math xmlns="http://www.w3.org/1998/Math/MathML">
      <mstyle displaystyle="true">
        <mrow>
          <msup>
            <mi>f</mi>
            <mo>&#x2032;</mo>
          </msup>
          <msup>
            <mrow>
              <mtext></mtext>
            </mrow>
            <mo>&#x2032;</mo>
          </msup>
        </mrow>
        <mrow>
          <mo>(</mo>
          <mi>x</mi>
          <mo>)</mo>
        </mrow>
      </mstyle>
    </math>
    

    One possible solution that produces better MathML is to use the double-prime unicode character, U+2033, as in f^″(x), or if you are entering it in an HTML page, as f^&#x2033;(x). This is rendered by MathJax's HTML-CSS output as

    f''(x) by MathJax

    and as

    f''(x) by Firefox

    by Forefox's native MathML renderer. Moreover, the MathML that AsciiMath produces for this input is more semantically meaningful:

    <math xmlns="http://www.w3.org/1998/Math/MathML">
      <mstyle displaystyle="true">
        <mrow>
          <msup>
            <mi>f</mi>
            <mo>&#x2033;</mo>
          </msup>
          <mrow>
            <mo>(</mo>
            <mi>x</mi>
            <mo>)</mo>
          </mrow>
        </mrow>
      </mstyle>
    </math>
    

    There is also a triple prime at U+2034 and a quadruple prime at U+2057, in case you need those as well. It would be nice if AsciiMath could combine the two separate primes into U+2033 automatically, but it doesn't currently do that.