在我的索引中,如果能搜索仅有的与顶级索引条目匹配。
一种方法是将索引全部设为图像,但想知道是否有更简单的方法?如果这是唯一的解决方案,那么将文本设为图像的最佳方法是什么?
例如,在下面的索引中,搜索“字节”应该产生一个结果,而不是三个。
代码:
\documentclass{article}
\usepackage{imakeidx}
\usepackage{xparse}
\usepackage{siunitx}
\usepackage{xcolor}
\usepackage{hyperref}
\newcommand*\lettergroup[1]{\subsection{#1}}
\newcommand*{\IndexWithName}[2]{%
% #1 = word to index
% #2 = index name
\index[#2]{#1}%
}
\NewDocumentCommand{\FormatIndexEntry}{mm}{%
\textcolor{blue}{#1} #2%
}
%% Defer the binary units until AFTER \begin{document} as per
%% http://tex.stackexchange.com/questions/287579/how-to-overwrite-siunitxs-binary-prefixes
\sisetup{binary-units=true}
\AtBeginDocument{%
\DeclareSIUnit\bit{\textcolor{red}{bit}}%
}
\NewDocumentCommand{\AddIndexEntry}{%
O{}% #1 = index name
m% #2 = word to index this under
m% #3 = indexed term
m% #4 = symbol
}{%
\expandafter\IndexWithName\expandafter{%
#2!#3@\FormatIndexEntry{#3}{\unexpanded{\unexpanded{#4}}}%
}{#1}%
}
\newcommand{\indexopt}[2]{\index[#2]{#1}}
\makeindex[title={Main Index},columns=1,program=texindy]
\makeindex[title={Name Index},columns=1,program=texindy,name=Name]
\indexsetup{level=\section}
\begin{document}
\SI{1}{\bit}
\AddIndexEntry[Name]{byte}{bit}{symbol: \si{\bit}}
\AddIndexEntry[Name]{byte}{nibble}{}
\AddIndexEntry[Name]{bit}{byte}{}
\AddIndexEntry[Name]{bit}{nibble}{}
\AddIndexEntry[Name]{nibble}{bit}{}
\AddIndexEntry[Name]{nibble}{byte}{}
\clearpage
\setcounter{secnumdepth}{0}
\printindex[Name]
\end{document}