# How to typeset chess series-movers with animated diagrams and solution-lines?

I am trying to use the packages xskak and animate to typeset a PDF of chess problems together with their solutions, and to embed animatable widgets which replay the solutions.

As far as I can make out from the documentation of xskak (and chessboard and skak before it), they assume that White and Black make alternate moves.

In series problems, one player makes a series of consecutive moves. The other player does not make any moves in between. Each move in the series gets a move number. The player is White except in serieshelpmates, where Black plays a move-series, then White mates.

\hidemoves can be used to feed xskak a series of moves -- but only a series alternating white and black. How can I input a series of moves which do not alternate white and black, and have the animation work so that each press of the > ("step forward") button advances the display by one move? (I fear that a solution involving interleaving dummy "moves" in between the real moves would mean that only alternate presses would advance the display, which is not so good.)

It would be nice to be able to feed the chess notation directly all in one command, like

\hidemoves{1. Ra4 2. g4 3. g5 4. g6 5. g7 6. g8=R 7. Rgg4 8. Rgb4#}

Failing that, is there a way to do it by feeding xskak the moves one at a time, then, after each move, telling xskak that the next move is played by white (or black, as the case may be)? I tried various commands as suggested by xskak's documentation, with no success.

I have packages

• xskak v.1.4 (packaged on 13 Jan 2015; documentation 2 Jan 2015),
• skak v.1.5.3 (packaged on 8 Feb 2018; documentation 8 Jan 2018)
• animate (packaged on 10 Apr 2019; documentation 9 Apr 2019)
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[LSBC4,T1]{fontenc}
\usepackage{animate}
\usepackage{chessboard}
\usepackage{xskak}

\setlength{\unitlength}{1mm}

\setboardfontencoding{LSBC4}

\begin{document}

\newchessgame[setfen=8////6R/1k/3K2P]

\hidemoves{1. Ra4}
%\xskakset{player=w} % "2 is not the correct move number."
%\xskakset{moveid=2w} % "2 is not the correct move number."
%\xskakset{stepmoveid=2} % "2 is not the correct move number."
%\xskakset{nextplayer=w} % key doesn't exist
%\xskakset{nextmoveid=2w} % key doesn't exist
%\hidemoves{2. g4}% 3. g5 4. g6 5. g7 6. g8=R 7. Rgg4 8. Rgb4#}

\noindent
\begin{tabular}{cl}
\begin{minipage}[c]{63mm}
\begin{animateinline}[controls]{1}%
\begin{picture}(65,67)
\put(0,6){\chessboard[setfen=\xskakgetgame{initfen}]}%
\end{picture}
\newframe
\xskakloop{%
\begin{picture}(65,67)
\put(0,6){\chessboard[setfen=\xskakget{nextfen}]}%
\end{picture}%
\newframe}%
\begin{picture}(65,67)
\put(0,6){\chessboard[setfen=\xskakgetgame{lastfen}]}%
\end{picture}
\end{animateinline}
\end{minipage}&
\begin{minipage}[c][64mm]{112mm}
\textbf{Erich Bartel}

\textit{feenschach} Jul-Oct 1977, no. 12

ser-\#8
\vfill
3+1
\vspace{7mm}
\end{minipage}
\end{tabular}

Solution: \printchessgame

\end{document}

• skak (and xskak as it is based on skak) certainly asssumes that White and Black make alternate moves, but it should be possible to store the game and reload it and change the player color in this step. I don't have time now, but can try tomorrow. – Ulrike Fischer Jun 8 at 15:47
• I occasionally typeset chess puzzles (see elfsoft2000.com/chess/index.htm) so skak does nothing for me. – John Kormylo Jun 9 at 0:03

skak (and xskak as it is based on skak) asssumes that White and Black make alternate moves, but it is possible to store the game and reload it and change the player color in this step. The following shows an example. There is room for improvement, e.g. to add the last position etc. The A is an id for the series.

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[LSBC4,T1]{fontenc}
\usepackage{animate}
\usepackage{chessboard}
\usepackage{xskak,xparse}

\setlength{\unitlength}{1mm}
\setboardfontencoding{LSBC4}
\ExplSyntaxOn
\NewDocumentCommand\seriesmoves{ m }
{
\int_if_exist:cTF {g__rosie_series_#1_int }
{
\int_gzero:c {g__rosie_series_#1_int }
}
{
\int_new:c {g__rosie_series_#1_int }
}
\group_begin:
\char_set_catcode_other:N \#
\__rosie_seriesmoves:nn { #1 }
}

\NewDocumentCommand\printseriesmoves {m}
{
\int_step_inline:nn { \int_use:c { g__rosie_series_#1_int } }
{
##1.\,\use:c {Xskak.#1##1.\use:c{Xskak#1##1initmovenr}.\use:c{Xskak#1##1initplayer}.san}~
}
}

\cs_new:Nn  \__rosie_seriesmoves:nn
{
\group_end:
\clist_map_inline:nn {#2}{\__rosie_seriesmove:nn{#1}{##1}}
}

\cs_new:Nn\__rosie_seriesmove:nn
{
\int_gincr:c { g__rosie_series_#1_int }
\use:c{@storegame}{tmp}%
\newchessgame[setfen=\use:c{chessgame.tmp},moveid=\int_use:c{ g__rosie_series_#1_int }w,
id=#1\int_use:c{ g__rosie_series_#1_int }
]%
\hidemoves{#2}
}

\newcommand\serieslast[1]{\int_use:c{ g__rosie_series_#1_int }}
\ExplSyntaxOff

\begin{document}

\newchessgame[setfen=8////6R/1k/3K2P]
\seriesmoves{A}{1. Ra4,2. g4,3. g5,4. g6,5. g7,6. g8=R,7. Rgg4,8. Rgb4#}

\noindent
\begin{tabular}{cl}
\begin{minipage}[c]{63mm}
\begin{animateinline}[controls]{1}%
\multiframe{\serieslast{A}}{id=1+1}{%
\xskakset{id=A\id}
\begin{picture}(65,67)
\put(0,6){\chessboard[setfen=\xskakgetgame{initfen}]}%
\end{picture}%
}
\end{animateinline}
\end{minipage}&
\begin{minipage}[c][64mm]{112mm}
\textbf{Erich Bartel}

\textit{feenschach} Jul-Oct 1977, no. 12

ser-\#8
\vfill
3+1
\vspace{7mm}
\end{minipage}
\end{tabular}

\bigskip
\printseriesmoves {A}

\end{document}


• Thank you for your code. Unfortunately I find that the animation does not animate the last move. Is there a way to fix this? – Rosie F Jun 9 at 13:04
• Add the lastfen code from your example. – Ulrike Fischer Jun 9 at 13:23