1

I am trying to put { in index using xindy as my index processor and xelatex as the typesetting format:

\documentclass{article}
\usepackage{makeidx}
\makeindex
\usepackage{fontspec}
\begin{document}
This is a test
\index{\texttt{\{}}
\printindex
\end{document}

However, I get the following error:

Runaway argument?
{\texttt{\{}} \printindex \end{document} 
! File ended while scanning use of \@wrindex.
<inserted text> 
                \par 
<*> test.tex

What's wrong and how do I fix it?

1
  • Nontheless, I consider this a LaTeX bug which is annoying. Nov 12, 2014 at 10:03

3 Answers 3

2

There are two issues:

  • if you want to format index entry with \texttt, \textbf or similar command, use index entry in the form:

    \index{word@\textbf{word}

  • for index entries which are not alphanumeric, you should provide sort key. so if you want to sort left brace as braceleft, use this:

    \index{braceleft@\texttt{\textbraceleft}}

this will create following .ind file after running

 xindy -L english -C utf8 -M texindy filename.idx

\begin{theindex}
  \providecommand*\lettergroupDefault[1]{}
  \providecommand*\lettergroup[1]{%
      \par\textbf{#1}\par
      \nopagebreak
  }

  \lettergroup{B}
  \item \texttt{\textbraceleft}, 1

\end{theindex}

if you don't want to sort it under some letter, use

\index{\relax@\texttt{\textbraceleft}}

this produces:

\begin{theindex}
  \providecommand*\lettergroupDefault[1]{}
  \providecommand*\lettergroup[1]{%
      \par\textbf{#1}\par
      \nopagebreak
  }

  \lettergroupDefault{default}
  \item \texttt{\textbraceleft}, 1

\end{theindex}
0

I can do this as

\documentclass{article}
\usepackage{makeidx}
\makeindex
\usepackage{fontspec}
\begin{document}
This is a test
\index{\texttt{\textbraceleft}}
\printindex
\end{document}

But this time xindy gives the following error message:

ERROR: CHAR: index 0 should be less than the length of the string

or alternatively as

\documentclass{article}
\usepackage{makeidx}
\makeindex
\usepackage{fontspec}
\begin{document}
This is a test
\index{\texttt{\char"007B}}
\printindex
\end{document}

but then again, xindy converts \char"007B (in the .idx file) to \char007B (in the .ind file) perhaps because " has special meaning for xindy and xindy simply ignores it.

Alternative, I can do it as

\documentclass{article}
\usepackage{makeidx}
\makeindex
\usepackage{fontspec}
\chardef\mylb="007B
\begin{document}
This is a test
\index{\texttt{\mylb}}
\printindex
\end{document}

But this time xindy gives the following error message:

ERROR: CHAR: index 0 should be less than the length of the string
0

I found the following solution by Heiko Oberdiek:

\documentclass{article}
\usepackage{makeidx}
\makeindex
\begingroup
  \lccode`0=`\{
  \lccode`1=`\}
\lowercase{%
  \endgroup
  \newcommand\BraceLeft{0}%
  \newcommand\BraceRight{1}%
}
\newcommand*{\Index}[1]{%
  \index{#1}%
}

\begin{document}
foo\Index{"\BraceLeft @\string\textbraceleft}
\printindex
\end{document}

I do not understand German and I just copied his TeX code. If you speak German, please edit my answer and add some details.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .