PHPackages                             abiturma/laravel-latex - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. abiturma/laravel-latex

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

abiturma/laravel-latex
======================

A LaTeX compiler wrapper for Laravel

2.0.2(1y ago)73.6k↓34.8%MITPHPPHP ^8.1CI passing

Since Jan 8Pushed 1y ago1 watchersCompare

[ Source](https://github.com/koona-labs/laravel-latex)[ Packagist](https://packagist.org/packages/abiturma/laravel-latex)[ RSS](/packages/abiturma-laravel-latex/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (12)Used By (0)

Laravel LaTeX
=============

[](#laravel-latex)

This package compiles Blade views containing LaTeX source code to a pdf file

Requirements
------------

[](#requirements)

You need an installation of a latex compiler (e.g. texlive) on your server. This package is designed for the use with Laravel 10 or newer. Php 8.1 ist required starting from version 2.0.0.

Older Laravel versions
----------------------

[](#older-laravel-versions)

For laravel 8 and 9 use version ^1.3 of this package.

Installation and Setup
----------------------

[](#installation-and-setup)

Install using composer:

`composer require abiturma/laravel-latex`

The Service Provider and the Facade will be installed automatically via laravel package auto-discover.

To publish the config file to config/latex.php run:

`php artisan vendor:publish --provider="Abiturma\LaravelLatex\LatexServiceProvider`

The default configuration looks like so

```
return [
    'temp_directory' => storage_path().'/latex/temp',
    'output' => [
        'disk' => 'local',
        'path' => 'latex/output'
    ],
    'debug' => false,
    'pdflatex' => env('PATH_TO_PDFLATEX','pdflatex')
];

```

With the key `pdflatex` you have to set the absolute path to the pdflatex binary on your server.

Usage
-----

[](#usage)

You can compile a blade view either by calling the Facade `Latex` or by injecting the class `Abiturma\LaravelLatex\LatexToPdf`. Within the documentation we will

### Basic usage

[](#basic-usage)

The class has a fluent interface, which is terminated by a call of `->get()` to start compilation.

You have to pass a blade view together with the data of the view. A standard use case looks like so

```
use Latex

...

$pdf = Latex::view('your.favourite.latex.view')
    ->with(['key' => 'value'])
    ->get()

```

The return value will be a path to compiled pdf. The path is relative to the root directory of the storage disk given in your config file.

```
...

Storage::disk(config('latex.output.disk'))
->exists($pdf) //true

```

### Escaping input

[](#escaping-input)

Since LaTeX has its own syntax it is not advised to use the standard blade syntax `{{ $variable }}` or `{!! $variable !!}`. Instead you can use `@latex($variable)` in your blade templates instead, which handles the suitable escaping of reserved LaTeX characters.

### Multiple runs

[](#multiple-runs)

To enable LaTeX to handle cross references it is sometimes necessary to compile a document multiple times. You can specify the number of runs like so:

```
    Latex::view('myView')->runs($numberOfRuns)->get()

```

The number of runs will be automatically truncated to an integer between 1 and 10.

### Asset Files

[](#asset-files)

Once you use graphics or custom sty-files in your template your compiler needs more than one file. To handle this situation you can call

```
->assets([
    './relative/path/to/one/asset',
    './relative/path/to/another/asset
])

```

on the compiler. This will copy all specified files to the compilation directory. The path is relative to the directory of the view. If absolute paths are needed, set the `absolutePath` flag to `true`:

```
->assets([
    '/absolute/path/to/asset',
    '/absolute/path/to/another/asset
],
true)

```

Very often you have the case, that you want to include all files in the directory of the view as assets. In this case you can simply call `->includeViewFolder()` on the compiler. This will copy all files of the ambient directory of the view in the compilation directory.

After copying the asset files to the compilation directory all blade views are compiled to the according tex files using the variables passed by `->with($data)`.

#### Example

[](#example)

Given the following tree structure

```
views
│
└── myDocument
     │   main.blade.php
     │   package.sty.blade.php
     │   picture.jpg
    ...

```

the command

```
Latex::view('myDocument.main)
    ->with($data)
    ->includeViewFolder()
    ->get()

```

will produce a (temporary) compilation directory of the form

```
temp
│
└── #someHash
     │   main.tex
     │   package.sty
     │   picture.jpg
    ...

```

where `package.sty` is the compiled version of `package.sty.blade.php` using `$data`.

### Using Texables

[](#using-texables)

Instead of calling the Compiler with all the necessary parameters you can also pass a `Texable` class which act similarly like [Laravel Mailables](https://laravel.com/docs/master/mail#generating-mailables).

For creating a mailable run the command `latex:make MyTexable` to create a stub in your view directory.

To compile a Texable run `make::latex(new MyTexable())`. Texables have basically the same methods as the compiler class. Before the latex compiler run, the `->build()` method is run on the Texable. Moreover, all public variables on the Texable are available as data for the given view.

#### Example

[](#example-1)

Say the class `MyTexable` is given by

```
use Abiturma\LaravelLatex\Texable

class MyTexable extends Texable
{
    public $message;

    __construct($message) {
        $this->message = $message;
    }

    public function build() {
        return $this->view('someview')
    }

}

```

then running `Latex::make(MyTexable("someString")` is equivalent to

```
Latex::view('someview')->with(["message" => "someString"])->get()

```

#### Assets

[](#assets)

Besides the `->asset()` method, Texables have more options to handle assets. It is possible to add assets using `->addAsset()`. These methods not only understand absolute and relative paths via the `absolutePath` flag as second argument, they also parse file patterns as glob. So it also possible to add assets like this `->addAsset('*.jpg')`. To exclude file patterns use the method `->excludeAssets($assets)`

### Debugging

[](#debugging)

If the compilation fails a `CompilationFailedException` is raised. By default the exception message contains the truncated compilation log. If `debug` is set to `true` the exception message contains the full compilation log.

### Commands

[](#commands)

#### Testing

[](#testing)

The command `latex:test` runs the compiler on two test files. If the compilation is successful the output paths of the files are printed.

#### Garbage Collection

[](#garbage-collection)

The command `latex:gc` removes all temporary directories and files which were not garbage collected during the compilation process. This might happen, if the process failes before the automatic clean-up process of the compiler kicked in.

If you add the flag `--output` also the given output directory is cleaned. This makes sense if you are used to move the output files after generation to someplace else anyways.

Upgrade/Breaking changes
------------------------

[](#upgradebreaking-changes)

As of version 1.2.0, the `->assets()` method of the LatexToPdf and Texable class now expect paths relative to the view folder instead of absolute paths. For downward compatibility use the `absolutePath` flag as second argument, e.g. `->assets($someLegacyPath, true)`.

Acknowledgements
----------------

[](#acknowledgements)

This project is inspired by [latexcompiler](https://github.com/fvhockney/latexcompiler) by [Vernon Hockney](https://github.com/fvhockney).

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance45

Moderate activity, may be stable

Popularity27

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 80.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~153 days

Recently: every ~180 days

Total

11

Last Release

427d ago

Major Versions

1.3.2 → 2.0.02024-04-08

PHP version history (2 changes)1.1.0PHP ^8.0

2.0.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17247267?v=4)[abiturma](/maintainers/abiturma)[@abiturma](https://github.com/abiturma)

---

Top Contributors

[![abiturma](https://avatars.githubusercontent.com/u/17247267?v=4)](https://github.com/abiturma "abiturma (25 commits)")[![koona-labs](https://avatars.githubusercontent.com/u/124568679?v=4)](https://github.com/koona-labs "koona-labs (6 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/abiturma-laravel-latex/health.svg)

```
[![Health](https://phpackages.com/badges/abiturma-laravel-latex/health.svg)](https://phpackages.com/packages/abiturma-laravel-latex)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[livewire/flux

The official UI component library for Livewire.

9475.0M86](/packages/livewire-flux)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[laravel-zero/framework

The Laravel Zero Framework.

3371.4M369](/packages/laravel-zero-framework)[orchestra/canvas

Code Generators for Laravel Applications and Packages

20917.2M158](/packages/orchestra-canvas)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
