xskak: An extension to the package skak
Ulrike Fischer
June 23, 2019

Contents
1. Changes

2

2. Introduction

3

2.1. Warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2. Some history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3. Bugs and errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4. Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.5. Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.6. Loading and package options . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.7. Adaption to the package skak version 1.5 . . . . . . . . . . . . . . . . . . . . . .
2.8. The example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5
6
6
7
7
7
7
8

3. Improved parsing of comments

9

4. The core of the package xskak: Saving games.

10

4.1. Initialization of the game . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.2. Continuing a game . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.3. The stored information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.3.1. Essential game related information . . . . . . . . . . . . . . . . . . . . .
4.3.2. Optional game information: PGN-infos . . . . . . . . . . . . . . . . . . .
4.3.3. The move related data . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4. Exporting the games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5. The inner technique: how the data are stored . . . . . . . . . . . . . . . . . . .
5. Retrieving the stored information

11
15
17
17
19
20
23
24
27

5.1. Setting the variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.2. Getting the game information . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.3. Getting the move information . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.4. Using the data with \chessboard . . . . . . . . . . . . . . . . . . . . . . . . . .

1

27
28
29
30

5.5. Labeling a game . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.5.1. Retrieving the tagged values with \xskakget . . . . . . . . . . . . . . .
5.5.2. The ref-keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6. Looping

31
32
33
34

7. Printing
7.1. \longmoves revisitated38. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.2. An user interface for styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.2.1. Defining style items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.2.2. Defining style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.3. Using the styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.4. The predefined styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.5. The new xskak printing command . . . . . . . . . . . . . . . . . . . . . . . . . .
7.6. Game titles and chessboard captions . . . . . . . . . . . . . . . . . . . . . . . .

38
39
41
42
46
47
48
49

8. PGN2LTX or How to sort the input

49

9. Compability issues
9.1. xskak and texmate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.2. xskak and beamer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

52

52
53

Index

54

1. Changes
2019-06-23 (Version 1.5)] Corrected a bug: \xskak@beforecomment was not defined.
styleA was missing a space. Improved the documentation and added the source
to the ctan upload.
2015-01-02 (Version 1.4)] Corrected a bug: After a promotion the promotionpiece and thefen position were wrong.
2014-04-19 (Version 1.3)] Corrected a bug: enpassant test didn’t check the piece and soother figures than a pawn could make an enpassant move.
2012-08-24 (Version 1.2b) Corrected a small bug – \printchessgame doesn’t wrap arounda wrapfigure.
2012-08-24 (Version 1.2a) Corrected a small bug – \hidemoves printed comment signs.
2008-10-10 (Version 1.2) Made some changes to make the package xskak compatible tothe version 1.5 of the package skak. See below for details.
Changed Code: As \longmoves doesn’t work with \variation anyway \variation
now use always \shortmoves.

June 23, 20192

xskak 1.5

Bug correction: the package skak forgets to store comments after castling moves. Codeto correct this has been added to the package xskak.
Bug correction: the package xskak didn’t print check and mate symbol after castlingmoves due to wrong position of braces.
2008-07-28 (Version 1.1) Bug correction: Added the code for the promotion piece to the
SAN and LAN notation.
Bug correction: Remove some spurious spaces.

2. Introduction
The package xskak1 is an extension for the package skak– and as the package xskak is anextension (and not a replacement) the main work is still done by the package skak so please
read first the documentation of the package skak as I’m not explaining the skak commandsin this documentation.
The package skak is a package from Torben Hoffmann which can parse and print chessgames given in (a subset of ) the PGN notation.
The main features of xskak are:• xskak can handle an extended set of PGN.
• xskak can parse and store an arbitrary number of chess games in PGN. The games canbe exported and imported and all positions and moves can be retrieved at anytime.
• xskak can handle an arbitrary number of printing styles to distinguish the different
variations levels.
Extended PGN handling

When handling a PGN chess parsers at first have to split the notation in different chunks. I
will call this step the PGN parser. As an example
15.Ne5!+ $3 {This breaks the black defense} (15.Re1?

Kg8!)

contains as chunks a move number (15.), a move (Ne5), short move comments (!+), a
NAG ($3), a comment ({This breaks the black defense}) and a variation ((15.Re1?
Kg8!)).
Neither skak nor xskak can handle all legal PGN’s. The package skak can only handle PGN’s
which contains move numbers, moves and short comments. xskak can additionally handle
NAG’s and a special form of comments. None of the packages can currently parse PGN’s
with variations.
1

License: LATEX Project Public License

June 23, 20193

xskak 1.5

Storing moves

After the splitting of the PGN the chunks are processed further. Depending on the type ofthe chunk different actions are taken. The most important subprocess is the move parser. It
takes the move, retrieves from somewhere the current (FEN-)position of the game and tries
to figure out what the move is exactly doing.
In xskak only the commands \mainline and \hidemoves calls the move parser, \variation
uses only the PGN parser.
The main difference between xskak and skak is how they handle the information gathered by
the move parser: The package skak uses the results of the move parser mainly to update theboard and after the move throws almost all other information away – including previous
positions. the package xskak saves all information about the moves for later use. Here asimple example:
1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 4. Ba4 Nf6

rmblkans
opopZpop
6
0Z0Z0Z0Z
5
Z0Z0o0Z0
4
0Z0ZPZ0Z
3
Z0Z0ZNZ0
2
POPO0OPO
1
SNAQJBZR
8\newchessgame\mainline{1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 4. Ba4 Nf6}
\xskakset{moveid=2w}%\chessboard[setfen=\xskakget{nextfen}]\\[1ex]Position after 2.\,\xskakget{lan}

7

a

b

c

d

e

f

g

h

Position after 2. Ng1–f3
So in short you start a game with \newchessgame, you enter moves with \mainline (or\hidemoves), you set the move for which you want to retrieve data with \xskakset, andthen you retrieve the data with \xskakget.
The storing of the moves and positions is not restricted to the main game. You can store andretrieve as much variation levels you want.
Printing styles

The following example shows how to use different styles for different variation levels. But it
also shows the problems: It can be quite tiresome to get a good printing result. You must
pay attention to the levels and the spaces after commands, and for each variation you haveto start a new game and resume older games if you go back to them.

June 23, 20194

xskak 1.5

\longmoves \xskakset{style=UF}\newchessgame[id=main]\mainline{1.e4 e5}%(Alternatives are\newchessgame[newvar=main,id=var1]%\mainline[invar]{1... d5} which is answeredby\mainline{2. exd5 Qxd5}%\newchessgame[newvar=var1,id=var1-1](\mainline[invar]{2... Nf6})%
or\newchessgame[newvar=main,id=var2]\mainline[outvar]{1... e6 2. d4})%
\resumechessgame[id=main]%\mainline[outvar]{2.Nf3}

1. e2–e4 e7–e5 (Alternatives are 1. . . d7–d5 which
is answered by 2. e4Xd5 Qd8Xd5 (2. . . Ng8–f6) or
1. . . e7–e6 2. d2–d4) 2. Ng1–f3

rmblkans
opopZpop
6
0Z0Z0Z0Z
5
Z0Z0o0Z0
4
0Z0ZPZ0Z
3
Z0Z0ZNZ0
2
POPO0OPO
1
SNAQJBZR
8
7

a

b

c

d

e

f

g

h

\chessboard

In the following sections I will describe the finer points. This includes• how to handle more than one game at a time,• how to retrieve the data faster,• what data you can retrieve,• how to loop through a game,• how to export the data,• how to improve the printing of the games,• and some other changes/additions I made to skak.

2.1. Warnings
xskak and skak

The package xskak doesn’t only define some new commands, it also changes some quite
central internal commands of the package skak. This means• it can break standard commands of the package skak,• it will possibly not work together with future versions of the package skak,• loading xskak.sty can lead to problems with packages like texmate which use internallyskak.

June 23, 20195

xskak 1.5

Local and global commands

In the package chessboard almost every setting is local to the board. This was a quite naturaldecision as a board is a confined space. In xskak the situation is quite different: As a startskak already sets and saves some information globally and the data saved by xskak during theparsing must be saved globally or they wouldn’t never escape the \mainline. And secondly,as I wanted to use beamer and animate a lot of data must be preserved from one frame/picture
to the next. So I decided to use in most cases global commands unless – like in the cases ofstyles – I could see a real advantage in keeping a setting local.
So please be aware that settings made e.g. in a figure environment can affect the following
text.

2.2. Some history
While the commands \mainline and \hidemoves parse a chess game the package skak
updates an internal board and so can always show the current position. Sadly a lot of thedata gathered during the parsing are thrown away after skak has updated the board and has
go on to the next move and so can not be used by the user. E.g. there is no way to get thefield a piece came from or to store easily all positions of a game.
Some years ago I tried to find out how to print a game in long algebraic notation and I
realized quite fast that I need some of these lost data to be able to do it, and that it would benecessary to patch some internal commands of the package skak to save the data. At thesame time I also tried to insert some code that allows the parsing of standard PGN-comment
signs. Due to lack of time the whole project didn’t got very far but I had a working beta. Thena new version of the package skak came. It had even a – sadly at the time not fully working –command \longmoves (and the counterpart \shortmoves) to switch to the long algebraic
notation. But I hadn’t the time to test and adjust my package.
Then in 2006 I wrote the package chessboard and during the tests also tried to make animatedpdf’s which show all positions of a game. That worked fine but the input was so tiresomethat I restarted the xskak-project: Like in the case of the long algebraic notation the main
problem was the loss of previous positions.

2.3. Bugs and errors
I’m quite sure that they are bugs and errors in the package.
If you have questions ask them in the newsgroups comp.text.tex, de.comp.text.tex
or fr.comp.text.tex or at http://tex.stackexchange.com/. I’m reading these groups
regularly and I’m much better in answering there than in answering e-mails.
If you find errors in this text (this includes wrong english) or in the package, you canwrite me a bugreport at chess@nililand.de or – better – add an issue to the github site

June 23, 20196

xskak 1.5

https://github.com/u-fischer/xskak/issues/. A bugreport should contain a com-plete, running, minimal example and the log-file of the pdfLATEX run (that means the engine
that makes a pdf!).

2.4. Requirements
The package xskak uses some primitives of eTEX. It needs version 1.4 or version 1.5 of the
package skak, a recent version of the package chessfss (chess font selection) and xkeyval(key=value-syntax), version 1.5 of chessboard (which in turns needs pgf) and xifthen.

2.5. Installation
Run xskak.ins through LATEX and then put the *.sty where LATEX finds them. (<texmf>/tex/latex/xskak/ is a good place.) Update the filename database.

2.6. Loading and package options
Loading of the package is done with \usepackage{xskak}. Currently the package has only
one option: nopdfmatch. The option will disable the use of the experimental \pdfmatch
used in the processing of the style levels (see section 7.3). xskak will load the package skak
without option (and won’t pass options to it). So, if you want to load skak with options, youmust do it before loading the package xskak.

2.7. Adaption to the package skak version 1.5
Above I warned that the package xskak can break with newer versions of the package skak.
When the version 1.5 of skak appeared promptly a lot of things broke so I had to adapt andchange my code. Version 1.2 of the package xskak will work with both versions of the package
skak.
In version 1.5 of the package skak some fundamental things have changed. At first\longmoves works now correctly, even as you can see for the \variation command:

June 23, 20197

xskak 1.5

Example 1: The new longmoves implementation of the package skak\documentclass[12pt]{article}\usepackage{skak}%=skak version 1.5\begin{document}\newgame\longmoves\mainline{1.e4 e5 2.Nf3 Nf6}

1 e2-e4 e7-e5 2 Ng1-f3 Ng8-f6
2. . . d7-d5\variation{2... d5}\end{document}

The more important change (from the point of my package) is that \variation now parsethe moves too (that’s why it can show the long algebraic notation). To achieve this the authorof the package skak, Torben Hoffman, stores now the position before a move so that he cango back to this position and start the variation from there.
The main problem with this approach is that it imposes restrictions on the move numbers ofvariations: All variations must start with the move number of the last move in a \mainline
command. So separating two moves of a variation by some text is no longer possible:\documentclass{article}\usepackage{skak} %=skak version 1.5\begin{document}\newgame\mainline{1.e4 e5 2. Nf3}
\variation{2. d3 d6} %works\variation{2. c3} %works
and then\variation{2...c6} %error\end{document}

To tell the truth, I’m not sure that this a very good idea. In any case: the package xskak overwrites the responsable definitions of the package skak. With the package xskak \variation
currently doesn’t parse games (and so also can’t show moves in long algebraic notation – ifyou want this you will have to start with the commands described later in this documentation a new game with another id). So the above example works fine with the package
xskak.

2.8. The example
Almost all examples use as starting point a new game. But in some cases the following
position is used, which allows to show almost all special cases (like enpassant, promotion,
capture, castling, ambiguous moves). The position is stored under the name “example” and1

June 23, 20198xskak 1.5

so can be retrieved e.g. with the key restorefen=example from chessboard or the command\restoregame{example} of the package skak2 :Example 2: The standard example position
4k2r/2P4p/5n2/3pn1P1/1p2P1B1/7b/P6P/R3K3 w Q- - 0 1\newchessgame[id=example,
castling=Q,
setwhite={pa2,pc7,pg5,ph2,pe4,
ke1,ra1,bg4},
addblack={pb4,ph7,pd5,
ke8,rh8,bh3,nf6,ne5},
storefen=example]%\mbox{\Xskakexampleinitfen}\chessboard

0Z0ZkZ0s
Z0O0Z0Zp
6
0Z0Z0m0Z
5
Z0Zpm0O0
4
0o0ZPZBZ
3
Z0Z0Z0Zb
2
PZ0Z0Z0O
1
S0Z0J0Z0
8
7

a

b

c

d

e

f

g

h

3. Improved parsing of comments
The package skak can handle comments in the input if they follow directly the move, if thecommands are robust and if the spaces that separate moves and numbers are not swallowed
by a command.
Example 3: comments in the package skak\documentclass[12pt]{article}\usepackage{skak} %=skak version 1.5\begin{document}\newgame\newcommand\mycomment{ What else?}\mainline{1.e4!\wbetter{}\mycomment{} e5
2.Nf3 Nc6}\end{document}

1 e4!f What else? e5 2 Nf3 Nc6

This is quite okay for a few small comments in a small number of games, but a bit tiresome if
you want to handle a lot of games that you have annotated with a chess application. The PGN
export of such games uses NAG’s for short comments and curly braces for longer comments.
With the package xskak the commands \mainline, \hidemoves and \variation now canparse NAG’s and longer comments if the input meet the following conditions:• There must be spaces between the moves, each NAG and the comments.
2

One could also use key tag to store the position and key reffen to retrieve it.

June 23, 20199xskak 1.5

