Latex 文档中的超级参考链接从页面开头开始

发布于 2024-08-05 03:55:39 字数 343 浏览 3 评论 0原文

我有一个乳胶文档。我在我的文档中使用 hyperref、makeidx 和词汇表包。

万物皆生精;目录(所有参考文献都很好)、术语表和索引,但术语表和索引中打印的页码是正确的,但它们指向从文档开头开始的页码,其中最初 10 页是阿拉伯数字,然后是罗马数字从1开始。

例如,我有 10 页的初始前言(摘要、声明、目录等)。之后,mainmatter 开始,罗马页码从 1 开始。因此,在第 1 页上,我有一个索引条目“hello”。

现在在索引中,它打印“hello 1”,这是正确的,除了当单击1,然后它会转到文档开头的右侧,而不是编号为第 1 页。我们

将非常感谢您的帮助。

谢谢, 奥马尔

I have a latex document. I am using hyperref, makeidx and glossary packages for my document.

Every thing is created fine; table of content (all references works nicely), glossary and index except that page numbers printed in the glossary and index are correct but they point to page numbers starting from the beginning of the document where initial 10 pages are in arabic numbers and then roman numbers from 1 starts.

e.g. I have 10 pages for initial front matter (abstract, declaration, table of contents etc etc). After that, mainmatter begins and so does the page numbers in roman from 1. So on this page 1, I have an index entry "hello"

Now in the index, it prints "hello 1" which is correct except that when one clicks on 1, then it goes to the right at the beginning of the document rather then numbered page 1.

Your help would be much appreciated.

Thanks,
Omer

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

樱花细雨 2024-08-12 03:55:39

好的,googlefu(*) 会生成标题为 Hyperref 和重复页码 的 TeX FAQ 条目,其中表示:是一个已知问题,建议将两个选项传递给 hyperref 包:

  • plainpages=false
  • pdfpagelabels

尽管它警告这些选项在 < em>每种情况(但我相信你的情况也会如此)。该应用程序看起来像:

\usepackage[plainpages=false,pdfpagelabels,pagebackref]{hyperref}

在您的序言中。

如果这篇 Wiki 文章失败,则提供了一个更笨拙的技巧,该技巧将在上述情况下起作用失败。 (向下滚动到“链接问题”部分。)

(*) 结果我发现这个东西是由于拼写错误,并向谷歌询问 "hyperef frontmatter" 而不是 "<代码>hyperref frontmatter"。有时候你只是运气好。

OK, googlefu(*) yields the TeX FAQ entry titled Hyperref and repeated page numbers where it says that this is a known problem, and suggests passing two options to the hyperref package:

  • plainpages=false
  • pdfpagelabels

though it warns that these will not work in every situation (but I believe it will in yours). The application would look something like:

\usepackage[plainpages=false,pdfpagelabels,pagebackref]{hyperref}

in your preamble.

Failing that this Wiki article provides an even clunkier trick which will work in places where the above fails. (Scroll down to the "Problems with Links" section.)

(*) Turns out I found this stuff due to a typo, and asked google for "hyperef frontmatter" rather than "hyperref frontmatter". Some days you just get lucky.

世界如花海般美丽 2024-08-12 03:55:39

好吧,这个问题很老了,但我遇到了同样的问题,必须找到解决方案。该解决方案涉及一些 tex hacking,并且不是通用的,但您应该能够使其适应您的特定情况。

问题

索引包使用 \hyperpage 宏生成链接,该宏只接受一个参数:它将打印该数字并链接到具有该绝对数字的页面。

临时解决方案

将前面的页数保存在宏中,然后将所有页面锚点移动相同的数字。

在实践中

这个解决方案很脆弱,因为如果您的书籍样式或hyperref包的代码发生变化,它将不再起作用。这对我来说仍然是一个可行的解决方案。
我修改了我的书籍风格中的 \frontmatter 宏:(

添加的新行是第 2 行和第 3 行,请注意,当计算发生在编号为“1”的新页面上时,我们需要减 1)

 \newcommand\mainmatter{\clearemptydoublepage
    \count0=\value{page}\advance\count0 by -1
    \xdef\pagesfrontmatter{\the\count0}
    \@mainmattertrue\pagenumbering{arabic}}

然后更棘手的部分来了。 \hyperpage 嵌入了大量代码,并且可以处理诸如“2,4”或“3-5”之类的参数,因此我们需要修改实际输出文本和超链接的结束宏。如果您查看 hyperref.sty,您会发现它名为 \HyInd@removespaces。我们需要仅针对索引重新定义它,以便每个链接具有相同的文本,但锚点移动正确的量(修改的行是那些包含对 \count0 的引用的行):

