
我正在嘗試使用乳膠用波蘭語寫一些東西。我正在將babel
包與hyperref
.我以為這就夠了,但顯然還不夠。
\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}
這會產生:
正如您所看到的,圖標題是用波蘭語正確書寫的,但自動引用仍然是英語。
我想這應該是一些簡單的事情。例如,問題使用 babel 的 `main=` 功能時,自動引用名稱錯誤表明上述應該工作。我在 stackexchange 或 google 上找到的所有其他材料都集中在比我描述的更具體的用途。
那麼,我錯過了什麼?
我知道的一個可能的解決方法是通過 手動定義所有這些名稱\def\figureautorefname
,但我希望有人已經在公共包中做到了這一點,並且得到了適當的維護。
答案1
不幸的是,巨Polish
集中沒有定義對語言的支援。hyperref
\...autorefname
hyperref
english,afrikaans,french,german,spanish,catalan,portuges,magyar, russian,italian,vietnamese
截至 2017/03/14 的 6.85a 版本,尚支援。
嘗試解決方案:
宏觀
\ProvidePolishAutoRefNames{figure=\figurename,chapter,section={PolishSectionName},table,equation={PolishEquationName}}
循環遍歷以逗號分隔的清單中給出的計數器名稱並\##1autorefname
動態產生。
如果figure=\figurename
給出,它使用來自 etc 的名稱,如果只給出\figurename
計數器名稱,它會嘗試使用,它在任何情況下都沒有定義。X
\Xname
由於我不會說波蘭語,因此我使用PolishSectionName
等作為替代。
\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}
\addto\captionspolish{%
\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}
\begin{equation}
E=mc^{2} \label{fooequation}
\end{equation}
See \autoref{foochapter} or \autoref{fooequation}
\autoref{sec:here}
\autoref{fig:here}
\end{document}
類似的版本,透過\HyLang@polish
類似地定義HyLang@french
等。
\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}
\begin{equation}
E=mc^{2} \label{fooequation}
\end{equation}
See \autoref{foochapter} or \autoref{fooequation}
\autoref{sec:here}
\autoref{fig:here}
\end{document}