Using pdflatex
and babel
I have this code (taken from the answer to this question) to redefine the way \autoref
from the hyperref
package prints my references, it also adds automatically the respective page number of the referenced content:
\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\addto\extrasngerman{
\def\subsectionautorefname{Abschnitt} % subsection autoref -> Abschnitt ...
\def\subsubsectionautorefname{Abschnitt} % subsubsection autoref -> Abschnitt ...
\def\pageautorefname{S.}} % Was vor der Seitenzahl in der Klammer der Referenz steht
\let\oldautoref\autoref
\renewcommand{\autoref}[1]{\oldautoref{#1} (\autopageref{#1})} % autoref prints respective pagenumber
% No pagenumber if the reference is on the same page
\usepackage{ifthen}
\newcounter{cPage}
\renewcommand{\autoref}[1]{\oldautoref{#1}%
\refstepcounter{cPage}\label{current\thecPage}%
\ifthenelse{\equal{\pageref{#1}}{\pageref{current\thecPage}}}%
{}{~(\autopageref{#1})}}
\begin{document}
\section{Einleitung}\label{sec:intro}
\newpage
Text. \autoref{sec:intro}
\end{document}
Using XeLaTeX
and therefore polyglossia
instead of babel
, how would I go about adapting this code to achieve the same output? Is it possible?
MWE (for XeLaTeX
):
\documentclass{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage[]{german}
\usepackage[german]{hyperref}
\addto\extrasngerman{
\def\subsectionautorefname{Abschnitt} % subsection autoref -> Abschnitt ...
\def\subsubsectionautorefname{Abschnitt} % subsubsection autoref -> Abschnitt ...
\def\pageautorefname{S.}} % Was vor der Seitenzahl in der Klammer der Referenz steht
\let\oldautoref\autoref
\renewcommand{\autoref}[1]{\oldautoref{#1} (\autopageref{#1})} % autoref druckt automatisch die zugehörige Seitenzahl
% No pagenumber if the reference is on the same page
\usepackage{ifthen}
\newcounter{cPage}
\renewcommand{\autoref}[1]{\oldautoref{#1}%
\refstepcounter{cPage}\label{current\thecPage}%
\ifthenelse{\equal{\pageref{#1}}{\pageref{current\thecPage}}}%
{}{~(\autopageref{#1})}}
\begin{document}
\section{Einleitung}\label{sec:intro}
\newpage
Text. \autoref{sec:intro}
\end{document}
polyglossia
what can I do withbabel
’ are based on the assumptionbabel
cannot be used withxelatex
orlualatex
.