Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Fri Feb 02, 2024 2:22 pm

I'm trying to create a doc file with a Latex Formula in it. For some reason, when passing a string with the equation to FromLatexMathCode method of an OfficeMath object, I'm getting an error. Here is a minimal example that reproduces the issue:
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

lebron23ny
 
Posts: 1
Joined: Fri Feb 02, 2024 1:48 pm

Sun Feb 04, 2024 6:02 am

Hello,

Thank you for your inquiry.
I tested your code and did reproduce the issue you mentioned. I have logged the issue into our bug tracking system with the ticket number SPIREDOC-10294. Our development team will investigate and fix it. Once it is resolved, I will inform you in time. Sorry for the inconvenience caused.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Mon Dec 09, 2024 9:56 am

Hello,

Thank you for your patience.
We have just released the latest Spire.Doc for Python Version:12.12.0, which fixes SPIREDOC-10294, welcome to update and test.
Website link:https://www.e-iceblue.com/Download/Spire-Doc-Python.html

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 472
Joined: Mon Dec 27, 2021 2:23 am

Return to Spire.Doc