in chess, kid, latex

Updated mate-in-one document, now includes chess coordinates

Update: A new updated version of the PDF is available, which includes which side to play.

After a request to have coordinates on the board, to be able to write answers (a really nice idea, especially that Ido begins writing), I noticed I couldn’t do it so easily, because the LaTeX module (chess12) didn’t support that. What a disappointment!

And the only way I had for converting from PGN to TeX was through Scid (still cool, still being developed), but supporting only exports to TeX with chess12 module. Fortunately, Dirk Baechle wrote a tool to convert directly from PGN format to TeX, using his tool pgn2ltx. That tool, written in C++ hasn’t been updated since 2003, so after a small patch to the source, it worked!

And the best part, is that it generates TeX files for the skak module, the best alternative to the old, dead chess12 module.

So, if you wan to generate yourself the PDF, here is my procedure:

  • First, download the pgn2ltx zip file and uncompress it
  • Patch it with the following diff file:
--- pgn2ltx.cpp.ori 2010-12-27 21:06:56.000000000 +0100
+++ pgn2ltx.cpp 2010-12-27 21:07:10.000000000 +0100
/*------------------------------------------------------------- Includes */
#include <iostream>
+#include <cstring>
#include <string>
#include <fstream>
#include <sstream>

In fact, just add the #include <cstring> besides the other includes.

  • Now just compile it (you need g++ and usual compilation tools like make).
  • Download the mate-in-one PGN database I have in my previous article (no way to get the original, the web page we I found it was erased).
  • Generate the TeX file (did I tell you that you need the TeX Live distribution, which includes by default the skak module?) with the following command:
./pgn2ltx  < mate_in_one.pgn  > temp.tex

Now, if you generate your PDF file with that temp.tex file, you’ll get just one diagram per page, and horrible text placement, so I modified the header to remove the useless text and also remove the answers. That makes space for 6 diagrams on each page.

I used this grep command to remove the text:

cat temp.tex |grep -v "White to Move and Mate in One" |grep -v mate | grep -v mainline > temp2.tex

Replace the header with the following :



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

Here is the result, 196 pages of mate in one! (here is the .tex file, if someone is interested)

Note: There are two problems left.

  • First is that when generating the PDF, I get a lot of “Underfull \vbox (badness 10000) has occurred while \output is active“. If a LaTeX expert can take a look…
  • Second problem, I just noticed that some diagrams have the Black mate in one. I thought there were only White mate in one. So there is no way to know whose turn it is. A solution to this is to use a small coloredbox with the side to play. I think the skak module supports it. Some reading in perspective