This Laravel package provides a straightforward way to compile Typst documents directly from your Laravel application. Typst is a modern, markup-based typesetting system that offers a compelling alternative to traditional tools like LaTeX, focusing on simplicity, power, and speed.
Key Capabilities
This package is designed to empower your Laravel applications with robust document generation, offering a suite of features that streamline the process:
- Versatile Output Formats: Generate Typst documents into various formats, including high-fidelity PDFs for print and digital distribution, and scalable PNG and SVG images for web integration.
- Adaptable Input Sources: Whether your Typst content resides in a file or is dynamically generated within your application, the package supports both file-based and direct source compilation, providing flexibility for diverse workflows.
- Extensive Configuration Options: Tailor the compilation process to your specific needs with comprehensive runtime settings and configuration options, allowing fine-grained control over output and behavior.
- Seamless Laravel Integration: Leverage a clean, intuitive facade interface with full dependency injection support, ensuring the package feels like a native part of your Laravel application.
- Resilient Error Handling: Built-in robust error handling mechanisms gracefully manage compilation failures, providing clear feedback and preventing unexpected application behavior.
- Broad Cross-Platform Compatibility: Operate confidently across any environment where the Typst binary is available, ensuring consistent document generation regardless of your deployment platform.
Installation
Requirements
To ensure a smooth installation and operation of this package, please verify the following prerequisites:
- PHP 8.1 or higher
- Laravel 10.0 or 11.0
- Typst Binary: The
typstcommand-line tool must be installed and accessible in your system’s PATH. You can download it from the official Typst website or install it via your system’s package manager. We recommend verifying its installation by runningtypst --versionin your terminal.
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',
];
Practical Applications
The Durable Laravel Typst package unlocks a wide range of document generation possibilities within your Laravel applications. Here are some common scenarios where its capabilities prove invaluable:
- Automated Invoice Generation: Effortlessly create and dispatch professional PDF invoices, complete with dynamic data, custom branding, and complex layouts, directly from your application’s billing system.
- Dynamic Report Creation: Generate sophisticated reports featuring charts, tables, and rich text. This is ideal for business intelligence dashboards, analytical summaries, or any scenario requiring structured data presentation.
- Reusable Document Templates: Design and manage a library of Typst templates for various document types (e.g., contracts, letters, marketing materials). Populate these templates with data from your Laravel models to produce consistent, high-quality output.
- Personalized Certificate Generation: Produce unique, personalized certificates or awards with custom designs and recipient-specific information, perfect for educational platforms, event management, or recognition programs.
- Academic and Technical Document Formatting: Streamline the creation of academic papers, research documents, or technical manuals, ensuring consistent formatting, citations, and complex mathematical typesetting.
Why Typst? A Modern Approach to Document Generation
For many years, LaTeX has been the gold standard for high-quality typesetting, particularly in academic and technical fields. However, LaTeX’s steep learning curve, verbose syntax, and often slow compilation times can be a barrier for developers.
Typst emerges as a modern alternative, designed from the ground up to address these challenges while retaining the power and precision expected of a professional typesetting system. When we consider integrating document generation into a Laravel application, Typst offers several compelling advantages:
- Developer-Friendly Syntax: Typst’s markup is significantly more approachable than LaTeX, making it easier for developers to learn and write. This reduces the cognitive load and speeds up development.
- Blazing Fast Compilation: Unlike LaTeX, which can be notoriously slow, Typst boasts near-instant compilation times. For applications requiring on-demand document generation (like invoices or reports), this speed is a critical performance benefit.
- Robust Scripting Capabilities: Typst includes a powerful, built-in scripting language that allows for dynamic content generation and complex layout logic directly within your document. This is particularly useful for integrating data from your Laravel application.
- Modern Tooling and Design: Built with contemporary programming practices, Typst offers a more predictable and enjoyable development experience.
- High-Quality Output: Despite its simplicity and speed, Typst produces professional-quality PDFs, PNGs, and SVGs, ensuring your documents look polished and consistent.
In essence, Typst allows us to achieve the high-quality output of traditional typesetting systems with the developer experience and performance benefits that modern web applications demand. This package bridges the gap, bringing Typst’s capabilities directly into your Laravel workflow.
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.

