# eras-hallow/mathtex architecture

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

- Interactive diagram: https://gitdiagram.com/eras-hallow/mathtex
- Repository: https://github.com/eras-hallow/mathtex

## Overview

MathTex is a small Luau library that parses a documented subset of LaTeX-inspired math syntax and renders it as native Roblox UI. The user-facing workflow is to call the public API with a parent, source, and options; the documented processing stages are lexing, parsing into an AST, layout, and rendering. Layout uses Roblox text measurement, and the native backend creates UI primitives. The README documents these relationships, but no source excerpts were provided, so internal call ownership and finer-grained data flow are not verified.

Main entry points: [`src/Parser.luau`](https://github.com/eras-hallow/mathtex/blob/main/src/Parser.luau) (Parser), [`src/init.luau`](https://github.com/eras-hallow/mathtex/blob/main/src/init.luau) (Public API), [`src/Lexer.luau`](https://github.com/eras-hallow/mathtex/blob/main/src/Lexer.luau) (Lexer), [`src/AST.luau`](https://github.com/eras-hallow/mathtex/blob/main/src/AST.luau) (Syntax tree)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_parse["Parsing"]
  node_lexer["Lexer<br/>[Lexer.luau]"]
  node_parser["Parser<br/>[Parser.luau]"]
  node_ast["Syntax tree<br/>[AST.luau]"]
  node_symbols["Symbol registry<br/>[Symbols.luau]"]
end

subgraph group_layout["Math Layout"]
  node_layoutmod["Layout engine<br/>[Layout.luau]"]
end

subgraph group_render["Roblox Rendering"]
  node_api["Public API<br/>[init.luau]"]
  node_native["Native backend<br/>[Native.luau]"]
end

node_user(("Library caller"))
node_textservice["Roblox TextService"]
node_gui["Roblox UI parent"]

node_user -->|"calls"| node_api
node_api -->|"starts processing"| node_lexer
node_lexer -->|"tokens to"| node_parser
node_parser -->|"builds"| node_ast
node_ast -->|"laid out by"| node_layoutmod
node_layoutmod -->|"measures text"| node_textservice
node_api -->|"renders with"| node_native
node_native -->|"creates UI in"| node_gui
node_parser -->|"uses commands"| node_symbols

click node_api "https://github.com/eras-hallow/mathtex/blob/main/src/init.luau"
click node_lexer "https://github.com/eras-hallow/mathtex/blob/main/src/Lexer.luau"
click node_parser "https://github.com/eras-hallow/mathtex/blob/main/src/Parser.luau"
click node_ast "https://github.com/eras-hallow/mathtex/blob/main/src/AST.luau"
click node_symbols "https://github.com/eras-hallow/mathtex/blob/main/src/Symbols.luau"
click node_layoutmod "https://github.com/eras-hallow/mathtex/blob/main/src/Layout.luau"
click node_native "https://github.com/eras-hallow/mathtex/blob/main/src/Backends/Native.luau"

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_lexer,node_parser,node_ast,node_symbols,node_gui toneBlue
class node_layoutmod toneAmber
class node_api,node_native toneMint
class node_user,node_textservice toneIndigo
```

## Components

### Parsing

- [Lexer](https://github.com/eras-hallow/mathtex/blob/main/src/Lexer.luau): `src/Lexer.luau`
- [Parser](https://github.com/eras-hallow/mathtex/blob/main/src/Parser.luau): `src/Parser.luau`
- [Syntax tree](https://github.com/eras-hallow/mathtex/blob/main/src/AST.luau): `src/AST.luau`
- [Symbol registry](https://github.com/eras-hallow/mathtex/blob/main/src/Symbols.luau): `src/Symbols.luau`

### Math Layout

- [Layout engine](https://github.com/eras-hallow/mathtex/blob/main/src/Layout.luau): `src/Layout.luau`

### Roblox Rendering

- [Public API](https://github.com/eras-hallow/mathtex/blob/main/src/init.luau): `src/init.luau`
- [Native backend](https://github.com/eras-hallow/mathtex/blob/main/src/Backends/Native.luau): `src/Backends/Native.luau`

### Other components

- **Library caller**
- **Roblox TextService**
- **Roblox UI parent**

## Connections

- Library caller → Public API: calls (evidence: `README.md`)
- Public API → Lexer: starts processing (evidence: `README.md`)
- Lexer → Parser: tokens to (evidence: `README.md`)
- Parser → Syntax tree: builds (evidence: `README.md`)
- Syntax tree → Layout engine: laid out by (evidence: `README.md`)
- Layout engine → Roblox TextService: measures text (evidence: `README.md`)
- Public API → Native backend: renders with (evidence: `README.md`)
- Native backend → Roblox UI parent: creates UI in (evidence: `README.md`)
- Parser → Symbol registry: uses commands (evidence: `README.md`)
