fabricatio-typst
Academic article generation and Typst document tooling, built on Fabricatio's event-based agent framework.
Installation
pip install fabricatio[typst]
For RAG-backed article writing:
pip install fabricatio[typst,rag]
Overview
Two layers compose this package:
Rust extension (fabricatio_typst.rust) — performance-critical utilities:
- TeX-to-Typst math conversion (raw LaTeX and delimited
$/$$/\(/\[math) - BibTeX bibliography management with fuzzy citation lookup
- Typst comment manipulation and YAML front-matter handling
- Markdown section extraction
Python layer — agent-based academic content generation:
- Extract paper essences and generate structured research proposals
- Build hierarchical article outlines and generate full content
- RAG-backed article writing with citation-aware iterative retrieval
- Store and query article chunks in LanceDB
- Compile
.typdocuments to PDF, PNG, or SVG via thetypstcompiler
Rust API
from fabricatio_typst.rust import (
BibManager,
tex_to_typst,
convert_all_tex_math,
comment,
uncomment,
strip_comment,
split_out_metadata,
to_metadata,
extract_body,
replace_thesis_body,
extract_sections,
fix_misplaced_labels,
)
TeX Conversion
| Function | Description |
|---|---|
tex_to_typst(string) |
Convert raw LaTeX code to Typst math |
convert_all_tex_math(string) |
Convert $, $$, \(, \[ math delimiters to Typst $ |
tex_to_typst(r"\frac{1}{\sqrt{x^2 + 1}}")
# => '#frac(1, sqrt(x^2 + 1))'
convert_all_tex_math("Einstein's $E = mc^2$ is famous.")
# => "Einstein's $E = m c^2$ is famous."
Comment Utilities
| Function | Description |
|---|---|
comment(string) |
Prepend // to every line |
uncomment(string) |
Remove // prefix from every line |
strip_comment(string) |
Strip leading and trailing comment lines |
BibManager
Loads a BibTeX bibliography file and provides fuzzy citation lookup.
bib = BibManager("references.bib")
cite_key = bib.get_cite_key_by_title("Attention Is All You Need")
# => "vaswani2017attention"
key = bib.get_cite_key_fuzzy("transformers attention mechanism")
authors = bib.get_author_by_key(key)
abstract = bib.get_abstract_by_key(key)
| Method | Description |
|---|---|
get_cite_key_by_title(title) |
Exact-match citation key by title |
get_cite_key_by_title_fuzzy(title) |
Fuzzy-match citation key by title |
get_cite_key_fuzzy(query) |
Fuzzy-match citation key by arbitrary query |
list_titles(is_verbatim=False) |
List all bibliography titles |
get_author_by_key(key) |
Authors for a citation key |
get_year_by_key(key) |
Publication year for a citation key |
get_abstract_by_key(key) |
Abstract for a citation key |
get_title_by_key(key) |
Title for a citation key |
get_field_by_key(key, field) |
Arbitrary BibTeX field for a citation key |
Document Utilities
| Function | Description |
|---|---|
split_out_metadata(string) |
Extract YAML front matter as (metadata, rest) |
to_metadata(data) |
Serialize Python object to YAML comment block |
extract_body(string, wrapper) |
Extract content between wrapper markers |
replace_thesis_body(string, wrapper, new_body) |
Replace content between wrapper markers |
extract_sections(string, level=1, section_char="#") |
Parse markdown sections at given header level |
fix_misplaced_labels(string) |
Move \<label\> tags outside display math blocks |
Python Models
Hierarchical article representation from proposal through completed paper:
| Model | Description |
|---|---|
ArticleProposal |
Research proposal: problems, approaches, methods, aims, keywords |
ArticleEssence |
Semantic fingerprint: title, authors, equations, figures, contributions |
ArticleOutline |
Hierarchical outline: chapters → sections → subsections |
ArticleChapterOutline |
Chapter-level outline node |
ArticleSectionOutline |
Section-level outline node |
ArticleSubsectionOutline |
Subsection-level outline node |
Article |
Complete paper with full content and validation |
ArticleChapter |
Chapter with sections |
ArticleSection |
Section with subsections |
ArticleSubsection |
Subsection with paragraphs |
Paragraph |
Structured paragraph blueprint with word count |
ArticleChunk |
LanceDB-storable chunk with bibtex metadata |
ArticleEssenceStorable |
ArticleEssence with LanceDB storage capability |
CitationManager |
Deduplicated, iteratively expanded citation set for RAG |
ChunkKwargs |
TypedDict for chunking parameters |
Actions
Each action is a Fabricatio Action — an async callable unit in the agent workflow. Available actions:
Content Extraction
| Action | Description |
|---|---|
ExtractArticleEssence |
Extract article essences from files on disk |
FixArticleEssence |
Fix extracted essences using BibTeX reference data |
ExtractOutlineFromRaw |
Parse an outline from raw text |
Generation
| Action | Description |
|---|---|
GenerateArticleProposal |
Generate a research proposal from a briefing |
GenerateInitialOutline |
Build an outline from a proposal |
GenerateArticle |
Generate full article content from an outline |
LoadArticle |
Load a complete article from outline + Typst code |
WriteChapterSummary |
Write summaries for each chapter |
WriteResearchContentSummary |
Write a research content summary |
RAG-Backed Writing
| Action | Description |
|---|---|
WriteArticleContentRAG |
Write article content with citation-aware RAG |
TweakArticleLancedbRAG |
Refine article content using LanceDB RAG |
ChunkArticle |
Split an article into storeable chunks |
StoreArticleEssence |
Store article essences into LanceDB |
Compilation
| Action | Description |
|---|---|
CompileTypstDocument |
Compile a .typ file or source string to PDF/PNG/SVG |
CompileArticle |
Compile a previously dumped article .typ to PDF |
from pathlib import Path
from fabricatio_typst.actions.article import CompileArticle, CompileTypstDocument
# Compile a standalone .typ file
result = await CompileTypstDocument().act({
"typst_source": Path("paper.typ"),
"output_path": Path("paper.pdf"),
})
# result["compiled_path"] → Path("paper.pdf")
# Compile a generated article (after DumpFinalizedOutput)
result = await CompileArticle().act({
"article_path": Path("output.typ"),
})
# result["compiled_path"] → Path("output.pdf")
Citation Capability
CitationLancedbRAG — citation-aware iterative search that expands queries over multiple rounds and deduplicates by bibtex key.
Workflows
Pre-composed action pipelines:
| Workflow | Steps |
|---|---|
WriteOutlineCorrectedWorkFlow |
GenerateArticleProposal → GenerateInitialOutline → dump output |
CompileArticleWorkflow |
Compile a .typ article to PDF |
StoreArticle |
ExtractArticleEssence → StoreArticleEssence |
Usage:
from fabricatio_typst.actions.article import GenerateArticleProposal, GenerateInitialOutline
from fabricatio_typst.models.article_proposal import ArticleProposal
from fabricatio_typst.models.article_outline import ArticleOutline
async def generate_outline():
result = await GenerateArticleProposal().act({
"article_briefing": "Quantum error correction in near-term devices",
})
proposal: ArticleProposal = result["article_proposal"]
print(f"Proposal: {proposal.title}")
result = await GenerateInitialOutline().act({
"article_proposal": proposal,
})
outline: ArticleOutline = result["initial_article_outline"]
print(f"Outline chapters: {len(outline.chapters)}")
Dependencies
fabricatio-core— agent framework and core modelsfabricatio-tool— filesystem utilitiesfabricatio-capabilities— capability mixins (Extract, Censor, etc.)typst— Typst compiler Python bindings (for compilation actions)
Optional for article generation workflows:
fabricatio-actions— output dumping actionsfabricatio-improve,fabricatio-rule— content improvement and validation
Optional for RAG features:
fabricatio-lancedb— vector storage and retrieval
CLI
The package includes the ttm (TeX to Typst Math) binary:
# Convert math in a file
ttm file input.md -o output.md
# Convert raw LaTeX string
ttm raw "\frac{a}{b}"
# Convert a string with math delimiters
ttm string "The formula $\int_0^\infty e^{-x} dx$ is useful."
Configuration
All options below are read through the fabricatio configuration chain (see the
Configuration Guide). Set them under the
[ext.typst] table in fabricatio.toml, equivalently under
[tool.fabricatio.ext.typst] in pyproject.toml, or via
FABRICATIO_EXT__TYPST__<FIELD_UPPER> environment variables.
[ext.typst]
chap_summary_template = "built-in/chap_summary"
| Option | Type | Default | Description |
|---|---|---|---|
chap_summary_template |
str |
"built-in/chap_summary" |
The name of the chap summary template which will be used to generate a chapter summary. |
research_content_summary_template |
str |
"built-in/research_content_summary" |
The name of the research content summary template which will be used to generate a summary of research content. |
paragraph_sep |
str |
"// - - -" |
The separator used to separate paragraphs. |
article_wrapper |
str |
"// =-=-=-=-=-=-=-=-=-=" |
The wrapper used to wrap an article. |
extract_essence_template |
str |
"built-in/extract_essence" |
The name of the extract essence template which will be used to extract the essence of a text. |
generate_outline_template |
str |
"built-in/generate_outline" |
The name of the generate outline template which will be used to generate an outline. |
Access at runtime: from fabricatio_typst.config import typst_config.
License
MIT — see LICENSE
Metadata
Release files for fabricatio-typst 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 43.8 MB
Release files / fabricatio_typst-0.2.0-cp314-cp314-win_amd64.whl
| Download URL | fabricatio_typst-0.2.0-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 3.5 MB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
eb0a48a41ac1cde3441b93fe92b6cbc8fd8616a40e1c5cbc043c95c379367fe3
|
|
BLAKE2b-256 checksum How to use checksums |
c8fe5295af0d1a1685db3b8d074ab3237e387c5ae32ca5b0a584e74092b26b23
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / fabricatio_typst-0.2.0-cp314-cp314-manylinux_2_34_x86_64.whl
| Download URL | fabricatio_typst-0.2.0-cp314-cp314-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 4.0 MB |
| Tags | CPython 3.14 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
4f37c95073a523aec5581c8594e64fe6b2c29e1713a0054bd15866df36e59e0d
|
|
BLAKE2b-256 checksum How to use checksums |
e72be910c8956c11098e2b9deccd8c149b65ad41ed1c15673a629da018177df9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / fabricatio_typst-0.2.0-cp314-cp314-manylinux_2_34_aarch64.whl
| Download URL | fabricatio_typst-0.2.0-cp314-cp314-manylinux_2_34_aarch64.whl |
|---|---|
| Size | 3.6 MB |
| Tags | CPython 3.14 Linux glibc 2.34+ ARM64 |
|
SHA-256 checksum How to use checksums |
4e88e42a8944a3ca763495d4203633878e3b2a4b010a803c2495aa608e345578
|
|
BLAKE2b-256 checksum How to use checksums |
620155a3512784d9de549e9a4b040350454a1d8a9179b25b6871f4390caf5e93
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / fabricatio_typst-0.2.0-cp314-cp314-macosx_11_0_arm64.whl
| Download URL | fabricatio_typst-0.2.0-cp314-cp314-macosx_11_0_arm64.whl |
|---|---|
| Size | 3.5 MB |
| Tags | CPython 3.14 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
9935c4997ecc38d1b66ff14a2453867e38beed3d6ab2f1b35f8499725717a58d
|
|
BLAKE2b-256 checksum How to use checksums |
986834b97c1d02191bcff6c4162fb01f7e1d6ce3e12019c5d8d04da87e659432
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","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":true}
|
Release files / fabricatio_typst-0.2.0-cp313-cp313-win_amd64.whl
| Download URL | fabricatio_typst-0.2.0-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 3.5 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
f801cae8090eba5883c510698d52f647e47a15e5805d32c5c3291b467e74eedc
|
|
BLAKE2b-256 checksum How to use checksums |
c4f25a9e7a2990f281b2b35540e49f2dae9c163637b3aaff87bbd9e8c783b4c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / fabricatio_typst-0.2.0-cp313-cp313-manylinux_2_34_x86_64.whl
| Download URL | fabricatio_typst-0.2.0-cp313-cp313-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 4.0 MB |
| Tags | CPython 3.13 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
120183a79e32cb62ab07d7e81c904719a107095285783a0a1d9c2eca8a4f0a2b
|
|
BLAKE2b-256 checksum How to use checksums |
268723c62a1b7c2a527a806c4a8fe204410875019c36e68388fba44e49e6d65a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / fabricatio_typst-0.2.0-cp313-cp313-manylinux_2_34_aarch64.whl
| Download URL | fabricatio_typst-0.2.0-cp313-cp313-manylinux_2_34_aarch64.whl |
|---|---|
| Size | 3.6 MB |
| Tags | CPython 3.13 Linux glibc 2.34+ ARM64 |
|
SHA-256 checksum How to use checksums |
cadde6cf79ddba8e069d90acfcb9b18c4f7f72f87b72bb81773e96fb5da78dfe
|
|
BLAKE2b-256 checksum How to use checksums |
a69efac3705b7506780178ee8fbf2a56f21d61cbd6bf8c1674418e6e8cd8597c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / fabricatio_typst-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | fabricatio_typst-0.2.0-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 3.5 MB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
7473b2cc10eadb13ef6e78fe2e958aa2c65446fd9c0cb00be2a77942843f3945
|
|
BLAKE2b-256 checksum How to use checksums |
dcf788b1a7d7f04775029636a63d05f36f9b0e85efd466cd2212649e4f6bf253
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","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":true}
|
Release files / fabricatio_typst-0.2.0-cp312-cp312-win_amd64.whl
| Download URL | fabricatio_typst-0.2.0-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 3.5 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
fd46f606bf50bad346d898bbd4a2933fea34b7158a7a14b74c1c18efc8ea5457
|
|
BLAKE2b-256 checksum How to use checksums |
60f2c24a4ce63b69c5011e33164392ebfdde0104ec34d66953a59234dfefcb00
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / fabricatio_typst-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl
| Download URL | fabricatio_typst-0.2.0-cp312-cp312-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 4.0 MB |
| Tags | CPython 3.12 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
87df60713ad520d943e3098ad1da90bac826931ef1f948f0bb40030b23956357
|
|
BLAKE2b-256 checksum How to use checksums |
265efb11063894bb87cd82cc96e5d4cf693a76fd89cd9dd81e2f871ff79763c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / fabricatio_typst-0.2.0-cp312-cp312-manylinux_2_34_aarch64.whl
| Download URL | fabricatio_typst-0.2.0-cp312-cp312-manylinux_2_34_aarch64.whl |
|---|---|
| Size | 3.6 MB |
| Tags | CPython 3.12 Linux glibc 2.34+ ARM64 |
|
SHA-256 checksum How to use checksums |
415b9ff121a712ccad6613ee3d2b647347570326fd98ca27851f37da58f4b685
|
|
BLAKE2b-256 checksum How to use checksums |
bb4d63e53f70639afd8563ef5d7abf7c2209a5d3afc21265809edf107d5042c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / fabricatio_typst-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | fabricatio_typst-0.2.0-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 3.5 MB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
fa63d569a3b824b150a0358e3b367a1fa4b15dc2c8f1ed42db26049f1d2c903a
|
|
BLAKE2b-256 checksum How to use checksums |
107638c7f103aae5f288310aca20a665838da046c742cc48467da12d872ad024
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","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":true}
|