Commit 8f58b508 authored by Jonas Schüppen's avatar Jonas Schüppen
Browse files

Tried to fix equation-update function

parent 917e8dd4
Loading
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -2601,12 +2601,26 @@ def update_equation_style(docx_input, docx_output):

    # Loop over all elements to find "Equation" and change to "EQ"
    for equation in root.xpath('.//m:oMath', namespaces=ns):
        p = equation.getparent()

        # Surrounding paragraph
        p = equation
        while p is not None and p.tag != f"{{{ns['w']}}}p":
            p = p.getparent()

        if p is None:
            continue

        pStyle = p.xpath('./w:pPr/w:pStyle', namespaces=ns)

        if pStyle:
            current_style = pStyle[0].get(f"{{{ns['w']}}}val")

            # Do not overwrite Example/Note Styles
            if current_style in ["EW", "NO", "TAN"]:
                continue

            pStyle[0].set(f"{{{ns['w']}}}val", new_style)

        counter += 1
        
    print(f'Changed style "Equation" to "EQ" {counter} times')
@@ -2731,6 +2745,7 @@ def update_format_styles_cli():
    update_table_captions(args.docx_input, args.docx_output)
    update_abbreviations(args.docx_input, args.docx_output)
    update_table_rows(args.docx_input, args.docx_output)
    update_notes(args.docx_input, args.docx_output)
    update_references(args.docx_input, args.docx_output)
    update_lists(args.docx_input, args.docx_output)
    update_body_text_style(args.docx_input, args.docx_output)
@@ -2740,7 +2755,6 @@ def update_format_styles_cli():
    add_break_after_code_blocks_and_tables(args.docx_input, args.docx_output)
    update_equation_style(args.docx_input, args.docx_output)
    correct_quotes_docx(args.docx_input, args.docx_output)
    update_notes(args.docx_input, args.docx_output)
    
    # Final sanitization: remove invalid XML characters
    ns = {"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"}