0

My goal is to add a heavy underline to text that contains hyperlinks via the hyperref-package, such that, when printing out the file, one can see that there is a link hidded behind some words.

When adding a new command, \myhref, I found that the special German characters (ä,ö,ü,ß) contained in the latin1-options of inputenc are no longer working. In the normal \href, they are working, as they are contained in the scrbook document class, I believe.

\documentclass%
% [12pt,abstracton,titlepage,parskip=false, no, no,twoside=true,open=right]
{scrbook}

\usepackage[autooneside=false, headsepline, plainheadsepline, automark]{scrlayer-scrpage} %%%%% Layout \usepackage{geometry} \geometry{top=1in, bottom=1in, left=1in, right=1in} \usepackage{setspace} \linespread{1}

\usepackage{url} \usepackage[breaklinks=true]{hyperref} \usepackage{graphicx} \usepackage{color,soul} \setul{0.4ex}{0.3ex} \setulcolor{blue} \sethlcolor{yellow}

\newcommand{\myhref}[2]{% \href{#1}{\ul{#2}}}

% \let\oldhref\href % \renewcommand{\href}{% % \oldhref{#1}{\setulcolor{blue}\ul{#2}}}

\begin{document}

\myhref{www.google.com%}{Schär Schar. fließen. Önvestment Investment.}

\href{www.google.com%}{Schär Schar. fließen. Önvestment Investment.}

\end{document}

enter image description here

Am I defining the new command wrongly?

As a comment pointed out, the solution was to use the package soulutf8 instead of soul in order to make the unterline accept the characters. However, I now ran into the subsequent problem, that the new command myhref does not accept "%" in the URL, but the old command hrefdoes. I adjusted the MWE.

Marie. P.
  • 675

1 Answers1

1

The following code solves both problems:

\documentclass{scrbook}

\usepackage[T1]{fontenc} \usepackage{hyperref,xcolor,soulutf8}

\NewDocumentCommand{\myhref}{ v m }{\href{#1}{\ul{#2}}}

\begin{document}

\myhref{www.google.com/%}{Schär Schar. fließen. Önvestment Investment.}

\end{document}

  • the link should start with https://, without the protocol hyperref will produce a file link instead of an URI. – Ulrike Fischer Jan 28 '23 at 13:34
  • 1
    @Ulrike Fischer It works for me with valid link. For example https://www.google.com/search?q=%25&hl=hu&source=hp&ei=BjHVY8q0C4-xrgSG_Zm4Bw&iflsig=AK50M_UAAAAAY9U_FgbE51fsYccKKtKggk3fKyiscDfP&ved=0ahUKEwjKz7LavOr8AhWPmIsKHYZ-BncQ4dUDCAg&uact=5&oq=%25&gs_lcp=Cgdnd3Mtd2l6EANQAFgAYKwIaABwAHgAgAFZiAFZkgEBMZgBAKABAQ&sclient=gws-wiz – hair-splitter Jan 28 '23 at 14:31