1

enter image description hereI have been reading about hyperlinks and tried this in my tex file:

\documentclass[a4paper,12pt]{book}
\usepackage{epsfig,amsmath,amssymb,float,tabls}
\usepackage{pstricks,pst-node}
\usepackage{caption}
\usepackage{graphicx,latexcad}
\usepackage{multicol}
\setcounter{tocdepth}{3}
\makeatletter \@addtoreset{equation}{chapter} \makeatother
\renewcommand{\theequation}{\thechapter.\arabic{equation}}
\thispagestyle{empty}
\usepackage[bookmarks=true,ps2pdf]{hyperref}
\begin{document}

\tableofcontents

\end{document}

My aim is to be able to go to the Table of Contents in the generated PDF file, click on the chapter number say 11.4 and hopefully the file will bring me straight to the page of chapter 11.4. Similarly, if I click on a reference, for example, [5], it will bring me to bibliography section with reference number 5.

Currently, when I click on the relevant section in Table of Contents of the PDF, it will not take me anywhere!

Can I ask what else needs to be done to make this work?


 \documentclass[a4paper,12pt]{book}
 \usepackage{epsfig,amsmath,amssymb,float,tabls}
 \usepackage{pstricks,pst-node}
 \usepackage{caption}
 \usepackage{graphicx,latexcad}
 \usepackage{multicol}
 \usepackage{lipsum}
 \newfont{\vecfont}{ptmb at 12pt}
 \renewcommand{\vec}[1]{\mbox{\vecfont #1}}
 \newcommand{\va}[1]{\mbox{\vecfont #1}}
 \newcommand{\ovec}[1]{\mbox{$\stackrel{\longrightarrow}{#1}$}}
 \setcounter{tocdepth}{3}
 \newfont{\chris}{cmfi10 at 10pt}

 \setlength{\textwidth}{160mm} \setlength{\textheight}{245mm}

 \setlength{\topmargin}{-8mm} \setlength{\oddsidemargin}{4mm}
 \setlength{\evensidemargin}{-5mm} \setlength{\parindent}{0mm}
 \setlength{\parskip}{2ex} \setlength{\arraycolsep}{1.6mm}
 \setlength{\unitlength}{1mm}

 \thispagestyle{empty}
 \newtheorem{rul}{Rule}[section]
 \newtheorem{fact}{Fact}[section]
 \newtheorem{propt}{Property}[section]
 \newtheorem{thm}{Theorem}[section]
 \newtheorem{defn}{Definition}[section]
 \newtheorem{ex}{Example}[section]
 \newcommand{\blackbox}{\mbox{}\\
                \hspace*{\fill} \rule{3mm}{3mm}}
\newcommand{\RR}{\mathbf{R}}
\newcommand{\dst}{\displaystyle}
\newcommand{\vspa}{\vspace{1ex}}
\newcommand{\vvspa}{\vspace{3ex}}
\newcommand{\hspa}{\hspace{2mm}}
\newcommand{\hhspa}{\hspace{4mm}}
\newcommand{\ds}{\displaystyle}
\newcommand{\vt}{\mathbf}
\newcommand{\ddm}[3]{\frac{\partial^2 #1}{\partial #2 \partial
 #3}}
\newcommand{\dd}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\ddp}[2]{\frac{\partial^2 #1}{\partial #2^2}}

\newcommand{\soln}{{\bf Solution:}}
\newenvironment{pro1}%
          {{\bf Proof 1:}}%
                 {\blackbox}%
\newenvironment{pro2}%
          {{\bf Proof 2:}}%
                 {\blackbox}%
\newenvironment{pro}%
          {{\bf Proof:}}%
                 {\blackbox}%
\newcommand{\dn}[2]{\frac{d #1}{d #2}}
\newcommand{\ddn}[2]{\frac{d^{2} #1}{d #2^{2}}}
\newcommand{\dddn}[2]{\frac{d^{3} #1}{d #2^{3}}}
\newcommand{\cosec}{\mbox{cosec}}
\newcommand{\cosech}{\mbox{cosech}}
\newcommand{\sech}{\mbox{sech}}
\newcommand{\arcsinh}{\mbox{arcsinh}}
\newcommand{\arccosh}{\mbox{arccosh}}
\newcommand{\arctanh}{\mbox{arctanh}}
\newcommand{\dint}{\displaystyle\int}
\renewcommand{\exp}[1]{e^{#1}}
\renewcommand{\deg}{\mbox{$^\circ\,$}}
\newcommand{\longvec}[1]{\stackrel{\longrightarrow}{#1}}

\newtheorem{workex}{Worked Example}[section]
\newtheorem{example}{Example}[section]
\newcommand{\fd}{\frac}
\renewcommand{\deg}{\mbox{$^\circ\,$}}
\newcommand{\cis}{\mbox{$\,\mbox{cis}\,$}}%
\newcommand{\mph}[1]{\mbox{\phantom{#1}}}
\newcommand{\pos}{\mph{$-$}}

\newcommand{\pivotcircle}{$\begin{picture}(2,2)
\put(-1.5,1){\circle{7}}\end{picture}$}

\newcommand{\bigpivotcircle}{$\begin{picture}(2,2)
\put(-2.5,1){\circle{9}}\end{picture}$}


\newcommand{\pivot}[2]{\begin{picture}(2,2)
\put(1,1){\makebox(0,0){$#1$}}
\put(1,1){\circle{#2}}\end{picture}}

%
%                     TO NUMBER EQUATIONS BY CHAPTER
%
\makeatletter \@addtoreset{equation}{chapter} \makeatother
\renewcommand{\theequation}{\thechapter.\arabic{equation}}

\thispagestyle{empty}



\usepackage[bookmarks=true,colorlinks=true,linkcolor=blue,citecolor=red]{hyperref}
\begin{document}

\tableofcontents

\newpage

\setcounter{page}{1}
\renewcommand{\thepage}{\arabic{page}}







\pagestyle{myheadings} \markboth{\hfill {Preliminaries}
 }{{Preliminaries} \hfill}
\addcontentsline{toc}{chapter}{Unit 0. Preliminaries}
\setcounter{chapter}{0} \setcounter{section}{0}
\setcounter{equation}{0} \thispagestyle{empty}

 \font\bignumber=cmti10 at 90pt \font\bigletter=cmr12 at 26pt

\parbox[b]{20mm}{\bf \bigletter Unit \\
\vspace{10mm}\null } \hspace{-4mm} {\bignumber 0} \hfill
\begin{minipage}[b]{120mm} {\Huge \bf  \hfill Preliminaries}
\end{minipage}

 \rule[3mm]{\textwidth}{0.5mm}

 \vspace*{-0.5cm}


 \section{Start}
   Hello


\newpage 

\section{Next}
123

\newpage

\mbox{ }

\section{One more}

\newpage
\subsection{Subs}

 \newpage


  \pagestyle{myheadings} \markboth{\hfill {\chris Vectors} }{{\chris
 Vectors} \hfill} \addcontentsline{toc}{chapter}{Unit 1. Vectors}
 \setcounter{chapter}{1} \setcounter{section}{0}
 \setcounter{equation}{0} \thispagestyle{empty}

 \font\bignumber=cmti10 at 90pt \font\bigletter=cmr12 at 26pt

 \parbox[b]{20mm}{\bf \bigletter Unit \\
 \vspace{10mm}\null } \hspace{-4mm} {\bignumber 1} \hfill
  \begin{minipage}[b]{105mm} {\Huge \bf  \hfill Vectors}
  \end{minipage}

  \rule[3mm]{\textwidth}{0.5mm}



 \section{New chapter}
  Issues?

  \newpage

  \section{Another}

  More?

 \newpage

  \mbox{ }

  \newpage

  \mbox{ }




       \end{document}
9
  • Welcome to TeX.SE. It is best if you compose a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. Furthermore that would ensure that the solution actually works for your particular case. Commented Oct 28, 2014 at 1:50
  • Please edit the question and add the MWE there. Commented Oct 28, 2014 at 2:59
  • @PeterGrill...It still won't work....After LaTeX-ing, I click on dvi->ps then ps->pdf on WinEdt to generate the PDF file.
    – Kris
    Commented Oct 28, 2014 at 4:36
  • Did you try the workarounds at PDF Bookmarks appear correctly but don't link anywhere. Commented Oct 30, 2014 at 6:16
  • @PeterGrill, thanks for the reply. It works now when I installed the new version of Ghostscript. However, another problem arises. When I clicked on Chapter 2, instead of going to Chapter 2, it goes to one page earlier, then when I clicked on Chapter 3, it goes to 2 pages before Chapter 3, and so on. Has that got to do with me putting \newpage \mbox{ } \newpage \mbox{ } at the end of each chapter to create blank pages or ...?? There is one more question which I needed to show pictorially. Is there anyway of uploading a pdf file here to show you?
    – Kris
    Commented Nov 7, 2014 at 2:55

2 Answers 2

1

You need to include \tableofcontents and run the file twice to obtain click able links in the TOC:

enter image description here

Clicking on the text in red takes you to the appropriate chapter.

Notes:

Code:

\documentclass[a4paper,12pt]{book} 
\usepackage{epsfig,amsmath,amssymb,float,tabls} 
\usepackage{pstricks,pst-node} 
\usepackage{caption} 
\usepackage{graphicx} 
%\usepackage{latexcad} 
\usepackage{multicol} 
\usepackage{lipsum}

\setcounter{tocdepth}{3} 
\thispagestyle{empty} 

\makeatletter 
\@addtoreset{equation}{chapter} 
\makeatother \renewcommand{\theequation}{\thechapter.\arabic{equation}} 
\usepackage[bookmarks=true]{hyperref} 

\begin{document} 
\tableofcontents
\chapter{First Chapter}
\lipsum[1-12]
\chapter{Second Chapter}
\lipsum[1-12]
\chapter{Third Chapter}
\lipsum[1-12]
\end{document}
1

There are lots of issues, the answer only covers quite a few of them:

Duplicate code

TeX is a macro language, thus it is easy to define a macro, e.g. for the chapter/unit starts:

\newcommand*{\myunit}[1]{...}

and using it, e.g.:

\myunit{Preliminaries}
...
\myunit{Vectors}
...

The chapter number can be handled automically, see below.

Anchors, labels for chapters

The bookmark is created via \addcontentsline, which uses the latest anchor setting, that might be occur some pages before. \phantomsection sets an anchor and \refstepcounter does. Since chapter numbers are usually incremented in a regular way, I would just use \refstepcounter{chapter} with an initial value of the counter of -1 to start the unit with 0. Then also \label and \ref will work, e.g.:

\setcounter{chapter}{-1}

\newcommand*{\myunit}[1]{%
  \cleardoublepage % or \clearpage
  \refstepcounter{chapter}% \label and anchor setting
  \addcontentsline{toc}{chapter}{Unit \thechapter. #1}%
  ...
}

Font commands

The use of \bf is deprecated, it is only kept for compatibility with old LaTeX 2.09 documents. Instead \bfseries or \textbf{...} can be used.

Usually there is no need to use the low level \font command. For example, the font size can be changed with \fontsize{<size>}{<baselineskip>}\selectfont, see LaTeX2e font selection.

Bookmarks

I recommend using package bookmark after hyperref. Bookmarks are faster updated, ...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .