3

I don't want the readers jumping on text by mistakenly clicking on author names or figure/table numbers. So I want to disable hyperref but still keep the bookmark sidebar in the pdf file. Bookmarks are kind of like toc and help the reader jump on references or appendices whenever they want.

So I want a combination of "nohyperref" and "bookmarks=true", but i don't know how to get it done.

Thanks.

\documentclass[a4paper, 12pt]{article}
\usepackage{lscape}
\usepackage[margin=1in]{geometry}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\definecolor{light-gray}{gray}{0.8}
\usepackage{soul} 
\sethlcolor{light-gray}
\usepackage{tipa}
\usepackage{lipsum}
\usepackage{caption}
\usepackage{color}
\usepackage{afterpage}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{amsfonts}
\usepackage{amscd}
\usepackage{longtable}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{eucal}
\usepackage{hhline}
\usepackage{natbib}
\usepackage{setspace}
\usepackage{mathpazo}
\usepackage{calc}
\usepackage{booktabs}
\usepackage{mathtools}
\usepackage{eurosym}
\usepackage{stmaryrd}
\usepackage{float}
\usepackage{rotating}
\usepackage{pdflscape}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{positioning}
\usepackage{dcolumn}
\usetikzlibrary{shadows,shadings,shapes,decorations.pathreplacing}
\usepackage{times}
\usetikzlibrary{shapes.geometric}
\usepackage[nokeyprefix]{refstyle}
\usepackage{varioref}
\usepackage{xr-hyper}
\usepackage[bookmarks=true]{hyperref}
\usepackage{filecontents}
\begin{filecontents*}{References.bib}
@article{cite1,
title={Nothing special},
author={Nobody, Noboditch},
year={1988}
}
\end{filecontents*}

\begin{document}


\section{Introduction}
 \onehalfspacing
 \citep[see, e.g.,][]{cite1}


\section*{}
\addcontentsline{toc}{section}{References}

\bibliographystyle{agsm}
\bibliography{References}

\end{document}

So I want the links to citations be disabled but "introduction" and "References" to appear in bookmarks.

koleygr
  • 20,105
D_B
  • 389
  • 2
    @Sebastiano there is a bookmark package... You already have +1 from me... but with this package I think your answer will fit his expectations – koleygr Sep 16 '18 at 21:05
  • @D_B Into your code you have \usepackage{amsmath} and \usepackage{mathtools}. The last package is strong and contains \usepackage{amsmath}. See this link https://tex.stackexchange.com/questions/43860/mathtools-vs-amsmath – Sebastiano Sep 16 '18 at 21:12
  • 2
    Your long list of packages seems quite likely copied from some friend's template; don't do like this, use only the packages you really need. For instance, it's very dubious to load both mathpazo (for Palatino in text and math) and times (for Times New Roman in text): you end up with Times for text and Palatino for math, a very awkward combination. – egreg Sep 16 '18 at 21:18
  • 1
    You might use the hidelinks option. – egreg Sep 16 '18 at 21:23
  • 1
    hidelinks hides only the blue borders but doesn't disable the links. – D_B Sep 16 '18 at 21:24
  • @Sebastiano... A downvote to an answer of an unclear question is something we have to avoid... Thus my upvote was to show this fact and to wait from you to edit after the MWE. – koleygr Sep 16 '18 at 21:36
  • @koleygr You're right. Never I have thought for the points in this community. And believe me with all my heart, I don't want to fight with anyone. As soon as I write something that someone doesn't like slightly, after a few minutes the downvote arrives. I don't care about anything, but I had nothing in my hands. – Sebastiano Sep 16 '18 at 21:40
  • @D_B What's the reason for disabling the links? I mean, you want the bookmarks which are links. – egreg Sep 16 '18 at 21:56
  • Bookmarks are showed on the sidebar. Links are within the text. I don't ant the latter. @egreg – D_B Sep 16 '18 at 21:57
  • @D_B my code in the deleted answer had sidebar (click-able that was going to the section) but not clickable in-text references (i tested on linux). But if draft removed figures then it was not ok for you and deleted – koleygr Sep 16 '18 at 22:10
  • @koleygr bookmarks sidebar doesn't show up in the pdf! – D_B Sep 16 '18 at 22:26
  • Please download the pdf from here and check it: https://v2.overleaf.com/read/nzrmtkzxtbkf. If you have problem with sidebar ("outline" in evince viewer for me) is probably your viewer problem. You have to turn on the option or something. Check other documents too – koleygr Sep 16 '18 at 22:28
  • @koleygr I downloaded your version and tried both adobe reader and professional. It doesn't show side bar in my pc. – D_B Sep 16 '18 at 22:34
  • @D_B, did you tried with other document that you know it shows sidebar? May be sidebar is not the same that I mean. I mean a bar (for me in the left) that shows the sections and you can navigate inside them by clicking on the names of the sections – koleygr Sep 16 '18 at 22:38
  • Yes, I meant the same sidebar. This is strange! – D_B Sep 16 '18 at 22:45
  • @D_B I am deleting my answer since you are rigth. The bookmarks shows on my viewer but aren't clickable and thus your clever viewer is hiding tthem. I think we have to delete some comments here to let people help you easier without seeing all these comments. When agree just comment here. – koleygr Sep 16 '18 at 23:09
  • Please check last edit and tell me to delete some unuseful comments from here. – koleygr Sep 16 '18 at 23:48

