[Tex/LaTex] Correctly using hyperref package to underline href elements

hyperrefunderlineurls

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.

Best Answer

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

Related Question