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
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): 1. Sb1+ Kb3 2. Qd1+ Rc2 3. Bc1 axb6 4. Ra1 b5 5. Rh1 bxc4 6. Ke1 c3 7. Sg1 f3 8. Bf1 f2.

April 20th, 2008 at 7:54 pm
Nice solution Ivan! I had a look at your script and it’s really simple. Python just glues things together.
April 21st, 2008 at 2:02 pm
Thanks for the comment and the link!