# Format with Hyperref but Disable Links

How can I get hyperref to format the link, but not actually link to anything. For instance, in the Legend section in the MWE below I would prefer that clicking on the links not actually attempt to open anything. But, at the same time, I need hyperref to do formatting of the link so that it is consistent with the rest of the document.

Using \hypersetup{draft} does not seem to have any effect.

## Code:

\documentclass{article}

\usepackage{xcolor}

\begin{document}
\begingroup
\hypersetup{draft}% <-- This has no effect.
\textbf{Legend:} Want these two links to \emph{not} be clickable
\begin{itemize}
\item links to local pdf file are displayed as \href{run:foo.pdf}{PDF name}
\end{itemize}
\endgroup
\medskip

\textbf{Main Document}\par

A good place for news: \href{http://www.yahoo.com}{Yahoo}

Here is an important PDF file: \href{run:foo.pdf}{My PDF}
\end{document}


I think it would be difficult to avoid links completly but you could use internal links:

\documentclass{article}

\usepackage{xcolor}

\begin{document}
\begingroup
\textbf{Legend:} Want these two links to \emph{not} be clickable
\begin{itemize}
\item links to local pdf file are displayed as {\label{anchor2}\hyperref[anchor2]{PDF name}}
\end{itemize}
\endgroup
\medskip

\textbf{Main Document}\par

A good place for news: \href{http://www.yahoo.com}{Yahoo}

Here is an important PDF file: \href{run:foo.pdf}{My PDF}
\end{document}


Here is a solution.

The key point is \IfBeginWith command from xstring package

It was hard to find the correct syntax for underlining using \pdfliteral but thanks to this tricks

\documentclass{article}

\usepackage{xcolor}

\usepackage{xstring}
\newlength\mtlength

\begin{document}
\begingroup
\makeatletter
\renewcommand{\href}[2]{%
\settowidth{\mtlength}{#2}%
\def\mtl{\strip@pt\mtlength}%
\IfBeginWith{#1}{run}{%
\def\mtcolor{1 0 0 RG}}{%  red
\def\mtcolor{0 1 1 RG}}%   light blue ??!
\pdfliteral{q 1 w 1 J \mtcolor\space 0 -2 m \mtl\space -2 l S Q}#2}
\makeatother
\textbf{Legend:} Want these two links to \emph{not} be clickable
\begin{itemize}
\item links to local pdf file are displayed as \href{run:foo.pdf}{PDF name}
\end{itemize}
\endgroup
\medskip

\textbf{Main Document}\par

• Problem with this approach is the two are not always displayed the same way as the PDF viewer is the one that decides how to format the link. See no border around hyperlinks with hyperref. With your code I get this view. I think Ulrike Fischer's answer is probably going to be the way to go, unless the hyperref package provides such a feature. Apr 4, 2016 at 0:13
• If I had a choice I'd choose the box for the draft mode, and colored text for final mode. However, the choice is made by the PDF viewer, not TeX. So, I don't get to choose. The requirement is that the same formatting be applied to both the link and "non-link". As this formatting is controlled by the PDF viewer, Ulrike Fischer's is probably the best solution. Apr 4, 2016 at 6:42
• @PeterGrill Sorry but it's your fault pdfborderstyle={/S/U/W 1} means that you need underlined link not boxed. Apr 4, 2016 at 19:04