latex3 / hyperref

Hypertext support for LaTeX
165 stars 35 forks source link

command in \url not working #217

Closed Reissner closed 2 years ago

Reissner commented 2 years ago

I need \url{...} with configurable content, as \url{\repo}, \repo resolved to be some repository. This does not work. I think within \url commands are not resolved. This should change in my opinion.

u-fischer commented 2 years ago

\url is not defined by hyperref but by the url package. And by design it must be able to handle for example windows pathes with backslashes like C:\users\whatever. So it can't expand arbitrary commands. But you can define your own variant, e.g.:

\documentclass{article}
\usepackage{url}

\begin{document}
\newcommand\myurl{\expandafter\url\expandafter}
\newcommand\repo{myrepo}
\myurl{\repo}

\end{document}

Be aware that your repo url then can't contain special chars like a percent or a hash as url no longer can adapt the catcodes.