5

I use texindy to generate an index.

There are several indexed terms with a leading number. I want these terms to be sorted as if the leading numbers weren't there. This I attempted to achieve with the following merge-rule in my xindy stylesheet:

(merge-rule "^[0-9]+ (.*)" "\1" :eregexp)

Texindy is invoked like this:

texindy --debug level=2 -L czech -M lang/czech/utf8 -M stylesheet.xdy indexfile.idx

However, the result suggests the rule doesn't get applied: terms with a leading number are sorted according to the number, which results in them being at the very beginning of the index. It seems there might be an issue with rule precedence, as xindy applies some rules to normalize numbers included in terms by zero-padding them. The log sample below documents complete processing of one term with leading number.

apply rules once: '1 Kron 29, 10- 13' => '0000001' ' Kron 29, 10- 13'
apply rules once: ' Kron 29, 10- 13' => 'NIL' 'NIL'
apply rules once: 'Kron 29, 10- 13' => 'NIL' 'NIL'
apply rules once: 'ron 29, 10- 13' => 'NIL' 'NIL'
apply rules once: 'on 29, 10- 13' => 'NIL' 'NIL'
apply rules once: 'n 29, 10- 13' => 'NIL' 'NIL'
apply rules once: ' 29, 10- 13' => 'NIL' 'NIL'
apply rules once: '29, 10- 13' => '0000029' ', 10- 13'
apply rules once: ', 10- 13' => 'NIL' 'NIL'
apply rules once: ' 10- 13' => 'NIL' 'NIL'
apply rules once: '10- 13' => '0000010' '- 13'
apply rules once: '- 13' => 'NIL' 'NIL'
apply rules once: ' 13' => 'NIL' 'NIL'
apply rules once: '13' => '0000013' ''
Final merge-rule result: '1 Kron 29, 10- 13' -> '0000001 Kron 0000029, 0000010- 0000013'

How to solve this?

EDIT: minimal example:

document (document.tex):

\documentclass[a4paper]{article}

\usepackage[utf8]{inputenc}

\usepackage{multind}
\makeindex{index}

\begin{document}

This paragraph contains term without a number: 
Term\index{index}{Term}

This paragraph contains term beginning with a number:
1st Term\index{index}{1 Term}

Let's add a random\index{index}{random} word to the index.

\printindex{index}{The Testing Index}

\end{document}

xindy stylesheet (stylesheet.xdy):

;; ignore leading numbers when sorting and grouping
(merge-rule "^[0-9]+ (.*)" "\1" :eregexp)

commands to compile:

pdflatex document
texindy -M stylesheet.xdy index.idx
pdflatex document

expected result: index with two letter groups, R and T, with "Term" and "1 Term" under T

actual result: index with three letter groups: R, T and default (no letter). "1 Term" falls into default.

  • Please add a minimal working example (MWE) which allows people to reproduce the issue. This will include at least your stylesheet and a small, complete document which can be used to demonstrate the problem. – cfr Apr 22 '14 at 0:25
  • You need to put the xdy with your own merge rule first in the xindy call. texindy loads a couple of other xdys and the merge-rules of each those styles are executed prior to yours and destroy the context for your regexp. – Lupino Apr 7 '15 at 9:18
3

xindy syntax is, at least for me, almost misterious, and I always need a Trial-and-error approach. The code below allows to order the index words in the right way. The ruel I wrote is:

(sort-rule "^[0-9]* *" "")

it ignores all the leading numbers in sorting process and also ignores all spaces that you write after the first numbers. You cannot use a merge rule, because two keywords are equal if they are mapped onto the same merge key, so in your example "1 Term" is equal to "Term", and in the final index you will have only the "Term" keyword.

% arara: xelatex: {shell : yes}
\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\begin{filecontents*}{ignorestyle}
;; ignore leading numbers when sorting and grouping
(sort-rule "^[0-9]* *" "")
\end{filecontents*}
\usepackage{imakeidx}
\makeindex[program=xindy,options= -C utf8 -M ignorestyle]
\begin{document}
This paragraph contains term without a number: 
Term\index{Term}
This paragraph contains term beginning with a number:
1st Term\index{1 Term}
Let's add a random\index{random} word to the index.
\index{231   Minnie}
\index{1Donald 125  Duck}
\index{1Donald 126  Auck}
\index{ Duffy Duck}
\index{126565Hallo}
\printindex
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.