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


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

  • 1
    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.

1.e4 e6 2.d4 b6#

\catcode`#=12 %
\catcode`#=6 %





enter image description here

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.
    – Heinz M.
    Aug 9 '17 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.