texlive[44101] Master/texmf-dist: babel (28apr17)

commits+karl at tug.org commits+karl at tug.org
Fri Apr 28 23:20:37 CEST 2017


Revision: 44101
          http://tug.org/svn/texlive?view=revision&revision=44101
Author:   karl
Date:     2017-04-28 23:20:36 +0200 (Fri, 28 Apr 2017)
Log Message:
-----------
babel (28apr17)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/babel/README
    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/bbcompat.dtx
    trunk/Master/texmf-dist/source/latex/babel/bbunicode.dtx
    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/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/xebabel.def

Added Paths:
-----------
    trunk/Master/texmf-dist/doc/latex/babel/locale.zip

Modified: trunk/Master/texmf-dist/doc/latex/babel/README
===================================================================
--- trunk/Master/texmf-dist/doc/latex/babel/README	2017-04-28 21:17:39 UTC (rev 44100)
+++ trunk/Master/texmf-dist/doc/latex/babel/README	2017-04-28 21:20:36 UTC (rev 44101)
@@ -1,11 +1,11 @@
-Babel 3.9r
+Babel 3.9t
 ----------
 
-This is Babel 3.9r.
+This is Babel 3.9t.
 
 *** Babel 3.9o and 3.9p are deprecated ***
 *** For incompatibilities with polyglossia read the manual ***
-*** You must recreate the formats if coming from an older version ***
+*** You must recreate the formats if coming from version <3.9q ***
 
 Version 3.9a fixed lots of bugs and added some new features, intended
 mainly to make it compatible somehow with Unicode engines. Some bugs
@@ -106,6 +106,13 @@
       - bbunicode - Fixed a line break at \cs{foreignlanguage} with
         unloaded patterns. Also added \babelcatcodetablenum, just in
 	case.
+3.9s  - Bug fix - extra speces with \babelensure
+3.9t  - Part of the code for 3.10 has been "back-ported" to this
+        release, but they are only internal changes.
+      - Fix - with \babelhyphen{soft} the hyphen could vanish.
+      - English, Indonesian and Malay "dialects" now rely on the proxy
+        files provided by these languages (eg, american.ldf, melayu.ldf).
+	If you upgrade babel, you must upgrade those languages, too.
 
 * bbunicode.dtx
 1.0b  - Improvements by Elie Roux for LuaTeX.
@@ -122,5 +129,5 @@
 
 ------------
 Javier Bezos
-2016-04-23
+2017-04-28
 

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

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

Index: trunk/Master/texmf-dist/doc/latex/babel/locale.zip
===================================================================
--- trunk/Master/texmf-dist/doc/latex/babel/locale.zip	2017-04-28 21:17:39 UTC (rev 44100)
+++ trunk/Master/texmf-dist/doc/latex/babel/locale.zip	2017-04-28 21:20:36 UTC (rev 44101)

Property changes on: trunk/Master/texmf-dist/doc/latex/babel/locale.zip
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Modified: trunk/Master/texmf-dist/source/latex/babel/babel.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/babel/babel.dtx	2017-04-28 21:17:39 UTC (rev 44100)
+++ trunk/Master/texmf-dist/source/latex/babel/babel.dtx	2017-04-28 21:20:36 UTC (rev 44101)
@@ -1,6 +1,6 @@
 % \iffalse meta-comment
 %
-% Copyright 2012-2016 Javier Bezos and Johannes L. Braams.
+% Copyright 2012-2017 Javier Bezos and Johannes L. Braams.
 % Copyright 1989-2012 Johannes L. Braams and any individual authors
 % listed elsewhere in this file. 
 % All rights reserved.
@@ -36,7 +36,7 @@
 %\iffalse
 %% File 'babel.dtx'
 %\fi
-%%\ProvidesFile{babel.dtx}[2016/04/23 v3.9r The Babel package]
+%%\ProvidesFile{babel.dtx}[2017/04/28 v3.9t The Babel package]
 %\iffalse
 %
 % Babel DOCUMENT-STYLE option for LaTeX version 2.09 or plain TeX;
@@ -45,9 +45,9 @@
 %% Copyright (C) 1989-2008 by Johannes Braams,
 %%                            TeXniek
 %%                            all rights reserved.
-%% Copyright (C) 2013-2016 by Johannes Braams 
+%% Copyright (C) 2013-2017 by Johannes Braams 
 %%                            TeXniek
-%%                            by Javier Bezos
+%%                         by Javier Bezos
 %%                            all rights reserved.
 %
 %<*filedriver>
@@ -68,8 +68,6 @@
 \newcommand*\langlist{%
   \meta{language}\texttt{,}\meta{language}\texttt{,}...}
 \newcommand*\langvar{\m{lang}}
