# “! Missing } inserted.” error when using the xeindex packege

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?

-
I revised my answer. Hopefully it is much clearer now. But anyway. This seems like a buggy package. – Qrrbrbirlbel Oct 2 '12 at 21:57
There is even a bug report and the problem is identified: tug.org/pipermail/xetex/2011-February/020051.html – Qrrbrbirlbel Oct 2 '12 at 22:03
If I remember correctly, the author of XeIndex and XeSearch has abandoned the projects. – egreg Oct 2 '12 at 23:05

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

-
Thanks for your reply, but my document is very long and there are tons of words and phrases which should be indexed, so manually handling them is very tough and time cosuming. Apart from this, your solution (using \StopSearching) prevents some entries from being indexed. Any other idea please? – Vahid Damanafshan Oct 3 '12 at 8:10
@VahidDamanafshan Yes, of course. It seems to me, that xeindex´ sees foo but can't end its search for and bar. This is not a problem is foo followed by some arbitrary text, but breaks in the instances mentioned. My solution prevents xeindex to try to start indexing foo (It isn't in your \IndexList so it shouldn't be indexed anyway.) Do you want to index foo and foo and bar? – Qrrbrbirlbel Oct 3 '12 at 16:32
‎‎@Qrrbrbirlbel‎: ‎‎Thank you again for ‎clarifying‎ the issue. ‎Ok,‎ I've been ‎completely ‎convinced as for the ‎second‎ problem in ‎my‎ comment above. Now, do you have any idea for the first problem ‎(‎manually handling ‎them)? ‎My‎ document has a lot of sections and tabular environments, so its very tough and time ‎cosuming‎ to me to put ‎the‎ \PreventIndex` inside them ‎one‎ by one. – Vahid Damanafshan Oct 4 '12 at 7:54
No, not really. Some ideas: Regex? Search-and-Replace? Perl? – Qrrbrbirlbel Oct 4 '12 at 17:57