{ % open local group
% locally change how hyperpage creates hyperlinks to take
% frontmatter pages into account
\makeatletter
\def\HyInd@removespaces#1 #2\@nil{%
  \toks@=\expandafter{\the\toks@#1}%
  \ifx\\#2\\%
    \edef\x{\the\toks@}%
    \ifx\x\@empty
    \else
      \count0=\the\toks@\advance\count0 by \pagesfrontmatter%
      \hyperlink{page.\the\count0}{\the\toks@}%
    \fi
  \else
    \ltx@ReturnAfterFi{%
      \HyInd@removespaces#2\@nil
    }%
  \fi
}
\makeatother

\printindex
} % close local group

Ok this question is old, but I encountered the same problem and had to find a solution. The solution involves a bit of tex hacking and is not generic but you should be able to adapt it to your particular case.

The problem

The index package generates links using the \hyperpage macro, which takes only one argument: it will print this number and link to the page that has this absolute number.

Ad-hoc solution

Saving the number of pages in the front matter in a macro, then shifting all page anchors by that same number.

In practice

This solution is fragile since if the code of your book style or the hyperref packages changes, it will not work anymore. Still this is a working solution for me.
I modified the \frontmatter macro in my book style:

(New lines added are lines 2 and 3, note that we need to decrement by 1 as the computation occurs on the new page numbered '1')

 \newcommand\mainmatter{\clearemptydoublepage
    \count0=\value{page}\advance\count0 by -1
    \xdef\pagesfrontmatter{\the\count0}
    \@mainmattertrue\pagenumbering{arabic}}

Then comes a trickier part. The \hyperpage embeds a lot of code, and can handle for instance arguments like '2,4' or '3-5', so we need to modify the end macro that actually outputs the text and hyperlink. If you look at hyperref.sty, you will find it named \HyInd@removespaces. We need to redefine it only for the index so that each link has the same text but the anchor is shifted by the right amount (modified lines are those including references to \count0):

{ % open local group
% locally change how hyperpage creates hyperlinks to take
% frontmatter pages into account
\makeatletter
\def\HyInd@removespaces#1 #2\@nil{%
  \toks@=\expandafter{\the\toks@#1}%
  \ifx\\#2\\%
    \edef\x{\the\toks@}%
    \ifx\x\@empty
    \else
      \count0=\the\toks@\advance\count0 by \pagesfrontmatter%
      \hyperlink{page.\the\count0}{\the\toks@}%
    \fi
  \else
    \ltx@ReturnAfterFi{%
      \HyInd@removespaces#2\@nil
    }%
  \fi
}
\makeatother

\printindex
} % close local group
玻璃人 2024-08-12 03:55:39

我写了一篇关于此的博客文章不久前,解释了如何简单地将页面编号为 1...n,摆脱罗马数字。这解决了您的问题,并在 PDF 阅读器中实现了合理的页码编号。如果这是您想要的,请将以下代码放入您的序言中:

\let\oldsetcounter=\setcounter
\renewcommand\setcounter[2]{%
  \ifx\not{#1}{page}\oldsetcounter{#1}{#2}\fi}

I wrote a blog post about this a while ago, explaining how to simply number your pages 1...n, getting rid of the Roman numerals. This solves your problem, and makes for sensible page numbering within the PDF reader as well. If this is what you want, put the following code in your preamble:

\let\oldsetcounter=\setcounter
\renewcommand\setcounter[2]{%
  \ifx\not{#1}{page}\oldsetcounter{#1}{#2}\fi}
浮生面具三千个 2024-08-12 03:55:39

我不确定这是否有效,但是您是否尝试过

添加\frontmatter

\mainmatter

\backmatter

在适当的位置

?请注意,这仅适用于书籍和书籍。像书本一样的课程,而不是文章、信件等。

i am not sure if this will work at all, but have you tried adding

\frontmatter

\mainmatter

\backmatter

in the appropriate places?

note that this only applies to the book & book-like classes, not article, letter, etc.

很快妥协 2024-08-12 03:55:39

这是一个肮脏的伎俩,但它有效

\newcounter{glshyperpage}%
\def\glshyper#1#2{%
\setcounter{glshyperpage}{#2}%
\addtocounter{glshyperpage}{6}%number of front-matter pages
(\hyperlink{#1.\theglshyperpage}{#2})}

This is a dirty trick, but it works

\newcounter{glshyperpage}%
\def\glshyper#1#2{%
\setcounter{glshyperpage}{#2}%
\addtocounter{glshyperpage}{6}%number of front-matter pages
(\hyperlink{#1.\theglshyperpage}{#2})}
如梦亦如幻 2024-08-12 03:55:39

只需将选项 hypertextnames=true 放入您的 \usepackage{hyperref} 中,即

\usepackage[hypertexnames=true]{hyperref}

在序言中放入类似的内容。

Just put the option hypertextnames=true into your \usepackage{hyperref}, i.e. put something like

\usepackage[hypertexnames=true]{hyperref}

into your preamble.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文