6

I am hoping this is an easy question with a straightforward answer, but I have been poking around for a while now and I haven't seen any instructions for how to do this:

I just want to add clickable links for URLs, I don't want to generate internal links at all. I have just installed hyperref, and I was hoping there was some nice option called "urlonly" or something but I can't see it.

\documentclass{article}
\usepackage{hyperref}
\begin{document}
\tableofcontents
\section{This is a section, but I don't want a link in the toc}
I want this link to work. \href{http://news.bbc.co.uk}{BBC news}
\end{document}

Can anyone tell me how to do this?

5
  • 1
    Could you please add a minimum (working) example demonstrating your situation?
    – Malipivo
    Commented Apr 10, 2014 at 9:55
  • I don't think a MWE is relevant - it is a pretty general question relating to the standard behaviour of a package... but if anyone else asks for one, I will!
    – FionaSmith
    Commented Apr 10, 2014 at 10:30
  • 1
    Thanks @IanThompson for doing my work for me :) Sorry I was too lazy.
    – FionaSmith
    Commented Apr 10, 2014 at 10:33
  • If the link appearances are disturbing you, then you can use option hidelinks. Commented Apr 10, 2014 at 10:39
  • Thanks @HeikoOberdiek I was using that already, and I know I can switch off the bookmarks, but I think it is a little odd to have thousands of hidden links throughout a document - someone might click by accident and wonder what on earth happened when they zoom to another part of the document. Maybe I just need to embrace internal hyperlinks!
    – FionaSmith
    Commented Apr 10, 2014 at 10:46

2 Answers 2

5

I am enclosing my patch. I am partly executing the draft option as defined in the hyperref.sty file from the hyperref bundle with two key lines commented out.

%! *latex mal-hyperlinks.tex
\documentclass{article}
\pagestyle{empty}
\usepackage[colorlinks]{hyperref}
% Patch: draft option do all this:
\makeatletter
    \let\hyper@@anchor\@gobble
    \gdef\hyper@link#1#2#3{#3\Hy@xspace@end}%
    \def\hyper@anchorstart#1#2{#2\Hy@xspace@end}%
    \def\hyper@anchorend{\Hy@xspace@end}%
    \let\hyper@linkstart\@gobbletwo
    \def\hyper@linkend{\Hy@xspace@end}%
    % \def\hyper@linkurl#1#2{#1\Hy@xspace@end}%
    \def\hyper@linkfile#1#2#3{#1\Hy@xspace@end}%
    % \def\hyper@link@[#1]#2#3#4{#4\Hy@xspace@end}%
    \def\Acrobatmenu#1#2{\leavevmode#2\Hy@xspace@end}%
    \let\PDF@SetupDoc\@empty
    \let\PDF@FinishDoc\@empty
    \let\@fifthoffive\@secondoftwo
    \let\@secondoffive\@secondoftwo
    \let\ReadBookmarks\relax
    \let\WriteBookmarks\relax
    \Hy@WarningNoLine{Draft mode on}%
\makeatother
% End of patch...
\begin{document}
\tableofcontents
\section{This is a section, but I don't want a link in the toc}
\label{test}Cross-reference~\ref{test} on page~\pageref{test}. Cited book is~\cite{mybook}.\par
I want this link to work. \href{http://news.bbc.co.uk/}{BBC news}
\begin{thebibliography}{9}
\bibitem{mybook} A book about\ldots
\end{thebibliography}
\end{document}

mwe

2
  • Fantastic. Messy to have to include all that code, but fantastic! I guess I just have to persuade @HeikoOberdiek that this is an option that would be useful to more people than just me!
    – FionaSmith
    Commented Apr 10, 2014 at 11:55
  • While I wouldn't use it in anything I'm working on at the moment I should think it would be a valid option, worth including.
    – Chris H
    Commented Apr 10, 2014 at 12:47
0

A partial answer to my own question: I use cleveref and I only just noticed the part of the documentation that says to use the starred variants \cref*{}when combining with `hyperref if you don't want the references to generate links.

I doubt this would have helped solve my MWE though, as I am sure the table of contents works differently, but I thought it would potentially help others in my position to know that most of my internal linking issues could have been fixed with this answer!

You must log in to answer this question.

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