-\newcommand*\note[1]{}
-\newcommand*\bsl{\protect\bslash}
 \newcommand*\Lopt[1]{\textsf{#1}}
 \newcommand*\Lenv[1]{\textsf{#1}}
 \newcommand*\menv[1]{\char`\{#1\char`\}}
@@ -92,7 +90,7 @@
 \definecolor{lightgray}{gray}{0.95}
 \IfFileExists{listings.sty}{
   \usepackage{listings}
-  \lstset{
+  \lstdefinestyle{verbatim}{
     % gobble=1,
     columns=flexible,
     keepspaces,
@@ -118,7 +116,7 @@
     framerule=\fboxrule,
   }
   \let\verbatim\relax
-  \lstnewenvironment{verbatim}[1][]{\lstset{##1}}{}
+  \lstnewenvironment{verbatim}[1][]{\lstset{style=verbatim,##1}}{}
 }{}
 \def\PrintDescribeMacro#1{%
   \strut\MacroFont\color{thered}\normalsize\string#1}
@@ -196,8 +194,8 @@
 \vspace{2cm}\hspace{1.5cm}
 \begin{minipage}{5cm}
 \Large
-Version 3.9r\newline
-2016/04/23
+Version 3.9t\newline
+2017/04/28
 
 \vspace{1cm}
 \textit{Original author}\newline
@@ -407,13 +405,13 @@
 \Describe\foreignlanguage{\marg{language}\marg{text}}
 The command |\foreignlanguage| takes two arguments; the second
 argument is a phrase to be typeset according to the rules of the
-language named in its first argument. This command (1) only
-switches the extra definitions and the hyphenation rules for the
-language, \emph{not} the names and dates, (2) does not send
-information about the language to auxiliary files (i.e., the
-surrounding language is still in force), and (3) it works even if
-the language has not been set as package option (but in such a
-case it only sets the hyphenation patterns and a warning is shown).
+language named in its first one. This command (1) only switches the
+extra definitions and the hyphenation rules for the language,
+\emph{not} the names and dates, (2) does not send information about
+the language to auxiliary files (i.e., the surrounding language is
+still in force), and (3) it works even if the language has not been
+set as package option (but in such a case it only sets the hyphenation
+patterns and a warning is shown).
 
 \Describe{\begin\menv{otherlanguage*}}%
 {\marg{language}\Eenv{otherlanguage*}}
@@ -421,10 +419,10 @@
 Same as |\foreignlanguage| but as environment. Spaces after the
 environment are \textit{not} ignored.
 
-This environment (or in some cases |otherlanguage|) may be required for
-intermixing left-to-right typesetting with right-to-left typesetting
-in engines not supporting a change in the writing direction inside a
-line.
+This environment was also intended for intermixing left-to-right
+typesetting with right-to-left typesetting in engines not supporting a
+change in the writing direction inside a line. However, its behaviour
+is not always the expected one.
 
 \Describe{\begin\menv{hyphenrules}}{\marg{language}\Eenv{hyphenrules}}
 
@@ -453,9 +451,9 @@
 
 It defines |\text|\m{tag1}\marg{text} to be
 |\foreignlanguage|\marg{language1}\marg{text}, and |\begin|\marg{tag1}
-  to be |\begin{otherlanguage*}|\marg{language1}, and so on. Note
-    |\|\m{tag1} is also allowed, but remember set it locally inside a
-    group. So, with
+to be |\begin{otherlanguage*}|\marg{language1}, and so on. Note
+|\|\m{tag1} is also allowed, but remember set it locally inside a
+group. So, with
 \begin{verbatim}
 \babeltags{de = german}
 \end{verbatim}
@@ -472,6 +470,8 @@
 text
 \end{verbatim}
 
+Something like \verb|\babeltag{finnish = finnish}| is legitimate -- it
+defines |\textfinnish| and |\finnish|.
 \Describe\babelensure{|[include=|\m{commands}|,exclude=|\m{commands}%
   |,fontenc=|\m{encoding}|]|\marg{language}}
 
@@ -528,9 +528,9 @@
 (low level) or a language name (high level). Even the Latin script may
 require different encodings (ie, sets of glyphs) depending on the
 language, and therefore such a switch would be in a sense
-incomplete.\footnote{The so-called Unicode fonts does not improve the
+incomplete.\footnote{The so-called Unicode fonts do not improve the
 situation either. So, a font suited for Vietnamese is not necessarily
-suited for, say, romanization of Indic languages, and the fact it
+suited for, say, the romanization of Indic languages, and the fact it
 contains glyphs for Modern Greek does not mean it includes them for
 Classic Greek. As to directionality, it poses special challenges
 because it also affects individual characters and layout elements.}
@@ -601,6 +601,9 @@
 \item If on a certain level (system, language, user) there is a
   one-char shorthand, two-char ones starting with that 
   char and on the same level are ignored.
+\item Since they are active, a shorthand cannot contain the same
+  character in its definition (except if it is deactivated with, eg,
+  |string|).
 \end{enumerate}
 
 A typical error when using shorthands is the following:
@@ -787,7 +790,6 @@
 space.\footnote{This declaration serves to nothing, but it is
 preserved for backward compatibility.}
 
-
 \subsection{Package options}
 
 \New{3.9a}
@@ -1518,13 +1520,15 @@
   (high level, which in turn may switch the font encoding). Usage of things
   like |\latintext| is deprecated.\footnote{But not removed, for backward
   compatibility.}
+\item Please, for ``private'' internal macros do not use the |\bbl@|
+  prefix. It is used by \babel{} and it can lead to incompatibilities.
 \end{itemize}
 
 There are no special requirements for documenting your language
 files. Now they are not included in the base \babel{} manual, so
-provide a standalone document suited for your needs (and the
-corresponding PDF, if you like), as well as other files you think can
-be useful (eg, samples, readme).
+provide a standalone document suited for your needs, as well as other
+files you think can be useful. A PDF and a ``readme'' are strongly
+recommended.
 
 \subsection{Basic macros}
 
@@ -2307,7 +2311,7 @@
  \bibitem{ilatex} Joachim Schrod,
    \emph{International \LaTeX\ is ready to use},
    \emph{TUGboat} 11 (1990) \#1, p.~87--90.
- \bibitem{ilatex} Apostolos Syropoulos, Antonis Tsolomitis and Nick
+ \bibitem{STS} Apostolos Syropoulos, Antonis Tsolomitis and Nick
    Sofroniu,  
    \emph{Digital typography using \LaTeX},
    Springer, 2002, p.~301--373.
@@ -2317,8 +2321,6 @@
 \end{document}
 %</filedriver>
 %\fi
-% \changes{babel~3.7a}{1997/04/16}{Make multiple loading of
-%    \file{babel.def} impossible} 
 % \changes{babel~3.9a}{2012/05/16}{Now using \cs{ldf at quit} for the test} 
 %    \begin{macrocode}
 %<*core>
@@ -2335,57 +2337,6 @@
 %
 % \GetFileInfo{babel.dtx}
 %
-% \changes{babel~2.0a}{1990/04/02}{Added text about \file{german.sty}}
-% \changes{babel~2.0b}{1990/04/18}{Changed order of code to prevent
-%    plain \TeX from seeing all of it}
-% \changes{babel~2.1}{1990/04/24}{Modified user interface,
-%    \cs{langTeX} no longer necessary}
-% \changes{babel~2.1a}{1990/05/01}{Incorporated Nico's comments}
-% \changes{babel~2.1b}{1990/05/01}{rename \cs{language} to
-%    \cs{current at language}}
-% \changes{babel~2.1c}{1990/05/22}{abstract for report fixed, missing
-%    \texttt{\}}, found by Nicolas Brouard}
-% \changes{babel~2.1d}{1990/07/04}{Missing right brace in definition of
-%    abstract environment, found by Werenfried Spit}
-% \changes{babel~2.1e}{1990/07/16}{Incorporated more comments from
-%    Nico}
-% \changes{babel~2.2}{1990/07/17}{Renamed \cs{newlanguage} to
-%    \cs{addlanguage}}
-% \changes{babel~2.2a}{1990/08/27}{Modified the documentation
-%    somewhat}
-% \changes{babel~3.0}{1991/04/23}{Moved part of the code to hyphen.doc
-%    in preparation for \TeX~3.0}
-% \changes{babel~3.0a}{1991/05/21}{Updated comments in various places}
-% \changes{babel~3.0b}{1991/05/25}{Removed some problems in change log}
-% \changes{babel~3.0c}{1991/07/15}{Renamed \file{babel.sty} and
-%    \file{latexhax.sty} to \file{.com}}
-% \changes{babel~3.1}{1991/10/31}{Added the support for active
-%    characters and for extending a macro}
-% \changes{babel~3.1}{1991/11/05}{Removed the need for
-%    \file{latexhax}}
-% \changes{babel~3.2}{1991/11/10}{Some Changes by br}
-% \changes{babel~3.2a}{1992/02/15}{Fixups of the code and
-%    documentation}
-% \changes{babel~3.3}{1993/07/06}{Included driver file, and prepared
-%    for distribution}
-% \changes{babel~3.4}{1994/01/30}{Updated for \LaTeXe}
-% \changes{babel~3.4}{1994/02/28}{Added language definition file for
-%    bahasa}
-% \changes{babel~3.4b}{1994/05/18}{Added a small driver to be able to
-%    process just this file}
-% \changes{babel~3.5a}{1995/02/03}{Provided common code to handle the
-%    active double quote}
-% \changes{babel~3.5c}{1995/06/14}{corrected a few typos (PR1652)}
-% \changes{babel~3.5d}{1995/07/02}{Merged glyphs.dtx into this file}
-% \changes{babel~3.5f}{1995/07/13}{repaired a typo}
-% \changes{babel~3.5f}{1996/01/09}{replaced \cs{tmp}, \cs{bbl at tmp} and
-%    \cs{bbl at temp} with \cs{bbl at tempa}}
-% \changes{babel~3.5g}{1996/07/09}{replaced \cs{undefined} with
-%    \cs{@undefined} to be consistent with \LaTeX}
-% \changes{babel~3.7d}{1999/05/05}{Fixed a few typos in \cs{changes}
-%    entries which made typesetting the code impossible}
-% \changes{babel~3.7h}{2001/03/01}{Added a number of missing comment
-%    characters which caused spurious white space}
 % \changes{babel~3.8e}{2005/03/24}{Many enhancements to the text by
 %    Andrew Young} 
 % \changes{babel~3.9c}{2013/04/04}{Added the ``modifiers'' mechanism}
@@ -2433,10 +2384,15 @@
 %    little bit of literate programming.
 %
 %    \begin{macrocode}
-%<<version=3.9r>>
-%<<date=2016/04/23>>
+%<<version=3.9t>>
+%<<date=2017/04/28>>
 %    \end{macrocode}
 %
+% \section{Tools}
+%
+% \changes{babel~3.9t}{2017/04/22}{Added new helper macros. Not all are
+%   currently used, but will be in 3.10 -- \cs{bbl at trim},
+%   \cs{bbl at ifunset}, \cs{bbl at exp}, \cs{bbl at stripslash}}
 %    We define some basic macros which just make the code cleaner.
 %    |\bbl at add| is now used internally instead of |\addto| because of
 %    the unpredictable behaviour of the latter. Used in
@@ -2443,17 +2399,17 @@
 %    \file{babel.def} and in \file{babel.sty}, which means in \LaTeX{}
 %    is executed twice, but we need them when defining options and
 %    \file{babel.def} cannot be load until options have been defined.
+%    This does not hurt, but should be fixed somehow.
 % \changes{babel~3.9i}{2014/02/16}{\cs{@for} didn't work with
 %    Plain. Added \cs{bbl at loop}}
 %    \begin{macrocode}
 %<<*Basic macros>>
+\def\bbl at stripslash{\expandafter\@gobble\string}
 \def\bbl at add#1#2{%
-  \@ifundefined{\expandafter\@gobble\string#1}%
+  \bbl at ifunset{\bbl at stripslash#1}%
     {\def#1{#2}}%
     {\expandafter\def\expandafter#1\expandafter{#1#2}}}
 \def\bbl at csarg#1#2{\expandafter#1\csname bbl@#2\endcsname}%
-\long\def\bbl at afterelse#1\else#2\fi{\fi#1}
-\long\def\bbl at afterfi#1\fi{\fi#1}
 \def\bbl at loop#1#2#3{\bbl@@loop#1{#3}#2,\@nnil,}
 \def\bbl at loopx#1#2{\expandafter\bbl at loop\expandafter#1\expandafter{#2}}
 \def\bbl@@loop#1#2#3,{%
@@ -2461,6 +2417,147 @@
     \def#1{#3}#2\bbl at afterfi\bbl@@loop#1{#2}%
   \fi}
 \def\bbl at for#1#2#3{\bbl at loopx#1{#2}{\ifx#1\@empty\else#3\fi}}
+%    \end{macrocode}
+% \changes{babel~3.9t}{2017/04/22}{Use \cs{bbl at ifunset} instead of
+%    \cs{@ifundefined}.}
+%
+%  \begin{macro}{\bbl at add@list}
+%    This internal macro adds its second argument to a comma
+%    separated list in its first argument. When the list is not
+%    defined yet (or empty), it will be initiated. It presumes
+%    expandable character strings.
+% \changes{babel~3.9t}{2017/04/22}{Redefined to avoid infinite loops
+%    if the macro is \cs{relax}.}
+%    \begin{macrocode}
+\def\bbl at add@list#1#2{%
+  \edef#1{%
+    \bbl at ifunset{\bbl at stripslash#1}%
+      {}%
+      {\ifx#1\@empty\else#1,\fi}%
+    #2}}
+%    \end{macrocode}
+%  \end{macro}
+%
+%  \begin{macro}{\bbl at afterelse}
+%  \begin{macro}{\bbl at afterfi}
+%    Because the code that is used in the handling of active
+%    characters may need to look ahead, we take extra care to `throw'
+%    it over the |\else| and |\fi| parts of an
+%    |\if|-statement\footnote{This code is based on code presented in
+%    TUGboat vol. 12, no2, June 1991 in ``An expansion Power Lemma''
+%    by Sonja Maus.}. These macros will break if another |\if...\fi|
+%    statement appears in one of the arguments and it is not enclosed
+%    in braces.
+%    \begin{macrocode}
+\long\def\bbl at afterelse#1\else#2\fi{\fi#1}
+\long\def\bbl at afterfi#1\fi{\fi#1}
+%    \end{macrocode}
+%  \end{macro}
+%  \end{macro}
+%
+% The following piece of code is stolen (with some changes) from
+% \textsf{keyval}, by David Carlisle. It defines two macros:
+% |\bbl at trim| and |bbl at trim@def|. The first one strips the leading
+% and trailing spaces from the second argument and then applies the
+% first argument (a macro, |\toks@| and the like). The second one, as
+% its name suggests, defines the first argument as the stripped second
+% argument.
+%
+%    \begin{macrocode}
+\def\bbl at tempa#1{%
+  \long\def\bbl at trim##1##2{%
+    \futurelet\bbl at trim@a\bbl at trim@c##2\@nil\@nil#1\@nil\relax{##1}}%
+  \def\bbl at trim@c{%
+    \ifx\bbl at trim@a\@sptoken
+      \expandafter\bbl at trim@b
+    \else
+      \expandafter\bbl at trim@b\expandafter#1%
+    \fi}%
+  \long\def\bbl at trim@b#1##1 \@nil{\bbl at trim@i##1}}
+\bbl at tempa{ }
+\long\def\bbl at trim@i#1\@nil#2\relax#3{#3{#1}}
+\long\def\bbl at trim@def#1{\bbl at trim{\def#1}}
+%    \end{macrocode}
+%
+%    To check if a macro is defined, we create a new macro, which does
+%    the same as |\@ifundefined|. However, in an $\epsilon$-tex
+%    engine, it is redefined more robust
+%
+%    \begin{macrocode}
+\def\bbl at ifunset#1{%
+  \expandafter\ifx\csname#1\endcsname\relax
+    \expandafter\@firstoftwo
+  \else
+    \expandafter\@secondoftwo
+  \fi}
+\bbl at ifunset{ifcsname}%
+  {}%
+  {\def\bbl at ifunset#1{%
+     \ifcsname#1\endcsname
+       \expandafter\ifx\csname#1\endcsname\relax
+         \bbl at afterelse\expandafter\@firstoftwo
+       \else
+         \bbl at afterfi\expandafter\@secondoftwo
+       \fi
+     \else
+       \expandafter\@firstoftwo
+     \fi}}
+%    \end{macrocode}
+%
+% A tool from \textsf{url}, by Donald
+% Arseneau, which test if a string is empty or space.
+%
+%    \begin{macrocode}
+\def\bbl at ifblank#1{%
+  \bbl at ifblank@i#1\@nil\@nil\@secondoftwo\@firstoftwo\@nil}
+\long\def\bbl at ifblank@i#1#2\@nil#3#4#5\@nil{#4}
+%    \end{macrocode}
+%
+% Now, just syntactical sugar, but it makes partial expansion of some
+% code a lot more simple and readable. Here |\\| stands for
+% |\noexpand| and |\<..>| for |\noexpand| applied to a built macro
+% name (the latter does not define the macro if undefined to |\relax|,
+% because it is created locally). The result may be followed by extra
+% arguments, if necessary.
+%
+%    \begin{macrocode}
+\def\bbl at exp#1{%
+  \begingroup
+    \let\\\noexpand
+    \def\<##1>{\expandafter\noexpand\csname##1\endcsname}%
+    \edef\bbl at exp@aux{\endgroup#1}%
+  \bbl at exp@aux}
+%    \end{macrocode}
+%
+% Two more tools.  |\bbl at samestring| first expand its arguments and
+% then compare their expansion (sanitized, so that the catcodes do not
+% matter). |\bbl at engine| takes the following values: 0 is pdf\TeX, 1
+% is \luatex, and 2 is \xetex. You may use the latter it in your
+% language style if you want.
+%
+%    \begin{macrocode}
+\def\bbl at ifsamestring#1#2{%
+  \begingroup
+    \protected at edef\bbl at tempb{#1}%
+    \edef\bbl at tempb{\expandafter\strip at prefix\meaning\bbl at tempb}%
+    \protected at edef\bbl at tempc{#2}%
+    \edef\bbl at tempc{\expandafter\strip at prefix\meaning\bbl at tempc}%
+    \ifx\bbl at tempb\bbl at tempc
+      \aftergroup\@firstoftwo
+    \else
+      \aftergroup\@secondoftwo
+    \fi
+  \endgroup}
+\chardef\bbl at engine=%
+  \ifx\directlua\@undefined
+    \ifx\XeTeXinputencoding\@undefined
+      \z@
+    \else
+      \tw@
+    \fi
+  \else
+    \@ne
+  \fi
 %<</Basic macros>>
 %    \end{macrocode}
 %
@@ -2549,8 +2646,6 @@
 %    other purposes in these formats. Therefore |\addlanguage| is
 %    defined using a definition based on the macros used to define
 %    |\newlanguage| in plain \TeX\ version~3.0.
-% \changes{babel~3.2}{1991/11/11}{Added a \texttt{\%}, removed
-%    \texttt{by}}
 %
 %    For formats based on plain version~3.0 the definition of
 %    |\newlanguage| can be simply copied, removing |\outer|.
@@ -2563,7 +2658,7 @@
     \global\advance\last at language\@ne
     \ifnum\last at language<\@cclvi
     \else
-        \errmessage{No room for a new \string\language!}%
+      \errmessage{No room for a new \string\language!}%
     \fi
     \global\chardef#1\last at language
     \wlog{\string#1 = \string\language\the\last at language}}
@@ -2577,9 +2672,6 @@
 %  \end{macro}
 %
 %    Identify each file that is produced from this source file.
-% \changes{babel~3.4c}{1995/04/28}{lhyphen.cfg has become
-%    lthyphen.cfg}
-% \changes{babel~3.5b}{1995/01/25}{lthyphen.cfg has become hyphen.cfg}
 %    \begin{macrocode}
 %<*driver&!user>
 \ProvidesFile{babel.drv}[<@date@> <@version@>]
@@ -2605,7 +2697,6 @@
 %    previously loaded (mainly, \file{hyphen.cfg}). If not, load it
 %    now. We cannot load |babel.def| here because we first need to
 %    declare and process the package options.
-% \changes{babel~3.0d}{1991/10/29}{Removed use of \cs{@ifundefined}}
 % \changes{babel~3.9a}{2012/08/11}{Now switch.def is loaded always, so
 %    that there is no need to rebuild formats just to update babel}
 % \changes{babel~3.9a}{2012/12/13}{But switch.def is loaded only if
@@ -2612,8 +2703,6 @@
 %    loaded in a different version (or not loaded)}
 % \changes{babel~3.9a}{2013/01/14}{Added the debug option}
 % \changes{babel~3.9a}{2013/02/05}{Added \cs{bbl at add}}
-% \changes{babel~3.6a}{1996/11/02}{Removed \cs{babel at core@loaded}, no
-%    longer needed with the advent of \cs{LdfInit}}
 %
 %    \section{The Package File (\LaTeX)}
 %
@@ -2641,17 +2730,11 @@
 %    \LaTeX forgets about the first loading. After |switch.def| has
 %    been loaded (above) and |\AfterBabelLanguage| defined, exits.
 %
-% \changes{babel~3.5d}{1995/07/04}{Added options to influence
-%    behaviour of active acute and grave accents}
 % \changes{babel~3.9a}{2012/10/05}{preset option started,
 %    party stolen from fontenc}
 % \changes{babel~3.9a}{2012/10/17}{Hooks started}
 % \changes{babel~3.9a}{2013/02/07}{Rejected preset, and replaced by
 %   base}
-% \changes{babel~3.5g}{1996/10/10}{We need at least \LaTeX\ from
-%    December 1994}
-% \changes{babel~3.6k}{1999/03/18}{We need at least \LaTeX\ from
-%    June 1998}
 % \changes{babel~3.9q}{2016/02/11}{Load patterns with option base.
 %    To be improved. Moved showlanguages before base}
 %    \begin{macrocode}
@@ -2689,9 +2772,9 @@
   \bbl at languages
 \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 \textsf{polyglossia}, too.
+% 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}
 \@ifpackagewith{babel}{base}{%
   \ifx\directlua\@undefined
@@ -2716,7 +2799,7 @@
 %    and assigned to |\BabelModifiers| at |\bbl at load@language|; when
 %    no modifiers have been given, the former is |\relax|. How
 %    modifiers are handled are left to language styles; they can use
-%    |\in@|, loop them with |\@for| o load |keyval|).
+%    |\in@|, loop them with |\@for| or load |keyval|, for example).
 % \changes{babel~3.9e}{2013/04/15}{Bug fixed - a dot was added in
 %    key=value pairs}
 %
@@ -2745,10 +2828,6 @@
 %    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 this can help.
-% \changes{babel~3.6f}{1997/01/14}{Added option
-%    \Lopt{KeepShorthandsActive}}
-% \changes{babel~3.7a}{1997/03/21}{No longer define the control
-%    sequence \cs{KeepShorthandsActive}}
 % \changes{babel~3.9a}{2012/08/14}{Implemented the \texttt{noconfigs}
 %    option}
 % \changes{babel~3.9a}{2012/09/26}{Implemented the
@@ -2786,8 +2865,8 @@
 %    options.
 %    \begin{macrocode}
 \def\bbl at tempa#1=#2\bbl at tempa{%
-  \expandafter\ifx\csname bbl at opt@#1\endcsname\@nnil
-    \expandafter\edef\csname bbl at opt@#1\endcsname{#2}%
+  \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\\%
@@ -2808,9 +2887,7 @@
   \ifin@
     \expandafter\bbl at tempa\CurrentOption\bbl at tempa
   \else
-    \edef\bbl at language@opts{%
-      \ifx\bbl at language@opts\@empty\else\bbl at language@opts,\fi
-      \CurrentOption}%
+    \bbl at add@list\bbl at language@opts{\CurrentOption}%
   \fi}
 %    \end{macrocode}
 %    Now we finish the first pass (and start over).
@@ -2889,7 +2966,9 @@
 %    |\bbl at opt@safe| says which macros are redefined (B for bibs and R
 %    for refs). By default, both are set. 
 %    \begin{macrocode}
-\@ifundefined{bbl at opt@safe}{\def\bbl at opt@safe{BR}}{}
+\ifx\bbl at opt@safe\@undefined
+  \def\bbl at opt@safe{BR}
+\fi
 \ifx\bbl at opt@main\@nnil\else
   \edef\bbl at language@opts{%
     \ifx\bbl at language@opts\@empty\else\bbl at language@opts,\fi
@@ -2899,66 +2978,18 @@
 %
 %  \subsection{Language options}
 %
-% \changes{babel~3.6c}{1997/01/05}{When \cs{LdfInit} is undefined we
-%    need to load \file{babel.def} from \file{babel.sty}}
-% \changes{babel~3.6l}{1999/04/03}{Don't load \file{babel.def} now,
-%    but rather define \cs{LdfInit} temporarily in order to load
-%    \file{babel.def} at the right time, preventing problems with the
-%    temporary definition of \cs{bbl at redefine}}
-% \changes{babel~3.6r}{1999/04/12}{We \textbf{do} need to load
-%    \file{babel.def} right now as \cs{ProvidesLanguage} needs to be
-%    defined before the \file{.ldf} files are read and the reason for
-%    for 3.6l has been removed}
 % \changes{babel~3.9a}{2012/06/15}{Rewritten the loading mechanism, so
 %    that languages not declared are also correctly recognized, even
 %    if given as global options} 
 % \changes{babel~3.9a}{2012/08/12}{Revised the loading mechanism}
-% \changes{babel~3.5a}{1995/03/14}{Changed extension of language
-%    definition files to \texttt{ldf}}
-% \changes{babel~3.5d}{1995/07/02}{Load language definition files
-%    \emph{after} the check for the hyphenation patterns}
-% \changes{babel~3.5g}{1996/10/04}{Added option \Lopt{afrikaans}}
-% \changes{babel~3.7g}{2001/02/09}{Added option \Lopt{acadian}}
 % \changes{babel~3.8c}{2004/06/12}{Added option \Lopt{australian}}
 % \changes{babel~3.8h}{2005/11/23}{Added option \Lopt{albanian}}
-% \changes{babel~3.6i}{1997/02/20}{Added the \Lopt{Basque} option}
 % \changes{babel~3.8h}{2005/11/23}{added synonyms \Lopt{indonesian},
 %    \Lopt{indon} and \Lopt{bahasai} for the original bahasa
 %    (indonesia) support}
 % \changes{babel~3.8h}{2005/11/23}{added \Lopt{malay}, \Lopt{meyalu}
 %    and \Lopt{bahasam} for the Bahasa Malaysia support}
-% \changes{babel~3.5b}{1995/05/25}{Added \Lopt{brazilian} as
-%    alternative for \Lopt{brazil}}
-% \changes{babel~3.5d}{1995/07/02}{Added \Lopt{british} as an
-%    alternative for \Lopt{english} with a preference for british
-%    hyphenation}
-% \changes{babel~3.7f}{2000/09/21}{Added the \Lopt{bulgarian} option}
-% \changes{babel~3.7g}{2001/02/07}{Added option \Lopt{canadian}}
-% \changes{babel~3.7g}{2001/02/09}{Added option \Lopt{canadien}}
-% \changes{babel~3.5b}{1995/06/06}{Added the \Lopt{estonian} option}
-% \changes{babel~3.5f}{1996/01/10}{Now use the file \file{frenchb.ldf}
-%    from Daniel Flipo for french support}
-% \changes{babel~3.6e}{1997/01/08}{Added option \Lopt{frenchb} an
-%    alias for \Lopt{francais}}
-% \changes{babel~3.5d}{1995/07/02}{Load \file{french.ldf} when it is
-%    found instead of \file{frenchb.ldf}}
-% \changes{babel~3.7j}{2003/06/07}{\emph{only} load
-%    \file{frenchb.ldf}}
-% \changes{babel~3.5f}{1996/05/31}{Added the \Lopt{greek} option}
-% \changes{babel~3.7a}{1997/11/13}{Added the \Lopt{polutonikogreek}
-%    option}
-% \changes{babel~3.7c}{1999/04/22}{set the correct language attribute
-%    for polutoniko greek}
-% \changes{babel~3.7a}{1998/03/27}{Added the \Lopt{hebrew} option}
-% \changes{babel~3.7b}{1998/06/25}{Added the \Lopt{latin} option}
-% \changes{babel~3.7m}{2003/11/13}{Added the \Lopt{interlingua}
-%    option}
-% \changes{babel~3.6p}{1999/04/10}{Added the \Lopt{ngerman} and
-%    \Lopt{naustrian} options}
-% \changes{babel~3.7f}{2000/09/26}{Added the \Lopt{samin} option}
 % \changes{babel~3.8c}{2004/06/12}{Added the \Lopt{newzealand} option}
-% \changes{babel~3.6e}{1997/01/08}{Added options \Lopt{UKenglish} and
-%    \Lopt{USenglish}}
 % \changes{babel~3.9i}{2014/03/01}{Removed German options, because
 %    they are now loaded directly}
 % \changes{babel~3.9m}{2015/07/28}{Added melayu (meyalu preserved for
@@ -2989,18 +3020,15 @@
        headfoot=, strings=, config=, hyphenmap=, or a language name.}}}
 %    \end{macrocode}
 %    Now, we set language options whose names are different from |ldf| files.
+% 
+% \changes{babel~3.9t}{2017/04/23}{Removed options for English, Indonesian and
+%    Malay, now handled with proxy files}
+%
 %    \begin{macrocode}
 \DeclareOption{acadian}{\bbl at load@language{frenchb}}
 \DeclareOption{afrikaans}{\bbl at load@language{dutch}}
-\DeclareOption{american}{\bbl at load@language{english}}
-\DeclareOption{australian}{\bbl at load@language{english}}
-\DeclareOption{bahasa}{\bbl at load@language{bahasai}}
-\DeclareOption{bahasai}{\bbl at load@language{bahasai}}
-\DeclareOption{bahasam}{\bbl at load@language{bahasam}}
 \DeclareOption{brazil}{\bbl at load@language{portuges}}
 \DeclareOption{brazilian}{\bbl at load@language{portuges}}
-\DeclareOption{british}{\bbl at load@language{english}}
-\DeclareOption{canadian}{\bbl at load@language{english}}
 \DeclareOption{canadien}{\bbl at load@language{frenchb}}
 \DeclareOption{francais}{\bbl at load@language{frenchb}}
 \DeclareOption{french}{\bbl at load@language{frenchb}}%
@@ -3008,13 +3036,7 @@
   \input{rlbabel.def}%
   \bbl at load@language{hebrew}}
 \DeclareOption{hungarian}{\bbl at load@language{magyar}}
-\DeclareOption{indon}{\bbl at load@language{bahasai}}
-\DeclareOption{indonesian}{\bbl at load@language{bahasai}}
 \DeclareOption{lowersorbian}{\bbl at load@language{lsorbian}}
-\DeclareOption{malay}{\bbl at load@language{bahasam}}
-\DeclareOption{meyalu}{\bbl at load@language{bahasam}}
-\DeclareOption{melayu}{\bbl at load@language{bahasam}}
-\DeclareOption{newzealand}{\bbl at load@language{english}}
 \DeclareOption{nynorsk}{\bbl at load@language{norsk}}
 \DeclareOption{polutonikogreek}{%
   \bbl at load@language{greek}%
@@ -3021,13 +3043,11 @@
   \languageattribute{greek}{polutoniko}}
 \DeclareOption{portuguese}{\bbl at load@language{portuges}}
 \DeclareOption{russian}{\bbl at load@language{russianb}}
-\DeclareOption{UKenglish}{\bbl at load@language{english}}
 \DeclareOption{ukrainian}{\bbl at load@language{ukraineb}}
 \DeclareOption{uppersorbian}{\bbl at load@language{usorbian}}
-\DeclareOption{USenglish}{\bbl at load@language{english}}
 %    \end{macrocode}
 %
-%    Another way to extend the list of `known' options for \babel\ is
+%    Another way to extend the list of `known' options for \babel\ was
 %    to create the file \file{bblopts.cfg} in which one can add option
 %    declarations. However, this mechanism is deprecated -- if you
 %    want an alternative name for a language, just create a new |.ldf|
@@ -3034,8 +3054,6 @@
 %    file loading the actual one. You can also set the name
 %    of the file with the package option |config=<name>|, which will
 %    load |<name>.cfg| instead. 
-% \changes{babel~3.6i}{1997/03/15}{Added the possibility to have a
-%    \file{bblopts.cfg} file with option declarations.}
 % \changes{babel~3.9a}{2012/06/28}{Added the \cs{AfterBabelLanguage}
 %    mechanism, to be used mainly with the local cfg file.}
 % \changes{babel~3.9a}{2012/06/31}{Now you can set the name of the
@@ -3068,7 +3086,7 @@
 %    file are the same.
 %    \begin{macrocode}
 \bbl at for\bbl at tempa\bbl at language@opts{%
-  \@ifundefined{ds@\bbl at tempa}%
+  \bbl at ifunset{ds@\bbl at tempa}%
     {\edef\bbl at tempb{%
        \noexpand\DeclareOption
          {\bbl at tempa}%
@@ -3083,7 +3101,7 @@
 %    option could be a language.
 %    \begin{macrocode}
 \bbl at for\bbl at tempa\@classoptionslist{%
-  \@ifundefined{ds@\bbl at tempa}%
+  \bbl at ifunset{ds@\bbl at tempa}%
     {\IfFileExists{\bbl at tempa.ldf}%
       {\edef\bbl at tempb{%
          \noexpand\DeclareOption
@@ -3103,7 +3121,6 @@
 %    \end{macrocode}
 %    And we are done, because all options for this pass has been
 %    declared. Those already processed in the first pass are just ignored.
-% \changes{babel~3.6i}{1997/03/12}{Added default option}
 % \changes{babel~3.9a}{2012/12/22}{Default option does nothing}
 %
 %    The options have to be processed in the order in which the user
@@ -3150,15 +3167,11 @@
     {Too late for \string\AfterBabelLanguage}%
     {Languages have been loaded, so I can do nothing}}
 %    \end{macrocode}
-% \changes{babel~3.7c}{1999/03/13}{Added an error message for when no
-%    language option was specified}
+%
 %    In order to catch the case where the user forgot to specify a
 %    language we check whether |\bbl at main@language|, has become
 %    defined. If not, no language has been loaded and an error
 %    message is displayed.
-% \changes{babel~3.7c}{1999/04/09}{No longer us a redefinition of an
-%    internal macro, just check \cs{bbl at main@language} and load
-%    \file{babel.def}}
 % \changes{babel~3.9a}{2012/06/24}{Now babel is not loaded to prevent
 %    the document from raising errors after fixing it}
 %    \begin{macrocode}
@@ -3212,10 +3225,6 @@
 %
 %    \subsection{Tools}
 %
-%    |\bbl at engine| takes the following values: 0 is pdf\TeX, 1 is
-%    \luatex, and 2 is \xetex. You may use it in your language style
-%    if necessary.
-%
 % \changes{babel~3.9k}{2014/03/24}{Added definition for
 %    \cs{uselanguage}}
 % \changes{babel~3.9n}{2015/12/21}{Define a few macros for 2.09}
@@ -3258,38 +3267,8 @@
 \fi
 <@Load patterns in luatex@>
 <@Basic macros@>
-\def\bbl at csarg#1#2{\expandafter#1\csname bbl@#2\endcsname}%
-\chardef\bbl at engine=%
-  \ifx\directlua\@undefined
-    \ifx\XeTeXinputencoding\@undefined
-      \z@
-    \else
-      \tw@
-    \fi
-  \else
-    \@ne
-  \fi
 %    \end{macrocode}
 %
-%  \begin{macro}{\bbl at afterelse}
-%  \begin{macro}{\bbl at afterfi}
-%    Because the code that is used in the handling of active
-%    characters may need to look ahead, we take extra care to `throw'
-%    it over the |\else| and |\fi| parts of an
-%    |\if|-statement\footnote{This code is based on code presented in
-%    TUGboat vol. 12, no2, June 1991 in ``An expansion Power Lemma''
-%    by Sonja Maus.}. These macros will break if another |\if...\fi|
-%    statement appears in one of the arguments and it is not enclosed
-%    in braces.
-% \changes{babel~3.6i}{1997/02/20}{Made \cs{bbl at afterelse} and
-%    \cs{bbl at afterfi} \cs{long}}
-%    \begin{macrocode}
-\long\def\bbl at afterelse#1\else#2\fi{\fi#1}
-\long\def\bbl at afterfi#1\fi{\fi#1}
-%    \end{macrocode}
-%  \end{macro}
-%  \end{macro}
-%
 %  \begin{macro}{\addto}
 %    For each language four control sequences have to be defined that
 %    control the language-specific definitions. To be able to add
@@ -3307,10 +3286,6 @@
 %    \meta{control sequence} is \emph{re}defined, using the contents
 %    of the token register.
 %
-% \changes{babel~3.1}{1991/11/05}{Added macro}
-% \changes{babel~3.4}{1994/02/04}{Changed to use toks register}
-% \changes{babel~3.6b}{1996/12/30}{Also check if control sequence
-%    expands to \cs{relax}}
 %    \begin{macrocode}
 \def\addto#1#2{%
   \ifx#1\@undefined
@@ -3331,8 +3306,6 @@
 %    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.
-% \changes{babel~3.7c}{1999/04/30}{Only execute
-%    \cs{initiate at active@char} once for each character}
 % \changes{babel~3.9a}{1999/04/30}{Added \cs{bbl at withactive}}
 %    \begin{macrocode}
 \def\bbl at withactive#1#2{%
@@ -3343,7 +3316,6 @@
 %
 %
 %  \begin{macro}{\bbl at redefine}
-% \changes{babel~3.5f}{1995/11/15}{Macro added}
 %    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
@@ -3355,7 +3327,7 @@
 %    new control sequence, |\org at ...|
 %    \begin{macrocode}
 \def\bbl at redefine#1{%
-  \edef\bbl at tempa{\expandafter\@gobble\string#1}%
+  \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}
@@ -3367,12 +3339,11 @@
 %  \end{macro}
 %
 %  \begin{macro}{\bbl at redefine@long}
-% \changes{babel~3.6f}{1997/01/14}{Macro added}
 %    This version of |\babel at redefine| can be used to redefine |\long|
 %    commands such as |\ifthenelse|.
 %    \begin{macrocode}
 \def\bbl at redefine@long#1{%
-  \edef\bbl at tempa{\expandafter\@gobble\string#1}%
+  \edef\bbl at tempa{\bbl at stripslash#1}%
   \expandafter\let\csname org@\bbl at tempa\endcsname#1%
   \expandafter\long\expandafter\def\csname\bbl at tempa\endcsname}
 \@onlypreamble\bbl at redefine@long
@@ -3380,9 +3351,6 @@
 %  \end{macro}
 %
 %  \begin{macro}{\bbl at redefinerobust}
-% \changes{babel~3.5f}{1995/11/15}{Macro added}
-% \changes{babel~3.5f}{1996/04/09}{Define \cs*{foo } instead of
-%    \cs{foo}}
 %    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
@@ -3391,16 +3359,12 @@
 %    afterwards.  Therefore all we need to do now is define \verb*|\foo |.
 %    \begin{macrocode}
 \def\bbl at redefinerobust#1{%
-  \edef\bbl at tempa{\expandafter\@gobble\string#1}%
-  \expandafter\ifx\csname\bbl at tempa\space\endcsname\relax
-    \expandafter\let\csname org@\bbl at tempa\endcsname#1%
-    \expandafter\edef\csname\bbl at tempa\endcsname{\noexpand\protect
-      \expandafter\noexpand\csname\bbl at tempa\space\endcsname}%
-  \else
-    \expandafter\let\csname org@\bbl at tempa\expandafter\endcsname
-                    \csname\bbl at tempa\space\endcsname
-  \fi
-  \expandafter\def\csname\bbl at tempa\space\endcsname}
+  \edef\bbl at tempa{\bbl at stripslash#1}%
+  \bbl at ifunset{\bbl at tempa\space}%
+    {\expandafter\let\csname org@\bbl at tempa\endcsname#1%
+     \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.
@@ -3422,10 +3386,10 @@
 %
 %    \begin{macrocode}
 \def\AddBabelHook#1#2{%
-  \@ifundefined{bbl at hk@#1}{\EnableBabelHook{#1}}{}%
+  \bbl at ifunset{bbl at hk@#1}{\EnableBabelHook{#1}}{}%
   \def\bbl at tempa##1,#2=##2,##3\@empty{\def\bbl at tempb{##2}}%
   \expandafter\bbl at tempa\bbl at evargs,#2=,\@empty
-  \@ifundefined{bbl at ev@#1@#2}%
+  \bbl at ifunset{bbl at ev@#1@#2}%
     {\bbl at csarg\bbl at add{ev@#2}{\bbl at elt{#1}}%
      \bbl at csarg\newcommand}%
     {\bbl at csarg\let{ev@#1@#2}\relax
@@ -3474,6 +3438,9 @@
 % \changes{babel~3.9i}{2014/02/14}{Macro \cs{babelensure} added}
 % \changes{babel~3.9k}{2014/03/23}{Encapsulate \cs{foreignlanguage} in
 %   \cs{bbl at ensure@}language, to "protect" strings}
+% \changes{babel~3.9s}{2017/04/10}{Bug fix - extra spaces because a
+%   missing percent}
+% \changes{babel~3.9s}{2017/04/10}{\cs{bbl at ensure@lang} defined only once}
 %
 %    \begin{macrocode}
 \newcommand\babelensure[2][]{%
@@ -3496,28 +3463,27 @@
     \expandafter\bbl at add\expandafter\bbl at tempc\expandafter{%
       \expandafter{\bbl at ens@exclude}}%
     \toks@\expandafter{\bbl at tempc}%
-    \edef\x{%
-      \endgroup
-      \noexpand\@namedef{bbl at e@#2}{\the\toks@{\bbl at ens@fontenc}}}%
-    \x}
+    \bbl at exp{%
+  \endgroup
+  \def\<bbl at e@#2>{\the\toks@{\bbl at ens@fontenc}}}}
 \def\bbl at ensure#1#2#3{%
   \def\bbl at tempb##1{% elt for \bbl at ensured list
     \ifx##1\@empty\else
       \in@{##1}{#2}%
       \ifin@\else
+        \bbl at ifunset{bbl at ensure@\languagename}%
+          {\bbl at exp{%
+            \\\DeclareRobustCommand\<bbl at ensure@\languagename>[1]{%
+              \\\foreignlanguage{\languagename}%
+              {\ifx\relax#3\else
+                \\\fontencoding{#3}\\\selectfont
+               \fi
+               ########1}}}}%
+          {}%
         \toks@\expandafter{##1}%
-        \edef\bbl at tempa{%
-          \noexpand\DeclareRobustCommand
-          \bbl at csarg\noexpand{ensure@\languagename}[1]{%
-            \noexpand\foreignlanguage{\languagename}%
-            {\ifx\relax#3\else
-              \noexpand\fontencoding{#3}\noexpand\selectfont
-             \fi
-             ########1}}}%
-        \bbl at tempa
         \edef##1{%
            \bbl at csarg\noexpand{ensure@\languagename}%
-           {\the\toks@}}
+           {\the\toks@}}%
       \fi
       \expandafter\bbl at tempb
     \fi}%
@@ -3559,8 +3525,6 @@
 %    `=', because it is sometimes used in constructions with the
 %    |\let| primitive. Therefore we store its current catcode and
 %    restore it later on.
-% \changes{babel~3.7o}{2003/11/26}{make sure the equals sign has its
-%    default category code}
 %
 %    Now we check whether we should perhaps stop the processing of
 %    this file. To do this we first need to check whether the second
@@ -3610,10 +3574,7 @@
 %  \end{macro}
 %
 %  \begin{macro}{\ldf at quit}
-% \changes{babel~3.6a}{1996/10/29}{Macro added}
 %    This macro interrupts the processing of a language definition file.
-% \changes{babel~3.7o}{2003/11/26}{Also restore the category code of
-%    the equals sign}
 %    \begin{macrocode}
 \def\ldf at quit#1{%
   \expandafter\main at language\expandafter{#1}%
@@ -3624,7 +3585,6 @@
 %  \end{macro}
 %
 %  \begin{macro}{\ldf at finish}
-% \changes{babel~3.6a}{1996/10/16}{Macro added}
 %    This macro takes one argument. It is the name of the language
 %    that was defined in the language definition file.
 %
@@ -3632,8 +3592,6 @@
 %    the main language (taking into account that the argument might be
 %    a control sequence that needs to be expanded) and reset the
 %    category code of the @-sign.
-% \changes{babel~3.7o}{2003/11/26}{Also restore the category code of
-%    the equals sign}
 % \changes{babel~3.9a}{2012/10/01}{Added \cs{bbl at afterlang} which
 %    executes the code delayed with \cs{AfterBabelLanguage}}
 %    \begin{macrocode}
@@ -3659,12 +3617,7 @@
 %    \end{macrocode}
 %
 %  \begin{macro}{\main at language}
-% \changes{babel~3.5a}{1995/02/17}{Macro added}
-% \changes{babel~3.6a}{1996/10/16}{\cs{main at language} now also sets
-%    \cs{languagename} and \cs{l at languagename} for use by other
-%    packages in the preamble of a document}
 %  \begin{macro}{\bbl at main@language}
-% \changes{babel~3.5a}{1995/02/17}{Macro added}
 %    This command should be used in the various language definition
 %    files. It stores its argument in |\bbl at main@language|; to be used
 %    to switch to the correct language at the beginning of the
@@ -3685,11 +3638,22 @@
 %    \end{macrocode}
 %  \end{macro}
 %  \end{macro}
+%   
+% A bit of optimization. Select in heads/foots the language only if
+% necessary. 
 %
+%    \begin{macrocode}
+\def\select at language@x#1{%
+  \ifcase\bbl at select@type
+    \bbl at ifsamestring\languagename{#1}{}{\select at language{#1}}%
+  \else
+    \select at language{#1}%
+  \fi}
+%    \end{macrocode}
+%
 % \subsection{Shorthands}
 %
 %  \begin{macro}{\bbl at add@special}
-% \changes{babel~3.2}{1991/11/10}{Added macro}
 %    The macro |\bbl at add@special| is used to add a new character (or
 %    single character control sequence) to the macro |\dospecials|
 %    (and |\@sanitize| if \LaTeX\ is used).
@@ -3727,10 +3691,10 @@
 %  \end{macro}
 %
 %  \begin{macro}{\bbl at remove@special}
-% \changes{babel~3.2}{1991/11/10}{Added macro}
+%
 %    The companion of the former macro is |\bbl at remove@special|.  It
-%    is used to remove a character from the set macros |\dospecials|
-%    and |\@sanitize|.
+%    removes a character from the set macros |\dospecials| and
+%    |\@sanitize|, but it is not used at all in the \babel{} core.
 %
 %    To keep all changes local, we begin a new group.  Then we define
 %    a help macro |\x|, which expands to empty if the characters
@@ -3751,7 +3715,7 @@
     \def\@makeother{\x\@makeother}%
   \edef\x{\endgroup
     \def\noexpand\dospecials{\dospecials}%
-    \expandafter\ifx\csname @sanitize\endcsname\relax \else
+    \expandafter\ifx\csname @sanitize\endcsname\relax\else
       \def\noexpand\@sanitize{\@sanitize}%
     \fi}%
   \x}
@@ -3760,8 +3724,6 @@
 %
 %
 %  \begin{macro}{\initiate at active@char}
-% \changes{babel~3.5a}{1995/02/11}{Added macro}
-% \changes{babel~3.5b}{1995/03/03}{Renamed macro}
 %    A language definition file can call this macro to make a
 %    character active. This macro takes one argument, the character
 %    that is to be made active. When the character was already active
@@ -3805,9 +3767,6 @@
 %    When there is also no current-level shorthand with an argument we
 %    will check whether there is a next-level  defined shorthand for
 %    this active character. 
-% \changes{babel~3.7e}{1999/09/24}{pass the argument on with braces in
-%    order to prevent it from breaking up}
-% \changes{babel~3.7f}{2000/02/18}{remove the braces again}
 %    \begin{macrocode}
   \long\@namedef{#3 at arg#1}##1{%
     \expandafter\ifx\csname#2 at sh@#1@\string##1@\endcsname\relax
@@ -3820,13 +3779,14 @@
 %    \cs{@initiate at active@char} with 3 arguments.}
 %    |\initiate at active@char| calls |\@initiate at active@char| with 3
 %    arguments. All of them are the same character with different
-%    catcodes: active, other (string'ed) and the original one.
+%    catcodes: active, other (|\string|'ed) and the original one.
+%    This trick simplifies the code a lot.
 %    \begin{macrocode}
 \def\initiate at active@char#1{%
-  \expandafter\ifx\csname active at char\string#1\endcsname\relax
-    \bbl at withactive
-      {\expandafter\@initiate at active@char\expandafter}#1\string#1#1%
-  \fi}
+  \bbl at ifunset{active at char\string#1}%
+    {\bbl at withactive
+      {\expandafter\@initiate at active@char\expandafter}#1\string#1#1}%
+    {}}
 %    \end{macrocode}
 % \changes{babel~3.9e}{2012/08/18}{Introduced the 3-argument
 %   \cs{@initiate at active@char}, with different catcodes: active,
@@ -3842,14 +3802,12 @@
 %   making them |\relax|).  
 %    \begin{macrocode}
 \def\@initiate at active@char#1#2#3{%
-  \expandafter\edef\csname bbl at oricat@#2\endcsname{%
-    \catcode`#2=\the\catcode`#2\relax}%
+  \bbl at csarg\edef{oricat@#2}{\catcode`#2=\the\catcode`#2\relax}%
   \ifx#1\@undefined
-    \expandafter\edef\csname bbl at oridef@#2\endcsname{%
-      \let\noexpand#1\noexpand\@undefined}%
+    \bbl at csarg\edef{oridef@#2}{\let\noexpand#1\noexpand\@undefined}%
   \else
-    \expandafter\let\csname bbl at oridef@@#2\endcsname#1%
-    \expandafter\edef\csname bbl at oridef@#2\endcsname{%
+    \bbl at csarg\let{oridef@@#2}#1%
+    \bbl at csarg\edef{oridef@#2}{%
       \let\noexpand#1%
       \expandafter\noexpand\csname bbl at oridef@@#2\endcsname}%
   \fi
@@ -3882,17 +3840,8 @@
 %    shorthands are active during the processing of the \file{.aux}
 %    file. Otherwise some citations may give unexpected results in
 %    the printout when a shorthand was used in the optional argument
-%    of |\bibitem| for example.
-% \changes{babel~3.6i}{1997/03/01}{Make shorthands active during
-%    \file{.aux} file processing}. Then we
-%    make it active (not strictly necessary, but done for backward
-%    compatibility).
-% \changes{babel~3.5f}{1995/12/01}{Restore the category code of a
-%    shorthand char at end of package}
-% \changes{babel~3.6f}{1997/01/14}{Made restoring of the category code
-%    of shorthand characters optional}
-% \changes{babel~3.7a}{1997/03/21}{Use \cs{@ifpackagewith} to
-%    determine whether shorthand characters need to remain active}
+%    of |\bibitem| for example. Then we make it active (not strictly
+%    necessary, but done for backward compatibility).
 %    \begin{macrocode}
     \bbl at restoreactive{#2}%
     \AtBeginDocument{%
@@ -3962,8 +3911,6 @@
 %    shorthand for himself with this character. First we check for a
 %    single character shorthand. If that doesn't exist we check for a
 %    shorthand with an argument.
-% \changes{babel~3.5d}{1995/07/02}{Skip the user-level active char
-%    with argument if no shorthands with arguments were defined}
 % \changes{babel~3.8b}{2004/04/19}{Now use \cs{bbl at sh@select}}
 % \changes{babel~3.9a}{2012/08/18}{Instead of the ``copy-paste pattern''
 %    a new macro is used}
@@ -3979,8 +3926,6 @@
 %    shorthand combination such as |''| ends up in a heading \TeX\
 %    would see |\protect'\protect'|. To prevent this from happening a
 %    couple of shorthand needs to be defined at user level.
-% \changes{babel~3.7f}{1999/12/09}{Added an extra shorthand
-%    combination on user level to catch an interfering \cs{protect}}
 % \changes{babel~3.9a}{2012/8/18}{Use \cs{user at group}, as above,
 %    instead of the hardwired \texttt{user}}
 %    \begin{macrocode}
@@ -3997,16 +3942,6 @@
 %    works. Therefore an extra level of expansion is introduced with a
 %    check for math mode on the upper level.
 %
-% \changes{babel~3.7f}{1999/12/18}{Insert a check for math mode in
-%    the definition of \cs{normal at char'}}
-% \changes{babel~3.7g}{2000/10/02}{use \cs{textormath} to get rid
-%    of the \cs{fi} (PR 3266)}
-% \changes{babel~3.7f}{1999/12/18}{The redefinition needs to take
-%    place one level higher, \cs{prim at s} needs to be redefined.}
-% \changes{babel~3.7f}{1999/12/18}{Introduced an extra
-%    level of expansion in the definition of an active caret}
-% \changes{babel~3.7f}{2000/09/25}{Make an exception for the active
-%    caret which needs an extra level of expansion}
 % \changes{babel~3.9a}{2012/09/11}{The output routine resets the quote
 %   to \cs{active at math@prime}, so we redefine the latter with the new
 %  ``normal'' value}
@@ -4089,10 +4024,6 @@
 %    active characters has a function similar to |\OT1-cmd| in that it
 %    |\protect|s the active character whenever |\protect| is
 %    \emph{not} |\@typeset at protect|.
-% \changes{babel~3.5d}{1995/07/02}{\cs{@protected at cmd} has vanished
-%    from \file{ltoutenc.dtx}}
-% \changes{babel~3.7o}{2003/11/17}{Added handling of the situation
-%    where \cs{protect} is set to \cs{@unexpandable at protect}}
 %    \begin{macrocode}
 \def\active at prefix#1{%
   \ifx\protect\@typeset at protect
@@ -4127,7 +4058,6 @@
 %  \end{macro}
 %
 %  \begin{macro}{\bbl at restore@actives}
-% \changes{babel~3.7m}{2003/11/15}{New macro added}
 %    When the output routine kicks in while the
 %    active characters were made ``safe'' this must be undone in
 %    the headers to prevent unexpected typeset results. For this
@@ -4139,7 +4069,6 @@
 %
 %  \begin{macro}{\bbl at activate}
 %  \begin{macro}{\bbl at deactivate}
-%  \changes{babel~3.5a}{1995/02/11}{Added macro}
 %  \changes{babel~3.9a}{2013/01/11}{\cs{bbl at withactive} makes sure the
 %    catcode is active} 
 %    Both macros take one argument, like |\initiate at active@char|. The
@@ -4179,10 +4108,6 @@
 %      i.e. |~| or |"a|;
 %    \item the code to be executed when the shorthand is encountered.
 %    \end{enumerate}
-% \changes{babel~3.5d}{1995/07/02}{Make a `note' when a shorthand with
-%    an argument is defined.}
-% \changes{babel~3.6i}{1997/02/23}{Make it possible to distinguish the
-%    constructed control sequences for the case with argument}
 % \changes{babel~3.8b}{2004/04/19}{We need to support shorthands with
 %    and without argument in different groups; added the name of the
 %    group to the storage macro}
@@ -4193,7 +4118,7 @@
   \def\bbl at tempa{#3}%
   \ifx\bbl at tempa\@empty
     \expandafter\let\csname #1 at sh@\string#2 at sel\endcsname\bbl at scndcs
-    \@ifundefined{#1 at sh@\string#2@}{}%
+    \bbl at ifunset{#1 at sh@\string#2@}{}%
       {\def\bbl at tempa{#4}%
        \expandafter\ifx\csname#1 at sh@\string#2@\endcsname\bbl at tempa
        \else
@@ -4204,7 +4129,7 @@
     \@namedef{#1 at sh@\string#2@}{#4}%
   \else
     \expandafter\let\csname #1 at sh@\string#2 at sel\endcsname\bbl at firstcs
-    \@ifundefined{#1 at sh@\string#2@\string#3@}{}%
+    \bbl at ifunset{#1 at sh@\string#2@\string#3@}{}%
       {\def\bbl at tempa{#4}%
        \expandafter\ifx\csname#1 at sh@\string#2@\string#3@\endcsname\bbl at tempa
        \else
@@ -4241,8 +4166,6 @@
 %    group is stored in a macro. The default is to have a user group;
 %    use language group `english' and have a system group called
 %    `system'.
-% \changes{babel~3.6i}{1997/02/24}{Have a user group called `user' by
-%    default}
 %    \begin{macrocode}
 \def\user at group{user}
 \def\language at group{english}
@@ -4262,11 +4185,6 @@
 %    version is also provided which activates them always after the
 %    language has been switched.
 %
-% \changes{babel~3.7j}{2001/11/11}{When \TeX\ has seen a character
-%    its category code is fixed; need to use a `stand-in' for the
-%    call of \cs{bbl at activate}} 
-% \changes{babel~3.7j}{2003/09/11}{The change from 11/112001 was
-%    incomplete}
 % \changes{babel~3.9a}{2012/08/05}{Now \cs{bbl at activate} makes sure
 %    the catcode is active, so this part is simplified}
 % \changes{babel~3.9a}{2012/08/12}{User shorhands can be
@@ -4307,7 +4225,7 @@
 %    \begin{macrocode}
 \def\user at language@group{user@\language at group}
 \def\bbl at set@user at generic#1#2{%
-  \@ifundefined{user at generic@active#1}%
+  \bbl at ifunset{user at generic@active#1}%
     {\bbl at active@def#1\user at language@group{user at active}{user at generic@active}%
      \bbl at active@def#1\user at group{user at generic@active}{language at active}%
      \expandafter\edef\csname#2 at sh@#1@@\endcsname{%
@@ -4338,7 +4256,6 @@
 %  \end{macro}
 %
 %  \begin{macro}{\aliasshorthand}
-% \changes{babel~3.5f}{1996/01/25}{New command}
 %    First the new shorthand needs to be initialized,
 %    \begin{macrocode}
 \def\aliasshorthand#1#2{%
@@ -4388,11 +4305,7 @@
 %  \end{macro}
 %
 %  \begin{macro}{\shorthandon}
-% \changes{babel~3.7a}{1998/06/07}{Added command}
 %  \begin{macro}{\shorthandoff}
-% \changes{babel~3.7a}{1998/06/07}{Added command}
-% \changes{babel~3.9a}{2012/09/08}{Added code for the starred variant
-%    of \cs{shorthandoff}} 
 %    The first level definition of these macros just passes the
 %    argument on to |\bbl at switch@sh|, adding |\@nil| at the end to
 %    denote the end of the list of characters.
@@ -4404,7 +4317,6 @@
 %    \end{macrocode}
 %
 %  \begin{macro}{\bbl at switch@sh}
-% \changes{babel~3.7a}{1998/06/07}{Added command}
 % \changes{babel~3.9a}{2013/02/21}{Code revised}
 %    The macro |\bbl at switch@sh| takes the list of characters apart one
 %    by  one and subsequently switches the category code of the
@@ -4424,7 +4336,7 @@
 %    \begin{macrocode}
 \def\bbl at switch@sh#1#2{%
   \ifx#2\@nnil\else
-    \@ifundefined{bbl at active@\string#2}%
+    \bbl at ifunset{bbl at active@\string#2}%
       {\bbl at error
          {I cannot switch `\string#2' on or off--not a shorthand}%
          {This character is not a shorthand. Maybe you made\\%
@@ -4451,7 +4363,7 @@
 %    \begin{macrocode}
 \def\babelshorthand{\active at prefix\babelshorthand\bbl at putsh}
 \def\bbl at putsh#1{%
-  \@ifundefined{bbl at active@\string#1}%
+  \bbl at ifunset{bbl at active@\string#1}%
      {\bbl at putsh@i#1\@empty\@nnil}%
      {\csname bbl at active@\string#1\endcsname}}
 \def\bbl at putsh@i#1#2\@nnil{%
@@ -4479,10 +4391,7 @@
 % \changes{babel~3.9a}{2012/12/27}{Removed redundant system declarations}
 %
 %  \begin{macro}{\bbl at prim@s}
-% \changes{babel~3.7f}{1999/12/01}{Need to redefine \cs{prim at s} as
-%    well as plain \TeX's definition uses \cs{next}}
 %  \begin{macro}{\bbl at pr@m at s}
-% \changes{babel~3.5a}{1995/03/10}{Added macro}
 % \changes{babel~3.9a}{2012/07/29}{\cs{bbl at pr@m at s} rewritten to
 %    take into account catcodes for both the quote and the hat}
 %    One of the internal macros that are involved in substituting
@@ -4558,8 +4467,6 @@
 %    Language attributes provide a means to give the user control over
 %    which features of the language definition files he wants to
 %    enable.
-% \changes{babel~3.7c}{1998/07/02}{Added support for language
-%    attributes}
 %  \begin{macro}{\languageattribute}
 % \changes{babel~3.9a}{2012/09/07}{Use \cs{@expandtwoargs} with \cs{in@}}
 %    The macro |\languageattribute| checks whether its arguments are
@@ -4646,7 +4553,6 @@
 %  \end{macro}
 %
 %  \begin{macro}{\bbl at ifattributeset}
-% \changes{babel~3.7f}{2000/02/12}{macro added}
 %    This internal macro has 4 arguments. It can be used to interpret
 %    \TeX\ code based on whether a certain attribute was set. This
 %    command should appear inside the argument to |\AtBeginDocument|
@@ -4684,25 +4590,6 @@
 %    \end{macrocode}
 %  \end{macro}
 %
-%  \begin{macro}{\bbl at add@list}
-%    This internal macro adds its second argument to a comma
-%    separated list in its first argument. When the list is not
-%    defined yet (or empty), it will be initiated
-%    \begin{macrocode}
-\def\bbl at add@list#1#2{%
-  \ifx#1\@undefined
-    \def#1{#2}%
-  \else
-    \ifx#1\@empty
-      \def#1{#2}%
-    \else
-      \edef#1{#1,#2}%
-    \fi
-  \fi
-  }
-%    \end{macrocode}
-%  \end{macro}
-%
 %  \begin{macro}{\bbl at ifknown@ttrib}
 %    An internal macro to check whether a given language/attribute is
 %    known. The macro takes 4 arguments, the language/attribute, the
@@ -4738,8 +4625,6 @@
 %  \begin{macro}{\bbl at clear@ttribs}
 %    This macro removes all the attribute code from \LaTeX's memory at
 %    |\begin{document}| time (if any is present).
-% \changes{babel~3.7e}{1999/09/24}{When \cs{bbl at attributes} is
-%    undefined this should be a no-op} 
 %    \begin{macrocode}
 \def\bbl at clear@ttribs{%
   \ifx\bbl at attributes\@undefined\else
@@ -4747,8 +4632,7 @@
       \expandafter\bbl at clear@ttrib\bbl at tempa.
       }%
     \let\bbl at attributes\@undefined
-  \fi
-  }
+  \fi}
 \def\bbl at clear@ttrib#1-#2.{%
   \expandafter\let\csname#1 at attr@#2\endcsname\@undefined}
 \AtBeginDocument{\bbl at clear@ttribs}
@@ -4769,9 +4653,7 @@
 %  |\relax|'ed.
 %
 %  \begin{macro}{\babel at savecnt}
-% \changes{babel~3.2}{1991/11/10}{Added macro}
 %  \begin{macro}{\babel at beginsave}
-% \changes{babel~3.2}{1991/11/10}{Added macro}
 %    The initialization of a new save cycle: reset the counter to
 %    zero.
 %    \begin{macrocode}
@@ -4786,7 +4668,6 @@
 %  \end{macro}
 %
 %  \begin{macro}{\babel at save}
-% \changes{babel~3.2}{1991/11/10}{Added macro}
 %    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
@@ -4794,10 +4675,6 @@
 %    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.
-% \changes{babel~3.2c}{1992/03/17}{missing backslash led to errors
-%    when executing \cs{originalTeX}}
-% \changes{babel~3.2d}{1992/07/02}{saving in \cs{babel at i} and
-%    restoring from \cs{@babel at i} doesn't work very well...}
 %    \begin{macrocode}
 \def\babel at save#1{%
   \expandafter\let\csname babel@\number\babel at savecnt\endcsname#1\relax
@@ -4903,7 +4780,7 @@
         \bbl at fixname\bbl at tempa
         \bbl at iflanguage\bbl at tempa{%
           \bbl at csarg\protected at edef{hyphenation@\bbl at tempa}{%
-            \@ifundefined{bbl at hyphenation@\bbl at tempa}%
+            \bbl at ifunset{bbl at hyphenation@\bbl at tempa}%
               \@empty
               {\csname bbl at hyphenation@\bbl at tempa\endcsname\space}%
             #2}}}%
@@ -4912,18 +4789,19 @@
 %  \end{macro}
 %
 %  \begin{macro}{\bbl at allowhyphens}
-% \changes{babel~3.2b}{1992/02/16}{Moved macro from language
-%    definition files}
-% \changes{babel~3.7a}{1998/03/12}{Make \cs{allowhyphens} a no-op for
-%    T1 fontencoding}
+%
 % \changes{babel-3.9a}{2012/07/28}{Replaced many \cs{allowhyphens} by
 %    \cs{bbl at allowhyphen}. They were either no-op or executed always.}
 % \changes{babel-3.9i}{2014/01/29}{\cs{bbl at allowhyphens} must be
 %    ignored at the beginning of a paragraph or table cell.}
+% \changes{babel-3.9t}{2017/04/26}{Fixed misplaced \cs{nobreak} -
+%    sx366454 - soft hyphens could vanish.}
+%
 %    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}
 \def\bbl at t@one{T1}
@@ -4934,10 +4812,12 @@
 % \changes{babel-3.9a}{2012/08/27}{Added \cs{babelhyphen} and related
 %    macros}
 % \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.
+%    the same procedure as shorthands, with |\active at prefix|.
+%
 %    \begin{macrocode}
 \newcommand\babelnullhyphen{\char\hyphenchar\font}
 \def\babelhyphen{\active at prefix\babelhyphen\bbl at hyphen}
@@ -4944,10 +4824,11 @@
 \def\bbl at hyphen{%
   \@ifstar{\bbl at hyphen@i @}{\bbl at hyphen@i\@empty}}
 \def\bbl at hyphen@i#1#2{%
-  \@ifundefined{bbl at hy@#1#2\@empty}%
+  \bbl at ifunset{bbl at hy@#1#2\@empty}%
     {\csname bbl@#1usehyphen\endcsname{\discretionary{#2}{}{#2}}}%
     {\csname bbl at hy@#1#2\@empty\endcsname}}
 %    \end{macrocode}
+%
 %    The following two commands are used to wrap the ``hyphen'' and
 %    set the behaviour of the rest of the word -- the version with a
 %    single |@| is used when further hyphenation is allowed, while
@@ -4960,15 +4841,18 @@
 %    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{%
   \leavevmode
-  \ifdim\lastskip>\z@\mbox{#1}\nobreak\else\nobreak#1\fi
-  \hskip\z at skip}
+  \ifdim\lastskip>\z@\mbox{#1}\else\nobreak#1\fi
+  \nobreak\hskip\z at skip}
 \def\bbl@@usehyphen#1{%
   \leavevmode\ifdim\lastskip>\z@\mbox{#1}\else#1\fi}
 %    \end{macrocode}
+%
 %    The following macro inserts the hyphen char.
+%
 %    \begin{macrocode}
 \def\bbl at hyphenchar{%
   \ifnum\hyphenchar\font=\m at ne
@@ -4977,19 +4861,21 @@
     \char\hyphenchar\font
   \fi}
 %    \end{macrocode}
+%
 %    Finally, we define the hyphen ``types''. Their names will not
-%    change, so you may use them in |ldf|'s.
+%    change, so you may use them in |ldf|'s. After a space, the
+%    |\mbox| in |\bbl at hy@nobreak| is redundant.
+%
 %    \begin{macrocode}
 \def\bbl at hy@soft{\bbl at usehyphen{\discretionary{\bbl at hyphenchar}{}{}}}
 \def\bbl at hy@@soft{\bbl@@usehyphen{\discretionary{\bbl at hyphenchar}{}{}}}
 \def\bbl at hy@hard{\bbl at usehyphen\bbl at hyphenchar}
 \def\bbl at hy@@hard{\bbl@@usehyphen\bbl at hyphenchar}
-\def\bbl at hy@nobreak{\bbl at usehyphen{\mbox{\bbl at hyphenchar}\nobreak}}
+\def\bbl at hy@nobreak{\bbl at usehyphen{\mbox{\bbl at hyphenchar}}}
 \def\bbl at hy@@nobreak{\mbox{\bbl at hyphenchar}}
 \def\bbl at hy@repeat{%
   \bbl at usehyphen{%
-    \discretionary{\bbl at hyphenchar}{\bbl at hyphenchar}{\bbl at hyphenchar}%
-    \nobreak}}
+    \discretionary{\bbl at hyphenchar}{\bbl at hyphenchar}{\bbl at hyphenchar}}}
 \def\bbl at hy@@repeat{%
   \bbl@@usehyphen{%
     \discretionary{\bbl at hyphenchar}{\bbl at hyphenchar}{\bbl at hyphenchar}}}
@@ -4999,8 +4885,6 @@
 %  \end{macro}
 %
 %  \begin{macro}{\bbl at disc}
-% \changes{babel~3.5f}{1996/01/24}{Macro moved from language
-%    definition files}
 %    For some languages the macro |\bbl at disc| is used to ease the
 %    insertion of discretionaries for letters that behave `abnormally'
 %    at a breakpoint.
@@ -5060,7 +4944,7 @@
     \g at addto@macro\@uclclist{\reserved at b{\reserved at b\bbl at uclc}}%
     \gdef\bbl at uclc##1{%
       \let\bbl at encoded\bbl at encoded@uclc
-      \@ifundefined{\languagename @bbl at uclc}% and resumes it
+      \bbl at ifunset{\languagename @bbl at uclc}% and resumes it
         {##1}%
         {\let\bbl at tempa##1\relax % Used by LANG at bbl@uclc
          \csname\languagename @bbl at uclc\endcsname}%
@@ -5175,7 +5059,7 @@
     \edef\bbl at sc@charset{\expandafter\zap at space\bbl at sc@charset\@empty}%
     \def\bbl at encstring##1##2{%
       \bbl at for\bbl at tempc\bbl at sc@fontenc{%
-        \@ifundefined{T@\bbl at tempc}%
+        \bbl at ifunset{T@\bbl at tempc}%
           {}%
           {\ProvideTextCommand##1\bbl at tempc{##2}%
            \bbl at toglobal##1%
@@ -5205,7 +5089,6 @@
          captions or extras, but you set none}}%
   \fi
   \ifx\@empty#1%
-    \@expandtwoargs
     \bbl at usehooks{defaultcommands}{}%
   \else
     \@expandtwoargs
@@ -5244,7 +5127,7 @@
       \fi
     \fi}}
 \AtEndOfPackage{%
-  \def\bbl at forlang#1#2{\bbl at for#1\bbl at L{\@ifundefined{date#1}{}{#2}}}%
+  \def\bbl at forlang#1#2{\bbl at for#1\bbl at L{\bbl at ifunset{date#1}{}{#2}}}%
   \let\bbl at scswitch\relax}
 \@onlypreamble\EndBabelCommands
 \def\EndBabelCommands{%
@@ -5271,8 +5154,8 @@
 %    \begin{macrocode}
 \def\bbl at setstring#1#2{%
   \bbl at forlang\bbl at tempa{%
-    \edef\bbl at LC{\bbl at tempa\expandafter\@gobble\string#1}%
-    \@ifundefined{\bbl at LC}% eg, \germanchaptername
+    \edef\bbl at LC{\bbl at tempa\bbl at stripslash#1}%
+    \bbl at ifunset{\bbl at LC}% eg, \germanchaptername
       {\global\expandafter
        \bbl at add\csname\bbl at G\bbl at tempa\expandafter\endcsname\expandafter
          {\expandafter\bbl at scset\expandafter#1\csname\bbl at LC\endcsname}}%
@@ -5317,6 +5200,8 @@
 %    |\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.
 %
 % \changes{babel~3.9h}{2013/10/16}{Tidied up and bug fixed - first
 %    element expanded prematurely.}
@@ -5326,7 +5211,7 @@
 \def\SetStringLoop##1##2{%
     \def\bbl at templ####1{\expandafter\noexpand\csname##1\endcsname}%
     \count@\z@
-    \bbl at loop\bbl at tempa{##2}{%
+    \bbl at loop\bbl at tempa{##2}{% empty items and spaces are ok
       \advance\count@\@ne
       \toks@\expandafter{\bbl at tempa}%
       \edef\bbl at tempb{%
@@ -5438,8 +5323,6 @@
 % \subsection{Macros common to a number of languages}
 %
 %  \begin{macro}{\set at low@box}
-% \changes{babel~3.2b}{1992/02/16}{Moved macro from language
-%    definition files}
 %    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}
@@ -5450,12 +5333,8 @@
 %  \end{macro}
 %
 %  \begin{macro}{\save at sf@q}
-% \changes{babel~3.2b}{1992/02/16}{Moved macro from language
-%    definition files}
 %    The macro |\save at sf@q| is used to save and reset the current
 %    space factor.
-% \changes{babel~3.7f}{2000/09/19}{PR3119, don't start a paragraph in
-%    a local group}
 %    \begin{macrocode}
 \def\save at sf@q#1{\leavevmode
   \begingroup 
@@ -5464,8 +5343,6 @@
 %    \end{macrocode}
 %  \end{macro}
 %
-% \changes{babel~3.5c}{1995/06/14}{Repaired a typo (itlaic, PR1652)}
-%
 %  \subsection{Making glyphs available}
 %
 %    This section makes a number of glyphs available that either do not
@@ -5578,8 +5455,6 @@
 %    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.
-% \changes{dutch-3.7a}{1995/02/04}{Changed the kerning in the faked ij
-%    to match the dc-version of it}
 % \changes{babel~3.9a}{2012/07/28}{Removed the first \cs{allowhyphens}.
 %    Moved the second one just after the kern.}
 %    \begin{macrocode}
@@ -5610,8 +5485,6 @@
 %    Some code to construct these glyphs for the \texttt{OT1} encoding
 %    was made available to me by Stipcevic Mario,
 %    (\texttt{stipcevic at olimp.irb.hr}).
-% \changes{babel~3.5f}{1996/03/28}{New definition of \cs{dj}, see PR
-%    2058}
 %    \begin{macrocode}
 \def\crrtic@{\hrule height0.1ex width0.3em}
 \def\crttic@{\hrule height0.1ex width0.33em}
@@ -5661,8 +5534,6 @@
 %
 %  \begin{macro}{\glq}
 %  \begin{macro}{\grq}
-% \changes{babel~3.7a}{1997/04/25}{Make the definition of \cs{grq}
-%    dependent on the font encoding}
 % \changes{babel~3.8b}{2004/05/02}{Made \cs{glq} fontencoding
 %    dependent as well} 
 %    The `german' single quotes.
@@ -5689,8 +5560,6 @@
 %
 %  \begin{macro}{\glqq}
 %  \begin{macro}{\grqq}
-% \changes{babel~3.7a}{1997/04/25}{Make the definition of \cs{grqq}
-%    dependent on the font encoding}
 % \changes{babel~3.8b}{2004/05/02}{Made \cs{grqq} fontencoding
 %    dependent as well} 
 %    The `german' double quotes.
@@ -5717,10 +5586,6 @@
 %
 %  \begin{macro}{\flq}
 %  \begin{macro}{\frq}
-% \changes{babel~3.5f}{1995/08/07}{corrected spelling of
-%    \cs{quilsingl...}}
-% \changes{babel~3.5f}{1995/09/05}{now use \cs{textormath} in these
-%    definitions}
 % \changes{babel~3.8b}{2004/05/02}{Made \cs{flq} and \cs{frq}
 %    fontencoding dependent} 
 %    The `french' single guillemets.
@@ -5744,10 +5609,6 @@
 %
 %  \begin{macro}{\flqq}
 %  \begin{macro}{\frqq}
-% \changes{babel~3.5f}{1995/08/07}{corrected spelling of
-%    \cs{quillemot...}}
-% \changes{babel~3.5f}{1995/09/05}{now use \cs{textormath} in these
-%    definitions}
 % \changes{babel~3.8b}{2004/05/02}{Made \cs{flqq} and \cs{frqq}
 %    fontencoding dependent} 
 %    The `french' double guillemets.
@@ -5827,8 +5688,6 @@
 %    If the new x-height is too low, it is not changed.
 %    Finally we call the |\accent| primitive, reset the old x-height
 %    and insert the base character in the argument.
-% \changes{babel~3.5f}{1996/04/02}{Added a \cs{allowhyphens}}
-% \changes{babel~3.5f}{1996/06/25}{removed \cs{allowhyphens}}
 %    \begin{macrocode}
 \def\lower at umlaut#1{%
   \leavevmode\bgroup
@@ -5871,9 +5730,6 @@
 %    \end{macrocode}
 %
 %    Finally, the default is to use English as the main language.
-% \changes{babel~3.6c}{1997/01/05}{When \file{hyphen.cfg} is not
-%    loaded in the format \cs{l at english} might not be defined; assume
-%    english is language 0}
 % \changes{babel~3.9a}{2012-05-17}{Languages are best assigned with
 %    \cs{chardef}, not \cs{let}}
 %    \begin{macrocode}
@@ -5943,7 +5799,6 @@
 %    `|macro:#1->\B|' with all category codes set to `other' or
 %    `space'.
 %  \begin{macro}{\newlabel}
-% \changes{babel~3.5f}{1995/11/15}{Now use \cs{bbl at redefine}}
 %    The macro |\label| writes a line with a |\newlabel| command
 %    into the |.aux| file to define labels.
 %    \begin{macrocode}
@@ -5953,8 +5808,6 @@
 %  \end{macro}
 %
 %  \begin{macro}{\@newl at bel}
-% \changes{babel~3.6i}{1997/03/01}{Now redefine \cs{@newl at bel} instead
-%    of \cs{@lbibitem} and \cs{newlabel}}
 %    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.
@@ -5973,13 +5826,11 @@
 %    |\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.
-% \changes{babel~3.7a}{1997/12/19}{Call \cs{@safe at activestrue}
-%    directly}
 %    \begin{macrocode}
 \ifx\bbl at opt@safe\@empty\else
   \def\@newl at bel#1#2#3{%
    {\@safe at activestrue
-    \@ifundefined{#1@#2}%
+    \bbl at ifunset{#1@#2}%
        \relax
        {\gdef\@multiplelabels{%
           \@latex at warning@no at line{There were multiply-defined labels}}%
@@ -5996,20 +5847,6 @@
 %    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.
-% \changes{babel~3.4g}{1994/08/30}{Moved the \cs{def} inside the
-%    macrocode environment}
-% \changes{babel~3.5f}{1995/11/15}{Now use \cs{bbl at redefine}}
-% \changes{babel~3.5f}{1996/01/09}{Complete rewrite of this macro as
-%    the same character ended up with different category codes in the
-%    labels that are being compared. Now use \cs{meaning}}
-% \changes{babel~3.5f}{1996/01/16}{Use \cs{strip at prefix} only on
-%    \cs{bbl at tempa} when it is not \cs{relax}}
-% \changes{babel~3.6i}{1997/02/28}{Make sure that shorthands don't get
-%    expanded at the wrong moment.}
-% \changes{babel~3.6i}{1997/03/01}{\cs{@safe at activesfalse} is now
-%    part of the label definition}
-% \changes{babel~3.7a}{1998/03/13}{Removed \cs{@safe at activesfalse}
-%    from the label definition}
 %    \begin{macrocode}
   \CheckCommand*\@testdef[3]{%
     \def\reserved at a{#3}%
@@ -6065,17 +5902,6 @@
 %    |\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.
-% \changes{babel~3.5b}{1995/03/07}{Made \cs{ref} and \cs{pageref}
-%    robust (PR1353)}
-% \changes{babel~3.5d}{1995/07/04}{use a different control sequence
-%    while making \cs{ref} and \cs{pageref} robust}
-% \changes{babel~3.5f}{1995/11/06}{redefine \cs*{ref } if it exists
-%    instead of \cs{ref}}
-% \changes{babel~3.5f}{1995/11/15}{Now use \cs{bbl at redefinerobust}}
-% \changes{babel~3.5f}{1996/01/19}{redefine \cs{\@setref} instead of
-%    \cs{ref} and \cs{pageref} in \LaTeXe.}
-% \changes{babel~3.5f}{1996/01/21}{Reverse the previous change as it
-%    inhibits the use of active characters in labels}
 %    \begin{macrocode}
 \@expandtwoargs\in@{R}\bbl at opt@safe
 \ifin@
@@ -6092,7 +5918,6 @@
 %  \end{macro}
 %
 %  \begin{macro}{\@citex}
-% \changes{babel~3.5f}{1995/11/15}{Now use \cs{bbl at redefine}}
 %    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),
@@ -6099,8 +5924,6 @@
 %    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.
-% \changes{babel~3.7g}{2000/10/01}{The shorthands need to be
-%    deactivated for the second argument of \cs{@citex} only.}
 %    \begin{macrocode}
 \@expandtwoargs\in@{B}\bbl at opt@safe
 \ifin@
@@ -6143,7 +5966,6 @@
 %  \end{macro}
 %
 %  \begin{macro}{\nocite}
-% \changes{babel~3.5f}{1995/11/15}{Now use \cs{bbl at redefine}}
 %    The macro |\nocite| which is used to instruct BiB\TeX\ to
 %    extract uncited references from the database.
 %    \begin{macrocode}
@@ -6153,7 +5975,6 @@
 %  \end{macro}
 %
 %  \begin{macro}{\bibcite}
-% \changes{babel~3.5f}{1995/11/15}{Now use \cs{bbl at redefine}}
 %    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
@@ -6164,10 +5985,6 @@
 %    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.
-% \changes{babel~3.6s}{1999/04/13}{Need to determine `online' which
-%    definition of \cs{bibcite} is needed}
-% \changes{babel~3.6v}{1999/04/21}{Also check for \pkg{cite} it can't
-%    handle \cs{@safe at activesfalse} in its second argument}
 %    \begin{macrocode}
   \bbl at redefine\bibcite{%
 %    \end{macrocode}
@@ -6180,7 +5997,6 @@
 %  \end{macro}
 %
 %  \begin{macro}{\bbl at bibcite}
-% \changes{babel~3.6v}{1999/04/21}{Macro \cs{bbl at bibcite} added}
 %    The macro |\bbl at bibcite| holds the definition of |\bibcite|
 %    needed when neither \pkg{natbib} nor \pkg{cite} is loaded.
 %    \begin{macrocode}
@@ -6190,7 +6006,6 @@
 %  \end{macro}
 %
 %  \begin{macro}{\bbl at cite@choice}
-% \changes{babel~3.6v}{1999/04/21}{Macro \cs{bbl at cite@choice} added}
 %    The macro |\bbl at cite@choice| determines which definition of
 %    |\bibcite| is needed.
 %    \begin{macrocode}
@@ -6223,7 +6038,6 @@
 %  \end{macro}
 %
 %  \begin{macro}{\@bibitem}
-% \changes{babel~3.5f}{1995/11/15}{Now use \cs{bbl at redefine}}
 %    One of the two internal \LaTeX\ macros called by |\bibitem|
 %    that write the citation label on the |.aux| file.
 %    \begin{macrocode}
@@ -6241,18 +6055,10 @@
 %  \subsection{Marks}
 %
 %  \begin{macro}{\markright}
-% \changes{babel~3.6i}{1997/03/15}{Added redefinition of \cs{mark...}
-%    commands}
 %    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.
-% \changes{babel~3.7c}{1999/04/08}{Removed the use of \cs{head at lang}
-%    (PR 2990)}
-% \changes{babel~3.7c}{1999/04/09}{Avoid expanding the arguments by
-%    storing them in token registers}
-% \changes{babel~3.7m}{2003/11/15}{added \cs{bbl at restore@actives} to
-%    the mark}
 % \changes{babel~3.8c}{2004/05/26}{No need to add \emph{anything} to
 %    an empty mark; prevented this by checking the contents of the
 %    argument}
@@ -6259,49 +6065,26 @@
 % \changes{babel~3.8f}{2005/05/15}{Make the definition independent of
 %    the original definition; expand \cs{languagename} before passing
 %    it into the token registers} 
+% \changes{babel~3.9t}{2017/04/23}{Refactored \cs{markright} and
+%    \cs{markboth}}  
+%
+%    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 redefine\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}
-%    First of all we temporarily store the language switching command,
-%    using an expanded definition in order to get the current value of
-%    |\languagename|. 
-%    \begin{macrocode}
-  \edef\bbl at tempb{\noexpand\protect
-    \noexpand\foreignlanguage{\languagename}}%
-%    \end{macrocode}
-%    Then, we check whether the argument is empty; if it is, we
-%    just make sure the scratch token register is empty.
-%    \begin{macrocode}
-  \def\bbl at arg{#1}%
-  \ifx\bbl at arg\@empty
-    \toks@{}%
-  \else
-%    \end{macrocode}
-%    Next, we store the argument to |\markright| in the scratch token
-%    register, together with the expansion of |\bbl at tempb| (containing
-%    the language switching command) as defined before. This way
-%    these commands will not be expanded by using |\edef| later
-%    on, 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}
-    \expandafter\toks@\expandafter{%
-             \bbl at tempb{\protect\bbl at restore@actives#1}}%
-  \fi
-%    \end{macrocode}
-%    Then we define a temporary control sequence using |\edef|.
-%    \begin{macrocode}
-  \edef\bbl at tempa{%
-%    \end{macrocode}
-%     When |\bbl at tempa| is executed, only |\languagename| will be
-%    expanded, because of the way the token register was filled.
-%    \begin{macrocode}
-    \noexpand\org at markright{\the\toks@}}%
-  \bbl at tempa
-}
-%    \end{macrocode}
 %  \end{macro}
 %
 %  \begin{macro}{\markboth}
@@ -6312,9 +6095,7 @@
 %    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 |\makrboth|.
-% \changes{babel~3.7m}{2003/11/15}{added \cs{bbl at restore@actives} to
-%    the mark}
+%    with the new definition of |\markboth|.
 % \changes{babel~3.8c}{2004/05/26}{No need to add \emph{anything} to
 %    an empty mark, prevented this by checking the contents of the
 %    arguments} 
@@ -6333,28 +6114,17 @@
 %    Now we can start the new definition of |\markboth|
 %    \begin{macrocode}
 \bbl at redefine\markboth#1#2{%
-  \edef\bbl at tempb{\noexpand\protect
-    \noexpand\foreignlanguage{\languagename}}%
-  \def\bbl at arg{#1}%
-  \ifx\bbl at arg\@empty
-    \toks@{}%
-  \else
-   \expandafter\toks@\expandafter{%
-             \bbl at tempb{\protect\bbl at restore@actives#1}}%
-  \fi
-  \def\bbl at arg{#2}%
-  \ifx\bbl at arg\@empty
-    \toks8{}%
-  \else
-    \expandafter\toks8\expandafter{%
-             \bbl at tempb{\protect\bbl at restore@actives#2}}%
-  \fi
-  \edef\bbl at tempa{%
-    \noexpand\org at markboth{\the\toks@}{\the\toks8}}%
-  \bbl at tempa
-}
+  \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}}}
 %    \end{macrocode}
-%    and copy it to |\@mkboth| if necesary.
+%    and copy it to |\@mkboth| if necessary.
 %    \begin{macrocode}
 \bbl at tempc
 %    \end{macrocode}
@@ -6366,9 +6136,6 @@
 %  \subsubsection{\pkg{ifthen}}
 %
 %  \begin{macro}{\ifthenelse}
-% \changes{babel~3.5g}{1996/08/11}{Redefinition of \cs{ifthenelse}
-%    added to circumvent problems with \cs{pageref} in the argument of
-%    \cs{isodd}}
 % \changes{babel~3.9a}{2012/09/07}{Redefine only if `ref' is `safe'}%
 % \changes{babel~3.9a}{2013/01/03}{Moved to babel.def}
 %    Sometimes a document writer wants to create a special effect
@@ -6394,7 +6161,6 @@
     \@ifpackageloaded{ifthen}{%
 %    \end{macrocode}
 %    Then we can redefine |\ifthenelse|:
-% \changes{babel~3.6f}{1997/01/14}{\cs{ifthenelse} needs to be long}
 % \changes{babel~3.9a}{2012/06/22}{\cs{ref} is also taken into account}
 % \changes{babel~3.9n}{2015/12/14}{Don't use generic temp
 %    macros. babel/4441}
@@ -6415,21 +6181,17 @@
 %    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.
-% \changes{babel~3.6i}{1997/02/25}{Now reset the @safe at actives switch
-%    inside the 2nd and 3rd arguments of \cs{ifthenelse}}
-% \changes{babel~3.7f}{2000/06/29}{\cs{pageref} needs to have its
-%    babel definition reinstated in the second and third arguments}
 %    \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}%
+        \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}%
         }%
       }{}%
     }
@@ -6439,12 +6201,7 @@
 %  \subsubsection{\pkg{varioref}}
 %
 %  \begin{macro}{\@@vpageref}
-% \changes{babel~3.6a}{1996/10/29}{Redefinition of \cs{@@vpageref}
-%    added to circumvent problems with active \texttt{:} in the
-%    argument of \cs{vref} when \pkg{varioref} is used}
 %  \begin{macro}{\vrefpagenum}
-% \changes{babel~3.7o}{2003/11/18}{Added redefinition of
-%    \cs{vrefpagenum} which deals with ranges of pages}
 %  \begin{macro}{\Ref}
 % \changes{babel~3.8g}{2005/05/21}{We also need to adapt \cs{Ref}
 %    which needs to be able to uppercase the first letter of the
@@ -6535,12 +6292,9 @@
 %    
 %    \begin{macrocode}
 \AtBeginDocument{%
-  \@ifundefined{pdfstringdefDisableCommands}%
-    {}%
-    {\pdfstringdefDisableCommands{%
-       \languageshorthands{system}}%
-    }%
-}
+  \ifx\pdfstringdefDisableCommands\@undefined\else
+    \pdfstringdefDisableCommands{\languageshorthands{system}}%
+  \fi}
 %    \end{macrocode}
 %  \end{macro}
 %
@@ -6553,8 +6307,6 @@
 %    marks can end up inside the argument of |\MakeUppercase|. To
 %    prevent unexpected results we need to define |\FOREIGNLANGUAGE|
 %    here.
-% \changes{babel~3.7j}{2003/05/23}{Define \cs{FOREIGNLANGUAGE}
-%    unconditionally}
 %    \begin{macrocode}
 \DeclareRobustCommand{\FOREIGNLANGUAGE}[1]{%
   \lowercase{\foreignlanguage{#1}}}
@@ -6565,7 +6317,6 @@
 %    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.
-%    \changes{babel~3.7j}{2003/06/15}{create file with lowercase name}
 %    \begin{macrocode}
 \def\substitutefontfamily#1#2#3{%
   \lowercase{\immediate\openout15=#1#2.fd\relax}%
@@ -6592,7 +6343,7 @@
 %    \end{macrocode}
 %  \end{macro}
 %
-%  \subsection{Encoding issues}
+%  \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
@@ -6629,7 +6380,7 @@
     \def\bbl at tempb#1\@@{\uppercase{\bbl at tempc#1}ENC.DEF\@empty\@@}%
     \def\bbl at tempc#1ENC.DEF#2\@@{%
       \ifx\@empty#2\else
-        \@ifundefined{T@#1}% 
+        \bbl at ifunset{T@#1}% 
           {}%
           {\@expandtwoargs\in@{,#1,}{,\BabelNonASCII,}%
            \ifin@
@@ -6654,8 +6405,6 @@
 %  determine, at |\begin{document}|, which latin fontencoding to use.
 %
 %  \begin{macro}{\latinencoding}
-% \changes{babel~3.6i}{1997/03/15}{Macro added, moved from
-%    \file{.ldf} files}
 %    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.
@@ -6671,18 +6420,6 @@
 %    disabled for this package. Now we have to revert to parsing the
 %    internal macro |\@filelist| which contains all the filenames
 %    loaded.
-% \changes{babel~3.6k}{1999/03/15}{Use T1 encoding when it is a known
-%    encoding}
-% \changes{babel~3.6m}{1999/04/06}{Can't use \cs{@ifpackageloaded}
-%    need to parse \cs{@filelist}}
-% \changes{babel~3.6n}{1999/04/07}{moved checking for fontenc right to
-%    the top of \file{babel.sty}}
-% \changes{babel~3.6n}{1999/04/07}{Added a check for `manual' selection
-%    of \texttt{T1} encoding, without loading \pkg{fontenc}}
-% \changes{babel~3.6q}{1999/04/12}{Better solution than parsing
-%    \cs{@filelist}, use \cs{@ifl at aded}}
-% \changes{babel~3.6u}{1999/04/20}{Moved this code to
-%    \file{babel.def}}
 % \changes{babel~3.9l}{2014/08/02}{fontspec used to set
 %    \cs{latinencoding} to EUx, but now it doesn't. So, it's done
 %    here.}
@@ -6692,9 +6429,11 @@
 \AtBeginDocument{%
   \@ifpackageloaded{fontspec}%
     {\xdef\latinencoding{%
-       \@ifundefined{UTFencname}%
-         {EU\ifcase\bbl at engine\or2\or1\fi}%
-         {\UTFencname}}}%
+       \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}%
@@ -6705,8 +6444,6 @@
 %  \end{macro}
 %
 %  \begin{macro}{\latintext}
-% \changes{babel~3.6i}{1997/03/15}{Macro added, moved from
-%    \file{.ldf} files}
 %    Then we can define the command |\latintext| which is a
 %    declarative switch to a latin font-encoding. Usage of this macro
 %    is deprecated.
@@ -6718,11 +6455,6 @@
 %  \end{macro}
 %
 %  \begin{macro}{\textlatin}
-% \changes{babel~3.6i}{1997/03/15}{Macro added, moved from
-%    \file{.ldf} files}
-% \changes{babel~3.7j}{2003/03/19}{added \cs{leavevmode} to prevent a
-%    paragraph starting \emph{inside} the group}
-% \changes{babel~3.7k}{2003/10/12}{Use \cs{DeclareTextFontComand}}
 %    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.
@@ -6745,7 +6477,6 @@
 %    will be loaded when the language definition file \file{norsk.ldf}
 %    is loaded.
 %
-% \changes{babel~3.5d}{1995/06/22}{Added macro}
 %    For plain-based formats we don't want to override the definition
 %    of |\loadlocalcfg| from \file{plain.def}.
 %    \begin{macrocode}
@@ -7122,7 +6853,6 @@
 %    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.
-% \changes{babel~3.2}{1991/11/11}{Added \cs{relax}}
 %    \begin{macrocode}
 \def\bbl at version{<@version@>}
 \def\bbl at date{<@date@>}
@@ -7136,7 +6866,7 @@
 % \changes{babel~3.9a}{2013/01/23}{New macro to normalize 
 %    a macro (eg, \cs{languagename}) to lowercase if necessary}
 %
-%    |\bbl at iflanguage| executes code only of the language
+%    |\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
@@ -7145,7 +6875,8 @@
 %    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).
+%    trapped). Note |l@| is encapsulated, so that its case does not
+%    change.
 %    \begin{macrocode}
 \def\bbl at fixname#1{%
   \begingroup
@@ -7174,10 +6905,6 @@
 %    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.
-% \changes{babel~3.2}{1991/11/11}{Rephrased \cs{ifnum} test}
-% \changes{babel~3.7a}{1998/06/10}{Now evaluate the \cs{ifnum} test
-%    \emph{after} the \cs{fi} from the \cs{ifx} test and use
-%    \cs{@firstoftwo} and \cs{@secondoftwo}}
 %    \begin{macrocode}
 \def\iflanguage#1{%
   \bbl at iflanguage{#1}{%
@@ -7219,18 +6946,6 @@
 %    If the user gives an empty argument, we provide a default
 %    argument for |\string|.  This argument should expand to nothing.
 %
-% \changes{babel~3.0c}{1991/06/06}{Made \cs{selectlanguage}
-%    robust}
-% \changes{babel~3.2}{1991/11/11}{Modified to allow arguments that
-%    start with an escape character}
-% \changes{babel~3.2a}{1991/11/17}{Simplified the modification to
-%    allow the use in a \cs{write} command}
-% \changes{babel~3.5b}{1995/05/13}{Store the name of the current
-%    language in a control sequence instead of passing the whole macro
-%    construct to strip the escape character in the argument of
-%    \cs{selectlanguage }.}
-% \changes{babel~3.5f}{1995/11/16}{Moved check for escape character
-%    one level down in the expansion}
 % \changes{babel~3.9a}{2012/11/16}{\cs{bbl at select@type} keep tracks of
 %    the selection method: 0 is select, 1 is foreign}
 %    \begin{macrocode}
@@ -7261,12 +6976,6 @@
 %    \end{macrocode}
 % \end{macro}
 %
-% \changes{babel~3.5b}{1995/03/04}{Changed the name of the internal
-%    macro to \cs{selectlanguage }.}
-% \changes{babel~3.5b}{1995/03/05}{Added an extra level of expansion to
-%    separate the switching mechanism from writing to aux files}
-% \changes{babel~3.7f}{2000/09/25}{Use \cs{aftergroup} to keep the
-%    language grouping correct in auxiliary files {PR3091}}
 %    Since version 3.5 \babel\ writes entries to the auxiliary files in
 %    order to typeset table of contents etc. in the correct language
 %    environment.
@@ -7280,8 +6989,6 @@
 %    executed at the end of the group. It calls |\bbl at set@language|
 %    with the name of the current language as its argument.
 %
-% \changes{babel~3.7j}{2003/03/18}{Introduce the language stack
-%    mechanism}
 %  \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
@@ -7334,7 +7041,6 @@
 %  \end{macro}
 %  \end{macro}
 %
-% \changes{babel~3.7j}{2003/03/18}{Now use the language stack mechanism}
 %    \begin{macrocode}
 \expandafter\def\csname selectlanguage \endcsname#1{%
   \ifnum\bbl at hymapsel=\@cclv\let\bbl at hymapsel\tw@\fi
@@ -7342,13 +7048,9 @@
   \aftergroup\bbl at pop@language
   \bbl at set@language{#1}}
 %    \end{macrocode}
-% \changes{babel~3.7m}{2003/11/12}{Removed the superfluous empty
-%    definition of \cs{bbl at pop@language}}
 %  \end{macro}
 %
 %  \begin{macro}{\bbl at set@language}
-%    \changes{babel~3.7f}{2000/09/25}{Macro \cs{bbl at set@language}
-%    introduced}
 % 
 %    The macro |\bbl at set@language| takes care of switching the
 %    language environment \emph{and} of writing entries on the
@@ -7363,8 +7065,6 @@
 %
 %    We also write a command to change the current language in the
 %    auxiliary files.
-% \changes{babel~3.5a}{1995/02/17}{Write the language change to the
-%    auxiliary files}
 % \changes{babel~3.9a}{2012/09/09}{Added hook}
 % \changes{babel~3.9a}{2012/11/07}{Use a loop for contents files, with
 %    the help of \cs{BabelContentsFiles}}
@@ -7397,41 +7097,29 @@
          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}%
-        {You may proceed, but expect unexpected results}%
+        {You may proceed, but expect wrong results}%
     \else
       \let\bbl at select@type\z@
       \expandafter\bbl at switch\expandafter{\languagename}%
     \fi}}
-% A bit of optimization:
-\def\select at language@x#1{%
-  \ifcase\bbl at select@type
-    \bbl at ifsamestring\languagename{#1}{}{\select at language{#1}}%
-  \else
-    \select at language{#1}%
-  \fi}
 %    \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.
-% \changes{babel~3.0a}{1991/05/29}{Added \cs{@bsphack} and
-%    \cs{@esphack}}
-% \changes{babel~3.0d}{1991/08/08}{Removed superfluous
-%    \cs{expandafter}}
-% \changes{babel~3.0d}{1991/10/07}{Removed space hacks and use of
-%    \cs{@ifundefined}}
-% \changes{babel~3.2a}{1991/11/17}{Added \cs{relax} as first command
-%    to stop an expansion if \cs{protect} is empty}
-% \changes{babel~3.6a}{1996/11/07}{Check for the existence of
-%    \cs{date...} instead of \cs{l at ...}}
-% \changes{babel~3.7m}{2003/11/16}{Check for the existence of both
-%    \cs{l at ...} and \cs{date...}}
 % \changes{babel~3.8l}{2008/07/06}{Use \cs{bbl at patterns}}
 % \changes{babel~3.9a}{2012/07/27}{Moved \cs{bbl at patterns} to the
 %    correct place, after setting the extras for the current
 %    language}
-% \changes{babel~3.9a}{2012/08/01}{Created \cs{bbl at swith} with code
+% \changes{babel~3.9a}{2012/08/01}{Created \cs{bbl at switch} with code
 %    shared by \cs{select at language} and \cs{foreing at language}}
 %    \begin{macrocode}
 %    \end{macrocode}
@@ -7450,8 +7138,6 @@
 %    macros. \nb{What if \cs{hyphenation} was used in |extras|? Patch
 %    temply set at hyphenmins and hyphenation. It can be done in hooks if
 %    necessary.}
-% \changes{babel~3.5b}{1995/05/13}{Separated the setting of the
-%    hyphenmin values}%
 % \changes{babel~3.9c}{2013/04/08}{Removed an extra empty line}
 %
 %    The switching of the values of |\lefthyphenmin| and
@@ -7459,24 +7145,11 @@
 %    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.
-% \changes{babel~3.5b}{1995/06/05}{Addedd default setting of hyphenmin
-%    parameters}
 % \changes{babel~3.9a}{2012/08/01}{Adddd \cs{bbl at iflanguagename} and
 %   \cs{select at language@x}, which is no-op if the language is the same}
 % \changes{babel~3.9a}{2013/01/23}{\cs{select at language} sets 
 %   \textsc{languagename} so that it has the correct value in the aux
 %   file (eg, shorthand expansion was wrong)}
-% \changes{babel~3.0a}{1991/06/06}{Replaced \cs{gdef} with \cs{def}}
-% \changes{babel~3.1}{1991/10/31}{\cs{originalTeX} should only be
-%    executed once}
-% \changes{babel~3.2a}{1991/11/17}{Added three \cs{expandafter}s
-%    to save macro space for \cs{originalTeX}}
-% \changes{babel~3.2a}{1991/11/20}{Moved definition of
-%    \cs{originalTeX} before \cs{extras\langvar}}
-% \changes{babel~3.2a}{1991/11/24}{Set \cs{originalTeX} to
-%    \cs{empty}, because it should be expandable.}
-% \changes{babel~3.6d}{1997/01/07}{set the language shorthands to
-%    `none' before switching on the extras}
 % \changes{babel~3.9a}{2012/08/14}{Make sure the save counter is reset
 %    even if \cs{originalTeX} is used in other contexts}
 % \changes{babel~3.9h}{2013/11/29}{Use \cs{def} instead of
@@ -7492,8 +7165,8 @@
   \bbl at usehooks{afterreset}{}%
   \languageshorthands{none}%
   \ifcase\bbl at select@type
-    \csname captions#1\endcsname
-    \csname date#1\endcsname
+    \csname captions#1\endcsname\relax
+    \csname date#1\endcsname\relax
   \fi
   \bbl at usehooks{beforeextras}{}%
   \csname extras#1\endcsname\relax
@@ -7520,18 +7193,6 @@
       \csname #1hyphenmins\endcsname\relax
   \fi}
 %    \end{macrocode}
-%    \begin{macrocode}
-\def\bbl at ifsamestring#1#2{%
-  \protected at edef\bbl at tempb{#1}%
-  \edef\bbl at tempb{\expandafter\strip at prefix\meaning\bbl at tempb}%
-  \protected at edef\bbl at tempc{#2}%
-  \edef\bbl at tempc{\expandafter\strip at prefix\meaning\bbl at tempc}%
-  \ifx\bbl at tempb\bbl at tempc
-    \expandafter\@firstoftwo
-  \else
-    \expandafter\@secondoftwo
-  \fi}
-%    \end{macrocode}
 %
 %  \begin{environment}{otherlanguage}
 %    The \Lenv{otherlanguage} environment can be used as an
@@ -7545,10 +7206,6 @@
 %    \verb*=\selectlanguage = to switch on everything that is needed for
 %    this language The |\ignorespaces| command is necessary to hide
 %    the environment when it is entered in horizontal mode.
-% \changes{babel~3.5d}{1995/06/22}{environment added}
-% \changes{babel~3.5e}{1995/07/07}{changed name}
-% \changes{babel~3.7j}{2003/03/18}{rely on \cs{selectlanguage } to
-%    keep track of the nesting}
 % \changes{babel~3.9a}{2012/07/31}{Removed \cs{originalTeX}}
 %    \begin{macrocode}
 \long\def\otherlanguage#1{%
@@ -7569,8 +7226,6 @@
 %    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|.
-% \changes{babel~3.5f}{1996/05/29}{environment added}
-% \changes{babel~3.6d}{1997/01/07}{Introduced \cs{foreign at language}}
 %    \begin{macrocode}
 \expandafter\def\csname otherlanguage*\endcsname#1{%
   \ifnum\bbl at hymapsel=\@cclv\chardef\bbl at hymapsel4\relax\fi
@@ -7596,9 +7251,6 @@
 %    a group and assumes the |\extras|\langvar\ command doesn't make
 %    any |\global| changes. The coding is very similar to part of
 %    |\selectlanguage|.
-% \changes{babel~3.5d}{1995/06/22}{Macro added}
-% \changes{babel~3.6d}{1997/01/07}{Introduced \cs{foreign at language}}
-% \changes{babel~3.7a}{1998/03/12}{Added executing \cs{originalTeX}}
 % \changes{babel~3.9a}{2012/07/30}{Removed unnecesary \cs{noextras}
 %    just before closing the group}
 % \changes{babel~3.9a}{2012/07/31}{Moved \cs{originalTeX} to
@@ -7619,7 +7271,7 @@
 %  \end{macro}
 %
 %  \begin{macro}{\foreign at language}
-% \changes{babel~3.6d}{1997/01/07}{New macro} This macro does the
+%    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
@@ -7633,8 +7285,11 @@
   \bbl at iflanguage\languagename{%
     \expandafter\ifx\csname date\languagename\endcsname\relax
       \bbl at warning
-        {You haven't loaded the language \languagename\space yet\\%
-         I'll proceed, but expect unexpected results.\\%
+        {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.\\%
+         I'll proceed, but expect wrong results.\\%
          Reported}%
     \fi
     \let\bbl at select@type\@ne
@@ -7674,9 +7329,9 @@
     \else
       \csname l@#1:\f at encoding\endcsname
       \edef\bbl at tempa{#1:\f at encoding}%
-    \fi\relax
+    \fi
   \@expandtwoargs\bbl at usehooks{patterns}{{#1}{\bbl at tempa}}%
-  \@ifundefined{bbl at hyphenation@}{}{%
+  \@ifundefined{bbl at hyphenation@}{}{% Can be \relax!
     \begingroup
       \@expandtwoargs\in@{,\number\language,}{,\bbl at hyphlist}%
       \ifin@\else
@@ -7693,7 +7348,6 @@
 %  \end{macro}
 %
 %  \begin{environment}{hyphenrules}
-% \changes{babel~3.7e}{2000/01/28}{Added 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
@@ -7721,7 +7375,6 @@
 %  \end{environment}
 %
 %  \begin{macro}{\providehyphenmins}
-% \changes{babel~3.7f}{2000/02/18}{added macro}
 %    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
@@ -7744,9 +7397,6 @@
 %  \end{macro}
 %
 %  \begin{macro}{\ProvidesLanguage}
-% \changes{babel~3.7a}{1997/03/18}{Added macro to prevent problems
-%    with unexpected \cs{ProvidesFile} in plain formats because of
-%    \babel.}
 %    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
@@ -7755,14 +7405,6 @@
 %
 %    Depending on the format, ie, on if the former is defined, we use
 %    a similar definition or not.
-%    \changes{babel~3.4e}{1994/06/24}{Redid the identification code,
-%    provided dummy definition of \cs{ProvidesFile} for plain \TeX}
-%    \changes{babel~3.5f}{1995/07/26}{Store version in
-%    \cs{fileversion}} \changes{babel~3.5f}{1995/12/18}{Need to
-%    temporarily change the definition of \cs{ProvidesFile} for
-%    December 1995 release} \changes{babel~3.5g}{1996/07/09}{Save a
-%    few csnames; use \cs{bbl at tempa} instead of \cs{\@ProvidesFile}
-%    and store message in \cs{toks8}}
 %    \changes{babel~3.9a}{2012/12/09}{Save info about the babel
 %    version in the format (switch.def) so that it can be checked
 %    later if necessary}
@@ -7787,7 +7429,6 @@
 %  \end{macro}
 %
 %  \begin{macro}{\LdfInit}
-% \changes{babel~3.6a}{1996/10/16}{Macro added}
 %    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}.
@@ -7811,8 +7452,6 @@
 %    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|.
-% \changes{babel~3.2a}{1991/11/24}{Set \cs{originalTeX} to
-%    \cs{empty}, because it should be expandable.}
 %    \begin{macrocode}
 \ifx\originalTeX\@undefined\let\originalTeX\@empty\fi
 %    \end{macrocode}
@@ -7824,13 +7463,26 @@
 %    \end{macrocode}
 %  \end{macro}
 %
+% A few macro names are reserved for future releases of \babel, which
+% will use the concept of `locale':
+% \changes{babel~3.9s}{2017/04/13}{Reserved macros}
+%    \begin{macrocode}
+\newcommand\setlocale{%
+  \bbl at error
+    {Not yet available}%
+    {Find an armchair, sit down and wait}}
+\let\uselocale\setlocale
+\let\locale\setlocale
+\let\selectlocale\setlocale
+\let\textlocale\setlocale
+\let\textlanguage\setlocale
+\let\languagetext\setlocale
+%    \end{macrocode}
+%
 %    \subsection{Errors}
 %
 %  \begin{macro}{\@nolanerr}
-% \changes{babel~3.4e}{1994/06/25}{Use \cs{PackageError} in \LaTeXe\
-%    mode}
 %  \begin{macro}{\@nopatterns}
-% \changes{babel~3.4e}{1994/06/25}{Macro added}
 %    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
@@ -7839,7 +7491,6 @@
 %    In most formats that will be (US)english, but it might also be
 %    empty.
 %  \begin{macro}{\@noopterr}
-% \changes{babel~3.7m}{2003/11/16}{Macro added}
 %    When the package was loaded without options not everything will
 %    work as expected. An error message is issued in that case.
 %
@@ -7846,11 +7497,6 @@
 %    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'.
-% \changes{babel~3.0d}{1991/10/07}{Added a percent sign to remove
-%    unwanted white space}
-% \changes{babel~3.5a}{1995/02/15}{Added \cs{@activated} to log active
-%    characters}
-% \changes{babel~3.5c}{1995/06/19}{Added missing closing brace}
 % \changes{babel~3.9a}{2012/07/30}{\cs{newcommand}s replaced by
 %    \cs{def}'s, so that the file can be loaded twice}
 % \changes{babel~3.9a}{2013/01/26}{Define generic variants instead of
@@ -7926,10 +7572,6 @@
 %    |toks8| stores info to be shown when the program is run.
 %
 % \changes{babel~3.9g}{2013/05/30}{Code moved from plain.def}
-% \changes{bbplain-1.0c}{1995/11/08}{Moved the \cs{dump} code here from
-%    \file{babel.dtx}}
-% \changes{bbplain-0.1}{1991/10/31}{Added redefinition of \cs{dump} to
-%    add a message to \cs{everyjob}}
 %    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: 
@@ -7966,19 +7608,10 @@
 %    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|.
-% \changes{bbplain-1.0c}{1995/11/19}{Add execution of
-%    \cs{@begindocumenthook} to \cs{@preamblecmds}} 
-% \changes{bbplain-1.0i}{1997/01/02}{\cs{document} is not a
-%    \LaTeX2.09-only command; AMS\TeX defines it too; now use
-%    \cs{@ztryfc} to detect \LaTeX2.09} 
-% \changes{bbplain-1.0j}{1997/01/07}{Add the definition of
-%    \cs{@begindocumenthook} to the \LaTeX2.09 format} 
 %
 %    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.
-% \changes{bbplain-1.0f}{1996/07/09}{Use \cs{toks8} instead of
-%    \cs{patterns at loaded}} 
 %
 %    Then everything is restored to the old situation and the format
 %    is dumped.
@@ -8004,11 +7637,8 @@
 \toks8{Babel <<@version@>> and hyphenation patterns for }%
 %    \end{macrocode}
 %
-% \changes{babel~3.5g}{1996/07/09}{Removed the use of
-%    \cs{patterns at loaded} altogether}
 %
 %  \begin{macro}{\process at line}
-% \changes{babel~3.5b}{1995/04/28}{added macro}
 %    Each line in the file \file{language.dat} is processed by
 %    |\process at line| after it is read. The first thing this macro does
 %    is to check whether the line starts with \texttt{=}.
@@ -8015,8 +7645,6 @@
 %    When the first token of a line is an \texttt{=}, the macro
 %    |\process at synonym| is called; otherwise the macro
 %    |\process at language| will continue.
-% \changes{babel~3.5g}{1996/07/09}{Simplified code, removing
-%    \cs{bbl at eq@}}
 % \changes{babel~3.9a}{2012/12/12}{Use spaces as delimiters, to avoid
 %    extra spaces. Once parsed, pass them in the traditional way}
 %    \begin{macrocode}   
@@ -8031,10 +7659,6 @@
 %  \end{macro}
 %
 %  \begin{macro}{\process at synonym}
-% \changes{babel~3.5b}{1995/04/28}{added macro}
-% \changes{babel~3.7c}{1999/04/27}{Use a token register to temporarily
-%    store a command to set hyphenmin parameters for the synonym which
-%    is defined \emph{before} the first pattern file is processed}
 %
 %    This macro takes care of the lines which start with an
 %    \texttt{=}. It needs an empty token register to begin with.
@@ -8052,8 +7676,6 @@
 %    Otherwise the name will be a synonym for the language loaded last.
 %
 %    We also need to copy the hyphenmin parameters for the synonym.
-% \changes{babel~3.7c}{1999/04/22}{Now also store hyphenmin parameters
-%    for language synonyms}
 % \changes{babel~3.9a}{2012/06/25}{Added \cs{bbl at languages}}
 %    \begin{macrocode}
 \def\process at synonym#1{%
@@ -8080,18 +7702,9 @@
 %
 %    The first thing to do is call |\addlanguage| to allocate a
 %    pattern register and to make that register `active'.
-% \changes{babel~3.0d}{1991/08/08}{Removed superfluous
-%    \cs{expandafter}}
-% \changes{babel~3.0d}{1991/08/21}{Reinserted \cs{expandafter}}
-% \changes{babel~3.0d}{1991/10/27}{Added the collection of pattern
-%    names.}
-% \changes{babel~3.7c}{1999/04/22}{Also store \cs{languagename} for
-%    possible later use in \cs{process at synonym}}
 %    Then the `name' of the language that will be loaded now is
 %    added to the token register |\toks8|. and finally
 %    the pattern file is read.
-% \changes{babel~3.7f}{2000/02/18}{Allow for the encoding to be used
-%    as part of the language name} 
 % \changes{babel~3.9a}{2012/12/10}{Removed \cs{selectfont} (I presume
 %    it was intended to catch wrong encoding codes, but I don't think
 %    this is necessary and as a side effect it might preload fonts)}
@@ -8105,16 +7718,6 @@
 %    you need to set a behaviour depending on the given encoding (it
 %    is set to empty if no encoding is given).
 %
-% \changes{babel~3.4e}{1994/06/24}{Added code to detect assignments to
-%    left- and righthyphenmin in the patternfile.}
-% \changes{babel~3.7a}{1998/03/27}{Read pattern files in a group}
-% \changes{babel~3.7c}{1999/04/05}{need to set hyphenmin values
-%    globally}
-% \changes{babel~3.7c}{1999/04/22}{Set \cs{lefthyphenmin} to \cs{m at ne}
-%    \emph{inside} the group; explicitly set the hyphenmin parameters
-%    for language 0}
-% \changes{babel~3.7c}{1999/04/25}{Only set hyphenmin values when the
-%    pattern file changed them}
 %    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
@@ -8134,10 +7737,6 @@
 %    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.)
-% \changes{babel~3.5b}{1995/04/28}{Added optional reading of file with
-%    hyphenation exceptions}
-% \changes{babel~3.5f}{1995/07/25}{Use \cs{empty} instead of
-%    \cs{@empty} as the latter is unknown in plain}
 %
 % \changes{babel~3.9a}{2012/06/25}{Added \cs{bbl at languages}}
 % \changes{babel~3.9f}{2013/05/16}{Restored code to set default
@@ -8148,8 +7747,6 @@
 %    arguments are empty in `dialects' defined in |language.dat| with
 %    |=|. Note also the language name can have encoding info.
 %
-% \changes{babel~3.7c}{1999/04/27}{Added the execution of the contents
-%    of \cs{toks@}}
 %    Finally, if the counter |\language| is equal to zero we execute the
 %    synonyms stored.
 %    \begin{macrocode}
@@ -8188,7 +7785,6 @@
 %    \end{macrocode}
 %
 %  \begin{macro}{\bbl at get@enc}
-% \changes{babel~3.7f}{2000/02/18}{Added macro}
 % \changes{babel~3.9a}{2012/12/11}{Code much simplified}
 %  \begin{macro}{\bbl at hyph@enc}
 %    The macro |\bbl at get@enc| extracts the font encoding from the
@@ -8261,7 +7857,6 @@
 %    first patterns loaded in pattern register number~0 we initialize
 %    |\last at language| with the value~$-1$.
 %
-% \changes{babel~3.1}{1991/05/21}{Removed use of \cs{toks0}}
 %    \begin{macrocode}
   \last at language\m at ne
 %    \end{macrocode}
@@ -8316,20 +7911,13 @@
 \fi
 %    \end{macrocode}
 %    and close the configuration file.
-% \changes{babel~3.2a}{1991/11/20}{Free macro space for
-%    \cs{process at language}}
 %    \begin{macrocode}
 \closein1
 %    \end{macrocode}
 %
-% \changes{babel~3.5f}{1995/11/08}{Moved the fiddling with \cs{dump}
-%     to \file{bbplain.dtx} as it is no longer needed for \LaTeX}
 %    We add a message about the fact that babel is loaded in the
 %    format and with which language patterns to the \cs{everyjob}
 %    register.
-% \changes{babel~3.6h}{1997/01/23}{Added a couple of \cs{expandafter}s
-%    to copy the contents of \cs{toks8} into \cs{everyjob} instead of
-%    the reference}
 % \changes{babel~3.9a}{2012/09/25}{The list of languages is not
 %    printed every job any more (it is saved in \cs{bbl at languages}).} 
 % \changes{babel~3.9g}{2013/07/28}{In non-LaTeX formats the number of
@@ -8431,8 +8019,6 @@
 %</nil>
 %    \end{macrocode}
 %
-% \changes{bbplain-1.0n}{1998/06/08}{Added the source for the format
-%    wrapper files} 
 %
 %  \section{Support for Plain \TeX}
 %
@@ -8529,22 +8115,6 @@
 %    The following code duplicates or emulates parts of \LaTeXe\ that
 %    are needed for \babel.
 %
-% \changes{bbplain-1.0f}{1996/07/09}{Consistently use \cs{@undefined}
-%    instead of \cs{undefined}} 
-% \changes{bbplain-1.0f}{1996/07/09}{added \cs{@empty}}
-% \changes{bbplain-1.0h}{1996/10/07}{Only load the necessary parts
-%    into the format, let this file be read agian by babel.def} 
-% \changes{bbplain-1.0h}{2012/12/21}{Use \cs{orig at dump} as flag to
-%    decide if we are building the format, defined in hyphen.cfg} 
-%
-%    We need to define |\loadlocalcfg| for plain users as the
-%    \LaTeX\ definition uses |\InputIfFileExists|. We have to execute
-%    \cs{@endofldf} in this case.
-% \changes{bbplain-1.0c}{1995/07/26}{Added definition of
-%    \cs{loadlocalcfg}}
-% \changes{bbplain-1.0d}{1996/01/08}{Also reset category codes after
-%    loading the configuration file as \cs{AtEndOfPackage} is
-%    undefined in this case} 
 % \changes{bbplain-1.0s}{2012/12/21}{\cs{loadlocalcfg} not loaded in
 %    the format} 
 %    \begin{macrocode}
@@ -8568,8 +8138,6 @@
 % \subsection{General tools}
 %
 %    A number of \LaTeX\ macro's that are needed later on.
-% \changes{bbplain-1.0n}{1998/06/10}{Added \cs{@secondoftwo}}
-% \changes{bbplain-1.0q}{1999/09/16}{Added \cs{@ifundefined}}
 % \changes{bbplain-1.0t}{2013/04/10}{Added \cs{@expandtwoargs}}
 % \changes{babel~3.9h}{2013/12/02}{Added \cs{zap at space}}
 % \changes{babel~3.9k}{2014/03/22}{Added \cs{@nnil}}
@@ -8635,9 +8203,6 @@
   \global\let\do\noexpand}
 %    \end{macrocode}
 %    
-% \changes{bbplain-1.0j}{1997/01/07}{\cs{@begindocumenthook} might
-%    already be defined} 
-% \changes{bbplain-1.0k}{1997/01/14}{missing \cs{@undefined} added}
 %    \begin{macrocode}
 \ifx\@begindocumenthook\@undefined
   \def\@begindocumenthook{}
@@ -8660,10 +8225,6 @@
 %    \end{macrocode}
 %    \LaTeX\ needs to be able to switch off writing to its auxiliary
 %    files; plain doesn't have them by default.
-%  \changes{bbplain-1.0m}{1997/04/28}{Set \cs{if at filesw} to 
-%    \cs{iffalse} only for plain \TeX}
-% \changes{bbplain-1.0n}{1997/09/11}{Repaired typo and added missing
-%    \cs{endcsname}}
 %    \begin{macrocode}
 \ifx\if at filesw\@undefined
   \expandafter\let\csname if at filesw\expandafter\endcsname
@@ -8671,8 +8232,6 @@
 \fi
 %    \end{macrocode}
 %    Mimick \LaTeX's commands to define control sequences.
-% \changes{bbplain-1.0e}{1996/02/22}{Provide a more complete emulation
-%    of \cs{DeclareRobustCommand} and \cs{newcommand}} 
 %    \begin{macrocode}
 \def\newcommand{\@star at or@long\new at command}
 \def\new at command#1{%
@@ -8724,11 +8283,9 @@
          \noexpand#1%
       \fi
       \noexpand\protect
-      \expandafter\noexpand\csname
-         \expandafter\@gobble\string#1 \endcsname
+      \expandafter\noexpand\csname\bbl at stripslash#1 \endcsname
    }%
-   \expandafter\new at command\csname
-      \expandafter\@gobble\string#1 \endcsname
+   \expandafter\new at command\csname\bbl at stripslash#1 \endcsname
 }
 \def\x at protect#1{%
    \ifx\protect\@typeset at protect\else
@@ -8745,7 +8302,6 @@
 %    argument. It uses the boolean |\in@|; allocating a new boolean
 %    inside conditionally executed code is not possible, hence the
 %    construct with the temporary definition of |\bbl at tempa|.
-% \changes{bbplain-1.0o}{1998/07/02}{Added definition of \cs{in@}}
 % \changes{bbplain-1.0s}{2013/01/15}{Use \cs{bbl at tempa} as
 %    documented}
 %    \begin{macrocode}
@@ -8773,15 +8329,15 @@
 %    \begin{macrocode}
 \def\@ifpackagewith#1#2#3#4{#3}
 %    \end{macrocode}
+%
 %    The \LaTeX\ macro |\@ifl at aded| checks whether a file was
 %    loaded. This functionality is not needed for plain \TeX\ but we
 %    need the macro to be defined as a no-op.
-% \changes{bbplain-1.0p}{1999/04/27}{Added \cs{@ifl at aded} as a no-op}
+%
 %    \begin{macrocode}
 \def\@ifl at aded#1#2#3#4{}
 %    \end{macrocode}
 %
-% \changes{bbplain-1.0e}{1996/01/15}{Added the \cs{newcommand} code}
 %    For the following code we need to make sure that the commands
 %    |\newcommand| and |\providecommand| exist with some sensible
 %    definition. They are not fully equivalent to their \LaTeXe\
@@ -8788,10 +8344,6 @@
 %    versions; just enough to make things work in plain~\TeX
 %    environments.
 %
-% \changes{bbplain-1.0k}{1997/01/14}{\cs{newcount} is an \cs{outer}
-%    command, can't use it inside an \cs{if} construct} 
-% \changes{bbplain-1.0l}{1997/01/19}{Mixed up the definition of 
-%    \cs{@tempcntb}}
 %    \begin{macrocode}
 \ifx\@tempcnta\@undefined
   \csname newcount\endcsname\@tempcnta\relax
@@ -8994,11 +8546,6 @@
 %    \end{macrocode}
 %    The following control sequences are used in \file{babel.def}
 %    but are not defined for \textsc{plain} \TeX.
-% \changes{bbplain-1.0f}{1996/07/10}{Added \cs{textquotedblright} and
-%    \cs{textquoteright}} 
-% \changes{bbplain-1.0g}{1996/08/15}{Added \cs{ss} and \cs{i}}
-% \changes{bbplain-1.0r}{2000/10/02}{Added \cs{textquotedblleft} and
-%    \cs{textquoteleft}} 
 %    \begin{macrocode}
 \DeclareTextSymbol{\textquotedblleft}{OT1}{92}
 \DeclareTextSymbol{\textquotedblright}{OT1}{`\"}
@@ -9011,8 +8558,6 @@
 %    |\scriptsize| to be available. Because plain \TeX\ doesn't have
 %    such a sofisticated font mechanism as \LaTeX\ has, we just |\let|
 %    it to |\sevenrm|.
-% \changes{bbplain-1.0f}{1996/07/10}{Added definition of
-%    \cs{scriptsize}} 
 %    \begin{macrocode}
 \ifx\scriptsize\@undefined
   \let\scriptsize\sevenrm

Modified: trunk/Master/texmf-dist/source/latex/babel/bbcompat.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/babel/bbcompat.dtx	2017-04-28 21:17:39 UTC (rev 44100)
+++ trunk/Master/texmf-dist/source/latex/babel/bbcompat.dtx	2017-04-28 21:20:36 UTC (rev 44101)
@@ -30,7 +30,7 @@
 %
 % \iffalse
 %<*dtx>
-\ProvidesFile{bbcompat.dtx}[2016/04/23 v3.9r]
+\ProvidesFile{bbcompat.dtx}[2017/04/28 v3.9t]
 %</dtx>
 %
 %% File 'bbcompat.dtx'

Modified: trunk/Master/texmf-dist/source/latex/babel/bbunicode.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/babel/bbunicode.dtx	2017-04-28 21:17:39 UTC (rev 44100)
+++ trunk/Master/texmf-dist/source/latex/babel/bbunicode.dtx	2017-04-28 21:20:36 UTC (rev 44101)
@@ -1,6 +1,6 @@
 % \iffalse meta-comment
 %
-% Copyright 2013-2016 Javier Bezos and any individual authors
+% Copyright 2013-2017 Javier Bezos and any individual authors
 % listed elsewhere in this file.  All rights reserved.
 % 
 % This file is part of the Babel system.
@@ -31,12 +31,12 @@
 % \iffalse
 %<*dtx>
 \ProvidesFile{bbunicode.dtx}
-       [2016/04/23 v3.9r Babel hooks for Unicode engines]
+       [2017/04/28 v3.9t Babel hooks for Unicode engines]
 %</dtx>
 %
 %% File `bbunicode.dtx'
 %% Babel package for LaTeX version 2e
-%% Copyright (C) 2103-2016
+%% Copyright (C) 2103-2017
 %%           by Javier Bezos
 %
 %<*filedriver>

Modified: trunk/Master/texmf-dist/tex/generic/babel/babel.def
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/babel.def	2017-04-28 21:17:39 UTC (rev 44100)
+++ trunk/Master/texmf-dist/tex/generic/babel/babel.def	2017-04-28 21:20:36 UTC (rev 44101)
@@ -38,14 +38,14 @@
 %% and covered by LPPL is defined by the unpacking scripts (with
 %% extension .ins) which are part of the distribution.
 %% File 'babel.dtx'
-%%\ProvidesFile{babel.dtx}[2016/04/23 v3.9r The Babel package]
+%%\ProvidesFile{babel.dtx}[2017/04/28 v3.9t The Babel package]
 %% Babel package for LaTeX2e.
 %% Copyright (C) 1989-2008 by Johannes Braams,
 %%                            TeXniek
 %%                            all rights reserved.
-%% Copyright (C) 2013-2016 by Johannes Braams
+%% Copyright (C) 2013-2017 by Johannes Braams
 %%                            TeXniek
-%%                            by Javier Bezos
+%%                         by Javier Bezos
 %%                            all rights reserved.
 \ifx\ldf at quit\@undefined
 \else
@@ -56,7 +56,7 @@
     \wlog{File: #1 #4 #3 <#2>}%
     \let\ProvidesFile\@undefined}
 \fi
-\ProvidesFile{babel.def}[2016/04/23 3.9r Babel common definitions]
+\ProvidesFile{babel.def}[2017/04/28 3.9t Babel common definitions]
 \ifx\AtBeginDocument\@undefined
   \input plain.def\relax
 \fi
@@ -67,7 +67,7 @@
   \let\bbl at afterlang\relax
   \let\bbl at language@opts\@empty
 \fi
-\def\bbl at tempa{3.9r}%
+\def\bbl at tempa{3.9t}%
 \ifx\bbl at version\bbl at tempa\else
   \input switch.def\relax
 \fi
@@ -97,13 +97,12 @@
     \input luababel.def
   \fi
 \fi
+\def\bbl at stripslash{\expandafter\@gobble\string}
 \def\bbl at add#1#2{%
-  \@ifundefined{\expandafter\@gobble\string#1}%
+  \bbl at ifunset{\bbl at stripslash#1}%
     {\def#1{#2}}%
     {\expandafter\def\expandafter#1\expandafter{#1#2}}}
 \def\bbl at csarg#1#2{\expandafter#1\csname bbl@#2\endcsname}%
-\long\def\bbl at afterelse#1\else#2\fi{\fi#1}
-\long\def\bbl at afterfi#1\fi{\fi#1}
 \def\bbl at loop#1#2#3{\bbl@@loop#1{#3}#2,\@nnil,}
 \def\bbl at loopx#1#2{\expandafter\bbl at loop\expandafter#1\expandafter{#2}}
 \def\bbl@@loop#1#2#3,{%
@@ -111,7 +110,66 @@
     \def#1{#3}#2\bbl at afterfi\bbl@@loop#1{#2}%
   \fi}
 \def\bbl at for#1#2#3{\bbl at loopx#1{#2}{\ifx#1\@empty\else#3\fi}}
-\def\bbl at csarg#1#2{\expandafter#1\csname bbl@#2\endcsname}%
+\def\bbl at add@list#1#2{%
+  \edef#1{%
+    \bbl at ifunset{\bbl at stripslash#1}%
+      {}%
+      {\ifx#1\@empty\else#1,\fi}%
+    #2}}
+\long\def\bbl at afterelse#1\else#2\fi{\fi#1}
+\long\def\bbl at afterfi#1\fi{\fi#1}
+\def\bbl at tempa#1{%
+  \long\def\bbl at trim##1##2{%
+    \futurelet\bbl at trim@a\bbl at trim@c##2\@nil\@nil#1\@nil\relax{##1}}%
+  \def\bbl at trim@c{%
+    \ifx\bbl at trim@a\@sptoken
+      \expandafter\bbl at trim@b
+    \else
+      \expandafter\bbl at trim@b\expandafter#1%
+    \fi}%
+  \long\def\bbl at trim@b#1##1 \@nil{\bbl at trim@i##1}}
+\bbl at tempa{ }
+\long\def\bbl at trim@i#1\@nil#2\relax#3{#3{#1}}
+\long\def\bbl at trim@def#1{\bbl at trim{\def#1}}
+\def\bbl at ifunset#1{%
+  \expandafter\ifx\csname#1\endcsname\relax
+    \expandafter\@firstoftwo
+  \else
+    \expandafter\@secondoftwo
+  \fi}
+\bbl at ifunset{ifcsname}%
+  {}%
+  {\def\bbl at ifunset#1{%
+     \ifcsname#1\endcsname
+       \expandafter\ifx\csname#1\endcsname\relax
+         \bbl at afterelse\expandafter\@firstoftwo
+       \else
+         \bbl at afterfi\expandafter\@secondoftwo
+       \fi
+     \else
+       \expandafter\@firstoftwo
+     \fi}}
+\def\bbl at ifblank#1{%
+  \bbl at ifblank@i#1\@nil\@nil\@secondoftwo\@firstoftwo\@nil}
+\long\def\bbl at ifblank@i#1#2\@nil#3#4#5\@nil{#4}
+\def\bbl at exp#1{%
+  \begingroup
+    \let\\\noexpand
+    \def\<##1>{\expandafter\noexpand\csname##1\endcsname}%
+    \edef\bbl at exp@aux{\endgroup#1}%
+  \bbl at exp@aux}
+\def\bbl at ifsamestring#1#2{%
+  \begingroup
+    \protected at edef\bbl at tempb{#1}%
+    \edef\bbl at tempb{\expandafter\strip at prefix\meaning\bbl at tempb}%
+    \protected at edef\bbl at tempc{#2}%
+    \edef\bbl at tempc{\expandafter\strip at prefix\meaning\bbl at tempc}%
+    \ifx\bbl at tempb\bbl at tempc
+      \aftergroup\@firstoftwo
+    \else
+      \aftergroup\@secondoftwo
+    \fi
+  \endgroup}
 \chardef\bbl at engine=%
   \ifx\directlua\@undefined
     \ifx\XeTeXinputencoding\@undefined
@@ -122,8 +180,6 @@
   \else
     \@ne
   \fi
-\long\def\bbl at afterelse#1\else#2\fi{\fi#1}
-\long\def\bbl at afterfi#1\fi{\fi#1}
 \def\addto#1#2{%
   \ifx#1\@undefined
     \def#1{#2}%
@@ -140,32 +196,28 @@
     \lccode`~=`#2\relax
     \lowercase{\endgroup#1~}}
 \def\bbl at redefine#1{%
-  \edef\bbl at tempa{\expandafter\@gobble\string#1}%
+  \edef\bbl at tempa{\bbl at stripslash#1}%
   \expandafter\let\csname org@\bbl at tempa\endcsname#1%
   \expandafter\def\csname\bbl at tempa\endcsname}
 \@onlypreamble\bbl at redefine
 \def\bbl at redefine@long#1{%
-  \edef\bbl at tempa{\expandafter\@gobble\string#1}%
+  \edef\bbl at tempa{\bbl at stripslash#1}%
   \expandafter\let\csname org@\bbl at tempa\endcsname#1%
   \expandafter\long\expandafter\def\csname\bbl at tempa\endcsname}
 \@onlypreamble\bbl at redefine@long
 \def\bbl at redefinerobust#1{%
-  \edef\bbl at tempa{\expandafter\@gobble\string#1}%
-  \expandafter\ifx\csname\bbl at tempa\space\endcsname\relax
-    \expandafter\let\csname org@\bbl at tempa\endcsname#1%
-    \expandafter\edef\csname\bbl at tempa\endcsname{\noexpand\protect
-      \expandafter\noexpand\csname\bbl at tempa\space\endcsname}%
-  \else
-    \expandafter\let\csname org@\bbl at tempa\expandafter\endcsname
-                    \csname\bbl at tempa\space\endcsname
-  \fi
-  \expandafter\def\csname\bbl at tempa\space\endcsname}
+  \edef\bbl at tempa{\bbl at stripslash#1}%
+  \bbl at ifunset{\bbl at tempa\space}%
+    {\expandafter\let\csname org@\bbl at tempa\endcsname#1%
+     \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}}
 \@onlypreamble\bbl at redefinerobust
 \def\AddBabelHook#1#2{%
-  \@ifundefined{bbl at hk@#1}{\EnableBabelHook{#1}}{}%
+  \bbl at ifunset{bbl at hk@#1}{\EnableBabelHook{#1}}{}%
   \def\bbl at tempa##1,#2=##2,##3\@empty{\def\bbl at tempb{##2}}%
   \expandafter\bbl at tempa\bbl at evargs,#2=,\@empty
-  \@ifundefined{bbl at ev@#1@#2}%
+  \bbl at ifunset{bbl at ev@#1@#2}%
     {\bbl at csarg\bbl at add{ev@#2}{\bbl at elt{#1}}%
      \bbl at csarg\newcommand}%
     {\bbl at csarg\let{ev@#1@#2}\relax
@@ -202,28 +254,27 @@
     \expandafter\bbl at add\expandafter\bbl at tempc\expandafter{%
       \expandafter{\bbl at ens@exclude}}%
     \toks@\expandafter{\bbl at tempc}%
-    \edef\x{%
-      \endgroup
-      \noexpand\@namedef{bbl at e@#2}{\the\toks@{\bbl at ens@fontenc}}}%
-    \x}
+    \bbl at exp{%
+  \endgroup
+  \def\<bbl at e@#2>{\the\toks@{\bbl at ens@fontenc}}}}
 \def\bbl at ensure#1#2#3{%
   \def\bbl at tempb##1{% elt for \bbl at ensured list
     \ifx##1\@empty\else
       \in@{##1}{#2}%
       \ifin@\else
+        \bbl at ifunset{bbl at ensure@\languagename}%
+          {\bbl at exp{%
+            \\\DeclareRobustCommand\<bbl at ensure@\languagename>[1]{%
+              \\\foreignlanguage{\languagename}%
+              {\ifx\relax#3\else
+                \\\fontencoding{#3}\\\selectfont
+               \fi
+               ########1}}}}%
+          {}%
         \toks@\expandafter{##1}%
-        \edef\bbl at tempa{%
-          \noexpand\DeclareRobustCommand
-          \bbl at csarg\noexpand{ensure@\languagename}[1]{%
-            \noexpand\foreignlanguage{\languagename}%
-            {\ifx\relax#3\else
-              \noexpand\fontencoding{#3}\noexpand\selectfont
-             \fi
-             ########1}}}%
-        \bbl at tempa
         \edef##1{%
            \bbl at csarg\noexpand{ensure@\languagename}%
-           {\the\toks@}}
+           {\the\toks@}}%
       \fi
       \expandafter\bbl at tempb
     \fi}%
@@ -289,6 +340,12 @@
   \bbl at patterns{\languagename}}
 \AtBeginDocument{%
   \expandafter\selectlanguage\expandafter{\bbl at main@language}}
+\def\select at language@x#1{%
+  \ifcase\bbl at select@type
+    \bbl at ifsamestring\languagename{#1}{}{\select at language{#1}}%
+  \else
+    \select at language{#1}%
+  \fi}
 \def\bbl at add@special#1{%
   \begingroup
     \def\do{\noexpand\do\noexpand}%
@@ -307,7 +364,7 @@
     \def\@makeother{\x\@makeother}%
   \edef\x{\endgroup
     \def\noexpand\dospecials{\dospecials}%
-    \expandafter\ifx\csname @sanitize\endcsname\relax \else
+    \expandafter\ifx\csname @sanitize\endcsname\relax\else
       \def\noexpand\@sanitize{\@sanitize}%
     \fi}%
   \x}
@@ -325,19 +382,17 @@
       \bbl at afterfi\csname#2 at sh@#1@\string##1@\endcsname
     \fi}}%
 \def\initiate at active@char#1{%
-  \expandafter\ifx\csname active at char\string#1\endcsname\relax
-    \bbl at withactive
-      {\expandafter\@initiate at active@char\expandafter}#1\string#1#1%
-  \fi}
+  \bbl at ifunset{active at char\string#1}%
+    {\bbl at withactive
+      {\expandafter\@initiate at active@char\expandafter}#1\string#1#1}%
+    {}}
 \def\@initiate at active@char#1#2#3{%
-  \expandafter\edef\csname bbl at oricat@#2\endcsname{%
-    \catcode`#2=\the\catcode`#2\relax}%
+  \bbl at csarg\edef{oricat@#2}{\catcode`#2=\the\catcode`#2\relax}%
   \ifx#1\@undefined
-    \expandafter\edef\csname bbl at oridef@#2\endcsname{%
-      \let\noexpand#1\noexpand\@undefined}%
+    \bbl at csarg\edef{oridef@#2}{\let\noexpand#1\noexpand\@undefined}%
   \else
-    \expandafter\let\csname bbl at oridef@@#2\endcsname#1%
-    \expandafter\edef\csname bbl at oridef@#2\endcsname{%
+    \bbl at csarg\let{oridef@@#2}#1%
+    \bbl at csarg\edef{oridef@#2}{%
       \let\noexpand#1%
       \expandafter\noexpand\csname bbl at oridef@@#2\endcsname}%
   \fi
@@ -440,7 +495,7 @@
   \def\bbl at tempa{#3}%
   \ifx\bbl at tempa\@empty
     \expandafter\let\csname #1 at sh@\string#2 at sel\endcsname\bbl at scndcs
-    \@ifundefined{#1 at sh@\string#2@}{}%
+    \bbl at ifunset{#1 at sh@\string#2@}{}%
       {\def\bbl at tempa{#4}%
        \expandafter\ifx\csname#1 at sh@\string#2@\endcsname\bbl at tempa
        \else
@@ -451,7 +506,7 @@
     \@namedef{#1 at sh@\string#2@}{#4}%
   \else
     \expandafter\let\csname #1 at sh@\string#2 at sel\endcsname\bbl at firstcs
-    \@ifundefined{#1 at sh@\string#2@\string#3@}{}%
+    \bbl at ifunset{#1 at sh@\string#2@\string#3@}{}%
       {\def\bbl at tempa{#4}%
        \expandafter\ifx\csname#1 at sh@\string#2@\string#3@\endcsname\bbl at tempa
        \else
@@ -488,7 +543,7 @@
         turned off in the package options}}}
 \def\user at language@group{user@\language at group}
 \def\bbl at set@user at generic#1#2{%
-  \@ifundefined{user at generic@active#1}%
+  \bbl at ifunset{user at generic@active#1}%
     {\bbl at active@def#1\user at language@group{user at active}{user at generic@active}%
      \bbl at active@def#1\user at group{user at generic@active}{language at active}%
      \expandafter\edef\csname#2 at sh@#1@@\endcsname{%
@@ -537,7 +592,7 @@
 \def\bbl at shorthandoff#1#2{\bbl at switch@sh#1#2\@nnil}
 \def\bbl at switch@sh#1#2{%
   \ifx#2\@nnil\else
-    \@ifundefined{bbl at active@\string#2}%
+    \bbl at ifunset{bbl at active@\string#2}%
       {\bbl at error
          {I cannot switch `\string#2' on or off--not a shorthand}%
          {This character is not a shorthand. Maybe you made\\%
@@ -554,7 +609,7 @@
   \fi}
 \def\babelshorthand{\active at prefix\babelshorthand\bbl at putsh}
 \def\bbl at putsh#1{%
-  \@ifundefined{bbl at active@\string#1}%
+  \bbl at ifunset{bbl at active@\string#1}%
      {\bbl at putsh@i#1\@empty\@nnil}%
      {\csname bbl at active@\string#1\endcsname}}
 \def\bbl at putsh@i#1#2\@nnil{%
@@ -652,17 +707,6 @@
     \bbl at afterfi#4%
   \fi
   }
-\def\bbl at add@list#1#2{%
-  \ifx#1\@undefined
-    \def#1{#2}%
-  \else
-    \ifx#1\@empty
-      \def#1{#2}%
-    \else
-      \edef#1{#1,#2}%
-    \fi
-  \fi
-  }
 \def\bbl at ifknown@ttrib#1#2{%
   \let\bbl at tempa\@secondoftwo
   \bbl at loopx\bbl at tempb{#2}{%
@@ -679,8 +723,7 @@
       \expandafter\bbl at clear@ttrib\bbl at tempa.
       }%
     \let\bbl at attributes\@undefined
-  \fi
-  }
+  \fi}
 \def\bbl at clear@ttrib#1-#2.{%
   \expandafter\let\csname#1 at attr@#2\endcsname\@undefined}
 \AtBeginDocument{\bbl at clear@ttribs}
@@ -743,7 +786,7 @@
         \bbl at fixname\bbl at tempa
         \bbl at iflanguage\bbl at tempa{%
           \bbl at csarg\protected at edef{hyphenation@\bbl at tempa}{%
-            \@ifundefined{bbl at hyphenation@\bbl at tempa}%
+            \bbl at ifunset{bbl at hyphenation@\bbl at tempa}%
               \@empty
               {\csname bbl at hyphenation@\bbl at tempa\endcsname\space}%
             #2}}}%
@@ -756,13 +799,13 @@
 \def\bbl at hyphen{%
   \@ifstar{\bbl at hyphen@i @}{\bbl at hyphen@i\@empty}}
 \def\bbl at hyphen@i#1#2{%
-  \@ifundefined{bbl at hy@#1#2\@empty}%
+  \bbl at ifunset{bbl at hy@#1#2\@empty}%
     {\csname bbl@#1usehyphen\endcsname{\discretionary{#2}{}{#2}}}%
     {\csname bbl at hy@#1#2\@empty\endcsname}}
 \def\bbl at usehyphen#1{%
   \leavevmode
-  \ifdim\lastskip>\z@\mbox{#1}\nobreak\else\nobreak#1\fi
-  \hskip\z at skip}
+  \ifdim\lastskip>\z@\mbox{#1}\else\nobreak#1\fi
+  \nobreak\hskip\z at skip}
 \def\bbl@@usehyphen#1{%
   \leavevmode\ifdim\lastskip>\z@\mbox{#1}\else#1\fi}
 \def\bbl at hyphenchar{%
@@ -775,12 +818,11 @@
 \def\bbl at hy@@soft{\bbl@@usehyphen{\discretionary{\bbl at hyphenchar}{}{}}}
 \def\bbl at hy@hard{\bbl at usehyphen\bbl at hyphenchar}
 \def\bbl at hy@@hard{\bbl@@usehyphen\bbl at hyphenchar}
-\def\bbl at hy@nobreak{\bbl at usehyphen{\mbox{\bbl at hyphenchar}\nobreak}}
+\def\bbl at hy@nobreak{\bbl at usehyphen{\mbox{\bbl at hyphenchar}}}
 \def\bbl at hy@@nobreak{\mbox{\bbl at hyphenchar}}
 \def\bbl at hy@repeat{%
   \bbl at usehyphen{%
-    \discretionary{\bbl at hyphenchar}{\bbl at hyphenchar}{\bbl at hyphenchar}%
-    \nobreak}}
+    \discretionary{\bbl at hyphenchar}{\bbl at hyphenchar}{\bbl at hyphenchar}}}
 \def\bbl at hy@@repeat{%
   \bbl@@usehyphen{%
     \discretionary{\bbl at hyphenchar}{\bbl at hyphenchar}{\bbl at hyphenchar}}}
@@ -804,7 +846,7 @@
     \g at addto@macro\@uclclist{\reserved at b{\reserved at b\bbl at uclc}}%
     \gdef\bbl at uclc##1{%
       \let\bbl at encoded\bbl at encoded@uclc
-      \@ifundefined{\languagename @bbl at uclc}% and resumes it
+      \bbl at ifunset{\languagename @bbl at uclc}% and resumes it
         {##1}%
         {\let\bbl at tempa##1\relax % Used by LANG at bbl@uclc
          \csname\languagename @bbl at uclc\endcsname}%
@@ -818,7 +860,7 @@
   \def\SetStringLoop##1##2{%
     \def\bbl at templ####1{\expandafter\noexpand\csname##1\endcsname}%
     \count@\z@
-    \bbl at loop\bbl at tempa{##2}{%
+    \bbl at loop\bbl at tempa{##2}{% empty items and spaces are ok
       \advance\count@\@ne
       \toks@\expandafter{\bbl at tempa}%
       \edef\bbl at tempb{%
@@ -890,7 +932,7 @@
     \edef\bbl at sc@charset{\expandafter\zap at space\bbl at sc@charset\@empty}%
     \def\bbl at encstring##1##2{%
       \bbl at for\bbl at tempc\bbl at sc@fontenc{%
-        \@ifundefined{T@\bbl at tempc}%
+        \bbl at ifunset{T@\bbl at tempc}%
           {}%
           {\ProvideTextCommand##1\bbl at tempc{##2}%
            \bbl at toglobal##1%
@@ -920,7 +962,6 @@
          captions or extras, but you set none}}%
   \fi
   \ifx\@empty#1%
-    \@expandtwoargs
     \bbl at usehooks{defaultcommands}{}%
   \else
     \@expandtwoargs
@@ -943,7 +984,7 @@
       \fi
     \fi}}
 \AtEndOfPackage{%
-  \def\bbl at forlang#1#2{\bbl at for#1\bbl at L{\@ifundefined{date#1}{}{#2}}}%
+  \def\bbl at forlang#1#2{\bbl at for#1\bbl at L{\bbl at ifunset{date#1}{}{#2}}}%
   \let\bbl at scswitch\relax}
 \@onlypreamble\EndBabelCommands
 \def\EndBabelCommands{%
@@ -953,8 +994,8 @@
   \bbl at scafter}
 \def\bbl at setstring#1#2{%
   \bbl at forlang\bbl at tempa{%
-    \edef\bbl at LC{\bbl at tempa\expandafter\@gobble\string#1}%
-    \@ifundefined{\bbl at LC}% eg, \germanchaptername
+    \edef\bbl at LC{\bbl at tempa\bbl at stripslash#1}%
+    \bbl at ifunset{\bbl at LC}% eg, \germanchaptername
       {\global\expandafter
        \bbl at add\csname\bbl at G\bbl at tempa\expandafter\endcsname\expandafter
          {\expandafter\bbl at scset\expandafter#1\csname\bbl at LC\endcsname}}%
@@ -1202,7 +1243,7 @@
 \ifx\bbl at opt@safe\@empty\else
   \def\@newl at bel#1#2#3{%
    {\@safe at activestrue
-    \@ifundefined{#1@#2}%
+    \bbl at ifunset{#1@#2}%
        \relax
        {\gdef\@multiplelabels{%
           \@latex at warning@no at line{There were multiply-defined labels}}%
@@ -1277,19 +1318,12 @@
   \let\org@@bibitem\@bibitem
 \fi
 \bbl at redefine\markright#1{%
-  \edef\bbl at tempb{\noexpand\protect
-    \noexpand\foreignlanguage{\languagename}}%
-  \def\bbl at arg{#1}%
-  \ifx\bbl at arg\@empty
-    \toks@{}%
-  \else
-    \expandafter\toks@\expandafter{%
-             \bbl at tempb{\protect\bbl at restore@actives#1}}%
-  \fi
-  \edef\bbl at tempa{%
-    \noexpand\org at markright{\the\toks@}}%
-  \bbl at tempa
-}
+  \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
@@ -1296,26 +1330,15 @@
   \def\bbl at tempc{}
 \fi
 \bbl at redefine\markboth#1#2{%
-  \edef\bbl at tempb{\noexpand\protect
-    \noexpand\foreignlanguage{\languagename}}%
-  \def\bbl at arg{#1}%
-  \ifx\bbl at arg\@empty
-    \toks@{}%
-  \else
-   \expandafter\toks@\expandafter{%
-             \bbl at tempb{\protect\bbl at restore@actives#1}}%
-  \fi
-  \def\bbl at arg{#2}%
-  \ifx\bbl at arg\@empty
-    \toks8{}%
-  \else
-    \expandafter\toks8\expandafter{%
-             \bbl at tempb{\protect\bbl at restore@actives#2}}%
-  \fi
-  \edef\bbl at tempa{%
-    \noexpand\org at markboth{\the\toks@}{\the\toks8}}%
-  \bbl at tempa
-}
+  \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
 \@expandtwoargs\in@{R}\bbl at opt@safe
 \ifin@
@@ -1327,15 +1350,15 @@
         \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}%
+        \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}%
         }%
       }{}%
     }
@@ -1364,12 +1387,9 @@
        \fi}%
       {}}}
 \AtBeginDocument{%
-  \@ifundefined{pdfstringdefDisableCommands}%
-    {}%
-    {\pdfstringdefDisableCommands{%
-       \languageshorthands{system}}%
-    }%
-}
+  \ifx\pdfstringdefDisableCommands\@undefined\else
+    \pdfstringdefDisableCommands{\languageshorthands{system}}%
+  \fi}
 \DeclareRobustCommand{\FOREIGNLANGUAGE}[1]{%
   \lowercase{\foreignlanguage{#1}}}
 \def\substitutefontfamily#1#2#3{%
@@ -1409,7 +1429,7 @@
     \def\bbl at tempb#1\@@{\uppercase{\bbl at tempc#1}ENC.DEF\@empty\@@}%
     \def\bbl at tempc#1ENC.DEF#2\@@{%
       \ifx\@empty#2\else
-        \@ifundefined{T@#1}%
+        \bbl at ifunset{T@#1}%
           {}%
           {\@expandtwoargs\in@{,#1,}{,\BabelNonASCII,}%
            \ifin@
@@ -1430,9 +1450,11 @@
 \AtBeginDocument{%
   \@ifpackageloaded{fontspec}%
     {\xdef\latinencoding{%
-       \@ifundefined{UTFencname}%
-         {EU\ifcase\bbl at engine\or2\or1\fi}%
-         {\UTFencname}}}%
+       \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}%

Modified: trunk/Master/texmf-dist/tex/generic/babel/babel.sty
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/babel.sty	2017-04-28 21:17:39 UTC (rev 44100)
+++ trunk/Master/texmf-dist/tex/generic/babel/babel.sty	2017-04-28 21:20:36 UTC (rev 44101)
@@ -38,20 +38,20 @@
 %% and covered by LPPL is defined by the unpacking scripts (with
 %% extension .ins) which are part of the distribution.
 %% File 'babel.dtx'
-%%\ProvidesFile{babel.dtx}[2016/04/23 v3.9r The Babel package]
+%%\ProvidesFile{babel.dtx}[2017/04/28 v3.9t The Babel package]
 %% Babel package for LaTeX2e.
 %% Copyright (C) 1989-2008 by Johannes Braams,
 %%                            TeXniek
 %%                            all rights reserved.
-%% Copyright (C) 2013-2016 by Johannes Braams
+%% Copyright (C) 2013-2017 by Johannes Braams
 %%                            TeXniek
-%%                            by Javier Bezos
+%%                         by Javier Bezos
 %%                            all rights reserved.
 \NeedsTeXFormat{LaTeX2e}[2005/12/01]
-\ProvidesPackage{babel}[2016/04/23 3.9r The Babel package]
+\ProvidesPackage{babel}[2017/04/28 3.9t The Babel package]
 \@ifpackagewith{babel}{debug}
  {\input switch.def\relax}
- {\def\bbl at tempa{3.9r}%
+ {\def\bbl at tempa{3.9t}%
 \ifx\bbl at version\bbl at tempa\else
   \input switch.def\relax
 \fi}
@@ -60,13 +60,12 @@
     \input luababel.def
   \fi
 \fi
+\def\bbl at stripslash{\expandafter\@gobble\string}
 \def\bbl at add#1#2{%
-  \@ifundefined{\expandafter\@gobble\string#1}%
+  \bbl at ifunset{\bbl at stripslash#1}%
     {\def#1{#2}}%
     {\expandafter\def\expandafter#1\expandafter{#1#2}}}
 \def\bbl at csarg#1#2{\expandafter#1\csname bbl@#2\endcsname}%
-\long\def\bbl at afterelse#1\else#2\fi{\fi#1}
-\long\def\bbl at afterfi#1\fi{\fi#1}
 \def\bbl at loop#1#2#3{\bbl@@loop#1{#3}#2,\@nnil,}
 \def\bbl at loopx#1#2{\expandafter\bbl at loop\expandafter#1\expandafter{#2}}
 \def\bbl@@loop#1#2#3,{%
@@ -74,6 +73,76 @@
     \def#1{#3}#2\bbl at afterfi\bbl@@loop#1{#2}%
   \fi}
 \def\bbl at for#1#2#3{\bbl at loopx#1{#2}{\ifx#1\@empty\else#3\fi}}
+\def\bbl at add@list#1#2{%
+  \edef#1{%
+    \bbl at ifunset{\bbl at stripslash#1}%
+      {}%
+      {\ifx#1\@empty\else#1,\fi}%
+    #2}}
+\long\def\bbl at afterelse#1\else#2\fi{\fi#1}
+\long\def\bbl at afterfi#1\fi{\fi#1}
+\def\bbl at tempa#1{%
+  \long\def\bbl at trim##1##2{%
+    \futurelet\bbl at trim@a\bbl at trim@c##2\@nil\@nil#1\@nil\relax{##1}}%
+  \def\bbl at trim@c{%
+    \ifx\bbl at trim@a\@sptoken
+      \expandafter\bbl at trim@b
+    \else
+      \expandafter\bbl at trim@b\expandafter#1%
+    \fi}%
+  \long\def\bbl at trim@b#1##1 \@nil{\bbl at trim@i##1}}
+\bbl at tempa{ }
+\long\def\bbl at trim@i#1\@nil#2\relax#3{#3{#1}}
+\long\def\bbl at trim@def#1{\bbl at trim{\def#1}}
+\def\bbl at ifunset#1{%
+  \expandafter\ifx\csname#1\endcsname\relax
+    \expandafter\@firstoftwo
+  \else
+    \expandafter\@secondoftwo
+  \fi}
+\bbl at ifunset{ifcsname}%
+  {}%
+  {\def\bbl at ifunset#1{%
+     \ifcsname#1\endcsname
+       \expandafter\ifx\csname#1\endcsname\relax
+         \bbl at afterelse\expandafter\@firstoftwo
+       \else
+         \bbl at afterfi\expandafter\@secondoftwo
+       \fi
+     \else
+       \expandafter\@firstoftwo
+     \fi}}
+\def\bbl at ifblank#1{%
+  \bbl at ifblank@i#1\@nil\@nil\@secondoftwo\@firstoftwo\@nil}
+\long\def\bbl at ifblank@i#1#2\@nil#3#4#5\@nil{#4}
+\def\bbl at exp#1{%
+  \begingroup
+    \let\\\noexpand
+    \def\<##1>{\expandafter\noexpand\csname##1\endcsname}%
+    \edef\bbl at exp@aux{\endgroup#1}%
+  \bbl at exp@aux}
+\def\bbl at ifsamestring#1#2{%
+  \begingroup
+    \protected at edef\bbl at tempb{#1}%
+    \edef\bbl at tempb{\expandafter\strip at prefix\meaning\bbl at tempb}%
+    \protected at edef\bbl at tempc{#2}%
+    \edef\bbl at tempc{\expandafter\strip at prefix\meaning\bbl at tempc}%
+    \ifx\bbl at tempb\bbl at tempc
+      \aftergroup\@firstoftwo
+    \else
+      \aftergroup\@secondoftwo
+    \fi
+  \endgroup}
+\chardef\bbl at engine=%
+  \ifx\directlua\@undefined
+    \ifx\XeTeXinputencoding\@undefined
+      \z@
+    \else
+      \tw@
+    \fi
+  \else
+    \@ne
+  \fi
 \def\AfterBabelLanguage#1{%
   \global\expandafter\bbl at add\csname#1.ldf-h@@k\endcsname}%
 \ifx\bbl at languages\@undefined\else
@@ -154,8 +223,8 @@
 \let\bbl at opt@main\@nnil
 \let\bbl at opt@headfoot\@nnil
 \def\bbl at tempa#1=#2\bbl at tempa{%
-  \expandafter\ifx\csname bbl at opt@#1\endcsname\@nnil
-    \expandafter\edef\csname bbl at opt@#1\endcsname{#2}%
+  \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\\%
@@ -169,9 +238,7 @@
   \ifin@
     \expandafter\bbl at tempa\CurrentOption\bbl at tempa
   \else
-    \edef\bbl at language@opts{%
-      \ifx\bbl at language@opts\@empty\else\bbl at language@opts,\fi
-      \CurrentOption}%
+    \bbl at add@list\bbl at language@opts{\CurrentOption}%
   \fi}
 \ProcessOptions*
 \def\bbl at sh@string#1{%
@@ -207,7 +274,9 @@
     \expandafter\select at language@x\expandafter{\bbl at opt@headfoot}%
     \let\protect\noexpand}
 \fi
-\@ifundefined{bbl at opt@safe}{\def\bbl at opt@safe{BR}}{}
+\ifx\bbl at opt@safe\@undefined
+  \def\bbl at opt@safe{BR}
+\fi
 \ifx\bbl at opt@main\@nnil\else
   \edef\bbl at language@opts{%
     \ifx\bbl at language@opts\@empty\else\bbl at language@opts,\fi
@@ -232,15 +301,8 @@
        headfoot=, strings=, config=, hyphenmap=, or a language name.}}}
 \DeclareOption{acadian}{\bbl at load@language{frenchb}}
 \DeclareOption{afrikaans}{\bbl at load@language{dutch}}
-\DeclareOption{american}{\bbl at load@language{english}}
-\DeclareOption{australian}{\bbl at load@language{english}}
-\DeclareOption{bahasa}{\bbl at load@language{bahasai}}
-\DeclareOption{bahasai}{\bbl at load@language{bahasai}}
-\DeclareOption{bahasam}{\bbl at load@language{bahasam}}
 \DeclareOption{brazil}{\bbl at load@language{portuges}}
 \DeclareOption{brazilian}{\bbl at load@language{portuges}}
-\DeclareOption{british}{\bbl at load@language{english}}
-\DeclareOption{canadian}{\bbl at load@language{english}}
 \DeclareOption{canadien}{\bbl at load@language{frenchb}}
 \DeclareOption{francais}{\bbl at load@language{frenchb}}
 \DeclareOption{french}{\bbl at load@language{frenchb}}%
@@ -248,13 +310,7 @@
   \input{rlbabel.def}%
   \bbl at load@language{hebrew}}
 \DeclareOption{hungarian}{\bbl at load@language{magyar}}
-\DeclareOption{indon}{\bbl at load@language{bahasai}}
-\DeclareOption{indonesian}{\bbl at load@language{bahasai}}
 \DeclareOption{lowersorbian}{\bbl at load@language{lsorbian}}
-\DeclareOption{malay}{\bbl at load@language{bahasam}}
-\DeclareOption{meyalu}{\bbl at load@language{bahasam}}
-\DeclareOption{melayu}{\bbl at load@language{bahasam}}
-\DeclareOption{newzealand}{\bbl at load@language{english}}
 \DeclareOption{nynorsk}{\bbl at load@language{norsk}}
 \DeclareOption{polutonikogreek}{%
   \bbl at load@language{greek}%
@@ -261,10 +317,8 @@
   \languageattribute{greek}{polutoniko}}
 \DeclareOption{portuguese}{\bbl at load@language{portuges}}
 \DeclareOption{russian}{\bbl at load@language{russianb}}
-\DeclareOption{UKenglish}{\bbl at load@language{english}}
 \DeclareOption{ukrainian}{\bbl at load@language{ukraineb}}
 \DeclareOption{uppersorbian}{\bbl at load@language{usorbian}}
-\DeclareOption{USenglish}{\bbl at load@language{english}}
 \ifx\bbl at opt@config\@nnil
   \@ifpackagewith{babel}{noconfigs}{}%
     {\InputIfFileExists{bblopts.cfg}%
@@ -282,7 +336,7 @@
        Perhaps you misspelled it.}}%
 \fi
 \bbl at for\bbl at tempa\bbl at language@opts{%
-  \@ifundefined{ds@\bbl at tempa}%
+  \bbl at ifunset{ds@\bbl at tempa}%
     {\edef\bbl at tempb{%
        \noexpand\DeclareOption
          {\bbl at tempa}%
@@ -290,7 +344,7 @@
      \bbl at tempb}%
      \@empty}
 \bbl at for\bbl at tempa\@classoptionslist{%
-  \@ifundefined{ds@\bbl at tempa}%
+  \bbl at ifunset{ds@\bbl at tempa}%
     {\IfFileExists{\bbl at tempa.ldf}%
       {\edef\bbl at tempb{%
          \noexpand\DeclareOption

Modified: trunk/Master/texmf-dist/tex/generic/babel/blplain.tex
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/blplain.tex	2017-04-28 21:17:39 UTC (rev 44100)
+++ trunk/Master/texmf-dist/tex/generic/babel/blplain.tex	2017-04-28 21:20:36 UTC (rev 44101)
@@ -38,14 +38,14 @@
 %% and covered by LPPL is defined by the unpacking scripts (with
 %% extension .ins) which are part of the distribution.
 %% File 'babel.dtx'
-%%\ProvidesFile{babel.dtx}[2016/04/23 v3.9r The Babel package]
+%%\ProvidesFile{babel.dtx}[2017/04/28 v3.9t The Babel package]
 %% Babel package for LaTeX2e.
 %% Copyright (C) 1989-2008 by Johannes Braams,
 %%                            TeXniek
 %%                            all rights reserved.
-%% Copyright (C) 2013-2016 by Johannes Braams
+%% Copyright (C) 2013-2017 by Johannes Braams
 %%                            TeXniek
-%%                            by Javier Bezos
+%%                         by Javier Bezos
 %%                            all rights reserved.
 \catcode`\{=1 % left brace is begin-group character
 \catcode`\}=2 % right brace is end-group character

Modified: trunk/Master/texmf-dist/tex/generic/babel/bplain.tex
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/bplain.tex	2017-04-28 21:17:39 UTC (rev 44100)
+++ trunk/Master/texmf-dist/tex/generic/babel/bplain.tex	2017-04-28 21:20:36 UTC (rev 44101)
@@ -38,14 +38,14 @@
 %% and covered by LPPL is defined by the unpacking scripts (with
 %% extension .ins) which are part of the distribution.
 %% File 'babel.dtx'
-%%\ProvidesFile{babel.dtx}[2016/04/23 v3.9r The Babel package]
+%%\ProvidesFile{babel.dtx}[2017/04/28 v3.9t The Babel package]
 %% Babel package for LaTeX2e.
 %% Copyright (C) 1989-2008 by Johannes Braams,
 %%                            TeXniek
 %%                            all rights reserved.
-%% Copyright (C) 2013-2016 by Johannes Braams
+%% Copyright (C) 2013-2017 by Johannes Braams
 %%                            TeXniek
-%%                            by Javier Bezos
+%%                         by Javier Bezos
 %%                            all rights reserved.
 \catcode`\{=1 % left brace is begin-group character
 \catcode`\}=2 % right brace is end-group character

Modified: trunk/Master/texmf-dist/tex/generic/babel/hyphen.cfg
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/hyphen.cfg	2017-04-28 21:17:39 UTC (rev 44100)
+++ trunk/Master/texmf-dist/tex/generic/babel/hyphen.cfg	2017-04-28 21:20:36 UTC (rev 44101)
@@ -38,14 +38,14 @@
 %% and covered by LPPL is defined by the unpacking scripts (with
 %% extension .ins) which are part of the distribution.
 %% File 'babel.dtx'
-%%\ProvidesFile{babel.dtx}[2016/04/23 v3.9r The Babel package]
+%%\ProvidesFile{babel.dtx}[2017/04/28 v3.9t The Babel package]
 %% Babel package for LaTeX2e.
 %% Copyright (C) 1989-2008 by Johannes Braams,
 %%                            TeXniek
 %%                            all rights reserved.
-%% Copyright (C) 2013-2016 by Johannes Braams
+%% Copyright (C) 2013-2017 by Johannes Braams
 %%                            TeXniek
-%%                            by Javier Bezos
+%%                         by Javier Bezos
 %%                            all rights reserved.
 \ifx\ProvidesFile\@undefined
   \def\ProvidesFile#1[#2 #3 #4]{%
@@ -52,7 +52,7 @@
     \wlog{File: #1 #4 #3 <#2>}%
     \let\ProvidesFile\@undefined}
 \fi
-\ProvidesFile{hyphen.cfg}[2016/04/23 3.9r Babel hyphens]
+\ProvidesFile{hyphen.cfg}[2017/04/28 3.9t Babel hyphens]
 \xdef\bbl at format{\jobname}
 \ifx\AtBeginDocument\@undefined
   \def\@empty{}
@@ -75,7 +75,7 @@
     \global\advance\last at language\@ne
     \ifnum\last at language<\@cclvi
     \else
-        \errmessage{No room for a new \string\language!}%
+      \errmessage{No room for a new \string\language!}%
     \fi
     \global\chardef#1\last at language
     \wlog{\string#1 = \string\language\the\last at language}}
@@ -83,7 +83,7 @@
   \countdef\last at language=19
   \def\addlanguage{\alloc at 9\language\chardef\@cclvi}
 \fi
-\toks8{Babel <3.9r> and hyphenation patterns for }%
+\toks8{Babel <3.9t> and hyphenation patterns for }%
 \def\process at line#1#2 #3 #4 {%
   \ifx=#1%
     \process at synonym{#2}%

Modified: trunk/Master/texmf-dist/tex/generic/babel/luababel.def
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/luababel.def	2017-04-28 21:17:39 UTC (rev 44100)
+++ trunk/Master/texmf-dist/tex/generic/babel/luababel.def	2017-04-28 21:20:36 UTC (rev 44101)
@@ -39,7 +39,7 @@
 %% extension .ins) which are part of the distribution.
 %% File `bbunicode.dtx'
 %% Babel package for LaTeX version 2e
-%% Copyright (C) 2103-2016
+%% Copyright (C) 2103-2017
 %%           by Javier Bezos
 \ifx\AddBabelHook\@undefined
 \begingroup

Modified: trunk/Master/texmf-dist/tex/generic/babel/nil.ldf
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/nil.ldf	2017-04-28 21:17:39 UTC (rev 44100)
+++ trunk/Master/texmf-dist/tex/generic/babel/nil.ldf	2017-04-28 21:20:36 UTC (rev 44101)
@@ -38,16 +38,16 @@
 %% and covered by LPPL is defined by the unpacking scripts (with
 %% extension .ins) which are part of the distribution.
 %% File 'babel.dtx'
-%%\ProvidesFile{babel.dtx}[2016/04/23 v3.9r The Babel package]
+%%\ProvidesFile{babel.dtx}[2017/04/28 v3.9t The Babel package]
 %% Babel package for LaTeX2e.
 %% Copyright (C) 1989-2008 by Johannes Braams,
 %%                            TeXniek
 %%                            all rights reserved.
-%% Copyright (C) 2013-2016 by Johannes Braams
+%% Copyright (C) 2013-2017 by Johannes Braams
 %%                            TeXniek
-%%                            by Javier Bezos
+%%                         by Javier Bezos
 %%                            all rights reserved.
-\ProvidesLanguage{nil}[2016/04/23 3.9r Nil language]
+\ProvidesLanguage{nil}[2017/04/28 3.9t Nil language]
 \LdfInit{nil}{datenil}
 \ifx\l at nohyphenation\@undefined
    \@nopatterns{nil}

Modified: trunk/Master/texmf-dist/tex/generic/babel/plain.def
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/plain.def	2017-04-28 21:17:39 UTC (rev 44100)
+++ trunk/Master/texmf-dist/tex/generic/babel/plain.def	2017-04-28 21:20:36 UTC (rev 44101)
@@ -38,14 +38,14 @@
 %% and covered by LPPL is defined by the unpacking scripts (with
 %% extension .ins) which are part of the distribution.
 %% File 'babel.dtx'
-%%\ProvidesFile{babel.dtx}[2016/04/23 v3.9r The Babel package]
+%%\ProvidesFile{babel.dtx}[2017/04/28 v3.9t The Babel package]
 %% Babel package for LaTeX2e.
 %% Copyright (C) 1989-2008 by Johannes Braams,
 %%                            TeXniek
 %%                            all rights reserved.
-%% Copyright (C) 2013-2016 by Johannes Braams
+%% Copyright (C) 2013-2017 by Johannes Braams
 %%                            TeXniek
-%%                            by Javier Bezos
+%%                         by Javier Bezos
 %%                            all rights reserved.
 \def\@empty{}
 \def\loadlocalcfg#1{%
@@ -171,11 +171,9 @@
          \noexpand#1%
       \fi
       \noexpand\protect
-      \expandafter\noexpand\csname
-         \expandafter\@gobble\string#1 \endcsname
+      \expandafter\noexpand\csname\bbl at stripslash#1 \endcsname
    }%
-   \expandafter\new at command\csname
-      \expandafter\@gobble\string#1 \endcsname
+   \expandafter\new at command\csname\bbl at stripslash#1 \endcsname
 }
 \def\x at protect#1{%
    \ifx\protect\@typeset at protect\else

Modified: trunk/Master/texmf-dist/tex/generic/babel/switch.def
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/switch.def	2017-04-28 21:17:39 UTC (rev 44100)
+++ trunk/Master/texmf-dist/tex/generic/babel/switch.def	2017-04-28 21:20:36 UTC (rev 44101)
@@ -38,14 +38,14 @@
 %% and covered by LPPL is defined by the unpacking scripts (with
 %% extension .ins) which are part of the distribution.
 %% File 'babel.dtx'
-%%\ProvidesFile{babel.dtx}[2016/04/23 v3.9r The Babel package]
+%%\ProvidesFile{babel.dtx}[2017/04/28 v3.9t The Babel package]
 %% Babel package for LaTeX2e.
 %% Copyright (C) 1989-2008 by Johannes Braams,
 %%                            TeXniek
 %%                            all rights reserved.
-%% Copyright (C) 2013-2016 by Johannes Braams
+%% Copyright (C) 2013-2017 by Johannes Braams
 %%                            TeXniek
-%%                            by Javier Bezos
+%%                         by Javier Bezos
 %%                            all rights reserved.
 \ifx\ProvidesFile\@undefined
   \def\ProvidesFile#1[#2 #3 #4]{%
@@ -52,7 +52,7 @@
     \wlog{File: #1 #4 #3 <#2>}%
     \let\ProvidesFile\@undefined}
 \fi
-\ProvidesFile{switch.def}[2016/04/23 3.9r Babel switching mechanism]
+\ProvidesFile{switch.def}[2017/04/28 3.9t Babel switching mechanism]
 \ifx\AtBeginDocument\@undefined
   \input plain.def\relax
 \fi
@@ -65,7 +65,7 @@
     \global\advance\last at language\@ne
     \ifnum\last at language<\@cclvi
     \else
-        \errmessage{No room for a new \string\language!}%
+      \errmessage{No room for a new \string\language!}%
     \fi
     \global\chardef#1\last at language
     \wlog{\string#1 = \string\language\the\last at language}}
@@ -73,8 +73,8 @@
   \countdef\last at language=19
   \def\addlanguage{\alloc at 9\language\chardef\@cclvi}
 \fi
-\def\bbl at version{3.9r}
-\def\bbl at date{2016/04/23}
+\def\bbl at version{3.9t}
+\def\bbl at date{2017/04/28}
 \def\adddialect#1#2{%
   \global\chardef#1#2\relax
   \bbl at usehooks{adddialect}{{#1}{#2}}%
@@ -151,17 +151,12 @@
          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}%
-        {You may proceed, but expect unexpected results}%
+        {You may proceed, but expect wrong results}%
     \else
       \let\bbl at select@type\z@
       \expandafter\bbl at switch\expandafter{\languagename}%
     \fi}}
-\def\select at language@x#1{%
-  \ifcase\bbl at select@type
-    \bbl at ifsamestring\languagename{#1}{}{\select at language{#1}}%
-  \else
-    \select at language{#1}%
-  \fi}
+\let\select at language@x\select at language
 \def\bbl at switch#1{%
   \originalTeX
   \expandafter\def\expandafter\originalTeX\expandafter{%
@@ -171,8 +166,8 @@
   \bbl at usehooks{afterreset}{}%
   \languageshorthands{none}%
   \ifcase\bbl at select@type
-    \csname captions#1\endcsname
-    \csname date#1\endcsname
+    \csname captions#1\endcsname\relax
+    \csname date#1\endcsname\relax
   \fi
   \bbl at usehooks{beforeextras}{}%
   \csname extras#1\endcsname\relax
@@ -198,16 +193,6 @@
     \expandafter\expandafter\expandafter\set at hyphenmins
       \csname #1hyphenmins\endcsname\relax
   \fi}
-\def\bbl at ifsamestring#1#2{%
-  \protected at edef\bbl at tempb{#1}%
-  \edef\bbl at tempb{\expandafter\strip at prefix\meaning\bbl at tempb}%
-  \protected at edef\bbl at tempc{#2}%
-  \edef\bbl at tempc{\expandafter\strip at prefix\meaning\bbl at tempc}%
-  \ifx\bbl at tempb\bbl at tempc
-    \expandafter\@firstoftwo
-  \else
-    \expandafter\@secondoftwo
-  \fi}
 \long\def\otherlanguage#1{%
   \ifnum\bbl at hymapsel=\@cclv\let\bbl at hymapsel\thr@@\fi
   \csname selectlanguage \endcsname{#1}%
@@ -232,8 +217,11 @@
   \bbl at iflanguage\languagename{%
     \expandafter\ifx\csname date\languagename\endcsname\relax
       \bbl at warning
-        {You haven't loaded the language \languagename\space yet\\%
-         I'll proceed, but expect unexpected results.\\%
+        {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.\\%
+         I'll proceed, but expect wrong results.\\%
          Reported}%
     \fi
     \let\bbl at select@type\@ne
@@ -250,9 +238,9 @@
     \else
       \csname l@#1:\f at encoding\endcsname
       \edef\bbl at tempa{#1:\f at encoding}%
-    \fi\relax
+    \fi
   \@expandtwoargs\bbl at usehooks{patterns}{{#1}{\bbl at tempa}}%
-  \@ifundefined{bbl at hyphenation@}{}{%
+  \@ifundefined{bbl at hyphenation@}{}{% Can be \relax!
     \begingroup
       \@expandtwoargs\in@{,\number\language,}{,\bbl at hyphlist}%
       \ifin@\else
@@ -307,6 +295,16 @@
   \LdfInit}
 \ifx\originalTeX\@undefined\let\originalTeX\@empty\fi
 \ifx\babel at beginsave\@undefined\let\babel at beginsave\relax\fi
+\newcommand\setlocale{%
+  \bbl at error
+    {Not yet available}%
+    {Find an armchair, sit down and wait}}
+\let\uselocale\setlocale
+\let\locale\setlocale
+\let\selectlocale\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{%

Modified: trunk/Master/texmf-dist/tex/generic/babel/xebabel.def
===================================================================
--- trunk/Master/texmf-dist/tex/generic/babel/xebabel.def	2017-04-28 21:17:39 UTC (rev 44100)
+++ trunk/Master/texmf-dist/tex/generic/babel/xebabel.def	2017-04-28 21:20:36 UTC (rev 44101)
@@ -39,7 +39,7 @@
 %% extension .ins) which are part of the distribution.
 %% File `bbunicode.dtx'
 %% Babel package for LaTeX version 2e
-%% Copyright (C) 2103-2016
+%% Copyright (C) 2103-2017
 %%           by Javier Bezos
 \def\BabelStringsDefault{unicode}
 \let\xebbl at stop\relax



More information about the tex-live-commits mailing list