• Text comments must be written as \xskakcomment{〈Text〉}3
While parsing the comments the spaces before and between them will be swallowed. If you
want a space you must add it to the text. The NAG’s ($1, $2 etc) are translated following thedefinitions in xskak-nagdef.sty. The list there is neither complete nor definite. For quite
a lot NAG’s I hadn’t the faintest idea what do. I’m open for suggestions/corrections.
There exist two “fake” NAG’s: $d and $D. If used in a \mainline or \hidemoves both will savethe identification of the current move in an internal list and print whatever they have been defined to. (Currently $D will print \chessdiagramname which is defined as \ (Diagram)\ ,$d is empty). This can be used to refer to diagrams printed later.4
Example 4: NAG’s, comments and diagram references in the input\newchessgame[id=GameA]\mainline{1.e4! $2 e5 $D 2.Nf3 Nf6\xskakcomment{ What’s that? }}\renewcommand\xskakcomment[1]{{\itshape #1}}%\mainline{3. Nxe5
\xskakcomment{ I took a pawn! } $D }\variation[invar]{3. Nc3 $4\xskakcomment{ (boring) }}\makeatletter\@for\mymoveid:=\XskakGameAdiagramlist\do{%\xskakset{moveid=\mymoveid}%\begin{tabular}{c}\chessboard[tinyboard,
setfen=\xskakget{nextfen}]\\After move \xskakget{opennr}\xskakget{lan}\end{tabular} }1. e4!? e5 (Diagram) 2. Nf3 Nf6 What’s that?
3. NXe5 I took a pawn! (Diagram) 3. Nc3??
(boring)rmblkans
opopZpop
6
0Z0Z0Z0Z
5
Z0Z0o0Z0
4
0Z0ZPZ0Z
3
Z0Z0Z0Z0
2
POPO0OPO
1
SNAQJBMR

rmblka0s
opopZpop
6
0Z0Z0m0Z
5
Z0Z0M0Z0
4
0Z0ZPZ0Z
3
Z0Z0Z0Z0
2
POPO0OPO
1
SNAQJBZR

8

8

7

7

a

b

c

d

e

f

g

h

After move 1. . . e7–e5

a

b

c

d

e

f

g

h

After move 3. Nf3Xe5

4. The core of the package xskak: Saving games.
The package xskak redefines some internal commands of the package skak to enable\mainline and \hidemoves to store quite a lot5 data about the moves and the state of
the game while parsing the game.
There are two sorts of data: Information related to the game as a whole (e.g. the namesof the players and the start position) and information related to the moves. Both type of3

Braces are so frequent in TEX that is simply not possible to identify the comments simply by looking for abrace – at least not without a lot of complicated hacks.
4
It is not a accidental that there is a similar command “\toD” in texmate. That’s where I got the idea from.
5
Attention: When I say “a lot” I really mean it. Currently about 30 commands for each halfmove is saved plus
about 30 commands for each game. A lot of games with individual game identifications can use a lot ofmemory. But in practice that shouldn’t be a problem as it is seldom necessary to use a lot of different game
identifications.

June 23, 201910

xskak 1.5

information use a 〈GameId〉 in the names of the commands to identify the game they arereferring to, the move data use additionally a 〈MoveId〉.

Exkurs 1

It is important to understand one difference between the use of 〈GameId〉 and 〈MoveId〉:
There is only one command that holds the current 〈GameId〉. The 〈GameId〉 is a concept
specific to the package xskak. The current value 〈GameId〉 is stored in a command and will
be used (and can be changed) by all the commands that store information and by all thecommands that retrieve information. So if you are parsing a game in bits you should be
careful to use the same 〈GameId〉 for each part.
On the other sides there are three different places where move data are set or used: thepackage skak uses in \mainline and \hidemoves a counter called “move” and a boolean tokeep track of the current move and player. The package xskak has two internal commands
which are used to set up the start moves of games and to retrieve the stored move data,
and \chessboard has two keys that set move data in FEN’s. This can be sometimes a bit
confusing. The package skak will not like it if its move counter is changed while parsing agame, but it is normally not a problem to change the xskak move commands e.g. to retrieve
data about previous moves – as long as you don’t use commands like \newchessgame that
affects also the skak move counter.

Exkurs 2

In chess we speak quite as often about the last move and the last position than about thenext move and the next position: A position can be described as the one after the last move,the result of a move. But it can also be described as the one before the next move.
The keys and commands described later reflect this: Given a move number you can accesse.g. the position before the move through the key word pastfen and the position after themove through the key word nextfen. Given a tag – that is a label between two moves, you
can refer to the move before the tag through keys with the prefix past and to the move after
the tag through keys with the prefix next.
In short: past looks back and next looks forward.
The first position of a game and the first move have the prefix init. The last position (after
the last move) and the last move have the prefix last.

4.1. Initialization of the game\newchessgame

When using the package xskak you should start a new game with \newchessgame[〈key=value

June 23, 201911

xskak 1.5

list〉] instead of \newgame. It will set the identification 〈GameId〉 of the game, the start
position, start move and quite a lot of other variables to sensible values.
In the optional argument you can use the following keys:
id=〈GameId〉 This key sets the string that identifies the game and is used in the following

parsing commands to store the data. It is possible to use commands and counterse.g. for automatic numbering of the games. If you don’t use the key or if you use thekey without argument (\newchessgame[id]) a default is used. The initial value of thisdefault is game, but it can be changed with \xskakset. You can use the key id in each\newchessgame only once.
\newchessgame[white=Bob]%\mainline{1. e4 e5}\newchessgame[id=MY,white=Bill]%\mainline{1. e4 e5}

1. e4 e5

\newcounter{gamecounter}%\stepcounter{gamecounter}%\xskakset{defaultid=Game\Alph{gamecounter}}%

1. e4 e5
1. e4 e5

\newchessgame[white=Harry]%\mainline{1. e4 e5}

1. d4 d5
Bob, Bill, Harry, Thomas\stepcounter{gamecounter}%\newchessgame[white=Thomas]%\mainline{1. d4 d5}\Xskakgamewhite, \XskakMYwhite,\XskakGameAwhite, \XskakGameBwhite%

movenr=〈number〉, player=〈“w” or “b”〉, moveid=〈number + “w” or “b”〉 With this keys you
can change the start move for the parsing commands \mainline and \hidemoves.
Setting this keys will change the counter and boolean of skak and the internal commands of xskak. The changes are global. Default is moveid=1w, this default can bechanged with \xskakset. Move number and player given through one of the FEN-keysof \chessboard will not affect the move counter of skak!
\newchessgame\mainline{1. e4}\newchessgame[moveid=4w]\mainline{4. e4 e5}

1. e4
4. e4 e5\xskakset{defaultmoveid=5b}\newchessgame\mainline{5... c4}\xskakset{defaultmoveid=1w} %back to normal

June 23, 2019

5. . . c4

12xskak 1.5

newvar=〈GameId〉 If you use this key \newchessgame will use the position and the 〈moveid〉

before the last move of the game 〈GameId〉 as start position. If you don’t give a value
the current meaning of 〈GameId〉 is used. This can be used to start variations. The
new game inherits only the start position of the reference game!
ref...=〈tag〉 The 〈GameId〉 and the start move can also be set with keys which use values
saved with a tag. The keys are described in section 5.5.

keys to set PGN-infos With the keys result, white, black, whiteelo, blackelo, site,date, event and round you can store the content of the PGN-infos. Unused keys
are set to default values. These defaults can be changed with \xskakset.
With \xskaknewpgninfo[〈default value〉]{〈keyname〉} you can define a own PGNinfo key. This will also define a key default〈name〉 to change the default value later.

\xskaknewpgninfo\xskaknewpgninfo[Tom]{commentary}\newchessgame[white=Harry,date=2007]\xskakgetgame{white}, \xskakgetgame{date},\xskakgetgame{event},\xskakgetgame{commentary}

Harry, 2007, , Tom\xskakset{defaultevent=My open}

Mller, My open

\newchessgame[commentary=Mller]\xskakgetgame{commentary},\xskakgetgame{event}using chessboard keys You can use any key that can be used in the optional argument of\chessboard from the package chessboard. \newchessgame will pass all keys to aninternal \chessboard6 . \chessboard will set a position and give it back as the start
position for the game. All chessboard keys are processed normally. You can even print
directly the board by using the key print. The only exceptions7 are the keys maxfieldand zero that change the size of the board – skak doesn’t like unusual sizes of theboard – and the keys mover and fullmove which are overwritten by the (eventually
default) value of key moveid. The castling possibilities and the enpassant field are set
accordingly the values in the default fen, you only need to set them if you want to use
other values. Read the documentation of chessboard for more information.

6
7

That’s why you will get an error from \chessboard if you use an unknown key.
They don’t gives error but they will have no effect.

June 23, 201913

xskak 1.5

0Z0ZkZ0s
Z0O0Z0Zp
6
0Z0Z0m0Z
5
Z0Zpm0O0
4
Po0ZPZBZ
3
Z0Z0Z0Zb
2
0Z0Z0Z0O
1
S0Z0J0Z0
8
7\newchessgame[moveid=4b,print,
showmover,mover=w,% has no effectcastling=Q,enpassant=a3,
setwhite={pa4,pc7,pg5,ph2,pe4,ke1,ra1,bg4},
addblack={pb4,ph7,pd5,ke8,rh8,bh3,nf6,ne5}]%

a

b

c

d

e

f

g

h

0Z0ZkZ0s
Z0O0Z0Zp
6
0Z0Z0m0Z
5
Z0Zpm0O0
4
0Z0ZPZBZ
3o0Z0Z0Zb
2
0Z0Z0Z0O
1
S0Z0J0Z0
4. . . bXa3
8\mainline{4... bxa3}\chessboard

7

a

b

c

d

e

f

g

h

To use a position of another game as a start position you can use e.g. this sequence of keys(a shorter method that use a label/ref-method will be described in the section 5.5):\newchessgame[id=〈old id〉, moveid=〈old move id〉,
setfen=\xskakget{〈nextfen|pastfen〉},
id=〈new id〉, moveid=〈new initmove id〉]

Attention: A new game is a new game. It doesn’t inherit moves of another game – it only
reuses a position. So if the new and the old game have identical 〈GameId〉 then the old game
will be more or less lost.
In case that you want to go one half move back and start a new game from there you can use
the key newvar:\newchessgame[newvar=〈old id〉, id=〈new id〉]

June 23, 201914

xskak 1.5

1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 4. Ba4 Nf6 5. O-O\newchessgame[id=A]%\mainline{1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 4.
Ba4 Nf6 5. O-O}
\newchessgame[
id=A,moveid=3w,print,
setfen=\xskakget{nextfen},%fen after move 3w
id=B,moveid=1b]\mainline{1... Nf6}
\newchessgame[id=C]\mainline{1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 4.
Ba4 Nf6 5. O-O}
\newchessgame[print,
id=C,% we retrieve the number of the last move% of game C and set it as first number% of the new game B at the same time:
moveid=\xskakgetgame{lastmoveid},
setfen=\xskakget{pastfen},
id=B]\mainline{5. d3}\resumechessgame

rZblkans
opopZpop
60ZnZ0Z0Z
5ZBZ0o0Z0
4
0Z0ZPZ0Z
3
Z0Z0ZNZ0
2
POPO0OPO
1
SNAQJ0ZR
8
7

a

b

c

d

e

f

g

h

1. . . Nf6
1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 4. Ba4 Nf6 5. O-O

rZblka0s
ZpopZpop6
pZnZ0m0Z
5
Z0Z0o0Z0
4
BZ0ZPZ0Z
3
Z0Z0ZNZ0
2
POPO0OPO
1
SNAQJ0ZR
8
7

a

b

c

d

e

f

g

h

5. d3

4.2. Continuing a gameThe package skak doesn’t have a problem if you split a game in pieces. You can use as
many \mainline commands as you want. It even doesn’t matter if you started the gamein another group. But if you mix two games you must first reset the position and the movecounter to the end position of the old game before you can continue it. This is possible
with \resumechessgame[〈key=value list〉]. You can use \chessboard-keys in the optional
argument but all the keys that tries to change the position will have no effect. It is also notpossible to store the new moves under a new game identification or to renumber the moves.
The command accepts the following additional keys in the optional argument:
id=〈GameId〉 This key identifies the game that should be continued (as a default the cur-rently active identification is used). The key changes 〈GameId〉 globally!
movenr=〈number〉, player=〈“w” or “b”〉, moveid〈number + “w” or “b”〉 This keys set themove from which on the game should be restarted. With the keys it is possible to go
back and then continue the game along another variation (in this case the moves ofJune 23, 201915

xskak 1.5

the first variation will be lost). The values describes the next move that means the
position before the move is used. As a default \resumechessgame continues the game.
\newchessgame[id=main]\mainline{1. e4 e5 2. Nf3 Nc6 3. Bb5}
That reminds me another gamesome years ago where I played\newchessgame[id=exkurs]\mainline{1. d4 Nf6 2. c4 e6}\ldots\ lots of text \ldots\
Let’s continue the second game with -as a reminder -- the last move of
black\resumechessgame[id=exkurs,moveid=2b]%\mainline{2... e6 3. Nc3}
Let us now go back to the first game\\\resumechessgame[id=main,print,
tinyboard,showmover]%\mainline{3... a6}

1. e4 e5 2. Nf3 Nc6 3. Bb5
That reminds me another game some years
ago where I played 1. d4 Nf6 2. c4 e6 . . . lotsof text . . .
Let’s continue the second game with – as a reminder – the last move of black 2. . . e6 3. Nc3
Let us now go back to the first gamerZblkans
opopZpop
60ZnZ0Z0Z
5ZBZ0o0Z0
4
0Z0ZPZ0Z
3
Z0Z0ZNZ0
2
POPO0OPO
1
SNAQJ0ZR
8
7

a

b

c

d

e

f

g

3. . . a6hnewvar=〈GameId〉 This key moves you one halfmove back. This can be used to write down

a lot of variations. With the (optional) value of the key you set the 〈GameId〉. If you
don’t give a value the current meaning of 〈GameId〉 is used.

June 23, 201916

xskak 1.5

1. e4 e5 2. Nf3 Nc6 3. Bb5
1. d4 Nf6 2. c4 e6
3. Bc4\newchessgame[id=main]\mainline{1. e4 e5 2. Nf3 Nc6 3. Bb5}rZblkans
opopZpop
60ZnZ0Z0Z
5
Z0Z0o0Z0
4
0Z0ZPZ0Z
3
Z0M0ZNZ0
2
POPO0OPO
1
S0AQJBZR
3. Nc38
7\newchessgame[id=exkurs]\mainline{1. d4 Nf6 2. c4 e6}\resumechessgame[newvar=main]\mainline{3. Bc4}a\resumechessgame[newvar]\mainline{3. Nc3}
\chessboard

b

c

d

e

f

g

h

rmblka0s
opZpopop
6
0Z0Z0m0Z
5
Z0o0Z0Z0
4
0ZPO0Z0Z
3
Z0Z0Z0Z0
2
PO0ZPOPO
2. . . c5 1 SNAQJBMR
8\xskakset{id=exkurs}\resumechessgame[newvar]\mainline{2... c5}\chessboard

7

a

b

c

d

e

f

g

h

ref...=〈tag〉 The 〈GameId〉 and start move can also be set with this keys which use values
saved with a tag. The keys are described in section 5.5.

4.3. The stored information
The following lists describes all the types of information stored during the parsing of a game.
As you will see some data are stored more than once with only slight differences. I did it
because it is easier to store the redundant data than to have to convert them later.
There are also commands which contains the 〈GameId〉 and the 〈MoveId〉. That looks a bit
senseless as you need to know this values to be able to retrieve them but they allow easy
access to the values without having to know or use the internal command names.

4.3.1. Essential game related information\Xskak〈GameId〉initfen The position before the first move. Set by \newchessgame.

June 23, 201917

xskak 1.5

\Xskak〈GameId〉initplayer “w” or “b”. The color of the next (first) player, (must be identicalto the color in the initfen). Also set by \newchessgame.
\Xskak〈GameId〉initmovenr The number of the first move (must be identical to the fullmove number in the initfen). Also set by \newchessgame.
\Xskak〈GameId〉initmoveid Combination of initmovenr and initplayer.

0ZKZ0Z0Z
j0Z0Z0Z0
6
0Z0Z0Z0S
5
Z0Z0Z0Z0
4
0Z0Z0Z0Z
3
Z0Z0Z0Z0
2
0Z0Z0Z0Z
1
Z0Z0Z0Z0
8\newchessgame[id=show,
setfen=2K/k/7R,
moveid=10b,
print]

7\mbox{\xskakgetgame{initfen}},\\\xskakgetgame{initplayer},\xskakgetgame{initmovenr},\xskakgetgame{initmoveid}

a

b

c

d

e

f

g

h

2K5/k7/7R/8/8/8/8/8 b KQkq - 0 10,
b, 10, 10b\Xskak〈GameId〉lastfen The fen after the last move, set during parsing.
\Xskak〈GameId〉lastplayer “w” or “b”. The player which made the last move, set by\newchessgame, by \resumechessgame and during parsing. Identical to color in thefen before the last move! Not identical to the color in \Xskak〈GameId〉lastfen!
\Xskak〈GameId〉lastmovenr The number of the last move, set during parsing. Identical tofullmove in the fen before the last move! Not necessarily identical to the number in\Xskak〈GameId〉lastfen!
\Xskak〈GameId〉lastmoveid Combination of lastmovenr and lastplayer.
10. . . Ka8\newchessgame[id=show,
setfen=2K/k/7R,
castling={},% sets correct castling in the FEN
moveid=10b]\mainline{10... Ka8}kZKZ0Z0Z
Z0Z0Z0Z0
6
0Z0Z0Z0S
5
Z0Z0Z0Z0
4
0Z0Z0Z0Z
3
Z0Z0Z0Z0
2
0Z0Z0Z0Z
1
Z0Z0Z0Z087\chessboard\mbox{\xskakgetgame{lastfen}},\\\xskakgetgame{lastplayer},\xskakgetgame{lastmovenr},\xskakgetgame{lastmoveid}

a

b

c

d

e

f

g

h

k1K5/8/7R/8/8/8/8/8 w - - 1 11,
b, 10, 10b

June 23, 201918

xskak 1.5

\xskaknewpgninfo\Xskak〈GameId〉nextplayer “w” or “b”. The player which will make the next move, set by\newchessgame, by \resumechessgame and during parsing. Identical to the color in\Xskak〈GameId〉lastfen.
\Xskak〈GameId〉nextmovenr The number of the next move, set during parsing. Identicalto fullmove in \Xskak〈GameId〉lastfen.
\Xskak〈GameId〉nextmoveid Combination of nextmovenr and nextplayer.
10. . . Ka8\newchessgame[id=show,
setfen=2K/k/7R,
moveid=10b]\mainline{10... Ka8}kZKZ0Z0Z
Z0Z0Z0Z0
6
0Z0Z0Z0S
5
Z0Z0Z0Z0
4
0Z0Z0Z0Z
3
Z0Z0Z0Z0
2
0Z0Z0Z0Z
1
Z0Z0Z0Z087\chessboard\xskakgetgame{nextplayer},\xskakgetgame{nextmovenr},\xskakgetgame{nextmoveid}

a

b

c

d

e

f

g

h

w, 11, 11w\Xskak〈GameId〉diagramlist A comma separated list of moves (a combination of movenr
and player), (e.g. 3b,20w). Records the moves with an $d or $D after the move. See
section 3.
\Xskak〈GameId〉gameid This command holds the game identification (the value is equal
to the value of 〈GameId〉).
\newchessgame[id=game\arabic{section}]
The id of the current game is \xskakgetgame{gameid}

The id of the current game is game4

4.3.2. Optional game information: PGN-infos

The following commands store various optional information which are normally stored
in the so-called PGN-infos. You can set them in \newchessgame and retrieve them later.
New PGN-infos can be defined with the \xskaknewpgninfo[〈default〉]{〈name〉}. With the
exception of “result” all currently defined commands are empty by default.
\Xskak〈GameId〉result Default is *, value should be 1-0, or 1/2-1/2, 0-1 or something likethat.
\Xskak〈GameId〉white The name of the white player.
\Xskak〈GameId〉black The name of the black player.
\Xskak〈GameId〉whiteelo The elo of the white player.

June 23, 201919

xskak 1.5

\Xskak〈GameId〉blackelo The elo of the black player.
\Xskak〈GameId〉site The site of the tournament.
\Xskak〈GameId〉event The name of the tournament.
\Xskak〈GameId〉date The date of the game.
\Xskak〈GameId〉round The round of game.

4.3.3. The move related data

The move data are stored during the parsing of a game with \mainline and/or \hidemoves.
You can split the game in as much pieces as you want but you must start a game with
\newchessgame and you must use the same game identification for each piece if you don’t
want to end with broken games.
All values depends on the parsing from the package skak which in turn depends heavily on
the correct input: the package skak knows a bit about the position of the game (it needs it
e.g. to find out where a piece came from) but doesn’t analyze it thoroughly. The main work
is done by analyzing the notation e.g. the package skak will recognize a check by the +-sign.
Quite often the package skak doesn’t recognize illegal moves or wrong input syntax (e.g. 0-0
for casting instead the correct O-O) but fails some moves later or shows a wrong position:

rmblkans
opopZpop
6
0Z0Z0Z0Z
5
Z0Z0o0Z0
4
0Z0O0Z0Z
3
Z0Z0Z0Z0
2
POPZPOPO
1
1. d4 e5 2. Bc4
SNAQJBMR
8
7\newchessgame\mainline{1.d4 e5 2.Bc4}\chessboard

a

b

c

d

e

f

g

h

The following types store the piece which was moved and the piece that was
perhaps captured. The variants differ in the storing of black pieces and pawns:a). Piece data

