LaTeX supports chess notation by means of the package skak. This package also shows a chessboard where the entered moves are displayed.
Contents |
To start writing chess notation, the board mus be set up to the initial position.
\documentclass{article} \usepackage[utf8]{inputenc} \usepackage[english]{babel} \usepackage{skak} \begin{document} Chess notation in \LaTeX{} \medskip \newgame \showboard \end{document}
In the example, the package skak is imported by
\usepackage{skak}
After importing the package you can use all the chess-related commands. Two of them are described below:
\newgame
\showboard
Open an example of the skak package in ShareLaTeX
If you are used to algebraic chess notation, typesetting chess moves is easy. To print the moves as the game progress you must use the command \mainline
.
\documentclass{article} \usepackage[utf8]{inputenc} \usepackage[english]{babel} \usepackage{skak} \begin{document} \mainline{1.e4} \showboard \lastmove{} Is the most common opening move \mainline{1...e5 2.Nf3 Nc6 3.d4} \showboard \mainline{3...e5xd4 4.Bb5 a6 5.O-O} \showboard \end{document}
The command \mainline{}
takes as parameter a set of moves,
after several moves you can print the current state of the chessboard with the command \showboard
.
The notation for the moves is standard algebraic notation in English. See the further reading section for links about this.
The command \lastmove{}
is used to print the last move.
Open an example of the skak package in ShareLaTeX
There's an additional command to print chess notation inline in normal font
\mainline{1...e5 2.Nf3 Nc6 3.d4} \showboard From this point, \variation{3.d3 d5} is a good but far less aggressive alternative. \mainline{3...e5xd4 4.Bb5 a6 5.O-O}
The command \variation{}
helps to analyse variations of a move. The number of the first move passed to this command must be the last move in the immediately previous \mainline
command. For instance, in the example 3.d4
is the last move before analysing a variation, hence 3.d3
is the first move in \variation{}
Open an example of the skak package in ShareLaTeX
If you need to focus on only one side of the board, hiding the opposite colour will greatly help.
\mainline{1...e5 2.Nf3 Nc6 3.d4} \showonlywhite \showboard From this point, \variation{3.d3 d5} is a good but far less aggressive alternative. \mainline{3...e5xd4 4.Bb5 a6 5.O-O} \showonlyblack \showboard
The commands \showonlywhite
and \showonlyblack
will show on the board only the white or black pieces, respectively.
Another feature that is helpful to analyse some moves is to show only the relevant pieces in said moves. This can be accomplished with \showonly
To the command \showonly{}
a list of comma-separated pieces must be passed as parameter inside the braces. See the reference guide for a description of the letters and the pieces they represent.
Open an example of the skak package in ShareLaTeX
You can set up the board in any position.
The command \fenboard{ }
uses FEN notation to set up the board (see further reading). For instance, the example above shows in the row 8 a rook, 5 empty squares, the king and 1 empty square; hence the "r5k1".
Open an example of the skak package in ShareLaTeX
The skak package uses the next list of letters for the piece. In the commands \showonly
and \fenboard
Upper-case letters are used for the white side and lower-case for the black side
Letter | Pieces |
---|---|
K | King |
Q | Queen |
R | Rook |
B | Bishop |
N | Knight |
P | Pawn |
Open an example of the skak package in ShareLaTeX
For more information see: