-
-
Notifications
You must be signed in to change notification settings - Fork 495
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
Insert Math with Mathml or latex #2842
Comments
Yes, this is possible, Is this what you need? |
I have reviewed the document you provided, but it is very inconvenient. For generating complex mathematical formulas, I would prefer to use LaTeX or MathML directly, and docx supports this approach. If the functionality hasn't been available yet, I really hope you can give me some advice on how to add such a feature on top of docx. |
That would require writing a parser/ast generator though. Are there any parsers available? I am sure this is not a trivial project |
I don't quite understand what you're trying to express. Can you explain it in detail? |
As in, you are suggesting Feel free to make a PR to allow support for this, but from my knowledge, I am saying it is not easy I can see someone has created a package: https://github.com/siefkenj/unified-latex?tab=readme-ov-file |
If anyone finds is helpful, I have written a very simple parser for a personal project. It supports divisions, subscripts and superscripts. /** Converts simple mathematics equations to DOCX objects */
function stringToMathItem(l_str){
if(l_str.includes("/")){
// Find fraction
let slpt = l_str.split("/");
return new docx.MathFraction({numerator: [stringToMathItem(slpt[0])], denominator: [stringToMathItem(slpt[1])]});
}else if(l_str.includes("_")){
// Find subscript
let slpt = l_str.split("_");
return new docx.MathSubScript({children: [stringToMathItem(slpt[0])], subScript: [stringToMathItem(slpt[1])]});
}else if(l_str.includes("^")){
// Find superscript
let slpt = l_str.split("^");
return new docx.MathSuperScript({children: [stringToMathItem(slpt[0])], superScript: [stringToMathItem(slpt[1])]});
}
return new docx.MathRun(`${l_str}`);
}; It may require splitting a string first, e.g.: let mathChildren = [];
mystr.split(" ").forEach(l_str =>{
mathChildren.push(stringToMathItem(l_str));
mathChildren.push(new docx.MathRun(` `));
}); |
I hope that the input of mathematical formulas and symbols can support the use of LaTeX or MathML, which is more compatible. Of course, existing methods can also be retained for coexistence
latexlive this website can export word. Looking forward to your answer.
The text was updated successfully, but these errors were encountered: