无法使引用行号的索引列出多个实例

无法使引用行号的索引列出多个实例

我无法理解现有的例子,例如

我正在使用ekdosis依赖于的包verse,最终lineno为基于长诗的文档生成行号。现在我得到了以下命令的帮助,但我无法获得正确的结果,该结果应为“rose, 1, 4, 8”。我得到的是“rose, 8”:

\documentclass{report}
\usepackage{imakeidx}
\usepackage{xpatch}
\usepackage{ekdosis}

\makeindex

\makeatletter
\newcommand{\lineindex}[1]{\linelabel{#1}\index{#1}}
\patchcmd{\@wrindex}{\thepage}{\getrefnumber{#2}}{}{}
\makeatother

\begin{document}
\begin{ekdosis}
\begin{ekdverse}
The rose is a rose,\lineindex{rose} \\*
And was always a rose. \\*
But the theory now goes \\*
That the apple's a rose,\lineindex{rose} \\*
And the pear is, and so's \\*
The plum, I suppose. \\*
The dear only knows \\*
What will next prove a rose.\lineindex{rose} \\*
You, of course, are a rose - \\*
But were always a rose.\\*
Robert Frost\\*
\end{ekdverse}
\end{ekdosis}

\printindex
\end{document}

答案1

如果ekdosis加载了[poetry=verse],就像这样:\usepackage[poetry=verse]{ekdosis},这应该可以工作:

\documentclass{report}
\usepackage{imakeidx}
\usepackage{xpatch}
\usepackage[poetry=verse]{ekdosis}

\makeindex

\makeatletter
\patchcmd{\@wrindex}{\thepage}{\thepoemline}{}{}
\makeatother


\begin{document}

\begin{ekdosis}
  \begin{ekdverse}
    The rose is a rose,\index{rose} \\*
    And was always a rose. \\*
    But the theory now goes \\*
    That the apple's a rose,\index{rose} \\*
    And the pear is, and so's \\*
    The plum, I suppose. \\*
    The dear only knows \\*
    What will next prove a rose.\index{rose} \\*
    You, of course, are a rose - \\*
    But were always a rose.\\*
    Robert Frost\\*
  \end{ekdverse}
\end{ekdosis}

\printindex
\end{document}

在此处输入图片描述

相关内容