A Python library for generating, validating and converting academic content using Typst format.
Project description
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 |
ArticleConsultRAG |
Retrieve relevant citations for article sections |
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
TypstConfig exposes tunable settings via the Fabricatio config system:
from fabricatio_typst.config import typst_config
typst_config.paragraph_sep # "// - - -"
typst_config.article_wrapper # "// =-=-=-=-=-=-=-=-=-="
typst_config.chap_summary_template # "built-in/chap_summary"
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 Distributions
Built Distributions
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 fabricatio_typst-0.1.31-cp314-cp314-win_amd64.whl.
File metadata
- Download URL: fabricatio_typst-0.1.31-cp314-cp314-win_amd64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.14, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2386c328eded0acc7e86974b79a675f308011827d5b174e3243054edd44dea5d
|
|
| MD5 |
e7b6acdd59259a354c84ed3814f43a6d
|
|
| BLAKE2b-256 |
2535437a2c6681ff82c90bba572e94f8cab4861f713ec00b9387db66f705e315
|
File details
Details for the file fabricatio_typst-0.1.31-cp314-cp314-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: fabricatio_typst-0.1.31-cp314-cp314-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 4.3 MB
- Tags: CPython 3.14, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89ae5a88d4aeb100ef877f49e253d6e01cd23a7f17fdfae3814718d9c65cca23
|
|
| MD5 |
d8b81a3e98dae719771042d66da9a47f
|
|
| BLAKE2b-256 |
831315fd0e59f690556aa329941749d90d5e37f8f3e298f7a2ada2392fec1c9f
|
File details
Details for the file fabricatio_typst-0.1.31-cp314-cp314-manylinux_2_34_aarch64.whl.
File metadata
- Download URL: fabricatio_typst-0.1.31-cp314-cp314-manylinux_2_34_aarch64.whl
- Upload date:
- Size: 3.9 MB
- Tags: CPython 3.14, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8c7d3005b3a4b4aeec98c67f3c3d5fb313b4e15877f4e48bc6e45e1163bc44c
|
|
| MD5 |
45b0f6e155e28e2b277d0555f97a3fae
|
|
| BLAKE2b-256 |
9facc86d4bf05bf787317f6e1c8b0d14e2903ac484440b1eccf8286fc86a690f
|
File details
Details for the file fabricatio_typst-0.1.31-cp314-cp314-macosx_11_0_arm64.whl.
File metadata
- Download URL: fabricatio_typst-0.1.31-cp314-cp314-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.14, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5d849692139e859e97c183a4164a35ddbb8f34718ece296921b3192d84434af
|
|
| MD5 |
e0fec50a088552a1da896f3c0f39d9a1
|
|
| BLAKE2b-256 |
bbb3cbc6582b9ffc5a64f28849e6bc784f22e631b87041c42fa28caae8602798
|
File details
Details for the file fabricatio_typst-0.1.31-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: fabricatio_typst-0.1.31-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2626a91db7ef6cb2e319d0e7b9409fe9bff6168eec7517b4de56df52ae88071
|
|
| MD5 |
f04fe3a989e48e561e92020d92412bd7
|
|
| BLAKE2b-256 |
1828da6bb0ff1017653874d9f0a2755f39a36fc52c3b22a63105bd7377dd299e
|
File details
Details for the file fabricatio_typst-0.1.31-cp313-cp313-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: fabricatio_typst-0.1.31-cp313-cp313-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 4.3 MB
- Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2106e4a16e72f17d536fd77b19dd8621f9bf92766c3e36e4de55d43bfd7c4102
|
|
| MD5 |
42a6f74d5949c1711515437833725f7d
|
|
| BLAKE2b-256 |
f564547bee7e0e858a2cf094047a179ba3a377767b0a474cf61953c49982f565
|
File details
Details for the file fabricatio_typst-0.1.31-cp313-cp313-manylinux_2_34_aarch64.whl.
File metadata
- Download URL: fabricatio_typst-0.1.31-cp313-cp313-manylinux_2_34_aarch64.whl
- Upload date:
- Size: 3.9 MB
- Tags: CPython 3.13, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f864beb13127dd98d4efc6026e5c598142563ca9dd3f100ea3a6238fce33423
|
|
| MD5 |
d7dff4fc60ce83d23448d7652c32ccc2
|
|
| BLAKE2b-256 |
5ecdc5119b2f782949f809e74452bfebd8d760eb6928e942de414ca5a2ed5ae2
|
File details
Details for the file fabricatio_typst-0.1.31-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: fabricatio_typst-0.1.31-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1864781482368d792bbe51f2dbf9522a9780c39584ae8ddfb52d00c77fc5d21b
|
|
| MD5 |
207a5af9c82466ec6e5ca7121b3f5827
|
|
| BLAKE2b-256 |
e19de80ed416dfcc12e1accd030fbf97d0f6b9f5446b7d00f8b85773d8422bb7
|
File details
Details for the file fabricatio_typst-0.1.31-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: fabricatio_typst-0.1.31-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ba31d3f4d486d4ef17a1d6fe0d8016e58dde3feed6e8cc5fd2171691b90dd0c
|
|
| MD5 |
843ba6dfce0c1a8659bdb51f62a5f4bd
|
|
| BLAKE2b-256 |
7f8275916c249ba3c65b1a076cb53c02459ac688410fe86c9b82c1dbc2f0fc84
|
File details
Details for the file fabricatio_typst-0.1.31-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: fabricatio_typst-0.1.31-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 4.3 MB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa4734304d38d3103ace14aba3869ed5ca5be36c1740dea4af4646afd6f60524
|
|
| MD5 |
3429d2d49b6a4397e880f8a70bc49eb5
|
|
| BLAKE2b-256 |
7746b76ad44263f1c4d12ee8e42a867d9a3b22cd0abe7cf817b35b626c7ef060
|
File details
Details for the file fabricatio_typst-0.1.31-cp312-cp312-manylinux_2_34_aarch64.whl.
File metadata
- Download URL: fabricatio_typst-0.1.31-cp312-cp312-manylinux_2_34_aarch64.whl
- Upload date:
- Size: 3.9 MB
- Tags: CPython 3.12, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
971a59cfa66e5099b74c1f32151a4881909d993995802ed91168837352e6a76a
|
|
| MD5 |
ed2b176797706a57ddc4788d7a63ad04
|
|
| BLAKE2b-256 |
95019a5aa7f511c0d03a4ae813c7e0b01d483859c210b7cf03be71764f2d555d
|
File details
Details for the file fabricatio_typst-0.1.31-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: fabricatio_typst-0.1.31-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ab6880f6dac8f3a3769d9473e9c81431ab1a4ecdff63a2bdeeabb6b33149d9c
|
|
| MD5 |
f11ed1c257b45cba49a2bd6e07c71f6b
|
|
| BLAKE2b-256 |
dcd002941ebcbaadce861cf77a13f6c2bc6d0b0dac578934fb74352036a39e33
|