以下 MWE 使用版本XeTeX
和版本正确编译:3.1415926-2.5-0.9999.3
TeX Live 2013
fontspec
2.3c
\documentclass{article}
\usepackage{fontspec}
\setmainfont{Linux Libertine O}
\newcommand{\foobar}{\textit{\kern-.2em\raisebox{.1ex}{\char"02CB}\kern.2em\kern-.25em}}
\begin{document}
Wo{\foobar}rd
\section{Wo{\foobar}rd}
\end{document}
但是,使用XeTeX
版本和版本时3.14159265-2.6-0.99991
,我收到以下错误:TeX Live 2014
fontspec
2.4a
! Argument of \@sect has an extra }.
<inserted text>
\par
l.9 \section{Wo{\foobar}rd}
我不知道这是否是由XeTeX
或 的新版本引起的fontspec
。但我该如何修复它?
答案1
版本2.4a
fontspec
不再加载包fixltx2e
,fontspec
参见README
文件:
Change history
--------------
- v2.4a (2014/06/21)
* No longer load fixltx2e.sty -- this package should really be loaded before \documentclass.
\raisebox
当在节标题中使用脆弱的命令时,就会出现问题。fixltx2e
使命令变得健壮,如其在文档:
%\begin{verbatim}
% >Number: 3816
% >Category: latex
% >Synopsis: Argument of \@sect has an extra }.
% >Arrival-Date: Sat Oct 22 23:11:01 +0200 2005
% >Originator: [email protected] (Susanne Wunsch)
%
% Use of a \raisebox in \section{} produces the error message
% mentioned in the subject.
%
% PR latex/1738 descriped a similar problem, which has been solved
% 10 years ago. Protecting the \raisebox with \protect solved my
% problem as well, but wouldn't it make sense to have a similar fix
% as in the PR?
%
% It is particulary confusing, that an unprotected \raisebox in a
% \section*-environment works fine, while in a \section-environment
% produces error.
%\end{verbatim}
%
% While not technically a bug, in this day and age there are few
% reasons why commands taking optional arguments should not be robust.
%
% \subsubsection{Notes on the implementation strategy}
%
% Rather than changing the kernel macros to be robust, we have decided
% to add the macro \DescribeMacro{\MakeRobust}|\MakeRobust| in
% \Lpack{fixltx2e} so that users can easily turn fragile macros into
% robust ones. A macro |\foo| is made robust by doing the simple
% |\MakeRobust{\foo}|. \Lpack{fixltx2e} makes the following kernel
% macros robust: |\(|, |\)|, |\[|, |\]|, |\makebox|, |\savebox|,
% |\framebox|, |\parbox|, |\rule| and |\raisebox|.
加载fixltx2e
可以解决问题:
\documentclass{article}
\usepackage{fixltx2e,fontspec}
\setmainfont{Linux Libertine O}
\newcommand{\foobar}{\textit{\kern-.2em\raisebox{.1ex}{\char"02CB}\kern.2em\kern-.25em}}
\begin{document}
Wo{\foobar}rd
\section{Wo{\foobar}rd}
\end{document}
\DeclareRobustCommand
或者,当宏包含脆弱命令时使用,例如\raisebox
:
\documentclass{article}
\usepackage{fontspec}
\setmainfont{Linux Libertine O}
\DeclareRobustCommand{\foobar}{\textit{\kern-.2em\raisebox{.1ex}{\char"02CB}\kern.2em\kern-.25em}}
\begin{document}
Wo{\foobar}rd
\section{Wo{\foobar}rd}
\end{document}