[{"data":1,"prerenderedAt":4},["ShallowReactive",2],{"GVTJ2SBx0V":3},"# imprimatur\n\n*Imprimatur* (\"let it be printed\") keeps the LaTeX of a paper in step with a\nLean 4 development.\n\n- **Generated content.** Authors mark places in ordinary `.tex` files where a\n  Lean declaration should appear: a theorem statement, a definition, a set of\n  inference rules or a grammar. imprimatur renders that content from the\n  compiled Lean environment, in the paper's own notation, and splices it in\n  place.\n- **Checked prose.** Hand-written theorem prose can be tied to the Lean\n  results it describes. The build then fails if a result disappears, depends\n  on `sorry` or a disallowed axiom, or changes its statement after an author\n  last checked the prose against it.\n- **Faithful notation.** Every formula imprimatur typesets is read back, in\n  the grammar of the paper's notation, and must mean the Lean statement it\n  came from: one reading, and the right one.\n\nThe `.tex` files stay ordinary LaTeX, so they compile on Overleaf and arXiv\nwith no preprocessor. The host Lean project doesn't need to change.\n\n## Try it in two minutes\n\nYou need [elan](https://github.com/leanprover/elan) (`curl -sSfL\nhttps://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh | sh`)\nand, for the PDF, a TeX distribution with `latexmk` (Debian and Ubuntu:\n`apt install texlive-latex-extra texlive-science latexmk`). The commands\nbelow build imprimatur, then a short paper on a typed λ-calculus from the\nLean development that proves its theorems:\n\n```sh\ngit clone --depth 1 https://github.com/theorem-press/imprimatur.git\ncd imprimatur/splice && lake build && export PATH=\"$PWD/.lake/build/bin:$PATH\"\ncd ../examples/semantics\n(cd host && lake build)\nimprimatur build --profile public --commit \"$(git rev-parse HEAD)\"\nimprimatur check\ngit --no-pager diff paper.tex\nlatexmk -pdf paper.tex\n```\n\nLine by line: build the splicer and put it on the path; build the Lean\ndevelopment, as its owners would; `imprimatur build` renders the grammar,\nrules and theorems into `paper.tex`, building an extractor for the host's\nLean the first time, and under the `public` profile at the commit you cloned\nit also links every theorem, example, checked sentence and row of the index\nof notation to its Lean on GitHub\n([docs/blocks.md](docs/blocks.md#source-links)); `imprimatur check` reports\nnothing stale, untrusted or unfaithful; the diff is the TeX imprimatur\nwrote, since the committed `paper.tex` has empty blocks and the hand-written\nprose around them is untouched; and `latexmk` typesets `paper.pdf`, which\n`open paper.pdf` shows on macOS and `xdg-open paper.pdf` on Linux. The\nresult is the\n[PDF](https://theorem-press.github.io/imprimatur/examples/semantics/paper.pdf)\nthe site builds from these commands.\n[expected/paper.tex](examples/semantics/expected/paper.tex) is the same\npaper built for submission, by `imprimatur build` with no profile, which\nleaves the links out, and with the hashes on its five `\\leancheck`\nsentences that `imprimatur accept --all` records once an author has read\neach sentence against the Lean result it names\n([docs/trust.md](docs/trust.md#tying-prose-to-lean-leancheck-and-accept)).\nClone to PDF took about a minute on one machine; the first run also\ndownloads Lean v4.35.0.\n\n## What it looks like\n\nIn Lean, from [examples/semantics](examples/semantics/README.md):\n\n```lean\ntheorem preservation {e e' : Tm} (hs : Step e e') :\n    ∀ {Γ : Ctx} {t : Ty}, HasType Γ e t → HasType Γ e' t\n```\n\nIn the paper, the author writes an empty block that names the theorem:\n\n```latex\n\\begin{leantheorem}{Stlc.preservation}{Preservation}\n\\end{leantheorem}\n```\n\nThe first argument is the **key**, the Lean name of the declaration to show;\nthe second is the theorem's title. `leantheorem` is an environment the\npaper's `imprimatur.toml` declares, as a sentence (the `prose` view) wrapped\nin `theorem`:\n\n```toml\n[aliases]\nleantheorem = { view = \"prose\", wrap = \"theorem\", label = \"thm:{key}\" }\n```\n\n`imprimatur build` looks up `Stlc.preservation`, renders it with the\nnotation the paper declares for `Step`, `HasType` and the rest, and fills in\nthe block:\n\n```latex\n\\begin{leantheorem}[sum=jU5x8J0Hfl]{Stlc.preservation}{Preservation}\n\\label{thm:Stlc.preservation}\n\\LeanProse{Let $e, e' \\in \\mathit{Term}$, $\\Gamma \\in \\mathit{Context}$ and\n$\\tau \\in \\mathit{Type}$. Assume $e \\longrightarrow e'$ and\n$\\Gamma \\vdash e : \\tau$. Then $\\Gamma \\vdash e' : \\tau$.}\n\\end{leantheorem}\n```\n\nwhich typesets as a theorem: *Let e, e′ ∈ Term, Γ ∈ Context and τ ∈ Type.\nAssume e ⟶ e′ and Γ ⊢ e : τ. Then Γ ⊢ e′ : τ.* The `sum=` checksum records\nwhat was generated. If the Lean theorem changes, `imprimatur check` reports\nthe block as stale; if someone edits it by hand, as edited; if the theorem\ncomes to depend on `sorry`, as untrusted.\n\nA key can also be a title the paper uses, mapped to the Lean name in the\nnotation module (`latex_entry \"Preservation\" => Stlc.preservation`), as\n[examples/semantics](examples/semantics/paper.tex) does.\n\n### What the block rests on\n\nBetween the Lean development and the paper there is one file, the *bundle*,\nwhich `imprimatur build` writes and the splicer reads. Its entry for the\ntheorem above is, abridged:\n\n```json\n\"Stlc.preservation\": {\n  \"kind\": \"theorem\",\n  \"stmtHash\": \"a89b1dbd…\",\n  \"sigHash\":  \"dd711a64…\",\n  \"views\": { \"prose\": \"\\\\LeanProse{Let $e, e' \\\\in \\\\mathit{Term}$ …}\", \"math\": \"…\" },\n  \"sorry\": false, \"axioms\": [], \"cone\": { \"size\": 16, \"untrusted\": [] }\n}\n```\n\nIt says nothing about the *proof* of preservation, and cannot: the splicer\nnever sees Lean. It carries two images of the *statement*, a hash that\nnames its meaning and TeX that shows it, and a verdict on the proof. That\nis the whole interface, and it is a Lean type, `Bundle (Image TeX) Verdict`\nin [bundle/Bundle.lean](bundle/Bundle.lean), of which the file is the JSON.\n\nThe type comes with its meaning. A bundle is *true* of a development when\nevery claim it makes holds of the statement it is about: the hash is that\nstatement's, each view is that statement rendered, and a view with no\nrecorded problems reads back as it. A bundle may say less than Lean knows,\na view it could not render, a hash it could not compute, never something\nfalse; where it is silent, `check` reports the silence.\n\nThat is enough for one theorem, proved in Lean for a model of the splicer\n(`splice/SpliceModel`):\n\n> **If `imprimatur check` reports nothing, and the bundle is true, then the\n> paper is true:** every displayed formula is a statement Lean proved,\n> rendered by the paper's notation, and reads back as that statement; and\n> every `\\leancheck` names, by its hash, a statement Lean proved.\n\nThe theorem's hypothesis is the trust boundary, stated once: the extractor\nis honest about the development, and SHA-256 does not collide. Everything\nafter that, generation, hand edits, staleness, slot text, drift, is covered\nby the proof.\n\n## What it does\n\n- **Views:** a declaration as Lean prints it (`lean`), as a formula\n  (`math`, or its defining equations with `def`), as a sentence (`prose`),\n  as inference rules (`rules`), as a BNF grammar (`grammar`), or its source,\n  axioms and `sorry` status (`meta`). Indexes of the paper's metavariables,\n  its notation and its results are views too. See\n  [docs/views.md](docs/views.md).\n- **Notation** is declared in Lean, with `latex_notation`, `latex_category`\n  and `latex_style`, and shared packs for logic, sets, order and common\n  Mathlib notation. See\n  [docs/notation.md](docs/notation.md).\n- **Trust checks:** results that disappear, depend on `sorry` or a\n  disallowed axiom, or whose statement changed since `\\leancheck` recorded\n  it. Comparator manifests and leanblueprint's `\\lean{…}` are read too.\n  With `checker = \"con-leche\"`, the development must also be accepted by\n  the verified checker the Lean toolchain ships, whose acceptance is proved\n  to give it a model. See [docs/trust.md](docs/trust.md).\n- **Translation validation:** each formula is parsed back in the notation's\n  grammar, and one that is ambiguous, cannot be read back, or reads as\n  something other than its statement is reported where it is. The parser is\n  proved sound and complete, so a formula that passes has no reading in the\n  grammar but its statement's (docs/verified-validator.md). With\n  `latex_style categories := strict`, a variable is always written with its\n  type's letter, so a reader can tell its type.\n- **Three modes:** inside the Lean project, as a sidecar package, or\n  external, which leaves the host project untouched. See\n  [docs/blocks.md](docs/blocks.md).\n\n## Using it in your own paper\n\nimprimatur reads a built Lean project in one of three modes\n([docs/blocks.md](docs/blocks.md)): **external**, which reads the project as\nit is, as the example above does, with the notation in a file beside the\npaper; **sidecar**, a Lake package beside the host that requires it; or\n**in-project**, where the host's lakefile requires imprimatur. The\nrepository is the extractor's package at its root, so the last two need no\n`subDir`:\n\n```toml\n[[require]]\nname = \"imprimatur\"\ngit = \"https://github.com/theorem-press/imprimatur\"\nrev = \"main\"   # pin a commit\n```\n\nA paper is a directory with an `imprimatur.toml` naming the main `.tex`\nfile, the Lean project, the modules to import and the notation module. In\nit:\n\n```sh\nimprimatur build\nimprimatur check\nlatexmk -pdf paper.tex\n```\n\n`build` renders and splices the blocks, and `check` reports what is stale,\nuntrusted or unfaithful.\n\nIn external mode the first run builds an extractor for the host's Lean\nversion, once per version, into `~/.cache/imprimatur`;\n`imprimatur toolchain install VERSION` does it ahead of time, and\n`--no-install` fails instead, for CI that must not compile what it did not\nask for. An extractor built from other sources than the running imprimatur,\nby another checkout say, is rebuilt the same way.\n\n[examples/](examples/README.md) has five working papers: one for each mode, the\nlonger one on a λ-calculus built above, and a note on a Mathlib host that\nstates what the Lean archive claiming the Riemann Hypothesis claims.\n\n## Status\n\nUsable now from source: build it from `main`, as in Getting started above.\nIt works on Lean v4.28.0-rc1 to v4.35.0, and builds the papers of two\nprogramming-language projects, whose grammars, rules and results are\ngenerated, and a paper about imprimatur itself (in preparation), whose\ntheorems about the splicer, and about the extractor's layouts, are proved\nin Lean (`splice/SpliceModel`).\n\nThere is no tagged release yet, so pin a commit if you depend on it. The\nfirst release, v0.5.0, adds an index of every result a paper cites,\n`check --anonymous` for double-blind submission and `init`, and lists\nimprimatur on [Reservoir](https://reservoir.lean-lang.org): see the\n[v0.5.0 milestone](https://github.com/theorem-press/imprimatur/milestone/1).\nOther planned work is in the\n[issues](https://github.com/theorem-press/imprimatur/issues).\n\n## More\n\n- [DESIGN.md](DESIGN.md): the architecture (a Lean-side extractor and a\n  text-only splicer, connected by a versioned JSON bundle), the notation\n  language, the trust checks, prior art, and what correctness means (§18).\n- [CHANGELOG.md](CHANGELOG.md): what has changed.\n- [CONTRIBUTING.md](CONTRIBUTING.md) and [docs/TESTING.md](docs/TESTING.md):\n  working on the code.\n\n## License\n\nApache-2.0. See [LICENSE](LICENSE).\n",1795286058584]