章节标题中的特殊内容

章节标题中的特殊内容

我正在尝试使用 skak 国际象棋包设置一篇文章,并在章节标题中包含符号:

\documentclass[a4paper]{article}
\usepackage{skak}
\begin{document}
    \section{Open Games (\newgame\mainline{1.e4 e5})}
\end{document}

这给出了一长串错误列表,首先是Undefined control sequence. ...on{Open Games (\newgame\mainline{1.e4 e5})}

我知道标题适用特殊规则,但我不明白它们——如何将符号放入章节标题中?(我知道在这种情况下我不需要 skak,因为生成的符号看起来就像纯文本,但情况并非总是如此,有时它会涉及棋子的符号。而且 skak 对移动的有效性的检查也很有用——我第一次输入它时输入了 1.e4 44。)

编辑-根据 DG' 的回答,我的新 MWE 是:

\documentclass[a4paper]{book}
\usepackage{xskak}
\usepackage[inline]{enumitem}
\begin{document}
    \chapter{First Group}
    \section{Open Games (\protect\newchessgame\mainline{1.e4 e5})}
    \subsection{Centre Game}
    (\newchessgame\mainline{1.e4 e5 2.d4})
    
    \newchessgame\styleC\mainline{1.e4 e5 2.d4 exd4 3.Qxd4 Nc6 4.Qe3     Nf6\wbetter}\storegame{centregame1}
    
    \begin{enumerate}
        \item \mainline{5.e5 Ng4 6.Qe4}
        \mainline{6...d5 7.exd6 Be6 8.dxc7 Qd1+ 9.Kxd1 Nxf2 10.Ke1     Nxe4}
        \item \restoregame{centregame1}\mainline{5.Nc3 Bb4 6.Bd2 O-O 7.O-O-O Re8 8.Bc4}\storegame{centregame2}

    \begin{figure}
        \centering
        \caption{Position after White's 8\textsuperscript{th} Move}
        \chessboard
    \end{figure}

    \begin{figure}
        \centering
        \caption{Position after White's 13\textsuperscript{th} Move}
        \chessboard
    \end{figure}

Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    \end{enumerate}
\end{document}

这会导致以下几个错误:

! LaTeX Error: Something's wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.32 \end{document}
                   
Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.


! LaTeX Error: Something's wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.32 \end{document}
                   
Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.


! LaTeX Error: Something's wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.32 \end{document}
                   
Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.

! Missing \endgroup inserted.
<inserted text> 
                \endgroup 
l.32 \end{document}
                   
I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing } inserted.
<inserted text> 
                }
l.32 \end{document}

如果我将棋步从标题移开,问题就会消失 - 但公平地说,如果我改变几乎任何其他东西,包括删除一些 lorem ipsum 文本,问题仍然会消失,所以我不再确定问题出在哪里。

答案1

在这种情况下,使用xskak代替skak并保护命令是\section可行的。但我不知道它是否适用于更复杂的游戏。

\documentclass[a4paper]{article}
\usepackage{xskak}
\begin{document}
    \section{Open Games (\protect\newgame\mainline{1.e4 e5})}
    \section{Open Games 2 (\protect\newgame\mainline{1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 4. Ba4 Nf6})}
\end{document}

在此处输入图片描述

如果您想使用hyperref,您可能需要编写如下包装器:

\documentclass[a4paper]{article}
\usepackage{xskak}
\usepackage{hyperref}

\DeclareRobustCommand\GameLine[1]{%
    \texorpdfstring{\newgame\mainline{#1}}{#1}}

\begin{document}
    \section{Open Games (\GameLine{1.e4 e5})}
    \section{Open Games 2 (\GameLine{1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 4. Ba4 Nf6})}
\end{document}

相关内容