1

I am adding a footnote:

\footnote{\url{http://example.org/\#manual}}

The hashtag # escaped and success in compile the document and result in a http://example.org/#manual footnote. However, the link itself was encoded, and if one clicks the URL, it will open http://example.org/%23manual, which cannot be processed by the destination website.

Since we cannot change the behavior of the destination website, how to disable the URL encoding for the URL itself?

Example, use latexmk -pdf main.tex to compile:

% main.tex
\documentclass{scrartcl}
\usepackage{hyperref}
\begin{document}
Read\footnote{\url{https://threejs.org/docs/index.html\#manual/en/introduction/Creating-a-scene}}
\end{document}

If we click the generated URL, the link opened in a browser is encoded by the percentage symbol, i.e. because the hashtag is encoded to %23.

Expected:

https://threejs.org/docs/index.html#manual/en/introduction/Creating-a-scene

Actual:

https://threejs.org/docs/index.html%23manual/en/introduction/Creating-a-scene

It looks like the problem exists in the macOS Preview. Adobe Acrobat works and doesn't introduce URL encoding.

More investigation:

I believe this is a problem that can be addressed by the package but doesn't know how to do it. Evidence: in the hyperref's document (Septmber 2018), page 7, the link http://somewhere/path/file.pdf#nameddest=chapter.4 opens without URL encoding and works as expected.


A workaround (many thanks to @Ulrike Fischer), use the following instead:

\footnote{\color{blue}\texttt{http://example.org/\#manual}}
Changkun
  • 111
  • 4
  • Welcome to TeX.SX! Please provide a MWE in order for people to be able to reproduce your problem and help you. Without it, it might be impossible to reproduce the behavior your encounter. Indeed, when I try to add your link in a simple document, the # character is correctly transcribed and the link works perfectly. – KersouMan Apr 27 '20 at 08:43
  • @KersouMan An reproducible example is added. – Changkun Apr 27 '20 at 08:53
  • Well, for me, your code works fine and the compiled document gets the # character just right. Would, by any chance, adding the inputenc package with the utf8 option as \usepackage[utf8]{inputenc} solve your problem? – KersouMan Apr 27 '20 at 09:13
  • The url looks fine in the pdf. What pdf viewer are you using? – Ulrike Fischer Apr 27 '20 at 09:14
  • @KersouMan No. It doesn't work for me. – Changkun Apr 27 '20 at 09:23
  • @UlrikeFischer Very interesting observation. I was using macOS Preview: if I click the link, it open as an encoded URL, and I just tried Adobe's PDF viewer, the link opens properly. – Changkun Apr 27 '20 at 09:25
  • @UlrikeFischer I believe this is a problem that can be addressed by the package but doesn't know how to do it. Evidence: in the hyperref's document (Septmber 2018), page 7, the link http://somewhere/path/file.pdf#nameddest=chapter.4 opens without URL encoding. – Changkun Apr 27 '20 at 09:33
  • http://somewhere/path/file.pdf#nameddest=chapter.4 is not a real link in the manual, it is simple verbatim text. That means you pdf viewer is guessing what to do here (and now does it right). I'm sorry but there have been other reports regarding preview. It seems not to be the best of pdf viewer. – Ulrike Fischer Apr 27 '20 at 09:42
  • @UlrikeFischer How to create such a text? I just need to make sure if a student clicks and opens the link properly. Prevent your user using Preview is not an option at all. – Changkun Apr 27 '20 at 09:46
  • 1
    Add \input{glyphtounicode} \pdfgentounicode=1 in the preamble (or use lualatex), then use \texttt{http://somewhere/path/file.pdf\#nameddest=chapter.4} and hope for the best. But be aware that every pdf viewer will then have to guess that this is a link, so if your students use a viewer who doesn't do this they will have no link at all. – Ulrike Fischer Apr 27 '20 at 10:01
  • @UlrikeFischer Thanks! it works! – Changkun Apr 27 '20 at 10:07
  • Maybe https://tex.stackexchange.com/q/12855/35864 can help you. I like the method from Michael Ummels' answer https://tex.stackexchange.com/a/13073/35864. (I couldn't test if it works for you, because your MWE produced the expected results in all viewers I tested [TeXworks, SumatraPDF, Adobe Reader all on Win 10]). I usually use something like https://gist.github.com/moewew/c42e93cc007e2aa068a46fdd0b92d3e6. But maybe this is just a bug in macOS Preview? – moewe Apr 27 '20 at 16:01
  • Hi @moewe , thanks for your method, I just tried yours. The result shows it doesn't work for macOS Preview :( – Changkun Apr 28 '20 at 07:46

0 Answers0