5

What I want is to disable \hypersetup{hidelinks}. I can use it inside group but this is not a good idea. Here is a MWE.

\documentclass{article}

\usepackage{hyperref}

\begin{document}
\tableofcontents
{\hypersetup{hidelinks} 
\section{bla}\label{aa}  link text and anchore are hidden \ref{bb}}

\section{bla}\label{bb} here back to defaut \ref{aa}

But what I want is

\hypersetup{hidelinks} 
\section{bla}\label{cc}  link text and anchore are hidden \ref{dd}

%some thing like 
%\hypersetup{hidelinks=off }  
\section{bla}\label{dd} here back to defaut \ref{cc}

\end{document}

1 Answer 1

5

Use at own risk:

\documentclass{article}

\usepackage[colorlinks]{hyperref}

\makeatletter
\newif\ifhidelinks@hidelinks
\newcommand{\hidelinks}{%
  \hidelinks@hidelinkstrue
  \let\hidelinks@ifHy@colorlinks@status\ifHy@colorlinks
  \let\hidelinks@ifHy@ocgcolorlinks@status\ifHy@ocgcolorlinks
  \let\hidelinks@ifHy@frenchlinks@status\ifHy@frenchlinks
  \let\hidelinks@Hy@colorlink\Hy@colorlink
  \let\hidelinks@Hy@endcolorlink\Hy@endcolorlink
  \let\hidelinks@@pdfborder\@pdfborder
  \let\hidelinks@@pdfborderstyle\@pdfborderstyle
  \hypersetup{hidelinks}%
}
\newcommand{\restorelinks}{%
  \ifhidelinks@hidelinks
    \hidelinks@hidelinksfalse
    \let\ifHy@colorlinks\hidelinks@ifHy@colorlinks@status
    \let\ifHy@ocgcolorlinks\hidelinks@ifHy@ocgcolorlinks@status
    \let\ifHy@frenchlinks\hidelinks@ifHy@frenchlinks@status
    \let\Hy@colorlink\hidelinks@Hy@colorlink
    \let\Hy@endcolorlink\hidelinks@Hy@endcolorlink
    \let\@pdfborder\hidelinks@@pdfborder
    \let\@pdfborderstyle\hidelinks@@pdfborderstyle
  \fi
}
\makeatother

\begin{document}
\tableofcontents

\hidelinks
\section{bla}\label{cc}  link text and anchore are hidden \ref{dd}

\restorelinks
\section{bla}\label{dd} here back to defaut \ref{cc}

\end{document}

I used colorlinks to better show the links. The \restorelinks reverts to the previous situation, provided a \hidelinks command has appeared before at the same grouping level, otherwise it does nothing.

enter image description here

1
  • not really this time, i don't want to risk ;-)
    – touhami
    Mar 28, 2016 at 8:43

You must log in to answer this question.

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