Typesetting Chess in L^{A}TEXwith the skak Package

Torben Hoffmann

e-mail: toho@it.dtu.dk

June 30, 2000

Abstract

This user guide will show how to use an enhancement to the existing package for typesetting chess in L^{A}TEX(skak). The primary improvement over the old package is that it has become easier to typeset chess games with this new package, as we shall demonstrate in this user guide.

1 Terms of Usage

This package is distributed under the terms described in the Latex Project Public Licence, i.e.,

This software is copyright but you are granted a license which gives you, the “user” of the software, legal permission to copy, distribute, and/or modify the software. However, if you modify the software and then distribute it (even just locally) you must change the name of the software to avoid confusion.

2 Acknowledgements

I would like to thank the creator of the lambda package, Alan Jeffrey, for making a splendid package that made this package possible.

For discussions and alpha-testing I send my thanks to Guido Governatori— some of his ideas have allready been implemented; the rest? Time will show.

3 The Old chess Package Versus the New skak Package

The main reason for considering an improvement of the chess package that Piet Tutelaers made back in 1991 is the cumbersome user interface the package has when one wants to write about a chess game and display a diagram every now and then. Typesetting the two opening moves where white and black moves their kingside knights is done as follows in the chess package:

\move g1f3 g8f6

The package then produces a nice typesetting of these moves in figurine notation, but it is hard to keep track of what is going on because the one usually uses the PGN notation to write down the moves of a chess game. The PGN version of the two moves above is: 1. Nf3 Nf6, which is much clearer to most chess players. In the skak package we allow the author of a chess article to use the PGN notation as input to the command that updates the chess board. In addition to making it easier for the author to write about chess using a familiar notation it also provides an easy way to include moves generated by a chess program such as xboardin the document—most other chess programs can also output a PGN version of a chess game.

The skak can also input chess board positions given in the FEN notation, which is also quite standard in the domain of chess programs. Besides a better user interface the chess font the skak package uses is three small modifications of the font created by Piet Tutelaers: the knight now looks a bit more “youthfull”, the contur of the queen has been smoothened and all the chess pieces has been shrunk such that they do not fill as much of a square as before. We find this font nicer to look at, but your milage may vary.

4 How to use the skak Package

Writing about a chess game is straightforward:

\newgame
\mainline{1. e4 e5 2. Nf3 Bc5}

starts a new game and produces the following in your document:

1 e4 e5 2 f3 c5.

So far, so good. And just like the old chess package we can produce a chess board in our ducument: \[\showboard\] yields

8 ^{7} ^{6} ^{5} ^{4} ^{3} ^{2} ^{1} a b c d e f g h

(the use of math \[...\] is just to make sure the board is centered.)

The board comes in four different sizes: tiny, small, normal (which we just saw) and large. The size used can be altered at any time in a

                                          document using the \tinyboard, \smallboard,
                                          \normalboard and \largeboard.

The size of the figurine notation is determined automatically for the standard font sizes 10pt, 11pt and 12pt — other sizes can be made by creating a new Metafont file based on the file

                                          fig10.mf.

It is also possible to use ones native language as input to mainline. First create a new lan-

                                          guage: \newskaklanguage{danish}{KDTLSB},

the first argument is the name of the language and the second argument is the uppercase letters used in that language to denote a king, queen, rook, bishop, knight and pawn. The newlanguage can then be activated using

                                          \skaklanguage[danish], and the package will

take care of the translation to english piece

                                          names. An example: \mainline{3. De2 De7}

will now move the white queen to e2.

3. e2, e7

Notice that we have changed the typesetting of the moves from the more modern way of showing the figurine notation to the traditional german/danish way of doing it. This is done with the command \styleA — switching back is done

with \styleB.

There is another style available as well, \styleC, which will be demonstrated below.

8 ^{7} ^{6} ^{5} ^{4} ^{3} ^{2} ^{1} a b c d e f g h

Going back to english is easy: just type \skaklanguage (english is the default arug-

ment). Now \mainline{4. Nc3 b7} will give
us (in \styleC):

4  c3  b7

Notice that we used ... instead of . after the number to denote that is a black move we start with; if the input move colour does not match the state of the game the package will issue a error message. Another thing to notice is that the move is not separated from the periods by a space — this feature is due to some programs that output PGN writes the move directly after the period(s) (observation by Guido Governatori).

Some input errors will be detected and an error message will be issued, but with regards to the validity of the moves used as argument to \mainline only the valid moves are guaranteed to work—invalid moves will produce error messages or spurious chess positions!

