TeX's paragraph breaking algorithm

Andrew Kuchling akuchlin at mems-exchange.org
Wed May 16 17:08:56 CEST 2001


My hack of the week: an implementation of the paragraph breaking
algorithm used in TeX, and described in a chapter of Knuth's _Digital
Typography_ book.  

You have an ObjectList class that simulates a list.  After filling the
sequence with a bunch of Box, Glue, and Penalty objects representing a
paragraph, you can get a list of optimal indexes at which line breaks
should be inserted.

http://www.amk.ca/files/python/tex_wrap-1.00.tar.gz

An initial attempt at implementing this failed because I started with
the second, more optimized version given in that chapter, and got
completely confused.  By starting over with the first, simpler and
clearer, outline, I actually managed to get it to work.

If you have an application for the module, please let me know.  I'm
planning to try integrating it into Reportlab in place of the existing
paragraph-breaking algorithm.  A wackier project would be to implement
support for .tfm files and .dvi output, and try using Python as a page
formatting language.

--amk



More information about the Python-list mailing list