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?

3
  • 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 Commented May 22, 2014 at 9:49
  • @DavidCarlisle I suspect you're referring to e.g. imki@indexitem for imakeidx?
    – 1010011010
    Commented May 22, 2014 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. Commented May 22, 2014 at 11:52

1 Answer 1

5
+50

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

6
  • 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
    Commented May 24, 2014 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
    Commented May 24, 2014 at 22:01
  • I believe I found it at tex.stackexchange.com/questions/52142/…
    – 1010011010
    Commented May 24, 2014 at 22:06
  • 1
    @1010011010 You could also “silence” the final column, see tex.stackexchange.com/questions/16604/… which might be easier in this case.
    – egreg
    Commented May 24, 2014 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
    Commented May 24, 2014 at 22:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .