I'm trying to create a class that, among other things, generates URLs from parameters passed to an environment. For some weird reason, if the URL string contains a /, hyperref tries to create a URL that points to a file named <URL>.pdf.
\documentclass{article}
\usepackage{expl3}
\usepackage{xparse}
\usepackage{verbatim}
\usepackage{hyperref}
\ExplSyntaxOn
\keys_define:nn { mydocument / myenvironment }
{
link .tl_set:N = \l_myenvironment_link_tl,
print .bool_set:N = \l_myenvironment_print_bool,
}
\NewDocumentEnvironment { myenvironment } { m }
{
\keys_set:nn { mydocument / myenvironment } { #1 }
\minipage{\textwidth}
\tl_clear_new:N \l_item_url_tl
\tl_put_left:Nn \l_item_url_tl { https:// }
\tl_put_right:Nx \l_item_url_tl { \l_myenvironment_link_tl }
\href{\l_item_url_tl}{TeX.StackExchange} \\
\url{\l_item_url_tl} \\
}
{
\endminipage
}
\ExplSyntaxOff
\begin{document}
\begin{myenvironment}
{
link = tex.stackexchange.com,
}
Here is some content in my environment with a good link
\end{myenvironment}
\begin{myenvironment}
{
link = tex.stackexchange.com/users/3351/robbie,
}
Here is some content in my environment with a \textbf{bad} link
\end{myenvironment}
\end{document}
The above MWE exhibits the behaviour I'm describing: the first instance of the environment has a link to https://tex.stackexchange.com, but the second creates a link to https://tex.stackexchange.com/users/3351/robbie.pdf. Weirdly enough, it doesn't mangle the URL if I use \url, but I can't use that command in my document as the link text is also generated.
Why does it do this, and how do I make it use the raw URL value in the hyperlink target?