## LaTeX forum ⇒ MakeIndex, Nomenclature, Glossaries and Acronyms ⇒ Forcing a blank index line alphabetically Topic is solved

Information and discussion about MakeIndex - the tool to generate subject indices for LaTeX documents.
gossett
Posts: 5
Joined: Thu Sep 17, 2015 11:11 pm

### Forcing a blank index line alphabetically

There are times when makeindex leaves some unfortunate page or column breaks. I know that it is possible to edit the .ind file and add a \indexspace entry.

However, I would like a solution that is handled at the source file level. Something like \indexspace{masquerades as} where "masquerades as" would indicate where, in alphabetical order, the blank space should reside.

For example, I have the index entries

cable
cat
coin

but want a space between cable and cat. I would like to add this to my source file:

\indexspace{cac}

(cac is not a valid word, but it lands where I want a blank line).

Tags:

rais
Posts: 172
Joined: Sun Nov 16, 2014 8:51 pm
I'm not sure what you may need this for, but here's an idea:
1. \documentclass{article}
2. \usepackage{makeidx}
3. % You could add this to your .ist file, if you're using one (makeindex -s .ist); .mst is loaded by makeindex automatically, if it has the same basename as the file to be processed (unless suppressed via -s argument):
4. \begin{filecontents*}{\jobname.mst}
5. delim_0 "\\idxcomma"
6. delim_1 "\\idxcomma"
7. delim_2 "\\idxcomma"
8. \end{filecontents*}
9. \makeindex
10. \newif\ifidxskippage %flag for skipping over page entry ... and its delimeter
11. \newcommand*\skipindex[1]{%
12. \index{#1@\protect\idxskippagetrue~|skippageentry}%
13. % this reads: create an index under #1 (`cac' in this example), set the skipping flag, use a non-breaking space as entry, and use \skippageentry for encapsuling the entry's page number.
14. }
15. \newcommand*\skippageentry[1]{\idxskippagefalse}% ignore the parameter (the page number) and reset the skipping flag
16. \newcommand*\idxcomma{% now the reason for creating the skipping flag:
17. \ifidxskippage
18. % if skipping flag is active, do nothing
19. \else % otherwise, output the usual comma, followed by space
20. ,
21. \fi
22. }
23. \begin{document}
24. foo\index{cat}\index{coin}\index{cable}
25. \skipindex{cac}
26. \printindex
27. \end{document}

KR
Rainer

gossett
Posts: 5
Joined: Thu Sep 17, 2015 11:11 pm
Thank you so much. This almost does what I need. If I run it on a typical latex file it works great. Unfortunately, I have the following .ist file:

IndexTest.ist:
1. preamble
2. "\\thispagestyle{empty}\n\\begin{theindex}\n"
3. postamble
4. "\\end{theindex}\n"

When I run your code in conjunction with this, the commas are not suppressed on the blank index line.

Index
cable, 1
,
cat, 1
coin, 1

the revision replaces \makeindex with
\makeindex[options=-s IndexTest.ist]

(I am using the imakeindex package.)

gossett
Posts: 5
Joined: Thu Sep 17, 2015 11:11 pm
I found a way to avoid using the .ist file. So your solution works just fine. Thanks again.

rais
Posts: 172
Joined: Sun Nov 16, 2014 8:51 pm
gossett wrote:Unfortunately, I have the following .ist file:

IndexTest.ist:
1. preamble
2. "\\thispagestyle{empty}\n\\begin{theindex}\n"
3. postamble
4. "\\end{theindex}\n"

so what? Can't you just add the three lines from my .mst file (delim...) to your .ist file?
Or was your .ist file automagically created?

KR
Rainer

gossett
Posts: 5
Joined: Thu Sep 17, 2015 11:11 pm
Adding your code into my .ist file did not eliminate the extra commas. I am not sure why the two don't play well together.

I will upload sample files.
Attachments
IndexTest.tex
The main file

rais
Posts: 172
Joined: Sun Nov 16, 2014 8:51 pm
gossett wrote:Adding your code into my .ist file did not eliminate the extra commas.

well, I still don't see the problem you're describing---after merging the three lines from my .mst into your .ist, that is.
1. preamble
2. "\\thispagestyle{empty}\n\\begin{theindex}\n"
3. postamble
4. "\\end{theindex}\n"
5. delim_0 "\\idxcomma"
6. delim_1 "\\idxcomma"
7. delim_2 "\\idxcomma"

Of course, you won't be needing the filecontents* environment any longer (by using the -s option, a .mst file would be ignored, anyway...but I wrote sth. to that regard already, didn't I?)

KR
Rainer

gossett
Posts: 5
Joined: Thu Sep 17, 2015 11:11 pm
That did fix the test file. I think I was pasting too much into the .ist file. Thanks for the help.

Return to “MakeIndex, Nomenclature, Glossaries and Acronyms”

### Who is online

Users browsing this forum: No registered users and 1 guest