How to use section symbols ‘§’ in urls with the url-package

hrefurls

How do you create a url which includes a section symbol '§'?

I'm trying to create a link to this following url using the url-package:

https://lovdata.no/lov/1997-02-28-19/§20-20

Notice the section symbol '§'. This symbol is not printed to the output.

Consider the following example:

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{url}

\urldef{\mydefinedurl}\url{https://section_symbol_§_not_printed}

\begin{document}

\url{https://works_without_section_symbol}

\mydefinedurl

\url{https://section_symbol_§_not_printed}

% Real world-example: § is not printed.
\url{https://lovdata.no/lov/1997-02-28-19/§20-20}

\end{document}

This is the result. I have marked the places where the '§' is missing.

Result

Thanks!

Best Answer

As noted in my comment, the easy way to resolve your problem is to switch your engine from pdflatex to either xelatex or lualatex, which can directly digest glyphs from extended character sets. In pdflatex the catcode-changing mechanism used by \url interferes with the ability to properly decode the § token in the input stream.

As an alternative, you can use \texttt to typeset the url, as long as you change the catcode of _ in advance.

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}

\begin{document}

§\texttt{§}

{\catcode`_=12\texttt{https://section_symbol_§_is_printed}}

\end{document}

enter image description here

Related Question