# Color of chess notation (xskak)

I would like to set color for specific moves in \mainline, like \mainline{1. f4 e5 2. {\color{red} g4} Qh4#}.

Is is any way to change the color for some moves?

-
Hi, Welcome to TeX.sx! :) Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. :) By the way, you can use backticks  to mark your inline code as I did in my edit. :) Welcome aboard! – Paulo Cereda Jul 10 '12 at 20:49
I can't get that to work using \mainline but you can get the effect you want (in the obvious straightforward way) if you abandon \mainline and use \wmove commands. – DJP Jul 11 '12 at 1:07

There is no natural way but you can try the following mix of using NAG's to start and stop colors and a hand made style. The main problem is to stop the color: skak (used by xskak) mixes the parsing and the printing and so grouping commands have a tendency to explode.

\documentclass[]{scrbook}
\usepackage{xskak,xcolor}

\newcommand\mycolor{}
%NAG to start color:
\expandafter\def\csname $100\endcsname{\gdef\mycolor{\color{red}}} %NAG to stop color: \expandafter\def\csname$101\endcsname{\gdef\mycolor{\color{black}}}

\xskaknewstyleitem[%
whiteopen={.\,},
beforewhite=\mycolor,
beforeblack=\mycolor,
blackopen={\ldots\,},
afterwhite={\color{black}\ },
beforenumber=\color{black},
afterblack={\ }]{color}

\xskaknewstyle[level= 1,styleitem=color,font=\bfseries,
level= 3,font=\itshape]{color}

\begin{document}
\newchessgame
\mainline[style=color]{1. f4 e5 $100 2. e4$101 e6 3. Nf3 $100 Nf6 4. d4$101 d5}
\end{document}
`
-