# import data chess dat for xskak with \input command

Is there a way to import chess data from a file? The content of the file can be restricted to the moves only.

It is clear to me that

\hidemoves{\input{datafile}}


can not work. However, is it possible to expand \input{datafile} first and feed the result to \hidemoves afterwards?

• You haven't provided a test file so untested but probably \expandafter\expandafter\expandafter\hidemoves\expandafter\expandafter\expandafter{\csname @@input\endcsname datafile} will work Aug 9 '17 at 12:00
• Depends on the content of the file. If it contains only moves of one game it should be possible, but if you have a pgn file with various game you need some script to preprocess the file. Aug 9 '17 at 12:10

Using the readarray package to place the file contents into a \def named \myhidemoves. Then one only needs to expand \myhidemoves once before passing it to \hidemoves.

EDITED to change # catcode for \readdef.

\documentclass{book}
\begin{filecontents*}{datafile}
1.e4 e6 2.d4 b6#
\end{filecontents*}

\begin{document}
\newchessgame[id=title]
\catcode#=12 %
\catcode#=6 %
\expandafter\hidemoves\expandafter{\myhidemoves}

\tableofcontents

\chapter{\protect\printchessgame[id=title]}

\printchessgame[id=title]
\chessboard[id=title]

\end{document}


Note: copied MWE from \chapter command and skak package.

• This won't work generally, chess changes the catcode of # (the mate symbol). Aug 9 '17 at 12:08
• @UlrikeFischer I believe you, of course, but don't fully grok what you are saying. Is there a simple breaking example for datafile you could type in? (I am not a skak user) Aug 9 '17 at 12:10
• Try \newchessgame\mainline{1.e4 e6 2.d4 b6#} and in comparision 1.e4 e6 2.d4 b6# in your datafile. Aug 9 '17 at 12:13
• @UlrikeFischer It would seem that simply changing the # catcode for the \readdef is sufficient to remedy the issue. Aug 9 '17 at 12:22
• @UlrikeFischer Thank you, that is exactly what I needed. Aug 9 '17 at 12:30