Txt2tagsPlusHtmldocEqualsHeaven: When it comes to creating your own books, the best solution is to throw away your word processor and start again.

When it comes to creating your own books, the best solution is to throw away your word processor and start again.

I love the phrase word processor. It’s the second most inaccurate name in the business (the first being Microsoft Works, of course!). They don’t process words at all, and are far more likely to inhibit words than process them. With all those lovely buttons, fonts and margins to fiddle with, it’s just far too easy to spend hours pretending to work without actually putting a single word onto the page. These wonderful apps aren’t word processors, but prevarication processors.

So, what’s the alternative, Grey? Well, I’m glad you asked.

I’ve recently taken the articles over at Save Or Die and gone about converting them to pdfs. The pdf creator module I found for Drupal is ok, but a bit rough-and-ready for my liking. What I needed was a way of taking clean text, applying a minimum of markup and spit out a beautiful .pdf of each issue.

Enter txt2tags and htmldoc. These are two tools I’ve used before to write book length technical documentation, and they’re perfect for any writing needs.

In short, txt2tags can take a minimally marked-up text file and spits out a document in HTML, XHTML, SGML, LaTeX, Lout, Man Page, MoinMoin, Magic Point or PageMaker format. Phew!

htmldoc can take a HTML file, and convert it into a beautifully laid-out .pdf.

Put the two together and you’ve a marriage made in heaven :)

If all that sounds far too geek for you, let’s put it this way:

You type plain text, you get a pdf

There’s no need to worry about fonts, margins or any other that periphery – just use any old text editor, the bare minimum of markup and you’re done.

By minimal, this is all that’s needed. If you need more, the markup is very comprehensive, covering tables, hotlinks and more. No footnotes though, which is a shame.

Here’s a very short bash script which takes the resulting .t2t file, adds a cover image (with a filename of issue1.jpg, issue2.jpg to match the name of the issue[1-2].t2t file) and sends out a formatted .pdf. Along the way it also created a nicely formatted .html file too as an added bonus.

 txt2tags  --css-sugar --style=modern.css -t html $1.t2t
 htmldoc --linkstyle plain --toclevels 1 --titleimage $1.jpg -f $1.pdf $1.html

I call it as

 ./makebook issue1

and it converts issue1.t2t into a .html then converts that into a .pdf with issue1.jpg as the cover. Simple. It’s worth noting that this is Linux, so the file extension doesn’t really matter. Using .t2t is useful though as quite a lot of editors will recognise that extension and use the correct syntax highlighting.

The big advantage to using txt2tags is that you’re working in plain text, so you’re not tied to any application, OS or whatever. Keep your work on a pendrive and you can write anywhere, with anything from notepad upward. Terrific stuff!

To give you a clearer idea of how this works, here’s the .t2t file for Issue1 and the resulting pdf.

Save Or Die Issue 1

Incidentally, it’s just amazing how many spelling errors crept into the articles online. I swear they weren’t there while I wrote ‘em! All of the errors are fixed in the .pdf versions, and I’ll go through and correct the online articles over the next few days. Sheesh.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.