pgnpiece K,Q,R,B or N. Is empty for pawn and castling moves.
piecechar K,Q,R,B,N or p. Is empty for castling.
piece K,Q,R,B,N or P or k,q,r,b,n or p (for black). Is empty for castling.
pgnlostpiece In case of a capture move: K,Q,R,B, or N.

June 23, 201920

xskak 1.5

lostpiecechar In case of a capture move: K,Q,R,B,N or p, empty else.
lostpiece In case of a capture move it stores the lost piece as K,Q,R,B,N or P or k,q,r,b,n or p.

b). Move data

movefrom The field were the piece came from. Two fields in case of castling moves e.g.
“e1,h1”.
pgnmovefrom This contains the additional “movefrom” information in the PGN for ambiguous moves or pawn captures. E.g. In case of eXd5 the value is “e”, in case of Nbd2
it is “b”.
moveto The field were the piece move to. Two fields in case of castling moves e.g. “g1,f1”.
enpassant Sets the boolean xskakboolenpassant to true if the move was an enpassantcapture.
enpassantsquare A field, after e.g. e4 the value is e3. Indicates if the next pawn move canbe an enpassant capture.

\newchessgame[restorefen=example]\mainline{1. a4 h5}\chessboard[lastmoveid,
pgfstyle=border,
color=red,
markfield=\xskakget{enpassantsquare},moveid=1w, color=blue,
markfield=\xskakget{enpassantsquare}]

0Z0ZkZ0s
Z0O0Z0Z0
6
0Z0Z0m0Z
5
Z0Zpm0Op
4
Po0ZPZBZ
3
Z0Z0Z0Zb
2
0Z0Z0Z0O
1. a4 h5 1 S0Z0J0Z0
8
7

a

b

c

d

e

f

g

h

castling Sets the boolean xskakboolcastling, is true for short *and* long castling!
longcastling Sets the boolean xskakboollongcastling.
capture Sets the boolean xskakboolcapture.
promotion Sets the boolean xskakboolpromotion.
promotionpiece Q,R,B or N or q,r,b or n or empty.
promotionpiecechar Q,R,B or N or empty.

June 23, 201921

xskak 1.5

\newcommand\testpromotion{%\xskakget{promotion}%\ifthenelse{\boolean{xskakboolpromotion}}{A pawn promoted to\figsymbol{\xskakget{promotionpiecechar}}}{No promotion in this move}}\newchessgame[restorefen=example]\mainline{1. c8=Q+ Ke7}

1. c8Q+ Ke7
A pawn promoted to Q
No promotion in this move

\xskakset{moveid=1w}\testpromotion\xskakset{moveid=1b}\testpromotionc). Other data/combinations

