如何获取 Babel 加载的语言编号列表

如何获取 Babel 加载的语言编号列表

在过去的美好时光里,Babel 曾经提供已加载语言的列表:

LaTeX2e <2011/06/27>
Babel <v3.8m> and hyphenation patterns for american, french, loaded.

升级到 TeXLive 2016 后,现在我只得到这个:

LaTeX2e <2016/03/31> patch level 2
Babel <3.9r> and hyphenation patterns for 53 language(s) loaded.

有没有办法返回到以前的系统并按加载顺序获取语言列表?我将不胜感激。

原因是,我\language在某些情况下手动使用标识符(\language=13例如,切换到语言 13)。当然,我知道标识符\language可以从一种格式编译更改为另一种格式编译,并且我“通常”不应该使用它。但我想自行承担风险,在自己的系统中为自己的文档使用它,如果 babel 允许我获得这些非常有价值的信息,我将不胜感激。因此,如果我可以对 babel 代码进行一些更改以恢复该信息,请告诉我。

答案1

如果您只是想知道已加载了哪些语言,这很简单:

\usepackage[english,showlanguages]{babel}

然后只需查看日志文件。

答案2

babel 格式还将语言列表存储在 中\bbl@languages。它们存储的格式如下:

\bbl@elt{<language name>}{<number>}{<pattern file or empty for alias name>}{<empty>}

应用示例:

