Beautiful documents with Markdown, LaTeX and little printers

By Greg Goltsov

Update: After finishing writing this post, I realised I more or less re-impelemnted gimli. Well, let this be an exercise.

This morning I received a delightfully unexpected update from Little Printer -- it's avaialbe for pre-order! Well, £199 is a bit too much for me just now, but it got me thinking.

I was always fascinated by the beatiful documents LaTeX is capable of producing, but there was always too many gotchas to fully use it in a day-to-day basis (I mean, I did, but it was always nagging me that I could've found more things to tweak for further perfection). So I thought if it could be generated from something simpler -- like, Markdown. And, of course, it's a well known problem and it has many solutions.

In the end, I ended up using Kramdown, with quite a few outcomes -- for example my university's maths lecture notes. However, it is still a pain to actually write big documents in Markdown -- it always ends up being a Frankenstein of the two.

So I was using this approach for quite a while, yet it was very hacky and just generally being a simple tool that I didn't have time to improve.

But the release of Little Printer instantly sparked a question -- is it possible to get some great LaTeX typography on that device. What could be possible? So, in a way, it acted as a very effective catalyst, pushing me to finally release what I've been using.

Kramtex

So, today I'm releasing the very basic form of kramtex -- an opinionated wrapper around kramdown with the aim to simplify the creation of LaTeX documents through custom templates.

At the moment, only three templates are provided:

Article

This is a straightforward article class with bare minimum in terms of headers, lists -- everything is straight KOMA-Script.

Try it yourself using ./kramtex -t article text.md

Little Printer

This is a version of the article template, heavily optimised for the form factor of the Little Printer. It respects the non-printable area of the roll (perhaps not as perfectly as it should yet). Lists have been compressed as to take the least amount of space and still look great. Section headers have been stylised according to the published publication design principles. I also spent a while getting the microtype to do its magick, so now it looks quite stunning.

This can really be useful for small passages of text you we going to look over (if you want to write corrections on top of text, replace microtype's final option with draft for extra spacing).

Try it yourself using ./kramtex -t lp text.md

Little Printer To-Do list

Just as a variation on the theme of what can be done, I quickly added a to-do template -- however, I'm sure there's going to be a lot of them around when the printer is released.

Try it yourself using ./kramtex -t lp-todo todo.md

Little Printer code snippets?

This one is still an idea, as I ran out of time today. I do think one of the uses of the printer might be in printing small snippets of code, perhaps small algorithms or just things to annotate.

Implementing a template for that should be pretty straightforward as well -- just customising the listings package to not eat a lot of space and handle wrapping gracefully.

Anything else?

It should be mentioned that LaTeX is all good and stuff, but Little Printer doesn't actually accept PDFs. Now, I was thinking of trying to serve them through pdf.js, but instead I went with the simpler option of just using ImageMagick's convert to output the document in PNG. So, to use that, just append -png option while converting and it'll also give you that. Since the resolution hasn't been announced yet, it's set to 96 DPI.

I must say this is very much work in progress -- the code is still very messy, unoptimised and just bad. This is mostly due to the fact this is the first useful thing I wrote in Ruby, so am still learning. A gem might be coming out soon.

Get the source from GitHub.