[Tex/LaTex] Representing hyperlinks differently in a single pdf file

hyperreflinkslyx

Can someone tell me how to color/represent (only internal) hyperlinks in a pdf differently (preferably just by using LyX,i.e. without diving deeper into pure latex) ? For example I would like the links from the table of contents to the separate sections my pdf to be put in a blue box, but all the other links (links to formulas or footnotes) to be green-coloured text.

My problem is, if I set a color and a "style"(in a box/text-colored) all links are like that and I see no way of differentiating between them.

My version of LyX is 2.

Best Answer

I don’t know Lyx, so I can only show you a pure LaTeX solution:
You can use \hypersetup several times:

\documentclass{article}
\usepackage[latin,english]{babel} % needed for "blindtext",
                                  % "english" is the active language
\usepackage{blindtext,lipsum,kantlipsum}

\usepackage[%
  colorlinks=true,% 
  linkcolor=red,%
  linktoc=all,%
]{hyperref}

\begin{document}

\tableofcontents

\newpage

\hypersetup{%
  linkcolor=blue,%
}

\section{Package \texttt{blindtext}}

\subsection{English blindtext}\label{btext-en}
See also package \hyperref[klipsum]{\ttfamily kantlipsum}.
\medskip

\blindtext[1]

\subsection{Latin blindtext}\label{btext-la}
Compare package \hyperref[lipsum]{\ttfamily lipsum}.
\medskip

{\selectlanguage{latin}% note the grouping
\blindtext[1]}

\newpage

\hypersetup{%
  linkcolor=green,%
}

\section{Package \texttt{kantlipsum}}\label{klipsum}
See also package \hyperref[btext-en]{\texttt{blindtext} with English text}.
\medskip

\kant[1]

\section{Package \texttt{lipsum}}\label{lipsum}
Compare package \hyperref[btext-la]{\texttt{blindtext} with pseudo-Latin text}.
\medskip

{\selectlanguage{latin}% actually not needed here
\lipsum[1]}% note the grouping again

\end{document}

First I’ve defined red link colour inside the hyperref package options (the two others are for better recognizability). This could have been done in a first separate \hypersetup, too.

After the table of contents I’ve put one \hypersetup for blue link colour, and later I set another one, just to show you the opportunity.