# Type uneven number of curly braces '{' '}' in URL using hyperref

My question is somewhat similar to this one: Type '{' '}' in url However, how can I write an uneven number of curly braces, e.g.:

\url{http://example.org/foo/\{bar}


The documentation of the URL package says, one should use another char than {}. However as soon as I load hyperref, the URL functional seems to be overwritten. The only working code I could produce was something like

\url{http://example.org/foo/\%7Bbar}


which is still syntactically correct but produces the %7B in the output (where I want to have the human-readable '{').

Minimal example which does not compile correctly:

\documentclass{article}
\usepackage{url}
\usepackage{hyperref}
\begin{document}
foo \url+http://example.org/foo/\{bar+ bar
\end{document}


If I remove hyperref, the example works…

• Instead of curly braces, use a non-special character that doesn't occur inside the URL string as the delimiter at both the beginning and the end of the string. E.g., with the + symbol as the delimiter character, write \url+http://example.org/foo/\{bar+. Of course, the url package must be loaded for this to work. (Aside: A "special" character, in a TeX context, is one of % & # \ _ ^ { }. – Mico Dec 11 '18 at 7:59
• this does only work for the url package. If i load hyperref, I get a compile error – Ben Dec 11 '18 at 13:57
• As I wrote very explicitly in my earlier comment, the url package must be loaded for my suggestion to work. If you don't load the url package, I can see no reason for why my suggestion would work. If you want to (or need to) load the hyperref package as well, you are of course free to do so. Just be sure to load hyperref after url. – Mico Dec 11 '18 at 14:07
• That's what I tried. Minimal example: \documentclass{article}\usepackage{url} \usepackage{hyperref} \begin{document} foo \url+http://example.org/foo/\{bar+ bar \end{document} results in foo +http://example.org/foo/{bar+ bar (note the additional +-sign, I think hyperref destroys the functionality of url) – Ben Dec 11 '18 at 14:36
• You are right that hyperref modifies \url in a way breaking its usage with a delimiter. It provides \nolinkurl with comment save the meaning of the original \cmd{\url} in \cmd{\nolinkurl} but this does not work for usage with delimiter. – user4686 Jan 8 at 15:09

As a workaround (perhaps a better way exists, not yet investigated) you can use this:

\documentclass{article}
\usepackage{url}
\usepackage{hyperref}
\begin{document}
foo \href{http://example.org/foo/\%7Bbar}{\texttt{http://example.org/foo/\{bar}} bar
\end{document}


The image is from usage of Acrobat Reader. In another PDF viewer, the tooltip displayed a brace, not %7B in the displayed URL with yellow background.

• Nice solution, however it breaks the linebreak algorithm which should break urls on / characters and does not add a hyphen… – Ben Jan 20 at 10:16