Backend Python library for rendering LaTeX problem statements and CP editorial animations to self-contained HTML
Project description
Scriba
Status: v0.15.3 · MIT · Python 3.10+
Scriba is a backend Python library that renders LaTeX problem statements and
competitive-programming editorials to self-contained HTML fragments. It is
LaTeX-first: drop a .tex source in, get out HTML plus the exact CSS/JS
asset basenames needed to display it.
What is Scriba?
- LaTeX-first rendering for CP problem statements and editorials, with
KaTeX math, Pygments code highlighting, lists, tables, sections, figures,
\href/\urlwith XSS hardening, and\begin{lstlisting}code blocks. - Self-contained output contract: every render produces an HTML fragment plus a namespaced set of required CSS and JS basenames and a block-data map — consumers decide how to serve the static assets.
\begin{animation}environment (shipping since 0.2.0) for step-through editorial walkthroughs with 16 built-in primitives (arrays, grids, graphs, trees, DP tables, number lines, matrices/heatmaps, stacks, plane-2D, metric plots, and the 5 data-structure primitives: code panel, hash map, linked list, queue, variable watch).\begin{diagram}for inline static graph/tree figures is reserved under extension E5. Seedocs/spec/ruleset.mdfor the full grammar and error catalog.
What's new in v0.15.3
- README status fix — 0.15.2 shipped with a stale README (showed
Status: v0.9.0). 0.15.3 fixes README + CONTRIBUTING + packaging docs to reflect current version. No code changes; prefer 0.15.3 for installs. (0.15.1 is yanked — 48 MiB sdist bloat; 0.15.2 is yanked — stale README.) - (v0.15.1) GEP v2.0.0 graph edge pill (pre-layout expansion, typography hierarchy, simulated-annealing refinement), Sugiyama hierarchical
layout="auto"for directed graphs, R-32 annotation-stable-layout fix (reflow-flash eliminated), TEX-REFERENCE 47-issue audit closed, examples corpus audit + cleanup. - (v0.15.0) Leader-line visual-gap gate.
- See
CHANGELOG.mdfor the full history.
v0.8.2 changelog
- Position-aware auto-ID generation. Duplicate animation/diagram blocks with identical content now produce distinct HTML element IDs.
- Duplicate block ID warning. The pipeline emits
CollectedWarning(code="E1019", severity="dangerous")when two blocks share the sameblock_id.
v0.8.0 changelog
- Fixed state styling regression. Cell/node/edge state colors
(
current,error,good,highlight, etc.) were silently overridden by primitive base selectors due to a CSS specificity conflict. Primitive base selectors now use:where()to zero their qualifying specificity, so.scriba-state-*rules always win.
v0.7.0 changelog
- Fully portable HTML output.
render.pynow produces single-file, offline-ready HTML. All CSS (scene primitives, animation, widget chrome, Pygments syntax highlighting), KaTeX math fonts (20 woff2 files, base64-encoded), and\includegraphicsimages (data URIs) are inlined. Zero CDN dependencies — just open the.htmlin any browser. - CSS deduplication. The ~470-line inline CSS block in
render.pywas replaced by a newscriba.core.css_bundlermodule that reads CSS from source.cssfiles at render time. Single source of truth for all styling. traversable_to_path()helper. Centralised thePath(str(traversable))anti-pattern across 3 files into a documented helper inscriba.core.artifact, ready for futureas_file()upgrade.text_outline=parameter removed. The per-call text outline parameter on primitives, deprecated in v0.6.0, is removed. Use the CSS halo cascade instead.
v0.6.0 changelog
- Wave 8 — vstack layout. Array, DP-table, and related primitives now
compose their caption, index labels, and cells through a shared
scriba/animation/primitives/layout.pyvstack helper. - Wave 9 — CSS-first text halo cascade. Every
[data-primitive] textelement now inheritspaint-order: stroke fill markerswith a--scriba-haloCSS variable that each state class overrides. - RFC-001 — structural mutation ops. Tree, Graph, and Plane2D primitives
gained safe structural ops (
add_node,remove_node,reparent). - RFC-002 — strict mode and document warnings. Pipeline surfaces
non-fatal issues on
Document.warnings. Seedocs/guides/strict-mode.md. - Examples reorganized. 53
.texexamples acrossexamples/quickstart/,examples/algorithms/,examples/cses/, andexamples/primitives/. Seedocs/cookbook/README.md.
Install
pip install scriba-tex
Scriba shells out to a small Node.js worker for KaTeX math, so the host environment needs Node.js 18+ on PATH:
# System prerequisite — Node.js only
apt-get install nodejs # or: brew install node
KaTeX 0.16.11 is vendored inside the wheel (at
scriba/tex/vendor/katex/katex.min.js), so no separate
npm install -g katex step is required. pip install scriba-tex is all
you need once Node is present.
Using Scriba with an AI assistant
To have an AI write .tex for Scriba, give it one file:
docs/SCRIBA-TEX-REFERENCE.md.
It's self-contained — all commands, all 15 primitives, all selectors, all gotchas. No other spec files needed.
Prompt template:
Read
SCRIBA-TEX-REFERENCE.md. Write a Scriba.texfile that animates [algorithm]. Use only commands and primitives documented in that file.
Hello world
from scriba import Pipeline, RenderContext, SubprocessWorkerPool
from scriba.tex import TexRenderer
pool = SubprocessWorkerPool()
pipeline = Pipeline([TexRenderer(worker_pool=pool, pygments_theme="one-light")])
ctx = RenderContext(
resource_resolver=lambda name: f"/cdn/problems/1/{name}",
theme="light", dark_mode=False, metadata={}, render_inline_tex=None,
)
doc = pipeline.render(r"\section{Hello} Let $x^2$ be the square.", ctx)
print(doc.html) # HTML fragment
print(doc.required_css) # namespaced CSS keys
pipeline.close()
Standalone CLI
For quick rendering without writing Python, use render.py directly:
python render.py input.tex # → input.html
python render.py input.tex -o out.html # → custom output path
python render.py input.tex --open # → render and open in browser
Output is a single, fully portable HTML file — all CSS, KaTeX math
fonts, syntax highlighting, and images (via \includegraphics) are
inlined as data URIs. No internet connection or external files needed.
Just open the .html file in any browser.
For legacy filmstrip mode (static frames, no JavaScript):
python render.py input.tex --static
Sanitize before embedding
Scriba does not sanitize its output — consumers must pass it through a vetted sanitizer before embedding in a page. Scriba ships an allowlist that matches its output contract:
import bleach
from bleach.css_sanitizer import CSSSanitizer
from scriba import ALLOWED_TAGS, ALLOWED_ATTRS
css = CSSSanitizer(allowed_css_properties=("transform","transform-origin","width","height"))
safe = bleach.clean(doc.html, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRS,
css_sanitizer=css, strip=True)
Serving static assets
Assets ship inside the Python package. Copy them at deploy time:
from importlib.resources import files
import shutil
shutil.copytree(str(files("scriba.tex.static")), "./public/scriba", dirs_exist_ok=True)
Then include them alongside the rendered fragment:
<link rel="stylesheet" href="/cdn/katex/katex.min.css">
<link rel="stylesheet" href="/public/scriba/scriba-tex-content.css">
<link rel="stylesheet" href="/public/scriba/scriba-tex-pygments-light.css">
<script defer src="/public/scriba/scriba-tex-copy.js"></script>
<article class="scriba-tex-content">{{ doc.html }}</article>
Note: This section applies to the Pipeline API (library usage), where you serve assets yourself. If you use
render.pyinstead, the output HTML is fully self-contained — all CSS, KaTeX fonts (base64), and Pygments highlighting are inlined. No separate asset serving needed.
Documentation
Full architecture, contracts, and roadmap live under the project docs tree: https://github.com/Danchuong/scriba/tree/main/docs
License
MIT. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file scriba_tex-0.15.3.tar.gz.
File metadata
- Download URL: scriba_tex-0.15.3.tar.gz
- Upload date:
- Size: 1.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2f6352e3f9cb4be2831946b3239961a87416e0d05f5ba15f7185589bbc47dc3
|
|
| MD5 |
4378459f6e28943cf06ce74cfc8741b8
|
|
| BLAKE2b-256 |
71a82c9fa39081813d2001c8eb96c9d398f533ff965c73b483da5a60b095ab9d
|
File details
Details for the file scriba_tex-0.15.3-py3-none-any.whl.
File metadata
- Download URL: scriba_tex-0.15.3-py3-none-any.whl
- Upload date:
- Size: 716.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da37153f4baa002509025e138f32bbe3eeb02e27580c199f9875999cee847978
|
|
| MD5 |
033db0687187886d598b33a5407e4f50
|
|
| BLAKE2b-256 |
f0e49a7b31e4206270643ef81ac8b51e023091b24984e52ba0893317c72ba10b
|