# How to use different formatting for multiple indices with imakeidx and .ist files?

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]{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]{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:

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.

• Shouldn't it be .mst instead of .ist files? This is a content of one of my .mst files: headings_flag 1 heading_prefix "\\adjustbox{minipage=\\linewidth, cfbox=black, bgcolor=gray!20, vspace= 0ex .5em}{\\textbf\{\\large " heading_suffix "\}}\\par\\nopagebreak\n" item_0 "\n \\item \\small " delim_0 " \\dotfill " delim_1 " \\dotfill " delim_2 " \\dotfill " And, this package might be useful: ctan.org/pkg/idxlayout – gilu Feb 20 '17 at 13:46
• Thanks for your reply! I changed the text of one of my .ist files to your code but I didn't see a difference, not even the dotfill. Instead the index reverted to a comma separation and space before the page number. Not sure what's wrong here. And I'll look into .mst v. .ist. As for idxlayout, I didn't seen anything in the package that would help me get the results I need, so far as italics and designated empty lines. How did you think I could use it? – niesen Feb 20 '17 at 16:58
• niesen, I thought you wanted to change the indent of your index. With the package idxlayout this could be done - that's all. As I wrote, this was the content of my .mst file, not .ist. I don't even have .ist files in this project... maybe just rename your .ist to .mst? – gilu Feb 21 '17 at 9:00
• Realised what was wrong earlier, it was looking for the wrong .ist file (my problem). When fixed, the code you supplied caused errors. When I looked at the output, half the code as in the index itself. Looking for a way to upload a photo. In the meanwhile, my main concern is getting italics for only particular item levels and controlling index spacing around the different item levels. I think the indents can be removed using the class file. Do you know how I would format the item levels differently using the .ist/.mst system? – niesen Feb 21 '17 at 13:30
• I can't add an extra photo into the first post until I have ten reputation points. The index output now has most of the code before the bold letter working as a header within the index. It runs from "minipage" through ".5em". – niesen Feb 21 '17 at 13:38

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]{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]{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}

\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.

• Just a small question: how do you deal with the space that is produced by \indexspace before the first item? I copied your code of index 4, but now I'm stuck with spaces on top of every column. – Jopie Dec 19 '17 at 9:48