0

I would like to add bookmark into a dictionary style PDF, which is an output of LaTex document. I loaded the package hyperref with the optional argument bookmarks=true. But I still did not get the bookmark in the PDF output. The dictionary-style Tex code can be looked up in following:

\documentclass[twoside,10pt,twocolumn]{book}
\usepackage{lipsum}
\usepackage{adforn}
\usepackage[top=2.0cm, bottom=3.5cm, left=2cm, right=2cm]{geometry}%
\usepackage{fancyhdr}
\usepackage[french, english]{babel}%
\usepackage[utf8x,utf8]{inputenc}
\usepackage{color}
\definecolor{marron}{RGB}{60,30,10}
\definecolor{darkblue}{RGB}{0,0,80}
\definecolor{lightblue}{RGB}{80,80,80}
\definecolor{darkgreen}{RGB}{0,80,0}
\definecolor{darkgray}{RGB}{0,80,0}
\definecolor{darkred}{RGB}{80,0,0}
\definecolor{shadecolor}{rgb}{0.97,0.97,0.97}
\usepackage[T1]{fontenc}
\usepackage{hanging}
\usepackage{tikz}
\usetikzlibrary{calc}

%---------------------------------------------------------------------------------------------%
\usepackage{fourier-orns}
\newcommand{\ornpar}{\noindent \textcolor{darkgray}{ \raisebox{-1.9pt}       [10pt][10pt]{\leafright} \hrulefill \raisebox{-1.9pt}[10pt][10pt] {\leafright \decofourleft \decothreeleft  \aldineright \decotwo                    \floweroneleft \decoone}}}%

\newcommand{\ornimpar}{\textcolor{darkgray}{\raisebox{-1.9pt}[10pt][10pt]{\decoone \floweroneright \decotwo \aldineleft \decothreeright  \decofourright \leafleft} \hrulefill \raisebox{-1.9pt}[10pt][10pt]{\leafleft}}}%
%---------------------------------------------------------------------------------------------%


