简体   繁体   English

在以\\ newcommand为别名的LaTeX \\ indexentry中包含哈希标记

[英]Inclusion of hash marks in a LaTeX \indexentry aliased with a \newcommand

This is a strange one. 这是一个奇怪的。 I've had to do some interesting workarounds to get it to function even a little bit, but we have another stumbling block. 我不得不做一些有趣的变通办法才能使它正常工作,但是我们还有另一个绊脚石。

I've been struggling to create a separate document which employs a large .ind file (index created using makeindex from catenated, small individual .idx files), the idea being that I will eventually have a single document which indicates the SUB-documents and page numbers where the indexed data occurs. 我一直在努力创建一个单独的文档,该文档使用一个大的.ind文件(使用makeedindex从连接的,小的单个.idx文件中创建的索引),我的想法是最终将只有一个文档来指示SUB文档和索引数据所在的页码。

To this end, I've had to define a command which collects all index entries as: 为此,我必须定义一个命令来收集所有索引条目,如下所示:

\newcommand{\myindexer}[3]
    {\index{myindex}{#1 : #2.#3!\href{\doctitle.pdf}}}

The result is index entries in the myindex.idx file as: 结果是myindex.idx文件中的索引条目为:

\indexentry{IndexedItemA : 55.iii!\href{Volume 1.pdf}{Volume 1.pdf}}{30}}
\indexentry{IndexedItemB : 23.vi!\href{Volume 3.pdf}{Volume 3.pdf}}{114}}

Yet, the problem exists in trying to create a hyperref to the target PDF. 但是,问题在于尝试创建对目标PDF的超级引用。 In order to open a PDF at a specific page, the following format needs to be employed (thanks to someone else on this board for pointing out the #page.xx syntax in the hyperref package): 为了在特定页面上打开PDF,需要采用以下格式(感谢此板上的其他人指出了hyperref软件包中的#page.xx语法):

\href{FILENAME#page.XX}{Link Text}

wihch means that a hash mark needs to be included in the output stream of the \\newcommand when myindex is declared, possibly using an escaped hash mark # as: wihch表示在声明myindex时,\\ new命令的输出流中需要包含一个哈希标记,可能使用转义的哈希标记#作为:

\newcommand{\myindexer}[3]
    {\index{myindex}{#1 : #2.#3!\href{\doctitle.pdf\#page.\thepage}}}

or according to some fragment I found somewhere using a double-hash mark as: 或根据我在某个地方使用双哈希标记的某些片段作为:

\newcommand{\myindexer}[3]
    {\index{myindex}{#1 : #2.#3!\href{\doctitle.pdf##page.\thepage}}}

The former results in the following error during compilation of the latex source for the multiple documents being indexed: 前者在为多个要索引的文档的乳胶源的编译过程中导致以下错误:

! Illegal parameter number in definition of \@gtempa.
<to be read again>
                   \thepage
l.31 \myindex{IndexedItemA}{55}{iii}

While the latter results in an unwanted backslash in the resulting myindex.idx file as: 虽然后者在生成的myindex.idx文件中导致不必要的反斜杠,如下所示:

\indexentry{IndexedItemA : 55.iii!\href  {Volume 1.pdf\#page.33}{Volume 1}}{33}

which results in the target PDF not opening correctly. 这会导致目标PDF无法正确打开。

Any idea how the newcommand can be forced to output the hash mark to support hyperlinking of PDFs in this way? 知道如何以这种方式强制newcommand输出哈希标记以支持PDF的超链接吗?

\\href包裹在\\protect呢?

You can swap the catcode of # and %: 您可以交换catcode的#和%:

\catcode`\%=6 \catcode`\#=12

Then use % to mark parameters: 然后使用%标记参数:

\newcommand{\myindexer}[3]
    {\index{myindex}{%1 : %2.%3!\href{\doctitle.pdf#page.\thepage}}}

After that, restore the usual catcodes: 之后,恢复通常的目录代码:

\catcode`\%=12 \catcode`\#=6

This is kind of clumsy, but it should work even if something interferes with usual escaping mechanisms, and it allows \\href to be exanded at the point \\myindexer is used. 这有点笨拙,但是即使某些东西干扰了通常的转义机制,它也应该起作用,并且允许在使用\\myindexer时扩展\\href

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM