gregwar/tex2png-bundle
A Symfony bundle that converts LaTeX and TeX markup into PNG images via the tex2png library, with caching and Twig helpers for embedding rendered formulas directly in your templates.
composer require gregwar/tex2png-bundle. Because the package is old and lightly maintained (4 stars, no dependents), pin it and check that it resolves against your PHP/Symfony version before committing — Composer may pull a very old release or fail on modern PHP constraints.app/AppKernel.php, add new Gregwar\Tex2pngBundle\GregwarTex2pngBundle(), to the registerBundles() array (or config/bundles.php on Symfony 4+ with a Flex-style shim).latex/pdflatex, dvipng, and ImageMagick's convert on the host, plus a writable cache directory. Nothing will work without them, and the bundle has no pure-PHP fallback.gregwar_tex2png (or gregwar_tex2png_bundle depending on the version) so generated PNGs land in a web-accessible location, e.g. %kernel.root_dir%/../web/tex.{{ '\\frac{a}{b}'|tex2png }}, which returns a URL to a generated PNG. Hit that page once and confirm a file appears in the configured cache directory.Start by reading the bundle's DependencyInjection/Configuration.php and the Twig extension class in the repo — those two files document almost everything the package exposes, and there is little beyond them.
<img>-ready URL from a LaTeX string directly in templates. Use it inline for one-off formulas, but wrap it in your own Twig macro if you need consistent alt, class, or width attributes across the app.dvipng. For any page with repeated formulas (a math quiz, a documentation site), pre-generate during a build or console command and store the resulting URL alongside the formula in your database. Treat the bundle as a build-time tool, not a request-time one.rendered_at / error flag on the entity. When the binary is missing (common on fresh CI images or containers), degrade to displaying the raw LaTeX in a <code> block.texlive + dvipng + imagemagick into the image and mount the cache as a volume, otherwise the cache is lost on every container restart.latex, dvipng, or convert aren't on PATH. Verify with which latex dvipng convert inside the exact user/container that runs PHP, not your local shell.\write18 and shell metacharacters are a real risk. Prefer server-controlled formulas or a strict whitelist of LaTeX commands.texlive package change.gregwar/tex2png) and calling it directly from your own service may be more sustainable than depending on the Symfony bundle wrapper.How can I help you explore Laravel packages today?