我刚刚尝试了 main=<language>
包选项babel
,发现它似乎与不能很好地hyperref
兼容\autoref
。
使用传统语法效果很好:
\documentclass{scrartcl}
\usepackage[english,ngerman]{babel}
\usepackage{hyperref}
\begin{document}
\section{Test}
\label{sec:test}
\autoref{sec:test}
\end{document}
该main=
版本没有:
\documentclass{scrartcl}
\usepackage[english,main=ngerman]{babel}
\usepackage{hyperref}
\begin{document}
\section{Test}
\label{sec:test}
\autoref{sec:test}
\end{document}
无法解决这个问题的方法
- 使用
\setmainlanguage
缓解问题的方法(但看起来像黑客手段)
- 使用“旧”形式(显然)
- 用一个文档“旧”形式的选择
处理这个问题的最佳方法是什么?
编辑:更准确地说,hyperref
当我无法更改文档选项或 babel 的选项时,我该做些什么来解决这个问题?
答案1
该hyperref
软件包只是寻找没有的语言选项main=
,但它现在应该babel
正式支持这一点。
这是一个 hack,从某种意义上说,代码(可能更短)应该进入hyperref.sty
。
\documentclass{scrartcl}
\usepackage[english,main=ngerman]{babel}
\usepackage{hyperref}
\makeatletter
\def\HyLang@DeclareLang#1#2#3{%
\@ifpackagewith{babel}{#1}{%
\expandafter\HyLang@addto
\csname extras#1\expandafter\endcsname
\csname HyLang@#2\endcsname
\begingroup
\edef\x{\endgroup
#3%
}%
\x
\@namedef{HyLang@#1@done}{}%
}{% added check for "main=#1" (presumably Heiko can do better)
\@ifpackagewith{babel}{main=#1}{%
\expandafter\HyLang@addto
\csname extras#1\expandafter\endcsname
\csname HyLang@#2\endcsname
\begingroup
\edef\x{\endgroup
#3%
}%
\x
\@namedef{HyLang@#1@done}{}%
}{}%
}%
\begingroup
\edef\x##1##2{%
\noexpand\ifx##2\relax
\errmessage{No definitions for language #2' found!}%
\noexpand\fi
\endgroup
\noexpand\define@key{Hyp}{#1}[]{%
\noexpand\@ifundefined{HyLang@#1@done}{%
\noexpand\HyLang@addto{\noexpand##1}{\noexpand##2}%
#3%
\noexpand\@namedef{HyLang@#1@done}{}%
}{}%
}%
}%
\expandafter\x\csname extras#1\expandafter\endcsname
\csname HyLang@#2\endcsname
}
% repeat the known language declarations
\HyLang@DeclareLang{english}{english}{}
\HyLang@DeclareLang{UKenglish}{english}{}
\HyLang@DeclareLang{british}{english}{}
\HyLang@DeclareLang{USenglish}{english}{}
\HyLang@DeclareLang{american}{english}{}
\HyLang@DeclareLang{german}{german}{}
\HyLang@DeclareLang{austrian}{german}{}
\HyLang@DeclareLang{ngerman}{german}{}
\HyLang@DeclareLang{naustrian}{german}{}
\HyLang@DeclareLang{russian}{russian}{\noexpand\hypersetup{unicode}}
\HyLang@DeclareLang{brazil}{portuges}{}
\HyLang@DeclareLang{brazilian}{portuges}{}
\HyLang@DeclareLang{portuguese}{portuges}{}
\HyLang@DeclareLang{spanish}{spanish}{}
\HyLang@DeclareLang{afrikaans}{afrikaans}{}
\HyLang@DeclareLang{french}{french}{}
\HyLang@DeclareLang{frenchb}{french}{}
\HyLang@DeclareLang{francais}{french}{}
\HyLang@DeclareLang{acadian}{french}{}
\HyLang@DeclareLang{canadien}{french}{}
\HyLang@DeclareLang{italian}{italian}{}
\HyLang@DeclareLang{magyar}{magyar}{}
\HyLang@DeclareLang{hungarian}{magyar}{}
\makeatother
\begin{document}
\section{Test}
\label{sec:test}
\autoref{sec:test}
\end{document}