Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
petiard opened this issue Feb 3, 2024 · 3 comments
Open

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

petiard opened this issue Feb 3, 2024 · 3 comments

Comments

@petiard
Copy link

petiard commented Feb 3, 2024

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
Copy link
Member

(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 #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
Copy link
Member

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
Copy link
Author

petiard commented Feb 5, 2024

Thank you.
I agree: no # in filenames...
In fact, it's not for me but there was a question on Liste Gutenberg ([email protected]). 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants