Skip to content

Confused about reserved characters in the \url macro #411

@Juanc1to

Description

@Juanc1to

As the title says, I am very confused about how hyperref (and also the url package) handle escaping in the argument. The documentation says that hyperref "makes use of the url package", with an important difference: "[m]ost importantly the hyperref \url expands commands." To me that sounds good, but I am quite baffled about using the core LaTeX escaping commands in the argument. Here's an approximately minimal working example (where "working" means "successfully compiling"):

\documentclass{article}
\usepackage[hidelinks]{hyperref}

\begin{document}

\noindent\raggedright \url{https://example.org/foo/{}bar} \break
\url{https://example.org/\{leftbrace} \break
\url{https://example.org/\}rightbrace} \break
\url{https://example.org/\$dollar1} \break
\url{https://example.org/$dollar2} (Only the unescaped dollar sign works?) \break 
\url{https://example.org/\&ampersand1} \break
\url{https://example.org/&ampersand2} (Both ampersands work?) \break
\url{https://example.org/%percent1} (Not a line-ending comment?) \break
\url{https://example.org/\%percent2} \break
\url{https://example.org/\^{}circumflex} \break
\url{https://example.org/^circumflex} (Both circumflexes work?) \break
\url{https://example.org/\~{}tilde} \break
\url{https://example.org/~tilde} (... but only the unescaped tilde works?) \break
\url{https://example.org/\textbackslash{}backslash} \break
\url{https://example.org/\backslash} \break
\url{https://example.org/\tilde} \break
%\url{https://example.org/\s} (Uncommenting this line causes compilation to fail.) \break
\url{https://example.org/\\backslash} (Both unescaped and strangely-escaped backslash work, and also some other weird things are happening here.) \break

\end{document}

With this result:

Image

I don't really know exactly how hyperref expects to process each of these input cases, but the cases seem quite inconsistent with each other and the documentation I quoted above. Could someone help me understand how these cases should work, and whether any of them indicate a bug in this package? In addition to these cases, if you uncomment the line starting with %\url{https://example.org/\s}, compilation fails.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions