# Architecture note — the render path

The second of three documents in this folder.

Rendering happens once and feeds every output, which is why a formula looks the
same in the reading pane, the PDF and the Word file.

```mermaid
flowchart LR
    S[Source] --> P[Parse]
    P --> R[Render]
    R --> V[Reading pane]
    R --> X[PDF / Word / HTML / PNG]
```

## Why parse once

Two rendering paths mean two sets of bugs, and the differences only ever show
up in the output the customer sends to someone else. A single path costs a
little flexibility and buys the guarantee that what you see is what you send.

$$
\text{cost}(n) = O(n) \quad \text{per document, in the number of blocks}
$$

## Invariants

1. No network call is required to render anything.
2. Nothing is written to disk until the file is saved.
3. An unknown file type opens as text rather than failing.
