2

I can get this by \index{apple|textit}

\item apple, \textit{1}

But i need to have index like this

apple, 3, 4 ex., 12-13 pr.

I tried this, but without any success

\newcommand{\mycommand}[1]{%
  #1 ex.%
}
...
\index{apple|mycommand}

EDIT: Minimal example:

\documentclass{book}
\usepackage[xindy]{imakeidx}
\makeindex

\makeatletter
\newcommand{\mycommand}[1]{%
  #1 ex.%
}
\makeatother

\begin{document}

Blablabla said Nobody 

\index{apple|textit}
\pagebreak
\index{apple|mycommand}

Blablabla said Nobody 
\printindex

\end{document}

Resulted ind-file:

\begin{theindex}
  \providecommand*\lettergroupDefault[1]{}
  \providecommand*\lettergroup[1]{%
      \par\textbf{#1}\par
      \nopagebreak
  }

  \lettergroup{A}
  \item apple, \textit{1}

\end{theindex}
  • Does it have to use the imakeidxpackage? I know glossaries can do this. – Guilherme Zanotelli Sep 16 '16 at 17:06
3

If you use xindy you can write in a new file my.xdy these lines:

(define-location-class "arabic-page-numbers"
    ("arabic-numbers") :min-range-length 1)
(define-attributes (("mycommand")))
(markup-locref :open "\mycommand{" :close "}" :attr "mycommand")
(markup-locref-list :open "\myrange{" :close "}" :sep "--" :depth 0 :class "arabic-page-numbers")

and run xindy with -M my option.

See xindy manual and this thread

In the output you can get something like this:

\lettergroup{A}
\item apple, \myrange{\textit{1}--\mycommand{2}}
\indexspace
\lettergroup{B}
\item banana, \myrange{\mycommand{1}--\mycommand{2}}

And then you redefine the commands and make some kind of switcher:

\newcounter{printEX}
\setcounter{printEX}{1}
\newcommand{\mycommand}[1]{%
    #1\ifcase\theprintEX\relax \or{~ex.}\fi%
}
\newcommand{\myrange}[1]{%
    \setcounter{printex}{0}#1%
    \setcounter{printEX}{1}%
}
|improve this answer|||||
  • May be you know how to make it works with multipage indices? – Yola Sep 17 '16 at 7:44
  • I edited the post a little, added "define-attributes" – pantlmn Sep 18 '16 at 10:03
  • Edited once again, added range processing. – pantlmn Sep 18 '16 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.