%---------------------------------------------------------------------------------------------%
\newcommand\entry[4][]{\hangpara{2em}{1}  {\fontfamily{phv}\selectfont{\textbf{{#2}}}}\ #4\ 
#3 \ifx\relax #1 \relax \markboth{#2}{#2}\else\markboth{#1}{#1}\fi
\vspace*{5pt}\par} \nopagebreak[4]%
\newcommand*{\dictchar}[1]{\centerline{\LARGE\textbf{#1}}\vspace*{10pt}\par}%
%---------------------------------------------------------------------------------------------%




%---------------------------------------------------------------------------------------------%
% use fancyhdr or whatever you want to add
% the boxes to the header to make them appear
% on every page

% new counter to hold the current number of the
% letter to determine the vertical position
\newcounter{letternum}
% newcounter for the sum of all letters to get
% the right height of a box
\newcounter{lettersum}
\setcounter{lettersum}{26}
% some margin settings
\newlength{\thumbtopmargin}
\setlength{\thumbtopmargin}{2.06cm}%1cm
\newlength{\thumbbottommargin}
\setlength{\thumbbottommargin}{3cm}
% calculate the box height by dividing the page height
\newlength{\thumbheight}
\pgfmathsetlength{\thumbheight}{%
(\paperheight-\thumbtopmargin-\thumbbottommargin)%
/%
\value{lettersum}
}
% box width
\newlength{\thumbwidth}
\setlength{\thumbwidth}{1.5cm}
% style the boxes
\tikzset{
thumb/.style={
fill=black!50!red,
text=white,
minimum height=\thumbheight,
text width=\thumbwidth,
outer sep=0pt,
font=\sffamily\bfseries,
}
}
\newcommand{\oddthumb}[1]{%
% see pgfmanual.pdf for more information about this part
\begin{tikzpicture}[remember picture, overlay]
    \node [thumb,text centered,anchor=north east,] at ($%
        (current page.north east)-%
        (0,\thumbtopmargin+\value{letternum}*\thumbheight)%
    $) {#1};                                              
\end{tikzpicture}                                          
}
\newcommand{\eventhumb}[1]{%
% see pgfmanual.pdf for more information about this part
\begin{tikzpicture}[remember picture, overlay]
    \node [thumb,text centered,anchor=north west,] at ($%
        (current page.north west)-%
        (0,\thumbtopmargin+\value{letternum}*\thumbheight)%
    $) {#1};
\end{tikzpicture}
}

% create a new command to set a new lettergroup
\newcommand{\lettergroup}[1]{%

\fancypagestyle{chapterstart}{%
\fancyhf{}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\chead{\oddthumb{#1}}% chapters start only on odd pages
\cfoot{\thepage}
}

%\renewcommand{\headrulewidth}{0pt}
%\fancyhead{}

\fancyhead[LO]{ \raisebox{1em}{ \fontfamily{phv}     \selectfont{\textbf{\rightmark}} } \oddthumb{#1}}%
\fancyhead[RE]{ \raisebox{1em}{ \fontfamily{phv}   \selectfont{\textbf{\leftmark}} } \eventhumb{#1}}


\fancyhead[LE]{{\fontfamily{phv}\selectfont{\textbf{\raisebox{1em}{\rightmark}}}}}


\fancyhead[CO,CE]{\color{darkgray} \raisebox{-2.1pt}[10pt][10pt]  {\leafright} \hrulefill \raisebox{-2.1pt}[10pt][10pt]{~~~\decofourleft \decotwo \decofourright~~~} \hrulefill \raisebox{-2.1pt}[10pt][10pt]{  \leafleft}}


\fancyhead[RO]{{\fontfamily{phv}\selectfont{\textbf{\raisebox{1em}{\leftmark}}}}}

 % step the counter of the letters
 \stepcounter{letternum}
 }
 %---------------------------------------------------------------------------------------------%







%---------------------------------------------------------------------------------------------%
\fancypagestyle{basicstyle}{%
\fancyhf{}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhead[LE,RO]{\textbf{\chaptitle}}
\fancyhead[LO,RE]{\textbf{\thepage}}
\fancyfoot[LE,RO]{\thepage}}



\fancypagestyle{dictstyle}{%
\fancyhf{}
\renewcommand{\headrulewidth}{0pt} 
\fancyhead{}

\fancyfoot[LO]{
\ornimpar \\ \hfill \textcolor{darkgray}{\large \leafNE ~~~   \raisebox{-0.35em}{\textsf{\textbf{\thepage}}} }  }

\fancyfoot[RE]{\ornpar   \\ \textcolor{darkgray}{\large  \raisebox{-0.35em}{\textsf{\textbf{\thepage}}} ~~~ \reflectbox{\leafNE}}  \hfill  }
}


\setlength{\columnsep}{20pt}
\setlength{\columnseprule}{0pt}
%---------------------------------------------------------------------------------------------%

\usepackage[bookmarks=true]{hyperref}







%\pagestyle{basicstyle}


%----------------------------------------------------------------------------------------------%

\begin{document}
%\maketitle
\begin{titlepage}
\centering\Huge   \adforn{26}\adforn{21}\quad\adforn{11}\quad\adforn{49}\adforn{54}

\vspace*{2em}\centering\bf  
\texttt{My Dictionary}\par

\vspace{2em}
{\hfill\centering \large{The Author}\hfill} 
\end{titlepage}

\newpage

%----------------------------------------------------------------------------------------------%


\pagestyle{dictstyle}%dictstyle
\lettergroup{A}
\dictchar{A}
% \hyperlink{A}{\dictchar{A}} 
\entry[headwords]{headwords}{translations}{\textsf{/yinfu/}}
\entry[headwords2]{headwords2}{translations2}{/yinfu/}
\entry[philosophy]{philosophy} {Lorem ipsum dolor sit amet,  consectetuer
adipiscing elit. Ut purus elit, vestibulum ut, \emph{plac- erat ac}}  {/yinfu/}
\entry[Math]{Math}{Lorem ipsum dolor sit amet}{/yinfu/}
\entry[Physics]{Physics}{\lipsum[1-2]}{/yinfu/}
\entry[Nature]{Nature}{\lipsum}{/yinfu/}
\clearpage


\lettergroup{B}
\dictchar{B}
\entry[headwords]{headwords}{translations}{/yinfu/}
\entry[headwords2]{headwords2}{translations2}{/yinfu/}
\clearpage

\lettergroup{C}
\dictchar{C}
\entry[headwords]{headwords}{translations}{/yinfu/}
\entry[headwords2]{headwords2}{translations2}{/yinfu/}
\clearpage
\end{document} 

Thanks for your suggestions in advance.

  • 2
    You should better make a smaller example and show it here instead of asking people to hunt down your code in some other place and then spent a lot time to dissect and shorten it. – Ulrike Fischer Jul 13 '17 at 12:38
  • @ Ulrike Fischer Thanks for your advice. I have updated the post. – GL_n Jul 13 '17 at 13:17
  • There is no chapter/section/etc... . Related Add PDF bookmark manually – Bobyandbob Jul 13 '17 at 13:25
  • 1
    You didn't try very much to reduce your code. Beside this: you will have to add them manually as you don't have heading commands. Load the bookmark package and check its documentation. – Ulrike Fischer Jul 13 '17 at 13:26
  • @ Bobyandbob That is exactly the confusion I encounter. There are no sections or chapters in the dictionary Tex, and I do not know how to mark a link anchor, which is equivalent to the usage of the command \section{}. – GL_n Jul 13 '17 at 16:41
1

I solve the question by myself, and display the adjusted code in following. It may be helpful to some beginner (at least like me). When I posted my question previously I did not know how to set up the link anchor partly. I solved this problem by using the commands \label{name} inside the letter group and \pdfbookmark[section]{A or B ...}{name} before the letter group. However, I do not know whether this method is standard or we have other better solutions. The MWE:

\documentclass[twoside,10pt,twocolumn]{book}
\usepackage{lipsum}
\usepackage{adforn}
\usepackage[top=2.0cm, bottom=3.5cm, left=2cm, right=2cm]{geometry}%
\usepackage{fancyhdr}
\usepackage[french, english]{babel}%
\usepackage[utf8x,utf8]{inputenc}
\usepackage{color}
\definecolor{marron}{RGB}{60,30,10}
\definecolor{darkblue}{RGB}{0,0,80}
\definecolor{lightblue}{RGB}{80,80,80}
\definecolor{darkgreen}{RGB}{0,80,0}
\definecolor{darkgray}{RGB}{0,80,0}
\definecolor{darkred}{RGB}{80,0,0}
\definecolor{shadecolor}{rgb}{0.97,0.97,0.97}
\usepackage[T1]{fontenc}
\usepackage{hanging}
\usepackage{tikz}
\usetikzlibrary{calc}

%---------------------------------------------------------------------------------------------%
\usepackage{fourier-orns}
\newcommand{\ornpar}{\noindent \textcolor{darkgray}{ \raisebox{-1.9pt}       [10pt][10pt]{\leafright} \hrulefill \raisebox{-1.9pt}[10pt][10pt] {\leafright \decofourleft \decothreeleft  \aldineright \decotwo                    \floweroneleft \decoone}}}%

\newcommand{\ornimpar}{\textcolor{darkgray}{\raisebox{-1.9pt}[10pt][10pt]{\decoone \floweroneright \decotwo \aldineleft \decothreeright  \decofourright \leafleft} \hrulefill \raisebox{-1.9pt}[10pt][10pt]{\leafleft}}}%
%---------------------------------------------------------------------------------------------%


%---------------------------------------------------------------------------------------------%
\newcommand\entry[4][]{\hangpara{2em}{1}  {\fontfamily{phv}\selectfont{\textbf{{#2}}}}\ #4\ 
#3 \ifx\relax #1 \relax \markboth{#2}{#2}\else\markboth{#1}{#1}\fi
\vspace*{5pt}\par} \nopagebreak[4]%
\newcommand*{\dictchar}[1]{\centerline{\LARGE\textbf{#1}}\vspace*{10pt}\par}%
%---------------------------------------------------------------------------------------------%




%---------------------------------------------------------------------------------------------%
% use fancyhdr or whatever you want to add
% the boxes to the header to make them appear
% on every page

% new counter to hold the current number of the
% letter to determine the vertical position
\newcounter{letternum}
% newcounter for the sum of all letters to get
% the right height of a box
\newcounter{lettersum}
\setcounter{lettersum}{26}
% some margin settings
\newlength{\thumbtopmargin}
\setlength{\thumbtopmargin}{2.06cm}%1cm
\newlength{\thumbbottommargin}
\setlength{\thumbbottommargin}{3cm}
% calculate the box height by dividing the page height
\newlength{\thumbheight}
\pgfmathsetlength{\thumbheight}{%
(\paperheight-\thumbtopmargin-\thumbbottommargin)%
/%
\value{lettersum}
}
% box width
\newlength{\thumbwidth}
\setlength{\thumbwidth}{1.5cm}
% style the boxes
\tikzset{
thumb/.style={
fill=black!50!red,
text=white,
minimum height=\thumbheight,
text width=\thumbwidth,
outer sep=0pt,
font=\sffamily\bfseries,
}
}
\newcommand{\oddthumb}[1]{%
% see pgfmanual.pdf for more information about this part
\begin{tikzpicture}[remember picture, overlay]
    \node [thumb,text centered,anchor=north east,] at ($%
        (current page.north east)-%
        (0,\thumbtopmargin+\value{letternum}*\thumbheight)%
    $) {#1};                                              
\end{tikzpicture}                                          
}
\newcommand{\eventhumb}[1]{%
% see pgfmanual.pdf for more information about this part
\begin{tikzpicture}[remember picture, overlay]
    \node [thumb,text centered,anchor=north west,] at ($%
        (current page.north west)-%
        (0,\thumbtopmargin+\value{letternum}*\thumbheight)%
    $) {#1};
\end{tikzpicture}
}

% create a new command to set a new lettergroup
\newcommand{\lettergroup}[1]{%

\fancypagestyle{chapterstart}{%
\fancyhf{}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\chead{\oddthumb{#1}}% chapters start only on odd pages
\cfoot{\thepage}
}

%\renewcommand{\headrulewidth}{0pt}
%\fancyhead{}

\fancyhead[LO]{ \raisebox{1em}{ \fontfamily{phv}     \selectfont{\textbf{\rightmark}} } \oddthumb{#1}}%
\fancyhead[RE]{ \raisebox{1em}{ \fontfamily{phv}   \selectfont{\textbf{\leftmark}} } \eventhumb{#1}}


\fancyhead[LE]{{\fontfamily{phv}\selectfont{\textbf{\raisebox{1em}{\rightmark}}}}}


\fancyhead[CO,CE]{\color{darkgray} \raisebox{-2.1pt}[10pt][10pt]  {\leafright} \hrulefill \raisebox{-2.1pt}[10pt][10pt]{~~~\decofourleft \decotwo \decofourright~~~} \hrulefill \raisebox{-2.1pt}[10pt][10pt]{  \leafleft}}


\fancyhead[RO]{{\fontfamily{phv}\selectfont{\textbf{\raisebox{1em}{\leftmark}}}}}

 % step the counter of the letters
 \stepcounter{letternum}
 }
 %---------------------------------------------------------------------------------------------%







%---------------------------------------------------------------------------------------------%
\fancypagestyle{basicstyle}{%
\fancyhf{}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhead[LE,RO]{\textbf{\chaptitle}}
\fancyhead[LO,RE]{\textbf{\thepage}}
\fancyfoot[LE,RO]{\thepage}}



\fancypagestyle{dictstyle}{%
\fancyhf{}
\renewcommand{\headrulewidth}{0pt} 
\fancyhead{}

\fancyfoot[LO]{
\ornimpar \\ \hfill \textcolor{darkgray}{\large \leafNE ~~~   \raisebox{-0.35em}{\textsf{\textbf{\thepage}}} }  }

\fancyfoot[RE]{\ornpar   \\ \textcolor{darkgray}{\large  \raisebox{-0.35em}{\textsf{\textbf{\thepage}}} ~~~ \reflectbox{\leafNE}}  \hfill  }
}


\setlength{\columnsep}{20pt}
\setlength{\columnseprule}{0pt}
%---------------------------------------------------------------------------------------------%

\usepackage[bookmarks=true]{hyperref}

\usepackage{bookmark}





%\pagestyle{basicstyle}


%----------------------------------------------------------------------------------------------%

\begin{document}
%\maketitle
\begin{titlepage}
\centering\Huge   \adforn{26}\adforn{21}\quad\adforn{11}\quad\adforn{49}\adforn{54}

\vspace*{2em}\centering\bf  
\texttt{My Dictionary}\par

\vspace{2em}
{\hfill\centering \large{The Author}\hfill} 
\end{titlepage}

\newpage

%----------------------------------------------------------------------------------------------%

\pdfbookmark[section]{A}{sec1}
\pagestyle{dictstyle}%dictstyle
\lettergroup{A}
\dictchar{A}
\label{sec1}
% \hyperlink{A}{\dictchar{A}} 
\entry[headwords]{headwords}{translations}{\textsf{/yinfu/}}
\entry[headwords2]{headwords2}{translations2}{/yinfu/}
\entry[philosophy]{philosophy} {Lorem ipsum dolor sit amet,  consectetuer
adipiscing elit. Ut purus elit, vestibulum ut, \emph{plac- erat ac}}  {/yinfu/}
\entry[Math]{Math}{Lorem ipsum dolor sit amet}{/yinfu/}
\entry[Physics]{Physics}{\lipsum[1-2]}{/yinfu/}
\entry[Nature]{Nature}{\lipsum}{/yinfu/}
\clearpage

\pdfbookmark[section]{B}{sec2}
\lettergroup{B}
\dictchar{B}
\label{sec2}
\entry[headwords]{headwords}{translations}{/yinfu/}
\entry[headwords2]{headwords2}{translations2}{/yinfu/}
\clearpage

\pdfbookmark[section]{C}{sec3}    
\lettergroup{C}
\dictchar{C}
\label{sec3}
\entry[headwords]{headwords}{translations}{/yinfu/}
\entry[headwords2]{headwords2}{translations2}{/yinfu/}
\clearpage
\end{document} 

The output of the Tex code above is as follows:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.