% \iffalse meta-comment
% SPDX-FileCopyrightText: Copyright (c) 2021-2026 Yegor Bugayenko
% SPDX-License-Identifier: MIT
% \fi

% \CheckSum{0}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}

% \GetFileInfo{href-ul.dtx}
% \DoNotIndex{\endgroup,\begingroup,\let,\else,\fi,\newcommand,\newenvironment}

% \iffalse
%<*driver>
\ProvidesFile{href-ul.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{href-ul}
%<*package>
[2026-07-08 0.5.3 Underlined Hyperlinks]
%</package>
%<*driver>
\documentclass{ltxdoc}
\usepackage{lmodern}
\usepackage{microtype}
\AddToHook{env/verbatim/begin}{\microtypesetup{protrusion=false}}
\usepackage{href-ul}
\usepackage{xcolor}
\usepackage[dtx]{docshots}
\PageIndex
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
	\DocInput{href-ul.dtx}
	\PrintChanges
	\PrintIndex
\end{document}
%</driver>
% \fi

% \title{|href-ul|: \LaTeX{} Package \\ That Makes Underscored Links\thanks{The sources are in GitHub at \href{https://github.com/yegor256/href-ul}{yegor256/href-ul}}}
% \author{Yegor Bugayenko \\ \texttt{yegor256@gmail.com}}
% \date{\filedate, \fileversion}
%
% \maketitle
%
% \section{Introduction}
%
% This package renders hyperlinks with an underscore through the |\href| command:
%
% \begin{docshot}
% \documentclass{article}
% \pagestyle{empty}
% \usepackage{href-ul}
% \begin{document}
% Go to
%   \href{https://google.com}{Google}!
% \end{document}
% \end{docshot}
%
% The package does not support line breaking within the title of the link.

% Altering the colour of the text simultaneously alters the colour of the underline:
% \begin{docshot}
% \documentclass{article}
% \pagestyle{empty}
% \usepackage{href-ul}
% \usepackage{xcolor}
% \begin{document}
% Go to {\color{red}
%   \href{https://google.com}{Google}}!
% \end{document}
% \end{docshot}

% Altering the size of the text leaves the height of the underline unaffected:
% \begin{docshot}
% \documentclass{article}
% \pagestyle{empty}
% \usepackage{href-ul}
% \begin{document}
% You can always find \\ anything in
% {\Large \href{https://google.com}{Google}},
% but \\ it's better to learn
% something \\ from a school too!
% \end{document}
% \end{docshot}

% By means of the |plain| package option, the underscores may be suppressed:
% \docshotOptions{firstline=3,lastline=7}
% \begin{docshot}
% \documentclass{article}
% \pagestyle{empty}
% \usepackage[plain]{href-ul}
% \begin{document}
% This link has no underscore: \\
% \href{https://google.com}{Google}.
% \end{document}
% \end{docshot}

% \StopEventually{}

% \section{Implementation}
% \changes{v0.2.0}{2021/06/11}{Initial version}
% \changes{v0.3.0}{2022/10/31}{We started using "docshots" package for better rendering of examples.}
% \changes{0.4.0}{2024/01/09}{Package options processing introduced with a single \texttt{plain} option.}
% \changes{0.5.0}{2025/03/02}{Enhanced URL breaking functionality to improve handling of long URLs.}
% \changes{0.5.1}{2025/03/02}{Added text breaking capabilities to the second argument of \texttt{\char`\\href} and shifted from \texttt{ulem} to \texttt{soul} package.}
% \changes{0.5.2}{2025/03/07}{Decided not to use \texttt{soul} package, because it's too fragile, and returned back to \texttt{ulem}.}
% \changes{0.5.3}{2026/07/08}{Passed the \texttt{normalem} option to \texttt{ulem} (via \texttt{\char`\\PassOptionsToPackage}, to avoid option clashes) so that \texttt{\char`\\emph} keeps italicizing instead of underlining.}

% First, we process package options:
%    \begin{macrocode}
\RequirePackage{pgfopts}
\pgfkeys{
  /href/.cd,
  plain/.store in=\href@plain
}
\ProcessPgfPackageOptions{/href}
%    \end{macrocode}

% Then, we include the |ulem| package in order to enable underscores. We pass
% the |normalem| option so that |ulem| does not replace italics with
% underlining in text emphasized by |\emph|. The option is passed via
% |\PassOptionsToPackage| rather than |\RequirePackage[normalem]{ulem}|, so that
% no ``option clash'' occurs if the document already loads |ulem| itself:
%    \begin{macrocode}
\makeatletter
\ifdefined\href@plain\else
\PassOptionsToPackage{normalem}{ulem}
\RequirePackage{ulem}
\fi
\makeatother
%    \end{macrocode}

% Then, we include the |hyperref| package for PDF hyperlinks:
%    \begin{macrocode}
\PassOptionsToPackage{hidelinks}{hyperref}
\PassOptionsToPackage{hyphens}{url}
\RequirePackage{hyperref}
\RequirePackage{url}
%    \end{macrocode}

% Then, we re-define the default |\href| command:
%    \begin{macrocode}
\makeatletter
\begingroup
\catcode`\$=6
\catcode`\#=12
\gdef\href@split$1#$2#$3\\$4{%
  \hyper@@link{$1}{$2}{%
    \ifdefined\href@plain$4\else\uline{$4}\fi%
  }%
  \endgroup%
}
\endgroup
\makeatother
%    \end{macrocode}

% \Finale

%\clearpage
%
%\PrintChanges
%\clearpage
%\PrintIndex
