omtex
aien-dev/omtex
Brought by drakestapleton
| 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: <reason> 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/<label>.om`, |
| 87 | runs `OMC` on it (fork, `dupfd`, `execprog`, `waitpid`, all Omega host words) and prints |
| 88 | `LISTING <label> want=W got=G PASS|FAIL`, then `LISTINGS pass=P fail=F fragments=R`. Any FAIL |
| 89 | exits 113. |
| 90 | |
| 91 | ## Order and structure checks |
| 92 | |
| 93 | Preamble words after `begindoc`, body words before it, unclosed lists/tables/emphasis/quotes at |
| 94 | `enddoc`, a second `enddoc`, and output over 4 MiB are refused. Output depends only on the |
| 95 | source: no clock, environment or randomness is read, so the same source gives identical bytes. |
| 96 | `tools/build.sh` exports `SOURCE_DATE_EPOCH` (default: the paper's last git commit time, else 0) |
| 97 | and `FORCE_SOURCE_DATE=1`, so pdfTeX's dates and IDs are fixed too and the PDF is byte-identical |
| 98 | across builds (`tests/run.sh` checks both). |
| 99 | |
| 100 | ## Zenodo |
| 101 | |
| 102 | `tools/zenodo-draft.sh` creates a new draft or a new-version draft and uploads the PDF. It checks |
| 103 | the upload md5 against Zenodo's checksum, then re-reads the deposition and fails unless it is still |
| 104 | unsubmitted. Every request goes through one function that refuses any URL containing `publish`. |
| 105 | Publishing stays a human action in the Zenodo web UI. |
| 106 | |
| 107 | ## Host dependencies |
| 108 | |
| 109 | pdflatex (TeX Live) renders and is the only consumer of the output; `sh`, `curl`, `jq`, `sha256sum`, |
| 110 | `cmp`, `pdftotext` run the build, tests and the Zenodo draft script. See `DEPENDENCIES.md`. |