在宏中将顶级索引条目设为粗体

在宏中将顶级索引条目设为粗体

我创建了一个索引,其中一些条目有子条目:对于这些类型的条目,我创建了\ati宏,而对于没有子条目的条目,我使用另一个宏。

在那些由宏创建的条目中,\ati我希望顶级条目为粗体。我能够使用“Entry”来获得我想要的结果,而无需宏:

采用粗体格式的索引条目

但是我无法用宏实现同样的效果不改变参数数量。我希望这个宏只有两个参数,按此顺序,因为我在现有文档中使用它。

我认为实现此目的的方法是以某种方式处理第一个!参数中第一个感叹号 ( ) 之前和之后的文本,然后以某种方式将其合并到宏定义中,而不改变参数数量。但我不知道该怎么做。

(如果它对解决方案很重要,我会使用它texindy作为索引处理器。)

梅威瑟:

\documentclass{book}
\usepackage{blindtext}
\usepackage{splitidx}
\makeindex
\def \ati#1#2{#2\index{#1}} % "Add to index" macro
\begin{document}
\blindtext

There are many ways to write a document. You could use a \ati{Markup!LaTeX@\LaTeX}{\LaTeX}, \ati{Markup!Markdown}{Markdown} or even \ati{Markup!HTML}{HTML}. If you do write your document by hand, do not use \ati{Markup!XML}{XML}, because you are going to go mad.

\blindtext[5]

\ati{Markup!LaTeX@\LaTeX}{\LaTeX} is obviously the best to produce high-quality PDF file, but you do not have to type it by hand. You can use \ati{Markup!Markdown}{Markdown} instead and then convert it to both \ati{Markup!HTML}{HTML} and \ati{Markup!LaTeX@\LaTeX}{\LaTeX}, as well as many other formats.

Now comes interesting stuff. When you write a technical book in \ati{Markup!LaTeX@\LaTeX}{\LaTeX}, you can quite easily create an \sindex{Index creation}index. When you do, you have quite a few choices when it comes to packages you use and \ati{Index processor}{index processors} that will sort your .idx file into .ind file that gets included in your document at the time of next compilation.

\blindtext[6]

One of those index processors is \ati{Index processor!MakeIndex}{MakeIndex}, but there are also few other alternatives. I personally prefer to use \ati{Index processor!xindy}{xindy} through command line program called texindy.

\pagebreak

Now, I want to make each top-level entry like ``Index processor'' and ``Markup'' bold, only for those entries which do have sub-entries (this is what \\ati macro is for). It would be awesome if I could use same macro even for entries which do not have subentries and still get bold top-level entries only for those entries with subentries, but it is not must-have.

So what I want to produce looks like this:

\index{Entry@\textbf{Entry}}{entry}

\index{Entry@\textbf{Entry}!subentry}{subentry}
\index{Entry@\textbf{Entry}!subentry!subsubentry}{subentry}

\index{Entry@\textbf{Entry}!another entry}{another entry}

\index{Entry@\textbf{Entry}!another entry}{another entry}

\index{Entry@\textbf{Entry}!yet another entry}{yet another entry}

but I want to achieve it inside ``ati'' macro.

\printindex

\end{document}

这是可能吗?

相关内容