Skip to content

How to change default Cambria Math font for math equations while using python-docx? #1341

@shashikulk

Description

@shashikulk

I am trying to add a math equation to Word document using python-docx. By default, the font used for the equation is Cambria Math. I want to change it to some other font.

How can I change it using python-docx or otherwise?

I am adding math equation to the docx paragraph using below code snippet -

    doc_1 = docx.Document()
    doc_para = doc_1.add_paragraph()
    # create MathML structure
    expr1xml = latex2mathml.converter.convert(<math equation as LaTeX expression>)
    tree = etree.fromstring(expr1xml)
    # convert to MS Office structure
    xslt = etree.parse('C:/Program Files/Microsoft Office/root/Office16/MML2OMML.XSL')
    transform = etree.XSLT(xslt)
    new_dom = transform(tree)
    doc_para._element.append(new_dom.getroot())

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions