chris blogs

February 2005

11feb2005 · TeX in Ruby, part 2

Yesterday, I started (re-)reading “TeX: The Program” and “The TeXbook”. Knuth’s code is very dense and some parts are very optimized. He uses linked lists everywhere, which doesn’t ease rewriting the code in a object-oriented way, as you may guess.

Nevertheless, I started porting the Packager, the part of TeX that “sets the glue”, as printers would say. It replaces the infinite measures of boxes (TeX has three levels of infinity) with concrete values to make them ready for output.

It’s a fairly easy task, actually, as Knuth describes what happens quite well. Nevertheless, I stepped into some traps and only did hpack so far. I expect far more trouble doing linebreaking and alignments, though. The hyphenation part is already done, as TeX::Hyphen (and the comparable, but not file-compatible Text::Hyphen) exists for Ruby. Puh. :-)

I also started writing a PDF generator, which isn’t a trivial task. So far, I use the approach of serializing Ruby structures directly to PDF… we will see how that turns out to work. Austin Ziegler’s PDF::Writer would be an option too, but I haven’t yet looked closer into it.

I had a great time hacking the last days, I don’t think I enjoyed programming like that in the last time.

Oh yeah, one thing… I need a name for it. :-) Mail or comment your ideas.

NP: Pearl Jam & Neil Young—What Happened Yesterday

Copyright © 2004–2016