# Issue with xindy for package glossaries

Everything was working perfectly. Suddenly I started getting the error for xindy while using the glossaries package

Warning: File 'PhDThesis.acn' is empty. Have you used any entries defined in glossary 'acronym'?
***Call to xindy failed*** Possible cause of problem: Sort key required for entries only containing command names Check 'PhDThesis.nlg' for details


I had just updated my Ubuntu 12.10.

The content of the .nlg file

;; This logfile was generated automatically by xindy'
;; at 14.08.2013  17:25:07
;; Indexstyle: "/tmp/HCmyqynpuv", Rawindex: "/tmp/z3QRNA2BGB", Output: "PhDThesis.not"

Building indexentry-tree:
Hierdepth of index is :TREE

sort-indexentries: (FORWARD BACKWARD FORWARD FORWARD)
sort-indexentries: (FORWARD BACKWARD FORWARD FORWARD)
sort-indexentries: (FORWARD BACKWARD FORWARD FORWARD)
sort-indexentries: (FORWARD BACKWARD FORWARD FORWARD)
sort-indexentries: (FORWARD BACKWARD FORWARD FORWARD)
sort-indexentries: (FORWARD BACKWARD FORWARD FORWARD)
sort-indexentries: (FORWARD BACKWARD FORWARD FORWARD)
ERROR: CHAR: index 0 should be less than the length of the string

*** Unable to execute: 'xindy  -L english  -I xindy -M "PhDThesis" -t "PhDThesis.nlg" -o "PhDThesis.not" "PhDThesis.ntn"' ***

Status report:

Opening logfile "PhDThesis.nlg" (done)
Finalizing indexstyle... (done)

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


