# arronhc/text2math architecture

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

- Interactive diagram: https://gitdiagram.com/arronhc/text2math
- Repository: https://github.com/arronhc/text2math

## Overview

Text2Math is an Obsidian plugin that converts selected or entered natural-language math descriptions into LaTeX, previews and validates the result, then replaces the selection or inserts at the cursor. The main.ts excerpt shows command/context-menu entry points, API invocation, preview dispatch, and editor commit; API, settings, and cleanup relationships are also supported by excerpts. README capabilities fill in documented mobile use and provider compatibility. The graph omits unsampled internals beyond those documented relationships.

Main entry points: [`src/main.ts`](https://github.com/arronhc/text2math/blob/main/src/main.ts) (Conversion coordinator), [`src/api.ts`](https://github.com/arronhc/text2math/blob/main/src/api.ts) (AI API client), [`src/modals.ts`](https://github.com/arronhc/text2math/blob/main/src/modals.ts) (Formula preview), [`src/settings.ts`](https://github.com/arronhc/text2math/blob/main/src/settings.ts) (Plugin settings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Conversion workflow"]
  node_commands["Commands and menu<br/>[main.ts]"]
  node_conversion["Conversion coordinator<br/>[main.ts]"]
  node_editor["Markdown editor"]
end

subgraph group_presentation["Input and preview"]
  node_input["Description input<br/>[modals.ts]"]
  node_preview["Formula preview<br/>[modals.ts]"]
  node_rendering["Math rendering<br/>[modals.ts]"]
end

subgraph group_services["API and configuration"]
  node_api["AI API client<br/>[api.ts]"]
  node_settings_ui["Settings interface<br/>[settingTab.ts]"]
  node_settings_state["Plugin settings<br/>[settings.ts]"]
end

subgraph group_domain["Formula processing"]
  node_latex_processing["LaTeX processing<br/>[clean.ts]"]
end

node_user(("Obsidian user"))
node_provider["OpenAI-compatible API"]

node_user -->|"invokes"| node_commands
node_commands -->|"reads selection"| node_editor
node_commands -->|"starts flow"| node_conversion
node_commands -->|"opens when empty"| node_input
node_input -->|"submits description"| node_conversion
node_conversion -->|"requests formula"| node_api
node_api -->|"sends request"| node_provider
node_provider -.->|"returns completion"| node_api
node_api -->|"cleans and classifies"| node_latex_processing
node_conversion -->|"applies letter case"| node_latex_processing
node_conversion -->|"opens preview"| node_preview
node_preview -->|"renders formula"| node_rendering
node_preview -->|"confirms or regenerates"| node_conversion
node_conversion -->|"replaces or inserts"| node_editor
node_settings_ui -->|"fetches models or tests"| node_api
node_settings_ui -->|"updates settings"| node_settings_state
node_conversion -->|"reads preferences"| node_settings_state
node_api -->|"reads API options"| node_settings_state

click node_commands "https://github.com/arronhc/text2math/blob/main/src/main.ts"
click node_conversion "https://github.com/arronhc/text2math/blob/main/src/main.ts"
click node_input "https://github.com/arronhc/text2math/blob/main/src/modals.ts"
click node_preview "https://github.com/arronhc/text2math/blob/main/src/modals.ts"
click node_rendering "https://github.com/arronhc/text2math/blob/main/src/modals.ts"
click node_api "https://github.com/arronhc/text2math/blob/main/src/api.ts"
click node_settings_ui "https://github.com/arronhc/text2math/blob/main/src/settingTab.ts"
click node_settings_state "https://github.com/arronhc/text2math/blob/main/src/settings.ts"
click node_latex_processing "https://github.com/arronhc/text2math/blob/main/src/clean.ts"

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_commands,node_conversion,node_editor,node_user toneBlue
class node_input,node_preview,node_rendering toneAmber
class node_api,node_settings_ui,node_settings_state,node_provider toneMint
class node_latex_processing toneRose
```

## Components

### Conversion workflow

- [Commands and menu](https://github.com/arronhc/text2math/blob/main/src/main.ts): `src/main.ts`
- [Conversion coordinator](https://github.com/arronhc/text2math/blob/main/src/main.ts): `src/main.ts`
- **Markdown editor**

### Input and preview

- [Description input](https://github.com/arronhc/text2math/blob/main/src/modals.ts): `src/modals.ts`
- [Formula preview](https://github.com/arronhc/text2math/blob/main/src/modals.ts): `src/modals.ts`
- [Math rendering](https://github.com/arronhc/text2math/blob/main/src/modals.ts): `src/modals.ts`

### API and configuration

- [AI API client](https://github.com/arronhc/text2math/blob/main/src/api.ts): `src/api.ts`
- [Settings interface](https://github.com/arronhc/text2math/blob/main/src/settingTab.ts): `src/settingTab.ts`
- [Plugin settings](https://github.com/arronhc/text2math/blob/main/src/settings.ts): `src/settings.ts`

### Formula processing

- [LaTeX processing](https://github.com/arronhc/text2math/blob/main/src/clean.ts): `src/clean.ts`

### Other components

- **Obsidian user**
- **OpenAI-compatible API**

## Connections

- Obsidian user → Commands and menu: invokes (evidence: `README.md`)
- Commands and menu → Markdown editor: reads selection (evidence: `src/main.ts`)
- Commands and menu → Conversion coordinator: starts flow (evidence: `src/main.ts`)
- Commands and menu → Description input: opens when empty (evidence: `src/main.ts`)
- Description input → Conversion coordinator: submits description (evidence: `src/main.ts`)
- Conversion coordinator → AI API client: requests formula (evidence: `src/main.ts`)
- AI API client → OpenAI-compatible API: sends request (evidence: `src/api.ts`)
- OpenAI-compatible API → AI API client: returns completion
- AI API client → LaTeX processing: cleans and classifies (evidence: `src/api.ts`)
- Conversion coordinator → LaTeX processing: applies letter case (evidence: `src/main.ts`)
- Conversion coordinator → Formula preview: opens preview (evidence: `src/main.ts`)
- Formula preview → Math rendering: renders formula (evidence: `src/modals.ts`)
- Formula preview → Conversion coordinator: confirms or regenerates (evidence: `src/main.ts`)
- Conversion coordinator → Markdown editor: replaces or inserts (evidence: `src/main.ts`)
- Settings interface → AI API client: fetches models or tests (evidence: `src/settingTab.ts`)
- Settings interface → Plugin settings: updates settings (evidence: `src/settingTab.ts`)
- Conversion coordinator → Plugin settings: reads preferences (evidence: `src/main.ts`)
- AI API client → Plugin settings: reads API options (evidence: `src/api.ts`)