2 Answers2

4

There is no in-built option to disable the links apart from the draft option. But these also disables the anchors and so bookmarks no longer have a target.

You could try to execute only a part of the commands used by the draft option. Be aware that while it works in the minimal example it could be that in larger documents you get errors because of some side-effect - hyperref is a rather complicated beast.

\documentclass{article}

\usepackage{bookmark}%loads hyperref
\makeatletter
\gdef\hyper@link#1#2#3{#3\Hy@xspace@end}
\gdef\hyper@link#1#2#3{#3\Hy@xspace@end}%
\let\hyper@linkstart\@gobbletwo
\def\hyper@linkend{\Hy@xspace@end}%
%\def\hyper@linkurl#1#2{#1\Hy@xspace@end}   % url optional
%\def\hyper@linkfile#1#2#3{#1\Hy@xspace@end}%files optional
\def\hyper@link@[#1]#2#3#4{#4\Hy@xspace@end}%
\let\@fifthoffive\@secondoftwo  %unclear if needed
\let\@secondoffive\@secondoftwo %unclear if needed
\makeatother
\begin{document}
\tableofcontents
\section{First section}
\ref{test} is on page \pageref{test}

\url{https://tex.stackexchange.com/}
\newpage
\section{Second section}\label{test}

\end{document} 

enter image description here

Ulrike Fischer
  • 327,261
  • For some reason \let\@secondoffive\@secondoftwo messed up my page number. Without it worked nicely. – Daniel May 06 '19 at 10:44
2

Last Edit: We create bookmarks manually and using the previous methods. On my linux (okular and evince) bookmarks are in the sidebar and active, and all links in the document are inactive.

\documentclass[a4paper, 12pt]{article}
\usepackage{lscape}
\usepackage[margin=1in]{geometry}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\definecolor{light-gray}{gray}{0.8}
\usepackage{soul} 
\sethlcolor{light-gray}
\usepackage{tipa}
\usepackage{lipsum}
\usepackage{caption}
\usepackage{color}
\usepackage{afterpage}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{amsfonts}
\usepackage{amscd}
\usepackage{longtable}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{eucal}
\usepackage{hhline}
\usepackage{natbib}
\usepackage{setspace}
\usepackage{mathpazo}
\usepackage{calc}
\usepackage{booktabs}
\usepackage{mathtools}
\usepackage{eurosym}
\usepackage{stmaryrd}
\usepackage{float}
\usepackage{rotating}
\usepackage{pdflscape}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{positioning}
\usepackage{dcolumn}
\usetikzlibrary{shadows,shadings,shapes,decorations.pathreplacing}
\usepackage{times}
\usetikzlibrary{shapes.geometric}
\usepackage[nokeyprefix]{refstyle}
\usepackage{varioref}
\usepackage{xr}

\usepackage[depth=-1]{bookmark}

\hypersetup{draft}
\PassOptionsToPackage{draft}{bookmark}

\usepackage{filecontents}
\begin{filecontents*}{References.bib}
@article{cite1,
title={Nothing special},
author={Nobody, Noboditch},
year={1988}
}
\end{filecontents*}


\begin{document}

\section{Introduction}\bookmark[page=\thepage,level=0]{Introduction}

 \onehalfspacing
 \citep[see, e.g.,][]{cite1}
 This is a reference \ref{sec:test}
\lipsum[1-5]

\section{Test}\label{sec:test}\bookmark[page=\thepage,level=0]{Test}
\lipsum[1-5]
\includegraphics[width=\textwidth]{example-image-a}
\subsection{Test subsection}\bookmark[page=\thepage,level=1]{Test subsection}
\lipsum[1-3]
\section*{}
\addcontentsline{toc}{section}{References}

\bibliographystyle{agsm}
\bibliography{References}\bookmark[page=\thepage,level=0]{References}

\end{document}

First answer

Here is a solution with bookmark package. I removed hyperref as you don't really need it:

\documentclass[a4paper, 12pt,draft]{article}
\usepackage{lscape}
\usepackage[margin=1in]{geometry}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\definecolor{light-gray}{gray}{0.8}
\usepackage{soul} 
\sethlcolor{light-gray}
\usepackage{tipa}
\usepackage{lipsum}
\usepackage{caption}
\usepackage{color}
\usepackage{afterpage}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{amsfonts}
\usepackage{amscd}
\usepackage{longtable}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{eucal}
\usepackage{hhline}
\usepackage{natbib}
\usepackage{setspace}
\usepackage{mathpazo}
\usepackage{calc}
\usepackage{booktabs}
\usepackage{mathtools}
\usepackage{eurosym}
\usepackage{stmaryrd}
\usepackage{float}
\usepackage{rotating}
\usepackage{pdflscape}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{positioning}
\usepackage{dcolumn}
\usetikzlibrary{shadows,shadings,shapes,decorations.pathreplacing}
\usepackage{times}
\usetikzlibrary{shapes.geometric}
\usepackage[nokeyprefix]{refstyle}
\usepackage{varioref}
\usepackage{xr}
%\usepackage[bookmarks=true]{hyperref}
\usepackage{bookmark}
\usepackage{filecontents}
\begin{filecontents*}{References.bib}
@article{cite1,
title={Nothing special},
author={Nobody, Noboditch},
year={1988}
}
\end{filecontents*}

\setlength\overfullrule{0pt}

\begin{document}


\section{Introduction}
 \onehalfspacing
 \citep[see, e.g.,][]{cite1}
 This is a reference \ref{sec:test}
\lipsum[1-5]

\section{Test}\label{sec:test}
\lipsum[1-3]
\includegraphics[width=\textwidth,draft=false]{example-image-a}
\section*{}
\addcontentsline{toc}{section}{References}

\bibliographystyle{agsm}
\bibliography{References}

\end{document}

Edit: added draft option in document class and checked... Also, I had to add [draft=false] option for the pictures and everything is fine. Test it.

Edit: Added \setlength\overfullrule{0pt} and changed \usepackage{hypre-xr} to \usepackage{xr} thanks to @blub.

Also from his comment, a better alternative (to avoid writing draft=false in every image) is to add the code:

 \makeatletter \lowercase{\Gin@boolkey{false}}{draft} \makeatother

in our preamble

koleygr
  • 20,105
  • The code gives some error that haven't figured out yet about a label or something... In your full example may be it is ok... But as MWE it has some problem even if compiles – koleygr Sep 16 '18 at 21:34
  • Thanks a lot. Sorry for my messy code. But the citation is still linked to the references section. – D_B Sep 16 '18 at 21:38
  • Only \usepackage{nohyperref} breaks the link, but also bookmarks. – D_B Sep 16 '18 at 21:39
  • @koleygr even in your code the citation is linked to the references. – D_B Sep 16 '18 at 21:53
  • @D_B.. I edited and aded Draft and seems to work. But you have to check it in your real document because possibly will give other problems – koleygr Sep 16 '18 at 21:58
  • 1
    @koleygr "draft" removed bookmarks as well. Plus figures don't show. – D_B Sep 16 '18 at 22:00
  • 1
    To remove the black lines caused by the draft option, add \setlength\overfullrule{0pt} – aloneprism Sep 16 '18 at 22:30
  • @blub... Thanks, solves the problem but adds an error – koleygr Sep 16 '18 at 22:35
  • 1
    @koleygr Strange, I don't get an error. I'll test again. Meanwhile to show images despite draft mode: \makeatletter \lowercase{\Gin@boolkey{false}}{draft} \makeatother – aloneprism Sep 16 '18 at 22:37
  • 1
    @koleygr Checked again and \setlength\overfullrule{0pt} works. Where did you place it? Without hyperref better change \usepackage{xr-hyper} to \usepackage{xr} – aloneprism Sep 16 '18 at 22:38
  • @blub, I forgot the \setlength and the error was wired to make me find the problem ("A number should have been here...")... Thank you.. Fixed. Do you have a sidebar with the chapters in your viewer? – koleygr Sep 16 '18 at 22:42
  • @koleygr Did you try the \Gin@boolkey? – aloneprism Sep 16 '18 at 22:45
  • @blub... Yes... It works. (Had lost that comment)... If you make it an answer I will upvote (the half of mine is already yours). – koleygr Sep 16 '18 at 22:48
  • @koleygr You had the good idea that solves the problem, my comments are just minor. – aloneprism Sep 16 '18 at 22:48
  • @blub... Please confirm that there is a sidebar in your pdf viewer and tell us witch viewer is it. OP cant see a sidebar. Thanks for everything... I will add the alternative (\Gin@boolkey) too – koleygr Sep 16 '18 at 22:56
  • @koleygr Was AFK, sorry. Both the texstudio viewer and adobe reader show the bookmarks in the sidebar. – aloneprism Sep 17 '18 at 00:14
  • @blub the bookmarks was shown there but was inactive... They all linked to page 1 at the time I gave the edited answer. My last edit is ok with everything (now) I think. Works fine. Even if doesn't use your code I am thankfull that learned from you. (Upvoted other answers of you) – koleygr Sep 17 '18 at 00:28