Transferring a mathtype formula to a new docx file

92 views Asked by At

I use the python-docx library to format articles There is a problem with formulas in the MathType format; it is not possible to transfer them to a new formatted file.

I tried using this code:

doc = Document(docx_file_path)
redoc = Document(docx_file_path)
p = redoc.add_paragraph()
p_el=p._element
elem = doc.paragraphs[0]._element
for i in elem.getchildren():
    p_el.append(i)

Unfortunately, he either cannot tolerate the formula or partially tolerates it. But if you paste the formulas into the same file from which they were taken, then all the formulas will be displayed correctly, but the original formulas will disappear, leaving empty lines, whose deletion via Word will not break anything But if you delete empty paragraphs in the code, the formulas will work again. I deleted it this way:

doc.element.body.remove(doc.paragraphs[i]._element)
0

There are 0 answers