It is often the case that one wants to comment on a small variation of the move sequence played, and for that purpose we have the \variation which displays the moves but it does not update the chess board. So

                                          \variation{3... Qf6 4. Nc3 b7} produces

3  …  f6
4  c3  b7

in the document, but the chess board remains unchanged (see below). If one wants to use a different typesetting style for the variations one has to redefine the \mainlinestyle and

                                          \variationstyle commands, eg,
                                          \def\mainlinestyle{\styleC\bfseries%
                                                 \let\Fig=\Figb} %\styleC added
                                          \def\variationstyle{\styleB\let\Fig=\Fign}

This will use the more spaceconsuming style for the mainline and the more textlike for the variations — this style is often used in books.

1 ^{2} ^{3} ^{4} ^{5} ^{6} ^{7} ^{8} h g f e d c b a

apart from the obvious fact that we have just shown the board from the perspective of black— this is done using the \showinverseboard command. Speaking of showing the board: it is also possible to toggle the use of rank and file names besides the board. \notationOff turns them off and \notationOn turns them back on. Let’s try turning them off:

4.1 Updating the Board

The command \hidemoves updates the board but does not update the board — this could come in handy in situations where you have the PGN of a game available but only wants to focus on the game after some moves.

Another way of setting up the board is using the FEN notation as argument to the \fenboard command. The \newgame command uses this command to setup the board in the first place like this:

\def\newgame{%
\fenboard{rnbqkbnr/pppppppp/8/8/8/8/
     PPPPPPPP/RNBQKBNR w KQkq - 0 1}}

The first part of the FEN string is the rows (from 8 to 1) separated by /; the black pieces uses small letters and the uppercase letters denotes white picecs; numbers denote empty squares. After the position has been stated the player to move is denoted using w or b, then we have the castling posibilities, followed by a square where one can make an en passant capture. The numbers denote the number of plies since a capture or pawn-move (used in the 50moves rule) and finaly we have the move number.

4.2 Game storage

Chess positions can be imported and exported using the FEN notation: \savegame{game1} will save the current position in the file game1.fen and \load{game1} will set the chess board to the position described in the file game1.fen. We save the position now, make a move

5 b3

, loads the saved game and the board has not changed one bit:

Games can also be stored and restored without resorting to files using the \storegame and \restoregame commands. We test the functionality of these commands right here:

\storegame{Joe-Mike,991010} followed by

5  b3  d6

6 a3

  and  \restoregame{Joe-Mike,991010}

—notice the free form naming of games.

4.3 Ornaments

The command \showmoverOff will turn of the showing of how is to move:

It can be turned on again with \showmoverOn. Finally, it is also possible to show only

some of the pieces on the board with the

commands \showonlywhite, \showonlyblack,
\showonlypawns and the general \showonly

which takes a comma separated list of piece names (in english! I have not had the time to do it for the current language — volunteer work apreciated here). Showing all pieces again is done with \showall.

Furthermore, it is possible to highlight squares on the board, e.g., \highlight{a2,b3} will highlight the squares a2 and b3.

Note, that \highlight is called after \showboard. Some dvi-viewers (e.g.,xdvi) will not show the highlighting box properly, but the PostScript-file will be allright.

The arrows in on the board has been generated using the com-

mands  \printknightmove{g1}{f3},
\printarrow{f1}{b5}  and
\printarrow{a1}{a8}.  The

\printknightmove command only behaves well for prober input, i.e., the two arguments describe a valid move by a knight. \printarrow draws a arrow between any two squares on the board — I think that only diagonals, ranks and files are needed, but the general solution was easier to implement.

Missing from the documentation:

• how to define your own typesetting of moves

• list of options to the class

• a rewrite of the documentation in order to present the many posibilities on more pages.

5 Installing the skak Package

I could not get the makefile to do the job, so if someone could help me out on this I would be very glad indeed.

Basically all you have to do is to follow the guidelines in the makefile. First you create all the required directories (stated in the install section of the makefile) and then you run the make install command. Remember to run texhash after you have updated your texmf tree.

Sorry that is not working 100%— I just do not have the time for it right now.

If you cannot get the things working just put the files where TEXand the other tools can find them and you will be just fine.

5.1 Using the lambda Package

The skak package uses the lambda package to do some of the hard processing necessary to allow the PGN notation as input — since it is not standard in L^{A}TEXdistributions it is included in the distribution of the skak package.

6 Future Additions

It would be nice if one could choose the language

for the mainline, variation and \hidemoves

for each invocation as it allows for easier inclusion of analysis from chess programs when using a non-english language.