[Tex/LaTex] How to use different formatting for multiple indices with imakeidx and .ist files

imakeidxindexing

I need to format the items and subitems for three different types of index in different ways with .ist files. How do I add italics to specific terms and introduce empty lines between different item levels for each index using separate .ist files?

MWE:

\documentclass[openany]{book}

\usepackage{imakeidx}
\makeindex[name=one,title=Index One, intoc, options= -s onetwothree.ist]
\makeindex[name=four,title=Index Four, intoc, options= -s four.ist]
\makeindex[name=six,title=Index Six, intoc, options= -s fivesix.ist]

\begin{document}

Some text.

\index[one]{Acts of the Avocados!2:2}
\index[one]{Romaines!3:3}
\index[one]{Romaines!4:4}
\index[four]{Aristotle!Metaphysallis!205c}
\index[four]{Aristotle!Metaphysallis!306d}
\index[four]{Plato!Tomatoes!407e}
\index[four]{Cicero!Lettuce!115}
\index[six]{Bananerges}
\index[six]{Appleadorus}
\index[six]{Plato}

\printindex[one]
\printindex[four]
\printindex[six]
\end{document}

.ist contents (all three files):

delim_0 " \\hfill  "
delim_1 " \\hfill  "
delim_2 " \\hfill  "

Long version of question: I’ve messed around with this for a while and read everything I could find online but frankly I just don’t know enough about working outside the TeX file itself to make this work. I've learned LaTeX through cribbing other people's code and tweaking it and some trial and error, and I don't have any books or coding background, so please make answers detailed and don't necessarily assume specific knowledge on my part. I intend to read the LaTeX companion in the future and I do understand plenty, but not jargon, if that makes sense.

My publisher has asked for three separate formats for different indices. I have six indices in total: three indices of (extra)biblical sources, one of ancient classical sources, one of places, and one of subjects. Indices 1-3 share a format, as do 5 and 6, but 4 has its own requirements. They're always completely flush left with no indents of any kind except for subitems in the place and subject indices. I thought using .ist files was the best way to get the three formats I need but so far I've only succeeded in getting the last style close to the way I want it.

These index formats break down like this:

Indices 1-3: empty line before items, item names are italicized (e.g. “Genesis”), followed by the citation as a subitem on the next line (with no skip), and \hfill to the page numbers.

Index 4: empty line before items in normal font, empty line before subitems, which are italicized, and no empty line before subsubitems. Everything should be flush left.

Indices 5 and 6: no empty lines between items with same starting letter, and no italicization, small indent for subitems.

As I see it, I need 3 .ist files for the three separate formats for these indices. So far, I have \hfill working in these .ist files but nothing else:

delim_0 " \\hfill "
delim_1 " \\hfill "
delim_2 " \\hfill "

Here's an image of the desired results:
enter image description here

A note for other indexing/LaTeX newbs, I've found I don't need to use Terminal to run this, it works just in texmaker running XeLaTex.

I've also seen this page with .ist commands, but I don't know enough to use these to achieve what I want. I don't know how to put the rest of the formatting into the .ist files to get what I need for the three index styles.

Best Answer

Ok, I think I've found the answer. My thanks go to Gilu, whose info led me to the following solution. Here is the MWE (a little expanded to better see how it works).

\documentclass[openany]{book}

\usepackage{imakeidx}
\makeindex[name=one,title=Index One, intoc, options= -s one.ist]
\makeindex[name=four,title=Index Four, intoc, options= -s four.ist]
\makeindex[name=six,title=Index Six, intoc, options= -s six.ist]

\usepackage[hangindent=0pt,subindent=0pt,subsubindent=0pt]{idxlayout}

\begin{document}

Some text.

