2009-07-23

plain text to PDF via Markdown and Beamer...

...and a little perl in between

My problem is that office software sucks, and presentation software sucks even more.  Too much mousing around needed (and it doesn't matter whether it is OpenOffice or MS Office; I hate them both equally)

All these years, my presentations have consisted of plain text on plain white backgrounds, with hardly any pictures.  I start sweating if I have to make a picture or a chart.  My preferred editor for everything and anything under the sun is vim.  Even my firefox browser is controlled by something called vimperator that lets me use vi keystrokes.

Anyway to cut a long story short, having to make one more presentation sort of broke me.  I'd tried various solutions in the past, but none of them seemed to work, so I finally bit the bullet, learned enough about LaTeX and Beamer to be able to generate input for Beamer, and I had a pretty decent PDF generator that takes HTML.  The HTMLcomes from plain text via Markdown, which is a wiki-like language that I really like.

[If you've never seen a wiki language, it's basically a simplified markup, like using **bold** and *italic* instead of <em>italic</em>, and so on -- the resulting document looks and feels pretty much like plain text when you're editing it, but when you pass it through the Wiki engine (in this case, Markdown), it gets converted to nice HTML].

So, I type in plain text using Markdown's minimalist syntax, Markdown converts it to HTML, I write a little perl program that converts the HTML to LaTeX, and then pass that to Beamer, which produces a really snazzy PDF, with nice colors, slide navigation, etc etc.

Done.

Well not quite.  I was using something similar for images (a package called graphviz).  Graphviz takes text like this:

        digraph {
            node[fontsize=24]
            a -> b -> c -> d
            b -> p -> q -> x
            p -> y
        }

and produces a neat little picture that I can't really show you in a blog post that doesn't seem to like images (well I pasted it at http://imagebin.ca/view/IWKbKYdH.html but that might not last forever).

Anyway now I got really greedy.  Since a lot of the "pictures" I had to make could be done using graphviz, and I was starting to use it more and more, I wanted to have it all in one file.  Text, images, the whole thing in one easy to edit text file :-)

So I did that next.  Made up a nice easy syntax that tells my HTML->LaTeX processor this is inline graphviz code, so it picks it out, runs graphviz on it, and puts the file in /tmp where Beamer picks it up.

[Along the way something amusing happened.  I'd hardly ever used LaTeX before, so everything was new, and at one point I went on to #latex to ask a question.  The helpful folks there (one of them was also a #git guru by the way) bombarded me with information such as TikZ, which contained far too much LaTeX for my taste.  I don't really like LaTeX syntax, though in its own way it's very beautiful and you can write it nicely and all.  [eh?  what's that?  Yes my favourite language is still perl.  Why do you ask?]

I did not have the heart to tell them that I would never directly code LaTeX to save a dying grandmother -- they were so nice and helpful it would seem like trolling.  But I bookmarked the URLs offered anyway, in case I ever change my mind.]

So that's my adventures in PDF making.  If you want to see sample input and output to get a feel for it, email me.

3 comments:

Diviya said...

WoW!

Raj said...

Using TeX for the layout and not the markup - delicious :-). Using visual and horizontal spacing (indentation anyone?) to convey the document structure and meaning seems so natural, doesn't it ;-)? Seems like Perl has become like an old cold romance that you are desperately trying to stoke the flames of.

Anonymous said...

oy...

More often used stuff should be more precisely specified/complexity dealt with. So @^$% in perl is fine, but a backslash-ised version of what amounts to an early, early, vision of XML is NOT!

But more importantly, self-deprecating humour <> self-doubt :-)

sita