MakeIndex, Nomenclature, Glossaries and AcronymsForcing a blank index line alphabetically

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

Forcing a blank index line alphabetically

Post by gossett »

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

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Forcing a blank index line alphabetically

Post by rais »

I'm not sure what you may need this for, but here's an idea:

Code: Select all

\documentclass{article}
\usepackage{makeidx}
% 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):
\begin{filecontents*}{\jobname.mst}
delim_0 "\\idxcomma"
delim_1 "\\idxcomma"
delim_2 "\\idxcomma"
\end{filecontents*}
\makeindex
\newif\ifidxskippage %flag for skipping over page entry ... and its delimeter
\newcommand*\skipindex[1]{%
  \index{#1@\protect\idxskippagetrue~|skippageentry}%
  % 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.
}
\newcommand*\skippageentry[1]{\idxskippagefalse}% ignore the parameter (the page number) and reset the skipping flag
\newcommand*\idxcomma{% now the reason for creating the skipping flag:
  \ifidxskippage
  % if skipping flag is active, do nothing
  \else % otherwise, output the usual comma, followed by space
  ,
  \fi
}
\begin{document}
foo\index{cat}\index{coin}\index{cable}
\skipindex{cac}
\printindex
\end{document}
KR
Rainer
gossett
Posts: 5
Joined: Thu Sep 17, 2015 11:11 pm

Forcing a blank index line alphabetically

Post by gossett »

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:

Code: Select all

preamble
"\\thispagestyle{empty}\n\\begin{theindex}\n"
postamble
"\\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

Re: Forcing a blank index line alphabetically

Post by gossett »

I found a way to avoid using the .ist file. So your solution works just fine. Thanks again.
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Forcing a blank index line alphabetically

Post by rais »

gossett wrote:Unfortunately, I have the following .ist file:

IndexTest.ist:

Code: Select all

preamble
"\\thispagestyle{empty}\n\\begin{theindex}\n"
postamble
"\\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

Re: Forcing a blank index line alphabetically

Post by gossett »

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
(1.3 KiB) Downloaded 568 times
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Forcing a blank index line alphabetically

Post by rais »

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.

Code: Select all

preamble
"\\thispagestyle{empty}\n\\begin{theindex}\n"
postamble
"\\end{theindex}\n"
delim_0 "\\idxcomma"
delim_1 "\\idxcomma"
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

Re: Forcing a blank index line alphabetically

Post by gossett »

That did fix the test file. I think I was pasting too much into the .ist file. Thanks for the help.
Post Reply