# Change autoref language?

I am trying to use latex to write something in polish. I am using babel package together with hyperref. I thought this would be enough, but apparently it is not.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[polish]{babel}
\usepackage[utf8]{inputenc}

\usepackage{hyperref}

\begin{document}
\section{foo}
\label{sec:here}

\begin{figure}
\caption{\label{fig:here} This is a figure caption}
\end{figure}

\autoref{sec:here}

\autoref{fig:here}
\end{document}


This produces:

As you can see the figure caption is correctly written in Polish, but the autoreferences are still in English.

I guess it should be something simple. For example, the question Wrong autoref names when using babel's main= feature suggests that the above should work. All other material I was able to find on stackexchange or google was focusing on more specific uses than the one I am describing.

So, what am I missing?

A possible walkaround I am aware of is to manually define all those names through \def\figureautorefname, but I hope someone already did that in a public package and is properly maintained.

• As far as I can see in the hyperref.sty (TeXlive 2016), there's no Polish translation for the autoref names. So, you'll have to introduce them yourself. – Sergei Golovan Jul 12 '17 at 14:29
• You could post your adjustments on this question as an answer after you done them for future readers. – Skillmon Jul 12 '17 at 14:35
• You have to do \renewcommand{\chapterautorefname}{....} etc with the relevant Polish names – user31729 Jul 12 '17 at 14:53

Unfortunately, support for Polish language is not defined in hyperref for the \...autorefname macros.

hyperref supports english,afrikaans,french,german,spanish,catalan,portuges,magyar, russian,italian,vietnamese yet, as of version 6.85a from 2017/03/14.

A trial of a solution:

The macro

\ProvidePolishAutoRefNames{figure=\figurename,chapter,section={PolishSectionName},table,equation={PolishEquationName}}

loops through the counter names that are given in a comma separated list and generates the \##1autorefname on the fly.

If figure=\figurename is given, it uses the name from \figurename etc, if just the counter name X is given, it tries to use \Xname, which is not defined in any case.

Since I don't speak Polish, I have used PolishSectionName etc. as replacement.

\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage[polish]{babel}
\usepackage[utf8]{inputenc}

\usepackage{xparse}

\ExplSyntaxOn
\cs_generate_variant:Nn \cs_gset:cpn {cpx,cpo}
\NewDocumentCommand{\ProvidePolishAutoRefNames}{m}{%
\seq_set_from_clist:Nn \l_tmpa_seq {#1}
\seq_map_inline:Nn \l_tmpa_seq {% Loop through names
\seq_set_split:Nnn \l_tmpb_seq {=} {##1}
\tl_set:Nx \l_tmpa_tl {\seq_item:Nn \l_tmpb_seq {1} autorefname}
\int_compare:nNnTF {\seq_count:N \l_tmpb_seq } > {1} {% Check whether there is a "=", if so, use the RHS
\cs_gset:cpx {\l_tmpa_tl} {\seq_item:Nn \l_tmpb_seq {2}}
}{% No, try to evaluate \##1name, e.g. \chaptername
\cs_gset:cpx {\l_tmpa_tl} {\use:c{\seq_item:Nn \l_tmpb_seq {1}name}}
}
}
}
\ExplSyntaxOff

\usepackage{hyperref}

\ProvidePolishAutoRefNames{figure=\figurename,chapter,section={PolishSectionName},table,equation={PolishEquationName}}
}

\begin{document}

\chapter{Foo chapter}\label{foochapter}

\section{foo}

\figureautorefname

\label{sec:here}

\begin{figure}
\caption{\label{fig:here} This is a figure caption}
\end{figure}

$$E=mc^{2} \label{fooequation}$$

See \autoref{foochapter} or \autoref{fooequation}

\autoref{sec:here}

\autoref{fig:here}
\end{document}


A similar version, by defining \HyLang@polish analogously to HyLang@french etc.

\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage[polish]{babel}
\usepackage[utf8]{inputenc}

\usepackage{xparse}

\ExplSyntaxOn
\cs_generate_variant:Nn \cs_gset:cpn {cpx,cpo}
\NewDocumentCommand{\ProvidePolishAutoRefNames}{m}{%
\seq_set_from_clist:Nn \l_tmpa_seq {#1}
\seq_map_inline:Nn \l_tmpa_seq {% Loop through names
\seq_set_split:Nnn \l_tmpb_seq {=} {##1}
\tl_set:Nx \l_tmpa_tl {\seq_item:Nn \l_tmpb_seq {1} autorefname}
\int_compare:nNnTF {\seq_count:N \l_tmpb_seq } > {1} {% Check whether there is a "=", if so, use the RHS
\cs_gset:cpx {\l_tmpa_tl} {\seq_item:Nn \l_tmpb_seq {2}}
}{% No, try to evaluate \##1name, e.g. \chaptername
\cs_gset:cpx {\l_tmpa_tl} {\use:c{\seq_item:Nn \l_tmpb_seq {1}name}}
}
}
}
\ExplSyntaxOff

\usepackage{hyperref}

\makeatletter
\def\HyLang@polish{
\ProvidePolishAutoRefNames{figure=\figurename,chapter,section={PolishSectionName},table,equation={PolishEquationName}}
}

\HyLang@DeclareLang{polish}{polish}{}

\makeatother

\begin{document}

\chapter{Foo chapter}\label{foochapter}

\section{foo}

\figureautorefname

\label{sec:here}

\begin{figure}
\caption{\label{fig:here} This is a figure caption}
\end{figure}

$$E=mc^{2} \label{fooequation}$$

See \autoref{foochapter} or \autoref{fooequation}

\autoref{sec:here}

\autoref{fig:here}
\end{document}