How to Generate Word Format Disclosures in Patent-Disclosure-Skill
Word format disclosures are generated by rendering Mermaid diagrams and LaTeX formulas into portable assets, then converting the Markdown source to DOCX using tools/shared/md_to_docx.py, which maps content to native Word styles and embeds OMML or PNG math.
The handsomestWei/patent-disclosure-skill repository automates patent disclosure generation by transforming Markdown drafts into submission-ready Microsoft Word documents. To generate Word format disclosures effectively, you must understand the three-stage pipeline that processes visual assets, handles mathematical notation, and applies standard Word styling through the core converter utility.
The Markdown-to-Word Pipeline
Step 1: Draft Content with Embedded Diagrams and Math
The process begins with a standard Markdown file that contains the disclosure text, tables, and specially marked blocks for Mermaid diagrams and LaTeX formulas. These blocks remain as raw text until the rendering stage prepares them for Word compatibility.
Step 2: Render Visual Assets to PNG
Before Word conversion, Mermaid diagram definitions must be rendered as static images. The tools/shared/mermaid_render.py script processes these blocks and outputs PNG files. According to the source code, this utility handles the diagram-to-image transformation at lines 20–23 source. These images are then embedded into the final document during the conversion stage.
Step 3: Convert to DOCX with md_to_docx.py
The final conversion is performed by tools/shared/md_to_docx.py, a comprehensive Markdown-to-Word converter. This script parses the Markdown structure, applies Word’s built-in heading styles, embeds the previously rendered PNGs, and processes mathematical notation. The file header description at lines 3–5 outlines its purpose as a Markdown-to-DOCX converter with math and diagram support source.
Core Converter Capabilities
Mapping Markdown to Word Styles
The converter automatically maps Markdown heading levels (# through #########) to Microsoft Word’s native “Heading 1” through “Heading 9” styles. This ensures that the generated document maintains proper hierarchical structure and is compatible with Word’s navigation pane and table-of-contents features. The style mapping logic is implemented at lines 33–37 source.
Handling Mathematical Formulas
Mathematical expressions are processed with a dual-rendering strategy. The converter first attempts to generate Office Math Markup Language (OMML) for native Word equation editing. If OMML rendering fails, it automatically falls back to PNG image embedding to ensure the formula remains visible. This fallback mechanism is detailed at lines 386–393 source. The LaTeX delimiter definitions used for parsing formulas are stored in tools/shared/latex_delimiters.py.
Command-Line Interface
The script exposes several flags to control the conversion behavior. At lines 17–20, the argument parser defines options for input and output paths, along with flags to control math rendering source. Specifically, the --math-render flag enables the OMML/PNG math processing pipeline at lines 22–24 source. You can also specify custom output paths using the --docx argument, implemented at lines 456–463 source.
Practical Usage Examples
Run the complete pipeline from a Markdown draft that contains Mermaid diagrams:
python tools/shared/mermaid_render.py -i draft.md -o disclosure.md --docx out/disclosure.docx
Convert a pre-processed Markdown file (with diagrams already rendered to PNGs) directly to Word:
python tools/shared/md_to_docx.py --input disclosure.md --output disclosure.docx
Enable mathematical formula conversion with fallback to PNG if OMML generation fails:
python tools/shared/md_to_docx.py -i draft.md -o disclosure.docx --math-render
Generate only the processed Markdown without creating a DOCX file:
python tools/shared/mermaid_render.py -i draft.md -o disclosure.md --no-docx
If the converter encounters dependency errors, the script provides a helpful manual command suggestion at lines 392–399 source.
Summary
- Pipeline Architecture: Word generation requires pre-rendering Mermaid diagrams to PNG via
mermaid_render.py, followed by Markdown-to-DOCX conversion viamd_to_docx.py. - Style Preservation: The converter maps Markdown headings directly to Word’s built-in Heading 1–9 styles for native document navigation.
- Math Support: LaTeX formulas are converted to editable OMML when possible, falling back to PNG images to prevent rendering failures.
- Flexible CLI: Use
--math-renderto enable equation processing,--docx <path>for custom output locations, and--no-docxto skip Word generation.
Frequently Asked Questions
How are mathematical equations handled during Word conversion?
The md_to_docx.py converter first attempts to translate LaTeX expressions into Office Math Markup Language (OMML), which creates editable equations in Word. If the OMML generation fails for any expression, the system automatically renders that formula as a PNG image and embeds it instead. This dual approach ensures mathematical content is always visible regardless of complexity.
Can I generate a Word document without first rendering Mermaid diagrams separately?
No, the pipeline requires that Mermaid diagrams be rendered to PNG files before the final conversion. The md_to_docx.py script embeds these pre-generated images into the document; it does not perform real-time Mermaid rendering. You must run mermaid_render.py first, or use its --docx flag to trigger the full pipeline automatically.
What happens if the converter cannot launch due to missing dependencies?
If the helper script detects that it cannot execute md_to_docx.py—typically due to missing Python dependencies—it prints a manual command suggestion showing the exact syntax needed to run the conversion step-by-step. This allows users to debug environment issues while still completing the disclosure generation process.
Which file defines the LaTeX delimiters recognized by the converter?
The delimiter patterns used to identify inline and block-level mathematical expressions are defined in tools/shared/latex_delimiters.py. This module provides the regular expression patterns that md_to_docx.py uses to locate LaTeX syntax within the Markdown source before converting it to OMML or PNG.
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:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →