Text processing and typesetting
Problems
- Hyphenation
Find the positions inside a word where it may be split across two lines with a hyphen, by the rules of a language.
intro - Page breaking
Split a sequence of lines, figures and footnotes into pages to minimize a cost of underfull pages, widows, orphans and distance from figure references.
core - Text shaping
Turn a run of characters of one script and font into a sequence of positioned glyphs, applying ligatures, contextual forms, reordering and kerning.
core - Three-way merge
Combine two edited versions of a file with their common ancestor, keeping the changes of both and reporting conflicts where they overlap.
core - Least weight subsequence problem
Choose indices 0 = i0 < ... < ik = n minimizing the sum of w(i_j, i_j+1); line breaking with a concave cost is the main example.
advanced - Table layout problem
Choose a layout for each cell of a table, from its possible width and height pairs, to minimize the table height within a given width; NP-complete in this model.
advanced
Algorithms
- Greedy line breaking
Put as many words on each line as fit and then start a new line. With rigid or shrink-only spaces it uses the fewest lines, but it can leave very uneven lines.
1 languagesintro - UTF-16
Encode each scalar value below 10000 as one 16-bit unit and each larger one as a surrogate pair that carries 10 bits each of the value minus 10000. Surrogates themselves are not encoded.
1 languagesintro - UTF-8
Encode each scalar value in one to four bytes. The count of leading one bits in the first byte gives the length, and each continuation byte starts with the bits 10.
1 languagesintro - Best-fit page breaking
Add lines to the current page and break at the feasible break of least cost seen before the page overflows, without looking ahead.
1 languagescore - Hangul syllable composition
Map each of the 11,172 precomposed Hangul syllables to its leading consonant, vowel and optional trailing consonant jamo by arithmetic on the code point, and back, with no data table.
1 languagescore - Heckel's diff algorithm
Link the lines that occur once in each file, then extend the links to equal neighbors. Expected linear time with hashing; it finds moved blocks, but the diff is not minimal.
1 languagescore - Liang's hyphenation algorithm
Match all hyphenation patterns of a language against the word, take the largest digit at each gap, and allow a break where it is odd.
1 languagescore - Patience diff
Match equal first and last lines, then the lines that occur once in both files by a longest increasing subsequence, and diff each gap between them again.
1 languagescore - Punycode
Encode a Unicode string as ASCII letters, digits and hyphens. The basic characters are copied, and the others are written as sorted insertions with deltas in a variable-length base 36 code.
1 languagescore - Tichy's block move algorithm
Build the target from the fewest copied blocks of the source and added symbols, by taking the longest block of the source that matches at each position.
1 languagescore - Unicode bidirectional algorithm
Give each character of mixed left-to-right and right-to-left text an embedding level by the explicit, weak, neutral and implicit rules of UAX 9, then reverse runs of each line by level.
1 languagescore - Unicode case folding
Map each code point to its folding from CaseFolding.txt, so that strings that differ only in case become equal. Full folding can change the length: ß becomes ss.
1 languagescore - Unicode collation algorithm
Map strings to collation elements with primary, secondary and tertiary weights from a table such as the DUCET, then compare sort keys level by level. Tailorings adapt it to a language.
1 languagescore - Unicode line breaking algorithm
Find the positions where a line may or must break, with the ordered rules LB1 to LB31 of UAX 14 on line break classes. A line breaker then picks some of these positions.
1 languagescore - Unicode normalization algorithm
Normalize a string by full decomposition, a stable sort by combining class inside each run of combining marks, and, for NFC and NFKC, a left-to-right canonical composition.
1 languagescore - Unicode text segmentation
Find grapheme cluster, word and sentence boundaries with the ordered rules of UAX 29 on break properties. Some rules look at long contexts on both sides of a position.
1 languagescore - diff3 algorithm
Merge by diffing the ancestor with each version, splitting the files into stable and unstable chunks, and taking the side that changed in each chunk.
1 languagescore - Chawathe change detection
Turn a node matching of two ordered labeled trees into a least cost script of inserts, deletes, updates and subtree moves that keeps it, in O(n d) time for d misaligned nodes.
1 languagesadvanced - Hirschberg-Larmore algorithm
Solve the least weight subsequence problem with a concave weight in O(n log n) time with a queue of candidates and binary search.
1 languagesadvanced - Histogram diff
Count the old lines of a range, keep the run of equal lines whose rarest line has the lowest count, and diff the parts before and after it again. From JGit; also in Git.
1 languagesadvanced - Hyphenation pattern generation
Learn hyphenation patterns from a hyphenated word list in levels, greedily keeping patterns whose good matches outweigh bad ones at each level.
1 languagesadvanced - Optimal pagination by dynamic programming
Choose all page breaks of a document at once by dynamic programming over break points, with figures placed in order on or after their first reference.
1 languagesadvanced - TeX math layout algorithm
Lay out a formula by turning a math list into boxes recursively, with styles that shrink sub and superscripts and font parameters for their shifts.
1 languagesadvanced - Unicode confusable detection
Map each string to a skeleton by NFD, removal of default ignorable code points and the prototypes of confusables.txt. Two strings are confusable when their skeletons are equal.
1 languagesadvanced - Keiser-Lemire UTF-8 validation
Validate UTF-8 with vector table lookups on the nibbles of each byte and of the byte before it. The authors measured under 0.4 instructions per byte on AVX2 hardware.
1 languagesresearch - Semistructured merge
Merge program versions on their trees of declarations, matching elements by name so that reordered members do not conflict, with line merge inside bodies.
1 languagesresearch - Wilber's algorithm
Solve the concave least weight subsequence problem in O(n) time by applying SMAWK to blocks of the online dynamic program.
1 languagesresearch
Data structures
- Packed trie
A trie whose node arrays are overlapped in one table by first fit, so that sparse nodes share space and lookup stays one index per character.
1 languagesadvanced
Definitions
- Kerning
An adjustment of the space between a specific pair of glyphs, such as A and V, read from a pair table or class table of the font.
intro - Unicode code point
An integer in the Unicode codespace 0 to 10FFFF. Only some code points are assigned to characters, and the scalar values are all code points except the surrogates D800 to DFFF.
intro - Widows and orphans
Lines of a paragraph left alone by a page break: the last line at the top of a page and the first line at the bottom. Names vary; TeX calls the first line a club line.
intro - Badness of a line
A measure of how far a line's glue must stretch or shrink, about 100 times the cube of the adjustment ratio, used in the cost of a line break.
core - Canonical equivalence
Two Unicode strings are canonically equivalent when their full canonical decompositions, with the combining marks in canonical order, are the same. Such strings show the same text.
core - Extended grapheme cluster
The text between two boundaries of the UAX 29 grapheme rules, which a reader sees as one character, such as a letter with combining marks or an emoji ZWJ sequence.
core - Unicode normalization forms
NFD, NFC, NFKD and NFKC pick one string from each class of canonically or compatibly equivalent strings, in decomposed or composed form, so that equal text compares equal.
core
Theorems
- NP-completeness of pagination with figures
Pagination with figures that may change order is strongly NP-complete for the total distance from figures to their references, by reduction from 3-partition.
advanced
Models
- Box, glue and penalty model
A paragraph as a sequence of rigid boxes, stretchable and shrinkable glue, and penalties that mark optional breaks, used by optimal line breaking.
core