HyphenationPatterns

Automatic hyphenation using Frank Liang's pattern-matching algorithm — the same approach TeX uses.

A pattern is a fragment such as hy3ph or .in2 whose embedded digits score the inter-letter positions of any word the fragment occurs in. The word is sandwiched between two boundary markers (.), every pattern that occurs as a substring contributes its digits to the overlapping positions, and the highest digit wins each position. Odd final scores mark legal break points; even (and zero) scores forbid a break. A leading/trailing run is additionally protected by leftMin/rightMin so words never break after one letter or before two.

Patterns are stored packed into one space-separated string and parsed lazily into a trie the first time hyphenate runs, so a document that never opts in pays nothing.

Opt in per paragraph via com.conamobile.pdfkmp.style.TextStyle.hyphenation; see Hyphenators for the bundled language sets.

Functions

Link copied to clipboard
fun hyphenate(word: String): List<Int>

Returns the indices inside word before which a hyphen may be inserted, in ascending order. An index i means the word may split as word.take(i) + "-" + word.drop(i). Honours leftMin/rightMin, so the smallest possible value is leftMin and the largest is word.length - rightMin.