# sakuramathcraft/latexsnipper architecture

> Architecture diagram of the GitHub repository sakuramathcraft/latexsnipper, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sakuramathcraft/latexsnipper
- Repository: https://github.com/sakuramathcraft/latexsnipper

## Overview

LaTeXSnipper is a desktop formula-recognition and editing application, with a companion Microsoft Office plugin and an Automation API. Its primary workflow takes a capture, image, PDF page, or handwriting input through recognition into a reviewable result, then supports editing, preview, copying, and export. The graph also preserves model selection, external-model documents, Office insertion/editing, and API access. Edges use README-documented workflows or the shown source-index references and excerpts; unsampled implementation details are not assumed.

Main entry points: [`office_plugin/hosts/WordAddIn/WordPluginController.cs`](https://github.com/sakuramathcraft/latexsnipper/blob/main/office_plugin/hosts/WordAddIn/WordPluginController.cs) (Word plugin), [`src/recognition/workers.py`](https://github.com/sakuramathcraft/latexsnipper/blob/main/src/recognition/workers.py) (Recognition workers), [`src/recognition/jobs/coordinator.py`](https://github.com/sakuramathcraft/latexsnipper/blob/main/src/recognition/jobs/coordinator.py) (Recognition jobs), [`src/recognition/image_input.py`](https://github.com/sakuramathcraft/latexsnipper/blob/main/src/recognition/image_input.py) (Image input)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop experience"]
  node_main["App startup<br/>[main.py]"]
  node_capture["Screen capture"]
  node_result["Result review"]
end

subgraph group_recognition["Recognition"]
  node_imageinput["Image input<br/>[image_input.py]"]
  node_pdf["PDF preview<br/>[window.py]"]
  node_handwriting["Handwriting input"]
  node_jobs["Recognition jobs<br/>[coordinator.py]"]
  node_workers["Recognition workers<br/>[workers.py]"]
end

subgraph group_formula["Formula workspace"]
  node_editor["Formula editor"]
  node_preview["Live preview"]
  node_mathpreview["Math preview<br/>[math_preview.py]"]
  node_latexrender["LaTeX rendering<br/>[latex.py]"]
  node_export["Formula export<br/>[formula_export.py]"]
  node_documentexport["Document export<br/>[pandoc_exporter.py]"]
end

subgraph group_models["Model runtimes"]
  node_localmodel["MathCraft OCR<br/>[model.py]"]
  node_externalmodel["External model"]
end

subgraph group_integrations["Integrations"]
  node_automation["Automation API<br/>[server.py]"]
  node_officeword["Word plugin"]
  node_officepowerpoint["PowerPoint plugin"]
  node_officeclient["Office API client"]
  node_olepipeline["OLE rendering"]
  node_formulametadata["Formula metadata<br/>[FormulaMetadata.cs]"]
  node_formulaidentity["Formula identity<br/>[FormulaIdentity.cs]"]
  node_wordsettings["Word settings"]
  node_wordtext["Word messages<br/>[WordAddInText.cs]"]
end

node_user(("User"))
node_externalclient(("Script or tool"))
node_officeuser(("Office user"))

node_user -->|"captures screen"| node_capture
node_user -->|"opens image"| node_imageinput
node_user -->|"selects pages"| node_pdf
node_user -->|"writes formula"| node_handwriting
node_main -->|"starts app"| node_capture
node_capture -.->|"supplies capture"| node_imageinput
node_imageinput -.->|"submits input"| node_jobs
node_pdf -.->|"requests recognition"| node_jobs
node_handwriting -.->|"requests recognition"| node_jobs
node_jobs -->|"dispatches jobs"| node_workers
node_workers -->|"loads images"| node_imageinput
node_workers -.->|"runs OCR"| node_localmodel
node_workers -.->|"uses configured model"| node_externalmodel
node_workers -.->|"publishes results"| node_result
node_result -.->|"opens for editing"| node_editor
node_editor -.->|"updates preview"| node_preview
node_preview -->|"builds preview"| node_mathpreview
node_preview -->|"renders formulas"| node_latexrender
node_result -->|"exports formula"| node_export
node_export -.->|"exports documents"| node_documentexport
node_externalclient -->|"submits recognition"| node_automation
node_automation -->|"coordinates jobs"| node_jobs
node_officeuser -->|"edits in Word"| node_officeword
node_officeuser -->|"inserts formulas"| node_officepowerpoint
node_officeword -->|"requests OCR"| node_officeclient
node_officepowerpoint -->|"requests OCR"| node_officeclient
node_officeclient -->|"calls API"| node_automation
node_officeword -->|"renders OLE"| node_olepipeline
node_officepowerpoint -->|"renders OLE"| node_olepipeline
node_olepipeline -->|"uses request metadata"| node_formulametadata
node_officeword -->|"updates formula metadata"| node_formulametadata
node_formulametadata -->|"carries identity"| node_formulaidentity
node_officeword -->|"reads settings"| node_wordsettings
node_officeword -->|"shows status text"| node_wordtext

click node_main "https://github.com/sakuramathcraft/latexsnipper/blob/main/src/main.py"
click node_capture "https://github.com/sakuramathcraft/latexsnipper/blob/main/src/capture/capture_controller.py"
click node_imageinput "https://github.com/sakuramathcraft/latexsnipper/blob/main/src/recognition/image_input.py"
click node_pdf "https://github.com/sakuramathcraft/latexsnipper/blob/main/src/preview/document/window.py"
click node_handwriting "https://github.com/sakuramathcraft/latexsnipper/blob/main/src/handwriting/handwriting_window.py"
click node_jobs "https://github.com/sakuramathcraft/latexsnipper/blob/main/src/recognition/jobs/coordinator.py"
click node_workers "https://github.com/sakuramathcraft/latexsnipper/blob/main/src/recognition/workers.py"
click node_result "https://github.com/sakuramathcraft/latexsnipper/blob/main/src/ui/predict_result_controller.py"
click node_localmodel "https://github.com/sakuramathcraft/latexsnipper/blob/main/src/backend/mathcraft/model.py"
click node_externalmodel "https://github.com/sakuramathcraft/latexsnipper/blob/main/src/backend/external_model/document_pipeline.py"
click node_editor "https://github.com/sakuramathcraft/latexsnipper/blob/main/src/editor/workbench_window.py"
click node_preview "https://github.com/sakuramathcraft/latexsnipper/blob/main/src/preview/preview_controller.py"
click node_mathpreview "https://github.com/sakuramathcraft/latexsnipper/blob/main/src/preview/math_preview.py"
click node_latexrender "https://github.com/sakuramathcraft/latexsnipper/blob/main/src/rendering/latex.py"
click node_export "https://github.com/sakuramathcraft/latexsnipper/blob/main/src/exporting/formula_export.py"
click node_documentexport "https://github.com/sakuramathcraft/latexsnipper/blob/main/src/exporting/pandoc_exporter.py"
click node_automation "https://github.com/sakuramathcraft/latexsnipper/blob/main/src/integration/automation/server.py"
click node_officeword "https://github.com/sakuramathcraft/latexsnipper/blob/main/office_plugin/hosts/WordAddIn/WordPluginController.cs"
click node_officepowerpoint "https://github.com/sakuramathcraft/latexsnipper/blob/main/office_plugin/hosts/PowerPointAddIn/PowerPointPluginController.cs"
click node_officeclient "https://github.com/sakuramathcraft/latexsnipper/blob/main/office_plugin/src/LaTeXSnipper.OfficePlugin.Automation/AutomationApiClient.cs"
click node_olepipeline "https://github.com/sakuramathcraft/latexsnipper/blob/main/office_plugin/src/LaTeXSnipper.OfficePlugin.Rendering/OlePresentationPipeline.cs"
click node_formulametadata "https://github.com/sakuramathcraft/latexsnipper/blob/main/office_plugin/src/LaTeXSnipper.OfficePlugin.Abstractions/FormulaMetadata.cs"
click node_formulaidentity "https://github.com/sakuramathcraft/latexsnipper/blob/main/office_plugin/src/LaTeXSnipper.OfficePlugin.Abstractions/FormulaIdentity.cs"
click node_wordsettings "https://github.com/sakuramathcraft/latexsnipper/blob/main/office_plugin/hosts/WordAddIn/WordPluginSettings.cs"
click node_wordtext "https://github.com/sakuramathcraft/latexsnipper/blob/main/office_plugin/hosts/WordAddIn/WordAddInText.cs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_capture,node_result,node_user,node_officeuser toneBlue
class node_imageinput,node_pdf,node_handwriting,node_jobs,node_workers toneAmber
class node_editor,node_preview,node_mathpreview,node_latexrender,node_export,node_documentexport toneMint
class node_localmodel,node_externalmodel toneRose
class node_automation,node_officeword,node_officepowerpoint,node_officeclient,node_olepipeline,node_formulametadata,node_formulaidentity,node_wordsettings,node_wordtext,node_externalclient toneIndigo
```

## Components

### Desktop experience

- [App startup](https://github.com/sakuramathcraft/latexsnipper/blob/main/src/main.py): `src/main.py`
- [Screen capture](https://github.com/sakuramathcraft/latexsnipper/blob/main/src/capture/capture_controller.py): `src/capture/capture_controller.py`
- [Result review](https://github.com/sakuramathcraft/latexsnipper/blob/main/src/ui/predict_result_controller.py): `src/ui/predict_result_controller.py`

### Recognition

- [Image input](https://github.com/sakuramathcraft/latexsnipper/blob/main/src/recognition/image_input.py): `src/recognition/image_input.py`
- [PDF preview](https://github.com/sakuramathcraft/latexsnipper/blob/main/src/preview/document/window.py): `src/preview/document/window.py`
- [Handwriting input](https://github.com/sakuramathcraft/latexsnipper/blob/main/src/handwriting/handwriting_window.py): `src/handwriting/handwriting_window.py`
- [Recognition jobs](https://github.com/sakuramathcraft/latexsnipper/blob/main/src/recognition/jobs/coordinator.py): `src/recognition/jobs/coordinator.py`
- [Recognition workers](https://github.com/sakuramathcraft/latexsnipper/blob/main/src/recognition/workers.py): `src/recognition/workers.py`

### Formula workspace

- [Formula editor](https://github.com/sakuramathcraft/latexsnipper/blob/main/src/editor/workbench_window.py): `src/editor/workbench_window.py`
- [Live preview](https://github.com/sakuramathcraft/latexsnipper/blob/main/src/preview/preview_controller.py): `src/preview/preview_controller.py`
- [Math preview](https://github.com/sakuramathcraft/latexsnipper/blob/main/src/preview/math_preview.py): `src/preview/math_preview.py`
- [LaTeX rendering](https://github.com/sakuramathcraft/latexsnipper/blob/main/src/rendering/latex.py): `src/rendering/latex.py`
- [Formula export](https://github.com/sakuramathcraft/latexsnipper/blob/main/src/exporting/formula_export.py): `src/exporting/formula_export.py`
- [Document export](https://github.com/sakuramathcraft/latexsnipper/blob/main/src/exporting/pandoc_exporter.py): `src/exporting/pandoc_exporter.py`

### Model runtimes

- [MathCraft OCR](https://github.com/sakuramathcraft/latexsnipper/blob/main/src/backend/mathcraft/model.py): `src/backend/mathcraft/model.py`
- [External model](https://github.com/sakuramathcraft/latexsnipper/blob/main/src/backend/external_model/document_pipeline.py): `src/backend/external_model/document_pipeline.py`

### Integrations

- [Automation API](https://github.com/sakuramathcraft/latexsnipper/blob/main/src/integration/automation/server.py): `src/integration/automation/server.py`
- [Word plugin](https://github.com/sakuramathcraft/latexsnipper/blob/main/office_plugin/hosts/WordAddIn/WordPluginController.cs): `office_plugin/hosts/WordAddIn/WordPluginController.cs`
- [PowerPoint plugin](https://github.com/sakuramathcraft/latexsnipper/blob/main/office_plugin/hosts/PowerPointAddIn/PowerPointPluginController.cs): `office_plugin/hosts/PowerPointAddIn/PowerPointPluginController.cs`
- [Office API client](https://github.com/sakuramathcraft/latexsnipper/blob/main/office_plugin/src/LaTeXSnipper.OfficePlugin.Automation/AutomationApiClient.cs): `office_plugin/src/LaTeXSnipper.OfficePlugin.Automation/AutomationApiClient.cs`
- [OLE rendering](https://github.com/sakuramathcraft/latexsnipper/blob/main/office_plugin/src/LaTeXSnipper.OfficePlugin.Rendering/OlePresentationPipeline.cs): `office_plugin/src/LaTeXSnipper.OfficePlugin.Rendering/OlePresentationPipeline.cs`
- [Formula metadata](https://github.com/sakuramathcraft/latexsnipper/blob/main/office_plugin/src/LaTeXSnipper.OfficePlugin.Abstractions/FormulaMetadata.cs): `office_plugin/src/LaTeXSnipper.OfficePlugin.Abstractions/FormulaMetadata.cs`
- [Formula identity](https://github.com/sakuramathcraft/latexsnipper/blob/main/office_plugin/src/LaTeXSnipper.OfficePlugin.Abstractions/FormulaIdentity.cs): `office_plugin/src/LaTeXSnipper.OfficePlugin.Abstractions/FormulaIdentity.cs`
- [Word settings](https://github.com/sakuramathcraft/latexsnipper/blob/main/office_plugin/hosts/WordAddIn/WordPluginSettings.cs): `office_plugin/hosts/WordAddIn/WordPluginSettings.cs`
- [Word messages](https://github.com/sakuramathcraft/latexsnipper/blob/main/office_plugin/hosts/WordAddIn/WordAddInText.cs): `office_plugin/hosts/WordAddIn/WordAddInText.cs`

### Other components

- **User**
- **Script or tool**
- **Office user**

## Connections

- User → Screen capture: captures screen
- User → Image input: opens image
- User → PDF preview: selects pages
- User → Handwriting input: writes formula
- App startup → Screen capture: starts app (evidence: `src/main.py`)
- Screen capture → Image input: supplies capture
- Image input → Recognition jobs: submits input
- PDF preview → Recognition jobs: requests recognition
- Handwriting input → Recognition jobs: requests recognition
- Recognition jobs → Recognition workers: dispatches jobs (evidence: `src/recognition/workers.py`)
- Recognition workers → Image input: loads images (evidence: `src/recognition/workers.py`)
- Recognition workers → MathCraft OCR: runs OCR
- Recognition workers → External model: uses configured model
- Recognition workers → Result review: publishes results
- Result review → Formula editor: opens for editing
- Formula editor → Live preview: updates preview
- Live preview → Math preview: builds preview (evidence: `src/preview/preview_controller.py`)
- Live preview → LaTeX rendering: renders formulas (evidence: `src/preview/preview_controller.py`)
- Result review → Formula export: exports formula (evidence: `src/ui/predict_result_controller.py`)
- Formula export → Document export: exports documents
- Script or tool → Automation API: submits recognition
- Automation API → Recognition jobs: coordinates jobs (evidence: `src/integration/automation/server.py`)
- Office user → Word plugin: edits in Word
- Office user → PowerPoint plugin: inserts formulas
- Word plugin → Office API client: requests OCR (evidence: `office_plugin/hosts/WordAddIn/WordPluginController.cs`)
- PowerPoint plugin → Office API client: requests OCR (evidence: `office_plugin/hosts/PowerPointAddIn/PowerPointPluginController.cs`)
- Office API client → Automation API: calls API (evidence: `office_plugin/src/LaTeXSnipper.OfficePlugin.Automation/AutomationApiClient.cs`)
- Word plugin → OLE rendering: renders OLE (evidence: `office_plugin/hosts/WordAddIn/WordPluginController.cs`)
- PowerPoint plugin → OLE rendering: renders OLE (evidence: `office_plugin/hosts/PowerPointAddIn/PowerPointPluginController.cs`)
- OLE rendering → Formula metadata: uses request metadata (evidence: `office_plugin/src/LaTeXSnipper.OfficePlugin.Rendering/OlePresentationPipeline.cs`)
- Word plugin → Formula metadata: updates formula metadata (evidence: `office_plugin/hosts/WordAddIn/WordPluginController.cs`)
- Formula metadata → Formula identity: carries identity (evidence: `office_plugin/src/LaTeXSnipper.OfficePlugin.Abstractions/FormulaMetadata.cs`)
- Word plugin → Word settings: reads settings (evidence: `office_plugin/hosts/WordAddIn/WordPluginController.cs`)
- Word plugin → Word messages: shows status text (evidence: `office_plugin/hosts/WordAddIn/WordPluginController.cs`)
