3

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.

enter image description here

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

References:

Code:

\documentclass{article}

\usepackage{xcolor}
\usepackage[colorlinks=false, pdfborderstyle={/S/U/W 1}, runbordercolor=red]{hyperref}

\begin{document}
\begingroup
    \hypersetup{draft}% <-- This has no effect.
    \textbf{Legend:} Want these two links to \emph{not} be clickable
    \begin{itemize}
        \item Web links are displayed as \href{http://www.google.com}{site name} and 
        \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 search engine: \href{http://www.google.com}{Google}

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}
5

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

\documentclass{article}

\usepackage{xcolor}
\usepackage[colorlinks=false, pdfborderstyle={/S/U/W 1}, runbordercolor=red]{hyperref}

\begin{document}
\begingroup
    \textbf{Legend:} Want these two links to \emph{not} be clickable
    \begin{itemize}
        \item Web links are displayed as {\hypersetup{linkbordercolor=cyan}\label{anchor1}\hyperref[anchor1]{site name}} and
        \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 search engine: \href{http://www.google.com}{Google}

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}

enter image description here

| improve this answer | |
2

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[colorlinks=false, pdfborderstyle={/S/U/W 1}, runbordercolor=red]{hyperref}

\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 Web links are displayed as \href{http://www.google.com}{site name} and 
        \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 search engine: \href{http://www.google.com}{Google}

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}
| improve this answer | |
  • 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. – Peter Grill Apr 4 '16 at 0:13
  • what do you want a box or underline? as i noticed I am not sure I can do it but I think the hard part is gone so i can give it a try. – touhami Apr 4 '16 at 5:20
  • 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. – Peter Grill Apr 4 '16 at 6:42
  • @PeterGrill Sorry but it's your fault pdfborderstyle={/S/U/W 1} means that you need underlined link not boxed. – touhami Apr 4 '16 at 19:04
  • Ok, it yields a box for me with TeXShop so I did not check that carefully. However, I still want the links and "non-link" to look the same independent of the PDF viewer. – Peter Grill Apr 4 '16 at 21:06

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.