19

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.

Torbjørn T.
  • 206,688
  • 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
  • Some other scattered suggestions: just \usepackage[T1]{fontenc} fix some characters: https://tex.stackexchange.com/a/444468/250119 ■ see also https://tex.stackexchange.com/q/392970/250119 and \hrefurl[urlencode] in https://tex.stackexchange.com/a/673889/250119 for an alternative solution to automatically convert URL to percent encoding ■ and https://tex.stackexchange.com/q/562537/250119 for file paths. ■ also https://tex.stackexchange.com/q/672441/250119 for line-breaking. – user202729 Apr 17 '23 at 06:24

4 Answers4

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.

Moriambar
  • 11,466
matth
  • 12,381
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

CarLaTeX
  • 62,716
gerry
  • 895
  • 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
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.

Ulrike Fischer
  • 327,261
1

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

Stephen
  • 14,890