Hyperlink links in a Latex document start at the top of the page

I have a latex document. I use hyperref, makeidx and a glossary for my document.

Every thing is created beautifully; (all links work well), the glossary and index, except that the page numbers printed in the glossary and index are correct, but they indicate page numbers starting from the beginning of the document, where the initial 10 pages are in Arabic numbers, and then Roman numbers from 1 start.

eg. I have 10 pages for the initial starting question (abstraction, declaration, table of contents, etc. Etc.). After that, the mainmatter begins, as well as the page numbers in roman from 1. So, on this page 1, I have the index entry "hello"

Now in the index it prints “hello 1”, which is correct, except that when you click one of them 1 it goes to the right at the beginning of the document, and then it is numbered on page 1.

Your help would be greatly appreciated.

Thanks, Omer

+4
source share
6 answers

, googlefu (*) TeX Hyperref , , , hyperref :

  • plainpages=false
  • pdfpagelabels

, ( , ). :

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

.

, Wiki , , . ( " ".)

(*) , - , Google " hyperef frontmatter ", " hyperref frontmatter ". .

+4

, , . tex , .

\hyperpage, : .

Ad-hoc

, .

, 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
+1

, ,

\ frontmatter

\ mainmatter

\ backmatter

in the appropriate places?

note that this applies only to book and book classes, and not to article, letter, etc.

0
source

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})}
0
source

Just put the option hypertextnames=truein yours \usepackage{hyperref}, i.e. put something like

\usepackage[hypertexnames=true]{hyperref}

into your preamble.

0
source

Source: https://habr.com/ru/post/1718203/


All Articles