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}
1
  • Does it have to use the imakeidxpackage? I know glossaries can do this. Commented Sep 16, 2016 at 17:06

1 Answer 1

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}%
}
3
  • May be you know how to make it works with multipage indices?
    – Yola
    Commented Sep 17, 2016 at 7:44
  • I edited the post a little, added "define-attributes"
    – pantlmn
    Commented Sep 18, 2016 at 10:03
  • Edited once again, added range processing.
    – pantlmn
    Commented Sep 18, 2016 at 10:46

You must log in to answer this question.

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