- Notifications
You must be signed in to change notification settings - Fork3
C++ layouting library inspired by TeX
License
strandfield/typeset
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
libtypeset
is a C++ library that aims at providing an abstract layouting enginesuitable for typesetting complex documents.
The library is heavily inspired byTeX, thetypesetting system designed byDonald Knuth.It currently implements many of the primitives present in the language including boxes,glue, kerns and penalties.
The Qt framework is used to provide some examples of typesetting text.
Albeit being extremely simple, the concepts of boxes and glue turn out tobe also incredibly powerful.They make text justification an easy task while also allowing particularspacing rules out of the box.
The following picture shows how a single line of text can be rendered onpages with different width.First the line is rendered on its ideal page width, then the page width isincreased respectively by 15% and 25%.
Notice how the spacing rules are different after a comma or a period.Here, the interword space increase 50% faster after a comma and 100%faster after a period, hence making the space after a period almost twiceas large as a regular space.
libtypeset
also provides a basic implementation of TeX linebreaking algorithm.This algorithm is used to break a paragraph of text into a series of line.
Unlike a naive algorithm which would consider each line independently,TeX linebreaking algorithm considers the paragraph as a whole to producemore aesthetic results.Indeed, the basic strategy that consists of filling a line with as muchtext as possible and then going to the next line may produce lineswith too few words that will look bad.TeX tries to avoid such situations by sometimes putting fewer words thanpossible on a line to make the next lines look better.The whole process is in fact an optimisation problem: the algorithm triesto minimise a cost (in the context of TeX, this cost is called the demerit).