latex3 / hyperref

Hypertext support for LaTeX
169 stars 36 forks source link

Problem with \href and character # in the name of a file #328

Open petiard opened 9 months ago

petiard commented 9 months ago

Hello (sorry for my bad english...) OS : Windows 10 Pro Adobe Reader updated hyperref version 7.01h

Suppose you have a file named ##abc.pdf and located in C:\Documents\

Then, compile that file with pdflatex:

\documentclass[12pt,a4paper]{article} \usepackage{hyperref} \begin{document} \href{C:/Documents/##abc.pdf}{Fichier} : doesn't work as expected.

\href{{C:/Documents/##abc.pdf}}{Fichier} : doesn't work as expected.

\href{{{C:/Documents/##abc.pdf}}}{Fichier} : works!??? \end{document}

and open the pdf with Adobe Reader; links 1 and 2 don't work but link 3 works! Why?

I don't know if it's similar under Linux or MacOS.

Best regards

François

u-fischer commented 9 months ago

(sorry for my bad english...)

Its fine, and even if not: there would no need to apologize.

links 1 and 2 don't work but link 3 works! Why?

url's uses the # to denote targets on a page. hyperref therefore carefully splits the input at the # in pieces directly at the begin of the processing. (see also https://github.com/latex3/hyperref/issues/254)

There is imho not much one can do. Avoid such file names, or use the braces to protect the argument.

You could also try \hrefpdf from the pdfmanagement. As it is restricted to pdf-files it doesn't have to apply code for urls:

\DocumentMetadata{}
\documentclass[12pt,a4paper]{article}
\usepackage{hyperref}
\begin{document}
\hrefpdf{C:/Documents/##abc.pdf}{Fichier}
\end{document}
davidcarlisle commented 9 months ago

you can probably use the correctly encoded URL to refer to such a file which would be to %-encode the # as %23 but why have a # in a file name (other than editor backup files)

petiard commented 9 months ago

Thank you. I agree: no # in filenames... In fact, it's not for me but there was a question on Liste Gutenberg (gut@ens.fr). I've found the solution with two couples of braces but I really don't understand why it works... And, no, the encode # by %23 doesn't work. François