in chess, kid, latex, python

OK, I’m shameful. After fighting with Scid’s exporter, and then correcting bugs in pgn2ltx’s source, I finally decided to take a look at that PGN file format. And guess what? It’s already composed of FEN notation. And guess what? that super-├╝ber cool new skaknew module for LaTeX gets its input as FEN!!

So, if I had a working brain 1 week ago (at least), I would write a small python program that would eat that PGN and make it into a nicely formatted skaknew TeX formatted file!

Here is that much wanted program, that took just 5 minutes to write:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim:syntax=python:sw=4:ts=4:expandtab
import sys,re


\\def\\Metafont{\\mbox{\\logo METAFONT}}

%\\usepackage{geometry} % to change the page dimensions

\\usepackage{fancyhdr} % This should be set AFTER setting up the page geometry
\\pagestyle{fancy} % options: empty , plain , fancy
\\renewcommand{\\headrulewidth}{0pt} % customise the layout...




END_DOC = "\\end{document}"

def main():
    pre = sys.argv[1].split('.',2)[0]
    output_file = open("%s-out.tex" % pre,'w')

    # First, write the header

    expr = re.compile('^\[FEN "([^"]+)"\]')
    for line in open(sys.argv[1]).xreadlines():
        result =
        if result:
            output_file.write(TEMPLATE %


if __name__ == '__main__':

And the best of all, is that I have now full control in its output (well, in my light LaTeX’s knowledge limits). So now I can add a marker to tell which turn it is (little colored square box next to each game). You wll still get 196 pages, that is 1171 mate in one diagrams to solve.

So, to summarize, here are the files: