Skip to content

LaTeX supports chess notation by means of the package skak. This package also shows a chessboard where the entered moves are displayed.

Introduction

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}

ChessNotationEx1.png


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
Starts a new game, sets all the pieces in the starting positions.
\showboard
Prints the chessboard on the document.

  Open an example of the skak package in ShareLaTeX

Writing a move

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}

ChessNotationEx2.png


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

Variations and notes

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}

ChessNotationEx3.png


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

Showing only some pieces

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

ChessNotationEx4.png


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

\mainline{3...e5xd4 4.Bb5 a6 5.O-O}
\showonly{B,Q,q,K,k,N,n}
\showboard

ChessNotationEx5.png


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

Setting up the chessboard

You can set up the board in any position.

\newgame

\fenboard{r5k1/1b1p1ppp/p7/1p1Q4/2p1r3/PP4Pq/BBP2b1P/R4R1K w - - 0 20}

\showboard

ChessNotationEx6.png


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

Reference guide

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

Further reading

For more information see:

Overleaf guides

LaTeX Basics

Mathematics

Figures and tables

References and Citations

Languages

Document structure

Formatting

Fonts

Presentations

Commands

Field specific

Class files

Advanced TeX/LaTeX