使用MediaWiki API获取维基百科数学表达式

3
2个回答

4
您需要使用MediaWiki的本地API函数查询整个页面源代码:https://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvlimit=1&rvprop=content&format=xml&titles=delta-v。这将给您与编辑页面时看到的完全相同的内容。
查询prop=extracts是由扩展TextExtracts实现的,它不能始终处理其他扩展(如Math)生成的代码内容。这可能被认为是TextExtracts的一个错误,但考虑到MediaWiki中页面呈现的复杂性以及各种扩展添加内容的方式数量,它可能永远无法捕获所有情况。

0
在您的原始链接中,您可以获取MathML渲染,其中包括注释元素<annotation encoding="application/x-tex">中的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>


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接