How patent-disclosure-skill Generates Draft Patent Applications (Invention, Utility Model, Design)

patent-disclosure-skill creates draft patent applications through a modular, data-driven pipeline that transforms raw invention data—PDFs, YAML/JSON plans, and Markdown drafts—into filing-ready Word documents with SVG/PNG figures and LaTeX-rendered formulas.

The open-source tool handles all three patent types (invention, utility model, and design patents) by breaking the workflow into three distinct stages: ingestion, figure rendering, and document export. Each stage is implemented as a standalone Python module in the handsomestWei/patent-disclosure-skill repository, making the pipeline easy to test, extend, and integrate into automated workflows.


Stage 1: Ingestion and Draft Markdown Generation

The process begins in skills/patent-oa/tools/ingest_case.py, where the build_draft_from_pdfs function parses source patent PDFs.

This function extracts:

  • The specification (说明书)
  • Claims (权利要求书)
  • Abstract (说明书摘要)
  • Existing figures and metadata

It then writes a draft Markdown file ({case_id}.md) to the oa/drafts/ directory, preserving placeholders for figures, LaTeX mathematical expressions, and Mermaid diagrams.

python skills/patent-oa/tools/ingest_case.py \
    --case-id U123 \
    --src /path/to/U123.pdf \
    --out-dir oa/drafts

# Creates oa/drafts/U123.md with structured placeholders

The output draft serves as the central artifact that subsequent stages modify in place, ensuring traceability from source PDF to final application.


Stage 2: Figure Rendering from Plan Files

Technical figures are generated according to a declarative plan stored in *.yaml or *.json files. The render_plan function in skills/patent-application/tools/render_invention_figures.py orchestrates this stage.

The plan describes every required figure—block diagrams for system architectures, flowcharts for method claims, or invention-figure sheets for design patents. Based on figure type, render_plan dispatches to:

  • render_block_diagram – Produces SVG block diagrams for apparatus claims
  • render_flowchart – Generates SVG flowcharts for method claims

The svg_to_png function (using Playwright) then converts each SVG to a tightly-cropped PNG, ensuring consistent image dimensions for Word document insertion.

python skills/patent-application/tools/render_invention_figures.py \
    --plan figures/invention_figures.yaml \
    --out-dir figures

# Outputs 图1.svg / 图1.png, 图2.svg / 图2.png, etc.

This plan-driven approach makes patent-disclosure-skill highly extensible: adding new figure types requires only extending the JSON/YAML schema and implementing a corresponding renderer.


Stage 3: Post-Processing and Word Document Export

The final stage sanitizes the draft Markdown and converts it to a Word (.docx) application through four specialized tools in skills/patent-disclosure/tools/:

LaTeX Delimiter Normalization

latex_delimiters.py scans the draft for mathematical expressions and enforces \(...\) delimiter wrapping. This prevents formula corruption during Word conversion by rejecting improperly marked LaTeX and forcing a re-run until all math is correctly formatted.

python skills/patent-disclosure/tools/latex_delimiters.py \
    -i oa/drafts/U123.md \
    -o oa/drafts/U123_clean.md

Math Rendering as PNG Images

math_render.py replaces inline LaTeX expressions with PNG images rendered to the math_figures/ directory. This ensures formulas appear correctly in the final Word document without relying on client-side LaTeX installation or OMML fallback rendering.

python skills/patent-disclosure/tools/math_render.py \
    -i oa/drafts/U123_clean.md \
    -o oa/drafts/U123_math.md \
    --assets-dir math_figures

Mermaid Diagram Expansion

mermaid_render.py processes any Mermaid diagram blocks in the draft, converting them to SVG/PNG assets and updating the Markdown references accordingly.

Final Word Generation

emit_application_docx.py calls the bundled md_to_docx library to produce the complete patent application package:

python skills/patent-application/tools/emit_application_docx.py \
    --dir oa/drafts

# Produces: 权利要求书.docx, 说明书.docx, 说明书摘要.docx, 说明书附图.docx

Complete Workflow Architecture

The three stages connect through file-based artifacts, enabling inspection at any point:

  • Input: Source PDF + figure plan (YAML/JSON)
  • Intermediate: Draft Markdown with placeholders
  • Assets: SVG/PNG figures + PNG math images
  • Output: Structured Word documents ready for patent office filing

This separation of concerns—each step as a pure function reading and writing files—makes the pipeline robust and debuggable. Failed stages can be re-run independently without restarting the entire workflow.


Key Implementation Files

File Function Purpose
skills/patent-oa/tools/ingest_case.py build_draft_from_pdfs Parse source PDF and generate initial draft.md
skills/patent-application/tools/render_invention_figures.py render_plan, render_block_diagram, render_flowchart, svg_to_png Generate figures from plan specifications
skills/patent-disclosure/tools/latex_delimiters.py — Normalize LaTeX delimiters to \(...\) format
skills/patent-disclosure/tools/math_render.py — Convert LaTeX to PNG images for Word compatibility
skills/patent-disclosure/tools/mermaid_render.py — Render Mermaid diagrams to SVG/PNG
skills/patent-application/tools/emit_application_docx.py convert_md_to_docx Export final Markdown sections to Word documents

Summary

  • Ingestion: build_draft_from_pdfs in ingest_case.py extracts patent content from PDFs into structured Markdown.
  • Figure rendering: render_plan and associated functions in render_invention_figures.py produce SVG/PNG assets from YAML/JSON plans.
  • Sanitization: latex_delimiters.py, math_render.py, and mermaid_render.py ensure mathematical and diagrammatic content converts reliably to Word.
  • Export: emit_application_docx.py generates filing-ready .docx files for all patent document sections.
  • Extensibility: The plan-driven architecture supports invention patents, utility models, and design patents through configuration rather than code changes.

Frequently Asked Questions

What patent types does patent-disclosure-skill support?

Invention patents (发明专利), utility models (实用新型), and design patents (外观设计). The tool handles all three through the same pipeline, with differences captured in the figure plan YAML/JSON files rather than code modifications.

Why does the tool convert LaTeX to PNG images instead of using Word's native equation support?

math_render.py renders LaTeX as PNG images to eliminate dependency on client-side LaTeX installations and avoid OMML (Office Math Markup Language) fallback issues. This guarantees consistent formula appearance across all Word versions and operating systems.

Can I customize figure generation for specialized technical domains?

Yes. The plan-based architecture in render_invention_figures.py allows extension by adding new figure types to the YAML/JSON schema and implementing corresponding renderer functions alongside render_block_diagram and render_flowchart.

How does the pipeline handle errors in LaTeX formatting?

latex_delimiters.py acts as a gate: it scans the draft for delimiters not in \(...\) form and forces re-processing until all mathematical expressions are properly wrapped. This prevents silent corruption of formulas in the final Word document.

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 →