\index[one]{Acts of the Avocados!2:2}
\index[one]{Acts of the Avocados!5:5}
\index[one]{Acts of the Avocados!3:3}
\index[one]{Acts of the Avocados!5:5}
\index[one]{Acts of the Avocados!6:6}
\index[one]{Acts of the Avocados!7:7}
\index[one]{Acts of the Avocados!8:8}
\index[one]{Romaines!3:3}
\index[one]{Romaines!4:4}
\index[one]{Romaines!5:5}
\index[four]{Aristotle!Metaphysalis!205c}
\index[four]{Aristotle!Metaphysalis!306d}
\index[four]{Plato!Tomatoes!407e}
\index[four]{Cicero!Lettuce!115}
\index[six]{Bananerges}
\index[six]{Appleadorus}
\index[six]{Plato}
\index[six]{Plato!\textit{Potatoes}!144a}
\index[six]{Plato!\textit{Potatoes}!166d}

\printindex[one]
\printindex[four]
\idxlayout{itemlayout=abshang} 
\printindex[six]
\end{document}

Things that have changed: 1) I added idxlayout to make life easy when it comes to turning off indents within the indices without having to mess around in the class file, as suggested by Gilu, 2) I set up the .ist files correctly for what I want to achieve and 3) I added a line of idxlayout code to re-apply indents for the subject index, which comes last.

Now, here are the new .ist files, followed by the .ind files they produce in case anyone else has to customize their index in a similar way. I used the page cited in my question to find the "keys" to controlling different aspects of the index formatting in the .ist files (index style files). This is the link: https://www.sharelatex.com/learn/Indices#/Parameters_for_the_.5Cmakeindex_command.

I messed around with the .ist files until they produced an .ind file that read like working code, so if anyone has to format an index in the same way, that would be my number one tip from this experience: mess around with your .ist files until the .ind files they make when you run (xe)latex look like latex code that should work. Sometimes that means opening curly brackets under one key and closing them under another key.

Final thing: Always make sure your text editor doesn't convert straight quotes (") into curly quotes in your .ist files when you're not looking. It will screw things up.

one.ist:

item_0 "\\indexspace \\vspace{-12pt} \n \\textit{\\item " 
item_x1 " } \n \\subitem "


delim_0 " \\hfill " 
delim_1 " \\hfill " 
delim_2 " \\hfill "

one.ind (although it's set off like code here, this is just the contents of the file; setting it up as code in the forum post editor makes it easier to read):

 \begin{theindex}

 \textit{\item Acts of the Avocados } 
 \subitem 2:2 \hfill 1 
 \subitem 3:3 \hfill 1 
 \subitem 5:5 \hfill 1 
 \subitem 6:6 \hfill 1 
 \subitem 7:7 \hfill 1 
 \subitem 8:8 \hfill 1

  \indexspace

 \textit{\item Romaines } 
 \subitem 3:3 \hfill 1 
 \subitem 4:4 \hfill 1 
 \subitem 5:5 \hfill 1

\end{theindex}

four.ist: (\no indent was added because without it there was a space moving the \item in)

item_0 " \\indexspace \n \\item \\noindent \\vspace{10.5pt}"
item_x1 " \n  \\subitem  \\textit{"
item_x2 " \n } \\subitem "

delim_0 " \\hfill "
delim_1 " \\hfill "
delim_2 " \\hfill "

four.ind:

\begin{theindex}
\item \noindent \vspace{10.5pt}Aristotle 
  \subitem  \textit{Metaphysalis 
 } \subitem 205c \hfill 1
      \subsubitem 306d \hfill 1

  \indexspace
\item \noindent \vspace{10.5pt}Cicero 
  \subitem  \textit{Lettuce 
 } \subitem 115 \hfill 1

  \indexspace
\item \noindent \vspace{10.5pt}Plato 
  \subitem  \textit{Tomatoes 
 } \subitem 407e \hfill 1

\end{theindex}

six.ist:

delim_0 " \\hfill "
delim_1 " \\hfill "
delim_2 " \\hfill "

six.ind:

\begin{theindex}

  \item Appleadorus \hfill 1

  \indexspace

  \item Bananerges \hfill 1

  \indexspace

  \item Plato \hfill 1
    \subitem \textit{Potatoes}
      \subsubitem 144a \hfill 1
      \subsubitem 166d \hfill 1

\end{theindex}

I'll wait a few days before accepting my own post as the answer since someone may have a more elegant solution.

Related Question