Java 如何打印/显示MathML表达式?

Java 如何打印/显示MathML表达式?,java,jasper-reports,mathml,Java,Jasper Reports,Mathml,目前,我正在尝试使用带有markup=“html”的文本字段,但它不起作用 示例 <textField isStretchWithOverflow="true" isBlankWhenNull="true"> <reportElement positionType="Float" stretchType="RelativeToTallestObject" x="100" y=&q

目前,我正在尝试使用带有
markup=“html”
的文本字段,但它不起作用

示例

<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="100" y="0" width="450" height="25" isPrintWhenDetailOverflows="true" uuid="1aeaa5e9-4136-4239-a301-2733598340d9">
    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<textElement verticalAlignment="Middle" markup="html">
    <paragraph lineSpacing="Single" leftIndent="5" rightIndent="3"/>
</textElement>
<textFieldExpression><![CDATA[$F{question}]]></textFieldExpression>

$F{question}包含:

"<p id="id"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>A</mi><mo>+</mo><mo>&#160;</mo><mi>B</mi><mo>&#160;</mo><mo>&#160;</mo><msqrt><mi>c</mi><mfenced><mrow><mi>d</mi><mfenced open="[" close="]"><mi>r</mi></mfenced></mrow></mfenced></msqrt><mo>&#160;</mo><mi>&#948;</mi><mo>&#160;</mo><mo>&#8734;</mo><mi mathvariant="normal">&#960;</mi><mo>&#160;</mo></math></p>"

A+ ;B ;cdr ;δ; ;∞;π; ;

预期结果:

"<p id="id"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>A</mi><mo>+</mo><mo>&#160;</mo><mi>B</mi><mo>&#160;</mo><mo>&#160;</mo><msqrt><mi>c</mi><mfenced><mrow><mi>d</mi><mfenced open="[" close="]"><mi>r</mi></mfenced></mrow></mfenced></msqrt><mo>&#160;</mo><mi>&#948;</mi><mo>&#160;</mo><mo>&#8734;</mo><mi mathvariant="normal">&#960;</mi><mo>&#160;</mo></math></p>"

我得到的结果:

"<p id="id"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>A</mi><mo>+</mo><mo>&#160;</mo><mi>B</mi><mo>&#160;</mo><mo>&#160;</mo><msqrt><mi>c</mi><mfenced><mrow><mi>d</mi><mfenced open="[" close="]"><mi>r</mi></mfenced></mrow></mfenced></msqrt><mo>&#160;</mo><mi>&#948;</mi><mo>&#160;</mo><mo>&#8734;</mo><mi mathvariant="normal">&#960;</mi><mo>&#160;</mo></math></p>"

文本字段不支持MathML,它只支持非常基本的html,也不能使用html组件,因为构建它的JEditorPane不支持MathML

例如,您将需要一个外部库,一旦在类路径中有了这个库,您就可以使用将xml呈现到
buffereImage
,然后在jasper报告中显示它

这可以在没有java助手类的情况下完成,如本例中所示,因此在一行上直接在jrxml中编写所有代码(使用下面的构建器模式),但为了示例的清晰性,我将使用外部助手类

例子 JAVA jrxml

输出(导出为pdf)