PHPackages                             dagstuhl/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. dagstuhl/latex

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

dagstuhl/latex
==============

A library for handling LaTeX files (parsing/manipulating/extracting metadata).

2.11.18(5y ago)0161GPL-2.0-or-laterPHPPHP ^8.1

Since Aug 24Pushed 4w ago1 watchersCompare

[ Source](https://github.com/dagstuhl-publishing/latex)[ Packagist](https://packagist.org/packages/dagstuhl/latex)[ RSS](/packages/dagstuhl-latex/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (6)Versions (53)Used By (0)

The Dagstuhl LaTeX project
==========================

[](#the-dagstuhl-latex-project)

This project is a php class framework developed and used by Dagstuhl Publishing for handling LaTeX submissions on the Dagstuhl Submission Server. A large part is about parsing metadata from LaTeX files. Since the metadata information comes as the content of style-specific LaTeX macros (e.g. `\title{...}`, `\author{...}`), or environments (e.g. `\begin{abstract}...\end{abstract}`), we provide...

- some generic (low-level) methods for parsing macros/environments from the LaTeX source code
- a string-conversion support for LaTeX &lt;-&gt; UTF8

(these two may be useful in a wider context) and

- a customizable metadata reader which collects the metadata contained in a LaTeX file and converts it into a structured collection of UTF8-encoded strings.

Dagstuhl Publishing removes all comments from LaTeX files first, so the methods work best with comment-free LaTeX code.

Installation: `composer require dagstuhl/latex`

1. Generic methods for parsing LaTeX files
------------------------------------------

[](#1-generic-methods-for-parsing-latex-files)

To get to know the basic methods, let's have a look at the LIPIcs example file.

```
$latexFile = new LatexFile('/resources/latex-examples/lipics-authors-v2021.1.3/lipics-v2021-sample-article.tex');
```

### Parsing macros

[](#parsing-macros)

The above file contains the macro `\documentclass[a4paper,UKenglish,cleveref, autoref, thm-restate]{lipics-v2021}`specifying the underlying style file and the applied options.

To read out this information in a structured way, just do the following:

```
$documentClass = $latexFile->getMacro('documentclass');

$documentClass->getArgument();
// 'lipics-v2021'

$documentClass->getOptions();
// [ 'a4paper', 'UKenglish', 'cleveref', 'autoref', 'thm-restate' ]
```

If a macro may occur several times, apply `$latexFile->getMacros('...')` and you will get an array of `LatexMacro`-objects

```
$sections = $latexFile->getMacros('section');
$sections[0]->getArgument();
// 'Typesetting instructions -- Summary'
```

If a macro has more than one argument, use the `$macro->getArguments()` method to get its arguments as an array of strings. As an example, take the first author macro from the LIPIcs file:

```
\author{John Q. Public}{Dummy University Computing Laboratory, [optional: Address], Country \and My second affiliation, Country \and \url{http://www.myhomepage.edu} }{johnqpublic@dummyuni.org}{https://orcid.org/0000-0002-1825-0097}{(Optional) author-specific funding acknowledgements}
```

To split it into the different parts, just do:

```
$authors = $latexFile->getMacros('author');
$firstAuthor = $authors[0];
$firstAuthor->getArguments();
// [ 'John Q. Public', 'Dummy University ...', 'johnqpublic@dummyuni.org', ... ]
```

### Parsing Environments

[](#parsing-environments)

To read environments as `LatexEnvironment` objects from a LaTex-file, use `$latexFile->getEnvironment('...');'` or `$latexFile->getEnvironments('...');'`.

E.g. `$latexFile->getEnvironment('abstract')` will read the abstract, while `$latexFile->getEnvironments('figure')` will return the array of all figure-environments.

The contents of an environment (i.e. what is between `\begin{...}` and `\end{...}`) can be catched using the `$environment->getContents()` method.

To get the total LaTeX code of the environment (including the `begin/end`) use `$environment->getSnippet()`.

**Note**: The getter-Methods for macros/environments remove `%...`-like comments from the LaTex file internally. Therefore, the LaTeX snippets they return by the `->getSnippet()` method differ by the comments

2. LaTeX to UTF8 conversion
---------------------------

[](#2-latex-to-utf8-conversion)

Converting metadata from LaTeX files to UTF8 can be arbitrarily complicated, depending on the structure of the underlying LaTeX file and the contents of the string to be converted. In most of the cases, `MetadataString::toUtf8String()` should do the job.

```
$metaString = new MetadataString('Fran\c{c}ois M\"{u}ller-\"{A}hrenbaum recently proved that $a^2 + b^2 = c^2$'.);
$metaString->toUtf8String();
// 'François Müller-Ährenbaum recently proved that a² + b² = c².'
```

(As a second argument the `MetadataString` constructor accepts a LaTex file which will be used to resolve unknown macros.)

The other direction, namely UTF8 to LaTeX, is established by the `Converter` class:

```
Converter::convert('François Müller-Ährenbaum', Converter::MAP_UTF8_TO_LATEX);
// 'Fran\c{c}ois M\"{u}ller-\"{A}hrenbaum'
```

(Note that math environments cannot be reconstructed from the UTF8 code, so this is essentially limited to plain-text conversion.)

3. Metadata-Reader
------------------

[](#3-metadata-reader)

After a style-description php-class (see `src/Styles/StyleDescriptions`) has been configured for a certain LaTeX `documentclass`, the metadata extraction and conversion is as simple as it can be:

```
$reader = $latexFile->getMetadataReader();
$metadata = $reader->getMetadata();
// array of metadata - structured and converted as specified in the StyleDescription file
```

4. Integration into laravel projects
------------------------------------

[](#4-integration-into-laravel-projects)

When used inside a laravel project, the `Storage` class is used for interactions with files. To interact with your LaTeX installation (e.g., via the `LatexCompiler` class), you must add a config file named `config/latex.php`provide the following values:

```
return [
    'paths' => [
        'bin' => env('LATEX_USER_BIN'),   // PATH variable used in default build environment
        'home' => env('LATEX_USER_HOME'), // HOME variable used in default build environment
        'pdf-info-bin' => env('PDF_INFO_BIN'),  // path to your pdf-info binary
        'resources' => env('LATEX_RESOURCES_FOLDER'), // resources folder (in case you want to use your own resources)
    ],
    'styles' => [
        'registry' => \Your\Local\StylesRegistry::class // in case you want to use a custom styles registry
    ]
];
```

Outside a laravel project, write a global `config` function like so:

```
function config(string $key): array
{
    return match($key) {
        'latex.paths.bin' => '/usr/bin:/usr/local/bin',
        'latex.paths.home' => '/path/to/home/of/latex-user',
        ...
    };
}
```

Note: The config keys related to the LaTeX compiler class have changed in version 2.6. The old keys `latex.paths.latex-bin`, `latex.paths.bibtex-bin`, `latex.paths.www-data-path`, `latex.paths.www-data-home` are deprecated (but still supported temporarily by the LegacyProfile, which can be applied by instantiating the compiler class as follows

```
$latexCompiler = new LatexCompiler($latexCompiler, new LegacyProfile());
```

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance61

Regular maintenance activity

Popularity7

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 92.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

Every ~0 days

Total

47

Last Release

2139d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1a3e25acc5299e3d77c48632a2cf5569427fb149ac4458f80c86163858e4f441?d=identicon)[Schloss Dagstuhl - LZI](/maintainers/Schloss%20Dagstuhl%20-%20LZI)

---

Top Contributors

[![mdidas](https://avatars.githubusercontent.com/u/55133075?v=4)](https://github.com/mdidas "mdidas (111 commits)")[![tp971](https://avatars.githubusercontent.com/u/29186351?v=4)](https://github.com/tp971 "tp971 (9 commits)")

---

Tags

metadatalatexLaTeX-to-UTF8 conversion

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M46](/packages/tencentcloud-tencentcloud-sdk-php)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[files.com/files-php-sdk

Files.com PHP SDK

2481.1k](/packages/filescom-files-php-sdk)

PHPackages © 2026

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