texlive[54930] Master/texmf-dist: babel (28apr20)

commits+karl at tug.org commits+karl at tug.org
Tue Apr 28 23:14:00 CEST 2020


Revision: 54930
          http://tug.org/svn/texlive?view=revision&revision=54930
Author:   karl
Date:     2020-04-28 23:14:00 +0200 (Tue, 28 Apr 2020)
Log Message:
-----------
babel (28apr20)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/babel/README.md
    trunk/Master/texmf-dist/doc/latex/babel/babel.pdf
    trunk/Master/texmf-dist/source/latex/babel/babel.dtx
    trunk/Master/texmf-dist/source/latex/babel/babel.ins
    trunk/Master/texmf-dist/source/latex/babel/bbcompat.dtx
    trunk/Master/texmf-dist/source/latex/babel/locale.zip
    trunk/Master/texmf-dist/tex/generic/babel/babel-bidi-basic-r.lua
    trunk/Master/texmf-dist/tex/generic/babel/babel-bidi-basic.lua
    trunk/Master/texmf-dist/tex/generic/babel/babel-data-bidi.lua
    trunk/Master/texmf-dist/tex/generic/babel/babel-data-cjk.lua
    trunk/Master/texmf-dist/tex/generic/babel/babel.def
    trunk/Master/texmf-dist/tex/generic/babel/babel.sty
    trunk/Master/texmf-dist/tex/generic/babel/blplain.tex
    trunk/Master/texmf-dist/tex/generic/babel/bplain.tex
    trunk/Master/texmf-dist/tex/generic/babel/hyphen.cfg
    trunk/Master/texmf-dist/tex/generic/babel/locale/as/babel-as.ini
    trunk/Master/texmf-dist/tex/generic/babel/locale/bn/babel-bn.ini
    trunk/Master/texmf-dist/tex/generic/babel/locale/fi/babel-fi.ini
    trunk/Master/texmf-dist/tex/generic/babel/locale/hy/babel-hy.ini
    trunk/Master/texmf-dist/tex/generic/babel/locale/lb/babel-lb.ini
    trunk/Master/texmf-dist/tex/generic/babel/locale/mr/babel-mr.ini
    trunk/Master/texmf-dist/tex/generic/babel/luababel.def
    trunk/Master/texmf-dist/tex/generic/babel/nil.ldf
    trunk/Master/texmf-dist/tex/generic/babel/plain.def
    trunk/Master/texmf-dist/tex/generic/babel/switch.def
    trunk/Master/texmf-dist/tex/generic/babel/txtbabel.def
    trunk/Master/texmf-dist/tex/generic/babel/xebabel.def

Modified: trunk/Master/texmf-dist/doc/latex/babel/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/latex/babel/README.md	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/doc/latex/babel/README.md	2020-04-28 21:14:00 UTC (rev 54930)
@@ -1,4 +1,4 @@
-## Babel 3.42
+## Babel 3.43
 
 This package manages culturally-determined typographical (and other)
 rules, and hyphenation patterns for a wide range of languages.  Many
@@ -7,9 +7,9 @@
 
 The latest stable version is available on <https://ctan.org/pkg/babel>.
 
-Changes in version 3.42 are described in:
+Changes in version 3.43 are described in:
 
-https://github.com/latex3/babel/wiki/What's-new-in-babel-3.42
+https://github.com/latex3/babel/wiki/What's-new-in-babel-3.43
 
 Included is a set of ini files for about 200 languages.
 
@@ -44,6 +44,18 @@
 ### Latest changes
 
 ```
+3.43   2020-04-28
+       - Autoloading based on the BCP47 codes, with basic lookup.
+       - Now only a few essential commands are loaded in the format.
+       - Improvements in Assamese, Luxembourgish, Marathi, Armenian,
+         Bengali, and Finnish.
+       - First steps in the removal of switch.def and plain.def.
+       - Fixes:
+         - Babel reset the \sfcode of » to 1000. It should be 0.
+         - \guillemotleft and \guillemotleft renamed to \guillemetleft
+           and \guillemetleft (#63).
+         - A couple of bugs related to autoloading.
+       
 3.42   2020-03-22
        - \getlocaleproperty, to get the value of a field from the loaded
          ini files.
@@ -60,6 +72,7 @@
            (#52). 
          - Locale was not switched correctly with COMBINING characters
            (#54).
+See https://github.com/latex3/babel/wiki/What's-new-in-babel-3.42
            
 3.41   2020-02-27
        - Counters and numerals added in some ini files, based on those
@@ -145,30 +158,6 @@
        - Basic support for the picture environment (with pict2e) and pgf
          (lua, somewhat experimental).
        - Start support for harftex (just try - it may work).
-
-3.31   2019-05-04
-       - Basic support for line breaking with CJK scripts (lua)
-       - layout=tabular now works with the 'array' package (and some
-         others; lua).
-
-3.30   2019-04-22
-       - Fix - dir in boxes inside math (hopefully now it works; lua).
-       - Option mapdigits for \babelprovide, which converts European
-         digits to local ones (lua).
-
-3.29    2019-04-03
-       - The fix for boxes inside math is incompatible with ams.
-         Removed (a better fix is under study).
-       - Options bidi-l and bidi-r (for the bidi package; xe).
-
-3.28    2019-04-01
-       - Fixes - wrong dir after math, in math inside tabular, in weak L
-         inside R inside L, and in boxes inside math.
-       - \babelfont now takes into account \defaultfontfeatures. This
-         is a potential source of backwards incompatibilities, but
-         very likely the risks are very low, and it is, I think, the
-         expected behavior.
-
 ```
 
 Javier Bezos

Modified: trunk/Master/texmf-dist/doc/latex/babel/babel.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/source/latex/babel/babel.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/babel/babel.dtx	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/source/latex/babel/babel.dtx	2020-04-28 21:14:00 UTC (rev 54930)
@@ -31,7 +31,7 @@
 %
 % \iffalse
 %<*filedriver>
-\ProvidesFile{babel.dtx}[2020/03/22 v3.42 The Babel package]
+\ProvidesFile{babel.dtx}[2020/04/28 v3.43 The Babel package]
 \documentclass{ltxdoc}
 \GetFileInfo{babel.dtx}
 \usepackage{fontspec}
@@ -217,10 +217,10 @@
 \fontsize{35}{45}\selectfont
 \setlength\parskip{3mm}\raggedright
 Localization and internationalization\\[1cm]
+Unicode\\
 \largetex\\
 pdf\largetex\\
 Lua\largetex\\
-LuaHB\largetex\\
 Xe\largetex
  \vspace{20cm}
 \end{minipage}
@@ -245,15 +245,16 @@
   most recent features could be still unstable. Please, report any
   issues you find in
   \href{https://github.com/latex3/babel/issues}{GitHub}, which is
-  better than just complaining on an e-mail list or a web forum. 
+  better than just complaining on an e-mail list or a web forum.
 
 \item If you are interested in the \TeX{} multilingual support, please
-  join the  \href{http://tug.org/mailman/listinfo/kadingira}{kadingira
-  mail list}. You can follow
-  the development of \babel{} in
+  join the \href{http://tug.org/mailman/listinfo/kadingira}{kadingira
+  mail list}. You can follow the development of \babel{} in
   \href{https://github.com/latex3/babel}{GitHub} (which provides many
   \href{https://github.com/latex3/babel/tree/master/samples}{sample
-  files}, too).
+  files}, too). If you are the author of a package, feel free to send
+  to me a few test files which I'll add to mine, so that possible
+  issues could be caught in the development phase.
 
 \item  See section \ref{contribute} for contributing a language.
 
@@ -623,8 +624,10 @@
 \begin{note}
   For ``historical reasons'', a macro name is converted to a language
   name without the leading |\|; in other words,
-  |\selectlanguage{\german}| is equivalent to |\selectlanguage{german}|.
-  Using a macro instead of a ``real'' name is deprecated.
+  |\selectlanguage{\german}| is equivalent to
+  |\selectlanguage{german}|. Using a macro instead of a ``real'' name
+  is deprecated. \New{3.43} However, if the macro name does not match
+  any language, it will get expanded as expected.
 \end{note}
 
 \begin{warning}
@@ -919,7 +922,7 @@
   words are repeated at the beginning of the next line. You could then
   set:
 \begin{verbatim}
-\defineshorthand[*polish,*portugese]{"-}{\babelhyphen{repeat}}
+\defineshorthand[*polish,*portuguese]{"-}{\babelhyphen{repeat}}
 \end{verbatim}
   Here, options with |*| set a language-dependent user shorthand,
   which means the generic one above only applies for the rest of
@@ -1144,7 +1147,7 @@
 and the like (this feature misuses some internal \LaTeX\ tools, so use
 it only as a last resort).
 
-\Describe{hyphenmap=}{\texttt{off} $\string|$ \texttt{main}
+\Describe{hyphenmap=}{\texttt{off} $\string|$ \texttt{first}
 $\string|$ \texttt{select} $\string|$ \texttt{other} $\string|$
 \texttt{other*}}
 
@@ -1225,6 +1228,11 @@
 \end{verbatim}
 \end{example}
 
+\begin{warning}
+  Currently this option is not compatible with languages loaded on the
+  fly.
+\end{warning}
+
 \subsection{\texttt{ini} files}
 
 An alternative approach to define a language (or, more precisely, a
@@ -1285,25 +1293,26 @@
   \textsf{fontspec}/\textsf{loaotfload} is required. In \xetex{}
   \babel{} resorts to the \textsf{bidi} package, which seems to work.
 \item[Hebrew] Niqqud marks seem to work in both engines, but
-  cantillation marks are misplaced (\xetex{} seems better, but still
-  problematic).
-\item[Devanagari] In \luatex{} many fonts work, but some others do
-  not, the main issue being the ‘ra’. It is advisable to set explicitly
-  the script to either |deva| or |dev2|, eg:
+  cantillation marks are misplaced (\xetex{} or \luatex{} with Harfbuzz
+  seems better, but still problematic).
+\item[Devanagari] In \luatex{} and the the default renderer many fonts
+work, but some others do not, the main issue being the ‘ra’. It is
+advisable to set explicitly the script to either |deva| or |dev2|, eg:
 \begin{verbatim}
 \newfontscript{Devanagari}{deva}
 \end{verbatim}  
-  Other Indic scripts are still under development in \luatex{}. On the
-  other hand, \xetex{} is better. The upcoming \textsf{lualatex} will
-  be based on \textsf{luahbtex}, so Indic scripts will be rendered
-  correctly with the option |Renderer=Harfbuzz| in \textsc{fontspec}.
+  Other Indic scripts are still under development in the default
+  \luatex{} renderer, but should work with the option
+  |Renderer=Harfbuzz| in \textsc{fontspec}. They also work with
+  \xetex{}, although fine tuning the font behaviour is not always
+  possible.
 \item[Southeast scripts] Thai works in both \luatex{} and \xetex{}, but
   line breaking differs (rules can be modified in \luatex; they are
   hard-coded in \xetex). Lao seems to work, too, but there are no
   patterns for the latter in \luatex{}. Khemer clusters are rendered
-  wrongly. The comment about Indic scripts and \textsf{lualatex} also
-  applies here. Some quick patterns could help, with something similar
-  to:
+  wrongly with the default renderer. The comment about Indic scripts
+  and \textsf{lualatex} also applies here. Some quick patterns could
+  help, with something similar to:
 \begingroup
 \setmonofont[Script=Lao,Scale=MatchLowercase]{DejaVu Sans Mono}
 \begin{verbatim}
@@ -1312,8 +1321,7 @@
 \end{verbatim}
 \endgroup
 \item[East Asia scripts] Settings for either Simplified of Traditional
-should work out of the box. \luatex{} does basic line breaking, but
-currently \xetex{} does not (you may load \textsf{zhspacing}). Although
+should work out of the box, with basic line breaking. Although
 for a few words and shorts texts the |ini| files should be fine, CJK
 texts are best set with a dedicated framework (\textsf{CJK},
 \textsf{luatexja}, \textsf{kotex}, \textsf{CTeX}, etc.). This is what
@@ -2502,7 +2510,7 @@
 
 \item[Hindi] |alphabetic|
 
-\item[Armenian] |lower|, |upper|
+\item[Armenian] |lower.letter|, |upper.letter|
 
 \item[Japanese] |hiragana|, |hiragana.iroha|, |katakana|,
 |katakana.iroha|, |circled.katakana|, |informal|, |formal|,
@@ -2781,6 +2789,68 @@
   |\babelprehyphenation| is on the way.)
 \end{example}
 
+\subsection{Selection based on BCP 47 tags}
+
+\New{3.43} The recommended way to select languages is that described at
+the beginning of this document. However, BCP 47 tags are becoming
+customary, particularly in document (or parts of documents) generated
+by external sources, and therefore \babel{} will provide a set of tools
+to select the locales in different situations, adapted to the
+particular needs of each case. Currently, \babel{} provides autoloading
+of locales as described in this section. In these contexts autoloading
+is particularly important because we may not know on beforehand which
+languages will be requested.
+
+It must be activated explicitly, because it is primarily meant for
+special tasks. Mapping from BCP 47 codes to locale names are not
+hardcoded in \babel. Instead the data is taken from the \texttt{ini}
+files, which means currently about 250 tags are already recognized.
+\Babel{} performs a simple lookup in the following way: |fr-Latn-FR| $\to$
+|fr-Latn| $\to$ |fr-FR| $\to$ |fr|. Languages with the same resolved
+name are considered the same. Case is normalized before, so that
+|fr-latn-fr| $\to$ |fr-Latn-FR|. If a tag and a name overlap, the tag
+takes precedence.
+
+Here is a minimal example:
+\begin{verbatim}
+\documentclass{article}
+
+\usepackage[danish]{babel}
+
+\babeladjust{ autoload.bcp47 = on }
+
+\begin{document}
+
+\today
+
+\selectlanguage{fr-CA}
+
+\today
+
+\end{document}
+\end{verbatim}
+
+Currently the locales loaded are based on the \texttt{ini} files and
+decoupled from the main \texttt{ldf} files. This is by design, to
+ensure code generated externally produces the same result regardless of
+the languages requested in the document, but an option to use the
+\texttt{ldf} instead will be added in a future release, because both
+options make sense depending on the particular needs of each document
+(there will be some restrictions, however).
+
+The behaviour is adjusted with |\babeladjust| with the following parameters:
+\begin{description}
+\item \texttt{autoload.bcp47} with values on and off.
+\item \texttt{autoload.bcp47.options}, which are passed to
+  |\babelprovide|; empty by default, but you may add \texttt{import}
+  (features defined in the corresponding |babel-...tex| file might not
+  available).
+\item \texttt{autoload.bcp47.prefix}. Although the public name used in
+  selectors is the tag, the internal name will be different and
+  generated by prepending a prefix, which by default is
+  \texttt{bcp47-}. You may change it with this key.
+\end{description}
+
 \subsection{Selecting scripts}
 
 Currently \babel{} provides no standard interface to select
@@ -3256,8 +3326,8 @@
 \itemsep=-\parskip
 \item[everylanguage] (language) Executed before every language patterns
   are loaded.
-\item[loadkernel] (file) By default loads |switch.def|. It can be used
-  to load a different version of this file or to load nothing.
+\item[loadkernel] (file) By default just defines a few basic commands.
+  It can be used to define different versions of them or to load a file.
 \item[loadpatterns] (patterns file) Loads the patterns file. Used by
   \file{luababel.def}.
 \item[loadexceptions] (exceptions file) Loads the exceptions
@@ -3301,17 +3371,19 @@
 \item[Greek] greek, polutonikogreek
 \item[Hebrew] hebrew
 \item[Icelandic] icelandic
-\item[Indonesian] bahasa, indonesian, indon, bahasai
+\item[Indonesian] indonesian, bahasa, indon, bahasai
 \item[Interlingua] interlingua
 \item[Irish Gaelic] irish
 \item[Italian] italian
 \item[Latin] latin
 \item[Lower Sorbian] lowersorbian
-\item[Malay] bahasam, malay, melayu
+\item[Malay] malay, melayu, bahasam
 \item[North Sami] samin
 \item[Norwegian] norsk, nynorsk
 \item[Polish] polish
-\item[Portuguese] portuges, portuguese, brazilian, brazil
+\item[Portuguese] portuguese, portuges\footnote{This name comes from
+  the times when they had to be shortened to 8 characters}, brazilian,
+  brazil
 \item[Romanian] romanian
 \item[Russian] russian
 \item[Scottish Gaelic] scottish
@@ -4388,6 +4460,9 @@
 %
 %    \textit{Code documentation is still under revision.}
 %
+%  \textbf{The following description is no longer valid, because switch
+%  and plain have been merged into babel.def.}
+%
 %    The \babel{} package after unpacking consists of the following files:
 %    \begin{description}
 %    \itemsep=-\parskip
@@ -4399,8 +4474,7 @@
 %  \item[plain.def] defines some \LaTeX{} macros required by
 %    \file{babel.def} and provides a few tools for Plain.
 %   \item[hyphen.cfg] is the file to be used when generating the
-%    formats to load hyphenation patterns. By default it also loads
-%    \file{switch.def}.
+%    formats to load hyphenation patterns.
 %    \end{description}
 %
 % The \babel{} installer extends \textsf{docstrip} with a few
@@ -4456,8 +4530,8 @@
 % \section{Tools}
 %
 %    \begin{macrocode}
-%<<version=3.42>>
-%<<date=2020/03/22>>
+%<<version=3.43>>
+%<<date=2020/04/28>>
 %    \end{macrocode}
 %
 % \textbf{Do not use the following macros in \texttt{ldf} files. They
@@ -4756,30 +4830,6 @@
 %<</Make sure ProvidesFile is defined>>
 %    \end{macrocode}
 %
-% The following code is used in \file{babel.sty} and
-% \file{babel.def}, and loads (only once) the data in |language.dat|.
-%
-%    \begin{macrocode}
-%<<*Load patterns in luatex>>
-\ifx\directlua\@undefined\else
-  \ifx\bbl at luapatterns\@undefined
-    \input luababel.def
-  \fi
-\fi
-%<</Load patterns in luatex>>
-%    \end{macrocode}
-%
-%    The following code is used in \file{babel.def} and
-%    \file{switch.def}.
-%
-%    \begin{macrocode}
-%<<*Load macros for plain if not LaTeX>>
-\ifx\AtBeginDocument\@undefined
-  \input plain.def\relax
-\fi
-%<</Load macros for plain if not LaTeX>>
-%    \end{macrocode}
-%
 % \subsection{Multiple languages}
 %
 %  \begin{macro}{\language}
@@ -4857,31 +4907,20 @@
 %    now. We cannot load |babel.def| here because we first need to
 %    declare and process the package options.
 %
-% \section{The Package File (\LaTeX, \texttt{babel.sty})}
 %
-%    In order to make use of the features of \LaTeXe, the \babel\
-%    system contains a package file, \file{babel.sty}. This file is
-%    loaded by the |\usepackage| command and defines all the language
-%    options whose name is different from that of the |.ldf| file
-%    (like variant spellings). It also takes care of a number of
-%    compatibility issues with other packages an defines a few
-%    aditional package options.
+% \subsection{The Package File (\LaTeX, \texttt{babel.sty})}
 %
-%    Apart from all the language options below we also have a few options
-%    that influence the behavior of language definition files.
+% This file also takes care of a number of compatibility issues with
+% other packages an defines a few aditional package options. Apart from
+% all the language options below we also have a few options that
+% influence the behavior of language definition files.
 %
-%    Many of the following options don't do anything themselves, they
-%    are just defined in order to make it possible for babel and
-%    language definition files to check if one of them was specified
-%    by the user.
+% Many of the following options don't do anything themselves, they are
+% just defined in order to make it possible for babel and language
+% definition files to check if one of them was specified by the user.
 %
-% \subsection{\texttt{base}}
+% The first two options are for debugging.
 %
-%    The first option to be processed is |base|, which set the
-%    hyphenation patterns then resets |ver at babel.sty| so that
-%    \LaTeX forgets about the first loading. After |switch.def| has
-%    been loaded (above) and |\AfterBabelLanguage| defined, exits.
-%
 %    \begin{macrocode}
 %<*package>
 \NeedsTeXFormat{LaTeX2e}[2005/12/01]
@@ -4891,12 +4930,66 @@
    \let\bbl at debug\@firstofone}
   {\providecommand\bbl at trace[1]{}%
    \let\bbl at debug\@gobble}
-\ifx\bbl at switchflag\@undefined % Prevent double input
-  \let\bbl at switchflag\relax
-  \input switch.def\relax
-\fi
-<@Load patterns in luatex@>
 <@Basic macros@>
+  % Temporarily repeat here the code for errors
+  \def\bbl at error#1#2{%
+    \begingroup
+      \def\\{\MessageBreak}%
+      \PackageError{babel}{#1}{#2}%
+    \endgroup}
+  \def\bbl at warning#1{%
+    \begingroup
+      \def\\{\MessageBreak}%
+      \PackageWarning{babel}{#1}%
+    \endgroup}
+  \def\bbl at infowarn#1{%
+    \begingroup
+      \def\\{\MessageBreak}%
+      \GenericWarning
+        {(babel) \@spaces\@spaces\@spaces}%
+        {Package babel Info: #1}%
+    \endgroup}
+  \def\bbl at info#1{%
+    \begingroup
+      \def\\{\MessageBreak}%
+      \PackageInfo{babel}{#1}%
+    \endgroup}
+    \def\bbl at nocaption{\protect\bbl at nocaption@i}
+\def\bbl at nocaption@i#1#2{% 1: text to be printed 2: caption macro \langXname
+  \global\@namedef{#2}{\textbf{?#1?}}%
+  \@nameuse{#2}%
+  \bbl at warning{%
+    \@backslashchar#2 not set. Please, define\\%
+    it in the preamble with something like:\\%
+    \string\renewcommand\@backslashchar#2{..}\\%
+    Reported}}
+\def\bbl at tentative{\protect\bbl at tentative@i}
+\def\bbl at tentative@i#1{%
+  \bbl at warning{%
+    Some functions for '#1' are tentative.\\%
+    They might not work as expected and their behavior\\%
+    could change in the future.\\%
+    Reported}}
+\def\@nolanerr#1{%
+  \bbl at error
+    {You haven't defined the language #1\space yet.\\%
+     Perhaps you misspelled it or your installation\\%
+     is not complete}%
+    {Your command will be ignored, type <return> to proceed}}
+\def\@nopatterns#1{%
+  \bbl at warning
+    {No hyphenation patterns were preloaded for\\%
+     the language `#1' into the format.\\%
+     Please, configure your TeX system to add them and\\%
+     rebuild the format. Now I will use the patterns\\%
+     preloaded for \bbl at nulllanguage\space instead}}
+    % End of errors
+\@ifpackagewith{babel}{silent}
+  {\let\bbl at info\@gobble
+   \let\bbl at infowarn\@gobble
+   \let\bbl at warning\@gobble}
+  {}
+%
 \def\AfterBabelLanguage#1{%
   \global\expandafter\bbl at add\csname#1.ldf-h@@k\endcsname}%
 %    \end{macrocode}
@@ -4903,7 +4996,8 @@
 %
 % If the format created a list of loaded languages (in
 % |\bbl at languages|), get the name of the 0-th to show the actual
-% language used.
+% language used. Also avaliable with |base|, because it just shows
+% info.
 %
 %    \begin{macrocode}
 \ifx\bbl at languages\@undefined\else
@@ -4923,7 +5017,48 @@
       \def\bbl at elt##1##2##3##4{}%
     \fi}%
   \bbl at languages
-\fi
+\fi%
+%    \end{macrocode}
+% \subsection{\texttt{base}}
+%
+% The first `real' option to be processed is |base|, which set the
+% hyphenation patterns then resets |ver at babel.sty| so that \LaTeX
+% forgets about the first loading. After a subset of |babel.def| has
+% been loaded (the old |switch.def|) and |\AfterBabelLanguage| defined,
+% it exits.
+%
+% Now the \texttt{base} option. With it we can define (and load, with
+% \luatex) hyphenation patterns, even if we are not interesed in the
+% rest of babel.
+%
+%    \begin{macrocode}
+\bbl at trace{Defining option 'base'}
+\@ifpackagewith{babel}{base}{%
+  \let\bbl at onlyswitch\@empty
+  \let\bbl at provide@locale\relax
+  \input babel.def
+  \let\bbl at onlyswitch\@undefined
+  \ifx\directlua\@undefined
+    \DeclareOption*{\bbl at patterns{\CurrentOption}}%
+  \else
+    \input luababel.def
+    \DeclareOption*{\bbl at patterns@lua{\CurrentOption}}%
+  \fi
+  \DeclareOption{base}{}%
+  \DeclareOption{showlanguages}{}%
+  \ProcessOptions
+  \global\expandafter\let\csname opt at babel.sty\endcsname\relax
+  \global\expandafter\let\csname ver at babel.sty\endcsname\relax
+  \global\let\@ifl at ter@@\@ifl at ter
+  \def\@ifl at ter#1#2#3#4#5{\global\let\@ifl at ter\@ifl at ter@@}%
+  \endinput}{}%
+% \end{macrocode}
+%
+% TODO. Code for lua bidi options must be moved to a logical place. The
+% problem is |\RequirePackage|, which is forbidden allowed in the options
+% section.
+%
+% \begin{macrocode}
 \ifodd\bbl at engine
   \def\bbl at activate@preotf{%
     \let\bbl at activate@preotf\relax  % only once
@@ -4981,28 +5116,6 @@
 \fi
 %    \end{macrocode}
 %
-% Now the \texttt{base} option. With it we can define (and load, with
-% \luatex) hyphenation patterns, even if we are not interesed in the
-% rest of babel. Useful for old versions of \textsf{polyglossia}, too.
-%
-%    \begin{macrocode}
-\bbl at trace{Defining option 'base'}
-\@ifpackagewith{babel}{base}{%
-  \ifx\directlua\@undefined
-    \DeclareOption*{\bbl at patterns{\CurrentOption}}%
-  \else
-    \DeclareOption*{\bbl at patterns@lua{\CurrentOption}}%
-  \fi
-  \DeclareOption{base}{}%
-  \DeclareOption{showlanguages}{}%
-  \ProcessOptions
-  \global\expandafter\let\csname opt at babel.sty\endcsname\relax
-  \global\expandafter\let\csname ver at babel.sty\endcsname\relax
-  \global\let\@ifl at ter@@\@ifl at ter
-  \def\@ifl at ter#1#2#3#4#5{\global\let\@ifl at ter\@ifl at ter@@}%
-  \endinput}{}%
-%    \end{macrocode}
-%
 % \subsection{\texttt{key=value} options and other general option}
 %
 %    The following macros extract language modifiers, and only real
@@ -5033,7 +5146,7 @@
 \expandafter\let\csname opt at babel.sty\endcsname\bbl at tempc
 %    \end{macrocode}
 %
-% The next option tells \babel\ to leave shorthand characters active
+% The next option tells \babel{} to leave shorthand characters active
 % at the end of processing the package. This is \emph{not} the default
 % as it can cause problems with other packages, but for those who want
 % to use the shorthand characters in the preamble of their documents
@@ -5049,7 +5162,7 @@
 \DeclareOption{silent}{}
 \DeclareOption{mono}{}
 \DeclareOption{shorthands=off}{\bbl at tempa shorthands=\bbl at tempa}
-% Don't use. Experimental:
+% Don't use. Experimental. TODO.
 \newif\ifbbl at single
 \DeclareOption{selectors=off}{\bbl at singletrue}
 <@More package options@>
@@ -5078,11 +5191,12 @@
   \bbl at csarg\ifx{opt@#1}\@nnil
     \bbl at csarg\edef{opt@#1}{#2}%
   \else
-    \bbl at error{%
-      Bad option `#1=#2'. Either you have misspelled the\\%
-      key or there is a previous setting of `#1'}{%
-      Valid keys are `shorthands', `config', `strings', `main',\\%
-      `headfoot', `safe', `math', among others.}
+    \bbl at error
+     {Bad option `#1=#2'. Either you have misspelled the\\%
+      key or there is a previous setting of `#1'. Valid\\%
+      keys are, among others, `shorthands', `main', `bidi',\\%
+      `strings', `config', `headfoot', `safe', `math'.}%
+     {See the manual for further details.}
   \fi}
 %    \end{macrocode}
 %
@@ -5198,7 +5312,8 @@
 %    \end{macrocode}
 %
 % For |layout| an auxiliary macro is provided, available for packages
-% and language styles.
+% and language styles. Optimization: if there is no |layout|, just do
+% nothing.
 %
 %    \begin{macrocode}
 \bbl at trace{Defining IfBabelLayout}
@@ -5215,6 +5330,933 @@
 \fi
 %    \end{macrocode}
 %
+% \textbf{Common definitions.} \textit{In progress.} Still based on
+% |babel.def|, but the code should be moved here.
+%
+%    \begin{macrocode}
+\input babel.def
+%    \end{macrocode}
+%
+% \subsection{Cross referencing macros}
+%
+%    The \LaTeX\ book states:
+%  \begin{quote}
+%    The \emph{key} argument is any sequence of letters, digits, and
+%    punctuation symbols; upper- and lowercase letters are regarded as
+%    different.
+%  \end{quote}
+%    When the above quote should still be true when a document is
+%    typeset in a language that has active characters, special care
+%    has to be taken of the category codes of these characters when
+%    they appear in an argument of the cross referencing macros.
+%
+%    When a cross referencing command processes its argument, all
+%    tokens in this argument should be character tokens with category
+%    `letter' or `other'.
+%
+%    The following package options control which macros are to be
+%    redefined.
+%
+%    \begin{macrocode}
+%<<*More package options>>
+\DeclareOption{safe=none}{\let\bbl at opt@safe\@empty}
+\DeclareOption{safe=bib}{\def\bbl at opt@safe{B}}
+\DeclareOption{safe=ref}{\def\bbl at opt@safe{R}}
+%<</More package options>>
+%    \end{macrocode}
+%
+%  \begin{macro}{\@newl at bel}
+%
+%    First we open a new group to keep the changed setting of
+%    |\protect| local and then we set the |@safe at actives| switch to
+%    true to make sure that any shorthand that appears in any of the
+%    arguments immediately expands to its non-active self.
+%
+%    \begin{macrocode}
+\bbl at trace{Cross referencing macros}
+\ifx\bbl at opt@safe\@empty\else
+  \def\@newl at bel#1#2#3{%
+   {\@safe at activestrue
+    \bbl at ifunset{#1@#2}%
+       \relax
+       {\gdef\@multiplelabels{%
+          \@latex at warning@no at line{There were multiply-defined labels}}%
+        \@latex at warning@no at line{Label `#2' multiply defined}}%
+    \global\@namedef{#1@#2}{#3}}}
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+%  \begin{macro}{\@testdef}
+%
+%    An internal \LaTeX\ macro used to test if the labels that have
+%    been written on the |.aux| file have changed.  It is called by
+%    the |\enddocument| macro.
+%
+%    \begin{macrocode}
+  \CheckCommand*\@testdef[3]{%
+    \def\reserved at a{#3}%
+    \expandafter\ifx\csname#1@#2\endcsname\reserved at a
+    \else
+      \@tempswatrue
+    \fi}
+%    \end{macrocode}
+%
+%  Now that we made sure that |\@testdef| still has the same definition
+%  we can rewrite it. First we make the shorthands `safe'. Then we use
+%  |\bbl at tempa| as an `alias' for the macro that contains the label
+%  which is being checked. Then we define |\bbl at tempb| just as
+%  |\@newl at bel| does it. When the label is defined we replace the
+%  definition of |\bbl at tempa| by its meaning. If the label didn't
+%  change, |\bbl at tempa| and |\bbl at tempb| should be identical macros.
+%
+%    \begin{macrocode}
+  \def\@testdef#1#2#3{%  TODO. With @samestring?
+    \@safe at activestrue
+    \expandafter\let\expandafter\bbl at tempa\csname #1@#2\endcsname
+    \def\bbl at tempb{#3}%
+    \@safe at activesfalse
+    \ifx\bbl at tempa\relax
+    \else
+      \edef\bbl at tempa{\expandafter\strip at prefix\meaning\bbl at tempa}%
+    \fi
+    \edef\bbl at tempb{\expandafter\strip at prefix\meaning\bbl at tempb}%
+    \ifx\bbl at tempa\bbl at tempb
+    \else
+      \@tempswatrue
+    \fi}
+\fi
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+%  \begin{macro}{\ref}
+%  \begin{macro}{\pageref}
+%
+%    The same holds for the macro |\ref| that references a label and
+%    |\pageref| to reference a page. We make them robust as well (if
+%    they weren't already) to prevent problems if they should become
+%    expanded at the wrong moment.
+%
+%    \begin{macrocode}
+\bbl at xin@{R}\bbl at opt@safe
+\ifin@
+  \bbl at redefinerobust\ref#1{%
+    \@safe at activestrue\org at ref{#1}\@safe at activesfalse}
+  \bbl at redefinerobust\pageref#1{%
+    \@safe at activestrue\org at pageref{#1}\@safe at activesfalse}
+\else
+  \let\org at ref\ref
+  \let\org at pageref\pageref
+\fi
+%    \end{macrocode}
+%
+%  \end{macro}
+%  \end{macro}
+%
+%  \begin{macro}{\@citex}
+%    The macro used to cite from a bibliography, |\cite|, uses an
+%    internal macro, |\@citex|.
+%    It is this internal macro that picks up the argument(s),
+%    so we redefine this internal macro and leave |\cite| alone. The
+%    first argument is used for typesetting, so the shorthands need
+%    only be deactivated in the second argument.
+%
+%    \begin{macrocode}
+\bbl at xin@{B}\bbl at opt@safe
+\ifin@
+  \bbl at redefine\@citex[#1]#2{%
+    \@safe at activestrue\edef\@tempa{#2}\@safe at activesfalse
+    \org@@citex[#1]{\@tempa}}
+%    \end{macrocode}
+%
+%    Unfortunately, the packages \pkg{natbib} and \pkg{cite} need a
+%    different definition of |\@citex|...
+%    To begin with, \pkg{natbib} has a definition for |\@citex| with
+%    \emph{three} arguments... We only know that a package is loaded
+%    when |\begin{document}| is executed, so we need to postpone the
+%    different redefinition.
+%
+%    \begin{macrocode}
+  \AtBeginDocument{%
+    \@ifpackageloaded{natbib}{%
+%    \end{macrocode}
+%
+%    Notice that we use |\def| here instead of |\bbl at redefine| because
+%    |\org@@citex| is already defined and we don't want to overwrite
+%    that definition (it would result in parameter stack overflow
+%    because of a circular definition).
+%
+%   (Recent versions of \pkg{natbib} change dynamically |\@citex|, so PR4087
+%    doesn't seem fixable in a simple way. Just load \pkg{natbib} before.)
+%
+%    \begin{macrocode}
+    \def\@citex[#1][#2]#3{%
+      \@safe at activestrue\edef\@tempa{#3}\@safe at activesfalse
+      \org@@citex[#1][#2]{\@tempa}}%
+    }{}}
+%    \end{macrocode}
+%
+%    The package \pkg{cite} has a definition of |\@citex| where the
+%    shorthands need to be turned off in both arguments.
+%
+%    \begin{macrocode}
+  \AtBeginDocument{%
+    \@ifpackageloaded{cite}{%
+      \def\@citex[#1]#2{%
+        \@safe at activestrue\org@@citex[#1]{#2}\@safe at activesfalse}%
+      }{}}
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+%  \begin{macro}{\nocite}
+%    The macro |\nocite| which is used to instruct BiB\TeX\ to
+%    extract uncited references from the database.
+%
+%    \begin{macrocode}
+  \bbl at redefine\nocite#1{%
+    \@safe at activestrue\org at nocite{#1}\@safe at activesfalse}
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+%  \begin{macro}{\bibcite}
+%  The macro that is used in the |.aux| file to
+%  define citation labels. When packages such as \pkg{natbib} or
+%  \pkg{cite} are not loaded its second argument is used to typeset the
+%  citation label. In that case, this second argument can contain
+%  active characters but is used in an environment where
+%  |\@safe at activestrue| is in effect. This switch needs to be reset
+%  inside the |\hbox| which contains the citation label. In order to
+%  determine during \file{.aux} file processing which definition of
+%  |\bibcite| is needed we define |\bibcite| in such a way that it
+%  redefines itself with the proper definition. We call
+%  |\bbl at cite@choice| to select the proper definition for |\bibcite|.
+%  This new definition is then activated.
+%
+%    \begin{macrocode}
+  \bbl at redefine\bibcite{%
+    \bbl at cite@choice
+    \bibcite}
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+%  \begin{macro}{\bbl at bibcite}
+%    The macro |\bbl at bibcite| holds the definition of |\bibcite|
+%    needed when neither \pkg{natbib} nor \pkg{cite} is loaded.
+%
+%    \begin{macrocode}
+  \def\bbl at bibcite#1#2{%
+    \org at bibcite{#1}{\@safe at activesfalse#2}}
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+%  \begin{macro}{\bbl at cite@choice}
+%    The macro |\bbl at cite@choice| determines which definition of
+%    |\bibcite| is needed. First we give |\bibcite| its default
+%    definition.
+%
+%    \begin{macrocode}
+  \def\bbl at cite@choice{%
+    \global\let\bibcite\bbl at bibcite
+    \@ifpackageloaded{natbib}{\global\let\bibcite\org at bibcite}{}%
+    \@ifpackageloaded{cite}{\global\let\bibcite\org at bibcite}{}%
+    \global\let\bbl at cite@choice\relax}
+%    \end{macrocode}
+%
+%    When a document is run for the first time, no \file{.aux} file is
+%    available, and |\bibcite| will not yet be properly defined. In
+%    this case, this has to happen before the document starts.
+%
+%    \begin{macrocode}
+  \AtBeginDocument{\bbl at cite@choice}
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+%  \begin{macro}{\@bibitem}
+%    One of the two internal \LaTeX\ macros called by |\bibitem|
+%    that write the citation label on the |.aux| file.
+%
+%    \begin{macrocode}
+  \bbl at redefine\@bibitem#1{%
+    \@safe at activestrue\org@@bibitem{#1}\@safe at activesfalse}
+\else
+  \let\org at nocite\nocite
+  \let\org@@citex\@citex
+  \let\org at bibcite\bibcite
+  \let\org@@bibitem\@bibitem
+\fi
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+% \subsection{Marks}
+%
+% \begin{macro}{\markright}
+% Because the output routine is asynchronous, we must pass the
+% current language attribute to the head lines. To achieve this we
+% need to adapt the definition of |\markright| and |\markboth|
+% somewhat. However, headlines and footlines can contain text
+% outside marks; for that we must take some actions in the output
+% routine if the 'headfoot' options is used. 
+%
+% We need to make some redefinitions to the output routine
+% to avoid an endless loop and to correctly handle the page number
+% in bidi documents.
+%
+%    \begin{macrocode}
+\bbl at trace{Marks}
+\IfBabelLayout{sectioning}
+  {\ifx\bbl at opt@headfoot\@nnil
+     \g at addto@macro\@resetactivechars{%
+       \set at typeset@protect
+       \expandafter\select at language@x\expandafter{\bbl at main@language}%
+       \let\protect\noexpand
+       \edef\thepage{% TODO. Only with bidi. See also above
+         \noexpand\babelsublr{\unexpanded\expandafter{\thepage}}}}%
+   \fi}
+  {\ifbbl at single\else
+     \bbl at ifunset{markright }\bbl at redefine\bbl at redefinerobust
+     \markright#1{%
+       \bbl at ifblank{#1}%
+         {\org at markright{}}%
+         {\toks@{#1}%
+          \bbl at exp{%
+            \\\org at markright{\\\protect\\\foreignlanguage{\languagename}%
+              {\\\protect\\\bbl at restore@actives\the\toks@}}}}}%
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+%  \begin{macro}{\markboth}
+%  \begin{macro}{\@mkboth}
+%    The definition of |\markboth| is equivalent to that of
+%    |\markright|, except that we need two token registers. The
+%    documentclasses \cls{report} and \cls{book} define and set the
+%    headings for the page. While doing so they also store a copy of
+%    |\markboth| in |\@mkboth|. Therefore we need to check whether
+%    |\@mkboth| has already been set. If so we neeed to do that again
+%    with the new definition of |\markboth|. (As of Oct 2019, \LaTeX{}
+%    stores the definition in an intermediate macro, so it's not
+%    necessary anymore, but it's preserved for older versions.)
+%
+%    \begin{macrocode}
+     \ifx\@mkboth\markboth
+       \def\bbl at tempc{\let\@mkboth\markboth}
+     \else
+       \def\bbl at tempc{}
+     \fi
+     \bbl at ifunset{markboth }\bbl at redefine\bbl at redefinerobust
+     \markboth#1#2{%
+       \protected at edef\bbl at tempb##1{%
+         \protect\foreignlanguage
+         {\languagename}{\protect\bbl at restore@actives##1}}%
+       \bbl at ifblank{#1}%
+         {\toks@{}}%
+         {\toks@\expandafter{\bbl at tempb{#1}}}%
+       \bbl at ifblank{#2}%
+         {\@temptokena{}}%
+         {\@temptokena\expandafter{\bbl at tempb{#2}}}%
+       \bbl at exp{\\\org at markboth{\the\toks@}{\the\@temptokena}}}
+       \bbl at tempc
+     \fi}  % end ifbbl at single, end \IfBabelLayout
+%    \end{macrocode}
+%
+%  \end{macro}
+%  \end{macro}
+%
+% \subsection{Preventing clashes with other packages}
+%
+% \subsubsection{\pkg{ifthen}}
+%
+%  \begin{macro}{\ifthenelse}
+%
+%    Sometimes a document writer wants to create a special effect
+%    depending on the page a certain fragment of text appears on. This
+%    can be achieved by the following piece of code:
+%\begin{verbatim}
+%    \ifthenelse{\isodd{\pageref{some:label}}}
+%               {code for odd pages}
+%               {code for even pages}
+%\end{verbatim}
+%    In order for this to work the argument of |\isodd| needs to be
+%    fully expandable. With the above redefinition of |\pageref| it is
+%    not in the case of this example. To overcome that, we add some
+%    code to the definition of |\ifthenelse| to make things work.
+%
+%    We want to revert the definition of |\pageref| and |\ref| to
+%    their original definition for the first argument of |\ifthenelse|,
+%    so we first need to store their current meanings.
+%
+%    Then we can set the |\@safe at actives| switch and call the original
+%    |\ifthenelse|. In order to be able to use shorthands in the
+%    second and third arguments of |\ifthenelse| the resetting of the
+%    switch \emph{and} the definition of |\pageref| happens inside
+%    those arguments. 
+%
+%    \begin{macrocode}
+\bbl at trace{Preventing clashes with other packages}
+\bbl at xin@{R}\bbl at opt@safe
+\ifin@
+  \AtBeginDocument{%
+    \@ifpackageloaded{ifthen}{%
+      \bbl at redefine@long\ifthenelse#1#2#3{%
+        \let\bbl at temp@pref\pageref
+        \let\pageref\org at pageref
+        \let\bbl at temp@ref\ref
+        \let\ref\org at ref
+        \@safe at activestrue
+        \org at ifthenelse{#1}%
+          {\let\pageref\bbl at temp@pref
+           \let\ref\bbl at temp@ref
+           \@safe at activesfalse
+           #2}%
+          {\let\pageref\bbl at temp@pref
+           \let\ref\bbl at temp@ref
+           \@safe at activesfalse
+           #3}%
+        }%
+      }{}%
+    }
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+% \subsubsection{\pkg{varioref}}
+%
+%  \begin{macro}{\@@vpageref}
+%  \begin{macro}{\vrefpagenum}
+%  \begin{macro}{\Ref}
+%
+%    When the package varioref is in use we need to modify its
+%    internal command |\@@vpageref| in order to prevent problems when
+%    an active character ends up in the argument of |\vref|. The same
+%    needs to happen for |\vrefpagenum|.
+%
+%    \begin{macrocode}
+  \AtBeginDocument{%
+    \@ifpackageloaded{varioref}{%
+      \bbl at redefine\@@vpageref#1[#2]#3{%
+        \@safe at activestrue
+        \org@@@vpageref{#1}[#2]{#3}%
+        \@safe at activesfalse}%
+      \bbl at redefine\vrefpagenum#1#2{%
+        \@safe at activestrue
+        \org at vrefpagenum{#1}{#2}%
+        \@safe at activesfalse}%
+%    \end{macrocode}
+%
+%    The package \pkg{varioref} defines |\Ref| to be a robust command
+%    wich uppercases the first character of the reference text. In
+%    order to be able to do that it needs to access the expandable form
+%    of |\ref|. So we employ a little trick here. We redefine the
+%    (internal) command \verb*|\Ref | to call |\org at ref| instead of
+%    |\ref|. The disadvantage of this solution is that whenever the
+%    definition of |\Ref| changes, this definition needs to be updated
+%    as well.
+%
+%    \begin{macrocode}
+      \expandafter\def\csname Ref \endcsname#1{%
+        \protected at edef\@tempa{\org at ref{#1}}\expandafter\MakeUppercase\@tempa}
+      }{}%
+    }
+\fi
+%    \end{macrocode}
+%
+%  \end{macro}
+%  \end{macro}
+%  \end{macro}
+%
+% \subsubsection{\pkg{hhline}}
+%
+%  \begin{macro}{\hhline}
+%    Delaying the activation of the shorthand characters has introduced
+%    a problem with the \pkg{hhline} package. The reason is that it
+%    uses the `:' character which is made active by the french support
+%    in \babel. Therefore we need to \emph{reload} the package when
+%    the `:' is an active character. Note that this happens
+%    \emph{after} the category code of the @-sign has been changed to
+%    other, so we need to temporarily change it to letter again.
+%
+%    \begin{macrocode}
+\AtEndOfPackage{%
+  \AtBeginDocument{%
+    \@ifpackageloaded{hhline}%
+      {\expandafter\ifx\csname normal at char\string:\endcsname\relax
+       \else
+         \makeatletter
+         \def\@currname{hhline}\input{hhline.sty}\makeatother
+       \fi}%
+      {}}}
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+% \subsubsection{\pkg{hyperref}}
+%
+%  \begin{macro}{\pdfstringdefDisableCommands}
+%
+%    A number of interworking problems between \pkg{babel} and
+%    \pkg{hyperref} are tackled by \pkg{hyperref} itself. The
+%    following code was introduced to prevent some annoying warnings
+%    but it broke bookmarks. This was quickly fixed in \pkg{hyperref},
+%    which essentially made it no-op. However, it will not removed for
+%    the moment because \pkg{hyperref} is expecting it. TODO. Still
+%    true? 
+%
+%    \begin{macrocode}
+\AtBeginDocument{%
+  \ifx\pdfstringdefDisableCommands\@undefined\else
+    \pdfstringdefDisableCommands{\languageshorthands{system}}%
+  \fi}
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+% \subsubsection{\pkg{fancyhdr}}
+%
+%  \begin{macro}{\FOREIGNLANGUAGE}
+%    The package \pkg{fancyhdr} treats the running head and fout lines
+%    somewhat differently as the standard classes. A symptom of this is
+%    that the command |\foreignlanguage| which \babel\ adds to the
+%    marks can end up inside the argument of |\MakeUppercase|. To
+%    prevent unexpected results we need to define |\FOREIGNLANGUAGE|
+%    here.
+%
+%    \begin{macrocode}
+\DeclareRobustCommand{\FOREIGNLANGUAGE}[1]{%
+  \lowercase{\foreignlanguage{#1}}}
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+%  \begin{macro}{\substitutefontfamily}
+%
+%    The command |\substitutefontfamily| creates an
+%    \file{.fd} file on the fly. The first argument is an encoding
+%    mnemonic, the second and third arguments are font family names.
+%    This command is deprecated. Use the tools provides by \LaTeX.
+%
+%    \begin{macrocode}
+\def\substitutefontfamily#1#2#3{%
+  \lowercase{\immediate\openout15=#1#2.fd\relax}%
+  \immediate\write15{%
+    \string\ProvidesFile{#1#2.fd}%
+    [\the\year/\two at digits{\the\month}/\two at digits{\the\day}
+     \space generated font description file]^^J
+    \string\DeclareFontFamily{#1}{#2}{}^^J
+    \string\DeclareFontShape{#1}{#2}{m}{n}{<->ssub * #3/m/n}{}^^J
+    \string\DeclareFontShape{#1}{#2}{m}{it}{<->ssub * #3/m/it}{}^^J
+    \string\DeclareFontShape{#1}{#2}{m}{sl}{<->ssub * #3/m/sl}{}^^J
+    \string\DeclareFontShape{#1}{#2}{m}{sc}{<->ssub * #3/m/sc}{}^^J
+    \string\DeclareFontShape{#1}{#2}{b}{n}{<->ssub * #3/bx/n}{}^^J
+    \string\DeclareFontShape{#1}{#2}{b}{it}{<->ssub * #3/bx/it}{}^^J
+    \string\DeclareFontShape{#1}{#2}{b}{sl}{<->ssub * #3/bx/sl}{}^^J
+    \string\DeclareFontShape{#1}{#2}{b}{sc}{<->ssub * #3/bx/sc}{}^^J
+    }%
+  \closeout15
+  }
+\@onlypreamble\substitutefontfamily
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+% \subsection{Encoding and fonts}
+%
+%  Because documents may use non-ASCII font encodings, we make sure
+%  that the logos of \TeX\ and \LaTeX\ always come out in the right
+%  encoding. There is a list of non-ASCII encodings. Unfortunately,
+%  \textsf{fontenc} deletes its package options, so we must guess which
+%  encodings has been loaded by traversing |\@filelist| to search for
+%  \m{enc}|enc.def|. If a non-ASCII has been loaded, we define versions
+%  of |\TeX| and |\LaTeX| for them using |\ensureascii|. The default
+%  ASCII encoding is set, too (in reverse order): the ``main'' encoding
+%  (when the document begins), the last loaded, or |OT1|.
+%
+%  \begin{macro}{\ensureascii}
+%
+%    \begin{macrocode}
+\bbl at trace{Encoding and fonts}
+\newcommand\BabelNonASCII{LGR,X2,OT2,OT3,OT6,LHE,LWN,LMA,LMC,LMS,LMU,PU,PD1}
+\newcommand\BabelNonText{TS1,T3,TS3}
+\let\org at TeX\TeX
+\let\org at LaTeX\LaTeX
+\let\ensureascii\@firstofone
+\AtBeginDocument{%
+  \in at false
+  \bbl at foreach\BabelNonASCII{% is there a text non-ascii enc?
+    \ifin@\else
+      \lowercase{\bbl at xin@{,#1enc.def,}{,\@filelist,}}%
+    \fi}%
+  \ifin@ % if a text non-ascii has been loaded
+    \def\ensureascii#1{{\fontencoding{OT1}\selectfont#1}}%
+    \DeclareTextCommandDefault{\TeX}{\org at TeX}%
+    \DeclareTextCommandDefault{\LaTeX}{\org at LaTeX}%
+    \def\bbl at tempb#1\@@{\uppercase{\bbl at tempc#1}ENC.DEF\@empty\@@}%
+    \def\bbl at tempc#1ENC.DEF#2\@@{%
+      \ifx\@empty#2\else
+        \bbl at ifunset{T@#1}%
+          {}%
+          {\bbl at xin@{,#1,}{,\BabelNonASCII,\BabelNonText,}%
+           \ifin@
+             \DeclareTextCommand{\TeX}{#1}{\ensureascii{\org at TeX}}%
+             \DeclareTextCommand{\LaTeX}{#1}{\ensureascii{\org at LaTeX}}%
+           \else
+             \def\ensureascii##1{{\fontencoding{#1}\selectfont##1}}%
+           \fi}%
+      \fi}%
+    \bbl at foreach\@filelist{\bbl at tempb#1\@@}%  TODO - \@@ de mas??
+    \bbl at xin@{,\cf at encoding,}{,\BabelNonASCII,\BabelNonText,}%
+    \ifin@\else
+      \edef\ensureascii#1{{%
+        \noexpand\fontencoding{\cf at encoding}\noexpand\selectfont#1}}%
+    \fi
+  \fi}
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+%  Now comes the old deprecated stuff (with a little change in 3.9l,
+%  for \textsf{fontspec}).  The first thing we need to do is to
+%  determine, at |\begin{document}|, which latin fontencoding to use.
+%
+%  \begin{macro}{\latinencoding}
+%    When text is being typeset in an encoding other than `latin'
+%    (\texttt{OT1} or \texttt{T1}), it would be nice to still have
+%    Roman numerals come out in the Latin encoding.
+%    So we first assume that the current encoding at the end
+%    of processing the package is the Latin encoding.
+%
+%    \begin{macrocode}
+\AtEndOfPackage{\edef\latinencoding{\cf at encoding}}
+%    \end{macrocode}
+%
+%    But this might be overruled with a later loading of the package
+%    \pkg{fontenc}. Therefore we check at the execution of
+%    |\begin{document}| whether it was loaded with the \Lopt{T1}
+%    option. The normal way to do this (using |\@ifpackageloaded|) is
+%    disabled for this package. Now we have to revert to parsing the
+%    internal macro |\@filelist| which contains all the filenames
+%    loaded.
+%
+%    \begin{macrocode}
+\AtBeginDocument{%
+  \@ifpackageloaded{fontspec}%
+    {\xdef\latinencoding{%
+       \ifx\UTFencname\@undefined
+         EU\ifcase\bbl at engine\or2\or1\fi
+       \else
+         \UTFencname
+       \fi}}%
+    {\gdef\latinencoding{OT1}%
+     \ifx\cf at encoding\bbl at t@one
+       \xdef\latinencoding{\bbl at t@one}%
+     \else
+       \ifx\@fontenc at load@list\@undefined
+         \@ifl at aded{def}{t1enc}{\xdef\latinencoding{\bbl at t@one}}{}%
+       \else
+         \def\@elt#1{,#1,}%
+         \edef\bbl at tempa{\expandafter\@gobbletwo\@fontenc at load@list}%
+         \let\@elt\relax
+         \bbl at xin@{,T1,}\bbl at tempa
+         \ifin@
+           \xdef\latinencoding{\bbl at t@one}%
+         \fi
+       \fi
+     \fi}}
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+%  \begin{macro}{\latintext}
+%    Then we can define the command |\latintext| which is a
+%    declarative switch to a latin font-encoding. Usage of this macro
+%    is deprecated.
+%
+%    \begin{macrocode}
+\DeclareRobustCommand{\latintext}{%
+  \fontencoding{\latinencoding}\selectfont
+  \def\encodingdefault{\latinencoding}}
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+%  \begin{macro}{\textlatin}
+%    This command takes an argument which is then typeset using the
+%    requested font encoding. In order to avoid many encoding switches
+%    it operates in a local scope.
+%
+%    \begin{macrocode}
+\ifx\@undefined\DeclareTextFontCommand
+  \DeclareRobustCommand{\textlatin}[1]{\leavevmode{\latintext #1}}
+\else
+  \DeclareTextFontCommand{\textlatin}{\latintext}
+\fi
+%    \end{macrocode}
+%
+% \end{macro}
+%
+% \subsection{Basic bidi support}
+%
+% \textbf{Work in progress.} This code is currently placed here for
+% practical reasons. It will be moved to the correct place soon, I
+% hope.
+%
+% It is loosely based on |rlbabel.def|, but most of it has been
+% developed from scratch. This \babel{} module (by Johannes Braams and
+% Boris Lavva) has served the purpose of typesetting R documents for
+% two decades, and despite its flaws I think it is still a good starting
+% point (some parts have been copied here almost verbatim), partly
+% thanks to its simplicity. I've also looked at \textsc{arabi} (by
+% Youssef Jabri), which is compatible with \babel{}.
+%
+% There are two ways of modifying macros to make them “bidi”, namely,
+% by patching the internal low-level macros (which is what I have done
+% with lists, columns, counters, tocs, much like |rlbabel| did), and
+% by introducing a “middle layer” just below the user interface
+% (sectioning, footnotes).
+%
+%    \begin{itemize}
+%    \item pdftex provides a minimal support for bidi text, and it
+%      must be done by hand. Vertical typesetting is not possible.
+%    \item \xetex{} is somewhat better, thanks to its font engine
+%      (even if not always reliable) and a few additional tools. However,
+%      very little is done at the paragraph level. Another challenging
+%      problem is text direction does not honour \TeX{} grouping.
+%    \item \luatex{} can provide the most complete solution, as we can
+%      manipulate almost freely the node list, the generated lines,
+%      and so on, but bidi text does not work out of the box and some
+%      development is necessary. It also provides tools to properly
+%      set left-to-right and right-to-left page layouts. As Lua\TeX-ja
+%      shows, vertical typesetting is possible, too.
+%    \end{itemize}
+%
+%    \begin{macrocode}
+\bbl at trace{Basic (internal) bidi support}
+\def\bbl at alscripts{,Arabic,Syriac,Thaana,}
+\def\bbl at rscripts{%
+  ,Imperial Aramaic,Avestan,Cypriot,Hatran,Hebrew,%
+  Old Hungarian,Old Hungarian,Lydian,Mandaean,Manichaean,%
+  Manichaean,Meroitic Cursive,Meroitic,Old North Arabian,%
+  Nabataean,N'Ko,Orkhon,Palmyrene,Inscriptional Pahlavi,%
+  Psalter Pahlavi,Phoenician,Inscriptional Parthian,Samaritan,%
+  Old South Arabian,}%
+\def\bbl at provide@dirs#1{%
+  \bbl at xin@{\csname bbl at sname@#1\endcsname}{\bbl at alscripts\bbl at rscripts}%
+  \ifin@
+    \global\bbl at csarg\chardef{wdir@#1}\@ne
+    \bbl at xin@{\csname bbl at sname@#1\endcsname}{\bbl at alscripts}%
+    \ifin@
+      \global\bbl at csarg\chardef{wdir@#1}\tw@  % useless in xetex
+    \fi
+  \else
+    \global\bbl at csarg\chardef{wdir@#1}\z@
+  \fi
+  \ifodd\bbl at engine
+    \bbl at csarg\ifcase{wdir@#1}%
+      \directlua{ Babel.locale_props[\the\localeid].textdir = 'l' }%
+    \or
+      \directlua{ Babel.locale_props[\the\localeid].textdir = 'r' }%
+    \or
+      \directlua{ Babel.locale_props[\the\localeid].textdir = 'al' }%
+    \fi
+  \fi}
+\def\bbl at switchdir{%
+  \bbl at ifunset{bbl at lsys@\languagename}{\bbl at provide@lsys{\languagename}}{}%
+  \bbl at ifunset{bbl at wdir@\languagename}{\bbl at provide@dirs{\languagename}}{}%
+  \bbl at exp{\\\bbl at setdirs\bbl at cl{wdir}}}
+\def\bbl at setdirs#1{% TODO - math
+  \ifcase\bbl at select@type % TODO - strictly, not the right test
+    \bbl at bodydir{#1}%
+    \bbl at pardir{#1}%
+  \fi
+  \bbl at textdir{#1}}
+\ifodd\bbl at engine  % luatex=1
+  \AddBabelHook{babel-bidi}{afterextras}{\bbl at switchdir}
+  \DisableBabelHook{babel-bidi}
+  \chardef\bbl at thetextdir\z@
+  \chardef\bbl at thepardir\z@
+  \def\bbl at getluadir#1{%
+    \directlua{
+      if tex.#1dir == 'TLT' then
+        tex.sprint('0')
+      elseif tex.#1dir == 'TRT' then
+        tex.sprint('1')
+      end}}
+  \def\bbl at setluadir#1#2#3{% 1=text/par.. 2=\textdir.. 3=0 lr/1 rl
+    \ifcase#3\relax
+      \ifcase\bbl at getluadir{#1}\relax\else
+        #2 TLT\relax
+      \fi
+    \else
+      \ifcase\bbl at getluadir{#1}\relax
+        #2 TRT\relax
+      \fi
+    \fi}
+  \def\bbl at textdir#1{%
+    \bbl at setluadir{text}\textdir{#1}%
+    \chardef\bbl at thetextdir#1\relax
+    \setattribute\bbl at attr@dir{\numexpr\bbl at thepardir*3+#1}}
+  \def\bbl at pardir#1{%
+    \bbl at setluadir{par}\pardir{#1}%
+    \chardef\bbl at thepardir#1\relax}
+  \def\bbl at bodydir{\bbl at setluadir{body}\bodydir}
+  \def\bbl at pagedir{\bbl at setluadir{page}\pagedir}
+  \def\bbl at dirparastext{\pardir\the\textdir\relax}%   %%%%
+  % Sadly, we have to deal with boxes in math with basic.
+  % Activated every math with the package option bidi=:
+  \def\bbl at mathboxdir{%
+    \ifcase\bbl at thetextdir\relax
+      \everyhbox{\textdir TLT\relax}%
+    \else
+      \everyhbox{\textdir TRT\relax}%
+    \fi}
+\else % pdftex=0, xetex=2
+  \AddBabelHook{babel-bidi}{afterextras}{\bbl at switchdir}
+  \DisableBabelHook{babel-bidi}
+  \newcount\bbl at dirlevel
+  \chardef\bbl at thetextdir\z@
+  \chardef\bbl at thepardir\z@
+  \def\bbl at textdir#1{%
+    \ifcase#1\relax
+       \chardef\bbl at thetextdir\z@
+       \bbl at textdir@i\beginL\endL
+     \else
+       \chardef\bbl at thetextdir\@ne
+       \bbl at textdir@i\beginR\endR
+    \fi}
+  \def\bbl at textdir@i#1#2{%
+    \ifhmode
+      \ifnum\currentgrouplevel>\z@
+        \ifnum\currentgrouplevel=\bbl at dirlevel
+          \bbl at error{Multiple bidi settings inside a group}%
+            {I'll insert a new group, but expect wrong results.}%
+          \bgroup\aftergroup#2\aftergroup\egroup
+        \else
+          \ifcase\currentgrouptype\or % 0 bottom
+            \aftergroup#2% 1 simple {}
+          \or
+            \bgroup\aftergroup#2\aftergroup\egroup % 2 hbox
+          \or
+            \bgroup\aftergroup#2\aftergroup\egroup % 3 adj hbox
+          \or\or\or % vbox vtop align
+          \or
+            \bgroup\aftergroup#2\aftergroup\egroup % 7 noalign
+          \or\or\or\or\or\or % output math disc insert vcent mathchoice
+          \or
+            \aftergroup#2% 14 \begingroup
+          \else
+            \bgroup\aftergroup#2\aftergroup\egroup % 15 adj
+          \fi
+        \fi
+        \bbl at dirlevel\currentgrouplevel
+      \fi
+      #1%
+    \fi}
+  \def\bbl at pardir#1{\chardef\bbl at thepardir#1\relax}
+  \let\bbl at bodydir\@gobble
+  \let\bbl at pagedir\@gobble
+  \def\bbl at dirparastext{\chardef\bbl at thepardir\bbl at thetextdir}
+%    \end{macrocode}
+%
+% The following command is executed only if there is a right-to-left
+% script (once). It activates the |\everypar| hack for \xetex, to
+% properly handle the par direction. Note text and par dirs are
+% decoupled to some extent (although not completely).
+%
+%    \begin{macrocode}
+  \def\bbl at xebidipar{%
+    \let\bbl at xebidipar\relax
+    \TeXXeTstate\@ne
+    \def\bbl at xeeverypar{%
+      \ifcase\bbl at thepardir
+        \ifcase\bbl at thetextdir\else\beginR\fi
+      \else
+        {\setbox\z@\lastbox\beginR\box\z@}%
+      \fi}%
+    \let\bbl at severypar\everypar
+    \newtoks\everypar
+    \everypar=\bbl at severypar
+    \bbl at severypar{\bbl at xeeverypar\the\everypar}}
+  \def\bbl at tempb{%
+    \let\bbl at textdir@i\@gobbletwo
+    \let\bbl at xebidipar\@empty
+    \AddBabelHook{bidi}{foreign}{%
+      \def\bbl at tempa{\def\BabelText########1}%
+      \ifcase\bbl at thetextdir
+        \expandafter\bbl at tempa\expandafter{\BabelText{\LR{####1}}}%
+      \else
+        \expandafter\bbl at tempa\expandafter{\BabelText{\RL{####1}}}%
+      \fi}
+    \def\bbl at pardir##1{\ifcase##1\relax\setLR\else\setRL\fi}}
+  \@ifpackagewith{babel}{bidi=bidi}{\bbl at tempb}{}%
+  \@ifpackagewith{babel}{bidi=bidi-l}{\bbl at tempb}{}%
+  \@ifpackagewith{babel}{bidi=bidi-r}{\bbl at tempb}{}%
+\fi
+%    \end{macrocode}
+%
+% A tool for weak L (mainly digits). We also disable warnings with
+% \textsf{hyperref}.
+%
+%    \begin{macrocode}
+\DeclareRobustCommand\babelsublr[1]{\leavevmode{\bbl at textdir\z@#1}}
+\AtBeginDocument{%
+  \ifx\pdfstringdefDisableCommands\@undefined\else
+    \ifx\pdfstringdefDisableCommands\relax\else
+      \pdfstringdefDisableCommands{\let\babelsublr\@firstofone}%
+    \fi
+  \fi}
+%    \end{macrocode}
+%
+% \subsection{Local Language Configuration}
+%
+%  \begin{macro}{\loadlocalcfg}
+%    At some sites it may be necessary to add site-specific actions to
+%    a language definition file. This can be done by creating a file
+%    with the same name as the language definition file, but with the
+%    extension \file{.cfg}. For instance the file \file{norsk.cfg}
+%    will be loaded when the language definition file \file{norsk.ldf}
+%    is loaded.
+%
+%    For plain-based formats we don't want to override the definition
+%    of |\loadlocalcfg| from \file{plain.def}.
+%
+%    \begin{macrocode}
+\bbl at trace{Local Language Configuration}
+\ifx\loadlocalcfg\@undefined
+  \@ifpackagewith{babel}{noconfigs}%
+    {\let\loadlocalcfg\@gobble}%
+    {\def\loadlocalcfg#1{%
+      \InputIfFileExists{#1.cfg}%
+        {\typeout{*************************************^^J%
+                       * Local config file #1.cfg used^^J%
+                       *}}%
+        \@empty}}
+\fi
+%    \end{macrocode}%
+%    \end{macro}
+%
+%    Just to be compatible with \LaTeX$\:$2.09 we add a few more lines
+%    of code. TODO. Necessary? Correct place? Used by some ldf file?
+%
+%    \begin{macrocode}
+\ifx\@unexpandable at protect\@undefined
+  \def\@unexpandable at protect{\noexpand\protect\noexpand}
+  \long\def\protected at write#1#2#3{%
+    \begingroup
+      \let\thepage\relax
+      #2%
+      \let\protect\@unexpandable at protect
+      \edef\reserved at a{\write#1{#3}}%
+      \reserved at a
+    \endgroup
+    \if at nobreak\ifvmode\nobreak\fi\fi}
+\fi
+%
 % \subsection{Language options}
 %
 %    Languages are loaded when processing the corresponding option
@@ -5363,6 +6405,7 @@
 %    |\AfterBabelLanguage|.
 %
 %    \begin{macrocode}
+\bbl at trace{Option 'main'}
 \ifx\bbl at opt@main\@nnil
   \edef\bbl at tempa{\@classoptionslist,\bbl at language@opts}
   \let\bbl at tempc\@empty
@@ -5409,18 +6452,11 @@
 %
 % \section{The kernel of Babel (\texttt{babel.def}, common)}
 %
-% The kernel of the \babel\ system is stored in either
-% \file{hyphen.cfg} or \file{switch.def} and \file{babel.def}.  The
-% file \file{babel.def} contains most of the code, while
-% \file{switch.def} defines the language-switching commands; both can
-% be read at run time. The file \file{hyphen.cfg} is a file that can
-% be loaded into the format, which is necessary when you want to be
-% able to switch hyphenation patterns (by default, it also inputs
-% \file{switch.def}, for ``historical reasons'', but it is not
-% necessary). When \file{babel.def} is loaded it checks if the current
-% version of \file{switch.def} is in the format; if not, it is
-% loaded. A further file, \file{babel.sty}, contains \LaTeX-specific
-% stuff.
+% The kernel of the \babel\ system is currently stored in
+% \file{babel.def}. The file \file{babel.def} contains most of the
+% code. The file \file{hyphen.cfg} is a file that can be loaded into
+% the format, which is necessary when you want to be able to switch
+% hyphenation patterns.
 %
 % Because plain \TeX\ users might want to use some of the features of
 % the \babel{} system too, care has to be taken that plain \TeX\ can
@@ -5437,13 +6473,10 @@
 % \subsection{Tools}
 %
 %    \begin{macrocode}
-\ifx\ldf at quit\@undefined
-\else
-  \expandafter\endinput
-\fi
+\ifx\ldf at quit\@undefined\else
+\endinput\fi % Same line!
 <@Make sure ProvidesFile is defined@>
 \ProvidesFile{babel.def}[<@date@> <@version@> Babel common definitions]
-<@Load macros for plain if not LaTeX@>
 %    \end{macrocode}
 %
 % The file |babel.def| expects some definitions made in the \LaTeXe{}
@@ -5456,7 +6489,9 @@
 % set too (but not sure it works).
 %
 %    \begin{macrocode}
-\ifx\bbl at ifshorthand\@undefined
+\ifx\AtBeginDocument\@undefined  % TODO. change test.
+  <@Emulate LaTeX@>
+  \def\languagename{english}%
   \let\bbl at opt@shorthands\@nnil
   \def\bbl at ifshorthand#1#2#3{#2}%
   \let\bbl at language@opts\@empty
@@ -5480,17 +6515,957 @@
 \fi
 %    \end{macrocode}
 %
+% Exit immediately with 2.09. An error is raised by the sty file, but
+% also try to minimize the number of errors.
+%
+%    \begin{macrocode}
+\ifx\bbl at trace\@undefined
+  \let\LdfInit\endinput
+  \def\ProvidesLanguage#1{\endinput}
+\endinput\fi % Same line!
+%    \end{macrocode}
+%
 % And continue.
 %
+% \section{Multiple languages}
+%
+% This is not a separate file (\texttt{switch.def}) anymore.
+%
+% Plain \TeX\ version~3.0 provides the primitive |\language| that
+% is used to store the current language. When used with a pre-3.0
+% version this function has to be implemented by allocating a
+% counter.
+%
 %    \begin{macrocode}
-\ifx\bbl at switchflag\@undefined % Prevent double input
-  \let\bbl at switchflag\relax
-  \input switch.def\relax
+<@Define core switching macros@>
+%    \end{macrocode}
+%
+% \begin{macro}{\adddialect}
+% The macro |\adddialect| can be used to add the name of a dialect
+% or variant language, for which an already defined hyphenation
+% table can be used.
+%
+%    \begin{macrocode}
+\def\bbl at version{<@version@>}
+\def\bbl at date{<@date@>}
+\def\adddialect#1#2{%
+  \global\chardef#1#2\relax
+  \bbl at usehooks{adddialect}{{#1}{#2}}%
+  \begingroup
+    \count@#1\relax
+    \def\bbl at elt##1##2##3##4{%
+      \ifnum\count@=##2\relax
+        \bbl at info{\string#1 = using hyphenrules for ##1\\%
+                  (\string\language\the\count@)}%
+        \def\bbl at elt####1####2####3####4{}%
+      \fi}%
+    \bbl at cs{languages}%
+  \endgroup}
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+%    |\bbl at iflanguage| executes code only if the language |l@|
+%    exists. Otherwise raises and error.
+%
+%    The argument of |\bbl at fixname| has to be a macro name, as it may get
+%    ``fixed'' if casing (lc/uc) is wrong. It's intented to fix a
+%    long-standing bug when |\foreignlanguage| and the like appear in
+%    a |\MakeXXXcase|. However, a lowercase form is not imposed to
+%    improve backward compatibility (perhaps you defined a language
+%    named |MYLANG|, but unfortunately mixed case names cannot be
+%    trapped). Note |l@| is encapsulated, so that its case does not
+%    change.
+%
+%    \begin{macrocode}
+\def\bbl at fixname#1{%
+  \begingroup
+    \def\bbl at tempe{l@}%
+    \edef\bbl at tempd{\noexpand\@ifundefined{\noexpand\bbl at tempe#1}}%
+    \bbl at tempd
+      {\lowercase\expandafter{\bbl at tempd}%
+         {\uppercase\expandafter{\bbl at tempd}%
+           \@empty
+           {\edef\bbl at tempd{\def\noexpand#1{#1}}%
+            \uppercase\expandafter{\bbl at tempd}}}%
+         {\edef\bbl at tempd{\def\noexpand#1{#1}}%
+          \lowercase\expandafter{\bbl at tempd}}}%
+      \@empty
+    \edef\bbl at tempd{\endgroup\def\noexpand#1{#1}}%
+  \bbl at tempd
+  \bbl at exp{\\\bbl at usehooks{languagename}{{\languagename}{#1}}}}
+\def\bbl at iflanguage#1{%
+  \@ifundefined{l@#1}{\@nolanerr{#1}\@gobble}\@firstofone}
+%    \end{macrocode}
+%
+% After a name has been ‘fixed’, the selectors will try to load the
+% language. If even the fixed name is not defined, will load it on the
+% fly, either based on its name, or if activated, its BCP47 code.
+%
+% We first need a couple of macros for a simple BCP 47 look up. It also
+% makes sure, with |\bbl at bcpcase|, casing is the correct one, so that
+% sr-latn-ba becomes fr-Latn-BA. Note |#4| may contain some
+% |\@empty|'s, but they are eventually removed. |\bbl at bcplookup| either
+% returns the found |ini| or it is |\relax|.
+% 
+%    \begin{macrocode}
+\def\bbl at bcpcase#1#2#3#4\@@#5{%
+  \ifx\@empty#3%
+    \uppercase{\def#5{#1#2}}%
+  \else
+    \uppercase{\def#5{#1}}%
+    \lowercase{\edef#5{#5#2#3#4}}%
+  \fi}
+\def\bbl at bcplookup#1-#2-#3-#4\@@{%
+  \let\bbl at bcp\relax
+  \lowercase{\def\bbl at tempa{#1}}%
+  \ifx\@empty#2%
+    \IfFileExists{babel-\bbl at tempa.ini}{\let\bbl at bcp\bbl at tempa}{}%
+  \else\ifx\@empty#3%
+    \bbl at bcpcase#2\@empty\@empty\@@\bbl at tempb
+    \IfFileExists{babel-\bbl at tempa-\bbl at tempb.ini}%
+      {\edef\bbl at bcp{\bbl at tempa-\bbl at tempb}}%
+      {}%
+    \ifx\bbl at bcp\relax   
+      \IfFileExists{babel-\bbl at tempa.ini}{\let\bbl at bcp\bbl at tempa}{}%
+    \fi
+  \else
+    \bbl at bcpcase#2\@empty\@empty\@@\bbl at tempb
+    \bbl at bcpcase#3\@empty\@empty\@@\bbl at tempc
+    \IfFileExists{babel-\bbl at tempa-\bbl at tempb-\bbl at tempc.ini}%
+      {\edef\bbl at bcp{\bbl at tempa-\bbl at tempb-\bbl at tempc}}%
+      {}%
+    \ifx\bbl at bcp\relax   
+      \IfFileExists{babel-\bbl at tempa-\bbl at tempc.ini}%
+        {\edef\bbl at bcp{\bbl at tempa-\bbl at tempc}}%
+        {}%
+    \fi
+    \ifx\bbl at bcp\relax   
+      \IfFileExists{babel-\bbl at tempa-\bbl at tempc.ini}%
+        {\edef\bbl at bcp{\bbl at tempa-\bbl at tempc}}%
+        {}%
+    \fi
+    \ifx\bbl at bcp\relax   
+      \IfFileExists{babel-\bbl at tempa.ini}{\let\bbl at bcp\bbl at tempa}{}%
+    \fi
+  \fi\fi}
+\let\bbl at autoload@options\@empty
+\let\bbl at initoload\relax
+\def\bbl at provide@locale{%
+  \ifx\babelprovide\@undefined
+    \bbl at error{For a language to be defined on the fly 'base'\\%
+               is not enough, and the whole package must be\\%
+               loaded. Either delete the 'base' option or\\%
+               request the languages explicitly}%
+              {See the manual for further details.}%
+  \fi
+% TODO. Option to search if loaded, with \LocaleForEach
+  \let\bbl at auxname\languagename % Still necessary. TODO
+  \bbl at ifunset{bbl at bcp@map@\languagename}{}% Move uplevel??
+    {\edef\languagename{\@nameuse{bbl at bcp@map@\languagename}}}% 
+  \ifbbl at bcpallowed
+    \expandafter\ifx\csname date\languagename\endcsname\relax
+      \expandafter
+      \bbl at bcplookup\languagename-\@empty-\@empty-\@empty\@@
+      \ifx\bbl at bcp\relax\else  % Returned by \bbl at bcplookup
+        \edef\languagename{\bbl at bcp@prefix\bbl at bcp}%
+        \edef\localename{\bbl at bcp@prefix\bbl at bcp}%
+        \expandafter\ifx\csname date\languagename\endcsname\relax
+          \let\bbl at initoload\bbl at bcp
+          \bbl at exp{\\\babelprovide[\bbl at autoload@bcpoptions]{\languagename}}%
+          \let\bbl at initoload\relax
+        \fi
+        \bbl at csarg\xdef{bcp at map@\bbl at bcp}{\localename}%
+      \fi
+    \fi
+  \fi
+  \expandafter\ifx\csname date\languagename\endcsname\relax
+    \IfFileExists{babel-\languagename.tex}%
+      {\bbl at exp{\\\babelprovide[\bbl at autoload@options]{\languagename}}}%
+      {}%
+  \fi}
+%    \end{macrocode}
+%
+%  \begin{macro}{\iflanguage}
+% Users might want to test (in a private package for instance)
+% which language is currently active. For this we provide a test
+% macro, |\iflanguage|, that has three arguments.  It checks
+% whether the first argument is a known language. If so, it
+% compares the first argument with the value of |\language|. Then,
+% depending on the result of the comparison, it executes either the
+% second or the third argument.
+%
+%    \begin{macrocode}
+\def\iflanguage#1{%
+  \bbl at iflanguage{#1}{%
+    \ifnum\csname l@#1\endcsname=\language
+      \expandafter\@firstoftwo
+    \else
+      \expandafter\@secondoftwo
+    \fi}}
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+% \subsection{Selecting the language}
+%
+%  \begin{macro}{\selectlanguage}
+%
+% The macro |\selectlanguage| checks whether the language is
+% already defined before it performs its actual task, which is to
+% update |\language| and activate language-specific definitions.
+%
+%    \begin{macrocode}
+\let\bbl at select@type\z@
+\edef\selectlanguage{%
+  \noexpand\protect
+  \expandafter\noexpand\csname selectlanguage \endcsname}
+%    \end{macrocode}
+%
+% Because the command |\selectlanguage| could be used in a moving
+% argument it expands to \verb*=\protect\selectlanguage =.
+% Therefore, we have to make sure that a macro |\protect| exists.
+% If it doesn't it is |\let| to |\relax|.
+%
+%    \begin{macrocode}
+\ifx\@undefined\protect\let\protect\relax\fi
+%    \end{macrocode}
+%
+% The following definition is preserved for backwards compatibility. It
+% is related to a trick for 2.09.
+%
+%    \begin{macrocode}
+\let\xstring\string
+%    \end{macrocode}
+%
+% \end{macro}
+%
+%    Since version 3.5 \babel\ writes entries to the auxiliary files in
+%    order to typeset table of contents etc. in the correct language
+%    environment.
+%
+% \begin{macro}{\bbl at pop@language}
+%
+% \emph{But} when the language change happens \emph{inside} a group
+% the end of the group doesn't write anything to the auxiliary
+% files. Therefore we need \TeX's |aftergroup| mechanism to help
+% us. The command |\aftergroup| stores the token immediately
+% following it to be executed when the current group is closed. So
+% we define a temporary control sequence |\bbl at pop@language| to be
+% executed at the end of the group. It calls |\bbl at set@language|
+% with the name of the current language as its argument.
+%
+% \begin{macro}{\bbl at language@stack}
+% The previous solution works for one level of nesting groups, but
+% as soon as more levels are used it is no longer adequate. For
+% that case we need to keep track of the nested languages using a
+% stack mechanism. This stack is called |\bbl at language@stack| and
+% initially empty.
+%
+%    \begin{macrocode}
+\def\bbl at language@stack{}
+%    \end{macrocode}
+%
+% When using a stack we need a mechanism to push an element on the
+% stack and to retrieve the information afterwards.
+%
+% \begin{macro}{\bbl at push@language}
+% \begin{macro}{\bbl at pop@language}
+% The stack is simply a list of languagenames, separated with a `+'
+% sign; the push function can be simple:
+%
+%    \begin{macrocode}
+\def\bbl at push@language{%
+  \ifx\languagename\@undefined\else
+    \xdef\bbl at language@stack{\languagename+\bbl at language@stack}%
+  \fi}
+%    \end{macrocode}
+%
+% Retrieving information from the stack is a little bit less simple, as
+% we need to remove the element from the stack while storing it in the
+% macro |\languagename|. For this we first define a helper function.
+%  \begin{macro}{\bbl at pop@lang}
+%    This macro stores its first element (which is delimited by the
+%    `+'-sign) in |\languagename| and stores the rest of the string
+%    (delimited by `-') in its third argument.
+%
+%    \begin{macrocode}
+\def\bbl at pop@lang#1+#2&#3{%
+  \edef\languagename{#1}\xdef#3{#2}}
+%    \end{macrocode}
+%
+%  \end{macro}
+% The reason for the somewhat weird arrangement of arguments to the
+% helper function is the fact it is called in the following way.
+% This means that before |\bbl at pop@lang| is executed \TeX\ first
+% \emph{expands} the stack, stored in |\bbl at language@stack|. The
+% result of that is that the argument string of |\bbl at pop@lang|
+% contains one or more language names, each followed by a `+'-sign
+% (zero language names won't occur as this macro will only be
+% called after something has been pushed on the stack) followed by
+% the `\&'-sign and finally the reference to the stack.
+%
+%    \begin{macrocode}
+\let\bbl at ifrestoring\@secondoftwo
+\def\bbl at pop@language{%
+  \expandafter\bbl at pop@lang\bbl at language@stack&\bbl at language@stack
+  \let\bbl at ifrestoring\@firstoftwo
+  \expandafter\bbl at set@language\expandafter{\languagename}%
+  \let\bbl at ifrestoring\@secondoftwo}
+%    \end{macrocode}
+%
+% Once the name of the previous language is retrieved from the stack,
+% it is fed to |\bbl at set@language| to do the actual work of
+% switching everything that needs switching.
+%  \end{macro}
+%  \end{macro}
+%  \end{macro}
+%
+% An alternative way to identify languages (in the \babel{} sense)
+% with a numerical value is introduced in 3.30. This is one of the
+% first steps for a new interface based on the concept of locale,
+% which explains the name of |\localeid|. This means |\l at ...| will be
+% reserved for hyphenation patterns (so that two locales can share the
+% same rules).
+%
+%    \begin{macrocode}
+\chardef\localeid\z@
+\def\bbl at id@last{0}    % No real need for a new counter
+\def\bbl at id@assign{%
+  \bbl at ifunset{bbl at id@@\languagename}%
+    {\count@\bbl at id@last\relax
+     \advance\count@\@ne
+     \bbl at csarg\chardef{id@@\languagename}\count@
+     \edef\bbl at id@last{\the\count@}%
+     \ifcase\bbl at engine\or
+       \directlua{
+         Babel = Babel or {}
+         Babel.locale_props = Babel.locale_props or {}
+         Babel.locale_props[\bbl at id@last] = {}
+         Babel.locale_props[\bbl at id@last].name = '\languagename'
+        }%
+      \fi}%
+    {}%
+    \chardef\localeid\bbl at cl{id@}}
+%    \end{macrocode}
+%
+% The unprotected part of |\selectlanguage|.
+%
+%    \begin{macrocode}
+\expandafter\def\csname selectlanguage \endcsname#1{%
+  \ifnum\bbl at hymapsel=\@cclv\let\bbl at hymapsel\tw@\fi
+  \bbl at push@language
+  \aftergroup\bbl at pop@language
+  \bbl at set@language{#1}}
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+%  \begin{macro}{\bbl at set@language}
+%
+% The macro |\bbl at set@language| takes care of switching the language
+% environment \emph{and} of writing entries on the auxiliary files.
+% For historial reasons, language names can be either |language| of
+% |\language|. To catch either form a trick is used, but
+% unfortunately as a side effect the catcodes of letters in
+% |\languagename| are messed up. This is a bug, but preserved for
+% backwards compatibility. The list of auxiliary files can be
+% extended by redefining |\BabelContentsFiles|, but make sure they
+% are loaded inside a group (as |aux|, |toc|, |lof|, and |lot| do)
+% or the last language of the document will remain active
+% afterwards.
+%
+% We also write a command to change the current language in the
+% auxiliary files.
+%
+%    \begin{macrocode}
+\def\BabelContentsFiles{toc,lof,lot}
+\def\bbl at set@language#1{% from selectlanguage, pop@
+  % The old buggy way. Preserved for compatibility.
+  \edef\languagename{%
+    \ifnum\escapechar=\expandafter`\string#1\@empty
+    \else\string#1\@empty\fi}%
+  \ifcat\relax\noexpand#1%
+    \expandafter\ifx\csname date\languagename\endcsname\relax
+      \edef\languagename{#1}%
+      \let\localename\languagename
+    \else
+      \bbl at info{Using '\string\language' instead of 'language' is\\%
+                deprecated. If what you want is to use a\\%
+                macro containing the actual locale, make\\%
+                sure it does not not match any language.\\%
+                Reported}%
+%                 I'll\\%
+%                 try to fix '\string\localename', but I cannot promise\\%
+%                 anything. Reported}%
+      \ifx\scantokens\@undefined
+         \def\localename{??}%
+      \else
+        \scantokens\expandafter{\expandafter
+          \def\expandafter\localename\expandafter{\languagename}}%
+      \fi
+    \fi
+  \else
+    \def\localename{#1}% This one has the correct catcodes
+  \fi
+  \select at language{\languagename}%
+  % write to auxs
+  \expandafter\ifx\csname date\languagename\endcsname\relax\else
+    \if at filesw
+      \ifx\babel at aux\@gobbletwo\else % Set if single in the first, redundant
+        \protected at write\@auxout{}{\string\babel at aux{\bbl at auxname}{}}%
+      \fi
+      \bbl at usehooks{write}{}%
+    \fi
+  \fi}
+% 
+\newif\ifbbl at bcpallowed
+\bbl at bcpallowedfalse
+\def\select at language#1{% from set@, babel at aux
+  % set hymap
+  \ifnum\bbl at hymapsel=\@cclv\chardef\bbl at hymapsel4\relax\fi
+  % set name
+  \edef\languagename{#1}%
+  \bbl at fixname\languagename
+  % TODO. name at map must be here?
+  \bbl at provide@locale
+  \bbl at iflanguage\languagename{%
+     \expandafter\ifx\csname date\languagename\endcsname\relax
+      \bbl at error
+        {Unknown language `\languagename'. Either you have\\%
+         misspelled its name, it has not been installed,\\%
+         or you requested it in a previous run. Fix its name,\\%
+         install it or just rerun the file, respectively. In\\%
+         some cases, you may need to remove the aux file}%
+        {You may proceed, but expect wrong results}%
+    \else
+      % set type
+      \let\bbl at select@type\z@
+      \expandafter\bbl at switch\expandafter{\languagename}%
+    \fi}}
+\def\babel at aux#1#2{%
+  \select at language{#1}%
+  \bbl at foreach\BabelContentsFiles{%
+    \@writefile{##1}{\babel at toc{#1}{#2}}}}% %% TODO - ok in plain?
+\def\babel at toc#1#2{%
+  \select at language{#1}}
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+% First, check if the user asks for a known language. If so,
+% update the value of |\language| and call |\originalTeX|
+% to bring \TeX\ in a certain pre-defined state.
+%
+% The name of the language is stored in the control sequence
+% |\languagename|.
+%
+% Then we have to \emph{re}define |\originalTeX| to compensate for
+% the things that have been activated.  To save memory space for
+% the macro definition of |\originalTeX|, we construct the control
+% sequence name for the |\noextras|\langvar\ command at definition
+% time by expanding the |\csname| primitive.
+%
+% Now activate the language-specific definitions. This is done by
+% constructing the names of three macros by concatenating three
+% words with the argument of |\selectlanguage|, and calling these
+% macros. \nb{What if \cs{hyphenation} was used in |extras|? Patch
+% temporarily |\set at hyphenmins| and hyphenation. It can be done in
+% hooks if necessary.}
+%
+% The switching of the values of |\lefthyphenmin| and
+% |\righthyphenmin| is somewhat different. First we save their
+% current values, then we check if |\|\langvar|hyphenmins| is
+% defined. If it is not, we set default values (2 and 3), otherwise
+% the values in |\|\langvar|hyphenmins| will be used.
+%
+%    \begin{macrocode}
+\newif\ifbbl at usedategroup
+\def\bbl at switch#1{%  from select@, foreign@
+  % make sure there is info for the language if so requested
+  \bbl at ensureinfo{#1}%
+  % restore
+  \originalTeX
+  \expandafter\def\expandafter\originalTeX\expandafter{%
+    \csname noextras#1\endcsname
+    \let\originalTeX\@empty
+    \babel at beginsave}%
+  \bbl at usehooks{afterreset}{}%
+  \languageshorthands{none}%
+  % set the locale id
+  \bbl at id@assign
+  % switch captions, date
+  \ifcase\bbl at select@type
+    \ifhmode
+      \hskip\z at skip % trick to ignore spaces
+      \csname captions#1\endcsname\relax
+      \csname date#1\endcsname\relax
+      \loop\ifdim\lastskip>\z@\unskip\repeat\unskip
+    \else
+      \csname captions#1\endcsname\relax
+      \csname date#1\endcsname\relax
+    \fi
+  \else
+    \ifbbl at usedategroup   % if \foreign... within \<lang>date
+      \bbl at usedategroupfalse
+      \ifhmode
+        \hskip\z at skip % trick to ignore spaces
+        \csname date#1\endcsname\relax
+        \loop\ifdim\lastskip>\z@\unskip\repeat\unskip
+      \else
+        \csname date#1\endcsname\relax
+      \fi
+    \fi
+  \fi
+  % switch extras
+  \bbl at usehooks{beforeextras}{}%
+  \csname extras#1\endcsname\relax
+  \bbl at usehooks{afterextras}{}%
+  %  > babel-ensure
+  %  > babel-sh-<short>
+  %  > babel-bidi
+  %  > babel-fontspec
+  % hyphenation - case mapping
+  \ifcase\bbl at opt@hyphenmap\or
+    \def\BabelLower##1##2{\lccode##1=##2\relax}%
+    \ifnum\bbl at hymapsel>4\else
+      \csname\languagename @bbl at hyphenmap\endcsname
+    \fi
+    \chardef\bbl at opt@hyphenmap\z@
+  \else
+    \ifnum\bbl at hymapsel>\bbl at opt@hyphenmap\else
+      \csname\languagename @bbl at hyphenmap\endcsname
+    \fi
+  \fi
+  \global\let\bbl at hymapsel\@cclv
+  % hyphenation - patterns
+  \bbl at patterns{#1}%
+  % hyphenation - mins
+  \babel at savevariable\lefthyphenmin
+  \babel at savevariable\righthyphenmin
+  \expandafter\ifx\csname #1hyphenmins\endcsname\relax
+    \set at hyphenmins\tw@\thr@@\relax
+  \else
+    \expandafter\expandafter\expandafter\set at hyphenmins
+      \csname #1hyphenmins\endcsname\relax
+  \fi}
+%    \end{macrocode}
+%
+% \begin{environment}{otherlanguage}
+% The \Lenv{otherlanguage} environment can be used as an
+% alternative to using the |\selectlanguage| declarative
+% command. When you are typesetting a document which mixes
+% left-to-right and right-to-left typesetting you have to use this
+% environment in order to let things work as you expect them to.
+%
+% The |\ignorespaces| command is necessary to hide the environment
+% when it is entered in horizontal mode.
+%
+%    \begin{macrocode}
+\long\def\otherlanguage#1{%
+  \ifnum\bbl at hymapsel=\@cclv\let\bbl at hymapsel\thr@@\fi
+  \csname selectlanguage \endcsname{#1}%
+  \ignorespaces}
+%    \end{macrocode}
+%
+% The |\endotherlanguage| part of the environment tries to hide
+% itself when it is called in horizontal mode.
+%
+%    \begin{macrocode}
+\long\def\endotherlanguage{%
+  \global\@ignoretrue\ignorespaces}
+%    \end{macrocode}
+%
+%  \end{environment}
+%
+% \begin{environment}{otherlanguage*}
+% The \Lenv{otherlanguage} environment is meant to be used when a
+% large part of text from a different language needs to be typeset,
+% but without changing the translation of words such as `figure'.
+% This environment makes use of |\foreign at language|.
+%
+%    \begin{macrocode}
+\expandafter\def\csname otherlanguage*\endcsname#1{%
+  \ifnum\bbl at hymapsel=\@cclv\chardef\bbl at hymapsel4\relax\fi
+  \foreign at language{#1}}
+%    \end{macrocode}
+%
+% At the end of the environment we need to switch off the extra
+% definitions. The grouping mechanism of the environment will take
+% care of resetting the correct hyphenation rules and ``extras''.
+%
+%    \begin{macrocode}
+\expandafter\let\csname endotherlanguage*\endcsname\relax
+%    \end{macrocode}
+%
+%  \end{environment}
+%
+% \begin{macro}{\foreignlanguage}
+%
+% The |\foreignlanguage| command is another substitute for the
+% |\selectlanguage| command. This command takes two arguments, the
+% first argument is the name of the language to use for typesetting
+% the text specified in the second argument.
+%
+% Unlike |\selectlanguage| this command doesn't switch
+% \emph{everything}, it only switches the hyphenation rules and the
+% extra definitions for the language specified. It does this within
+% a group and assumes the |\extras|\langvar\ command doesn't make
+% any |\global| changes. The coding is very similar to part of
+% |\selectlanguage|.
+%
+% |\bbl at beforeforeign| is a trick to fix a bug in bidi
+% texts. |\foreignlanguage| is supposed to be a `text' command, and
+% therefore it must emit a |\leavevmode|, but it does not, and
+% therefore the indent is placed on the opposite margin. For
+% backward compatibility, however, it is done only if a
+% right-to-left script is requested; otherwise, it is no-op.
+%
+% (3.11) |\foreignlanguage*| is a temporary, experimental macro for
+% a few lines with a different script direction, while preserving
+% the paragraph format (thank the braces around |\par|, things like
+% |\hangindent| are not reset). Do not use it in production,
+% because its semantics and its syntax may change (and very likely
+% will, or even it could be removed altogether). Currently it
+% enters in vmode and then selects the language (which in turn sets the
+% paragraph direction).
+%
+% (3.11) Also experimental are the hook |foreign| and |foreign*|.
+% With them you can redefine |\BabelText| which by default does
+% nothing. Its behavior is not well defined yet. So, use it in
+% horizontal mode only if you do not want surprises.
+%
+% In other words, at the beginning of a paragraph |\foreignlanguage|
+% enters into hmode with the surrounding lang, and with
+% |\foreignlanguage*| with the new lang.
+%
+%    \begin{macrocode}
+\providecommand\bbl at beforeforeign{}
+\edef\foreignlanguage{%
+  \noexpand\protect
+  \expandafter\noexpand\csname foreignlanguage \endcsname}
+\expandafter\def\csname foreignlanguage \endcsname{%
+  \@ifstar\bbl at foreign@s\bbl at foreign@x}
+\def\bbl at foreign@x#1#2{%
+  \begingroup
+    \let\BabelText\@firstofone
+    \bbl at beforeforeign
+    \foreign at language{#1}%
+    \bbl at usehooks{foreign}{}%
+    \BabelText{#2}% Now in horizontal mode!
+  \endgroup}
+\def\bbl at foreign@s#1#2{% TODO - \shapemode, \@setpar, ?\@@par
+  \begingroup
+    {\par}%
+    \let\BabelText\@firstofone
+    \foreign at language{#1}%
+    \bbl at usehooks{foreign*}{}%
+    \bbl at dirparastext
+    \BabelText{#2}% Still in vertical mode!
+    {\par}%
+  \endgroup}
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+%  \begin{macro}{\foreign at language}
+%
+% This macro does the work for |\foreignlanguage| and the
+% \Lenv{otherlanguage*} environment. First we need to store the name
+% of the language and check that it is a known language. Then it
+% just calls |bbl at switch|.
+%
+%    \begin{macrocode}
+\def\foreign at language#1{%
+  % set name
+  \edef\languagename{#1}%
+  \bbl at fixname\languagename
+  % TODO. name at map here?
+  \bbl at provide@locale
+  \bbl at iflanguage\languagename{%
+    \expandafter\ifx\csname date\languagename\endcsname\relax
+      \bbl at warning   % TODO - why a warning, not an error?
+        {Unknown language `#1'. Either you have\\%
+         misspelled its name, it has not been installed,\\%
+         or you requested it in a previous run. Fix its name,\\%
+         install it or just rerun the file, respectively. In\\%
+         some cases, you may need to remove the aux file.\\%
+         I'll proceed, but expect wrong results.\\%
+         Reported}%
+    \fi
+    % set type
+    \let\bbl at select@type\@ne
+    \expandafter\bbl at switch\expandafter{\languagename}}}
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+% \begin{macro}{\bbl at patterns}
+%
+% This macro selects the hyphenation patterns by changing the
+% \cs{language} register.  If special hyphenation patterns
+% are available specifically for the current font encoding,
+% use them instead of the default.
+%
+% It also sets hyphenation exceptions, but only once, because they
+% are global (here language |\lccode|'s has been set, too).
+% |\bbl at hyphenation@| is set to relax until the very first
+% |\babelhyphenation|, so do nothing with this value. If the
+% exceptions for a language (by its number, not its name, so that
+% |:ENC| is taken into account) has been set, then use
+% |\hyphenation| with both global and language exceptions and empty
+% the latter to mark they must not be set again.
+%
+%    \begin{macrocode}
+\let\bbl at hyphlist\@empty
+\let\bbl at hyphenation@\relax
+\let\bbl at pttnlist\@empty
+\let\bbl at patterns@\relax
+\let\bbl at hymapsel=\@cclv
+\def\bbl at patterns#1{%
+  \language=\expandafter\ifx\csname l@#1:\f at encoding\endcsname\relax
+      \csname l@#1\endcsname
+      \edef\bbl at tempa{#1}%
+    \else
+      \csname l@#1:\f at encoding\endcsname
+      \edef\bbl at tempa{#1:\f at encoding}%
+    \fi
+  \@expandtwoargs\bbl at usehooks{patterns}{{#1}{\bbl at tempa}}%
+  %  > luatex
+  \@ifundefined{bbl at hyphenation@}{}{% Can be \relax!
+    \begingroup
+      \bbl at xin@{,\number\language,}{,\bbl at hyphlist}%
+      \ifin@\else
+        \@expandtwoargs\bbl at usehooks{hyphenation}{{#1}{\bbl at tempa}}%
+        \hyphenation{%
+          \bbl at hyphenation@
+          \@ifundefined{bbl at hyphenation@#1}%
+            \@empty
+            {\space\csname bbl at hyphenation@#1\endcsname}}%
+        \xdef\bbl at hyphlist{\bbl at hyphlist\number\language,}%
+      \fi
+    \endgroup}}
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+% \begin{environment}{hyphenrules}
+%
+% The environment \Lenv{hyphenrules} can be used to select
+% \emph{just} the hyphenation rules. This environment does
+% \emph{not} change |\languagename| and when the hyphenation rules
+% specified were not loaded it has no effect. Note however,
+% |\lccode|'s and font encodings are not set at all, so in most
+% cases you should use |otherlanguage*|.
+%
+%    \begin{macrocode}
+\def\hyphenrules#1{%
+  \edef\bbl at tempf{#1}%
+  \bbl at fixname\bbl at tempf
+  \bbl at iflanguage\bbl at tempf{%
+    \expandafter\bbl at patterns\expandafter{\bbl at tempf}%
+    \languageshorthands{none}%
+    \expandafter\ifx\csname\bbl at tempf hyphenmins\endcsname\relax
+      \set at hyphenmins\tw@\thr@@\relax
+    \else
+      \expandafter\expandafter\expandafter\set at hyphenmins
+      \csname\bbl at tempf hyphenmins\endcsname\relax
+    \fi}}
+\let\endhyphenrules\@empty
+%    \end{macrocode}
+%
+%  \end{environment}
+%
+% \begin{macro}{\providehyphenmins}
+% The macro |\providehyphenmins| should be used in the language
+% definition files to provide a \emph{default} setting for the
+% hyphenation parameters |\lefthyphenmin| and |\righthyphenmin|. If
+% the macro |\|\langvar|hyphenmins| is already defined this command
+% has no effect.
+%
+%    \begin{macrocode}
+\def\providehyphenmins#1#2{%
+  \expandafter\ifx\csname #1hyphenmins\endcsname\relax
+    \@namedef{#1hyphenmins}{#2}%
+  \fi}
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+%  \begin{macro}{\set at hyphenmins}
+%    This macro sets the values of |\lefthyphenmin| and
+%    |\righthyphenmin|. It expects two values as its argument.
+%
+%    \begin{macrocode}
+\def\set at hyphenmins#1#2{%
+  \lefthyphenmin#1\relax
+  \righthyphenmin#2\relax}
+%    \end{macrocode}
+%
+% \end{macro}
+%
+% \begin{macro}{\ProvidesLanguage}
+% The identification code for each file is something that was
+% introduced in \LaTeXe. When the command |\ProvidesFile| does not
+% exist, a dummy definition is provided temporarily. For use in the
+% language definition file the command |\ProvidesLanguage| is
+% defined by \babel.
+%
+% Depending on the format, ie, on if the former is defined, we use
+% a similar definition or not.
+%
+%    \begin{macrocode}
+\ifx\ProvidesFile\@undefined
+  \def\ProvidesLanguage#1[#2 #3 #4]{%
+    \wlog{Language: #1 #4 #3 <#2>}%
+    }
+\else
+  \def\ProvidesLanguage#1{%
+    \begingroup
+      \catcode`\ 10 %
+      \@makeother\/%
+      \@ifnextchar[%]
+        {\@provideslanguage{#1}}{\@provideslanguage{#1}[]}}
+  \def\@provideslanguage#1[#2]{%
+    \wlog{Language: #1 #2}%
+    \expandafter\xdef\csname ver@#1.ldf\endcsname{#2}%
+    \endgroup}
 \fi
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+%  \begin{macro}{\originalTeX}
+%    The macro|\originalTeX| should be known to \TeX\ at this moment.
+%    As it has to be expandable we |\let| it to |\@empty| instead of
+%    |\relax|.
+%
+%    \begin{macrocode}
+\ifx\originalTeX\@undefined\let\originalTeX\@empty\fi
+%    \end{macrocode}
+%
+%    Because this part of the code can be included in a format, we
+%    make sure that the macro which initializes the save mechanism,
+%    |\babel at beginsave|, is not considered to be undefined.
+%
+%    \begin{macrocode}
+\ifx\babel at beginsave\@undefined\let\babel at beginsave\relax\fi
+%    \end{macrocode}
+%
+%  \end{macro}
+%
+% A few macro names are reserved for future releases of \babel, which
+% will use the concept of `locale':
+%
+%    \begin{macrocode}
+\providecommand\setlocale{%
+  \bbl at error
+    {Not yet available}%
+    {Find an armchair, sit down and wait}}
+\let\uselocale\setlocale
+\let\locale\setlocale
+\let\selectlocale\setlocale
+\let\localename\setlocale
+\let\textlocale\setlocale
+\let\textlanguage\setlocale
+\let\languagetext\setlocale
+%    \end{macrocode}
+%
+% \subsection{Errors}
+%
+% \begin{macro}{\@nolanerr}
+% \begin{macro}{\@nopatterns}
+%
+% The \babel\ package will signal an error when a documents tries
+% to select a language that hasn't been defined earlier. When a
+% user selects a language for which no hyphenation patterns were
+% loaded into the format he will be given a warning about that
+% fact. We revert to the patterns for |\language|=0 in that case.
+% In most formats that will be (US)english, but it might also be
+% empty.
+%
+% \begin{macro}{\@noopterr}
+% When the package was loaded without options not everything will
+% work as expected. An error message is issued in that case.
+%
+% When the format knows about |\PackageError| it must be \LaTeXe,
+% so we can safely use its error handling interface. Otherwise
+% we'll have to `keep it simple'.
+%
+% Infos are not written to the console, but on the other hand many
+% people think warnings are errors, so a further message type is
+% defined: an important info which is sent to the console.
+%
+%    \begin{macrocode}
+\edef\bbl at nulllanguage{\string\language=0}
+\ifx\PackageError\@undefined  % TODO. Move to Plain
+  \def\bbl at error#1#2{%
+    \begingroup
+      \newlinechar=`\^^J
+      \def\\{^^J(babel) }%
+      \errhelp{#2}\errmessage{\\#1}%
+    \endgroup}
+  \def\bbl at warning#1{%
+    \begingroup
+      \newlinechar=`\^^J
+      \def\\{^^J(babel) }%
+      \message{\\#1}%
+    \endgroup}
+  \let\bbl at infowarn\bbl at warning
+  \def\bbl at info#1{%
+    \begingroup
+      \newlinechar=`\^^J
+      \def\\{^^J}%
+      \wlog{#1}%
+    \endgroup}
+\fi
+\def\bbl at nocaption{\protect\bbl at nocaption@i}
+\def\bbl at nocaption@i#1#2{% 1: text to be printed 2: caption macro \langXname
+  \global\@namedef{#2}{\textbf{?#1?}}%
+  \@nameuse{#2}%
+  \bbl at warning{%
+    \@backslashchar#2 not set. Please, define\\%
+    it in the preamble with something like:\\%
+    \string\renewcommand\@backslashchar#2{..}\\%
+    Reported}}
+\def\bbl at tentative{\protect\bbl at tentative@i}
+\def\bbl at tentative@i#1{%
+  \bbl at warning{%
+    Some functions for '#1' are tentative.\\%
+    They might not work as expected and their behavior\\%
+    could change in the future.\\%
+    Reported}}
+\def\@nolanerr#1{%
+  \bbl at error
+    {You haven't defined the language #1\space yet.\\%
+     Perhaps you misspelled it or your installation\\%
+     is not complete}%
+    {Your command will be ignored, type <return> to proceed}}
+\def\@nopatterns#1{%
+  \bbl at warning
+    {No hyphenation patterns were preloaded for\\%
+     the language `#1' into the format.\\%
+     Please, configure your TeX system to add them and\\%
+     rebuild the format. Now I will use the patterns\\%
+     preloaded for \bbl at nulllanguage\space instead}}
+\let\bbl at usehooks\@gobbletwo
+\ifx\bbl at onlyswitch\@empty\endinput\fi
+  % Here ended switch.def
+%    \end{macrocode}
+%
+% Here ended |switch.def|.
+%
+%    \begin{macrocode}
+\ifx\directlua\@undefined\else
+  \ifx\bbl at luapatterns\@undefined
+    \input luababel.def
+  \fi
+\fi
+<@Basic macros@>
 \bbl at trace{Compatibility with language.def}
 \ifx\bbl at languages\@undefined
   \ifx\directlua\@undefined
-    \openin1 = language.def
+    \openin1 = language.def % TODO. Remove hardcoded number
     \ifeof1
       \closein1
       \message{I couldn't find the file language.def}
@@ -5509,26 +7484,17 @@
   \fi
   \chardef\l at english\z@
 \fi
-<@Load patterns in luatex@>
-<@Basic macros@>
 %    \end{macrocode}
 %
 %  \begin{macro}{\addto}
-%    For each language four control sequences have to be defined that
-%    control the language-specific definitions. To be able to add
-%    something to these macro once they have been defined the macro
-%    |\addto| is introduced. It takes two arguments, a \meta{control
-%    sequence} and \TeX-code to be added to the \meta{control
-%    sequence}.
+% It takes two arguments, a \meta{control sequence} and \TeX-code to
+% be added to the \meta{control sequence}.
 %
-%    If the \meta{control sequence} has not been defined before it is
-%    defined now.  The control sequence could also expand to |\relax|,
-%    in which case a circular definition results. The net result is a
-%    stack overflow.  Otherwise the replacement text for the
-%    \meta{control sequence} is expanded and stored in a token
-%    register, together with the \TeX-code to be added.  Finally the
-%    \meta{control sequence} is \emph{re}defined, using the contents
-%    of the token register.
+% If the \meta{control sequence} has not been defined before it is
+% defined now.  The control sequence could also expand to |\relax|,
+% in which case a circular definition results. The net result is a
+% stack overflow.  Note there is an inconsistency, because the
+% assignment in the last branch is global. 
 %
 %    \begin{macrocode}
 \def\addto#1#2{%
@@ -5546,9 +7512,11 @@
 %
 %  \end{macro}
 %
-%    The macro |\initiate at active@char| takes all the necessary actions
-%    to make its argument a shorthand character. The real work is
-%    performed once for each character.
+% The macro |\initiate at active@char| below takes all the necessary
+% actions to make its argument a shorthand character. The real work
+% is performed once for each character. But first we define a little
+% tool. TODO. Always used with additional expansions. Move them here?
+% Move the macro to basic?
 %
 %    \begin{macrocode}
 \def\bbl at withactive#1#2{%
@@ -5558,15 +7526,13 @@
 %    \end{macrocode}
 %
 %  \begin{macro}{\bbl at redefine}
-%    To redefine a command, we save the old meaning of the macro.
-%    Then we redefine it to call the original macro with the
-%    `sanitized' argument.  The reason why we do it this way is that
-%    we don't want to redefine the \LaTeX\ macros completely in case
-%    their definitions change (they have changed in the past).
 %
-%    Because we need to redefine a number of commands we define the
-%    command |\bbl at redefine| which takes care of this. It creates a
-%    new control sequence, |\org at ...|
+% To redefine a command, we save the old meaning of the macro. Then
+% we redefine it to call the original macro with the `sanitized'
+% argument. The reason why we do it this way is that we don't want
+% to redefine the \LaTeX\ macros completely in case their
+% definitions change (they have changed in the past). A macro named
+% |\macro| will be saved new control sequences named |\org at macro|.
 %
 %    \begin{macrocode}
 \def\bbl at redefine#1{%
@@ -5573,11 +7539,6 @@
   \edef\bbl at tempa{\bbl at stripslash#1}%
   \expandafter\let\csname org@\bbl at tempa\endcsname#1%
   \expandafter\def\csname\bbl at tempa\endcsname}
-%    \end{macrocode}
-%
-%    This command should only be used in the preamble of the document.
-%
-%    \begin{macrocode}
 \@onlypreamble\bbl at redefine
 %    \end{macrocode}
 %
@@ -5597,13 +7558,13 @@
 %
 %  \end{macro}
 %
-%  \begin{macro}{\bbl at redefinerobust}
-%    For commands that are redefined, but which \textit{might} be
-%    robust we need a slightly more intelligent macro. A robust
-%    command |foo| is defined to expand to |\protect|\verb*|\foo |. So
-%    it is necessary to check whether \verb*|\foo | exists. The result
-%    is that the command that is being redefined is always robust
-%    afterwards.  Therefore all we need to do now is define \verb*|\foo |.
+% \begin{macro}{\bbl at redefinerobust}
+% For commands that are redefined, but which \textit{might} be
+% robust we need a slightly more intelligent macro. A robust
+% command |foo| is defined to expand to |\protect|\verb*|\foo |. So
+% it is necessary to check whether \verb*|\foo | exists. The result
+% is that the command that is being redefined is always robust
+% afterwards.  Therefore all we need to do now is define \verb*|\foo |.
 %
 %    \begin{macrocode}
 \def\bbl at redefinerobust#1{%
@@ -5613,11 +7574,6 @@
      \bbl at exp{\def\\#1{\\\protect\<\bbl at tempa\space>}}}%
     {\bbl at exp{\let\<org@\bbl at tempa>\<\bbl at tempa\space>}}%
     \@namedef{\bbl at tempa\space}}
-%    \end{macrocode}
-%
-%    This command should only be used in the preamble of the document.
-%
-%    \begin{macrocode}
 \@onlypreamble\bbl at redefinerobust
 %    \end{macrocode}
 %
@@ -5625,12 +7581,10 @@
 %
 % \subsection{Hooks}
 %
-%  Note they are loaded in babel.def. switch.def only provides a
-%  ``hook'' for hooks (with a default value which is a no-op,
-%  below). Admittedly, the current implementation is a somewhat
-%  simplistic and does vety little to catch errors, but it is intended
-%  for developpers, after all. |\bbl at usehooks| is the commands used by
-%  babel to execute hooks defined for an event.
+% Admittedly, the current implementation is a somewhat simplistic and
+% does very little to catch errors, but it is meant for developers,
+% after all. |\bbl at usehooks| is the commands used by \babel{} to execute
+% hooks defined for an event.
 %
 %    \begin{macrocode}
 \bbl at trace{Hooks}
@@ -5655,11 +7609,11 @@
   \fi}
 %    \end{macrocode}
 %
-%    To ensure forward compatibility, arguments in hooks are set
-%    implicitly. So, if a further argument is added in the future,
-%    there is no need to change the existing code. Note events
-%    intended for \textsf{hyphen.cfg} are also loaded (just in
-%    case you need them for some reason).
+% To ensure forward compatibility, arguments in hooks are set
+% implicitly. So, if a further argument is added in the future,
+% there is no need to change the existing code. Note events
+% intended for \textsf{hyphen.cfg} are also loaded (just in
+% case you need them for some reason).
 %
 %    \begin{macrocode}
 \def\bbl at evargs{,% <- don't delete this comma
@@ -5667,7 +7621,7 @@
   adddialect=2,patterns=2,defaultcommands=0,encodedcommands=2,write=0,%
   beforeextras=0,afterextras=0,stopcommands=0,stringprocess=0,%
   hyphenation=2,initiateactive=3,afterreset=0,foreign=0,foreign*=0,%
-  beforestart=0,languagename=0}
+  beforestart=0,languagename=2}
 %    \end{macrocode}
 %
 % \begin{macro}{\babelensure}
@@ -5716,7 +7670,7 @@
   \def\<bbl at e@#2>{\the\toks@{\bbl at ens@fontenc}}}}
 \def\bbl at ensure#1#2#3{% 1: include 2: exclude 3: fontenc
   \def\bbl at tempb##1{% elt for (excluding) \bbl at captionslist list
-    \ifx##1\@undefined % 3.32 - Don't assume the macros exists
+    \ifx##1\@undefined % 3.32 - Don't assume the macro exists
       \edef##1{\noexpand\bbl at nocaption
         {\bbl at stripslash##1}{\languagename\bbl at stripslash##1}}%
     \fi
@@ -5761,42 +7715,43 @@
 % \subsection{Setting up language files}
 %
 % \begin{macro}{\LdfInit}
-%    The second version of |\LdfInit| macro takes two arguments. The first
-%    argument is the name of the language that will be defined in the
-%    language definition file; the second argument is either a control
-%    sequence or a string from which a control sequence should be
-%    constructed. The existence of the control sequence indicates that
-%    the file has been processed before.
 %
-%    At the start of processing a language definition file we always
-%    check the category code of the at-sign. We make sure that it is
-%    a `letter' during the processing of the file. We also save its
-%    name as the last called option, even if not loaded.
+% |\LdfInit| macro takes two arguments. The first
+% argument is the name of the language that will be defined in the
+% language definition file; the second argument is either a control
+% sequence or a string from which a control sequence should be
+% constructed. The existence of the control sequence indicates that
+% the file has been processed before.
 %
-%    Another character that needs to have the correct category code
-%    during processing of language definition files is the equals sign,
-%    `=', because it is sometimes used in constructions with the
-%    |\let| primitive. Therefore we store its current catcode and
-%    restore it later on.
+% At the start of processing a language definition file we always
+% check the category code of the at-sign. We make sure that it is
+% a `letter' during the processing of the file. We also save its
+% name as the last called option, even if not loaded.
 %
-%    Now we check whether we should perhaps stop the processing of
-%    this file. To do this we first need to check whether the second
-%    argument that is passed to |\LdfInit| is a control sequence. We
-%    do that by looking at the first token after passing |#2| through
-%    |string|. When it is equal to |\@backslashchar| we are dealing
-%    with a control sequence which we can compare with |\@undefined|.
+% Another character that needs to have the correct category code
+% during processing of language definition files is the equals sign,
+% `=', because it is sometimes used in constructions with the
+% |\let| primitive. Therefore we store its current catcode and
+% restore it later on.
 %
-%   If so, we call |\ldf at quit| to set the main language, restore the
-%   category code of the @-sign and call |\endinput|
+% Now we check whether we should perhaps stop the processing of
+% this file. To do this we first need to check whether the second
+% argument that is passed to |\LdfInit| is a control sequence. We
+% do that by looking at the first token after passing |#2| through
+% |string|. When it is equal to |\@backslashchar| we are dealing
+% with a control sequence which we can compare with |\@undefined|.
 %
-%    When |#2| was \emph{not} a control sequence we construct one and
-%    compare it with |\relax|.
+% If so, we call |\ldf at quit| to set the main language, restore the
+% category code of the @-sign and call |\endinput|
 %
-%    Finally we check |\originalTeX|.
+% When |#2| was \emph{not} a control sequence we construct one and
+% compare it with |\relax|.
 %
+% Finally we check |\originalTeX|.
+%
 %    \begin{macrocode}
 \bbl at trace{Macros for setting language files up}
-\def\bbl at ldfinit{%
+\def\bbl at ldfinit{% TODO. Merge into the next macro? Unused elsewhere
   \let\bbl at screset\@empty
   \let\BabelStrings\bbl at opt@string
   \let\BabelOptions\@empty
@@ -5849,13 +7804,15 @@
 %    category code of the @-sign.
 %
 %    \begin{macrocode}
-\def\bbl at afterldf#1{%
+\def\bbl at afterldf#1{% TODO. Merge into the next macro? Unused elsewhere
   \bbl at afterlang
   \let\bbl at afterlang\relax
   \let\BabelModifiers\relax
   \let\bbl at screset\relax}%
 \def\ldf at finish#1{%
-  \loadlocalcfg{#1}%
+  \ifx\loadlocalcfg\@undefined\else % For LaTeX 209
+    \loadlocalcfg{#1}%
+  \fi
   \bbl at afterldf{#1}%
   \expandafter\main at language\expandafter{#1}%
   \catcode`\@=\atcatcode \let\atcatcode\relax
@@ -5884,14 +7841,16 @@
 %    \begin{macrocode}
 \def\main at language#1{%
   \def\bbl at main@language{#1}%
-  \let\languagename\bbl at main@language
+  \let\languagename\bbl at main@language % TODO. Set localename
   \bbl at id@assign
   \bbl at patterns{\languagename}}
 %    \end{macrocode}
 %
-%    We also have to make sure that some code gets executed at the
-%    beginning of the document. Languages do not set |\pagedir|, so
-%    we set here for the whole document to the main |\bodydir|.
+% We also have to make sure that some code gets executed at the
+% beginning of the document, either when the |aux| file is read or,
+% if it does not exist, when the |\AtBeginDocument| is executed.
+% Languages do not set |\pagedir|, so we set here for the whole
+% document to the main |\bodydir|.
 %
 %    \begin{macrocode}
 \def\bbl at beforestart{%
@@ -5898,17 +7857,17 @@
   \bbl at usehooks{beforestart}{}%
   \global\let\bbl at beforestart\relax}
 \AtBeginDocument{%
-  \bbl at cs{beforestart}%
+  \@nameuse{bbl at beforestart}%
   \if at filesw
-    \immediate\write\@mainaux{\string\bbl at cs{beforestart}}%
+    \immediate\write\@mainaux{\string\@nameuse{bbl at beforestart}}%
   \fi
   \expandafter\selectlanguage\expandafter{\bbl at main@language}%
-  \ifbbl at single  % must go after the line above
+  \ifbbl at single  % must go after the line above.
     \renewcommand\selectlanguage[1]{}%
     \renewcommand\foreignlanguage[2]{#2}%
     \global\let\babel at aux\@gobbletwo  % Also as flag
   \fi
-  \ifcase\bbl at engine\or\pagedir\bodydir\fi}  % TODO - a better place
+  \ifcase\bbl at engine\or\pagedir\bodydir\fi} % TODO - a better place
 %    \end{macrocode}
 %
 %  \end{macro}
@@ -6269,7 +8228,7 @@
 %
 %    \begin{macrocode}
 \begingroup
-\bbl at ifunset{ifincsname}%
+\bbl at ifunset{ifincsname}% TODO. Ugly. Correct?
   {\gdef\active at prefix#1{%
      \ifx\protect\@typeset at protect
      \else
@@ -6332,8 +8291,7 @@
 %    Both macros take one argument, like |\initiate at active@char|. The
 %    macro is used to change the definition of an active character to
 %    expand to |\active at char|\m{char} in the case of |\bbl at activate|,
-%    or |\normal at char|\m{char} in the case of
-%    |\bbl at deactivate|.
+%    or |\normal at char|\m{char} in the case of |\bbl at deactivate|.
 %
 %    \begin{macrocode}
 \def\bbl at activate#1{%
@@ -6349,9 +8307,9 @@
 %
 %  \begin{macro}{\bbl at firstcs}
 %  \begin{macro}{\bbl at scndcs}
-%    These macros have two arguments. They use one of their arguments
-%    to build a control sequence from.
 %
+% These macros are used only as a trick when declaring shorthands.
+%
 %    \begin{macrocode}
 \def\bbl at firstcs#1#2{\csname#1\endcsname}
 \def\bbl at scndcs#1#2{\csname#2\endcsname}
@@ -6429,7 +8387,7 @@
 %
 %    \begin{macrocode}
 \def\user at group{user}
-\def\language at group{english}
+\def\language at group{english} % TODO. I don't like defaults
 \def\system at group{system}
 %    \end{macrocode}
 %
@@ -6438,11 +8396,9 @@
 %  \end{macro}
 %
 %  \begin{macro}{\useshorthands}
-%    This is the user level command to tell \LaTeX\ that user level
-%    shorthands will be used in the document. It takes one argument,
-%    the character that starts a shorthand. First note that this is
-%    user level, and then initialize and activate the character for
-%    use as a shorthand character (ie, it's active in the
+%
+%    This is the user level macro. It initializes and activates the
+%    character for use as a shorthand character (ie, it's active in the
 %    preamble). Languages can deactivate shorthands, so a starred
 %    version is also provided which activates them always after the
 %    language has been switched.
@@ -6504,10 +8460,11 @@
 %  \end{macro}
 %
 %  \begin{macro}{\languageshorthands}
+%
 %    A user level command to change the language from which shorthands
 %    are used. Unfortunately, \babel{} currently does not keep track
 %    of defined groups, and therefore there is no way to catch a
-%    possible change in casing.
+%    possible change in casing [TODO. Unclear].
 %
 %    \begin{macrocode}
 \def\languageshorthands#1{\def\language at group{#1}}
@@ -6516,8 +8473,12 @@
 %  \end{macro}
 %
 %  \begin{macro}{\aliasshorthand}
-%    First the new shorthand needs to be initialized,
+%    First the new shorthand needs to be initialized. Then, we define
+%    the new shorthand in terms of the original one, but note with
+%    |\aliasshorthands{"}{/}| is |\active at prefix /\active at char/|, so we
+%    still need to let the lattest to |\active at char"|.
 %
+%
 %    \begin{macrocode}
 \def\aliasshorthand#1#2{%
   \bbl at ifshorthand{#2}%
@@ -6526,14 +8487,6 @@
          \@notshorthand{#2}%
        \else
          \initiate at active@char{#2}%
-%    \end{macrocode}
-%
-%    Then, we define the new shorthand in terms of the original
-%    one, but note with |\aliasshorthands{"}{/}| is
-%    |\active at prefix /\active at char/|, so we still need to let the
-%    lattest to |\active at char"|.
-%
-%    \begin{macrocode}
          \expandafter\let\csname active at char\string#2\expandafter\endcsname
            \csname active at char\string#1\endcsname
          \expandafter\let\csname normal at char\string#2\expandafter\endcsname
@@ -6579,19 +8532,18 @@
 %  \begin{macro}{\bbl at switch@sh}
 %
 %    The macro |\bbl at switch@sh| takes the list of characters apart one
-%    by  one and subsequently switches the category code of the
+%    by one and subsequently switches the category code of the
 %    shorthand character according to the first argument of
 %    |\bbl at switch@sh|.
 %
-%    But before any of this switching takes place we make sure that
-%    the character we are dealing with is known as a shorthand
-%    character. If it is, a macro such as |\active at char"| should
-%    exist.
+%    But before any of this switching takes place we make sure that the
+%    character we are dealing with is known as a shorthand character.
+%    If it is, a macro such as |\active at char"| should exist.
 %
-%    Switching off and on is easy -- we just set the category
-%    code to `other' (12) and |\active|. With the starred version, the
-%    original catcode and the original definition, saved
-%    in |@initiate at active@char|, are restored.
+%    Switching off and on is easy -- we just set the category code to
+%    `other' (12) and |\active|. With the starred version, the original
+%    catcode and the original definition, saved in
+%    |@initiate at active@char|, are restored.
 %
 %    \begin{macrocode}
 \def\bbl at switch@sh#1#2{%
@@ -6617,7 +8569,7 @@
 %  \end{macro}
 %  \end{macro}
 %
-% Note the value is that at the expansion time, eg, in the preample
+% Note the value is that at the expansion time; eg, in the preample
 % shorhands are usually deactivated.
 %
 %    \begin{macrocode}
@@ -6780,11 +8732,6 @@
         {\csname\bbl at tempc @attr@##1\endcsname}%
         {\@attrerr{\bbl at tempc}{##1}}%
      \fi}}}
-%    \end{macrocode}
-%
-%    This command should only be used in the preamble of a document.
-%
-%    \begin{macrocode}
 \@onlypreamble\languageattribute
 %    \end{macrocode}
 %
@@ -6833,31 +8780,19 @@
 %    attribute being checked, and the third and fourth arguments are
 %    the true and false clauses.
 %
+%    First we need to find out if any attributes were set; if not we're
+%    done. Then we need to check the list of known attributes. When
+%    we're this far |\ifin@| has a value indicating if the attribute in
+%    question was set or not. Just to be safe the code to be executed
+%    is `thrown over the |\fi|'.
+%
 %    \begin{macrocode}
 \def\bbl at ifattributeset#1#2#3#4{%
-%    \end{macrocode}
-%
-%    First we need to find out if any attributes were set; if not
-%    we're done.
-%
-%    \begin{macrocode}
   \ifx\bbl at known@attribs\@undefined
     \in at false
   \else
-%    \end{macrocode}
-%
-%    The we need to check the list of known attributes.
-%
-%    \begin{macrocode}
     \bbl at xin@{,#1-#2,}{,\bbl at known@attribs,}%
   \fi
-%    \end{macrocode}
-%
-%    When we're this far |\ifin@| has a value indicating if the
-%    attribute in question was set or not. Just to be safe the code to
-%    be executed is `thrown over the |\fi|'.
-%
-%    \begin{macrocode}
   \ifin@
     \bbl at afterelse#3%
   \else
@@ -6874,36 +8809,20 @@
 %    attribute list, the \TeX-code to be executed when the attribute
 %    is known and the \TeX-code to be executed otherwise.
 %
+%    We first assume the attribute is unknown. Then we loop over the
+%    list of known attributes, trying to find a match. When a match is
+%    found the definition of |\bbl at tempa| is changed. Finally we
+%    execute |\bbl at tempa|.
+%
 %    \begin{macrocode}
 \def\bbl at ifknown@ttrib#1#2{%
-%    \end{macrocode}
-%
-%    We first assume the attribute is unknown.
-%
-%    \begin{macrocode}
   \let\bbl at tempa\@secondoftwo
-%    \end{macrocode}
-%
-%    Then we loop over the list of known attributes, trying to find a
-%    match.
-%
-%    \begin{macrocode}
   \bbl at loopx\bbl at tempb{#2}{%
     \expandafter\in@\expandafter{\expandafter,\bbl at tempb,}{,#1,}%
     \ifin@
-%    \end{macrocode}
-%
-%    When a match is found the definition of |\bbl at tempa| is changed.
-%
-%    \begin{macrocode}
       \let\bbl at tempa\@firstoftwo
     \else
     \fi}%
-%    \end{macrocode}
-%
-%    Finally we execute |\bbl at tempa|.
-%
-%    \begin{macrocode}
   \bbl at tempa
 }
 %    \end{macrocode}
@@ -6965,15 +8884,15 @@
 %  \begin{macro}{\babel at save}
 %  \begin{macro}{\babel at savevariable}
 %
-%    The macro |\babel at save|\meta{csname} saves the current meaning of
-%    the control sequence \meta{csname} to
-%    |\originalTeX|\footnote{\cs{originalTeX} has to be expandable,
-%    i.\,e.\ you shouldn't let it to \cs{relax}.}. To do this, we let
-%    the current meaning to a temporary control sequence, the restore
-%    commands are appended to |\originalTeX| and the counter is
-%    incremented. The macro |\babel at savevariable|\meta{variable} saves
-%    the value of the variable. \meta{variable} can be anything allowed
-%    after the |\the| primitive.
+% The macro |\babel at save|\meta{csname} saves the current meaning of the
+% control sequence \meta{csname} to
+% |\originalTeX|\footnote{\cs{originalTeX} has to be expandable,
+% i.\,e.\ you shouldn't let it to \cs{relax}.}. To do this, we let the
+% current meaning to a temporary control sequence, the restore commands
+% are appended to |\originalTeX| and the counter is incremented. The
+% macro |\babel at savevariable|\meta{variable} saves the value of the
+% variable. \meta{variable} can be anything allowed after the |\the|
+% primitive.
 %
 %    \begin{macrocode}
 \def\babel at save#1{%
@@ -6992,10 +8911,10 @@
 %
 %  \begin{macro}{\bbl at frenchspacing}
 %  \begin{macro}{\bbl at nonfrenchspacing}
-%    Some languages need to have |\frenchspacing| in effect. Others
-%    don't want that. The command |\bbl at frenchspacing| switches it on
-%    when it isn't already in effect and |\bbl at nonfrenchspacing|
-%    switches it off if necessary.
+% Some languages need to have |\frenchspacing| in effect. Others
+% don't want that. The command |\bbl at frenchspacing| switches it on
+% when it isn't already in effect and |\bbl at nonfrenchspacing|
+% switches it off if necessary.
 %
 %    \begin{macrocode}
 \def\bbl at frenchspacing{%
@@ -7043,11 +8962,11 @@
 %
 %  \begin{macro}{\babelhyphenation}
 %
-%     This macro saves hyphenation exceptions. Two macros are used to
-%     store them: |\bbl at hyphenation@| for the global ones and
-%     |\bbl at hyphenation<lang>| for language ones. See |\bbl at patterns|
-%     above for further details. We make sure there is a space between
-%     words when multiple commands are used.
+% This macro saves hyphenation exceptions. Two macros are used to
+% store them: |\bbl at hyphenation@| for the global ones and
+% |\bbl at hyphenation<lang>| for language ones. See |\bbl at patterns|
+% above for further details. We make sure there is a space between
+% words when multiple commands are used.
 %
 %    \begin{macrocode}
 \bbl at trace{Hyphens}
@@ -7082,10 +9001,10 @@
 %
 %  \begin{macro}{\bbl at allowhyphens}
 %
-%    This macro makes hyphenation possible. Basically its definition
-%    is nothing more than |\nobreak| |\hskip| \texttt{0pt plus
-%    0pt}\footnote{\TeX\ begins and ends a word for hyphenation at a
-%    glue node. The penalty prevents a linebreak at this glue node.}.
+% This macro makes hyphenation possible. Basically its definition
+% is nothing more than |\nobreak| |\hskip| \texttt{0pt plus
+% 0pt}\footnote{\TeX\ begins and ends a word for hyphenation at a
+% glue node. The penalty prevents a linebreak at this glue node.}.
 %
 %    \begin{macrocode}
 \def\bbl at allowhyphens{\ifvmode\else\nobreak\hskip\z at skip\fi}
@@ -7097,10 +9016,10 @@
 %
 % \begin{macro}{\babelhyphen}
 %
-%    Macros to insert common hyphens. Note the space before |@| in
-%    |\babelhyphen|. Instead of protecting it with
-%    |\DeclareRobustCommand|, which could insert a |\relax|, we use
-%    the same procedure as shorthands, with |\active at prefix|.
+% Macros to insert common hyphens. Note the space before |@| in
+% |\babelhyphen|. Instead of protecting it with
+% |\DeclareRobustCommand|, which could insert a |\relax|, we use
+% the same procedure as shorthands, with |\active at prefix|.
 %
 %    \begin{macrocode}
 \newcommand\babelnullhyphen{\char\hyphenchar\font}
@@ -7113,18 +9032,18 @@
     {\csname bbl at hy@#1#2\@empty\endcsname}}
 %    \end{macrocode}
 %
-%    The following two commands are used to wrap the ``hyphen'' and
-%    set the behavior of the rest of the word -- the version with a
-%    single |@| is used when further hyphenation is allowed, while
-%    that with |@@| if no more hyphens are allowed. In both cases, if
-%    the hyphen is preceded by a positive space, breaking after the
-%    hyphen is disallowed.
+% The following two commands are used to wrap the ``hyphen'' and
+% set the behavior of the rest of the word -- the version with a
+% single |@| is used when further hyphenation is allowed, while
+% that with |@@| if no more hyphens are allowed. In both cases, if
+% the hyphen is preceded by a positive space, breaking after the
+% hyphen is disallowed.
 %
-%    There should not be a discretionary after a hyphen at the
-%    beginning of a word, so it is prevented if preceded by a
-%    skip. Unfortunately, this does handle cases like ``(-suffix)''.
-%    |\nobreak| is always preceded by |\leavevmode|, in case the
-%    shorthand starts a paragraph.
+% There should not be a discretionary after a hyphen at the
+% beginning of a word, so it is prevented if preceded by a
+% skip. Unfortunately, this does handle cases like ``(-suffix)''.
+% |\nobreak| is always preceded by |\leavevmode|, in case the
+% shorthand starts a paragraph.
 %
 %    \begin{macrocode}
 \def\bbl at usehyphen#1{%
@@ -7184,7 +9103,7 @@
 %
 % The aim following commands is to provide a commom interface for
 % strings in several encodings. They also contains several hooks which
-% can be ued by \luatex{} and \xetex. The code is organized here with
+% can be used by \luatex{} and \xetex. The code is organized here with
 % pseudo-guards, so we start with the basic commands.
 %
 %  \paragraph{Tools}
@@ -7195,7 +9114,7 @@
 %    \begin{macrocode}
 \bbl at trace{Multiencoding strings}
 \def\bbl at toglobal#1{\global\let#1#1}
-\def\bbl at recatcode#1{%
+\def\bbl at recatcode#1{% TODO. Used only once?
   \@tempcnta="7F
   \def\bbl at tempa{%
     \ifnum\@tempcnta>"FF\else
@@ -7255,10 +9174,10 @@
 %<</More package options>>
 %    \end{macrocode}
 %
-%    \paragraph{Main command} This is the main command.  With the
-%    first use it is redefined to omit the basic setup in subsequent
-%    blocks. We make sure strings contain actual letters in the range
-%    128-255, not active characters.
+% \paragraph{Main command} This is the main command. With the first
+% use it is redefined to omit the basic setup in subsequent blocks.
+% We make sure strings contain actual letters in the range 128-255,
+% not active characters.
 %
 %    \begin{macrocode}
 \@onlypreamble\StartBabelCommands
@@ -7296,22 +9215,22 @@
 \let\bbl at startcommands\StartBabelCommands
 %    \end{macrocode}
 %
-%    Parse the encoding info to get the label, input, and font parts.
+% Parse the encoding info to get the label, input, and font parts.
 %
-%    Select the behavior of |\SetString|. Thre are two main cases,
-%    depending of if there is an optional argument: without it and
-%    |strings=encoded|, strings are defined
-%    always; otherwise, they are set only if they are still undefined
-%    (ie, fallback values). With labelled blocks and
-%    |strings=encoded|, define the strings, but with another value,
-%    define strings only if the current label or font encoding is the
-%    value of |strings|; otherwise (ie, no |strings| or a block whose
-%    label is not in |strings=|) do nothing.
+% Select the behavior of |\SetString|. Thre are two main cases,
+% depending of if there is an optional argument: without it and
+% |strings=encoded|, strings are defined
+% always; otherwise, they are set only if they are still undefined
+% (ie, fallback values). With labelled blocks and
+% |strings=encoded|, define the strings, but with another value,
+% define strings only if the current label or font encoding is the
+% value of |strings|; otherwise (ie, no |strings| or a block whose
+% label is not in |strings=|) do nothing.
 %
-%    We presume the current block is not loaded, and therefore set
-%    (above) a couple of default values to gobble the arguments. Then,
-%    these macros are redefined if necessary according to several
-%    parameters.
+% We presume the current block is not loaded, and therefore set
+% (above) a couple of default values to gobble the arguments. Then,
+% these macros are redefined if necessary according to several
+% parameters.
 %
 %    \begin{macrocode}
 \newcommand\bbl at startcmds@ii[1][\@empty]{%
@@ -7375,19 +9294,20 @@
   \fi}
 %    \end{macrocode}
 %
-%    There are two versions of |\bbl at scswitch|. The first version is
-%    used when |ldf|s are read, and it makes sure
-%    |\|\m{group}\m{language} is reset, but only once (|\bbl at screset|
-%    is used to keep track of this). The second version is used in the
-%    preamble and packages loaded after \babel{} and does nothing. The
-%    macro |\bbl at forlang| loops |\bbl at L| but its body is executed only
-%    if the value is in |\BabelLanguages| (inside \babel) or
-%    |\date|\m{language} is defined (after \babel{} has been loaded).
-%    There are also two version of |\bbl at forlang|. The first one skips
-%    the current iteration if the language is not in |\BabelLanguages|
-%    (used in |ldf|s), and the second one skips undefined languages
-%    (after \babel{} has been loaded) .
+% There are two versions of |\bbl at scswitch|. The first version is used
+% when |ldf|s are read, and it makes sure |\|\m{group}\m{language} is
+% reset, but only once (|\bbl at screset| is used to keep track of this).
+% The second version is used in the preamble and packages loaded after
+% \babel{} and does nothing.
 %
+% The macro |\bbl at forlang| loops |\bbl at L| but its body is executed only
+% if the value is in |\BabelLanguages| (inside \babel) or
+% |\date|\m{language} is defined (after \babel{} has been loaded).
+% There are also two version of |\bbl at forlang|. The first one skips the
+% current iteration if the language is not in |\BabelLanguages| (used
+% in |ldf|s), and the second one skips undefined languages (after
+% \babel{} has been loaded) .
+%
 %   \begin{macrocode}
 \def\bbl at forlang#1#2{%
   \bbl at for#1\bbl at L{%
@@ -7417,17 +9337,17 @@
 \let\bbl at endcommands\EndBabelCommands
 %    \end{macrocode}
 %
-%    Now we define commands to be used inside |\StartBabelCommands|.
+% Now we define commands to be used inside |\StartBabelCommands|.
 %
-%    \paragraph{Strings} The following macro is the actual definition
-%    of |\SetString| when it is ``active''
+% \paragraph{Strings} The following macro is the actual definition
+% of |\SetString| when it is ``active''
 %
-%    First save the ``switcher''. Create it if undefined. Strings are
-%    defined only if undefined (ie, like |\providescommmand|). With
-%    the event |stringprocess| you can preprocess the string by
-%    manipulating the value of |\BabelString|. If there are several
-%    hooks assigned to this event, preprocessing is done in the same
-%    order as defined.  Finally, the string is set.
+% First save the ``switcher''. Create it if undefined. Strings are
+% defined only if undefined (ie, like |\providescommmand|). With
+% the event |stringprocess| you can preprocess the string by
+% manipulating the value of |\BabelString|. If there are several
+% hooks assigned to this event, preprocessing is done in the same
+% order as defined.  Finally, the string is set.
 %
 %    \begin{macrocode}
 \def\bbl at setstring#1#2{%
@@ -7471,12 +9391,11 @@
 \fi
 %    \end{macrocode}
 %
-%    Define |\SetStringLoop|, which is actually set inside
-%    |\StartBabelCommands|. The current definition is
-%    somewhat complicated because we need a count, but |\count@| is
-%    not under our control (remember |\SetString| may call hooks).
-%    Instead of defining a dedicated count, we just ``pre-expand''
-%    its value.
+% Define |\SetStringLoop|, which is actually set inside
+% |\StartBabelCommands|. The current definition is somewhat complicated
+% because we need a count, but |\count@| is not under our control
+% (remember |\SetString| may call hooks). Instead of defining a
+% dedicated count, we just ``pre-expand'' its value.
 %
 %    \begin{macrocode}
 %<<*Macros local to BabelCommands>>
@@ -7492,8 +9411,8 @@
 %<</Macros local to BabelCommands>>
 %    \end{macrocode}
 %
-%    \paragraph{Delaying code} Now the definition of
-%    |\AfterBabelCommands| when it is activated.
+% \paragraph{Delaying code} Now the definition of |\AfterBabelCommands|
+% when it is activated.
 %
 %    \begin{macrocode}
 \def\bbl at aftercmds#1{%
@@ -7565,8 +9484,8 @@
   \bbl at tempa}
 %    \end{macrocode}
 %
-%    The following package options control the behavior of
-%    hyphenation mapping.
+% The following package options control the behavior of
+% hyphenation mapping.
 %
 %    \begin{macrocode}
 %<<*More package options>>
@@ -7592,9 +9511,10 @@
 % \subsection{Macros common to a number of languages}
 %
 %  \begin{macro}{\set at low@box}
-%    The following macro is used to lower quotes to the same level as
-%    the comma.  It prepares its argument in box register~0.
 %
+% The following macro is used to lower quotes to the same level as
+% the comma.  It prepares its argument in box register~0.
+%
 %    \begin{macrocode}
 \bbl at trace{Macros related to glyphs}
 \def\set at low@box#1{\setbox\tw@\hbox{,}\setbox\z@\hbox{#1}%
@@ -7619,18 +9539,18 @@
 %
 % \subsection{Making glyphs available}
 %
-%    This section makes a number of glyphs available that either do not
-%    exist in the \texttt{OT1} encoding and have to be `faked', or
-%    that are not accessible through \file{T1enc.def}.
+% This section makes a number of glyphs available that either do not
+% exist in the \texttt{OT1} encoding and have to be `faked', or
+% that are not accessible through \file{T1enc.def}.
 %
 % \subsubsection{Quotation marks}
 %
 %  \begin{macro}{\quotedblbase}
-%    In the \texttt{T1} encoding the opening double quote at the
-%    baseline is available as a separate character, accessible via
-%    |\quotedblbase|. In the \texttt{OT1} encoding it is not
-%    available, therefore we make it available by lowering the normal
-%    open quote character to the baseline.
+% In the \texttt{T1} encoding the opening double quote at the
+% baseline is available as a separate character, accessible via
+% |\quotedblbase|. In the \texttt{OT1} encoding it is not
+% available, therefore we make it available by lowering the normal
+% open quote character to the baseline.
 %
 %    \begin{macrocode}
 \ProvideTextCommand{\quotedblbase}{OT1}{%
@@ -7638,8 +9558,8 @@
     \box\z@\kern-.04em\bbl at allowhyphens}}
 %    \end{macrocode}
 %
-%    Make sure that when an encoding other than \texttt{OT1} or
-%    \texttt{T1} is used this glyph can still be typeset.
+% Make sure that when an encoding other than \texttt{OT1} or
+% \texttt{T1} is used this glyph can still be typeset.
 %
 %    \begin{macrocode}
 \ProvideTextCommandDefault{\quotedblbase}{%
@@ -7667,12 +9587,27 @@
 %
 %  \end{macro}
 %
-%  \begin{macro}{\guillemotleft}
-%  \begin{macro}{\guillemotright}
-%    The guillemet characters are not available in \texttt{OT1}
-%    encoding. They are faked.
+%  \begin{macro}{\guillemetleft}
+%  \begin{macro}{\guillemetright}
+% The guillemet characters are not available in \texttt{OT1}
+% encoding. They are faked. (Wrong names with o preserved for
+% compatibility.)
 %
 %    \begin{macrocode}
+\ProvideTextCommand{\guillemetleft}{OT1}{%
+  \ifmmode
+    \ll
+  \else
+    \save at sf@q{\nobreak
+      \raise.2ex\hbox{$\scriptscriptstyle\ll$}\bbl at allowhyphens}%
+  \fi}
+\ProvideTextCommand{\guillemetright}{OT1}{%
+  \ifmmode
+    \gg
+  \else
+    \save at sf@q{\nobreak
+      \raise.2ex\hbox{$\scriptscriptstyle\gg$}\bbl at allowhyphens}%
+  \fi}
 \ProvideTextCommand{\guillemotleft}{OT1}{%
   \ifmmode
     \ll
@@ -7689,10 +9624,14 @@
   \fi}
 %    \end{macrocode}
 %
-%    Make sure that when an encoding other than \texttt{OT1} or
-%    \texttt{T1} is used these glyphs can still be typeset.
+% Make sure that when an encoding other than \texttt{OT1} or
+% \texttt{T1} is used these glyphs can still be typeset.
 %
 %    \begin{macrocode}
+\ProvideTextCommandDefault{\guillemetleft}{%
+  \UseTextSymbol{OT1}{\guillemetleft}}
+\ProvideTextCommandDefault{\guillemetright}{%
+  \UseTextSymbol{OT1}{\guillemetright}}
 \ProvideTextCommandDefault{\guillemotleft}{%
   \UseTextSymbol{OT1}{\guillemotleft}}
 \ProvideTextCommandDefault{\guillemotright}{%
@@ -7724,8 +9663,8 @@
   \fi}
 %    \end{macrocode}
 %
-%    Make sure that when an encoding other than \texttt{OT1} or
-%    \texttt{T1} is used these glyphs can still be typeset.
+% Make sure that when an encoding other than \texttt{OT1} or
+% \texttt{T1} is used these glyphs can still be typeset.
 %
 %    \begin{macrocode}
 \ProvideTextCommandDefault{\guilsinglleft}{%
@@ -7741,9 +9680,9 @@
 %
 %  \begin{macro}{\ij}
 %  \begin{macro}{\IJ}
-%    The dutch language uses the letter `ij'. It is available in
-%    \texttt{T1} encoded fonts, but not in the \texttt{OT1} encoded
-%    fonts. Therefore we fake it for the \texttt{OT1} encoding.
+% The dutch language uses the letter `ij'. It is available in
+% \texttt{T1} encoded fonts, but not in the \texttt{OT1} encoded
+% fonts. Therefore we fake it for the \texttt{OT1} encoding.
 %
 %    \begin{macrocode}
 \DeclareTextCommand{\ij}{OT1}{%
@@ -7767,15 +9706,15 @@
 %  \end{macro}
 %  \end{macro}
 %
-%  \begin{macro}{\dj}
-%  \begin{macro}{\DJ}
-%    The croatian language needs the letters |\dj| and |\DJ|; they are
-%    available in the \texttt{T1} encoding, but not in the
-%    \texttt{OT1} encoding by default.
+% \begin{macro}{\dj}
+% \begin{macro}{\DJ}
+% The croatian language needs the letters |\dj| and |\DJ|; they are
+% available in the \texttt{T1} encoding, but not in the
+% \texttt{OT1} encoding by default.
 %
-%    Some code to construct these glyphs for the \texttt{OT1} encoding
-%    was made available to me by Stipčević Mario,
-%    (\texttt{stipcevic at olimp.irb.hr}).
+% Some code to construct these glyphs for the \texttt{OT1} encoding
+% was made available to me by Stipčević Mario,
+% (\texttt{stipcevic at olimp.irb.hr}).
 %
 %    \begin{macrocode}
 \def\crrtic@{\hrule height0.1ex width0.3em}
@@ -7910,9 +9849,9 @@
 %
 %    \begin{macrocode}
 \ProvideTextCommandDefault{\flqq}{%
-  \textormath{\guillemotleft}{\mbox{\guillemotleft}}}
+  \textormath{\guillemetleft}{\mbox{\guillemetleft}}}
 \ProvideTextCommandDefault{\frqq}{%
-  \textormath{\guillemotright}{\mbox{\guillemotright}}}
+  \textormath{\guillemetright}{\mbox{\guillemetright}}}
 %    \end{macrocode}
 %
 %  \end{macro}
@@ -8021,13 +9960,13 @@
 }
 %    \end{macrocode}
 %
-%    Finally, the default is to use English as the main language.
+% Finally, make sure the default hyphenrules are defined (even if
+% empty). 
 %
 %    \begin{macrocode}
 \ifx\l at english\@undefined
   \chardef\l at english\z@
 \fi
-\main at language{english}
 %    \end{macrocode}
 %
 % \subsection{Layout}
@@ -8088,7 +10027,7 @@
 \fi
 %    \end{macrocode}
 %
-% \subsection{Creating languages}
+% \subsection{Creating and modifying languages}
 %
 % |\babelprovide| is a general purpose tool for creating and modifying
 % languages. It creates the language infrastructure, and loads, if
@@ -8129,10 +10068,14 @@
   % == import, captions ==
   \ifx\bbl at KVP@import\@nil\else
     \bbl at exp{\\\bbl at ifblank{\bbl at KVP@import}}%
-      {\begingroup
-         \def\BabelBeforeIni##1##2{\gdef\bbl at KVP@import{##1}\endinput}%
-         \InputIfFileExists{babel-#2.tex}{}{}%
-       \endgroup}%
+      {\ifx\bbl at initoload\relax
+         \begingroup
+           \def\BabelBeforeIni##1##2{\gdef\bbl at KVP@import{##1}\endinput}%
+           \InputIfFileExists{babel-#2.tex}{}{}%
+         \endgroup
+       \else
+         \xdef\bbl at KVP@import{\bbl at initoload}%
+       \fi}%
       {}%
   \fi
   \ifx\bbl at KVP@captions\@nil
@@ -8156,11 +10099,14 @@
         \\\foreignlanguage{\languagename}%
         {####1}}}}%
     {}%
+  \bbl at exp{%
+     \\\bbl at toglobal\<bbl at ensure@\languagename>%
+     \\\bbl at toglobal\<bbl at ensure@\languagename\space>}%
   % At this point all parameters are defined if 'import'. Now we
   % execute some code depending on them. But what about if nothing was
   % imported? We just load the very basic parameters: ids and a few
   % more. 
-  \bbl at ifunset{bbl at lname@#2}%
+  \bbl at ifunset{bbl at lname@#2}%  TODO. Duplicated
     {\def\BabelBeforeIni##1##2{%
        \begingroup
          \catcode`\[=12 \catcode`\]=12 \catcode`\==12  \catcode`\;=12 %
@@ -8171,14 +10117,21 @@
          \bbl at exportkey{dgnat}{numbers.digits.native}{}%
          \bbl at exportkey{prehc}{typography.prehyphenchar}{}%
          \bbl at exportkey{lnbrk}{typography.linebreaking}{h}%
+         \bbl at exportkey{lfthm}{typography.lefthyphenmin}{2}%
+         \bbl at exportkey{rgthm}{typography.righthyphenmin}{3}%
          \bbl at exportkey{hyphr}{typography.hyphenrules}{}%
          \bbl at exportkey{hyoth}{typography.hyphenate.other}{}%
          \bbl at exportkey{intsp}{typography.intraspace}{}%
-         \endinput
-       \endgroup}%           boxed, to avoid extra spaces:
-     {\setbox\z@\hbox{\InputIfFileExists{babel-#2.tex}{}{}}}}%
+         \ifx\bbl at initoload\relax\endinput\fi
+       \endgroup}%
+     \begingroup       % boxed, to avoid extra spaces:
+       \ifx\bbl at initoload\relax
+         \setbox\z@\hbox{\InputIfFileExists{babel-#2.tex}{}{}}%
+       \else
+         \setbox\z@\hbox{\BabelBeforeIni{\bbl at initoload}{}}%
+       \fi
+     \endgroup}%
     {}%
-  % -
   % == script, language ==
   % Override the values from ini or defines them
   \ifx\bbl at KVP@script\@nil\else
@@ -8441,7 +10394,11 @@
         \fi}%
       \expandafter\bbl at tempb\bbl at captionslist\@empty
     \else
-      \bbl at read@ini{\bbl at KVP@captions}{data}%  Here all letters cat = 11
+      \ifx\bbl at initoload\relax
+        \bbl at read@ini{\bbl at KVP@captions}{data}%  Here letters cat = 11
+      \else
+        \bbl at read@ini{\bbl at initoload}{data}%  Here all letters cat = 11
+      \fi
       \bbl at after@ini
       \bbl at savestrings
     \fi
@@ -8454,8 +10411,34 @@
       \bbl at savedate
     \fi
   \bbl at endcommands
+  \bbl at ifunset{bbl at lname@#1}%     TODO. Duplicated
+    {\def\BabelBeforeIni##1##2{%
+       \begingroup
+         \catcode`\[=12 \catcode`\]=12 \catcode`\==12  \catcode`\;=12 %
+         \let\bbl at ini@captions at aux\@gobbletwo
+         \def\bbl at inidate ####1.####2.####3.####4\relax ####5####6{}%
+         \bbl at read@ini{##1}{basic data}%
+         \bbl at exportkey{prehc}{typography.prehyphenchar}{}%
+         \bbl at exportkey{lnbrk}{typography.linebreaking}{h}%
+         \bbl at exportkey{lfthm}{typography.lefthyphenmin}{2}%
+         \bbl at exportkey{rgthm}{typography.righthyphenmin}{3}%
+         \bbl at exportkey{hyphr}{typography.hyphenrules}{}%
+         \bbl at exportkey{hyoth}{typography.hyphenate.other}{}%
+         \bbl at exportkey{intsp}{typography.intraspace}{}%
+         \bbl at exportkey{chrng}{characters.ranges}{}%
+         \bbl at exportkey{dgnat}{numbers.digits.native}{}%
+         \ifx\bbl at initoload\relax\endinput\fi
+       \endgroup}%
+     \begingroup       % boxed, to avoid extra spaces:
+       \ifx\bbl at initoload\relax
+         \setbox\z@\hbox{\InputIfFileExists{babel-#1.tex}{}{}}%
+       \else
+         \setbox\z@\hbox{\BabelBeforeIni{\bbl at initoload}{}}%
+       \fi
+     \endgroup}%
+    {}%
   \bbl at exp{%
-    \def\<#1hyphenmins>{%
+    \gdef\<#1hyphenmins>{%
       {\bbl at ifunset{bbl at lfthm@#1}{2}{\bbl at cs{lfthm@#1}}}%
       {\bbl at ifunset{bbl at rgthm@#1}{3}{\bbl at cs{rgthm@#1}}}}}%
   \bbl at provide@hyphens{#1}%
@@ -8498,7 +10481,14 @@
       \fi}%
   \fi
   \ifx\bbl at tempa\relax %        if no opt or no language in opt found
-    \ifx\bbl at KVP@import\@nil\else % if importing
+    \ifx\bbl at KVP@import\@nil
+      \ifx\bbl at initoload\relax\else
+        \bbl at exp{%                    and hyphenrules is not empty
+          \\\bbl at ifblank{\bbl at cs{hyphr@#1}}%
+            {}%
+            {\let\\\bbl at tempa\<l@\bbl at cl{hyphr}>}}%
+      \fi 
+    \else % if importing
       \bbl at exp{%                    and hyphenrules is not empty
         \\\bbl at ifblank{\bbl at cs{hyphr@#1}}%
           {}%
@@ -8677,13 +10667,13 @@
   \in@{.1$}{#1$}%
   \ifin@
     \bbl at replace\bbl at tempc{.1}{}%
-    \bbl at csarg\xdef{cntr@\bbl at tempc @\languagename}{%
+    \bbl at csarg\protected at xdef{cntr@\bbl at tempc @\languagename}{%
       \noexpand\bbl at alphnumeral{\bbl at tempc}}%
   \fi
   \in@{.F.}{#1}%
   \ifin@\else\in@{.S.}{#1}\fi
   \ifin@
-    \bbl at csarg\xdef{cntr@#1@\languagename}{\bbl at tempb*}%
+    \bbl at csarg\protected at xdef{cntr@#1@\languagename}{\bbl at tempb*}%
   \else
     \toks@{}% Required by \bbl at buildifcase, which returns \bbl at tempa
     \expandafter\bbl at buildifcase\bbl at tempb* \\ % Space after \\
@@ -8954,10 +10944,10 @@
     \fi}}
 %    \end{macrocode}
 %
-%  More general, but non-expandable, is |\getlocaleproperty|. To inspect
-%  every possible loaded |ini|, we define |\LocaleForEach|, where
-%  |\bbl at ini@loaded| is a comma-separated list of locales, built by
-%  |\bbl at read@ini|. 
+% More general, but non-expandable, is |\getlocaleproperty|. To inspect
+% every possible loaded |ini|, we define |\LocaleForEach|, where
+% |\bbl at ini@loaded| is a comma-separated list of locales, built by
+% |\bbl at read@ini|. 
 %
 %    \begin{macrocode}   
 \newcommand\getlocaleproperty[3]{% 
@@ -8985,7 +10975,10 @@
 %
 %    \begin{macrocode}
 \newcommand\babeladjust[1]{%  TODO. Error handling.
-  \bbl at forkv{#1}{\bbl at cs{ADJ@##1@##2}}}
+  \bbl at forkv{#1}{%
+    \bbl at ifunset{bbl at ADJ@##1@##2}% 
+      {\bbl at cs{ADJ@##1}{##2}}%
+      {\bbl at cs{ADJ@##1@##2}}}}
 %
 \def\bbl at adjust@lua#1#2{%
   \ifvmode
@@ -9039,1940 +11032,38 @@
   \bbl at adjust@layout{\let\list\bbl at OL@list}}
 \@namedef{bbl at ADJ@hyphenation.extra at on}{%
   \bbl at activateposthyphen}
-%    \end{macrocode}
 %
-% \section{The kernel of Babel (\texttt{babel.def} for \LaTeX only)}
+\@namedef{bbl at ADJ@autoload.bcp47 at on}{%
+  \bbl at bcpallowedtrue}
+\@namedef{bbl at ADJ@autoload.bcp47 at off}{%
+  \bbl at bcpallowedfalse}
+\@namedef{bbl at ADJ@autoload.bcp47.prefix}#1{%
+  \def\bbl at bcp@prefix{#1}}
+\def\bbl at bcp@prefix{bcp47-}
+\@namedef{bbl at ADJ@autoload.options}#1{%
+  \def\bbl at autoload@options{#1}}
+\let\bbl at autoload@bcpoptions\@empty
+\@namedef{bbl at ADJ@autoload.bcp47.options}#1{%
+  \def\bbl at autoload@bcpoptions{#1}}
+% TODO: use babel name, override 
 %
-% \subsection{The redefinition of the style commands}
+% As the final task, load the code for lua.
 %
-%    The rest of the code in this file can only be processed by
-%    \LaTeX, so we check the current format. If it is plain \TeX,
-%    processing should stop here. But, because of the need to limit
-%    the scope of the definition of |\format|, a macro that is used
-%    locally in the following |\if|~statement, this comparison is done
-%    inside a group. To prevent \TeX\ from complaining about an
-%    unclosed group, the processing of the command |\endinput| is
-%    deferred until after the group is closed. This is accomplished by
-%    the command |\aftergroup|.
-%
-%    \begin{macrocode}
-{\def\format{lplain}
-\ifx\fmtname\format
-\else
-  \def\format{LaTeX2e}
-  \ifx\fmtname\format
-  \else
-    \aftergroup\endinput
+\ifx\directlua\@undefined\else
+  \ifx\bbl at luapatterns\@undefined
+    \input luababel.def
   \fi
-\fi}
-%    \end{macrocode}
-%
-% \subsection{Cross referencing macros}
-%
-%    The \LaTeX\ book states:
-%  \begin{quote}
-%    The \emph{key} argument is any sequence of letters, digits, and
-%    punctuation symbols; upper- and lowercase letters are regarded as
-%    different.
-%  \end{quote}
-%    When the above quote should still be true when a document is
-%    typeset in a language that has active characters, special care
-%    has to be taken of the category codes of these characters when
-%    they appear in an argument of the cross referencing macros.
-%
-%    When a cross referencing command processes its argument, all
-%    tokens in this argument should be character tokens with category
-%    `letter' or `other'.
-%
-%    The only way to accomplish this in most cases is to use the trick
-%    described in the \TeX book~\cite{DEK} (Appendix~D, page~382).
-%    The primitive |\meaning| applied to a token expands to the
-%    current meaning of this token.  For example, `|\meaning\A|' with
-%    |\A| defined as `|\def\A#1{\B}|' expands to the characters
-%    `|macro:#1->\B|' with all category codes set to `other' or
-%    `space'.
-%  \begin{macro}{\newlabel}
-%    The macro |\label| writes a line with a |\newlabel| command
-%    into the |.aux| file to define labels.
-%
-%    \begin{macrocode}
-%\bbl at redefine\newlabel#1#2{%
-%  \@safe at activestrue\org at newlabel{#1}{#2}\@safe at activesfalse}
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-%  \begin{macro}{\@newl at bel}
-%    We need to change the definition of the \LaTeX-internal macro
-%    |\@newl at bel|. This is needed because we need to make sure that
-%    shorthand characters expand to their non-active version.
-%
-%    The following package options control which macros are to be
-%    redefined.
-%
-%    \begin{macrocode}
-%<<*More package options>>
-\DeclareOption{safe=none}{\let\bbl at opt@safe\@empty}
-\DeclareOption{safe=bib}{\def\bbl at opt@safe{B}}
-\DeclareOption{safe=ref}{\def\bbl at opt@safe{R}}
-%<</More package options>>
-%    \end{macrocode}
-%
-%    First we open a new group to keep the changed setting of
-%    |\protect| local and then we set the |@safe at actives| switch to
-%    true to make sure that any shorthand that appears in any of the
-%    arguments immediately expands to its non-active self.
-%
-%    \begin{macrocode}
-\bbl at trace{Cross referencing macros}
-\ifx\bbl at opt@safe\@empty\else
-  \def\@newl at bel#1#2#3{%
-   {\@safe at activestrue
-    \bbl at ifunset{#1@#2}%
-       \relax
-       {\gdef\@multiplelabels{%
-          \@latex at warning@no at line{There were multiply-defined labels}}%
-        \@latex at warning@no at line{Label `#2' multiply defined}}%
-    \global\@namedef{#1@#2}{#3}}}
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-%  \begin{macro}{\@testdef}
-%    An internal \LaTeX\ macro used to test if the labels that have
-%    been written on the |.aux| file have changed.  It is called by
-%    the |\enddocument| macro. This macro needs to be completely
-%    rewritten, using |\meaning|. The reason for this is that in some
-%    cases the expansion of |\#1@#2| contains the same characters as
-%    the |#3|; but the character codes differ. Therefore \LaTeX\ keeps
-%    reporting that the labels may have changed.
-%
-%    \begin{macrocode}
-  \CheckCommand*\@testdef[3]{%
-    \def\reserved at a{#3}%
-    \expandafter\ifx\csname#1@#2\endcsname\reserved at a
-    \else
-      \@tempswatrue
-    \fi}
-%    \end{macrocode}
-%
-%    Now that we made sure that |\@testdef| still has the same
-%    definition we can rewrite it. First we make the shorthands
-%    `safe'.
-%
-%    \begin{macrocode}
-  \def\@testdef#1#2#3{%
-    \@safe at activestrue
-%    \end{macrocode}
-%
-%    Then we use |\bbl at tempa| as an `alias' for the macro that
-%    contains the label which is being checked.
-%
-%    \begin{macrocode}
-    \expandafter\let\expandafter\bbl at tempa\csname #1@#2\endcsname
-%    \end{macrocode}
-%
-%    Then we define |\bbl at tempb| just as |\@newl at bel| does it.
-%
-%    \begin{macrocode}
-    \def\bbl at tempb{#3}%
-    \@safe at activesfalse
-%    \end{macrocode}
-%
-%    When the label is defined we replace the definition of
-%    |\bbl at tempa| by its meaning.
-%
-%    \begin{macrocode}
-    \ifx\bbl at tempa\relax
-    \else
-      \edef\bbl at tempa{\expandafter\strip at prefix\meaning\bbl at tempa}%
-    \fi
-%    \end{macrocode}
-%
-%    We do the same for |\bbl at tempb|.
-%
-%    \begin{macrocode}
-    \edef\bbl at tempb{\expandafter\strip at prefix\meaning\bbl at tempb}%
-%    \end{macrocode}
-%
-%    If the label didn't change, |\bbl at tempa| and |\bbl at tempb| should
-%    be identical macros.
-%
-%    \begin{macrocode}
-    \ifx\bbl at tempa\bbl at tempb
-    \else
-      \@tempswatrue
-    \fi}
 \fi
+%</core>
 %    \end{macrocode}
 %
-%  \end{macro}
+% A proxy file for switch.def
 %
-%  \begin{macro}{\ref}
-%  \begin{macro}{\pageref}
-%    The same holds for the macro |\ref| that references a label
-%    and |\pageref| to reference a page. So we redefine |\ref| and
-%    |\pageref|. While we change these macros, we make them robust as
-%    well (if they weren't already) to prevent problems if they should
-%    become expanded at the wrong moment.
-%
 %    \begin{macrocode}
-\bbl at xin@{R}\bbl at opt@safe
-\ifin@
-  \bbl at redefinerobust\ref#1{%
-    \@safe at activestrue\org at ref{#1}\@safe at activesfalse}
-  \bbl at redefinerobust\pageref#1{%
-    \@safe at activestrue\org at pageref{#1}\@safe at activesfalse}
-\else
-  \let\org at ref\ref
-  \let\org at pageref\pageref
-\fi
-%    \end{macrocode}
-%
-%  \end{macro}
-%  \end{macro}
-%
-%  \begin{macro}{\@citex}
-%    The macro used to cite from a bibliography, |\cite|, uses an
-%    internal macro, |\@citex|.
-%    It is this internal macro that picks up the argument(s),
-%    so we redefine this internal macro and leave |\cite| alone. The
-%    first argument is used for typesetting, so the shorthands need
-%    only be deactivated in the second argument.
-%
-%    \begin{macrocode}
-\bbl at xin@{B}\bbl at opt@safe
-\ifin@
-  \bbl at redefine\@citex[#1]#2{%
-    \@safe at activestrue\edef\@tempa{#2}\@safe at activesfalse
-    \org@@citex[#1]{\@tempa}}
-%    \end{macrocode}
-%
-%    Unfortunately, the packages \pkg{natbib} and \pkg{cite} need a
-%    different definition of |\@citex|...
-%    To begin with, \pkg{natbib} has a definition for |\@citex| with
-%    \emph{three} arguments... We only know that a package is loaded
-%    when |\begin{document}| is executed, so we need to postpone the
-%    different redefinition.
-%
-%    \begin{macrocode}
-  \AtBeginDocument{%
-    \@ifpackageloaded{natbib}{%
-%    \end{macrocode}
-%
-%    Notice that we use |\def| here instead of |\bbl at redefine| because
-%    |\org@@citex| is already defined and we don't want to overwrite
-%    that definition (it would result in parameter stack overflow
-%    because of a circular definition).
-%
-%   (Recent versions of \pkg{natbib} change dynamically |\@citex|, so PR4087
-%    doesn't seem fixable in a simple way. Just load \pkg{natbib} before.)
-%
-%    \begin{macrocode}
-    \def\@citex[#1][#2]#3{%
-      \@safe at activestrue\edef\@tempa{#3}\@safe at activesfalse
-      \org@@citex[#1][#2]{\@tempa}}%
-    }{}}
-%    \end{macrocode}
-%
-%    The package \pkg{cite} has a definition of |\@citex| where the
-%    shorthands need to be turned off in both arguments.
-%
-%    \begin{macrocode}
-  \AtBeginDocument{%
-    \@ifpackageloaded{cite}{%
-      \def\@citex[#1]#2{%
-        \@safe at activestrue\org@@citex[#1]{#2}\@safe at activesfalse}%
-      }{}}
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-%  \begin{macro}{\nocite}
-%    The macro |\nocite| which is used to instruct BiB\TeX\ to
-%    extract uncited references from the database.
-%
-%    \begin{macrocode}
-  \bbl at redefine\nocite#1{%
-    \@safe at activestrue\org at nocite{#1}\@safe at activesfalse}
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-%  \begin{macro}{\bibcite}
-%  The macro that is used in the |.aux| file to
-%  define citation labels. When packages such as \pkg{natbib} or
-%  \pkg{cite} are not loaded its second argument is used to typeset the
-%  citation label. In that case, this second argument can contain
-%  active characters but is used in an environment where
-%  |\@safe at activestrue| is in effect. This switch needs to be reset
-%  inside the |\hbox| which contains the citation label. In order to
-%  determine during \file{.aux} file processing which definition of
-%  |\bibcite| is needed we define |\bibcite| in such a way that it
-%  redefines itself with the proper definition. We call
-%  |\bbl at cite@choice| to select the proper definition for |\bibcite|.
-%  This new definition is then activated.
-%
-%    \begin{macrocode}
-  \bbl at redefine\bibcite{%
-    \bbl at cite@choice
-    \bibcite}
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-%  \begin{macro}{\bbl at bibcite}
-%    The macro |\bbl at bibcite| holds the definition of |\bibcite|
-%    needed when neither \pkg{natbib} nor \pkg{cite} is loaded.
-%
-%    \begin{macrocode}
-  \def\bbl at bibcite#1#2{%
-    \org at bibcite{#1}{\@safe at activesfalse#2}}
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-%  \begin{macro}{\bbl at cite@choice}
-%    The macro |\bbl at cite@choice| determines which definition of
-%    |\bibcite| is needed. First we give |\bibcite| its default
-%    definition.
-%
-%    \begin{macrocode}
-  \def\bbl at cite@choice{%
-    \global\let\bibcite\bbl at bibcite
-%    \end{macrocode}
-%
-%    Then, when \pkg{natbib} is loaded we restore the original
-%    definition of |\bibcite|. For \pkg{cite} we do the same.
-%
-%    \begin{macrocode}
-    \@ifpackageloaded{natbib}{\global\let\bibcite\org at bibcite}{}%
-    \@ifpackageloaded{cite}{\global\let\bibcite\org at bibcite}{}%
-%    \end{macrocode}
-%
-%    Make sure this only happens once.
-%
-%    \begin{macrocode}
-    \global\let\bbl at cite@choice\relax}
-%    \end{macrocode}
-%
-%    When a document is run for the first time, no \file{.aux} file is
-%    available, and |\bibcite| will not yet be properly defined. In
-%    this case, this has to happen before the document starts.
-%
-%    \begin{macrocode}
-  \AtBeginDocument{\bbl at cite@choice}
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-%  \begin{macro}{\@bibitem}
-%    One of the two internal \LaTeX\ macros called by |\bibitem|
-%    that write the citation label on the |.aux| file.
-%
-%    \begin{macrocode}
-  \bbl at redefine\@bibitem#1{%
-    \@safe at activestrue\org@@bibitem{#1}\@safe at activesfalse}
-\else
-  \let\org at nocite\nocite
-  \let\org@@citex\@citex
-  \let\org at bibcite\bibcite
-  \let\org@@bibitem\@bibitem
-\fi
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-% \subsection{Marks}
-%
-%  \begin{macro}{\markright}
-%    Because the output routine is asynchronous, we must
-%    pass the current language attribute to the head lines, together
-%    with the text that is put into them. To achieve this we need to
-%    adapt the definition of |\markright| and |\markboth| somewhat.
-%
-%    We check whether the argument is empty; if it is, we just make
-%    sure the scratch token register is empty.  Next, we store the
-%    argument to |\markright| in the scratch token register. This way
-%    these commands will not be expanded later, and we make sure that
-%    the text is typeset using the correct language settings. While
-%    doing so, we make sure that active characters that may end up in
-%    the mark are not disabled by the output routine kicking in while
-%    \cs{@safe at activestrue} is in effect.
-%
-%    \begin{macrocode}
-\bbl at trace{Marks}
-\IfBabelLayout{sectioning}
-  {\ifx\bbl at opt@headfoot\@nnil
-     \g at addto@macro\@resetactivechars{%
-       \set at typeset@protect
-       \expandafter\select at language@x\expandafter{\bbl at main@language}%
-       \let\protect\noexpand
-       \edef\thepage{%
-         \noexpand\babelsublr{\unexpanded\expandafter{\thepage}}}}%
-   \fi}
-  {\ifbbl at single\else
-     \bbl at ifunset{markright }\bbl at redefine\bbl at redefinerobust
-     \markright#1{%
-       \bbl at ifblank{#1}%
-         {\org at markright{}}%
-         {\toks@{#1}%
-          \bbl at exp{%
-            \\\org at markright{\\\protect\\\foreignlanguage{\languagename}%
-              {\\\protect\\\bbl at restore@actives\the\toks@}}}}}%
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-%  \begin{macro}{\markboth}
-%  \begin{macro}{\@mkboth}
-%    The definition of |\markboth| is equivalent to that of
-%    |\markright|, except that we need two token registers. The
-%    documentclasses \cls{report} and \cls{book} define and set the
-%    headings for the page. While doing so they also store a copy of
-%    |\markboth| in |\@mkboth|. Therefore we need to check whether
-%    |\@mkboth| has already been set. If so we neeed to do that again
-%    with the new definition of |\markboth|. (As of Oct 2019, \LaTeX{}
-%    stores the definition in an intermediate macros, so it's not
-%    necessary anymore, but it's preserved for older versions.)
-%
-%    \begin{macrocode}
-     \ifx\@mkboth\markboth
-       \def\bbl at tempc{\let\@mkboth\markboth}
-     \else
-       \def\bbl at tempc{}
-     \fi
-     \bbl at ifunset{markboth }\bbl at redefine\bbl at redefinerobust
-     \markboth#1#2{%
-       \protected at edef\bbl at tempb##1{%
-         \protect\foreignlanguage
-         {\languagename}{\protect\bbl at restore@actives##1}}%
-       \bbl at ifblank{#1}%
-         {\toks@{}}%
-         {\toks@\expandafter{\bbl at tempb{#1}}}%
-       \bbl at ifblank{#2}%
-         {\@temptokena{}}%
-         {\@temptokena\expandafter{\bbl at tempb{#2}}}%
-       \bbl at exp{\\\org at markboth{\the\toks@}{\the\@temptokena}}}
-       \bbl at tempc
-     \fi}  % end ifbbl at single, end \IfBabelLayout
-%    \end{macrocode}
-%
-%  \end{macro}
-%  \end{macro}
-%
-% \subsection{Preventing clashes with other packages}
-%
-% \subsubsection{\pkg{ifthen}}
-%
-%  \begin{macro}{\ifthenelse}
-%
-%    Sometimes a document writer wants to create a special effect
-%    depending on the page a certain fragment of text appears on. This
-%    can be achieved by the following piece of code:
-%\begin{verbatim}
-%    \ifthenelse{\isodd{\pageref{some:label}}}
-%               {code for odd pages}
-%               {code for even pages}
-%\end{verbatim}
-%    In order for this to work the argument of |\isodd| needs to be
-%    fully expandable. With the above redefinition of |\pageref| it is
-%    not in the case of this example. To overcome that, we add some
-%    code to the definition of |\ifthenelse| to make things work.
-%
-%    The first thing we need to do is check if the package
-%    \pkg{ifthen} is loaded. This should be done at |\begin{document}|
-%    time.
-%
-%    \begin{macrocode}
-\bbl at trace{Preventing clashes with other packages}
-\bbl at xin@{R}\bbl at opt@safe
-\ifin@
-  \AtBeginDocument{%
-    \@ifpackageloaded{ifthen}{%
-%    \end{macrocode}
-%
-%    Then we can redefine |\ifthenelse|:
-%
-%    \begin{macrocode}
-      \bbl at redefine@long\ifthenelse#1#2#3{%
-%    \end{macrocode}
-%
-%    We want to revert the definition of |\pageref| and |\ref| to
-%    their original definition for the first argument of |\ifthenelse|,
-%    so we first need to store their current meanings.
-%
-%    \begin{macrocode}
-        \let\bbl at temp@pref\pageref
-        \let\pageref\org at pageref
-        \let\bbl at temp@ref\ref
-        \let\ref\org at ref
-%    \end{macrocode}
-%
-%    Then we can set the |\@safe at actives| switch and call the original
-%    |\ifthenelse|. In order to be able to use shorthands in the
-%    second and third arguments of |\ifthenelse| the resetting of the
-%    switch \emph{and} the definition of |\pageref| happens inside
-%    those arguments.  When the package wasn't loaded we do nothing.
-%
-%    \begin{macrocode}
-        \@safe at activestrue
-        \org at ifthenelse{#1}%
-          {\let\pageref\bbl at temp@pref
-           \let\ref\bbl at temp@ref
-           \@safe at activesfalse
-           #2}%
-          {\let\pageref\bbl at temp@pref
-           \let\ref\bbl at temp@ref
-           \@safe at activesfalse
-           #3}%
-        }%
-      }{}%
-    }
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-% \subsubsection{\pkg{varioref}}
-%
-%  \begin{macro}{\@@vpageref}
-%  \begin{macro}{\vrefpagenum}
-%  \begin{macro}{\Ref}
-%
-%    When the package varioref is in use we need to modify its
-%    internal command |\@@vpageref| in order to prevent problems when
-%    an active character ends up in the argument of |\vref|. The same
-%    needs to happen for |\vrefpagenum|.
-%
-%    \begin{macrocode}
-  \AtBeginDocument{%
-    \@ifpackageloaded{varioref}{%
-      \bbl at redefine\@@vpageref#1[#2]#3{%
-        \@safe at activestrue
-        \org@@@vpageref{#1}[#2]{#3}%
-        \@safe at activesfalse}%
-      \bbl at redefine\vrefpagenum#1#2{%
-        \@safe at activestrue
-        \org at vrefpagenum{#1}{#2}%
-        \@safe at activesfalse}%
-%    \end{macrocode}
-%
-%    The package \pkg{varioref} defines |\Ref| to be a robust command
-%    wich uppercases the first character of the reference text. In
-%    order to be able to do that it needs to access the expandable form
-%    of |\ref|. So we employ a little trick here. We redefine the
-%    (internal) command \verb*|\Ref | to call |\org at ref| instead of
-%    |\ref|. The disadvantage of this solution is that whenever the
-%    definition of |\Ref| changes, this definition needs to be updated
-%    as well.
-%
-%    \begin{macrocode}
-      \expandafter\def\csname Ref \endcsname#1{%
-        \protected at edef\@tempa{\org at ref{#1}}\expandafter\MakeUppercase\@tempa}
-      }{}%
-    }
-\fi
-%    \end{macrocode}
-%
-%  \end{macro}
-%  \end{macro}
-%  \end{macro}
-%
-% \subsubsection{\pkg{hhline}}
-%
-%  \begin{macro}{\hhline}
-%    Delaying the activation of the shorthand characters has introduced
-%    a problem with the \pkg{hhline} package. The reason is that it
-%    uses the `:' character which is made active by the french support
-%    in \babel. Therefore we need to \emph{reload} the package when
-%    the `:' is an active character.
-%
-%    So at |\begin{document}| we check whether \pkg{hhline} is loaded.
-%
-%    \begin{macrocode}
-\AtEndOfPackage{%
-  \AtBeginDocument{%
-    \@ifpackageloaded{hhline}%
-%    \end{macrocode}
-%
-%    Then we check whether the expansion of |\normal at char:| is not
-%    equal to |\relax|.
-%
-%    \begin{macrocode}
-      {\expandafter\ifx\csname normal at char\string:\endcsname\relax
-       \else
-%    \end{macrocode}
-%
-%    In that case we simply reload the package. Note that this happens
-%    \emph{after} the category code of the @-sign has been changed to
-%    other, so we need to temporarily change it to letter again.
-%
-%    \begin{macrocode}
-         \makeatletter
-         \def\@currname{hhline}\input{hhline.sty}\makeatother
-       \fi}%
-      {}}}
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-% \subsubsection{\pkg{hyperref}}
-%
-%  \begin{macro}{\pdfstringdefDisableCommands}
-%
-%    A number of interworking problems between \pkg{babel} and
-%    \pkg{hyperref} are tackled by \pkg{hyperref} itself. The
-%    following code was introduced to prevent some annoying warnings
-%    but it broke bookmarks. This was quickly fixed in \pkg{hyperref},
-%    which essentially made it no-op. However, it will not removed for
-%    the moment because \pkg{hyperref} is expecting it.
-%
-%    \begin{macrocode}
-\AtBeginDocument{%
-  \ifx\pdfstringdefDisableCommands\@undefined\else
-    \pdfstringdefDisableCommands{\languageshorthands{system}}%
-  \fi}
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-% \subsubsection{\pkg{fancyhdr}}
-%
-%  \begin{macro}{\FOREIGNLANGUAGE}
-%    The package \pkg{fancyhdr} treats the running head and fout lines
-%    somewhat differently as the standard classes. A symptom of this is
-%    that the command |\foreignlanguage| which \babel\ adds to the
-%    marks can end up inside the argument of |\MakeUppercase|. To
-%    prevent unexpected results we need to define |\FOREIGNLANGUAGE|
-%    here.
-%
-%    \begin{macrocode}
-\DeclareRobustCommand{\FOREIGNLANGUAGE}[1]{%
-  \lowercase{\foreignlanguage{#1}}}
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-%  \begin{macro}{\substitutefontfamily}
-%    The command |\substitutefontfamily| creates an
-%    \file{.fd} file on the fly. The first argument is an encoding
-%    mnemonic, the second and third arguments are font family names.
-%
-%    \begin{macrocode}
-\def\substitutefontfamily#1#2#3{%
-  \lowercase{\immediate\openout15=#1#2.fd\relax}%
-  \immediate\write15{%
-    \string\ProvidesFile{#1#2.fd}%
-    [\the\year/\two at digits{\the\month}/\two at digits{\the\day}
-     \space generated font description file]^^J
-    \string\DeclareFontFamily{#1}{#2}{}^^J
-    \string\DeclareFontShape{#1}{#2}{m}{n}{<->ssub * #3/m/n}{}^^J
-    \string\DeclareFontShape{#1}{#2}{m}{it}{<->ssub * #3/m/it}{}^^J
-    \string\DeclareFontShape{#1}{#2}{m}{sl}{<->ssub * #3/m/sl}{}^^J
-    \string\DeclareFontShape{#1}{#2}{m}{sc}{<->ssub * #3/m/sc}{}^^J
-    \string\DeclareFontShape{#1}{#2}{b}{n}{<->ssub * #3/bx/n}{}^^J
-    \string\DeclareFontShape{#1}{#2}{b}{it}{<->ssub * #3/bx/it}{}^^J
-    \string\DeclareFontShape{#1}{#2}{b}{sl}{<->ssub * #3/bx/sl}{}^^J
-    \string\DeclareFontShape{#1}{#2}{b}{sc}{<->ssub * #3/bx/sc}{}^^J
-    }%
-  \closeout15
-  }
-%    \end{macrocode}
-%
-%    This command should only be used in the preamble of a document.
-%
-%    \begin{macrocode}
-\@onlypreamble\substitutefontfamily
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-% \subsection{Encoding and fonts}
-%
-%  Because documents may use non-ASCII font encodings, we make sure
-%  that the logos of \TeX\ and \LaTeX\ always come out in the right
-%  encoding. There is a list of non-ASCII encodings. Unfortunately,
-%  \textsf{fontenc} deletes its package options, so we must guess which
-%  encodings has been loaded by traversing |\@filelist| to search for
-%  \m{enc}|enc.def|. If a non-ASCII has been loaded, we define versions
-%  of |\TeX| and |\LaTeX| for them using |\ensureascii|. The default
-%  ASCII encoding is set, too (in reverse order): the ``main'' encoding
-%  (when the document begins), the last loaded, or |OT1|.
-%
-%  \begin{macro}{\ensureascii}
-%
-%    \begin{macrocode}
-\bbl at trace{Encoding and fonts}
-\newcommand\BabelNonASCII{LGR,X2,OT2,OT3,OT6,LHE,LWN,LMA,LMC,LMS,LMU,PU,PD1}
-\newcommand\BabelNonText{TS1,T3,TS3}
-\let\org at TeX\TeX
-\let\org at LaTeX\LaTeX
-\let\ensureascii\@firstofone
-\AtBeginDocument{%
-  \in at false
-  \bbl at foreach\BabelNonASCII{% is there a text non-ascii enc?
-    \ifin@\else
-      \lowercase{\bbl at xin@{,#1enc.def,}{,\@filelist,}}%
-    \fi}%
-  \ifin@ % if a text non-ascii has been loaded
-    \def\ensureascii#1{{\fontencoding{OT1}\selectfont#1}}%
-    \DeclareTextCommandDefault{\TeX}{\org at TeX}%
-    \DeclareTextCommandDefault{\LaTeX}{\org at LaTeX}%
-    \def\bbl at tempb#1\@@{\uppercase{\bbl at tempc#1}ENC.DEF\@empty\@@}%
-    \def\bbl at tempc#1ENC.DEF#2\@@{%
-      \ifx\@empty#2\else
-        \bbl at ifunset{T@#1}%
-          {}%
-          {\bbl at xin@{,#1,}{,\BabelNonASCII,\BabelNonText,}%
-           \ifin@
-             \DeclareTextCommand{\TeX}{#1}{\ensureascii{\org at TeX}}%
-             \DeclareTextCommand{\LaTeX}{#1}{\ensureascii{\org at LaTeX}}%
-           \else
-             \def\ensureascii##1{{\fontencoding{#1}\selectfont##1}}%
-           \fi}%
-      \fi}%
-    \bbl at foreach\@filelist{\bbl at tempb#1\@@}%  TODO - \@@ de mas??
-    \bbl at xin@{,\cf at encoding,}{,\BabelNonASCII,\BabelNonText,}%
-    \ifin@\else
-      \edef\ensureascii#1{{%
-        \noexpand\fontencoding{\cf at encoding}\noexpand\selectfont#1}}%
-    \fi
-  \fi}
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-%  Now comes the old deprecated stuff (with a little change in 3.9l,
-%  for \textsf{fontspec}).  The first thing we need to do is to
-%  determine, at |\begin{document}|, which latin fontencoding to use.
-%
-%  \begin{macro}{\latinencoding}
-%    When text is being typeset in an encoding other than `latin'
-%    (\texttt{OT1} or \texttt{T1}), it would be nice to still have
-%    Roman numerals come out in the Latin encoding.
-%    So we first assume that the current encoding at the end
-%    of processing the package is the Latin encoding.
-%
-%    \begin{macrocode}
-\AtEndOfPackage{\edef\latinencoding{\cf at encoding}}
-%    \end{macrocode}
-%
-%    But this might be overruled with a later loading of the package
-%    \pkg{fontenc}. Therefore we check at the execution of
-%    |\begin{document}| whether it was loaded with the \Lopt{T1}
-%    option. The normal way to do this (using |\@ifpackageloaded|) is
-%    disabled for this package. Now we have to revert to parsing the
-%    internal macro |\@filelist| which contains all the filenames
-%    loaded.
-%
-%    \begin{macrocode}
-\AtBeginDocument{%
-  \@ifpackageloaded{fontspec}%
-    {\xdef\latinencoding{%
-       \ifx\UTFencname\@undefined
-         EU\ifcase\bbl at engine\or2\or1\fi
-       \else
-         \UTFencname
-       \fi}}%
-    {\gdef\latinencoding{OT1}%
-     \ifx\cf at encoding\bbl at t@one
-       \xdef\latinencoding{\bbl at t@one}%
-     \else
-       \ifx\@fontenc at load@list\@undefined
-         \@ifl at aded{def}{t1enc}{\xdef\latinencoding{\bbl at t@one}}{}%
-       \else
-         \def\@elt#1{,#1,}%
-         \edef\bbl at tempa{\expandafter\@gobbletwo\@fontenc at load@list}%
-         \let\@elt\relax
-         \bbl at xin@{,T1,}\bbl at tempa
-         \ifin@
-           \xdef\latinencoding{\bbl at t@one}%
-         \fi
-       \fi
-     \fi}}
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-%  \begin{macro}{\latintext}
-%    Then we can define the command |\latintext| which is a
-%    declarative switch to a latin font-encoding. Usage of this macro
-%    is deprecated.
-%
-%    \begin{macrocode}
-\DeclareRobustCommand{\latintext}{%
-  \fontencoding{\latinencoding}\selectfont
-  \def\encodingdefault{\latinencoding}}
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-%  \begin{macro}{\textlatin}
-%    This command takes an argument which is then typeset using the
-%    requested font encoding. In order to avoid many encoding switches
-%    it operates in a local scope.
-%
-%    \begin{macrocode}
-\ifx\@undefined\DeclareTextFontCommand
-  \DeclareRobustCommand{\textlatin}[1]{\leavevmode{\latintext #1}}
-\else
-  \DeclareTextFontCommand{\textlatin}{\latintext}
-\fi
-%    \end{macrocode}
-%
-% \end{macro}
-%
-% \subsection{Basic bidi support}
-%
-% \textbf{Work in progress.} This code is currently placed here for
-% practical reasons.
-%
-% It is loosely based on |rlbabel.def|, but most of it has been
-% developed from scratch. This \babel{} module (by Johannes Braams and
-% Boris Lavva) has served the purpose of typesetting R documents for
-% two decades, and despite its flaws I think it is still a good starting
-% point (some parts have been copied here almost verbatim), partly
-% thanks to its simplicity. I've also looked at \textsc{arabi} (by
-% Youssef Jabri), which is compatible with \babel{}.
-%
-% There are two ways of modifying macros to make them “bidi”, namely,
-% by patching the internal low-level macros (which is what I have done
-% with lists, columns, counters, tocs, much like |rlbabel| did), and
-% by introducing a “middle layer” just below the user interface
-% (sectioning, footnotes).
-%
-%    \begin{itemize}
-%    \item pdftex provides a minimal support for bidi text, and it
-%      must be done by hand. Vertical typesetting is not possible.
-%    \item \xetex{} is somewhat better, thanks to its font engine
-%      (even if not always reliable) and a few additional tools. However,
-%      very little is done at the paragraph level. Another challenging
-%      problem is text direction does not honour \TeX{} grouping.
-%    \item \luatex{} can provide the most complete solution, as we can
-%      manipulate almost freely the node list, the generated lines,
-%      and so on, but bidi text does not work out of the box and some
-%      development is necessary. It also provides tools to properly
-%      set left-to-right and right-to-left page layouts. As Lua\TeX-ja
-%      shows, vertical typesetting is possible, too.
-%    \end{itemize}
-%
-%    \begin{macrocode}
-\bbl at trace{Basic (internal) bidi support}
-\def\bbl at alscripts{,Arabic,Syriac,Thaana,}
-\def\bbl at rscripts{%
-  ,Imperial Aramaic,Avestan,Cypriot,Hatran,Hebrew,%
-  Old Hungarian,Old Hungarian,Lydian,Mandaean,Manichaean,%
-  Manichaean,Meroitic Cursive,Meroitic,Old North Arabian,%
-  Nabataean,N'Ko,Orkhon,Palmyrene,Inscriptional Pahlavi,%
-  Psalter Pahlavi,Phoenician,Inscriptional Parthian,Samaritan,%
-  Old South Arabian,}%
-\def\bbl at provide@dirs#1{%
-  \bbl at xin@{\csname bbl at sname@#1\endcsname}{\bbl at alscripts\bbl at rscripts}%
-  \ifin@
-    \global\bbl at csarg\chardef{wdir@#1}\@ne
-    \bbl at xin@{\csname bbl at sname@#1\endcsname}{\bbl at alscripts}%
-    \ifin@
-      \global\bbl at csarg\chardef{wdir@#1}\tw@  % useless in xetex
-    \fi
-  \else
-    \global\bbl at csarg\chardef{wdir@#1}\z@
-  \fi
-  \ifodd\bbl at engine
-    \bbl at csarg\ifcase{wdir@#1}%
-      \directlua{ Babel.locale_props[\the\localeid].textdir = 'l' }%
-    \or
-      \directlua{ Babel.locale_props[\the\localeid].textdir = 'r' }%
-    \or
-      \directlua{ Babel.locale_props[\the\localeid].textdir = 'al' }%
-    \fi
-  \fi}
-\def\bbl at switchdir{%
-  \bbl at ifunset{bbl at lsys@\languagename}{\bbl at provide@lsys{\languagename}}{}%
-  \bbl at ifunset{bbl at wdir@\languagename}{\bbl at provide@dirs{\languagename}}{}%
-  \bbl at exp{\\\bbl at setdirs\bbl at cl{wdir}}}
-\def\bbl at setdirs#1{% TODO - math
-  \ifcase\bbl at select@type % TODO - strictly, not the right test
-    \bbl at bodydir{#1}%
-    \bbl at pardir{#1}%
-  \fi
-  \bbl at textdir{#1}}
-\ifodd\bbl at engine  % luatex=1
-  \AddBabelHook{babel-bidi}{afterextras}{\bbl at switchdir}
-  \DisableBabelHook{babel-bidi}
-  \chardef\bbl at thetextdir\z@
-  \chardef\bbl at thepardir\z@
-  \def\bbl at getluadir#1{%
-    \directlua{
-      if tex.#1dir == 'TLT' then
-        tex.sprint('0')
-      elseif tex.#1dir == 'TRT' then
-        tex.sprint('1')
-      end}}
-  \def\bbl at setluadir#1#2#3{% 1=text/par.. 2=\textdir.. 3=0 lr/1 rl
-    \ifcase#3\relax
-      \ifcase\bbl at getluadir{#1}\relax\else
-        #2 TLT\relax
-      \fi
-    \else
-      \ifcase\bbl at getluadir{#1}\relax
-        #2 TRT\relax
-      \fi
-    \fi}
-  \def\bbl at textdir#1{%
-    \bbl at setluadir{text}\textdir{#1}%
-    \chardef\bbl at thetextdir#1\relax
-    \setattribute\bbl at attr@dir{\numexpr\bbl at thepardir*3+#1}}
-  \def\bbl at pardir#1{%
-    \bbl at setluadir{par}\pardir{#1}%
-    \chardef\bbl at thepardir#1\relax}
-  \def\bbl at bodydir{\bbl at setluadir{body}\bodydir}
-  \def\bbl at pagedir{\bbl at setluadir{page}\pagedir}
-  \def\bbl at dirparastext{\pardir\the\textdir\relax}%   %%%%
-  % Sadly, we have to deal with boxes in math with basic.
-  % Activated every math with the package option bidi=:
-  \def\bbl at mathboxdir{%
-    \ifcase\bbl at thetextdir\relax
-      \everyhbox{\textdir TLT\relax}%
-    \else
-      \everyhbox{\textdir TRT\relax}%
-    \fi}
-\else % pdftex=0, xetex=2
-  \AddBabelHook{babel-bidi}{afterextras}{\bbl at switchdir}
-  \DisableBabelHook{babel-bidi}
-  \newcount\bbl at dirlevel
-  \chardef\bbl at thetextdir\z@
-  \chardef\bbl at thepardir\z@
-  \def\bbl at textdir#1{%
-    \ifcase#1\relax
-       \chardef\bbl at thetextdir\z@
-       \bbl at textdir@i\beginL\endL
-     \else
-       \chardef\bbl at thetextdir\@ne
-       \bbl at textdir@i\beginR\endR
-    \fi}
-  \def\bbl at textdir@i#1#2{%
-    \ifhmode
-      \ifnum\currentgrouplevel>\z@
-        \ifnum\currentgrouplevel=\bbl at dirlevel
-          \bbl at error{Multiple bidi settings inside a group}%
-            {I'll insert a new group, but expect wrong results.}%
-          \bgroup\aftergroup#2\aftergroup\egroup
-        \else
-          \ifcase\currentgrouptype\or % 0 bottom
-            \aftergroup#2% 1 simple {}
-          \or
-            \bgroup\aftergroup#2\aftergroup\egroup % 2 hbox
-          \or
-            \bgroup\aftergroup#2\aftergroup\egroup % 3 adj hbox
-          \or\or\or % vbox vtop align
-          \or
-            \bgroup\aftergroup#2\aftergroup\egroup % 7 noalign
-          \or\or\or\or\or\or % output math disc insert vcent mathchoice
-          \or
-            \aftergroup#2% 14 \begingroup
-          \else
-            \bgroup\aftergroup#2\aftergroup\egroup % 15 adj
-          \fi
-        \fi
-        \bbl at dirlevel\currentgrouplevel
-      \fi
-      #1%
-    \fi}
-  \def\bbl at pardir#1{\chardef\bbl at thepardir#1\relax}
-  \let\bbl at bodydir\@gobble
-  \let\bbl at pagedir\@gobble
-  \def\bbl at dirparastext{\chardef\bbl at thepardir\bbl at thetextdir}
-%    \end{macrocode}
-%
-% The following command is executed only if there is a right-to-left
-% script (once). It activates the |\everypar| hack for \xetex, to
-% properly handle the par direction. Note text and par dirs are
-% decoupled to some extent (although not completely).
-%
-%    \begin{macrocode}
-  \def\bbl at xebidipar{%
-    \let\bbl at xebidipar\relax
-    \TeXXeTstate\@ne
-    \def\bbl at xeeverypar{%
-      \ifcase\bbl at thepardir
-        \ifcase\bbl at thetextdir\else\beginR\fi
-      \else
-        {\setbox\z@\lastbox\beginR\box\z@}%
-      \fi}%
-    \let\bbl at severypar\everypar
-    \newtoks\everypar
-    \everypar=\bbl at severypar
-    \bbl at severypar{\bbl at xeeverypar\the\everypar}}
-  \def\bbl at tempb{%
-    \let\bbl at textdir@i\@gobbletwo
-    \let\bbl at xebidipar\@empty
-    \AddBabelHook{bidi}{foreign}{%
-      \def\bbl at tempa{\def\BabelText########1}%
-      \ifcase\bbl at thetextdir
-        \expandafter\bbl at tempa\expandafter{\BabelText{\LR{####1}}}%
-      \else
-        \expandafter\bbl at tempa\expandafter{\BabelText{\RL{####1}}}%
-      \fi}
-    \def\bbl at pardir##1{\ifcase##1\relax\setLR\else\setRL\fi}}
-  \@ifpackagewith{babel}{bidi=bidi}{\bbl at tempb}{}%
-  \@ifpackagewith{babel}{bidi=bidi-l}{\bbl at tempb}{}%
-  \@ifpackagewith{babel}{bidi=bidi-r}{\bbl at tempb}{}%
-\fi
-%    \end{macrocode}
-%
-% A tool for weak L (mainly digits). We also disable warnings with
-% \textsf{hyperref}.
-%
-%    \begin{macrocode}
-\DeclareRobustCommand\babelsublr[1]{\leavevmode{\bbl at textdir\z@#1}}
-\AtBeginDocument{%
-  \ifx\pdfstringdefDisableCommands\@undefined\else
-    \ifx\pdfstringdefDisableCommands\relax\else
-      \pdfstringdefDisableCommands{\let\babelsublr\@firstofone}%
-    \fi
-  \fi}
-%    \end{macrocode}
-%
-% \subsection{Local Language Configuration}
-%
-%  \begin{macro}{\loadlocalcfg}
-%    At some sites it may be necessary to add site-specific actions to
-%    a language definition file. This can be done by creating a file
-%    with the same name as the language definition file, but with the
-%    extension \file{.cfg}. For instance the file \file{norsk.cfg}
-%    will be loaded when the language definition file \file{norsk.ldf}
-%    is loaded.
-%
-%    For plain-based formats we don't want to override the definition
-%    of |\loadlocalcfg| from \file{plain.def}.
-%
-%    \begin{macrocode}
-\bbl at trace{Local Language Configuration}
-\ifx\loadlocalcfg\@undefined
-  \@ifpackagewith{babel}{noconfigs}%
-    {\let\loadlocalcfg\@gobble}%
-    {\def\loadlocalcfg#1{%
-      \InputIfFileExists{#1.cfg}%
-        {\typeout{*************************************^^J%
-                       * Local config file #1.cfg used^^J%
-                       *}}%
-        \@empty}}
-\fi
-%    \end{macrocode}
-%
-%    Just to be compatible with \LaTeX$\:$2.09 we add a few more lines
-%    of code:
-%
-%    \begin{macrocode}
-\ifx\@unexpandable at protect\@undefined
-  \def\@unexpandable at protect{\noexpand\protect\noexpand}
-  \long\def\protected at write#1#2#3{%
-    \begingroup
-      \let\thepage\relax
-      #2%
-      \let\protect\@unexpandable at protect
-      \edef\reserved at a{\write#1{#3}}%
-      \reserved at a
-    \endgroup
-    \if at nobreak\ifvmode\nobreak\fi\fi}
-\fi
-%</core>
 %<*kernel>
-%    \end{macrocode}%
-%    \end{macro}
-%
-% \section{Multiple languages (\texttt{switch.def)}}
-%
-%    Plain \TeX\ version~3.0 provides the primitive |\language| that
-%    is used to store the current language. When used with a pre-3.0
-%    version this function has to be implemented by allocating a
-%    counter.
-%
-%    \begin{macrocode}
-<@Make sure ProvidesFile is defined@>
-\ProvidesFile{switch.def}[<@date@> <@version@> Babel switching mechanism]
-<@Load macros for plain if not LaTeX@>
-<@Define core switching macros@>
-%    \end{macrocode}
-%
-%  \begin{macro}{\adddialect}
-%    The macro |\adddialect| can be used to add the name of a dialect
-%    or variant language, for which an already defined hyphenation
-%    table can be used.
-%
-%    \begin{macrocode}
-\def\bbl at version{<@version@>}
-\def\bbl at date{<@date@>}
-\def\adddialect#1#2{%
-  \global\chardef#1#2\relax
-  \bbl at usehooks{adddialect}{{#1}{#2}}%
-  \begingroup
-    \count@#1\relax
-    \def\bbl at elt##1##2##3##4{%
-      \ifnum\count@=##2\relax
-        \bbl at info{\string#1 = using hyphenrules for ##1\\%
-                  (\string\language\the\count@)}%
-        \def\bbl at elt####1####2####3####4{}%
-      \fi}%
-    \bbl at cs{languages}%
-  \endgroup}
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-%    |\bbl at iflanguage| executes code only if the language |l@|
-%    exists. Otherwise raises and error.
-%
-%    The argument of |\bbl at fixname| has to be a macro name, as it may get
-%    ``fixed'' if casing (lc/uc) is wrong. It's intented to fix a
-%    long-standing bug when |\foreignlanguage| and the like appear in
-%    a |\MakeXXXcase|. However, a lowercase form is not imposed to
-%    improve backward compatibility (perhaps you defined a language
-%    named |MYLANG|, but unfortunately mixed case names cannot be
-%    trapped). Note |l@| is encapsulated, so that its case does not
-%    change.
-%
-%    \begin{macrocode}
-\def\bbl at fixname#1{%
-  \begingroup
-    \def\bbl at tempe{l@}%
-    \edef\bbl at tempd{\noexpand\@ifundefined{\noexpand\bbl at tempe#1}}%
-    \bbl at tempd
-      {\lowercase\expandafter{\bbl at tempd}%
-         {\uppercase\expandafter{\bbl at tempd}%
-           \@empty
-           {\edef\bbl at tempd{\def\noexpand#1{#1}}%
-            \uppercase\expandafter{\bbl at tempd}}}%
-         {\edef\bbl at tempd{\def\noexpand#1{#1}}%
-          \lowercase\expandafter{\bbl at tempd}}}%
-      \@empty
-    \edef\bbl at tempd{\endgroup\def\noexpand#1{#1}}%
-  \bbl at tempd
-  \bbl at usehooks{languagename}{}}
-\def\bbl at iflanguage#1{%
-  \@ifundefined{l@#1}{\@nolanerr{#1}\@gobble}\@firstofone}
-%    \end{macrocode}
-%
-%  \begin{macro}{\iflanguage}
-%    Users might want to test (in a private package for instance)
-%    which language is currently active. For this we provide a test
-%    macro, |\iflanguage|, that has three arguments.  It checks
-%    whether the first argument is a known language. If so, it
-%    compares the first argument with the value of |\language|. Then,
-%    depending on the result of the comparison, it executes either the
-%    second or the third argument.
-%
-%    \begin{macrocode}
-\def\iflanguage#1{%
-  \bbl at iflanguage{#1}{%
-    \ifnum\csname l@#1\endcsname=\language
-      \expandafter\@firstoftwo
-    \else
-      \expandafter\@secondoftwo
-    \fi}}
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-% \subsection{Selecting the language}
-%
-%  \begin{macro}{\selectlanguage}
-%    The macro |\selectlanguage| checks whether the language is
-%    already defined before it performs its actual task, which is to
-%    update |\language| and activate language-specific definitions.
-%
-%    To allow the call of |\selectlanguage| either with a control
-%    sequence name or with a simple string as argument, we have to use
-%    a trick to delete the optional escape character.
-%
-%    To convert a control sequence to a string, we use the |\string|
-%    primitive.  Next we have to look at the first character of this
-%    string and compare it with the escape character.  Because this
-%    escape character can be changed by setting the internal integer
-%    |\escapechar| to a character number, we have to compare this
-%    number with the character of the string.  To do this we have to
-%    use \TeX's backquote notation to specify the character as a
-%    number.
-%
-%    If the first character of the |\string|'ed argument is the
-%    current escape character, the comparison has stripped this
-%    character and the rest in the `then' part consists of the rest of
-%    the control sequence name.  Otherwise we know that either the
-%    argument is not a control sequence or |\escapechar| is set to a
-%    value outside of the character range~$0$--$255$.
-%
-%    If the user gives an empty argument, we provide a default
-%    argument for |\string|.  This argument should expand to nothing.
-%
-%    \begin{macrocode}
-\let\bbl at select@type\z@
-\edef\selectlanguage{%
-  \noexpand\protect
-  \expandafter\noexpand\csname selectlanguage \endcsname}
-%    \end{macrocode}
-%
-%    Because the command |\selectlanguage| could be used in a moving
-%    argument it expands to \verb*=\protect\selectlanguage =.
-%    Therefore, we have to make sure that a macro |\protect| exists.
-%    If it doesn't it is |\let| to |\relax|.
-%
-%    \begin{macrocode}
-\ifx\@undefined\protect\let\protect\relax\fi
-%    \end{macrocode}
-%
-%    As \LaTeX$\:$2.09 writes to files \textit{expanded} whereas
-%    \LaTeXe\ takes care \textit{not} to expand the arguments of
-%    |\write| statements we need to be a bit clever about the way we
-%    add information to \file{.aux} files. Therefore we introduce the
-%    macro |\xstring| which should expand to the right amount of
-%    |\string|'s.
-%
-%    \begin{macrocode}
-\ifx\documentclass\@undefined
-  \def\xstring{\string\string\string}
-\else
-  \let\xstring\string
-\fi
-%    \end{macrocode}
-%
-% \end{macro}
-%
-%    Since version 3.5 \babel\ writes entries to the auxiliary files in
-%    order to typeset table of contents etc. in the correct language
-%    environment.
-%  \begin{macro}{\bbl at pop@language}
-%    \emph{But} when the language change happens \emph{inside} a group
-%    the end of the group doesn't write anything to the auxiliary
-%    files. Therefore we need \TeX's |aftergroup| mechanism to help
-%    us. The command |\aftergroup| stores the token immediately
-%    following it to be executed when the current group is closed. So
-%    we define a temporary control sequence |\bbl at pop@language| to be
-%    executed at the end of the group. It calls |\bbl at set@language|
-%    with the name of the current language as its argument.
-%
-%  \begin{macro}{\bbl at language@stack}
-%    The previous solution works for one level of nesting groups, but
-%    as soon as more levels are used it is no longer adequate. For
-%    that case we need to keep track of the nested languages using a
-%    stack mechanism. This stack is called |\bbl at language@stack| and
-%    initially empty.
-%
-%    \begin{macrocode}
-\def\bbl at language@stack{}
-%    \end{macrocode}
-%
-%    When using a stack we need a mechanism to push an element on the
-%    stack and to retrieve the information afterwards.
-%  \begin{macro}{\bbl at push@language}
-%  \begin{macro}{\bbl at pop@language}
-%    The stack is simply a list of languagenames, separated with a `+'
-%    sign; the push function can be simple:
-%
-%    \begin{macrocode}
-\def\bbl at push@language{%
-  \xdef\bbl at language@stack{\languagename+\bbl at language@stack}}
-%    \end{macrocode}
-%
-% Retrieving information from the stack is a little bit less simple, as
-% we need to remove the element from the stack while storing it in the
-% macro |\languagename|. For this we first define a helper function.
-%  \begin{macro}{\bbl at pop@lang}
-%    This macro stores its first element (which is delimited by the
-%    `+'-sign) in |\languagename| and stores the rest of the string
-%    (delimited by `-') in its third argument.
-%
-%    \begin{macrocode}
-\def\bbl at pop@lang#1+#2-#3{%
-  \edef\languagename{#1}\xdef#3{#2}}
-%    \end{macrocode}
-%
-%  \end{macro}
-%    The reason for the somewhat weird arrangement of arguments to the
-%    helper function is the fact it is called in the following way.
-%    This means that before |\bbl at pop@lang| is executed \TeX\ first
-%    \emph{expands} the stack, stored in |\bbl at language@stack|. The
-%    result of that is that the argument string of |\bbl at pop@lang|
-%    contains one or more language names, each followed by a `+'-sign
-%    (zero language names won't occur as this macro will only be
-%    called after something has been pushed on the stack) followed by
-%    the `-'-sign and finally the reference to the stack.
-%
-%    \begin{macrocode}
-\let\bbl at ifrestoring\@secondoftwo
-\def\bbl at pop@language{%
-  \expandafter\bbl at pop@lang\bbl at language@stack-\bbl at language@stack
-  \let\bbl at ifrestoring\@firstoftwo
-  \expandafter\bbl at set@language\expandafter{\languagename}%
-  \let\bbl at ifrestoring\@secondoftwo}
-%    \end{macrocode}
-%
-%    Once the name of the previous language is retrieved from the stack,
-%    it is fed to |\bbl at set@language| to do the actual work of
-%    switching everything that needs switching.
-%  \end{macro}
-%  \end{macro}
-%  \end{macro}
-%
-%  An alternative way to identify languages (in the \babel{} sense)
-%  with a numerical value is introduced in 3.30. This is one of the
-%  first steps for a new interface based on the concept of locale,
-%  which explains the name of |\localeid|. This means |\l at ...| will be
-%  reserved for hyphenation patterns.
-%
-%    \begin{macrocode}
-\chardef\localeid\z@
-\def\bbl at id@last{0}    % No real need for a new counter
-\def\bbl at id@assign{%
-  \bbl at ifunset{bbl at id@@\languagename}%
-    {\count@\bbl at id@last\relax
-     \advance\count@\@ne
-     \bbl at csarg\chardef{id@@\languagename}\count@
-     \edef\bbl at id@last{\the\count@}%
-     \ifcase\bbl at engine\or
-       \directlua{
-         Babel = Babel or {}
-         Babel.locale_props = Babel.locale_props or {}
-         Babel.locale_props[\bbl at id@last] = {}
-         Babel.locale_props[\bbl at id@last].name = '\languagename'
-        }%
-      \fi}%
-    {}%
-    \chardef\localeid\bbl at cl{id@}}
-%    \end{macrocode}
-%
-% The unprotected part of |\selectlanguage|.
-%
-%    \begin{macrocode}
-\expandafter\def\csname selectlanguage \endcsname#1{%
-  \ifnum\bbl at hymapsel=\@cclv\let\bbl at hymapsel\tw@\fi
-  \bbl at push@language
-  \aftergroup\bbl at pop@language
-  \bbl at set@language{#1}}
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-%  \begin{macro}{\bbl at set@language}
-%
-%    The macro |\bbl at set@language| takes care of switching the language
-%    environment \emph{and} of writing entries on the auxiliary files.
-%    For historial reasons, language names can be either |language| of
-%    |\language|. To catch either form a trick is used, but
-%    unfortunately as a side effect the catcodes of letters in
-%    |\languagename| are messed up. This is a bug, but preserved for
-%    backwards compatibility. The list of auxiliary files can be
-%    extended by redefining |\BabelContentsFiles|, but make sure they
-%    are loaded inside a group (as |aux|, |toc|, |lof|, and |lot| do)
-%    or the last language of the document will remain active
-%    afterwards.
-%
-%    We also write a command to change the current language in the
-%    auxiliary files.
-%
-%    \begin{macrocode}
-\def\BabelContentsFiles{toc,lof,lot}
-\def\bbl at set@language#1{% from selectlanguage, pop@
-  \edef\languagename{%
-    \ifnum\escapechar=\expandafter`\string#1\@empty
-    \else\string#1\@empty\fi}%
-  \select at language{\languagename}%
-  % write to auxs
-  \expandafter\ifx\csname date\languagename\endcsname\relax\else
-    \if at filesw
-      \ifx\babel at aux\@gobbletwo\else % Set if single in the first, redundant
-        \protected at write\@auxout{}{\string\babel at aux{\languagename}{}}%
-      \fi
-      \bbl at usehooks{write}{}%
-    \fi
-  \fi}
-\def\select at language#1{% from set@, babel at aux
-  % set hymap
-  \ifnum\bbl at hymapsel=\@cclv\chardef\bbl at hymapsel4\relax\fi
-  % set name
-  \edef\languagename{#1}%
-  \bbl at fixname\languagename
-  \expandafter\ifx\csname date\languagename\endcsname\relax
-    \IfFileExists{babel-\languagename.tex}%
-      {\babelprovide{\languagename}}%
-      {}%
-  \fi
-  \bbl at iflanguage\languagename{%
-     \expandafter\ifx\csname date\languagename\endcsname\relax
-      \bbl at error
-        {Unknown language `#1'. Either you have\\%
-         misspelled its name, it has not been installed,\\%
-         or you requested it in a previous run. Fix its name,\\%
-         install it or just rerun the file, respectively. In\\%
-         some cases, you may need to remove the aux file}%
-        {You may proceed, but expect wrong results}%
-    \else
-      % set type
-      \let\bbl at select@type\z@
-      \expandafter\bbl at switch\expandafter{\languagename}%
-    \fi}}
-\def\babel at aux#1#2{%
-  \select at language{#1}%
-  \bbl at foreach\BabelContentsFiles{%
-    \@writefile{##1}{\babel at toc{#1}{#2}}}}% %% TODO - ok in plain?
-\def\babel at toc#1#2{%
-  \select at language{#1}}
-%    \end{macrocode}
-%
-% A bit of optimization. Select in heads/foots the language only if
-% necessary. The real thing is in \texttt{babel.def}.
-%
-%    \begin{macrocode}
-\let\select at language@x\select at language
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-%    First, check if the user asks for a known language. If so,
-%    update the value of |\language| and call |\originalTeX|
-%    to bring \TeX\ in a certain pre-defined state.
-%
-%    The name of the language is stored in the control sequence
-%    |\languagename|.
-%
-%    Then we have to \emph{re}define |\originalTeX| to compensate for
-%    the things that have been activated.  To save memory space for
-%    the macro definition of |\originalTeX|, we construct the control
-%    sequence name for the |\noextras|\langvar\ command at definition
-%    time by expanding the |\csname| primitive.
-%
-%    Now activate the language-specific definitions. This is done by
-%    constructing the names of three macros by concatenating three
-%    words with the argument of |\selectlanguage|, and calling these
-%    macros. \nb{What if \cs{hyphenation} was used in |extras|? Patch
-%    temporarily |\set at hyphenmins| and hyphenation. It can be done in
-%    hooks if necessary.}
-%
-%    The switching of the values of |\lefthyphenmin| and
-%    |\righthyphenmin| is somewhat different. First we save their
-%    current values, then we check if |\|\langvar|hyphenmins| is
-%    defined. If it is not, we set default values (2 and 3), otherwise
-%    the values in |\|\langvar|hyphenmins| will be used.
-%
-%    \begin{macrocode}
-\newif\ifbbl at usedategroup
-\def\bbl at switch#1{%  from select@, foreign@
-  % make sure there is info for the language if so requested
-  \bbl at ensureinfo{#1}%
-  % restore
-  \originalTeX
-  \expandafter\def\expandafter\originalTeX\expandafter{%
-    \csname noextras#1\endcsname
-    \let\originalTeX\@empty
-    \babel at beginsave}%
-  \bbl at usehooks{afterreset}{}%
-  \languageshorthands{none}%
-  % set the locale id
-  \bbl at id@assign
-  % switch captions, date
-  \ifcase\bbl at select@type
-    \ifhmode
-      \hskip\z at skip % trick to ignore spaces
-      \csname captions#1\endcsname\relax
-      \csname date#1\endcsname\relax
-      \loop\ifdim\lastskip>\z@\unskip\repeat\unskip
-    \else
-      \csname captions#1\endcsname\relax
-      \csname date#1\endcsname\relax
-    \fi
-  \else
-    \ifbbl at usedategroup   % if \foreign... within \<lang>date
-      \bbl at usedategroupfalse
-      \ifhmode
-        \hskip\z at skip % trick to ignore spaces
-        \csname date#1\endcsname\relax
-        \loop\ifdim\lastskip>\z@\unskip\repeat\unskip
-      \else
-        \csname date#1\endcsname\relax
-      \fi
-    \fi
-  \fi
-  % switch extras
-  \bbl at usehooks{beforeextras}{}%
-  \csname extras#1\endcsname\relax
-  \bbl at usehooks{afterextras}{}%
-  %  > babel-ensure
-  %  > babel-sh-<short>
-  %  > babel-bidi
-  %  > babel-fontspec
-  % hyphenation - case mapping
-  \ifcase\bbl at opt@hyphenmap\or
-    \def\BabelLower##1##2{\lccode##1=##2\relax}%
-    \ifnum\bbl at hymapsel>4\else
-      \csname\languagename @bbl at hyphenmap\endcsname
-    \fi
-    \chardef\bbl at opt@hyphenmap\z@
-  \else
-    \ifnum\bbl at hymapsel>\bbl at opt@hyphenmap\else
-      \csname\languagename @bbl at hyphenmap\endcsname
-    \fi
-  \fi
-  \global\let\bbl at hymapsel\@cclv
-  % hyphenation - patterns
-  \bbl at patterns{#1}%
-  % hyphenation - mins
-  \babel at savevariable\lefthyphenmin
-  \babel at savevariable\righthyphenmin
-  \expandafter\ifx\csname #1hyphenmins\endcsname\relax
-    \set at hyphenmins\tw@\thr@@\relax
-  \else
-    \expandafter\expandafter\expandafter\set at hyphenmins
-      \csname #1hyphenmins\endcsname\relax
-  \fi}
-%    \end{macrocode}
-%
-%  \begin{environment}{otherlanguage}
-%    The \Lenv{otherlanguage} environment can be used as an
-%    alternative to using the |\selectlanguage| declarative
-%    command. When you are typesetting a document which mixes
-%    left-to-right and right-to-left typesetting you have to use this
-%    environment in order to let things work as you expect them to.
-%
-%    The |\ignorespaces| command is necessary to hide the environment
-%    when it is entered in horizontal mode.
-%
-%    \begin{macrocode}
-\long\def\otherlanguage#1{%
-  \ifnum\bbl at hymapsel=\@cclv\let\bbl at hymapsel\thr@@\fi
-  \csname selectlanguage \endcsname{#1}%
-  \ignorespaces}
-%    \end{macrocode}
-%
-%    The |\endotherlanguage| part of the environment tries to hide
-%    itself when it is called in horizontal mode.
-%
-%    \begin{macrocode}
-\long\def\endotherlanguage{%
-  \global\@ignoretrue\ignorespaces}
-%    \end{macrocode}
-%
-%  \end{environment}
-%
-%  \begin{environment}{otherlanguage*}
-%    The \Lenv{otherlanguage} environment is meant to be used when a
-%    large part of text from a different language needs to be typeset,
-%    but without changing the translation of words such as `figure'.
-%    This environment makes use of |\foreign at language|.
-%
-%    \begin{macrocode}
-\expandafter\def\csname otherlanguage*\endcsname#1{%
-  \ifnum\bbl at hymapsel=\@cclv\chardef\bbl at hymapsel4\relax\fi
-  \foreign at language{#1}}
-%    \end{macrocode}
-%
-%    At the end of the environment we need to switch off the extra
-%    definitions. The grouping mechanism of the environment will take
-%    care of resetting the correct hyphenation rules and ``extras''.
-%
-%    \begin{macrocode}
-\expandafter\let\csname endotherlanguage*\endcsname\relax
-%    \end{macrocode}
-%
-%  \end{environment}
-%
-%  \begin{macro}{\foreignlanguage}
-%    The |\foreignlanguage| command is another substitute for the
-%    |\selectlanguage| command. This command takes two arguments, the
-%    first argument is the name of the language to use for typesetting
-%    the text specified in the second argument.
-%
-%    Unlike |\selectlanguage| this command doesn't switch
-%    \emph{everything}, it only switches the hyphenation rules and the
-%    extra definitions for the language specified. It does this within
-%    a group and assumes the |\extras|\langvar\ command doesn't make
-%    any |\global| changes. The coding is very similar to part of
-%    |\selectlanguage|.
-%
-%    |\bbl at beforeforeign| is a trick to fix a bug in bidi
-%    texts. |\foreignlanguage| is supposed to be a `text' command, and
-%    therefore it must emit a |\leavevmode|, but it does not, and
-%    therefore the indent is placed on the opposite margin. For
-%    backward compatibility, however, it is done only if a
-%    right-to-left script is requested; otherwise, it is no-op.
-%
-%    (3.11) |\foreignlanguage*| is a temporary, experimental macro for
-%    a few lines with a different script direction, while preserving
-%    the paragraph format (thank the braces around |\par|, things like
-%    |\hangindent| are not reset). Do not use it in production,
-%    because its semantics and its syntax may change (and very likely
-%    will, or even it could be removed altogether). Currently it
-%    enters in vmode and then selects the language (which in turn sets the
-%    paragraph direction).
-%
-%    (3.11) Also experimental are the hook |foreign| and
-%    |foreign*|. With them you can redefine |\BabelText| which by
-%    default does nothing. Its
-%    behavior is not well defined yet. So, use it in
-%    horizontal mode only if you do not want surprises.
-%
-%    In other words, at the beginning of a paragraph |\foreignlanguage|
-%    enters into hmode with the surrounding lang, and with
-%    |\foreignlanguage*| with the new lang.
-%
-%    \begin{macrocode}
-\providecommand\bbl at beforeforeign{}
-\edef\foreignlanguage{%
-  \noexpand\protect
-  \expandafter\noexpand\csname foreignlanguage \endcsname}
-\expandafter\def\csname foreignlanguage \endcsname{%
-  \@ifstar\bbl at foreign@s\bbl at foreign@x}
-\def\bbl at foreign@x#1#2{%
-  \begingroup
-    \let\BabelText\@firstofone
-    \bbl at beforeforeign
-    \foreign at language{#1}%
-    \bbl at usehooks{foreign}{}%
-    \BabelText{#2}% Now in horizontal mode!
-  \endgroup}
-\def\bbl at foreign@s#1#2{% TODO - \shapemode, \@setpar, ?\@@par
-  \begingroup
-    {\par}%
-    \let\BabelText\@firstofone
-    \foreign at language{#1}%
-    \bbl at usehooks{foreign*}{}%
-    \bbl at dirparastext
-    \BabelText{#2}% Still in vertical mode!
-    {\par}%
-  \endgroup}
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-%  \begin{macro}{\foreign at language}
-%    This macro does the
-%    work for |\foreignlanguage| and the \Lenv{otherlanguage*}
-%    environment. First we need to store the name of the language and
-%    check that it is a known language. Then it just calls
-%    |bbl at switch|.
-%
-%    \begin{macrocode}
-\def\foreign at language#1{%
-  % set name
-  \edef\languagename{#1}%
-  \bbl at fixname\languagename
-  \expandafter\ifx\csname date\languagename\endcsname\relax
-    \IfFileExists{babel-\languagename.tex}%
-      {\babelprovide{\languagename}}%
-      {}%
-  \fi
-  \bbl at iflanguage\languagename{%
-    \expandafter\ifx\csname date\languagename\endcsname\relax
-      \bbl at warning   % TODO - why a warning, not an error?
-        {Unknown language `#1'. Either you have\\%
-         misspelled its name, it has not been installed,\\%
-         or you requested it in a previous run. Fix its name,\\%
-         install it or just rerun the file, respectively. In\\%
-         some cases, you may need to remove the aux file.\\%
-         I'll proceed, but expect wrong results.\\%
-         Reported}%
-    \fi
-    % set type
-    \let\bbl at select@type\@ne
-    \expandafter\bbl at switch\expandafter{\languagename}}}
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-%  \begin{macro}{\bbl at patterns}
-%
-%    This macro selects the hyphenation patterns by changing the
-%    \cs{language} register.  If special hyphenation patterns
-%    are available specifically for the current font encoding,
-%    use them instead of the default.
-%
-%    It also sets hyphenation exceptions, but only once, because they
-%    are global (here language |\lccode|'s has been set,
-%    too). |\bbl at hyphenation@| is set to relax until the very first
-%    |\babelhyphenation|, so do nothing with this value. If the
-%    exceptions for a language (by its number, not its name, so that
-%    |:ENC| is taken into account) has been set, then use
-%    |\hyphenation| with both global and language exceptions and empty
-%    the latter to mark they must not be set again.
-%
-%    \begin{macrocode}
-\let\bbl at hyphlist\@empty
-\let\bbl at hyphenation@\relax
-\let\bbl at pttnlist\@empty
-\let\bbl at patterns@\relax
-\let\bbl at hymapsel=\@cclv
-\def\bbl at patterns#1{%
-  \language=\expandafter\ifx\csname l@#1:\f at encoding\endcsname\relax
-      \csname l@#1\endcsname
-      \edef\bbl at tempa{#1}%
-    \else
-      \csname l@#1:\f at encoding\endcsname
-      \edef\bbl at tempa{#1:\f at encoding}%
-    \fi
-  \@expandtwoargs\bbl at usehooks{patterns}{{#1}{\bbl at tempa}}%
-  %  > luatex
-  \@ifundefined{bbl at hyphenation@}{}{% Can be \relax!
-    \begingroup
-      \bbl at xin@{,\number\language,}{,\bbl at hyphlist}%
-      \ifin@\else
-        \@expandtwoargs\bbl at usehooks{hyphenation}{{#1}{\bbl at tempa}}%
-        \hyphenation{%
-          \bbl at hyphenation@
-          \@ifundefined{bbl at hyphenation@#1}%
-            \@empty
-            {\space\csname bbl at hyphenation@#1\endcsname}}%
-        \xdef\bbl at hyphlist{\bbl at hyphlist\number\language,}%
-      \fi
-    \endgroup}}
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-%  \begin{environment}{hyphenrules}
-%    The environment \Lenv{hyphenrules} can be used to select
-%    \emph{just} the hyphenation rules. This environment does
-%    \emph{not} change |\languagename| and when the hyphenation rules
-%    specified were not loaded it has no effect. Note however,
-%    |\lccode|'s and font encodings are not set at all, so in most
-%    cases you should use |otherlanguage*|.
-%
-%    \begin{macrocode}
-\def\hyphenrules#1{%
-  \edef\bbl at tempf{#1}%
-  \bbl at fixname\bbl at tempf
-  \bbl at iflanguage\bbl at tempf{%
-    \expandafter\bbl at patterns\expandafter{\bbl at tempf}%
-    \languageshorthands{none}%
-    \expandafter\ifx\csname\bbl at tempf hyphenmins\endcsname\relax
-      \set at hyphenmins\tw@\thr@@\relax
-    \else
-      \expandafter\expandafter\expandafter\set at hyphenmins
-      \csname\bbl at tempf hyphenmins\endcsname\relax
-    \fi}}
-\let\endhyphenrules\@empty
-%    \end{macrocode}
-%
-%  \end{environment}
-%
-%  \begin{macro}{\providehyphenmins}
-%    The macro |\providehyphenmins| should be used in the language
-%    definition files to provide a \emph{default} setting for the
-%    hyphenation parameters |\lefthyphenmin| and |\righthyphenmin|. If
-%    the macro |\|\langvar|hyphenmins| is already defined this command
-%    has no effect.
-%
-%    \begin{macrocode}
-\def\providehyphenmins#1#2{%
-  \expandafter\ifx\csname #1hyphenmins\endcsname\relax
-    \@namedef{#1hyphenmins}{#2}%
-  \fi}
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-%  \begin{macro}{\set at hyphenmins}
-%    This macro sets the values of |\lefthyphenmin| and
-%    |\righthyphenmin|. It expects two values as its argument.
-%
-%    \begin{macrocode}
-\def\set at hyphenmins#1#2{%
-  \lefthyphenmin#1\relax
-  \righthyphenmin#2\relax}
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-%  \begin{macro}{\ProvidesLanguage}
-%    The identification code for each file is something that was
-%    introduced in \LaTeXe. When the command |\ProvidesFile| does not
-%    exist, a dummy definition is provided temporarily. For use in the
-%    language definition file the command |\ProvidesLanguage| is
-%    defined by \babel.
-%
-%    Depending on the format, ie, on if the former is defined, we use
-%    a similar definition or not.
-%
-%    \begin{macrocode}
-\ifx\ProvidesFile\@undefined
-  \def\ProvidesLanguage#1[#2 #3 #4]{%
-    \wlog{Language: #1 #4 #3 <#2>}%
-    }
-\else
-  \def\ProvidesLanguage#1{%
-    \begingroup
-      \catcode`\ 10 %
-      \@makeother\/%
-      \@ifnextchar[%]
-        {\@provideslanguage{#1}}{\@provideslanguage{#1}[]}}
-  \def\@provideslanguage#1[#2]{%
-    \wlog{Language: #1 #2}%
-    \expandafter\xdef\csname ver@#1.ldf\endcsname{#2}%
-    \endgroup}
-\fi
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-%  \begin{macro}{\LdfInit}
-%    This macro is defined in two versions. The first version is to be
-%    part of the `kernel' of \babel, ie. the part that is loaded in
-%    the format; the second version is defined in \file{babel.def}.
-%    The version in the format just checks the category code of the
-%    ampersand and then loads \file{babel.def}.
-%
-%    The category code of the ampersand is restored and the macro
-%    calls itself again with the new definition from
-%    \file{babel.def}
-%
-%    \begin{macrocode}
-\def\LdfInit{%
-  \chardef\atcatcode=\catcode`\@
-  \catcode`\@=11\relax
-  \input babel.def\relax
-  \catcode`\@=\atcatcode \let\atcatcode\relax
-  \LdfInit}
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-%  \begin{macro}{\originalTeX}
-%    The macro|\originalTeX| should be known to \TeX\ at this moment.
-%    As it has to be expandable we |\let| it to |\@empty| instead of
-%    |\relax|.
-%
-%    \begin{macrocode}
-\ifx\originalTeX\@undefined\let\originalTeX\@empty\fi
-%    \end{macrocode}
-%
-%    Because this part of the code can be included in a format, we
-%    make sure that the macro which initialises the save mechanism,
-%    |\babel at beginsave|, is not considered to be undefined.
-%
-%    \begin{macrocode}
-\ifx\babel at beginsave\@undefined\let\babel at beginsave\relax\fi
-%    \end{macrocode}
-%
-%  \end{macro}
-%
-% A few macro names are reserved for future releases of \babel, which
-% will use the concept of `locale':
-%
-%    \begin{macrocode}
-\providecommand\setlocale{%
-  \bbl at error
-    {Not yet available}%
-    {Find an armchair, sit down and wait}}
-\let\uselocale\setlocale
-\let\locale\setlocale
-\let\selectlocale\setlocale
-\let\localename\setlocale
-\let\textlocale\setlocale
-\let\textlanguage\setlocale
-\let\languagetext\setlocale
-%    \end{macrocode}
-%
-% \subsection{Errors}
-%
-%  \begin{macro}{\@nolanerr}
-%  \begin{macro}{\@nopatterns}
-%    The \babel\ package will signal an error when a documents tries
-%    to select a language that hasn't been defined earlier. When a
-%    user selects a language for which no hyphenation patterns were
-%    loaded into the format he will be given a warning about that
-%    fact. We revert to the patterns for |\language|=0 in that case.
-%    In most formats that will be (US)english, but it might also be
-%    empty.
-%  \begin{macro}{\@noopterr}
-%    When the package was loaded without options not everything will
-%    work as expected. An error message is issued in that case.
-%
-%    When the format knows about |\PackageError| it must be \LaTeXe,
-%    so we can safely use its error handling interface. Otherwise
-%    we'll have to `keep it simple'.
-%
-%    Infos are not written to the console, but on the other hand many
-%    people think warnings are errors, so a further message type is
-%    defined: an important info which is sent to the console.
-%
-%    \begin{macrocode}
-\edef\bbl at nulllanguage{\string\language=0}
-\ifx\PackageError\@undefined
-  \def\bbl at error#1#2{%
-    \begingroup
-      \newlinechar=`\^^J
-      \def\\{^^J(babel) }%
-      \errhelp{#2}\errmessage{\\#1}%
-    \endgroup}
-  \def\bbl at warning#1{%
-    \begingroup
-      \newlinechar=`\^^J
-      \def\\{^^J(babel) }%
-      \message{\\#1}%
-    \endgroup}
-  \let\bbl at infowarn\bbl at warning
-  \def\bbl at info#1{%
-    \begingroup
-      \newlinechar=`\^^J
-      \def\\{^^J}%
-      \wlog{#1}%
-    \endgroup}
-\else
-  \def\bbl at error#1#2{%
-    \begingroup
-      \def\\{\MessageBreak}%
-      \PackageError{babel}{#1}{#2}%
-    \endgroup}
-  \def\bbl at warning#1{%
-    \begingroup
-      \def\\{\MessageBreak}%
-      \PackageWarning{babel}{#1}%
-    \endgroup}
-  \def\bbl at infowarn#1{%
-    \begingroup
-      \def\\{\MessageBreak}%
-      \GenericWarning
-        {(babel) \@spaces\@spaces\@spaces}%
-        {Package babel Info: #1}%
-    \endgroup}
-  \def\bbl at info#1{%
-    \begingroup
-      \def\\{\MessageBreak}%
-      \PackageInfo{babel}{#1}%
-    \endgroup}
-\fi
-\@ifpackagewith{babel}{silent}
-  {\let\bbl at info\@gobble
-   \let\bbl at infowarn\@gobble
-   \let\bbl at warning\@gobble}
-  {}
-\def\bbl at nocaption{\protect\bbl at nocaption@i}
-\def\bbl at nocaption@i#1#2{% 1: text to be printed 2: caption macro \langXname
-  \global\@namedef{#2}{\textbf{?#1?}}%
-  \@nameuse{#2}%
-  \bbl at warning{%
-    \@backslashchar#2 not set. Please, define\\%
-    it in the preamble with something like:\\%
-    \string\renewcommand\@backslashchar#2{..}\\%
-    Reported}}
-\def\bbl at tentative{\protect\bbl at tentative@i}
-\def\bbl at tentative@i#1{%
-  \bbl at warning{%
-    Some functions for '#1' are tentative.\\%
-    They might not work as expected and their behavior\\%
-    could change in the future.\\%
-    Reported}}
-\def\@nolanerr#1{%
-  \bbl at error
-    {You haven't defined the language #1\space yet.\\%
-     Perhaps you misspelled it or your installation\\%
-     is not complete}%
-    {Your command will be ignored, type <return> to proceed}}
-\def\@nopatterns#1{%
-  \bbl at warning
-    {No hyphenation patterns were preloaded for\\%
-     the language `#1' into the format.\\%
-     Please, configure your TeX system to add them and\\%
-     rebuild the format. Now I will use the patterns\\%
-     preloaded for \bbl at nulllanguage\space instead}}
-\let\bbl at usehooks\@gobbletwo
+\let\bbl at onlyswitch\@empty
+\input babel.def
+\let\bbl at onlyswitch\@undefined
 %</kernel>
 %<*patterns>
 %    \end{macrocode}
@@ -10983,60 +11074,31 @@
 %
 % \section{Loading hyphenation patterns}
 %
-%  The following code is meant to be read by ini\TeX\ because it
-%  should instruct \TeX\ to read hyphenation patterns. To this end the
-%  \texttt{docstrip} option \texttt{patterns} can be used to include
-%  this code in the file \file{hyphen.cfg}. Code is written with lower
-%  level macros.
+% The following code is meant to be read by ini\TeX\ because it
+% should instruct \TeX\ to read hyphenation patterns. To this end the
+% \texttt{docstrip} option \texttt{patterns} can be used to include
+% this code in the file \file{hyphen.cfg}. Code is written with lower
+% level macros.
 %
-%    We want to add a message to the message \LaTeX$\:$2.09 puts in
-%    the |\everyjob| register. This could be done by the following
-%    code:
-%\begin{verbatim}
-%    \let\orgeveryjob\everyjob
-%    \def\everyjob#1{%
-%      \orgeveryjob{#1}%
-%      \orgeveryjob\expandafter{\the\orgeveryjob\immediate\write16{%
-%          hyphenation patterns for \the\loaded at patterns loaded.}}%
-%      \let\everyjob\orgeveryjob\let\orgeveryjob\@undefined}
-%\end{verbatim}
-%    The code above redefines the control sequence \cs{everyjob}
-%    in order to be able to add something to the current contents of
-%    the register. This is necessary because the processing of
-%    hyphenation patterns happens long before \LaTeX\ fills the
-%    register.
+% To make sure that \LaTeX$\:$2.09 executes the |\@begindocumenthook|
+% we would want to alter |\begin{document}|, but as this done too often
+% already, we add the new code at the front of |\@preamblecmds|. But we
+% can only do that after it has been defined, so we add this piece of
+% code to |\dump|.
 %
-%    There are some problems with this approach though.
-%  \begin{itemize}
-%    \item When someone wants to use several hyphenation patterns with
-%    \SliTeX\ the above scheme won't work. The reason is that \SliTeX\
-%    overwrites the contents of the |\everyjob| register with its own
-%    message.
-%    \item Plain \TeX\ does not use the |\everyjob| register so the
-%    message would not be displayed.
-%  \end{itemize}
-%    To circumvent this a `dirty trick' can be used. As this code is
-%    only processed when creating a new format file there is one
-%    command that is sure to be used, |\dump|. Therefore the original
-%    |\dump| is saved in |\org at dump| and a new definition is supplied.
+% This new definition starts by adding an instruction to write a
+% message on the terminal and in the transcript file to inform the
+% user of the preloaded hyphenation patterns.
 %
-%    To make sure that \LaTeX$\:$2.09 executes the
-%    |\@begindocumenthook| we would want to alter |\begin{document}|,
-%    but as this done too often already, we add the new code at the
-%    front of |\@preamblecmds|. But we can only do that after it has
-%    been defined, so we add this piece of code to |\dump|.
+% Then everything is restored to the old situation and the format
+% is dumped.
 %
-%    This new definition starts by adding an instruction to write a
-%    message on the terminal and in the transcript file to inform the
-%    user of the preloaded hyphenation patterns.
-%
-%    Then everything is restored to the old situation and the format
-%    is dumped.
-%
 %    \begin{macrocode}
 <@Make sure ProvidesFile is defined@>
 \ProvidesFile{hyphen.cfg}[<@date@> <@version@> Babel hyphens]
 \xdef\bbl at format{\jobname}
+\def\bbl at version{<@version@>}
+\def\bbl at date{<@date@>}
 \ifx\AtBeginDocument\@undefined
   \def\@empty{}
   \let\orig at dump\dump
@@ -11074,9 +11136,9 @@
 %
 %  \begin{macro}{\process at synonym}
 %
-%    This macro takes care of the lines which start with an
-%    \texttt{=}. It needs an empty token register to begin with.
-%    |\bbl at languages| is also set to empty.
+% This macro takes care of the lines which start with an
+% \texttt{=}. It needs an empty token register to begin with.
+% |\bbl at languages| is also set to empty.
 %
 %    \begin{macrocode}
 \toks@{}
@@ -11109,56 +11171,57 @@
 %
 %  \end{macro}
 %
-%  \begin{macro}{\process at language}
-%    The macro |\process at language| is used to process a non-empty line
-%    from the `configuration file'. It has three arguments, each
-%    delimited by white space. The first argument is the `name' of a
-%    language; the second is the name of the file that contains the
-%    patterns. The optional third argument is the name of a file
-%    containing hyphenation exceptions.
+% \begin{macro}{\process at language}
 %
-%    The first thing to do is call |\addlanguage| to allocate a pattern
-%    register and to make that register `active'. Then the pattern file
-%    is read.
+% The macro |\process at language| is used to process a non-empty line
+% from the `configuration file'. It has three arguments, each
+% delimited by white space. The first argument is the `name' of a
+% language; the second is the name of the file that contains the
+% patterns. The optional third argument is the name of a file
+% containing hyphenation exceptions.
 %
-%    For some hyphenation patterns it is needed to load them with a
-%    specific font encoding selected. This can be specified in the
-%    file \file{language.dat} by adding for instance `\texttt{:T1}' to
-%    the name of the language. The macro |\bbl at get@enc| extracts the
-%    font encoding from the language name and stores it in
-%    |\bbl at hyph@enc|. The latter can be used in hyphenation files if
-%    you need to set a behavior depending on the given encoding (it
-%    is set to empty if no encoding is given).
+% The first thing to do is call |\addlanguage| to allocate a pattern
+% register and to make that register `active'. Then the pattern file
+% is read.
 %
-%    Pattern files may contain assignments to |\lefthyphenmin| and
-%    |\righthyphenmin|. \TeX\ does not keep track of these
-%    assignments. Therefore we try to detect such assignments and
-%    store them in the |\|\langvar|hyphenmins| macro. When no
-%    assignments were made we provide a default setting.
+% For some hyphenation patterns it is needed to load them with a
+% specific font encoding selected. This can be specified in the
+% file \file{language.dat} by adding for instance `\texttt{:T1}' to
+% the name of the language. The macro |\bbl at get@enc| extracts the
+% font encoding from the language name and stores it in
+% |\bbl at hyph@enc|. The latter can be used in hyphenation files if
+% you need to set a behavior depending on the given encoding (it
+% is set to empty if no encoding is given).
 %
-%    Some pattern files contain changes to the |\lccode| en |\uccode|
-%    arrays. Such changes should remain local to the language;
-%    therefore we process the pattern file in a group; the |\patterns|
-%    command acts globally so its effect will be remembered.
+% Pattern files may contain assignments to |\lefthyphenmin| and
+% |\righthyphenmin|. \TeX\ does not keep track of these
+% assignments. Therefore we try to detect such assignments and
+% store them in the |\|\langvar|hyphenmins| macro. When no
+% assignments were made we provide a default setting.
 %
-%    Then we globally store the settings of |\lefthyphenmin| and
-%    |\righthyphenmin| and close the group.
+% Some pattern files contain changes to the |\lccode| en |\uccode|
+% arrays. Such changes should remain local to the language;
+% therefore we process the pattern file in a group; the |\patterns|
+% command acts globally so its effect will be remembered.
 %
-%    When the hyphenation patterns have been processed we need to see
-%    if a file with hyphenation exceptions needs to be read. This is
-%    the case when the third argument is not empty and when it does
-%    not contain a space token. (Note however there is no need to save
-%    hyphenation exceptions into the format.)
+% Then we globally store the settings of |\lefthyphenmin| and
+% |\righthyphenmin| and close the group.
 %
-%    \cs{bbl at languages} saves a snapshot of the loaded languages in the
-%    form  \cs{bbl at elt}\marg{language-name}\marg{number}%
-%    \marg{patterns-file}\marg{exceptions-file}. Note the last 2
-%    arguments are empty in `dialects' defined in |language.dat| with
-%    |=|. Note also the language name can have encoding info.
+% When the hyphenation patterns have been processed we need to see
+% if a file with hyphenation exceptions needs to be read. This is
+% the case when the third argument is not empty and when it does
+% not contain a space token. (Note however there is no need to save
+% hyphenation exceptions into the format.)
 %
-%    Finally, if the counter |\language| is equal to zero we execute the
-%    synonyms stored.
+% \cs{bbl at languages} saves a snapshot of the loaded languages in the
+% form  \cs{bbl at elt}\marg{language-name}\marg{number}%
+% \marg{patterns-file}\marg{exceptions-file}. Note the last 2
+% arguments are empty in `dialects' defined in |language.dat| with
+% |=|. Note also the language name can have encoding info.
 %
+% Finally, if the counter |\language| is equal to zero we execute the
+% synonyms stored.
+%
 %    \begin{macrocode}
 \def\process at language#1#2#3{%
   \expandafter\addlanguage\csname l@#1\endcsname
@@ -11197,30 +11260,69 @@
   \fi}
 %    \end{macrocode}
 %
-%  \begin{macro}{\bbl at get@enc}
+% \begin{macro}{\bbl at get@enc}
 %
-%  \begin{macro}{\bbl at hyph@enc}
-%    The macro |\bbl at get@enc| extracts the font encoding from the
-%    language name and stores it in |\bbl at hyph@enc|. It uses delimited
-%    arguments to achieve this.
+% \begin{macro}{\bbl at hyph@enc}
+% The macro |\bbl at get@enc| extracts the font encoding from the
+% language name and stores it in |\bbl at hyph@enc|. It uses delimited
+% arguments to achieve this.
 %
 %    \begin{macrocode}
 \def\bbl at get@enc#1:#2:#3\@@@{\def\bbl at hyph@enc{#2}}
 %    \end{macrocode}
 %
-%  \end{macro}
-%  \end{macro}
-%  \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
 %
-%    Now, hooks are defined. For efficiency reasons, they are dealt
-%    here in a special way. Besides \luatex, format-specific
-%    configuration files are taken into account.
+% Now, hooks are defined. For efficiency reasons, they are dealt
+% here in a special way. Besides \luatex, format-specific
+% configuration files are taken into account. |loadkernel| currently
+% loads nothing, but define some basic macros instead.
 %
 %    \begin{macrocode}
 \def\bbl at hook@everylanguage#1{}
 \def\bbl at hook@loadpatterns#1{\input #1\relax}
 \let\bbl at hook@loadexceptions\bbl at hook@loadpatterns
-\let\bbl at hook@loadkernel\bbl at hook@loadpatterns
+\def\bbl at hook@loadkernel#1{%
+  \def\addlanguage{\alloc at 9\language\chardef\@cclvi}%
+  \def\adddialect##1##2{%
+    \global\chardef##1##2\relax
+    \wlog{\string##1 = a dialect from \string\language##2}}%
+  \def\iflanguage##1{%
+    \expandafter\ifx\csname l@##1\endcsname\relax
+      \@nolanerr{##1}%
+    \else
+      \ifnum\csname l@##1\endcsname=\language
+        \expandafter\expandafter\expandafter\@firstoftwo
+      \else
+        \expandafter\expandafter\expandafter\@secondoftwo
+      \fi
+    \fi}%
+  \def\providehyphenmins##1##2{%
+    \expandafter\ifx\csname ##1hyphenmins\endcsname\relax
+      \@namedef{##1hyphenmins}{##2}%
+    \fi}%
+  \def\set at hyphenmins##1##2{%
+    \lefthyphenmin##1\relax
+    \righthyphenmin##2\relax}%
+  \def\selectlanguage{%
+    \errhelp{Selecting a language requires a package supporting it}%
+    \errmessage{Not loaded}}%
+  \let\foreignlanguage\selectlanguage
+  \let\otherlanguage\selectlanguage
+  \expandafter\let\csname otherlanguage*\endcsname\selectlanguage
+  \def\bbl at usehooks##1##2{}% TODO. Temporary!!
+  \def\setlocale{%
+    \errhelp{Find an armchair, sit down and wait}%
+    \errmessage{Not yet available}}%
+  \let\uselocale\setlocale
+  \let\locale\setlocale
+  \let\selectlocale\setlocale
+  \let\localename\setlocale
+  \let\textlocale\setlocale
+  \let\textlanguage\setlocale
+  \let\languagetext\setlocale}
 \begingroup
   \def\AddBabelHook#1#2{%
     \expandafter\ifx\csname bbl at hook@#2\endcsname\relax
@@ -11266,28 +11368,24 @@
 \else
 %    \end{macrocode}
 %
-%    Pattern registers are allocated using count register
-%    |\last at language|. Its initial value is~0. The definition of the
-%    macro |\newlanguage| is such that it first increments the count
-%    register and then defines the language. In order to have the
-%    first patterns loaded in pattern register number~0 we initialize
-%    |\last at language| with the value~$-1$.
+% Pattern registers are allocated using count register
+% |\last at language|. Its initial value is~0. The definition of the
+% macro |\newlanguage| is such that it first increments the count
+% register and then defines the language. In order to have the
+% first patterns loaded in pattern register number~0 we initialize
+% |\last at language| with the value~$-1$.
 %
 %    \begin{macrocode}
   \last at language\m at ne
 %    \end{macrocode}
 %
-%    We now read lines from the file until the end is found
+% We now read lines from the file until the end is found. While
+% reading from the input, it is useful to switch off recognition of
+% the end-of-line character. This saves us stripping off spaces from
+% the contents of the control sequence.
 %
 %    \begin{macrocode}
   \loop
-%    \end{macrocode}
-%
-%    While reading from the input, it is useful to switch off
-%    recognition of the end-of-line character. This saves us stripping
-%    off spaces from the contents of the control sequence.
-%
-%    \begin{macrocode}
     \endlinechar\m at ne
     \read1 to \bbl at line
     \endlinechar`\^^M
@@ -11308,8 +11406,9 @@
   \repeat
 %    \end{macrocode}
 %
-%    Check for the end of the file. We must reverse the test for
-%    |\ifeof| without |\else|. Then reactivate the default patterns.
+% Check for the end of the file. We must reverse the test for
+% |\ifeof| without |\else|. Then reactivate the default patterns,
+% and close the configuration file.
 %
 %    \begin{macrocode}
   \begingroup
@@ -11320,17 +11419,12 @@
     \bbl at languages
   \endgroup
 \fi
-%    \end{macrocode}
-%
-%    and close the configuration file.
-%
-%    \begin{macrocode}
 \closein1
 %    \end{macrocode}
 %
-%    We add a message about the fact that babel is loaded in the
-%    format and with which language patterns to the \cs{everyjob}
-%    register.
+% We add a message about the fact that babel is loaded in the
+% format and with which language patterns to the \cs{everyjob}
+% register.
 %
 %    \begin{macrocode}
 \if/\the\toks@/\else
@@ -11683,49 +11777,7 @@
 %    therefore it is reset always to |utf8|, which seems a sensible
 %    default.
 %
-%    \LaTeX{} sets many ``codes'' just before loading
-%    \verb|hyphen.cfg|. That is not a problem in luatex, but in xetex
-%    they must be reset to the proper value. Most of the work is done in
-%    \textsf{xe(la)tex.ini}, so here we just ``undo'' some of the
-%    changes done by \LaTeX. Anyway, for consistency Lua\TeX{} also
-%    resets the catcodes.
-%
 %    \begin{macrocode}
-%<<*Restore Unicode catcodes before loading patterns>>
-  \begingroup
-      % Reset chars "80-"C0 to category "other", no case mapping:
-    \catcode`\@=11 \count@=128
-    \loop\ifnum\count@<192
-      \global\uccode\count@=0 \global\lccode\count@=0
-      \global\catcode\count@=12 \global\sfcode\count@=1000
-      \advance\count@ by 1 \repeat
-      % Other:
-    \def\O ##1 {%
-      \global\uccode"##1=0 \global\lccode"##1=0
-      \global\catcode"##1=12 \global\sfcode"##1=1000 }%
-      % Letter:
-    \def\L ##1 ##2 ##3 {\global\catcode"##1=11
-      \global\uccode"##1="##2
-      \global\lccode"##1="##3
-      % Uppercase letters have sfcode=999:
-      \ifnum"##1="##3 \else \global\sfcode"##1=999 \fi }%
-      % Letter without case mappings:
-    \def\l ##1 {\L ##1 ##1 ##1 }%
-    \l 00AA
-    \L 00B5 039C 00B5
-    \l 00BA
-    \O 00D7
-    \l 00DF
-    \O 00F7
-    \L 00FF 0178 00FF
-  \endgroup
-  \input #1\relax
-%<</Restore Unicode catcodes before loading patterns>>
-%    \end{macrocode}
-%
-% Some more common code.
-%
-%    \begin{macrocode}
 %<<*Footnote changes>>
 \bbl at trace{Bidi footnotes}
 \ifx\bbl at beforeforeign\leavevmode
@@ -11838,8 +11890,6 @@
           \expandafter\bbl at toglobal\csname selectfont \endcsname}%
       \fi}%
   \fi}
-\AddBabelHook{xetex}{loadkernel}{%
-<@Restore Unicode catcodes before loading patterns@>}
 \ifx\DisableBabelHook\@undefined\endinput\fi
 \AddBabelHook{babel-fontspec}{afterextras}{\bbl at switchfont}
 \AddBabelHook{babel-fontspec}{beforestart}{\bbl at ckeckstdfonts}
@@ -11953,7 +12003,7 @@
 %
 % \subsection{LuaTeX}
 %
-% The new loader for luatex is based solely on |language.dat|, which
+% The loader for \luatex{} is based solely on |language.dat|, which
 % is read on the fly. The code shouldn't be executed when the format
 % is build, so we check if |\AddBabelHook| is defined. Then comes a
 % modified version of the loader in |hyphen.cfg| (without the
@@ -11995,14 +12045,21 @@
 %
 % We need catcode tables, but no format (targeted by \babel) provide a
 % command to allocate them (although there are packages like
-% \textsf{ctablestack}). For the moment, a dangerous approach is used
-% -- just allocate a high random number and cross the fingers. To
-% complicate things, \textsf{etex.sty} changes the way languages are
-% allocated.
+% \textsf{ctablestack}). FIX - This isn't true anymore. For the moment,
+% a dangerous approach is used - just allocate a high random number and
+% cross the fingers. To complicate things, \textsf{etex.sty} changes
+% the way languages are allocated.
 %
+% This files is read at three places: (1) when |plain.def|, |babel.sty|
+% starts, to read the list of available languages from |language.dat|
+% (for the |base| option); (2) at hyphen.cfg, to modify some macros;
+% (3) in the middle of |plain.def| and |babel.sty|, by |babel.def|,
+% with the commands and other definitions for |luatex| (eg,
+% |\babelpatterns|).
+%  
 %    \begin{macrocode}
 %<*luatex>
-\ifx\AddBabelHook\@undefined
+\ifx\AddBabelHook\@undefined % When plain.def, babel.sty starts
 \bbl at trace{Read language.dat}
 \ifx\bbl at readstream\@undefined
   \csname newread\endcsname\bbl at readstream
@@ -12089,29 +12146,31 @@
 \endgroup
 \bbl at trace{Macros for reading patterns files}
 \def\bbl at get@enc#1:#2:#3\@@@{\def\bbl at hyph@enc{#2}}
-% TODO - Harcoded value:
 \ifx\babelcatcodetablenum\@undefined
-  \def\babelcatcodetablenum{5211}
+  \ifx\newcatcodetable\@undefined
+    \def\babelcatcodetablenum{5211}
+    \def\bbl at pattcodes{\numexpr\babelcatcodetablenum+1\relax}
+  \else
+    \newcatcodetable\babelcatcodetablenum
+    \newcatcodetable\bbl at pattcodes
+  \fi
+\else
+  \def\bbl at pattcodes{\numexpr\babelcatcodetablenum+1\relax}
 \fi
 \def\bbl at luapatterns#1#2{%
   \bbl at get@enc#1::\@@@
   \setbox\z@\hbox\bgroup
     \begingroup
-      \ifx\catcodetable\@undefined
-        \let\savecatcodetable\luatexsavecatcodetable
-        \let\initcatcodetable\luatexinitcatcodetable
-        \let\catcodetable\luatexcatcodetable
-      \fi
       \savecatcodetable\babelcatcodetablenum\relax
-      \initcatcodetable\numexpr\babelcatcodetablenum+1\relax
-      \catcodetable\numexpr\babelcatcodetablenum+1\relax
-      \catcode`\#=6  \catcode`\$=3 \catcode`\&=4 \catcode`\^=7
-      \catcode`\_=8  \catcode`\{=1 \catcode`\}=2 \catcode`\~=13
-      \catcode`\@=11 \catcode`\^^I=10 \catcode`\^^J=12
-      \catcode`\<=12 \catcode`\>=12 \catcode`\*=12 \catcode`\.=12
-      \catcode`\-=12 \catcode`\/=12 \catcode`\[=12 \catcode`\]=12
-      \catcode`\`=12 \catcode`\'=12 \catcode`\"=12
-      \input #1\relax
+      \initcatcodetable\bbl at pattcodes\relax
+      \catcodetable\bbl at pattcodes\relax
+        \catcode`\#=6  \catcode`\$=3 \catcode`\&=4 \catcode`\^=7
+        \catcode`\_=8  \catcode`\{=1 \catcode`\}=2 \catcode`\~=13
+        \catcode`\@=11 \catcode`\^^I=10 \catcode`\^^J=12
+        \catcode`\<=12 \catcode`\>=12 \catcode`\*=12 \catcode`\.=12
+        \catcode`\-=12 \catcode`\/=12 \catcode`\[=12 \catcode`\]=12
+        \catcode`\`=12 \catcode`\'=12 \catcode`\"=12
+        \input #1\relax
       \catcodetable\babelcatcodetablenum\relax
     \endgroup
     \def\bbl at tempa{#2}%
@@ -12144,6 +12203,25 @@
        {\expandafter\expandafter\expandafter\bbl at luapatterns
           \csname bbl at hyphendata@\the\language\endcsname}}{}}
 \endinput\fi
+  % Here ends \ifx\AddBabelHook\@undefined
+  % A few lines are only read by hyphen.cfg
+\ifx\DisableBabelHook\@undefined
+  \AddBabelHook{luatex}{everylanguage}{%
+    \def\process at language##1##2##3{%
+      \def\process at line####1####2 ####3 ####4 {}}}
+  \AddBabelHook{luatex}{loadpatterns}{%
+     \input #1\relax
+     \expandafter\gdef\csname bbl at hyphendata@\the\language\endcsname
+       {{#1}{}}}
+  \AddBabelHook{luatex}{loadexceptions}{%
+     \input #1\relax
+     \def\bbl at tempb##1##2{{##1}{#1}}%
+     \expandafter\xdef\csname bbl at hyphendata@\the\language\endcsname
+       {\expandafter\expandafter\expandafter\bbl at tempb
+        \csname bbl at hyphendata@\the\language\endcsname}}
+\endinput\fi
+  % Here stops reading code for hyphen.cfg
+  % The following is read the 2nd time it's loaded
 \begingroup
 \catcode`\%=12
 \catcode`\'=12
@@ -12251,19 +12329,6 @@
     \bbl at ifunset{bbl at prehc@\languagename}{}%
       {\\\bbl at ifblank{\bbl at cs{prehc@\languagename}}{}%
         {\prehyphenchar=\bbl at cl{prehc}\relax}}}}
-\AddBabelHook{luatex}{everylanguage}{%
-  \def\process at language##1##2##3{%
-    \def\process at line####1####2 ####3 ####4 {}}}
-\AddBabelHook{luatex}{loadpatterns}{%
-   \input #1\relax
-   \expandafter\gdef\csname bbl at hyphendata@\the\language\endcsname
-     {{#1}{}}}
-\AddBabelHook{luatex}{loadexceptions}{%
-   \input #1\relax
-   \def\bbl at tempb##1##2{{##1}{#1}}%
-   \expandafter\xdef\csname bbl at hyphendata@\the\language\endcsname
-     {\expandafter\expandafter\expandafter\bbl at tempb
-      \csname bbl at hyphendata@\the\language\endcsname}}
 %    \end{macrocode}
 %
 %  \begin{macro}{\babelpatterns}
@@ -12540,9 +12605,6 @@
 % Common stuff.
 %
 %    \begin{macrocode}
-\AddBabelHook{luatex}{loadkernel}{%
-<@Restore Unicode catcodes before loading patterns@>}
-\ifx\DisableBabelHook\@undefined\endinput\fi
 \AddBabelHook{babel-fontspec}{afterextras}{\bbl at switchfont}
 \AddBabelHook{babel-fontspec}{beforestart}{\bbl at ckeckstdfonts}
 \DisableBabelHook{babel-fontspec}
@@ -12737,7 +12799,7 @@
 % trying other patterns, and this is very likely the main bottleneck).
 %
 % |post_hyphenate_replace| is the callback applied after
-% |tex.hyphenate|. This means the automatic hyphenation points are
+% |lang.hyphenate|. This means the automatic hyphenation points are
 % known. As empty captures return a byte position (as explained in the
 % \luatex{} manual), we must convert it to a utf8 position. With
 % |first|, the last byte can be the leading byte in a utf8 sequence, so
@@ -20306,33 +20368,34 @@
 % \section{Support for Plain \TeX\ (\texttt{plain.def})}
 %
 % \subsection{Not renaming \file{hyphen.tex}}
-%    As Don Knuth has declared that the filename \file{hyphen.tex} may
-%    only be used to designate \emph{his} version of the american
-%    English hyphenation patterns, a new solution has to be found in
-%    order to be able to load hyphenation patterns for other languages
-%    in a plain-based \TeX-format.
-%    When asked he responded:
-%    \begin{quote}
-%      That file name is ``sacred'', and if anybody changes it they will
-%      cause severe upward/downward compatibility headaches.
 %
-%      People can have a file localhyphen.tex or whatever they like,
-%      but they mustn't diddle with hyphen.tex (or plain.tex except to
-%      preload additional fonts).
-%    \end{quote}
+% As Don Knuth has declared that the filename \file{hyphen.tex} may
+% only be used to designate \emph{his} version of the american
+% English hyphenation patterns, a new solution has to be found in
+% order to be able to load hyphenation patterns for other languages
+% in a plain-based \TeX-format.
+% When asked he responded:
+% \begin{quote}
+%   That file name is ``sacred'', and if anybody changes it they will
+%   cause severe upward/downward compatibility headaches.
 %
-%    The files \file{bplain.tex} and \file{blplain.tex} can be used as
-%    replacement wrappers around \file{plain.tex} and
-%    \file{lplain.tex} to acheive the desired effect, based on the
-%    \pkg{babel} package. If you load each of them with ini\TeX, you
-%    will get a file called either \file{bplain.fmt} or
-%    \file{blplain.fmt}, which you can use as replacements for
-%    \file{plain.fmt} and \file{lplain.fmt}.
+%   People can have a file localhyphen.tex or whatever they like,
+%   but they mustn't diddle with hyphen.tex (or plain.tex except to
+%   preload additional fonts).
+% \end{quote}
 %
-%    As these files are going to be read as the first thing ini\TeX\
-%    sees, we need to set some category codes just to be able to
-%    change the definition of |\input|
+% The files \file{bplain.tex} and \file{blplain.tex} can be used as
+% replacement wrappers around \file{plain.tex} and
+% \file{lplain.tex} to achieve the desired effect, based on the
+% \pkg{babel} package. If you load each of them with ini\TeX, you
+% will get a file called either \file{bplain.fmt} or
+% \file{blplain.fmt}, which you can use as replacements for
+% \file{plain.fmt} and \file{lplain.fmt}.
 %
+% As these files are going to be read as the first thing ini\TeX\
+% sees, we need to set some category codes just to be able to
+% change the definition of |\input|.
+%
 %    \begin{macrocode}
 %<*bplain|blplain>
 \catcode`\{=1 % left brace is begin-group character
@@ -20340,47 +20403,28 @@
 \catcode`\#=6 % hash mark is macro parameter character
 %    \end{macrocode}
 %
-%    Now let's see if a file called \file{hyphen.cfg} can be found
-%    somewhere on \TeX's input path by trying to open it for
-%    reading...
+% If a file called \file{hyphen.cfg} can be found, we make sure that
+% \emph{it} will be read instead of the file \file{hyphen.tex}. We
+% do this by first saving the original meaning of |\input| (and I
+% use a one letter control sequence for that so as not to waste
+% multi-letter control sequence on this in the format).
 %
 %    \begin{macrocode}
 \openin 0 hyphen.cfg
-%    \end{macrocode}
-%
-%    If the file wasn't found the following test turns out true.
-%
-%    \begin{macrocode}
 \ifeof0
 \else
-%    \end{macrocode}
-%
-%    When \file{hyphen.cfg} could be opened we make sure that
-%    \emph{it} will be read instead of the file \file{hyphen.tex}
-%    which should (according to Don Knuth's ruling) contain the
-%    american English hyphenation patterns and nothing else.
-%
-%    We do this by first saving the original meaning of |\input| (and
-%    I use a one letter control sequence for that so as not to waste
-%    multi-letter control sequence on this in the format).
-%
-%    \begin{macrocode}
   \let\a\input
 %    \end{macrocode}
 %
-%    Then |\input| is defined to forget about its argument and load
-%    \file{hyphen.cfg} instead.
+% Then |\input| is defined to forget about its argument and load
+% \file{hyphen.cfg} instead. Once that's done the original meaning
+% of |\input| can be restored and the definition of |\a| can be
+% forgotten.
 %
 %    \begin{macrocode}
   \def\input #1 {%
     \let\input\a
     \a hyphen.cfg
-%    \end{macrocode}
-%
-%    Once that's done the original meaning of |\input| can be restored
-%    and the definition of |\a| can be forgotten.
-%
-%    \begin{macrocode}
     \let\a\undefined
   }
 \fi
@@ -20387,8 +20431,8 @@
 %</bplain|blplain>
 %    \end{macrocode}
 %
-%    Now that we have made sure that \file{hyphen.cfg} will be loaded
-%    at the right moment it is time to load \file{plain.tex}.
+% Now that we have made sure that \file{hyphen.cfg} will be loaded
+% at the right moment it is time to load \file{plain.tex}.
 %
 %    \begin{macrocode}
 %<bplain>\a plain.tex
@@ -20395,9 +20439,9 @@
 %<blplain>\a lplain.tex
 %    \end{macrocode}
 %
-%    Finally we change the contents of |\fmtname| to indicate that
-%    this is \emph{not} the plain format, but a format based on plain
-%    with the \pkg{babel} package preloaded.
+% Finally we change the contents of |\fmtname| to indicate that
+% this is \emph{not} the plain format, but a format based on plain
+% with the \pkg{babel} package preloaded.
 %
 %    \begin{macrocode}
 %<bplain>\def\fmtname{babel-plain}
@@ -20404,17 +20448,18 @@
 %<blplain>\def\fmtname{babel-lplain}
 %    \end{macrocode}
 %
-%    When you are using a different format, based on plain.tex you can
-%    make a copy of blplain.tex, rename it and replace \file{plain.tex}
-%    with the name of your format file.
+% When you are using a different format, based on plain.tex you can
+% make a copy of blplain.tex, rename it and replace \file{plain.tex}
+% with the name of your format file.
 %
 % \subsection{Emulating some \LaTeX{} features}
 %
-%    The following code duplicates or emulates parts of \LaTeXe\ that
-%    are needed for \babel.
+% The following code duplicates or emulates parts of \LaTeXe\ that
+% are needed for \babel.
 %
 %    \begin{macrocode}
-%<*plain>
+%<<*Emulate LaTeX>>
+  % == Code for plain ==
 \def\@empty{}
 \def\loadlocalcfg#1{%
   \openin0#1.cfg
@@ -20471,6 +20516,7 @@
   #1%
   \ifx#2\@empty\else\expandafter\zap at space\fi
   #2}
+\let\bbl at trace\@gobble
 %    \end{macrocode}
 %
 %    \LaTeXe\ has the command |\@onlypreamble| which adds commands to
@@ -20521,13 +20567,17 @@
 %    \end{macrocode}
 %
 %    \LaTeX\ needs to be able to switch off writing to its auxiliary
-%    files; plain doesn't have them by default.
+%    files; plain doesn't have them by default. There is a trick to
+%    hide some conditional commands from the outer |\ifx|. The same
+%    trick is applied below.
 %
 %    \begin{macrocode}
-\ifx\if at filesw\@undefined
+\catcode`\&=\z@
+\ifx&if at filesw\@undefined
   \expandafter\let\csname if at filesw\expandafter\endcsname
     \csname iffalse\endcsname
 \fi
+\catcode`\&=4
 %    \end{macrocode}
 %
 %    Mimick \LaTeX's commands to define control sequences.
@@ -20594,9 +20644,8 @@
       \@x at protect#1%
    \fi
 }
-\def\@x at protect#1\fi#2#3{%
-   \fi\protect#1%
-}
+\catcode`\&=\z@  % Trick to hide conditionals
+  \def\@x at protect#1&fi#2#3{&fi\protect#1}
 %    \end{macrocode}
 %
 %    The following little macro |\in@| is taken from \file{latex.ltx};
@@ -20606,7 +20655,8 @@
 %    construct with the temporary definition of |\bbl at tempa|.
 %
 %    \begin{macrocode}
-\def\bbl at tempa{\csname newif\endcsname\ifin@}
+  \def\bbl at tempa{\csname newif\endcsname&ifin@}
+\catcode`\&=4
 \ifx\in@\@undefined
   \def\in@#1#2{%
     \def\in@@##1#1##2##3\in@@{%
@@ -20872,8 +20922,17 @@
 \ifx\scriptsize\@undefined
   \let\scriptsize\sevenrm
 \fi
+  % End of code for plain
+%<</Emulate LaTeX>>
+%    \end{macrocode}
+%
+% A proxy file:
+%    \begin{macrocode}
+%<*plain>
+\input babel.def
 %</plain>
 %    \end{macrocode}
+
 %
 % \Finale
 %

Modified: trunk/Master/texmf-dist/source/latex/babel/babel.ins
===================================================================
--- trunk/Master/texmf-dist/source/latex/babel/babel.ins	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/source/latex/babel/babel.ins	2020-04-28 21:14:00 UTC (rev 54930)
@@ -26,7 +26,7 @@
 %% and covered by LPPL is defined by the unpacking scripts (with
 %% extension .ins) which are part of the distribution.
 %%
-\def\filedate{2020/03/22}
+\def\filedate{2020/04/28}
 \def\batchfile{babel.ins}
 \input docstrip.tex
 

Modified: trunk/Master/texmf-dist/source/latex/babel/bbcompat.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/babel/bbcompat.dtx	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/source/latex/babel/bbcompat.dtx	2020-04-28 21:14:00 UTC (rev 54930)
@@ -30,7 +30,7 @@
 %
 % \iffalse
 %<*dtx>
-\ProvidesFile{bbcompat.dtx}[2020/03/22 v3.42]
+\ProvidesFile{bbcompat.dtx}[2020/04/28 v3.43]
 %</dtx>
 %
 %% File 'bbcompat.dtx'

Modified: trunk/Master/texmf-dist/source/latex/babel/locale.zip
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/tex/generic/babel/babel-bidi-basic-r.lua
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/babel-bidi-basic-r.lua	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/tex/generic/babel/babel-bidi-basic-r.lua	2020-04-28 21:14:00 UTC (rev 54930)
@@ -200,3 +200,4 @@
   end
   return node.prev(head) or head
 end
+

Modified: trunk/Master/texmf-dist/tex/generic/babel/babel-bidi-basic.lua
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/babel-bidi-basic.lua	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/tex/generic/babel/babel-bidi-basic.lua	2020-04-28 21:14:00 UTC (rev 54930)
@@ -409,3 +409,4 @@
 
   return node.prev(head) or head
 end
+

Modified: trunk/Master/texmf-dist/tex/generic/babel/babel-data-bidi.lua
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/babel-data-bidi.lua	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/tex/generic/babel/babel-data-bidi.lua	2020-04-28 21:14:00 UTC (rev 54930)
@@ -6113,3 +6113,4 @@
  [0xE007E]={d='bn'},
  [0xE007F]={d='bn'}
 }
+

Modified: trunk/Master/texmf-dist/tex/generic/babel/babel-data-cjk.lua
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/babel-data-cjk.lua	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/tex/generic/babel/babel-data-cjk.lua	2020-04-28 21:14:00 UTC (rev 54930)
@@ -288,3 +288,4 @@
   ['I']  = { ['op']=1, ['pr']=1, ['I']=1, ['O']=1 },
   ['O']  = {                     ['I']=1 }
 }
+

Modified: trunk/Master/texmf-dist/tex/generic/babel/babel.def
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/babel.def	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/tex/generic/babel/babel.def	2020-04-28 21:14:00 UTC (rev 54930)
@@ -32,20 +32,344 @@
 %% extension |.ins|) which are part of the distribution.
 %%
 
-\ifx\ldf at quit\@undefined
-\else
-  \expandafter\endinput
-\fi
+\ifx\ldf at quit\@undefined\else
+\endinput\fi % Same line!
 \ifx\ProvidesFile\@undefined
   \def\ProvidesFile#1[#2 #3 #4]{%
     \wlog{File: #1 #4 #3 <#2>}%
     \let\ProvidesFile\@undefined}
 \fi
-\ProvidesFile{babel.def}[2020/03/22 3.42 Babel common definitions]
-\ifx\AtBeginDocument\@undefined
-  \input plain.def\relax
+\ProvidesFile{babel.def}[2020/04/28 3.43 Babel common definitions]
+\ifx\AtBeginDocument\@undefined  % TODO. change test.
+    % == Code for plain ==
+\def\@empty{}
+\def\loadlocalcfg#1{%
+  \openin0#1.cfg
+  \ifeof0
+    \closein0
+  \else
+    \closein0
+    {\immediate\write16{*************************************}%
+     \immediate\write16{* Local config file #1.cfg used}%
+     \immediate\write16{*}%
+     }
+    \input #1.cfg\relax
+  \fi
+  \@endofldf}
+\long\def\@firstofone#1{#1}
+\long\def\@firstoftwo#1#2{#1}
+\long\def\@secondoftwo#1#2{#2}
+\def\@nnil{\@nil}
+\def\@gobbletwo#1#2{}
+\def\@ifstar#1{\@ifnextchar *{\@firstoftwo{#1}}}
+\def\@star at or@long#1{%
+  \@ifstar
+  {\let\l at ngrel@x\relax#1}%
+  {\let\l at ngrel@x\long#1}}
+\let\l at ngrel@x\relax
+\def\@car#1#2\@nil{#1}
+\def\@cdr#1#2\@nil{#2}
+\let\@typeset at protect\relax
+\let\protected at edef\edef
+\long\def\@gobble#1{}
+\edef\@backslashchar{\expandafter\@gobble\string\\}
+\def\strip at prefix#1>{}
+\def\g at addto@macro#1#2{{%
+    \toks@\expandafter{#1#2}%
+    \xdef#1{\the\toks@}}}
+\def\@namedef#1{\expandafter\def\csname #1\endcsname}
+\def\@nameuse#1{\csname #1\endcsname}
+\def\@ifundefined#1{%
+  \expandafter\ifx\csname#1\endcsname\relax
+    \expandafter\@firstoftwo
+  \else
+    \expandafter\@secondoftwo
+  \fi}
+\def\@expandtwoargs#1#2#3{%
+  \edef\reserved at a{\noexpand#1{#2}{#3}}\reserved at a}
+\def\zap at space#1 #2{%
+  #1%
+  \ifx#2\@empty\else\expandafter\zap at space\fi
+  #2}
+\let\bbl at trace\@gobble
+\ifx\@preamblecmds\@undefined
+  \def\@preamblecmds{}
 \fi
-\ifx\bbl at ifshorthand\@undefined
+\def\@onlypreamble#1{%
+  \expandafter\gdef\expandafter\@preamblecmds\expandafter{%
+    \@preamblecmds\do#1}}
+\@onlypreamble\@onlypreamble
+\def\begindocument{%
+  \@begindocumenthook
+  \global\let\@begindocumenthook\@undefined
+  \def\do##1{\global\let##1\@undefined}%
+  \@preamblecmds
+  \global\let\do\noexpand}
+\ifx\@begindocumenthook\@undefined
+  \def\@begindocumenthook{}
+\fi
+\@onlypreamble\@begindocumenthook
+\def\AtBeginDocument{\g at addto@macro\@begindocumenthook}
+\def\AtEndOfPackage#1{\g at addto@macro\@endofldf{#1}}
+\@onlypreamble\AtEndOfPackage
+\def\@endofldf{}
+\@onlypreamble\@endofldf
+\let\bbl at afterlang\@empty
+\chardef\bbl at opt@hyphenmap\z@
+\catcode`\&=\z@
+\ifx&if at filesw\@undefined
+  \expandafter\let\csname if at filesw\expandafter\endcsname
+    \csname iffalse\endcsname
+\fi
+\catcode`\&=4
+\def\newcommand{\@star at or@long\new at command}
+\def\new at command#1{%
+  \@testopt{\@newcommand#1}0}
+\def\@newcommand#1[#2]{%
+  \@ifnextchar [{\@xargdef#1[#2]}%
+                {\@argdef#1[#2]}}
+\long\def\@argdef#1[#2]#3{%
+  \@yargdef#1\@ne{#2}{#3}}
+\long\def\@xargdef#1[#2][#3]#4{%
+  \expandafter\def\expandafter#1\expandafter{%
+    \expandafter\@protected at testopt\expandafter #1%
+    \csname\string#1\expandafter\endcsname{#3}}%
+  \expandafter\@yargdef \csname\string#1\endcsname
+  \tw@{#2}{#4}}
+\long\def\@yargdef#1#2#3{%
+  \@tempcnta#3\relax
+  \advance \@tempcnta \@ne
+  \let\@hash@\relax
+  \edef\reserved at a{\ifx#2\tw@ [\@hash at 1]\fi}%
+  \@tempcntb #2%
+  \@whilenum\@tempcntb <\@tempcnta
+  \do{%
+    \edef\reserved at a{\reserved at a\@hash@\the\@tempcntb}%
+    \advance\@tempcntb \@ne}%
+  \let\@hash@##%
+  \l at ngrel@x\expandafter\def\expandafter#1\reserved at a}
+\def\providecommand{\@star at or@long\provide at command}
+\def\provide at command#1{%
+  \begingroup
+    \escapechar\m at ne\xdef\@gtempa{{\string#1}}%
+  \endgroup
+  \expandafter\@ifundefined\@gtempa
+    {\def\reserved at a{\new at command#1}}%
+    {\let\reserved at a\relax
+     \def\reserved at a{\new at command\reserved at a}}%
+   \reserved at a}%
+\def\DeclareRobustCommand{\@star at or@long\declare at robustcommand}
+\def\declare at robustcommand#1{%
+   \edef\reserved at a{\string#1}%
+   \def\reserved at b{#1}%
+   \edef\reserved at b{\expandafter\strip at prefix\meaning\reserved at b}%
+   \edef#1{%
+      \ifx\reserved at a\reserved at b
+         \noexpand\x at protect
+         \noexpand#1%
+      \fi
+      \noexpand\protect
+      \expandafter\noexpand\csname
+         \expandafter\@gobble\string#1 \endcsname
+   }%
+   \expandafter\new at command\csname
+      \expandafter\@gobble\string#1 \endcsname
+}
+\def\x at protect#1{%
+   \ifx\protect\@typeset at protect\else
+      \@x at protect#1%
+   \fi
+}
+\catcode`\&=\z@  % Trick to hide conditionals
+  \def\@x at protect#1&fi#2#3{&fi\protect#1}
+  \def\bbl at tempa{\csname newif\endcsname&ifin@}
+\catcode`\&=4
+\ifx\in@\@undefined
+  \def\in@#1#2{%
+    \def\in@@##1#1##2##3\in@@{%
+      \ifx\in@##2\in at false\else\in at true\fi}%
+    \in@@#2#1\in@\in@@}
+\else
+  \let\bbl at tempa\@empty
+\fi
+\bbl at tempa
+\def\@ifpackagewith#1#2#3#4{#3}
+\def\@ifl at aded#1#2#3#4{}
+\ifx\@tempcnta\@undefined
+  \csname newcount\endcsname\@tempcnta\relax
+\fi
+\ifx\@tempcntb\@undefined
+  \csname newcount\endcsname\@tempcntb\relax
+\fi
+\ifx\bye\@undefined
+  \advance\count10 by -2\relax
+\fi
+\ifx\@ifnextchar\@undefined
+  \def\@ifnextchar#1#2#3{%
+    \let\reserved at d=#1%
+    \def\reserved at a{#2}\def\reserved at b{#3}%
+    \futurelet\@let at token\@ifnch}
+  \def\@ifnch{%
+    \ifx\@let at token\@sptoken
+      \let\reserved at c\@xifnch
+    \else
+      \ifx\@let at token\reserved at d
+        \let\reserved at c\reserved at a
+      \else
+        \let\reserved at c\reserved at b
+      \fi
+    \fi
+    \reserved at c}
+  \def\:{\let\@sptoken= } \:  % this makes \@sptoken a space token
+  \def\:{\@xifnch} \expandafter\def\: {\futurelet\@let at token\@ifnch}
+\fi
+\def\@testopt#1#2{%
+  \@ifnextchar[{#1}{#1[#2]}}
+\def\@protected at testopt#1{%
+  \ifx\protect\@typeset at protect
+    \expandafter\@testopt
+  \else
+    \@x at protect#1%
+  \fi}
+\long\def\@whilenum#1\do #2{\ifnum #1\relax #2\relax\@iwhilenum{#1\relax
+     #2\relax}\fi}
+\long\def\@iwhilenum#1{\ifnum #1\expandafter\@iwhilenum
+         \else\expandafter\@gobble\fi{#1}}
+\def\DeclareTextCommand{%
+   \@dec at text@cmd\providecommand
+}
+\def\ProvideTextCommand{%
+   \@dec at text@cmd\providecommand
+}
+\def\DeclareTextSymbol#1#2#3{%
+   \@dec at text@cmd\chardef#1{#2}#3\relax
+}
+\def\@dec at text@cmd#1#2#3{%
+   \expandafter\def\expandafter#2%
+      \expandafter{%
+         \csname#3-cmd\expandafter\endcsname
+         \expandafter#2%
+         \csname#3\string#2\endcsname
+      }%
+   \expandafter#1\csname#3\string#2\endcsname
+}
+\def\@current at cmd#1{%
+  \ifx\protect\@typeset at protect\else
+      \noexpand#1\expandafter\@gobble
+  \fi
+}
+\def\@changed at cmd#1#2{%
+   \ifx\protect\@typeset at protect
+      \expandafter\ifx\csname\cf at encoding\string#1\endcsname\relax
+         \expandafter\ifx\csname ?\string#1\endcsname\relax
+            \expandafter\def\csname ?\string#1\endcsname{%
+               \@changed at x@err{#1}%
+            }%
+         \fi
+         \global\expandafter\let
+           \csname\cf at encoding \string#1\expandafter\endcsname
+           \csname ?\string#1\endcsname
+      \fi
+      \csname\cf at encoding\string#1%
+        \expandafter\endcsname
+   \else
+      \noexpand#1%
+   \fi
+}
+\def\@changed at x@err#1{%
+    \errhelp{Your command will be ignored, type <return> to proceed}%
+    \errmessage{Command \protect#1 undefined in encoding \cf at encoding}}
+\def\DeclareTextCommandDefault#1{%
+   \DeclareTextCommand#1?%
+}
+\def\ProvideTextCommandDefault#1{%
+   \ProvideTextCommand#1?%
+}
+\expandafter\let\csname OT1-cmd\endcsname\@current at cmd
+\expandafter\let\csname?-cmd\endcsname\@changed at cmd
+\def\DeclareTextAccent#1#2#3{%
+  \DeclareTextCommand#1{#2}[1]{\accent#3 ##1}
+}
+\def\DeclareTextCompositeCommand#1#2#3#4{%
+   \expandafter\let\expandafter\reserved at a\csname#2\string#1\endcsname
+   \edef\reserved at b{\string##1}%
+   \edef\reserved at c{%
+     \expandafter\@strip at args\meaning\reserved at a:-\@strip at args}%
+   \ifx\reserved at b\reserved at c
+      \expandafter\expandafter\expandafter\ifx
+         \expandafter\@car\reserved at a\relax\relax\@nil
+         \@text at composite
+      \else
+         \edef\reserved at b##1{%
+            \def\expandafter\noexpand
+               \csname#2\string#1\endcsname####1{%
+               \noexpand\@text at composite
+                  \expandafter\noexpand\csname#2\string#1\endcsname
+                  ####1\noexpand\@empty\noexpand\@text at composite
+                  {##1}%
+            }%
+         }%
+         \expandafter\reserved at b\expandafter{\reserved at a{##1}}%
+      \fi
+      \expandafter\def\csname\expandafter\string\csname
+         #2\endcsname\string#1-\string#3\endcsname{#4}
+   \else
+     \errhelp{Your command will be ignored, type <return> to proceed}%
+     \errmessage{\string\DeclareTextCompositeCommand\space used on
+         inappropriate command \protect#1}
+   \fi
+}
+\def\@text at composite#1#2#3\@text at composite{%
+   \expandafter\@text at composite@x
+      \csname\string#1-\string#2\endcsname
+}
+\def\@text at composite@x#1#2{%
+   \ifx#1\relax
+      #2%
+   \else
+      #1%
+   \fi
+}
+\def\@strip at args#1:#2-#3\@strip at args{#2}
+\def\DeclareTextComposite#1#2#3#4{%
+   \def\reserved at a{\DeclareTextCompositeCommand#1{#2}{#3}}%
+   \bgroup
+      \lccode`\@=#4%
+      \lowercase{%
+   \egroup
+      \reserved at a @%
+   }%
+}
+\def\UseTextSymbol#1#2{%
+   #2%
+}
+\def\UseTextAccent#1#2#3{%
+}
+\def\@use at text@encoding#1{%
+}
+\def\DeclareTextSymbolDefault#1#2{%
+   \DeclareTextCommandDefault#1{\UseTextSymbol{#2}#1}%
+}
+\def\DeclareTextAccentDefault#1#2{%
+   \DeclareTextCommandDefault#1{\UseTextAccent{#2}#1}%
+}
+\def\cf at encoding{OT1}
+\DeclareTextAccent{\"}{OT1}{127}
+\DeclareTextAccent{\'}{OT1}{19}
+\DeclareTextAccent{\^}{OT1}{94}
+\DeclareTextAccent{\`}{OT1}{18}
+\DeclareTextAccent{\~}{OT1}{126}
+\DeclareTextSymbol{\textquotedblleft}{OT1}{92}
+\DeclareTextSymbol{\textquotedblright}{OT1}{`\"}
+\DeclareTextSymbol{\textquoteleft}{OT1}{`\`}
+\DeclareTextSymbol{\textquoteright}{OT1}{`\'}
+\DeclareTextSymbol{\i}{OT1}{16}
+\DeclareTextSymbol{\ss}{OT1}{25}
+\ifx\scriptsize\@undefined
+  \let\scriptsize\sevenrm
+\fi
+  % End of code for plain
+  \def\languagename{english}%
   \let\bbl at opt@shorthands\@nnil
   \def\bbl at ifshorthand#1#2#3{#2}%
   \let\bbl at language@opts\@empty
@@ -67,32 +391,503 @@
   \ifx\bbl at trace\@undefined\def\bbl at trace#1{}\fi
   \expandafter\newif\csname ifbbl at single\endcsname
 \fi
-\ifx\bbl at switchflag\@undefined % Prevent double input
-  \let\bbl at switchflag\relax
-  \input switch.def\relax
+\ifx\bbl at trace\@undefined
+  \let\LdfInit\endinput
+  \def\ProvidesLanguage#1{\endinput}
+\endinput\fi % Same line!
+\ifx\language\@undefined
+  \csname newcount\endcsname\language
 \fi
-\bbl at trace{Compatibility with language.def}
-\ifx\bbl at languages\@undefined
-  \ifx\directlua\@undefined
-    \openin1 = language.def
-    \ifeof1
-      \closein1
-      \message{I couldn't find the file language.def}
+\ifx\newlanguage\@undefined
+  \csname newcount\endcsname\last at language
+  \def\addlanguage#1{%
+    \global\advance\last at language\@ne
+    \ifnum\last at language<\@cclvi
     \else
-      \closein1
-      \begingroup
-        \def\addlanguage#1#2#3#4#5{%
-          \expandafter\ifx\csname lang@#1\endcsname\relax\else
-            \global\expandafter\let\csname l@#1\expandafter\endcsname
-              \csname lang@#1\endcsname
-          \fi}%
-        \def\uselanguage#1{}%
-        \input language.def
-      \endgroup
+      \errmessage{No room for a new \string\language!}%
     \fi
+    \global\chardef#1\last at language
+    \wlog{\string#1 = \string\language\the\last at language}}
+\else
+  \countdef\last at language=19
+  \def\addlanguage{\alloc at 9\language\chardef\@cclvi}
+\fi
+\def\bbl at version{3.43}
+\def\bbl at date{2020/04/28}
+\def\adddialect#1#2{%
+  \global\chardef#1#2\relax
+  \bbl at usehooks{adddialect}{{#1}{#2}}%
+  \begingroup
+    \count@#1\relax
+    \def\bbl at elt##1##2##3##4{%
+      \ifnum\count@=##2\relax
+        \bbl at info{\string#1 = using hyphenrules for ##1\\%
+                  (\string\language\the\count@)}%
+        \def\bbl at elt####1####2####3####4{}%
+      \fi}%
+    \bbl at cs{languages}%
+  \endgroup}
+\def\bbl at fixname#1{%
+  \begingroup
+    \def\bbl at tempe{l@}%
+    \edef\bbl at tempd{\noexpand\@ifundefined{\noexpand\bbl at tempe#1}}%
+    \bbl at tempd
+      {\lowercase\expandafter{\bbl at tempd}%
+         {\uppercase\expandafter{\bbl at tempd}%
+           \@empty
+           {\edef\bbl at tempd{\def\noexpand#1{#1}}%
+            \uppercase\expandafter{\bbl at tempd}}}%
+         {\edef\bbl at tempd{\def\noexpand#1{#1}}%
+          \lowercase\expandafter{\bbl at tempd}}}%
+      \@empty
+    \edef\bbl at tempd{\endgroup\def\noexpand#1{#1}}%
+  \bbl at tempd
+  \bbl at exp{\\\bbl at usehooks{languagename}{{\languagename}{#1}}}}
+\def\bbl at iflanguage#1{%
+  \@ifundefined{l@#1}{\@nolanerr{#1}\@gobble}\@firstofone}
+\def\bbl at bcpcase#1#2#3#4\@@#5{%
+  \ifx\@empty#3%
+    \uppercase{\def#5{#1#2}}%
+  \else
+    \uppercase{\def#5{#1}}%
+    \lowercase{\edef#5{#5#2#3#4}}%
+  \fi}
+\def\bbl at bcplookup#1-#2-#3-#4\@@{%
+  \let\bbl at bcp\relax
+  \lowercase{\def\bbl at tempa{#1}}%
+  \ifx\@empty#2%
+    \IfFileExists{babel-\bbl at tempa.ini}{\let\bbl at bcp\bbl at tempa}{}%
+  \else\ifx\@empty#3%
+    \bbl at bcpcase#2\@empty\@empty\@@\bbl at tempb
+    \IfFileExists{babel-\bbl at tempa-\bbl at tempb.ini}%
+      {\edef\bbl at bcp{\bbl at tempa-\bbl at tempb}}%
+      {}%
+    \ifx\bbl at bcp\relax
+      \IfFileExists{babel-\bbl at tempa.ini}{\let\bbl at bcp\bbl at tempa}{}%
+    \fi
+  \else
+    \bbl at bcpcase#2\@empty\@empty\@@\bbl at tempb
+    \bbl at bcpcase#3\@empty\@empty\@@\bbl at tempc
+    \IfFileExists{babel-\bbl at tempa-\bbl at tempb-\bbl at tempc.ini}%
+      {\edef\bbl at bcp{\bbl at tempa-\bbl at tempb-\bbl at tempc}}%
+      {}%
+    \ifx\bbl at bcp\relax
+      \IfFileExists{babel-\bbl at tempa-\bbl at tempc.ini}%
+        {\edef\bbl at bcp{\bbl at tempa-\bbl at tempc}}%
+        {}%
+    \fi
+    \ifx\bbl at bcp\relax
+      \IfFileExists{babel-\bbl at tempa-\bbl at tempc.ini}%
+        {\edef\bbl at bcp{\bbl at tempa-\bbl at tempc}}%
+        {}%
+    \fi
+    \ifx\bbl at bcp\relax
+      \IfFileExists{babel-\bbl at tempa.ini}{\let\bbl at bcp\bbl at tempa}{}%
+    \fi
+  \fi\fi}
+\let\bbl at autoload@options\@empty
+\let\bbl at initoload\relax
+\def\bbl at provide@locale{%
+  \ifx\babelprovide\@undefined
+    \bbl at error{For a language to be defined on the fly 'base'\\%
+               is not enough, and the whole package must be\\%
+               loaded. Either delete the 'base' option or\\%
+               request the languages explicitly}%
+              {See the manual for further details.}%
   \fi
-  \chardef\l at english\z@
+  \let\bbl at auxname\languagename % Still necessary. TODO
+  \bbl at ifunset{bbl at bcp@map@\languagename}{}% Move uplevel??
+    {\edef\languagename{\@nameuse{bbl at bcp@map@\languagename}}}%
+  \ifbbl at bcpallowed
+    \expandafter\ifx\csname date\languagename\endcsname\relax
+      \expandafter
+      \bbl at bcplookup\languagename-\@empty-\@empty-\@empty\@@
+      \ifx\bbl at bcp\relax\else  % Returned by \bbl at bcplookup
+        \edef\languagename{\bbl at bcp@prefix\bbl at bcp}%
+        \edef\localename{\bbl at bcp@prefix\bbl at bcp}%
+        \expandafter\ifx\csname date\languagename\endcsname\relax
+          \let\bbl at initoload\bbl at bcp
+          \bbl at exp{\\\babelprovide[\bbl at autoload@bcpoptions]{\languagename}}%
+          \let\bbl at initoload\relax
+        \fi
+        \bbl at csarg\xdef{bcp at map@\bbl at bcp}{\localename}%
+      \fi
+    \fi
+  \fi
+  \expandafter\ifx\csname date\languagename\endcsname\relax
+    \IfFileExists{babel-\languagename.tex}%
+      {\bbl at exp{\\\babelprovide[\bbl at autoload@options]{\languagename}}}%
+      {}%
+  \fi}
+\def\iflanguage#1{%
+  \bbl at iflanguage{#1}{%
+    \ifnum\csname l@#1\endcsname=\language
+      \expandafter\@firstoftwo
+    \else
+      \expandafter\@secondoftwo
+    \fi}}
+\let\bbl at select@type\z@
+\edef\selectlanguage{%
+  \noexpand\protect
+  \expandafter\noexpand\csname selectlanguage \endcsname}
+\ifx\@undefined\protect\let\protect\relax\fi
+\let\xstring\string
+\def\bbl at language@stack{}
+\def\bbl at push@language{%
+  \ifx\languagename\@undefined\else
+    \xdef\bbl at language@stack{\languagename+\bbl at language@stack}%
+  \fi}
+\def\bbl at pop@lang#1+#2&#3{%
+  \edef\languagename{#1}\xdef#3{#2}}
+\let\bbl at ifrestoring\@secondoftwo
+\def\bbl at pop@language{%
+  \expandafter\bbl at pop@lang\bbl at language@stack&\bbl at language@stack
+  \let\bbl at ifrestoring\@firstoftwo
+  \expandafter\bbl at set@language\expandafter{\languagename}%
+  \let\bbl at ifrestoring\@secondoftwo}
+\chardef\localeid\z@
+\def\bbl at id@last{0}    % No real need for a new counter
+\def\bbl at id@assign{%
+  \bbl at ifunset{bbl at id@@\languagename}%
+    {\count@\bbl at id@last\relax
+     \advance\count@\@ne
+     \bbl at csarg\chardef{id@@\languagename}\count@
+     \edef\bbl at id@last{\the\count@}%
+     \ifcase\bbl at engine\or
+       \directlua{
+         Babel = Babel or {}
+         Babel.locale_props = Babel.locale_props or {}
+         Babel.locale_props[\bbl at id@last] = {}
+         Babel.locale_props[\bbl at id@last].name = '\languagename'
+        }%
+      \fi}%
+    {}%
+    \chardef\localeid\bbl at cl{id@}}
+\expandafter\def\csname selectlanguage \endcsname#1{%
+  \ifnum\bbl at hymapsel=\@cclv\let\bbl at hymapsel\tw@\fi
+  \bbl at push@language
+  \aftergroup\bbl at pop@language
+  \bbl at set@language{#1}}
+\def\BabelContentsFiles{toc,lof,lot}
+\def\bbl at set@language#1{% from selectlanguage, pop@
+  % The old buggy way. Preserved for compatibility.
+  \edef\languagename{%
+    \ifnum\escapechar=\expandafter`\string#1\@empty
+    \else\string#1\@empty\fi}%
+  \ifcat\relax\noexpand#1%
+    \expandafter\ifx\csname date\languagename\endcsname\relax
+      \edef\languagename{#1}%
+      \let\localename\languagename
+    \else
+      \bbl at info{Using '\string\language' instead of 'language' is\\%
+                deprecated. If what you want is to use a\\%
+                macro containing the actual locale, make\\%
+                sure it does not not match any language.\\%
+                Reported}%
+      \ifx\scantokens\@undefined
+         \def\localename{??}%
+      \else
+        \scantokens\expandafter{\expandafter
+          \def\expandafter\localename\expandafter{\languagename}}%
+      \fi
+    \fi
+  \else
+    \def\localename{#1}% This one has the correct catcodes
+  \fi
+  \select at language{\languagename}%
+  % write to auxs
+  \expandafter\ifx\csname date\languagename\endcsname\relax\else
+    \if at filesw
+      \ifx\babel at aux\@gobbletwo\else % Set if single in the first, redundant
+        \protected at write\@auxout{}{\string\babel at aux{\bbl at auxname}{}}%
+      \fi
+      \bbl at usehooks{write}{}%
+    \fi
+  \fi}
+\newif\ifbbl at bcpallowed
+\bbl at bcpallowedfalse
+\def\select at language#1{% from set@, babel at aux
+  % set hymap
+  \ifnum\bbl at hymapsel=\@cclv\chardef\bbl at hymapsel4\relax\fi
+  % set name
+  \edef\languagename{#1}%
+  \bbl at fixname\languagename
+  % TODO. name at map must be here?
+  \bbl at provide@locale
+  \bbl at iflanguage\languagename{%
+     \expandafter\ifx\csname date\languagename\endcsname\relax
+      \bbl at error
+        {Unknown language `\languagename'. Either you have\\%
+         misspelled its name, it has not been installed,\\%
+         or you requested it in a previous run. Fix its name,\\%
+         install it or just rerun the file, respectively. In\\%
+         some cases, you may need to remove the aux file}%
+        {You may proceed, but expect wrong results}%
+    \else
+      % set type
+      \let\bbl at select@type\z@
+      \expandafter\bbl at switch\expandafter{\languagename}%
+    \fi}}
+\def\babel at aux#1#2{%
+  \select at language{#1}%
+  \bbl at foreach\BabelContentsFiles{%
+    \@writefile{##1}{\babel at toc{#1}{#2}}}}% %% TODO - ok in plain?
+\def\babel at toc#1#2{%
+  \select at language{#1}}
+\newif\ifbbl at usedategroup
+\def\bbl at switch#1{%  from select@, foreign@
+  % make sure there is info for the language if so requested
+  \bbl at ensureinfo{#1}%
+  % restore
+  \originalTeX
+  \expandafter\def\expandafter\originalTeX\expandafter{%
+    \csname noextras#1\endcsname
+    \let\originalTeX\@empty
+    \babel at beginsave}%
+  \bbl at usehooks{afterreset}{}%
+  \languageshorthands{none}%
+  % set the locale id
+  \bbl at id@assign
+  % switch captions, date
+  \ifcase\bbl at select@type
+    \ifhmode
+      \hskip\z at skip % trick to ignore spaces
+      \csname captions#1\endcsname\relax
+      \csname date#1\endcsname\relax
+      \loop\ifdim\lastskip>\z@\unskip\repeat\unskip
+    \else
+      \csname captions#1\endcsname\relax
+      \csname date#1\endcsname\relax
+    \fi
+  \else
+    \ifbbl at usedategroup   % if \foreign... within \<lang>date
+      \bbl at usedategroupfalse
+      \ifhmode
+        \hskip\z at skip % trick to ignore spaces
+        \csname date#1\endcsname\relax
+        \loop\ifdim\lastskip>\z@\unskip\repeat\unskip
+      \else
+        \csname date#1\endcsname\relax
+      \fi
+    \fi
+  \fi
+  % switch extras
+  \bbl at usehooks{beforeextras}{}%
+  \csname extras#1\endcsname\relax
+  \bbl at usehooks{afterextras}{}%
+  %  > babel-ensure
+  %  > babel-sh-<short>
+  %  > babel-bidi
+  %  > babel-fontspec
+  % hyphenation - case mapping
+  \ifcase\bbl at opt@hyphenmap\or
+    \def\BabelLower##1##2{\lccode##1=##2\relax}%
+    \ifnum\bbl at hymapsel>4\else
+      \csname\languagename @bbl at hyphenmap\endcsname
+    \fi
+    \chardef\bbl at opt@hyphenmap\z@
+  \else
+    \ifnum\bbl at hymapsel>\bbl at opt@hyphenmap\else
+      \csname\languagename @bbl at hyphenmap\endcsname
+    \fi
+  \fi
+  \global\let\bbl at hymapsel\@cclv
+  % hyphenation - patterns
+  \bbl at patterns{#1}%
+  % hyphenation - mins
+  \babel at savevariable\lefthyphenmin
+  \babel at savevariable\righthyphenmin
+  \expandafter\ifx\csname #1hyphenmins\endcsname\relax
+    \set at hyphenmins\tw@\thr@@\relax
+  \else
+    \expandafter\expandafter\expandafter\set at hyphenmins
+      \csname #1hyphenmins\endcsname\relax
+  \fi}
+\long\def\otherlanguage#1{%
+  \ifnum\bbl at hymapsel=\@cclv\let\bbl at hymapsel\thr@@\fi
+  \csname selectlanguage \endcsname{#1}%
+  \ignorespaces}
+\long\def\endotherlanguage{%
+  \global\@ignoretrue\ignorespaces}
+\expandafter\def\csname otherlanguage*\endcsname#1{%
+  \ifnum\bbl at hymapsel=\@cclv\chardef\bbl at hymapsel4\relax\fi
+  \foreign at language{#1}}
+\expandafter\let\csname endotherlanguage*\endcsname\relax
+\providecommand\bbl at beforeforeign{}
+\edef\foreignlanguage{%
+  \noexpand\protect
+  \expandafter\noexpand\csname foreignlanguage \endcsname}
+\expandafter\def\csname foreignlanguage \endcsname{%
+  \@ifstar\bbl at foreign@s\bbl at foreign@x}
+\def\bbl at foreign@x#1#2{%
+  \begingroup
+    \let\BabelText\@firstofone
+    \bbl at beforeforeign
+    \foreign at language{#1}%
+    \bbl at usehooks{foreign}{}%
+    \BabelText{#2}% Now in horizontal mode!
+  \endgroup}
+\def\bbl at foreign@s#1#2{% TODO - \shapemode, \@setpar, ?\@@par
+  \begingroup
+    {\par}%
+    \let\BabelText\@firstofone
+    \foreign at language{#1}%
+    \bbl at usehooks{foreign*}{}%
+    \bbl at dirparastext
+    \BabelText{#2}% Still in vertical mode!
+    {\par}%
+  \endgroup}
+\def\foreign at language#1{%
+  % set name
+  \edef\languagename{#1}%
+  \bbl at fixname\languagename
+  % TODO. name at map here?
+  \bbl at provide@locale
+  \bbl at iflanguage\languagename{%
+    \expandafter\ifx\csname date\languagename\endcsname\relax
+      \bbl at warning   % TODO - why a warning, not an error?
+        {Unknown language `#1'. Either you have\\%
+         misspelled its name, it has not been installed,\\%
+         or you requested it in a previous run. Fix its name,\\%
+         install it or just rerun the file, respectively. In\\%
+         some cases, you may need to remove the aux file.\\%
+         I'll proceed, but expect wrong results.\\%
+         Reported}%
+    \fi
+    % set type
+    \let\bbl at select@type\@ne
+    \expandafter\bbl at switch\expandafter{\languagename}}}
+\let\bbl at hyphlist\@empty
+\let\bbl at hyphenation@\relax
+\let\bbl at pttnlist\@empty
+\let\bbl at patterns@\relax
+\let\bbl at hymapsel=\@cclv
+\def\bbl at patterns#1{%
+  \language=\expandafter\ifx\csname l@#1:\f at encoding\endcsname\relax
+      \csname l@#1\endcsname
+      \edef\bbl at tempa{#1}%
+    \else
+      \csname l@#1:\f at encoding\endcsname
+      \edef\bbl at tempa{#1:\f at encoding}%
+    \fi
+  \@expandtwoargs\bbl at usehooks{patterns}{{#1}{\bbl at tempa}}%
+  %  > luatex
+  \@ifundefined{bbl at hyphenation@}{}{% Can be \relax!
+    \begingroup
+      \bbl at xin@{,\number\language,}{,\bbl at hyphlist}%
+      \ifin@\else
+        \@expandtwoargs\bbl at usehooks{hyphenation}{{#1}{\bbl at tempa}}%
+        \hyphenation{%
+          \bbl at hyphenation@
+          \@ifundefined{bbl at hyphenation@#1}%
+            \@empty
+            {\space\csname bbl at hyphenation@#1\endcsname}}%
+        \xdef\bbl at hyphlist{\bbl at hyphlist\number\language,}%
+      \fi
+    \endgroup}}
+\def\hyphenrules#1{%
+  \edef\bbl at tempf{#1}%
+  \bbl at fixname\bbl at tempf
+  \bbl at iflanguage\bbl at tempf{%
+    \expandafter\bbl at patterns\expandafter{\bbl at tempf}%
+    \languageshorthands{none}%
+    \expandafter\ifx\csname\bbl at tempf hyphenmins\endcsname\relax
+      \set at hyphenmins\tw@\thr@@\relax
+    \else
+      \expandafter\expandafter\expandafter\set at hyphenmins
+      \csname\bbl at tempf hyphenmins\endcsname\relax
+    \fi}}
+\let\endhyphenrules\@empty
+\def\providehyphenmins#1#2{%
+  \expandafter\ifx\csname #1hyphenmins\endcsname\relax
+    \@namedef{#1hyphenmins}{#2}%
+  \fi}
+\def\set at hyphenmins#1#2{%
+  \lefthyphenmin#1\relax
+  \righthyphenmin#2\relax}
+\ifx\ProvidesFile\@undefined
+  \def\ProvidesLanguage#1[#2 #3 #4]{%
+    \wlog{Language: #1 #4 #3 <#2>}%
+    }
+\else
+  \def\ProvidesLanguage#1{%
+    \begingroup
+      \catcode`\ 10 %
+      \@makeother\/%
+      \@ifnextchar[%]
+        {\@provideslanguage{#1}}{\@provideslanguage{#1}[]}}
+  \def\@provideslanguage#1[#2]{%
+    \wlog{Language: #1 #2}%
+    \expandafter\xdef\csname ver@#1.ldf\endcsname{#2}%
+    \endgroup}
 \fi
+\ifx\originalTeX\@undefined\let\originalTeX\@empty\fi
+\ifx\babel at beginsave\@undefined\let\babel at beginsave\relax\fi
+\providecommand\setlocale{%
+  \bbl at error
+    {Not yet available}%
+    {Find an armchair, sit down and wait}}
+\let\uselocale\setlocale
+\let\locale\setlocale
+\let\selectlocale\setlocale
+\let\localename\setlocale
+\let\textlocale\setlocale
+\let\textlanguage\setlocale
+\let\languagetext\setlocale
+\edef\bbl at nulllanguage{\string\language=0}
+\ifx\PackageError\@undefined  % TODO. Move to Plain
+  \def\bbl at error#1#2{%
+    \begingroup
+      \newlinechar=`\^^J
+      \def\\{^^J(babel) }%
+      \errhelp{#2}\errmessage{\\#1}%
+    \endgroup}
+  \def\bbl at warning#1{%
+    \begingroup
+      \newlinechar=`\^^J
+      \def\\{^^J(babel) }%
+      \message{\\#1}%
+    \endgroup}
+  \let\bbl at infowarn\bbl at warning
+  \def\bbl at info#1{%
+    \begingroup
+      \newlinechar=`\^^J
+      \def\\{^^J}%
+      \wlog{#1}%
+    \endgroup}
+\fi
+\def\bbl at nocaption{\protect\bbl at nocaption@i}
+\def\bbl at nocaption@i#1#2{% 1: text to be printed 2: caption macro \langXname
+  \global\@namedef{#2}{\textbf{?#1?}}%
+  \@nameuse{#2}%
+  \bbl at warning{%
+    \@backslashchar#2 not set. Please, define\\%
+    it in the preamble with something like:\\%
+    \string\renewcommand\@backslashchar#2{..}\\%
+    Reported}}
+\def\bbl at tentative{\protect\bbl at tentative@i}
+\def\bbl at tentative@i#1{%
+  \bbl at warning{%
+    Some functions for '#1' are tentative.\\%
+    They might not work as expected and their behavior\\%
+    could change in the future.\\%
+    Reported}}
+\def\@nolanerr#1{%
+  \bbl at error
+    {You haven't defined the language #1\space yet.\\%
+     Perhaps you misspelled it or your installation\\%
+     is not complete}%
+    {Your command will be ignored, type <return> to proceed}}
+\def\@nopatterns#1{%
+  \bbl at warning
+    {No hyphenation patterns were preloaded for\\%
+     the language `#1' into the format.\\%
+     Please, configure your TeX system to add them and\\%
+     rebuild the format. Now I will use the patterns\\%
+     preloaded for \bbl at nulllanguage\space instead}}
+\let\bbl at usehooks\@gobbletwo
+\ifx\bbl at onlyswitch\@empty\endinput\fi
+  % Here ended switch.def
 \ifx\directlua\@undefined\else
   \ifx\bbl at luapatterns\@undefined
     \input luababel.def
@@ -246,6 +1041,28 @@
   \else
     \@ne
   \fi
+\bbl at trace{Compatibility with language.def}
+\ifx\bbl at languages\@undefined
+  \ifx\directlua\@undefined
+    \openin1 = language.def % TODO. Remove hardcoded number
+    \ifeof1
+      \closein1
+      \message{I couldn't find the file language.def}
+    \else
+      \closein1
+      \begingroup
+        \def\addlanguage#1#2#3#4#5{%
+          \expandafter\ifx\csname lang@#1\endcsname\relax\else
+            \global\expandafter\let\csname l@#1\expandafter\endcsname
+              \csname lang@#1\endcsname
+          \fi}%
+        \def\uselanguage#1{}%
+        \input language.def
+      \endgroup
+    \fi
+  \fi
+  \chardef\l at english\z@
+\fi
 \def\addto#1#2{%
   \ifx#1\@undefined
     \def#1{#2}%
@@ -304,7 +1121,7 @@
   adddialect=2,patterns=2,defaultcommands=0,encodedcommands=2,write=0,%
   beforeextras=0,afterextras=0,stopcommands=0,stringprocess=0,%
   hyphenation=2,initiateactive=3,afterreset=0,foreign=0,foreign*=0,%
-  beforestart=0,languagename=0}
+  beforestart=0,languagename=2}
 \bbl at trace{Defining babelensure}
 \newcommand\babelensure[2][]{%  TODO - revise test files
   \AddBabelHook{babel-ensure}{afterextras}{%
@@ -331,7 +1148,7 @@
   \def\<bbl at e@#2>{\the\toks@{\bbl at ens@fontenc}}}}
 \def\bbl at ensure#1#2#3{% 1: include 2: exclude 3: fontenc
   \def\bbl at tempb##1{% elt for (excluding) \bbl at captionslist list
-    \ifx##1\@undefined % 3.32 - Don't assume the macros exists
+    \ifx##1\@undefined % 3.32 - Don't assume the macro exists
       \edef##1{\noexpand\bbl at nocaption
         {\bbl at stripslash##1}{\languagename\bbl at stripslash##1}}%
     \fi
@@ -370,7 +1187,7 @@
   \tablename\partname\enclname\ccname\headtoname\pagename\seename
   \alsoname\proofname\glossaryname}
 \bbl at trace{Macros for setting language files up}
-\def\bbl at ldfinit{%
+\def\bbl at ldfinit{% TODO. Merge into the next macro? Unused elsewhere
   \let\bbl at screset\@empty
   \let\BabelStrings\bbl at opt@string
   \let\BabelOptions\@empty
@@ -401,13 +1218,15 @@
   \catcode`\@=\atcatcode \let\atcatcode\relax
   \catcode`\==\eqcatcode \let\eqcatcode\relax
   \endinput}
-\def\bbl at afterldf#1{%
+\def\bbl at afterldf#1{% TODO. Merge into the next macro? Unused elsewhere
   \bbl at afterlang
   \let\bbl at afterlang\relax
   \let\BabelModifiers\relax
   \let\bbl at screset\relax}%
 \def\ldf at finish#1{%
-  \loadlocalcfg{#1}%
+  \ifx\loadlocalcfg\@undefined\else % For LaTeX 209
+    \loadlocalcfg{#1}%
+  \fi
   \bbl at afterldf{#1}%
   \expandafter\main at language\expandafter{#1}%
   \catcode`\@=\atcatcode \let\atcatcode\relax
@@ -417,7 +1236,7 @@
 \@onlypreamble\ldf at finish
 \def\main at language#1{%
   \def\bbl at main@language{#1}%
-  \let\languagename\bbl at main@language
+  \let\languagename\bbl at main@language % TODO. Set localename
   \bbl at id@assign
   \bbl at patterns{\languagename}}
 \def\bbl at beforestart{%
@@ -424,17 +1243,17 @@
   \bbl at usehooks{beforestart}{}%
   \global\let\bbl at beforestart\relax}
 \AtBeginDocument{%
-  \bbl at cs{beforestart}%
+  \@nameuse{bbl at beforestart}%
   \if at filesw
-    \immediate\write\@mainaux{\string\bbl at cs{beforestart}}%
+    \immediate\write\@mainaux{\string\@nameuse{bbl at beforestart}}%
   \fi
   \expandafter\selectlanguage\expandafter{\bbl at main@language}%
-  \ifbbl at single  % must go after the line above
+  \ifbbl at single  % must go after the line above.
     \renewcommand\selectlanguage[1]{}%
     \renewcommand\foreignlanguage[2]{#2}%
     \global\let\babel at aux\@gobbletwo  % Also as flag
   \fi
-  \ifcase\bbl at engine\or\pagedir\bodydir\fi}  % TODO - a better place
+  \ifcase\bbl at engine\or\pagedir\bodydir\fi} % TODO - a better place
 \def\select at language@x#1{%
   \ifcase\bbl at select@type
     \bbl at ifsamestring\languagename{#1}{}{\select at language{#1}}%
@@ -570,7 +1389,7 @@
     \bbl at afterfi\csname#1 at sh@#2 at sel\endcsname
   \fi}
 \begingroup
-\bbl at ifunset{ifincsname}%
+\bbl at ifunset{ifincsname}% TODO. Ugly. Correct?
   {\gdef\active at prefix#1{%
      \ifx\protect\@typeset at protect
      \else
@@ -641,7 +1460,7 @@
     \expandafter\@firstoftwo
   \fi}
 \def\user at group{user}
-\def\language at group{english}
+\def\language at group{english} % TODO. I don't like defaults
 \def\system at group{system}
 \def\useshorthands{%
   \@ifstar\bbl at usesh@s{\bbl at usesh@x{}}}
@@ -947,7 +1766,7 @@
 \def\bbl at disc#1#2{\nobreak\discretionary{#2-}{}{#1}\bbl at allowhyphens}
 \bbl at trace{Multiencoding strings}
 \def\bbl at toglobal#1{\global\let#1#1}
-\def\bbl at recatcode#1{%
+\def\bbl at recatcode#1{% TODO. Used only once?
   \@tempcnta="7F
   \def\bbl at tempa{%
     \ifnum\@tempcnta>"FF\else
@@ -1190,6 +2009,20 @@
     \box\z@\kern-.04em\bbl at allowhyphens}}
 \ProvideTextCommandDefault{\quotesinglbase}{%
   \UseTextSymbol{OT1}{\quotesinglbase}}
+\ProvideTextCommand{\guillemetleft}{OT1}{%
+  \ifmmode
+    \ll
+  \else
+    \save at sf@q{\nobreak
+      \raise.2ex\hbox{$\scriptscriptstyle\ll$}\bbl at allowhyphens}%
+  \fi}
+\ProvideTextCommand{\guillemetright}{OT1}{%
+  \ifmmode
+    \gg
+  \else
+    \save at sf@q{\nobreak
+      \raise.2ex\hbox{$\scriptscriptstyle\gg$}\bbl at allowhyphens}%
+  \fi}
 \ProvideTextCommand{\guillemotleft}{OT1}{%
   \ifmmode
     \ll
@@ -1204,6 +2037,10 @@
     \save at sf@q{\nobreak
       \raise.2ex\hbox{$\scriptscriptstyle\gg$}\bbl at allowhyphens}%
   \fi}
+\ProvideTextCommandDefault{\guillemetleft}{%
+  \UseTextSymbol{OT1}{\guillemetleft}}
+\ProvideTextCommandDefault{\guillemetright}{%
+  \UseTextSymbol{OT1}{\guillemetright}}
 \ProvideTextCommandDefault{\guillemotleft}{%
   \UseTextSymbol{OT1}{\guillemotleft}}
 \ProvideTextCommandDefault{\guillemotright}{%
@@ -1287,9 +2124,9 @@
 \ProvideTextCommandDefault{\frq}{%
   \textormath{\guilsinglright}{\mbox{\guilsinglright}}}
 \ProvideTextCommandDefault{\flqq}{%
-  \textormath{\guillemotleft}{\mbox{\guillemotleft}}}
+  \textormath{\guillemetleft}{\mbox{\guillemetleft}}}
 \ProvideTextCommandDefault{\frqq}{%
-  \textormath{\guillemotright}{\mbox{\guillemotright}}}
+  \textormath{\guillemetright}{\mbox{\guillemetright}}}
 \def\umlauthigh{%
   \def\bbl at umlauta##1{\leavevmode\bgroup%
       \expandafter\accent\csname\f at encoding dqpos\endcsname
@@ -1329,7 +2166,6 @@
 \ifx\l at english\@undefined
   \chardef\l at english\z@
 \fi
-\main at language{english}
 \bbl at trace{Bidi layout}
 \providecommand\IfBabelLayout[3]{#3}%
 \newcommand\BabelPatchSection[1]{%
@@ -1406,10 +2242,14 @@
   % == import, captions ==
   \ifx\bbl at KVP@import\@nil\else
     \bbl at exp{\\\bbl at ifblank{\bbl at KVP@import}}%
-      {\begingroup
-         \def\BabelBeforeIni##1##2{\gdef\bbl at KVP@import{##1}\endinput}%
-         \InputIfFileExists{babel-#2.tex}{}{}%
-       \endgroup}%
+      {\ifx\bbl at initoload\relax
+         \begingroup
+           \def\BabelBeforeIni##1##2{\gdef\bbl at KVP@import{##1}\endinput}%
+           \InputIfFileExists{babel-#2.tex}{}{}%
+         \endgroup
+       \else
+         \xdef\bbl at KVP@import{\bbl at initoload}%
+       \fi}%
       {}%
   \fi
   \ifx\bbl at KVP@captions\@nil
@@ -1433,11 +2273,14 @@
         \\\foreignlanguage{\languagename}%
         {####1}}}}%
     {}%
+  \bbl at exp{%
+     \\\bbl at toglobal\<bbl at ensure@\languagename>%
+     \\\bbl at toglobal\<bbl at ensure@\languagename\space>}%
   % At this point all parameters are defined if 'import'. Now we
   % execute some code depending on them. But what about if nothing was
   % imported? We just load the very basic parameters: ids and a few
   % more.
-  \bbl at ifunset{bbl at lname@#2}%
+  \bbl at ifunset{bbl at lname@#2}%  TODO. Duplicated
     {\def\BabelBeforeIni##1##2{%
        \begingroup
          \catcode`\[=12 \catcode`\]=12 \catcode`\==12  \catcode`\;=12 %
@@ -1448,14 +2291,21 @@
          \bbl at exportkey{dgnat}{numbers.digits.native}{}%
          \bbl at exportkey{prehc}{typography.prehyphenchar}{}%
          \bbl at exportkey{lnbrk}{typography.linebreaking}{h}%
+         \bbl at exportkey{lfthm}{typography.lefthyphenmin}{2}%
+         \bbl at exportkey{rgthm}{typography.righthyphenmin}{3}%
          \bbl at exportkey{hyphr}{typography.hyphenrules}{}%
          \bbl at exportkey{hyoth}{typography.hyphenate.other}{}%
          \bbl at exportkey{intsp}{typography.intraspace}{}%
-         \endinput
-       \endgroup}%           boxed, to avoid extra spaces:
-     {\setbox\z@\hbox{\InputIfFileExists{babel-#2.tex}{}{}}}}%
+         \ifx\bbl at initoload\relax\endinput\fi
+       \endgroup}%
+     \begingroup       % boxed, to avoid extra spaces:
+       \ifx\bbl at initoload\relax
+         \setbox\z@\hbox{\InputIfFileExists{babel-#2.tex}{}{}}%
+       \else
+         \setbox\z@\hbox{\BabelBeforeIni{\bbl at initoload}{}}%
+       \fi
+     \endgroup}%
     {}%
-  % -
   % == script, language ==
   % Override the values from ini or defines them
   \ifx\bbl at KVP@script\@nil\else
@@ -1706,7 +2556,11 @@
         \fi}%
       \expandafter\bbl at tempb\bbl at captionslist\@empty
     \else
-      \bbl at read@ini{\bbl at KVP@captions}{data}%  Here all letters cat = 11
+      \ifx\bbl at initoload\relax
+        \bbl at read@ini{\bbl at KVP@captions}{data}%  Here letters cat = 11
+      \else
+        \bbl at read@ini{\bbl at initoload}{data}%  Here all letters cat = 11
+      \fi
       \bbl at after@ini
       \bbl at savestrings
     \fi
@@ -1719,8 +2573,34 @@
       \bbl at savedate
     \fi
   \bbl at endcommands
+  \bbl at ifunset{bbl at lname@#1}%     TODO. Duplicated
+    {\def\BabelBeforeIni##1##2{%
+       \begingroup
+         \catcode`\[=12 \catcode`\]=12 \catcode`\==12  \catcode`\;=12 %
+         \let\bbl at ini@captions at aux\@gobbletwo
+         \def\bbl at inidate ####1.####2.####3.####4\relax ####5####6{}%
+         \bbl at read@ini{##1}{basic data}%
+         \bbl at exportkey{prehc}{typography.prehyphenchar}{}%
+         \bbl at exportkey{lnbrk}{typography.linebreaking}{h}%
+         \bbl at exportkey{lfthm}{typography.lefthyphenmin}{2}%
+         \bbl at exportkey{rgthm}{typography.righthyphenmin}{3}%
+         \bbl at exportkey{hyphr}{typography.hyphenrules}{}%
+         \bbl at exportkey{hyoth}{typography.hyphenate.other}{}%
+         \bbl at exportkey{intsp}{typography.intraspace}{}%
+         \bbl at exportkey{chrng}{characters.ranges}{}%
+         \bbl at exportkey{dgnat}{numbers.digits.native}{}%
+         \ifx\bbl at initoload\relax\endinput\fi
+       \endgroup}%
+     \begingroup       % boxed, to avoid extra spaces:
+       \ifx\bbl at initoload\relax
+         \setbox\z@\hbox{\InputIfFileExists{babel-#1.tex}{}{}}%
+       \else
+         \setbox\z@\hbox{\BabelBeforeIni{\bbl at initoload}{}}%
+       \fi
+     \endgroup}%
+    {}%
   \bbl at exp{%
-    \def\<#1hyphenmins>{%
+    \gdef\<#1hyphenmins>{%
       {\bbl at ifunset{bbl at lfthm@#1}{2}{\bbl at cs{lfthm@#1}}}%
       {\bbl at ifunset{bbl at rgthm@#1}{3}{\bbl at cs{rgthm@#1}}}}}%
   \bbl at provide@hyphens{#1}%
@@ -1758,7 +2638,14 @@
       \fi}%
   \fi
   \ifx\bbl at tempa\relax %        if no opt or no language in opt found
-    \ifx\bbl at KVP@import\@nil\else % if importing
+    \ifx\bbl at KVP@import\@nil
+      \ifx\bbl at initoload\relax\else
+        \bbl at exp{%                    and hyphenrules is not empty
+          \\\bbl at ifblank{\bbl at cs{hyphr@#1}}%
+            {}%
+            {\let\\\bbl at tempa\<l@\bbl at cl{hyphr}>}}%
+      \fi
+    \else % if importing
       \bbl at exp{%                    and hyphenrules is not empty
         \\\bbl at ifblank{\bbl at cs{hyphr@#1}}%
           {}%
@@ -1899,13 +2786,13 @@
   \in@{.1$}{#1$}%
   \ifin@
     \bbl at replace\bbl at tempc{.1}{}%
-    \bbl at csarg\xdef{cntr@\bbl at tempc @\languagename}{%
+    \bbl at csarg\protected at xdef{cntr@\bbl at tempc @\languagename}{%
       \noexpand\bbl at alphnumeral{\bbl at tempc}}%
   \fi
   \in@{.F.}{#1}%
   \ifin@\else\in@{.S.}{#1}\fi
   \ifin@
-    \bbl at csarg\xdef{cntr@#1@\languagename}{\bbl at tempb*}%
+    \bbl at csarg\protected at xdef{cntr@#1@\languagename}{\bbl at tempb*}%
   \else
     \toks@{}% Required by \bbl at buildifcase, which returns \bbl at tempa
     \expandafter\bbl at buildifcase\bbl at tempb* \\ % Space after \\
@@ -2117,7 +3004,10 @@
   \fi}
 \newcommand\LocaleForEach{\bbl at foreach\bbl at ini@loaded}
 \newcommand\babeladjust[1]{%  TODO. Error handling.
-  \bbl at forkv{#1}{\bbl at cs{ADJ@##1@##2}}}
+  \bbl at forkv{#1}{%
+    \bbl at ifunset{bbl at ADJ@##1@##2}%
+      {\bbl at cs{ADJ@##1}{##2}}%
+      {\bbl at cs{ADJ@##1@##2}}}}
 \def\bbl at adjust@lua#1#2{%
   \ifvmode
     \ifnum\currentgrouplevel=\z@
@@ -2168,455 +3058,24 @@
   \bbl at adjust@layout{\let\list\bbl at OL@list}}
 \@namedef{bbl at ADJ@hyphenation.extra at on}{%
   \bbl at activateposthyphen}
-{\def\format{lplain}
-\ifx\fmtname\format
-\else
-  \def\format{LaTeX2e}
-  \ifx\fmtname\format
-  \else
-    \aftergroup\endinput
+\@namedef{bbl at ADJ@autoload.bcp47 at on}{%
+  \bbl at bcpallowedtrue}
+\@namedef{bbl at ADJ@autoload.bcp47 at off}{%
+  \bbl at bcpallowedfalse}
+\@namedef{bbl at ADJ@autoload.bcp47.prefix}#1{%
+  \def\bbl at bcp@prefix{#1}}
+\def\bbl at bcp@prefix{bcp47-}
+\@namedef{bbl at ADJ@autoload.options}#1{%
+  \def\bbl at autoload@options{#1}}
+\let\bbl at autoload@bcpoptions\@empty
+\@namedef{bbl at ADJ@autoload.bcp47.options}#1{%
+  \def\bbl at autoload@bcpoptions{#1}}
+\ifx\directlua\@undefined\else
+  \ifx\bbl at luapatterns\@undefined
+    \input luababel.def
   \fi
-\fi}
-\bbl at trace{Cross referencing macros}
-\ifx\bbl at opt@safe\@empty\else
-  \def\@newl at bel#1#2#3{%
-   {\@safe at activestrue
-    \bbl at ifunset{#1@#2}%
-       \relax
-       {\gdef\@multiplelabels{%
-          \@latex at warning@no at line{There were multiply-defined labels}}%
-        \@latex at warning@no at line{Label `#2' multiply defined}}%
-    \global\@namedef{#1@#2}{#3}}}
-  \CheckCommand*\@testdef[3]{%
-    \def\reserved at a{#3}%
-    \expandafter\ifx\csname#1@#2\endcsname\reserved at a
-    \else
-      \@tempswatrue
-    \fi}
-  \def\@testdef#1#2#3{%
-    \@safe at activestrue
-    \expandafter\let\expandafter\bbl at tempa\csname #1@#2\endcsname
-    \def\bbl at tempb{#3}%
-    \@safe at activesfalse
-    \ifx\bbl at tempa\relax
-    \else
-      \edef\bbl at tempa{\expandafter\strip at prefix\meaning\bbl at tempa}%
-    \fi
-    \edef\bbl at tempb{\expandafter\strip at prefix\meaning\bbl at tempb}%
-    \ifx\bbl at tempa\bbl at tempb
-    \else
-      \@tempswatrue
-    \fi}
 \fi
-\bbl at xin@{R}\bbl at opt@safe
-\ifin@
-  \bbl at redefinerobust\ref#1{%
-    \@safe at activestrue\org at ref{#1}\@safe at activesfalse}
-  \bbl at redefinerobust\pageref#1{%
-    \@safe at activestrue\org at pageref{#1}\@safe at activesfalse}
-\else
-  \let\org at ref\ref
-  \let\org at pageref\pageref
-\fi
-\bbl at xin@{B}\bbl at opt@safe
-\ifin@
-  \bbl at redefine\@citex[#1]#2{%
-    \@safe at activestrue\edef\@tempa{#2}\@safe at activesfalse
-    \org@@citex[#1]{\@tempa}}
-  \AtBeginDocument{%
-    \@ifpackageloaded{natbib}{%
-    \def\@citex[#1][#2]#3{%
-      \@safe at activestrue\edef\@tempa{#3}\@safe at activesfalse
-      \org@@citex[#1][#2]{\@tempa}}%
-    }{}}
-  \AtBeginDocument{%
-    \@ifpackageloaded{cite}{%
-      \def\@citex[#1]#2{%
-        \@safe at activestrue\org@@citex[#1]{#2}\@safe at activesfalse}%
-      }{}}
-  \bbl at redefine\nocite#1{%
-    \@safe at activestrue\org at nocite{#1}\@safe at activesfalse}
-  \bbl at redefine\bibcite{%
-    \bbl at cite@choice
-    \bibcite}
-  \def\bbl at bibcite#1#2{%
-    \org at bibcite{#1}{\@safe at activesfalse#2}}
-  \def\bbl at cite@choice{%
-    \global\let\bibcite\bbl at bibcite
-    \@ifpackageloaded{natbib}{\global\let\bibcite\org at bibcite}{}%
-    \@ifpackageloaded{cite}{\global\let\bibcite\org at bibcite}{}%
-    \global\let\bbl at cite@choice\relax}
-  \AtBeginDocument{\bbl at cite@choice}
-  \bbl at redefine\@bibitem#1{%
-    \@safe at activestrue\org@@bibitem{#1}\@safe at activesfalse}
-\else
-  \let\org at nocite\nocite
-  \let\org@@citex\@citex
-  \let\org at bibcite\bibcite
-  \let\org@@bibitem\@bibitem
-\fi
-\bbl at trace{Marks}
-\IfBabelLayout{sectioning}
-  {\ifx\bbl at opt@headfoot\@nnil
-     \g at addto@macro\@resetactivechars{%
-       \set at typeset@protect
-       \expandafter\select at language@x\expandafter{\bbl at main@language}%
-       \let\protect\noexpand
-       \edef\thepage{%
-         \noexpand\babelsublr{\unexpanded\expandafter{\thepage}}}}%
-   \fi}
-  {\ifbbl at single\else
-     \bbl at ifunset{markright }\bbl at redefine\bbl at redefinerobust
-     \markright#1{%
-       \bbl at ifblank{#1}%
-         {\org at markright{}}%
-         {\toks@{#1}%
-          \bbl at exp{%
-            \\\org at markright{\\\protect\\\foreignlanguage{\languagename}%
-              {\\\protect\\\bbl at restore@actives\the\toks@}}}}}%
-     \ifx\@mkboth\markboth
-       \def\bbl at tempc{\let\@mkboth\markboth}
-     \else
-       \def\bbl at tempc{}
-     \fi
-     \bbl at ifunset{markboth }\bbl at redefine\bbl at redefinerobust
-     \markboth#1#2{%
-       \protected at edef\bbl at tempb##1{%
-         \protect\foreignlanguage
-         {\languagename}{\protect\bbl at restore@actives##1}}%
-       \bbl at ifblank{#1}%
-         {\toks@{}}%
-         {\toks@\expandafter{\bbl at tempb{#1}}}%
-       \bbl at ifblank{#2}%
-         {\@temptokena{}}%
-         {\@temptokena\expandafter{\bbl at tempb{#2}}}%
-       \bbl at exp{\\\org at markboth{\the\toks@}{\the\@temptokena}}}
-       \bbl at tempc
-     \fi}  % end ifbbl at single, end \IfBabelLayout
-\bbl at trace{Preventing clashes with other packages}
-\bbl at xin@{R}\bbl at opt@safe
-\ifin@
-  \AtBeginDocument{%
-    \@ifpackageloaded{ifthen}{%
-      \bbl at redefine@long\ifthenelse#1#2#3{%
-        \let\bbl at temp@pref\pageref
-        \let\pageref\org at pageref
-        \let\bbl at temp@ref\ref
-        \let\ref\org at ref
-        \@safe at activestrue
-        \org at ifthenelse{#1}%
-          {\let\pageref\bbl at temp@pref
-           \let\ref\bbl at temp@ref
-           \@safe at activesfalse
-           #2}%
-          {\let\pageref\bbl at temp@pref
-           \let\ref\bbl at temp@ref
-           \@safe at activesfalse
-           #3}%
-        }%
-      }{}%
-    }
-  \AtBeginDocument{%
-    \@ifpackageloaded{varioref}{%
-      \bbl at redefine\@@vpageref#1[#2]#3{%
-        \@safe at activestrue
-        \org@@@vpageref{#1}[#2]{#3}%
-        \@safe at activesfalse}%
-      \bbl at redefine\vrefpagenum#1#2{%
-        \@safe at activestrue
-        \org at vrefpagenum{#1}{#2}%
-        \@safe at activesfalse}%
-      \expandafter\def\csname Ref \endcsname#1{%
-        \protected at edef\@tempa{\org at ref{#1}}\expandafter\MakeUppercase\@tempa}
-      }{}%
-    }
-\fi
-\AtEndOfPackage{%
-  \AtBeginDocument{%
-    \@ifpackageloaded{hhline}%
-      {\expandafter\ifx\csname normal at char\string:\endcsname\relax
-       \else
-         \makeatletter
-         \def\@currname{hhline}\input{hhline.sty}\makeatother
-       \fi}%
-      {}}}
-\AtBeginDocument{%
-  \ifx\pdfstringdefDisableCommands\@undefined\else
-    \pdfstringdefDisableCommands{\languageshorthands{system}}%
-  \fi}
-\DeclareRobustCommand{\FOREIGNLANGUAGE}[1]{%
-  \lowercase{\foreignlanguage{#1}}}
-\def\substitutefontfamily#1#2#3{%
-  \lowercase{\immediate\openout15=#1#2.fd\relax}%
-  \immediate\write15{%
-    \string\ProvidesFile{#1#2.fd}%
-    [\the\year/\two at digits{\the\month}/\two at digits{\the\day}
-     \space generated font description file]^^J
-    \string\DeclareFontFamily{#1}{#2}{}^^J
-    \string\DeclareFontShape{#1}{#2}{m}{n}{<->ssub * #3/m/n}{}^^J
-    \string\DeclareFontShape{#1}{#2}{m}{it}{<->ssub * #3/m/it}{}^^J
-    \string\DeclareFontShape{#1}{#2}{m}{sl}{<->ssub * #3/m/sl}{}^^J
-    \string\DeclareFontShape{#1}{#2}{m}{sc}{<->ssub * #3/m/sc}{}^^J
-    \string\DeclareFontShape{#1}{#2}{b}{n}{<->ssub * #3/bx/n}{}^^J
-    \string\DeclareFontShape{#1}{#2}{b}{it}{<->ssub * #3/bx/it}{}^^J
-    \string\DeclareFontShape{#1}{#2}{b}{sl}{<->ssub * #3/bx/sl}{}^^J
-    \string\DeclareFontShape{#1}{#2}{b}{sc}{<->ssub * #3/bx/sc}{}^^J
-    }%
-  \closeout15
-  }
-\@onlypreamble\substitutefontfamily
-\bbl at trace{Encoding and fonts}
-\newcommand\BabelNonASCII{LGR,X2,OT2,OT3,OT6,LHE,LWN,LMA,LMC,LMS,LMU,PU,PD1}
-\newcommand\BabelNonText{TS1,T3,TS3}
-\let\org at TeX\TeX
-\let\org at LaTeX\LaTeX
-\let\ensureascii\@firstofone
-\AtBeginDocument{%
-  \in at false
-  \bbl at foreach\BabelNonASCII{% is there a text non-ascii enc?
-    \ifin@\else
-      \lowercase{\bbl at xin@{,#1enc.def,}{,\@filelist,}}%
-    \fi}%
-  \ifin@ % if a text non-ascii has been loaded
-    \def\ensureascii#1{{\fontencoding{OT1}\selectfont#1}}%
-    \DeclareTextCommandDefault{\TeX}{\org at TeX}%
-    \DeclareTextCommandDefault{\LaTeX}{\org at LaTeX}%
-    \def\bbl at tempb#1\@@{\uppercase{\bbl at tempc#1}ENC.DEF\@empty\@@}%
-    \def\bbl at tempc#1ENC.DEF#2\@@{%
-      \ifx\@empty#2\else
-        \bbl at ifunset{T@#1}%
-          {}%
-          {\bbl at xin@{,#1,}{,\BabelNonASCII,\BabelNonText,}%
-           \ifin@
-             \DeclareTextCommand{\TeX}{#1}{\ensureascii{\org at TeX}}%
-             \DeclareTextCommand{\LaTeX}{#1}{\ensureascii{\org at LaTeX}}%
-           \else
-             \def\ensureascii##1{{\fontencoding{#1}\selectfont##1}}%
-           \fi}%
-      \fi}%
-    \bbl at foreach\@filelist{\bbl at tempb#1\@@}%  TODO - \@@ de mas??
-    \bbl at xin@{,\cf at encoding,}{,\BabelNonASCII,\BabelNonText,}%
-    \ifin@\else
-      \edef\ensureascii#1{{%
-        \noexpand\fontencoding{\cf at encoding}\noexpand\selectfont#1}}%
-    \fi
-  \fi}
-\AtEndOfPackage{\edef\latinencoding{\cf at encoding}}
-\AtBeginDocument{%
-  \@ifpackageloaded{fontspec}%
-    {\xdef\latinencoding{%
-       \ifx\UTFencname\@undefined
-         EU\ifcase\bbl at engine\or2\or1\fi
-       \else
-         \UTFencname
-       \fi}}%
-    {\gdef\latinencoding{OT1}%
-     \ifx\cf at encoding\bbl at t@one
-       \xdef\latinencoding{\bbl at t@one}%
-     \else
-       \ifx\@fontenc at load@list\@undefined
-         \@ifl at aded{def}{t1enc}{\xdef\latinencoding{\bbl at t@one}}{}%
-       \else
-         \def\@elt#1{,#1,}%
-         \edef\bbl at tempa{\expandafter\@gobbletwo\@fontenc at load@list}%
-         \let\@elt\relax
-         \bbl at xin@{,T1,}\bbl at tempa
-         \ifin@
-           \xdef\latinencoding{\bbl at t@one}%
-         \fi
-       \fi
-     \fi}}
-\DeclareRobustCommand{\latintext}{%
-  \fontencoding{\latinencoding}\selectfont
-  \def\encodingdefault{\latinencoding}}
-\ifx\@undefined\DeclareTextFontCommand
-  \DeclareRobustCommand{\textlatin}[1]{\leavevmode{\latintext #1}}
-\else
-  \DeclareTextFontCommand{\textlatin}{\latintext}
-\fi
-\bbl at trace{Basic (internal) bidi support}
-\def\bbl at alscripts{,Arabic,Syriac,Thaana,}
-\def\bbl at rscripts{%
-  ,Imperial Aramaic,Avestan,Cypriot,Hatran,Hebrew,%
-  Old Hungarian,Old Hungarian,Lydian,Mandaean,Manichaean,%
-  Manichaean,Meroitic Cursive,Meroitic,Old North Arabian,%
-  Nabataean,N'Ko,Orkhon,Palmyrene,Inscriptional Pahlavi,%
-  Psalter Pahlavi,Phoenician,Inscriptional Parthian,Samaritan,%
-  Old South Arabian,}%
-\def\bbl at provide@dirs#1{%
-  \bbl at xin@{\csname bbl at sname@#1\endcsname}{\bbl at alscripts\bbl at rscripts}%
-  \ifin@
-    \global\bbl at csarg\chardef{wdir@#1}\@ne
-    \bbl at xin@{\csname bbl at sname@#1\endcsname}{\bbl at alscripts}%
-    \ifin@
-      \global\bbl at csarg\chardef{wdir@#1}\tw@  % useless in xetex
-    \fi
-  \else
-    \global\bbl at csarg\chardef{wdir@#1}\z@
-  \fi
-  \ifodd\bbl at engine
-    \bbl at csarg\ifcase{wdir@#1}%
-      \directlua{ Babel.locale_props[\the\localeid].textdir = 'l' }%
-    \or
-      \directlua{ Babel.locale_props[\the\localeid].textdir = 'r' }%
-    \or
-      \directlua{ Babel.locale_props[\the\localeid].textdir = 'al' }%
-    \fi
-  \fi}
-\def\bbl at switchdir{%
-  \bbl at ifunset{bbl at lsys@\languagename}{\bbl at provide@lsys{\languagename}}{}%
-  \bbl at ifunset{bbl at wdir@\languagename}{\bbl at provide@dirs{\languagename}}{}%
-  \bbl at exp{\\\bbl at setdirs\bbl at cl{wdir}}}
-\def\bbl at setdirs#1{% TODO - math
-  \ifcase\bbl at select@type % TODO - strictly, not the right test
-    \bbl at bodydir{#1}%
-    \bbl at pardir{#1}%
-  \fi
-  \bbl at textdir{#1}}
-\ifodd\bbl at engine  % luatex=1
-  \AddBabelHook{babel-bidi}{afterextras}{\bbl at switchdir}
-  \DisableBabelHook{babel-bidi}
-  \chardef\bbl at thetextdir\z@
-  \chardef\bbl at thepardir\z@
-  \def\bbl at getluadir#1{%
-    \directlua{
-      if tex.#1dir == 'TLT' then
-        tex.sprint('0')
-      elseif tex.#1dir == 'TRT' then
-        tex.sprint('1')
-      end}}
-  \def\bbl at setluadir#1#2#3{% 1=text/par.. 2=\textdir.. 3=0 lr/1 rl
-    \ifcase#3\relax
-      \ifcase\bbl at getluadir{#1}\relax\else
-        #2 TLT\relax
-      \fi
-    \else
-      \ifcase\bbl at getluadir{#1}\relax
-        #2 TRT\relax
-      \fi
-    \fi}
-  \def\bbl at textdir#1{%
-    \bbl at setluadir{text}\textdir{#1}%
-    \chardef\bbl at thetextdir#1\relax
-    \setattribute\bbl at attr@dir{\numexpr\bbl at thepardir*3+#1}}
-  \def\bbl at pardir#1{%
-    \bbl at setluadir{par}\pardir{#1}%
-    \chardef\bbl at thepardir#1\relax}
-  \def\bbl at bodydir{\bbl at setluadir{body}\bodydir}
-  \def\bbl at pagedir{\bbl at setluadir{page}\pagedir}
-  \def\bbl at dirparastext{\pardir\the\textdir\relax}%   %%%%
-  % Sadly, we have to deal with boxes in math with basic.
-  % Activated every math with the package option bidi=:
-  \def\bbl at mathboxdir{%
-    \ifcase\bbl at thetextdir\relax
-      \everyhbox{\textdir TLT\relax}%
-    \else
-      \everyhbox{\textdir TRT\relax}%
-    \fi}
-\else % pdftex=0, xetex=2
-  \AddBabelHook{babel-bidi}{afterextras}{\bbl at switchdir}
-  \DisableBabelHook{babel-bidi}
-  \newcount\bbl at dirlevel
-  \chardef\bbl at thetextdir\z@
-  \chardef\bbl at thepardir\z@
-  \def\bbl at textdir#1{%
-    \ifcase#1\relax
-       \chardef\bbl at thetextdir\z@
-       \bbl at textdir@i\beginL\endL
-     \else
-       \chardef\bbl at thetextdir\@ne
-       \bbl at textdir@i\beginR\endR
-    \fi}
-  \def\bbl at textdir@i#1#2{%
-    \ifhmode
-      \ifnum\currentgrouplevel>\z@
-        \ifnum\currentgrouplevel=\bbl at dirlevel
-          \bbl at error{Multiple bidi settings inside a group}%
-            {I'll insert a new group, but expect wrong results.}%
-          \bgroup\aftergroup#2\aftergroup\egroup
-        \else
-          \ifcase\currentgrouptype\or % 0 bottom
-            \aftergroup#2% 1 simple {}
-          \or
-            \bgroup\aftergroup#2\aftergroup\egroup % 2 hbox
-          \or
-            \bgroup\aftergroup#2\aftergroup\egroup % 3 adj hbox
-          \or\or\or % vbox vtop align
-          \or
-            \bgroup\aftergroup#2\aftergroup\egroup % 7 noalign
-          \or\or\or\or\or\or % output math disc insert vcent mathchoice
-          \or
-            \aftergroup#2% 14 \begingroup
-          \else
-            \bgroup\aftergroup#2\aftergroup\egroup % 15 adj
-          \fi
-        \fi
-        \bbl at dirlevel\currentgrouplevel
-      \fi
-      #1%
-    \fi}
-  \def\bbl at pardir#1{\chardef\bbl at thepardir#1\relax}
-  \let\bbl at bodydir\@gobble
-  \let\bbl at pagedir\@gobble
-  \def\bbl at dirparastext{\chardef\bbl at thepardir\bbl at thetextdir}
-  \def\bbl at xebidipar{%
-    \let\bbl at xebidipar\relax
-    \TeXXeTstate\@ne
-    \def\bbl at xeeverypar{%
-      \ifcase\bbl at thepardir
-        \ifcase\bbl at thetextdir\else\beginR\fi
-      \else
-        {\setbox\z@\lastbox\beginR\box\z@}%
-      \fi}%
-    \let\bbl at severypar\everypar
-    \newtoks\everypar
-    \everypar=\bbl at severypar
-    \bbl at severypar{\bbl at xeeverypar\the\everypar}}
-  \def\bbl at tempb{%
-    \let\bbl at textdir@i\@gobbletwo
-    \let\bbl at xebidipar\@empty
-    \AddBabelHook{bidi}{foreign}{%
-      \def\bbl at tempa{\def\BabelText########1}%
-      \ifcase\bbl at thetextdir
-        \expandafter\bbl at tempa\expandafter{\BabelText{\LR{####1}}}%
-      \else
-        \expandafter\bbl at tempa\expandafter{\BabelText{\RL{####1}}}%
-      \fi}
-    \def\bbl at pardir##1{\ifcase##1\relax\setLR\else\setRL\fi}}
-  \@ifpackagewith{babel}{bidi=bidi}{\bbl at tempb}{}%
-  \@ifpackagewith{babel}{bidi=bidi-l}{\bbl at tempb}{}%
-  \@ifpackagewith{babel}{bidi=bidi-r}{\bbl at tempb}{}%
-\fi
-\DeclareRobustCommand\babelsublr[1]{\leavevmode{\bbl at textdir\z@#1}}
-\AtBeginDocument{%
-  \ifx\pdfstringdefDisableCommands\@undefined\else
-    \ifx\pdfstringdefDisableCommands\relax\else
-      \pdfstringdefDisableCommands{\let\babelsublr\@firstofone}%
-    \fi
-  \fi}
-\bbl at trace{Local Language Configuration}
-\ifx\loadlocalcfg\@undefined
-  \@ifpackagewith{babel}{noconfigs}%
-    {\let\loadlocalcfg\@gobble}%
-    {\def\loadlocalcfg#1{%
-      \InputIfFileExists{#1.cfg}%
-        {\typeout{*************************************^^J%
-                       * Local config file #1.cfg used^^J%
-                       *}}%
-        \@empty}}
-\fi
-\ifx\@unexpandable at protect\@undefined
-  \def\@unexpandable at protect{\noexpand\protect\noexpand}
-  \long\def\protected at write#1#2#3{%
-    \begingroup
-      \let\thepage\relax
-      #2%
-      \let\protect\@unexpandable at protect
-      \edef\reserved at a{\write#1{#3}}%
-      \reserved at a
-    \endgroup
-    \if at nobreak\ifvmode\nobreak\fi\fi}
-\fi
+
 \endinput
 %%
 %% End of file `babel.def'.

Modified: trunk/Master/texmf-dist/tex/generic/babel/babel.sty
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/babel.sty	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/tex/generic/babel/babel.sty	2020-04-28 21:14:00 UTC (rev 54930)
@@ -33,21 +33,12 @@
 %%
 
 \NeedsTeXFormat{LaTeX2e}[2005/12/01]
-\ProvidesPackage{babel}[2020/03/22 3.42 The Babel package]
+\ProvidesPackage{babel}[2020/04/28 3.43 The Babel package]
 \@ifpackagewith{babel}{debug}
   {\providecommand\bbl at trace[1]{\message{^^J[ #1 ]}}%
    \let\bbl at debug\@firstofone}
   {\providecommand\bbl at trace[1]{}%
    \let\bbl at debug\@gobble}
-\ifx\bbl at switchflag\@undefined % Prevent double input
-  \let\bbl at switchflag\relax
-  \input switch.def\relax
-\fi
-\ifx\directlua\@undefined\else
-  \ifx\bbl at luapatterns\@undefined
-    \input luababel.def
-  \fi
-\fi
 \bbl at trace{Basic macros}
 \def\bbl at stripslash{\expandafter\@gobble\string}
 \def\bbl at add#1#2{%
@@ -196,6 +187,64 @@
   \else
     \@ne
   \fi
+  % Temporarily repeat here the code for errors
+  \def\bbl at error#1#2{%
+    \begingroup
+      \def\\{\MessageBreak}%
+      \PackageError{babel}{#1}{#2}%
+    \endgroup}
+  \def\bbl at warning#1{%
+    \begingroup
+      \def\\{\MessageBreak}%
+      \PackageWarning{babel}{#1}%
+    \endgroup}
+  \def\bbl at infowarn#1{%
+    \begingroup
+      \def\\{\MessageBreak}%
+      \GenericWarning
+        {(babel) \@spaces\@spaces\@spaces}%
+        {Package babel Info: #1}%
+    \endgroup}
+  \def\bbl at info#1{%
+    \begingroup
+      \def\\{\MessageBreak}%
+      \PackageInfo{babel}{#1}%
+    \endgroup}
+    \def\bbl at nocaption{\protect\bbl at nocaption@i}
+\def\bbl at nocaption@i#1#2{% 1: text to be printed 2: caption macro \langXname
+  \global\@namedef{#2}{\textbf{?#1?}}%
+  \@nameuse{#2}%
+  \bbl at warning{%
+    \@backslashchar#2 not set. Please, define\\%
+    it in the preamble with something like:\\%
+    \string\renewcommand\@backslashchar#2{..}\\%
+    Reported}}
+\def\bbl at tentative{\protect\bbl at tentative@i}
+\def\bbl at tentative@i#1{%
+  \bbl at warning{%
+    Some functions for '#1' are tentative.\\%
+    They might not work as expected and their behavior\\%
+    could change in the future.\\%
+    Reported}}
+\def\@nolanerr#1{%
+  \bbl at error
+    {You haven't defined the language #1\space yet.\\%
+     Perhaps you misspelled it or your installation\\%
+     is not complete}%
+    {Your command will be ignored, type <return> to proceed}}
+\def\@nopatterns#1{%
+  \bbl at warning
+    {No hyphenation patterns were preloaded for\\%
+     the language `#1' into the format.\\%
+     Please, configure your TeX system to add them and\\%
+     rebuild the format. Now I will use the patterns\\%
+     preloaded for \bbl at nulllanguage\space instead}}
+    % End of errors
+\@ifpackagewith{babel}{silent}
+  {\let\bbl at info\@gobble
+   \let\bbl at infowarn\@gobble
+   \let\bbl at warning\@gobble}
+  {}
 \def\AfterBabelLanguage#1{%
   \global\expandafter\bbl at add\csname#1.ldf-h@@k\endcsname}%
 \ifx\bbl at languages\@undefined\else
@@ -215,7 +264,27 @@
       \def\bbl at elt##1##2##3##4{}%
     \fi}%
   \bbl at languages
-\fi
+\fi%
+\bbl at trace{Defining option 'base'}
+\@ifpackagewith{babel}{base}{%
+  \let\bbl at onlyswitch\@empty
+  \let\bbl at provide@locale\relax
+  \input babel.def
+  \let\bbl at onlyswitch\@undefined
+  \ifx\directlua\@undefined
+    \DeclareOption*{\bbl at patterns{\CurrentOption}}%
+  \else
+    \input luababel.def
+    \DeclareOption*{\bbl at patterns@lua{\CurrentOption}}%
+  \fi
+  \DeclareOption{base}{}%
+  \DeclareOption{showlanguages}{}%
+  \ProcessOptions
+  \global\expandafter\let\csname opt at babel.sty\endcsname\relax
+  \global\expandafter\let\csname ver at babel.sty\endcsname\relax
+  \global\let\@ifl at ter@@\@ifl at ter
+  \def\@ifl at ter#1#2#3#4#5{\global\let\@ifl at ter\@ifl at ter@@}%
+  \endinput}{}%
 \ifodd\bbl at engine
   \def\bbl at activate@preotf{%
     \let\bbl at activate@preotf\relax  % only once
@@ -271,21 +340,6 @@
     \bbl at activate@preotf
   \fi
 \fi
-\bbl at trace{Defining option 'base'}
-\@ifpackagewith{babel}{base}{%
-  \ifx\directlua\@undefined
-    \DeclareOption*{\bbl at patterns{\CurrentOption}}%
-  \else
-    \DeclareOption*{\bbl at patterns@lua{\CurrentOption}}%
-  \fi
-  \DeclareOption{base}{}%
-  \DeclareOption{showlanguages}{}%
-  \ProcessOptions
-  \global\expandafter\let\csname opt at babel.sty\endcsname\relax
-  \global\expandafter\let\csname ver at babel.sty\endcsname\relax
-  \global\let\@ifl at ter@@\@ifl at ter
-  \def\@ifl at ter#1#2#3#4#5{\global\let\@ifl at ter\@ifl at ter@@}%
-  \endinput}{}%
 \bbl at trace{key=value and another general options}
 \bbl at csarg\let{tempa\expandafter}\csname opt at babel.sty\endcsname
 \def\bbl at tempb#1.#2{%
@@ -315,6 +369,9 @@
 \DeclareOption{shorthands=off}{\bbl at tempa shorthands=\bbl at tempa}
 \newif\ifbbl at single
 \DeclareOption{selectors=off}{\bbl at singletrue}
+\DeclareOption{safe=none}{\let\bbl at opt@safe\@empty}
+\DeclareOption{safe=bib}{\def\bbl at opt@safe{B}}
+\DeclareOption{safe=ref}{\def\bbl at opt@safe{R}}
 \DeclareOption{math=active}{}
 \DeclareOption{math=normal}{\def\bbl at mathnormal{\noexpand\textormath}}
 \DeclareOption{nocase}{}
@@ -327,9 +384,6 @@
 \DeclareOption{hyphenmap=select}{\chardef\bbl at opt@hyphenmap\tw@}
 \DeclareOption{hyphenmap=other}{\chardef\bbl at opt@hyphenmap\thr@@}
 \DeclareOption{hyphenmap=other*}{\chardef\bbl at opt@hyphenmap4\relax}
-\DeclareOption{safe=none}{\let\bbl at opt@safe\@empty}
-\DeclareOption{safe=bib}{\def\bbl at opt@safe{B}}
-\DeclareOption{safe=ref}{\def\bbl at opt@safe{R}}
 \ifodd\bbl at engine
   \DeclareOption{bidi=basic-r}%
     {\ExecuteOptions{bidi=basic}}
@@ -396,11 +450,12 @@
   \bbl at csarg\ifx{opt@#1}\@nnil
     \bbl at csarg\edef{opt@#1}{#2}%
   \else
-    \bbl at error{%
-      Bad option `#1=#2'. Either you have misspelled the\\%
-      key or there is a previous setting of `#1'}{%
-      Valid keys are `shorthands', `config', `strings', `main',\\%
-      `headfoot', `safe', `math', among others.}
+    \bbl at error
+     {Bad option `#1=#2'. Either you have misspelled the\\%
+      key or there is a previous setting of `#1'. Valid\\%
+      keys are, among others, `shorthands', `main', `bidi',\\%
+      `strings', `config', `headfoot', `safe', `math'.}%
+     {See the manual for further details.}
   \fi}
 \let\bbl at language@opts\@empty
 \DeclareOption*{%
@@ -465,6 +520,447 @@
       \expandafter\@secondoftwo
     \fi}
 \fi
+\input babel.def
+\bbl at trace{Cross referencing macros}
+\ifx\bbl at opt@safe\@empty\else
+  \def\@newl at bel#1#2#3{%
+   {\@safe at activestrue
+    \bbl at ifunset{#1@#2}%
+       \relax
+       {\gdef\@multiplelabels{%
+          \@latex at warning@no at line{There were multiply-defined labels}}%
+        \@latex at warning@no at line{Label `#2' multiply defined}}%
+    \global\@namedef{#1@#2}{#3}}}
+  \CheckCommand*\@testdef[3]{%
+    \def\reserved at a{#3}%
+    \expandafter\ifx\csname#1@#2\endcsname\reserved at a
+    \else
+      \@tempswatrue
+    \fi}
+  \def\@testdef#1#2#3{%  TODO. With @samestring?
+    \@safe at activestrue
+    \expandafter\let\expandafter\bbl at tempa\csname #1@#2\endcsname
+    \def\bbl at tempb{#3}%
+    \@safe at activesfalse
+    \ifx\bbl at tempa\relax
+    \else
+      \edef\bbl at tempa{\expandafter\strip at prefix\meaning\bbl at tempa}%
+    \fi
+    \edef\bbl at tempb{\expandafter\strip at prefix\meaning\bbl at tempb}%
+    \ifx\bbl at tempa\bbl at tempb
+    \else
+      \@tempswatrue
+    \fi}
+\fi
+\bbl at xin@{R}\bbl at opt@safe
+\ifin@
+  \bbl at redefinerobust\ref#1{%
+    \@safe at activestrue\org at ref{#1}\@safe at activesfalse}
+  \bbl at redefinerobust\pageref#1{%
+    \@safe at activestrue\org at pageref{#1}\@safe at activesfalse}
+\else
+  \let\org at ref\ref
+  \let\org at pageref\pageref
+\fi
+\bbl at xin@{B}\bbl at opt@safe
+\ifin@
+  \bbl at redefine\@citex[#1]#2{%
+    \@safe at activestrue\edef\@tempa{#2}\@safe at activesfalse
+    \org@@citex[#1]{\@tempa}}
+  \AtBeginDocument{%
+    \@ifpackageloaded{natbib}{%
+    \def\@citex[#1][#2]#3{%
+      \@safe at activestrue\edef\@tempa{#3}\@safe at activesfalse
+      \org@@citex[#1][#2]{\@tempa}}%
+    }{}}
+  \AtBeginDocument{%
+    \@ifpackageloaded{cite}{%
+      \def\@citex[#1]#2{%
+        \@safe at activestrue\org@@citex[#1]{#2}\@safe at activesfalse}%
+      }{}}
+  \bbl at redefine\nocite#1{%
+    \@safe at activestrue\org at nocite{#1}\@safe at activesfalse}
+  \bbl at redefine\bibcite{%
+    \bbl at cite@choice
+    \bibcite}
+  \def\bbl at bibcite#1#2{%
+    \org at bibcite{#1}{\@safe at activesfalse#2}}
+  \def\bbl at cite@choice{%
+    \global\let\bibcite\bbl at bibcite
+    \@ifpackageloaded{natbib}{\global\let\bibcite\org at bibcite}{}%
+    \@ifpackageloaded{cite}{\global\let\bibcite\org at bibcite}{}%
+    \global\let\bbl at cite@choice\relax}
+  \AtBeginDocument{\bbl at cite@choice}
+  \bbl at redefine\@bibitem#1{%
+    \@safe at activestrue\org@@bibitem{#1}\@safe at activesfalse}
+\else
+  \let\org at nocite\nocite
+  \let\org@@citex\@citex
+  \let\org at bibcite\bibcite
+  \let\org@@bibitem\@bibitem
+\fi
+\bbl at trace{Marks}
+\IfBabelLayout{sectioning}
+  {\ifx\bbl at opt@headfoot\@nnil
+     \g at addto@macro\@resetactivechars{%
+       \set at typeset@protect
+       \expandafter\select at language@x\expandafter{\bbl at main@language}%
+       \let\protect\noexpand
+       \edef\thepage{% TODO. Only with bidi. See also above
+         \noexpand\babelsublr{\unexpanded\expandafter{\thepage}}}}%
+   \fi}
+  {\ifbbl at single\else
+     \bbl at ifunset{markright }\bbl at redefine\bbl at redefinerobust
+     \markright#1{%
+       \bbl at ifblank{#1}%
+         {\org at markright{}}%
+         {\toks@{#1}%
+          \bbl at exp{%
+            \\\org at markright{\\\protect\\\foreignlanguage{\languagename}%
+              {\\\protect\\\bbl at restore@actives\the\toks@}}}}}%
+     \ifx\@mkboth\markboth
+       \def\bbl at tempc{\let\@mkboth\markboth}
+     \else
+       \def\bbl at tempc{}
+     \fi
+     \bbl at ifunset{markboth }\bbl at redefine\bbl at redefinerobust
+     \markboth#1#2{%
+       \protected at edef\bbl at tempb##1{%
+         \protect\foreignlanguage
+         {\languagename}{\protect\bbl at restore@actives##1}}%
+       \bbl at ifblank{#1}%
+         {\toks@{}}%
+         {\toks@\expandafter{\bbl at tempb{#1}}}%
+       \bbl at ifblank{#2}%
+         {\@temptokena{}}%
+         {\@temptokena\expandafter{\bbl at tempb{#2}}}%
+       \bbl at exp{\\\org at markboth{\the\toks@}{\the\@temptokena}}}
+       \bbl at tempc
+     \fi}  % end ifbbl at single, end \IfBabelLayout
+\bbl at trace{Preventing clashes with other packages}
+\bbl at xin@{R}\bbl at opt@safe
+\ifin@
+  \AtBeginDocument{%
+    \@ifpackageloaded{ifthen}{%
+      \bbl at redefine@long\ifthenelse#1#2#3{%
+        \let\bbl at temp@pref\pageref
+        \let\pageref\org at pageref
+        \let\bbl at temp@ref\ref
+        \let\ref\org at ref
+        \@safe at activestrue
+        \org at ifthenelse{#1}%
+          {\let\pageref\bbl at temp@pref
+           \let\ref\bbl at temp@ref
+           \@safe at activesfalse
+           #2}%
+          {\let\pageref\bbl at temp@pref
+           \let\ref\bbl at temp@ref
+           \@safe at activesfalse
+           #3}%
+        }%
+      }{}%
+    }
+  \AtBeginDocument{%
+    \@ifpackageloaded{varioref}{%
+      \bbl at redefine\@@vpageref#1[#2]#3{%
+        \@safe at activestrue
+        \org@@@vpageref{#1}[#2]{#3}%
+        \@safe at activesfalse}%
+      \bbl at redefine\vrefpagenum#1#2{%
+        \@safe at activestrue
+        \org at vrefpagenum{#1}{#2}%
+        \@safe at activesfalse}%
+      \expandafter\def\csname Ref \endcsname#1{%
+        \protected at edef\@tempa{\org at ref{#1}}\expandafter\MakeUppercase\@tempa}
+      }{}%
+    }
+\fi
+\AtEndOfPackage{%
+  \AtBeginDocument{%
+    \@ifpackageloaded{hhline}%
+      {\expandafter\ifx\csname normal at char\string:\endcsname\relax
+       \else
+         \makeatletter
+         \def\@currname{hhline}\input{hhline.sty}\makeatother
+       \fi}%
+      {}}}
+\AtBeginDocument{%
+  \ifx\pdfstringdefDisableCommands\@undefined\else
+    \pdfstringdefDisableCommands{\languageshorthands{system}}%
+  \fi}
+\DeclareRobustCommand{\FOREIGNLANGUAGE}[1]{%
+  \lowercase{\foreignlanguage{#1}}}
+\def\substitutefontfamily#1#2#3{%
+  \lowercase{\immediate\openout15=#1#2.fd\relax}%
+  \immediate\write15{%
+    \string\ProvidesFile{#1#2.fd}%
+    [\the\year/\two at digits{\the\month}/\two at digits{\the\day}
+     \space generated font description file]^^J
+    \string\DeclareFontFamily{#1}{#2}{}^^J
+    \string\DeclareFontShape{#1}{#2}{m}{n}{<->ssub * #3/m/n}{}^^J
+    \string\DeclareFontShape{#1}{#2}{m}{it}{<->ssub * #3/m/it}{}^^J
+    \string\DeclareFontShape{#1}{#2}{m}{sl}{<->ssub * #3/m/sl}{}^^J
+    \string\DeclareFontShape{#1}{#2}{m}{sc}{<->ssub * #3/m/sc}{}^^J
+    \string\DeclareFontShape{#1}{#2}{b}{n}{<->ssub * #3/bx/n}{}^^J
+    \string\DeclareFontShape{#1}{#2}{b}{it}{<->ssub * #3/bx/it}{}^^J
+    \string\DeclareFontShape{#1}{#2}{b}{sl}{<->ssub * #3/bx/sl}{}^^J
+    \string\DeclareFontShape{#1}{#2}{b}{sc}{<->ssub * #3/bx/sc}{}^^J
+    }%
+  \closeout15
+  }
+\@onlypreamble\substitutefontfamily
+\bbl at trace{Encoding and fonts}
+\newcommand\BabelNonASCII{LGR,X2,OT2,OT3,OT6,LHE,LWN,LMA,LMC,LMS,LMU,PU,PD1}
+\newcommand\BabelNonText{TS1,T3,TS3}
+\let\org at TeX\TeX
+\let\org at LaTeX\LaTeX
+\let\ensureascii\@firstofone
+\AtBeginDocument{%
+  \in at false
+  \bbl at foreach\BabelNonASCII{% is there a text non-ascii enc?
+    \ifin@\else
+      \lowercase{\bbl at xin@{,#1enc.def,}{,\@filelist,}}%
+    \fi}%
+  \ifin@ % if a text non-ascii has been loaded
+    \def\ensureascii#1{{\fontencoding{OT1}\selectfont#1}}%
+    \DeclareTextCommandDefault{\TeX}{\org at TeX}%
+    \DeclareTextCommandDefault{\LaTeX}{\org at LaTeX}%
+    \def\bbl at tempb#1\@@{\uppercase{\bbl at tempc#1}ENC.DEF\@empty\@@}%
+    \def\bbl at tempc#1ENC.DEF#2\@@{%
+      \ifx\@empty#2\else
+        \bbl at ifunset{T@#1}%
+          {}%
+          {\bbl at xin@{,#1,}{,\BabelNonASCII,\BabelNonText,}%
+           \ifin@
+             \DeclareTextCommand{\TeX}{#1}{\ensureascii{\org at TeX}}%
+             \DeclareTextCommand{\LaTeX}{#1}{\ensureascii{\org at LaTeX}}%
+           \else
+             \def\ensureascii##1{{\fontencoding{#1}\selectfont##1}}%
+           \fi}%
+      \fi}%
+    \bbl at foreach\@filelist{\bbl at tempb#1\@@}%  TODO - \@@ de mas??
+    \bbl at xin@{,\cf at encoding,}{,\BabelNonASCII,\BabelNonText,}%
+    \ifin@\else
+      \edef\ensureascii#1{{%
+        \noexpand\fontencoding{\cf at encoding}\noexpand\selectfont#1}}%
+    \fi
+  \fi}
+\AtEndOfPackage{\edef\latinencoding{\cf at encoding}}
+\AtBeginDocument{%
+  \@ifpackageloaded{fontspec}%
+    {\xdef\latinencoding{%
+       \ifx\UTFencname\@undefined
+         EU\ifcase\bbl at engine\or2\or1\fi
+       \else
+         \UTFencname
+       \fi}}%
+    {\gdef\latinencoding{OT1}%
+     \ifx\cf at encoding\bbl at t@one
+       \xdef\latinencoding{\bbl at t@one}%
+     \else
+       \ifx\@fontenc at load@list\@undefined
+         \@ifl at aded{def}{t1enc}{\xdef\latinencoding{\bbl at t@one}}{}%
+       \else
+         \def\@elt#1{,#1,}%
+         \edef\bbl at tempa{\expandafter\@gobbletwo\@fontenc at load@list}%
+         \let\@elt\relax
+         \bbl at xin@{,T1,}\bbl at tempa
+         \ifin@
+           \xdef\latinencoding{\bbl at t@one}%
+         \fi
+       \fi
+     \fi}}
+\DeclareRobustCommand{\latintext}{%
+  \fontencoding{\latinencoding}\selectfont
+  \def\encodingdefault{\latinencoding}}
+\ifx\@undefined\DeclareTextFontCommand
+  \DeclareRobustCommand{\textlatin}[1]{\leavevmode{\latintext #1}}
+\else
+  \DeclareTextFontCommand{\textlatin}{\latintext}
+\fi
+\bbl at trace{Basic (internal) bidi support}
+\def\bbl at alscripts{,Arabic,Syriac,Thaana,}
+\def\bbl at rscripts{%
+  ,Imperial Aramaic,Avestan,Cypriot,Hatran,Hebrew,%
+  Old Hungarian,Old Hungarian,Lydian,Mandaean,Manichaean,%
+  Manichaean,Meroitic Cursive,Meroitic,Old North Arabian,%
+  Nabataean,N'Ko,Orkhon,Palmyrene,Inscriptional Pahlavi,%
+  Psalter Pahlavi,Phoenician,Inscriptional Parthian,Samaritan,%
+  Old South Arabian,}%
+\def\bbl at provide@dirs#1{%
+  \bbl at xin@{\csname bbl at sname@#1\endcsname}{\bbl at alscripts\bbl at rscripts}%
+  \ifin@
+    \global\bbl at csarg\chardef{wdir@#1}\@ne
+    \bbl at xin@{\csname bbl at sname@#1\endcsname}{\bbl at alscripts}%
+    \ifin@
+      \global\bbl at csarg\chardef{wdir@#1}\tw@  % useless in xetex
+    \fi
+  \else
+    \global\bbl at csarg\chardef{wdir@#1}\z@
+  \fi
+  \ifodd\bbl at engine
+    \bbl at csarg\ifcase{wdir@#1}%
+      \directlua{ Babel.locale_props[\the\localeid].textdir = 'l' }%
+    \or
+      \directlua{ Babel.locale_props[\the\localeid].textdir = 'r' }%
+    \or
+      \directlua{ Babel.locale_props[\the\localeid].textdir = 'al' }%
+    \fi
+  \fi}
+\def\bbl at switchdir{%
+  \bbl at ifunset{bbl at lsys@\languagename}{\bbl at provide@lsys{\languagename}}{}%
+  \bbl at ifunset{bbl at wdir@\languagename}{\bbl at provide@dirs{\languagename}}{}%
+  \bbl at exp{\\\bbl at setdirs\bbl at cl{wdir}}}
+\def\bbl at setdirs#1{% TODO - math
+  \ifcase\bbl at select@type % TODO - strictly, not the right test
+    \bbl at bodydir{#1}%
+    \bbl at pardir{#1}%
+  \fi
+  \bbl at textdir{#1}}
+\ifodd\bbl at engine  % luatex=1
+  \AddBabelHook{babel-bidi}{afterextras}{\bbl at switchdir}
+  \DisableBabelHook{babel-bidi}
+  \chardef\bbl at thetextdir\z@
+  \chardef\bbl at thepardir\z@
+  \def\bbl at getluadir#1{%
+    \directlua{
+      if tex.#1dir == 'TLT' then
+        tex.sprint('0')
+      elseif tex.#1dir == 'TRT' then
+        tex.sprint('1')
+      end}}
+  \def\bbl at setluadir#1#2#3{% 1=text/par.. 2=\textdir.. 3=0 lr/1 rl
+    \ifcase#3\relax
+      \ifcase\bbl at getluadir{#1}\relax\else
+        #2 TLT\relax
+      \fi
+    \else
+      \ifcase\bbl at getluadir{#1}\relax
+        #2 TRT\relax
+      \fi
+    \fi}
+  \def\bbl at textdir#1{%
+    \bbl at setluadir{text}\textdir{#1}%
+    \chardef\bbl at thetextdir#1\relax
+    \setattribute\bbl at attr@dir{\numexpr\bbl at thepardir*3+#1}}
+  \def\bbl at pardir#1{%
+    \bbl at setluadir{par}\pardir{#1}%
+    \chardef\bbl at thepardir#1\relax}
+  \def\bbl at bodydir{\bbl at setluadir{body}\bodydir}
+  \def\bbl at pagedir{\bbl at setluadir{page}\pagedir}
+  \def\bbl at dirparastext{\pardir\the\textdir\relax}%   %%%%
+  % Sadly, we have to deal with boxes in math with basic.
+  % Activated every math with the package option bidi=:
+  \def\bbl at mathboxdir{%
+    \ifcase\bbl at thetextdir\relax
+      \everyhbox{\textdir TLT\relax}%
+    \else
+      \everyhbox{\textdir TRT\relax}%
+    \fi}
+\else % pdftex=0, xetex=2
+  \AddBabelHook{babel-bidi}{afterextras}{\bbl at switchdir}
+  \DisableBabelHook{babel-bidi}
+  \newcount\bbl at dirlevel
+  \chardef\bbl at thetextdir\z@
+  \chardef\bbl at thepardir\z@
+  \def\bbl at textdir#1{%
+    \ifcase#1\relax
+       \chardef\bbl at thetextdir\z@
+       \bbl at textdir@i\beginL\endL
+     \else
+       \chardef\bbl at thetextdir\@ne
+       \bbl at textdir@i\beginR\endR
+    \fi}
+  \def\bbl at textdir@i#1#2{%
+    \ifhmode
+      \ifnum\currentgrouplevel>\z@
+        \ifnum\currentgrouplevel=\bbl at dirlevel
+          \bbl at error{Multiple bidi settings inside a group}%
+            {I'll insert a new group, but expect wrong results.}%
+          \bgroup\aftergroup#2\aftergroup\egroup
+        \else
+          \ifcase\currentgrouptype\or % 0 bottom
+            \aftergroup#2% 1 simple {}
+          \or
+            \bgroup\aftergroup#2\aftergroup\egroup % 2 hbox
+          \or
+            \bgroup\aftergroup#2\aftergroup\egroup % 3 adj hbox
+          \or\or\or % vbox vtop align
+          \or
+            \bgroup\aftergroup#2\aftergroup\egroup % 7 noalign
+          \or\or\or\or\or\or % output math disc insert vcent mathchoice
+          \or
+            \aftergroup#2% 14 \begingroup
+          \else
+            \bgroup\aftergroup#2\aftergroup\egroup % 15 adj
+          \fi
+        \fi
+        \bbl at dirlevel\currentgrouplevel
+      \fi
+      #1%
+    \fi}
+  \def\bbl at pardir#1{\chardef\bbl at thepardir#1\relax}
+  \let\bbl at bodydir\@gobble
+  \let\bbl at pagedir\@gobble
+  \def\bbl at dirparastext{\chardef\bbl at thepardir\bbl at thetextdir}
+  \def\bbl at xebidipar{%
+    \let\bbl at xebidipar\relax
+    \TeXXeTstate\@ne
+    \def\bbl at xeeverypar{%
+      \ifcase\bbl at thepardir
+        \ifcase\bbl at thetextdir\else\beginR\fi
+      \else
+        {\setbox\z@\lastbox\beginR\box\z@}%
+      \fi}%
+    \let\bbl at severypar\everypar
+    \newtoks\everypar
+    \everypar=\bbl at severypar
+    \bbl at severypar{\bbl at xeeverypar\the\everypar}}
+  \def\bbl at tempb{%
+    \let\bbl at textdir@i\@gobbletwo
+    \let\bbl at xebidipar\@empty
+    \AddBabelHook{bidi}{foreign}{%
+      \def\bbl at tempa{\def\BabelText########1}%
+      \ifcase\bbl at thetextdir
+        \expandafter\bbl at tempa\expandafter{\BabelText{\LR{####1}}}%
+      \else
+        \expandafter\bbl at tempa\expandafter{\BabelText{\RL{####1}}}%
+      \fi}
+    \def\bbl at pardir##1{\ifcase##1\relax\setLR\else\setRL\fi}}
+  \@ifpackagewith{babel}{bidi=bidi}{\bbl at tempb}{}%
+  \@ifpackagewith{babel}{bidi=bidi-l}{\bbl at tempb}{}%
+  \@ifpackagewith{babel}{bidi=bidi-r}{\bbl at tempb}{}%
+\fi
+\DeclareRobustCommand\babelsublr[1]{\leavevmode{\bbl at textdir\z@#1}}
+\AtBeginDocument{%
+  \ifx\pdfstringdefDisableCommands\@undefined\else
+    \ifx\pdfstringdefDisableCommands\relax\else
+      \pdfstringdefDisableCommands{\let\babelsublr\@firstofone}%
+    \fi
+  \fi}
+\bbl at trace{Local Language Configuration}
+\ifx\loadlocalcfg\@undefined
+  \@ifpackagewith{babel}{noconfigs}%
+    {\let\loadlocalcfg\@gobble}%
+    {\def\loadlocalcfg#1{%
+      \InputIfFileExists{#1.cfg}%
+        {\typeout{*************************************^^J%
+                       * Local config file #1.cfg used^^J%
+                       *}}%
+        \@empty}}
+\fi
+\ifx\@unexpandable at protect\@undefined
+  \def\@unexpandable at protect{\noexpand\protect\noexpand}
+  \long\def\protected at write#1#2#3{%
+    \begingroup
+      \let\thepage\relax
+      #2%
+      \let\protect\@unexpandable at protect
+      \edef\reserved at a{\write#1{#3}}%
+      \reserved at a
+    \endgroup
+    \if at nobreak\ifvmode\nobreak\fi\fi}
+\fi
 \bbl at trace{Language options}
 \let\bbl at afterlang\relax
 \let\BabelModifiers\relax
@@ -541,6 +1037,7 @@
   \bbl at ifsamestring\CurrentOption{#1}{\global\bbl at add\bbl at afterlang}{}}
 \DeclareOption*{}
 \ProcessOptions*
+\bbl at trace{Option 'main'}
 \ifx\bbl at opt@main\@nnil
   \edef\bbl at tempa{\@classoptionslist,\bbl at language@opts}
   \let\bbl at tempc\@empty
@@ -573,6 +1070,7 @@
     as the main language. Reported}
     \bbl at load@language{nil}
 \fi
+
 \endinput
 %%
 %% End of file `babel.sty'.

Modified: trunk/Master/texmf-dist/tex/generic/babel/blplain.tex
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/blplain.tex	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/tex/generic/babel/blplain.tex	2020-04-28 21:14:00 UTC (rev 54930)
@@ -47,6 +47,7 @@
 \fi
 \a lplain.tex
 \def\fmtname{babel-lplain}
+
 \endinput
 %%
 %% End of file `blplain.tex'.

Modified: trunk/Master/texmf-dist/tex/generic/babel/bplain.tex
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/bplain.tex	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/tex/generic/babel/bplain.tex	2020-04-28 21:14:00 UTC (rev 54930)
@@ -47,6 +47,7 @@
 \fi
 \a plain.tex
 \def\fmtname{babel-plain}
+
 \endinput
 %%
 %% End of file `bplain.tex'.

Modified: trunk/Master/texmf-dist/tex/generic/babel/hyphen.cfg
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/hyphen.cfg	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/tex/generic/babel/hyphen.cfg	2020-04-28 21:14:00 UTC (rev 54930)
@@ -37,8 +37,10 @@
     \wlog{File: #1 #4 #3 <#2>}%
     \let\ProvidesFile\@undefined}
 \fi
-\ProvidesFile{hyphen.cfg}[2020/03/22 3.42 Babel hyphens]
+\ProvidesFile{hyphen.cfg}[2020/04/28 3.43 Babel hyphens]
 \xdef\bbl at format{\jobname}
+\def\bbl at version{3.43}
+\def\bbl at date{2020/04/28}
 \ifx\AtBeginDocument\@undefined
   \def\@empty{}
   \let\orig at dump\dump
@@ -127,7 +129,45 @@
 \def\bbl at hook@everylanguage#1{}
 \def\bbl at hook@loadpatterns#1{\input #1\relax}
 \let\bbl at hook@loadexceptions\bbl at hook@loadpatterns
-\let\bbl at hook@loadkernel\bbl at hook@loadpatterns
+\def\bbl at hook@loadkernel#1{%
+  \def\addlanguage{\alloc at 9\language\chardef\@cclvi}%
+  \def\adddialect##1##2{%
+    \global\chardef##1##2\relax
+    \wlog{\string##1 = a dialect from \string\language##2}}%
+  \def\iflanguage##1{%
+    \expandafter\ifx\csname l@##1\endcsname\relax
+      \@nolanerr{##1}%
+    \else
+      \ifnum\csname l@##1\endcsname=\language
+        \expandafter\expandafter\expandafter\@firstoftwo
+      \else
+        \expandafter\expandafter\expandafter\@secondoftwo
+      \fi
+    \fi}%
+  \def\providehyphenmins##1##2{%
+    \expandafter\ifx\csname ##1hyphenmins\endcsname\relax
+      \@namedef{##1hyphenmins}{##2}%
+    \fi}%
+  \def\set at hyphenmins##1##2{%
+    \lefthyphenmin##1\relax
+    \righthyphenmin##2\relax}%
+  \def\selectlanguage{%
+    \errhelp{Selecting a language requires a package supporting it}%
+    \errmessage{Not loaded}}%
+  \let\foreignlanguage\selectlanguage
+  \let\otherlanguage\selectlanguage
+  \expandafter\let\csname otherlanguage*\endcsname\selectlanguage
+  \def\bbl at usehooks##1##2{}% TODO. Temporary!!
+  \def\setlocale{%
+    \errhelp{Find an armchair, sit down and wait}%
+    \errmessage{Not yet available}}%
+  \let\uselocale\setlocale
+  \let\locale\setlocale
+  \let\selectlocale\setlocale
+  \let\localename\setlocale
+  \let\textlocale\setlocale
+  \let\textlanguage\setlocale
+  \let\languagetext\setlocale}
 \begingroup
   \def\AddBabelHook#1#2{%
     \expandafter\ifx\csname bbl at hook@#2\endcsname\relax
@@ -194,6 +234,7 @@
 \let\bbl at hook@everylanguage\@undefined
 \let\bbl at hook@loadpatterns\@undefined
 \let\bbl at hook@loadexceptions\@undefined
+
 \endinput
 %%
 %% End of file `hyphen.cfg'.

Modified: trunk/Master/texmf-dist/tex/generic/babel/locale/as/babel-as.ini
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/locale/as/babel-as.ini	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/tex/generic/babel/locale/as/babel-as.ini	2020-04-28 21:14:00 UTC (rev 54930)
@@ -8,11 +8,12 @@
 ; * Common Locale Data Repository (license Unicode):
 ;   http://cldr.unicode.org/
 ;   http://unicode.org/copyright.html
+; * Contributors: Navanath Saharia
 
 [identification]
 charset = utf8
-version = 1.4
-date = 2020-03-22
+version = 1.5
+date = 2020-04-07
 name.local = অসমীয়া
 name.english = Assamese
 name.babel = assamese
@@ -27,51 +28,28 @@
 derivate = no
 
 [captions]
-preface = 
-ref = 
-abstract = 
-bib = 
-chapter = 
-appendix = 
-contents = 
-listfigure = 
-listtable = 
-index = 
-figure = 
-table = 
-part = 
-encl = 
-cc = 
-headto = 
-page = 
-see = 
-also = 
-proof = 
-glossary = 
+preface = পাতনি
+ref = প্ৰসংগ
+abstract = মূলভাৱ
+bib = তথ্যসূত্ৰ
+chapter = অধ্যায়
+appendix = পৰিশিষ্ট
+contents = সমল
+listfigure = চিত্ৰসূচী
+listtable = তালিকাসূচী
+index =  বিষয়সূচী
+figure = চিত্ৰ
+table = তালিকা
+part = অংশ
+encl = সংযোজিত
+cc = প্ৰতিলিপি
+headto = মুখে
+page = পৃষ্ঠা
+see = চাওক
+also = ও
+proof = প্ৰমাণ
+glossary = অৰ্থকোষ
 
-[captions.licr]
-preface = 
-ref = 
-abstract = 
-bib = 
-chapter = 
-appendix = 
-contents = 
-listfigure = 
-listtable = 
-index = 
-figure = 
-table = 
-part = 
-encl = 
-cc = 
-headto = 
-page = 
-see = 
-also = 
-proof = 
-glossary = 
-
 [date.gregorian]
 date.long = [y] [MMMM] [d]
 date.short = [y]-[MM]-[dd]
@@ -87,18 +65,18 @@
 months.wide.10 = অক্টোবৰ
 months.wide.11 = নৱেম্বৰ
 months.wide.12 = ডিচেম্বৰ
-months.narrow.1 = 1
-months.narrow.2 = 2
-months.narrow.3 = 3
-months.narrow.4 = 4
-months.narrow.5 = 5
-months.narrow.6 = 6
-months.narrow.7 = 7
-months.narrow.8 = 8
-months.narrow.9 = 9
-months.narrow.10 = 10
-months.narrow.11 = 11
-months.narrow.12 = 12
+months.narrow.1 = ১
+months.narrow.2 = ২
+months.narrow.3 = ৩
+months.narrow.4 = ৪
+months.narrow.5 = ৫
+months.narrow.6 = ৬
+months.narrow.7 = ৭
+months.narrow.8 = ৮
+months.narrow.9 = ৯
+months.narrow.10 = ১০
+months.narrow.11 = ১১
+months.narrow.12 = ১২
 days.wide.mon = সোমবাৰ
 days.wide.tue = মঙ্গলবাৰ
 days.wide.wed = বুধবাৰ
@@ -109,17 +87,17 @@
 days.abbreviated.mon = সোম
 days.abbreviated.tue = মঙ্গল
 days.abbreviated.wed = বুধ
-days.abbreviated.thu = বৃহষ্পতি
+days.abbreviated.thu = বৃহ
 days.abbreviated.fri = শুক্ৰ
 days.abbreviated.sat = শনি
 days.abbreviated.sun = ৰবি
-days.narrow.mon = M
-days.narrow.tue = T
-days.narrow.wed = W
-days.narrow.thu = T
-days.narrow.fri = F
-days.narrow.sat = S
-days.narrow.sun = S
+days.narrow.mon = সো
+days.narrow.tue = ম
+days.narrow.wed = বু
+days.narrow.thu = বৃ
+days.narrow.fri = শু
+days.narrow.sat = শ
+days.narrow.sun = ৰ
 dayPeriods.abbreviated.am = পূৰ্বাহ্ণ
 dayPeriods.abbreviated.pm = অপৰাহ্ণ
 dayPeriods.narrow.am = পূৰ্বাহ্ণ
@@ -150,7 +128,7 @@
 delimiters.quotes = “”‘’
 auxiliary = [\u200C\u200D ৲]
 exemplarCharacters = [\u09BC অ আ ই ঈ উ ঊ ঋ এ ঐ ও ঔ ং \u0981 ঃ ক খ গ ঘ ঙ চ ছ জ ঝ ঞ ট ঠ ড {ড\u09BC} ঢ {ঢ\u09BC} ণ ত থ দ ধ ন প ফ ব ভ ম য {য\u09BC} ৰ ল ৱ শ ষ স হ {ক\u09CDষ} া ি ী \u09C1 \u09C2 \u09C3 ে ৈ ো ৌ \u09CD]
-punctuation = [\\- , ; \\: ! ? . ( ) \\[ \\] \\{ \\}]
+punctuation = [\\- , ; \\: ! ? . । ( ) \\[ \\] \\{ \\}]
 
 [numbers]
 defaultNumberingSystem = beng
@@ -168,4 +146,4 @@
 plusSign = +
 superscriptingExponent = ×
 
-[counters]
+[counters]
\ No newline at end of file

Modified: trunk/Master/texmf-dist/tex/generic/babel/locale/bn/babel-bn.ini
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/locale/bn/babel-bn.ini	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/tex/generic/babel/locale/bn/babel-bn.ini	2020-04-28 21:14:00 UTC (rev 54930)
@@ -11,8 +11,8 @@
 
 [identification]
 charset = utf8
-version = 1.4
-date = 2020-03-22
+version = 1.5
+date = 2020-04-22
 name.local = বাংলা
 name.english = Bangla
 name.babel = bengali
@@ -148,3 +148,4 @@
 superscriptingExponent = ×
 
 [counters]
+alphabetic = ক খ গ ঘ ঙ চ ছ জ ঝ ঞ ট ঠ ড ঢ ণ ত থ দ ধ ন প ফ ব ভ
\ No newline at end of file

Modified: trunk/Master/texmf-dist/tex/generic/babel/locale/fi/babel-fi.ini
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/locale/fi/babel-fi.ini	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/tex/generic/babel/locale/fi/babel-fi.ini	2020-04-28 21:14:00 UTC (rev 54930)
@@ -8,11 +8,12 @@
 ; * Common Locale Data Repository (license Unicode):
 ;   http://cldr.unicode.org/
 ;   http://unicode.org/copyright.html
+; * Contributors: Teemu Likonen
 
 [identification]
 charset = utf8
-version = 1.1
-date = 2020-03-22
+version = 1.2
+date = 2020-04-08
 name.local = suomi
 name.english = Finnish
 name.babel = finnish
@@ -34,7 +35,7 @@
 bib = Kirjallisuutta
 chapter = Luku
 appendix = Liite
-contents = Sisältö
+contents = Sisällys
 listfigure = Kuvat
 listtable = Taulukot
 index = Hakemisto
@@ -57,7 +58,7 @@
 bib = Kirjallisuutta
 chapter = Luku
 appendix = Liite
-contents = Sis\"alt\"o
+contents = Sis\"allys
 listfigure = Kuvat
 listtable = Taulukot
 index = Hakemisto

Modified: trunk/Master/texmf-dist/tex/generic/babel/locale/hy/babel-hy.ini
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/locale/hy/babel-hy.ini	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/tex/generic/babel/locale/hy/babel-hy.ini	2020-04-28 21:14:00 UTC (rev 54930)
@@ -13,8 +13,8 @@
 
 [identification]
 charset = utf8
-version = 1.3
-date = 2020-03-22
+version = 1.4
+date = 2020-04-20
 name.local = հայերեն
 name.english = Armenian
 name.babel = armenian
@@ -171,12 +171,12 @@
 superscriptingExponent = ×
 
 [counters]
-lower.1 = ա բ գ դ ե զ է ը թ
-lower.2 = ժ ի լ խ ծ կ հ ձ ղ
-lower.3 = ճ մ յ ն շ ո չ պ ջ
-lower.4 = ռ ս վ տ ր ց ւ փ ք
-upper.1 = Ա Բ Գ Դ Ե Զ Է Ը Թ
-upper.2 = Ժ Ի Լ Խ Ծ Կ Հ Ձ Ղ
-upper.3 = Ճ Մ Յ Ն Շ Ո Չ Պ Ջ
-upper.4 = Ռ Ս Վ Տ Ր Ց Ւ Փ Ք
+lower.letters.1 = ա բ գ դ ե զ է ը թ
+lower.letters.2 = ժ ի լ խ ծ կ հ ձ ղ
+lower.letters.3 = ճ մ յ ն շ ո չ պ ջ
+lower.letters.4 = ռ ս վ տ ր ց ւ փ ք
+upper.letters.1 = Ա Բ Գ Դ Ե Զ Է Ը Թ
+upper.letters.2 = Ժ Ի Լ Խ Ծ Կ Հ Ձ Ղ
+upper.letters.3 = Ճ Մ Յ Ն Շ Ո Չ Պ Ջ
+upper.letters.4 = Ռ Ս Վ Տ Ր Ց Ւ Փ Ք
 

Modified: trunk/Master/texmf-dist/tex/generic/babel/locale/lb/babel-lb.ini
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/locale/lb/babel-lb.ini	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/tex/generic/babel/locale/lb/babel-lb.ini	2020-04-28 21:14:00 UTC (rev 54930)
@@ -8,11 +8,12 @@
 ; * Common Locale Data Repository (license Unicode):
 ;   http://cldr.unicode.org/
 ;   http://unicode.org/copyright.html
+; * Contributors: Sam Mersch.
 
 [identification]
 charset = utf8
-version = 1.1
-date = 2020-03-22
+version = 1.2
+date = 2020-04-20
 name.local = Lëtzebuergesch
 name.english = Luxembourgish
 name.babel = luxembourgish
@@ -27,50 +28,50 @@
 derivate = no
 
 [captions]
-preface = 
-ref = 
-abstract = 
-bib = 
-chapter = 
-appendix = 
-contents = 
-listfigure = 
-listtable = 
-index = 
-figure = 
-table = 
-part = 
-encl = 
-cc = 
-headto = 
-page = 
-see = 
-also = 
-proof = 
-glossary = 
+preface = Virwuert
+ref = Literatur
+abstract = Resümee
+bib = Bibliographie
+chapter = Kapitel
+appendix = Annex
+contents = Contenue
+listfigure = Lëscht vun de Biller
+listtable = Lëscht vun den Tabellen
+index = Index
+figure = Bild
+table = Tabell
+part = Deel
+encl = Annex(en)
+cc = Distributeur
+headto = Un
+page = Säit
+see = kuck
+also = kuck och
+proof = Beweis
+glossary = Glossär
 
 [captions.licr]
-preface = 
-ref = 
-abstract = 
-bib = 
-chapter = 
-appendix = 
-contents = 
-listfigure = 
-listtable = 
-index = 
-figure = 
-table = 
-part = 
-encl = 
-cc = 
-headto = 
-page = 
-see = 
-also = 
-proof = 
-glossary = 
+preface = Virwuert
+ref = Literatur
+abstract = Res\"umee
+bib = Bibliographie
+chapter = Kapitel
+appendix = Annex
+contents = Contenue
+listfigure = L\"escht vun de Biller
+listtable = L\"escht vun den Tabellen
+index = Index
+figure = Bild
+table = Tabell
+part = Deel
+encl = Annex(en)
+cc = Distributeur
+headto = Un
+page = Säit
+see = kuck
+also = kuck och
+proof = Beweis
+glossary = Glossär
 
 [date.gregorian]
 date.long = [d]. [MMMM] [y]
@@ -106,13 +107,13 @@
 days.wide.fri = Freideg
 days.wide.sat = Samschdeg
 days.wide.sun = Sonndeg
-days.abbreviated.mon = Méi.
-days.abbreviated.tue = Dën.
+days.abbreviated.mon = Méin.
+days.abbreviated.tue = Dë.
 days.abbreviated.wed = Mët.
-days.abbreviated.thu = Don.
-days.abbreviated.fri = Fre.
-days.abbreviated.sat = Sam.
-days.abbreviated.sun = Son.
+days.abbreviated.thu = Do.
+days.abbreviated.fri = Fr.
+days.abbreviated.sat = Sa.
+days.abbreviated.sun = So.
 days.narrow.mon = M
 days.narrow.tue = D
 days.narrow.wed = M
@@ -122,8 +123,8 @@
 days.narrow.sun = S
 dayPeriods.abbreviated.am = moies
 dayPeriods.abbreviated.pm = nomëttes
-dayPeriods.narrow.am = mo.
-dayPeriods.narrow.pm = nomë.
+dayPeriods.narrow.am = moies
+dayPeriods.narrow.pm = nomëttes
 dayPeriods.wide.am = moies
 dayPeriods.wide.pm = nomëttes
 
@@ -146,10 +147,10 @@
 time.short = [HH]:[mm]
 
 [typography]
-frenchspacing = 
-hyphenrules = 
-lefthyphenmin = 
-righthyphenmin = 
+frenchspacing = yes
+hyphenrules = ngerman
+lefthyphenmin = 2
+righthyphenmin = 2
 hyphenchar = 
 prehyphenchar = 
 posthyphenchar = 

Modified: trunk/Master/texmf-dist/tex/generic/babel/locale/mr/babel-mr.ini
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/locale/mr/babel-mr.ini	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/tex/generic/babel/locale/mr/babel-mr.ini	2020-04-28 21:14:00 UTC (rev 54930)
@@ -8,11 +8,12 @@
 ; * Common Locale Data Repository (license Unicode):
 ;   http://cldr.unicode.org/
 ;   http://unicode.org/copyright.html
+; * With some suggestions by NiranjanTambe
 
 [identification]
 charset = utf8
-version = 1.4
-date = 2020-03-22
+version = 1.5
+date = 2020-04-23
 name.local = मराठी
 name.english = Marathi
 name.babel = marathi
@@ -42,13 +43,13 @@
 table = कोष्टक
 part = भाग
 encl = समाविष्ट
-cc = सि.सि.
+cc = प्रत
 headto = प्रति
 page = पान
 see = पहा
 also = हे सुध्दा पहा
 proof = कसोटी
-glossary = स्पष्टीकरणकोश
+glossary = संज्ञांची सूची
 
 [date.gregorian]
 date.long = [d] [MMMM], [y]
@@ -148,3 +149,4 @@
 superscriptingExponent = ×
 
 [counters]
+alphabetic = क ख ग घ ङ च छ ज झ ञ ट ठ ड ढ ण त थ द ध न प फ ब भ म य र ल व श ष स ह ळ

Modified: trunk/Master/texmf-dist/tex/generic/babel/luababel.def
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/luababel.def	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/tex/generic/babel/luababel.def	2020-04-28 21:14:00 UTC (rev 54930)
@@ -32,7 +32,7 @@
 %% extension |.ins|) which are part of the distribution.
 %%
 
-\ifx\AddBabelHook\@undefined
+\ifx\AddBabelHook\@undefined % When plain.def, babel.sty starts
 \bbl at trace{Read language.dat}
 \ifx\bbl at readstream\@undefined
   \csname newread\endcsname\bbl at readstream
@@ -120,27 +120,30 @@
 \bbl at trace{Macros for reading patterns files}
 \def\bbl at get@enc#1:#2:#3\@@@{\def\bbl at hyph@enc{#2}}
 \ifx\babelcatcodetablenum\@undefined
-  \def\babelcatcodetablenum{5211}
+  \ifx\newcatcodetable\@undefined
+    \def\babelcatcodetablenum{5211}
+    \def\bbl at pattcodes{\numexpr\babelcatcodetablenum+1\relax}
+  \else
+    \newcatcodetable\babelcatcodetablenum
+    \newcatcodetable\bbl at pattcodes
+  \fi
+\else
+  \def\bbl at pattcodes{\numexpr\babelcatcodetablenum+1\relax}
 \fi
 \def\bbl at luapatterns#1#2{%
   \bbl at get@enc#1::\@@@
   \setbox\z@\hbox\bgroup
     \begingroup
-      \ifx\catcodetable\@undefined
-        \let\savecatcodetable\luatexsavecatcodetable
-        \let\initcatcodetable\luatexinitcatcodetable
-        \let\catcodetable\luatexcatcodetable
-      \fi
       \savecatcodetable\babelcatcodetablenum\relax
-      \initcatcodetable\numexpr\babelcatcodetablenum+1\relax
-      \catcodetable\numexpr\babelcatcodetablenum+1\relax
-      \catcode`\#=6  \catcode`\$=3 \catcode`\&=4 \catcode`\^=7
-      \catcode`\_=8  \catcode`\{=1 \catcode`\}=2 \catcode`\~=13
-      \catcode`\@=11 \catcode`\^^I=10 \catcode`\^^J=12
-      \catcode`\<=12 \catcode`\>=12 \catcode`\*=12 \catcode`\.=12
-      \catcode`\-=12 \catcode`\/=12 \catcode`\[=12 \catcode`\]=12
-      \catcode`\`=12 \catcode`\'=12 \catcode`\"=12
-      \input #1\relax
+      \initcatcodetable\bbl at pattcodes\relax
+      \catcodetable\bbl at pattcodes\relax
+        \catcode`\#=6  \catcode`\$=3 \catcode`\&=4 \catcode`\^=7
+        \catcode`\_=8  \catcode`\{=1 \catcode`\}=2 \catcode`\~=13
+        \catcode`\@=11 \catcode`\^^I=10 \catcode`\^^J=12
+        \catcode`\<=12 \catcode`\>=12 \catcode`\*=12 \catcode`\.=12
+        \catcode`\-=12 \catcode`\/=12 \catcode`\[=12 \catcode`\]=12
+        \catcode`\`=12 \catcode`\'=12 \catcode`\"=12
+        \input #1\relax
       \catcodetable\babelcatcodetablenum\relax
     \endgroup
     \def\bbl at tempa{#2}%
@@ -173,6 +176,25 @@
        {\expandafter\expandafter\expandafter\bbl at luapatterns
           \csname bbl at hyphendata@\the\language\endcsname}}{}}
 \endinput\fi
+  % Here ends \ifx\AddBabelHook\@undefined
+  % A few lines are only read by hyphen.cfg
+\ifx\DisableBabelHook\@undefined
+  \AddBabelHook{luatex}{everylanguage}{%
+    \def\process at language##1##2##3{%
+      \def\process at line####1####2 ####3 ####4 {}}}
+  \AddBabelHook{luatex}{loadpatterns}{%
+     \input #1\relax
+     \expandafter\gdef\csname bbl at hyphendata@\the\language\endcsname
+       {{#1}{}}}
+  \AddBabelHook{luatex}{loadexceptions}{%
+     \input #1\relax
+     \def\bbl at tempb##1##2{{##1}{#1}}%
+     \expandafter\xdef\csname bbl at hyphendata@\the\language\endcsname
+       {\expandafter\expandafter\expandafter\bbl at tempb
+        \csname bbl at hyphendata@\the\language\endcsname}}
+\endinput\fi
+  % Here stops reading code for hyphen.cfg
+  % The following is read the 2nd time it's loaded
 \begingroup
 \catcode`\%=12
 \catcode`\'=12
@@ -280,19 +302,6 @@
     \bbl at ifunset{bbl at prehc@\languagename}{}%
       {\\\bbl at ifblank{\bbl at cs{prehc@\languagename}}{}%
         {\prehyphenchar=\bbl at cl{prehc}\relax}}}}
-\AddBabelHook{luatex}{everylanguage}{%
-  \def\process at language##1##2##3{%
-    \def\process at line####1####2 ####3 ####4 {}}}
-\AddBabelHook{luatex}{loadpatterns}{%
-   \input #1\relax
-   \expandafter\gdef\csname bbl at hyphendata@\the\language\endcsname
-     {{#1}{}}}
-\AddBabelHook{luatex}{loadexceptions}{%
-   \input #1\relax
-   \def\bbl at tempb##1##2{{##1}{#1}}%
-   \expandafter\xdef\csname bbl at hyphendata@\the\language\endcsname
-     {\expandafter\expandafter\expandafter\bbl at tempb
-      \csname bbl at hyphendata@\the\language\endcsname}}
 \@onlypreamble\babelpatterns
 \AtEndOfPackage{%
   \newcommand\babelpatterns[2][\@empty]{%
@@ -522,36 +531,6 @@
      \ifx\bbl at KVP@intrapenalty\@nil\else
        \expandafter\bbl at intrapenalty\bbl at KVP@intrapenalty\@@
      \fi}}
-\AddBabelHook{luatex}{loadkernel}{%
-  \begingroup
-      % Reset chars "80-"C0 to category "other", no case mapping:
-    \catcode`\@=11 \count@=128
-    \loop\ifnum\count@<192
-      \global\uccode\count@=0 \global\lccode\count@=0
-      \global\catcode\count@=12 \global\sfcode\count@=1000
-      \advance\count@ by 1 \repeat
-      % Other:
-    \def\O ##1 {%
-      \global\uccode"##1=0 \global\lccode"##1=0
-      \global\catcode"##1=12 \global\sfcode"##1=1000 }%
-      % Letter:
-    \def\L ##1 ##2 ##3 {\global\catcode"##1=11
-      \global\uccode"##1="##2
-      \global\lccode"##1="##3
-      % Uppercase letters have sfcode=999:
-      \ifnum"##1="##3 \else \global\sfcode"##1=999 \fi }%
-      % Letter without case mappings:
-    \def\l ##1 {\L ##1 ##1 ##1 }%
-    \l 00AA
-    \L 00B5 039C 00B5
-    \l 00BA
-    \O 00D7
-    \l 00DF
-    \O 00F7
-    \L 00FF 0178 00FF
-  \endgroup
-  \input #1\relax}
-\ifx\DisableBabelHook\@undefined\endinput\fi
 \AddBabelHook{babel-fontspec}{afterextras}{\bbl at switchfont}
 \AddBabelHook{babel-fontspec}{beforestart}{\bbl at ckeckstdfonts}
 \DisableBabelHook{babel-fontspec}
@@ -1291,6 +1270,7 @@
      \babelsublr{%
        \LaTeX\kern.15em2\bbl at nextfake$_{\textstyle\varepsilon}$}}}}
   {}
+
 \endinput
 %%
 %% End of file `luababel.def'.

Modified: trunk/Master/texmf-dist/tex/generic/babel/nil.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/nil.ldf	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/tex/generic/babel/nil.ldf	2020-04-28 21:14:00 UTC (rev 54930)
@@ -32,7 +32,7 @@
 %% extension |.ins|) which are part of the distribution.
 %%
 
-\ProvidesLanguage{nil}[2020/03/22 3.42 Nil language]
+\ProvidesLanguage{nil}[2020/04/28 3.43 Nil language]
 \LdfInit{nil}{datenil}
 \ifx\l at nil\@undefined
   \newlanguage\l at nil
@@ -45,6 +45,7 @@
 \let\captionsnil\@empty
 \let\datenil\@empty
 \ldf at finish{nil}
+
 \endinput
 %%
 %% End of file `nil.ldf'.

Modified: trunk/Master/texmf-dist/tex/generic/babel/plain.def
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/plain.def	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/tex/generic/babel/plain.def	2020-04-28 21:14:00 UTC (rev 54930)
@@ -32,329 +32,8 @@
 %% extension |.ins|) which are part of the distribution.
 %%
 
-\def\@empty{}
-\def\loadlocalcfg#1{%
-  \openin0#1.cfg
-  \ifeof0
-    \closein0
-  \else
-    \closein0
-    {\immediate\write16{*************************************}%
-     \immediate\write16{* Local config file #1.cfg used}%
-     \immediate\write16{*}%
-     }
-    \input #1.cfg\relax
-  \fi
-  \@endofldf}
-\long\def\@firstofone#1{#1}
-\long\def\@firstoftwo#1#2{#1}
-\long\def\@secondoftwo#1#2{#2}
-\def\@nnil{\@nil}
-\def\@gobbletwo#1#2{}
-\def\@ifstar#1{\@ifnextchar *{\@firstoftwo{#1}}}
-\def\@star at or@long#1{%
-  \@ifstar
-  {\let\l at ngrel@x\relax#1}%
-  {\let\l at ngrel@x\long#1}}
-\let\l at ngrel@x\relax
-\def\@car#1#2\@nil{#1}
-\def\@cdr#1#2\@nil{#2}
-\let\@typeset at protect\relax
-\let\protected at edef\edef
-\long\def\@gobble#1{}
-\edef\@backslashchar{\expandafter\@gobble\string\\}
-\def\strip at prefix#1>{}
-\def\g at addto@macro#1#2{{%
-    \toks@\expandafter{#1#2}%
-    \xdef#1{\the\toks@}}}
-\def\@namedef#1{\expandafter\def\csname #1\endcsname}
-\def\@nameuse#1{\csname #1\endcsname}
-\def\@ifundefined#1{%
-  \expandafter\ifx\csname#1\endcsname\relax
-    \expandafter\@firstoftwo
-  \else
-    \expandafter\@secondoftwo
-  \fi}
-\def\@expandtwoargs#1#2#3{%
-  \edef\reserved at a{\noexpand#1{#2}{#3}}\reserved at a}
-\def\zap at space#1 #2{%
-  #1%
-  \ifx#2\@empty\else\expandafter\zap at space\fi
-  #2}
-\ifx\@preamblecmds\@undefined
-  \def\@preamblecmds{}
-\fi
-\def\@onlypreamble#1{%
-  \expandafter\gdef\expandafter\@preamblecmds\expandafter{%
-    \@preamblecmds\do#1}}
-\@onlypreamble\@onlypreamble
-\def\begindocument{%
-  \@begindocumenthook
-  \global\let\@begindocumenthook\@undefined
-  \def\do##1{\global\let##1\@undefined}%
-  \@preamblecmds
-  \global\let\do\noexpand}
-\ifx\@begindocumenthook\@undefined
-  \def\@begindocumenthook{}
-\fi
-\@onlypreamble\@begindocumenthook
-\def\AtBeginDocument{\g at addto@macro\@begindocumenthook}
-\def\AtEndOfPackage#1{\g at addto@macro\@endofldf{#1}}
-\@onlypreamble\AtEndOfPackage
-\def\@endofldf{}
-\@onlypreamble\@endofldf
-\let\bbl at afterlang\@empty
-\chardef\bbl at opt@hyphenmap\z@
-\ifx\if at filesw\@undefined
-  \expandafter\let\csname if at filesw\expandafter\endcsname
-    \csname iffalse\endcsname
-\fi
-\def\newcommand{\@star at or@long\new at command}
-\def\new at command#1{%
-  \@testopt{\@newcommand#1}0}
-\def\@newcommand#1[#2]{%
-  \@ifnextchar [{\@xargdef#1[#2]}%
-                {\@argdef#1[#2]}}
-\long\def\@argdef#1[#2]#3{%
-  \@yargdef#1\@ne{#2}{#3}}
-\long\def\@xargdef#1[#2][#3]#4{%
-  \expandafter\def\expandafter#1\expandafter{%
-    \expandafter\@protected at testopt\expandafter #1%
-    \csname\string#1\expandafter\endcsname{#3}}%
-  \expandafter\@yargdef \csname\string#1\endcsname
-  \tw@{#2}{#4}}
-\long\def\@yargdef#1#2#3{%
-  \@tempcnta#3\relax
-  \advance \@tempcnta \@ne
-  \let\@hash@\relax
-  \edef\reserved at a{\ifx#2\tw@ [\@hash at 1]\fi}%
-  \@tempcntb #2%
-  \@whilenum\@tempcntb <\@tempcnta
-  \do{%
-    \edef\reserved at a{\reserved at a\@hash@\the\@tempcntb}%
-    \advance\@tempcntb \@ne}%
-  \let\@hash@##%
-  \l at ngrel@x\expandafter\def\expandafter#1\reserved at a}
-\def\providecommand{\@star at or@long\provide at command}
-\def\provide at command#1{%
-  \begingroup
-    \escapechar\m at ne\xdef\@gtempa{{\string#1}}%
-  \endgroup
-  \expandafter\@ifundefined\@gtempa
-    {\def\reserved at a{\new at command#1}}%
-    {\let\reserved at a\relax
-     \def\reserved at a{\new at command\reserved at a}}%
-   \reserved at a}%
-\def\DeclareRobustCommand{\@star at or@long\declare at robustcommand}
-\def\declare at robustcommand#1{%
-   \edef\reserved at a{\string#1}%
-   \def\reserved at b{#1}%
-   \edef\reserved at b{\expandafter\strip at prefix\meaning\reserved at b}%
-   \edef#1{%
-      \ifx\reserved at a\reserved at b
-         \noexpand\x at protect
-         \noexpand#1%
-      \fi
-      \noexpand\protect
-      \expandafter\noexpand\csname
-         \expandafter\@gobble\string#1 \endcsname
-   }%
-   \expandafter\new at command\csname
-      \expandafter\@gobble\string#1 \endcsname
-}
-\def\x at protect#1{%
-   \ifx\protect\@typeset at protect\else
-      \@x at protect#1%
-   \fi
-}
-\def\@x at protect#1\fi#2#3{%
-   \fi\protect#1%
-}
-\def\bbl at tempa{\csname newif\endcsname\ifin@}
-\ifx\in@\@undefined
-  \def\in@#1#2{%
-    \def\in@@##1#1##2##3\in@@{%
-      \ifx\in@##2\in at false\else\in at true\fi}%
-    \in@@#2#1\in@\in@@}
-\else
-  \let\bbl at tempa\@empty
-\fi
-\bbl at tempa
-\def\@ifpackagewith#1#2#3#4{#3}
-\def\@ifl at aded#1#2#3#4{}
-\ifx\@tempcnta\@undefined
-  \csname newcount\endcsname\@tempcnta\relax
-\fi
-\ifx\@tempcntb\@undefined
-  \csname newcount\endcsname\@tempcntb\relax
-\fi
-\ifx\bye\@undefined
-  \advance\count10 by -2\relax
-\fi
-\ifx\@ifnextchar\@undefined
-  \def\@ifnextchar#1#2#3{%
-    \let\reserved at d=#1%
-    \def\reserved at a{#2}\def\reserved at b{#3}%
-    \futurelet\@let at token\@ifnch}
-  \def\@ifnch{%
-    \ifx\@let at token\@sptoken
-      \let\reserved at c\@xifnch
-    \else
-      \ifx\@let at token\reserved at d
-        \let\reserved at c\reserved at a
-      \else
-        \let\reserved at c\reserved at b
-      \fi
-    \fi
-    \reserved at c}
-  \def\:{\let\@sptoken= } \:  % this makes \@sptoken a space token
-  \def\:{\@xifnch} \expandafter\def\: {\futurelet\@let at token\@ifnch}
-\fi
-\def\@testopt#1#2{%
-  \@ifnextchar[{#1}{#1[#2]}}
-\def\@protected at testopt#1{%
-  \ifx\protect\@typeset at protect
-    \expandafter\@testopt
-  \else
-    \@x at protect#1%
-  \fi}
-\long\def\@whilenum#1\do #2{\ifnum #1\relax #2\relax\@iwhilenum{#1\relax
-     #2\relax}\fi}
-\long\def\@iwhilenum#1{\ifnum #1\expandafter\@iwhilenum
-         \else\expandafter\@gobble\fi{#1}}
-\def\DeclareTextCommand{%
-   \@dec at text@cmd\providecommand
-}
-\def\ProvideTextCommand{%
-   \@dec at text@cmd\providecommand
-}
-\def\DeclareTextSymbol#1#2#3{%
-   \@dec at text@cmd\chardef#1{#2}#3\relax
-}
-\def\@dec at text@cmd#1#2#3{%
-   \expandafter\def\expandafter#2%
-      \expandafter{%
-         \csname#3-cmd\expandafter\endcsname
-         \expandafter#2%
-         \csname#3\string#2\endcsname
-      }%
-   \expandafter#1\csname#3\string#2\endcsname
-}
-\def\@current at cmd#1{%
-  \ifx\protect\@typeset at protect\else
-      \noexpand#1\expandafter\@gobble
-  \fi
-}
-\def\@changed at cmd#1#2{%
-   \ifx\protect\@typeset at protect
-      \expandafter\ifx\csname\cf at encoding\string#1\endcsname\relax
-         \expandafter\ifx\csname ?\string#1\endcsname\relax
-            \expandafter\def\csname ?\string#1\endcsname{%
-               \@changed at x@err{#1}%
-            }%
-         \fi
-         \global\expandafter\let
-           \csname\cf at encoding \string#1\expandafter\endcsname
-           \csname ?\string#1\endcsname
-      \fi
-      \csname\cf at encoding\string#1%
-        \expandafter\endcsname
-   \else
-      \noexpand#1%
-   \fi
-}
-\def\@changed at x@err#1{%
-    \errhelp{Your command will be ignored, type <return> to proceed}%
-    \errmessage{Command \protect#1 undefined in encoding \cf at encoding}}
-\def\DeclareTextCommandDefault#1{%
-   \DeclareTextCommand#1?%
-}
-\def\ProvideTextCommandDefault#1{%
-   \ProvideTextCommand#1?%
-}
-\expandafter\let\csname OT1-cmd\endcsname\@current at cmd
-\expandafter\let\csname?-cmd\endcsname\@changed at cmd
-\def\DeclareTextAccent#1#2#3{%
-  \DeclareTextCommand#1{#2}[1]{\accent#3 ##1}
-}
-\def\DeclareTextCompositeCommand#1#2#3#4{%
-   \expandafter\let\expandafter\reserved at a\csname#2\string#1\endcsname
-   \edef\reserved at b{\string##1}%
-   \edef\reserved at c{%
-     \expandafter\@strip at args\meaning\reserved at a:-\@strip at args}%
-   \ifx\reserved at b\reserved at c
-      \expandafter\expandafter\expandafter\ifx
-         \expandafter\@car\reserved at a\relax\relax\@nil
-         \@text at composite
-      \else
-         \edef\reserved at b##1{%
-            \def\expandafter\noexpand
-               \csname#2\string#1\endcsname####1{%
-               \noexpand\@text at composite
-                  \expandafter\noexpand\csname#2\string#1\endcsname
-                  ####1\noexpand\@empty\noexpand\@text at composite
-                  {##1}%
-            }%
-         }%
-         \expandafter\reserved at b\expandafter{\reserved at a{##1}}%
-      \fi
-      \expandafter\def\csname\expandafter\string\csname
-         #2\endcsname\string#1-\string#3\endcsname{#4}
-   \else
-     \errhelp{Your command will be ignored, type <return> to proceed}%
-     \errmessage{\string\DeclareTextCompositeCommand\space used on
-         inappropriate command \protect#1}
-   \fi
-}
-\def\@text at composite#1#2#3\@text at composite{%
-   \expandafter\@text at composite@x
-      \csname\string#1-\string#2\endcsname
-}
-\def\@text at composite@x#1#2{%
-   \ifx#1\relax
-      #2%
-   \else
-      #1%
-   \fi
-}
-\def\@strip at args#1:#2-#3\@strip at args{#2}
-\def\DeclareTextComposite#1#2#3#4{%
-   \def\reserved at a{\DeclareTextCompositeCommand#1{#2}{#3}}%
-   \bgroup
-      \lccode`\@=#4%
-      \lowercase{%
-   \egroup
-      \reserved at a @%
-   }%
-}
-\def\UseTextSymbol#1#2{%
-   #2%
-}
-\def\UseTextAccent#1#2#3{%
-}
-\def\@use at text@encoding#1{%
-}
-\def\DeclareTextSymbolDefault#1#2{%
-   \DeclareTextCommandDefault#1{\UseTextSymbol{#2}#1}%
-}
-\def\DeclareTextAccentDefault#1#2{%
-   \DeclareTextCommandDefault#1{\UseTextAccent{#2}#1}%
-}
-\def\cf at encoding{OT1}
-\DeclareTextAccent{\"}{OT1}{127}
-\DeclareTextAccent{\'}{OT1}{19}
-\DeclareTextAccent{\^}{OT1}{94}
-\DeclareTextAccent{\`}{OT1}{18}
-\DeclareTextAccent{\~}{OT1}{126}
-\DeclareTextSymbol{\textquotedblleft}{OT1}{92}
-\DeclareTextSymbol{\textquotedblright}{OT1}{`\"}
-\DeclareTextSymbol{\textquoteleft}{OT1}{`\`}
-\DeclareTextSymbol{\textquoteright}{OT1}{`\'}
-\DeclareTextSymbol{\i}{OT1}{16}
-\DeclareTextSymbol{\ss}{OT1}{25}
-\ifx\scriptsize\@undefined
-  \let\scriptsize\sevenrm
-\fi
+\input babel.def
+
 \endinput
 %%
 %% End of file `plain.def'.

Modified: trunk/Master/texmf-dist/tex/generic/babel/switch.def
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/switch.def	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/tex/generic/babel/switch.def	2020-04-28 21:14:00 UTC (rev 54930)
@@ -32,452 +32,10 @@
 %% extension |.ins|) which are part of the distribution.
 %%
 
-\ifx\ProvidesFile\@undefined
-  \def\ProvidesFile#1[#2 #3 #4]{%
-    \wlog{File: #1 #4 #3 <#2>}%
-    \let\ProvidesFile\@undefined}
-\fi
-\ProvidesFile{switch.def}[2020/03/22 3.42 Babel switching mechanism]
-\ifx\AtBeginDocument\@undefined
-  \input plain.def\relax
-\fi
-\ifx\language\@undefined
-  \csname newcount\endcsname\language
-\fi
-\ifx\newlanguage\@undefined
-  \csname newcount\endcsname\last at language
-  \def\addlanguage#1{%
-    \global\advance\last at language\@ne
-    \ifnum\last at language<\@cclvi
-    \else
-      \errmessage{No room for a new \string\language!}%
-    \fi
-    \global\chardef#1\last at language
-    \wlog{\string#1 = \string\language\the\last at language}}
-\else
-  \countdef\last at language=19
-  \def\addlanguage{\alloc at 9\language\chardef\@cclvi}
-\fi
-\def\bbl at version{3.42}
-\def\bbl at date{2020/03/22}
-\def\adddialect#1#2{%
-  \global\chardef#1#2\relax
-  \bbl at usehooks{adddialect}{{#1}{#2}}%
-  \begingroup
-    \count@#1\relax
-    \def\bbl at elt##1##2##3##4{%
-      \ifnum\count@=##2\relax
-        \bbl at info{\string#1 = using hyphenrules for ##1\\%
-                  (\string\language\the\count@)}%
-        \def\bbl at elt####1####2####3####4{}%
-      \fi}%
-    \bbl at cs{languages}%
-  \endgroup}
-\def\bbl at fixname#1{%
-  \begingroup
-    \def\bbl at tempe{l@}%
-    \edef\bbl at tempd{\noexpand\@ifundefined{\noexpand\bbl at tempe#1}}%
-    \bbl at tempd
-      {\lowercase\expandafter{\bbl at tempd}%
-         {\uppercase\expandafter{\bbl at tempd}%
-           \@empty
-           {\edef\bbl at tempd{\def\noexpand#1{#1}}%
-            \uppercase\expandafter{\bbl at tempd}}}%
-         {\edef\bbl at tempd{\def\noexpand#1{#1}}%
-          \lowercase\expandafter{\bbl at tempd}}}%
-      \@empty
-    \edef\bbl at tempd{\endgroup\def\noexpand#1{#1}}%
-  \bbl at tempd
-  \bbl at usehooks{languagename}{}}
-\def\bbl at iflanguage#1{%
-  \@ifundefined{l@#1}{\@nolanerr{#1}\@gobble}\@firstofone}
-\def\iflanguage#1{%
-  \bbl at iflanguage{#1}{%
-    \ifnum\csname l@#1\endcsname=\language
-      \expandafter\@firstoftwo
-    \else
-      \expandafter\@secondoftwo
-    \fi}}
-\let\bbl at select@type\z@
-\edef\selectlanguage{%
-  \noexpand\protect
-  \expandafter\noexpand\csname selectlanguage \endcsname}
-\ifx\@undefined\protect\let\protect\relax\fi
-\ifx\documentclass\@undefined
-  \def\xstring{\string\string\string}
-\else
-  \let\xstring\string
-\fi
-\def\bbl at language@stack{}
-\def\bbl at push@language{%
-  \xdef\bbl at language@stack{\languagename+\bbl at language@stack}}
-\def\bbl at pop@lang#1+#2-#3{%
-  \edef\languagename{#1}\xdef#3{#2}}
-\let\bbl at ifrestoring\@secondoftwo
-\def\bbl at pop@language{%
-  \expandafter\bbl at pop@lang\bbl at language@stack-\bbl at language@stack
-  \let\bbl at ifrestoring\@firstoftwo
-  \expandafter\bbl at set@language\expandafter{\languagename}%
-  \let\bbl at ifrestoring\@secondoftwo}
-\chardef\localeid\z@
-\def\bbl at id@last{0}    % No real need for a new counter
-\def\bbl at id@assign{%
-  \bbl at ifunset{bbl at id@@\languagename}%
-    {\count@\bbl at id@last\relax
-     \advance\count@\@ne
-     \bbl at csarg\chardef{id@@\languagename}\count@
-     \edef\bbl at id@last{\the\count@}%
-     \ifcase\bbl at engine\or
-       \directlua{
-         Babel = Babel or {}
-         Babel.locale_props = Babel.locale_props or {}
-         Babel.locale_props[\bbl at id@last] = {}
-         Babel.locale_props[\bbl at id@last].name = '\languagename'
-        }%
-      \fi}%
-    {}%
-    \chardef\localeid\bbl at cl{id@}}
-\expandafter\def\csname selectlanguage \endcsname#1{%
-  \ifnum\bbl at hymapsel=\@cclv\let\bbl at hymapsel\tw@\fi
-  \bbl at push@language
-  \aftergroup\bbl at pop@language
-  \bbl at set@language{#1}}
-\def\BabelContentsFiles{toc,lof,lot}
-\def\bbl at set@language#1{% from selectlanguage, pop@
-  \edef\languagename{%
-    \ifnum\escapechar=\expandafter`\string#1\@empty
-    \else\string#1\@empty\fi}%
-  \select at language{\languagename}%
-  % write to auxs
-  \expandafter\ifx\csname date\languagename\endcsname\relax\else
-    \if at filesw
-      \ifx\babel at aux\@gobbletwo\else % Set if single in the first, redundant
-        \protected at write\@auxout{}{\string\babel at aux{\languagename}{}}%
-      \fi
-      \bbl at usehooks{write}{}%
-    \fi
-  \fi}
-\def\select at language#1{% from set@, babel at aux
-  % set hymap
-  \ifnum\bbl at hymapsel=\@cclv\chardef\bbl at hymapsel4\relax\fi
-  % set name
-  \edef\languagename{#1}%
-  \bbl at fixname\languagename
-  \expandafter\ifx\csname date\languagename\endcsname\relax
-    \IfFileExists{babel-\languagename.tex}%
-      {\babelprovide{\languagename}}%
-      {}%
-  \fi
-  \bbl at iflanguage\languagename{%
-     \expandafter\ifx\csname date\languagename\endcsname\relax
-      \bbl at error
-        {Unknown language `#1'. Either you have\\%
-         misspelled its name, it has not been installed,\\%
-         or you requested it in a previous run. Fix its name,\\%
-         install it or just rerun the file, respectively. In\\%
-         some cases, you may need to remove the aux file}%
-        {You may proceed, but expect wrong results}%
-    \else
-      % set type
-      \let\bbl at select@type\z@
-      \expandafter\bbl at switch\expandafter{\languagename}%
-    \fi}}
-\def\babel at aux#1#2{%
-  \select at language{#1}%
-  \bbl at foreach\BabelContentsFiles{%
-    \@writefile{##1}{\babel at toc{#1}{#2}}}}% %% TODO - ok in plain?
-\def\babel at toc#1#2{%
-  \select at language{#1}}
-\let\select at language@x\select at language
-\newif\ifbbl at usedategroup
-\def\bbl at switch#1{%  from select@, foreign@
-  % make sure there is info for the language if so requested
-  \bbl at ensureinfo{#1}%
-  % restore
-  \originalTeX
-  \expandafter\def\expandafter\originalTeX\expandafter{%
-    \csname noextras#1\endcsname
-    \let\originalTeX\@empty
-    \babel at beginsave}%
-  \bbl at usehooks{afterreset}{}%
-  \languageshorthands{none}%
-  % set the locale id
-  \bbl at id@assign
-  % switch captions, date
-  \ifcase\bbl at select@type
-    \ifhmode
-      \hskip\z at skip % trick to ignore spaces
-      \csname captions#1\endcsname\relax
-      \csname date#1\endcsname\relax
-      \loop\ifdim\lastskip>\z@\unskip\repeat\unskip
-    \else
-      \csname captions#1\endcsname\relax
-      \csname date#1\endcsname\relax
-    \fi
-  \else
-    \ifbbl at usedategroup   % if \foreign... within \<lang>date
-      \bbl at usedategroupfalse
-      \ifhmode
-        \hskip\z at skip % trick to ignore spaces
-        \csname date#1\endcsname\relax
-        \loop\ifdim\lastskip>\z@\unskip\repeat\unskip
-      \else
-        \csname date#1\endcsname\relax
-      \fi
-    \fi
-  \fi
-  % switch extras
-  \bbl at usehooks{beforeextras}{}%
-  \csname extras#1\endcsname\relax
-  \bbl at usehooks{afterextras}{}%
-  %  > babel-ensure
-  %  > babel-sh-<short>
-  %  > babel-bidi
-  %  > babel-fontspec
-  % hyphenation - case mapping
-  \ifcase\bbl at opt@hyphenmap\or
-    \def\BabelLower##1##2{\lccode##1=##2\relax}%
-    \ifnum\bbl at hymapsel>4\else
-      \csname\languagename @bbl at hyphenmap\endcsname
-    \fi
-    \chardef\bbl at opt@hyphenmap\z@
-  \else
-    \ifnum\bbl at hymapsel>\bbl at opt@hyphenmap\else
-      \csname\languagename @bbl at hyphenmap\endcsname
-    \fi
-  \fi
-  \global\let\bbl at hymapsel\@cclv
-  % hyphenation - patterns
-  \bbl at patterns{#1}%
-  % hyphenation - mins
-  \babel at savevariable\lefthyphenmin
-  \babel at savevariable\righthyphenmin
-  \expandafter\ifx\csname #1hyphenmins\endcsname\relax
-    \set at hyphenmins\tw@\thr@@\relax
-  \else
-    \expandafter\expandafter\expandafter\set at hyphenmins
-      \csname #1hyphenmins\endcsname\relax
-  \fi}
-\long\def\otherlanguage#1{%
-  \ifnum\bbl at hymapsel=\@cclv\let\bbl at hymapsel\thr@@\fi
-  \csname selectlanguage \endcsname{#1}%
-  \ignorespaces}
-\long\def\endotherlanguage{%
-  \global\@ignoretrue\ignorespaces}
-\expandafter\def\csname otherlanguage*\endcsname#1{%
-  \ifnum\bbl at hymapsel=\@cclv\chardef\bbl at hymapsel4\relax\fi
-  \foreign at language{#1}}
-\expandafter\let\csname endotherlanguage*\endcsname\relax
-\providecommand\bbl at beforeforeign{}
-\edef\foreignlanguage{%
-  \noexpand\protect
-  \expandafter\noexpand\csname foreignlanguage \endcsname}
-\expandafter\def\csname foreignlanguage \endcsname{%
-  \@ifstar\bbl at foreign@s\bbl at foreign@x}
-\def\bbl at foreign@x#1#2{%
-  \begingroup
-    \let\BabelText\@firstofone
-    \bbl at beforeforeign
-    \foreign at language{#1}%
-    \bbl at usehooks{foreign}{}%
-    \BabelText{#2}% Now in horizontal mode!
-  \endgroup}
-\def\bbl at foreign@s#1#2{% TODO - \shapemode, \@setpar, ?\@@par
-  \begingroup
-    {\par}%
-    \let\BabelText\@firstofone
-    \foreign at language{#1}%
-    \bbl at usehooks{foreign*}{}%
-    \bbl at dirparastext
-    \BabelText{#2}% Still in vertical mode!
-    {\par}%
-  \endgroup}
-\def\foreign at language#1{%
-  % set name
-  \edef\languagename{#1}%
-  \bbl at fixname\languagename
-  \expandafter\ifx\csname date\languagename\endcsname\relax
-    \IfFileExists{babel-\languagename.tex}%
-      {\babelprovide{\languagename}}%
-      {}%
-  \fi
-  \bbl at iflanguage\languagename{%
-    \expandafter\ifx\csname date\languagename\endcsname\relax
-      \bbl at warning   % TODO - why a warning, not an error?
-        {Unknown language `#1'. Either you have\\%
-         misspelled its name, it has not been installed,\\%
-         or you requested it in a previous run. Fix its name,\\%
-         install it or just rerun the file, respectively. In\\%
-         some cases, you may need to remove the aux file.\\%
-         I'll proceed, but expect wrong results.\\%
-         Reported}%
-    \fi
-    % set type
-    \let\bbl at select@type\@ne
-    \expandafter\bbl at switch\expandafter{\languagename}}}
-\let\bbl at hyphlist\@empty
-\let\bbl at hyphenation@\relax
-\let\bbl at pttnlist\@empty
-\let\bbl at patterns@\relax
-\let\bbl at hymapsel=\@cclv
-\def\bbl at patterns#1{%
-  \language=\expandafter\ifx\csname l@#1:\f at encoding\endcsname\relax
-      \csname l@#1\endcsname
-      \edef\bbl at tempa{#1}%
-    \else
-      \csname l@#1:\f at encoding\endcsname
-      \edef\bbl at tempa{#1:\f at encoding}%
-    \fi
-  \@expandtwoargs\bbl at usehooks{patterns}{{#1}{\bbl at tempa}}%
-  %  > luatex
-  \@ifundefined{bbl at hyphenation@}{}{% Can be \relax!
-    \begingroup
-      \bbl at xin@{,\number\language,}{,\bbl at hyphlist}%
-      \ifin@\else
-        \@expandtwoargs\bbl at usehooks{hyphenation}{{#1}{\bbl at tempa}}%
-        \hyphenation{%
-          \bbl at hyphenation@
-          \@ifundefined{bbl at hyphenation@#1}%
-            \@empty
-            {\space\csname bbl at hyphenation@#1\endcsname}}%
-        \xdef\bbl at hyphlist{\bbl at hyphlist\number\language,}%
-      \fi
-    \endgroup}}
-\def\hyphenrules#1{%
-  \edef\bbl at tempf{#1}%
-  \bbl at fixname\bbl at tempf
-  \bbl at iflanguage\bbl at tempf{%
-    \expandafter\bbl at patterns\expandafter{\bbl at tempf}%
-    \languageshorthands{none}%
-    \expandafter\ifx\csname\bbl at tempf hyphenmins\endcsname\relax
-      \set at hyphenmins\tw@\thr@@\relax
-    \else
-      \expandafter\expandafter\expandafter\set at hyphenmins
-      \csname\bbl at tempf hyphenmins\endcsname\relax
-    \fi}}
-\let\endhyphenrules\@empty
-\def\providehyphenmins#1#2{%
-  \expandafter\ifx\csname #1hyphenmins\endcsname\relax
-    \@namedef{#1hyphenmins}{#2}%
-  \fi}
-\def\set at hyphenmins#1#2{%
-  \lefthyphenmin#1\relax
-  \righthyphenmin#2\relax}
-\ifx\ProvidesFile\@undefined
-  \def\ProvidesLanguage#1[#2 #3 #4]{%
-    \wlog{Language: #1 #4 #3 <#2>}%
-    }
-\else
-  \def\ProvidesLanguage#1{%
-    \begingroup
-      \catcode`\ 10 %
-      \@makeother\/%
-      \@ifnextchar[%]
-        {\@provideslanguage{#1}}{\@provideslanguage{#1}[]}}
-  \def\@provideslanguage#1[#2]{%
-    \wlog{Language: #1 #2}%
-    \expandafter\xdef\csname ver@#1.ldf\endcsname{#2}%
-    \endgroup}
-\fi
-\def\LdfInit{%
-  \chardef\atcatcode=\catcode`\@
-  \catcode`\@=11\relax
-  \input babel.def\relax
-  \catcode`\@=\atcatcode \let\atcatcode\relax
-  \LdfInit}
-\ifx\originalTeX\@undefined\let\originalTeX\@empty\fi
-\ifx\babel at beginsave\@undefined\let\babel at beginsave\relax\fi
-\providecommand\setlocale{%
-  \bbl at error
-    {Not yet available}%
-    {Find an armchair, sit down and wait}}
-\let\uselocale\setlocale
-\let\locale\setlocale
-\let\selectlocale\setlocale
-\let\localename\setlocale
-\let\textlocale\setlocale
-\let\textlanguage\setlocale
-\let\languagetext\setlocale
-\edef\bbl at nulllanguage{\string\language=0}
-\ifx\PackageError\@undefined
-  \def\bbl at error#1#2{%
-    \begingroup
-      \newlinechar=`\^^J
-      \def\\{^^J(babel) }%
-      \errhelp{#2}\errmessage{\\#1}%
-    \endgroup}
-  \def\bbl at warning#1{%
-    \begingroup
-      \newlinechar=`\^^J
-      \def\\{^^J(babel) }%
-      \message{\\#1}%
-    \endgroup}
-  \let\bbl at infowarn\bbl at warning
-  \def\bbl at info#1{%
-    \begingroup
-      \newlinechar=`\^^J
-      \def\\{^^J}%
-      \wlog{#1}%
-    \endgroup}
-\else
-  \def\bbl at error#1#2{%
-    \begingroup
-      \def\\{\MessageBreak}%
-      \PackageError{babel}{#1}{#2}%
-    \endgroup}
-  \def\bbl at warning#1{%
-    \begingroup
-      \def\\{\MessageBreak}%
-      \PackageWarning{babel}{#1}%
-    \endgroup}
-  \def\bbl at infowarn#1{%
-    \begingroup
-      \def\\{\MessageBreak}%
-      \GenericWarning
-        {(babel) \@spaces\@spaces\@spaces}%
-        {Package babel Info: #1}%
-    \endgroup}
-  \def\bbl at info#1{%
-    \begingroup
-      \def\\{\MessageBreak}%
-      \PackageInfo{babel}{#1}%
-    \endgroup}
-\fi
-\@ifpackagewith{babel}{silent}
-  {\let\bbl at info\@gobble
-   \let\bbl at infowarn\@gobble
-   \let\bbl at warning\@gobble}
-  {}
-\def\bbl at nocaption{\protect\bbl at nocaption@i}
-\def\bbl at nocaption@i#1#2{% 1: text to be printed 2: caption macro \langXname
-  \global\@namedef{#2}{\textbf{?#1?}}%
-  \@nameuse{#2}%
-  \bbl at warning{%
-    \@backslashchar#2 not set. Please, define\\%
-    it in the preamble with something like:\\%
-    \string\renewcommand\@backslashchar#2{..}\\%
-    Reported}}
-\def\bbl at tentative{\protect\bbl at tentative@i}
-\def\bbl at tentative@i#1{%
-  \bbl at warning{%
-    Some functions for '#1' are tentative.\\%
-    They might not work as expected and their behavior\\%
-    could change in the future.\\%
-    Reported}}
-\def\@nolanerr#1{%
-  \bbl at error
-    {You haven't defined the language #1\space yet.\\%
-     Perhaps you misspelled it or your installation\\%
-     is not complete}%
-    {Your command will be ignored, type <return> to proceed}}
-\def\@nopatterns#1{%
-  \bbl at warning
-    {No hyphenation patterns were preloaded for\\%
-     the language `#1' into the format.\\%
-     Please, configure your TeX system to add them and\\%
-     rebuild the format. Now I will use the patterns\\%
-     preloaded for \bbl at nulllanguage\space instead}}
-\let\bbl at usehooks\@gobbletwo
+\let\bbl at onlyswitch\@empty
+\input babel.def
+\let\bbl at onlyswitch\@undefined
+
 \endinput
 %%
 %% End of file `switch.def'.

Modified: trunk/Master/texmf-dist/tex/generic/babel/txtbabel.def
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/txtbabel.def	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/tex/generic/babel/txtbabel.def	2020-04-28 21:14:00 UTC (rev 54930)
@@ -150,6 +150,7 @@
    \def\@roman#1{\babelsublr{\ensureascii{\bbl at asciiroman#1}}}%
    \let\bbl at asciiRoman=\@Roman
    \def\@Roman#1{\babelsublr{\ensureascii{\bbl at asciiRoman#1}}}}{}
+
 \endinput
 %%
 %% End of file `txtbabel.def'.

Modified: trunk/Master/texmf-dist/tex/generic/babel/xebabel.def
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/xebabel.def	2020-04-28 21:11:54 UTC (rev 54929)
+++ trunk/Master/texmf-dist/tex/generic/babel/xebabel.def	2020-04-28 21:14:00 UTC (rev 54930)
@@ -91,35 +91,6 @@
           \expandafter\bbl at toglobal\csname selectfont \endcsname}%
       \fi}%
   \fi}
-\AddBabelHook{xetex}{loadkernel}{%
-  \begingroup
-      % Reset chars "80-"C0 to category "other", no case mapping:
-    \catcode`\@=11 \count@=128
-    \loop\ifnum\count@<192
-      \global\uccode\count@=0 \global\lccode\count@=0
-      \global\catcode\count@=12 \global\sfcode\count@=1000
-      \advance\count@ by 1 \repeat
-      % Other:
-    \def\O ##1 {%
-      \global\uccode"##1=0 \global\lccode"##1=0
-      \global\catcode"##1=12 \global\sfcode"##1=1000 }%
-      % Letter:
-    \def\L ##1 ##2 ##3 {\global\catcode"##1=11
-      \global\uccode"##1="##2
-      \global\lccode"##1="##3
-      % Uppercase letters have sfcode=999:
-      \ifnum"##1="##3 \else \global\sfcode"##1=999 \fi }%
-      % Letter without case mappings:
-    \def\l ##1 {\L ##1 ##1 ##1 }%
-    \l 00AA
-    \L 00B5 039C 00B5
-    \l 00BA
-    \O 00D7
-    \l 00DF
-    \O 00F7
-    \L 00FF 0178 00FF
-  \endgroup
-  \input #1\relax}
 \ifx\DisableBabelHook\@undefined\endinput\fi
 \AddBabelHook{babel-fontspec}{afterextras}{\bbl at switchfont}
 \AddBabelHook{babel-fontspec}{beforestart}{\bbl at ckeckstdfonts}
@@ -307,6 +278,7 @@
     \babel at save\bbl at langfeatures
     \edef\bbl at langfeatures{#2,}}}
 \input txtbabel.def
+
 \endinput
 %%
 %% End of file `xebabel.def'.



More information about the tex-live-commits mailing list.