Skip to content

Architecture en

AminiamEva edited this page Nov 29, 2026 · 3 revisions

Architecture (English)

中文 · English

Lineae's editing model is a ProseMirror document tree carried by Tiptap; MathLive handles interactive math input; a standalone LaTeX module handles parsing and serialisation. The .tex source is always the authoritative document, and the TeX engine is the authority on final typesetting. On top of this, the desktop app provides a native workspace rendered by real LuaLaTeX.

Layers

Browser UI / Tauri shell (ribbon, status bar, settings panel)
        |
        v
Work modes: Document / Source / Split
        |
        v
Tiptap / ProseMirror  <---->  MathLive
        |
        v
LaTeX import and export (byte-preserving source)
        |
        +---- recognised syntax -> editable document nodes
        |
        +---- unrecognised syntax -> preserved source blocks
        |
        v
      .tex files / projects

Engine profiles (XeLaTeX / LuaLaTeX / pdfLaTeX)
        |
        +---- web: JS typesetting pipeline (layout + pagination)
        +---- desktop: native LuaLaTeX workspace (rtex rendering + hybrid editing)

BibTeX / BibLaTeX module
        +---- parsing, validation, editing, serialisation, citation checks

Editor

  • src/main.js assembles the editor, ribbon, source view, project sidebar, and display controls.
  • All changes go through ProseMirror transactions, so selection mapping, undo, and redo are unified.
  • Document / Source / Split modes share one document model; Source mode is an explicit edit of the whole document and rebuilds the editable projection when applied.

Engines and pagination

  • latex/typeset-layout.mjs derives font size, baselines, indents, and page capacity from \documentclass and font/spacing declarations, and plans pagination at block and visual-line boundaries. The pdfLaTeX path additionally detects font packages (lmodern, mathpazo, newtxtext, helvet, …) to derive the Computer Modern font stack.
  • src/typesetting/engine-profile.mjs provides a uniform profile interface for the three engines: documentStyle(), paragraph parameters, and CJK precision assessment.
  • src/typesetting/engine-resolution.mjs infers the engine from the source: % !TeX program magic comments, engine primitives (\XeTeX…, \directlua), and characteristic packages (xeCJK, luatexja). Explicit choices win; conflicting evidence falls back to the global default, with conflicts pinned to source locations.
  • src/editor/typeset-pagination.js only generates background sheets and translate styles; it never inserts nodes into the ProseMirror document or writes layout state onto editable nodes.
  • latex/geometry.mjs uses article.cls native page dimensions when no geometry package is present, instead of geometry's default margins.
  • assets/fonts/latin-modern bundles Latin Modern OTF; the pdfLaTeX profile switches to a Computer Modern / CMU stack.

Native TeX workspace (desktop)

  • src/ui/native-tex-preview.mjs and src/editor/native-surface/ implement direct editing of pages rendered by rtex 0.0.8 (bundled distribution): prose, inline and display math, tables.
  • Hybrid editing pipeline (docs/native-tex/hybrid-line-editing.md): ProseMirror owns input, composition, selection, and history for the lifetime of an edit; the native page owns the confirmed glyphs. Obsolete glyphs are masked until that sheet has painted the matching revision, and a late complete page cannot roll back newer paragraph ink.
  • Sessions are hosted by Rust's tex_session.rs (experimental, trusted documents only): the bundled rtex is preferred, otherwise a system TeX Live LuaLaTeX is auto-detected (RTEX_TEXLIVE_BIN, LINEAE_RTEX_PATH override); missing tools are reported and never silently substituted.
  • Content the glyph painter cannot draw (Type 1/TTC fonts, images, TikZ, …) uses a revision-frozen whole-page PDF rendered by the bundled PDF.js 4.10.38; "Export clean PDF" is available only for a confirmed current frame.
  • Unknown or stale geometry never writes a guessed source range; edits apply only to verified source spans.
  • The legacy JS pipeline remains as a fallback and can be restored in settings (after a restart).

Project model

  • src/project/ maintains the project file tree, the \include / \input dependency graph, and main-file resolution.
  • Engine selection resolves per project (project.resolveTypesetting), with conflict diagnostics located in specific files and source positions.
  • Document mode supports continuous cross-file editing, cross-file selection and replacement, and project-wide outline jumps.

LaTeX codec

  • src/editor/latex-codec.js converts between supported LaTeX and the editor tree; parsing and editing checkpoints preserve untouched source byte-for-byte.
  • latex/document.mjs keeps the preamble, document boundary, and opaque source blocks.
  • latex/inline.mjs recognises supported inline syntax; latex/tables.mjs recognises a restricted tabular syntax, and latex/tblr.mjs / latex/tabularx.mjs adapt supported source tables to the existing Table nodes while retaining source ranges, so cell edits patch rather than rebuild; latex/packages.mjs resolves package dependencies needed on export.

Bibliography module

The BibTeX/BibLaTeX engine is separate from the editor UI and has its own public API and tests:

  • Parsing, validation, entry editing, serialisation
  • Diagnostics
  • Scanning .tex sources for citations
  • Pre-compilation checks

Documentation: docs/bib-engine/ (API, architecture).

Build and deployment

  • Dependencies are locked in package-lock.json; CI uses npm ci.
  • esbuild bundles apps/web/src/main.js into apps/web/editor.mjs.
  • MathLive is vendored as a standalone asset into apps/web/vendor/mathlive.
  • editor.mjs and vendor assets are deployment artifacts and are not committed.

pages.yml builds on every push to main, runs the LaTeX / config / bibliography / browser regression tests, and deploys to GitHub Pages (http://lineae.aminiam.com/).

Desktop artifacts are built by desktop.yml (Windows), macos-release.yml (Apple Silicon), and linux-release.yml (x86_64); native TeX baselines and acceptance run remotely via native-tex.yml. See Development and Desktop.

Fidelity boundary

The web JS typesetting is not calibrated against TeX line breaking or arbitrary package expansion:

  • Font metrics, kerning, and paragraph spacing are approximations.
  • Editing a supported block may change whitespace, comments, and command spelling in the source.
  • Complex package constructs and source details need dedicated adapters and a lossless syntax model.

The desktop native workspace, rendered by real LuaLaTeX, is the reference and target for typesetting fidelity; the web pipeline keeps calibrating metrics, math layout, spacing, and pagination against the engine profiles.

Related documents

Clone this wiki locally