Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omtex/blob/main/docs/DESIGN.md # omtex aien-dev/omtex Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omtex / docs / DESIGN.md` 110 lines ยท 6211 bytes Raw Blame History Rendered 1 # omtex design 2 3 Status: IMPLEMENTED and EXERCISED on a Linux AArch64 host (see `evidence/`). Not a compiler target. 4 5 ## Goal 6 7 Author a paper as an Omega program and get LaTeX (and, through pdflatex, a PDF) whose every byte 8 was emitted by checked Omega code. Escaping and math are where hand-written LaTeX goes wrong, so 9 the library refuses input it cannot render safely instead of passing it through. 10 11 ## Shape: a library, not a compiler target 12 13 A paper is an Omega unit. `lib/omtex.om` (an OM-2 unit) is concatenated in front of the paper 14 body, because Omega has no imports yet (FR-3: units concatenate). The pinned seeded compiler 15 builds that unit into a generator; running the generator writes the `.tex` file on stdout. 16 17 ``` 18 cat lib/omtex.om paper.om | omc > paper.gen # Omega -> AArch64 program 19 ./paper.gen > paper.tex # program -> LaTeX 20 pdflatex paper.tex # host renderer (recorded dependency) 21 ``` 22 23 The library depends on one OM-2 feature: unsized views (`t view uchar *`, OMEGESE 9.13). A 24 `text` literal of any length can be passed to a library word, so the document reads as a list of 25 calls such as `section s1` and `para p1`. The output buffer is a global the library names 26 directly (globals are never passed, error 19). 27 28 Why not `target latex` in omc: LaTeX is a document format, not an instruction set. Putting it in 29 the compiler would add a second lowering with no use for types, registers or traps, enlarge the 30 compiler's trusted surface, and couple paper releases to the compiler's serial merge queue. A 31 library keeps the compiler unchanged and the escaping rules in ordinary, testable Omega. What a 32 compiler change would buy is imports (FR-3), so a paper could name the library instead of being 33 concatenated with it; that is already an open request, not something to add for this. 34 35 ## Prose markup (the only way text reaches LaTeX) 36 37 Every prose word (`title`, `author`, `date`, `abstract`, `para`, `section`, `item`, `cell`, 38 captions, bibliography entries) scans its bytes once: 39 40 | Source | LaTeX | Rule | 41 |---|---|---| 42 | `# $ % & _ { }` | `\#` ... `\}` | always escaped | 43 | `^ < > \|` | `\textasciicircum{}` ... | always escaped | 44 | `~` | `~` | a tie (non-breaking space), as in LaTeX: `Lemma~2` | 45 | `[` `]` | `{[}` `{]}` | so an `\item` never takes a prose `[` as its option | 46 | `"` ... `"` | ` `` ` ... `''` | must pair inside the element | 47 | `*x*` / `**x**` | `\emph{x}` / `\textbf{x}` | must nest and close inside the element | 48 | `` `x` `` | `\texttt{x}` | contents escaped as code | 49 | `$m$` | `$m$` | `m` passes the math check | 50 | `[@k]` / `[#k]` | `~\cite{k}` / `~\ref{k}` | key characters `A-Za-z0-9:._-+/,` | 51 | `\c` (the Omega text `\\c`) | literal `c` | only for `` \ * ` $ [ ] " ~ ``; any other backslash is refused | 52 | tab, LF | space | | 53 | other control bytes, malformed UTF-8 | refused | | 54 55 A refusal writes `omtex: refused element N: at byte B` to stderr and traps 11 56 (exit 111). There is no silent fallback and no raw prose path. 57 58 Inline math ends at the first `$` that is not part of a backslash pair, so `$\$5$` is one span. 59 60 ## Paragraphs and displays 61 62 `para t` writes `t` and ends the paragraph; `paran t` does the same with `\noindent`. `prose t` 63 writes `t` without ending the paragraph, so it can lead into a display. `equation`, `displaymath` 64 and `align` do not end the paragraph either: text after `\end{equation}` continues it, exactly as 65 in hand-written LaTeX. `parbreak` ends a paragraph explicitly. This matters for indentation: the 66 Turing brief reproduction showed that ending the paragraph after a display indents the next line. 67 68 ## Math check 69 70 Math (`$m$`, `equation`, `displaymath`, `align`) is passed through only when: every byte is 71 printable ASCII; `{` `}` balance (escaped `\{ \}` excluded); `% $ #` do not appear; `&` and `\\` 72 appear only in `align`; and no control sequence from the deny list (`\input \include \write \def 73 \edef \gdef \xdef \let \catcode \immediate \openout \openin \csname \special \read`) is used. 74 `rawtex` and `preamble` lines use the same check with `&` and `\\` allowed. 75 76 ## Listings 77 78 `listing` (any language), `omlisting` (Omega, must compile with rc 0), `omrefused` (Omega, must 79 be refused with a stated rc) and `omfragment` (Omega, shown, explicitly not compiled). Bodies are 80 verbatim inside `lstlisting`; a body containing `\end{lstlisting}`, a non-ASCII byte or a control 81 byte other than LF/tab is refused. `omlang` emits `\lstdefinelanguage{Omega}` whose keyword 82 groups are the pin's keyword table (`seed/omc/genkw.awk`) plus the OM-2 words; `tests/run.sh` 83 compares them. Keyword groups are coloured (blue, teal, violet, orange) and comments are grey 84 italic, because the `cmtt` typewriter font has no bold, so bold keywords would not show. 85 86 Running the generator as `paper.gen check OMC DIR` writes each Omega listing to `DIR/