Download the PHP package agungsugiarto/latex-for-laravel without Composer
On this page you can find all versions of the php package agungsugiarto/latex-for-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download agungsugiarto/latex-for-laravel
More information about agungsugiarto/latex-for-laravel
Files in agungsugiarto/latex-for-laravel
Package latex-for-laravel
Short Description A Laravel package that provides seamless integration between Laravel Blade templates and LaTeX, enabling dynamic PDF generation
License MIT
Homepage https://github.com/agungsugiarto/latex-for-laravel
Informations about the package latex-for-laravel
LaTeX for Laravel
A Laravel package that provides seamless integration between Laravel Blade templates and LaTeX, enabling you to create dynamic PDF documents using familiar Blade syntax while maintaining valid LaTeX structure.
Features
- ๐ฅ Blade + LaTeX Integration: Use Laravel Blade directives within LaTeX templates
- ๐ Valid LaTeX Structure: Templates remain compilable with standard LaTeX compilers
- ๐ฏ Multiple Output Formats: Generate PDFs, download source files, or return content as strings
- ๐ Easy to Use: Simple API with powerful customization options
- โก Pipeline-Based Processing: Clean, extensible compilation using Laravel Pipeline
- ๐ Extensible: Add custom processors and restorers for specialized LaTeX needs
- ๐งช Well Tested: Comprehensive test suite ensuring reliability
Support us
If this package helps you in your projects, consider supporting the development by buying me a coffee on Saweria.
Your support helps maintain and improve this package for the Laravel community. โ๏ธ
Installation
You can install the package via composer:
The package will automatically register its service provider.
Requirements
- PHP 8.1 or higher
- Laravel 10.0 or higher
pdflatex
installed on your system (for PDF compilation)
Quick Start
Create a LaTeX template file resources/views/invoice.blade.tex
:
Use it in your controller:
LaTeX Template Structure
All .blade.tex
files must follow this structure to ensure they are valid LaTeX documents that can be compiled directly while still supporting Laravel Blade directives.
Required Structure
1. Include the \newcommand{\blade}[1]{}
definition
Every LaTeX template must include this command in the preamble:
2. Wrap all Blade directives in \blade{}
All PHP/Blade code must be wrapped in \blade{}
commands. There are three forms of blade directives:
Escaped Output: \blade{{ expression }}
For safe output of variables that should be escaped to prevent LaTeX compilation issues:
Unescaped Output: \blade{!! expression !!}
For raw LaTeX content that should be rendered without escaping:
Literal Content: \blade{content}
For Blade directives, PHP code, and other content that should pass through directly:
Complete Example
Benefits of This Structure
- Valid LaTeX: The file can be compiled directly with
pdflatex
without processing Blade directives - Blade Processing: Laravel can process all
\blade{}
commands to generate dynamic content - IDE Support: LaTeX editors will recognize the file as valid LaTeX and provide syntax highlighting
- Version Control: The files are readable and diffable in version control systems
Pipeline Processing Architecture
The package uses a modern pipeline-based approach for processing LaTeX templates, providing clean separation of concerns and extensibility for custom use cases.
How It Works
The compilation process follows these steps:
-
Blade Directive Processing: Using Laravel Pipeline, the compiler processes different types of
\blade{}
directives:\blade{!! raw content !!}
โ Direct unescaped output\blade{{ expression }}
โ Escaped output (converted to markers, then restored as PHP echo statements)\blade{literal content}
โ Direct literal content (for Blade directives, PHP code, etc.)
-
Blade Compilation: Standard Laravel Blade compilation processes the resulting template
- Marker Restoration: Another pipeline restores any temporary markers to proper PHP code
Built-in Processors
Raw Content Processor
Handles unescaped LaTeX content:
Echo Expression Processor
Handles escaped variable output:
Literal Content Processor
Handles Blade directives and PHP code:
Extending the Pipeline
You can add custom processors and restorers to handle specialized LaTeX needs:
Adding Custom Processors
Adding Custom Restorers
Complete Custom Extension Example
Register the service provider in your config/app.php
:
Usage in Templates
After registering the extension:
API Reference
Compilation Methods
The compile()
method supports various output destinations:
Advanced Usage
Using with Blade Components
Create reusable LaTeX components:
Use in your main template:
Working with Complex LaTeX Structures
For advanced LaTeX documents with multiple processors:
Example Template for Advanced Processors
Error Handling
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Agung Sugiarto
- All Contributors
License
The MIT License (MIT). Please see License File for more information.