addpieces contains the (list of) piece(s) that should be put on the board.
E.g. {kg8,rf8} in case of black short castling.
clearfields The list of fields that should be emptied on the board (equal to the movefrom
field with the exception of enpassant moves).
nextfen The fen position after the current move.
pastfen The fen position before the current move (identical to the fen after the previousmove).
san The standard algebraic notation of the move. It use chess commands: E.g.
\textsymfigsymbol{R}a2 for Ra2
e\capturesymbol d5 for eXd5,\castlingchar\castlinghyphen\castlingchar for O-O
It contains also the signs for chess and mate, but not the comments.
lan Long algebraic notation of the move, similar to san.
\newchessgame\mainline{1.f3 e5 2. g4?? Qh4+#!}

1. f3 e5 2. g4?? Qh4+m!

\xskakset{moveid=2w}%\xskakget{san}, \xskakget{lan}g4, g2–g4

Qh4+m, Qd8–h4+m\xskakset{moveid=2b}%\xskakget{san}, \xskakget{lan}opennr This contains the code to print the number like the package skak would do it if you
start or continue a game with this move. The style must be set independantly eitherwith a \styleX of skak or – if you use the new interface of xskak to set a style – with\xskakset and \mainlinestyle or \variationstyle.

June 23, 201922

xskak 1.5

xskakexportgames\newchessgame\mainline{1.e4 e5}\xskakset{moveid=1w}%\xskakget{opennr}\xskakget{lan},{\styleB\mainlinestyle\xskakget{opennr}\xskakget{lan}}

1. e4 e5
1. e2–e4, 1. e2–e4\xskakset{moveid=1b}%\xskakget{opennr}\xskakget{lan}\xskakset{style=styleA,level=1}{\mainlinestyle\xskakget{opennr}\xskakget{lan}}

1. . . e7–e5 1. -, e7–e5\xskakset{style=UF}%return to my stylecomments contains the short comments after a move (!,? A etc)
\newchessgame\mainline{1.f3 e5 2. g4?? Qh4+#!}

1. f3 e5 2. g4?? Qh4+m!

\xskakset{moveid=2w}%\xskakget{comments}??
!

\xskakset{moveid=2b}%\xskakget{comments}

nag NAG’s and comments inputed with \xskakcomment.
\newchessgame\mainline{1.f3 e5 2. g4$4 \xskakcomment{ Why this? } Qh4+#!}

1. f3 e5 2. g4?? Why this?
Qh4+m!

\xskakset{moveid=2w}%\xskakget{nag}?? Why this?

4.4. Exporting the games
With \xskakexportgames[〈key=value list〉] you can export games to a file. As default
the command exports the game data of the game with the default 〈GameId〉 to the filexskakgames.xsk8 .
The command accept the following keys:
file=〈string〉 This changes the name of the file. The extension can not be changed.
games={〈comma separated list of games〉} With this key you can chose the games thatshould be exported.
8

I didn’t find any other application that use this extension. So I think it is quite safe.

June 23, 201923

xskak 1.5

You can then input the games in other document and use there the game data without haveto do all the parsing with \mainline again (which can be quite slow). The export file is alsoquite handy to debug the game parsing and saving.
As an example I exported in another document the following two games which I will use
later in this documentation:\newchessgame[id=export,white=Deep Blue, black=Kasparov,result=1-0]\mainline{1.e4 c6 2.d4 d5 3.Nc3 dxe4 4.Nxe4 Nd7 5.Ng5 Ngf6 6.Bd3 e6
7.N1f3 h6 8.Nxe6 Qe7 9.O-O fxe6 10.Bg6+ Kd8 \xskakcomment{Kasparovschüttelt kurz den Kopf} 11.Bf4 b5 12.a4 Bb7 13.Re1 Nd5 14.Bg3 Kc8
15.axb5 cxb5 16.Qd3 Bc6 17.Bf5 exf5 18.Rxe7 Bxe7 19.c4}\newchessgame[white=none,black=none,id=exportb]\mainline{1. e4 e5}\xskakexportgames[games={export,exportb}]

xskakendgamedata

kakcurrentgameid

The export consists more or less of a long list of definitions with one notable exception: At theend of each game there is the command \xskakendgamedata. As a default the command
does nothing but if you redefine it e.g. to \printchessgame (see section 7.5), it can beused to print all games during the input. \xskakcurrentgameid holds the 〈GameId〉 of theprevious game.

\renewcommand\xskakendgamedata{\xskakset{id=\xskakcurrentgameid}%\xskakgetgame{white}--\xskakgetgame{black}:\printchessgame[style=styleB,level=1]\par\bigskip}\input{xskakgames.xsk}

Deep Blue–Kasparov: 1 e4 c6 2 d4 d5 3 Nc3 dXe4
4 NXe4 Nd7 5 Ng5 Ngf6 6 Bd3 e6 7 N1f3 h6 8
NXe6 Qe7 9 O-O fXe6 10 Bg6+ Kd8 11 Bf4 b5
12 a4 Bb7 13 Re1 Nd5 14 Bg3 Kc8 15 aXb5
cXb5 16 Qd3 Bc6 17 Bf5 eXf5 18 RXe7 BXe7 19
c4
none–none: 1 e4 e5

4.5. The inner technique: how the data are stored
The game related data are stored in commands with names of the following structure:
Xskak〈GameId〉〈type of Information〉

If 〈GameId〉 is a simple string of characters you can use the command by putting a backslash
before the name, in other case you will have to use \csname. . . \endcsname.
The move related data are stored in commands with names that have the following structure:
Xskak.〈GameId〉.〈movenr〉.〈player〉.〈type of Information〉

As the names contain points and a number it is not possible to execute the commands byJune 23, 201924

xskak 1.5

putting a backslash before the name. If you want to use them you will have to surround thename by \csname. . . \endcsname – something that probably will not be necessary in normalcases as there are user commands that allows “normal” access.
During storing the data 〈movenr〉 and 〈player〉 are taken from the current move as processedby the package skak, that is \mainline{15... Nf3} will store the data in
Xskak.〈GameId〉.15.b.〈type of Information〉.
Renumbering the moves during storing is not possible9 .
Example 5 on page 26 shows an example that use the internal commands. As you can see,the \csname–\endcsname-input is quite powerful: You can construct a command with thehelp of other (expandable) commands or use the value of counters.
Warning!
\csname whatever\endcsname doesn’t give an error if the command isn’t defined. It simply
defines \whatever as \relax and then executes it. So it is easy to overlook typing errors –and then to wonder why one doesn’t get the expected output.

9

But it would be probably not difficult to implement. So if you need it badly, sent me a feature request.

June 23, 201925

xskak 1.5

Example 5: Using the internal commands
Game 1

1. e4 e5 2. Nf3 Nc6 3. Bb5 Nf6 4. O-O
NXe4 5. BXc6 bXc6

In the second game the second move ofwhite was Ra1–d1.
The position in the first game after the third
move of black was:Game 215. c8Q+ Ke7 16. Rd1
Comments

In the first game, white moved at first a p,then a N and a B. In his last move black
took a B, white took a N.

rZblka0s
opopZpop
60ZnZ0m0Z
5ZBZ0o0Z0
4
0Z0ZPZ0Z
3
Z0Z0ZNZ0
2
POPO0OPO
1
SNAQJ0ZR

8
7

a

b

c

d

e

f

g

The fourth move ofhwhite was a castling move.

\begin{multicols}{2}\minisec{Game 1}\newchessgame[id=gameA]%\mainline{1. e4 e5 2. Nf3 Nc6 3. Bb5 Nf6 4. O-O Nxe4 5.Bxc6 bxc6}\minisec{Game 2}\newchessgame[id=game,restorefen=example,moveid=15w]%\mainline{15. c8=Q+ Ke7 16. Rd1}
\minisec{Comments}\setcounter{enumi}{1}%In the first game, white moved at first a\figsymbol{\csname Xskak.gameA.\the\value{enumi}.w.piecechar\endcsname},then a \figsymbol{%\csname Xskak.gameA.\the\numexpr\the\value{enumi}+1\relax.w.piecechar\endcsname}and a \figsymbol{%\csname Xskak.gameA.\the\numexpr\the\value{enumi}+2\relax.w.piecechar\endcsname}.
In his last move black took a\figsymbol{\csname Xskak.gameA.\XskakgameAlastmovenr.b.lostpiecechar\endcsname},white took a \figsymbol{\csname
Xskak.gameA.5.w.lostpiecechar\endcsname}.
In the second game the second move of white was\figsymbol{%\csname Xskak.game.\the\numexpr \Xskakgameinitmovenr +1\relax.w.piece\endcsname}%\csname Xskak.game.16.w.movefrom\endcsname--%\csname Xskak.game.16.w.moveto\endcsname.
The position in the first game after the third move of black was:\chessboard[tinyboard, setfen=\csname Xskak.gameA.3.b.nextfen\endcsname]
The fourth move of white was\csname
Xskak.gameA.4.w.castling\endcsname\ifthenelse{\boolean{xskakboolcastling}}{}{not} a castling move.
\end{multicols}

June 23, 201926

xskak 1.5

5. Retrieving the stored information
5.1. Setting the variables\xskakset

It should be clear that to retrieve the information you must tell xskak the game and the movefor which you want to get data. This is done with \xskakset{〈key=value list〉} which will
set the variables 〈GameId〉 and/or 〈MoveId〉 to the values listed in the key=value list.
Some possible10 keys are:
id=〈name〉 The key will set/change globally the active game identification, the 〈GameId〉.

This will also affect the storing of the following moves! So if you change the 〈GameId〉in the middle of the parsing of a game, don’t forget to reset it to the old value before
continuing!
movenr=〈number〉, player=〈“w” or “b”〉, moveid=〈number + “w” or “b”〉 The keys will set
the move number and the player. The values are global but the values of movenr andplayer are not expanded directly while the value of moveid is. The keys change only

the internal commands that are used to retrieve information, the move counter andthe boolean of \mainline are not affected by this keys.
stepmoveid=〈number〉 stepmoveid picks up the current value of the move variables of
xskak and “adds” the given number of halfmoves. When no number is given the value
1 is used and this gives the next move. E.g. if the current move is 10w and you use
stepmoveid=3 then you get 11b. Negative numbers can be used, if this results in amove number smaller than 1, a warning is given but not an error: This gives you thepossibility e.g. in loops to handle the case yourself.
lastmoveid=〈GameId〉 This key sets the xskak move identification commands to the number/color of the last move of the game 〈GameId〉. 〈GameId〉 is optional. lastmoveid=A
ist equivalent to id=A,lastmoveid.
tag=〈name〉, ref...=〈name〉 tag saves the current values of 〈GameId〉 and the move ininternal commands. They can then later be retrieved by the keys of type ref.

For more information on the labeling and referencing see section 5.5.
defaultid=〈name〉 With this key you can change the default game identification. Thechange is global.

10

More keys are described later.

June 23, 201927

xskak 1.5

\setcounter{gamecounter}{4}\xskakset{defaultid=game\Alph{gamecounter}}\newchessgame[white=John]\mainline{1. e4 e5}

1. e4 e5
1. d4 d5

\stepcounter{gamecounter}\newchessgame[white=Jack]\mainline{1. d4 d5}

The white players were John and Jack.

The white players were \XskakgameDwhite\ and\XskakgameEwhite.

defaultmovenr=〈number〉, defaultplayer=〈“w” or “b”〉,
defaultmoveid=〈number〉〈“w” or “b”〉 With this keys you can change the default start

move for the subsequent games. The change is global.
defaultfen=〈FEN〉 As a default \newchessgame sets the start position to a new game. You

can change this default with this key. The change is global.

5.2. Getting the game information\xskakgetgame

With \xskakgetgame{〈type〉} you can retrieve game data for the currently active 〈GameId〉(which can be set/changed with the commands \newchessgame, \resumechessgame and\xskakset).

\newchessgame[id=A,white=John White,black=Jack Black,
result=1--0]\minisec{\xskakgetgame{white}-\xskakgetgame{black}}\mainline{1.e4 e5 2.Bc4 Nc6 3. Qh5 Nf6 4.Qxf7#}\mbox{\xskakgetgame{result}}

John White– Jack Black

1. e4 e5 2. Bc4 Nc6 3. Qh5 Nf6 4. QXf7m
1–0

0Z0Z0Z0Z
Z0Z0Z0Z0
6
0Z0Z0Z0Z
5
Z0s0Z0Z0
4
0Z0Z0Z0Z
3
Z0ZkZ0Z0
2
0Z0Z0Z0Z
1
Z0ZKZ0Z0
8
7\newchessgame[id=B,
white=Harry Red,
black=Tom Green,
result=0--1,
setwhite={kd1},
addblack={kd3,rc5}]\chessboard[setfen={\xskakgetgame{initfen}}]\minisec{\xskakgetgame{white} -\xskakgetgame{black}}\mainline{1. Ke1 Rf5 2. Kd1 Rf1#}\mbox{\xskakgetgame{result}}

June 23, 2019

a

b

c

d

e

f

g

h

Harry Red – Tom Green

1. Ke1 Rf5 2. Kd1 Rf1m 0–1

28

xskak 1.5

It is also possible to get the stored information by simply calling the command\xskak〈gameid〉〈type〉 (if 〈gameid〉 consists of letters).

\newchessgame[id=A,white=John White,black=Jack Black, result=1--0]\minisec{\XskakAwhite\ -- \XskakAblack}\mainline{1.e4 e5 2.Bc4 Nc6 3. Qh5 Nf6 4.Qxf7#}\mbox{\XskakAresult}\newchessgame[id=B,white=Harry Red,
black=Tom Green, result=0--1]\minisec{\XskakBwhite\ -- \XskakBblack}\mainline{1.f3 e5 2.g4 Qh4#}\mbox{\XskakBresult}\minisec{List of Results}\begin{tabular}[t]{l@{\,--\,}lr}\XskakAwhite&\XskakAblack&\XskakAresult\\\XskakBwhite&\XskakBblack&\XskakBresult\end{tabular}\minisec{Final positions}\chessboard[tinyboard,lastmoveid=A,
setfen=\xskakget{nextfen}]\chessboard[tinyboard,lastmoveid=B,
setfen=\xskakget{nextfen}]

John White – Jack Black

1. e4 e5 2. Bc4 Nc6 3. Qh5 Nf6 4. QXf7m
1–0
Harry Red – Tom Green

1. f3 e5 2. g4 Qh4m 0–1
List of Results

John White – Jack Black
Harry Red – Tom Green

1–0
0–1

Final positions
rZblka0s
opopZQop
60ZnZ0m0Z
5
Z0Z0o0Z0
40ZBZPZ0Z
3
Z0Z0Z0Z0
2
POPO0OPO
1
SNA0J0MR

rmbZkans
opopZpop
6
0Z0Z0Z0Z
5
Z0Z0o0Z0
4
0Z0Z0ZPl
3
Z0Z0ZPZ0
2
POPOPZ0O
1
SNAQJBMR

8

8

7

7

a

b

c

d

e

f

g

h

a

b

c

d

e

f

g

h

5.3. Getting the move information
Move data are bit more difficult as they depend on more variables.
At first, you can naturally use a \csname...\endcsname:\csname xskak.〈gameid〉.〈movenr〉.〈player〉.〈type〉\endcsname.
But normally you should use a \xskakset/\xskakget-combination11 .
\xskakget\xskakget{〈type〉} will pick up the current values of the variables for the 〈GameId〉 and the〈MoveId〉 and then retrieve/print the content of type 〈type〉.
〈type〉 can be any of the types described in 4.3.3 and additionally the three virtual types
movenr, player and moveid can be used which will output the current move identification.
This allows easier retrieving of the current value of the internal variables e.g. in loops andtests.

11

I had to implement the retrieving as a two-step-method to be able to use the retrieving command in the
key=value list of \chessboard. As the values are expanded during the processing complicated commands
which use internally \def and \setkeys can not be used as values.

June 23, 201929

xskak 1.5

Attention: The move variables are not changed by the parsing command of the package skak. And they are not stored like the other types – you can’t retrieve them with a\csname...\endcsname construction.
\newchessgame[moveid=10b]\mainline{10... e5}

10. . . e5

The game started with move \xskakget{moveid}.

The game started with move 10b.

\xskakset{moveid=5w}
Now the moveid has value \xskakget{movenr}\xskakget{player}.

Now the moveid has value 5w.

5.4. Using the data with \chessboard
The move data can naturally be used with \chessboard e.g. to highlight the last move withan arrow. The 〈MoveId〉 you want to refer to can be set before the board with \xskakset but
if this were the sole possibility this would mean that you couldn’t get data from other moves.
So I defined a bunch of new keys for \chessboard (and changed some existing keys) whichallows to retrieve during building the board all available move datas. The most importantones are keys that tells \chessboard the 〈GameId〉 and the 〈MoveId〉 for which you want toretrieve datas:
id=〈name〉 Like the other id-keys this one sets the variable that identifies the game. But

setting this key will not affect the value of the game identification outside the board,
any change is local to the board.
Attention: Setting this key will not change the default position shown by \chessboard.
This is always the “current” game.
movenr=〈number〉, player=〈“w” or “b”〉, moveid=〈number + “w” or “b”〉 This keys storesthe number and player for which you want to retrieve move related information. Again
any setting is local to the board.
stepmoveid=〈number〉 Like the similar key of \xskakset stepmoveid picks up the current
value of the move variables of xskak and “adds” the given number of halfmoves. But
again when you use the key in the argument of \chessboard the change is local to theboard.
Attention: If you set the 〈MoveId〉 with the above keys to a value “outside” the gameand then try to retrieve a data you will probably get horrible errors.
lastmoveid=〈gameid〉 The usual case is probably that you want to use the (currently) last

move of a game. This can be done with this key. The (optional) value lets you specify
a game identification. lastmoveid=A ist equivalent to id=A,lastmoveid. Again thesetting is local to the board.

June 23, 201930

xskak 1.5

After you have set the move variables, you can use the command \xskakget{〈type〉} described above used without problems12 inside \chessboard as long as the value expands tosomething the keys can handle (markmove e.g. will not like it if you ask it to process a fen).
1. e4 e5 2. Bc4 Nc6 3. Qh5 Nf6
4. QXf7m\newchessgame[id=A,white=John White,black=Jack Black, result=1--0]\mainline{1.e4 e5 2.Bc4 Nc6 3. Qh5 Nf6 4.Qxf7#}

1. e4\newchessgame % a game between A and the board\mainline{1.e4}

rZblka0s
opopZQop
60ZnZ0m0Z
5
Z0Z0o0Z0
40ZBZPZ0Z
3
Z0Z0Z0Z0
2
POPO0OPO
1
SNA0J0MR
8
7\setchessboard{shortenend=5pt,color=red}%\chessboard[lastmoveid=A,setfen=\xskakget{nextfen},
pgfstyle=border,color=red,
markfields={\xskakget{moveto},\xskakget{movefrom}},
pgfstyle=straightmove,
markmove=\xskakget{movefrom}-\xskakget{moveto}]

a

b

c

d

e

f

g

h

\newchessgame[id=A]\mainline{1.e4 e5 2.Bc4 Nc6 3. Qh5 Nf6 4.Qxf7#}

1. e4 e5 2. Bc4 Nc6 3. Qh5 Nf6
4. QXf7m\xskakget{moveid}% to show 〈MoveId〉 is still 1w

1w\setchessboard{shortenend=5pt,color=red}%\chessboard[lastmoveid=A,setfen=\xskakget{nextfen},
moveid=1w,
pgfstyle=straightmove,
markmove=\xskakget{movefrom}-\xskakget{moveto},
stepmoveid=2,color=green,markmove=\xskakget{movefrom}-\xskakget{moveto},
stepmoveid=2,color=blue,
markmove=\xskakget{movefrom}-\xskakget{moveto},
stepmoveid=2,color=yellow,
markmove=\xskakget{movefrom}-\xskakget{moveto}]rZblka0s
opopZQop
60ZnZ0m0Z
5
Z0Z0o0Z0
40ZBZPZ0Z
3
Z0Z0Z0Z0
2
POPO0OPO
1
SNA0J0MR
8
7a\xskakget{moveid}% to show that 〈MoveId〉 is again 1w

b

c

d

e

f

g

h

1w

5.5. Labeling a game
It is a bit tedious to have to remember the number and the color of the moves when you want
to start or to continue a game, or for which you want to draw a diagram or retrieve anothermove information. So there is a sort of labeling system. In difference to the labeling in

12

I hope but I haven’t tested any possible usage.

June 23, 201931

xskak 1.5

normal LATEX it doesn’t write the values to auxiliary files. That means that you can’t referencelabels which come later in the document (at my opinion this would lead to chaos anyway).
To set a label you use the command \xskakset with the key tag13 . It saves the current valueof the move counter (the skak counter!), the value of the (skak!) boolean that holds the player
and the 〈GameId〉. If you haven’t started any game yet (more precisely: if the move counterhas value 0) then the package xskak will issue a warning and do nothing.
You can set the tag between two \mainline (or \hidemoves) commands, but it works also if
you put them directly in the argument of \mainline:\newchessgame%\mainline{1. e4 e5\xskakset{tag=A}
2. Nf3\xskakset{tag=B} Nc6
3. Bb5 Nf6
4. O-O Nxe4
5.Bxc6 bxc6}

1. e4 e5 2. Nf3 Nc6 3. Bb5 Nf6 4. O-O NXe4
5. BXc6 bXc6

The saved values can be retrieved with various keys of type ref (e.g. refpastmoveid,
refnextplayer), or by the command \xskakget.
The label is set in most cases between two moves. There probably will be cases when you
need the 〈MoveId〉 of the move before the tag e.g. to show the position or to comment on thelast move, and there will be cases when you will need the 〈MoveId〉 of the move after the tag
e.g. to continue the game. So there are ref-keys for both cases.

5.5.1. Retrieving the tagged values with \xskakget

Retrieving the 〈GameId〉 and/or 〈MoveId〉 values stored by a tag is again a more-than-onestep procedure: At first you must tell xskak the tag name you want to use, and then use
a \xskakget{〈list of ref types〉}, where 〈ref type〉 is one of the following keywords: refid,
refpastmoveid, refnextmoveid, refpastmovenr, refnextmovenr, refpastplayer,
refnextplayer.

Setting the tag name is done with the key reftag, which you can use with all commands
that accept the key id. If you use the key in the optional argument of \chessboard it willchange the tag name locally for the board. In all other cases the tag name is set globally.

13

The name “label” is used by \chessboard to set the labels of the boards.

June 23, 201932

xskak 1.5

rmblkans
opopZpop
6
0Z0Z0Z0Z
5
Z0Z0o0Z0
4
0Z0ZPZ0Z
3
Z0Z0ZNZ0
2
POPO0OPO
1
SNAQJBZR
8\newchessgame[id=new] % to set a new id\chessboard[
reftag=B,%from previous example
id=\xskakget{refid},%retrieves and sets the 〈Gameid〉 from tag B
moveid=\xskakget{refnextmoveid},%retrieves and sets the 〈Moveid〉 from tag B
setfen=\xskakget{pastfen}]

7

a

b

c

d

e

f

g

h

5.5.2. The ref-keys

As the more-step-procedure to use the tags is a bit longuish there exist keys that shorten theprocedure. This keys too work in the arguments of all commands that can also handle thecorrespondant keys id, moveid etc. The effect will be identical to setting the values directly:
Keys used in the optional argument of \chessboard will set their values only local to theboard, in the other cases the values are set globally.
refid=〈tag〉 This key will set the 〈GameId〉 to the value stored in the tag. It is a shortcut for
reftag=〈tag〉,id=\xskakgetverb+refid+
refpastmoveid=〈tag〉, refpastmovenr=〈tag〉, refpastplayer=〈tag〉 This keys will set therespective move information to the value of the move before the tag. If the tag is before
the move 1w, then the value 0b is used.
refnextmoveid=〈tag〉, refnextmovenr=〈tag〉, refnextplayer=〈tag〉 This keys will set therespective move information to the value of the move after the tag.
refpast=〈tag〉, refnext=〈tag〉 This keys will set the 〈GameId〉 and the 〈MoveId〉 in one go.
E.g. refpast is a shortcut for
reftag=〈tag〉,id=\xskakgetverb+refid+,moveid=\xskakgetverb+refpastmoveid+
reffen=〈tag〉 This is a \chessboard key. It will add the position at the tag on the board,
its effect is identical to using the key addfen =〈Position at tag〉 described in the
documentation of the package chessboard. So be aware that it really only places pieces

on the board. It will not change the 〈GameId〉 nor the 〈MoveId〉 or the move counter ofskak. So it is quite possible to use a position where black should move next to start agame with white to move.

June 23, 201933

xskak 1.5

rmblkans
opopZpop
6
0Z0Z0Z0Z
5
Z0Z0o0Z0
4
0Z0ZPZ0Z
3
Z0Z0ZNZ0
2
POPO0OPO
1
SNAQJBZR
8
7\newchessgame[id=new]% to set a new id\chessboard[reffen=B]

a

b

c

d

e

f

g

h

1. e4 e5 2. Nf3 Nc6 3. Bb5 Nf6 4. O-O NXe4
5. BXc6 bXc6
1. Nc3\newchessgame[id=A]%\mainline{1.e4 e5 2. Nf3\xskakset{tag=C}
Nc6
3. Bb5 Nf6 4. O-O Nxe4 5.Bxc6 bxc6}

rmblkans
opopZpop
6
0Z0Z0Z0Z
5
Z0Z0o0Z0
4
0Z0ZPZ0Z
3
Z0M0ZNZ0
2
POPO0OPO
1
S0AQJBZR
8
7\newchessgame[id=B,reffen=C]\mainline{1. Nc3}
\chessboard\chessboard[reffen=C,
markstyle=circle,
color=red,%from game B:
markfield=\xskakget{movefrom},
refpast=C,
color=green,%from game A:
markfield=\xskakget{movefrom}]

a

b

c

d

e

f

g

h

rmblkans
opopZpop
6
0Z0Z0Z0Z
5
Z0Z0o0Z0
4
0Z0ZPZ0Z
3
Z0Z0ZNZ0
2
POPO0OPO
1
SNAQJBZR
8
7

a

b

c

d

e

f

g

h

6. Looping
Looping with the \whiledo command of the package ifthen is not very difficult. But to adjust
to the special numbering of chessmoves (1w, 1b, 2w, 2b, 3w . . . ) one needs some special
commands to step through the moves and test for the end of the loop.

June 23, 201934

xskak 1.5

\xskaktestmoveid

Stepping can be done with the key stepmoveid described earlier.
\xskaktestmoveid{〈movenr〉}{〈player〉} is a test (defined with the help of package xifthen)which you can use in the first argument of \whiledo. It will give true if the move is in thecurrent game.

\newchessgame[id=A]\mainline{1. e4 e5 2. Nf3 Nf6}
\newchessgame[id=B](a second game)
Reprinting the first game:\xskakset{id=A,
moveid=\xskakgetgame{initmoveid}}\whiledo{\xskaktestmoveid{\xskakget{movenr}}{\xskakget{player}}}{\ifthenelse%{\equal{\xskakget{player}}{w}}{ \xskakget{movenr}.\,}{ }%\xskakget{lan}%\xskakset{stepmoveid}}

1. e4 e5 2. Nf3 Nf6(a second game)
Reprinting the first game: 1. e2–e4 e7–e5
2. Ng1–f3 Ng8–f6
Reprinting only the black moves: e7–e5 Ng8–f6

Reprinting only the black moves:\xskakset{%
id=A,
moveid=\xskakgetgame{initmoveid},stepmoveid}\whiledo{\xskaktestmoveid{\xskakget{movenr}}{\xskakget{player}}}{ \xskakget{lan}%\xskakset{stepmoveid=2}}\xskakloop\xskakloop[〈key=value list〉]{〈code〉} is a wrapper command for such a \whiledo loop.

The possible keys are:
id=〈string〉 Which sets the game identification. The setting is global.
initmovenr=〈number〉, initplayer=〈“w” or “b”〉, initmoveid=〈number + “w” or “b”〉 This

sets the move the loop should start with. Default is the first move of the game.
stopmovenr =〈number〉, stopplayer =〈“w” or “b”〉, stopmoveid=〈number + “w” or “b”〉

This sets the move where the loop should stop. Default is the last move of the game.
step=〈number〉 This sets the length of the steps of the loop. The number gives the numberof halfmoves. Default is one.
showlast=〈true|false〉 When you are using the key step with a number unequal to one, it
is possible that the last move (possibly set by stopmoveid) is left out. With the key
showlast you can force \xskakloop to process the code for the last move.

June 23, 201935

xskak 1.5

1. d4 Nf6 2. c4 g6 3. Nc3 Bg7 4. e4 d6 5. Nge2 O-O 6. Ng3 c6 7. Be2 a6 8. a4 a5 9. h4 h5
10. Be3 Na6 11. f3 e5 12. d5 Nd7 13. Nf1 Ndc5 14. Nd2 Qb6 15. Qb1 Nb4 16. Nb3
Ncd3+ 17. Kd2 QXe3+
rmblkans
opopopop
6
0Z0Z0Z0Z
5
Z0Z0Z0Z0
4
0Z0O0Z0Z
3
Z0Z0Z0Z0
2
POPZPOPO
1
SNAQJBMR

rmblkZ0s
opopopap
6
0Z0Z0mpZ
5
Z0Z0Z0Z0
40ZPOPZ0Z
3
Z0M0Z0Z0
2
PO0Z0OPO
1
S0AQJBMR

rmbl0skZ
opZ0opap
60Zpo0mpZ
5
Z0Z0Z0Z0
40ZPOPZ0Z
3
Z0M0Z0M0
2
PO0ZBOPO
1
S0AQJ0ZR

8

8

8

7

7

7

a

b

c

d

e

f

g

h

a

b

1. d2–d4

c

d

e

f

g

h

a

rmbl0skZ
ZpZ0opa0
60Zpo0mpZ
5
o0Z0Z0Zp
4
PZPOPZ0O
3
Z0M0A0M0
2
0O0ZBOPZ
1
S0ZQJ0ZR

rZbl0skZ
ZpZnZpa0
6nZpo0ZpZ
5o0ZPo0Zp
4
PZPZPZ0O
3
Z0M0APZ02
0O0ZBZPZ
1S0ZQJNZR

8

7

7

c

d

e

f

g

h

10. Bc1–e3

a

b

c

d

e

f

d

e

f

g

h

rZbZ0skZ
ZpZ0Zpa0
60lpo0ZpZ
5o0mPo0Zp
4
PmPZPZ0O
3
ZNM0APZ02
0O0ZBZPZ1SQZ0J0ZR

8

7

b

c

7. Bf1–e2

8ab

4. e2–e4g

13. Ng3–f1

h

a

b

c

d

e

f

g

h

16. Nd2–b3

rZbZ0skZ
ZpZ0Zpa0
60Zpo0ZpZ
5o0ZPo0Zp
4
PmPZPZ0O
3
ZNMnlPZ02
0O0JBZPZ
1SQZ0Z0ZR
8
7

a

b

c

d

e

f

g

h

17. . . Qb6Xe3+\newchessgame\mainline{%
1.d4 Nf6 2.c4 g6 3.Nc3 Bg7 4.e4 d6 5.Nge2 O-O 6.Ng3 c6 7.Be2 a6 8.a4
a5 9.h4 h5 10.Be3 Na6 11.f3 e5 12.d5 Nd7 13.Nf1 Ndc5 14.Nd2 Qb6
15.Qb1 Nb4 16.Nb3 Ncd3+ 17.Kd2 Qxe3+}\xskakloop[step=6,showlast]{%\begin{tabular}{c}\chessboard[tinyboard,
setfen=\xskakget{nextfen}]\\\xskakget{opennr}\xskakget{lan}%\end{tabular}\quad}%

June 23, 201936

xskak 1.5

With the help of the package animate and \xskakloop you can make animated boards:

8
7
6
5
4
3
2
1

3r2n4b5q1k4b2n3r
6p6p6p6p6p6p6p6p
zzzzzzzz
zzzzzzzz
zzzzzzzz
zzzzzzzz
6P6P6P6P6P6P6P6P
3R2N4B5Q1K4B2N3R
a

b

c

d

e

f

g

h

The board was made with the following code:\setchessboard{boardfontsize=0.8cm,shortenend=5pt, margin=false}%\setboardfontencoding{LSBC4}%\newskaklanguage{german}{KDTLSB}\skaklanguage[german]%%\newcommand\getmovestyle[1]{%\ifthenelse{\equal{#1}{N}}%knight move{\def\mymovestyle{[clockwise=false,style=knight]curvemove}}{\ifthenelse{\equal{#1}{}}% castling{\def\mymovestyle{curvemove}}{\def\mymovestyle{straightmove}}}}%%\newchessgame[white=Paethz,black=Dirr,result=0-1,id=anim]%\hidemoves{%
1.d4 Sf6 2.c4 g6 3.Sc3 Lg7 4.e4 d6 5.Sge2 O-O
6.Sg3 c6 7.Le2 a6 8.a4 a5 9.h4 h5 10.Le3 Sa6
11.f3 e5 12.d5 Sd7 13.Sf1 Sdc5 14.Sd2 Db6
15.Db1 Sb4 16.Sb3 Scd3+ 17.Kd2 Dxe3+}%%\unitlength0.8cm\relax

June 23, 201937

xskak 1.5

\begin{animateinline}[autoplay,loop,controls]{0.5}%\begin{picture}(11,11)\put(1.5,1.5){\chessboard[setfen=\xskakgetgame{initfen}]}%\end{picture}\newframe\xskakloop{%\getmovestyle{\xskakget{piecechar}}%\begin{picture}(11,11)\put(1.5,1.5){%\chessboard[pgfstyle=\mymovestyle, color=blue,
pgfshortenend=0.3em,arrow=to,
markmoves=\xskakget{move},coloremph,piececolor=blue,
emphfields={\xskakget{moveto}},setfen=\xskakget{nextfen}]}%\end{picture}%\newframe}%\begin{picture}(11,11)\put(1.5,1.5){\chessboard[setfen=\xskakgetgame{lastfen}]}%\end{picture}\end{animateinline}

7. Printing
7.1. \longmoves revisitated
In the example on page ?? I showed that the \longmoves of the package skak doesn’t work
correctly. This is due to the asynchronous parsing and printing of the skak-engine (skak – like
TEX – has sometimes to look a bit ahead). With the package xskak the problem can be easily
solved as it is now possible to retrieve information about previous moves. So the package
xskak redefines the internal commands to get \longmoves working.
Attention! The new \longmoves command works only correctly if the internal engine parses
the moves – so it doesn’t work with \variation. So starting with version 1.2 the package
xskak forces \variation to use \shortmoves.
The redefinition of \longmoves is done by first defining a printing command and then(re-)defining \longmoves such that the internal \printmove now use the new command.
The listing below shows the code14 . You can take it as a template for your own special
printing commands. \WhiteToMove{〈code for white〉}{〈code for black〉} is a command of
14

The code doesn’t show the complete truth. In the real code \longmoves also has to change the printing
mode for \printchessgame. See 7.5

June 23, 201938

xskak 1.5

the package skak that executes the first argument if white is to move and the second if its
black turn. The main trick in the new printing command is to go back one halfmove. The
new printing command defines only the printing format for the move itself as the number isprinted by the package skak at another place.
\def\xskak@do@printmove@algebraic{%\csname Xskak.\xskak@val@gameid.%\WhiteToMove{\the\numexpr\the\c@move-1\relax}{\the\c@move}.%\WhiteToMove{b}{w}.lan\endcsname\csname Xskak.\xskak@val@gameid.%\WhiteToMove{\the\numexpr\the\c@move-1\relax}{\the\c@move}.%\WhiteToMove{b}{w}.comments\endcsname{}}\def\longmoves{%\let\printmove=\xskak@do@printmove@algebraic}kakenpassanttext

The new printing command inserts a test for enpassant moves. You can suppress it byredefining \xskakenpassantext.

\longmoves\newchessgame\mainline{1.e4 e5 2.Nf3 Nf6}

1. e2–e4 e7–e5 2. Ng1–f3 Ng8–f6\newchessgame[restorefen=example]\mainline{1. a4 bxa3!}

1. a2–a4 b4Xa3!
1. a2–a4 b4Xa3!

\renewcommand\xskakenpassanttext{}\newchessgame[restorefen=example]\mainline{1. a4 bxa3!}

7.2. An user interface for styles
To format a game the package skak puts during parsing commands before and between the
moves and the counter. You can see the names of this commands in the following example(the style test is a simple local style predefined by xskak which contains different tests. In
level 1 and 2 it contains style items to show commands. The optional argument [invar]
force \variation to use level 2).

June 23, 201939

xskak 1.5

Example 6: The internal commands to format the output\mainlinestyle \opencommands \beforenumber 1\whiteopen \beforewhited4\afterwhite \beforeblack Nf6\afterblack \beforenumber 2\whiteopen\beforewhite c4\closecommands\mainlinestyle \opencommands \beforenumber 2\blackopen \beforeblack
g6\afterblack \beforenumber 3\whiteopen \beforewhite Nc3\afterwhite\beforeblack Bg7\afterblack \beforenumber 4\whiteopen \beforewhite
e4\closecommands\mainlinestyle \opencommands \beforenumber 4\blackopen \beforeblack
O-O\afterblack \beforenumber 5\whiteopen \beforewhite Nf3\afterwhite\beforeblack Re8\closecommands\mainlinestyle \opencommands \beforenumber 6\whiteopen \beforewhite
Be3\afterwhite \beforeblack e6\closecommands\variationstyle \opencommands \beforenumber 6\blackopen \beforeblack
d6\closecommands\newchessgame\xskakset{%style=test,level=1}\color{blue}\mainline{1.d4 Nf6 2.c4}\mainline{2... g6 3.Nc3 Bg7 4.e4}\mainline{4... O-O 5. Nf3 Re8}
\mainline{6. Be3 e6}\variation[invar]{6... d6}

By judiciously (re-)definining the commands skak inserts one can get almost every chess style
one want. skak itself defines three examples that demonstrates the possibilities. These styles
can be chosen by the commands \styleA, \styleB and \styleC. The first two are inline
styles, the third uses for \mainline a tabbing environment and switches to an inline stylefor \variation. But this styles are really no more than examples. There is no user interface
to change and define styles. And due to some dependencies between the predefined styles(\styleB is not only a stand-alone style but it is also used in the definition of \styleC for
the variation level) adapting the styles is not easy.
So I decided to define a real user interface to define styles and switch from one to another.
The user interface supports an unlimited number of levels: Each style is a bundle of levels
where the look on each level is describe by a style item and some optional commands.
Defining a style is therefore done in two steps:

June 23, 201940

xskak 1.5

skaknewstyleitem% Define items:\xskaknewstyleitem{A}{%beforenumber={},whiteopen={.\,},...}\xskaknewstyleitem{B}{...}%Define style\xskaknewstyle[%level=1,styleitem=A,
font=\bfseries, %add special command to level 1.
level=2,styleitem=A,level=3,styleitem=B,...]{mystyle}Attention! The (almost) indefinite number of levels comes at a price: \mainline and\variation no longer use automatically different styles. If a \variation should switch to a“variation style” you will have to use e.g. the option [invar] mentioned above (but you candefine your own “variation” commands that do this switch). Please read section 7.3 for more
information.

7.2.1. Defining style items

With \xskaknewstyleitem[〈key=value list〉]{〈item〉} you define the style item 〈item〉. You
can use the following keys:〈command name〉=〈commands〉 where 〈command name〉 is one of
opencommands, closecommands, beforenumber, whiteopen, blackopen,
beforewhite, beforeblack, afterwhite, afterblack.
There are endless possibilities for the value 〈commands〉 – as there are endless possibilities to get more or less horrible errors. So I will give only some general advices forthe definitions of style items:• While processing key=value lists xkeyval strips spaces. So if you want to set one of
the commands to a space use either commands like \ , \space and ~, or protect
the space by enough layers of braces.
• While processing key=value lists xkeyval strips also braces. If you need somegrouping use \begingroup and \endgroup or protect the “real” braces byenough other braces.
• Use if possible switches (like \bfseries) instead of commands with arguments.

June 23, 201941

xskak 1.5

• Think about how you want to handle spaces at the start and the end of (bits of) a
game or a variation. An input like \mainline{1. e4} \variation{1.e5} will
already insert a space so avoid to insert another one through e.g. opencommands.
• It is possible to open a group (with \begingroup) or a environment in one command and close it in another command. If you do this check carefully thatyou have balanced groups in all four combinations of white/black opening andending the game! Check also if everything works if you have only one move.
• You don’t have to give a definition for all keys/commands. Unused keys are set toempty.
• If you want to force a style (or a style item) to use the long or the short algebraic
notation you can add \longmoves/\shortmoves to opencommands.
〈beforeNAG〉=〈commands〉, 〈beforecomment〉=〈commands〉 xskak puts around each NAG
and comment given by \xskakcomment a group and before each NAG’s and comment a formatting command. This commands are named \xskak@beforeNAG and\xskak@beforecomment. With the keys beforeNAG and beforecomment you canchange this commands and so to some extend change the formatting of NAG andlong comments (the styles of short comments like + or ! are not affected!). The lastcommand in 〈commands〉 can be a command that has one argument. NAG and thecontent of the comment will then be used as this argument. This makes is e.g. possible
to gobble commands:\providecommand\gobble[1]{}\xskaknewstyleitem[%
template=UF,%a predefined style item
beforeNAG=\gobble,
beforecomment=\gobble]{gobblecomments}

1. e4! e5\xskakaddtostyle[%level=gobble,
styleitem=gobblecomments]{test}\variation[style=test,level=gobble]{1. e4! $1\xskakcomment{expected} e5 $2}

template=〈item〉 With this key you can reuse the definitions from another style item.

7.2.2. Defining style\xskaknewstyle\xskakaddtostyle

With \xskaknewstyle[〈key=value list〉]{〈style〉} you define the style 〈style〉.
With \xskakaddtostyle[〈key=value list〉]{〈style〉} you can add more levels (or overwrite
existing ones) to a style. Both commands can handle four keys: level, styleitem, fontand xfont.

June 23, 201942

xskak 1.5

level=〈number〉 With this key you set the number of the level for which you want todeclared a “look” with the following keys. The “highest” level number is 1. Normally it
should contain the description of the style for the main game. Variation styles shouldhave larger numbers. But the 〈number〉 don’t need to be a number, strings are also
possible.
If you want to keep everything simple: Use only (positive) numbers with levels. Thenthe levels have a well-defined order which is easy to handle. Key invar will add 1 toa level number, key outvar will substract 1 and if you set the level to a number forwhich no style item as been declared xskak will simply substract 1 from this number
until it finds a level with a style item it can use.
But you can also use level names with chars e.g. to define variants for a specificvariation level. So you could e.g. define levels 1open, 1close, 1middle, 1betteris.
In this case it depends on your compiler how the keys invar and outvar and levels
without declared style items are handled:
Case 1: You have an old pdfTEX where the (experimental) primitive \pdfmatch is notdefined (or you did use the package option nopdfmatch).
Then the keys invar and outvar will not work when the current level contains
chars or other non-numerical tokens. They will issue more or less bewildering
errors.
Levels without a declared style item will issue errors too.
Case 2: You have a recent pdfTEX where the (experimental) primitive \pdfmatch isdefined (and you didn’t use the package option nopdfmatch).
Case a) The level name doesn’t contain any number, e.g. level=gobble:
Then you will get an error if you try to set the level and you haven’t declareda style item for this level.
If the current level is gobble then the keys invar and outvar will issue awarning and let the level unchanged.
Case b) The level name do contain numbers, e.g. level=a12b567:
Then xskak will use the following substituation if you try to set the level andthere is no style item declared: xskak will extract the first number from thename (in this case “12”), substract one from this number and try the namewith the new number in it. If the first number is 1, level 1 is used (it is always
defined). If the first number is 0 you will get an error.
In the example xskak will try the levels in the following order until it finds
one that it can use: a12b567 → a11b567 → a10b567 → ...a2b567 →
a1b567 → 1

June 23, 201943

xskak 1.5

styleitem=〈item〉 With this key you set the style item used by the current level and all
following levels until another styleitem is set.
font=〈commands〉 With this key you can add some specific commands to the current level(and only to the current level). While the key is meant to add font switches to a level it
can also be used to overwrite some commands of a style item.
\xskaknewstyleitem[%
template=UF,%a predefined style item
beforenumber=\color{red},%whiteopen=.\,\color{black},
blackopen=\ldots\,\color{black}]{rednumbers}%% add to existing style test
\xskakaddtostyle[%level=10,styleitem=rednumbers,
level=12,
font=\def\beforenumber{\color{green}}\bfseries]{test}

1. Nf3 Nf6 2. d4
2. Nc3
2. . . d5\newchessgame\mainline[style=test,level=12]{1. Nf3 Nf6 2. d4}\variation[level=10]{2. Nc3}

\mainline[level=11]{2... d5}\xskakset{style=test}%\xskaknewstyleitem[%
template=UF,%a predefined style item
beforeNAG=\color{blue},
beforecomment=\mdseries]{mycomments}\xskakaddtostyle[level=13,styleitem=mycomments,
font=\bfseries]{test}\variation[level=13]{1. e4 $1 \xskakcomment{ as expected} e5}

1. e4! as expected e5\makeatletter\xskakaddtostyle[%level=gobbleB,styleitem=gobblecomments,
font=\renewcommand\xskak@beforeNAG{\color{red}}]%{test}\makeatother

1. e4!! e5?

\variation[level=gobbleB]{1. e4! $1 \xskakcomment{ Iexpected it} e5 $2}

xfont=〈commands〉 With this key you can add some specific commands to all levels withthe same first number in their name. It needs a recent pdfTEX with the command\pdfmatch.

June 23, 201944

xskak 1.5

As an example lets add three levels to the test style used above: the first (main) levelshould use a bold font, the second \mdseries and the third an italic font. For eachlevel we will define a variant which puts a \betteris (b) before the first move.
The example also demonstrates how to retrieve the current level. Please note thebraces around some of the \variations which keep the level change local.
Example 7: “betteris” style\xskaknewstyleitem[%
template=UF,
opencommands=(\betteris,closecommands=)]{betteris}\xskakaddtostyle[level=20 ,styleitem=UF,xfont=\bfseries,
level=20bis,styleitem=betteris,level=21 ,xfont=\mdseries,
level=22 ,xfont=\itshape]{test}

1. e4 e5 (level 20)(b1. . . e6) (level 20bis)\xskakset{style=test}\variation[level=20]{1. e4 e5} (level \xskakget{level})\variation[level=20bis]{1... e6} (level \xskakget{level})\variation[level=21]{1. e4 e5} (level \xskakget{level})\variation[level=21bis]{1... e6} (level \xskakget{level})\variation[level=22]{1. e4 e5} (level \xskakget{level})\variation[level=22bis]{1... e6} (level \xskakget{level})

1. e4 e5 (level 21)(b1. . . e6) (level 21bis)
1. e4 e5 (level 22)( b1. . . e6) (level 22bis)
1. e4 e5 (b1. . . e6)(b1. . . e6) ( b1. . . e6)
1. e4 e5 (b1. . . e6)
1. e4 e5 ( b1. . . e6)\variation[level=20]{1. e4 e5}{\variation[level=\xskakget{level}bis]{1... e6}\variation[invar]{1... e6} \variation[invar]{1... e6}}\variation[invar]{1. e4 e5} %to level 21{\variation[level=\xskakget{level}bis]{1... e6}}\variation[invar]{1. e4 e5} %to level 22{\variation[level=\xskakget{level}bis]{1... e6}}

The previous examples demonstrate some important points to consider when defining
styles:• You can define as much levels as you want.
• The number of the levels don’t have to be consecutive (they even need to be numbers).
If there is no definition for a level (in the first example level 11), the style item ofa previous level (in this case level 10) is used if xskak is able to figure out what theprevious level could be.

June 23, 201945

xskak 1.5

• While it is often sensible to store the settings for the main level in level 1, and for the
first variation level in level 2 and so on, you can also chose other orders or use morethan one level for each logical variation level. If you e.g. want sometimes to add braces
through opencommands you could define variants na, nb etc of the involved variationlevel.
• While it is easy to define style items and styles it is not easy sort and bundle them in asensible way.

7.3. Using the styles
The names of the commands \mainline and \variation give the impression that you
should use the first for the main game and the second for the variations. But at my opinion
this impression is wrong: You should use• \mainline if you want to parse and print chess moves,• \variation if you want only to print chess moves,• \hidemoves if you want only to parse moves and• \printchessgame (described later) if you want to (re)print a previously parsed game.
This means that each of the printing commands can be used for the main game and forvariations. And so it should be possible for each of the printing commands to set and use
every style level.
In consequence this means that if you use the new interface – you don’t have to – \variation
will no longer switch to another style.
You can set the style and the level either with \xskakset or in the optional argument of thethree printing commands. The keys you can use in both cases are:style=〈style name〉 This key sets the name of the style the following printing commands
should use. The setting is always local to the current group (even with \xskakset15 .
gstyle=〈style name〉 This key sets the name of the style globally.
level=〈number〉 This key sets the level the following printing commands should use. The

setting is always local to the current group.
glevel=〈number〉 This key sets the level globally.
invar This will add 1 to the first number in the current level (so it goes towards “higher”(deeper) levels). Again the change is local to the group. This key can break if thecurrent value of the level is not a number.
15

At first \xskakset did the settings globally. I changed it after the third time I had to correct the documentation because I forgot to reset a style after an example.

June 23, 201946

xskak 1.5

ginvar This is the global variant of invar.
outvar This will substract 1 to the first number in the current level (so it goes towards level1 as the main level). This key can break if the current value of the level is not a number.
goutvar This is the global variant of outvar.

7.4. The predefined styles
The package xskak predefines five styles: styleA, styleB and styleC imitate the predefinedstyles of skak with the addition that they change to italic in the third level. Style UF is mystyle and style test is a large container for all sorts of tests.
\minisec{style \enquote{styleA}}\newchessgame\xskakset{style=styleA}\mainline[level=1]{%
1. e4 e6 2. d4 d5 3. e5 c5 4. c3 Qb6}(\variation[invar]{4... Ne7 5. Nf3 Nec6}(\variation[invar]{5... Nf5 6. h4 Be7
7. Bd3 cxd4 8. cxd4 Nc6 9. Bxf5 exf5 10. Bg5 $14})\variation[outvar]{6. Bd3}(\variation[invar]{6. h4 Nd7 7. h5 f6 $1 $132}))\mainline[outvar,outvar]{ 5. Nf3 Bd7}

\minisec{style \enquote{styleB}}\newchessgame\xskakset{style=styleB}\mainline[level=1]{%
1. e4 e6 2. d4 d5 3. e5 c5 4. c3 Qb6}(\variation[invar]{4... Ne7 5. Nf3 Nec6}(\variation[invar]{5... Nf5 6. h4 Be7
7. Bd3 cxd4 8. cxd4 Nc6 9. Bxf5 exf5 10. Bg5 $14})\variation[outvar]{6. Bd3}(\variation[invar]{6. h4 Nd7 7. h5 f6 $1 $132}))\mainline[outvar,outvar]{ 5. Nf3 Bd7}

\minisec{style \enquote{UF}}\newchessgame\xskakset{style=UF}\mainline[level=1]{%
1. e4 e6 2. d4 d5 3. e5 c5 4. c3 Qb6}(\variation[invar]{4... Ne7 5. Nf3 Nec6}(\variation[invar]{5... Nf5 6. h4 Be7
7. Bd3 cxd4 8. cxd4 Nc6 9. Bxf5 exf5 10. Bg5 $14})\variation[outvar]{6. Bd3}(\variation[invar]{6. h4 Nd7 7. h5 f6 $1 $132}))\mainline[outvar,outvar]{ 5. Nf3 Bd7}

June 23, 201947style “styleA”

1. e4, e6 2. d4, d5 3. e5, c5 4. c3,
Qb6 (4. -, Ne7 5. Nf3, Nec6 (5. -,Nf5 6. h4, Be7 7. Bd3, cXd4 8. cXd4,
Nc6 9. BXf5, eXf5 10. Bg5f) 6. Bd3(6. h4, Nd7 7. h5, f6! V)) 5. Nf3,
Bd7

style “styleB”

1 e4 e6 2 d4 d5 3 e5 c5 4 c3 Qb6(4. . . Ne7 5 Nf3 Nec6 (5. . . Nf5 6 h4
Be7 7 Bd3 cXd4 8 cXd4 Nc6 9 BXf5
eXf5 10 Bg5f) 6 Bd3 (6 h4 Nd7 7 h5
f6! V)) 5 Nf3 Bd7style “UF”

1. e4 e6 2. d4 d5 3. e5 c5 4. c3 Qb6(4. . . Ne7 5. Nf3 Nec6 (5. . . Nf5
6. h4 Be7 7. Bd3 cXd4 8. cXd4 Nc6
9. BXf5 eXf5 10. Bg5f) 6. Bd3 (6. h4
Nd7 7. h5 f6! V)) 5. Nf3 Bd7

xskak 1.5

style “styleC”

styleC sets the moves in a tabbing and should be used only for the main moves.

\newchessgame\mainline[style=styleC,level=1]{%
1. e4 e6 2. d4 d5 3. e5 c5 4. c3 Qb6}(\variation[invar]{4... Ne7 5. Nf3 Nec6}(\variation[invar]{5... Nf5 6. h4 Be7
7. Bd3 cxd4 8. cxd4 Nc6 9. Bxf5 exf5 10. Bg5 $14})\variation[outvar]{6. Bd3}(\variation[invar]{6. h4 Nd7 7. h5 f6 $1 $132}))\mainline[outvar,outvar]{ 5. Nf3 Bd7}

1
2
3
4

e4
d4
e5
c3

e6
d5
c5
Qb6

(4. . . Ne7 5 Nf3 Nec6 (5. . . Nf5 6 h4
Be7 7 Bd3 cXd4 8 cXd4 Nc6 9 BXf5
eXf5 10 Bg5f) 6 Bd3 (6 h4 Nd7 7 h5
f6! V))
5

Nf3

Bd7

7.5. The new xskak printing command\printchessgame

As one of the aims of xskak is to separate the parsing from the printing of a game there isnaturally also a printing command. With \printchessgame[〈key=value list〉] you can print
a previously parsed and saved game. Without any options \printchessgame will print thegame with the currently active 〈GameId〉 from start to end.
As keys you can use
id=〈GameId〉, refid=〈tag〉 This keys change only for the printing the current 〈GameId〉.

Afterwards the old 〈GameId〉 is restored.
initmovenr=〈number〉, initplayer=〈“w” or “b”〉, initmoveid=〈number + “w” or “b”〉

This keys sets the move the printing should start with. If the move isn’t in the game awarning is issued and the first move of the game is used instead.
stopmovenr=〈number〉, stopplayer=〈“w” or “b”〉, stopmoveid=〈number + “w” or “b”〉

This keys sets the move the printing should end with. If the move isn’t in the game awarning is issued and the last move of the game is used instead.
reftag=〈tag〉 This sets the tag name in case that you want to use tagged moves as startor end of the printing. There are no keys like initrefpastmoveid (I thought solong names are no longer manageable), so you will have to use e.g. reftag=〈tag〉,initmovenr=\xskakget{refpast}.
style, level, keyinvar and outvar \printchessgame use the same formatting commands
as skak, so the style can be change through the interface defined and described in

section 7.2.

June 23, 201948

xskak 1.5

To set the level and the style you can use the keys described in section 7.3 in theoptional argument of \printchessgame. Like with \mainline and \variation thekeys sets the values locally for the current group.
To print the actual moves, \printchessgame doesn’t use the command \printmove
from skaksty but an internal command named \xskak@do@printmove. So commands
like \longmoves must set this command appropriately.
\input{xskakgames.xsk}\printchessgame[style=UF,level=1,id=export,
initmoveid=7w,stopmoveid=12b]

7. N1f3 h6 8. NXe6 Qe7 9. O-O fXe6 10. Bg6+
Kd8 11. Bf4 b5 12. a4 Bb7

7.6. Game titles and chessboard captions
There are no pre-made commands. You will have to define them with the help of the stored
game data/move data. For titles I advise you to use a sort of sectioning command – this will
prevent page breaks between the title and the game. Look e.g. at the definition of \minisec
in one of the classes from the KOMA-bundle. For captions: look at the package caption.

8. PGN2LTX or How to sort the input
While skak/xskak can handle games in PGN-notation they can’t handle PGN-files: neither
the PGN-infos (which is a small nuisances) nor the variations and the comments in the gamenotation (which makes it tedious to print large games with a lot of annotations).
There exists a small number of perl scripts and applications to help to convert PGN to LATEX
but none is really satisfactory. One of the problems that prevents better solutions is that
there is no clear description what should be the result of a conversion from PGN to LATEX. In
this section I will make some remarks about what I think would be a good output from sucha converter for xskak16 and where I see problems. The description should also help you toenter or convert complicated games manually.
The PGN-infos

The “tag pair” section of a chess game in PGN shouldn’t pose problems to a converter. The
tags should be simply converted to the equivalent keys of a \newchessgame:[Round "29"][White "Fischer, Robert J."]
[Black "Spassky, Boris V."]
[Result "1/2-1/2"]

16

texmate needs another output.

June 23, 201949

xskak 1.5

\newchessgame[id=〈GameId〉, %see below
round={29},white={Fischer, Robert J.},
black={Spassky, Boris V.},
result={12-12}]

If the game use a SetUp and a FEN tag to set an alternative starting position, the converter
will have to extract the start move from the FEN and set it with the key moveid.
The 〈GameId〉

While it is probably possible to give each game an unique 〈GameId〉 I don’t think that it issensible or really necessary. I would suggest, that each game gets uses
\newchessgame[id=main\xskakaddtoid,...] where \xskakaddtoid is empty by default
but can be redefined to allow some automatic numbering.
The parsing command

As you will probably sometimes use \mainline and sometimes \hidemoves it is probably
best if the converter use an general \parsechessgame which can be \let to both commands.
NAG’s

Most NAG’s don’t need any special handling as xskak can parse them.
But some chess applications seems to put NAG’s after a move to denote a symbol that should
go before the move. E.g. 1. e5 $142 should become b1. e5.
Putting such symbols before a move number is in most cases only possible at the start of a\mainline or \variation so the converter will have probably to split the input and add thesymbol either directly or through a style. A converter will need a list of all this special casesand good rules how to handle them.
Long comments

Longer commands (in the PGN in curly braces) could be handled either by adding a\xskakcomment at the begin of the comment or by ending the parsing and starting it again
after the comment. The first method has the advantage that one can use styles to format
to some extend the comments (or gobble them) but can cause problems if the comment
contains something that isn’t allowed in the argument of a command.
I think some real examples are needed to decide what is the best way.

June 23, 201950

xskak 1.5

The content of long comments

I don’t think that is possible to handle all possible contents automatically and get a suitable
result for LATEX. You will either have to follow some rules while inputing the comments or
tidy them up later.
But a converter will probably be able to identify moves like 4. Nf3 and to surround them bysuitable \variation[style=...,level=...]{...}.
Diagrams

Some chess applications let you put markers at places where you would like to print a
diagram. E.g. chessbase put Diagramm #17 in a comment.
A converter should also be able to recognize such markers for diagrams. But it is not easy
to decide what should be done with this markers. In some cases you would probably notwant to print boards at all. Sometimes the game should be interrupted and the diagram
printed directly. Sometimes it should float. And I recall that someone once tried to put
all diagrams in the order there were mentioned in the margin. If such markers are used
it is probably the best if the converter sets a tag and sets one of the fake NAG’s $D and$d. Then \printchessgame and the list of diagrams could be used to print the moves andthe diagrams in the intended order (but it will probably need some coding to get the right
results). The tag and the NAG should be move outside of the comment as the comment isn’t
processed in all cases.
Example 8: Input and suggested output for diagram markers
10. c3 e5 $1 {Diagramm # Die energische und konsequente
Fortsetzung, Schwarz öffnet das Zentrum, um seine Figuren zu
aktivieren.} 11. h3\mainline{10. c3 e5\xskakset{tag=dia1} $d $1\xskakcomment{ Die energische und konsequente Fortsetzung,Schwarz öffnet das Zentrum, um seine Figuren zu aktivieren. }11. h3}

Variations

Here starts the real problems. Even if we forget for the moment the parsing of moves anddiagrams it is not easy to describe a suitable output. The main problems come from thefact that styles and good typesetting are involved: E.g. PGN code two variations in a row as(1... e5) (1... e6). But you would probably print this as (1. . . e5; 1. . . e6).
So the converter will have to look ahead and use suitable “open”, “middle”, “close” and“single” styles in the different combinations.
17

I don’t know if “Diagramm” is language dependent. Probably yes.

June 23, 201951

xskak 1.5

If you make long analyzes you will probably want to use numbered list for the variations –but not every variation is so important that it need its own number. In this case there must
be a marker that tells the converter to handle this variation differently.
I haven’t solved all this problems but I think that the following code could be used as starting
point for further discussion about a LATEX-chess input18 :\newchessgame[id=main, ...]
\mainline{...}%new var level\newchessgame[newvar=main,id=var1a]%\mainline[level=1open]{.....}%same var level\newchessgame[newvar=main,id=var1b]%\mainline[level=1close]{....}%new var level\newchessgame[newvar=var1b,id=var2a]%\mainline[level=2single]{....}%% return to var1b:\resumechessgame[id=var1b]\mainline[level=1open]{....}

Initialization and title

Until now I have only discussed the game itself. But you would probably want to print titles,
make table of contents and other lists. So one should also add some generic commands orenvironments like \begin{chessgame}/\end{chessgame} and {\chessgameheader} toeach game.

9. Compability issues
9.1. xskak and texmate
It will probably work fine to use both packages in one document.
\newchessgame and \resumechessgame will both internally issue a \fenposition command that will setup the games also for texmate. This naturally means in return that bothcommands interfere with texmate!

You can’t benefit of the extended input possibilities for NAG’s and comments. texmate has its
own parsing method.

18

If one really wants to parse all variations a better naming for the nodes is needed.

June 23, 201952

xskak 1.5

Btw: If you are using texmate you should always indent your input as the package doesn’t
recognize new lines as spaces.

9.2. xskak and beamer
When making presentations with beamer you should remember two things: First you can’t
use verbatim material or other commands that relies on catcode changes in the frameenvironment or -command. That means for the package skak that you can’t use # in a\mainline but should replace it by \mate.
Second, if you are using overlays the content of the frame is processed more than once. Thatmeans that you should be careful to reset counters if you don’t want to run into never ending
loops.
The following listing shows an example how to print a chessgame with beamer. If yourpdf-reader can handle annotations you can see the result in the attached file:
It usesoverlays (which worked fine) and also shows how you can handle games in another language:\documentclass{beamer}\usepackage[LSBC4,T1]{fontenc}\usepackage{chessboard}\usepackage{xskak}\newcommand\getmovestyle[1]{%\ifthenelse{\equal{#1}{N}}%knight move{\def\mymovestyle{[clockwise=false,style=knight]curvemove}}{\ifthenelse{\equal{#1}{}}% castling{\def\mymovestyle{curvemove}}{\def\mymovestyle{straightmove}}}}\setboardfontencoding{LSBC4}\newskaklanguage{german}{KDTLSB}\skaklanguage[german]\begin{document}\newchessgame[white=Paethz,black=Dirr,result=0-1]\hidemoves{%
1.d4 Sf6 2.c4 g6 3.Sc3 Lg7 4.e4 d6 5.Sge2 O-O 6.Sg3 c6 7.Le2 a6 8.a4
a5 9.h4 h5 10.Le3 Sa6 11.f3 e5 12.d5 Sd7 13.Sf1 Sdc5 14.Sd2 Db6
15.Db1 Sb4 16.Sb3 Scd3+ 17.Kd2 Dxe3+}

June 23, 201953

xskak 1.5

\newcounter{chessmoves}\begin{frame}{\xskakgetgame{white} -- \xskakgetgame{black}}\begin{columns}[T]\column[T]{0.5\textwidth}\setcounter{chessmoves}{0}%\xskakloop{%\getmovestyle{\xskakget{piecechar}}%\refstepcounter{chessmoves}%\only<\arabic{chessmoves}>{%\chessboard[%
margin=false,showmover=false,inverse,
pgfstyle=\mymovestyle,color=blue,
linewidth=0.1em, pgfshortenend=0.4em,
arrow=to, markmoves=\xskakget{move},setfen=\xskakget{nextfen},coloremph,piececolor=blue,
emphfields={\xskakget{moveto}}
]\par
}%
}
\column[T]{0.45\textwidth}%\renewcommand\baselinestretch{1.2}\footnotesize\setcounter{chessmoves}{0}%\xskakloop{%\refstepcounter{chessmoves}%{ \color<\arabic{chessmoves}>{blue}%\uncover<\arabic{chessmoves}->{%\ifthenelse{\equal{\xskakget{player}}{w}}{\xskakget{opennr}}{}\xskakget{lan}}}}\xskakgetgame{result}\end{columns}\end{frame}\end{document}

Index
Aafterblack (\xskaknewstyleitem key) . . . . 41
addpieces (move data type) . . . . . . . . . . . . . 22

June 23, 201954

xskak 1.5

afterwhite (\xskaknewstyleitem key) . . . . 41
Bbeamer . . . . . . . . . . . . . . . . . . . . . . . . . . . .
beforeblack (\xskaknewstyleitem key) . . .
beforenumber (\xskaknewstyleitem key) .
beforewhite (\xskaknewstyleitem key) . . .
black (\newchessgame key) . . . . . . . . . . . . .
blackelo (\newchessgame key) . . . . . . . . . .
blackopen (\xskaknewstyleitem key) . . . .

Ffile (\xskakexportgames key) . . . . . . . . . . . 23
font (\xskaknewstyle key) . . . . . . . . . . . . . 44

53G
41
41 game data
\Xskak〈GameId〉diagramlist . . . . . . . . . .
41\Xskak〈GameId〉gameid . . . . . . . . . . . . .
13\Xskak〈GameId〉initfen . . . . . . . . . . . . .
13\Xskak〈GameId〉initmoveid . . . . . . . . . .
41\Xskak〈GameId〉initmovenr . . . . . . . . . .
C\Xskak〈GameId〉initplayer . . . . . . . . . . .
capture (move data type) . . . . . . . . . . . . . . 21
\Xskak〈GameId〉lastfen . . . . . . . . . . . . .
castling (move data type) . . . . . . . . . . . . . . 21
\Xskak〈GameId〉lastmoveid . . . . . . . . . .
\chessboard\Xskak〈GameId〉lastmovenr . . . . . . . . . .
id (key) . . . . . . . . . . . . . . . . . . . . . . . . . . 30
\Xskak〈GameId〉lastplayer . . . . . . . . . . .
lastmoveid (key) . . . . . . . . . . . . . . . . . . . 30
\Xskak〈GameId〉nextmoveid . . . . . . . . .
moveid (key) . . . . . . . . . . . . . . . . . . . . . 30
\Xskak〈GameId〉nextmovenr . . . . . . . . .
movenr (key) . . . . . . . . . . . . . . . . . . . . . 30
\Xskak〈GameId〉nextplayer . . . . . . . . . .
player (key) . . . . . . . . . . . . . . . . . . . . . . 30 games (\xskakexportgames key) . . . . . . . .
reffen (key) . . . . . . . . . . . . . . . . . . . . . . . 33 ginvar (\mainline key) . . . . . . . . . . . . . . . .
refid (key) . . . . . . . . . . . . . . . . . . . . . . . . 33 ginvar (\printchessgame key) . . . . . . . . . .
refnext (key) . . . . . . . . . . . . . . . . . . . . . . 33 ginvar (\variation key) . . . . . . . . . . . . . . .
refnextmoveid (key) . . . . . . . . . . . . . . . . 33 ginvar (\xskakset key) . . . . . . . . . . . . . . . .
refnextmovenr (key) . . . . . . . . . . . . . . . . 33 glevel (\mainline key) . . . . . . . . . . . . . . . .
refnextplayer (key) . . . . . . . . . . . . . . . . . 33 glevel (\printchessgame key) . . . . . . . . . .
refpast (key) . . . . . . . . . . . . . . . . . . . . . . 33 glevel (\variation key) . . . . . . . . . . . . . . .
refpastmoveid (key) . . . . . . . . . . . . . . . . 33 glevel (\xskakset key) . . . . . . . . . . . . . . . .
refpastmovenr (key) . . . . . . . . . . . . . . . . 33 goutvar (\mainline key) . . . . . . . . . . . . . . .
refpastplayer (key) . . . . . . . . . . . . . . . . . 33 goutvar (\printchessgame key) . . . . . . . . .
reftag (key) . . . . . . . . . . . . . . . . . . . . . . . 32 goutvar (\variation key) . . . . . . . . . . . . . .
clearfields (move data type) . . . . . . . . . . . . 22 goutvar (\xskakset key) . . . . . . . . . . . . . . .
closecommands (\xskaknewstyleitem key) 41 gstyle (\mainline key) . . . . . . . . . . . . . . . .
comments (move data type) . . . . . . . . . . . . 23 gstyle (\printchessgame key) . . . . . . . . . .
gstyle (\variation key) . . . . . . . . . . . . . . .
Dgstyle (\xskakset key) . . . . . . . . . . . . . . . .
date (\newchessgame key) . . . . . . . . . . . . . 13
Idefaultfen (\xskakset key) . . . . . . . . . . . . . 28
id(
\newchessgame
key)...............
defaultid (\xskakset key) . . . . . . . . . . . . . . 27
id(\printchessgame
key).............
defaultmoveid (\xskakset key) . . . . . . . . . 28
defaultmovenr (\xskakset key) . . . . . . . . . 28 id (\resumechessgame key) . . . . . . . . . . . .
defaultplayer (\xskakset key) . . . . . . . . . . 28 id (\xskakloop key) . . . . . . . . . . . . . . . . . .
id (\xskakset key) . . . . . . . . . . . . . . . . . . .
Einitmoveid (\printchessgame key) . . . . . .
enpassant (move data type) . . . . . . . . . . . . 21 initmoveid (\xskakloop key) . . . . . . . . . . .
enpassantsquare (move data type) . . . . . . . 21 initmovenr (\printchessgame key) . . . . . .
event (\newchessgame key) . . . . . . . . . . . . . 13 initmovenr (\xskakloop key) . . . . . . . . . . .

June 23, 2019

55

19
19
17
18
18
18
18
18
18
18
19
19
19
23
47
47
47
47
46
46
46
46
47
47
47
47
46
46
46
46

12
48
15
35
27
48
35
48
35

xskak 1.5

initplayer (\printchessgame key) . . . . . . . 48
initplayer (\xskakloop key) . . . . . . . . . . . . 35
invar (\mainline key) . . . . . . . . . . . . . . . . . 46
invar (\printchessgame key) . . . . . . . . 46, 48
invar (\variation key) . . . . . . . . . . . . . . . . 46
invar (\xskakset key) . . . . . . . . . . . . . . . . . 46
Llan (move data type) . . . . . . . . . . . . . . . . . . 22
lastmoveid (\chessboard key) . . . . . . . . . . 30
lastmoveid (\xskakset key) . . . . . . . . . . . . 27
level (\mainline key) . . . . . . . . . . . . . . . . . 46
level (\printchessgame key) . . . . . . . . 46, 48
level (\variation key) . . . . . . . . . . . . . . . . 46
level (\xskaknewstyle key) . . . . . . . . . . . . 43
level (\xskakset key) . . . . . . . . . . . . . . . . . 46
longcastling (move data type) . . . . . . . . . . . 21
\longmoves . . . . . . . . . . . . . . . . . . . . . 6, 38, 42
lostpiece (move data type) . . . . . . . . . . . . . 21
lostpiecechar (move data type) . . . . . . . . . . 21
M\mainline

ginvar (key) . . . . . . . . . . . . . . . . . . . . . .
glevel (key) . . . . . . . . . . . . . . . . . . . . . . .
goutvar (key) . . . . . . . . . . . . . . . . . . . . .
gstyle (key) . . . . . . . . . . . . . . . . . . . . . . .
invar (key) . . . . . . . . . . . . . . . . . . . . . . .
level (key) . . . . . . . . . . . . . . . . . . . . . . . .
outvar (key) . . . . . . . . . . . . . . . . . . . . . .
style (key) . . . . . . . . . . . . . . . . . . . . . . . .
Move data
addpieces . . . . . . . . . . . . . . . . . . . . . . . .
capture . . . . . . . . . . . . . . . . . . . . . . . . .
castling . . . . . . . . . . . . . . . . . . . . . . . . .
clearfields . . . . . . . . . . . . . . . . . . . . . . .
comments . . . . . . . . . . . . . . . . . . . . . . .
enpassant . . . . . . . . . . . . . . . . . . . . . . .
enpassantsquare . . . . . . . . . . . . . . . . . .
lan . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
longcastling . . . . . . . . . . . . . . . . . . . . . .
lostpiece . . . . . . . . . . . . . . . . . . . . . . . .
lostpiecechar . . . . . . . . . . . . . . . . . . . . .
movefrom . . . . . . . . . . . . . . . . . . . . . . .
moveid (virtual type) . . . . . . . . . . . . . . .
movenr (virtual type) . . . . . . . . . . . . . . .
moveto . . . . . . . . . . . . . . . . . . . . . . . . . .

June 23, 2019nag . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
nextfen . . . . . . . . . . . . . . . . . . . . . . . . . .
opennr . . . . . . . . . . . . . . . . . . . . . . . . . .
pastfen . . . . . . . . . . . . . . . . . . . . . . . . . .
pgnlostpiece . . . . . . . . . . . . . . . . . . . . .
pgnmovefrom . . . . . . . . . . . . . . . . . . . .
pgnpiece . . . . . . . . . . . . . . . . . . . . . . . .
piece . . . . . . . . . . . . . . . . . . . . . . . . . . .
piecechar . . . . . . . . . . . . . . . . . . . . . . . .
player (virtual type) . . . . . . . . . . . . . . . .
promotion . . . . . . . . . . . . . . . . . . . . . . .
promotionpiece . . . . . . . . . . . . . . . . . . .
promotionpiecechar . . . . . . . . . . . . . . .
san . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
movefrom (move data type) . . . . . . . . . . . .
moveid (\chessboard key) . . . . . . . . . . . . .
moveid (\newchessgame key) . . . . . . . . . . .
moveid (\resumechessgame key) . . . . . . . .
moveid (\xskakset key) . . . . . . . . . . . . . . .
moveid (virtual move data type) . . . . . . . . .
movenr (\chessboard key) . . . . . . . . . . . . .
movenr (\newchessgame key) . . . . . . . . . . .
movenr (\resumechessgame key) . . . . . . . .
movenr (\xskakset key) . . . . . . . . . . . . . . .
movenr (virtual move data type) . . . . . . . . .
moveto (move data type) . . . . . . . . . . . . . . .

47
46
47
46
46
N
46 nag (move data type) . . . . . . . . . . . . . . . . . .
47 \newchessgame
46
black (key) . . . . . . . . . . . . . . . . . . . . . . .
blackelo (key) . . . . . . . . . . . . . . . . . . . . .
22date (key) . . . . . . . . . . . . . . . . . . . . . . . .
21
event (key) . . . . . . . . . . . . . . . . . . . . . . .
21
id (key) . . . . . . . . . . . . . . . . . . . . . . . . . .
22
moveid (key) . . . . . . . . . . . . . . . . . . . . .
23
movenr (key) . . . . . . . . . . . . . . . . . . . . .
21
newvar (key) . . . . . . . . . . . . . . . . . . . . .
21
player (key) . . . . . . . . . . . . . . . . . . . . . .
22
reffen (key) . . . . . . . . . . . . . . . . . . . . . . .
21
refid (key) . . . . . . . . . . . . . . . . . . . . . . . .
21
refnext (key) . . . . . . . . . . . . . . . . . . . . . .
21
refnextmoveid (key) . . . . . . . . . . . . . . . .
21
refnextmovenr (key) . . . . . . . . . . . . . . . .
29
refnextplayer (key) . . . . . . . . . . . . . . . . .
29
refpast (key) . . . . . . . . . . . . . . . . . . . . . .
21
refpastmoveid (key) . . . . . . . . . . . . . . . .

56

23
22
22
22
20
21
20
20
20
29
21
21
21
22
21
30
12
15
27
29
30
12
15
27
29
21

23
13
13
13
13
12
12
12
13
12
33
33
33
33
33
33
33
33

xskak 1.5

refpastmovenr (key) . . . . . . . . . . . . . . . . 33 \printchessgame
ginvar (key) . . . . . . . . . . . . . . . . . . . . . . 47
refpastplayer (key) . . . . . . . . . . . . . . . . . 33
glevel (key) . . . . . . . . . . . . . . . . . . . . . . . 46
reftag (key) . . . . . . . . . . . . . . . . . . . . . . . 32
goutvar (key) . . . . . . . . . . . . . . . . . . . . . 47
result (key) . . . . . . . . . . . . . . . . . . . . . . . 13
gstyle (key) . . . . . . . . . . . . . . . . . . . . . . . 46
round (key) . . . . . . . . . . . . . . . . . . . . . . 13
id (key) . . . . . . . . . . . . . . . . . . . . . . . . . . 48
site (key) . . . . . . . . . . . . . . . . . . . . . . . . 13
initmoveid (key) . . . . . . . . . . . . . . . . . . . 48
using chessboard keys . . . . . . . . . . . . . . 13
initmovenr (key) . . . . . . . . . . . . . . . . . . 48
white (key) . . . . . . . . . . . . . . . . . . . . . . . 13
initplayer (key) . . . . . . . . . . . . . . . . . . . . 48
whiteelo (key) . . . . . . . . . . . . . . . . . . . . 13
invar (key) . . . . . . . . . . . . . . . . . . . . 46, 48\newchessgame – usage . . . . . . . . . . . . . . . 11
level (key) . . . . . . . . . . . . . . . . . . . . . 46, 48
newvar (\newchessgame key) . . . . . . . . . . . 13
outvar (key) . . . . . . . . . . . . . . . . . . . 47, 48
newvar (\resumechessgame key) . . . . . . . . 16
refid (key) . . . . . . . . . . . . . . . . . . . . . . . . 48
nextfen (move data type) . . . . . . . . . . . . . . . 22
reftag (key) . . . . . . . . . . . . . . . . . . . . . . . 48
nopdfmatch (package option) . . . . . . . . . . . . 7
stopmoveid (key) . . . . . . . . . . . . . . . . . . 48
stopmovenr (key) . . . . . . . . . . . . . . . . . . 48
O
stopplayer (key) . . . . . . . . . . . . . . . . . . . 48
opencommands (\xskaknewstyleitem key) 41
style (key) . . . . . . . . . . . . . . . . . . . . . 46, 48
opennr (move data type) . . . . . . . . . . . . . . . 22
\printchessgame– usage . . . . . . . . . . . . . . 48
outvar (\mainline key) . . . . . . . . . . . . . . . . 47
outvar (\printchessgame key) . . . . . . . 47, 48 \xskakloop
reftag (key) . . . . . . . . . . . . . . . . . . . . . . .
outvar (\variation key) . . . . . . . . . . . . . . . 47
promotion(move data type) . . . . . . . . . . . .
outvar (\xskakset key) . . . . . . . . . . . . . . . . 47
promotionpiece (move data type) . . . . . . . .
promotionpiecechar (move data type) . . . .
P
pastfen (move data type) . . . . . . . . . . . . . . . 22
PGN-info data
\Xskak〈GameId〉black . . . . . . . . . . . . . . 19
\Xskak〈GameId〉blackelo . . . . . . . . . . . . 20
\Xskak〈GameId〉date . . . . . . . . . . . . . . . 20
\Xskak〈GameId〉event . . . . . . . . . . . . . . 20
\Xskak〈GameId〉result . . . . . . . . . . . . . . 19
\Xskak〈GameId〉round . . . . . . . . . . . . . . 20
\Xskak〈GameId〉site . . . . . . . . . . . . . . . . 20
\Xskak〈GameId〉white . . . . . . . . . . . . . . 19
\Xskak〈GameId〉whiteelo . . . . . . . . . . . . 19
PGN-infos . . . . . . see (\newchessgame keys)13
pgnlostpiece (move data type) . . . . . . . . . . 20
pgnmovefrom (move data type) . . . . . . . . . 21
pgnpiece (move data type) . . . . . . . . . . . . . 20
piece (move data type) . . . . . . . . . . . . . . . . 20
piecechar (move data type) . . . . . . . . . . . . . 20
player (\chessboard key) . . . . . . . . . . . . . . 30
player (\newchessgame key) . . . . . . . . . . . . 12
player (\resumechessgame key) . . . . . . . . . 15
player (\xskakset key) . . . . . . . . . . . . . . . . 27
player (virtual move data type) . . . . . . . . . . 29

June 23, 2019

32
21
21
21

R
reffen (\chessboard key) . . . . . . . . . . . . . . 33
reffen (\newchessgame key) . . . . . . . . . . . . 33
refid (\chessboard key) . . . . . . . . . . . . . . . 33
refid (\newchessgame key) . . . . . . . . . . . . . 33
refid (\printchessgame key) . . . . . . . . . . . 48
refid (\resumechessgame key) . . . . . . . . . . 33
refid (\xskakloop key) . . . . . . . . . . . . . . . . 33
refid (\xskakset key) . . . . . . . . . . . . . . 27, 33
refnext (\chessboard key) . . . . . . . . . . . . . 33
refnext (\newchessgame key) . . . . . . . . . . . 33
refnext (\resumechessgame key) . . . . . . . . 33
refnext (\xskakset key) . . . . . . . . . . . . 27, 33
refnextmoveid (\chessboard key) . . . . . . . 33
refnextmoveid (\newchessgame key) . . . . . 33
refnextmoveid (\resumechessgame key) . . . 33
refnextmoveid (\xskakset key) . . . . . . 27, 33
refnextmovenr (\chessboard key) . . . . . . . 33
refnextmovenr (\newchessgame key) . . . . . 33
refnextmovenr (\resumechessgame key) . . 33
refnextmovenr (\xskakset key) . . . . . . 27, 33
refnextplayer (\chessboard key) . . . . . . . . 33

57

xskak 1.5

refnextplayer (\newchessgame key) . . . . . . 33
refnextplayer (\resumechessgame key) . . . . 33
refnextplayer (\xskakset key) . . . . . . . 27, 33
refpast (\chessboard key) . . . . . . . . . . . . . 33
refpast (\newchessgame key) . . . . . . . . . . . 33
refpast (\resumechessgame key) . . . . . . . . . 33
refpast (\xskakset key) . . . . . . . . . . . . 27, 33
refpastmoveid (\chessboard key) . . . . . . . 33
refpastmoveid (\newchessgame key) . . . . . . 33
refpastmoveid (\resumechessgame key) . . . 33
refpastmoveid (\xskakset key) . . . . . . 27, 33
refpastmovenr (\chessboard key) . . . . . . . 33
refpastmovenr (\newchessgame key) . . . . . 33
refpastmovenr (\resumechessgame key) . . 33
refpastmovenr (\xskakset key) . . . . . . 27, 33
refpastplayer (\chessboard key) . . . . . . . . 33
refpastplayer (\newchessgame key) . . . . . . . 33
refpastplayer (\resumechessgame key) . . . . 33
refpastplayer (\xskakset key) . . . . . . . 27, 33
reftag (\chessboard key) . . . . . . . . . . . . . . 32
reftag (\newchessgame key) . . . . . . . . . . . . 32
reftag (\printchessgame key) . . . . . . . 32, 48
reftag (\resumechessgame key) . . . . . . . . . 32
reftag (\xskakloop key) . . . . . . . . . . . . . . . 32
reftag (\xskakset key) . . . . . . . . . . . . . . . . 32
result (\newchessgame key) . . . . . . . . . . . . 13

\shortmoves . . . . . . . . . . . . . . . . . . . . . . 6, 42
showlast (\xskakloop key) . . . . . . . . . . . . . 35
site (\newchessgame key) . . . . . . . . . . . . . . 13
step (\xskakloop key) . . . . . . . . . . . . . . . . 35
stepmoveid (\chessboard key) . . . . . . . . . . 30
stepmoveid (\xskakset key) . . . . . . . . . . . . 27
stopmoveid (\printchessgame key) . . . . . . 48
stopmoveid (\xskakloop key) . . . . . . . . . . 35
stopmovenr (\printchessgame key) . . . . . 48
stopmovenr (\xskakloop key) . . . . . . . . . . 35
stopplayer (\printchessgame key) . . . . . . . 48
stopplayer (\xskakloop key) . . . . . . . . . . . 35
style (\mainline key) . . . . . . . . . . . . . . . . . 46
style (\printchessgame key) . . . . . . . . 46, 48
style (\variation key) . . . . . . . . . . . . . . . . 46
style (\xskakset key) . . . . . . . . . . . . . . . . . 46

style item . . . . . . . . . . . . . . . . . . . . . . . . . . 40
styleitem (\xskaknewstyle key) . . . . . . . . . 44
Ttag (\xskakset key) . . . . . . . . . . . . . . . 27, 32
template (\xskaknewstyleitem key) . . . . . 42
texmate . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
V\variation

ginvar (key) . . . . . . . . . . . . . . . . . . . . . .
glevel (key) . . . . . . . . . . . . . . . . . . . . . . .
goutvar (key) . . . . . . . . . . . . . . . . . . . . .
gstyle (key) . . . . . . . . . . . . . . . . . . . . . . .
invar (key) . . . . . . . . . . . . . . . . . . . . . . .
level (key) . . . . . . . . . . . . . . . . . . . . . . . .
outvar (key) . . . . . . . . . . . . . . . . . . . . . .
style (key) . . . . . . . . . . . . . . . . . . . . . . . .

\resumechessgame

id (key) . . . . . . . . . . . . . . . . . . . . . . . . . .
moveid (key) . . . . . . . . . . . . . . . . . . . . .
movenr (key) . . . . . . . . . . . . . . . . . . . . .
newvar (key) . . . . . . . . . . . . . . . . . . . . .
player (key) . . . . . . . . . . . . . . . . . . . . . .
refid (key) . . . . . . . . . . . . . . . . . . . . . . . .
refnext (key) . . . . . . . . . . . . . . . . . . . . . .
refnextmoveid (key) . . . . . . . . . . . . . . . .
refnextmovenr (key) . . . . . . . . . . . . . . . .
refnextplayer (key) . . . . . . . . . . . . . . . . .
refpast (key) . . . . . . . . . . . . . . . . . . . . . .
refpastmoveid (key) . . . . . . . . . . . . . . . .
refpastmovenr (key) . . . . . . . . . . . . . . . .
refpastplayer (key) . . . . . . . . . . . . . . . . .
reftag (key) . . . . . . . . . . . . . . . . . . . . . . .
\resumechessgame – usage . . . . . . . . . . . . .
round (\newchessgame key) . . . . . . . . . . . .

15
15
15
16
15
33
33
33
33
33
33
33
33
33
32
15
13

W
white (\newchessgame key) . . . . . . . . . . . . . 13
whiteelo (\newchessgame key) . . . . . . . . . . 13
whiteopen (\xskaknewstyleitem key) . . . . 41

X
xfont (\xskaknewstyle key) . . . . . . . . . . . .
\xskakaddtostyle – usage . . . . . . . . . . . . .
\Xskak〈GameId〉black . . . . . . . . . . . . . . . . .
\Xskak〈GameId〉blackelo . . . . . . . . . . . . . . .
\xskakcurrentgameid – usage . . . . . . . . . .
S\Xskak〈GameId〉date . . . . . . . . . . . . . . . . . .
san (move data type) . . . . . . . . . . . . . . . . . . 22 \Xskak〈GameId〉diagramlist . . . . . . . . . . . .

June 23, 2019

47
46
47
46
46
46
47
46

58

44
42
19
20
24
20
19

xskak 1.5

\xskakendgamedata – usage . . . . . . . . . . . . 24
\xskakenpassanttext – usage . . . . . . . . . . 39

\Xskak〈GameId〉event . . . . . . . . . . . . . . . . . 20
\xskakexportgames

file (key) . . . . . . . . . . . . . . . . . . . . . . . . .
games (key) . . . . . . . . . . . . . . . . . . . . . .
\xskakexportgames – usage . . . . . . . . . . . .
\Xskak〈GameId〉gameid . . . . . . . . . . . . . . .
\xskakget (with \chessboard) . . . . . . . . .
\xskakget – usage . . . . . . . . . . . . . . . . . . .
\xskakgetgame – usage . . . . . . . . . . . . . . .
\Xskak〈GameId〉initfen . . . . . . . . . . . . . . . .
\Xskak〈GameId〉initmoveid . . . . . . . . . . . . .
\Xskak〈GameId〉initmovenr . . . . . . . . . . . .
\Xskak〈GameId〉initplayer . . . . . . . . . . . . . .
\Xskak〈GameId〉lastfen . . . . . . . . . . . . . . . .
\Xskak〈GameId〉lastmoveid . . . . . . . . . . . . .
\Xskak〈GameId〉lastmovenr . . . . . . . . . . . .
\Xskak〈GameId〉lastplayer . . . . . . . . . . . . . .

closecommands (key) . . . . . . . . . . . . . .
opencommands (key) . . . . . . . . . . . . . .
template (key) . . . . . . . . . . . . . . . . . . . .
whiteopen (key) . . . . . . . . . . . . . . . . . . .
\xskaknewstyleitem – usage . . . . . . . . . . .
\Xskak〈GameId〉nextmoveid . . . . . . . . . . . .
\Xskak〈GameId〉nextmovenr . . . . . . . . . . . .
\Xskak〈GameId〉nextplayer . . . . . . . . . . . . .
\Xskak〈GameId〉result . . . . . . . . . . . . . . . . .
\Xskak〈GameId〉round . . . . . . . . . . . . . . . .

41
41
42
41
41
19
19
19
19
20

23
23
23
19
31
29
28 \chessboard
stepmoveid (key) . . . . . . . . . . . . . . . . . . 30
1718 \xskakset
defaultfen (key) . . . . . . . . . . . . . . . . . . . 28
18
defaultid (key) . . . . . . . . . . . . . . . . . . . . 27
18
defaultmoveid (key) . . . . . . . . . . . . . . . . 28
18
defaultmovenr (key) . . . . . . . . . . . . . . . . 28
18
defaultplayer (key) . . . . . . . . . . . . . . . . . 28
18
ginvar (key) . . . . . . . . . . . . . . . . . . . . . . 47
18
glevel (key) . . . . . . . . . . . . . . . . . . . . . . . 46
\xskakloop
goutvar (key) . . . . . . . . . . . . . . . . . . . . . 47
id (key) . . . . . . . . . . . . . . . . . . . . . . . . . . 35
gstyle (key) . . . . . . . . . . . . . . . . . . . . . . . 46
initmoveid (key) . . . . . . . . . . . . . . . . . . . 35
id (key) . . . . . . . . . . . . . . . . . . . . . . . . . . 27
initmovenr (key) . . . . . . . . . . . . . . . . . . 35
invar (key) . . . . . . . . . . . . . . . . . . . . . . . 46
initplayer (key) . . . . . . . . . . . . . . . . . . . . 35
lastmoveid (key) . . . . . . . . . . . . . . . . . . . 27
refid (key) . . . . . . . . . . . . . . . . . . . . . . . . 33
level (key) . . . . . . . . . . . . . . . . . . . . . . . . 46
reftag (key) . . . . . . . . . . . . . . . . . . . . . . . 32
moveid (key) . . . . . . . . . . . . . . . . . . . . . 27
showlast (key) . . . . . . . . . . . . . . . . . . . . 35
movenr (key) . . . . . . . . . . . . . . . . . . . . . 27
step (key) . . . . . . . . . . . . . . . . . . . . . . . . 35
outvar (key) . . . . . . . . . . . . . . . . . . . . . . 47
stopmoveid (key) . . . . . . . . . . . . . . . . . . 35
player (key) . . . . . . . . . . . . . . . . . . . . . . 27
stopmovenr (key) . . . . . . . . . . . . . . . . . . 35
refid (key) . . . . . . . . . . . . . . . . . . . . . 27, 33
stopplayer (key) . . . . . . . . . . . . . . . . . . . 35
refnext (key) . . . . . . . . . . . . . . . . . . . 27, 33\xskakloop – usage . . . . . . . . . . . . . . . . . . 35
refnextmoveid (key) . . . . . . . . . . . . . . . . 33
\xskaknewpgninfo – usage . . . . . . . . . . 13, 19
refnextmoveid(key) . . . . . . . . . . . . . . . . 27
\xskaknewstylerefnextmovenr (key) . . . . . . . . . . . . . 27, 33
font (key) . . . . . . . . . . . . . . . . . . . . . . . . 44
refnextplayer (key) . . . . . . . . . . . . . . 27, 33
level (key) . . . . . . . . . . . . . . . . . . . . . . . . 43
refpast (key) . . . . . . . . . . . . . . . . . . . 27, 33
styleitem (key) . . . . . . . . . . . . . . . . . . . . 44
refpastmoveid (key) . . . . . . . . . . . . . . . . 33
xfont (key) . . . . . . . . . . . . . . . . . . . . . . . 44
refpastmoveid(key) . . . . . . . . . . . . . . . . 27
\xskaknewstyle – usage . . . . . . . . . . . . . . 42
refpastmovenr (key) . . . . . . . . . . . . . 27, 33\xskaknewstyleitem
refpastplayer (key) . . . . . . . . . . . . . . 27, 33
afterblack (key) . . . . . . . . . . . . . . . . . . . 41
reftag (key) . . . . . . . . . . . . . . . . . . . . . . . 32
afterwhite (key) . . . . . . . . . . . . . . . . . . . 41
stepmoveid (key) . . . . . . . . . . . . . . . . . . 27
beforeblack (key) . . . . . . . . . . . . . . . . . . 41
style (key) . . . . . . . . . . . . . . . . . . . . . . . . 46
beforenumber (key) . . . . . . . . . . . . . . . . 41
tag (key) . . . . . . . . . . . . . . . . . . . . . . 27, 32
beforewhite (key) . . . . . . . . . . . . . . . . . . 41
blackopen (key) . . . . . . . . . . . . . . . . . . . 41 \xskakset – usage . . . . . . . . . . . . . . . . . . . 27

June 23, 201959

xskak 1.5

\Xskak〈GameId〉site . . . . . . . . . . . . . . . . . . 20 \Xskak〈GameId〉white . . . . . . . . . . . . . . . . . 19
\Xskak〈GameId〉whiteelo . . . . . . . . . . . . . . 19

\xskaktestmoveid – usage . . . . . . . . . . . . . 35

June 23, 201960

xskak 1.5