General\addcontentsline{toc} &behavior of TOC-links & PDF-bookmarks

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
neGODnick
Posts: 35
Joined: Mon Jun 16, 2008 9:31 pm

\addcontentsline{toc} &behavior of TOC-links & PDF-bookmarks

Post by neGODnick »

Hi!

I use hyperref package and known command to add unnumbered chapters into Table of Contents, for example:

Code: Select all

\chapter*{Введение} 
\addcontentsline{toc}{chapter}{Введение}
But clicking on their links in TOC or on the bookmarks opens the page on level below the chapter title, chapter title is unvisible. Normal chapters ("\chapter" without *) show the titles in the top of PDF-viewer window.

How to resolve this problem?
Last edited by neGODnick on Mon Jun 30, 2008 10:06 pm, edited 1 time in total.
Do not move your cursor near double underlined links — they are POPUP-ADs!!!
Избегайте попадания курсора на «ссылки» с двойным подчёркиванием — это ВСПЛЫВАЮЩАЯ РЕКЛАМА!!!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

chro
Posts: 1
Joined: Thu Jun 19, 2008 7:10 pm

\addcontentsline{toc} &behavior of TOC-links & PDF-bookmarks

Post by chro »

Hi,

I had the same problem;

Code: Select all

\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{Введение}
\chapter*{Введение}
worked for me.

