[Tex/LaTex] “! Missing } inserted.” error when using the xeindex packege

errorsindexing

In the following example, when I use the word foo in the \IndexList command (with some other words, not lonely), I'll get the following error:

! Missing } inserted.
<inserted text> 
                }
l.7 \section{foo}

The same error will also occur when I use the tabular environment. (I've not tried any other commands and environments, so maybe the error appears in there, too.)
Here is my code:

\documentclass{article}
\usepackage{xeindex}
\makeindex
\IndexList{mylist}{hello,foo and bar,hi}
\begin{document}
\section{foo}
\newpage
%\begin{tabular}{c}
%foo 
%\end{tabular} 
\printindex
\end{document}

How can I solve this problem?

Best Answer

The xeindex package seems very buggy in this instance.

This problem only occurs if “foo” is not followed by text (\section, \printindex, \end{table} and \\ don't count).

Works:

  • \section{foo and nothing else}
  • \section{foo and bar}

Breaks:

  • \section{foo}
  • … foo \printindex \end{document}

Help:

  • Dirty workarounds like f{}oo work everywhere, but are painful and break hyphenation.
  • The package provides \StopIndex{<list>}, \StopSearching and \StartSearching. In sections they need to be \protected.
    • Either \StopSearching foo \StartSearching or
    • {\StopSearching foo}

The package provides even \NoIndex:

\def\NoIndex#1{%
  \bgroup
  \StopIndex
  #1%
  \egroup
  }

but that fails. It needs at least a \protect but then it's missing a } again.

The following definition does work but does not typeset anything (no surprise there, just randomly adding \egroups can't be the solution.

\def\NoIndex#1{\bgroup\protect\StopIndex #1\egroup\egroup}

Therefore, I defined a custom command \PreventIndex{<to not be indexed>} which works everywhere (?).

Code (MWE)

\documentclass{article}
\usepackage[paperheight=8cm,paperwidth=8cm]{geometry}
\usepackage{xeindex} \makeindex
\IndexList{mylist}{hello,foo and bar,hi}

\newcommand*\PreventIndex[1]{{\protect\StopSearching #1}}

\AtBeginDocument{\LARGE}                       % only for this MWE
\begin{document}
\section{I give a \PreventIndex{foo}}          % Nothing after foo => \PreventIndex
Foo is horrible!                               % some plain text after foo => no need to stop Searching

\section{Foo, nothing else}                    % some plain text after foo => no need to stop Searching
There is really nothing else then foo?         % some plain text after foo => no need to stop Searching

\section{Let's index!}
Foo and bar are always together.               % Works, gets indexed
Bar was born ten minutes later then
\PreventIndex{foo} \(\Longleftarrow\)          % :(
needs {\small\texttt{\textbackslash PreventIndex}}

\newpage
\begin{tabular}{c}
 Foo and bar \\
 sitting on a \PreventIndex{foo} \\            %
 foo?                                          %
\end{tabular}
\printindex
\end{document}

Output

Better MWE

Related Question