Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

so I'm trying to figure out how to have all links underlined with a dotted line. The furthest I got with this and this is:

\documentclass{article}
\usepackage{xcolor,soul,lipsum}
\usepackage[hidelinks]{hyperref}
\usepackage{tikz}
 \def\@pdfborder{0 0 1}% Overrides border definition set with colorlinks=true
  \def\@pdfborderstyle{/S/U/W 0}
\newcommand{\udot}[1]{%
\tikz[baseline=(todotted.base)]{
\node[inner sep=-1pt,outer sep=0pt] (todotted) {#1};
\draw[dotted] (todotted.south west) -- (todotted.south east); }%}%
\newcommand{\myhy}[2]{\udot{\hyperref[#1]{\color{black}\setulcolor{white}\ul{#2}}}}
\begin{document}
\section{To See}\label{tosee}
\vskip2cm
This is \myhy{tosee}{just to see} what it looks like\footnote{\lipsum[1]}. \lipsum[1-2]
\end{document}

The problem is I want to have formatted in this way every singe link in a document (including links to footnotes, webpages, etc.). Any ideas?

share|improve this question
add comment

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.