TransWikia.com

href: broken links due to URL-encoding hash sign (# => %23)

TeX - LaTeX Asked by nnn on October 2, 2021

I am trying to use an href linking to a web URL including an HTML anchor pointer. Hence I am using a hash sign (#) in the URL. For example to link the page https://github.com/latex3/hyperref#bug-reports.

Here is a minimal example:

documentclass{article}
usepackage{hyperref}
begin{document}

href{https://github.com/latex3/hyperref#bug-reports}{link with hash that doesn't work}

href{https://en.wikibooks.org/wiki/LaTeX/Hyperlinks#Commands}{link with hash where it works}

end{document}

The problem is that the hash sign gets replaced by the URL escape character %23 when the PDF is generated. If I click on the link in the PDF the browser will get the link in the following form:

https://github.com/latex3/hyperref%23bug-reports

But this leads to an 404-Error on GitHub.

If I replace the %23 with # in the address bar, the proper page can be loaded.

On other pages (for example wikibooks) links with URL-escaped # work (shown in the example above).

Is it possible to switch off url-escaping of the hash sign in links?

I am using pdfTeX 3.14159265-2.6-1.40.21 (TeX Live 2020) on MacOS Catalina.

One Answer

As was layed out in the comments the problem here is not LaTeX and not the Browser but the pdf viewer. Some PDF viewers on MacOS seem to convert the hash sign in the PDF that is correctly inserted by LaTeX.

There is a table in this bug report showing which pdf viewers on MacOS create the problem:

Table of PDF viewers with hash problem

The bug seems to be on the side of Apple and was reported on 2 March this year. No fixes yet. I think the workaround for now is to use a different PDF viewer.

Also this question might be a duplicate of this question.

Correct answer by nnn on October 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP