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