Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Latex Bundle Laravel Package

bobv/latex-bundle

Symfony bundle for flexible PDF rendering via LaTeX. Build .tex documents with an OOP API, compile them to PDF, return PDFs in HTTP responses with one command, and avoid unnecessary recompiles with basic caching.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require bobv/latex-bundle
    

    Enable the bundle in config/bundles.php:

    Bobv\Bundle\LatexBundle\BobvLatexBundle::class => ['all' => true],
    
  2. Basic Configuration (config/packages/bob_v_latex.yaml):

    bob_v_latex:
        binaries:
            latex: '/usr/bin/latex'
            dvipdf: '/usr/bin/dvipdf'
        cache_dir: '%kernel.cache_dir%/latex'
        cache_enabled: true
    
  3. First Use Case: Generate a PDF from a Twig template:

    use Bobv\Bundle\LatexBundle\Generator\LatexGenerator;
    
    $generator = $this->container->get(LatexGenerator::class);
    $pdf = $generator->generateFromString(
        'Hello, {name}!', // LaTeX template
        ['name' => 'World'], // Variables
        'document' // Template name (for caching)
    );
    

Where to Look First


Implementation Patterns

Core Workflows

  1. Dynamic PDF Generation:

    // Generate from a Twig template file
    $pdf = $generator->generateFromFile(
        '@App/latex/templates/example.tex.twig',
        ['data' => 'value'],
        'dynamic_pdf'
    );
    
  2. HTTP Response:

    use Symfony\Component\HttpFoundation\Response;
    
    return new Response(
        $generator->generateFromString('...', ['var' => 'value']),
        200,
        ['Content-Type' => 'application/pdf']
    );
    
  3. Caching:

    # config/packages/bob_v_latex.yaml
    bob_v_latex:
        cache_enabled: true
        cache_ttl: 3600 # 1 hour
    

Integration Tips

  1. Twig Extensions: Use the latex Twig filter for inline LaTeX:

    {{ 'Hello, {name}!'|latex(name) }}
    
  2. Bibliography Support: Configure bibtex binary in config/packages/bob_v_latex.yaml:

    bob_v_latex:
        binaries:
            bibtex: '/usr/bin/bibtex'
    

    Then use in Twig:

    {% latex_bibliography('references.bib') %}
    
  3. Error Handling: Wrap generation in a try-catch:

    try {
        $pdf = $generator->generate(...);
    } catch (\Bobv\Bundle\LatexBundle\Exception\LatexException $e) {
        // Log or handle error
    }
    

Gotchas and Tips

Pitfalls

  1. Binary Paths: Ensure latex/dvipdf paths are correct (use absolute paths). Test with:

    which latex dvipdf
    
  2. Twig 3+ Compatibility: If using Twig 3+, ensure bob_v_latex config includes:

    escaping:
        use_symfony_string: true
    
  3. Caching Quirks:

    • Clear cache manually if templates change:
      php bin/console cache:clear
      
    • Disable caching for development:
      cache_enabled: false
      

Debugging

  1. Log LaTeX Output: Enable debug mode in config/packages/bob_v_latex.yaml:

    debug: true
    

    Logs will show generated .tex and .log files.

  2. Common Errors:

    • "Command not found": Verify binary paths.
    • LaTeX syntax errors: Check .log files in cache_dir.
    • PDF generation fails: Ensure dvipdf is installed.

Extension Points

  1. Custom Elements: Extend Bobv\Bundle\LatexBundle\Element\ElementInterface for reusable LaTeX blocks:

    class CustomElement implements ElementInterface {
        public function render(): string { return '\\customcommand{...}'; }
    }
    
  2. Event Listeners: Subscribe to latex.generate events for pre/post-processing:

    // src/EventListener/LatexListener.php
    public function onLatexGenerate(LatexEvent $event) {
        $event->setContent($event->getContent() . '\\newpage');
    }
    
  3. Symfony Process: Override Bobv\Bundle\LatexBundle\Generator\ProcessGenerator for custom binary handling.


Pro Tips

  • Use latex_preview Twig filter for debugging:
    {{ 'Hello, {name}!'|latex_preview(name) }}
    
  • Batch Processing: Queue PDF generation with Symfony Messenger for long-running tasks.
  • Docker: Include texlive in your Dockerfile for consistent environments:
    RUN apt-get update && apt-get install -y texlive-latex-base dvipdf
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui