Chess Puzzles to PDF booklet1
- a collection of PDF files (A4), evtl. for your personal printout as a booklet1,
- some scripts that has been used for its generation, and
- this readme with a description about the PDF compilation.
... was to support myself learning chess.
Starting chess learning at lichess.org which has a good entry point for online-training, I like to have a couple (e.g. ten) of these puzzles as a printout, to take them with me for later offline-walkthrough.
After some googling I found the lichess puzzle database giving us access to lots of the puzzle as a free download of the CSV-formated data.
... to prepare the PDF-collection
- Install a MySQL or MariaDB database, for later accessing the puzzles' data, etvl. plus an apache Webserver, a PHP and the phpMyAdmin - alternatively you may use XAMPP, which has that environment in one package.
- Download the puzzle's CSV-file from lichess puzzle database
- (optionally) split the large file into multiple smaller files with split command, e.g.
split -l 1000 <input-filename>
- Import the CSV-file into your database
- add some columns e.g. for tuning the access to a group of puzzles by its theme. The CSV-file has a column that lists for each puzzle the themes belonging to that puzzle. There are less than 64 themes, so I used the
set
type and made aview
for each theme with the same columns - use the Python script from this repository
generate_theme_puzzles.py
to generate for each theme (that are theviews
in your database) a dedicated subdirectory with ten puzzles' HTML-files- The Python script uses the
python-chess
to parse the FEN2 and UCI moves3 to generate the SVG4 chess board diagrams.
- The Python script uses the
- use
google-chrome --headless
to generate for each HTML-file a PDF-file- e.g.
- for one file:
google-chrome --headless --disable-gpu --print-to-pdf-no-header --print-to-pdf=underPromotion_00001.pdf underPromotion_00001.html
- for multiple files:
ls *.html | awk '{html = $1; gsub(/html/, "pdf", $1); pdf = $0; print "google-chrome --headless --disable-gpu --print-to-pdf-no-header --print-to-pdf=",pdf, html}' | sed -e 's/= /=/g' | while read -r line; do $line; done
wkhtmltopdf
andpython-pdfkit
corrupts my A4 layout; although HTML-files has the CSS@page { size: A4 }
- for one file:
- e.g.
- use
gs
ghostscript for merging / concatination ten puzzle's PDF-files to one puzzle's PDF-file- e.g.
- for all PDF-files of one puzzle:
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=../zugzwang.pdf -dBATCH $(ls -a *.pdf)
- for all PDF-files of one puzzle:
- e.g.
- alternatively to
python-chess
SVG drawing the chessboards, use free chess fonts (chess TTF examples here). Just B/W diagrams may give more contrast; anyway seems that Latex will be best choise for this (see that paper). - documentation of the used database structure and used
import
andalter
scripts - add some manual comments or automatically generated comments to each puzzle's move; e.g. by means of
python-chess
accessing the Stockfish engine - scripts for tasks' automation (with 1.) HTML-->PDF, 2.) merging PDFs, etc.)
- (evtl. for another project) similar script(s) for PGN5 files or a script that takes the FEN2 plus the PGN5 of a match generating such a booklet1.
Footnotes
-
FEN - see Wikipedia Forsyth–Edwards Notation ↩ ↩2
-
UCI - see Wikipedia Universal Chess Interface ↩
-
SVG - see Wikipedia Scalable Vector Graphics ↩
-
PGN - see Wikipedia Portable Game Notation ↩ ↩2