1

The following MWE compiles correctly with XeTeX version 3.1415926-2.5-0.9999.3 in TeX Live 2013 and fontspec version 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}

enter image description here

With XeTeX version 3.14159265-2.6-0.99991 in TeX Live 2014 and fontspec version 2.4a, however, I get the following error:

! Argument of \@sect has an extra }.
<inserted text> 
                \par 
l.9 \section{Wo{\foobar}rd}

I don't know if this is caused by the new version of XeTeX or fontspec. But how can I fix it?

Sverre
  • 20,729
  • fontspec no longer loads fixltx2e by default and so the raisebox breaks. You can load fixltx2e yourself, but better would be imho to define the command in a robust way with \DeclareRobustCommand. – Ulrike Fischer Sep 17 '14 at 13:09
  • @UlrikeFischer Could you expand that answer a bit? E.g. what is fixltx2e needed for in this case, and how do I define the command in a "robust" way? Also note that the command works in regular text, just not in a section heading. – Sverre Sep 17 '14 at 13:19
  • sverre: fixltx2e has a documentation. And you can search for \DeclareRobustCommand. – Ulrike Fischer Sep 17 '14 at 13:39
  • @UlrikeFischer The only documentation I can find for fixltx2e are the bullet points at http://www.ctan.org/pkg/fixltx2e, which don't really explain what the problem is with raisebox in section headings. – Sverre Sep 17 '14 at 13:51
  • Download http://mirrors.ctan.org/macros/latex/base/fixltx2e.dtx and compile it with pdflatex. – Ulrike Fischer Sep 17 '14 at 14:19
  • @UlrikeFischer If you don't mind, I'll add an answer. – Sverre Sep 17 '14 at 15:15

1 Answers1

1

Version 2.4a of fontspec no longer loads the package fixltx2e, cf. fontspec's README file:

Change history
--------------

- v2.4a (2014/06/21)

    * No longer load fixltx2e.sty -- this package should really be loaded before \documentclass.

The problem occurs when the fragile command \raisebox is used in a section heading. fixltx2e makes the command robust, as explained in its documentation:

%\begin{verbatim}
% >Number:         3816
% >Category:       latex
% >Synopsis:       Argument of \@sect has an extra }.
% >Arrival-Date:   Sat Oct 22 23:11:01 +0200 2005
% >Originator:     susi@uriah.heep.sax.de (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|.

Loading fixltx2e takes care of the problem:

\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}

Alternatively, use \DeclareRobustCommand when the macro contains a fragile command like \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}

Cf. also the LaTeX wiki book and What is the difference between Fragile and Robust commands?.

Sverre
  • 20,729