PHPackages                             xemlock/php-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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. xemlock/php-latex

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

xemlock/php-latex
=================

LaTeX parser and renderer

v0.1.0(4mo ago)5040.1k↓35.8%6MITPHPPHP &gt;=5.3.0CI passing

Since Jan 13Pushed 4mo ago4 watchersCompare

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

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

php-latex
=========

[](#php-latex)

[![Build status](https://github.com/xemlock/php-latex/workflows/build/badge.svg)](https://github.com/xemlock/php-latex/actions?query=workflow/build)[![License](https://camo.githubusercontent.com/f10af9ac549da2b29b64fa868a93a96196548d7b661f6ab3383260412208ea5f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f78656d6c6f636b2f7068702d6c617465782e737667)](https://packagist.org/packages/xemlock/php-latex)

The main purpose of this library is to provide a valid LaTeX output from, not always valid, user input. You can also render LaTeX code to HTML, with one limitation though - rendering to HTML is done only for the text mode, the math mode needs to be handled by a JavaScript library - in the browser. For this I recommend using [MathJax](https://www.mathjax.org/).

Bear in mind that not every LaTeX command is recognized or implemented. If you happen to need a command that's not supported you can either define it manually (see description below), or file a [feature request](https://github.com/xemlock/php-latex/issues/new/choose).

Installation
------------

[](#installation)

To use php-latex, you install it just as any other php package - with [Composer](https://getcomposer.org/).

```
composer require xemlock/php-latex

```

Usage
-----

[](#usage)

Basic usage is as follows:

### Parsing LaTeX source code

[](#parsing-latex-source-code)

```
$parser = new PhpLatex_Parser();
$parsedTree = $parser->parse($input);
// $parsedTree contains object representation of the LaTeX document
```

### Render parsed LaTeX source

[](#render-parsed-latex-source)

Once you have a parsed source code, you can render it to HTML (or to LaTeX) - please mind that math-mode code is rendered as-is.

```
// render parsed LaTeX code to HTML
$htmlRenderer = new PhpLatex_Renderer_Html();
$html = $htmlRenderer->render($parsedTree);

// render parsed LaTeX code to sanitized LaTeX code
$latex = PhpLatex_Renderer_Abstract::toLatex($parsedTree);
```

### Customization

[](#customization)

You can add custom (or not yet implemented) commands to the parser:

```
$parser = new PhpLatex_Parser();
$parser->addCommand(
    '\placeholder',
    array(
        // number of arguments
        'numArgs' => 1,
        // number of optional arguments, default 0
        'numOptArgs' => 1,
        // mode this command is valid in, can be: 'both', 'math', 'text'
        'mode' => 'both',
        // whether command arguments should be parsed, or handled as-is
        'parseArgs' => false,
        // whether command allows a starred variant
        'starred' => false,
    )
);
```

### pdflatex

[](#pdflatex)

Additionally, this library provides a wrapper for pdflatex to make rendering and compiling `.tex` files from PHP scripts easier.

```
$pdflatex = new PhpLatex_PdfLatex();

// to generate a PDF from .tex file
$pathToGeneratedPdf = $pdflatex->compile('/path/to/document.tex',
    array(/* optional paths to files included by .tex file (images) */])
);
```

You can access the build log of the last `compile` call via:

```
echo $pdflatex->getLog();
```

You can even compile on the fly a LaTeX string:

```
$pathToGeneratedPdf = $pdflatex->compileString('
\documentclass{article}
\begin{document}
Hello from \LaTeX!
\end{document}
');
```

By default, a system temp dir is used for generating PDF from string. You can however customize it:

```
$pdflatex->setBuildDir('/path/to/temp');
```

License
-------

[](#license)

The MIT License (MIT). See the LICENSE file.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance77

Regular maintenance activity

Popularity42

Moderate usage in the ecosystem

Community15

Small or concentrated contributor base

Maturity19

Early-stage or recently created project

 Bus Factor1

Top contributor holds 96.5% 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

Unknown

Total

1

Last Release

125d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/952555?v=4)[Mateusz Turcza](/maintainers/xemlock)[@xemlock](https://github.com/xemlock)

---

Top Contributors

[![xemlock](https://avatars.githubusercontent.com/u/952555?v=4)](https://github.com/xemlock "xemlock (83 commits)")[![larsgw](https://avatars.githubusercontent.com/u/14018963?v=4)](https://github.com/larsgw "larsgw (2 commits)")[![devgaucho](https://avatars.githubusercontent.com/u/119246170?v=4)](https://github.com/devgaucho "devgaucho (1 commits)")

---

Tags

latexlatex-parserphpphp-latex

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/xemlock-php-latex/health.svg)

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

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M170](/packages/hassankhan-config)[meyfa/php-svg

Read, edit, write, and render SVG files with PHP

54613.9M42](/packages/meyfa-php-svg)

PHPackages © 2026

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