![xskak 在某步之后展示棋盘](https://linux22.com/image/363707/xskak%20%E5%9C%A8%E6%9F%90%E6%AD%A5%E4%B9%8B%E5%90%8E%E5%B1%95%E7%A4%BA%E6%A3%8B%E7%9B%98.png)
使用以下代码,我有 2 个问题: 1- 是否可以在序言中插入重复的 \xskakloop 代码,而不是在每场游戏后重复它?
2- 是否可以从示例 2 开始,在某一步之后(例如从第 4 步开始)而不是第 1 步之后开始显示棋盘?
\documentclass{article}
\usepackage{xskak, chessboard}
\usepackage{verbatim}
\makeatletter
\providecommand\xskak@beforecomment{}
\makeatother
\newcommand\getmovestyle[1]{
\ifthenelse
{\equal{#1}{N}}
{\def\mymovestyle{[clockwise=false,style=knight]curvemove}}
{\ifthenelse
{\equal{#1}{}}
{\def\mymovestyle{curvemove}}
{\def\mymovestyle{straightmove}}}}
\begin{document}
\begin{center}
Ruy Lopez Opening\\
\newchessgame
\chessboard[tinyboard]{}
Example1 \\
\hidemoves{
1. e4 e5 2. Nf3 Nc6 3. d4 Nf6 4. dxe5 Nxe4 5. g3 f6
}% do not leave an empty line before this closing }
\xskakloop{%
\getmovestyle{\xskakget{piecechar}}%
\chessboard[tinyboard,
pgfstyle=\mymovestyle, color=blue!50,
markmoves=\xskakget{move}, pgfshortenend=0.3em, arrow=to, markstyle=\dots\, markfield=\xskakget{movefrom},
emphfields=\xskakget{moveto}, setfen=\xskakget{nextfen}]\\
\xskakget{opennr}
\xskakget{lan}
\xskakget{nag}
\par
}%
\clearpage
\newchessgame
\chessboard[tinyboard]{}
Example2 \\
\hidemoves{
1. e4 e5 2. Nf3 Nc6 3. d4 Nf6 4. dxe5 Nxe5 5. b4 a5
}% do not leave an empty line before this closing }
\xskakloop{%
\getmovestyle{\xskakget{piecechar}}%
\chessboard[tinyboard,
pgfstyle=\mymovestyle, color=blue!50,
markmoves=\xskakget{move}, pgfshortenend=0.3em, arrow=to, markstyle=\dots\, markfield=\xskakget{movefrom},
emphfields=\xskakget{moveto}, setfen=\xskakget{nextfen}]\\
\xskakget{opennr}
\xskakget{lan}
\xskakget{nag}
\par
}%
\clearpage
\newchessgame
\chessboard[tinyboard]{}
Example3 \\
\hidemoves{
1. e4 e5 2. Nf3 Nc6 3. d4 Nf6 4. d5 Na5 5. b4 Nc4
}% do not leave an empty line before this closing }
\xskakloop{%
\getmovestyle{\xskakget{piecechar}}%
\chessboard[tinyboard,
pgfstyle=\mymovestyle, color=blue!50,
markmoves=\xskakget{move}, pgfshortenend=0.3em, arrow=to, markstyle=\dots\, markfield=\xskakget{movefrom},
emphfields=\xskakget{moveto}, setfen=\xskakget{nextfen}]\\
\xskakget{opennr}
\xskakget{lan}
\xskakget{nag}
\par
}%
\clearpage
\newchessgame
\chessboard[tinyboard]{}
Example4 \\
\hidemoves{
1. e4 e5 2. Nf3 Nc6 3. d4 Nf6 4. d5 Na5 5. c3 Nxd5
}% do not leave an empty line before this closing }
\xskakloop{%
\getmovestyle{\xskakget{piecechar}}%
\chessboard[tinyboard,
pgfstyle=\mymovestyle, color=blue!50,
markmoves=\xskakget{move}, pgfshortenend=0.3em, arrow=to, markstyle=\dots\, markfield=\xskakget{movefrom},
emphfields=\xskakget{moveto}, setfen=\xskakget{nextfen}]\\
\xskakget{opennr}
\xskakget{lan}
\xskakget{nag}
\par
}%
\end{center}
\end{document}
答案1
如果您发现重复操作,您可以随时编写自己的命令。并且 yes\xskakloop
有一个可选参数,您可以在其中设置 initmove 和 stopmove(以及步长)。请参阅第 35 页的文档。
\documentclass[]{article}
\usepackage{xskak, chessboard}
\usepackage{verbatim}
\makeatletter
\providecommand\xskak@beforecomment{}
\makeatother
\newcommand\getmovestyle[1]{
\ifthenelse
{\equal{#1}{N}}
{\def\mymovestyle{[clockwise=false,style=knight]curvemove}}
{\ifthenelse
{\equal{#1}{}}
{\def\mymovestyle{curvemove}}
{\def\mymovestyle{straightmove}}}}
\newcommand\mychessloop[1][]{%
\xskakloop[#1]{%
\getmovestyle{\xskakget{piecechar}}%
\chessboard[tinyboard,
pgfstyle=\mymovestyle, color=blue!50,
markmoves=\xskakget{move}, pgfshortenend=0.3em, arrow=to, markstyle=\dots\, markfield=\xskakget{movefrom},
emphfields=\xskakget{moveto}, setfen=\xskakget{nextfen}]\\
\xskakget{opennr}
\xskakget{lan}
\xskakget{nag}
\par
}}%
\begin{document}
\centering
Example1
\newchessgame
\hidemoves{
1. e4 e5 2. Nf3 Nc6 3. d4 Nf6 4. dxe5 Nxe4 5. g3 f6
}% do not leave an empty line before this closing }
\mychessloop
\clearpage
Example2
\newchessgame
\hidemoves{
1. e4 e5 2. Nf3 Nc6 3. d4 Nf6 4. dxe5 Nxe5 5. b4 a5
}% do not leave an empty line before this closing }
\mychessloop[initmoveid=3w]
\end{document}