I assume this was done by design, seeing as the introduction of hyperlinks may clutter the user's view of the actual text. Moreover, not all hyperlink typesetting is printable - as you've mentioned, the PDF hyperlink is merely "a rectangular area of the page that is mouse-aware". However, if you want to do this, there are two options available
Manual
You deactivate the colorlinks
option so that hyperref
sets the link border:
\hypersetup{%
colorlinks=false,% hyperlinks will be black
linkbordercolor=red,% hyperlink borders will be red
pdfborderstyle={/S/U/W 1}% border style will be underline of width 1pt
}
and typeset the text manually using \color{<color>}
. For example:
...
\begin{document}
\section{To See}\label{tosee}
\hyperref[tosee]{\color{green}just to see}
\end{document}
Note that this is virtually the same as what hyperref
does internally, since the text colour is modified and will typeset this way even if the hyperlink is removed via printing to PDF (or flattening).
The advantage behind this approach (motivating to include it here) is that you can specify different colours for each hyperlink, if you so wish.
Automatic
You activate the colorlinks
option so that hyperref
sets the link colour in the text
\hypersetup{%
colorlinks=true,% hyperlinks will be coloured
linkcolor=green,% hyperlink text will be green
linkbordercolor=red,% hyperlink border will be red
}
and then add the following after the above \hypersetup{...}
:
\makeatletter
\Hy@AtBeginDocument{%
\def\@pdfborder{0 0 1}% Overrides border definition set with colorlinks=true
\def\@pdfborderstyle{/S/U/W 1}% Overrides border style set with colorlinks=true
% Hyperlink border style will be underline of width 1pt
}
\makeatother
Here is the pdfborderstyle
specification from Adobe:
What you should do is override the \ref
, \hyperref
, \footnote
commands, and any other command that you use to link. The following code should give you a starting point:
\documentclass{article}
\usepackage{lipsum}
\usepackage[hidelinks]{hyperref}
\usepackage{tikz}
\usetikzlibrary{calc}
\makeatletter
\newlength\link@width
\newsavebox\link@box
\newcommand{\formatlink}[1]{%
% --- save the box to be displayed (so that e.g. footnote counters do not
% get incremented twice)
\savebox{\link@box}{#1}%
% --- calculate the width of the box for later use
\settowidth\link@width{\usebox{\link@box}}%
% --- draw the link
\tikz[baseline=(todotted.base)]{
\node[inner sep=-1pt,outer sep=0pt] (todotted) {\usebox{\link@box}};
\draw[dotted, thick]
($(todotted.base)-(.5\link@width,2pt)$) -- +(\link@width,0);
}%
}
\makeatother
\AtBeginDocument{%
% --- replace \ref command
\let\oldref=\ref
\renewcommand\ref[1]{\formatlink{\oldref{#1}}}
% --- replace hyperref command
\let\oldhyperref=\hyperref
\renewcommand\hyperref[2][]{\formatlink{\oldhyperref[#1]{#2}}}
% --- replace footnote command
\let\oldfootnote=\footnote
\renewcommand\footnote[1]{\formatlink{\footnotemark}\footnotetext{#1}}
% --- replace cite command
\let\oldcite=\cite
\renewcommand\cite[1]{\formatlink{\oldcite{#1}}}
% --- introduce secref command
\newcommand\secref[1]{\hyperref[#1]{Section \oldref{#1}}}
}
\begin{document}
\section{To See}\label{tosee}
This is Section \ref{tosee}; or refer to it like \secref{tosee}.
This is \hyperref[tosee]{just to see} what it looks like\footnote{\lipsum[1]}. \lipsum[1-2]
How about this?\footnote{And a second footnote}
\end{document}
The code introduces a new command, \formatlink
, which, as the name suggests, formats a link. Its only argument is the text that is to be underlined with dots. The code for \formatlink
is about the same as what you wrote in your question, with minor changes for better appearance.
Next, the code inside \AtBeginDocument
(which gets executed at the \begin{document}
command) overrides the \ref
, \hyperref
, and footnote
commands. It also adds a new command called \secref
, which could be used to refer to sections in such a way that the word "Section" also gets underlined.
For illustration purposes, I have changed the code of \formatlink
code slightly, so that every link shows up as a red box; the result is:
There are probably more commands to override, but it may help you on your way.
Best Answer
You can try this: