Skip to content

fix(docx): preserve native OMML equation structure - #2163

Open
HenryZhu123 wants to merge 2 commits into
HKUDS:devfrom
HenryZhu123:fix/2144-docx-omml-equations
Open

HenryZhu123 wants to merge 2 commits into
HKUDS:devfrom
HenryZhu123:fix/2144-docx-omml-equations

Conversation

@HenryZhu123

Copy link
Copy Markdown

Description

Native Word equations are stored as structured Office Math (OMML), but the
current DOCX walker collects only their text leaves. This causes expressions
such as 1/2 + 1/3, 2^3, and sqrt(9) to be extracted as 12 + 13, 23,
and 9.

This change makes the shared DOCX extraction path namespace-aware and
recursively renders common OMML structures into unambiguous, model-readable
text:

  • fractions: a/b
  • superscripts and subscripts: a^b, a_b, and a_b^c
  • square roots and indexed roots: sqrt(x) and root(n, x)
  • nested expressions: for example, x^2/sqrt(y)

Unsupported structural elements are represented explicitly as
[unsupported equation: ...] instead of being silently flattened into a
potentially incorrect expression.

Because the fix is implemented in the shared DOCX extractor, the preserved
equations reach:

  • chat attachments
  • the text_only parsing path used for knowledge ingestion
  • Immersive Reading

The tests build valid DOCX files containing real OMML nodes rather than
mocking the extracted text.

Related Issues

Module(s) Affected

  • agents
  • api
  • config
  • core
  • knowledge
  • logging
  • services
  • tools
  • utils
  • web (Frontend)
  • docs (Documentation)
  • scripts
  • tests
  • Other: ...

Checklist

  • This PR targets dev (not main).
  • I have read and followed the contribution guidelines.
  • My code follows the project's coding standards.
  • I have run pre-commit run --all-files and fixed any issues.
  • I have added relevant tests for my changes.
  • Documentation is not required for this internal extraction fix.
  • My changes do not introduce any new security vulnerabilities.

Validation

Focused DOCX, parsing, attachment, and reading tests:

585 passed

Additional Notes

I noticed #2154 after completing this implementation. The two PRs overlap on
the core fraction, script, and radical handling.

This implementation additionally focuses on:

  • explicit handling of unsupported OMML structures instead of silently
    flattening them;
  • nested equation regression coverage;
  • integration coverage for chat attachments, text_only parsing, and
    Immersive Reading.

@HenryZhu123
HenryZhu123 force-pushed the fix/2144-docx-omml-equations branch from fd57c90 to 47e39c4 Compare October 30, 2026 02:50

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants