1

(SECOND POST) Here is an updated code which shows that when commenting the index package I get in the index two separate entries in the index for the term alldifferent (one for its definition and one for its occurrence). But if I put the index package I get only one entry for alldifferent (as it should be), but I dont get the explanatory text anymore.

\documentclass[]{book}

\usepackage{etex}
\usepackage{makeidx}
\usepackage[totoc,columns=1]{idxlayout}
%\usepackage{index}
\usepackage[plainpages=false,pdfpagelabels,colorlinks,linkcolor=cyan,citecolor=cyan,urlcolor=cyan,bookmarks,hyperindex=false,pagebackref=true]{hyperref}

\sloppy
\makeindex

\newcommand*{\indexuse}[1]{\hyperpage{#1}}
\newcommand*{\indexdef}[1]{\textbf{\hyperpage{#1}}}
\newcommand*{\indexsyn}[1]{\textbf{\textit{\hyperpage{#1}}}}

\def\constraint#1{\textsc{#1}}
\def\ctrref#1{$\constraint{#1}$\index{#1@$\constraint{#1}$|indexuse}}

\pagestyle{headings}

\begin{document}

\pagenumbering{Alph}% to avoid spurious warnings
\title{\Huge Title}
\author{toto}
\maketitle
\thispagestyle{empty}

\frontmatter

\tableofcontents

\chapter{Preface}

abc abc
toto \index{toto|indexuse}
def
\index{alldifferent@$\constraint{alldifferent}$|indexdef}

\mainmatter
\chapter{First chapter}

tutu \index{tutu|indexuse}
titi \index{titi|indexuse}
aaa aaa \index{toto|indexdef} bbb


tutu \index{tutu|indexdef}
titi \index{titi|indexdef}
\index{toto|indexsyn}
\ctrref{alldifferent}


\setindexprenote{%
  Page numbers in bold face (as in \textbf{160}) point to a definition
  of a constraint, keyword, restriction or system. Page numbers in
  bold-italic face (as in \textbf{\textit{160}}) notify an abbreviation
  of a constraint name. Finally, page numbers in serif face (as in 160) 
  indicate an occurrence of constraint name, keyword, system or author name.%
}
\printindex
\end{document}

(INITIAL POST) Is there a way to add an explanatory small text to an index page when using makeidx together with the book class (note that since I am using an .ist style file I prefer to stay with makeidx and not to use the splitidx or imakeidx packages suggested in some posts; since I also use the book class I dont want to switch to the memoir class as suggested in some other post).

Since I am not completely sure where to exactly add your suggested code, I add a tiny example of my document that compile:

\documentclass[]{book}
\usepackage{makeidx}
\usepackage{index}
\usepackage[plainpages=false,pdfpagelabels,colorlinks,linkcolor=cyan,
            citecolor=cyan,urlcolor=cyan,bookmarks,
            hyperindex=false,pagebackref=true]{hyperref} 

\sloppy
\makeindex

\newcommand*{\indexuse}[1]{\hyperpage{#1}}

\begin{document}

\pagestyle{headings}
\title{\Huge Title}
\author{toto}
\maketitle
\thispagestyle{empty}

\frontmatter
\chapter{Preface}

abc abc
toto \index{toto|indexuse}
def

\mainmatter
\chapter{First chapter}

tutu \index{tutu|indexuse}
titi \index{titi|indexuse}

\cleardoublepage
\markboth{INDEX}{INDEX}
\phantomsection
\addcontentsline{toc}{chapter}{Index}
% Page numbers in bold face (as in \textbf{160}) point to a definition
% of a constraint, keyword, restriction or system. Page numbers in
% bold-italic face (as in \textbf{\textit{160}}) notify an abbreviation
% of a constraint name. Finally, page numbers in serif face (as in 160) 
% indicate an occurrence of constraint name, keyword, system or author name.
\printindex
\end{document}

Finally the catalog.ist file contains the following lines:

preamble "\\begin{theindex} {\\small\\onecolumn\\newcounter{idxl}\n"
postamble "\n\n} \\end{theindex} \n"
group_skip "\n\n  \\vspace*{12mm}\n"
heading_prefix "{
\\bfseries\\Large\\hfill "
heading_suffix "\\hfill}\\nopagebreak\\vspace*{4mm}\\stepcounter{idxl}\n"
symhead_positive "1..."
headings_flag  1
7
  • to you mean text at the start of the index between the heading and the first entry, or additional notes on individual entries? (a test document always helps) Commented Jan 9, 2018 at 18:35
  • Yes I mean exactly that, i.e. adding some text at the start of the index between the heading and the first entry. I was trying imakeidx but it turned out to corrupt the printing of the index: lines were overlapping for some unknown reason (I did not provide the document since it was too big). Commented Jan 9, 2018 at 19:38
  • I understand that you redefine theindex, but I am not sure where to add the different parts in my text, for which I now provide an example that compile. Commented Jan 9, 2018 at 21:22
  • put the code in my answer in your preamble, in between \makeatletter and \makeatother Commented Jan 9, 2018 at 21:29
  • Do you mean just before "\begin{document}" ? Also should I just put the first 8 lines, or everything (because you also insert some text lines which do not seem to be part of the redefinition of theindex) Commented Jan 9, 2018 at 21:38

2 Answers 2

1

You can use idxlayout, which also makes it possible to avoid issuing \onecolumn. Here's the fixed .ist file:

preamble "\\begin{theindex} \\small\\newcounter{idxl}\n"
postamble "\n\n \\end{theindex} \n"
group_skip "\n\n  \\vspace*{12mm}\n"
heading_prefix "{\\bfseries\\Large\\hfill "
heading_suffix "\\hfill}\\nopagebreak\\vspace*{4mm}\\stepcounter{idxl}\n"
symhead_positive "1..."
headings_flag  1

Here's the example, where I have populated the index to show how the headers and the entry in the table of contents are as wanted.

\documentclass[]{book}
\usepackage{makeidx}
%\usepackage{index} % do you need it?
\usepackage[totoc,columns=1]{idxlayout}
\usepackage[
  plainpages=false,
  pdfpagelabels,
  colorlinks,
  linkcolor=cyan,
  citecolor=cyan,
  urlcolor=cyan,
  bookmarks,
  hyperindex=false,
  pagebackref=true,
]{hyperref} 

\sloppy
\makeindex

\newcommand*{\indexuse}[1]{\hyperpage{#1}}

\pagestyle{headings}

\begin{document}

\pagenumbering{Alph}% to avoid spurious warnings
\title{\Huge Title}
\author{toto}
\maketitle
\thispagestyle{empty}

\frontmatter

\tableofcontents

\chapter{Preface}

abc abc
toto \index{toto|indexuse}
def

\mainmatter
\chapter{First chapter}

tutu \index{tutu|indexuse}
titi \index{titi|indexuse}

% populate the index
\count255=0
\loop\ifnum\count255<200
  \advance\count255 1
  \expandafter\index\expandafter{\romannumeral\count255|indexuse}
\repeat

\setindexprenote{%
  Page numbers in bold face (as in \textbf{160}) point to a definition
  of a constraint, keyword, restriction or system. Page numbers in
  bold-italic face (as in \textbf{\textit{160}}) notify an abbreviation
  of a constraint name. Finally, page numbers in serif face (as in 160) 
  indicate an occurrence of constraint name, keyword, system or author name.%
}
\printindex
\end{document}
5
  • When I add back the \usepackage{index} line (which I need, otherwise the indexing process creates two separate entries for the definition and the occurrence of a same term) then it still compile and produce a document but with the following problems: I get two columns in the index (rather than one column) and the text inside \setindexprenote is not displayed any more. Commented Jan 10, 2018 at 10:59
  • @NicolasBeldiceanu No, you don't need index, in my opinion. Without seeing what you mean by “definition” and “occurrence”, it's difficult to help.
    – egreg
    Commented Jan 10, 2018 at 11:40
  • I modify my post (see the code just after the term SECOND POST) to illustrate the problem with "definition" and "occurrence", i.e. the "definition" refers to "\index{alldifferent@$\constraint{alldifferent}$|indexdef}" and the "reference" refers to "\ctrref{alldifferent}" Commented Jan 10, 2018 at 14:21
  • @NicolasBeldiceanu Just load index before idxlayout.
    – egreg
    Commented Jan 10, 2018 at 15:00
  • By loading the index package before the idxlayout package everything works now, i.e. both the generation of one single index entry for a "definition" and an "occurrence" of a same word, and the generation of the explanotary text at the beginning of the index. Commented Jan 10, 2018 at 16:57
0

You don't need any special packages for this. makeindex just writes \begin{theindex} ... \end{theindex} into the .ind file so you just define that environment to do whatever you want This is the definition from article.cls with a paragraph of text added

\renewenvironment{theindex}
               {\if@twocolumn
                  \@restonecolfalse
                \else
                  \@restonecoltrue
                \fi
                \twocolumn[\section*{\indexname}
this is a paragraph spanning a 2-column index

a second paragraph
]%
            \@mkboth{\MakeUppercase\indexname}%
                    {\MakeUppercase\indexname}%

  this is a paragraph in the first column of the index

            \thispagestyle{plain}\parindent\z@
            \parskip\z@ \@plus .3\p@\relax
            \columnseprule \z@
            \columnsep 35\p@
            \let\item\@idxitem}
           {\if@restonecol\onecolumn\else\clearpage\fi}

Seeing this in context of the example you added later, note i removed a bad group and\clearpage` from the ist file.

enter image description here

document

\documentclass[]{book}
\usepackage{makeidx}
\usepackage{index}
\usepackage[plainpages=false,pdfpagelabels,colorlinks,linkcolor=cyan,
            citecolor=cyan,urlcolor=cyan,bookmarks,
            hyperindex=false,pagebackref=true]{hyperref} 

\sloppy
\makeindex

\makeatletter
\newcounter{idxl}
\renewenvironment{theindex}
               {\if@twocolumn
                  \@restonecolfalse
                \else
                  \@restonecoltrue
                \fi
                \twocolumn[\section*{\indexname}
this is a paragraph spanning a 2-column index

a second paragraph
]%
            \@mkboth{\MakeUppercase\indexname}%
                    {\MakeUppercase\indexname}%

  this is a paragraph in the first column of the index

            \thispagestyle{plain}\parindent\z@
            \parskip\z@ \@plus .3\p@\relax
            \columnseprule \z@
            \columnsep 35\p@
            \let\item\@idxitem}
           {\if@restonecol\onecolumn\else\clearpage\fi}
\makeatother
\newcommand*{\indexuse}[1]{\hyperpage{#1}}

\begin{document}

\pagestyle{headings}
\title{\Huge Title}
\author{toto}
\maketitle
\thispagestyle{empty}

\frontmatter
\chapter{Preface}

abc abc
toto \index{toto|indexuse}
def

\mainmatter
\chapter{First chapter}

tutu \index{tutu|indexuse}
titi \index{titi|indexuse}

\cleardoublepage
\markboth{INDEX}{INDEX}
\phantomsection
\addcontentsline{toc}{chapter}{Index}
% Page numbers in bold face (as in \textbf{160}) point to a definition
% of a constraint, keyword, restriction or system. Page numbers in
% bold-italic face (as in \textbf{\textit{160}}) notify an abbreviation
% of a constraint name. Finally, page numbers in serif face (as in 160) 
% indicate an occurrence of constraint name, keyword, system or author name.
\printindex
\end{document}

ist

preamble "\\begin{theindex} 
postamble "\n\n} \\end{theindex} \n"
group_skip "\n\n  \\vspace*{12mm}\n"
heading_prefix "{
\\bfseries\\Large\\hfill "
heading_suffix "\\hfill}\\nopagebreak\\vspace*{4mm}\\stepcounter{idxl}\n"
symhead_positive "1..."
headings_flag  1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .