3

I want to get the content of <math> tags in the API response MediaWiki.

I've tried to use this query: https://en.wikipedia.org/w/api.php?action=query&prop=extracts&format=xml&titles=delta-v

And I'm getting valid xml file, but in place of enter image description here

I'm getting:

<dl><dd></dd></dl>

And what I want is:

<math>\Delta{v} = \int_{t_0}^{t_1} {\frac {|T|} {m}}\, dt</math>

Which is available via "Edit" button here: http://en.wikipedia.org/w/index.php?title=Delta-v&action=edit

is this somehow available via API?

leo
  • 8,106
  • 7
  • 48
  • 80
TigerInALoop
  • 225
  • 1
  • 2
  • 8

2 Answers2

4

You need to query for the whole page source, using MediaWiki's native API function:

    https://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvlimit=1&rvprop=content&format=xml&titles=delta-v

That will give you exactly the same thing as you see when editing the page.

The prop=extracts query is implemented by the extension TextExtracts, and does not always work with code content generated by other extensions (such as Math). It can probably be considered a bug in TextExtracts, but given the complexity of page rendering in MediaWiki, and the number of ways in which various extensions add to the content, it will probably never catch everything.

leo
  • 8,106
  • 7
  • 48
  • 80
0

In your original link you get the MathML rendering, including the TeX code in an annotation element <annotation encoding="application/x-tex">.

<dd>
  <span>
    <span>
      <math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \Delta {v}=\int _{t_{0}}^{t_{1}}{\frac {|T(t)|}{m(t)}}\,dt}">
        <semantics>
          <mrow class="MJX-TeXAtom-ORD">
            <mstyle displaystyle="true" scriptlevel="0">
              <mi mathvariant="normal">Δ</mi>
              <mrow class="MJX-TeXAtom-ORD">
                <mi>v</mi>
              </mrow>
              <mo>=</mo>
              <msubsup>
                <mo>∫</mo>
                <mrow class="MJX-TeXAtom-ORD">
                  <msub>
                    <mi>t</mi>
                    <mrow class="MJX-TeXAtom-ORD">
                      <mn>0</mn>
                    </mrow>
                  </msub>
                </mrow>
                <mrow class="MJX-TeXAtom-ORD">
                  <msub>
                    <mi>t</mi>
                    <mrow class="MJX-TeXAtom-ORD">
                      <mn>1</mn>
                    </mrow>
                  </msub>
                </mrow>
              </msubsup>
              <mrow class="MJX-TeXAtom-ORD">
                <mfrac>
                  <mrow>
                    <mrow class="MJX-TeXAtom-ORD">
                      <mo stretchy="false">|</mo>
                    </mrow>
                    <mi>T</mi>
                    <mo stretchy="false">(</mo>
                    <mi>t</mi>
                    <mo stretchy="false">)</mo>
                    <mrow class="MJX-TeXAtom-ORD">
                      <mo stretchy="false">|</mo>
                    </mrow>
                  </mrow>
                  <mrow>
                    <mi>m</mi>
                    <mo stretchy="false">(</mo>
                    <mi>t</mi>
                    <mo stretchy="false">)</mo>
                  </mrow>
                </mfrac>
              </mrow>
              <mspace width="thinmathspace" />
              <mi>d</mi>
              <mi>t</mi>
            </mstyle>
          </mrow>
          <annotation encoding="application/x-tex">{\displaystyle \Delta {v}=\int _{t_{0}}^{t_{1}}{\frac {|T(t)|}{m(t)}}\,dt}</annotation>
        </semantics>
      </math>
    </span>
  </span>
</dd>