TransWikia.com

Hyperref: Scandinavian characters (æø) don't work in url, hyperlink is wrong

TeX - LaTeX Asked by Torbjørn T. on August 1, 2021

Background

A while ago it became possible to use the letters æ, ø and å in URLs, and some websites, like the encyclopaedia Store Norske Leksikon, has made use of this.

Recently, a question was posted on a Norwegian forum about creating a hyperlink to such an URL, something that doesn’t work, at least not with æ and ø.

An example

documentclass[a4paper]{article}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{lmodern}

usepackage{hyperref}

begin{document}
url{http://snl.no/øl} 
url{http://snl.no/ære} 
url{http://snl.no/Ål}
end{document}

The first two links do not work, they are printed as http://snl.no/T1ol and http://snl.no/T1aere, but the third one works as it should.

(One can get the correct URL printed by using the href command, but as the hyperlink is still wrong, that isn’t really a solution.)

The question

I assume this has something to do with how hyperref handles non-english characters. Is there some way of making hyperref create a correct link with æ or ø in the url?

Update

By using the href command, and compiling with latex and the dvipdfm, the hyperlink is correct (see gerry’s answer below). I’ve been compiling with pdflatex.

4 Answers

Actually I can get the right link with href. It's compiled with latex & dvi2pdf

documentclass[a4paper]{article}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{lmodern}

usepackage{hyperref}

begin{document}
href{http://snl.no/øl}{http://snl.no/øl}   href{http://snl.no/ære}{http://snl.no/ære}    href{http://snl.no/Ål}{http://snl.no/Ål}
end{document}

alt text

Correct answer by gerry on August 1, 2021

I get the same results with pdflatex, latex+dvips+ps2pdf and latex+dvipdfmx. In your place I would ask the author of hyperref. E.g. in comp.text.tex.

Answered by Ulrike Fischer on August 1, 2021

With a small modification the answer given by gerry will even work directly with pdflatex:

documentclass[a4paper]{article}

usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{lmodern}

usepackage[]{hyperref}

begin{document}
  href{http://snl.no/%C3%B8l}{http://snl.no/øl} 
  href{http://snl.no/%C3%A6re}{http://snl.no/ære} 
  href{http://snl.no/%C3%85l}{http://snl.no/Ål}
end{document}

You just have to encode the URL, for example using the W3 URL Encoder.

Answered by matth on August 1, 2021

matth's answer works, but applying Heiko's answer (to another question) it is even possible to do:

documentclass{article}

usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage{hyperref}

begin{document}
  href{detokenize{http://snl.no/øl}}{http://snl.no/øl} 
  href{detokenize{http://snl.no/ære}}{http://snl.no/ære} 
  href{detokenize{http://snl.no/Ål}}{http://snl.no/Ål}
end{document}

Saves the need to look up the code for ø, æ, and Å.

Answered by Stephen on August 1, 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