-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MathML to Docx #2559
Labels
Milestone
Comments
Hi @KaioSpa , I am also very much interested in writing MathML to docx files, can anybody help with this? |
4 tasks
It's fixed in develop branch with #2645. Code : // Read contents
$name = basename(__FILE__, '.php');
$source = __DIR__ . "/{$name}.docx";
$mathML='<math xmlns="https://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> </mo><mo> </mo><mo> </mo><mi>e</mi><mo> </mo><mo> </mo><mo> </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>';
$reader = new \PhpOffice\Math\Reader\MathML();
$math = $reader->read($mathML);
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section->addFormula($math);
$phpWord->save($source, 'Word2007'); |
@Opussci & @KaioSpa This issue has been fixed by a maintainer. You can help him by sponsoring him through Github sponsors. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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).
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="https://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> </mo><mo> </mo><mo> </mo><mi>e</mi><mo> </mo><mo> </mo><mo> </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?
The text was updated successfully, but these errors were encountered: