4

I want to define \index[table]{#1} to hold several arguments: \index[table]{{#1}{#2}} and build a table row with it, using the splitindex.

How can I do this?

1010011010
  • 6,357
  • why complicate the makindex and change the structure of \item? just write \index{{aa}{bb}} and then define your final generated indexitem entry to take two arguments and make a table row – David Carlisle May 22 '14 at 09:49
  • @DavidCarlisle I suspect you're referring to e.g. imki@indexitem for imakeidx? – 1010011010 May 22 '14 at 11:20
  • not specifically but perhaps (not looked at imakeidx for a long while) just the general principle that makeindex writes a sorted list of commands but the definition of those commands is entirely under the control of macro definitions in latex so all you need to do is get makeindex to write stuff in the correct order. – David Carlisle May 22 '14 at 11:52

1 Answers1

5

This has nothing to do with imakeidx nor with \item. Just define a new index style. With imakeidx it's just simpler to manage the whole thing.

File ind10.ist

Save this file in the same directory as your LaTeX file

preamble "\\begin{theindex}\n\\begin{longtable}{lll}\\mygobble"
postamble "\n\\end{longtable}\n\\end{theindex}\n"
item_0 "\\\\\n\\mymacro"
delim_0 "&"

Test file

\documentclass{article}
\usepackage{longtable}
\usepackage{imakeidx}

\makeindex[options=-s ind10,columns=1]

\newcommand{\mymacro}[2]{#1&#2}
\newcommand{\mygobble}[1]{}% for gobbling the first \\

\begin{document}

abc\index{{aa}{bb}}\index{{ddd}{eeeeeeeee}}

\printindex

\end{document}

Resulting .ind file

\begin{theindex}
\begin{longtable}{lll}\mygobble\\
\mymacro{aa}{bb}&1\\
\mymacro{ddd}{eeeeeeeee}&1
\end{longtable}
\end{theindex}

Output

enter image description here

egreg
  • 1,121,712
  • One small additional question - how to supress the page numbering for the index? I'll accept your question tomorrow as I'm currently not at a PC with TeX on it - and I want to make sure that this works for my case. :-) – 1010011010 May 24 '14 at 21:59
  • Are you meaning the page number in the index entries? Then you don't want an index, but a glossary. The glossaries package is surely better for this. – egreg May 24 '14 at 22:01
  • I believe I found it at http://tex.stackexchange.com/questions/52142/remove-page-number-from-index-entries – 1010011010 May 24 '14 at 22:06
  • 1
    @1010011010 You could also “silence” the final column, see http://tex.stackexchange.com/questions/16604/easiest-way-to-delete-a-column which might be easier in this case. – egreg May 24 '14 at 22:09
  • While I still have the oppertunity to ask - I already have a different style file for another index - is this going to pose a problem? – 1010011010 May 24 '14 at 22:18
  • @1010011010 No, when you pass options=-s <name>.ist to an index, it's not inherited by other indices. If you don't pass the -s option, the default style is used. – egreg May 24 '14 at 22:20