# Multiple \seealso under one index entry with imakeidx and texindy

I need to have several seealso under one index entry. I tried several ways to get this work. First variant (see below) produces semicolons between entries but I need commas as separators. Other variants produces good output but throws the errors like ERROR: Cross-reference-target ("a, c") does not exist!. There is the solution with makeidx but I need to solve it with imakedx and xindy.

My MWE:

\documentclass{article}

\usepackage{hyperref}

\usepackage[xindy]{imakeidx}
\makeindex[options=-M texindy]

\begin{document}
foo\index{a} \index{b} \index{c} \index{d}

\index{a|seealso{c}} \index{a|seealso{d}} %1st

\index{b|seealso{a, c}} %2nd

\index{c\relax |seealso{a, b}} %3rd

\index{d\gobble |seealso{b, c}} %4th

\printindex
\end{document}


My output:

The separator for multiple seealso entries is defined in the file makeindex.xdy, which is normally located in the xindy installation directory. If you create an alternative makeindex.xdy file in the directory where your .tex file is stored then the alternative file is loaded. For example the following, which outputs a comma without errors for the first variant:

makeindex.xdy

(define-crossref-class "see")
(markup-crossref-list :class "see" :open "\see{" :sep ", " :close "}{}")

(define-crossref-class "seealso")
(markup-crossref-list :class "seealso" :open "\seealso{" :sep ", " :close "}{}")

(markup-crossref-layer-list :sep ", ")

(define-location-class-order ("roman-page-numbers"
"arabic-page-numbers"
"alpha-page-numbers"
"Roman-page-numbers"
"Alpha-page-numbers"
"see"
"seealso"))


Result:

It may also be possible to set the alternative rule as a command line option, however I didn't find a way to do that.

• Thank a lot. I have an additional question however. Your example work well as long as xindy style file is named makeindex.xdy. If I have another filename and call it by \makeindex[program=truexindy,options=-M texindy -M another_filename.xdy] output result is the same but now I have some errors: ERROR: replacing location-reference-class "see"' is not allowed ! and ERROR: replacing location-reference-class "seealso"' is not allowed !. It is not essentially to have style file with another filename just wondering what is the reason of such routine.
– andc
Jan 2, 2020 at 18:45
• When you use another filename the original file makeindex.xdy is also loaded, I'm guessing the \makeindex command loads a file with this name by default and additionally any other files that are passed in the options. Therefore the rules for see and seealso are loaded first from makeindex.xdy and then you try to load new definitions for the same commands from your custom file, which is not allowed. Defining a new command in another file is allowed, i.e., \index{a|myseealso{c}} and (define-crossref-class "myseealso") (markup-crossref-list :class "myseealso" :open "\seealso{" etc. Jan 2, 2020 at 18:58
• Commenting out lines (define-crossref-class "see") and (define-crossref-class "seealso") solves this "problem".
– andc
Jan 2, 2020 at 19:13