Lightweight Markdown-to-PDF converter: pfft

I just released the first version of my new Markdown-to-PDF converter, pfft.  It runs on Linux, at least as far back as Ubuntu 18.04.

Why yet another converter when pandoc and many others already do the job?  Size.  Pandoc uses TeX to generate PDFs.  All the other converters I found use a Web browser in one way or another to make the PDF.  Pandoc is 50 MB by itself, not counting TeX!  In less than 1.2 MB (a 5.25″ floppy 😉 ) and a single file, pfft will do the job.

Of course, there is a catch: pfft uses Pango and Cairo to make the PDFs.  Those have their own dependencies, but are installed on many Ubuntu systems by default!  So pfft itself does not add to the dependency load those systems already carry.

(By the way, I use and appreciate both TeX and Pandoc.  They are great tools!  But, like all tools, there are some use cases they are not great at.  I wanted a small converter, and now I have one! 🙂 )

Please give pfft a try and let me know how it works for you!  And, if you’re planning to do Hacktoberfest this year, know that I am happy to receive pull requests — there’s lots of room for features and polish in pfft.  Check out the issues list for some ideas, and feel free to add suggestions of your own.  Happy hacking!

Generating Roman numerals in Vala

I have recently been learning and enjoying the Vala programming language.  I am writing a lightweight markdown-to-PDF converter and wanted to be able to automatically number list items in Roman numerals.  Here, in case anyone wants it, is Knuth’s algorithm for producing the Roman numeral for a number.  I converted this to Vala from the original WEB source, part of TeX, as quoted by Hans Wennborg.  Enjoy!

string roman(uint num)
{
    // Knuth's algorithm for Roman numerals, from TeX.  Quoted by
    // Hans Wennborg at https://www.hanshq.net/roman-numerals.html.
    // Converted to Vala by Chris White (github.com/cxw42).  CC-BY 4.0 Intl.

    var sb = new StringBuilder();

    string control = "m2d5c2l5x2v5i";
    int j, k;   // mysterious indices into `control`
    uint u, v;  // mysterious numbers
    j = 0;
    v = 1000;

    while(true) {
        while(num >= v) {
            sb.append_c(control[j]);
            num -= v;
        }
        if(num <= 0) {  // nonpositive input produces no output
            break;
        }

        k = j+2;
        u = v / control[k-1].digit_value();
        if(control[k-1] == '2') {
            k += 2;
            u /= control[k-1].digit_value();
        }

        if(num+u >= v) {
            sb.append_c(control[k]);
            num += u;
        } else {
            j += 2;
            v /= control[j-1].digit_value();
        }
    }

    return sb.str;
} // roman()

(not extensively tested — use at your own risk. No warranty. License details here.)