0

I have a rather big project where I need multiple packages at the same time. I have problems in using "german umlaute" (äöü) and other special characters in \href links.

Here is what I have:

\documentclass[12pt,a4paper]{article}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{xcolor}
\usepackage{soulutf8}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{geometry}
\usepackage{eurosym}
\usepackage[hidelinks,pdfencoding=auto]{hyperref}
\geometry{
 left=20mm,
 top=15mm,
 right=20mm,
 bottom=15mm
}
\pagenumbering{gobble}
\setlength\parindent{0pt}

\newcommand{\cfbox}[2]{%
    \colorlet{currentcolor}{.}%
    {\color{#1}%
        \fbox{\color{currentcolor}#2}
    }%
}


\definecolor{COLOR_CON}{RGB}{255,0,0}
\definecolor{COLOR_DEF}{RGB}{0,255,0}


\begin{document}
    \Large


    \setul{0.5ex}{0.3ex}
    \setulcolor{COLOR_DEF} % mit rot unterstrichen

    \section*{§ 1 Beginn der Rechtsfähigkeit}

    Die \href{<ref.> Ä ä Ö ö Ü ü § \& € </ref.>}{\ul{Link with Ä ä Ö ö underlined}}.

    Die \href{<ref.> ä Ä ö Ö ü Ü § \& € </ref.>}{\cfbox{COLOR_CON}{Link with Ä ä Ö ö and text superscript in a box\textsuperscript{S1}}}.
\end{document}

I get an "TeX capacity exceeded" error. Or even if I remove all except one special character, it won't be displayed right.

I am using pdflatex for compiling. (Miktex 2.9 on Windows)

EDIT:

To be more clear, what my question is. How can I use those characters in both, the actual link (which is no http link) and the pdf document. As I already noted, if I remove the

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

the characters are correctly interpreted by my reader (texStudio). However those characters are not visible in the actual PDF document.

I can write something like \"a to get an ä in the output. Is there a way to avoid replacing all this manually, with a replacer function or something similar ?

  • 1
    Welcome, don't use any non-ascii characters in \href? – Johannes_B Feb 25 '18 at 8:10
  • 2
    Are you seriously numbering by hand and underlining? That is bad. – Johannes_B Feb 25 '18 at 8:11
  • 2
    You request that links are hidden, and then highlight them yourself. I am confused. – Johannes_B Feb 25 '18 at 8:14
  • 1
    Link target, just like urls, should not contain any non-ascii characters. – Johannes_B Feb 25 '18 at 8:20
  • 2
    Out of the used characters only € is not allowed in an url name (which must be the first mandatory argument of \href. If you want internal document links, you should not use \href, but \hypertarget and \hyperlink` as well as the regular \ref etc. commands. But as it stands it is not clear to which object you want to refer to – user31729 Feb 25 '18 at 8:30
2

The URI argument in the first argument of \href is wrong. From the PDF specification: The URI is an 7-bit encoded ASCII string. And the specification refers to RFC 2396, Uniform Resource Identifiers (URI): Generic Syntax. Characters not allowed in URIs have to be escaped, see percent encoding.

For example, the entry for baker in the German Wikipedia (Bäcker) has the URL:

https://de.wikipedia.org/wiki/B%C3%A4cker

This URL can be retrieved from via copy & paste from the location bar of some browsers (e.g. Mozilla Firefox, Google Chrome).

The encoding that is used to encode ä into URI octets depend on the URI and the server. In this case (often) it is UTF-8, but can also be different.

Non-ASCII characters in domain names (Internationalized domain name) and host names (Punycode) are much more complicate to implement.

  • So you recommend to use the percent encoding for those characters. That means I have to replace all occurrences of those characters in the .tex files right? Is there a way to "automate" this, since I have a lot of files. Furthermore is there a way, to still use the characters in the .tex files and translate them in compile time, such that I still have readable .tex files – Maxi Feb 25 '18 at 15:56
  • @Maxi It is quite a lot of work to automate this. The URI needs to be parsed into the components according to the protocol. Each component has its own rules. There are come conversions, from TeX code to URI characters: with/without macro support, category code issues, 8-bit bytes (TeX, pdfTeX), Unicode chars (XeTeX, LuaTeX), pseudo-Unicode bytes (LuaTeX), input encoding by package inputenc, font encoding if input encoding is not used, ). ... – Heiko Oberdiek Feb 25 '18 at 16:15
  • ... Then, URI characters are converted to URI 7-bit ASCII according to the component's rules. The encoding is not quite clear here, because it also depends on the URI, thus an additional user option is necessary. And there aren't volunteers for the hard work. – Heiko Oberdiek Feb 25 '18 at 16:15
0

So what I have achieved now is a "semi-optimal" solution to my problem.

If someone is interested:

First I use the \usepackage[OT1]{fontenc} now, therefore I can use ä, ö, ü, & and ß. However § and € don't work here.

The reason, why this is semi-optimal, the compiler dont gives me the real "ä", but something like

\protect \unhbox ... \U@D a\egroup

Since I am extracting this text later on, I can replace this string with an "ä".

Using another fontenc, I just got an "?" for every character, here I can distinguish them with the "\U@D a code"

For the other characters I still need a special solution.

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.