18

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/\T1\ol and http://snl.no/\T1\aere, 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.

  • Adding tags “url” and “unicode” could be helpful for people searching for this in future? – Peter LeFanu Lumsdaine Dec 11 '10 at 17:20
  • You're right, I added those, as well as pdftex. Thanks for the suggestion. – Torbjørn T. Dec 11 '10 at 17:53
  • I'd say this ought to work. Try asking on comp.text.tex. – Philipp Dec 11 '10 at 18:09
6

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

  • 1
    Indeed, it appears that this works. Thanks! I haven't compiled to DVI for a long time, so it didn't even occur to me to try. I'll wait a little, and see if anyone has a solution for using pdflatex. If not, I'll accept your answer. – Torbjørn T. Dec 11 '10 at 15:20
13

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.

2

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.

0

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 Å.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.