2

I can't for the life of me figure out a proper way to handle NAGs (Numeric Annotation Glyphs) and/or Chess Informant symbols with xskak.

I'm writing a document where I'm handling a lot of variations, so I'm staying away from \newchessgame and \mainline for the most part and putting everything in \variation{}s.

\documentclass{article}
\usepackage{xskak,mathtools,xspace}

\def\invar#1{{\variation[invar]{#1}}}
\def\onlymovesymbol{\ensuremath{\square}}
\def\onlymove{\xskakcomment{\onlymovesymbol}\xspace}
\def\onlymoveNAG{$7}%$ stop highlighting, Emacs+AUCTeX!

\begin{document}
\variation{1.e4 e5 2.Nf3 Nc6 3.Bc4 Nf6 4.Ng5 d5\onlymove 5.Nxe4}

\variation{%
  1.e4 e5 2.Nf3 Nc6 3.Bc4 Bc5 4.c3 Nf6 5.d4 exd4 6.cxd4 Bb4+ 7.Nc3 Nxe4 
  8.O-O Nxc3 9.bxc3 d5} 
\iffalse %This doesn't even compile:
  \invar{9... Bxc3 10.Qb3 d5\onlymove 11.Bxd5 O-O} 
\fi
\end{document}

If one compiles this the square shows up in the first variation, but "5 Nxe4" is printed without the figurine for the "N".

Am I correct in assuming that NAGs only work when xskak actually parses the moves (i.e. only with \mainline{})?

If that's the case, I can't see how I won't have to use \xskakcomment. I know I'm doing something wrong, but I can't for the life of me decipher how one is supposed to accomplish this.

PS: For those who use Emacs + AUCTeX and find this question by searching. Look at the options beginning with LaTeX-verbatim. You can consider adding \mainline, \variation[invar] and \variation[outvar] to the list of verbatim macros with delimiters if you want to use NAGs without AUCTeX spilling the colour for maths mode all over your buffer.

kahen
  • 2,165

1 Answers1

3

You loose the figurine of the move as (x)skak needs to see the spaces between the moves, but your command is eating it. Use braces to prevent this, or use the $7 instead of a command:

\documentclass{article}
\usepackage{xskak}

\begin{document}
\variation{1.e4 $1  e5 $2 2.Nf3 Nc6 3.Bc4 $7 Nf6 4.Ng5 d5\onlymove{} 5.Nxe4}
\end{document}

enter image description here

Edit

skak changes catcodes. So you shouldn't read the argument before this has been done. Define your \invar like this:

  \def\invar{\variation[invar]}

And naturally add braces after the \onlymove there too.

Ulrike Fischer
  • 327,261
  • One solution I've come up with for dealing with subvariations is \def\subv{\variation[invar]{}} \def\endsubv{\variation[outvar]{}} used like this: \variation{<stuff>} \subv \variation{<other stuff>} \endsubv. Ugly, but it kind of works. At least until you get three nested levels of variations (e.g. if you're GM Robert Hübner :D) – kahen May 02 '14 at 16:48
  • I don't understand what you are doing there and why. What's wrong with using \variation[invar]{moves} directly? – Ulrike Fischer May 03 '14 at 16:42
  • I dislike the inconsistency it leads to in the source file: {\variation[invar]{moves} blah blah explanation \variation{more moves}}. It just doesn't look right that a subvariation starts with invar but continues without it. I find that it makes it harder for me to verify that I've written what I wanted. – kahen May 03 '14 at 18:34
  • Hm. I see. Well I can't keep the effect of invar local to the \variation command, this would only be possible with printing commands completly under the control of xskak (like \printchessgame). But you can use braces: {\variation[invar]{..}}. You can also define commands which changes the levels like this: \newcommand\invar{\xskakset{invar}}\newcommand\outvar{\xskakset{outvar}} – Ulrike Fischer May 04 '14 at 09:22