(source: http://www.tex.ac.uk/cgi-bin/texfaq2htm ... =tocbibind )

regards, chris
neGODnick
Posts: 35
Joined: Mon Jun 16, 2008 9:31 pm

Re: \addcontentsline{toc} &behavior of TOC-links & PDF-bookmarks

Post by neGODnick »

Great!

This is exactly that I need! Now all toc-links and bookmarks open pages properly.

Thank you very, very much, Chris!
Do not move your cursor near double underlined links — they are POPUP-ADs!!!
Избегайте попадания курсора на «ссылки» с двойным подчёркиванием — это ВСПЛЫВАЮЩАЯ РЕКЛАМА!!!
gasatanig
Posts: 1
Joined: Thu Jun 26, 2008 2:43 pm

\addcontentsline{toc} &behavior of TOC-links & PDF-bookmarks

Post by gasatanig »

I love you!! :-P

I had a similar problem: I wanted to have entries plus links in my TOC, which should point in the middle of the text without any \subsection close to it.

I had the following combination in one of my userdefined commands:

Code: Select all

\pdfbookmark[2]{#1}{#1}
\addcontentsline{toc}{subsection}{\hyperlink{#1}{#1}}
resulting in dozens of errors of the form:

Code: Select all

"Undefined control sequence. \hyper@@link"
the trick with \phantomsection mentioned above did the job:

Code: Select all

\pdfbookmark[2]{#1}{#1}
\phantomsection
\addcontentsline{toc}{subsection}{#1}
works perfectly!

i think i just had to let the hyperref package do its job undisturbed!

Thanks a lot! gas
neGODnick
Posts: 35
Joined: Mon Jun 16, 2008 9:31 pm

\addcontentsline{toc} &behavior of TOC-links & PDF-bookmarks

Post by neGODnick »

Hello, people!

I'm sorry, but I have to reopen my question! The code from Chris works everywhere except the page of indexes. In LyX it goes as \printindex{}. Also the alternate code based on \pdfbookmark is not helpful:

Code: Select all

\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{Алфавитный указатель}
\printindex{}

Code: Select all

\cleardoublepage
\pdfbookmark[1]{Алфавитный указатель}{indexname}
\phantomsection
\printindex{}
Besides the \addtocontents{toc}{Алфавитный указатель} command if I try

Code: Select all

\cleardoublepage
\pdfbookmark[1]{Алфавитный указатель}{indexname}
\phantomsection
\addtocontents{toc}{Алфавитный указатель}
\printindex{}
gives an error messages like

Code: Select all

LaTeX Error: Something's wrong--perhaps a missing \item.
or

Code: Select all

I can't write on file `____________.pdf'. 
(note that I have closed the PDF-file compiled before, so it's not blocked with PDF-viewer). The "descriptions" of errors looks like

Code: Select all

...{\cyri }\IeC {\cyryu }}{231}{section*.26}
                                                  
Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.
Could anybody help me?
Do not move your cursor near double underlined links — they are POPUP-ADs!!!
Избегайте попадания курсора на «ссылки» с двойным подчёркиванием — это ВСПЛЫВАЮЩАЯ РЕКЛАМА!!!
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

\addcontentsline{toc} &behavior of TOC-links & PDF-bookmarks

Post by Juanjo »

Hi neGODnick,

The following code generates a pdf file where all links work as expected:

Code: Select all

\documentclass{book}

\usepackage{lipsum} % Just for getting some text
\usepackage{hyperref}

\usepackage{makeidx}
\makeindex

\begin{document}
\tableofcontents

\chapter{One}

Some text\index{text}.
\lipsum[1]

\chapter{Two}

More text\index{text}.
\lipsum[1]

\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{\indexname}
\printindex

\end{document}
So I don't guess what it may be wrong in your code. Please, provide a minimal working example, as the code above.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
neGODnick
Posts: 35
Joined: Mon Jun 16, 2008 9:31 pm

\addcontentsline{toc} &behavior of TOC-links & PDF-bookmarks

Post by neGODnick »

Hi, Juanjo!

Your minimal code (I have tried it) generates the PDF with the same problems as I described above (see also the 1st topic): clicking opens chapters at the level of it's titles, but the index page opens at the level of the text (list of entires) below the title "Index"; "Index" is hided under the top of PDF-viewer window.
Do not move your cursor near double underlined links — they are POPUP-ADs!!!
Избегайте попадания курсора на «ссылки» с двойным подчёркиванием — это ВСПЛЫВАЮЩАЯ РЕКЛАМА!!!
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

\addcontentsline{toc} &behavior of TOC-links & PDF-bookmarks

Post by Juanjo »

neGODnick wrote:Hi, Juanjo!

Your minimal code (I have tried it) generates the PDF with the same problems as I described above (see also the 1st topic): clicking opens chapters at the level of it's titles, but the index page opens at the level of the text (list of entires) below the title "Index"; "Index" is hided under the top of PDF-viewer window.
Yes, you're right. I had misunderstood the problem. Anyway, let's explore a different approach. In a recent thread, I provided a redefinition of theindex environment for the article class in order to write indexes with three or more columns. In the case of the book class, here is the code:

Code: Select all

\usepackage{multicol}
\makeatletter
\renewenvironment{theindex}
  {\if@twocolumn
      \@restonecolfalse
   \else
      \@restonecoltrue
   \fi
   \setlength{\columnseprule}{0pt}
   \setlength{\columnsep}{35pt}
   \begin{multicols}{3}[\chapter*{\indexname}]
   \markboth{\MakeUppercase\indexname}%
            {\MakeUppercase\indexname}%
   \thispagestyle{plain}
   \setlength{\parindent}{0pt}
   \setlength{\parskip}{0pt plus 0.3pt}
   \relax
   \let\item\@idxitem}%
  {\end{multicols}\if@restonecol\onecolumn\else\clearpage\fi}
\makeatother
Write begin{multicols}{2} for a classical index with two columns. If you add this code to my above minimal example, I think that things are now going on. Am I right?
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
neGODnick
Posts: 35
Joined: Mon Jun 16, 2008 9:31 pm

Re: \addcontentsline{toc} &behavior of TOC-links & PDF-bookmarks

Post by neGODnick »

Hi, Juanjo!

I'm sorry for my answer delay. Yes, you're right — this code works fine (and helpful for other reason)!

It is very interesting, what are the general principes, rules of links/bookmark behavior? What are the dependences? What exactly in your code have an influence on the condition? So, and how to resolve such problem in future?
Do not move your cursor near double underlined links — they are POPUP-ADs!!!
Избегайте попадания курсора на «ссылки» с двойным подчёркиванием — это ВСПЛЫВАЮЩАЯ РЕКЛАМА!!!
Post Reply