0

I'm interested in using hyperref package to highlight links typed as href elements, the links should be:

  • Of the same colour as the remaining text (default, black)
  • Underlined with single lines including spaces
  • No other modifications are required in the future I would like to be able to easily change link fonts, colour or face. Ideally by changing the hyperref package load.

Document

% Define document class, font size
\documentclass[9pt]{extarticle}


% Tweak page margins
% Set left and right margin and compute the remaining ones
% https://www.sharelatex.com/learn/Page_size_and_margins#!#Paper_size.2C_orientation_and_margins
\usepackage{geometry}
\geometry{
    a4paper,
    total={170mm,257mm},
    left=20mm,
    top=20mm
}
% --

% Font settings using the fontspec package
% https://stackoverflow.com/a/1840608/1655567
\usepackage{fontspec}
\setmainfont{IBM Plex Sans}
% --

% Define PDF metadata and link colours
\usepackage{xcolor}
\usepackage[pdfauthor={Person},
            pdftitle={What a fancy title},
            pdfkeywords={Keyword},
            pdfproducer={LaTeX},
            pdfcreator={xelatex},
        colorlinks=false,           % hyperlinks will be black
        linkbordercolor=black,      % hyperlink borders will be red
        pdfborderstyle={/S/U/W 1}       % border style will be underline of width 1pt
        ]{hyperref}
% --

\begin{document}  

% Place details side-by-side using minipage placeholder
% https://tex.stackexchange.com/a/157246/123504

% Minipage 1
\begin{minipage}{.5\textwidth}
    {\Large\textbf{ABC} \par} 
    \textit{abc:} 111  \textit{Email:} \href{mailto:abc.abc@abc.com}{abc.abc@abc.com}
\end{minipage}
\hspace{0.5cm}
% Another minipage 
\begin{minipage}{.5\textwidth}
    \textit{Search:} \href{https://www.google.com}{google.com}
\end{minipage}


\end{document}

Preview

Lack of underline

Desired results

Desired results can be achieved with use of \underline{}:

Underline applied to one link

\textit{Search:} \href{https://www.google.com}{\underline{google.com}}

I want to arrive at the same results via the hyperref settings, if possible.

  • 2
    Please make your document compilable for everyone -- the font settings are not necessary, in my point of view and not everyone has those fonts on his/her computer – user31729 Dec 10 '17 at 21:23
  • @ChristianHupfer Fair point, I reckon fontspec section is not that relevant and can be omitted. I wanted for the posted code to reflect closely my actual document. BTW, IBM Plex is free so it could be always be sourced, if desired. – Konrad Dec 10 '17 at 21:39
3

Based on https://tex.stackexchange.com/a/311148/36296 you could do something like:

\documentclass{article}
\usepackage[
    hidelinks
]{hyperref}
\usepackage[normalem]{ulem}
\usepackage{xcolor}


\makeatletter
\begingroup
  \catcode`\$=6 %
  \catcode`\#=12 %
  \gdef\href@split$1#$2#$3\\$4{%
    \hyper@@link{$1}{$2}{\uline{$4}}% or \underline
    \endgroup
  }%
\endgroup


\begin{document}

\href{mailto:abc.abc@abc.com}{abc.abc@abc.com}

\href{https://www.google.com}{google.com}

\end{document}

enter image description here

  • Thanks for the answer, I was hoping that I've messed something up in the hyperref settings that that there will be easier solution. – Konrad Dec 10 '17 at 21:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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