carthage-software / ext-typst
PHP extension for the Typst typesetting engine
Package info
github.com/carthage-software/ext-typst
Type:php-ext
Ext name:ext-typst
pkg:composer/carthage-software/ext-typst
Requires
- php: ~8.3.0 || ~8.4.0 || ~8.5.0
Requires (Dev)
- carthage-software/mago: ^1.43.0
- php-standard-library/php-standard-library: ^4.3 || ^5.0 || ^6.0
- phpunit/phpunit: ^12.0
README
A PHP extension that embeds the Typst typesetting engine, built with Rust via ext-php-rs.
Compile Typst markup to PDF, PNG, JPEG, and SVG directly from PHP. No CLI needed. No subprocess spawning.
Documentation | GitHub | Typst
Installation
Via PIE
pie install carthage-software/ext-typst
Pre-built binaries
Download the ZIP for your platform from GitHub Releases. Each ZIP contains a typst.so file. Extract it and add to your php.ini:
extension=/path/to/typst.so
IDE & static analysis stubs
composer require --dev carthage-software/ext-typst-stubs
Enables autocompletion in PhpStorm and Mago out of the box. For PHPStan or Psalm, point them at the stub directory. See the stubs package for the exact config. Each tag matches the corresponding extension release.
Quick Start
$world = new Typst\World(); $compiler = new Typst\Compiler($world); const TEMPLATE = <<<'TYPST' #set page(height: auto) = Hello from Typst This is a *bold* statement with _italic_ flair. TYPST; $document = $compiler->compileString(TEMPLATE); $document->toPdf()->save('output.pdf'); $document->toImage()->save('output.png'); $document->toSvg()->save('output.svg');
See the full documentation at ext-typst.carthage.software.
Supported Platforms
| Platform | Architecture |
|---|---|
| Linux | x86_64 |
| Linux | aarch64 |
| macOS | arm64 |
PHP 8.3, 8.4, and 8.5 are supported.
Development
Requires Rust (stable, 2024 edition) and just.
just build # debug build just release # release build just test # run tests just run-example X # run examples/X.php just lint # clippy + mago lint just check # cargo check + mago analyze just fmt # format rust + php just verify # fmt-check + lint + check
For more examples, see examples/.
Acknowledgments
This project was developed by Carthage Software and is fully funded by our partner Buhta.
License
MIT OR Apache-2.0