# Typesetting nested chess variations in Skak

I am hoping to use Skak to typeset my chess notes, and as part of the learning process, I decided to typeset a page from a chess book I own. I got as far as the following before I stumbled.

\documentclass[10pt,twocolumn]{article}

\usepackage{skak}

\begin{document}

\begin{center}
\textbf{Botvinnik -- Smyslov} \\
\textit{World Championship Match (17)} \\
\textit{Moscow 1957} \\
Gr\"{u}nfeld Defence
\end{center}

\newgame
\styleC

\mainline{ 1. Nf3 Nf6 2. g3 g6 3. c4 c6 4. Bg2 Bg7 5. Nc3 O-O 6. d4 d5 7. cxd5 cxd5 8. Ne5 b6}

A satisfactory way of developing.  After \variation{8... Nc6 9. Nxc6 bxc6} Black would be saddled with a weak pawn at c6.

\mainline{9. Bg5 Bb7 10. Bxf6 Bxf6 11. O-O}

In the variation \variation{11. e4 dxe4 12. Nxe4 Bxe5 13. dxe5 Nd7 14. f4 Nc5} Black has a good game.

\mainline{11... e6 12. f4}

If \variation{12. e4 Nc6 13. exd5 Nxe5 14. dxe5 Bxe5 15. dxe6 Bxg2 16. exf7+ Rxf7 17. Kxg2 Bxc3 18. bxc3 Qxd1 19. Rfxd1 Rc8 20. Rd3 Rc4}, and Black can successfully battle for a draw in the rook ending.

\end{document}


I would like to insert the variation (13. Nxc6 Bxc6 14. exd5 exd5) between the half-moves 13. exd5 and 13...Nxe5 of the last line. My first attempt was to use \variations within \variations, but that failed due to a discrepancy in move counts. Then I tried to be clever and spent some time playing with convoluted \hidemoves and \restoregame tricks, but still no luck. Any suggestion as to how I can typeset nested variations?

Try xskak. Be aware that in xskak mainline/variation are handled diffently than in skak. In xskak \mainline is used for moves which should be parsed (where you want to show a board) while \variation is used for moves which are only printed. Both commands can print their moves in "main style" and "variation style" and so you have to be careful with grouping and keys to get the correct style.

\documentclass[10pt,twocolumn]{article}

\usepackage{xskak}

\begin{document}

\begin{center}
\textbf{Botvinnik -- Smyslov} \\
\textit{World Championship Match (17)} \\
\textit{Moscow 1957} \\
Gr\"{u}nfeld Defence
\end{center}

\newchessgame
\xskakset{style=styleC}

\mainline{1. Nf3 Nf6 2. g3 g6 3. c4 c6 4. Bg2 Bg7 5. Nc3 O-O 6. d4 d5 7. cxd5
cxd5 8. Ne5 b6}

A satisfactory way of developing.  After {\variation[invar]{8... Nc6 9. Nxc6
bxc6}} Black would be saddled with a weak pawn at c6.

\mainline{9. Bg5 Bb7 10. Bxf6 Bxf6 11. O-O}

In the variation {\variation[invar]{11. e4 dxe4 12. Nxe4 Bxe5 13. dxe5 Nd7
14. f4 Nc5}} Black has a good game.

\mainline{11... e6 12. f4}

If {\variation[invar]{12. e4 Nc6 13. exd5} (\variation[invar]{13. Nxc6 Bxc6
14. exd5 exd5}) \variation[outvar]{13... Nxe5 14. dxe5 Bxe5 15. dxe6 Bxg2 16.
exf7+ Rxf7 17. Kxg2 Bxc3 18. bxc3 Qxd1 19. Rfxd1 Rc8 20. Rd3 Rc4}}, and Black
can successfully battle for a draw in the rook ending.

\end{document}

• Thank you very much for the answer, and also for writing packages xskak and chessboard. I am sure I will need to use chessboard once I start typesetting notes on corresponding squares. Nov 21, 2010 at 15:49
• There are even more chess related packages available which might be of interest to you. Go to the CTAN website and search on the term "chess".
– DJP
Aug 12, 2011 at 5:59