Text FormattingSelectively turn off Hyperlinks

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
nikolapoljak
Posts: 9
Joined: Sun Feb 26, 2012 3:03 pm

Selectively turn off Hyperlinks

Post by nikolapoljak »

Hi all,

I have a document that uses hyperref and has links to sections, URLs and outside PDFs. As you know, both URLs and outside PDF files use \href for linking to them. My question is: is there a way to turn off all file links without affecting the URL links? A short example with both types of links.

Code: Select all

\documentclass{article}
\usepackage{hyperref}
\begin{document}

This is a link to an URL \href{www.someurl.com} and this to a file \href{somefile.pdf}. How do I turn off all the file links? Keep in mind there are a lot of them (hundreds!)
\end{document}
Last edited by localghost on Thu Apr 25, 2013 9:28 am, edited 2 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
tommytex
Posts: 39
Joined: Wed Jan 23, 2013 10:04 pm

Selectively turn off Hyperlinks

Post by tommytex »

hi,

you can either change href to nolinkurl or change the colour of the linked text (the link is still there but nobody can see it in the printed version)

Code: Select all

\documentclass{article}
\usepackage{hyperref}
\usepackage[usenames,dvipsnames]{xcolor}


\hypersetup{
    filecolor=black,
    urlbordercolor = Red,
    filebordercolor = White
}
      
\urlstyle{same}
    
    
\begin{document}
This is a link to an URL \href{www.someurl.com}{some url} and this to a file \nolinkurl{README.pdf}. How do I turn off all the file links? Keep in mind there are a lot of them (hundreds!)
Maybe instead of changing href to nolinkurl a hundred times we might be happy with a black link url: \href{README.pdf}{some file}.
\end{document}
see http://en.wikibooks.org/wiki/LaTeX/Hype ... tomization

http://en.wikibooks.org/wiki/LaTeX/Colors

greez tommytex


of course this won't work (see below) because it's just a screenshot
Attachments
hyperref_filelinks.png
hyperref_filelinks.png (36.27 KiB) Viewed 17011 times
README.pdf
(114.85 KiB) Downloaded 603 times
nikolapoljak
Posts: 9
Joined: Sun Feb 26, 2012 3:03 pm

Re: Selectively turn off Hyperlinks

Post by nikolapoljak »

Thanks, but both solutions still have a bit of a problem in this particular case... I need to send the PDF electronically, so people could click on the link, even if it is black. Href to nolinkurl is also somewhat problematic (I assume you mean a "replace all" here), since I have hrefs for both local files and for URLs, and I want to turnoff only local file links (in one version of a document, I would keep the other version with the file links on).
User avatar
tommytex
Posts: 39
Joined: Wed Jan 23, 2013 10:04 pm

Selectively turn off Hyperlinks

Post by tommytex »

hi nikolapoljak,

yep, that's the problem with my solution you're right ;-)
but why do you want to have a file link when you do not want it to be shown?
Apart from an error message, nothing will happen if someone clicks on the file link...
maybe you could use a shell script to find out wether a \href is linked to
a file or not.

another idea - i don't know if it will work - would be to use the nohyperref.sty and delete the new definition of file link (marked as big "comment")

(i found this script on https://github.com/meli-lewis/latex2e-t ... perref.sty )

Code: Select all

%%
%% This is file `nohyperref.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% hyperref.dtx  (with options: `nohyperref')
%% 
%% File: hyperref.dtx Copyright 1995-2001 Sebastian Rahtz,
%% with portions written by David Carlisle and Heiko Oberdiek,
%% 2001-2012 Heiko Oberdiek.
%%
%% This file is part of the `Hyperref Bundle'.
%% -------------------------------------------
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% The Current Maintainer of this work is Heiko Oberdiek.
%%
%% The list of all files belonging to the `Hyperref Bundle' is
%% given in the file `manifest.txt'.
%%
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{nohyperref}
  [2012/11/06 v6.83m %
  Dummy hyperref (SR)]
\RequirePackage{letltxmacro}[2008/06/13]
\let\hyper@@anchor\@gobble
\def\hyper@link#1#2#3{#3}%
\let\hyper@anchorstart\@gobble
\let\hyper@anchorend\@empty
\let\hyper@linkstart\@gobbletwo
\let\hyper@linkend\@empty
\def\hyper@linkurl#1#2{#1}%
%%%%%%%%%%%%%%%%\def\hyper@linkfile#1#2#3{#1}%
\def\hyper@link@[#1]#2#3{}%
\let\PDF@SetupDoc\@empty
\let\PDF@FinishDoc\@empty
\def\nohyperpage#1{#1}
\def\Acrobatmenu#1#2{\leavevmode#2}
\let\pdfstringdefDisableCommands\@gobbletwo
\let\texorpdfstring\@firstoftwo
\let\pdfbookmark\@undefined
\newcommand\pdfbookmark[3][]{}
\let\phantomsection\@empty
\let\hypersetup\@gobble
\let\hyperbaseurl\@gobble
\newcommand*{\href}[3][]{#3}
\let\hyperdef\@gobbletwo
\let\hyperlink\@gobble
\let\hypertarget\@gobble
\def\hyperref{%
  \@ifnextchar[\@gobbleopt{\expandafter\@gobbletwo\@gobble}%
}
\long\def\@gobbleopt[#1]{}
\let\hyperpage\@empty
\LetLtxMacro\NoHy@OrgRef\ref
\DeclareRobustCommand*{\ref}{%
  \@ifstar\NoHy@OrgRef\NoHy@OrgRef
}
\LetLtxMacro\NoHy@OrgPageRef\pageref
\DeclareRobustCommand*{\pageref}{%
  \@ifstar\NoHy@OrgPageRef\NoHy@OrgPageRef
}
\endinput
%%
%% End of file `nohyperref.sty'.
tommytex
Post Reply