Drawing chess positions …

… with LaTeX, dvipng, and Python

This is a response to Thomas Guest’s blog post on the same topic.

I’ve tidied up my script for converting FEN format chess positions to PNG files, and I offer it up here: fen2png.py. It’s a Python script, and it requires LaTeX, the LaTeX skak package, and dvipng.

There’s not much more to add. Usage:

fen2png.py [-o filename] <fen>

If [-o filename] is not given, fen2png will use the fen code for the filename, replacing slashes with underscores. For example,

fen2png.py 3Q4/p7/PP3p2/R4P2/1pP2p1P/N3BN2/kr2BK1P/4R3

Produces the file 3Q4_p7_PP3p2_R4P2_1pP2p1P_N3BN2_kr2BK1P_4R3.png, as shown below.

Mark Kirtley
1 Pr The Problemist 1986

3Q4_p7_PP3p2_R4P2_1pP2p1P_N3BN2_kr2BK1P_4R3

S#8

This very nice selfmate in 8 is from John Rice’s Chess Wizardry and was cited in last November’s Problemist Supplement. In a selfmate, white moves first and must force black to give mate.

Here is the solution (in white on white; as before, ā€˜S’ is for Springer = Knight):

2 Responses to “Drawing chess positions …”

  1. Thomas Guest Says:

    Nice solution Ivan! I had a look at your script and it’s really simple. Python just glues things together.

  2. Ivan Says:

    Thanks for the comment and the link!

Leave a Reply