A Laravel package that provides a convenient facade for compiling Typst documents directly from your Laravel application. Typst is a modern markup-based typesetting system designed to be simple, powerful, and fast.
Features
- Multiple Output Formats: Compile Typst documents to PDF, PNG, and SVG
- Flexible Input: Support for both file-based and direct source compilation
- Configurable: Runtime settings and configuration options
- Laravel Integration: Clean facade interface with dependency injection support
- Error Handling: Robust error handling for compilation failures
- Cross-Platform: Works on any platform where Typst binary is available
Installation
Requirements
- PHP 8.1 or higher
- Laravel 10.0 or 11.0
- Typst binary installed on your system
Installation Steps
Add the package repository to your composer.json
:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/durableprogramming/durable-laravel-typst"
}
]
}
Install via Composer:
composer require durableprogramming/durable-laravel-typst
Publish the configuration file:
php artisan vendor:publish --tag=typst-config
Usage
Basic Compilation
use DurableProgramming\Typst\Facades\Typst;
// Compile Typst source to PDF
$outputPath = Typst::compile('#set text(font: "Arial")
Hello, World!');
// The compiled PDF is now available at $outputPath
Compile from File
// Compile a Typst file to PDF
$outputPath = Typst::compileFile('/path/to/document.typ');
Custom Output Formats
// Compile to PNG
$outputPath = Typst::compile(
'#set text(font: "Arial")
Hello, World!',
format: 'png'
);
// Compile to SVG
$outputPath = Typst::compile(
'#set text(font: "Arial")
Hello, World!',
format: 'svg'
);
Advanced Usage with Runtime Settings
// Compile with custom settings
$outputPath = Typst::compile(
'#set text(font: "Arial")
Hello, World!',
format: 'pdf',
settings: [
'ppi' => 300,
'font-path' => '/path/to/fonts'
]
);
Configuration
After publishing the configuration file, you can customize the package behavior in config/typst.php
:
return [
'binary_path' => env('TYPST_BINARY_PATH', 'typst'),
'output_path' => storage_path('app/typst'),
'default_format' => 'pdf',
];
Use Cases
- Invoice Generation: Generate professional PDF invoices with custom styling
- Report Creation: Create formatted reports with charts and tables
- Document Templates: Build reusable document templates for various purposes
- Certificate Generation: Generate certificates with custom designs
- Academic Papers: Format academic documents with proper citations and formatting
Why Typst?
Typst is a modern alternative to LaTeX that offers:
- Fast Compilation: Near-instant compilation times
- Simple Syntax: More approachable than LaTeX
- Modern Design: Built with contemporary programming practices
- Scripting: Powerful scripting capabilities for dynamic content
- Beautiful Output: Professional-quality typesetting
Development
Testing
composer test
Code Style
composer format
Contributing
Contributions are welcome! Please read our contributing guidelines before submitting pull requests.
- Fork the repository
- Create a feature branch (
git checkout -b feature/my-feature
) - Make your changes
- Ensure tests pass (
composer test
) - Commit your changes
- Push to your fork
- Open a pull request
License
MIT License - see LICENSE.md for details.
Copyright (c) 2025 Durable Programming, LLC. All rights reserved.
Support
For bugs, feature requests, or questions, please open an issue on GitHub.
GitHub
📅 Created September 2025 | 🔄 Updated September 2025