hyperref icon indicating copy to clipboard operation
hyperref copied to clipboard

Problem with \href and active characters of babel-french

Open petiard opened this issue 4 years ago • 2 comments

Hello!

With that example:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \documentclass[12pt,french,a4paper,twoside]{article} \usepackage[T1]{fontenc} \usepackage{babel} \usepackage{lmodern} \frenchsetup{og=«,fg=»} \usepackage{hyperref} \hypersetup{colorlinks,linkcolor=blue,urlcolor=blue} \usepackage{xcolor} \begin{document} \href{http://url}{Test: bla bla} \textcolor{red}{incorrect} (Test: bla bla)

\href{http://url}{Test; bla bla} \textcolor{red}{incorrect} (Test; bla bla)

\href{http://url}{Test! bla bla} \textcolor{red}{incorrect} (Test! bla bla)

\href{http://url}{Test? bla bla} \textcolor{red}{incorrect} (Test? bla bla)

\end{document} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%

you can see than the espacement between Test and : or ; or ! or ? is not correct (in French, of course). Into the parens, the espacement is correct.

Best regards.

François

petiard avatar Aug 05 '20 08:08 petiard

Yes, that is known. There is a rather long discussion about different variants here (the behaviour depends on the engine and also on the first argument) https://tex.stackexchange.com/questions/394208/how-to-get-suppress-french-spacing-before-punctuation-in-href

Basically you have to switch a boolean to reactivated the active chars:

\documentclass[12pt,french,a4paper,twoside]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{lmodern}
\frenchsetup{og=«,fg=»}
\usepackage{hyperref}
\hypersetup{colorlinks,linkcolor=blue,urlcolor=blue}
\usepackage{xcolor}
\begin{document}
\href{http://url}{Test: bla bla} \textcolor{red}{incorrect} (Test: bla bla)

\href{http://url}{\csname @safe@activesfalse\endcsname Test: bla bla}

\end{document}

I'm not sure if it would be a good idea to add this by default. It could change existing documents not expecting active chars in this place.

u-fischer avatar Aug 05 '20 09:08 u-fischer

OK, thank you Ulrike.

I've created a new command \Href:

\newcommand{\Href}[3][]{\href[#1]{#2}{\csname @safe@activesfalse\endcsname#3}}

and it makes the job.

It's maybe a solution?

petiard avatar Aug 06 '20 04:08 petiard