• xindy ignores command names in the sort key so if your sort key is just a command xindy has no sort information. Just set the sort key to something that doesn't contain a command. – Nicola Talbot Aug 14 '13 at 11:01
• I am not using any command name as sort keys. Thanks. – cosmicraga Aug 14 '13 at 11:18
• can you post an MWE so we see what kind of glossary entries you use etc – wierts Aug 14 '13 at 12:23
• If I use 'sort=def' in the package declaration, then everything works fine. I am not explicitly using any sort keys at all. it was the default one as nothing was mentioned. Now for the time being my purpose is solved. Though I am still in dark why xindy got confused while sorting. – cosmicraga Aug 14 '13 at 12:45
• I also use makeglossaries. Adding sort=def to the package declaration line (e.g. \usepackage[xindy,sort=def]{glossaries} worked for me also. Unlike @cosmicraga, I do use simple, custom sorting keys, although none of them have commands in them. Even with these custom sort keys, this fix worked for me with no obvious side-effects. – jvriesem Apr 8 '14 at 18:53

It sounds like xindy is unable to determine how to sort one or more of your entries, but without a minimal example it's hard to tell exactly. The default is for xindy to sort on the entry name unless you have specified a sort value. However, xindy ignores (La)TeX commands so if the sort key only contains commands, xindy is left with a blank sort key and issues a warning. Earlier versions of xindy gave a somewhat cryptic error:

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


Newer versions give a slightly more understandable warning:

WARNING: Would replace complete index key by empty string, ignoring


Since the first warning isn't very easy to understand, makeglossaries searches for instances of it and if found gives the warning:

Possible cause of problem: Sort key required for entries only containing command names


Here's a minimal example illustrating the problem:

\documentclass{article}

\usepackage[xindy]{glossaries}

\makeglossaries

\newglossaryentry{P}{name={\P},description={Paragraph symbol}}

\newglossaryentry{S}{name={\S},description={Section symbol}}

\begin{document}

Reference the terms: \gls{S} \gls{P}.

\printglossaries

\end{document}


In this case the first term has the sort key \P and the second term has the sort key \S. In both cases, once xindy has stripped out the commands, it's left with an empty sort string and doesn't know how to compare the entries. Should \P come before or after \S? The solution is to provide a sort key for these entries:

\documentclass{article}

\usepackage[xindy]{glossaries}

\makeglossaries

\newglossaryentry{P}{name={\P},sort={P},description={Paragraph symbol}}

\newglossaryentry{S}{name={\S},sort={S},description={Section symbol}}

\begin{document}

Reference the terms: \gls{S} \gls{P}.

\printglossaries

\end{document}


If all your terms are like this (for example they are all symbols) then it may not make any sense trying to sort them alphabetically. In which case it might be better to sort them by definition (package option sort=def, as you mentioned in your comment) or by use in the document. In either of these cases, glossaries manufactures a numerical sort key for each term, so the issue no longer arises.

Edit: There's a GUI diagnostic tool for the glossaries package called makeglossariesgui which can provide further details by analysing the .aux, .log and associated glossary files. The example below has three problematic entries and a working one for comparison:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[xindy]{glossaries}

\makeglossaries

\newglossaryentry{sample}{name={sample},
description={an example}}

\newglossaryentry{S}{name={\S},
description={section symbol}}

\newglossaryentry{alpha}{name={\ensuremath{\alpha}},
description={alpha}}

\newglossaryentry{beta}{name={$\beta$},text={\beta},
description={beta}}

\begin{document}
Test: \gls{sample}, \gls{S}, $\gls{alpha}$, $\gls{beta}$.

\printglossaries

\end{document}


A LaTeX run is first required to generate the .aux file (although this is usually already present if you're trying to work out why xindy has failed). The .aux file can then be opened in makeglossariesgui using the File > Open menu item.

For the above MWE, an error dialog is displayed to show that xindy failed:

Once that dialog box is dismissed, the "Diagnostics" tab lists each problem:

The text displayed is:

Xindy won't accept the sort value \S (for entry S) as it's treated as an empty string. This is because xindy ignores (La)TeX commands within the sort field, and once these commands have been stripped the sort field becomes empty. You will need to explicitly set the sort field using the sort key in the entry definition.

Xindy won't accept the sort value \ensuremath {\alpha } (for entry alpha) as it's treated as an empty string. This is because xindy ignores (La)TeX commands within the sort field, and once these commands have been stripped the sort field becomes empty. You will need to explicitly set the sort field using the sort key in the entry definition.

Xindy won't accept the sort value $\beta$ (for entry beta) as it's treated as an empty string. This is because xindy ignores (La)TeX commands within the sort field, and once these commands have been stripped the sort field becomes empty. You will need to explicitly set the sort field using the sort key in the entry definition.

Xindy reported the following:

    WARNING: Would replace complete index key by empty string, ignoring
#<ordrule-regexp: '\\[a-zA-Z@]+ *' => '' :again NIL :only-at-start NIL
ERROR: CHAR: index 0 should be less than the length of the string


So this explicitly identifies each problematic entry by its label (which neither xindy nor makeglossaries do).

The "General Information" tab contains a "Details" link, which when clicked on opens a window with a summary of all the entries. The second column shows the sort key, which is displayed in red if there's a problem with it.

Once the problems have been fixed, you can switch back to using makeglossaries or explicitly xindy.

Incidentally, the glossaries-extra package, provides the command \glsxtrnewsymbol when the symbols package option is used. This internally uses \newglossaryentry but sets the sort value to the label rather than the name field. For example:

\glsxtrnewsymbol[text={\beta},description={beta example}]{beta}{$\beta$}


This is equivalent to

\newglossaryentry{beta}{name={$\beta$},text={\beta},
sort={beta},
type=symbols,
category=symbol,
description={beta example}}

• As I just encountered this exact error, and this is the only reference to this error message on TeX.SE I thought I should post this comment in case anyone else runs into this, or I run into it again later :-): The CHAR: index 0 error can also occur with indexing and using xindy if the sort term is left blank as in \index{!abc}. – Peter Grill Mar 18 '14 at 6:22
• It would be SO MUCH better if xindy were able to give the line number where the error occurred. I have the same error and have neither entries with empty sort term nor command-only entries... – yannis Dec 7 '15 at 11:27
• I also ran into this error. I had some headache to find out from which line was the problem since the error message is not explicit on this point. It turn out that was a really stupid mistake from me... A coma missing between description and sort... – Gilles Bonnet Sep 23 '16 at 17:00
• @GillesBonnet I've been tripped by that as well. Unfortunately it's difficult to test for it, but I think part of the problem is that the description value tends to be long so it's easier to miss the trailing comma. I now try to put the description last to help avoid the problem. I've added information about makeglossariesgui to my answer as knowing which entry has the problem helps to narrow down the search. – Nicola Talbot Sep 24 '16 at 11:46
• @NicolaTalbot Thanks for your comment/answer and more generally for the packages you wrote! :D – Gilles Bonnet Sep 24 '16 at 12:47

This error also occurs if the first argument in an \indexentry (in the .idx` file) is blank. I ran into this with some automatically generated indices.