dolanmiu / docx

Easily generate and modify .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.
https://docx.js.org/
MIT License
4.42k stars 486 forks source link

How can I convert latex to Word format #2392

Closed xu756 closed 1 year ago

xu756 commented 1 year ago

Great library。

like this

new MathRun('c = \\pm\\sqrt{a^2 + b^2}')

I want

image

How can I do it?

mwashambw commented 1 year ago

I have spent more than 10 hours finding solution for this. I have not found the answer untill now

dolanmiu commented 1 year ago

Read the documentation here, it should give you a good idea:

https://docx.js.org/#/usage/math?id=math

mwashambw commented 1 year ago

Already I have read it. What I have understood from this documentation is math object useful if you know the math equations and you want to write it manually. What if I want to use the code to write different equations to the document that I don't know how they are? In my case i have different math equations in data base saved in latex format, I want to write them to the word document programmatically. How can I use math object to implement this, while I don't know if the equation will have radical or square e.t.c I have tried different approach, I tried to convert those latex equations into MathML and paste into word document manually I have found that equations are rendered correctly ,But I have not found the way to pass MathML to the document via docx library

dolanmiu commented 1 year ago

Not in scope I am afraid, it would require creating a Latex tokeniser and parser, and then a way to convert that MathML AST into json. It would be possible, if there is an NPM package which turns MathML into JSON, but out of scope of this project.

mwashambw commented 1 year ago

Thanks for your response. So what is work round for this? Should I convert those equations into images and then imbed the to the document?

dolanmiu commented 1 year ago

That can be a workaround yes. Would be cool if you could release this work around as an npm package too!

YaoKaiLun commented 4 months ago

I wrote a tool to do that https://github.com/seewo-doc/docx-math-converter

xu756 commented 4 months ago

I wrote a tool to do that https://github.com/seewo-doc/docx-math-converter

great

dolanmiu commented 1 month ago

I wrote a tool to do that https://github.com/seewo-doc/docx-math-converter

This is awesome! I may integrate this into docx once I get time