[Tex/LaTex] Chess diagramm with arrows in skak, xskak

skakxskak

How can I draw arrows on a chess game?

For example, if the game starts with 1. e4 …, I want to draw a black arrow from e2 to e4 to show the movement, and, in the same diagram, two red arrows from e4 to f5, and another from e4 to d5, to show the pawn attacking the squares.

Following game works for me. I'd like to find additional highlighting possibilities. For example, for educational purposes, an arrow between the knight in f6 to the squares being attacked by it.

\documentclass[a4paper,10pt]{article}
\usepackage{skak}
\usepackage{xskak}


\begin{document}

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

\end{document}

Best Answer

I followed the documentation of the xskak package, especially pages 35 and 36, and this is what I've got.

%! *latex mal-chess.tex
\documentclass[a4paper,10pt]{article}
\pagestyle{empty}\parindent=0pt
\usepackage{xskak}
%\usepackage{chessboard}
\begin{document}
\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
\hidemoves{1. e4 e5 2. Nf3 Bc5}%
%\chessboard[setfen=\xskakgetgame{initfen}]% Show me the empty board.
\xskakloop{%
\getmovestyle{\xskakget{piecechar}}%
\chessboard[pgfstyle=\mymovestyle, color=blue,
  markmoves=\xskakget{move}, pgfshortenend=0.3em, arrow=to, coloremph, color=red, markstyle=circle, markfield=\xskakget{movefrom},
  emphfields=\xskakget{moveto}, setfen=\xskakget{nextfen}]
  }% End of \xskakloop...
\end{document}

mwe