# Multiple indices with ledmac and the book class

The package for critical editions, Ledmac, provides an \edindex{} command to have references to the page and line number in the standard Makeindex index. The package documentation also specifies that, when used with the Memoir class, it is also possible to have multiple indices with the following syntax \edindex[indexName]{}. This syntax is quite close to the one provided by the Multind package, so I would like to know if anyone knew of a possibility to have multiple critical indices without using the memoir class, but instead the more standard book class, and a package dedicated to multiple indices (doesn't seem to work with the Multind package though).

Edit : Here is the part of the Ledmac code concerning multi-indexing with the memoir class :

\@ifclassloaded{memoir}{%
\def\edindex{\@bsphack%
\@ifnextchar [{\l@d@index}{\l@d@index[\jobname]}}}
\newcommand{\edindex}[2][\jobname]{\@bsphack\@esphack}
\def\l@d@index[#1]{%
\@ifundefined{#1@idxfile}%
{\ifreportnoidxfile
\led@warn@NoIndexFile{#1}%
\fi
\begingroup
\@sanitize
\@nowrindex}%
{\def\@idxfile{#1}%
\doedindexlabel
\begingroup
\@sanitize
\l@d@wrindexm@m}}
\newcommand{\l@d@wrindexm@m}[1]{\l@d@@wrindexhyp#1||\\}
\def\l@d@@wrindexhyp#1|#2|#3\\{%
\ifshowindexmark\@showidx{#1}\fi
\ifx\\#2\\%
\protected@write\@auxout{}%
{\string\@@wrindexm@m{\@idxfile}{#1|hyperpage}{\thepageline}}%
\else
\def\Hy@temp@A{#2}%
\ifx\Hy@temp@A\HyInd@ParenLeft
\protected@write\@auxout{}%
{\string\@@wrindexm@m{\@idxfile}{#1|#2hyperpage}{\thepageline}}%
\else
\protected@write\@auxout{}%
{\string\@@wrindexm@m{\@idxfile}{#1|#2}{\thepageline}}%
\fi
\fi
\endgroup
\@esphack}
}

-
I would have added a Ledmac and a Multind tag, but it appears I can't. –  Jean-Baptiste Camps Apr 10 '11 at 10:15

I don't know the special requirements of "critical indices", but the splitidx package allows for multiple indices.

EDIT: With regard to multiple indices, the memoir class emulates the funcionality of the index package. If you're using another class, try to load the index package in addition to ledmac -- you may have to experiment with the package loading order.

-
Thank you for your answer. What I meant was the possibility to use the \edindex{} command, that prints, in the index, both the page and the line number, provided by the Ledmac \beginnumbering environment. –  Jean-Baptiste Camps Apr 10 '11 at 13:42
Thank you for this idea, I'll look in this direction. It looks like I'm going to have to redefine a part of the Ledmac code, particularly this one : –  Jean-Baptiste Camps Apr 12 '11 at 9:32

I know that I'm to late but maybe some others are also interested in the following aproach. I split the index in mutliple indices with the splitidx package with keeping the page and linenumber which are given by ledmac.

Code modifications: In the ledmac package there is the \@wredindexcommand that writes the index entries to the *.idx file. That's the place where I made my modifications. I format the outputstring so that it is similar to the output written by the \sindex command from the splitidx package.To do this we have to redefine the \edindex command first to use an optional parameter which gives the name of the used index (same syntax like \sindex). The modified version of \@wredindex now checks if there is an optional argument and branches between two macros which writes the index entry to the (same) *.idx file. This file should be splited by the splitindex script after the first latex run.

Split the index file: Here is a short explanation how to split the index file using the splitindex script: Because on my computer isn't installed the perl and java environment I use the latex option to split the index file (see splitidx package documentation). That's the procedure: Open the Windows command window (cmd.exe) or the Windows Power Shell (powershell.exe) and navigate to your latex-document folder. There you type latex splitindex. You will be asked for the file to split. If your latexfile is named main.tex you just type in main (because your indexfile is also named main) without the extension idx. In our example the splitindex script generates three new files: main-idx.idx, main-name.idx and main-location.idx. You can stay in the command window and type in makeindex main-idx.idx (press enter), then makeindex main-name.idx and at last makeindex main-location.idx. The script generates again three new files (main-idx.ind, main-name.ind and main-location.ind). Thats all. Now latex your document again and the three indices will be printed.

%*main.tex*
\documentclass{book}
\usepackage{ledmac}
\usepackage{splitidx}

\makeatletter
% redefine the edindex-command to enable an optional argument
\def\edindex[#1]#2{\@bsphack\@esphack}

% branch between the index entry with/without opt. argument
\def\@wredindex{\@ifnextchar[\my@lindex\my@index}

% index entry with opt. argument
\def\my@lindex[#1]#2{%
\protected@write\@indexfile{}%
{\string\indexentry[#1]{#2}{\thepageline}}%
\endgroup
\@esphack
}

% indexentry without opt. argument
\def\my@index#1{%
\protected@write\@indexfile{}%
{\string\indexentry{#1}{\thepageline}}%
\endgroup
\@esphack
}
\makeatother

\makeindex

% create new indices
\newindex[StandardIndex]{idx}
\newindex[NameIndex]{name}
\newindex[LocationIndex]{location}

\begin{document}
\beginnumbering
\pstart
Lorem ipsum dolor sit amet\edindex{standardIndex1}, consetetur sadipscing elitr,  sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et\edindex[name]{nameIndex1} justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr,  sed diam nonumy eirmod tempor invidunt ut\edindex[location]{locationIndex1} labore et dolore magna aliquyam erat, sed diam voluptua.
\pend
\endnumbering
\newpage
\beginnumbering
\pstart
At\edindex{standardIndex2} vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur\edindex[name]{nameIndex2} sadipscing elitr,  sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita\edindex[location]{locationIndex2} kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
\pend
\endnumbering
\printindex[idx]
\printindex[name]
\printindex[location]
\end{document}

-