在索引中为页码添加后缀

在索引中为页码添加后缀

我可以通过\index{apple|textit}

\item apple, \textit{1}

但我需要有这样的索引

苹果,3,4 例如,12-13 pr。

我试过了,但没有成功

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

编辑: 最小示例:

\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}

结果印地语-文件:

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

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

\end{theindex}

答案1

如果您使用,xindy您可以在新文件中写入my.xdy以下行:

(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")

并运行xindy选项-M my

xindy 手册此主题

在输出中你可以得到如下内容:

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

然后重新定义命令并制作某种转换器:

\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}%
}

相关内容