Skip to main content

Python interface to generate Typst code.

Project description

python-typst

python-typst is a library for generating executable typst code (See typst repository and typst documentation for more information). It is written primarily in functional programming paradigm with some OOP content.

This package provides the interfaces in a way that is as close as possible to typst's native functions. Through python-typst and other data processing packages, you can generate data reports quickly.

Repository on GitHub: python-typst. Homepage on PyPI: python-typst. Contributions are welcome.

Installation

pip install typstpy

Examples

text

>>> text("Hello, World!", font="Arial", fallback=True)
'#text(font: "Arial", fallback: true)[Hello, World!]'
>>> text("Hello, World!", font=("Arial", "Times New Roman"), fallback=True)
'#text(font: ("Arial", "Times New Roman"), fallback: true)[Hello, World!]'
>>> text("Hello, World!", size=Length(12, "pt"))
'#text(size: 12pt)[Hello, World!]'
>>> text("Hello, World!", fill=color("red"))
'#text(fill: rgb("#ff4136"))[Hello, World!]'

emph

>>> emph("Hello, World!")
'#emph[Hello, World!]'

strong

>>> strong("Hello, World!")
'#strong[Hello, World!]'
>>> strong("Hello, World!", delta=300)
'#strong(delta: 300)[Hello, World!]'

par

>>> par("Hello, World!", leading=Length(1.5, "em"))
'#par(leading: 1.5em)[Hello, World!]'
>>> par("Hello, World!", justify=True)
'#par(justify: true)[Hello, World!]'
>>> par("Hello, World!")
'Hello, World!'

heading

>>> heading("Hello, World!", level=2, supplement=Content("Chapter"), label=Label("chap:chapter"))
'#heading(supplement: [Chapter], level: 2)[Hello, World!] <chap:chapter>'
>>> heading("Hello, World!", level=2)
'== Hello, World!'

image

>>> image("image.png")
'#image("image.png")'
>>> image("image.png", format="png")
'#image("image.png", format: "png")'

figure

>>> figure(image("image.png"))
'#figure(image("image.png"))'
>>> figure(image("image.png"), caption=Content("This is a figure."))
'#figure(image("image.png"), caption: [This is a figure.])'
>>> figure(image("image.png"), caption=Content("This is a figure."), label=Label("fig:figure"))
'#figure(image("image.png"), caption: [This is a figure.]) <fig:figure>'
>>> figure(image("image.png"), caption=figure.caption("This is a figure.", separator=Content("---")))
'#figure(image("image.png"), caption: figure.caption(separator: [---])[This is a figure.])'

Current Support

Name Parameters Implement Type
text font, fallback, size, fill Standard
emph Standard
strong delta Standard
par leading, justify, linebreaks, first_line_indent, hanging_indent Standard
heading level, supplement, numbering, label Standard
image path, format, width, height, alt, fit Standard
figure caption, label Standard
figure.caption separator Standard
rgb red, green, blue, alpha Standard
rgb hex Standard
luma lightness, alpha Standard
color name Not Standard

Standard means you could find implementation in typst. Not Standard means this function is not the standard implementation of corresponding function in typst, or is not implemented in typst but for convenience.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

typstpy-0.0.3.tar.gz (9.0 kB view hashes)

Uploaded Source

Built Distribution

typstpy-0.0.3-py3-none-any.whl (9.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page