组合 hyperref、imakeidx 和词汇表:不确定如何获得预期效果

组合 hyperref、imakeidx 和词汇表:不确定如何获得预期效果

当我将词汇表条目嵌入为索引参数的一部分时(此处的示例:)\index[m]{\gls{ccc}},索引会将条目分组到“符号”下,而不是词汇表条目的首字母下(在以下 MWE 的情况下为“c”)。我该如何防止这种情况发生?

我创建这种索引条目的原因是 hyperref 包使 PDF 中的索引条目可点击,然后直接将我带到词汇表。然而,意想不到的副作用是词汇表也会引用索引的页码。我该如何避免这种情况?

这是 MWE——请注意,index_style.ist下面还有一个文件也是需要的。

\documentclass[10pt, paper=156mm:235mm, BCOR=12mm, headings=optiontotocandhead, headings=openany]{scrbook}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage[dutch,british,UKenglish]{babel}
\KOMAoptions{headings=small}

\DeclareTOCStyleEntry[
  linefill={},
]{tocline}{chapter}

\makeatletter
\newcommand \Dotfill {\leavevmode \leaders \hb@xt@ 0.75em{\hss .\hss }\hfill \kern \z@}
\makeatother

\newcommand{\toclineinsert}[3][14mm]{%
    \Dotfill #2\makebox[#1][l]{#3\Dotfill}%
}

\usepackage[splitindex]{imakeidx}%Indexing package
\makeindex[intoc,options= -s index_style.ist,name=m,title=\mbox{Index},columns=2]

\usepackage[T1]{fontenc}
\usepackage{Alegreya,AlegreyaSans} 
\renewcommand*\oldstylenums[1]{{\AlegreyaOsF #1}}

%hyphenation
\pretolerance=4000
\tolerance=2000 
\emergencystretch=8pt

\usepackage[hidelinks, bookmarksopen=false]{hyperref}

\usepackage[toc]{glossaries}

\makeglossaries

    \newglossaryentry{aaa}
    {
        name=ate all apples,
        description={I did. I ate all apples and I liked it. But now my tummy hurts and I regret my decision}
    }
    
    \newglossaryentry{bbb}
    {
        name=bought both boxes,
        description={Yes, that's true. Why just buy the one if you can afford both? That's what I thought. However, now my wallet's empty, and so are my boxes}
    }

    \newglossaryentry{ccc}
    {
        name=caught Cathy's cold,
        description={Could have been worse though. It was really just a cold. Cathy and I are going to be OK}
    }

\begin{document}

\frontmatter
\tableofcontents

\addchap[tocentry={\emph{Preface}}, head={\textsc{preface}}]
  {Preface}
  
  I \gls{ccc} last Wednesday. \lipsum

\mainmatter

\addchap[tocentry={Exaltation \toclineinsert{\normalfont{17 December}}{} },head={}]{Exaltation}

I \gls{aaa} and I \gls{bbb}\index[m]{\gls{ccc}}.

\backmatter

\printglossary

\printindex[m]

\end{document}

与文件一起工作index_style.ist

headings_flag 1

heading_prefix "\n\\raggedright\\large\\sffamily\\normalfont%
\\noindent\\textbf{"heading_suffix "}\\par\\nopagebreak\n"

item_0 "\n \\item \\small "

delim_0 " \\Dotfill "
delim_1 " \\Dotfill "
delim_2 " \\Dotfill "

答案1

Andrew Swann 展示了如何让索引条目正确显示。下一步是让词汇表文本自动显示,我们可以使用 来实现\glsentrytext{ccc}\index[m]{\glsentrytext{ccc}@\gls{ccc}}不幸的是,它仍然显示在符号下。最后一步是展开,\glsentrytext{ccc}然后\index查看发生了什么:

I \gls{aaa} and I \gls{bbb}
\expandafter\index\expandafter[\expandafter m\expandafter]\expandafter{\glsentrytext{ccc}@\gls{ccc}}.

如果您经常这样做(超过零次),将其制成命令可能会很有用:

\newcommand{\indexgls}[1]{\expandafter\index\expandafter[\expandafter m\expandafter]\expandafter{\glsentrytext{#1}@\gls{#1}}}

然后你就可以拥有
I \gls{aaa} and I \gls{bbb}\indexgls{ccc}.

如果您不希望索引页出现在词汇表条目中,您可以删除该@\gls{...}部分。

考虑到发生了扩展奇怪的事情,该命令使用 LaTeX3 可能会更简单,但我对此了解不够。

相关内容