\documentclass{article}
\usepackage[
  a4paper,
  vmargin=10mm,
  includefoot,
]{geometry}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{lmodern}
\renewcommand*{\familydefault}{\sfdefault}
\begin{document}

  \makeatletter
  \@ifundefined{bbl@languages}{
    \emph{The language/pattern list of babel is not available.}
  }{
    \section*{The language/pattern list of babel}
    \def\bbl@elt#1#2#3#4{%
      \ifx\PrevNumber\relax
      \else
        \ifnum\PrevNumber=#2 %
        \else
          \midrule
        \fi
      \fi
      \gdef\PrevNumber{#2}%
      \typeout{* #2 #1\ifx\relax#3\relax\else\space(#3)\fi}%
      #2&#1&\texttt{#3}\\%
    }
    \global\let\PrevNumber\relax
    \begin{longtable}[l]{rll}
      \bbl@languages
    \end{longtable}
  }
  \makeatother

\end{document}

终端显示:

Babel <3.9r> and hyphenation patterns for 81 language(s) loaded.

* 0 english (hyphen.tex)
(/cygdrive/c/Users/one/tl/tldevsrc/Master/texmf-dist/tex/latex/lm/ot1lmtt.fd)
* 0 usenglish
* 0 USenglish
* 0 american
* 1 dumylang (dumyhyph.tex)
* 2 nohyphenation (zerohyph.tex)
* 3 german-x-2014-05-21 (dehypht-x-2014-05-21.tex)
* 3 german-x-latest
* 4 ngerman-x-2014-05-21 (dehyphn-x-2014-05-21.tex)
* 4 ngerman-x-latest
* 5 afrikaans (loadhyph-af.tex)
* 6 ancientgreek (loadhyph-grc.tex)
* 7 ibycus (ibyhyph.tex)
* 8 arabic (zerohyph.tex)
* 9 armenian (loadhyph-hy.tex)
* 10 basque (loadhyph-eu.tex)
* 11 bulgarian (loadhyph-bg.tex)
* 12 catalan (loadhyph-ca.tex)
* 13 pinyin (loadhyph-zh-latn-pinyin.tex)
* 14 coptic (loadhyph-cop.tex)
* 15 croatian (loadhyph-hr.tex)
* 16 czech (loadhyph-cs.tex)
* 17 danish (loadhyph-da.tex)
* 18 dutch (loadhyph-nl.tex)
* 19 ukenglish (loadhyph-en-gb.tex)
* 19 british
* 19 UKenglish
* 20 usenglishmax (loadhyph-en-us.tex)
* 21 esperanto (loadhyph-eo.tex)
* 22 estonian (loadhyph-et.tex)
* 23 ethiopic (loadhyph-mul-ethi.tex)
* 23 amharic
* 23 geez
* 24 farsi (zerohyph.tex)
* 24 persian
* 25 finnish (loadhyph-fi.tex)
* 26 french (loadhyph-fr.tex)
* 26 patois
* 26 francais
* 27 friulan (loadhyph-fur.tex)
* 28 galician (loadhyph-gl.tex)
* 29 georgian (loadhyph-ka.tex)
* 30 german (loadhyph-de-1901.tex)
* 31 ngerman (loadhyph-de-1996.tex)
* 32 swissgerman (loadhyph-de-ch-1901.tex)
...
* 80 welsh (loadhyph-cy.tex)

排版结果第一页:

结果,第 1 页

答案3

我可以提供以下代码,language.dat在必要时读取并执行计数器:

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn

\DeclareExpandableDocumentCommand{\getlanguagenumber}{m}
 {
  \prop_item:Nn \g_yannis_language_list_prop { #1 }
 }

\NewDocumentCommand{\listlanguages}{}
 {
  \prop_map_inline:Nn \g_yannis_language_list_prop
   {
    ##1~=~##2 \par
   }
 }

\ior_new:N \yannis_language_file_stream
\int_new:N \g_yannis_language_number_int
\prop_new:N \g_yannis_language_list_prop

\int_gset:Nn \g_yannis_language_number_int { -1 } % first language is 0

\cs_new_protected:Nn \yannis_language_number:
 {
  \ior_open:Nn \yannis_language_file_stream { language.dat }
  \ior_map_inline:Nn \yannis_language_file_stream
   {
    % check if an empty line slipped in, otherwise go on
    \tl_if_blank:nF { ##1 }
     {
      \__yannis_language_read:f { \tl_trim_spaces:n { ##1 } }
     }
   }
 }

\cs_new_protected:Nn \__yannis_language_read:n
 {
  \peek_charcode_remove:NTF =
   { \__yannis_language_alias:w } % if the line begins with =
   { \__yannis_language_real:w }  % normal language
   #1 \q_stop % the line contents and a terminator
 }
\cs_generate_variant:Nn \__yannis_language_read:n { f }

\cs_new_protected:Npn \__yannis_language_alias:w #1 \q_stop
 {
  \typeout { #1~=~\int_eval:n { \g_yannis_language_number_int } }
  \prop_gput:Nnx \g_yannis_language_list_prop
   { #1 }
   { \int_eval:n { \g_yannis_language_number_int } }
 }

\cs_new_protected:Npn \__yannis_language_real:w #1 ~ #2 \q_stop
 {
  \int_gincr:N \g_yannis_language_number_int
  \typeout { #1~=~\int_eval:n { \g_yannis_language_number_int } }
  \prop_gput:Nnx \g_yannis_language_list_prop
   { #1 }
   { \int_eval:n { \g_yannis_language_number_int } }
 }

%% make the list; need to make the space a space
\AtBeginDocument{ \yannis_language_number: }

\ExplSyntaxOff

\begin{document}

\listlanguages

Welsh is \getlanguagenumber{welsh}

\end{document}

您也可以说\language=\getlanguagenumber{italian}(尽管这样做会更简单\language=\csname l@italian\endcsname)。

没有必要这么做\listlanguages,因为终端上打印了相同的信息。

english = 0
usenglish = 0
USenglish = 0
american = 0
dumylang = 1
nohyphenation = 2
german-x-2014-05-21 = 3
german-x-latest = 3
ngerman-x-2014-05-21 = 4
ngerman-x-latest = 4
afrikaans = 5
ancientgreek = 6
ibycus = 7
arabic = 8
armenian = 9
basque = 10
[...]
thai = 77
turkish = 78
turkmen = 79
ukrainian = 80
uppersorbian = 81
welsh = 82

同意

LaTeX2e <2016/03/31> patch level 3
Babel <3.9r> and hyphenation patterns for 83 language(s) loaded.

在启动时发出。

复杂吗?嘿,使用旧设置时,您必须手动计数并忽略别名!;-)

相关内容