PHPackages                             ismaelw/laratex - 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. [PDF &amp; Document Generation](/categories/documents)
4. /
5. ismaelw/laratex

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

ismaelw/laratex
===============

A package for creating PDFs in Laravel using LaTeX

v1.3.1(1mo ago)12730.1k—2.7%16MITPHPPHP ^8.2CI passing

Since Jul 20Pushed 1mo ago4 watchersCompare

[ Source](https://github.com/ismaelw/laratex)[ Packagist](https://packagist.org/packages/ismaelw/laratex)[ Docs](https://github.com/ismaelw/laratex)[ GitHub Sponsors](https://github.com/ismaelw)[ RSS](/packages/ismaelw-laratex/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (15)Used By (0)

[![Contributors](https://camo.githubusercontent.com/e9fe89a90af31aee3c366b508dba5bf372a97cc478e0cfdcc6176f976f950049/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f69736d61656c772f6c6172617465782e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/ismaelw/laratex/graphs/contributors)[![Forks](https://camo.githubusercontent.com/5e543e5ec2b0de21e9719c77c5e17bcf5a377816daf62bb6c76be09fe065889d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f69736d61656c772f6c6172617465782e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/ismaelw/laratex/network/members)[![Stargazers](https://camo.githubusercontent.com/87605281b3dea2a44db11c1a83706bd6989c431db64b5e6324683a1a452f57ca/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f69736d61656c772f6c6172617465782e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/ismaelw/laratex/stargazers)[![Issues](https://camo.githubusercontent.com/62eaa806fcf40822a2b9034d6a4b37bec8f45e06147f0e0c3265c89e855379a1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f69736d61656c772f6c6172617465782e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/ismaelw/laratex/issues)[![MIT License](https://camo.githubusercontent.com/62141e10af4f6dbe8f92fd5c97df1ee9cbf8b5f5011359898297e16ce9024782/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f69736d61656c772f6c6172617465782e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/ismaelw/laratex/blob/master/LICENSE.md)

 [ ![Laratex](laratex.png) ](https://github.com/ismaelw/laratex)

### LaraTeX

[](#laratex)

 A laravel package to generate PDFs using LaTeX

 · [Report Bug](https://github.com/ismaelw/laratex/issues) · [Request Feature](https://github.com/ismaelw/laratex/issues)

 For better visualization you can find a small **Demo** and the **HTML to LaTeX converter** [here](https://laratest.wismann.ch).

 Table of Contents1. [Getting Started](#getting-started)
    - [Prerequisites](#prerequisites)
    - [Installation](#installation)
    - [Configuration](#configuration)
2. [Usage](#usage)
    - [Dry Run](#dry-run)
    - [Preparing a Laravel View with LaTeX Content](#preparing-a-laravel-view-with-latex-content)
    - [Using the blade directive](#using-the-blade-directive)
    - [Using graphics inside of your LaTeX files](#using-graphics-inside-of-your-latex-files)
    - [Download a PDF File](#download-a-pdf-file)
    - [Save a PDF file](#save-a-pdf-file)
    - [Return the PDF content](#return-the-pdf-content)
    - [Return the PDF inline](#return-the-pdf-inline)
    - [Return the TeX data](#return-the-tex-data)
    - [Using Raw TeX](#using-raw-tex)
    - [Compile multiple times](#compile-multiple-times)
    - [Compile using bibtex](#compile-using-bibtex)
    - [Bulk download in a ZIP archive](#bulk-download-in-a-zip-archive)
3. [Tests](#tests)
4. [Convert HTML to LaTeX BETA](#convert-html-to-latex-beta)
5. [Garbage Collection](#garbage-collection)
6. [Error Handling](#error-handling)
7. [Contribution](#contribution)
8. [Credits](#credits)
9. [Changelog](#changelog)
10. [License](#license)

Getting Started
---------------

[](#getting-started)

### Important information about your environment

[](#important-information-about-your-environment)

This package was developed and tested on Unix (FreeBSD) servers and has been tested successfully on a Windows machine both running pdflatex. Always make sure to write your paths correctly :)

This package makes use of the `storage_path()` function. On Windows it is possible that the absolute path will be written out with backslashes. Windows is really good with paths using both forward &amp; backslashes but just keep this in mind if something doesn't work that well on windows.

### Prerequisites

[](#prerequisites)

You need to have `texlive-full` installed on your server. This program has tex packages and language libraries which help you generate documents. Note: You can also choose to install `textlive` which is the lighter version of the package.

The difference is:

- When you install `textlive` and want to use any additional tex package, you need to install it manually.
- `texlive-full` comes with these extra packages. As a result it may take up some additional space on your server (to store the package library files).

If you are choosing a hosting provider that doesn't allow you to install applications yourself please make sure that pdflatex, xelatex or lualatex is installed or ask if it can get installed. Also make sure that you have SSH access to the server as you might need it to find out in which path your pdflatex installation is sitting.

### Installation

[](#installation)

You can install the package with composer:

```
composer require ismaelw/laratex
```

### Configuration

[](#configuration)

To load the config file with php artisan run the following command:

```
php artisan vendor:publish --tag=config
```

After this please make sure to configure your LaraTeX installation. In your LaraTeX Config file `\config\laratex.php` you can configure these settings:

#### binPath

[](#binpath)

If your system doesn't allow to just run the command line command "pdflatex" you may specify the correct one. On Unix systems you can find out which bin path to use by running the command `which pdflatex`

If you are running this package with on a windows system please check this in cmd.exe before. There you should find out if running the command `pdflatex` works in cmd or if you need to provide the absolute path to your pdflatex application.
If you cannot just run pdflatex you might have to add the path to your pdflatex compiler in your PATH system environment variables.

Change the config or add/change the entry in your `.env` file:
Example: `LARATEX_PATH=/usr/local/bin/pdflatex`

#### bibTexPath

[](#bibtexpath)

If your system doesn't allow to just run the command line command "bibtex" you may specify the correct one. On Unix systems you can find out which bibtex path to use by running the command `which bibtex`

If you are running this package with on a windows system please check this in cmd.exe before. There you should find out if running the command `bibtex` works in cmd or if you need to provide the absolute path to your bibtex application.
If you cannot just run bibtex you might have to add the path to your bibtex compiler in your PATH system environment variables.

Change the config or add/change the entry in your `.env` file:
Example: `LARATEX_BIBTEX_PATH=/usr/local/bin/bibtex`

#### tempPath

[](#temppath)

This specifies the folder where temporary files are saved while rendering a tex file into a PDF file. It is important that you always **start your path without a slash** and **end your path with a slash** (e.g. app/pdf/)

Change the config or add/change the entry in your `.env` file:
Example: `LARATEX_TEMP_PATH=app/latex-temp/`

#### teardown

[](#teardown)

As seen in the section Garbage Collection this package deletes all temp files (log, aux etc.) created while generating the PDF file. When debugging successfully generated PDF files it can be useful to check the generated tex file.
Set this setting to `false` if you don't want LaraTeX to delete those files after generating the PDF.

Change the config or add/change the entry in your `.env` file:
Example: `LARATEX_TEARDOWN=false`

#### timeout

[](#timeout)

You can set the timeout for the pdflatex process. This is useful when generating large PDFs that take longer than the default 120 seconds to compile. The default value is `120`.

Change the config or add/change the entry in your `.env` file:
Example: `LARATEX_TIMEOUT=300` (sets timeout to 5 minutes)

Usage
-----

[](#usage)

### Dry Run

[](#dry-run)

Before diving into the usage directly, it is important that you make sure that the required programs are installed properly on your server. The package comes with a dryrun method. It will automatically generate a file called `dryrun.pdf` if everything is set up properly on the server. If not please double-check the configuration of the `binPath` above.

```
` or `` (Example: `\textbf{}`).

As an addition there is also a `@latex()` Blade directive mentioned in the next chapter.

**Important note when using html characters**

When using the `{{ }}` statement in a blade template, Laravel's blade engine always sends data through the PHP function `htmlspecialchars()` first. This will convert characters like `&` to `&amp;` and `
