How to Handle Equations and Symbols in Patent Disclosures: LaTeX to Word and Markdown Workflows

The patent-disclosure skill provides two complementary pipelines—converting LaTeX to Office Math (OMML) for editable Word documents and rendering PNG images via Matplotlib for markdown—to ensure mathematical expressions and special symbols like °, µ, and Ω render correctly in patent applications.

Handling complex mathematical notation and special characters is critical when drafting patent disclosures that must meet strict formatting standards. The handsomestWei/patent-disclosure-skill repository implements a robust dual-track system that processes LaTeX equations into either native Word equation objects or high-resolution images. This ensures that whether you are generating a .docx filing document or a markdown draft, symbols such as °, ‰, µ, and Ω maintain mathematical fidelity.

Dual-Track Architecture for Equation Rendering

The skill distinguishes between Word document generation and markdown processing, implementing specialized converters for each output format.

Word Documents via Office Math (OMML)

In math_to_omml.py, the system converts LaTeX snippets into OMML elements using the m:oMath and m:oMathPara namespaces. The pipeline first normalizes the LaTeX to remove unsupported commands, then uses latex2mathml to generate MathML, which is walked node-by-node and transformed into Office Math XML. The resulting element attaches directly to a python-docx paragraph, creating an editable equation within the final Word document.

Markdown via Matplotlib PNG Rendering

For markdown workflows, math_render.py scans files for inline $...$, \(...\) and block $$...$$, \[...\] delimiters. Each equation undergoes normalization for Matplotlib compatibility before matplotlib.mathtext renders it to PNG at 220 DPI with 12 pt font. The system inserts hidden HTML comments <!-- ![formula](path) --> after the LaTeX source, ensuring images display in Word exports without disrupting markdown previews.

LaTeX Normalization Pipelines

Both converters share normalization logic to sanitize LaTeX for their respective renderers, ensuring consistent symbol handling.

Normalizing for OMML Conversion

The normalize_latex_for_omml function in math_to_omml.py performs specific transformations required for Word compatibility:

  • Removes equation numbering commands (\tag, \label, \notag)
  • Replaces inequality shorthands (\le, \ge with \leq, \geq)
  • Expands unit macros (e.g., \textcelsius → ℃)
  • Handles degree patterns (^\circ C → ℃)

Normalizing for Matplotlib Rendering

The normalize_latex_for_mathtext function in math_render.py targets Matplotlib's mathtext engine:

  • Maps aliases (\ge → \geq, \iff → \Longleftrightarrow)
  • Strips bold formatting commands (\mathbf{...})
  • Removes sizing delimiters (\big, \left, \right)
  • Discards label and tag constructs entirely

Converting LaTeX to OMML for Word Documents

When generating .docx files via md_to_docx.py with the --math-render flag, the system attempts OMML conversion first, falling back to PNG rendering only if latex2mathml is unavailable.

To convert LaTeX directly to OMML programmatically:

from math_to_omml import latex_to_omml, omml_available

if omml_available():
    # display=True creates a block equation (m:oMathPara)

    omml_elem = latex_to_omml(r"\frac{a}{b} = c", display=True)
    # Append to python-docx paragraph

    paragraph._p.append(omml_elem)
else:
    raise RuntimeError("latex2mathml not installed")

Rendering Markdown Equations as PNG Images

For pure markdown processing or when OMML conversion fails, use the PNG pipeline via CLI or the Python API.

Command-line usage:

python -m skills.patent-disclosure.tools.math_render \
    -i draft.md -o draft_with_math.md \
    --assets-dir math_figures --dpi 250 --block-fontsize 13.0

Programmatic usage in Python:

from math_render import render_markdown_math
from pathlib import Path

md_text = Path("example.md").read_text(encoding="utf-8")
new_md, ok, fail = render_markdown_math(
    md_text,
    out_md_path=Path("example_out.md"),
    assets_rel="math_figures",
    dpi=220,
    block_fontsize=12.0,
    inline_fontsize=11.0,
)
print(f"Rendered {ok} equations, {fail} fell back to raw LaTeX.")

Customizing Symbol Mappings and Output Parameters

Extend the normalization behavior by modifying mapping dictionaries or adjusting rendering parameters.

  • LaTeX command mappings: Add entries to _LATEX_CMD_TO_REPL in math_to_omml.py or _LATEX_CMD_ALIASES in math_render.py to support additional custom symbols.
  • Image resolution: Adjust --dpi (default 220) for higher quality print-ready equations.
  • Font sizing: Control --block-fontsize and --inline-fontsize to match document typography standards.
  • Asset directories: Redirect PNG output with --assets-dir (default math_figures).

Summary

  • The patent-disclosure skill implements dual rendering pipelines: OMML for editable Word equations and PNG for markdown portability.
  • LaTeX normalization occurs in math_to_omml.py (for Word) and math_render.py (for images), standardizing commands and converting symbols like °, µ, and Ω.
  • OMML conversion requires latex2mathml and produces native Word math elements via the latex_to_omml function.
  • PNG rendering uses matplotlib.mathtext with configurable DPI and font sizes, storing images in a specified assets directory.
  • The system automatically falls back from OMML to PNG rendering when dependencies are missing, ensuring robust equation handling.

Frequently Asked Questions

How does the system handle special symbols like degrees or micro signs?

The normalization functions in math_to_omml.py and math_render.py explicitly map LaTeX commands to Unicode symbols. For example, \textcelsius converts to ℃, and degree patterns like ^\circ C normalize to the degree symbol before rendering, ensuring accurate representation in both Word and PNG outputs.

Can I edit equations after converting to Word format?

Yes. When using the OMML pipeline via math_to_omml.py, equations convert to native Office Math Markup Language elements (m:oMath). These remain fully editable within Microsoft Word using the built-in equation editor, unlike static PNG images which cannot be modified.

What happens if latex2mathml is not installed?

If latex2mathml is unavailable, the omml_available() function returns False, triggering the fallback mechanism in md_to_docx.py. The system then routes equations through math_render.py to generate PNG images instead, ensuring the document still contains readable mathematical expressions without failing the conversion.

How do I adjust the resolution of equation images?

Control PNG resolution using the --dpi parameter in the math_render.py CLI (default 220) or the dpi argument in the render_markdown_math function. Higher values produce crisper images suitable for high-resolution patent printing, while lower values reduce file size for web distribution.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →