MakeIndex, Nomenclature, Glossaries and AcronymsMake index list section, index item?

Information and discussion about MakeIndex - the tool to generate subject indices for LaTeX documents.
Post Reply
bombcar
Posts: 22
Joined: Tue Oct 28, 2008 10:18 pm

Make index list section, index item?

Post by bombcar »

I am overriding the index functionality it possibly horrible ways to make a list of songs in my document.

Code: Select all

\documentclass[b5paper]{book}
\usepackage{multicol}

\makeatletter
\newcommand{\makesongs}{%
	\makeindex
	\bgroup
		\def\indexsection\numberline##1##2\endindexsection{%
			\protected@write\@indexfile{}{\string\indexentry{##2}{##1}}}%
		\def\contentsline##1##2##3{\indexsection##2\endindexsection}%
		\@input@{\jobname.toc}%
	\egroup
}

\newcommand{\listofsongs}{%
\begingroup
	\@input@{\jobname.ind}%
	\if@filesw
		\expandafter\newwrite\csname tf@toc\endcsname
		\immediate\openout\csname tf@toc\endcsname\jobname.toc\relax
	\fi
	\@nobreakfalse
\endgroup}

\newcommand*{\songsection}[2][]{%
	\newpage
	\def\thesongtitle{#1}%
	\ifx\thesongtitle\@empty
		\section{#2}%
	\else
		\section[#1@#2]{#2}%
	\fi
}
\makeatother

\makesongs
\begin{document}
% Document is here

\newpage

\begin{multicols}{2}
\listofsongs
\end{multicols}
\end{document}
This is working pretty well, but I'm getting things like:

Code: Select all

song . . . . . . . . 22
Which is fine, but I'd rather have:

Code: Select all

22 song
instead.

My songs.ist is:

Code: Select all

preamble "\\section*{List of Songs}"
postamble ""
group_skip ""
item_0 "\n\\contentsline\{section\}\{"
delim_0 "\}\{"
delim_t "\}"
headings_flag 0
level '>'
Everything I try to do to make it operate differently seems to break on \numberline or \contentsline. Any ideas?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

Post Reply