background

Durable Laravel Typst

License: MITPHP

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:

Installation

Requirements

To ensure a smooth installation and operation of this package, please verify the following prerequisites:

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:

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:

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.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/my-feature)
  3. Make your changes
  4. Ensure tests pass (composer test)
  5. Commit your changes
  6. Push to your fork
  7. 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

View on GitHub