Documentation
Getting started
Installation
composer require phppdf/tex-hyphenator
Your first hyphenation
TeXHyphenator is constructed with an array of raw TeX pattern strings. Bundled pattern files for several locales
are included under resources/hyphenation/:
use PhpPdf\Text\TeXHyphenator;
$patterns = file(
__DIR__ . '/vendor/phppdf/tex-hyphenator/resources/hyphenation/en-US.tex',
FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES,
) ?: [];
$hyphenator = new TeXHyphenator($patterns);
$hyphenator->breakWord('hyphenation'); // ['hy', 'phen', 'a', 'tion']
The result is a list of fragments; join consecutive fragments with a hyphen wherever a line break is needed.
Minimum margins
leftMin and rightMin control how many characters must remain before the first break and after the last break,
respectively (TeX defaults: 2 and 3):
$hyphenator = new TeXHyphenator($patterns, leftMin: 3, rightMin: 3);
Bundled locales
| Locale | File |
|---|---|
af-ZA | resources/hyphenation/af-ZA.tex |
en-GB | resources/hyphenation/en-GB.tex |
en-US | resources/hyphenation/en-US.tex |
en-ZA | resources/hyphenation/en-ZA.tex |
es-ES | resources/hyphenation/es-ES.tex |
fr-FR | resources/hyphenation/fr-FR.tex |
nl-NL | resources/hyphenation/nl-NL.tex |
Use with phppdf
use PhpPdf\Builder\TextBox;
use PhpPdf\Text\TeXHyphenator;
$box = TextBox::create($text, $metrics, 12, 200.0, hyphenator: new TeXHyphenator($patterns));