- Code: Select all
from spire.doc import *
outputFile = "Formula.docx"
latexMathFormula = "x^{2}"
doc = Document()
section = doc.AddSection()
textPara = section.AddParagraph()
textPara.AppendText("Creating Equations from LaTeX Code")
textPara.ApplyStyle(BuiltinStyle.Heading1)
textPara.Format.HorizontalAlignment = HorizontalAlignment.Center
officeMath = OfficeMath(doc)
officeMath.FromLatexMathCode(latexMathFormula)
paragraph = section.AddParagraph()
paragraph.Items.Add(officeMath)
section.AddParagraph()
doc.SaveToFile(outputFile, FileFormat.Docx)
doc.Close()
And here is the full error traceback:
- Traceback (most recent call last):
File "C:\Users\lebro\PycharmProjects\pyqt6\Different test\Spire_DOC\File.py", line 14, in <module>
officeMath.FromLatexMathCode(latexMathFormula)
File "C:\Users\lebro\AppData\Local\Programs\Python\Python312\Lib\site-packages\spire\doc\OfficeMath.py", line 58, in FromLatexMathCode
CallCFunction(GetDllLibDoc().OfficeMath_FromLatexMathCode,self.Ptr, latexMathCodePtr)
File "C:\Users\lebro\AppData\Local\Programs\Python\Python312\Lib\site-packages\spire\doc\common\__init__.py", line 109, in CallCFunction
raise SpireException(info)
spire.doc.common.SpireException: Arg_InvalidCastException: at System.Runtime.TypeCast.CheckCastClass(MethodTable*, Object) + 0x31
at Spire.AOT.Helper`1.PtrToObject(IntPtr) + 0xd6
at Spire.Doc.AOT.NLOfficeMath.OfficeMath_FromLatexMathCode(IntPtr, IntPtr, IntPtr) + 0x61