# Datatool (datagidx) index with special characters

When I define multiple terms that contain an underscore and begin with the same string ex_ 1, ex_ 2 (as shown in the example below) I get the following error:

! TeX capacity exceeded, sorry [input stack size=5000]. \expandafter l.30 \end{frame}

However, when I define the term e2 using the commented out line below (e2_ 2) it compiles fine. If I just remove the escaped underscores (see below) that works as well. Can someone tell me how to work around this?

\documentclass[16pt,pdftex]{beamer}
\usepackage[T1]{fontenc}

\makeatletter
% beamer doesn't define \@idxitem, but it's used by the
% \printterms "index" style, so define it:
\newcommand\@idxitem{\par\hangindent40pt}
\makeatother

\usepackage{datagidx}

\newgidx{index}{Index}
\DTLgidxSetDefaultDB{index}

% this fails:
\newterm[label=e1]{ex\_ 1}
\newterm[label=e2]{ex\_ 2}

% this works
%\newterm[label=e1]{ex\_ 1}
%\newterm[label=e2]{e2\_ 2}

% this works
%\newterm[label=e1]{ex 1}
%\newterm[label=e2]{ex 2}
\begin{document}

\begin{frame}
\frametitle{example}
\gls{e1}
\gls{e2}
\end{frame}

\begin{frame}[allowframebreaks]
\frametitle{Index}
\printterms[style=index]
\end{frame}
\end{document}

• As it says in the documentation, you can't use active characters in the label. Do you really need an underscore in your label? (After all, it's only an identifier not typeset material.) – Nicola Talbot Nov 11 '13 at 17:06
• I'm a little confused here. In this example: \newterm[label=e1]{ex_ 1} Isn't the label 'e1' and the text/term that contains the active character ('ex\_ 1')? – John Harrold Nov 11 '13 at 19:20
• Sorry, I misread your question. I think the problem is the mechanism that sets the default sort value. Try \newterm[label=e1,sort={ex1}]{ex\_ 1} – Nicola Talbot Nov 11 '13 at 19:36
• That's it, and I think it makes sense as well. Thanks, I appreciate it. – John Harrold Nov 11 '13 at 20:09

\newterm[label=e1,sort={ex1}]{ex\_ 1}