PHPOffice / PHPWord

A pure PHP library for reading and writing word processing documents
https://phpoffice.github.io/PHPWord/
Other
7.16k stars 2.68k forks source link

MathML to Docx #2559

Open KaioSpa opened 5 months ago

KaioSpa commented 5 months ago

Hey, I'm lost here and really need help. I'm sorry if it's obvious and I'm just blind...

I'm trying to convert MathML formulas to docx. I have seen that a merge was made, but I was not able to implement it.

When I try to convert directly to ODText, the formula does not appear, and it just shows the numbers without the formula (10^20 appears as 1020).

$phpWord = new PhpWord();
    $section = $phpWord->addSection();
    Html::addHtml($section, $html, false, false);

    // Save the resulting document to a temporary file
    $tempDoc = tempnam(sys_get_temp_dir(), 'PHPWord');
    $phpWord->save($tempDoc, 'Word2007');

And when trying to use the Formula class, it just returns empty:

$math = new Formula(new Math($mathML));

An example of my MathML element (I extracted the element to try to use the Formula class): $mathML=<math xmlns="http://www.w3.org/1998/Math/MathML"><mn>4</mn><mi>x</mi><mo>-</mo><mfrac><mrow><mn>3</mn><mo>-</mo><mi>x</mi></mrow><mn>2</mn></mfrac><mo>=</mo><mn>21</mn><mo>&#160;</mo><mo>&#160;</mo><mo>&#160;</mo><mi>e</mi><mo>&#160;</mo><mo>&#160;</mo><mo>&#160;</mo><mfrac><mrow><mi>y</mi><mo>-</mo><mn>3</mn></mrow><mn>2</mn></mfrac><mo>=</mo><mfrac><mn>1</mn><mrow><mi>y</mi><mo>+</mo><mn>2</mn></mrow></mfrac><mo>+</mo><mfrac><mn>3</mn><mn>2</mn></mfrac></math>

Can someone help?