我想要一个可以在两种语言之间进行选择并使用 cleveref 的文档。但是 cleveref 确实不是支持第二种语言nynorsk
。我仍然希望能够使用英文版本,所以我不能简单地使用\crefname
重新定义名称。以下是一个例子(请注意,cref 以英文提供):
\documentclass[5p,a4paper]{elsarticle}
\usepackage[english,nynorsk]{babel}
\usepackage{hyperref}
\usepackage[english,nynorsk]{cleveref}
\usepackage{appendix}
\begin{document}
\selectlanguage{nynorsk} % Switch between english and nynorsk
\begin{equation}
E=mc^2 \label{eq:E=mc}
\end{equation}
\Cref{eq:E=mc}
\appendix
\section{A} % To check that current language option is working.
\end{document}
我的问题是:如何定义语言的 cref 名称 nynorsk
同时仍然可以使用英文版本吗?
我在考虑是否可以使用 if 语句来检查所选语言是否正确nynorsk
,如果正确,则使用适当的名称。我还在考虑向cleveref
软件包的维护者发送一封电子邮件,其中包含文件包含此语言的适当代码.sty
(作为长期解决方案)。
答案1
如果您使用 的接口来定义特定于语言的定义,您几乎不需要自己进行任何语言检查cleveref
。此接口是内部的且未记录在案,因此理论上未来版本可能会出现问题,因此我仅建议将其用于测试和短期。中长期解决方案是联系维护者并要求他直接nynorsk
在包中包含 的语言支持。
例如,我只是将语言定义从 复制norsk
到nynorsk
,因此您必须自己翻译这些术语。
\documentclass[5p,a4paper,nynorsk,english]{elsarticle}
\usepackage{babel}
\usepackage{hyperref}
\usepackage{cleveref}
\usepackage{appendix}
\makeatletter
\cref@addlanguagedefs{nynorsk}{%
\PackageInfo{cleveref}{loaded `nynorsk' language definitions}%
\renewcommand{\crefrangeconjunction}{ til\nobreakspace}%
\renewcommand\crefrangepreconjunction{}%
\renewcommand\crefrangepostconjunction{}%
\renewcommand{\crefpairconjunction}{ og\nobreakspace}%
\renewcommand{\crefmiddleconjunction}{, }%
\renewcommand{\creflastconjunction}{ og\nobreakspace}%
\renewcommand{\crefpairgroupconjunction}{ og\nobreakspace}%
\renewcommand{\crefmiddlegroupconjunction}{, }%
\renewcommand{\creflastgroupconjunction}{ og\nobreakspace}%
%
\Crefname{equation}{Likning}{Likningene}%
\Crefname{figure}{Figur}{Figurene}%
\Crefname{subfigure}{Figur}{Figurene}%
\Crefname{table}{Tabell}{Tabellene}%
\Crefname{subtable}{Tabell}{Tabellene}%
\Crefname{page}{Side}{Siden}%
\Crefname{part}{Del}{Delene}%
\Crefname{chapter}{Kapittel}{Kapitlene}%
\Crefname{section}{Avsnitt}{Avsnittene}%
\Crefname{subsection}{Avsnitt}{Avsnittene}%
\Crefname{subsubsection}{Avsnitt}{Avsnittene}%
\Crefname{appendix}{Tillegg}{Tilleggene}%
\Crefname{subappendix}{Tillegg}{Tilleggene}%
\Crefname{subsubappendix}{Tillegg}{Tilleggene}%
\Crefname{subsubsubappendix}{Tillegg}{Tilleggene}%
\Crefname{enumi}{Punkt}{Punktene}%
\Crefname{enumii}{Punkt}{Punktene}%
\Crefname{enumiii}{Punkt}{Punktene}%
\Crefname{enumiv}{Punkt}{Punktene}%
\Crefname{enumv}{Punkt}{Punktene}%
\Crefname{footnote}{Fotnote}{Fotnotene}%
\Crefname{theorem}{Teorem}{Teoremene}%
\Crefname{lemma}{Lemma}{Lemma}%
\Crefname{corollary}{Korollar}{Korollarene}%
\Crefname{proposition}{P\aa stand}{P\aa standene}%
\Crefname{definition}{Definisjon}{Definisjonene}%
\Crefname{result}{Resultat}{Resultatene}%
\Crefname{example}{Eksempel}{Eksemplene}%
\Crefname{remark}{Bemerkning}{Bemerkningene}%
\Crefname{note}{Note}{Notene}%
\Crefname{algorithm}{Algoritme}{Algoritmene}%
\Crefname{listing}{Opplisting}{Opplistingene}%
\Crefname{line}{Linje}{Linjene}%
%
\if@cref@capitalise%
\crefname{equation}{Likning}{Likningene}%
\crefname{figure}{Figur}{Figurene}%
\crefname{subfigure}{Figur}{Figurene}%
\crefname{table}{Tabell}{Tabellene}%
\crefname{subtable}{Tabell}{Tabellene}%
\crefname{page}{Side}{Siden}%
\crefname{part}{Del}{Delene}%
\crefname{chapter}{Kapittel}{Kapitlene}%
\crefname{section}{Avsnitt}{Avsnittene}%
\crefname{subsection}{Avsnitt}{Avsnittene}%
\crefname{subsubsection}{Avsnitt}{Avsnittene}%
\crefname{appendix}{Tillegg}{Tilleggene}%
\crefname{subappendix}{Tillegg}{Tilleggene}%
\crefname{subsubappendix}{Tillegg}{Tilleggene}%
\crefname{subsubsubappendix}{Tillegg}{Tilleggene}%
\crefname{enumi}{Punkt}{Punktene}%
\crefname{enumii}{Punkt}{Punktene}%
\crefname{enumiii}{Punkt}{Punktene}%
\crefname{enumiv}{Punkt}{Punktene}%
\crefname{enumv}{Punkt}{Punktene}%
\crefname{footnote}{Fotnote}{Fotnotene}%
\crefname{theorem}{Teorem}{Teoremene}%
\crefname{lemma}{Lemma}{Lemma}%
\crefname{corollary}{Korollar}{Korollarene}%
\crefname{proposition}{P\aa stand}{P\aa standene}%
\crefname{definition}{Definisjon}{Definisjonene}%
\crefname{result}{Resultat}{Resultatene}%
\crefname{example}{Eksempel}{Eksemplene}%
\crefname{remark}{Bemerkning}{Bemerkningene}%
\crefname{note}{Note}{Notene}%
\crefname{algorithm}{Algoritme}{Algoritmene}%
\crefname{listing}{Opplisting}{Opplistingene}%
\crefname{line}{Linje}{Linjene}%
%
\else%
\crefname{equation}{likning}{likningene}%
\crefname{figure}{figur}{figurene}%
\crefname{subfigure}{figur}{figurene}%
\crefname{table}{tabell}{tabellene}%
\crefname{subtable}{tabell}{tabellene}%
\crefname{page}{side}{siden}%
\crefname{part}{del}{delene}%
\crefname{chapter}{kapittel}{kapitlene}%
\crefname{section}{avsnitt}{avsnittene}%
\crefname{subsection}{avsnitt}{avsnittene}%
\crefname{subsubsection}{avsnitt}{avsnittene}%
\crefname{appendix}{tillegg}{tilleggene}%
\crefname{subappendix}{tillegg}{tilleggene}%
\crefname{subsubappendix}{tillegg}{tilleggene}%
\crefname{subsubsubappendix}{tillegg}{tilleggene}%
\crefname{enumi}{punkt}{punktene}%
\crefname{enumii}{punkt}{punktene}%
\crefname{enumiii}{punkt}{punktene}%
\crefname{enumiv}{punkt}{punktene}%
\crefname{enumv}{punkt}{punktene}%
\crefname{footnote}{fotnote}{fotnotene}%
\crefname{theorem}{teorem}{teoremene}%
\crefname{lemma}{lemma}{lemma}%
\crefname{corollary}{korollar}{korollarene}%
\crefname{proposition}{p\aa stand}{p\aa standene}%
\crefname{definition}{definisjon}{definisjonene}%
\crefname{result}{resultat}{resultatene}%
\crefname{example}{eksempel}{eksemplene}%
\crefname{remark}{bemerkning}{bemerkningene}%
\crefname{note}{note}{notene}%
\crefname{algorithm}{algoritme}{algoritmene}%
\crefname{listing}{opplisting}{opplistingene}%
\crefname{line}{linje}{linjene}%
\fi}% end \cref@loadlanguagedefs
\makeatother
\begin{document}
\Cref{eq:E=mc}
\selectlanguage{nynorsk} % Switch between english and nynorsk
\begin{equation}
E=mc^2 \label{eq:E=mc}
\end{equation}
\Cref{eq:E=mc}
\appendix
\section{A} % To check that current language option is working.
\end{document}
有一个警告。由于语言选项的实施,如果新语言是文档的主要语言,则无法正常工作。在这种情况下,在之后直接将语言明确切换为主要语言会有所帮助。不过,这只是一个小问题,一旦开箱即用地支持您的语言,\begin{document}
它就不再重要了。cleveref