# Index - xindy attributes hierarchy

I am typesetting a document in french, hence using xindy to create an index.

I have three levels of references : major, which is typesetted in bold; default which is typesetted in roman and minor, which displays in italics.

For a better readability of the index, I want the following order of the location-references to be respected: major, default, minor; like this:

Then, I edited the xindy style file to create groups:

but I also want the minor page number to disappear in favor of the default one:

Almost done, but the minor reference still displays before the default one because of its value. When I introduce more nesting in the groups definition, xindy returns an error:

(define-attributes (("major") (("default") ("minor"))) )

ERROR: nesting level too deep !


Is the style I want, implying group ordering and substituing, possible with xindy?

Below is an example.

% pdflatex -draftmode test.tex; texindy -M style.xdy -C utf8 test.idx; pdflatex test.tex

\documentclass[a4paper, 12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage[xindy]{imakeidx}

\usepackage{filecontents}
\begin{filecontents*}{style.xdy}
(define-attributes (("major") ("default" "minor")) )
(markup-attribute-group-list :sep "; ")

(merge-to "minor" "default" :drop)

(markup-locref :attr "major" :open "\textbf{" :close "}")
(markup-locref  :attr "minor" :open "\textit{" :close "}")

(markup-locclass-list :open "\dotfill")
\end{filecontents*}

\makeindex

\begin{document}

\verb+\index{Index entry|minor}+\index{Index entry|minor}

\newpage
\verb+\index{Index entry|major}+\index{Index entry|major}

\newpage
\verb+\index{Index entry}+\index{Index entry}

\verb+\index{Index entry|minor}+\index{Index entry|minor}

\printindex
\verb+(define-attributes (("major") ("default" "minor")) )+

\end{document}


After the Sergei Golovan’s answer, I tried some tests.

The method seems to work well with alone index references, although when using intervals with |( and |), warnings can appear:

Processing index... [10%]
WARNING: Found a :close-range in the index that wasn't opened before!


The warning seems to me very similar to this bug: https://sourceforge.net/p/xindy/bugs/54/ , as it appears when interval indexes are used. Sadly, it erases location references.

It also seems that sometimes, the process of substituing which occurs because of the defined groups, can lead to a warning.

This would need more tests to find a pattern and avoid errors in the final documents. I think this question should stay open to other solutions.

I'm not sure I fully understand what happens, but using

(define-attributes (("major") ("default" "minor") ("minor")) )


seems to do the trick. Minor entries are still grouped with default ones if they are both present on one page, but if there's only a minor entry on a page, it falls into a separate "minor" group and goes after the default group.

• This “hack” seems to work nicely with alone index references and when there is only one group of attributes. Thank you for this. Aug 7, 2017 at 18:28

As I wanted to create index ranges within an environment I came up with a different solution. Instead of setting something like \index{foo|(} at the beginning and \index{foo|)} at the end, which could lead to the described problem, I just created those entries without specifying the start and the end of a range and set up texindy to do the job of building ranges. This needs some mechanism to create a duplicated entry on every page in between, wherefore I used the hook mechanism for shipout. So a working example looks like this:

\documentclass{article}
\usepackage{iftex}
\iftutex
\usepackage{fontspec}
\else
\usepackage[T1]{fontenc}
\fi
\usepackage{blindtext}
\makeindex

\newcommand*\texindyentries{}
\expandafter\def\expandafter\texindyentries\expandafter{%
\texindyentries\index{#1}%
}%
}
\NewDocumentEnvironment{texindy}{>{\SplitList{,}}o}{%
\texindyentries%
}{%
\texindyentries\endgraf%
}

\begin{document}
\meaning\texindyentries\par
\blindtext[4]

\begin{texindy}[AAA,BBB]
\meaning\texindyentries\par
\blindtext[4]

\begin{texindy}[CCC,DDD]
\meaning\texindyentries\par
\blindtext[8]
\end{texindy}

\meaning\texindyentries\par
\blindtext[4]
\end{texindy}

\meaning\texindyentries\par
\blindtext[4]
\end{document}