Giter Club home page Giter Club logo

typst-py's Introduction

typst-py

CI PyPI

Python binding to typst, a new markup-based typesetting system that is powerful and easy to learn.

Installation

pip install typst

Usage

import typst


# Compile `hello.typ` to PDF and save as `hello.pdf`
typst.compile("hello.typ", output="hello.pdf")

# Compile `hello.typ` to PNG and save as `hello.png`
typst.compile("hello.typ", output="hello.png", format="png", ppi=144.0)

# Or return PDF content as bytes
pdf_bytes = typst.compile("hello.typ")

# Also for svg
svg_bytes = typst.compile("hello.typ", format="svg")

# Or use Compiler class to avoid reinitialization
compiler = typst.Compiler("hello.typ")
compiler.compile(format="png", ppi=144.0)

License

This work is released under the Apache-2.0 license. A copy of the license is provided in the LICENSE file.

typst-py's People

Contributors

dependabot[bot] avatar icxolu avatar jocelyn-gas avatar kianmeng avatar messense avatar orangex4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

typst-py's Issues

Incorporate scope `show`/`set` rules in `metadata` output

Consider the following document:

#let mr(..args) = [#metadata(rect(..args))<rect>]
#mr(width: 5em, height: 5em, stroke: black)

#mr(width: 5em, height: 5em, stroke: black)

#set rect(stroke: rgb(255, 0, 0))
#show rect: it => it

#mr(width: 5em, height: 5em, fill: yellow)
#show rect: it => [Completely overridden!]
#mr(width: 5em, height: 5em, fill: yellow)

It would be ideal if the output of typst query file.typ "<rect>" could capture whatever content is about to be shown, not just what is passed directly. This allows the metadata to more accurately reflect what is actually present in the document. Currently, neither show rules or set rules are incorporated.

[feature request] add support for png export

The code mentions that you can export pdf, svg, and png formats:

Args:
input (PathLike): Project's main .typ file.
output (Optional[PathLike], optional): Path to save the compiled file.
Allowed extensions are `.pdf`, `.svg` and `.png`

But actually we can only export pdf:

typst-py/src/compiler.rs

Lines 27 to 30 in d1c177c

match result {
// Export the PDF / PNG.
Ok(document) => Ok(export_pdf(&document, self)?),
Err(errors) => Err(format_diagnostics(self, &errors, &warnings).unwrap().into()),

Add test documents

Hello, first of all thank you for this project. I have been using the library you wrote and it has been very useful. I am interested in contributing to solve some needs that have arisen and to keep typst versions up to date.

However, before making any contributions, I want to ensure that I'm not breaking anything, so I was thinking of adding the sample documents as tests, but noticed that there was no defined way to declare development dependencies, to add for example pytest.

Personally, I find that using Poetry to manage these dependencies is the most comfortable way. Nonetheless, I'd greatly appreciate your input on this matter.

Thank you for your time, and I look forward to your insights.

utf-8 and Python compiler

Hi all,
If I compile online with ² or ° in the text, I get no issues. With the Python compiler it does not work, I need to write ² or °.
Any idea why and how to fix it to be portable?
Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.