hyperref icon indicating copy to clipboard operation
hyperref copied to clipboard

Respect babel's named option 'main'

Open AdrianVollmer opened this issue 4 years ago • 3 comments

Hyperref uses the language set by babel, but does not know about the named option main.

MWE:

\documentclass{article}
\usepackage{acronym}
\usepackage[english,main=ngerman]{babel}
\usepackage{hyperref}
\begin{document}
\section{Test}\label{foo}\autoref{foo}
\end{document}

This outputs section 1, but should output Abschnitt 1.

A workaround is to simply leave out main= (babel uses the last language as main, I think). But when using the scrreprt class and switching languages in the document, babel shows a warning that you should be using main=. Plus, \selectlanguage stops working for references, perhaps more.

Also see here for a proposed fix.

AdrianVollmer avatar Dec 23 '20 10:12 AdrianVollmer

The language support in hyperref for \autoref is clearly quite restricted (and old): It knows a few babel languages, but ignores e.g. polyglossia and newer options offered by babel.

But I don't think that it would be sensible to extend it. In my opinion autoref and its language definitions doesn't really belong into hyperref. It is only there as it uses the trick to look at the destination name to guess the counter it refers too. It should be moved in some external package and based on e.g. zref-counter instead. (There is a branch where I made first tries, and with it you get german with your example).

u-fischer avatar Dec 23 '20 13:12 u-fischer

Thanks for your insight. We're considering switching to cleveref until a suitable replacement to \autoref lands in texlive.

For anybody who stumbles on this issue, this workaround seems to do the trick:

\usepackage[english,ngerman,main=ngerman]{babel}

AdrianVollmer avatar Jan 08 '21 12:01 AdrianVollmer

@u-fischer have you worked on your branch since then or can recommend a more featureful solution (/package)?

septatrix avatar Jun 28 '22 10:06 septatrix