From 47b05827e36c70484f9a11ecd9677b22537a8910 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Tue, 28 Apr 2020 21:14:00 +0000 Subject: babel (28apr20) git-svn-id: svn://tug.org/texlive/trunk@54930 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/latex/babel/README.md | 43 +- Master/texmf-dist/doc/latex/babel/babel.pdf | Bin 768198 -> 773032 bytes Master/texmf-dist/source/latex/babel/babel.dtx | 10361 ++++++++++--------- Master/texmf-dist/source/latex/babel/babel.ins | 2 +- Master/texmf-dist/source/latex/babel/bbcompat.dtx | 2 +- Master/texmf-dist/source/latex/babel/locale.zip | Bin 761543 -> 755233 bytes .../tex/generic/babel/babel-bidi-basic-r.lua | 1 + .../tex/generic/babel/babel-bidi-basic.lua | 1 + .../tex/generic/babel/babel-data-bidi.lua | 1 + .../tex/generic/babel/babel-data-cjk.lua | 1 + Master/texmf-dist/tex/generic/babel/babel.def | 1473 ++- Master/texmf-dist/tex/generic/babel/babel.sty | 566 +- Master/texmf-dist/tex/generic/babel/blplain.tex | 1 + Master/texmf-dist/tex/generic/babel/bplain.tex | 1 + Master/texmf-dist/tex/generic/babel/hyphen.cfg | 45 +- .../tex/generic/babel/locale/as/babel-as.ini | 114 +- .../tex/generic/babel/locale/bn/babel-bn.ini | 5 +- .../tex/generic/babel/locale/fi/babel-fi.ini | 9 +- .../tex/generic/babel/locale/hy/babel-hy.ini | 20 +- .../tex/generic/babel/locale/lb/babel-lb.ini | 113 +- .../tex/generic/babel/locale/mr/babel-mr.ini | 10 +- Master/texmf-dist/tex/generic/babel/luababel.def | 98 +- Master/texmf-dist/tex/generic/babel/nil.ldf | 3 +- Master/texmf-dist/tex/generic/babel/plain.def | 325 +- Master/texmf-dist/tex/generic/babel/switch.def | 450 +- Master/texmf-dist/tex/generic/babel/txtbabel.def | 1 + Master/texmf-dist/tex/generic/babel/xebabel.def | 30 +- 27 files changed, 6951 insertions(+), 6725 deletions(-) (limited to 'Master/texmf-dist') diff --git a/Master/texmf-dist/doc/latex/babel/README.md b/Master/texmf-dist/doc/latex/babel/README.md index 1274e405b31..d37c85f1d29 100644 --- a/Master/texmf-dist/doc/latex/babel/README.md +++ b/Master/texmf-dist/doc/latex/babel/README.md @@ -1,4 +1,4 @@ -## Babel 3.42 +## Babel 3.43 This package manages culturally-determined typographical (and other) rules, and hyphenation patterns for a wide range of languages. Many @@ -7,9 +7,9 @@ lualatex out of the box. A few even work with plain formats. The latest stable version is available on . -Changes in version 3.42 are described in: +Changes in version 3.43 are described in: -https://github.com/latex3/babel/wiki/What's-new-in-babel-3.42 +https://github.com/latex3/babel/wiki/What's-new-in-babel-3.43 Included is a set of ini files for about 200 languages. @@ -44,6 +44,18 @@ respective authors. ### Latest changes ``` +3.43 2020-04-28 + - Autoloading based on the BCP47 codes, with basic lookup. + - Now only a few essential commands are loaded in the format. + - Improvements in Assamese, Luxembourgish, Marathi, Armenian, + Bengali, and Finnish. + - First steps in the removal of switch.def and plain.def. + - Fixes: + - Babel reset the \sfcode of » to 1000. It should be 0. + - \guillemotleft and \guillemotleft renamed to \guillemetleft + and \guillemetleft (#63). + - A couple of bugs related to autoloading. + 3.42 2020-03-22 - \getlocaleproperty, to get the value of a field from the loaded ini files. @@ -60,6 +72,7 @@ respective authors. (#52). - Locale was not switched correctly with COMBINING characters (#54). +See https://github.com/latex3/babel/wiki/What's-new-in-babel-3.42 3.41 2020-02-27 - Counters and numerals added in some ini files, based on those @@ -145,30 +158,6 @@ See https://github.com/latex3/babel/wiki/What's-new-in-babel-3.36 - Basic support for the picture environment (with pict2e) and pgf (lua, somewhat experimental). - Start support for harftex (just try - it may work). - -3.31 2019-05-04 - - Basic support for line breaking with CJK scripts (lua) - - layout=tabular now works with the 'array' package (and some - others; lua). - -3.30 2019-04-22 - - Fix - dir in boxes inside math (hopefully now it works; lua). - - Option mapdigits for \babelprovide, which converts European - digits to local ones (lua). - -3.29 2019-04-03 - - The fix for boxes inside math is incompatible with ams. - Removed (a better fix is under study). - - Options bidi-l and bidi-r (for the bidi package; xe). - -3.28 2019-04-01 - - Fixes - wrong dir after math, in math inside tabular, in weak L - inside R inside L, and in boxes inside math. - - \babelfont now takes into account \defaultfontfeatures. This - is a potential source of backwards incompatibilities, but - very likely the risks are very low, and it is, I think, the - expected behavior. - ``` Javier Bezos diff --git a/Master/texmf-dist/doc/latex/babel/babel.pdf b/Master/texmf-dist/doc/latex/babel/babel.pdf index 854f18bea2c..95d4abf64a7 100644 Binary files a/Master/texmf-dist/doc/latex/babel/babel.pdf and b/Master/texmf-dist/doc/latex/babel/babel.pdf differ 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} -%<> -%<> +%<> +%<> % \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. %<> % \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 -%<> -% \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 -%<> -% \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. % -% Apart from all the language options below we also have a few options -% that influence the behavior of language definition files. +% \subsection{The Package File (\LaTeX, \texttt{babel.sty})} % -% 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. +% 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. % -% \subsection{\texttt{base}} +% 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. % -% 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 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,5764 +5330,5740 @@ help from Bernd Raichle, for which I am grateful. \fi % \end{macrocode} % -% \subsection{Language options} -% -% Languages are loaded when processing the corresponding option -% \textit{except} if a |main| language has been set. In such a -% case, it is not loaded until all options has been processed. -% The following macro inputs the ldf file and does some additional -% checks (|\input| works, too, but possible errors are not catched). +% \textbf{Common definitions.} \textit{In progress.} Still based on +% |babel.def|, but the code should be moved here. % % \begin{macrocode} -\bbl@trace{Language options} -\let\bbl@afterlang\relax -\let\BabelModifiers\relax -\let\bbl@loaded\@empty -\def\bbl@load@language#1{% - \InputIfFileExists{#1.ldf}% - {\edef\bbl@loaded{\CurrentOption - \ifx\bbl@loaded\@empty\else,\bbl@loaded\fi}% - \expandafter\let\expandafter\bbl@afterlang - \csname\CurrentOption.ldf-h@@k\endcsname - \expandafter\let\expandafter\BabelModifiers - \csname bbl@mod@\CurrentOption\endcsname}% - {\bbl@error{% - Unknown option `\CurrentOption'. Either you misspelled it\\% - or the language definition file \CurrentOption.ldf was not found}{% - Valid options are: shorthands=, KeepShorthandsActive,\\% - activeacute, activegrave, noconfigs, safe=, main=, math=\\% - headfoot=, strings=, config=, hyphenmap=, or a language name.}}} +\input babel.def % \end{macrocode} % -% Now, we set language options whose names are different from |ldf| files. +% \subsection{Cross referencing macros} % -% \begin{macrocode} -\def\bbl@try@load@lang#1#2#3{% - \IfFileExists{\CurrentOption.ldf}% - {\bbl@load@language{\CurrentOption}}% - {#1\bbl@load@language{#2}#3}} -\DeclareOption{afrikaans}{\bbl@try@load@lang{}{dutch}{}} -\DeclareOption{brazil}{\bbl@try@load@lang{}{portuges}{}} -\DeclareOption{brazilian}{\bbl@try@load@lang{}{portuges}{}} -\DeclareOption{hebrew}{% - \input{rlbabel.def}% - \bbl@load@language{hebrew}} -\DeclareOption{hungarian}{\bbl@try@load@lang{}{magyar}{}} -\DeclareOption{lowersorbian}{\bbl@try@load@lang{}{lsorbian}{}} -\DeclareOption{nynorsk}{\bbl@try@load@lang{}{norsk}{}} -\DeclareOption{polutonikogreek}{% - \bbl@try@load@lang{}{greek}{\languageattribute{greek}{polutoniko}}} -\DeclareOption{portuguese}{\bbl@try@load@lang{}{portuges}{}} -\DeclareOption{russian}{\bbl@try@load@lang{}{russianb}{}} -\DeclareOption{ukrainian}{\bbl@try@load@lang{}{ukraineb}{}} -\DeclareOption{uppersorbian}{\bbl@try@load@lang{}{usorbian}{}} -% \end{macrocode} +% 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. % -% Another way to extend the list of `known' options for \babel\ was -% to create the file \file{bblopts.cfg} in which one can add option -% declarations. However, this mechanism is deprecated -- if you -% want an alternative name for a language, just create a new |.ldf| -% file loading the actual one. You can also set the name -% of the file with the package option |config=|, which will -% load |.cfg| instead. +% 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} -\ifx\bbl@opt@config\@nnil - \@ifpackagewith{babel}{noconfigs}{}% - {\InputIfFileExists{bblopts.cfg}% - {\typeout{*************************************^^J% - * Local config file bblopts.cfg used^^J% - *}}% - {}}% -\else - \InputIfFileExists{\bbl@opt@config.cfg}% - {\typeout{*************************************^^J% - * Local config file \bbl@opt@config.cfg used^^J% - *}}% - {\bbl@error{% - Local config file `\bbl@opt@config.cfg' not found}{% - Perhaps you misspelled it.}}% -\fi +%<<*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}} +%<> % \end{macrocode} % -% Recognizing global options in packages not having a closed set of -% them is not trivial, as for them to be processed they must be -% defined explicitly. So, package options not yet taken into -% account and stored in |bbl@language@opts| are assumed to be -% languages (note this list also contains the language given with -% |main|). If not declared above, the names of the option and the -% file are the same. +% \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@for\bbl@tempa\bbl@language@opts{% - \bbl@ifunset{ds@\bbl@tempa}% - {\edef\bbl@tempb{% - \noexpand\DeclareOption - {\bbl@tempa}% - {\noexpand\bbl@load@language{\bbl@tempa}}}% - \bbl@tempb}% - \@empty} +\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} % -% Now, we make sure an option is explicitly declared for any -% language set as global option, by checking if an |ldf| -% exists. The previous step was, in fact, somewhat redundant, but -% that way we minimize accesing the file system just to see if the -% option could be a language. +% \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} -\bbl@foreach\@classoptionslist{% - \bbl@ifunset{ds@#1}% - {\IfFileExists{#1.ldf}% - {\DeclareOption{#1}{\bbl@load@language{#1}}}% - {}}% - {}} + \CheckCommand*\@testdef[3]{% + \def\reserved@a{#3}% + \expandafter\ifx\csname#1@#2\endcsname\reserved@a + \else + \@tempswatrue + \fi} % \end{macrocode} % -% If a main language has been set, store it for the third pass. +% 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} -\ifx\bbl@opt@main\@nnil\else - \expandafter - \let\expandafter\bbl@loadmain\csname ds@\bbl@opt@main\endcsname - \DeclareOption{\bbl@opt@main}{} + \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} % -% And we are done, because all options for this pass has been -% declared. Those already processed in the first pass are just -% ignored. -% -% The options have to be processed in the order in which the user -% specified them (except, of course, global options, which \LaTeX{} -% processes before): +% \end{macro} % -% \begin{macrocode} -\def\AfterBabelLanguage#1{% - \bbl@ifsamestring\CurrentOption{#1}{\global\bbl@add\bbl@afterlang}{}} -\DeclareOption*{} -\ProcessOptions* -% \end{macrocode} +% \begin{macro}{\ref} +% \begin{macro}{\pageref} % -% This finished the second pass. Now the third one begins, which -% loads the main language set with the key |main|. A warning is -% raised if the main language is not the same as the last named -% one, or if the value of the key |main| is not a language. Then -% execute directly the option (because it could be used only in -% |main|). After loading all languages, we deactivate -% |\AfterBabelLanguage|. +% 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} -\ifx\bbl@opt@main\@nnil - \edef\bbl@tempa{\@classoptionslist,\bbl@language@opts} - \let\bbl@tempc\@empty - \bbl@for\bbl@tempb\bbl@tempa{% - \bbl@xin@{,\bbl@tempb,}{,\bbl@loaded,}% - \ifin@\edef\bbl@tempc{\bbl@tempb}\fi} - \def\bbl@tempa#1,#2\@nnil{\def\bbl@tempb{#1}} - \expandafter\bbl@tempa\bbl@loaded,\@nnil - \ifx\bbl@tempb\bbl@tempc\else - \bbl@warning{% - Last declared language option is `\bbl@tempc',\\% - but the last processed one was `\bbl@tempb'.\\% - The main language cannot be set as both a global\\% - and a package option. Use `main=\bbl@tempc' as\\% - option. Reported}% - \fi +\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 - \DeclareOption{\bbl@opt@main}{\bbl@loadmain} - \ExecuteOptions{\bbl@opt@main} - \DeclareOption*{} - \ProcessOptions* -\fi -\def\AfterBabelLanguage{% - \bbl@error - {Too late for \string\AfterBabelLanguage}% - {Languages have been loaded, so I can do nothing}} -% \end{macrocode} -% -% In order to catch the case where the user forgot to specify a -% language we check whether |\bbl@main@language|, has become -% defined. If not, no language has been loaded and an error -% message is displayed. -% -% \begin{macrocode} -\ifx\bbl@main@language\@undefined - \bbl@info{% - You haven't specified a language. I'll use 'nil'\\% - as the main language. Reported} - \bbl@load@language{nil} + \let\org@ref\ref + \let\org@pageref\pageref \fi -% -%<*core> % \end{macrocode} % -% \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. -% -% 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 -% process the files. For this reason the current format will have to -% be checked in a number of places. Some of the code below is common -% to plain \TeX\ and \LaTeX, some of it is for the \LaTeX\ case only. -% -% Plain formats based on etex (etex, xetex, luatex) don't load -% |hyphen.cfg| but |etex.src|, which follows a different naming -% convention, so we need to define the babel names. It presumes -% |language.def| exists and it is the same file used when formats were -% created. +% \end{macro} +% \end{macro} % -% \subsection{Tools} +% \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} -\ifx\ldf@quit\@undefined -\else - \expandafter\endinput -\fi -<@Make sure ProvidesFile is defined@> -\ProvidesFile{babel.def}[<@date@> <@version@> Babel common definitions] -<@Load macros for plain if not LaTeX@> +\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} % -% The file |babel.def| expects some definitions made in the \LaTeXe{} -% style file. So, In \LaTeX2.09 and Plain{} we must provide at least -% some predefined values as well some tools to set them (even if not -% all options are available). There are no package options, and -% therefore and alternative mechanism is provided. For the moment, -% only |\babeloptionstrings| and |\babeloptionmath| are provided, -% which can be defined before loading \babel. |\BabelModifiers| can be -% set too (but not sure it works). +% 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} -\ifx\bbl@ifshorthand\@undefined - \let\bbl@opt@shorthands\@nnil - \def\bbl@ifshorthand#1#2#3{#2}% - \let\bbl@language@opts\@empty - \ifx\babeloptionstrings\@undefined - \let\bbl@opt@strings\@nnil - \else - \let\bbl@opt@strings\babeloptionstrings - \fi - \def\BabelStringsDefault{generic} - \def\bbl@tempa{normal} - \ifx\babeloptionmath\bbl@tempa - \def\bbl@mathnormal{\noexpand\textormath} - \fi - \def\AfterBabelLanguage#1#2{} - \ifx\BabelModifiers\@undefined\let\BabelModifiers\relax\fi - \let\bbl@afterlang\relax - \def\bbl@opt@safe{BR} - \ifx\@uclclist\@undefined\let\@uclclist\@empty\fi - \ifx\bbl@trace\@undefined\def\bbl@trace#1{}\fi - \expandafter\newif\csname ifbbl@single\endcsname -\fi + \AtBeginDocument{% + \@ifpackageloaded{natbib}{% % \end{macrocode} % -% And continue. +% 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} -\ifx\bbl@switchflag\@undefined % Prevent double input - \let\bbl@switchflag\relax - \input switch.def\relax -\fi -\bbl@trace{Compatibility with language.def} -\ifx\bbl@languages\@undefined - \ifx\directlua\@undefined - \openin1 = language.def - \ifeof1 - \closein1 - \message{I couldn't find the file language.def} - \else - \closein1 - \begingroup - \def\addlanguage#1#2#3#4#5{% - \expandafter\ifx\csname lang@#1\endcsname\relax\else - \global\expandafter\let\csname l@#1\expandafter\endcsname - \csname lang@#1\endcsname - \fi}% - \def\uselanguage#1{}% - \input language.def - \endgroup - \fi - \fi - \chardef\l@english\z@ -\fi -<@Load patterns in luatex@> -<@Basic macros@> + \def\@citex[#1][#2]#3{% + \@safe@activestrue\edef\@tempa{#3}\@safe@activesfalse + \org@@citex[#1][#2]{\@tempa}}% + }{}} % \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. +% The package \pkg{cite} has a definition of |\@citex| where the +% shorthands need to be turned off in both arguments. % % \begin{macrocode} -\def\addto#1#2{% - \ifx#1\@undefined - \def#1{#2}% - \else - \ifx#1\relax - \def#1{#2}% - \else - {\toks@\expandafter{#1#2}% - \xdef#1{\the\toks@}}% - \fi - \fi} + \AtBeginDocument{% + \@ifpackageloaded{cite}{% + \def\@citex[#1]#2{% + \@safe@activestrue\org@@citex[#1]{#2}\@safe@activesfalse}% + }{}} % \end{macrocode} % % \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. +% \begin{macro}{\nocite} +% The macro |\nocite| which is used to instruct BiB\TeX\ to +% extract uncited references from the database. % % \begin{macrocode} -\def\bbl@withactive#1#2{% - \begingroup - \lccode`~=`#2\relax - \lowercase{\endgroup#1~}} -% \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@...| -% -% \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} + \bbl@redefine\nocite#1{% + \@safe@activestrue\org@nocite{#1}\@safe@activesfalse} % \end{macrocode} % -% This command should only be used in the preamble of the document. +% \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} -\@onlypreamble\bbl@redefine + \bbl@redefine\bibcite{% + \bbl@cite@choice + \bibcite} % \end{macrocode} % % \end{macro} % -% \begin{macro}{\bbl@redefine@long} -% This version of |\babel@redefine| can be used to redefine |\long| -% commands such as |\ifthenelse|. +% \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@redefine@long#1{% - \edef\bbl@tempa{\bbl@stripslash#1}% - \expandafter\let\csname org@\bbl@tempa\endcsname#1% - \expandafter\long\expandafter\def\csname\bbl@tempa\endcsname} -\@onlypreamble\bbl@redefine@long + \def\bbl@bibcite#1#2{% + \org@bibcite{#1}{\@safe@activesfalse#2}} % \end{macrocode} % % \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@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@redefinerobust#1{% - \edef\bbl@tempa{\bbl@stripslash#1}% - \bbl@ifunset{\bbl@tempa\space}% - {\expandafter\let\csname org@\bbl@tempa\endcsname#1% - \bbl@exp{\def\\#1{\\\protect\<\bbl@tempa\space>}}}% - {\bbl@exp{\let\\<\bbl@tempa\space>}}% - \@namedef{\bbl@tempa\space}} + \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} % -% This command should only be used in the preamble of the document. +% 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} -\@onlypreamble\bbl@redefinerobust + \AtBeginDocument{\bbl@cite@choice} % \end{macrocode} % % \end{macro} % -% \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. +% \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@trace{Hooks} -\newcommand\AddBabelHook[3][]{% - \bbl@ifunset{bbl@hk@#2}{\EnableBabelHook{#2}}{}% - \def\bbl@tempa##1,#3=##2,##3\@empty{\def\bbl@tempb{##2}}% - \expandafter\bbl@tempa\bbl@evargs,#3=,\@empty - \bbl@ifunset{bbl@ev@#2@#3@#1}% - {\bbl@csarg\bbl@add{ev@#3@#1}{\bbl@elt{#2}}}% - {\bbl@csarg\let{ev@#2@#3@#1}\relax}% - \bbl@csarg\newcommand{ev@#2@#3@#1}[\bbl@tempb]} -\newcommand\EnableBabelHook[1]{\bbl@csarg\let{hk@#1}\@firstofone} -\newcommand\DisableBabelHook[1]{\bbl@csarg\let{hk@#1}\@gobble} -\def\bbl@usehooks#1#2{% - \def\bbl@elt##1{% - \bbl@cs{hk@##1}{\bbl@cs{ev@##1@#1@}#2}}% - \bbl@cs{ev@#1@}% - \ifx\languagename\@undefined\else % Test required for Plain (?) - \def\bbl@elt##1{% - \bbl@cs{hk@##1}{\bbl@cl{ev@##1@#1}#2}}% - \bbl@cl{ev@#1}% - \fi} + \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} % -% 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 - everylanguage=1,loadkernel=1,loadpatterns=1,loadexceptions=1,% - 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} -% \end{macrocode} +% \end{macro} % -% \begin{macro}{\babelensure} +% \subsection{Marks} % -% The user command just parses the optional argument and creates a -% new macro named |\bbl@e@|\m{language}. We register a hook at the -% |afterextras| event which just executes this macro in a -% ``complete'' selection (which, if undefined, is |\relax| and does -% nothing). This part is somewhat involved because we have to make -% sure things are expanded the correct number of times. +% \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. % -% The macro |\bbl@e@|\m{language} contains -% |\bbl@ensure|\marg{include}\marg{exclude}\marg{fontenc}, which in in -% turn loops over the macros names in |\bbl@captionslist|, excluding -% (with the help of |\in@|) those in the |exclude| list. If the -% |fontenc| is given (and not |\relax|), the |\fontencoding| is also -% added. Then we loop over the |include| list, but if the macro -% already contains |\foreignlanguage|, nothing is done. Note this -% macro (1) is not restricted to the preamble, and (2) changes are -% local. +% 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{Defining babelensure} -\newcommand\babelensure[2][]{% TODO - revise test files - \AddBabelHook{babel-ensure}{afterextras}{% - \ifcase\bbl@select@type - \bbl@cl{e}% - \fi}% - \begingroup - \let\bbl@ens@include\@empty - \let\bbl@ens@exclude\@empty - \def\bbl@ens@fontenc{\relax}% - \def\bbl@tempb##1{% - \ifx\@empty##1\else\noexpand##1\expandafter\bbl@tempb\fi}% - \edef\bbl@tempa{\bbl@tempb#1\@empty}% - \def\bbl@tempb##1=##2\@@{\@namedef{bbl@ens@##1}{##2}}% - \bbl@foreach\bbl@tempa{\bbl@tempb##1\@@}% - \def\bbl@tempc{\bbl@ensure}% - \expandafter\bbl@add\expandafter\bbl@tempc\expandafter{% - \expandafter{\bbl@ens@include}}% - \expandafter\bbl@add\expandafter\bbl@tempc\expandafter{% - \expandafter{\bbl@ens@exclude}}% - \toks@\expandafter{\bbl@tempc}% - \bbl@exp{% - \endgroup - \def\{\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 - \edef##1{\noexpand\bbl@nocaption - {\bbl@stripslash##1}{\languagename\bbl@stripslash##1}}% - \fi - \ifx##1\@empty\else - \in@{##1}{#2}% - \ifin@\else - \bbl@ifunset{bbl@ensure@\languagename}% - {\bbl@exp{% - \\\DeclareRobustCommand\[1]{% - \\\foreignlanguage{\languagename}% - {\ifx\relax#3\else - \\\fontencoding{#3}\\\selectfont - \fi - ########1}}}}% - {}% - \toks@\expandafter{##1}% - \edef##1{% - \bbl@csarg\noexpand{ensure@\languagename}% - {\the\toks@}}% - \fi - \expandafter\bbl@tempb - \fi}% - \expandafter\bbl@tempb\bbl@captionslist\today\@empty - \def\bbl@tempa##1{% elt for include list - \ifx##1\@empty\else - \bbl@csarg\in@{ensure@\languagename\expandafter}\expandafter{##1}% - \ifin@\else - \bbl@tempb##1\@empty - \fi - \expandafter\bbl@tempa - \fi}% - \bbl@tempa#1\@empty} -\def\bbl@captionslist{% - \prefacename\refname\abstractname\bibname\chaptername\appendixname - \contentsname\listfigurename\listtablename\indexname\figurename - \tablename\partname\enclname\ccname\headtoname\pagename\seename - \alsoname\proofname\glossaryname} +\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} +% \end{macro} % -% \subsection{Setting up language files} +% \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{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. +% \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} % -% 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. +% \end{macro} +% \end{macro} % -% 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. +% \subsection{Preventing clashes with other packages} % -% 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|. +% \subsubsection{\pkg{ifthen}} % -% If so, we call |\ldf@quit| to set the main language, restore the -% category code of the @-sign and call |\endinput| +% \begin{macro}{\ifthenelse} % -% When |#2| was \emph{not} a control sequence we construct one and -% compare it with |\relax|. +% 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. % -% Finally we check |\originalTeX|. +% 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{Macros for setting language files up} -\def\bbl@ldfinit{% - \let\bbl@screset\@empty - \let\BabelStrings\bbl@opt@string - \let\BabelOptions\@empty - \let\BabelLanguages\relax - \ifx\originalTeX\@undefined - \let\originalTeX\@empty - \else - \originalTeX - \fi} -\def\LdfInit#1#2{% - \chardef\atcatcode=\catcode`\@ - \catcode`\@=11\relax - \chardef\eqcatcode=\catcode`\= - \catcode`\==12\relax - \expandafter\if\expandafter\@backslashchar - \expandafter\@car\string#2\@nil - \ifx#2\@undefined\else - \ldf@quit{#1}% - \fi - \else - \expandafter\ifx\csname#2\endcsname\relax\else - \ldf@quit{#1}% - \fi - \fi - \bbl@ldfinit} +\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} % -% \begin{macro}{\ldf@quit} -% This macro interrupts the processing of a language definition file. +% \subsubsection{\pkg{varioref}} % -% \begin{macrocode} -\def\ldf@quit#1{% - \expandafter\main@language\expandafter{#1}% - \catcode`\@=\atcatcode \let\atcatcode\relax - \catcode`\==\eqcatcode \let\eqcatcode\relax - \endinput} -% \end{macrocode} +% \begin{macro}{\@@vpageref} +% \begin{macro}{\vrefpagenum} +% \begin{macro}{\Ref} % -% \end{macro} +% 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{macro}{\ldf@finish} -% This macro takes one argument. It is the name of the language -% that was defined in the language definition file. +% \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} % -% We load the local configuration file if one is present, we set -% the main language (taking into account that the argument might be -% a control sequence that needs to be expanded) and reset the -% category code of the @-sign. +% 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} -\def\bbl@afterldf#1{% - \bbl@afterlang - \let\bbl@afterlang\relax - \let\BabelModifiers\relax - \let\bbl@screset\relax}% -\def\ldf@finish#1{% - \loadlocalcfg{#1}% - \bbl@afterldf{#1}% - \expandafter\main@language\expandafter{#1}% - \catcode`\@=\atcatcode \let\atcatcode\relax - \catcode`\==\eqcatcode \let\eqcatcode\relax} + \expandafter\def\csname Ref \endcsname#1{% + \protected@edef\@tempa{\org@ref{#1}}\expandafter\MakeUppercase\@tempa} + }{}% + } +\fi % \end{macrocode} % % \end{macro} +% \end{macro} +% \end{macro} % -% After the preamble of the document the commands |\LdfInit|, -% |\ldf@quit| and |\ldf@finish| are no longer needed. Therefore -% they are turned into warning messages in \LaTeX. +% \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} -\@onlypreamble\LdfInit -\@onlypreamble\ldf@quit -\@onlypreamble\ldf@finish +\AtEndOfPackage{% + \AtBeginDocument{% + \@ifpackageloaded{hhline}% + {\expandafter\ifx\csname normal@char\string:\endcsname\relax + \else + \makeatletter + \def\@currname{hhline}\input{hhline.sty}\makeatother + \fi}% + {}}} % \end{macrocode} % -% \begin{macro}{\main@language} -% \begin{macro}{\bbl@main@language} -% This command should be used in the various language definition -% files. It stores its argument in |\bbl@main@language|; to be used -% to switch to the correct language at the beginning of the -% document. +% \end{macro} % -% \begin{macrocode} -\def\main@language#1{% - \def\bbl@main@language{#1}% - \let\languagename\bbl@main@language - \bbl@id@assign - \bbl@patterns{\languagename}} -% \end{macrocode} +% \subsubsection{\pkg{hyperref}} % -% 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|. +% \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} -\def\bbl@beforestart{% - \bbl@usehooks{beforestart}{}% - \global\let\bbl@beforestart\relax} \AtBeginDocument{% - \bbl@cs{beforestart}% - \if@filesw - \immediate\write\@mainaux{\string\bbl@cs{beforestart}}% - \fi - \expandafter\selectlanguage\expandafter{\bbl@main@language}% - \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 + \ifx\pdfstringdefDisableCommands\@undefined\else + \pdfstringdefDisableCommands{\languageshorthands{system}}% + \fi} % \end{macrocode} % % \end{macro} -% \end{macro} % -% A bit of optimization. Select in heads/foots the language only if -% necessary. +% \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} -\def\select@language@x#1{% - \ifcase\bbl@select@type - \bbl@ifsamestring\languagename{#1}{}{\select@language{#1}}% - \else - \select@language{#1}% - \fi} +\DeclareRobustCommand{\FOREIGNLANGUAGE}[1]{% + \lowercase{\foreignlanguage{#1}}} % \end{macrocode} % -% \subsection{Shorthands} +% \end{macro} % -% \begin{macro}{\bbl@add@special} -% The macro |\bbl@add@special| is used to add a new character (or -% single character control sequence) to the macro |\dospecials| -% (and |\@sanitize| if \LaTeX\ is used). It is used only at one -% place, namely when |\initiate@active@char| is called (which is -% ignored if the char has been made active before). Because -% |\@sanitize| can be undefined, we put the definition inside a -% conditional. +% \begin{macro}{\substitutefontfamily} % -% Items are added to the lists without checking its existence or -% the original catcode. It does not hurt, but should be fixed. It's -% already done with |\nfss@catcodes|, added in 3.10. +% 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} -\bbl@trace{Shorhands} -\def\bbl@add@special#1{% 1:a macro like \", \?, etc. - \bbl@add\dospecials{\do#1}% test @sanitize = \relax, for back. compat. - \bbl@ifunset{@sanitize}{}{\bbl@add\@sanitize{\@makeother#1}}% - \ifx\nfss@catcodes\@undefined\else % TODO - same for above - \begingroup - \catcode`#1\active - \nfss@catcodes - \ifnum\catcode`#1=\active - \endgroup - \bbl@add\nfss@catcodes{\@makeother#1}% - \else - \endgroup - \fi - \fi} +\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} % -% \begin{macro}{\bbl@remove@special} -% -% The companion of the former macro is |\bbl@remove@special|. It -% removes a character from the set macros |\dospecials| and -% |\@sanitize|, but it is not used at all in the \babel{} core. +% \subsection{Encoding and fonts} % -% \begin{macrocode} -\def\bbl@remove@special#1{% - \begingroup - \def\x##1##2{\ifnum`#1=`##2\noexpand\@empty - \else\noexpand##1\noexpand##2\fi}% - \def\do{\x\do}% - \def\@makeother{\x\@makeother}% - \edef\x{\endgroup - \def\noexpand\dospecials{\dospecials}% - \expandafter\ifx\csname @sanitize\endcsname\relax\else - \def\noexpand\@sanitize{\@sanitize}% +% 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}% - \x} + \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} % -% \begin{macro}{\initiate@active@char} -% A language definition file can call this macro to make a -% character active. This macro takes one argument, the character -% that is to be made active. When the character was already active -% this macro does nothing. Otherwise, this macro defines the -% control sequence |\normal@char|\m{char} to expand to the -% character in its `normal state' and it defines the active -% character to expand to |\normal@char|\m{char} by default -% (\m{char} being the character to be made active). Later its -% definition can be changed to expand to |\active@char|\m{char} -% by calling |\bbl@activate{|\m{char}|}|. -% -% For example, to make the double quote character active one could -% have |\initiate@active@char{"}| in a language definition file. -% This defines |"| as |\active@prefix "\active@char"| (where the -% first |"| is the character with its original catcode, when the -% shorthand is created, and |\active@char"| is a single token). In -% protected contexts, it expands to |\protect "| or |\noexpand "| -% (ie, with the original |"|); otherwise |\active@char"| is -% executed. This macro in turn expands to |\normal@char"| in -% ``safe'' contexts (eg, |\label|), but |\user@active"| in normal -% ``unsafe'' ones. The latter search a definition in the user, -% language and system levels, in this order, but if none is found, -% |\normal@char"| is used. However, a deactivated shorthand (with -% |\bbl@deactivate| is defined as |\active@prefix "\normal@char"|. +% 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. % -% The following macro is used to define shorthands in the three -% levels. It takes 4 arguments: the (string'ed) character, -% |\@group|, |@active| and |@active| -% (except in |system|). +% \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} -\def\bbl@active@def#1#2#3#4{% - \@namedef{#3#1}{% - \expandafter\ifx\csname#2@sh@#1@\endcsname\relax - \bbl@afterelse\bbl@sh@select#2#1{#3@arg#1}{#4#1}% - \else - \bbl@afterfi\csname#2@sh@#1@\endcsname - \fi}% +\AtEndOfPackage{\edef\latinencoding{\cf@encoding}} % \end{macrocode} % -% When there is also no current-level shorthand with an argument we -% will check whether there is a next-level defined shorthand for -% this active character. +% 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} - \long\@namedef{#3@arg#1}##1{% - \expandafter\ifx\csname#2@sh@#1@\string##1@\endcsname\relax - \bbl@afterelse\csname#4#1\endcsname##1% - \else - \bbl@afterfi\csname#2@sh@#1@\string##1@\endcsname - \fi}}% +\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} % -% |\initiate@active@char| calls |\@initiate@active@char| with 3 -% arguments. All of them are the same character with different -% catcodes: active, other (|\string|'ed) and the original one. -% This trick simplifies the code a lot. +% \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} -\def\initiate@active@char#1{% - \bbl@ifunset{active@char\string#1}% - {\bbl@withactive - {\expandafter\@initiate@active@char\expandafter}#1\string#1#1}% - {}} +\DeclareRobustCommand{\latintext}{% + \fontencoding{\latinencoding}\selectfont + \def\encodingdefault{\latinencoding}} % \end{macrocode} % -% The very first thing to do is saving the original catcode and the -% original definition, even if not active, which is possible -% (undefined characters require a special treatement to avoid -% making them |\relax|). +% \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} -\def\@initiate@active@char#1#2#3{% - \bbl@csarg\edef{oricat@#2}{\catcode`#2=\the\catcode`#2\relax}% - \ifx#1\@undefined - \bbl@csarg\edef{oridef@#2}{\let\noexpand#1\noexpand\@undefined}% - \else - \bbl@csarg\let{oridef@@#2}#1% - \bbl@csarg\edef{oridef@#2}{% - \let\noexpand#1% - \expandafter\noexpand\csname bbl@oridef@@#2\endcsname}% - \fi +\ifx\@undefined\DeclareTextFontCommand + \DeclareRobustCommand{\textlatin}[1]{\leavevmode{\latintext #1}} +\else + \DeclareTextFontCommand{\textlatin}{\latintext} +\fi % \end{macrocode} % -% If the character is already active we provide the default -% expansion under this shorthand mechanism. Otherwise we write a -% message in the transcript file, and define |\normal@char|\m{char} -% to expand to the character in its default state. If the character -% is mathematically active when \babel{} is loaded (for example -% |'|) the normal expansion is somewhat different to avoid an -% infinite loop (but it does not prevent the loop if the mathcode -% is set to |"8000| \textit{a posteriori}). +% \end{macro} % -% \begin{macrocode} - \ifx#1#3\relax - \expandafter\let\csname normal@char#2\endcsname#3% - \else - \bbl@info{Making #2 an active character}% - \ifnum\mathcode`#2=\ifodd\bbl@engine"1000000 \else"8000 \fi - \@namedef{normal@char#2}{% - \textormath{#3}{\csname bbl@oridef@@#2\endcsname}}% - \else - \@namedef{normal@char#2}{#3}% - \fi -% \end{macrocode} +% \subsection{Basic bidi support} % -% To prevent problems with the loading of other packages after -% \babel\ we reset the catcode of the character to the original one -% at the end of the package and of each language file (except with -% \textsf{KeepShorthandsActive}). It is re-activate again at -% |\begin{document}|. We also need to make sure that the -% shorthands are active during the processing of the \file{.aux} -% file. Otherwise some citations may give unexpected results in -% the printout when a shorthand was used in the optional argument -% of |\bibitem| for example. Then we make it active (not strictly -% necessary, but done for backward compatibility). +% \textbf{Work in progress.} This code is currently placed here for +% practical reasons. It will be moved to the correct place soon, I +% hope. % -% \begin{macrocode} - \bbl@restoreactive{#2}% - \AtBeginDocument{% - \catcode`#2\active - \if@filesw - \immediate\write\@mainaux{\catcode`\string#2\active}% - \fi}% - \expandafter\bbl@add@special\csname#2\endcsname - \catcode`#2\active - \fi -% \end{macrocode} +% 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{}. % -% Now we have set |\normal@char|\m{char}, we must define -% |\active@char|\m{char}, to be executed when the character is -% activated. We define the first level expansion of -% |\active@char|\m{char} to check the status of the |@safe@actives| -% flag. If it is set to true we expand to the `normal' version of -% this character, otherwise we call |\user@active|\m{char} to start -% the search of a definition in the user, language and system -% levels (or eventually |normal@char|\m{char}). +% 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{macrocode} - \let\bbl@tempa\@firstoftwo - \if\string^#2% - \def\bbl@tempa{\noexpand\textormath}% - \else - \ifx\bbl@mathnormal\@undefined\else - \let\bbl@tempa\bbl@mathnormal - \fi - \fi - \expandafter\edef\csname active@char#2\endcsname{% - \bbl@tempa - {\noexpand\if@safe@actives - \noexpand\expandafter - \expandafter\noexpand\csname normal@char#2\endcsname - \noexpand\else - \noexpand\expandafter - \expandafter\noexpand\csname bbl@doactive#2\endcsname - \noexpand\fi}% - {\expandafter\noexpand\csname normal@char#2\endcsname}}% - \bbl@csarg\edef{doactive#2}{% - \expandafter\noexpand\csname user@active#2\endcsname}% -% \end{macrocode} -% -% We now define the default values which the shorthand is set to -% when activated or deactivated. It is set to the deactivated form -% (globally), so that the character expands to -% \begin{center} -% |\active@prefix| \m{char} |\normal@char|\m{char} -% \end{center} -% (where |\active@char|\m{char} is \emph{one} control sequence!). +% \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@csarg\edef{active@#2}{% - \noexpand\active@prefix\noexpand#1% - \expandafter\noexpand\csname active@char#2\endcsname}% - \bbl@csarg\edef{normal@#2}{% - \noexpand\active@prefix\noexpand#1% - \expandafter\noexpand\csname normal@char#2\endcsname}% - \expandafter\let\expandafter#1\csname bbl@normal@#2\endcsname +\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 next level of the code checks whether a user has defined a -% shorthand for himself with this character. First we check for a -% single character shorthand. If that doesn't exist we check for a -% shorthand with an argument. +% 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} - \bbl@active@def#2\user@group{user@active}{language@active}% - \bbl@active@def#2\language@group{language@active}{system@active}% - \bbl@active@def#2\system@group{system@active}{normal@char}% + \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} % -% In order to do the right thing when a shorthand with an argument -% is used by itself at the end of the line we provide a definition -% for the case of an empty argument. For that case we let the -% shorthand character expand to its non-active self. Also, When a -% shorthand combination such as |''| ends up in a heading \TeX\ -% would see |\protect'\protect'|. To prevent this from happening a -% couple of shorthand needs to be defined at user level. +% A tool for weak L (mainly digits). We also disable warnings with +% \textsf{hyperref}. % % \begin{macrocode} - \expandafter\edef\csname\user@group @sh@#2@@\endcsname - {\expandafter\noexpand\csname normal@char#2\endcsname}% - \expandafter\edef\csname\user@group @sh@#2@\string\protect@\endcsname - {\expandafter\noexpand\csname user@active#2\endcsname}% +\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} % -% Finally, a couple of special cases are taken care of. (1) If we -% are making the right quote (|'|) active we need to change |\pr@m@s| as -% well. Also, make sure that a single |'| in math mode `does the -% right thing'. (2) If we are using the caret (|^|) as a shorthand -% character special care should be taken to make sure math still -% works. Therefore an extra level of expansion is introduced with a -% check for math mode on the upper level. +% \subsection{Local Language Configuration} % -% \begin{macrocode} - \if\string'#2% - \let\prim@s\bbl@prim@s - \let\active@math@prime#1% - \fi - \bbl@usehooks{initiateactive}{{#1}{#2}{#3}}} -% \end{macrocode} +% \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. % -% The following package options control the behavior of shorthands -% in math mode. +% For plain-based formats we don't want to override the definition +% of |\loadlocalcfg| from \file{plain.def}. % % \begin{macrocode} -%<<*More package options>> -\DeclareOption{math=active}{} -\DeclareOption{math=normal}{\def\bbl@mathnormal{\noexpand\textormath}} -%<> -% \end{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} % -% Initiating a shorthand makes active the char. That is not -% strictly necessary but it is still done for backward -% compatibility. So we need to restore the original catcode at the -% end of package \textit{and} and the end of the |ldf|. +% 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} -\@ifpackagewith{babel}{KeepShorthandsActive}% - {\let\bbl@restoreactive\@gobble}% - {\def\bbl@restoreactive#1{% - \bbl@exp{% - \\\AfterBabelLanguage\\\CurrentOption - {\catcode`#1=\the\catcode`#1\relax}% - \\\AtEndOfPackage - {\catcode`#1=\the\catcode`#1\relax}}}% - \AtEndOfPackage{\let\bbl@restoreactive\@gobble}} -% \end{macrocode} -% -% \end{macro} +\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 % -% \begin{macro}{\bbl@sh@select} -% This command helps the shorthand supporting macros to select how -% to proceed. Note that this macro needs to be expandable as do all -% the shorthand macros in order for them to work in expansion-only -% environments such as the argument of |\hyphenation|. +% \subsection{Language options} % -% This macro expects the name of a group of shorthands in its first -% argument and a shorthand character in its second argument. It -% will expand to either |\bbl@firstcs| or |\bbl@scndcs|. Hence two -% more arguments need to follow it. +% Languages are loaded when processing the corresponding option +% \textit{except} if a |main| language has been set. In such a +% case, it is not loaded until all options has been processed. +% The following macro inputs the ldf file and does some additional +% checks (|\input| works, too, but possible errors are not catched). % % \begin{macrocode} -\def\bbl@sh@select#1#2{% - \expandafter\ifx\csname#1@sh@#2@sel\endcsname\relax - \bbl@afterelse\bbl@scndcs - \else - \bbl@afterfi\csname#1@sh@#2@sel\endcsname - \fi} +\bbl@trace{Language options} +\let\bbl@afterlang\relax +\let\BabelModifiers\relax +\let\bbl@loaded\@empty +\def\bbl@load@language#1{% + \InputIfFileExists{#1.ldf}% + {\edef\bbl@loaded{\CurrentOption + \ifx\bbl@loaded\@empty\else,\bbl@loaded\fi}% + \expandafter\let\expandafter\bbl@afterlang + \csname\CurrentOption.ldf-h@@k\endcsname + \expandafter\let\expandafter\BabelModifiers + \csname bbl@mod@\CurrentOption\endcsname}% + {\bbl@error{% + Unknown option `\CurrentOption'. Either you misspelled it\\% + or the language definition file \CurrentOption.ldf was not found}{% + Valid options are: shorthands=, KeepShorthandsActive,\\% + activeacute, activegrave, noconfigs, safe=, main=, math=\\% + headfoot=, strings=, config=, hyphenmap=, or a language name.}}} % \end{macrocode} % -% \end{macro} -% -% \begin{macro}{\active@prefix} -% The command |\active@prefix| which is used in the expansion of -% active characters has a function similar to |\OT1-cmd| in that it -% |\protect|s the active character whenever |\protect| is -% \emph{not} |\@typeset@protect|. The |\@gobble| is needed to remove -% a token such as |\activechar:| (when the double colon was the -% active character to be dealt with). There are two definitions, -% depending of |\ifincsname| is available. If there is, the -% expansion will be more robust. +% Now, we set language options whose names are different from |ldf| files. % % \begin{macrocode} -\begingroup -\bbl@ifunset{ifincsname}% - {\gdef\active@prefix#1{% - \ifx\protect\@typeset@protect - \else - \ifx\protect\@unexpandable@protect - \noexpand#1% - \else - \protect#1% - \fi - \expandafter\@gobble - \fi}} - {\gdef\active@prefix#1{% - \ifincsname - \string#1% - \expandafter\@gobble - \else - \ifx\protect\@typeset@protect - \else - \ifx\protect\@unexpandable@protect - \noexpand#1% - \else - \protect#1% - \fi - \expandafter\expandafter\expandafter\@gobble - \fi - \fi}} -\endgroup +\def\bbl@try@load@lang#1#2#3{% + \IfFileExists{\CurrentOption.ldf}% + {\bbl@load@language{\CurrentOption}}% + {#1\bbl@load@language{#2}#3}} +\DeclareOption{afrikaans}{\bbl@try@load@lang{}{dutch}{}} +\DeclareOption{brazil}{\bbl@try@load@lang{}{portuges}{}} +\DeclareOption{brazilian}{\bbl@try@load@lang{}{portuges}{}} +\DeclareOption{hebrew}{% + \input{rlbabel.def}% + \bbl@load@language{hebrew}} +\DeclareOption{hungarian}{\bbl@try@load@lang{}{magyar}{}} +\DeclareOption{lowersorbian}{\bbl@try@load@lang{}{lsorbian}{}} +\DeclareOption{nynorsk}{\bbl@try@load@lang{}{norsk}{}} +\DeclareOption{polutonikogreek}{% + \bbl@try@load@lang{}{greek}{\languageattribute{greek}{polutoniko}}} +\DeclareOption{portuguese}{\bbl@try@load@lang{}{portuges}{}} +\DeclareOption{russian}{\bbl@try@load@lang{}{russianb}{}} +\DeclareOption{ukrainian}{\bbl@try@load@lang{}{ukraineb}{}} +\DeclareOption{uppersorbian}{\bbl@try@load@lang{}{usorbian}{}} % \end{macrocode} % -% \end{macro} -% -% \begin{macro}{\if@safe@actives} -% In some circumstances it is necessary to be able to change the -% expansion of an active character on the fly. For this purpose the -% switch |@safe@actives| is available. The setting of this switch -% should be checked in the first level expansion of -% |\active@char|\m{char}. +% Another way to extend the list of `known' options for \babel\ was +% to create the file \file{bblopts.cfg} in which one can add option +% declarations. However, this mechanism is deprecated -- if you +% want an alternative name for a language, just create a new |.ldf| +% file loading the actual one. You can also set the name +% of the file with the package option |config=|, which will +% load |.cfg| instead. % % \begin{macrocode} -\newif\if@safe@actives -\@safe@activesfalse +\ifx\bbl@opt@config\@nnil + \@ifpackagewith{babel}{noconfigs}{}% + {\InputIfFileExists{bblopts.cfg}% + {\typeout{*************************************^^J% + * Local config file bblopts.cfg used^^J% + *}}% + {}}% +\else + \InputIfFileExists{\bbl@opt@config.cfg}% + {\typeout{*************************************^^J% + * Local config file \bbl@opt@config.cfg used^^J% + *}}% + {\bbl@error{% + Local config file `\bbl@opt@config.cfg' not found}{% + Perhaps you misspelled it.}}% +\fi % \end{macrocode} % -% \end{macro} -% -% \begin{macro}{\bbl@restore@actives} -% When the output routine kicks in while the -% active characters were made ``safe'' this must be undone in -% the headers to prevent unexpected typeset results. For this -% situation we define a command to make them ``unsafe'' again. +% Recognizing global options in packages not having a closed set of +% them is not trivial, as for them to be processed they must be +% defined explicitly. So, package options not yet taken into +% account and stored in |bbl@language@opts| are assumed to be +% languages (note this list also contains the language given with +% |main|). If not declared above, the names of the option and the +% file are the same. % % \begin{macrocode} -\def\bbl@restore@actives{\if@safe@actives\@safe@activesfalse\fi} +\bbl@for\bbl@tempa\bbl@language@opts{% + \bbl@ifunset{ds@\bbl@tempa}% + {\edef\bbl@tempb{% + \noexpand\DeclareOption + {\bbl@tempa}% + {\noexpand\bbl@load@language{\bbl@tempa}}}% + \bbl@tempb}% + \@empty} % \end{macrocode} % -% \end{macro} +% Now, we make sure an option is explicitly declared for any +% language set as global option, by checking if an |ldf| +% exists. The previous step was, in fact, somewhat redundant, but +% that way we minimize accesing the file system just to see if the +% option could be a language. % -% \begin{macro}{\bbl@activate} -% \begin{macro}{\bbl@deactivate} +% \begin{macrocode} +\bbl@foreach\@classoptionslist{% + \bbl@ifunset{ds@#1}% + {\IfFileExists{#1.ldf}% + {\DeclareOption{#1}{\bbl@load@language{#1}}}% + {}}% + {}} +% \end{macrocode} % -% 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|. +% If a main language has been set, store it for the third pass. % % \begin{macrocode} -\def\bbl@activate#1{% - \bbl@withactive{\expandafter\let\expandafter}#1% - \csname bbl@active@\string#1\endcsname} -\def\bbl@deactivate#1{% - \bbl@withactive{\expandafter\let\expandafter}#1% - \csname bbl@normal@\string#1\endcsname} +\ifx\bbl@opt@main\@nnil\else + \expandafter + \let\expandafter\bbl@loadmain\csname ds@\bbl@opt@main\endcsname + \DeclareOption{\bbl@opt@main}{} +\fi % \end{macrocode} % -% \end{macro} -% \end{macro} +% And we are done, because all options for this pass has been +% declared. Those already processed in the first pass are just +% ignored. % -% \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. +% The options have to be processed in the order in which the user +% specified them (except, of course, global options, which \LaTeX{} +% processes before): % % \begin{macrocode} -\def\bbl@firstcs#1#2{\csname#1\endcsname} -\def\bbl@scndcs#1#2{\csname#2\endcsname} +\def\AfterBabelLanguage#1{% + \bbl@ifsamestring\CurrentOption{#1}{\global\bbl@add\bbl@afterlang}{}} +\DeclareOption*{} +\ProcessOptions* % \end{macrocode} % -% \end{macro} -% \end{macro} -% -% \begin{macro}{\declare@shorthand} -% The command |\declare@shorthand| is used to declare a shorthand -% on a certain level. It takes three arguments: -% \begin{enumerate} -% \item a name for the collection of shorthands, i.e. `system', or -% `dutch'; -% \item the character (sequence) that makes up the shorthand, -% i.e. |~| or |"a|; -% \item the code to be executed when the shorthand is encountered. -% \end{enumerate} +% This finished the second pass. Now the third one begins, which +% loads the main language set with the key |main|. A warning is +% raised if the main language is not the same as the last named +% one, or if the value of the key |main| is not a language. Then +% execute directly the option (because it could be used only in +% |main|). After loading all languages, we deactivate +% |\AfterBabelLanguage|. % % \begin{macrocode} -\def\declare@shorthand#1#2{\@decl@short{#1}#2\@nil} -\def\@decl@short#1#2#3\@nil#4{% - \def\bbl@tempa{#3}% - \ifx\bbl@tempa\@empty - \expandafter\let\csname #1@sh@\string#2@sel\endcsname\bbl@scndcs - \bbl@ifunset{#1@sh@\string#2@}{}% - {\def\bbl@tempa{#4}% - \expandafter\ifx\csname#1@sh@\string#2@\endcsname\bbl@tempa - \else - \bbl@info - {Redefining #1 shorthand \string#2\\% - in language \CurrentOption}% - \fi}% - \@namedef{#1@sh@\string#2@}{#4}% - \else - \expandafter\let\csname #1@sh@\string#2@sel\endcsname\bbl@firstcs - \bbl@ifunset{#1@sh@\string#2@\string#3@}{}% - {\def\bbl@tempa{#4}% - \expandafter\ifx\csname#1@sh@\string#2@\string#3@\endcsname\bbl@tempa - \else - \bbl@info - {Redefining #1 shorthand \string#2\string#3\\% - in language \CurrentOption}% - \fi}% - \@namedef{#1@sh@\string#2@\string#3@}{#4}% - \fi} +\bbl@trace{Option 'main'} +\ifx\bbl@opt@main\@nnil + \edef\bbl@tempa{\@classoptionslist,\bbl@language@opts} + \let\bbl@tempc\@empty + \bbl@for\bbl@tempb\bbl@tempa{% + \bbl@xin@{,\bbl@tempb,}{,\bbl@loaded,}% + \ifin@\edef\bbl@tempc{\bbl@tempb}\fi} + \def\bbl@tempa#1,#2\@nnil{\def\bbl@tempb{#1}} + \expandafter\bbl@tempa\bbl@loaded,\@nnil + \ifx\bbl@tempb\bbl@tempc\else + \bbl@warning{% + Last declared language option is `\bbl@tempc',\\% + but the last processed one was `\bbl@tempb'.\\% + The main language cannot be set as both a global\\% + and a package option. Use `main=\bbl@tempc' as\\% + option. Reported}% + \fi +\else + \DeclareOption{\bbl@opt@main}{\bbl@loadmain} + \ExecuteOptions{\bbl@opt@main} + \DeclareOption*{} + \ProcessOptions* +\fi +\def\AfterBabelLanguage{% + \bbl@error + {Too late for \string\AfterBabelLanguage}% + {Languages have been loaded, so I can do nothing}} % \end{macrocode} -% -% \end{macro} -% -% \begin{macro}{\textormath} -% Some of the shorthands that will be declared by the language -% definition files have to be usable in both text and mathmode. To -% achieve this the helper macro |\textormath| is provided. +% +% In order to catch the case where the user forgot to specify a +% language we check whether |\bbl@main@language|, has become +% defined. If not, no language has been loaded and an error +% message is displayed. % % \begin{macrocode} -\def\textormath{% - \ifmmode - \expandafter\@secondoftwo - \else - \expandafter\@firstoftwo - \fi} +\ifx\bbl@main@language\@undefined + \bbl@info{% + You haven't specified a language. I'll use 'nil'\\% + as the main language. Reported} + \bbl@load@language{nil} +\fi +% +%<*core> % \end{macrocode} % -% \end{macro} +% \section{The kernel of Babel (\texttt{babel.def}, common)} % -% \begin{macro}{\user@group} -% \begin{macro}{\language@group} -% \begin{macro}{\system@group} -% The current concept of `shorthands' supports three levels or -% groups of shorthands. For each level the name of the level or -% group is stored in a macro. The default is to have a user group; -% use language group `english' and have a system group called -% `system'. +% 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. % -% \begin{macrocode} -\def\user@group{user} -\def\language@group{english} -\def\system@group{system} -% \end{macrocode} +% 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 +% process the files. For this reason the current format will have to +% be checked in a number of places. Some of the code below is common +% to plain \TeX\ and \LaTeX, some of it is for the \LaTeX\ case only. % -% \end{macro} -% \end{macro} -% \end{macro} +% Plain formats based on etex (etex, xetex, luatex) don't load +% |hyphen.cfg| but |etex.src|, which follows a different naming +% convention, so we need to define the babel names. It presumes +% |language.def| exists and it is the same file used when formats were +% created. % -% \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 -% preamble). Languages can deactivate shorthands, so a starred -% version is also provided which activates them always after the -% language has been switched. +% \subsection{Tools} % % \begin{macrocode} -\def\useshorthands{% - \@ifstar\bbl@usesh@s{\bbl@usesh@x{}}} -\def\bbl@usesh@s#1{% - \bbl@usesh@x - {\AddBabelHook{babel-sh-\string#1}{afterextras}{\bbl@activate{#1}}}% - {#1}} -\def\bbl@usesh@x#1#2{% - \bbl@ifshorthand{#2}% - {\def\user@group{user}% - \initiate@active@char{#2}% - #1% - \bbl@activate{#2}}% - {\bbl@error - {Cannot declare a shorthand turned off (\string#2)} - {Sorry, but you cannot use shorthands which have been\\% - turned off in the package options}}} +\ifx\ldf@quit\@undefined\else +\endinput\fi % Same line! +<@Make sure ProvidesFile is defined@> +\ProvidesFile{babel.def}[<@date@> <@version@> Babel common definitions] % \end{macrocode} % -% \end{macro} -% -% \begin{macro}{\defineshorthand} -% -% Currently we only support two groups of user level shorthands, -% named internally |user| and |user@| (language-dependent -% user shorthands). By default, only the first one is taken into -% account, but if the former is also used (in the optional argument -% of |\defineshorthand|) a new level is inserted for it -% (|user@generic|, done by |\bbl@set@user@generic|); we make also -% sure |{}| and |\protect| are taken into account in this new top -% level. +% The file |babel.def| expects some definitions made in the \LaTeXe{} +% style file. So, In \LaTeX2.09 and Plain{} we must provide at least +% some predefined values as well some tools to set them (even if not +% all options are available). There are no package options, and +% therefore and alternative mechanism is provided. For the moment, +% only |\babeloptionstrings| and |\babeloptionmath| are provided, +% which can be defined before loading \babel. |\BabelModifiers| can be +% set too (but not sure it works). % % \begin{macrocode} -\def\user@language@group{user@\language@group} -\def\bbl@set@user@generic#1#2{% - \bbl@ifunset{user@generic@active#1}% - {\bbl@active@def#1\user@language@group{user@active}{user@generic@active}% - \bbl@active@def#1\user@group{user@generic@active}{language@active}% - \expandafter\edef\csname#2@sh@#1@@\endcsname{% - \expandafter\noexpand\csname normal@char#1\endcsname}% - \expandafter\edef\csname#2@sh@#1@\string\protect@\endcsname{% - \expandafter\noexpand\csname user@active#1\endcsname}}% - \@empty} -\newcommand\defineshorthand[3][user]{% - \edef\bbl@tempa{\zap@space#1 \@empty}% - \bbl@for\bbl@tempb\bbl@tempa{% - \if*\expandafter\@car\bbl@tempb\@nil - \edef\bbl@tempb{user@\expandafter\@gobble\bbl@tempb}% - \@expandtwoargs - \bbl@set@user@generic{\expandafter\string\@car#2\@nil}\bbl@tempb - \fi - \declare@shorthand{\bbl@tempb}{#2}{#3}}} +\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 + \ifx\babeloptionstrings\@undefined + \let\bbl@opt@strings\@nnil + \else + \let\bbl@opt@strings\babeloptionstrings + \fi + \def\BabelStringsDefault{generic} + \def\bbl@tempa{normal} + \ifx\babeloptionmath\bbl@tempa + \def\bbl@mathnormal{\noexpand\textormath} + \fi + \def\AfterBabelLanguage#1#2{} + \ifx\BabelModifiers\@undefined\let\BabelModifiers\relax\fi + \let\bbl@afterlang\relax + \def\bbl@opt@safe{BR} + \ifx\@uclclist\@undefined\let\@uclclist\@empty\fi + \ifx\bbl@trace\@undefined\def\bbl@trace#1{}\fi + \expandafter\newif\csname ifbbl@single\endcsname +\fi % \end{macrocode} % -% \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. +% Exit immediately with 2.09. An error is raised by the sty file, but +% also try to minimize the number of errors. % % \begin{macrocode} -\def\languageshorthands#1{\def\language@group{#1}} +\ifx\bbl@trace\@undefined + \let\LdfInit\endinput + \def\ProvidesLanguage#1{\endinput} +\endinput\fi % Same line! % \end{macrocode} % -% \end{macro} +% And continue. % -% \begin{macro}{\aliasshorthand} -% First the new shorthand needs to be initialized, +% \section{Multiple languages} % -% \begin{macrocode} -\def\aliasshorthand#1#2{% - \bbl@ifshorthand{#2}% - {\expandafter\ifx\csname active@char\string#2\endcsname\relax - \ifx\document\@notprerr - \@notshorthand{#2}% - \else - \initiate@active@char{#2}% -% \end{macrocode} +% This is not a separate file (\texttt{switch.def}) anymore. % -% 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"|. +% 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} - \expandafter\let\csname active@char\string#2\expandafter\endcsname - \csname active@char\string#1\endcsname - \expandafter\let\csname normal@char\string#2\expandafter\endcsname - \csname normal@char\string#1\endcsname - \bbl@activate{#2}% - \fi - \fi}% - {\bbl@error - {Cannot declare a shorthand turned off (\string#2)} - {Sorry, but you cannot use shorthands which have been\\% - turned off in the package options}}} +<@Define core switching macros@> % \end{macrocode} % -% \end{macro} -% -% \begin{macro}{\@notshorthand} +% \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\@notshorthand#1{% - \bbl@error{% - The character `\string #1' should be made a shorthand character;\\% - add the command \string\useshorthands\string{#1\string} to - the preamble.\\% - I will ignore your instruction}% - {You may proceed, but expect unexpected results}} +\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} % -% \begin{macro}{\shorthandon} -% \begin{macro}{\shorthandoff} -% The first level definition of these macros just passes the -% argument on to |\bbl@switch@sh|, adding |\@nil| at the end to -% denote the end of the list of characters. +% |\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} -\newcommand*\shorthandon[1]{\bbl@switch@sh\@ne#1\@nnil} -\DeclareRobustCommand*\shorthandoff{% - \@ifstar{\bbl@shorthandoff\tw@}{\bbl@shorthandoff\z@}} -\def\bbl@shorthandoff#1#2{\bbl@switch@sh#1#2\@nnil} +\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} % -% \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 -% 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. -% -% 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. +% 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@switch@sh#1#2{% - \ifx#2\@nnil\else - \bbl@ifunset{bbl@active@\string#2}% - {\bbl@error - {I cannot switch `\string#2' on or off--not a shorthand}% - {This character is not a shorthand. Maybe you made\\% - a typing mistake? I will ignore your instruction}}% - {\ifcase#1% - \catcode`#212\relax - \or - \catcode`#2\active - \or - \csname bbl@oricat@\string#2\endcsname - \csname bbl@oridef@\string#2\endcsname - \fi}% - \bbl@afterfi\bbl@switch@sh#1% +\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} % -% \end{macro} -% \end{macro} -% \end{macro} -% -% Note the value is that at the expansion time, eg, in the preample -% shorhands are usually deactivated. +% \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\babelshorthand{\active@prefix\babelshorthand\bbl@putsh} -\def\bbl@putsh#1{% - \bbl@ifunset{bbl@active@\string#1}% - {\bbl@putsh@i#1\@empty\@nnil}% - {\csname bbl@active@\string#1\endcsname}} -\def\bbl@putsh@i#1#2\@nnil{% - \csname\languagename @sh@\string#1@% - \ifx\@empty#2\else\string#2@\fi\endcsname} -\ifx\bbl@opt@shorthands\@nnil\else - \let\bbl@s@initiate@active@char\initiate@active@char - \def\initiate@active@char#1{% - \bbl@ifshorthand{#1}{\bbl@s@initiate@active@char{#1}}{}} - \let\bbl@s@switch@sh\bbl@switch@sh - \def\bbl@switch@sh#1#2{% - \ifx#2\@nnil\else - \bbl@afterfi - \bbl@ifshorthand{#2}{\bbl@s@switch@sh#1{#2}}{\bbl@switch@sh#1}% - \fi} - \let\bbl@s@activate\bbl@activate - \def\bbl@activate#1{% - \bbl@ifshorthand{#1}{\bbl@s@activate{#1}}{}} - \let\bbl@s@deactivate\bbl@deactivate - \def\bbl@deactivate#1{% - \bbl@ifshorthand{#1}{\bbl@s@deactivate{#1}}{}} -\fi +\def\iflanguage#1{% + \bbl@iflanguage{#1}{% + \ifnum\csname l@#1\endcsname=\language + \expandafter\@firstoftwo + \else + \expandafter\@secondoftwo + \fi}} % \end{macrocode} % -% You may want to test if a character is a shorthand. Note it does not -% test whether the shorthand is on or off. +% \end{macro} % -% \begin{macrocode} -\newcommand\ifbabelshorthand[3]{\bbl@ifunset{bbl@active@\string#1}{#3}{#2}} -% \end{macrocode} +% \subsection{Selecting the language} % -% \begin{macro}{\bbl@prim@s} -% \begin{macro}{\bbl@pr@m@s} +% \begin{macro}{\selectlanguage} % -% One of the internal macros that are involved in substituting |\prime| -% for each right quote in mathmode is |\prim@s|. This checks if the -% next character is a right quote. When the right quote is active, the -% definition of this macro needs to be adapted to look also for an -% active right quote; the hat could be active, too. +% 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} -\def\bbl@prim@s{% - \prime\futurelet\@let@token\bbl@pr@m@s} -\def\bbl@if@primes#1#2{% - \ifx#1\@let@token - \expandafter\@firstoftwo - \else\ifx#2\@let@token - \bbl@afterelse\expandafter\@firstoftwo - \else - \bbl@afterfi\expandafter\@secondoftwo - \fi\fi} -\begingroup - \catcode`\^=7 \catcode`\*=\active \lccode`\*=`\^ - \catcode`\'=12 \catcode`\"=\active \lccode`\"=`\' - \lowercase{% - \gdef\bbl@pr@m@s{% - \bbl@if@primes"'% - \pr@@@s - {\bbl@if@primes*^\pr@@@t\egroup}}} -\endgroup +\let\bbl@select@type\z@ +\edef\selectlanguage{% + \noexpand\protect + \expandafter\noexpand\csname selectlanguage \endcsname} % \end{macrocode} % -% \end{macro} -% \end{macro} -% -% Usually the |~| is active and expands to \verb*=\penalty\@M\ =. -% When it is written to the \file{.aux} file it is written -% expanded. To prevent that and to be able to use the character |~| -% as a start character for a shorthand, it is redefined here as a -% one character shorthand on system level. The system declaration -% is in most cases redundant (when |~| is still a non-break space), -% and in some cases is inconvenient (if |~| has been redefined); -% however, for backward compatibility it is maintained (some -% existing documents may rely on the \babel{} value). +% 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} -\initiate@active@char{~} -\declare@shorthand{system}{~}{\leavevmode\nobreak\ } -\bbl@activate{~} +\ifx\@undefined\protect\let\protect\relax\fi % \end{macrocode} % -% \begin{macro}{\OT1dqpos} -% \begin{macro}{\T1dqpos} -% The position of the double quote character is different for the -% OT1 and T1 encodings. It will later be selected using the -% |\f@encoding| macro. Therefore we define two macros here to store -% the position of the character in these encodings. +% The following definition is preserved for backwards compatibility. It +% is related to a trick for 2.09. % % \begin{macrocode} -\expandafter\def\csname OT1dqpos\endcsname{127} -\expandafter\def\csname T1dqpos\endcsname{4} +\let\xstring\string % \end{macrocode} % -% When the macro |\f@encoding| is undefined (as it is in plain -% \TeX) we define it here to expand to \texttt{OT1} -% -% \begin{macrocode} -\ifx\f@encoding\@undefined - \def\f@encoding{OT1} -\fi -% \end{macrocode} +% \end{macro} % -% \end{macro} -% \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. % -% \subsection{Language attributes} +% \begin{macro}{\bbl@pop@language} % -% Language attributes provide a means to give the user control over -% which features of the language definition files he wants to -% enable. -% \begin{macro}{\languageattribute} +% \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. % -% The macro |\languageattribute| checks whether its arguments are -% valid and then activates the selected language attribute. -% First check whether the language is known, and then process each -% attribute in the list. +% \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} -\bbl@trace{Language attributes} -\newcommand\languageattribute[2]{% - \def\bbl@tempc{#1}% - \bbl@fixname\bbl@tempc - \bbl@iflanguage\bbl@tempc{% - \bbl@vforeach{#2}{% +\def\bbl@language@stack{} % \end{macrocode} % -% We want to make sure that each attribute is selected only once; -% therefore we store the already selected attributes in -% |\bbl@known@attribs|. When that control sequence is not yet -% defined this attribute is certainly not selected before. +% 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} - \ifx\bbl@known@attribs\@undefined - \in@false - \else - \bbl@xin@{,\bbl@tempc-##1,}{,\bbl@known@attribs,}% - \fi - \ifin@ - \bbl@warning{% - You have more than once selected the attribute '##1'\\% - for language #1. Reported}% - \else +\def\bbl@push@language{% + \ifx\languagename\@undefined\else + \xdef\bbl@language@stack{\languagename+\bbl@language@stack}% + \fi} % \end{macrocode} % -% When we end up here the attribute is not selected before. So, we -% add it to the list of selected attributes and execute the -% associated \TeX-code. +% 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} - \bbl@exp{% - \\\bbl@add@list\\\bbl@known@attribs{\bbl@tempc-##1}}% - \edef\bbl@tempa{\bbl@tempc-##1}% - \expandafter\bbl@ifknown@ttrib\expandafter{\bbl@tempa}\bbl@attributes% - {\csname\bbl@tempc @attr@##1\endcsname}% - {\@attrerr{\bbl@tempc}{##1}}% - \fi}}} +\def\bbl@pop@lang#1+#2{% + \edef\languagename{#1}\xdef#3{#2}} % \end{macrocode} % -% This command should only be used in the preamble of a document. +% \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} -\@onlypreamble\languageattribute -% \end{macrocode} -% -% The error text to be issued when an unknown attribute is -% selected. -% -% \begin{macrocode} -\newcommand*{\@attrerr}[2]{% - \bbl@error - {The attribute #2 is unknown for language #1.}% - {Your command will be ignored, type to proceed}} +\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} % -% \begin{macro}{\bbl@declare@ttribute} -% This command adds the new language/attribute combination to the -% list of known attributes. +% 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). % -% Then it defines a control sequence to be executed when the -% attribute is used in a document. The result of this should be -% that the macro |\extras...| for the current language is extended, -% otherwise the attribute will not work as its code is removed from -% memory at |\begin{document}|. +% \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} -\def\bbl@declare@ttribute#1#2#3{% - \bbl@xin@{,#2,}{,\BabelModifiers,}% - \ifin@ - \AfterBabelLanguage{#1}{\languageattribute{#1}{#2}}% - \fi - \bbl@add@list\bbl@attributes{#1-#2}% - \expandafter\def\csname#1@attr@#2\endcsname{#3}} +\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@ifattributeset} -% This internal macro has 4 arguments. It can be used to interpret -% \TeX\ code based on whether a certain attribute was set. This -% command should appear inside the argument to |\AtBeginDocument| -% because the attributes are set in the document preamble, -% \emph{after} \babel\ is loaded. -% -% The first argument is the language, the second argument the -% attribute being checked, and the third and fourth arguments are -% the true and false clauses. +% \begin{macro}{\bbl@set@language} % -% \begin{macrocode} -\def\bbl@ifattributeset#1#2#3#4{% -% \end{macrocode} +% 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. % -% First we need to find out if any attributes were set; if not -% we're done. +% We also write a command to change the current language in the +% auxiliary files. % % \begin{macrocode} - \ifx\bbl@known@attribs\@undefined - \in@false +\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} % -% The we need to check the list of known attributes. +% \end{macro} % -% \begin{macrocode} - \bbl@xin@{,#1-#2,}{,\bbl@known@attribs,}% - \fi -% \end{macrocode} +% 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. % -% 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|'. +% 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} - \ifin@ - \bbl@afterelse#3% +\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 - \bbl@afterfi#4% + \ifbbl@usedategroup % if \foreign... within \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- + % > 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} % -% \end{macro} +% \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. % -% \begin{macro}{\bbl@ifknown@ttrib} -% An internal macro to check whether a given language/attribute is -% known. The macro takes 4 arguments, the language/attribute, the -% attribute list, the \TeX-code to be executed when the attribute -% is known and the \TeX-code to be executed otherwise. +% The |\ignorespaces| command is necessary to hide the environment +% when it is entered in horizontal mode. % % \begin{macrocode} -\def\bbl@ifknown@ttrib#1#2{% +\long\def\otherlanguage#1{% + \ifnum\bbl@hymapsel=\@cclv\let\bbl@hymapsel\thr@@\fi + \csname selectlanguage \endcsname{#1}% + \ignorespaces} % \end{macrocode} % -% We first assume the attribute is unknown. +% The |\endotherlanguage| part of the environment tries to hide +% itself when it is called in horizontal mode. % % \begin{macrocode} - \let\bbl@tempa\@secondoftwo +\long\def\endotherlanguage{% + \global\@ignoretrue\ignorespaces} % \end{macrocode} % -% Then we loop over the list of known attributes, trying to find a -% match. +% \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} - \bbl@loopx\bbl@tempb{#2}{% - \expandafter\in@\expandafter{\expandafter,\bbl@tempb,}{,#1,}% - \ifin@ +\expandafter\def\csname otherlanguage*\endcsname#1{% + \ifnum\bbl@hymapsel=\@cclv\chardef\bbl@hymapsel4\relax\fi + \foreign@language{#1}} % \end{macrocode} % -% When a match is found the definition of |\bbl@tempa| is changed. +% 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} - \let\bbl@tempa\@firstoftwo - \else - \fi}% +\expandafter\let\csname endotherlanguage*\endcsname\relax % \end{macrocode} % -% Finally we execute |\bbl@tempa|. +% \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} - \bbl@tempa -} +\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}{\bbl@clear@ttribs} -% This macro removes all the attribute code from \LaTeX's memory at -% |\begin{document}| time (if any is present). +% \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\bbl@clear@ttribs{% - \ifx\bbl@attributes\@undefined\else - \bbl@loopx\bbl@tempa{\bbl@attributes}{% - \expandafter\bbl@clear@ttrib\bbl@tempa. - }% - \let\bbl@attributes\@undefined - \fi} -\def\bbl@clear@ttrib#1-#2.{% - \expandafter\let\csname#1@attr@#2\endcsname\@undefined} -\AtBeginDocument{\bbl@clear@ttribs} +\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} % -% \subsection{Support for saving macro definitions} -% -% To save the meaning of control sequences using |\babel@save|, we -% use temporary control sequences. To save hash table entries for -% these control sequences, we don't use the name of the control -% sequence to be saved to construct the temporary name. Instead we -% simply use the value of a counter, which is reset to zero each time -% we begin to save new values. This works well because we release -% the saved meanings before we begin to save a new set of control -% sequence meanings (see |\selectlanguage| and |\originalTeX|). Note -% undefined macros are not undefined any more when saved -- they are -% |\relax|'ed. -% -% \begin{macro}{\babel@savecnt} -% \begin{macro}{\babel@beginsave} -% The initialization of a new save cycle: reset the counter to -% zero. +% \begin{macro}{\bbl@patterns} % -% \begin{macrocode} -\bbl@trace{Macros for saving definitions} -\def\babel@beginsave{\babel@savecnt\z@} -% \end{macrocode} +% 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. % -% Before it's forgotten, allocate the counter and initialize all. +% 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} -\newcount\babel@savecnt -\babel@beginsave +\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} -% \end{macro} % -% \begin{macro}{\babel@save} -% \begin{macro}{\babel@savevariable} +% \begin{environment}{hyphenrules} % -% 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 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\babel@save#1{% - \expandafter\let\csname babel@\number\babel@savecnt\endcsname#1\relax - \toks@\expandafter{\originalTeX\let#1=}% - \bbl@exp{% - \def\\\originalTeX{\the\toks@\\relax}}% - \advance\babel@savecnt\@ne} -\def\babel@savevariable#1{% - \toks@\expandafter{\originalTeX #1=}% - \bbl@exp{\def\\\originalTeX{\the\toks@\the#1\relax}}} +\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{macro} -% \end{macro} +% \end{environment} % -% \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. +% \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\bbl@frenchspacing{% - \ifnum\the\sfcode`\.=\@m - \let\bbl@nonfrenchspacing\relax - \else - \frenchspacing - \let\bbl@nonfrenchspacing\nonfrenchspacing +\def\providehyphenmins#1#2{% + \expandafter\ifx\csname #1hyphenmins\endcsname\relax + \@namedef{#1hyphenmins}{#2}% \fi} -\let\bbl@nonfrenchspacing\nonfrenchspacing % \end{macrocode} % % \end{macro} -% \end{macro} % -% \subsection{Short tags} -% -% \begin{macro}{\babeltags} -% This macro is straightforward. After zapping spaces, we -% loop over the list and define the macros |\text|\m{tag} and -% |\|\m{tag}. Definitions are first expanded so that they don't -% contain |\csname| but the actual macro. +% \begin{macro}{\set@hyphenmins} +% This macro sets the values of |\lefthyphenmin| and +% |\righthyphenmin|. It expects two values as its argument. % -% \begin{macrocode} -\bbl@trace{Short tags} -\def\babeltags#1{% - \edef\bbl@tempa{\zap@space#1 \@empty}% - \def\bbl@tempb##1=##2\@@{% - \edef\bbl@tempc{% - \noexpand\newcommand - \expandafter\noexpand\csname ##1\endcsname{% - \noexpand\protect - \expandafter\noexpand\csname otherlanguage*\endcsname{##2}} - \noexpand\newcommand - \expandafter\noexpand\csname text##1\endcsname{% - \noexpand\foreignlanguage{##2}}} - \bbl@tempc}% - \bbl@for\bbl@tempa\bbl@tempa{% - \expandafter\bbl@tempb\bbl@tempa\@@}} +% \begin{macrocode} +\def\set@hyphenmins#1#2{% + \lefthyphenmin#1\relax + \righthyphenmin#2\relax} % \end{macrocode} % % \end{macro} % -% \subsection{Hyphens} -% -% \begin{macro}{\babelhyphenation} +% \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. % -% This macro saves hyphenation exceptions. Two macros are used to -% store them: |\bbl@hyphenation@| for the global ones and -% |\bbl@hyphenation| for language ones. See |\bbl@patterns| -% above for further details. We make sure there is a space between -% words when multiple commands are used. +% Depending on the format, ie, on if the former is defined, we use +% a similar definition or not. % % \begin{macrocode} -\bbl@trace{Hyphens} -\@onlypreamble\babelhyphenation -\AtEndOfPackage{% - \newcommand\babelhyphenation[2][\@empty]{% - \ifx\bbl@hyphenation@\relax - \let\bbl@hyphenation@\@empty - \fi - \ifx\bbl@hyphlist\@empty\else - \bbl@warning{% - You must not intermingle \string\selectlanguage\space and\\% - \string\babelhyphenation\space or some exceptions will not\\% - be taken into account. Reported}% - \fi - \ifx\@empty#1% - \protected@edef\bbl@hyphenation@{\bbl@hyphenation@\space#2}% - \else - \bbl@vforeach{#1}{% - \def\bbl@tempa{##1}% - \bbl@fixname\bbl@tempa - \bbl@iflanguage\bbl@tempa{% - \bbl@csarg\protected@edef{hyphenation@\bbl@tempa}{% - \bbl@ifunset{bbl@hyphenation@\bbl@tempa}% - \@empty - {\csname bbl@hyphenation@\bbl@tempa\endcsname\space}% - #2}}}% - \fi}} +\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}{\bbl@allowhyphens} +% \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} % -% 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.}. +% 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} -\def\bbl@allowhyphens{\ifvmode\else\nobreak\hskip\z@skip\fi} -\def\bbl@t@one{T1} -\def\allowhyphens{\ifx\cf@encoding\bbl@t@one\else\bbl@allowhyphens\fi} +\ifx\babel@beginsave\@undefined\let\babel@beginsave\relax\fi % \end{macrocode} % % \end{macro} % -% \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|. +% A few macro names are reserved for future releases of \babel, which +% will use the concept of `locale': % % \begin{macrocode} -\newcommand\babelnullhyphen{\char\hyphenchar\font} -\def\babelhyphen{\active@prefix\babelhyphen\bbl@hyphen} -\def\bbl@hyphen{% - \@ifstar{\bbl@hyphen@i @}{\bbl@hyphen@i\@empty}} -\def\bbl@hyphen@i#1#2{% - \bbl@ifunset{bbl@hy@#1#2\@empty}% - {\csname bbl@#1usehyphen\endcsname{\discretionary{#2}{}{#2}}}% - {\csname bbl@hy@#1#2\@empty\endcsname}} +\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} % -% 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. +% \subsection{Errors} % -% 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{macro}{\@nolanerr} +% \begin{macro}{\@nopatterns} % -% \begin{macrocode} -\def\bbl@usehyphen#1{% - \leavevmode - \ifdim\lastskip>\z@\mbox{#1}\else\nobreak#1\fi - \nobreak\hskip\z@skip} -\def\bbl@@usehyphen#1{% - \leavevmode\ifdim\lastskip>\z@\mbox{#1}\else#1\fi} -% \end{macrocode} +% 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. % -% The following macro inserts the hyphen char. +% \begin{macro}{\@noopterr} +% When the package was loaded without options not everything will +% work as expected. An error message is issued in that case. % -% \begin{macrocode} -\def\bbl@hyphenchar{% - \ifnum\hyphenchar\font=\m@ne - \babelnullhyphen - \else - \char\hyphenchar\font - \fi} -% \end{macrocode} +% 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'. % -% Finally, we define the hyphen ``types''. Their names will not -% change, so you may use them in |ldf|'s. After a space, the -% |\mbox| in |\bbl@hy@nobreak| is redundant. +% 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} -\def\bbl@hy@soft{\bbl@usehyphen{\discretionary{\bbl@hyphenchar}{}{}}} -\def\bbl@hy@@soft{\bbl@@usehyphen{\discretionary{\bbl@hyphenchar}{}{}}} -\def\bbl@hy@hard{\bbl@usehyphen\bbl@hyphenchar} -\def\bbl@hy@@hard{\bbl@@usehyphen\bbl@hyphenchar} -\def\bbl@hy@nobreak{\bbl@usehyphen{\mbox{\bbl@hyphenchar}}} -\def\bbl@hy@@nobreak{\mbox{\bbl@hyphenchar}} -\def\bbl@hy@repeat{% - \bbl@usehyphen{% - \discretionary{\bbl@hyphenchar}{\bbl@hyphenchar}{\bbl@hyphenchar}}} -\def\bbl@hy@@repeat{% - \bbl@@usehyphen{% - \discretionary{\bbl@hyphenchar}{\bbl@hyphenchar}{\bbl@hyphenchar}}} -\def\bbl@hy@empty{\hskip\z@skip} -\def\bbl@hy@@empty{\discretionary{}{}{}} +\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 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} % -% \end{macro} -% -% \begin{macro}{\bbl@disc} -% For some languages the macro |\bbl@disc| is used to ease the -% insertion of discretionaries for letters that behave `abnormally' -% at a breakpoint. +% Here ended |switch.def|. % % \begin{macrocode} -\def\bbl@disc#1#2{\nobreak\discretionary{#2-}{}{#1}\bbl@allowhyphens} +\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 % TODO. Remove hardcoded number + \ifeof1 + \closein1 + \message{I couldn't find the file language.def} + \else + \closein1 + \begingroup + \def\addlanguage#1#2#3#4#5{% + \expandafter\ifx\csname lang@#1\endcsname\relax\else + \global\expandafter\let\csname l@#1\expandafter\endcsname + \csname lang@#1\endcsname + \fi}% + \def\uselanguage#1{}% + \input language.def + \endgroup + \fi + \fi + \chardef\l@english\z@ +\fi % \end{macrocode} % -% \end{macro} +% \begin{macro}{\addto} +% It takes two arguments, a \meta{control sequence} and \TeX-code to +% be added to the \meta{control sequence}. % -% \subsection{Multiencoding strings} +% 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. % -% 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 -% pseudo-guards, so we start with the basic commands. +% \begin{macrocode} +\def\addto#1#2{% + \ifx#1\@undefined + \def#1{#2}% + \else + \ifx#1\relax + \def#1{#2}% + \else + {\toks@\expandafter{#1#2}% + \xdef#1{\the\toks@}}% + \fi + \fi} +% \end{macrocode} % -% \paragraph{Tools} +% \end{macro} % -% But first, a couple of tools. The first one makes global a local -% variable. This is not the best solution, but it works. +% 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} -\bbl@trace{Multiencoding strings} -\def\bbl@toglobal#1{\global\let#1#1} -\def\bbl@recatcode#1{% - \@tempcnta="7F - \def\bbl@tempa{% - \ifnum\@tempcnta>"FF\else - \catcode\@tempcnta=#1\relax - \advance\@tempcnta\@ne - \expandafter\bbl@tempa - \fi}% - \bbl@tempa} +\def\bbl@withactive#1#2{% + \begingroup + \lccode`~=`#2\relax + \lowercase{\endgroup#1~}} % \end{macrocode} % -% The second one. We need to patch |\@uclclist|, but it is done once -% and only if |\SetCase| is used or if strings are encoded. The code -% is far from satisfactory for several reasons, including the fact -% |\@uclclist| is not a list any more. Therefore a package option is -% added to ignore it. Instead of gobbling the macro -% getting the next two elements (usually |\reserved@a|), we pass it as -% argument to |\bbl@uclc|. The parser is restarted inside -% |\|\m{lang}|@bbl@uclc| because we do not know how many expansions -% are necessary (depends on whether strings are encoded). The last -% part is tricky -- when uppercasing, we have: -%\begin{verbatim} -% \let\bbl@tolower\@empty\bbl@toupper\@empty -%\end{verbatim} -% and starts over (and similarly when lowercasing). +% \begin{macro}{\bbl@redefine} % -% \begin{macrocode} -\@ifpackagewith{babel}{nocase}% - {\let\bbl@patchuclc\relax}% - {\def\bbl@patchuclc{% - \global\let\bbl@patchuclc\relax - \g@addto@macro\@uclclist{\reserved@b{\reserved@b\bbl@uclc}}% - \gdef\bbl@uclc##1{% - \let\bbl@encoded\bbl@encoded@uclc - \bbl@ifunset{\languagename @bbl@uclc}% and resumes it - {##1}% - {\let\bbl@tempa##1\relax % Used by LANG@bbl@uclc - \csname\languagename @bbl@uclc\endcsname}% - {\bbl@tolower\@empty}{\bbl@toupper\@empty}}% - \gdef\bbl@tolower{\csname\languagename @bbl@lc\endcsname}% - \gdef\bbl@toupper{\csname\languagename @bbl@uc\endcsname}}} -% \end{macrocode} +% 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} -%<<*More package options>> -\DeclareOption{nocase}{} -%<> +\def\bbl@redefine#1{% + \edef\bbl@tempa{\bbl@stripslash#1}% + \expandafter\let\csname org@\bbl@tempa\endcsname#1% + \expandafter\def\csname\bbl@tempa\endcsname} +\@onlypreamble\bbl@redefine % \end{macrocode} % -% The following package options control the behavior of |\SetString|. +% \end{macro} +% +% \begin{macro}{\bbl@redefine@long} +% This version of |\babel@redefine| can be used to redefine |\long| +% commands such as |\ifthenelse|. % % \begin{macrocode} -%<<*More package options>> -\let\bbl@opt@strings\@nnil % accept strings=value -\DeclareOption{strings}{\def\bbl@opt@strings{\BabelStringsDefault}} -\DeclareOption{strings=encoded}{\let\bbl@opt@strings\relax} -\def\BabelStringsDefault{generic} -%<> +\def\bbl@redefine@long#1{% + \edef\bbl@tempa{\bbl@stripslash#1}% + \expandafter\let\csname org@\bbl@tempa\endcsname#1% + \expandafter\long\expandafter\def\csname\bbl@tempa\endcsname} +\@onlypreamble\bbl@redefine@long % \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. +% \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{macrocode} -\@onlypreamble\StartBabelCommands -\def\StartBabelCommands{% - \begingroup - \bbl@recatcode{11}% - <@Macros local to BabelCommands@> - \def\bbl@provstring##1##2{% - \providecommand##1{##2}% - \bbl@toglobal##1}% - \global\let\bbl@scafter\@empty - \let\StartBabelCommands\bbl@startcmds - \ifx\BabelLanguages\relax - \let\BabelLanguages\CurrentOption - \fi - \begingroup - \let\bbl@screset\@nnil % local flag - disable 1st stopcommands - \StartBabelCommands} -\def\bbl@startcmds{% - \ifx\bbl@screset\@nnil\else - \bbl@usehooks{stopcommands}{}% - \fi - \endgroup - \begingroup - \@ifstar - {\ifx\bbl@opt@strings\@nnil - \let\bbl@opt@strings\BabelStringsDefault - \fi - \bbl@startcmds@i}% - \bbl@startcmds@i} -\def\bbl@startcmds@i#1#2{% - \edef\bbl@L{\zap@space#1 \@empty}% - \edef\bbl@G{\zap@space#2 \@empty}% - \bbl@startcmds@ii} -\let\bbl@startcommands\StartBabelCommands +\def\bbl@redefinerobust#1{% + \edef\bbl@tempa{\bbl@stripslash#1}% + \bbl@ifunset{\bbl@tempa\space}% + {\expandafter\let\csname org@\bbl@tempa\endcsname#1% + \bbl@exp{\def\\#1{\\\protect\<\bbl@tempa\space>}}}% + {\bbl@exp{\let\\<\bbl@tempa\space>}}% + \@namedef{\bbl@tempa\space}} +\@onlypreamble\bbl@redefinerobust % \end{macrocode} % -% Parse the encoding info to get the label, input, and font parts. +% \end{macro} % -% 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. +% \subsection{Hooks} % -% 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. +% 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} -\newcommand\bbl@startcmds@ii[1][\@empty]{% - \let\SetString\@gobbletwo - \let\bbl@stringdef\@gobbletwo - \let\AfterBabelCommands\@gobble - \ifx\@empty#1% - \def\bbl@sc@label{generic}% - \def\bbl@encstring##1##2{% - \ProvideTextCommandDefault##1{##2}% - \bbl@toglobal##1% - \expandafter\bbl@toglobal\csname\string?\string##1\endcsname}% - \let\bbl@sctest\in@true - \else - \let\bbl@sc@charset\space % <- zapped below - \let\bbl@sc@fontenc\space % <- " " - \def\bbl@tempa##1=##2\@nil{% - \bbl@csarg\edef{sc@\zap@space##1 \@empty}{##2 }}% - \bbl@vforeach{label=#1}{\bbl@tempa##1\@nil}% - \def\bbl@tempa##1 ##2{% space -> comma - ##1% - \ifx\@empty##2\else\ifx,##1,\else,\fi\bbl@afterfi\bbl@tempa##2\fi}% - \edef\bbl@sc@fontenc{\expandafter\bbl@tempa\bbl@sc@fontenc\@empty}% - \edef\bbl@sc@label{\expandafter\zap@space\bbl@sc@label\@empty}% - \edef\bbl@sc@charset{\expandafter\zap@space\bbl@sc@charset\@empty}% - \def\bbl@encstring##1##2{% - \bbl@foreach\bbl@sc@fontenc{% - \bbl@ifunset{T@####1}% - {}% - {\ProvideTextCommand##1{####1}{##2}% - \bbl@toglobal##1% - \expandafter - \bbl@toglobal\csname####1\string##1\endcsname}}}% - \def\bbl@sctest{% - \bbl@xin@{,\bbl@opt@strings,}{,\bbl@sc@label,\bbl@sc@fontenc,}}% - \fi - \ifx\bbl@opt@strings\@nnil % ie, no strings key -> defaults - \else\ifx\bbl@opt@strings\relax % ie, strings=encoded - \let\AfterBabelCommands\bbl@aftercmds - \let\SetString\bbl@setstring - \let\bbl@stringdef\bbl@encstring - \else % ie, strings=value - \bbl@sctest - \ifin@ - \let\AfterBabelCommands\bbl@aftercmds - \let\SetString\bbl@setstring - \let\bbl@stringdef\bbl@provstring - \fi\fi\fi - \bbl@scswitch - \ifx\bbl@G\@empty - \def\SetString##1##2{% - \bbl@error{Missing group for string \string##1}% - {You must assign strings to some category, typically\\% - captions or extras, but you set none}}% - \fi - \ifx\@empty#1% - \bbl@usehooks{defaultcommands}{}% - \else - \@expandtwoargs - \bbl@usehooks{encodedcommands}{{\bbl@sc@charset}{\bbl@sc@fontenc}}% +\bbl@trace{Hooks} +\newcommand\AddBabelHook[3][]{% + \bbl@ifunset{bbl@hk@#2}{\EnableBabelHook{#2}}{}% + \def\bbl@tempa##1,#3=##2,##3\@empty{\def\bbl@tempb{##2}}% + \expandafter\bbl@tempa\bbl@evargs,#3=,\@empty + \bbl@ifunset{bbl@ev@#2@#3@#1}% + {\bbl@csarg\bbl@add{ev@#3@#1}{\bbl@elt{#2}}}% + {\bbl@csarg\let{ev@#2@#3@#1}\relax}% + \bbl@csarg\newcommand{ev@#2@#3@#1}[\bbl@tempb]} +\newcommand\EnableBabelHook[1]{\bbl@csarg\let{hk@#1}\@firstofone} +\newcommand\DisableBabelHook[1]{\bbl@csarg\let{hk@#1}\@gobble} +\def\bbl@usehooks#1#2{% + \def\bbl@elt##1{% + \bbl@cs{hk@##1}{\bbl@cs{ev@##1@#1@}#2}}% + \bbl@cs{ev@#1@}% + \ifx\languagename\@undefined\else % Test required for Plain (?) + \def\bbl@elt##1{% + \bbl@cs{hk@##1}{\bbl@cl{ev@##1@#1}#2}}% + \bbl@cl{ev@#1}% \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) . +% 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@forlang#1#2{% - \bbl@for#1\bbl@L{% - \bbl@xin@{,#1,}{,\BabelLanguages,}% - \ifin@#2\relax\fi}} -\def\bbl@scswitch{% - \bbl@forlang\bbl@tempa{% - \ifx\bbl@G\@empty\else - \ifx\SetString\@gobbletwo\else - \edef\bbl@GL{\bbl@G\bbl@tempa}% - \bbl@xin@{,\bbl@GL,}{,\bbl@screset,}% - \ifin@\else - \global\expandafter\let\csname\bbl@GL\endcsname\@undefined - \xdef\bbl@screset{\bbl@screset,\bbl@GL}% - \fi - \fi - \fi}} -\AtEndOfPackage{% - \def\bbl@forlang#1#2{\bbl@for#1\bbl@L{\bbl@ifunset{date#1}{}{#2}}}% - \let\bbl@scswitch\relax} -\@onlypreamble\EndBabelCommands -\def\EndBabelCommands{% - \bbl@usehooks{stopcommands}{}% - \endgroup - \endgroup - \bbl@scafter} -\let\bbl@endcommands\EndBabelCommands +% \begin{macrocode} +\def\bbl@evargs{,% <- don't delete this comma + everylanguage=1,loadkernel=1,loadpatterns=1,loadexceptions=1,% + 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=2} % \end{macrocode} % -% Now we define commands to be used inside |\StartBabelCommands|. -% -% \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. +% \begin{macro}{\babelensure} % -% \begin{macrocode} -\def\bbl@setstring#1#2{% - \bbl@forlang\bbl@tempa{% - \edef\bbl@LC{\bbl@tempa\bbl@stripslash#1}% - \bbl@ifunset{\bbl@LC}% eg, \germanchaptername - {\global\expandafter % TODO - con \bbl@exp ? - \bbl@add\csname\bbl@G\bbl@tempa\expandafter\endcsname\expandafter - {\expandafter\bbl@scset\expandafter#1\csname\bbl@LC\endcsname}}% - {}% - \def\BabelString{#2}% - \bbl@usehooks{stringprocess}{}% - \expandafter\bbl@stringdef - \csname\bbl@LC\expandafter\endcsname\expandafter{\BabelString}}} -% \end{macrocode} +% The user command just parses the optional argument and creates a +% new macro named |\bbl@e@|\m{language}. We register a hook at the +% |afterextras| event which just executes this macro in a +% ``complete'' selection (which, if undefined, is |\relax| and does +% nothing). This part is somewhat involved because we have to make +% sure things are expanded the correct number of times. % -% Now, some addtional stuff to be used when encoded strings are -% used. Captions then include |\bbl@encoded| for string to be -% expanded in case transformations. It is |\relax| by default, but -% in |\MakeUppercase| and |\MakeLowercase| its value is a modified -% expandable |\@changed@cmd|. +% The macro |\bbl@e@|\m{language} contains +% |\bbl@ensure|\marg{include}\marg{exclude}\marg{fontenc}, which in in +% turn loops over the macros names in |\bbl@captionslist|, excluding +% (with the help of |\in@|) those in the |exclude| list. If the +% |fontenc| is given (and not |\relax|), the |\fontencoding| is also +% added. Then we loop over the |include| list, but if the macro +% already contains |\foreignlanguage|, nothing is done. Note this +% macro (1) is not restricted to the preamble, and (2) changes are +% local. % % \begin{macrocode} -\ifx\bbl@opt@strings\relax - \def\bbl@scset#1#2{\def#1{\bbl@encoded#2}} - \bbl@patchuclc - \let\bbl@encoded\relax - \def\bbl@encoded@uclc#1{% - \@inmathwarn#1% - \expandafter\ifx\csname\cf@encoding\string#1\endcsname\relax - \expandafter\ifx\csname ?\string#1\endcsname\relax - \TextSymbolUnavailable#1% - \else - \csname ?\string#1\endcsname +\bbl@trace{Defining babelensure} +\newcommand\babelensure[2][]{% TODO - revise test files + \AddBabelHook{babel-ensure}{afterextras}{% + \ifcase\bbl@select@type + \bbl@cl{e}% + \fi}% + \begingroup + \let\bbl@ens@include\@empty + \let\bbl@ens@exclude\@empty + \def\bbl@ens@fontenc{\relax}% + \def\bbl@tempb##1{% + \ifx\@empty##1\else\noexpand##1\expandafter\bbl@tempb\fi}% + \edef\bbl@tempa{\bbl@tempb#1\@empty}% + \def\bbl@tempb##1=##2\@@{\@namedef{bbl@ens@##1}{##2}}% + \bbl@foreach\bbl@tempa{\bbl@tempb##1\@@}% + \def\bbl@tempc{\bbl@ensure}% + \expandafter\bbl@add\expandafter\bbl@tempc\expandafter{% + \expandafter{\bbl@ens@include}}% + \expandafter\bbl@add\expandafter\bbl@tempc\expandafter{% + \expandafter{\bbl@ens@exclude}}% + \toks@\expandafter{\bbl@tempc}% + \bbl@exp{% + \endgroup + \def\{\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 macro exists + \edef##1{\noexpand\bbl@nocaption + {\bbl@stripslash##1}{\languagename\bbl@stripslash##1}}% + \fi + \ifx##1\@empty\else + \in@{##1}{#2}% + \ifin@\else + \bbl@ifunset{bbl@ensure@\languagename}% + {\bbl@exp{% + \\\DeclareRobustCommand\[1]{% + \\\foreignlanguage{\languagename}% + {\ifx\relax#3\else + \\\fontencoding{#3}\\\selectfont + \fi + ########1}}}}% + {}% + \toks@\expandafter{##1}% + \edef##1{% + \bbl@csarg\noexpand{ensure@\languagename}% + {\the\toks@}}% \fi - \else - \csname\cf@encoding\string#1\endcsname - \fi} -\else - \def\bbl@scset#1#2{\def#1{#2}} -\fi + \expandafter\bbl@tempb + \fi}% + \expandafter\bbl@tempb\bbl@captionslist\today\@empty + \def\bbl@tempa##1{% elt for include list + \ifx##1\@empty\else + \bbl@csarg\in@{ensure@\languagename\expandafter}\expandafter{##1}% + \ifin@\else + \bbl@tempb##1\@empty + \fi + \expandafter\bbl@tempa + \fi}% + \bbl@tempa#1\@empty} +\def\bbl@captionslist{% + \prefacename\refname\abstractname\bibname\chaptername\appendixname + \contentsname\listfigurename\listtablename\indexname\figurename + \tablename\partname\enclname\ccname\headtoname\pagename\seename + \alsoname\proofname\glossaryname} % \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. +% \end{macro} % -% \begin{macrocode} -%<<*Macros local to BabelCommands>> -\def\SetStringLoop##1##2{% - \def\bbl@templ####1{\expandafter\noexpand\csname##1\endcsname}% - \count@\z@ - \bbl@loop\bbl@tempa{##2}{% empty items and spaces are ok - \advance\count@\@ne - \toks@\expandafter{\bbl@tempa}% - \bbl@exp{% - \\\SetString\bbl@templ{\romannumeral\count@}{\the\toks@}% - \count@=\the\count@\relax}}}% -%<> -% \end{macrocode} +% \subsection{Setting up language files} % -% \paragraph{Delaying code} Now the definition of -% |\AfterBabelCommands| when it is activated. +% \begin{macro}{\LdfInit} % -% \begin{macrocode} -\def\bbl@aftercmds#1{% - \toks@\expandafter{\bbl@scafter#1}% - \xdef\bbl@scafter{\the\toks@}} -% \end{macrocode} +% |\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. % -% \paragraph{Case mapping} +% 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. % -% The command |\SetCase| provides a way to change the behavior of -% |\MakeUppercase| and |\MakeLowercase|. |\bbl@tempa| is set by the -% patched |\@uclclist| to the parsing command. +% 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. % -% \begin{macrocode} -%<<*Macros local to BabelCommands>> - \newcommand\SetCase[3][]{% - \bbl@patchuclc - \bbl@forlang\bbl@tempa{% - \expandafter\bbl@encstring - \csname\bbl@tempa @bbl@uclc\endcsname{\bbl@tempa##1}% - \expandafter\bbl@encstring - \csname\bbl@tempa @bbl@uc\endcsname{##2}% - \expandafter\bbl@encstring - \csname\bbl@tempa @bbl@lc\endcsname{##3}}}% -%<> -% \end{macrocode} +% 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|. % -% Macros to deal with case mapping for hyphenation. To decide if the -% document is monolingual or multilingual, we make a rough guess -- -% just see if there is a comma in the languages list, built in the -% first pass of the package options. +% If so, we call |\ldf@quit| to set the main language, restore the +% category code of the @-sign and call |\endinput| % -% \begin{macrocode} -%<<*Macros local to BabelCommands>> - \newcommand\SetHyphenMap[1]{% - \bbl@forlang\bbl@tempa{% - \expandafter\bbl@stringdef - \csname\bbl@tempa @bbl@hyphenmap\endcsname{##1}}}% -%<> -% \end{macrocode} +% When |#2| was \emph{not} a control sequence we construct one and +% compare it with |\relax|. % -% There are 3 helper macros which do most of the work for you. -% -% \begin{macrocode} -\newcommand\BabelLower[2]{% one to one. - \ifnum\lccode#1=#2\else - \babel@savevariable{\lccode#1}% - \lccode#1=#2\relax - \fi} -\newcommand\BabelLowerMM[4]{% many-to-many - \@tempcnta=#1\relax - \@tempcntb=#4\relax - \def\bbl@tempa{% - \ifnum\@tempcnta>#2\else - \@expandtwoargs\BabelLower{\the\@tempcnta}{\the\@tempcntb}% - \advance\@tempcnta#3\relax - \advance\@tempcntb#3\relax - \expandafter\bbl@tempa - \fi}% - \bbl@tempa} -\newcommand\BabelLowerMO[4]{% many-to-one - \@tempcnta=#1\relax - \def\bbl@tempa{% - \ifnum\@tempcnta>#2\else - \@expandtwoargs\BabelLower{\the\@tempcnta}{#4}% - \advance\@tempcnta#3 - \expandafter\bbl@tempa - \fi}% - \bbl@tempa} -% \end{macrocode} -% -% The following package options control the behavior of -% hyphenation mapping. -% -% \begin{macrocode} -%<<*More package options>> -\DeclareOption{hyphenmap=off}{\chardef\bbl@opt@hyphenmap\z@} -\DeclareOption{hyphenmap=first}{\chardef\bbl@opt@hyphenmap\@ne} -\DeclareOption{hyphenmap=select}{\chardef\bbl@opt@hyphenmap\tw@} -\DeclareOption{hyphenmap=other}{\chardef\bbl@opt@hyphenmap\thr@@} -\DeclareOption{hyphenmap=other*}{\chardef\bbl@opt@hyphenmap4\relax} -%<> -% \end{macrocode} -% -% Initial setup to provide a default behavior if |hypenmap| -% is not set. +% Finally we check |\originalTeX|. % % \begin{macrocode} -\AtEndOfPackage{% - \ifx\bbl@opt@hyphenmap\@undefined - \bbl@xin@{,}{\bbl@language@opts}% - \chardef\bbl@opt@hyphenmap\ifin@4\else\@ne\fi +\bbl@trace{Macros for setting language files up} +\def\bbl@ldfinit{% TODO. Merge into the next macro? Unused elsewhere + \let\bbl@screset\@empty + \let\BabelStrings\bbl@opt@string + \let\BabelOptions\@empty + \let\BabelLanguages\relax + \ifx\originalTeX\@undefined + \let\originalTeX\@empty + \else + \originalTeX \fi} -% \end{macrocode} -% -% \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. -% -% \begin{macrocode} -\bbl@trace{Macros related to glyphs} -\def\set@low@box#1{\setbox\tw@\hbox{,}\setbox\z@\hbox{#1}% - \dimen\z@\ht\z@ \advance\dimen\z@ -\ht\tw@% - \setbox\z@\hbox{\lower\dimen\z@ \box\z@}\ht\z@\ht\tw@ \dp\z@\dp\tw@} +\def\LdfInit#1#2{% + \chardef\atcatcode=\catcode`\@ + \catcode`\@=11\relax + \chardef\eqcatcode=\catcode`\= + \catcode`\==12\relax + \expandafter\if\expandafter\@backslashchar + \expandafter\@car\string#2\@nil + \ifx#2\@undefined\else + \ldf@quit{#1}% + \fi + \else + \expandafter\ifx\csname#2\endcsname\relax\else + \ldf@quit{#1}% + \fi + \fi + \bbl@ldfinit} % \end{macrocode} % % \end{macro} % -% \begin{macro}{\save@sf@q} -% The macro |\save@sf@q| is used to save and reset the current -% space factor. +% \begin{macro}{\ldf@quit} +% This macro interrupts the processing of a language definition file. % % \begin{macrocode} -\def\save@sf@q#1{\leavevmode - \begingroup - \edef\@SF{\spacefactor\the\spacefactor}#1\@SF - \endgroup} +\def\ldf@quit#1{% + \expandafter\main@language\expandafter{#1}% + \catcode`\@=\atcatcode \let\atcatcode\relax + \catcode`\==\eqcatcode \let\eqcatcode\relax + \endinput} % \end{macrocode} % % \end{macro} % -% \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}. -% -% \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. -% -% \begin{macrocode} -\ProvideTextCommand{\quotedblbase}{OT1}{% - \save@sf@q{\set@low@box{\textquotedblright\/}% - \box\z@\kern-.04em\bbl@allowhyphens}} -% \end{macrocode} +% \begin{macro}{\ldf@finish} +% This macro takes one argument. It is the name of the language +% that was defined in the language definition file. % -% Make sure that when an encoding other than \texttt{OT1} or -% \texttt{T1} is used this glyph can still be typeset. +% We load the local configuration file if one is present, we set +% the main language (taking into account that the argument might be +% a control sequence that needs to be expanded) and reset the +% category code of the @-sign. % % \begin{macrocode} -\ProvideTextCommandDefault{\quotedblbase}{% - \UseTextSymbol{OT1}{\quotedblbase}} +\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{% + \ifx\loadlocalcfg\@undefined\else % For LaTeX 209 + \loadlocalcfg{#1}% + \fi + \bbl@afterldf{#1}% + \expandafter\main@language\expandafter{#1}% + \catcode`\@=\atcatcode \let\atcatcode\relax + \catcode`\==\eqcatcode \let\eqcatcode\relax} % \end{macrocode} % % \end{macro} % -% \begin{macro}{\quotesinglbase} -% We also need the single quote character at the baseline. -% -% \begin{macrocode} -\ProvideTextCommand{\quotesinglbase}{OT1}{% - \save@sf@q{\set@low@box{\textquoteright\/}% - \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. +% After the preamble of the document the commands |\LdfInit|, +% |\ldf@quit| and |\ldf@finish| are no longer needed. Therefore +% they are turned into warning messages in \LaTeX. % % \begin{macrocode} -\ProvideTextCommandDefault{\quotesinglbase}{% - \UseTextSymbol{OT1}{\quotesinglbase}} +\@onlypreamble\LdfInit +\@onlypreamble\ldf@quit +\@onlypreamble\ldf@finish % \end{macrocode} % -% \end{macro} -% -% \begin{macro}{\guillemotleft} -% \begin{macro}{\guillemotright} -% The guillemet characters are not available in \texttt{OT1} -% encoding. They are faked. +% \begin{macro}{\main@language} +% \begin{macro}{\bbl@main@language} +% This command should be used in the various language definition +% files. It stores its argument in |\bbl@main@language|; to be used +% to switch to the correct language at the beginning of the +% document. % % \begin{macrocode} -\ProvideTextCommand{\guillemotleft}{OT1}{% - \ifmmode - \ll - \else - \save@sf@q{\nobreak - \raise.2ex\hbox{$\scriptscriptstyle\ll$}\bbl@allowhyphens}% - \fi} -\ProvideTextCommand{\guillemotright}{OT1}{% - \ifmmode - \gg - \else - \save@sf@q{\nobreak - \raise.2ex\hbox{$\scriptscriptstyle\gg$}\bbl@allowhyphens}% - \fi} +\def\main@language#1{% + \def\bbl@main@language{#1}% + \let\languagename\bbl@main@language % TODO. Set localename + \bbl@id@assign + \bbl@patterns{\languagename}} % \end{macrocode} % -% Make sure that when an encoding other than \texttt{OT1} or -% \texttt{T1} is used these glyphs can still be typeset. +% 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} -\ProvideTextCommandDefault{\guillemotleft}{% - \UseTextSymbol{OT1}{\guillemotleft}} -\ProvideTextCommandDefault{\guillemotright}{% - \UseTextSymbol{OT1}{\guillemotright}} +\def\bbl@beforestart{% + \bbl@usehooks{beforestart}{}% + \global\let\bbl@beforestart\relax} +\AtBeginDocument{% + \@nameuse{bbl@beforestart}% + \if@filesw + \immediate\write\@mainaux{\string\@nameuse{bbl@beforestart}}% + \fi + \expandafter\selectlanguage\expandafter{\bbl@main@language}% + \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 % \end{macrocode} % % \end{macro} % \end{macro} % -% \begin{macro}{\guilsinglleft} -% \begin{macro}{\guilsinglright} -% The single guillemets are not available in \texttt{OT1} -% encoding. They are faked. +% A bit of optimization. Select in heads/foots the language only if +% necessary. % % \begin{macrocode} -\ProvideTextCommand{\guilsinglleft}{OT1}{% - \ifmmode - <% - \else - \save@sf@q{\nobreak - \raise.2ex\hbox{$\scriptscriptstyle<$}\bbl@allowhyphens}% - \fi} -\ProvideTextCommand{\guilsinglright}{OT1}{% - \ifmmode - >% +\def\select@language@x#1{% + \ifcase\bbl@select@type + \bbl@ifsamestring\languagename{#1}{}{\select@language{#1}}% \else - \save@sf@q{\nobreak - \raise.2ex\hbox{$\scriptscriptstyle>$}\bbl@allowhyphens}% + \select@language{#1}% \fi} % \end{macrocode} % -% Make sure that when an encoding other than \texttt{OT1} or -% \texttt{T1} is used these glyphs can still be typeset. +% \subsection{Shorthands} +% +% \begin{macro}{\bbl@add@special} +% The macro |\bbl@add@special| is used to add a new character (or +% single character control sequence) to the macro |\dospecials| +% (and |\@sanitize| if \LaTeX\ is used). It is used only at one +% place, namely when |\initiate@active@char| is called (which is +% ignored if the char has been made active before). Because +% |\@sanitize| can be undefined, we put the definition inside a +% conditional. +% +% Items are added to the lists without checking its existence or +% the original catcode. It does not hurt, but should be fixed. It's +% already done with |\nfss@catcodes|, added in 3.10. % % \begin{macrocode} -\ProvideTextCommandDefault{\guilsinglleft}{% - \UseTextSymbol{OT1}{\guilsinglleft}} -\ProvideTextCommandDefault{\guilsinglright}{% - \UseTextSymbol{OT1}{\guilsinglright}} +\bbl@trace{Shorhands} +\def\bbl@add@special#1{% 1:a macro like \", \?, etc. + \bbl@add\dospecials{\do#1}% test @sanitize = \relax, for back. compat. + \bbl@ifunset{@sanitize}{}{\bbl@add\@sanitize{\@makeother#1}}% + \ifx\nfss@catcodes\@undefined\else % TODO - same for above + \begingroup + \catcode`#1\active + \nfss@catcodes + \ifnum\catcode`#1=\active + \endgroup + \bbl@add\nfss@catcodes{\@makeother#1}% + \else + \endgroup + \fi + \fi} % \end{macrocode} % % \end{macro} -% \end{macro} % -% \subsubsection{Letters} +% \begin{macro}{\bbl@remove@special} % -% \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 companion of the former macro is |\bbl@remove@special|. It +% removes a character from the set macros |\dospecials| and +% |\@sanitize|, but it is not used at all in the \babel{} core. % % \begin{macrocode} -\DeclareTextCommand{\ij}{OT1}{% - i\kern-0.02em\bbl@allowhyphens j} -\DeclareTextCommand{\IJ}{OT1}{% - I\kern-0.02em\bbl@allowhyphens J} -\DeclareTextCommand{\ij}{T1}{\char188} -\DeclareTextCommand{\IJ}{T1}{\char156} -% \end{macrocode} -% -% Make sure that when an encoding other than \texttt{OT1} or -% \texttt{T1} is used these glyphs can still be typeset. -% -% \begin{macrocode} -\ProvideTextCommandDefault{\ij}{% - \UseTextSymbol{OT1}{\ij}} -\ProvideTextCommandDefault{\IJ}{% - \UseTextSymbol{OT1}{\IJ}} +\def\bbl@remove@special#1{% + \begingroup + \def\x##1##2{\ifnum`#1=`##2\noexpand\@empty + \else\noexpand##1\noexpand##2\fi}% + \def\do{\x\do}% + \def\@makeother{\x\@makeother}% + \edef\x{\endgroup + \def\noexpand\dospecials{\dospecials}% + \expandafter\ifx\csname @sanitize\endcsname\relax\else + \def\noexpand\@sanitize{\@sanitize}% + \fi}% + \x} % \end{macrocode} % % \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}{\initiate@active@char} +% A language definition file can call this macro to make a +% character active. This macro takes one argument, the character +% that is to be made active. When the character was already active +% this macro does nothing. Otherwise, this macro defines the +% control sequence |\normal@char|\m{char} to expand to the +% character in its `normal state' and it defines the active +% character to expand to |\normal@char|\m{char} by default +% (\m{char} being the character to be made active). Later its +% definition can be changed to expand to |\active@char|\m{char} +% by calling |\bbl@activate{|\m{char}|}|. % -% 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}). +% For example, to make the double quote character active one could +% have |\initiate@active@char{"}| in a language definition file. +% This defines |"| as |\active@prefix "\active@char"| (where the +% first |"| is the character with its original catcode, when the +% shorthand is created, and |\active@char"| is a single token). In +% protected contexts, it expands to |\protect "| or |\noexpand "| +% (ie, with the original |"|); otherwise |\active@char"| is +% executed. This macro in turn expands to |\normal@char"| in +% ``safe'' contexts (eg, |\label|), but |\user@active"| in normal +% ``unsafe'' ones. The latter search a definition in the user, +% language and system levels, in this order, but if none is found, +% |\normal@char"| is used. However, a deactivated shorthand (with +% |\bbl@deactivate| is defined as |\active@prefix "\normal@char"|. % -% \begin{macrocode} -\def\crrtic@{\hrule height0.1ex width0.3em} -\def\crttic@{\hrule height0.1ex width0.33em} -\def\ddj@{% - \setbox0\hbox{d}\dimen@=\ht0 - \advance\dimen@1ex - \dimen@.45\dimen@ - \dimen@ii\expandafter\rem@pt\the\fontdimen\@ne\font\dimen@ - \advance\dimen@ii.5ex - \leavevmode\rlap{\raise\dimen@\hbox{\kern\dimen@ii\vbox{\crrtic@}}}} -\def\DDJ@{% - \setbox0\hbox{D}\dimen@=.55\ht0 - \dimen@ii\expandafter\rem@pt\the\fontdimen\@ne\font\dimen@ - \advance\dimen@ii.15ex % correction for the dash position - \advance\dimen@ii-.15\fontdimen7\font % correction for cmtt font - \dimen\thr@@\expandafter\rem@pt\the\fontdimen7\font\dimen@ - \leavevmode\rlap{\raise\dimen@\hbox{\kern\dimen@ii\vbox{\crttic@}}}} +% The following macro is used to define shorthands in the three +% levels. It takes 4 arguments: the (string'ed) character, +% |\@group|, |@active| and |@active| +% (except in |system|). % -\DeclareTextCommand{\dj}{OT1}{\ddj@ d} -\DeclareTextCommand{\DJ}{OT1}{\DDJ@ D} +% \begin{macrocode} +\def\bbl@active@def#1#2#3#4{% + \@namedef{#3#1}{% + \expandafter\ifx\csname#2@sh@#1@\endcsname\relax + \bbl@afterelse\bbl@sh@select#2#1{#3@arg#1}{#4#1}% + \else + \bbl@afterfi\csname#2@sh@#1@\endcsname + \fi}% % \end{macrocode} % -% Make sure that when an encoding other than \texttt{OT1} or -% \texttt{T1} is used these glyphs can still be typeset. +% When there is also no current-level shorthand with an argument we +% will check whether there is a next-level defined shorthand for +% this active character. % % \begin{macrocode} -\ProvideTextCommandDefault{\dj}{% - \UseTextSymbol{OT1}{\dj}} -\ProvideTextCommandDefault{\DJ}{% - \UseTextSymbol{OT1}{\DJ}} + \long\@namedef{#3@arg#1}##1{% + \expandafter\ifx\csname#2@sh@#1@\string##1@\endcsname\relax + \bbl@afterelse\csname#4#1\endcsname##1% + \else + \bbl@afterfi\csname#2@sh@#1@\string##1@\endcsname + \fi}}% % \end{macrocode} % -% \end{macro} -% \end{macro} -% -% \begin{macro}{\SS} -% For the \texttt{T1} encoding |\SS| is defined and selects a -% specific glyph from the font, but for other encodings it is not -% available. Therefore we make it available here. +% |\initiate@active@char| calls |\@initiate@active@char| with 3 +% arguments. All of them are the same character with different +% catcodes: active, other (|\string|'ed) and the original one. +% This trick simplifies the code a lot. % % \begin{macrocode} -\DeclareTextCommand{\SS}{OT1}{SS} -\ProvideTextCommandDefault{\SS}{\UseTextSymbol{OT1}{\SS}} +\def\initiate@active@char#1{% + \bbl@ifunset{active@char\string#1}% + {\bbl@withactive + {\expandafter\@initiate@active@char\expandafter}#1\string#1#1}% + {}} % \end{macrocode} % -% \end{macro} -% -% \subsubsection{Shorthands for quotation marks} -% -% Shorthands are provided for a number of different quotation -% marks, which make them usable both outside and inside mathmode. -% They are defined with |\ProvideTextCommandDefault|, but this is -% very likely not required because their definitions are based on -% encoding-dependent macros. -% -% \begin{macro}{\glq} -% \begin{macro}{\grq} -% -% The `german' single quotes. +% The very first thing to do is saving the original catcode and the +% original definition, even if not active, which is possible +% (undefined characters require a special treatement to avoid +% making them |\relax|). % % \begin{macrocode} -\ProvideTextCommandDefault{\glq}{% - \textormath{\quotesinglbase}{\mbox{\quotesinglbase}}} +\def\@initiate@active@char#1#2#3{% + \bbl@csarg\edef{oricat@#2}{\catcode`#2=\the\catcode`#2\relax}% + \ifx#1\@undefined + \bbl@csarg\edef{oridef@#2}{\let\noexpand#1\noexpand\@undefined}% + \else + \bbl@csarg\let{oridef@@#2}#1% + \bbl@csarg\edef{oridef@#2}{% + \let\noexpand#1% + \expandafter\noexpand\csname bbl@oridef@@#2\endcsname}% + \fi % \end{macrocode} % -% The definition of |\grq| depends on the fontencoding. With -% \texttt{T1} encoding no extra kerning is needed. +% If the character is already active we provide the default +% expansion under this shorthand mechanism. Otherwise we write a +% message in the transcript file, and define |\normal@char|\m{char} +% to expand to the character in its default state. If the character +% is mathematically active when \babel{} is loaded (for example +% |'|) the normal expansion is somewhat different to avoid an +% infinite loop (but it does not prevent the loop if the mathcode +% is set to |"8000| \textit{a posteriori}). % % \begin{macrocode} -\ProvideTextCommand{\grq}{T1}{% - \textormath{\kern\z@\textquoteleft}{\mbox{\textquoteleft}}} -\ProvideTextCommand{\grq}{TU}{% - \textormath{\textquoteleft}{\mbox{\textquoteleft}}} -\ProvideTextCommand{\grq}{OT1}{% - \save@sf@q{\kern-.0125em - \textormath{\textquoteleft}{\mbox{\textquoteleft}}% - \kern.07em\relax}} -\ProvideTextCommandDefault{\grq}{\UseTextSymbol{OT1}\grq} + \ifx#1#3\relax + \expandafter\let\csname normal@char#2\endcsname#3% + \else + \bbl@info{Making #2 an active character}% + \ifnum\mathcode`#2=\ifodd\bbl@engine"1000000 \else"8000 \fi + \@namedef{normal@char#2}{% + \textormath{#3}{\csname bbl@oridef@@#2\endcsname}}% + \else + \@namedef{normal@char#2}{#3}% + \fi % \end{macrocode} % -% \end{macro} -% \end{macro} -% -% \begin{macro}{\glqq} -% \begin{macro}{\grqq} -% -% The `german' double quotes. +% To prevent problems with the loading of other packages after +% \babel\ we reset the catcode of the character to the original one +% at the end of the package and of each language file (except with +% \textsf{KeepShorthandsActive}). It is re-activate again at +% |\begin{document}|. We also need to make sure that the +% shorthands are active during the processing of the \file{.aux} +% file. Otherwise some citations may give unexpected results in +% the printout when a shorthand was used in the optional argument +% of |\bibitem| for example. Then we make it active (not strictly +% necessary, but done for backward compatibility). % % \begin{macrocode} -\ProvideTextCommandDefault{\glqq}{% - \textormath{\quotedblbase}{\mbox{\quotedblbase}}} + \bbl@restoreactive{#2}% + \AtBeginDocument{% + \catcode`#2\active + \if@filesw + \immediate\write\@mainaux{\catcode`\string#2\active}% + \fi}% + \expandafter\bbl@add@special\csname#2\endcsname + \catcode`#2\active + \fi % \end{macrocode} % -% The definition of |\grqq| depends on the fontencoding. With -% \texttt{T1} encoding no extra kerning is needed. +% Now we have set |\normal@char|\m{char}, we must define +% |\active@char|\m{char}, to be executed when the character is +% activated. We define the first level expansion of +% |\active@char|\m{char} to check the status of the |@safe@actives| +% flag. If it is set to true we expand to the `normal' version of +% this character, otherwise we call |\user@active|\m{char} to start +% the search of a definition in the user, language and system +% levels (or eventually |normal@char|\m{char}). % % \begin{macrocode} -\ProvideTextCommand{\grqq}{T1}{% - \textormath{\textquotedblleft}{\mbox{\textquotedblleft}}} -\ProvideTextCommand{\grqq}{TU}{% - \textormath{\textquotedblleft}{\mbox{\textquotedblleft}}} -\ProvideTextCommand{\grqq}{OT1}{% - \save@sf@q{\kern-.07em - \textormath{\textquotedblleft}{\mbox{\textquotedblleft}}% - \kern.07em\relax}} -\ProvideTextCommandDefault{\grqq}{\UseTextSymbol{OT1}\grqq} + \let\bbl@tempa\@firstoftwo + \if\string^#2% + \def\bbl@tempa{\noexpand\textormath}% + \else + \ifx\bbl@mathnormal\@undefined\else + \let\bbl@tempa\bbl@mathnormal + \fi + \fi + \expandafter\edef\csname active@char#2\endcsname{% + \bbl@tempa + {\noexpand\if@safe@actives + \noexpand\expandafter + \expandafter\noexpand\csname normal@char#2\endcsname + \noexpand\else + \noexpand\expandafter + \expandafter\noexpand\csname bbl@doactive#2\endcsname + \noexpand\fi}% + {\expandafter\noexpand\csname normal@char#2\endcsname}}% + \bbl@csarg\edef{doactive#2}{% + \expandafter\noexpand\csname user@active#2\endcsname}% % \end{macrocode} % -% \end{macro} -% \end{macro} -% -% \begin{macro}{\flq} -% \begin{macro}{\frq} -% -% The `french' single guillemets. +% We now define the default values which the shorthand is set to +% when activated or deactivated. It is set to the deactivated form +% (globally), so that the character expands to +% \begin{center} +% |\active@prefix| \m{char} |\normal@char|\m{char} +% \end{center} +% (where |\active@char|\m{char} is \emph{one} control sequence!). % % \begin{macrocode} -\ProvideTextCommandDefault{\flq}{% - \textormath{\guilsinglleft}{\mbox{\guilsinglleft}}} -\ProvideTextCommandDefault{\frq}{% - \textormath{\guilsinglright}{\mbox{\guilsinglright}}} + \bbl@csarg\edef{active@#2}{% + \noexpand\active@prefix\noexpand#1% + \expandafter\noexpand\csname active@char#2\endcsname}% + \bbl@csarg\edef{normal@#2}{% + \noexpand\active@prefix\noexpand#1% + \expandafter\noexpand\csname normal@char#2\endcsname}% + \expandafter\let\expandafter#1\csname bbl@normal@#2\endcsname % \end{macrocode} % -% \end{macro} -% \end{macro} +% The next level of the code checks whether a user has defined a +% shorthand for himself with this character. First we check for a +% single character shorthand. If that doesn't exist we check for a +% shorthand with an argument. % -% \begin{macro}{\flqq} -% \begin{macro}{\frqq} +% \begin{macrocode} + \bbl@active@def#2\user@group{user@active}{language@active}% + \bbl@active@def#2\language@group{language@active}{system@active}% + \bbl@active@def#2\system@group{system@active}{normal@char}% +% \end{macrocode} % -% The `french' double guillemets. +% In order to do the right thing when a shorthand with an argument +% is used by itself at the end of the line we provide a definition +% for the case of an empty argument. For that case we let the +% shorthand character expand to its non-active self. Also, When a +% shorthand combination such as |''| ends up in a heading \TeX\ +% would see |\protect'\protect'|. To prevent this from happening a +% couple of shorthand needs to be defined at user level. % % \begin{macrocode} -\ProvideTextCommandDefault{\flqq}{% - \textormath{\guillemotleft}{\mbox{\guillemotleft}}} -\ProvideTextCommandDefault{\frqq}{% - \textormath{\guillemotright}{\mbox{\guillemotright}}} + \expandafter\edef\csname\user@group @sh@#2@@\endcsname + {\expandafter\noexpand\csname normal@char#2\endcsname}% + \expandafter\edef\csname\user@group @sh@#2@\string\protect@\endcsname + {\expandafter\noexpand\csname user@active#2\endcsname}% % \end{macrocode} % -% \end{macro} -% \end{macro} +% Finally, a couple of special cases are taken care of. (1) If we +% are making the right quote (|'|) active we need to change |\pr@m@s| as +% well. Also, make sure that a single |'| in math mode `does the +% right thing'. (2) If we are using the caret (|^|) as a shorthand +% character special care should be taken to make sure math still +% works. Therefore an extra level of expansion is introduced with a +% check for math mode on the upper level. % -% \subsubsection{Umlauts and tremas} +% \begin{macrocode} + \if\string'#2% + \let\prim@s\bbl@prim@s + \let\active@math@prime#1% + \fi + \bbl@usehooks{initiateactive}{{#1}{#2}{#3}}} +% \end{macrocode} % -% The command |\"| needs to have a different effect for different -% languages. For German for instance, the `umlaut' should be -% positioned lower than the default position for placing it over -% the letters a, o, u, A, O and U. When placed over an e, i, E or I -% it can retain its normal position. For Dutch the same glyph is -% always placed in the lower position. +% The following package options control the behavior of shorthands +% in math mode. % -% \begin{macro}{\umlauthigh} +% \begin{macrocode} +%<<*More package options>> +\DeclareOption{math=active}{} +\DeclareOption{math=normal}{\def\bbl@mathnormal{\noexpand\textormath}} +%<> +% \end{macrocode} % -% \begin{macro}{\umlautlow} -% To be able to provide both positions of |\"| we provide two -% commands to switch the positioning, the default will be -% |\umlauthigh| (the normal positioning). +% Initiating a shorthand makes active the char. That is not +% strictly necessary but it is still done for backward +% compatibility. So we need to restore the original catcode at the +% end of package \textit{and} and the end of the |ldf|. % % \begin{macrocode} -\def\umlauthigh{% - \def\bbl@umlauta##1{\leavevmode\bgroup% - \expandafter\accent\csname\f@encoding dqpos\endcsname - ##1\bbl@allowhyphens\egroup}% - \let\bbl@umlaute\bbl@umlauta} -\def\umlautlow{% - \def\bbl@umlauta{\protect\lower@umlaut}} -\def\umlautelow{% - \def\bbl@umlaute{\protect\lower@umlaut}} -\umlauthigh +\@ifpackagewith{babel}{KeepShorthandsActive}% + {\let\bbl@restoreactive\@gobble}% + {\def\bbl@restoreactive#1{% + \bbl@exp{% + \\\AfterBabelLanguage\\\CurrentOption + {\catcode`#1=\the\catcode`#1\relax}% + \\\AtEndOfPackage + {\catcode`#1=\the\catcode`#1\relax}}}% + \AtEndOfPackage{\let\bbl@restoreactive\@gobble}} % \end{macrocode} % % \end{macro} -% \end{macro} % -% \begin{macro}{\lower@umlaut} -% The command |\lower@umlaut| is used to position the |\"| closer -% to the letter. +% \begin{macro}{\bbl@sh@select} +% This command helps the shorthand supporting macros to select how +% to proceed. Note that this macro needs to be expandable as do all +% the shorthand macros in order for them to work in expansion-only +% environments such as the argument of |\hyphenation|. % -% We want the umlaut character lowered, nearer to the letter. To do -% this we need an extra \meta{dimen} register. +% This macro expects the name of a group of shorthands in its first +% argument and a shorthand character in its second argument. It +% will expand to either |\bbl@firstcs| or |\bbl@scndcs|. Hence two +% more arguments need to follow it. % % \begin{macrocode} -\expandafter\ifx\csname U@D\endcsname\relax - \csname newdimen\endcsname\U@D -\fi +\def\bbl@sh@select#1#2{% + \expandafter\ifx\csname#1@sh@#2@sel\endcsname\relax + \bbl@afterelse\bbl@scndcs + \else + \bbl@afterfi\csname#1@sh@#2@sel\endcsname + \fi} % \end{macrocode} % -% The following code fools \TeX's \texttt{make\_accent} procedure -% about the current x-height of the font to force another placement -% of the umlaut character. -% First we have to save the current x-height of the font, because -% we'll change this font dimension and this is always done -% globally. +% \end{macro} % -% Then we compute the new x-height in such a way that the umlaut -% character is lowered to the base character. The value of -% \texttt{.45ex} depends on the \MF\ parameters with which the -% fonts were built. (Just try out, which value will look best.) -% If the new x-height is too low, it is not changed. -% Finally we call the |\accent| primitive, reset the old x-height -% and insert the base character in the argument. +% \begin{macro}{\active@prefix} +% The command |\active@prefix| which is used in the expansion of +% active characters has a function similar to |\OT1-cmd| in that it +% |\protect|s the active character whenever |\protect| is +% \emph{not} |\@typeset@protect|. The |\@gobble| is needed to remove +% a token such as |\activechar:| (when the double colon was the +% active character to be dealt with). There are two definitions, +% depending of |\ifincsname| is available. If there is, the +% expansion will be more robust. % % \begin{macrocode} -\def\lower@umlaut#1{% - \leavevmode\bgroup - \U@D 1ex% - {\setbox\z@\hbox{% - \expandafter\char\csname\f@encoding dqpos\endcsname}% - \dimen@ -.45ex\advance\dimen@\ht\z@ - \ifdim 1ex<\dimen@ \fontdimen5\font\dimen@ \fi}% - \expandafter\accent\csname\f@encoding dqpos\endcsname - \fontdimen5\font\U@D #1% - \egroup} +\begingroup +\bbl@ifunset{ifincsname}% TODO. Ugly. Correct? + {\gdef\active@prefix#1{% + \ifx\protect\@typeset@protect + \else + \ifx\protect\@unexpandable@protect + \noexpand#1% + \else + \protect#1% + \fi + \expandafter\@gobble + \fi}} + {\gdef\active@prefix#1{% + \ifincsname + \string#1% + \expandafter\@gobble + \else + \ifx\protect\@typeset@protect + \else + \ifx\protect\@unexpandable@protect + \noexpand#1% + \else + \protect#1% + \fi + \expandafter\expandafter\expandafter\@gobble + \fi + \fi}} +\endgroup % \end{macrocode} % % \end{macro} % -% For all vowels we declare |\"| to be a composite command which -% uses |\bbl@umlauta| or |\bbl@umlaute| to position the umlaut -% character. We need to be sure that these definitions override the -% ones that are provided when the package \pkg{fontenc} with -% option \Lopt{OT1} is used. Therefore these declarations are -% postponed until the beginning of the document. Note these -% definitions only apply to some languages, but -% babel sets them for \textit{all} languages -- you may want to -% redefine |\bbl@umlauta| and/or |\bbl@umlaute| for a language -% in the corresponding |ldf| (using the babel switching mechanism, -% of course). +% \begin{macro}{\if@safe@actives} +% In some circumstances it is necessary to be able to change the +% expansion of an active character on the fly. For this purpose the +% switch |@safe@actives| is available. The setting of this switch +% should be checked in the first level expansion of +% |\active@char|\m{char}. % % \begin{macrocode} -\AtBeginDocument{% - \DeclareTextCompositeCommand{\"}{OT1}{a}{\bbl@umlauta{a}}% - \DeclareTextCompositeCommand{\"}{OT1}{e}{\bbl@umlaute{e}}% - \DeclareTextCompositeCommand{\"}{OT1}{i}{\bbl@umlaute{\i}}% - \DeclareTextCompositeCommand{\"}{OT1}{\i}{\bbl@umlaute{\i}}% - \DeclareTextCompositeCommand{\"}{OT1}{o}{\bbl@umlauta{o}}% - \DeclareTextCompositeCommand{\"}{OT1}{u}{\bbl@umlauta{u}}% - \DeclareTextCompositeCommand{\"}{OT1}{A}{\bbl@umlauta{A}}% - \DeclareTextCompositeCommand{\"}{OT1}{E}{\bbl@umlaute{E}}% - \DeclareTextCompositeCommand{\"}{OT1}{I}{\bbl@umlaute{I}}% - \DeclareTextCompositeCommand{\"}{OT1}{O}{\bbl@umlauta{O}}% - \DeclareTextCompositeCommand{\"}{OT1}{U}{\bbl@umlauta{U}}% -} +\newif\if@safe@actives +\@safe@activesfalse % \end{macrocode} % -% Finally, the default is to use English as the main language. +% \end{macro} +% +% \begin{macro}{\bbl@restore@actives} +% When the output routine kicks in while the +% active characters were made ``safe'' this must be undone in +% the headers to prevent unexpected typeset results. For this +% situation we define a command to make them ``unsafe'' again. % % \begin{macrocode} -\ifx\l@english\@undefined - \chardef\l@english\z@ -\fi -\main@language{english} +\def\bbl@restore@actives{\if@safe@actives\@safe@activesfalse\fi} % \end{macrocode} % -% \subsection{Layout} +% \end{macro} % -% \textbf{Work in progress}. +% \begin{macro}{\bbl@activate} +% \begin{macro}{\bbl@deactivate} % -% Layout is mainly intended to set bidi documents, but there is at -% least a tool useful in general. +% 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|. % % \begin{macrocode} -\bbl@trace{Bidi layout} -\providecommand\IfBabelLayout[3]{#3}% -\newcommand\BabelPatchSection[1]{% - \@ifundefined{#1}{}{% - \bbl@exp{\let\\<#1>}% - \@namedef{#1}{% - \@ifstar{\bbl@presec@s{#1}}% - {\@dblarg{\bbl@presec@x{#1}}}}}} -\def\bbl@presec@x#1[#2]#3{% - \bbl@exp{% - \\\select@language@x{\bbl@main@language}% - \\\bbl@cs{sspre@#1}% - \\\bbl@cs{ss@#1}% - [\\\foreignlanguage{\languagename}{\unexpanded{#2}}]% - {\\\foreignlanguage{\languagename}{\unexpanded{#3}}}% - \\\select@language@x{\languagename}}} -\def\bbl@presec@s#1#2{% - \bbl@exp{% - \\\select@language@x{\bbl@main@language}% - \\\bbl@cs{sspre@#1}% - \\\bbl@cs{ss@#1}*% - {\\\foreignlanguage{\languagename}{\unexpanded{#2}}}% - \\\select@language@x{\languagename}}} -\IfBabelLayout{sectioning}% - {\BabelPatchSection{part}% - \BabelPatchSection{chapter}% - \BabelPatchSection{section}% - \BabelPatchSection{subsection}% - \BabelPatchSection{subsubsection}% - \BabelPatchSection{paragraph}% - \BabelPatchSection{subparagraph}% - \def\babel@toc#1{% - \select@language@x{\bbl@main@language}}}{} -\IfBabelLayout{captions}% - {\BabelPatchSection{caption}}{} +\def\bbl@activate#1{% + \bbl@withactive{\expandafter\let\expandafter}#1% + \csname bbl@active@\string#1\endcsname} +\def\bbl@deactivate#1{% + \bbl@withactive{\expandafter\let\expandafter}#1% + \csname bbl@normal@\string#1\endcsname} % \end{macrocode} % -% \subsection{Load engine specific macros} +% \end{macro} +% \end{macro} +% +% \begin{macro}{\bbl@firstcs} +% \begin{macro}{\bbl@scndcs} +% +% These macros are used only as a trick when declaring shorthands. % % \begin{macrocode} -\bbl@trace{Input engine specific macros} -\ifcase\bbl@engine - \input txtbabel.def -\or - \input luababel.def -\or - \input xebabel.def -\fi +\def\bbl@firstcs#1#2{\csname#1\endcsname} +\def\bbl@scndcs#1#2{\csname#2\endcsname} % \end{macrocode} % -% \subsection{Creating languages} +% \end{macro} +% \end{macro} % -% |\babelprovide| is a general purpose tool for creating and modifying -% languages. It creates the language infrastructure, and loads, if -% requested, an |ini| file. It may be used in conjunction to previouly -% loaded |ldf| files. +% \begin{macro}{\declare@shorthand} +% The command |\declare@shorthand| is used to declare a shorthand +% on a certain level. It takes three arguments: +% \begin{enumerate} +% \item a name for the collection of shorthands, i.e. `system', or +% `dutch'; +% \item the character (sequence) that makes up the shorthand, +% i.e. |~| or |"a|; +% \item the code to be executed when the shorthand is encountered. +% \end{enumerate} % % \begin{macrocode} -\bbl@trace{Creating languages and reading ini files} -\newcommand\babelprovide[2][]{% - \let\bbl@savelangname\languagename - \edef\bbl@savelocaleid{\the\localeid}% - % Set name and locale id - \edef\languagename{#2}% - % \global\@namedef{bbl@lcname@#2}{#2}% - \bbl@id@assign - \let\bbl@KVP@captions\@nil - \let\bbl@KVP@import\@nil - \let\bbl@KVP@main\@nil - \let\bbl@KVP@script\@nil - \let\bbl@KVP@language\@nil - \let\bbl@KVP@hyphenrules\@nil % only for provide@new - \let\bbl@KVP@mapfont\@nil - \let\bbl@KVP@maparabic\@nil - \let\bbl@KVP@mapdigits\@nil - \let\bbl@KVP@intraspace\@nil - \let\bbl@KVP@intrapenalty\@nil - \let\bbl@KVP@onchar\@nil - \let\bbl@KVP@alph\@nil - \let\bbl@KVP@Alph\@nil - \let\bbl@KVP@info\@nil % Ignored with import? Or error/warning? - \bbl@forkv{#1}{% TODO - error handling - \in@{/}{##1}% - \ifin@ - \bbl@renewinikey##1\@@{##2}% - \else - \bbl@csarg\def{KVP@##1}{##2}% - \fi}% - % == 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}% - {}% - \fi - \ifx\bbl@KVP@captions\@nil - \let\bbl@KVP@captions\bbl@KVP@import - \fi - % Load ini - \bbl@ifunset{date#2}% - {\bbl@provide@new{#2}}% - {\bbl@ifblank{#1}% - {\bbl@error - {If you want to modify `#2' you must tell how in\\% - the optional argument. See the manual for the\\% - available options.}% - {Use this macro as documented}}% - {\bbl@provide@renew{#2}}}% - % Post tasks - \bbl@exp{\\\babelensure[exclude=\\\today]{#2}}% - \bbl@ifunset{bbl@ensure@\languagename}% - {\bbl@exp{% - \\\DeclareRobustCommand\[1]{% - \\\foreignlanguage{\languagename}% - {####1}}}}% - {}% - % 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}% - {\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{chrng}{characters.ranges}{}% - \bbl@exportkey{dgnat}{numbers.digits.native}{}% - \bbl@exportkey{prehc}{typography.prehyphenchar}{}% - \bbl@exportkey{lnbrk}{typography.linebreaking}{h}% - \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}{}{}}}}% - {}% - % - - % == script, language == - % Override the values from ini or defines them - \ifx\bbl@KVP@script\@nil\else - \bbl@csarg\edef{sname@#2}{\bbl@KVP@script}% - \fi - \ifx\bbl@KVP@language\@nil\else - \bbl@csarg\edef{lname@#2}{\bbl@KVP@language}% - \fi - % == onchar == - \ifx\bbl@KVP@onchar\@nil\else - \bbl@luahyphenate - \directlua{ - if Babel.locale_mapped == nil then - Babel.locale_mapped = true - Babel.linebreaking.add_before(Babel.locale_map) - Babel.loc_to_scr = {} - Babel.chr_to_loc = Babel.chr_to_loc or {} - end}% - \bbl@xin@{ ids }{ \bbl@KVP@onchar\space}% - \ifin@ - \ifx\bbl@starthyphens\@undefined % Needed if no explicit selection - \AddBabelHook{babel-onchar}{beforestart}{{\bbl@starthyphens}}% - \fi - \bbl@exp{\\\bbl@add\\\bbl@starthyphens - {\\\bbl@patterns@lua{\languagename}}}% - % TODO - error/warning if no script - \directlua{ - if Babel.script_blocks['\bbl@cl{sbcp}'] then - Babel.loc_to_scr[\the\localeid] = - Babel.script_blocks['\bbl@cl{sbcp}'] - Babel.locale_props[\the\localeid].lc = \the\localeid\space - Babel.locale_props[\the\localeid].lg = \the\@nameuse{l@\languagename}\space - end - }% - \fi - \bbl@xin@{ fonts }{ \bbl@KVP@onchar\space}% - \ifin@ - \bbl@ifunset{bbl@lsys@\languagename}{\bbl@provide@lsys{\languagename}}{}% - \bbl@ifunset{bbl@wdir@\languagename}{\bbl@provide@dirs{\languagename}}{}% - \directlua{ - if Babel.script_blocks['\bbl@cl{sbcp}'] then - Babel.loc_to_scr[\the\localeid] = - Babel.script_blocks['\bbl@cl{sbcp}'] - end}% - \ifx\bbl@mapselect\@undefined - \AtBeginDocument{% - \expandafter\bbl@add\csname selectfont \endcsname{{\bbl@mapselect}}% - {\selectfont}}% - \def\bbl@mapselect{% - \let\bbl@mapselect\relax - \edef\bbl@prefontid{\fontid\font}}% - \def\bbl@mapdir##1{% - {\def\languagename{##1}% - \let\bbl@ifrestoring\@firstoftwo % To avoid font warning - \bbl@switchfont - \directlua{ - Babel.locale_props[\the\csname bbl@id@@##1\endcsname]% - ['/\bbl@prefontid'] = \fontid\font\space}}}% - \fi - \bbl@exp{\\\bbl@add\\\bbl@mapselect{\\\bbl@mapdir{\languagename}}}% - \fi - % TODO - catch non-valid values - \fi - % == mapfont == - % For bidi texts, to switch the font based on direction - \ifx\bbl@KVP@mapfont\@nil\else - \bbl@ifsamestring{\bbl@KVP@mapfont}{direction}{}% - {\bbl@error{Option `\bbl@KVP@mapfont' unknown for\\% - mapfont. Use `direction'.% - {See the manual for details.}}}% - \bbl@ifunset{bbl@lsys@\languagename}{\bbl@provide@lsys{\languagename}}{}% - \bbl@ifunset{bbl@wdir@\languagename}{\bbl@provide@dirs{\languagename}}{}% - \ifx\bbl@mapselect\@undefined - \AtBeginDocument{% - \expandafter\bbl@add\csname selectfont \endcsname{{\bbl@mapselect}}% - {\selectfont}}% - \def\bbl@mapselect{% - \let\bbl@mapselect\relax - \edef\bbl@prefontid{\fontid\font}}% - \def\bbl@mapdir##1{% - {\def\languagename{##1}% - \let\bbl@ifrestoring\@firstoftwo % avoid font warning - \bbl@switchfont - \directlua{Babel.fontmap - [\the\csname bbl@wdir@##1\endcsname]% - [\bbl@prefontid]=\fontid\font}}}% - \fi - \bbl@exp{\\\bbl@add\\\bbl@mapselect{\\\bbl@mapdir{\languagename}}}% - \fi - % == intraspace, intrapenalty == - % For CJK, East Asian, Southeast Asian, if interspace in ini - \ifx\bbl@KVP@intraspace\@nil\else % We can override the ini or set - \bbl@csarg\edef{intsp@#2}{\bbl@KVP@intraspace}% - \fi - \bbl@provide@intraspace - % == hyphenate.other == - \bbl@ifunset{bbl@hyoth@\languagename}{}% - {\bbl@csarg\bbl@replace{hyoth@\languagename}{ }{,}% - \bbl@startcommands*{\languagename}{}% - \bbl@csarg\bbl@foreach{hyoth@\languagename}{% - \ifcase\bbl@engine - \ifnum##1<257 - \SetHyphenMap{\BabelLower{##1}{##1}}% - \fi - \else - \SetHyphenMap{\BabelLower{##1}{##1}}% - \fi}% - \bbl@endcommands}% - % == maparabic == - % Native digits, if provided in ini (TeX level, xe and lua) - \ifcase\bbl@engine\else - \bbl@ifunset{bbl@dgnat@\languagename}{}% - {\expandafter\ifx\csname bbl@dgnat@\languagename\endcsname\@empty\else - \expandafter\expandafter\expandafter - \bbl@setdigits\csname bbl@dgnat@\languagename\endcsname - \ifx\bbl@KVP@maparabic\@nil\else - \ifx\bbl@latinarabic\@undefined - \expandafter\let\expandafter\@arabic - \csname bbl@counter@\languagename\endcsname - \else % ie, if layout=counters, which redefines \@arabic - \expandafter\let\expandafter\bbl@latinarabic - \csname bbl@counter@\languagename\endcsname - \fi - \fi - \fi}% - \fi - % == mapdigits == - % Native digits (lua level). - \ifodd\bbl@engine - \ifx\bbl@KVP@mapdigits\@nil\else - \bbl@ifunset{bbl@dgnat@\languagename}{}% - {\RequirePackage{luatexbase}% - \bbl@activate@preotf - \directlua{ - Babel = Babel or {} %%% -> presets in luababel - Babel.digits_mapped = true - Babel.digits = Babel.digits or {} - Babel.digits[\the\localeid] = - table.pack(string.utfvalue('\bbl@cl{dgnat}')) - if not Babel.numbers then - function Babel.numbers(head) - local LOCALE = luatexbase.registernumber'bbl@attr@locale' - local GLYPH = node.id'glyph' - local inmath = false - for item in node.traverse(head) do - if not inmath and item.id == GLYPH then - local temp = node.get_attribute(item, LOCALE) - if Babel.digits[temp] then - local chr = item.char - if chr > 47 and chr < 58 then - item.char = Babel.digits[temp][chr-47] - end - end - elseif item.id == node.id'math' then - inmath = (item.subtype == 0) - end - end - return head - end - end - }}% - \fi - \fi - % == alph, Alph == - % What if extras contains a \babel@save\@alph? It won't be - % restored correctly when exiting the language, so we ignore - % this change with the \bbl@alph@saved trick. - \ifx\bbl@KVP@alph\@nil\else - \toks@\expandafter\expandafter\expandafter{% - \csname extras\languagename\endcsname}% - \bbl@exp{% - \def\{% - \let\\\bbl@alph@saved\\\@alph - \the\toks@ - \let\\\@alph\\\bbl@alph@saved - \\\babel@save\\\@alph - \let\\\@alph\}}% - \fi - \ifx\bbl@KVP@Alph\@nil\else - \toks@\expandafter\expandafter\expandafter{% - \csname extras\languagename\endcsname}% - \bbl@exp{% - \def\{% - \let\\\bbl@Alph@saved\\\@Alph - \the\toks@ - \let\\\@Alph\\\bbl@Alph@saved - \\\babel@save\\\@Alph - \let\\\@Alph\}}% - \fi - % == require.babel in ini == - % To load or reaload the babel-*.tex, if require.babel in ini - \bbl@ifunset{bbl@rqtex@\languagename}{}% - {\expandafter\ifx\csname bbl@rqtex@\languagename\endcsname\@empty\else - \let\BabelBeforeIni\@gobbletwo - \chardef\atcatcode=\catcode`\@ - \catcode`\@=11\relax - \InputIfFileExists{babel-\bbl@cs{rqtex@\languagename}.tex}{}{}% - \catcode`\@=\atcatcode - \let\atcatcode\relax - \fi}% - % == main == - \ifx\bbl@KVP@main\@nil % Restore only if not 'main' - \let\languagename\bbl@savelangname - \chardef\localeid\bbl@savelocaleid\relax +\def\declare@shorthand#1#2{\@decl@short{#1}#2\@nil} +\def\@decl@short#1#2#3\@nil#4{% + \def\bbl@tempa{#3}% + \ifx\bbl@tempa\@empty + \expandafter\let\csname #1@sh@\string#2@sel\endcsname\bbl@scndcs + \bbl@ifunset{#1@sh@\string#2@}{}% + {\def\bbl@tempa{#4}% + \expandafter\ifx\csname#1@sh@\string#2@\endcsname\bbl@tempa + \else + \bbl@info + {Redefining #1 shorthand \string#2\\% + in language \CurrentOption}% + \fi}% + \@namedef{#1@sh@\string#2@}{#4}% + \else + \expandafter\let\csname #1@sh@\string#2@sel\endcsname\bbl@firstcs + \bbl@ifunset{#1@sh@\string#2@\string#3@}{}% + {\def\bbl@tempa{#4}% + \expandafter\ifx\csname#1@sh@\string#2@\string#3@\endcsname\bbl@tempa + \else + \bbl@info + {Redefining #1 shorthand \string#2\string#3\\% + in language \CurrentOption}% + \fi}% + \@namedef{#1@sh@\string#2@\string#3@}{#4}% \fi} % \end{macrocode} % -% A tool to define the macros for native digits from the list provided -% in the |ini| file. Somewhat convoluted because there are 10 digits, -% but only 9 arguments in \TeX. -% -% \begin{macrocode} -\def\bbl@setdigits#1#2#3#4#5{% - \bbl@exp{% - \def\<\languagename digits>####1{% ie, \langdigits - \####1\\\@nil}% - \def\<\languagename counter>####1{% ie, \langcounter - \\\expandafter\% - \\\csname c@####1\endcsname}% - \def\####1{% ie, \bbl@counter@lang - \\\expandafter\% - \\\number####1\\\@nil}}% - \def\bbl@tempa##1##2##3##4##5{% - \bbl@exp{% Wow, quite a lot of hashes! :-( - \def\########1{% - \\\ifx########1\\\@nil % ie, \bbl@digits@lang - \\\else - \\\ifx0########1#1% - \\\else\\\ifx1########1#2% - \\\else\\\ifx2########1#3% - \\\else\\\ifx3########1#4% - \\\else\\\ifx4########1#5% - \\\else\\\ifx5########1##1% - \\\else\\\ifx6########1##2% - \\\else\\\ifx7########1##3% - \\\else\\\ifx8########1##4% - \\\else\\\ifx9########1##5% - \\\else########1% - \\\fi\\\fi\\\fi\\\fi\\\fi\\\fi\\\fi\\\fi\\\fi\\\fi - \\\expandafter\% - \\\fi}}}% - \bbl@tempa} -% \end{macrocode} +% \end{macro} % -% Depending on whether or not the language exists, we define two macros. +% \begin{macro}{\textormath} +% Some of the shorthands that will be declared by the language +% definition files have to be usable in both text and mathmode. To +% achieve this the helper macro |\textormath| is provided. % % \begin{macrocode} -\def\bbl@provide@new#1{% - \@namedef{date#1}{}% marks lang exists - required by \StartBabelCommands - \@namedef{extras#1}{}% - \@namedef{noextras#1}{}% - \bbl@startcommands*{#1}{captions}% - \ifx\bbl@KVP@captions\@nil % and also if import, implicit - \def\bbl@tempb##1{% elt for \bbl@captionslist - \ifx##1\@empty\else - \bbl@exp{% - \\\SetString\\##1{% - \\\bbl@nocaption{\bbl@stripslash##1}{#1\bbl@stripslash##1}}}% - \expandafter\bbl@tempb - \fi}% - \expandafter\bbl@tempb\bbl@captionslist\@empty - \else - \bbl@read@ini{\bbl@KVP@captions}{data}% Here all letters cat = 11 - \bbl@after@ini - \bbl@savestrings - \fi - \StartBabelCommands*{#1}{date}% - \ifx\bbl@KVP@import\@nil - \bbl@exp{% - \\\SetString\\\today{\\\bbl@nocaption{today}{#1today}}}% - \else - \bbl@savetoday - \bbl@savedate - \fi - \bbl@endcommands - \bbl@exp{% - \def\<#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}% - \ifx\bbl@KVP@main\@nil\else - \expandafter\main@language\expandafter{#1}% +\def\textormath{% + \ifmmode + \expandafter\@secondoftwo + \else + \expandafter\@firstoftwo \fi} -\def\bbl@provide@renew#1{% - \ifx\bbl@KVP@captions\@nil\else - \StartBabelCommands*{#1}{captions}% - \bbl@read@ini{\bbl@KVP@captions}{data}% Here all letters cat = 11 - \bbl@after@ini - \bbl@savestrings - \EndBabelCommands - \fi - \ifx\bbl@KVP@import\@nil\else - \StartBabelCommands*{#1}{date}% - \bbl@savetoday - \bbl@savedate - \EndBabelCommands - \fi - % == hyphenrules == - \bbl@provide@hyphens{#1}} % \end{macrocode} % -% The |hyphenrules| option is handled with an auxiliary macro. +% \end{macro} +% +% \begin{macro}{\user@group} +% \begin{macro}{\language@group} +% \begin{macro}{\system@group} +% The current concept of `shorthands' supports three levels or +% groups of shorthands. For each level the name of the level or +% group is stored in a macro. The default is to have a user group; +% use language group `english' and have a system group called +% `system'. % % \begin{macrocode} -\def\bbl@provide@hyphens#1{% - \let\bbl@tempa\relax - \ifx\bbl@KVP@hyphenrules\@nil\else - \bbl@replace\bbl@KVP@hyphenrules{ }{,}% - \bbl@foreach\bbl@KVP@hyphenrules{% - \ifx\bbl@tempa\relax % if not yet found - \bbl@ifsamestring{##1}{+}% - {{\bbl@exp{\\\addlanguage\}}}% - {}% - \bbl@ifunset{l@##1}% - {}% - {\bbl@exp{\let\bbl@tempa\}}% - \fi}% - \fi - \ifx\bbl@tempa\relax % if no opt or no language in opt found - \ifx\bbl@KVP@import\@nil\else % if importing - \bbl@exp{% and hyphenrules is not empty - \\\bbl@ifblank{\bbl@cs{hyphr@#1}}% - {}% - {\let\\\bbl@tempa\}}% - \fi - \fi - \bbl@ifunset{bbl@tempa}% ie, relax or undefined - {\bbl@ifunset{l@#1}% no hyphenrules found - fallback - {\bbl@exp{\\\adddialect\\language}}% - {}}% so, l@ is ok - nothing to do - {\bbl@exp{\\\adddialect\\bbl@tempa}}}% found in opt list or ini - +\def\user@group{user} +\def\language@group{english} % TODO. I don't like defaults +\def\system@group{system} % \end{macrocode} % -% The reader of |ini| files. There are 3 possible cases: a section name -% (in the form |[...]|), a comment (starting with |;|) and a -% key/value pair. +% \end{macro} +% \end{macro} +% \end{macro} +% +% \begin{macro}{\useshorthands} +% +% 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. % % \begin{macrocode} -\ifx\bbl@readstream\@undefined - \csname newread\endcsname\bbl@readstream -\fi -\def\bbl@inipreread#1=#2\@@{% - \bbl@trim@def\bbl@tempa{#1}% Redundant below !! - \bbl@trim\toks@{#2}% - % Move trims here ?? - \bbl@ifunset{bbl@KVP@\bbl@section/\bbl@tempa}% - {\bbl@exp{% - \\\g@addto@macro\\\bbl@inidata{% - \\\bbl@elt{\bbl@section}{\bbl@tempa}{\the\toks@}}}% - \expandafter\bbl@inireader\bbl@tempa=#2\@@}% - {}}% -\def\bbl@read@ini#1#2{% - \bbl@csarg\edef{lini@\languagename}{#1}% - \openin\bbl@readstream=babel-#1.ini - \ifeof\bbl@readstream - \bbl@error - {There is no ini file for the requested language\\% - (#1). Perhaps you misspelled it or your installation\\% - is not complete.}% - {Fix the name or reinstall babel.}% - \else - \bbl@exp{\def\\\bbl@inidata{\\\bbl@elt{identificacion}{tag.ini}{#1}}}% - \let\bbl@section\@empty - \let\bbl@savestrings\@empty - \let\bbl@savetoday\@empty - \let\bbl@savedate\@empty - \let\bbl@inireader\bbl@iniskip - \bbl@info{Importing #2 for \languagename\\% - from babel-#1.ini. Reported}% - \loop - \if T\ifeof\bbl@readstream F\fi T\relax % Trick, because inside \loop - \endlinechar\m@ne - \read\bbl@readstream to \bbl@line - \endlinechar`\^^M - \ifx\bbl@line\@empty\else - \expandafter\bbl@iniline\bbl@line\bbl@iniline - \fi - \repeat - \bbl@foreach\bbl@renewlist{% - \bbl@ifunset{bbl@renew@##1}{}{\bbl@inisec[##1]\@@}}% - \global\let\bbl@renewlist\@empty - % Ends last section. See \bbl@inisec - \def\bbl@elt##1##2{\bbl@inireader##1=##2\@@}% - \bbl@cs{renew@\bbl@section}% - \global\bbl@csarg\let{renew@\bbl@section}\relax - \bbl@cs{secpost@\bbl@section}% - \bbl@csarg{\global\expandafter\let}{inidata@\languagename}\bbl@inidata - \bbl@exp{\\\bbl@add@list\\\bbl@ini@loaded{\languagename}}% - \bbl@toglobal\bbl@ini@loaded - \fi} -\def\bbl@iniline#1\bbl@iniline{% - \@ifnextchar[\bbl@inisec{\@ifnextchar;\bbl@iniskip\bbl@inipreread}#1\@@}% ] +\def\useshorthands{% + \@ifstar\bbl@usesh@s{\bbl@usesh@x{}}} +\def\bbl@usesh@s#1{% + \bbl@usesh@x + {\AddBabelHook{babel-sh-\string#1}{afterextras}{\bbl@activate{#1}}}% + {#1}} +\def\bbl@usesh@x#1#2{% + \bbl@ifshorthand{#2}% + {\def\user@group{user}% + \initiate@active@char{#2}% + #1% + \bbl@activate{#2}}% + {\bbl@error + {Cannot declare a shorthand turned off (\string#2)} + {Sorry, but you cannot use shorthands which have been\\% + turned off in the package options}}} % \end{macrocode} % -% The special cases for comment lines and sections are handled by the -% two following commands. In sections, we provide the posibility to -% take extra actions at the end or at the start (TODO - but note the last -% section is not ended). By default, key=val pairs are ignored. The -% |secpost| ``hook'' is used only by `identification', while |secpre| -% only by |date.gregorian.licr|. +% \end{macro} % -% \begin{macrocode} -\def\bbl@iniskip#1\@@{}% if starts with ; -\def\bbl@inisec[#1]#2\@@{% if starts with opening bracket - \def\bbl@elt##1##2{% - \expandafter\toks@\expandafter{% - \expandafter{\bbl@section}{##1}{##2}}% - \bbl@exp{% - \\\g@addto@macro\\\bbl@inidata{\\\bbl@elt\the\toks@}}% - \bbl@inireader##1=##2\@@}% - \bbl@cs{renew@\bbl@section}% - \global\bbl@csarg\let{renew@\bbl@section}\relax - \bbl@cs{secpost@\bbl@section}% - % The previous code belongs to the previous section. - % Now start the current one. - \def\bbl@section{#1}% - \def\bbl@elt##1##2{% - \@namedef{bbl@KVP@#1/##1}{}}% - \bbl@cs{renew@#1}% - \bbl@cs{secpre@#1}% pre-section `hook' - \bbl@ifunset{bbl@inikv@#1}% - {\let\bbl@inireader\bbl@iniskip}% - {\bbl@exp{\let\\\bbl@inireader\}}} -\let\bbl@renewlist\@empty -\def\bbl@renewinikey#1/#2\@@#3{% - \bbl@ifunset{bbl@renew@#1}% - {\bbl@add@list\bbl@renewlist{#1}}% - {}% - \bbl@csarg\bbl@add{renew@#1}{\bbl@elt{#2}{#3}}} -% \end{macrocode} +% \begin{macro}{\defineshorthand} % -% Reads a key=val line and stores the trimmed val in -% |\bbl@@kv@
.|. +% Currently we only support two groups of user level shorthands, +% named internally |user| and |user@| (language-dependent +% user shorthands). By default, only the first one is taken into +% account, but if the former is also used (in the optional argument +% of |\defineshorthand|) a new level is inserted for it +% (|user@generic|, done by |\bbl@set@user@generic|); we make also +% sure |{}| and |\protect| are taken into account in this new top +% level. % % \begin{macrocode} -\def\bbl@inikv#1=#2\@@{% key=value - \bbl@trim@def\bbl@tempa{#1}% - \bbl@trim\toks@{#2}% - \bbl@csarg\edef{@kv@\bbl@section.\bbl@tempa}{\the\toks@}} +\def\user@language@group{user@\language@group} +\def\bbl@set@user@generic#1#2{% + \bbl@ifunset{user@generic@active#1}% + {\bbl@active@def#1\user@language@group{user@active}{user@generic@active}% + \bbl@active@def#1\user@group{user@generic@active}{language@active}% + \expandafter\edef\csname#2@sh@#1@@\endcsname{% + \expandafter\noexpand\csname normal@char#1\endcsname}% + \expandafter\edef\csname#2@sh@#1@\string\protect@\endcsname{% + \expandafter\noexpand\csname user@active#1\endcsname}}% + \@empty} +\newcommand\defineshorthand[3][user]{% + \edef\bbl@tempa{\zap@space#1 \@empty}% + \bbl@for\bbl@tempb\bbl@tempa{% + \if*\expandafter\@car\bbl@tempb\@nil + \edef\bbl@tempb{user@\expandafter\@gobble\bbl@tempb}% + \@expandtwoargs + \bbl@set@user@generic{\expandafter\string\@car#2\@nil}\bbl@tempb + \fi + \declare@shorthand{\bbl@tempb}{#2}{#3}}} % \end{macrocode} % -% The previous assignments are local, so we need to export them. If -% the value is empty, we can provide a default value. +% \end{macro} % -% \begin{macrocode} -\def\bbl@exportkey#1#2#3{% - \bbl@ifunset{bbl@@kv@#2}% - {\bbl@csarg\gdef{#1@\languagename}{#3}}% - {\expandafter\ifx\csname bbl@@kv@#2\endcsname\@empty - \bbl@csarg\gdef{#1@\languagename}{#3}% - \else - \bbl@exp{\global\let\\}% - \fi}} -% \end{macrocode} +% \begin{macro}{\languageshorthands} % -% Key-value pairs are treated differently depending on the section in -% the |ini| file. The following macros are the readers for -% |identification| and |typography|. Note |\bbl@secpost@identification| -% is called always (via |\bbl@inisec|), while |\bbl@after@ini| must be -% called explicitly after |\bbl@read@ini| if necessary. +% 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 [TODO. Unclear]. % % \begin{macrocode} -\def\bbl@iniwarning#1{% - \bbl@ifunset{bbl@@kv@identification.warning#1}{}% - {\bbl@warning{% - From babel-\bbl@cs{lini@\languagename}.ini:\\% - \bbl@cs{@kv@identification.warning#1}\\% - Reported }}} -\let\bbl@inikv@identification\bbl@inikv -\def\bbl@secpost@identification{% - \bbl@iniwarning{}% - \ifcase\bbl@engine - \bbl@iniwarning{.pdflatex}% - \or - \bbl@iniwarning{.lualatex}% - \or - \bbl@iniwarning{.xelatex}% - \fi% - \bbl@exportkey{elname}{identification.name.english}{}% - \bbl@exp{\\\bbl@exportkey{lname}{identification.name.opentype}% - {\csname bbl@elname@\languagename\endcsname}}% - \bbl@exportkey{lbcp}{identification.tag.bcp47}{}% - \bbl@exportkey{lotf}{identification.tag.opentype}{dflt}% - \bbl@exportkey{esname}{identification.script.name}{}% - \bbl@exp{\\\bbl@exportkey{sname}{identification.script.name.opentype}% - {\csname bbl@esname@\languagename\endcsname}}% - \bbl@exportkey{sbcp}{identification.script.tag.bcp47}{}% - \bbl@exportkey{sotf}{identification.script.tag.opentype}{DFLT}} -\let\bbl@inikv@typography\bbl@inikv -\let\bbl@inikv@characters\bbl@inikv -\let\bbl@inikv@numbers\bbl@inikv -\def\bbl@inikv@counters#1=#2\@@{% - \def\bbl@tempc{#1}% - \bbl@trim@def{\bbl@tempb*}{#2}% - \in@{.1$}{#1$}% - \ifin@ - \bbl@replace\bbl@tempc{.1}{}% - \bbl@csarg\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*}% - \else - \toks@{}% Required by \bbl@buildifcase, which returns \bbl@tempa - \expandafter\bbl@buildifcase\bbl@tempb* \\ % Space after \\ - \bbl@csarg{\global\expandafter\let}{cntr@#1@\languagename}\bbl@tempa - \fi} -\def\bbl@after@ini{% - \bbl@exportkey{lfthm}{typography.lefthyphenmin}{2}% - \bbl@exportkey{rgthm}{typography.righthyphenmin}{3}% - \bbl@exportkey{prehc}{typography.prehyphenchar}{}% - \bbl@exportkey{lnbrk}{typography.linebreaking}{h}% - \bbl@exportkey{hyphr}{typography.hyphenrules}{}% - \bbl@exportkey{hyoth}{typography.hyphenate.other}{}% - \bbl@exportkey{intsp}{typography.intraspace}{}% - \bbl@exportkey{jstfy}{typography.justify}{w}% - \bbl@exportkey{chrng}{characters.ranges}{}% - \bbl@exportkey{dgnat}{numbers.digits.native}{}% - \bbl@exportkey{rqtex}{identification.require.babel}{}% - \bbl@toglobal\bbl@savetoday - \bbl@toglobal\bbl@savedate} +\def\languageshorthands#1{\def\language@group{#1}} % \end{macrocode} % -% Now |captions| and |captions.licr|, depending on the engine. And -% below also for dates. They rely on a few auxiliary macros. It is -% expected the ini file provides the complete set in Unicode and LICR, -% in that order. +% \end{macro} % -% \begin{macrocode} -\ifcase\bbl@engine - \bbl@csarg\def{inikv@captions.licr}#1=#2\@@{% - \bbl@ini@captions@aux{#1}{#2}} -\else - \def\bbl@inikv@captions#1=#2\@@{% - \bbl@ini@captions@aux{#1}{#2}} -\fi -% \end{macrocode} +% \begin{macro}{\aliasshorthand} +% 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"|. % -% The auxiliary macro for captions define |\name|. % % \begin{macrocode} -\def\bbl@ini@captions@aux#1#2{% - \bbl@trim@def\bbl@tempa{#1}% - \bbl@ifblank{#2}% - {\bbl@exp{% - \toks@{\\\bbl@nocaption{\bbl@tempa}{\languagename\bbl@tempa name}}}}% - {\bbl@trim\toks@{#2}}% - \bbl@exp{% - \\\bbl@add\\\bbl@savestrings{% - \\\SetString\<\bbl@tempa name>{\the\toks@}}}} +\def\aliasshorthand#1#2{% + \bbl@ifshorthand{#2}% + {\expandafter\ifx\csname active@char\string#2\endcsname\relax + \ifx\document\@notprerr + \@notshorthand{#2}% + \else + \initiate@active@char{#2}% + \expandafter\let\csname active@char\string#2\expandafter\endcsname + \csname active@char\string#1\endcsname + \expandafter\let\csname normal@char\string#2\expandafter\endcsname + \csname normal@char\string#1\endcsname + \bbl@activate{#2}% + \fi + \fi}% + {\bbl@error + {Cannot declare a shorthand turned off (\string#2)} + {Sorry, but you cannot use shorthands which have been\\% + turned off in the package options}}} % \end{macrocode} % -% But dates are more complex. The full date format is stores in -% |date.gregorian|, so we must read it in non-Unicode engines, too -% (saved months are just discarded when the LICR section is reached). +% \end{macro} % -% TODO. Remove copypaste pattern. +% \begin{macro}{\@notshorthand} % % \begin{macrocode} -\bbl@csarg\def{inikv@date.gregorian}#1=#2\@@{% for defaults - \bbl@inidate#1...\relax{#2}{}} -\bbl@csarg\def{inikv@date.islamic}#1=#2\@@{% - \bbl@inidate#1...\relax{#2}{islamic}} -\bbl@csarg\def{inikv@date.hebrew}#1=#2\@@{% - \bbl@inidate#1...\relax{#2}{hebrew}} -\bbl@csarg\def{inikv@date.persian}#1=#2\@@{% - \bbl@inidate#1...\relax{#2}{persian}} -\bbl@csarg\def{inikv@date.indian}#1=#2\@@{% - \bbl@inidate#1...\relax{#2}{indian}} -\ifcase\bbl@engine - \bbl@csarg\def{inikv@date.gregorian.licr}#1=#2\@@{% override - \bbl@inidate#1...\relax{#2}{}} - \bbl@csarg\def{secpre@date.gregorian.licr}{% discard uni - \ifcase\bbl@engine\let\bbl@savedate\@empty\fi} -\fi -% eg: 1=months, 2=wide, 3=1, 4=dummy -\def\bbl@inidate#1.#2.#3.#4\relax#5#6{% TODO - ignore with 'captions' - \bbl@trim@def\bbl@tempa{#1.#2}% - \bbl@ifsamestring{\bbl@tempa}{months.wide}% to savedate - {\bbl@trim@def\bbl@tempa{#3}% - \bbl@trim\toks@{#5}% - \bbl@exp{% - \\\bbl@add\\\bbl@savedate{% - \\\SetString\{\the\toks@}}}}% - {\bbl@ifsamestring{\bbl@tempa}{date.long}% defined now - {\bbl@trim@def\bbl@toreplace{#5}% - \bbl@TG@@date - \global\bbl@csarg\let{date@\languagename}\bbl@toreplace - \bbl@exp{% - \gdef\<\languagename date>{\\\protect\<\languagename date >}% - \gdef\<\languagename date >####1####2####3{% - \\\bbl@usedategrouptrue - \{% - \{####1}{####2}{####3}}}% - \\\bbl@add\\\bbl@savetoday{% - \\\SetString\\\today{% - \<\languagename date>{\\\the\year}{\\\the\month}{\\\the\day}}}}}}% - {}} +\def\@notshorthand#1{% + \bbl@error{% + The character `\string #1' should be made a shorthand character;\\% + add the command \string\useshorthands\string{#1\string} to + the preamble.\\% + I will ignore your instruction}% + {You may proceed, but expect unexpected results}} % \end{macrocode} % -% Dates will require some macros for the basic formatting. They may be -% redefined by language, so ``semi-public'' names (camel case) are -% used. Oddly enough, the CLDR places particles like “de” -% inconsistently in either in the date or in the month name. +% \end{macro} +% +% \begin{macro}{\shorthandon} +% \begin{macro}{\shorthandoff} +% The first level definition of these macros just passes the +% argument on to |\bbl@switch@sh|, adding |\@nil| at the end to +% denote the end of the list of characters. % % \begin{macrocode} -\let\bbl@calendar\@empty -\newcommand\BabelDateSpace{\nobreakspace} -\newcommand\BabelDateDot{.\@} -\newcommand\BabelDated[1]{{\number#1}} -\newcommand\BabelDatedd[1]{{\ifnum#1<10 0\fi\number#1}} -\newcommand\BabelDateM[1]{{\number#1}} -\newcommand\BabelDateMM[1]{{\ifnum#1<10 0\fi\number#1}} -\newcommand\BabelDateMMMM[1]{{% - \csname month\romannumeral#1\bbl@calendar name\endcsname}}% -\newcommand\BabelDatey[1]{{\number#1}}% -\newcommand\BabelDateyy[1]{{% - \ifnum#1<10 0\number#1 % - \else\ifnum#1<100 \number#1 % - \else\ifnum#1<1000 \expandafter\@gobble\number#1 % - \else\ifnum#1<10000 \expandafter\@gobbletwo\number#1 % - \else - \bbl@error - {Currently two-digit years are restricted to the\\ - range 0-9999.}% - {There is little you can do. Sorry.}% - \fi\fi\fi\fi}} -\newcommand\BabelDateyyyy[1]{{\number#1}} % FIXME - add leading 0 -\def\bbl@replace@finish@iii#1{% - \bbl@exp{\def\\#1####1####2####3{\the\toks@}}} -\def\bbl@TG@@date{% - \bbl@replace\bbl@toreplace{[ ]}{\BabelDateSpace{}}% - \bbl@replace\bbl@toreplace{[.]}{\BabelDateDot{}}% - \bbl@replace\bbl@toreplace{[d]}{\BabelDated{####3}}% - \bbl@replace\bbl@toreplace{[dd]}{\BabelDatedd{####3}}% - \bbl@replace\bbl@toreplace{[M]}{\BabelDateM{####2}}% - \bbl@replace\bbl@toreplace{[MM]}{\BabelDateMM{####2}}% - \bbl@replace\bbl@toreplace{[MMMM]}{\BabelDateMMMM{####2}}% - \bbl@replace\bbl@toreplace{[y]}{\BabelDatey{####1}}% - \bbl@replace\bbl@toreplace{[yy]}{\BabelDateyy{####1}}% - \bbl@replace\bbl@toreplace{[yyyy]}{\BabelDateyyyy{####1}}% -% Note after \bbl@replace \toks@ contains the resulting string. -% TODO - Using this implicit behavior doesn't seem a good idea. - \bbl@replace@finish@iii\bbl@toreplace} +\newcommand*\shorthandon[1]{\bbl@switch@sh\@ne#1\@nnil} +\DeclareRobustCommand*\shorthandoff{% + \@ifstar{\bbl@shorthandoff\tw@}{\bbl@shorthandoff\z@}} +\def\bbl@shorthandoff#1#2{\bbl@switch@sh#1#2\@nnil} % \end{macrocode} % -% Language and Script values to be used when defining a font or -% setting the direction are set with the following macros. +% \begin{macro}{\bbl@switch@sh} % -% \begin{macrocode} -\def\bbl@provide@lsys#1{% - \bbl@ifunset{bbl@lname@#1}% - {\bbl@ini@basic{#1}}% - {}% - \bbl@csarg\let{lsys@#1}\@empty - \bbl@ifunset{bbl@sname@#1}{\bbl@csarg\gdef{sname@#1}{Default}}{}% - \bbl@ifunset{bbl@sotf@#1}{\bbl@csarg\gdef{sotf@#1}{DFLT}}{}% - \bbl@csarg\bbl@add@list{lsys@#1}{Script=\bbl@cs{sname@#1}}% - \bbl@ifunset{bbl@lname@#1}{}% - {\bbl@csarg\bbl@add@list{lsys@#1}{Language=\bbl@cs{lname@#1}}}% - \ifcase\bbl@engine\or\or - \bbl@ifunset{bbl@prehc@#1}{}% - {\bbl@exp{\\\bbl@ifblank{\bbl@cs{prehc@#1}}}% - {}% - {\bbl@csarg\bbl@add@list{lsys@#1}{HyphenChar="200B}}}% - \fi - \bbl@csarg\bbl@toglobal{lsys@#1}} -% \end{macrocode} +% The macro |\bbl@switch@sh| takes the list of characters apart one +% by one and subsequently switches the category code of the +% shorthand character according to the first argument of +% |\bbl@switch@sh|. % -% The following |ini| reader ignores everything but the -% |identification| section. It is called when a font is defined (ie, -% when the language is first selected) to know which script/language -% must be enabled. This means we must make sure a few characters are -% not active. The |ini| is not read directly, but with a proxy |tex| -% file named as the language (which means any code in it must be -% skipped, too. +% 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. % % \begin{macrocode} -\def\bbl@ini@basic#1{% - \def\BabelBeforeIni##1##2{% - \begingroup - \bbl@add\bbl@secpost@identification{\closein\bbl@readstream }% - \catcode`\[=12 \catcode`\]=12 \catcode`\==12 \catcode`\;=12 % - \bbl@read@ini{##1}{font and identification data}% - \endinput % babel- .tex may contain onlypreamble's - \endgroup}% boxed, to avoid extra spaces: - {\setbox\z@\hbox{\InputIfFileExists{babel-#1.tex}{}{}}}} +\def\bbl@switch@sh#1#2{% + \ifx#2\@nnil\else + \bbl@ifunset{bbl@active@\string#2}% + {\bbl@error + {I cannot switch `\string#2' on or off--not a shorthand}% + {This character is not a shorthand. Maybe you made\\% + a typing mistake? I will ignore your instruction}}% + {\ifcase#1% + \catcode`#212\relax + \or + \catcode`#2\active + \or + \csname bbl@oricat@\string#2\endcsname + \csname bbl@oridef@\string#2\endcsname + \fi}% + \bbl@afterfi\bbl@switch@sh#1% + \fi} % \end{macrocode} % -% Alphabetic counters must be converted from a space separated list to -% an |\ifcase| structure. +% \end{macro} +% \end{macro} +% \end{macro} +% +% Note the value is that at the expansion time; eg, in the preample +% shorhands are usually deactivated. % % \begin{macrocode} -\def\bbl@buildifcase#1 {% Returns \bbl@tempa, requires \toks@={} - \ifx\\#1% % \\ before, in case #1 is multiletter - \bbl@exp{% - \def\\\bbl@tempa####1{% - \####1\space\the\toks@\\\\@ctrerr\}}% - \else - \toks@\expandafter{\the\toks@\or #1}% - \expandafter\bbl@buildifcase - \fi} +\def\babelshorthand{\active@prefix\babelshorthand\bbl@putsh} +\def\bbl@putsh#1{% + \bbl@ifunset{bbl@active@\string#1}% + {\bbl@putsh@i#1\@empty\@nnil}% + {\csname bbl@active@\string#1\endcsname}} +\def\bbl@putsh@i#1#2\@nnil{% + \csname\languagename @sh@\string#1@% + \ifx\@empty#2\else\string#2@\fi\endcsname} +\ifx\bbl@opt@shorthands\@nnil\else + \let\bbl@s@initiate@active@char\initiate@active@char + \def\initiate@active@char#1{% + \bbl@ifshorthand{#1}{\bbl@s@initiate@active@char{#1}}{}} + \let\bbl@s@switch@sh\bbl@switch@sh + \def\bbl@switch@sh#1#2{% + \ifx#2\@nnil\else + \bbl@afterfi + \bbl@ifshorthand{#2}{\bbl@s@switch@sh#1{#2}}{\bbl@switch@sh#1}% + \fi} + \let\bbl@s@activate\bbl@activate + \def\bbl@activate#1{% + \bbl@ifshorthand{#1}{\bbl@s@activate{#1}}{}} + \let\bbl@s@deactivate\bbl@deactivate + \def\bbl@deactivate#1{% + \bbl@ifshorthand{#1}{\bbl@s@deactivate{#1}}{}} +\fi % \end{macrocode} % -% The code for additive counters is somewhat tricky and it's based on -% the fact the arguments just before |\@@| collects digits which have -% been left ‘unused’ in previous arguments, the first of them being the -% number of digits in the number to be converted. This explains the -% reverse set |76543210|. Digits above 10000 are not handled yet. When -% the key contains the subkey |.F.|, the number after is treated as an -% special case. for a fixed form (see |babel-he.ini|, for example). +% You may want to test if a character is a shorthand. Note it does not +% test whether the shorthand is on or off. % % \begin{macrocode} -\newcommand\localenumeral[2]{\bbl@cs{cntr@#1@\languagename}{#2}} -\def\bbl@localecntr#1#2{\localenumeral{#2}{#1}} -\newcommand\localecounter[2]{% - \expandafter\bbl@localecntr\csname c@#2\endcsname{#1}} -\def\bbl@alphnumeral#1#2{% - \expandafter\bbl@alphnumeral@i\number#2 76543210\@@{#1}} -\def\bbl@alphnumeral@i#1#2#3#4#5#6#7#8\@@#9{% - \ifcase\@car#8\@nil\or % Currenty <10000, but prepared for bigger - \bbl@alphnumeral@ii{#9}000000#1\or - \bbl@alphnumeral@ii{#9}00000#1#2\or - \bbl@alphnumeral@ii{#9}0000#1#2#3\or - \bbl@alphnumeral@ii{#9}000#1#2#3#4\else - \bbl@alphnum@invalid{>9999}% - \fi} -\def\bbl@alphnumeral@ii#1#2#3#4#5#6#7#8{% - \bbl@ifunset{bbl@cntr@#1.F.\number#5#6#7#8@\languagename}% - {\bbl@cs{cntr@#1.4@\languagename}#5% - \bbl@cs{cntr@#1.3@\languagename}#6% - \bbl@cs{cntr@#1.2@\languagename}#7% - \bbl@cs{cntr@#1.1@\languagename}#8% - \ifnum#6#7#8>\z@ % An ad hod rule for Greek. Ugly. To be fixed. - \bbl@ifunset{bbl@cntr@#1.S.321@\languagename}{}% - {\bbl@cs{cntr@#1.S.321@\languagename}}% - \fi}% - {\bbl@cs{cntr@#1.F.\number#5#6#7#8@\languagename}}} -\def\bbl@alphnum@invalid#1{% - \bbl@error{Alphabetic numeral too large (#1)}% - {Currently this is the limit.}} +\newcommand\ifbabelshorthand[3]{\bbl@ifunset{bbl@active@\string#1}{#3}{#2}} % \end{macrocode} % -% The information in the identification section can be useful, so the -% following macro just exposes it with a user command. +% \begin{macro}{\bbl@prim@s} +% \begin{macro}{\bbl@pr@m@s} +% +% One of the internal macros that are involved in substituting |\prime| +% for each right quote in mathmode is |\prim@s|. This checks if the +% next character is a right quote. When the right quote is active, the +% definition of this macro needs to be adapted to look also for an +% active right quote; the hat could be active, too. % % \begin{macrocode} -\newcommand\localeinfo[1]{% - \bbl@ifunset{bbl@\csname bbl@info@#1\endcsname @\languagename}% - {\bbl@error{I've found no info for the current locale.\\% - The corresponding ini file has not been loaded\\% - Perhaps it doesn't exist}% - {See the manual for details.}}% - {\bbl@cs{\csname bbl@info@#1\endcsname @\languagename}}} -% \@namedef{bbl@info@name.locale}{lcname} -\@namedef{bbl@info@tag.ini}{lini} -\@namedef{bbl@info@name.english}{elname} -\@namedef{bbl@info@name.opentype}{lname} -\@namedef{bbl@info@tag.bcp47}{lbcp} -\@namedef{bbl@info@tag.opentype}{lotf} -\@namedef{bbl@info@script.name}{esname} -\@namedef{bbl@info@script.name.opentype}{sname} -\@namedef{bbl@info@script.tag.bcp47}{sbcp} -\@namedef{bbl@info@script.tag.opentype}{sotf} -\let\bbl@ensureinfo\@gobble -\newcommand\BabelEnsureInfo{% - \def\bbl@ensureinfo##1{% - \ifx\InputIfFileExists\@undefined\else % not in plain - \bbl@ifunset{bbl@lname@##1}{\bbl@ini@basic{##1}}{}% - \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|. -% -% \begin{macrocode} -\newcommand\getlocaleproperty[3]{% - \let#1\relax - \def\bbl@elt##1##2##3{% - \bbl@ifsamestring{##1/##2}{#3}% - {\providecommand#1{##3}% - \def\bbl@elt####1####2####3{}}% - {}}% - \bbl@cs{inidata@#2}% - \ifx#1\relax - \bbl@error - {Unknown key for locale '#2':\\% - #3\\% - \string#1 will be set to \relax}% - {Perhaps you misspelled it.}% - \fi} -\newcommand\LocaleForEach{\bbl@foreach\bbl@ini@loaded} +\def\bbl@prim@s{% + \prime\futurelet\@let@token\bbl@pr@m@s} +\def\bbl@if@primes#1#2{% + \ifx#1\@let@token + \expandafter\@firstoftwo + \else\ifx#2\@let@token + \bbl@afterelse\expandafter\@firstoftwo + \else + \bbl@afterfi\expandafter\@secondoftwo + \fi\fi} +\begingroup + \catcode`\^=7 \catcode`\*=\active \lccode`\*=`\^ + \catcode`\'=12 \catcode`\"=\active \lccode`\"=`\' + \lowercase{% + \gdef\bbl@pr@m@s{% + \bbl@if@primes"'% + \pr@@@s + {\bbl@if@primes*^\pr@@@t\egroup}}} +\endgroup % \end{macrocode} % -% \section{Adjusting the Babel bahavior} +% \end{macro} +% \end{macro} % -% A generic high level inteface is provided to adjust some global -% and general settings. +% Usually the |~| is active and expands to \verb*=\penalty\@M\ =. +% When it is written to the \file{.aux} file it is written +% expanded. To prevent that and to be able to use the character |~| +% as a start character for a shorthand, it is redefined here as a +% one character shorthand on system level. The system declaration +% is in most cases redundant (when |~| is still a non-break space), +% and in some cases is inconvenient (if |~| has been redefined); +% however, for backward compatibility it is maintained (some +% existing documents may rely on the \babel{} value). % % \begin{macrocode} -\newcommand\babeladjust[1]{% TODO. Error handling. - \bbl@forkv{#1}{\bbl@cs{ADJ@##1@##2}}} -% -\def\bbl@adjust@lua#1#2{% - \ifvmode - \ifnum\currentgrouplevel=\z@ - \directlua{ Babel.#2 }% - \expandafter\expandafter\expandafter\@gobble - \fi - \fi - {\bbl@error % The error is gobbled if everything went ok. - {Currently, #1 related features can be adjusted only\\% - in the main vertical list.}% - {Maybe things change in the future, but this is what it is.}}} -\@namedef{bbl@ADJ@bidi.mirroring@on}{% - \bbl@adjust@lua{bidi}{mirroring_enabled=true}} -\@namedef{bbl@ADJ@bidi.mirroring@off}{% - \bbl@adjust@lua{bidi}{mirroring_enabled=false}} -\@namedef{bbl@ADJ@bidi.text@on}{% - \bbl@adjust@lua{bidi}{bidi_enabled=true}} -\@namedef{bbl@ADJ@bidi.text@off}{% - \bbl@adjust@lua{bidi}{bidi_enabled=false}} -\@namedef{bbl@ADJ@bidi.mapdigits@on}{% - \bbl@adjust@lua{bidi}{digits_mapped=true}} -\@namedef{bbl@ADJ@bidi.mapdigits@off}{% - \bbl@adjust@lua{bidi}{digits_mapped=false}} -% -\@namedef{bbl@ADJ@linebreak.sea@on}{% - \bbl@adjust@lua{linebreak}{sea_enabled=true}} -\@namedef{bbl@ADJ@linebreak.sea@off}{% - \bbl@adjust@lua{linebreak}{sea_enabled=false}} -\@namedef{bbl@ADJ@linebreak.cjk@on}{% - \bbl@adjust@lua{linebreak}{cjk_enabled=true}} -\@namedef{bbl@ADJ@linebreak.cjk@off}{% - \bbl@adjust@lua{linebreak}{cjk_enabled=false}} -% -\def\bbl@adjust@layout#1{% - \ifvmode - #1% - \expandafter\@gobble - \fi - {\bbl@error % The error is gobbled if everything went ok. - {Currently, layout related features can be adjusted only\\% - in vertical mode.}% - {Maybe things change in the future, but this is what it is.}}} -\@namedef{bbl@ADJ@layout.tabular@on}{% - \bbl@adjust@layout{\let\@tabular\bbl@NL@@tabular}} -\@namedef{bbl@ADJ@layout.tabular@off}{% - \bbl@adjust@layout{\let\@tabular\bbl@OL@@tabular}} -\@namedef{bbl@ADJ@layout.lists@on}{% - \bbl@adjust@layout{\let\list\bbl@NL@list}} -\@namedef{bbl@ADJ@layout.lists@on}{% - \bbl@adjust@layout{\let\list\bbl@OL@list}} -\@namedef{bbl@ADJ@hyphenation.extra@on}{% - \bbl@activateposthyphen} +\initiate@active@char{~} +\declare@shorthand{system}{~}{\leavevmode\nobreak\ } +\bbl@activate{~} % \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{macro}{\OT1dqpos} +% \begin{macro}{\T1dqpos} +% The position of the double quote character is different for the +% OT1 and T1 encodings. It will later be selected using the +% |\f@encoding| macro. Therefore we define two macros here to store +% the position of the character in these encodings. % % \begin{macrocode} -{\def\format{lplain} -\ifx\fmtname\format -\else - \def\format{LaTeX2e} - \ifx\fmtname\format - \else - \aftergroup\endinput - \fi -\fi} +\expandafter\def\csname OT1dqpos\endcsname{127} +\expandafter\def\csname T1dqpos\endcsname{4} % \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. +% When the macro |\f@encoding| is undefined (as it is in plain +% \TeX) we define it here to expand to \texttt{OT1} % % \begin{macrocode} -%\bbl@redefine\newlabel#1#2{% -% \@safe@activestrue\org@newlabel{#1}{#2}\@safe@activesfalse} +\ifx\f@encoding\@undefined + \def\f@encoding{OT1} +\fi % \end{macrocode} % % \end{macro} +% \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}} -%<> -% \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} +% \subsection{Language attributes} % -% \end{macro} +% Language attributes provide a means to give the user control over +% which features of the language definition files he wants to +% enable. +% \begin{macro}{\languageattribute} % -% \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. +% The macro |\languageattribute| checks whether its arguments are +% valid and then activates the selected language attribute. +% First check whether the language is known, and then process each +% attribute in the list. % % \begin{macrocode} - \CheckCommand*\@testdef[3]{% - \def\reserved@a{#3}% - \expandafter\ifx\csname#1@#2\endcsname\reserved@a - \else - \@tempswatrue - \fi} +\bbl@trace{Language attributes} +\newcommand\languageattribute[2]{% + \def\bbl@tempc{#1}% + \bbl@fixname\bbl@tempc + \bbl@iflanguage\bbl@tempc{% + \bbl@vforeach{#2}{% % \end{macrocode} % -% Now that we made sure that |\@testdef| still has the same -% definition we can rewrite it. First we make the shorthands -% `safe'. +% We want to make sure that each attribute is selected only once; +% therefore we store the already selected attributes in +% |\bbl@known@attribs|. When that control sequence is not yet +% defined this attribute is certainly not selected before. % % \begin{macrocode} - \def\@testdef#1#2#3{% - \@safe@activestrue + \ifx\bbl@known@attribs\@undefined + \in@false + \else + \bbl@xin@{,\bbl@tempc-##1,}{,\bbl@known@attribs,}% + \fi + \ifin@ + \bbl@warning{% + You have more than once selected the attribute '##1'\\% + for language #1. Reported}% + \else % \end{macrocode} % -% Then we use |\bbl@tempa| as an `alias' for the macro that -% contains the label which is being checked. +% When we end up here the attribute is not selected before. So, we +% add it to the list of selected attributes and execute the +% associated \TeX-code. % % \begin{macrocode} - \expandafter\let\expandafter\bbl@tempa\csname #1@#2\endcsname + \bbl@exp{% + \\\bbl@add@list\\\bbl@known@attribs{\bbl@tempc-##1}}% + \edef\bbl@tempa{\bbl@tempc-##1}% + \expandafter\bbl@ifknown@ttrib\expandafter{\bbl@tempa}\bbl@attributes% + {\csname\bbl@tempc @attr@##1\endcsname}% + {\@attrerr{\bbl@tempc}{##1}}% + \fi}}} +\@onlypreamble\languageattribute % \end{macrocode} % -% Then we define |\bbl@tempb| just as |\@newl@bel| does it. +% The error text to be issued when an unknown attribute is +% selected. % % \begin{macrocode} - \def\bbl@tempb{#3}% - \@safe@activesfalse +\newcommand*{\@attrerr}[2]{% + \bbl@error + {The attribute #2 is unknown for language #1.}% + {Your command will be ignored, type to proceed}} % \end{macrocode} % -% When the label is defined we replace the definition of -% |\bbl@tempa| by its meaning. +% \end{macro} % -% \begin{macrocode} - \ifx\bbl@tempa\relax - \else - \edef\bbl@tempa{\expandafter\strip@prefix\meaning\bbl@tempa}% - \fi -% \end{macrocode} +% \begin{macro}{\bbl@declare@ttribute} +% This command adds the new language/attribute combination to the +% list of known attributes. % -% We do the same for |\bbl@tempb|. +% Then it defines a control sequence to be executed when the +% attribute is used in a document. The result of this should be +% that the macro |\extras...| for the current language is extended, +% otherwise the attribute will not work as its code is removed from +% memory at |\begin{document}|. % % \begin{macrocode} - \edef\bbl@tempb{\expandafter\strip@prefix\meaning\bbl@tempb}% +\def\bbl@declare@ttribute#1#2#3{% + \bbl@xin@{,#2,}{,\BabelModifiers,}% + \ifin@ + \AfterBabelLanguage{#1}{\languageattribute{#1}{#2}}% + \fi + \bbl@add@list\bbl@attributes{#1-#2}% + \expandafter\def\csname#1@attr@#2\endcsname{#3}} % \end{macrocode} % -% If the label didn't change, |\bbl@tempa| and |\bbl@tempb| should -% be identical macros. +% \end{macro} % -% \begin{macrocode} - \ifx\bbl@tempa\bbl@tempb - \else - \@tempswatrue - \fi} -\fi -% \end{macrocode} +% \begin{macro}{\bbl@ifattributeset} +% This internal macro has 4 arguments. It can be used to interpret +% \TeX\ code based on whether a certain attribute was set. This +% command should appear inside the argument to |\AtBeginDocument| +% because the attributes are set in the document preamble, +% \emph{after} \babel\ is loaded. % -% \end{macro} +% The first argument is the language, the second argument the +% attribute being checked, and the third and fourth arguments are +% the true and false clauses. % -% \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. +% 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} -\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 +\def\bbl@ifattributeset#1#2#3#4{% + \ifx\bbl@known@attribs\@undefined + \in@false + \else + \bbl@xin@{,#1-#2,}{,\bbl@known@attribs,}% + \fi + \ifin@ + \bbl@afterelse#3% + \else + \bbl@afterfi#4% + \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} +% \begin{macro}{\bbl@ifknown@ttrib} +% An internal macro to check whether a given language/attribute is +% known. The macro takes 4 arguments, the language/attribute, the +% attribute list, the \TeX-code to be executed when the attribute +% is known and the \TeX-code to be executed otherwise. % -% 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. +% 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} - \AtBeginDocument{% - \@ifpackageloaded{natbib}{% +\def\bbl@ifknown@ttrib#1#2{% + \let\bbl@tempa\@secondoftwo + \bbl@loopx\bbl@tempb{#2}{% + \expandafter\in@\expandafter{\expandafter,\bbl@tempb,}{,#1,}% + \ifin@ + \let\bbl@tempa\@firstoftwo + \else + \fi}% + \bbl@tempa +} % \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). +% \end{macro} % -% (Recent versions of \pkg{natbib} change dynamically |\@citex|, so PR4087 -% doesn't seem fixable in a simple way. Just load \pkg{natbib} before.) +% \begin{macro}{\bbl@clear@ttribs} +% This macro removes all the attribute code from \LaTeX's memory at +% |\begin{document}| time (if any is present). % % \begin{macrocode} - \def\@citex[#1][#2]#3{% - \@safe@activestrue\edef\@tempa{#3}\@safe@activesfalse - \org@@citex[#1][#2]{\@tempa}}% - }{}} +\def\bbl@clear@ttribs{% + \ifx\bbl@attributes\@undefined\else + \bbl@loopx\bbl@tempa{\bbl@attributes}{% + \expandafter\bbl@clear@ttrib\bbl@tempa. + }% + \let\bbl@attributes\@undefined + \fi} +\def\bbl@clear@ttrib#1-#2.{% + \expandafter\let\csname#1@attr@#2\endcsname\@undefined} +\AtBeginDocument{\bbl@clear@ttribs} % \end{macrocode} % -% The package \pkg{cite} has a definition of |\@citex| where the -% shorthands need to be turned off in both arguments. +% \end{macro} % -% \begin{macrocode} - \AtBeginDocument{% - \@ifpackageloaded{cite}{% - \def\@citex[#1]#2{% - \@safe@activestrue\org@@citex[#1]{#2}\@safe@activesfalse}% - }{}} -% \end{macrocode} +% \subsection{Support for saving macro definitions} % -% \end{macro} +% To save the meaning of control sequences using |\babel@save|, we +% use temporary control sequences. To save hash table entries for +% these control sequences, we don't use the name of the control +% sequence to be saved to construct the temporary name. Instead we +% simply use the value of a counter, which is reset to zero each time +% we begin to save new values. This works well because we release +% the saved meanings before we begin to save a new set of control +% sequence meanings (see |\selectlanguage| and |\originalTeX|). Note +% undefined macros are not undefined any more when saved -- they are +% |\relax|'ed. % -% \begin{macro}{\nocite} -% The macro |\nocite| which is used to instruct BiB\TeX\ to -% extract uncited references from the database. +% \begin{macro}{\babel@savecnt} +% \begin{macro}{\babel@beginsave} +% The initialization of a new save cycle: reset the counter to +% zero. % % \begin{macrocode} - \bbl@redefine\nocite#1{% - \@safe@activestrue\org@nocite{#1}\@safe@activesfalse} +\bbl@trace{Macros for saving definitions} +\def\babel@beginsave{\babel@savecnt\z@} % \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. +% Before it's forgotten, allocate the counter and initialize all. % % \begin{macrocode} - \bbl@redefine\bibcite{% - \bbl@cite@choice - \bibcite} +\newcount\babel@savecnt +\babel@beginsave % \end{macrocode} % % \end{macro} +% \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{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. % % \begin{macrocode} - \def\bbl@bibcite#1#2{% - \org@bibcite{#1}{\@safe@activesfalse#2}} +\def\babel@save#1{% + \expandafter\let\csname babel@\number\babel@savecnt\endcsname#1\relax + \toks@\expandafter{\originalTeX\let#1=}% + \bbl@exp{% + \def\\\originalTeX{\the\toks@\\relax}}% + \advance\babel@savecnt\@ne} +\def\babel@savevariable#1{% + \toks@\expandafter{\originalTeX #1=}% + \bbl@exp{\def\\\originalTeX{\the\toks@\the#1\relax}}} % \end{macrocode} % % \end{macro} +% \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{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. % % \begin{macrocode} - \def\bbl@cite@choice{% - \global\let\bibcite\bbl@bibcite +\def\bbl@frenchspacing{% + \ifnum\the\sfcode`\.=\@m + \let\bbl@nonfrenchspacing\relax + \else + \frenchspacing + \let\bbl@nonfrenchspacing\nonfrenchspacing + \fi} +\let\bbl@nonfrenchspacing\nonfrenchspacing % \end{macrocode} % -% Then, when \pkg{natbib} is loaded we restore the original -% definition of |\bibcite|. For \pkg{cite} we do the same. +% \end{macro} +% \end{macro} % -% \begin{macrocode} - \@ifpackageloaded{natbib}{\global\let\bibcite\org@bibcite}{}% - \@ifpackageloaded{cite}{\global\let\bibcite\org@bibcite}{}% -% \end{macrocode} +% \subsection{Short tags} % -% Make sure this only happens once. +% \begin{macro}{\babeltags} +% This macro is straightforward. After zapping spaces, we +% loop over the list and define the macros |\text|\m{tag} and +% |\|\m{tag}. Definitions are first expanded so that they don't +% contain |\csname| but the actual macro. % -% \begin{macrocode} - \global\let\bbl@cite@choice\relax} +% \begin{macrocode} +\bbl@trace{Short tags} +\def\babeltags#1{% + \edef\bbl@tempa{\zap@space#1 \@empty}% + \def\bbl@tempb##1=##2\@@{% + \edef\bbl@tempc{% + \noexpand\newcommand + \expandafter\noexpand\csname ##1\endcsname{% + \noexpand\protect + \expandafter\noexpand\csname otherlanguage*\endcsname{##2}} + \noexpand\newcommand + \expandafter\noexpand\csname text##1\endcsname{% + \noexpand\foreignlanguage{##2}}} + \bbl@tempc}% + \bbl@for\bbl@tempa\bbl@tempa{% + \expandafter\bbl@tempb\bbl@tempa\@@}} % \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. +% \end{macro} % -% \begin{macrocode} - \AtBeginDocument{\bbl@cite@choice} -% \end{macrocode} +% \subsection{Hyphens} % -% \end{macro} +% \begin{macro}{\babelhyphenation} % -% \begin{macro}{\@bibitem} -% One of the two internal \LaTeX\ macros called by |\bibitem| -% that write the citation label on the |.aux| file. +% This macro saves hyphenation exceptions. Two macros are used to +% store them: |\bbl@hyphenation@| for the global ones and +% |\bbl@hyphenation| 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@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 +\bbl@trace{Hyphens} +\@onlypreamble\babelhyphenation +\AtEndOfPackage{% + \newcommand\babelhyphenation[2][\@empty]{% + \ifx\bbl@hyphenation@\relax + \let\bbl@hyphenation@\@empty + \fi + \ifx\bbl@hyphlist\@empty\else + \bbl@warning{% + You must not intermingle \string\selectlanguage\space and\\% + \string\babelhyphenation\space or some exceptions will not\\% + be taken into account. Reported}% + \fi + \ifx\@empty#1% + \protected@edef\bbl@hyphenation@{\bbl@hyphenation@\space#2}% + \else + \bbl@vforeach{#1}{% + \def\bbl@tempa{##1}% + \bbl@fixname\bbl@tempa + \bbl@iflanguage\bbl@tempa{% + \bbl@csarg\protected@edef{hyphenation@\bbl@tempa}{% + \bbl@ifunset{bbl@hyphenation@\bbl@tempa}% + \@empty + {\csname bbl@hyphenation@\bbl@tempa\endcsname\space}% + #2}}}% + \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}{\bbl@allowhyphens} % -% \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.) +% 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} - \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 +\def\bbl@allowhyphens{\ifvmode\else\nobreak\hskip\z@skip\fi} +\def\bbl@t@one{T1} +\def\allowhyphens{\ifx\cf@encoding\bbl@t@one\else\bbl@allowhyphens\fi} % \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. +% \begin{macro}{\babelhyphen} % -% The first thing we need to do is check if the package -% \pkg{ifthen} is loaded. This should be done at |\begin{document}| -% time. +% 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} -\bbl@trace{Preventing clashes with other packages} -\bbl@xin@{R}\bbl@opt@safe -\ifin@ - \AtBeginDocument{% - \@ifpackageloaded{ifthen}{% +\newcommand\babelnullhyphen{\char\hyphenchar\font} +\def\babelhyphen{\active@prefix\babelhyphen\bbl@hyphen} +\def\bbl@hyphen{% + \@ifstar{\bbl@hyphen@i @}{\bbl@hyphen@i\@empty}} +\def\bbl@hyphen@i#1#2{% + \bbl@ifunset{bbl@hy@#1#2\@empty}% + {\csname bbl@#1usehyphen\endcsname{\discretionary{#2}{}{#2}}}% + {\csname bbl@hy@#1#2\@empty\endcsname}} % \end{macrocode} % -% Then we can redefine |\ifthenelse|: +% 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. % % \begin{macrocode} - \bbl@redefine@long\ifthenelse#1#2#3{% +\def\bbl@usehyphen#1{% + \leavevmode + \ifdim\lastskip>\z@\mbox{#1}\else\nobreak#1\fi + \nobreak\hskip\z@skip} +\def\bbl@@usehyphen#1{% + \leavevmode\ifdim\lastskip>\z@\mbox{#1}\else#1\fi} % \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. +% The following macro inserts the hyphen char. % % \begin{macrocode} - \let\bbl@temp@pref\pageref - \let\pageref\org@pageref - \let\bbl@temp@ref\ref - \let\ref\org@ref +\def\bbl@hyphenchar{% + \ifnum\hyphenchar\font=\m@ne + \babelnullhyphen + \else + \char\hyphenchar\font + \fi} % \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. +% Finally, we define the hyphen ``types''. Their names will not +% change, so you may use them in |ldf|'s. After a space, the +% |\mbox| in |\bbl@hy@nobreak| is redundant. % % \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}% - }% - }{}% - } +\def\bbl@hy@soft{\bbl@usehyphen{\discretionary{\bbl@hyphenchar}{}{}}} +\def\bbl@hy@@soft{\bbl@@usehyphen{\discretionary{\bbl@hyphenchar}{}{}}} +\def\bbl@hy@hard{\bbl@usehyphen\bbl@hyphenchar} +\def\bbl@hy@@hard{\bbl@@usehyphen\bbl@hyphenchar} +\def\bbl@hy@nobreak{\bbl@usehyphen{\mbox{\bbl@hyphenchar}}} +\def\bbl@hy@@nobreak{\mbox{\bbl@hyphenchar}} +\def\bbl@hy@repeat{% + \bbl@usehyphen{% + \discretionary{\bbl@hyphenchar}{\bbl@hyphenchar}{\bbl@hyphenchar}}} +\def\bbl@hy@@repeat{% + \bbl@@usehyphen{% + \discretionary{\bbl@hyphenchar}{\bbl@hyphenchar}{\bbl@hyphenchar}}} +\def\bbl@hy@empty{\hskip\z@skip} +\def\bbl@hy@@empty{\discretionary{}{}{}} % \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{macro}{\bbl@disc} +% For some languages the macro |\bbl@disc| is used to ease the +% insertion of discretionaries for letters that behave `abnormally' +% at a breakpoint. % % \begin{macrocode} - \expandafter\def\csname Ref \endcsname#1{% - \protected@edef\@tempa{\org@ref{#1}}\expandafter\MakeUppercase\@tempa} - }{}% - } -\fi +\def\bbl@disc#1#2{\nobreak\discretionary{#2-}{}{#1}\bbl@allowhyphens} % \end{macrocode} % % \end{macro} -% \end{macro} -% \end{macro} % -% \subsubsection{\pkg{hhline}} +% \subsection{Multiencoding strings} % -% \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. +% The aim following commands is to provide a commom interface for +% strings in several encodings. They also contains several hooks which +% can be used by \luatex{} and \xetex. The code is organized here with +% pseudo-guards, so we start with the basic commands. +% +% \paragraph{Tools} % -% So at |\begin{document}| we check whether \pkg{hhline} is loaded. +% But first, a couple of tools. The first one makes global a local +% variable. This is not the best solution, but it works. % % \begin{macrocode} -\AtEndOfPackage{% - \AtBeginDocument{% - \@ifpackageloaded{hhline}% +\bbl@trace{Multiencoding strings} +\def\bbl@toglobal#1{\global\let#1#1} +\def\bbl@recatcode#1{% TODO. Used only once? + \@tempcnta="7F + \def\bbl@tempa{% + \ifnum\@tempcnta>"FF\else + \catcode\@tempcnta=#1\relax + \advance\@tempcnta\@ne + \expandafter\bbl@tempa + \fi}% + \bbl@tempa} % \end{macrocode} % -% Then we check whether the expansion of |\normal@char:| is not -% equal to |\relax|. +% The second one. We need to patch |\@uclclist|, but it is done once +% and only if |\SetCase| is used or if strings are encoded. The code +% is far from satisfactory for several reasons, including the fact +% |\@uclclist| is not a list any more. Therefore a package option is +% added to ignore it. Instead of gobbling the macro +% getting the next two elements (usually |\reserved@a|), we pass it as +% argument to |\bbl@uclc|. The parser is restarted inside +% |\|\m{lang}|@bbl@uclc| because we do not know how many expansions +% are necessary (depends on whether strings are encoded). The last +% part is tricky -- when uppercasing, we have: +%\begin{verbatim} +% \let\bbl@tolower\@empty\bbl@toupper\@empty +%\end{verbatim} +% and starts over (and similarly when lowercasing). % % \begin{macrocode} - {\expandafter\ifx\csname normal@char\string:\endcsname\relax - \else +\@ifpackagewith{babel}{nocase}% + {\let\bbl@patchuclc\relax}% + {\def\bbl@patchuclc{% + \global\let\bbl@patchuclc\relax + \g@addto@macro\@uclclist{\reserved@b{\reserved@b\bbl@uclc}}% + \gdef\bbl@uclc##1{% + \let\bbl@encoded\bbl@encoded@uclc + \bbl@ifunset{\languagename @bbl@uclc}% and resumes it + {##1}% + {\let\bbl@tempa##1\relax % Used by LANG@bbl@uclc + \csname\languagename @bbl@uclc\endcsname}% + {\bbl@tolower\@empty}{\bbl@toupper\@empty}}% + \gdef\bbl@tolower{\csname\languagename @bbl@lc\endcsname}% + \gdef\bbl@toupper{\csname\languagename @bbl@uc\endcsname}}} % \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} +%<<*More package options>> +\DeclareOption{nocase}{} +%<> +% \end{macrocode} +% +% The following package options control the behavior of |\SetString|. % % \begin{macrocode} - \makeatletter - \def\@currname{hhline}\input{hhline.sty}\makeatother - \fi}% - {}}} +%<<*More package options>> +\let\bbl@opt@strings\@nnil % accept strings=value +\DeclareOption{strings}{\def\bbl@opt@strings{\BabelStringsDefault}} +\DeclareOption{strings=encoded}{\let\bbl@opt@strings\relax} +\def\BabelStringsDefault{generic} +%<> % \end{macrocode} % -% \end{macro} +% \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. % -% \subsubsection{\pkg{hyperref}} +% \begin{macrocode} +\@onlypreamble\StartBabelCommands +\def\StartBabelCommands{% + \begingroup + \bbl@recatcode{11}% + <@Macros local to BabelCommands@> + \def\bbl@provstring##1##2{% + \providecommand##1{##2}% + \bbl@toglobal##1}% + \global\let\bbl@scafter\@empty + \let\StartBabelCommands\bbl@startcmds + \ifx\BabelLanguages\relax + \let\BabelLanguages\CurrentOption + \fi + \begingroup + \let\bbl@screset\@nnil % local flag - disable 1st stopcommands + \StartBabelCommands} +\def\bbl@startcmds{% + \ifx\bbl@screset\@nnil\else + \bbl@usehooks{stopcommands}{}% + \fi + \endgroup + \begingroup + \@ifstar + {\ifx\bbl@opt@strings\@nnil + \let\bbl@opt@strings\BabelStringsDefault + \fi + \bbl@startcmds@i}% + \bbl@startcmds@i} +\def\bbl@startcmds@i#1#2{% + \edef\bbl@L{\zap@space#1 \@empty}% + \edef\bbl@G{\zap@space#2 \@empty}% + \bbl@startcmds@ii} +\let\bbl@startcommands\StartBabelCommands +% \end{macrocode} % -% \begin{macro}{\pdfstringdefDisableCommands} +% Parse the encoding info to get the label, input, and font parts. % -% 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. +% 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. % % \begin{macrocode} -\AtBeginDocument{% - \ifx\pdfstringdefDisableCommands\@undefined\else - \pdfstringdefDisableCommands{\languageshorthands{system}}% +\newcommand\bbl@startcmds@ii[1][\@empty]{% + \let\SetString\@gobbletwo + \let\bbl@stringdef\@gobbletwo + \let\AfterBabelCommands\@gobble + \ifx\@empty#1% + \def\bbl@sc@label{generic}% + \def\bbl@encstring##1##2{% + \ProvideTextCommandDefault##1{##2}% + \bbl@toglobal##1% + \expandafter\bbl@toglobal\csname\string?\string##1\endcsname}% + \let\bbl@sctest\in@true + \else + \let\bbl@sc@charset\space % <- zapped below + \let\bbl@sc@fontenc\space % <- " " + \def\bbl@tempa##1=##2\@nil{% + \bbl@csarg\edef{sc@\zap@space##1 \@empty}{##2 }}% + \bbl@vforeach{label=#1}{\bbl@tempa##1\@nil}% + \def\bbl@tempa##1 ##2{% space -> comma + ##1% + \ifx\@empty##2\else\ifx,##1,\else,\fi\bbl@afterfi\bbl@tempa##2\fi}% + \edef\bbl@sc@fontenc{\expandafter\bbl@tempa\bbl@sc@fontenc\@empty}% + \edef\bbl@sc@label{\expandafter\zap@space\bbl@sc@label\@empty}% + \edef\bbl@sc@charset{\expandafter\zap@space\bbl@sc@charset\@empty}% + \def\bbl@encstring##1##2{% + \bbl@foreach\bbl@sc@fontenc{% + \bbl@ifunset{T@####1}% + {}% + {\ProvideTextCommand##1{####1}{##2}% + \bbl@toglobal##1% + \expandafter + \bbl@toglobal\csname####1\string##1\endcsname}}}% + \def\bbl@sctest{% + \bbl@xin@{,\bbl@opt@strings,}{,\bbl@sc@label,\bbl@sc@fontenc,}}% + \fi + \ifx\bbl@opt@strings\@nnil % ie, no strings key -> defaults + \else\ifx\bbl@opt@strings\relax % ie, strings=encoded + \let\AfterBabelCommands\bbl@aftercmds + \let\SetString\bbl@setstring + \let\bbl@stringdef\bbl@encstring + \else % ie, strings=value + \bbl@sctest + \ifin@ + \let\AfterBabelCommands\bbl@aftercmds + \let\SetString\bbl@setstring + \let\bbl@stringdef\bbl@provstring + \fi\fi\fi + \bbl@scswitch + \ifx\bbl@G\@empty + \def\SetString##1##2{% + \bbl@error{Missing group for string \string##1}% + {You must assign strings to some category, typically\\% + captions or extras, but you set none}}% + \fi + \ifx\@empty#1% + \bbl@usehooks{defaultcommands}{}% + \else + \@expandtwoargs + \bbl@usehooks{encodedcommands}{{\bbl@sc@charset}{\bbl@sc@fontenc}}% \fi} % \end{macrocode} % -% \end{macro} -% -% \subsubsection{\pkg{fancyhdr}} +% 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. % -% \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. +% 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} -\DeclareRobustCommand{\FOREIGNLANGUAGE}[1]{% - \lowercase{\foreignlanguage{#1}}} +% \begin{macrocode} +\def\bbl@forlang#1#2{% + \bbl@for#1\bbl@L{% + \bbl@xin@{,#1,}{,\BabelLanguages,}% + \ifin@#2\relax\fi}} +\def\bbl@scswitch{% + \bbl@forlang\bbl@tempa{% + \ifx\bbl@G\@empty\else + \ifx\SetString\@gobbletwo\else + \edef\bbl@GL{\bbl@G\bbl@tempa}% + \bbl@xin@{,\bbl@GL,}{,\bbl@screset,}% + \ifin@\else + \global\expandafter\let\csname\bbl@GL\endcsname\@undefined + \xdef\bbl@screset{\bbl@screset,\bbl@GL}% + \fi + \fi + \fi}} +\AtEndOfPackage{% + \def\bbl@forlang#1#2{\bbl@for#1\bbl@L{\bbl@ifunset{date#1}{}{#2}}}% + \let\bbl@scswitch\relax} +\@onlypreamble\EndBabelCommands +\def\EndBabelCommands{% + \bbl@usehooks{stopcommands}{}% + \endgroup + \endgroup + \bbl@scafter} +\let\bbl@endcommands\EndBabelCommands % \end{macrocode} % -% \end{macro} +% Now we define commands to be used inside |\StartBabelCommands|. % -% \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. +% \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. % % \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 - } +\def\bbl@setstring#1#2{% + \bbl@forlang\bbl@tempa{% + \edef\bbl@LC{\bbl@tempa\bbl@stripslash#1}% + \bbl@ifunset{\bbl@LC}% eg, \germanchaptername + {\global\expandafter % TODO - con \bbl@exp ? + \bbl@add\csname\bbl@G\bbl@tempa\expandafter\endcsname\expandafter + {\expandafter\bbl@scset\expandafter#1\csname\bbl@LC\endcsname}}% + {}% + \def\BabelString{#2}% + \bbl@usehooks{stringprocess}{}% + \expandafter\bbl@stringdef + \csname\bbl@LC\expandafter\endcsname\expandafter{\BabelString}}} % \end{macrocode} % -% This command should only be used in the preamble of a document. +% Now, some addtional stuff to be used when encoded strings are +% used. Captions then include |\bbl@encoded| for string to be +% expanded in case transformations. It is |\relax| by default, but +% in |\MakeUppercase| and |\MakeLowercase| its value is a modified +% expandable |\@changed@cmd|. % % \begin{macrocode} -\@onlypreamble\substitutefontfamily +\ifx\bbl@opt@strings\relax + \def\bbl@scset#1#2{\def#1{\bbl@encoded#2}} + \bbl@patchuclc + \let\bbl@encoded\relax + \def\bbl@encoded@uclc#1{% + \@inmathwarn#1% + \expandafter\ifx\csname\cf@encoding\string#1\endcsname\relax + \expandafter\ifx\csname ?\string#1\endcsname\relax + \TextSymbolUnavailable#1% + \else + \csname ?\string#1\endcsname + \fi + \else + \csname\cf@encoding\string#1\endcsname + \fi} +\else + \def\bbl@scset#1#2{\def#1{#2}} +\fi % \end{macrocode} % -% \end{macro} +% 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. % -% \subsection{Encoding and fonts} +% \begin{macrocode} +%<<*Macros local to BabelCommands>> +\def\SetStringLoop##1##2{% + \def\bbl@templ####1{\expandafter\noexpand\csname##1\endcsname}% + \count@\z@ + \bbl@loop\bbl@tempa{##2}{% empty items and spaces are ok + \advance\count@\@ne + \toks@\expandafter{\bbl@tempa}% + \bbl@exp{% + \\\SetString\bbl@templ{\romannumeral\count@}{\the\toks@}% + \count@=\the\count@\relax}}}% +%<> +% \end{macrocode} % -% 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|. +% \paragraph{Delaying code} Now the definition of |\AfterBabelCommands| +% when it is activated. % -% \begin{macro}{\ensureascii} +% \begin{macrocode} +\def\bbl@aftercmds#1{% + \toks@\expandafter{\bbl@scafter#1}% + \xdef\bbl@scafter{\the\toks@}} +% \end{macrocode} +% +% \paragraph{Case mapping} +% +% The command |\SetCase| provides a way to change the behavior of +% |\MakeUppercase| and |\MakeLowercase|. |\bbl@tempa| is set by the +% patched |\@uclclist| to the parsing command. % % \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} +%<<*Macros local to BabelCommands>> + \newcommand\SetCase[3][]{% + \bbl@patchuclc + \bbl@forlang\bbl@tempa{% + \expandafter\bbl@encstring + \csname\bbl@tempa @bbl@uclc\endcsname{\bbl@tempa##1}% + \expandafter\bbl@encstring + \csname\bbl@tempa @bbl@uc\endcsname{##2}% + \expandafter\bbl@encstring + \csname\bbl@tempa @bbl@lc\endcsname{##3}}}% +%<> % \end{macrocode} % -% \end{macro} +% Macros to deal with case mapping for hyphenation. To decide if the +% document is monolingual or multilingual, we make a rough guess -- +% just see if there is a comma in the languages list, built in the +% first pass of the package options. % -% 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{macrocode} +%<<*Macros local to BabelCommands>> + \newcommand\SetHyphenMap[1]{% + \bbl@forlang\bbl@tempa{% + \expandafter\bbl@stringdef + \csname\bbl@tempa @bbl@hyphenmap\endcsname{##1}}}% +%<> +% \end{macrocode} % -% \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. +% There are 3 helper macros which do most of the work for you. +% +% \begin{macrocode} +\newcommand\BabelLower[2]{% one to one. + \ifnum\lccode#1=#2\else + \babel@savevariable{\lccode#1}% + \lccode#1=#2\relax + \fi} +\newcommand\BabelLowerMM[4]{% many-to-many + \@tempcnta=#1\relax + \@tempcntb=#4\relax + \def\bbl@tempa{% + \ifnum\@tempcnta>#2\else + \@expandtwoargs\BabelLower{\the\@tempcnta}{\the\@tempcntb}% + \advance\@tempcnta#3\relax + \advance\@tempcntb#3\relax + \expandafter\bbl@tempa + \fi}% + \bbl@tempa} +\newcommand\BabelLowerMO[4]{% many-to-one + \@tempcnta=#1\relax + \def\bbl@tempa{% + \ifnum\@tempcnta>#2\else + \@expandtwoargs\BabelLower{\the\@tempcnta}{#4}% + \advance\@tempcnta#3 + \expandafter\bbl@tempa + \fi}% + \bbl@tempa} +% \end{macrocode} +% +% The following package options control the behavior of +% hyphenation mapping. % % \begin{macrocode} -\AtEndOfPackage{\edef\latinencoding{\cf@encoding}} +%<<*More package options>> +\DeclareOption{hyphenmap=off}{\chardef\bbl@opt@hyphenmap\z@} +\DeclareOption{hyphenmap=first}{\chardef\bbl@opt@hyphenmap\@ne} +\DeclareOption{hyphenmap=select}{\chardef\bbl@opt@hyphenmap\tw@} +\DeclareOption{hyphenmap=other}{\chardef\bbl@opt@hyphenmap\thr@@} +\DeclareOption{hyphenmap=other*}{\chardef\bbl@opt@hyphenmap4\relax} +%<> % \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. +% Initial setup to provide a default behavior if |hypenmap| +% is not set. % % \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}} +\AtEndOfPackage{% + \ifx\bbl@opt@hyphenmap\@undefined + \bbl@xin@{,}{\bbl@language@opts}% + \chardef\bbl@opt@hyphenmap\ifin@4\else\@ne\fi + \fi} % \end{macrocode} % -% \end{macro} +% \subsection{Macros common to a number of languages} % -% \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{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. % % \begin{macrocode} -\DeclareRobustCommand{\latintext}{% - \fontencoding{\latinencoding}\selectfont - \def\encodingdefault{\latinencoding}} +\bbl@trace{Macros related to glyphs} +\def\set@low@box#1{\setbox\tw@\hbox{,}\setbox\z@\hbox{#1}% + \dimen\z@\ht\z@ \advance\dimen\z@ -\ht\tw@% + \setbox\z@\hbox{\lower\dimen\z@ \box\z@}\ht\z@\ht\tw@ \dp\z@\dp\tw@} % \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{macro}{\save@sf@q} +% The macro |\save@sf@q| is used to save and reset the current +% space factor. % % \begin{macrocode} -\ifx\@undefined\DeclareTextFontCommand - \DeclareRobustCommand{\textlatin}[1]{\leavevmode{\latintext #1}} -\else - \DeclareTextFontCommand{\textlatin}{\latintext} -\fi +\def\save@sf@q#1{\leavevmode + \begingroup + \edef\@SF{\spacefactor\the\spacefactor}#1\@SF + \endgroup} % \end{macrocode} % -% \end{macro} +% \end{macro} % -% \subsection{Basic bidi support} +% \subsection{Making glyphs available} % -% \textbf{Work in progress.} This code is currently placed here for -% practical reasons. +% 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}. % -% 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{}. +% \subsubsection{Quotation marks} % -% 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{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. % -% \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} +\ProvideTextCommand{\quotedblbase}{OT1}{% + \save@sf@q{\set@low@box{\textquotedblright\/}% + \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. % % \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} +\ProvideTextCommandDefault{\quotedblbase}{% + \UseTextSymbol{OT1}{\quotedblbase}} % \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). +% \end{macro} +% +% \begin{macro}{\quotesinglbase} +% We also need the single quote character at the baseline. % % \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 +\ProvideTextCommand{\quotesinglbase}{OT1}{% + \save@sf@q{\set@low@box{\textquoteright\/}% + \box\z@\kern-.04em\bbl@allowhyphens}} % \end{macrocode} % -% A tool for weak L (mainly digits). We also disable warnings with -% \textsf{hyperref}. +% Make sure that when an encoding other than \texttt{OT1} or +% \texttt{T1} is used this glyph can still be typeset. % % \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} +\ProvideTextCommandDefault{\quotesinglbase}{% + \UseTextSymbol{OT1}{\quotesinglbase}} % \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. +% \end{macro} % -% For plain-based formats we don't want to override the definition -% of |\loadlocalcfg| from \file{plain.def}. +% \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} -\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 +\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 + \else + \save@sf@q{\nobreak + \raise.2ex\hbox{$\scriptscriptstyle\ll$}\bbl@allowhyphens}% + \fi} +\ProvideTextCommand{\guillemotright}{OT1}{% + \ifmmode + \gg + \else + \save@sf@q{\nobreak + \raise.2ex\hbox{$\scriptscriptstyle\gg$}\bbl@allowhyphens}% + \fi} % \end{macrocode} % -% Just to be compatible with \LaTeX$\:$2.09 we add a few more lines -% of code: +% Make sure that when an encoding other than \texttt{OT1} or +% \texttt{T1} is used these glyphs can still be typeset. % % \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 -% -%<*kernel> -% \end{macrocode}% -% \end{macro} +\ProvideTextCommandDefault{\guillemetleft}{% + \UseTextSymbol{OT1}{\guillemetleft}} +\ProvideTextCommandDefault{\guillemetright}{% + \UseTextSymbol{OT1}{\guillemetright}} +\ProvideTextCommandDefault{\guillemotleft}{% + \UseTextSymbol{OT1}{\guillemotleft}} +\ProvideTextCommandDefault{\guillemotright}{% + \UseTextSymbol{OT1}{\guillemotright}} +% \end{macrocode} % -% \section{Multiple languages (\texttt{switch.def)}} +% \end{macro} +% \end{macro} % -% 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{macro}{\guilsinglleft} +% \begin{macro}{\guilsinglright} +% The single guillemets are not available in \texttt{OT1} +% encoding. They are faked. % % \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. +\ProvideTextCommand{\guilsinglleft}{OT1}{% + \ifmmode + <% + \else + \save@sf@q{\nobreak + \raise.2ex\hbox{$\scriptscriptstyle<$}\bbl@allowhyphens}% + \fi} +\ProvideTextCommand{\guilsinglright}{OT1}{% + \ifmmode + >% + \else + \save@sf@q{\nobreak + \raise.2ex\hbox{$\scriptscriptstyle>$}\bbl@allowhyphens}% + \fi} +% \end{macrocode} +% +% Make sure that when an encoding other than \texttt{OT1} or +% \texttt{T1} is used these glyphs can still be typeset. % % \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} +\ProvideTextCommandDefault{\guilsinglleft}{% + \UseTextSymbol{OT1}{\guilsinglleft}} +\ProvideTextCommandDefault{\guilsinglright}{% + \UseTextSymbol{OT1}{\guilsinglright}} % \end{macrocode} % % \end{macro} +% \end{macro} % -% |\bbl@iflanguage| executes code only if the language |l@| -% exists. Otherwise raises and error. +% \subsubsection{Letters} % -% 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{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. % % \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} +\DeclareTextCommand{\ij}{OT1}{% + i\kern-0.02em\bbl@allowhyphens j} +\DeclareTextCommand{\IJ}{OT1}{% + I\kern-0.02em\bbl@allowhyphens J} +\DeclareTextCommand{\ij}{T1}{\char188} +\DeclareTextCommand{\IJ}{T1}{\char156} % \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. +% Make sure that when an encoding other than \texttt{OT1} or +% \texttt{T1} is used these glyphs can still be typeset. % % \begin{macrocode} -\def\iflanguage#1{% - \bbl@iflanguage{#1}{% - \ifnum\csname l@#1\endcsname=\language - \expandafter\@firstoftwo - \else - \expandafter\@secondoftwo - \fi}} +\ProvideTextCommandDefault{\ij}{% + \UseTextSymbol{OT1}{\ij}} +\ProvideTextCommandDefault{\IJ}{% + \UseTextSymbol{OT1}{\IJ}} % \end{macrocode} % % \end{macro} +% \end{macro} % -% \subsection{Selecting the language} +% \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}{\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. +% 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} -\let\bbl@select@type\z@ -\edef\selectlanguage{% - \noexpand\protect - \expandafter\noexpand\csname selectlanguage \endcsname} +\def\crrtic@{\hrule height0.1ex width0.3em} +\def\crttic@{\hrule height0.1ex width0.33em} +\def\ddj@{% + \setbox0\hbox{d}\dimen@=\ht0 + \advance\dimen@1ex + \dimen@.45\dimen@ + \dimen@ii\expandafter\rem@pt\the\fontdimen\@ne\font\dimen@ + \advance\dimen@ii.5ex + \leavevmode\rlap{\raise\dimen@\hbox{\kern\dimen@ii\vbox{\crrtic@}}}} +\def\DDJ@{% + \setbox0\hbox{D}\dimen@=.55\ht0 + \dimen@ii\expandafter\rem@pt\the\fontdimen\@ne\font\dimen@ + \advance\dimen@ii.15ex % correction for the dash position + \advance\dimen@ii-.15\fontdimen7\font % correction for cmtt font + \dimen\thr@@\expandafter\rem@pt\the\fontdimen7\font\dimen@ + \leavevmode\rlap{\raise\dimen@\hbox{\kern\dimen@ii\vbox{\crttic@}}}} +% +\DeclareTextCommand{\dj}{OT1}{\ddj@ d} +\DeclareTextCommand{\DJ}{OT1}{\DDJ@ D} % \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|. +% Make sure that when an encoding other than \texttt{OT1} or +% \texttt{T1} is used these glyphs can still be typeset. % % \begin{macrocode} -\ifx\@undefined\protect\let\protect\relax\fi +\ProvideTextCommandDefault{\dj}{% + \UseTextSymbol{OT1}{\dj}} +\ProvideTextCommandDefault{\DJ}{% + \UseTextSymbol{OT1}{\DJ}} % \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. +% \end{macro} +% \end{macro} +% +% \begin{macro}{\SS} +% For the \texttt{T1} encoding |\SS| is defined and selects a +% specific glyph from the font, but for other encodings it is not +% available. Therefore we make it available here. % % \begin{macrocode} -\ifx\documentclass\@undefined - \def\xstring{\string\string\string} -\else - \let\xstring\string -\fi +\DeclareTextCommand{\SS}{OT1}{SS} +\ProvideTextCommandDefault{\SS}{\UseTextSymbol{OT1}{\SS}} % \end{macrocode} % -% \end{macro} +% \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. +% \subsubsection{Shorthands for quotation marks} +% +% Shorthands are provided for a number of different quotation +% marks, which make them usable both outside and inside mathmode. +% They are defined with |\ProvideTextCommandDefault|, but this is +% very likely not required because their definitions are based on +% encoding-dependent macros. +% +% \begin{macro}{\glq} +% \begin{macro}{\grq} +% +% The `german' single quotes. % % \begin{macrocode} -\def\bbl@language@stack{} +\ProvideTextCommandDefault{\glq}{% + \textormath{\quotesinglbase}{\mbox{\quotesinglbase}}} % \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: +% The definition of |\grq| depends on the fontencoding. With +% \texttt{T1} encoding no extra kerning is needed. % % \begin{macrocode} -\def\bbl@push@language{% - \xdef\bbl@language@stack{\languagename+\bbl@language@stack}} +\ProvideTextCommand{\grq}{T1}{% + \textormath{\kern\z@\textquoteleft}{\mbox{\textquoteleft}}} +\ProvideTextCommand{\grq}{TU}{% + \textormath{\textquoteleft}{\mbox{\textquoteleft}}} +\ProvideTextCommand{\grq}{OT1}{% + \save@sf@q{\kern-.0125em + \textormath{\textquoteleft}{\mbox{\textquoteleft}}% + \kern.07em\relax}} +\ProvideTextCommandDefault{\grq}{\UseTextSymbol{OT1}\grq} % \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. +% \end{macro} +% \end{macro} +% +% \begin{macro}{\glqq} +% \begin{macro}{\grqq} +% +% The `german' double quotes. % % \begin{macrocode} -\def\bbl@pop@lang#1+#2-#3{% - \edef\languagename{#1}\xdef#3{#2}} +\ProvideTextCommandDefault{\glqq}{% + \textormath{\quotedblbase}{\mbox{\quotedblbase}}} % \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. +% The definition of |\grqq| depends on the fontencoding. With +% \texttt{T1} encoding no extra kerning is needed. % % \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} +\ProvideTextCommand{\grqq}{T1}{% + \textormath{\textquotedblleft}{\mbox{\textquotedblleft}}} +\ProvideTextCommand{\grqq}{TU}{% + \textormath{\textquotedblleft}{\mbox{\textquotedblleft}}} +\ProvideTextCommand{\grqq}{OT1}{% + \save@sf@q{\kern-.07em + \textormath{\textquotedblleft}{\mbox{\textquotedblleft}}% + \kern.07em\relax}} +\ProvideTextCommandDefault{\grqq}{\UseTextSymbol{OT1}\grqq} % \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{macro}{\flq} +% \begin{macro}{\frq} +% +% The `french' single guillemets. % % \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@}} +\ProvideTextCommandDefault{\flq}{% + \textormath{\guilsinglleft}{\mbox{\guilsinglleft}}} +\ProvideTextCommandDefault{\frq}{% + \textormath{\guilsinglright}{\mbox{\guilsinglright}}} % \end{macrocode} % -% The unprotected part of |\selectlanguage|. +% \end{macro} +% \end{macro} +% +% \begin{macro}{\flqq} +% \begin{macro}{\frqq} +% +% The `french' double guillemets. % % \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}} +\ProvideTextCommandDefault{\flqq}{% + \textormath{\guillemetleft}{\mbox{\guillemetleft}}} +\ProvideTextCommandDefault{\frqq}{% + \textormath{\guillemetright}{\mbox{\guillemetright}}} % \end{macrocode} % % \end{macro} +% \end{macro} % -% \begin{macro}{\bbl@set@language} +% \subsubsection{Umlauts and tremas} +% +% The command |\"| needs to have a different effect for different +% languages. For German for instance, the `umlaut' should be +% positioned lower than the default position for placing it over +% the letters a, o, u, A, O and U. When placed over an e, i, E or I +% it can retain its normal position. For Dutch the same glyph is +% always placed in the lower position. % -% 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. +% \begin{macro}{\umlauthigh} % -% We also write a command to change the current language in the -% auxiliary files. +% \begin{macro}{\umlautlow} +% To be able to provide both positions of |\"| we provide two +% commands to switch the positioning, the default will be +% |\umlauthigh| (the normal positioning). % % \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}{}}% +\def\umlauthigh{% + \def\bbl@umlauta##1{\leavevmode\bgroup% + \expandafter\accent\csname\f@encoding dqpos\endcsname + ##1\bbl@allowhyphens\egroup}% + \let\bbl@umlaute\bbl@umlauta} +\def\umlautlow{% + \def\bbl@umlauta{\protect\lower@umlaut}} +\def\umlautelow{% + \def\bbl@umlaute{\protect\lower@umlaut}} +\umlauthigh +% \end{macrocode} +% +% \end{macro} +% \end{macro} +% +% \begin{macro}{\lower@umlaut} +% The command |\lower@umlaut| is used to position the |\"| closer +% to the letter. +% +% We want the umlaut character lowered, nearer to the letter. To do +% this we need an extra \meta{dimen} register. +% +% \begin{macrocode} +\expandafter\ifx\csname U@D\endcsname\relax + \csname newdimen\endcsname\U@D +\fi +% \end{macrocode} +% +% The following code fools \TeX's \texttt{make\_accent} procedure +% about the current x-height of the font to force another placement +% of the umlaut character. +% First we have to save the current x-height of the font, because +% we'll change this font dimension and this is always done +% globally. +% +% Then we compute the new x-height in such a way that the umlaut +% character is lowered to the base character. The value of +% \texttt{.45ex} depends on the \MF\ parameters with which the +% fonts were built. (Just try out, which value will look best.) +% If the new x-height is too low, it is not changed. +% Finally we call the |\accent| primitive, reset the old x-height +% and insert the base character in the argument. +% +% \begin{macrocode} +\def\lower@umlaut#1{% + \leavevmode\bgroup + \U@D 1ex% + {\setbox\z@\hbox{% + \expandafter\char\csname\f@encoding dqpos\endcsname}% + \dimen@ -.45ex\advance\dimen@\ht\z@ + \ifdim 1ex<\dimen@ \fontdimen5\font\dimen@ \fi}% + \expandafter\accent\csname\f@encoding dqpos\endcsname + \fontdimen5\font\U@D #1% + \egroup} +% \end{macrocode} +% +% \end{macro} +% +% For all vowels we declare |\"| to be a composite command which +% uses |\bbl@umlauta| or |\bbl@umlaute| to position the umlaut +% character. We need to be sure that these definitions override the +% ones that are provided when the package \pkg{fontenc} with +% option \Lopt{OT1} is used. Therefore these declarations are +% postponed until the beginning of the document. Note these +% definitions only apply to some languages, but +% babel sets them for \textit{all} languages -- you may want to +% redefine |\bbl@umlauta| and/or |\bbl@umlaute| for a language +% in the corresponding |ldf| (using the babel switching mechanism, +% of course). +% +% \begin{macrocode} +\AtBeginDocument{% + \DeclareTextCompositeCommand{\"}{OT1}{a}{\bbl@umlauta{a}}% + \DeclareTextCompositeCommand{\"}{OT1}{e}{\bbl@umlaute{e}}% + \DeclareTextCompositeCommand{\"}{OT1}{i}{\bbl@umlaute{\i}}% + \DeclareTextCompositeCommand{\"}{OT1}{\i}{\bbl@umlaute{\i}}% + \DeclareTextCompositeCommand{\"}{OT1}{o}{\bbl@umlauta{o}}% + \DeclareTextCompositeCommand{\"}{OT1}{u}{\bbl@umlauta{u}}% + \DeclareTextCompositeCommand{\"}{OT1}{A}{\bbl@umlauta{A}}% + \DeclareTextCompositeCommand{\"}{OT1}{E}{\bbl@umlaute{E}}% + \DeclareTextCompositeCommand{\"}{OT1}{I}{\bbl@umlaute{I}}% + \DeclareTextCompositeCommand{\"}{OT1}{O}{\bbl@umlauta{O}}% + \DeclareTextCompositeCommand{\"}{OT1}{U}{\bbl@umlauta{U}}% +} +% \end{macrocode} +% +% Finally, make sure the default hyphenrules are defined (even if +% empty). +% +% \begin{macrocode} +\ifx\l@english\@undefined + \chardef\l@english\z@ +\fi +% \end{macrocode} +% +% \subsection{Layout} +% +% \textbf{Work in progress}. +% +% Layout is mainly intended to set bidi documents, but there is at +% least a tool useful in general. +% +% \begin{macrocode} +\bbl@trace{Bidi layout} +\providecommand\IfBabelLayout[3]{#3}% +\newcommand\BabelPatchSection[1]{% + \@ifundefined{#1}{}{% + \bbl@exp{\let\\<#1>}% + \@namedef{#1}{% + \@ifstar{\bbl@presec@s{#1}}% + {\@dblarg{\bbl@presec@x{#1}}}}}} +\def\bbl@presec@x#1[#2]#3{% + \bbl@exp{% + \\\select@language@x{\bbl@main@language}% + \\\bbl@cs{sspre@#1}% + \\\bbl@cs{ss@#1}% + [\\\foreignlanguage{\languagename}{\unexpanded{#2}}]% + {\\\foreignlanguage{\languagename}{\unexpanded{#3}}}% + \\\select@language@x{\languagename}}} +\def\bbl@presec@s#1#2{% + \bbl@exp{% + \\\select@language@x{\bbl@main@language}% + \\\bbl@cs{sspre@#1}% + \\\bbl@cs{ss@#1}*% + {\\\foreignlanguage{\languagename}{\unexpanded{#2}}}% + \\\select@language@x{\languagename}}} +\IfBabelLayout{sectioning}% + {\BabelPatchSection{part}% + \BabelPatchSection{chapter}% + \BabelPatchSection{section}% + \BabelPatchSection{subsection}% + \BabelPatchSection{subsubsection}% + \BabelPatchSection{paragraph}% + \BabelPatchSection{subparagraph}% + \def\babel@toc#1{% + \select@language@x{\bbl@main@language}}}{} +\IfBabelLayout{captions}% + {\BabelPatchSection{caption}}{} +% \end{macrocode} +% +% \subsection{Load engine specific macros} +% +% \begin{macrocode} +\bbl@trace{Input engine specific macros} +\ifcase\bbl@engine + \input txtbabel.def +\or + \input luababel.def +\or + \input xebabel.def +\fi +% \end{macrocode} +% +% \subsection{Creating and modifying languages} +% +% |\babelprovide| is a general purpose tool for creating and modifying +% languages. It creates the language infrastructure, and loads, if +% requested, an |ini| file. It may be used in conjunction to previouly +% loaded |ldf| files. +% +% \begin{macrocode} +\bbl@trace{Creating languages and reading ini files} +\newcommand\babelprovide[2][]{% + \let\bbl@savelangname\languagename + \edef\bbl@savelocaleid{\the\localeid}% + % Set name and locale id + \edef\languagename{#2}% + % \global\@namedef{bbl@lcname@#2}{#2}% + \bbl@id@assign + \let\bbl@KVP@captions\@nil + \let\bbl@KVP@import\@nil + \let\bbl@KVP@main\@nil + \let\bbl@KVP@script\@nil + \let\bbl@KVP@language\@nil + \let\bbl@KVP@hyphenrules\@nil % only for provide@new + \let\bbl@KVP@mapfont\@nil + \let\bbl@KVP@maparabic\@nil + \let\bbl@KVP@mapdigits\@nil + \let\bbl@KVP@intraspace\@nil + \let\bbl@KVP@intrapenalty\@nil + \let\bbl@KVP@onchar\@nil + \let\bbl@KVP@alph\@nil + \let\bbl@KVP@Alph\@nil + \let\bbl@KVP@info\@nil % Ignored with import? Or error/warning? + \bbl@forkv{#1}{% TODO - error handling + \in@{/}{##1}% + \ifin@ + \bbl@renewinikey##1\@@{##2}% + \else + \bbl@csarg\def{KVP@##1}{##2}% + \fi}% + % == import, captions == + \ifx\bbl@KVP@import\@nil\else + \bbl@exp{\\\bbl@ifblank{\bbl@KVP@import}}% + {\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 + \let\bbl@KVP@captions\bbl@KVP@import + \fi + % Load ini + \bbl@ifunset{date#2}% + {\bbl@provide@new{#2}}% + {\bbl@ifblank{#1}% + {\bbl@error + {If you want to modify `#2' you must tell how in\\% + the optional argument. See the manual for the\\% + available options.}% + {Use this macro as documented}}% + {\bbl@provide@renew{#2}}}% + % Post tasks + \bbl@exp{\\\babelensure[exclude=\\\today]{#2}}% + \bbl@ifunset{bbl@ensure@\languagename}% + {\bbl@exp{% + \\\DeclareRobustCommand\[1]{% + \\\foreignlanguage{\languagename}% + {####1}}}}% + {}% + \bbl@exp{% + \\\bbl@toglobal\% + \\\bbl@toglobal\}% + % 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}% 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{chrng}{characters.ranges}{}% + \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}{}% + \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 + \bbl@csarg\edef{sname@#2}{\bbl@KVP@script}% + \fi + \ifx\bbl@KVP@language\@nil\else + \bbl@csarg\edef{lname@#2}{\bbl@KVP@language}% + \fi + % == onchar == + \ifx\bbl@KVP@onchar\@nil\else + \bbl@luahyphenate + \directlua{ + if Babel.locale_mapped == nil then + Babel.locale_mapped = true + Babel.linebreaking.add_before(Babel.locale_map) + Babel.loc_to_scr = {} + Babel.chr_to_loc = Babel.chr_to_loc or {} + end}% + \bbl@xin@{ ids }{ \bbl@KVP@onchar\space}% + \ifin@ + \ifx\bbl@starthyphens\@undefined % Needed if no explicit selection + \AddBabelHook{babel-onchar}{beforestart}{{\bbl@starthyphens}}% \fi - \bbl@usehooks{write}{}% + \bbl@exp{\\\bbl@add\\\bbl@starthyphens + {\\\bbl@patterns@lua{\languagename}}}% + % TODO - error/warning if no script + \directlua{ + if Babel.script_blocks['\bbl@cl{sbcp}'] then + Babel.loc_to_scr[\the\localeid] = + Babel.script_blocks['\bbl@cl{sbcp}'] + Babel.locale_props[\the\localeid].lc = \the\localeid\space + Babel.locale_props[\the\localeid].lg = \the\@nameuse{l@\languagename}\space + end + }% + \fi + \bbl@xin@{ fonts }{ \bbl@KVP@onchar\space}% + \ifin@ + \bbl@ifunset{bbl@lsys@\languagename}{\bbl@provide@lsys{\languagename}}{}% + \bbl@ifunset{bbl@wdir@\languagename}{\bbl@provide@dirs{\languagename}}{}% + \directlua{ + if Babel.script_blocks['\bbl@cl{sbcp}'] then + Babel.loc_to_scr[\the\localeid] = + Babel.script_blocks['\bbl@cl{sbcp}'] + end}% + \ifx\bbl@mapselect\@undefined + \AtBeginDocument{% + \expandafter\bbl@add\csname selectfont \endcsname{{\bbl@mapselect}}% + {\selectfont}}% + \def\bbl@mapselect{% + \let\bbl@mapselect\relax + \edef\bbl@prefontid{\fontid\font}}% + \def\bbl@mapdir##1{% + {\def\languagename{##1}% + \let\bbl@ifrestoring\@firstoftwo % To avoid font warning + \bbl@switchfont + \directlua{ + Babel.locale_props[\the\csname bbl@id@@##1\endcsname]% + ['/\bbl@prefontid'] = \fontid\font\space}}}% + \fi + \bbl@exp{\\\bbl@add\\\bbl@mapselect{\\\bbl@mapdir{\languagename}}}% + \fi + % TODO - catch non-valid values + \fi + % == mapfont == + % For bidi texts, to switch the font based on direction + \ifx\bbl@KVP@mapfont\@nil\else + \bbl@ifsamestring{\bbl@KVP@mapfont}{direction}{}% + {\bbl@error{Option `\bbl@KVP@mapfont' unknown for\\% + mapfont. Use `direction'.% + {See the manual for details.}}}% + \bbl@ifunset{bbl@lsys@\languagename}{\bbl@provide@lsys{\languagename}}{}% + \bbl@ifunset{bbl@wdir@\languagename}{\bbl@provide@dirs{\languagename}}{}% + \ifx\bbl@mapselect\@undefined + \AtBeginDocument{% + \expandafter\bbl@add\csname selectfont \endcsname{{\bbl@mapselect}}% + {\selectfont}}% + \def\bbl@mapselect{% + \let\bbl@mapselect\relax + \edef\bbl@prefontid{\fontid\font}}% + \def\bbl@mapdir##1{% + {\def\languagename{##1}% + \let\bbl@ifrestoring\@firstoftwo % avoid font warning + \bbl@switchfont + \directlua{Babel.fontmap + [\the\csname bbl@wdir@##1\endcsname]% + [\bbl@prefontid]=\fontid\font}}}% + \fi + \bbl@exp{\\\bbl@add\\\bbl@mapselect{\\\bbl@mapdir{\languagename}}}% + \fi + % == intraspace, intrapenalty == + % For CJK, East Asian, Southeast Asian, if interspace in ini + \ifx\bbl@KVP@intraspace\@nil\else % We can override the ini or set + \bbl@csarg\edef{intsp@#2}{\bbl@KVP@intraspace}% + \fi + \bbl@provide@intraspace + % == hyphenate.other == + \bbl@ifunset{bbl@hyoth@\languagename}{}% + {\bbl@csarg\bbl@replace{hyoth@\languagename}{ }{,}% + \bbl@startcommands*{\languagename}{}% + \bbl@csarg\bbl@foreach{hyoth@\languagename}{% + \ifcase\bbl@engine + \ifnum##1<257 + \SetHyphenMap{\BabelLower{##1}{##1}}% + \fi + \else + \SetHyphenMap{\BabelLower{##1}{##1}}% + \fi}% + \bbl@endcommands}% + % == maparabic == + % Native digits, if provided in ini (TeX level, xe and lua) + \ifcase\bbl@engine\else + \bbl@ifunset{bbl@dgnat@\languagename}{}% + {\expandafter\ifx\csname bbl@dgnat@\languagename\endcsname\@empty\else + \expandafter\expandafter\expandafter + \bbl@setdigits\csname bbl@dgnat@\languagename\endcsname + \ifx\bbl@KVP@maparabic\@nil\else + \ifx\bbl@latinarabic\@undefined + \expandafter\let\expandafter\@arabic + \csname bbl@counter@\languagename\endcsname + \else % ie, if layout=counters, which redefines \@arabic + \expandafter\let\expandafter\bbl@latinarabic + \csname bbl@counter@\languagename\endcsname + \fi + \fi + \fi}% + \fi + % == mapdigits == + % Native digits (lua level). + \ifodd\bbl@engine + \ifx\bbl@KVP@mapdigits\@nil\else + \bbl@ifunset{bbl@dgnat@\languagename}{}% + {\RequirePackage{luatexbase}% + \bbl@activate@preotf + \directlua{ + Babel = Babel or {} %%% -> presets in luababel + Babel.digits_mapped = true + Babel.digits = Babel.digits or {} + Babel.digits[\the\localeid] = + table.pack(string.utfvalue('\bbl@cl{dgnat}')) + if not Babel.numbers then + function Babel.numbers(head) + local LOCALE = luatexbase.registernumber'bbl@attr@locale' + local GLYPH = node.id'glyph' + local inmath = false + for item in node.traverse(head) do + if not inmath and item.id == GLYPH then + local temp = node.get_attribute(item, LOCALE) + if Babel.digits[temp] then + local chr = item.char + if chr > 47 and chr < 58 then + item.char = Babel.digits[temp][chr-47] + end + end + elseif item.id == node.id'math' then + inmath = (item.subtype == 0) + end + end + return head + end + end + }}% \fi + \fi + % == alph, Alph == + % What if extras contains a \babel@save\@alph? It won't be + % restored correctly when exiting the language, so we ignore + % this change with the \bbl@alph@saved trick. + \ifx\bbl@KVP@alph\@nil\else + \toks@\expandafter\expandafter\expandafter{% + \csname extras\languagename\endcsname}% + \bbl@exp{% + \def\{% + \let\\\bbl@alph@saved\\\@alph + \the\toks@ + \let\\\@alph\\\bbl@alph@saved + \\\babel@save\\\@alph + \let\\\@alph\}}% + \fi + \ifx\bbl@KVP@Alph\@nil\else + \toks@\expandafter\expandafter\expandafter{% + \csname extras\languagename\endcsname}% + \bbl@exp{% + \def\{% + \let\\\bbl@Alph@saved\\\@Alph + \the\toks@ + \let\\\@Alph\\\bbl@Alph@saved + \\\babel@save\\\@Alph + \let\\\@Alph\}}% + \fi + % == require.babel in ini == + % To load or reaload the babel-*.tex, if require.babel in ini + \bbl@ifunset{bbl@rqtex@\languagename}{}% + {\expandafter\ifx\csname bbl@rqtex@\languagename\endcsname\@empty\else + \let\BabelBeforeIni\@gobbletwo + \chardef\atcatcode=\catcode`\@ + \catcode`\@=11\relax + \InputIfFileExists{babel-\bbl@cs{rqtex@\languagename}.tex}{}{}% + \catcode`\@=\atcatcode + \let\atcatcode\relax + \fi}% + % == main == + \ifx\bbl@KVP@main\@nil % Restore only if not 'main' + \let\languagename\bbl@savelangname + \chardef\localeid\bbl@savelocaleid\relax \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}. +% A tool to define the macros for native digits from the list provided +% in the |ini| file. Somewhat convoluted because there are 10 digits, +% but only 9 arguments in \TeX. % % \begin{macrocode} -\let\select@language@x\select@language +\def\bbl@setdigits#1#2#3#4#5{% + \bbl@exp{% + \def\<\languagename digits>####1{% ie, \langdigits + \####1\\\@nil}% + \def\<\languagename counter>####1{% ie, \langcounter + \\\expandafter\% + \\\csname c@####1\endcsname}% + \def\####1{% ie, \bbl@counter@lang + \\\expandafter\% + \\\number####1\\\@nil}}% + \def\bbl@tempa##1##2##3##4##5{% + \bbl@exp{% Wow, quite a lot of hashes! :-( + \def\########1{% + \\\ifx########1\\\@nil % ie, \bbl@digits@lang + \\\else + \\\ifx0########1#1% + \\\else\\\ifx1########1#2% + \\\else\\\ifx2########1#3% + \\\else\\\ifx3########1#4% + \\\else\\\ifx4########1#5% + \\\else\\\ifx5########1##1% + \\\else\\\ifx6########1##2% + \\\else\\\ifx7########1##3% + \\\else\\\ifx8########1##4% + \\\else\\\ifx9########1##5% + \\\else########1% + \\\fi\\\fi\\\fi\\\fi\\\fi\\\fi\\\fi\\\fi\\\fi\\\fi + \\\expandafter\% + \\\fi}}}% + \bbl@tempa} % \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. +% Depending on whether or not the language exists, we define two macros. % % \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 +\def\bbl@provide@new#1{% + \@namedef{date#1}{}% marks lang exists - required by \StartBabelCommands + \@namedef{extras#1}{}% + \@namedef{noextras#1}{}% + \bbl@startcommands*{#1}{captions}% + \ifx\bbl@KVP@captions\@nil % and also if import, implicit + \def\bbl@tempb##1{% elt for \bbl@captionslist + \ifx##1\@empty\else + \bbl@exp{% + \\\SetString\\##1{% + \\\bbl@nocaption{\bbl@stripslash##1}{#1\bbl@stripslash##1}}}% + \expandafter\bbl@tempb + \fi}% + \expandafter\bbl@tempb\bbl@captionslist\@empty \else - \csname captions#1\endcsname\relax - \csname date#1\endcsname\relax - \fi - \else - \ifbbl@usedategroup % if \foreign... within \date - \bbl@usedategroupfalse - \ifhmode - \hskip\z@skip % trick to ignore spaces - \csname date#1\endcsname\relax - \loop\ifdim\lastskip>\z@\unskip\repeat\unskip + \ifx\bbl@initoload\relax + \bbl@read@ini{\bbl@KVP@captions}{data}% Here letters cat = 11 \else - \csname date#1\endcsname\relax + \bbl@read@ini{\bbl@initoload}{data}% Here all letters cat = 11 \fi + \bbl@after@ini + \bbl@savestrings \fi - \fi - % switch extras - \bbl@usehooks{beforeextras}{}% - \csname extras#1\endcsname\relax - \bbl@usehooks{afterextras}{}% - % > babel-ensure - % > babel-sh- - % > 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 + \StartBabelCommands*{#1}{date}% + \ifx\bbl@KVP@import\@nil + \bbl@exp{% + \\\SetString\\\today{\\\bbl@nocaption{today}{#1today}}}% + \else + \bbl@savetoday + \bbl@savedate \fi - \chardef\bbl@opt@hyphenmap\z@ - \else - \ifnum\bbl@hymapsel>\bbl@opt@hyphenmap\else - \csname\languagename @bbl@hyphenmap\endcsname + \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{% + \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}% + \ifx\bbl@KVP@main\@nil\else + \expandafter\main@language\expandafter{#1}% + \fi} +\def\bbl@provide@renew#1{% + \ifx\bbl@KVP@captions\@nil\else + \StartBabelCommands*{#1}{captions}% + \bbl@read@ini{\bbl@KVP@captions}{data}% Here all letters cat = 11 + \bbl@after@ini + \bbl@savestrings + \EndBabelCommands + \fi + \ifx\bbl@KVP@import\@nil\else + \StartBabelCommands*{#1}{date}% + \bbl@savetoday + \bbl@savedate + \EndBabelCommands + \fi + % == hyphenrules == + \bbl@provide@hyphens{#1}} +% \end{macrocode} +% +% The |hyphenrules| option is handled with an auxiliary macro. +% +% \begin{macrocode} +\def\bbl@provide@hyphens#1{% + \let\bbl@tempa\relax + \ifx\bbl@KVP@hyphenrules\@nil\else + \bbl@replace\bbl@KVP@hyphenrules{ }{,}% + \bbl@foreach\bbl@KVP@hyphenrules{% + \ifx\bbl@tempa\relax % if not yet found + \bbl@ifsamestring{##1}{+}% + {{\bbl@exp{\\\addlanguage\}}}% + {}% + \bbl@ifunset{l@##1}% + {}% + {\bbl@exp{\let\bbl@tempa\}}% + \fi}% + \fi + \ifx\bbl@tempa\relax % if no opt or no language in opt found + \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\}}% + \fi + \else % if importing + \bbl@exp{% and hyphenrules is not empty + \\\bbl@ifblank{\bbl@cs{hyphr@#1}}% + {}% + {\let\\\bbl@tempa\}}% \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 + \bbl@ifunset{bbl@tempa}% ie, relax or undefined + {\bbl@ifunset{l@#1}% no hyphenrules found - fallback + {\bbl@exp{\\\adddialect\\language}}% + {}}% so, l@ is ok - nothing to do + {\bbl@exp{\\\adddialect\\bbl@tempa}}}% found in opt list or ini + +% \end{macrocode} +% +% The reader of |ini| files. There are 3 possible cases: a section name +% (in the form |[...]|), a comment (starting with |;|) and a +% key/value pair. +% +% \begin{macrocode} +\ifx\bbl@readstream\@undefined + \csname newread\endcsname\bbl@readstream +\fi +\def\bbl@inipreread#1=#2\@@{% + \bbl@trim@def\bbl@tempa{#1}% Redundant below !! + \bbl@trim\toks@{#2}% + % Move trims here ?? + \bbl@ifunset{bbl@KVP@\bbl@section/\bbl@tempa}% + {\bbl@exp{% + \\\g@addto@macro\\\bbl@inidata{% + \\\bbl@elt{\bbl@section}{\bbl@tempa}{\the\toks@}}}% + \expandafter\bbl@inireader\bbl@tempa=#2\@@}% + {}}% +\def\bbl@read@ini#1#2{% + \bbl@csarg\edef{lini@\languagename}{#1}% + \openin\bbl@readstream=babel-#1.ini + \ifeof\bbl@readstream + \bbl@error + {There is no ini file for the requested language\\% + (#1). Perhaps you misspelled it or your installation\\% + is not complete.}% + {Fix the name or reinstall babel.}% + \else + \bbl@exp{\def\\\bbl@inidata{\\\bbl@elt{identificacion}{tag.ini}{#1}}}% + \let\bbl@section\@empty + \let\bbl@savestrings\@empty + \let\bbl@savetoday\@empty + \let\bbl@savedate\@empty + \let\bbl@inireader\bbl@iniskip + \bbl@info{Importing #2 for \languagename\\% + from babel-#1.ini. Reported}% + \loop + \if T\ifeof\bbl@readstream F\fi T\relax % Trick, because inside \loop + \endlinechar\m@ne + \read\bbl@readstream to \bbl@line + \endlinechar`\^^M + \ifx\bbl@line\@empty\else + \expandafter\bbl@iniline\bbl@line\bbl@iniline + \fi + \repeat + \bbl@foreach\bbl@renewlist{% + \bbl@ifunset{bbl@renew@##1}{}{\bbl@inisec[##1]\@@}}% + \global\let\bbl@renewlist\@empty + % Ends last section. See \bbl@inisec + \def\bbl@elt##1##2{\bbl@inireader##1=##2\@@}% + \bbl@cs{renew@\bbl@section}% + \global\bbl@csarg\let{renew@\bbl@section}\relax + \bbl@cs{secpost@\bbl@section}% + \bbl@csarg{\global\expandafter\let}{inidata@\languagename}\bbl@inidata + \bbl@exp{\\\bbl@add@list\\\bbl@ini@loaded{\languagename}}% + \bbl@toglobal\bbl@ini@loaded \fi} +\def\bbl@iniline#1\bbl@iniline{% + \@ifnextchar[\bbl@inisec{\@ifnextchar;\bbl@iniskip\bbl@inipreread}#1\@@}% ] % \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|. +% The special cases for comment lines and sections are handled by the +% two following commands. In sections, we provide the posibility to +% take extra actions at the end or at the start (TODO - but note the last +% section is not ended). By default, key=val pairs are ignored. The +% |secpost| ``hook'' is used only by `identification', while |secpre| +% only by |date.gregorian.licr|. % % \begin{macrocode} -\expandafter\def\csname otherlanguage*\endcsname#1{% - \ifnum\bbl@hymapsel=\@cclv\chardef\bbl@hymapsel4\relax\fi - \foreign@language{#1}} +\def\bbl@iniskip#1\@@{}% if starts with ; +\def\bbl@inisec[#1]#2\@@{% if starts with opening bracket + \def\bbl@elt##1##2{% + \expandafter\toks@\expandafter{% + \expandafter{\bbl@section}{##1}{##2}}% + \bbl@exp{% + \\\g@addto@macro\\\bbl@inidata{\\\bbl@elt\the\toks@}}% + \bbl@inireader##1=##2\@@}% + \bbl@cs{renew@\bbl@section}% + \global\bbl@csarg\let{renew@\bbl@section}\relax + \bbl@cs{secpost@\bbl@section}% + % The previous code belongs to the previous section. + % Now start the current one. + \def\bbl@section{#1}% + \def\bbl@elt##1##2{% + \@namedef{bbl@KVP@#1/##1}{}}% + \bbl@cs{renew@#1}% + \bbl@cs{secpre@#1}% pre-section `hook' + \bbl@ifunset{bbl@inikv@#1}% + {\let\bbl@inireader\bbl@iniskip}% + {\bbl@exp{\let\\\bbl@inireader\}}} +\let\bbl@renewlist\@empty +\def\bbl@renewinikey#1/#2\@@#3{% + \bbl@ifunset{bbl@renew@#1}% + {\bbl@add@list\bbl@renewlist{#1}}% + {}% + \bbl@csarg\bbl@add{renew@#1}{\bbl@elt{#2}{#3}}} % \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''. +% Reads a key=val line and stores the trimmed val in +% |\bbl@@kv@
.|. % % \begin{macrocode} -\expandafter\let\csname endotherlanguage*\endcsname\relax +\def\bbl@inikv#1=#2\@@{% key=value + \bbl@trim@def\bbl@tempa{#1}% + \bbl@trim\toks@{#2}% + \bbl@csarg\edef{@kv@\bbl@section.\bbl@tempa}{\the\toks@}} % \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. +% The previous assignments are local, so we need to export them. If +% the value is empty, we can provide a default value. % % \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} +\def\bbl@exportkey#1#2#3{% + \bbl@ifunset{bbl@@kv@#2}% + {\bbl@csarg\gdef{#1@\languagename}{#3}}% + {\expandafter\ifx\csname bbl@@kv@#2\endcsname\@empty + \bbl@csarg\gdef{#1@\languagename}{#3}% + \else + \bbl@exp{\global\let\\}% + \fi}} % \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|. +% Key-value pairs are treated differently depending on the section in +% the |ini| file. The following macros are the readers for +% |identification| and |typography|. Note |\bbl@secpost@identification| +% is called always (via |\bbl@inisec|), while |\bbl@after@ini| must be +% called explicitly after |\bbl@read@ini| if necessary. % % \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}}% - {}% +\def\bbl@iniwarning#1{% + \bbl@ifunset{bbl@@kv@identification.warning#1}{}% + {\bbl@warning{% + From babel-\bbl@cs{lini@\languagename}.ini:\\% + \bbl@cs{@kv@identification.warning#1}\\% + Reported }}} +\let\bbl@inikv@identification\bbl@inikv +\def\bbl@secpost@identification{% + \bbl@iniwarning{}% + \ifcase\bbl@engine + \bbl@iniwarning{.pdflatex}% + \or + \bbl@iniwarning{.lualatex}% + \or + \bbl@iniwarning{.xelatex}% + \fi% + \bbl@exportkey{elname}{identification.name.english}{}% + \bbl@exp{\\\bbl@exportkey{lname}{identification.name.opentype}% + {\csname bbl@elname@\languagename\endcsname}}% + \bbl@exportkey{lbcp}{identification.tag.bcp47}{}% + \bbl@exportkey{lotf}{identification.tag.opentype}{dflt}% + \bbl@exportkey{esname}{identification.script.name}{}% + \bbl@exp{\\\bbl@exportkey{sname}{identification.script.name.opentype}% + {\csname bbl@esname@\languagename\endcsname}}% + \bbl@exportkey{sbcp}{identification.script.tag.bcp47}{}% + \bbl@exportkey{sotf}{identification.script.tag.opentype}{DFLT}} +\let\bbl@inikv@typography\bbl@inikv +\let\bbl@inikv@characters\bbl@inikv +\let\bbl@inikv@numbers\bbl@inikv +\def\bbl@inikv@counters#1=#2\@@{% + \def\bbl@tempc{#1}% + \bbl@trim@def{\bbl@tempb*}{#2}% + \in@{.1$}{#1$}% + \ifin@ + \bbl@replace\bbl@tempc{.1}{}% + \bbl@csarg\protected@xdef{cntr@\bbl@tempc @\languagename}{% + \noexpand\bbl@alphnumeral{\bbl@tempc}}% \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}}} + \in@{.F.}{#1}% + \ifin@\else\in@{.S.}{#1}\fi + \ifin@ + \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 \\ + \bbl@csarg{\global\expandafter\let}{cntr@#1@\languagename}\bbl@tempa + \fi} +\def\bbl@after@ini{% + \bbl@exportkey{lfthm}{typography.lefthyphenmin}{2}% + \bbl@exportkey{rgthm}{typography.righthyphenmin}{3}% + \bbl@exportkey{prehc}{typography.prehyphenchar}{}% + \bbl@exportkey{lnbrk}{typography.linebreaking}{h}% + \bbl@exportkey{hyphr}{typography.hyphenrules}{}% + \bbl@exportkey{hyoth}{typography.hyphenate.other}{}% + \bbl@exportkey{intsp}{typography.intraspace}{}% + \bbl@exportkey{jstfy}{typography.justify}{w}% + \bbl@exportkey{chrng}{characters.ranges}{}% + \bbl@exportkey{dgnat}{numbers.digits.native}{}% + \bbl@exportkey{rqtex}{identification.require.babel}{}% + \bbl@toglobal\bbl@savetoday + \bbl@toglobal\bbl@savedate} % \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. +% Now |captions| and |captions.licr|, depending on the engine. And +% below also for dates. They rely on a few auxiliary macros. It is +% expected the ini file provides the complete set in Unicode and LICR, +% in that order. % % \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}} +\ifcase\bbl@engine + \bbl@csarg\def{inikv@captions.licr}#1=#2\@@{% + \bbl@ini@captions@aux{#1}{#2}} +\else + \def\bbl@inikv@captions#1=#2\@@{% + \bbl@ini@captions@aux{#1}{#2}} +\fi % \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*|. +% The auxiliary macro for captions define |\name|. % % \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 +\def\bbl@ini@captions@aux#1#2{% + \bbl@trim@def\bbl@tempa{#1}% + \bbl@ifblank{#2}% + {\bbl@exp{% + \toks@{\\\bbl@nocaption{\bbl@tempa}{\languagename\bbl@tempa name}}}}% + {\bbl@trim\toks@{#2}}% + \bbl@exp{% + \\\bbl@add\\\bbl@savestrings{% + \\\SetString\<\bbl@tempa name>{\the\toks@}}}} % \end{macrocode} % -% \end{environment} +% But dates are more complex. The full date format is stores in +% |date.gregorian|, so we must read it in non-Unicode engines, too +% (saved months are just discarded when the LICR section is reached). % -% \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. +% TODO. Remove copypaste pattern. % % \begin{macrocode} -\def\providehyphenmins#1#2{% - \expandafter\ifx\csname #1hyphenmins\endcsname\relax - \@namedef{#1hyphenmins}{#2}% - \fi} +\bbl@csarg\def{inikv@date.gregorian}#1=#2\@@{% for defaults + \bbl@inidate#1...\relax{#2}{}} +\bbl@csarg\def{inikv@date.islamic}#1=#2\@@{% + \bbl@inidate#1...\relax{#2}{islamic}} +\bbl@csarg\def{inikv@date.hebrew}#1=#2\@@{% + \bbl@inidate#1...\relax{#2}{hebrew}} +\bbl@csarg\def{inikv@date.persian}#1=#2\@@{% + \bbl@inidate#1...\relax{#2}{persian}} +\bbl@csarg\def{inikv@date.indian}#1=#2\@@{% + \bbl@inidate#1...\relax{#2}{indian}} +\ifcase\bbl@engine + \bbl@csarg\def{inikv@date.gregorian.licr}#1=#2\@@{% override + \bbl@inidate#1...\relax{#2}{}} + \bbl@csarg\def{secpre@date.gregorian.licr}{% discard uni + \ifcase\bbl@engine\let\bbl@savedate\@empty\fi} +\fi +% eg: 1=months, 2=wide, 3=1, 4=dummy +\def\bbl@inidate#1.#2.#3.#4\relax#5#6{% TODO - ignore with 'captions' + \bbl@trim@def\bbl@tempa{#1.#2}% + \bbl@ifsamestring{\bbl@tempa}{months.wide}% to savedate + {\bbl@trim@def\bbl@tempa{#3}% + \bbl@trim\toks@{#5}% + \bbl@exp{% + \\\bbl@add\\\bbl@savedate{% + \\\SetString\{\the\toks@}}}}% + {\bbl@ifsamestring{\bbl@tempa}{date.long}% defined now + {\bbl@trim@def\bbl@toreplace{#5}% + \bbl@TG@@date + \global\bbl@csarg\let{date@\languagename}\bbl@toreplace + \bbl@exp{% + \gdef\<\languagename date>{\\\protect\<\languagename date >}% + \gdef\<\languagename date >####1####2####3{% + \\\bbl@usedategrouptrue + \{% + \{####1}{####2}{####3}}}% + \\\bbl@add\\\bbl@savetoday{% + \\\SetString\\\today{% + \<\languagename date>{\\\the\year}{\\\the\month}{\\\the\day}}}}}}% + {}} % \end{macrocode} % -% \end{macro} -% -% \begin{macro}{\set@hyphenmins} -% This macro sets the values of |\lefthyphenmin| and -% |\righthyphenmin|. It expects two values as its argument. +% Dates will require some macros for the basic formatting. They may be +% redefined by language, so ``semi-public'' names (camel case) are +% used. Oddly enough, the CLDR places particles like “de” +% inconsistently in either in the date or in the month name. % % \begin{macrocode} -\def\set@hyphenmins#1#2{% - \lefthyphenmin#1\relax - \righthyphenmin#2\relax} +\let\bbl@calendar\@empty +\newcommand\BabelDateSpace{\nobreakspace} +\newcommand\BabelDateDot{.\@} +\newcommand\BabelDated[1]{{\number#1}} +\newcommand\BabelDatedd[1]{{\ifnum#1<10 0\fi\number#1}} +\newcommand\BabelDateM[1]{{\number#1}} +\newcommand\BabelDateMM[1]{{\ifnum#1<10 0\fi\number#1}} +\newcommand\BabelDateMMMM[1]{{% + \csname month\romannumeral#1\bbl@calendar name\endcsname}}% +\newcommand\BabelDatey[1]{{\number#1}}% +\newcommand\BabelDateyy[1]{{% + \ifnum#1<10 0\number#1 % + \else\ifnum#1<100 \number#1 % + \else\ifnum#1<1000 \expandafter\@gobble\number#1 % + \else\ifnum#1<10000 \expandafter\@gobbletwo\number#1 % + \else + \bbl@error + {Currently two-digit years are restricted to the\\ + range 0-9999.}% + {There is little you can do. Sorry.}% + \fi\fi\fi\fi}} +\newcommand\BabelDateyyyy[1]{{\number#1}} % FIXME - add leading 0 +\def\bbl@replace@finish@iii#1{% + \bbl@exp{\def\\#1####1####2####3{\the\toks@}}} +\def\bbl@TG@@date{% + \bbl@replace\bbl@toreplace{[ ]}{\BabelDateSpace{}}% + \bbl@replace\bbl@toreplace{[.]}{\BabelDateDot{}}% + \bbl@replace\bbl@toreplace{[d]}{\BabelDated{####3}}% + \bbl@replace\bbl@toreplace{[dd]}{\BabelDatedd{####3}}% + \bbl@replace\bbl@toreplace{[M]}{\BabelDateM{####2}}% + \bbl@replace\bbl@toreplace{[MM]}{\BabelDateMM{####2}}% + \bbl@replace\bbl@toreplace{[MMMM]}{\BabelDateMMMM{####2}}% + \bbl@replace\bbl@toreplace{[y]}{\BabelDatey{####1}}% + \bbl@replace\bbl@toreplace{[yy]}{\BabelDateyy{####1}}% + \bbl@replace\bbl@toreplace{[yyyy]}{\BabelDateyyyy{####1}}% +% Note after \bbl@replace \toks@ contains the resulting string. +% TODO - Using this implicit behavior doesn't seem a good idea. + \bbl@replace@finish@iii\bbl@toreplace} % \end{macrocode} % -% \end{macro} +% Language and Script values to be used when defining a font or +% setting the direction are set with the following macros. % -% \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. +% \begin{macrocode} +\def\bbl@provide@lsys#1{% + \bbl@ifunset{bbl@lname@#1}% + {\bbl@ini@basic{#1}}% + {}% + \bbl@csarg\let{lsys@#1}\@empty + \bbl@ifunset{bbl@sname@#1}{\bbl@csarg\gdef{sname@#1}{Default}}{}% + \bbl@ifunset{bbl@sotf@#1}{\bbl@csarg\gdef{sotf@#1}{DFLT}}{}% + \bbl@csarg\bbl@add@list{lsys@#1}{Script=\bbl@cs{sname@#1}}% + \bbl@ifunset{bbl@lname@#1}{}% + {\bbl@csarg\bbl@add@list{lsys@#1}{Language=\bbl@cs{lname@#1}}}% + \ifcase\bbl@engine\or\or + \bbl@ifunset{bbl@prehc@#1}{}% + {\bbl@exp{\\\bbl@ifblank{\bbl@cs{prehc@#1}}}% + {}% + {\bbl@csarg\bbl@add@list{lsys@#1}{HyphenChar="200B}}}% + \fi + \bbl@csarg\bbl@toglobal{lsys@#1}} +% \end{macrocode} % -% Depending on the format, ie, on if the former is defined, we use -% a similar definition or not. +% The following |ini| reader ignores everything but the +% |identification| section. It is called when a font is defined (ie, +% when the language is first selected) to know which script/language +% must be enabled. This means we must make sure a few characters are +% not active. The |ini| is not read directly, but with a proxy |tex| +% file named as the language (which means any code in it must be +% skipped, too. % % \begin{macrocode} -\ifx\ProvidesFile\@undefined - \def\ProvidesLanguage#1[#2 #3 #4]{% - \wlog{Language: #1 #4 #3 <#2>}% - } -\else - \def\ProvidesLanguage#1{% +\def\bbl@ini@basic#1{% + \def\BabelBeforeIni##1##2{% \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 + \bbl@add\bbl@secpost@identification{\closein\bbl@readstream }% + \catcode`\[=12 \catcode`\]=12 \catcode`\==12 \catcode`\;=12 % + \bbl@read@ini{##1}{font and identification data}% + \endinput % babel- .tex may contain onlypreamble's + \endgroup}% boxed, to avoid extra spaces: + {\setbox\z@\hbox{\InputIfFileExists{babel-#1.tex}{}{}}}} % \end{macrocode} % -% \end{macro} +% Alphabetic counters must be converted from a space separated list to +% an |\ifcase| structure. +% +% \begin{macrocode} +\def\bbl@buildifcase#1 {% Returns \bbl@tempa, requires \toks@={} + \ifx\\#1% % \\ before, in case #1 is multiletter + \bbl@exp{% + \def\\\bbl@tempa####1{% + \####1\space\the\toks@\\\\@ctrerr\}}% + \else + \toks@\expandafter{\the\toks@\or #1}% + \expandafter\bbl@buildifcase + \fi} +% \end{macrocode} +% +% The code for additive counters is somewhat tricky and it's based on +% the fact the arguments just before |\@@| collects digits which have +% been left ‘unused’ in previous arguments, the first of them being the +% number of digits in the number to be converted. This explains the +% reverse set |76543210|. Digits above 10000 are not handled yet. When +% the key contains the subkey |.F.|, the number after is treated as an +% special case. for a fixed form (see |babel-he.ini|, for example). % -% \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}. +% \begin{macrocode} +\newcommand\localenumeral[2]{\bbl@cs{cntr@#1@\languagename}{#2}} +\def\bbl@localecntr#1#2{\localenumeral{#2}{#1}} +\newcommand\localecounter[2]{% + \expandafter\bbl@localecntr\csname c@#2\endcsname{#1}} +\def\bbl@alphnumeral#1#2{% + \expandafter\bbl@alphnumeral@i\number#2 76543210\@@{#1}} +\def\bbl@alphnumeral@i#1#2#3#4#5#6#7#8\@@#9{% + \ifcase\@car#8\@nil\or % Currenty <10000, but prepared for bigger + \bbl@alphnumeral@ii{#9}000000#1\or + \bbl@alphnumeral@ii{#9}00000#1#2\or + \bbl@alphnumeral@ii{#9}0000#1#2#3\or + \bbl@alphnumeral@ii{#9}000#1#2#3#4\else + \bbl@alphnum@invalid{>9999}% + \fi} +\def\bbl@alphnumeral@ii#1#2#3#4#5#6#7#8{% + \bbl@ifunset{bbl@cntr@#1.F.\number#5#6#7#8@\languagename}% + {\bbl@cs{cntr@#1.4@\languagename}#5% + \bbl@cs{cntr@#1.3@\languagename}#6% + \bbl@cs{cntr@#1.2@\languagename}#7% + \bbl@cs{cntr@#1.1@\languagename}#8% + \ifnum#6#7#8>\z@ % An ad hod rule for Greek. Ugly. To be fixed. + \bbl@ifunset{bbl@cntr@#1.S.321@\languagename}{}% + {\bbl@cs{cntr@#1.S.321@\languagename}}% + \fi}% + {\bbl@cs{cntr@#1.F.\number#5#6#7#8@\languagename}}} +\def\bbl@alphnum@invalid#1{% + \bbl@error{Alphabetic numeral too large (#1)}% + {Currently this is the limit.}} +% \end{macrocode} % -% The category code of the ampersand is restored and the macro -% calls itself again with the new definition from -% \file{babel.def} +% The information in the identification section can be useful, so the +% following macro just exposes it with a user command. % % \begin{macrocode} -\def\LdfInit{% - \chardef\atcatcode=\catcode`\@ - \catcode`\@=11\relax - \input babel.def\relax - \catcode`\@=\atcatcode \let\atcatcode\relax - \LdfInit} +\newcommand\localeinfo[1]{% + \bbl@ifunset{bbl@\csname bbl@info@#1\endcsname @\languagename}% + {\bbl@error{I've found no info for the current locale.\\% + The corresponding ini file has not been loaded\\% + Perhaps it doesn't exist}% + {See the manual for details.}}% + {\bbl@cs{\csname bbl@info@#1\endcsname @\languagename}}} +% \@namedef{bbl@info@name.locale}{lcname} +\@namedef{bbl@info@tag.ini}{lini} +\@namedef{bbl@info@name.english}{elname} +\@namedef{bbl@info@name.opentype}{lname} +\@namedef{bbl@info@tag.bcp47}{lbcp} +\@namedef{bbl@info@tag.opentype}{lotf} +\@namedef{bbl@info@script.name}{esname} +\@namedef{bbl@info@script.name.opentype}{sname} +\@namedef{bbl@info@script.tag.bcp47}{sbcp} +\@namedef{bbl@info@script.tag.opentype}{sotf} +\let\bbl@ensureinfo\@gobble +\newcommand\BabelEnsureInfo{% + \def\bbl@ensureinfo##1{% + \ifx\InputIfFileExists\@undefined\else % not in plain + \bbl@ifunset{bbl@lname@##1}{\bbl@ini@basic{##1}}{}% + \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|. +% 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} -\ifx\originalTeX\@undefined\let\originalTeX\@empty\fi +% \begin{macrocode} +\newcommand\getlocaleproperty[3]{% + \let#1\relax + \def\bbl@elt##1##2##3{% + \bbl@ifsamestring{##1/##2}{#3}% + {\providecommand#1{##3}% + \def\bbl@elt####1####2####3{}}% + {}}% + \bbl@cs{inidata@#2}% + \ifx#1\relax + \bbl@error + {Unknown key for locale '#2':\\% + #3\\% + \string#1 will be set to \relax}% + {Perhaps you misspelled it.}% + \fi} +\newcommand\LocaleForEach{\bbl@foreach\bbl@ini@loaded} % \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. +% \section{Adjusting the Babel bahavior} % -% \begin{macrocode} -\ifx\babel@beginsave\@undefined\let\babel@beginsave\relax\fi -% \end{macrocode} +% A generic high level inteface is provided to adjust some global +% and general settings. % -% \end{macro} +% \begin{macrocode} +\newcommand\babeladjust[1]{% TODO. Error handling. + \bbl@forkv{#1}{% + \bbl@ifunset{bbl@ADJ@##1@##2}% + {\bbl@cs{ADJ@##1}{##2}}% + {\bbl@cs{ADJ@##1@##2}}}} % -% A few macro names are reserved for future releases of \babel, which -% will use the concept of `locale': +\def\bbl@adjust@lua#1#2{% + \ifvmode + \ifnum\currentgrouplevel=\z@ + \directlua{ Babel.#2 }% + \expandafter\expandafter\expandafter\@gobble + \fi + \fi + {\bbl@error % The error is gobbled if everything went ok. + {Currently, #1 related features can be adjusted only\\% + in the main vertical list.}% + {Maybe things change in the future, but this is what it is.}}} +\@namedef{bbl@ADJ@bidi.mirroring@on}{% + \bbl@adjust@lua{bidi}{mirroring_enabled=true}} +\@namedef{bbl@ADJ@bidi.mirroring@off}{% + \bbl@adjust@lua{bidi}{mirroring_enabled=false}} +\@namedef{bbl@ADJ@bidi.text@on}{% + \bbl@adjust@lua{bidi}{bidi_enabled=true}} +\@namedef{bbl@ADJ@bidi.text@off}{% + \bbl@adjust@lua{bidi}{bidi_enabled=false}} +\@namedef{bbl@ADJ@bidi.mapdigits@on}{% + \bbl@adjust@lua{bidi}{digits_mapped=true}} +\@namedef{bbl@ADJ@bidi.mapdigits@off}{% + \bbl@adjust@lua{bidi}{digits_mapped=false}} % -% \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} +\@namedef{bbl@ADJ@linebreak.sea@on}{% + \bbl@adjust@lua{linebreak}{sea_enabled=true}} +\@namedef{bbl@ADJ@linebreak.sea@off}{% + \bbl@adjust@lua{linebreak}{sea_enabled=false}} +\@namedef{bbl@ADJ@linebreak.cjk@on}{% + \bbl@adjust@lua{linebreak}{cjk_enabled=true}} +\@namedef{bbl@ADJ@linebreak.cjk@off}{% + \bbl@adjust@lua{linebreak}{cjk_enabled=false}} % -% \subsection{Errors} +\def\bbl@adjust@layout#1{% + \ifvmode + #1% + \expandafter\@gobble + \fi + {\bbl@error % The error is gobbled if everything went ok. + {Currently, layout related features can be adjusted only\\% + in vertical mode.}% + {Maybe things change in the future, but this is what it is.}}} +\@namedef{bbl@ADJ@layout.tabular@on}{% + \bbl@adjust@layout{\let\@tabular\bbl@NL@@tabular}} +\@namedef{bbl@ADJ@layout.tabular@off}{% + \bbl@adjust@layout{\let\@tabular\bbl@OL@@tabular}} +\@namedef{bbl@ADJ@layout.lists@on}{% + \bbl@adjust@layout{\let\list\bbl@NL@list}} +\@namedef{bbl@ADJ@layout.lists@on}{% + \bbl@adjust@layout{\let\list\bbl@OL@list}} +\@namedef{bbl@ADJ@hyphenation.extra@on}{% + \bbl@activateposthyphen} % -% \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. +\@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. % -% 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'. +\ifx\directlua\@undefined\else + \ifx\bbl@luapatterns\@undefined + \input luababel.def + \fi +\fi +% +% \end{macrocode} % -% 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. +% A proxy file for switch.def % % \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 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 % %<*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 -%<> -% \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 % % \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} %\a plain.tex %\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} %\def\fmtname{babel-plain} %\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 +%<> +% \end{macrocode} +% +% A proxy file: +% \begin{macrocode} +%<*plain> +\input babel.def % % \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] % % %% 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 Binary files a/Master/texmf-dist/source/latex/babel/locale.zip and b/Master/texmf-dist/source/latex/babel/locale.zip differ diff --git a/Master/texmf-dist/tex/generic/babel/babel-bidi-basic-r.lua b/Master/texmf-dist/tex/generic/babel/babel-bidi-basic-r.lua index 3fbb4e83e95..3c751fbcd42 100644 --- a/Master/texmf-dist/tex/generic/babel/babel-bidi-basic-r.lua +++ b/Master/texmf-dist/tex/generic/babel/babel-bidi-basic-r.lua @@ -200,3 +200,4 @@ function Babel.bidi(head, ispar) end return node.prev(head) or head end + diff --git a/Master/texmf-dist/tex/generic/babel/babel-bidi-basic.lua b/Master/texmf-dist/tex/generic/babel/babel-bidi-basic.lua index 8acc02ed6fe..efff60cefcf 100644 --- a/Master/texmf-dist/tex/generic/babel/babel-bidi-basic.lua +++ b/Master/texmf-dist/tex/generic/babel/babel-bidi-basic.lua @@ -409,3 +409,4 @@ function Babel.bidi(head, ispar, hdir) return node.prev(head) or head end + diff --git a/Master/texmf-dist/tex/generic/babel/babel-data-bidi.lua b/Master/texmf-dist/tex/generic/babel/babel-data-bidi.lua index 9e3aefa7990..1a059bfc62f 100644 --- a/Master/texmf-dist/tex/generic/babel/babel-data-bidi.lua +++ b/Master/texmf-dist/tex/generic/babel/babel-data-bidi.lua @@ -6113,3 +6113,4 @@ Babel.characters={ [0xE007E]={d='bn'}, [0xE007F]={d='bn'} } + diff --git a/Master/texmf-dist/tex/generic/babel/babel-data-cjk.lua b/Master/texmf-dist/tex/generic/babel/babel-data-cjk.lua index 99c356c4a83..fefd7a2d7f7 100644 --- a/Master/texmf-dist/tex/generic/babel/babel-data-cjk.lua +++ b/Master/texmf-dist/tex/generic/babel/babel-data-cjk.lua @@ -288,3 +288,4 @@ Babel.cjk_breaks = { ['I'] = { ['op']=1, ['pr']=1, ['I']=1, ['O']=1 }, ['O'] = { ['I']=1 } } + diff --git a/Master/texmf-dist/tex/generic/babel/babel.def b/Master/texmf-dist/tex/generic/babel/babel.def index 8c88c5f619e..3db01a667c0 100644 --- a/Master/texmf-dist/tex/generic/babel/babel.def +++ b/Master/texmf-dist/tex/generic/babel/babel.def @@ -32,20 +32,344 @@ %% extension |.ins|) which are part of the distribution. %% -\ifx\ldf@quit\@undefined -\else - \expandafter\endinput -\fi +\ifx\ldf@quit\@undefined\else +\endinput\fi % Same line! \ifx\ProvidesFile\@undefined \def\ProvidesFile#1[#2 #3 #4]{% \wlog{File: #1 #4 #3 <#2>}% \let\ProvidesFile\@undefined} \fi -\ProvidesFile{babel.def}[2020/03/22 3.42 Babel common definitions] -\ifx\AtBeginDocument\@undefined - \input plain.def\relax +\ProvidesFile{babel.def}[2020/04/28 3.43 Babel common definitions] +\ifx\AtBeginDocument\@undefined % TODO. change test. + % == Code for plain == +\def\@empty{} +\def\loadlocalcfg#1{% + \openin0#1.cfg + \ifeof0 + \closein0 + \else + \closein0 + {\immediate\write16{*************************************}% + \immediate\write16{* Local config file #1.cfg used}% + \immediate\write16{*}% + } + \input #1.cfg\relax + \fi + \@endofldf} +\long\def\@firstofone#1{#1} +\long\def\@firstoftwo#1#2{#1} +\long\def\@secondoftwo#1#2{#2} +\def\@nnil{\@nil} +\def\@gobbletwo#1#2{} +\def\@ifstar#1{\@ifnextchar *{\@firstoftwo{#1}}} +\def\@star@or@long#1{% + \@ifstar + {\let\l@ngrel@x\relax#1}% + {\let\l@ngrel@x\long#1}} +\let\l@ngrel@x\relax +\def\@car#1#2\@nil{#1} +\def\@cdr#1#2\@nil{#2} +\let\@typeset@protect\relax +\let\protected@edef\edef +\long\def\@gobble#1{} +\edef\@backslashchar{\expandafter\@gobble\string\\} +\def\strip@prefix#1>{} +\def\g@addto@macro#1#2{{% + \toks@\expandafter{#1#2}% + \xdef#1{\the\toks@}}} +\def\@namedef#1{\expandafter\def\csname #1\endcsname} +\def\@nameuse#1{\csname #1\endcsname} +\def\@ifundefined#1{% + \expandafter\ifx\csname#1\endcsname\relax + \expandafter\@firstoftwo + \else + \expandafter\@secondoftwo + \fi} +\def\@expandtwoargs#1#2#3{% + \edef\reserved@a{\noexpand#1{#2}{#3}}\reserved@a} +\def\zap@space#1 #2{% + #1% + \ifx#2\@empty\else\expandafter\zap@space\fi + #2} +\let\bbl@trace\@gobble +\ifx\@preamblecmds\@undefined + \def\@preamblecmds{} +\fi +\def\@onlypreamble#1{% + \expandafter\gdef\expandafter\@preamblecmds\expandafter{% + \@preamblecmds\do#1}} +\@onlypreamble\@onlypreamble +\def\begindocument{% + \@begindocumenthook + \global\let\@begindocumenthook\@undefined + \def\do##1{\global\let##1\@undefined}% + \@preamblecmds + \global\let\do\noexpand} +\ifx\@begindocumenthook\@undefined + \def\@begindocumenthook{} +\fi +\@onlypreamble\@begindocumenthook +\def\AtBeginDocument{\g@addto@macro\@begindocumenthook} +\def\AtEndOfPackage#1{\g@addto@macro\@endofldf{#1}} +\@onlypreamble\AtEndOfPackage +\def\@endofldf{} +\@onlypreamble\@endofldf +\let\bbl@afterlang\@empty +\chardef\bbl@opt@hyphenmap\z@ +\catcode`\&=\z@ +\ifx&if@filesw\@undefined + \expandafter\let\csname if@filesw\expandafter\endcsname + \csname iffalse\endcsname +\fi +\catcode`\&=4 +\def\newcommand{\@star@or@long\new@command} +\def\new@command#1{% + \@testopt{\@newcommand#1}0} +\def\@newcommand#1[#2]{% + \@ifnextchar [{\@xargdef#1[#2]}% + {\@argdef#1[#2]}} +\long\def\@argdef#1[#2]#3{% + \@yargdef#1\@ne{#2}{#3}} +\long\def\@xargdef#1[#2][#3]#4{% + \expandafter\def\expandafter#1\expandafter{% + \expandafter\@protected@testopt\expandafter #1% + \csname\string#1\expandafter\endcsname{#3}}% + \expandafter\@yargdef \csname\string#1\endcsname + \tw@{#2}{#4}} +\long\def\@yargdef#1#2#3{% + \@tempcnta#3\relax + \advance \@tempcnta \@ne + \let\@hash@\relax + \edef\reserved@a{\ifx#2\tw@ [\@hash@1]\fi}% + \@tempcntb #2% + \@whilenum\@tempcntb <\@tempcnta + \do{% + \edef\reserved@a{\reserved@a\@hash@\the\@tempcntb}% + \advance\@tempcntb \@ne}% + \let\@hash@##% + \l@ngrel@x\expandafter\def\expandafter#1\reserved@a} +\def\providecommand{\@star@or@long\provide@command} +\def\provide@command#1{% + \begingroup + \escapechar\m@ne\xdef\@gtempa{{\string#1}}% + \endgroup + \expandafter\@ifundefined\@gtempa + {\def\reserved@a{\new@command#1}}% + {\let\reserved@a\relax + \def\reserved@a{\new@command\reserved@a}}% + \reserved@a}% +\def\DeclareRobustCommand{\@star@or@long\declare@robustcommand} +\def\declare@robustcommand#1{% + \edef\reserved@a{\string#1}% + \def\reserved@b{#1}% + \edef\reserved@b{\expandafter\strip@prefix\meaning\reserved@b}% + \edef#1{% + \ifx\reserved@a\reserved@b + \noexpand\x@protect + \noexpand#1% + \fi + \noexpand\protect + \expandafter\noexpand\csname + \expandafter\@gobble\string#1 \endcsname + }% + \expandafter\new@command\csname + \expandafter\@gobble\string#1 \endcsname +} +\def\x@protect#1{% + \ifx\protect\@typeset@protect\else + \@x@protect#1% + \fi +} +\catcode`\&=\z@ % Trick to hide conditionals + \def\@x@protect#1&fi#2#3{&fi\protect#1} + \def\bbl@tempa{\csname newif\endcsname&ifin@} +\catcode`\&=4 +\ifx\in@\@undefined + \def\in@#1#2{% + \def\in@@##1#1##2##3\in@@{% + \ifx\in@##2\in@false\else\in@true\fi}% + \in@@#2#1\in@\in@@} +\else + \let\bbl@tempa\@empty +\fi +\bbl@tempa +\def\@ifpackagewith#1#2#3#4{#3} +\def\@ifl@aded#1#2#3#4{} +\ifx\@tempcnta\@undefined + \csname newcount\endcsname\@tempcnta\relax +\fi +\ifx\@tempcntb\@undefined + \csname newcount\endcsname\@tempcntb\relax +\fi +\ifx\bye\@undefined + \advance\count10 by -2\relax +\fi +\ifx\@ifnextchar\@undefined + \def\@ifnextchar#1#2#3{% + \let\reserved@d=#1% + \def\reserved@a{#2}\def\reserved@b{#3}% + \futurelet\@let@token\@ifnch} + \def\@ifnch{% + \ifx\@let@token\@sptoken + \let\reserved@c\@xifnch + \else + \ifx\@let@token\reserved@d + \let\reserved@c\reserved@a + \else + \let\reserved@c\reserved@b + \fi + \fi + \reserved@c} + \def\:{\let\@sptoken= } \: % this makes \@sptoken a space token + \def\:{\@xifnch} \expandafter\def\: {\futurelet\@let@token\@ifnch} \fi -\ifx\bbl@ifshorthand\@undefined +\def\@testopt#1#2{% + \@ifnextchar[{#1}{#1[#2]}} +\def\@protected@testopt#1{% + \ifx\protect\@typeset@protect + \expandafter\@testopt + \else + \@x@protect#1% + \fi} +\long\def\@whilenum#1\do #2{\ifnum #1\relax #2\relax\@iwhilenum{#1\relax + #2\relax}\fi} +\long\def\@iwhilenum#1{\ifnum #1\expandafter\@iwhilenum + \else\expandafter\@gobble\fi{#1}} +\def\DeclareTextCommand{% + \@dec@text@cmd\providecommand +} +\def\ProvideTextCommand{% + \@dec@text@cmd\providecommand +} +\def\DeclareTextSymbol#1#2#3{% + \@dec@text@cmd\chardef#1{#2}#3\relax +} +\def\@dec@text@cmd#1#2#3{% + \expandafter\def\expandafter#2% + \expandafter{% + \csname#3-cmd\expandafter\endcsname + \expandafter#2% + \csname#3\string#2\endcsname + }% + \expandafter#1\csname#3\string#2\endcsname +} +\def\@current@cmd#1{% + \ifx\protect\@typeset@protect\else + \noexpand#1\expandafter\@gobble + \fi +} +\def\@changed@cmd#1#2{% + \ifx\protect\@typeset@protect + \expandafter\ifx\csname\cf@encoding\string#1\endcsname\relax + \expandafter\ifx\csname ?\string#1\endcsname\relax + \expandafter\def\csname ?\string#1\endcsname{% + \@changed@x@err{#1}% + }% + \fi + \global\expandafter\let + \csname\cf@encoding \string#1\expandafter\endcsname + \csname ?\string#1\endcsname + \fi + \csname\cf@encoding\string#1% + \expandafter\endcsname + \else + \noexpand#1% + \fi +} +\def\@changed@x@err#1{% + \errhelp{Your command will be ignored, type to proceed}% + \errmessage{Command \protect#1 undefined in encoding \cf@encoding}} +\def\DeclareTextCommandDefault#1{% + \DeclareTextCommand#1?% +} +\def\ProvideTextCommandDefault#1{% + \ProvideTextCommand#1?% +} +\expandafter\let\csname OT1-cmd\endcsname\@current@cmd +\expandafter\let\csname?-cmd\endcsname\@changed@cmd +\def\DeclareTextAccent#1#2#3{% + \DeclareTextCommand#1{#2}[1]{\accent#3 ##1} +} +\def\DeclareTextCompositeCommand#1#2#3#4{% + \expandafter\let\expandafter\reserved@a\csname#2\string#1\endcsname + \edef\reserved@b{\string##1}% + \edef\reserved@c{% + \expandafter\@strip@args\meaning\reserved@a:-\@strip@args}% + \ifx\reserved@b\reserved@c + \expandafter\expandafter\expandafter\ifx + \expandafter\@car\reserved@a\relax\relax\@nil + \@text@composite + \else + \edef\reserved@b##1{% + \def\expandafter\noexpand + \csname#2\string#1\endcsname####1{% + \noexpand\@text@composite + \expandafter\noexpand\csname#2\string#1\endcsname + ####1\noexpand\@empty\noexpand\@text@composite + {##1}% + }% + }% + \expandafter\reserved@b\expandafter{\reserved@a{##1}}% + \fi + \expandafter\def\csname\expandafter\string\csname + #2\endcsname\string#1-\string#3\endcsname{#4} + \else + \errhelp{Your command will be ignored, type to proceed}% + \errmessage{\string\DeclareTextCompositeCommand\space used on + inappropriate command \protect#1} + \fi +} +\def\@text@composite#1#2#3\@text@composite{% + \expandafter\@text@composite@x + \csname\string#1-\string#2\endcsname +} +\def\@text@composite@x#1#2{% + \ifx#1\relax + #2% + \else + #1% + \fi +} +\def\@strip@args#1:#2-#3\@strip@args{#2} +\def\DeclareTextComposite#1#2#3#4{% + \def\reserved@a{\DeclareTextCompositeCommand#1{#2}{#3}}% + \bgroup + \lccode`\@=#4% + \lowercase{% + \egroup + \reserved@a @% + }% +} +\def\UseTextSymbol#1#2{% + #2% +} +\def\UseTextAccent#1#2#3{% +} +\def\@use@text@encoding#1{% +} +\def\DeclareTextSymbolDefault#1#2{% + \DeclareTextCommandDefault#1{\UseTextSymbol{#2}#1}% +} +\def\DeclareTextAccentDefault#1#2{% + \DeclareTextCommandDefault#1{\UseTextAccent{#2}#1}% +} +\def\cf@encoding{OT1} +\DeclareTextAccent{\"}{OT1}{127} +\DeclareTextAccent{\'}{OT1}{19} +\DeclareTextAccent{\^}{OT1}{94} +\DeclareTextAccent{\`}{OT1}{18} +\DeclareTextAccent{\~}{OT1}{126} +\DeclareTextSymbol{\textquotedblleft}{OT1}{92} +\DeclareTextSymbol{\textquotedblright}{OT1}{`\"} +\DeclareTextSymbol{\textquoteleft}{OT1}{`\`} +\DeclareTextSymbol{\textquoteright}{OT1}{`\'} +\DeclareTextSymbol{\i}{OT1}{16} +\DeclareTextSymbol{\ss}{OT1}{25} +\ifx\scriptsize\@undefined + \let\scriptsize\sevenrm +\fi + % End of code for plain + \def\languagename{english}% \let\bbl@opt@shorthands\@nnil \def\bbl@ifshorthand#1#2#3{#2}% \let\bbl@language@opts\@empty @@ -67,32 +391,503 @@ \ifx\bbl@trace\@undefined\def\bbl@trace#1{}\fi \expandafter\newif\csname ifbbl@single\endcsname \fi -\ifx\bbl@switchflag\@undefined % Prevent double input - \let\bbl@switchflag\relax - \input switch.def\relax +\ifx\bbl@trace\@undefined + \let\LdfInit\endinput + \def\ProvidesLanguage#1{\endinput} +\endinput\fi % Same line! +\ifx\language\@undefined + \csname newcount\endcsname\language \fi -\bbl@trace{Compatibility with language.def} -\ifx\bbl@languages\@undefined - \ifx\directlua\@undefined - \openin1 = language.def - \ifeof1 - \closein1 - \message{I couldn't find the file language.def} +\ifx\newlanguage\@undefined + \csname newcount\endcsname\last@language + \def\addlanguage#1{% + \global\advance\last@language\@ne + \ifnum\last@language<\@cclvi \else - \closein1 - \begingroup - \def\addlanguage#1#2#3#4#5{% - \expandafter\ifx\csname lang@#1\endcsname\relax\else - \global\expandafter\let\csname l@#1\expandafter\endcsname - \csname lang@#1\endcsname - \fi}% - \def\uselanguage#1{}% - \input language.def - \endgroup + \errmessage{No room for a new \string\language!}% + \fi + \global\chardef#1\last@language + \wlog{\string#1 = \string\language\the\last@language}} +\else + \countdef\last@language=19 + \def\addlanguage{\alloc@9\language\chardef\@cclvi} +\fi +\def\bbl@version{3.43} +\def\bbl@date{2020/04/28} +\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} +\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} +\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 - \chardef\l@english\z@ + \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} +\def\iflanguage#1{% + \bbl@iflanguage{#1}{% + \ifnum\csname l@#1\endcsname=\language + \expandafter\@firstoftwo + \else + \expandafter\@secondoftwo + \fi}} +\let\bbl@select@type\z@ +\edef\selectlanguage{% + \noexpand\protect + \expandafter\noexpand\csname selectlanguage \endcsname} +\ifx\@undefined\protect\let\protect\relax\fi +\let\xstring\string +\def\bbl@language@stack{} +\def\bbl@push@language{% + \ifx\languagename\@undefined\else + \xdef\bbl@language@stack{\languagename+\bbl@language@stack}% + \fi} +\def\bbl@pop@lang#1+#2{% + \edef\languagename{#1}\xdef#3{#2}} +\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} +\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@}} +\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}} +\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}% + \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}} +\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 \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- + % > 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} +\long\def\otherlanguage#1{% + \ifnum\bbl@hymapsel=\@cclv\let\bbl@hymapsel\thr@@\fi + \csname selectlanguage \endcsname{#1}% + \ignorespaces} +\long\def\endotherlanguage{% + \global\@ignoretrue\ignorespaces} +\expandafter\def\csname otherlanguage*\endcsname#1{% + \ifnum\bbl@hymapsel=\@cclv\chardef\bbl@hymapsel4\relax\fi + \foreign@language{#1}} +\expandafter\let\csname endotherlanguage*\endcsname\relax +\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} +\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}}} +\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}} +\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 +\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} +\ifx\ProvidesFile\@undefined + \def\ProvidesLanguage#1[#2 #3 #4]{% + \wlog{Language: #1 #4 #3 <#2>}% + } +\else + \def\ProvidesLanguage#1{% + \begingroup + \catcode`\ 10 % + \@makeother\/% + \@ifnextchar[%] + {\@provideslanguage{#1}}{\@provideslanguage{#1}[]}} + \def\@provideslanguage#1[#2]{% + \wlog{Language: #1 #2}% + \expandafter\xdef\csname ver@#1.ldf\endcsname{#2}% + \endgroup} \fi +\ifx\originalTeX\@undefined\let\originalTeX\@empty\fi +\ifx\babel@beginsave\@undefined\let\babel@beginsave\relax\fi +\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 +\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 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 \ifx\directlua\@undefined\else \ifx\bbl@luapatterns\@undefined \input luababel.def @@ -246,6 +1041,28 @@ \else \@ne \fi +\bbl@trace{Compatibility with language.def} +\ifx\bbl@languages\@undefined + \ifx\directlua\@undefined + \openin1 = language.def % TODO. Remove hardcoded number + \ifeof1 + \closein1 + \message{I couldn't find the file language.def} + \else + \closein1 + \begingroup + \def\addlanguage#1#2#3#4#5{% + \expandafter\ifx\csname lang@#1\endcsname\relax\else + \global\expandafter\let\csname l@#1\expandafter\endcsname + \csname lang@#1\endcsname + \fi}% + \def\uselanguage#1{}% + \input language.def + \endgroup + \fi + \fi + \chardef\l@english\z@ +\fi \def\addto#1#2{% \ifx#1\@undefined \def#1{#2}% @@ -304,7 +1121,7 @@ adddialect=2,patterns=2,defaultcommands=0,encodedcommands=2,write=0,% beforeextras=0,afterextras=0,stopcommands=0,stringprocess=0,% hyphenation=2,initiateactive=3,afterreset=0,foreign=0,foreign*=0,% - beforestart=0,languagename=0} + beforestart=0,languagename=2} \bbl@trace{Defining babelensure} \newcommand\babelensure[2][]{% TODO - revise test files \AddBabelHook{babel-ensure}{afterextras}{% @@ -331,7 +1148,7 @@ \def\{\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 @@ -370,7 +1187,7 @@ \tablename\partname\enclname\ccname\headtoname\pagename\seename \alsoname\proofname\glossaryname} \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 @@ -401,13 +1218,15 @@ \catcode`\@=\atcatcode \let\atcatcode\relax \catcode`\==\eqcatcode \let\eqcatcode\relax \endinput} -\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 @@ -417,24 +1236,24 @@ \@onlypreamble\ldf@finish \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}} \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 \def\select@language@x#1{% \ifcase\bbl@select@type \bbl@ifsamestring\languagename{#1}{}{\select@language{#1}}% @@ -570,7 +1389,7 @@ \bbl@afterfi\csname#1@sh@#2@sel\endcsname \fi} \begingroup -\bbl@ifunset{ifincsname}% +\bbl@ifunset{ifincsname}% TODO. Ugly. Correct? {\gdef\active@prefix#1{% \ifx\protect\@typeset@protect \else @@ -641,7 +1460,7 @@ \expandafter\@firstoftwo \fi} \def\user@group{user} -\def\language@group{english} +\def\language@group{english} % TODO. I don't like defaults \def\system@group{system} \def\useshorthands{% \@ifstar\bbl@usesh@s{\bbl@usesh@x{}}} @@ -947,7 +1766,7 @@ \def\bbl@disc#1#2{\nobreak\discretionary{#2-}{}{#1}\bbl@allowhyphens} \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 @@ -1190,6 +2009,20 @@ \box\z@\kern-.04em\bbl@allowhyphens}} \ProvideTextCommandDefault{\quotesinglbase}{% \UseTextSymbol{OT1}{\quotesinglbase}} +\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 @@ -1204,6 +2037,10 @@ \save@sf@q{\nobreak \raise.2ex\hbox{$\scriptscriptstyle\gg$}\bbl@allowhyphens}% \fi} +\ProvideTextCommandDefault{\guillemetleft}{% + \UseTextSymbol{OT1}{\guillemetleft}} +\ProvideTextCommandDefault{\guillemetright}{% + \UseTextSymbol{OT1}{\guillemetright}} \ProvideTextCommandDefault{\guillemotleft}{% \UseTextSymbol{OT1}{\guillemotleft}} \ProvideTextCommandDefault{\guillemotright}{% @@ -1287,9 +2124,9 @@ \ProvideTextCommandDefault{\frq}{% \textormath{\guilsinglright}{\mbox{\guilsinglright}}} \ProvideTextCommandDefault{\flqq}{% - \textormath{\guillemotleft}{\mbox{\guillemotleft}}} + \textormath{\guillemetleft}{\mbox{\guillemetleft}}} \ProvideTextCommandDefault{\frqq}{% - \textormath{\guillemotright}{\mbox{\guillemotright}}} + \textormath{\guillemetright}{\mbox{\guillemetright}}} \def\umlauthigh{% \def\bbl@umlauta##1{\leavevmode\bgroup% \expandafter\accent\csname\f@encoding dqpos\endcsname @@ -1329,7 +2166,6 @@ \ifx\l@english\@undefined \chardef\l@english\z@ \fi -\main@language{english} \bbl@trace{Bidi layout} \providecommand\IfBabelLayout[3]{#3}% \newcommand\BabelPatchSection[1]{% @@ -1406,10 +2242,14 @@ % == 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 @@ -1433,11 +2273,14 @@ \\\foreignlanguage{\languagename}% {####1}}}}% {}% + \bbl@exp{% + \\\bbl@toglobal\% + \\\bbl@toglobal\}% % 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 % @@ -1448,14 +2291,21 @@ \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 @@ -1706,7 +2556,11 @@ \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 @@ -1719,8 +2573,34 @@ \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}% @@ -1758,7 +2638,14 @@ \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\}}% + \fi + \else % if importing \bbl@exp{% and hyphenrules is not empty \\\bbl@ifblank{\bbl@cs{hyphr@#1}}% {}% @@ -1899,13 +2786,13 @@ \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 \\ @@ -2117,7 +3004,10 @@ \fi} \newcommand\LocaleForEach{\bbl@foreach\bbl@ini@loaded} \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 \ifnum\currentgrouplevel=\z@ @@ -2168,455 +3058,24 @@ \bbl@adjust@layout{\let\list\bbl@OL@list}} \@namedef{bbl@ADJ@hyphenation.extra@on}{% \bbl@activateposthyphen} -{\def\format{lplain} -\ifx\fmtname\format -\else - \def\format{LaTeX2e} - \ifx\fmtname\format - \else - \aftergroup\endinput - \fi -\fi} -\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}}} - \CheckCommand*\@testdef[3]{% - \def\reserved@a{#3}% - \expandafter\ifx\csname#1@#2\endcsname\reserved@a - \else - \@tempswatrue - \fi} - \def\@testdef#1#2#3{% - \@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 -\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 -\bbl@xin@{B}\bbl@opt@safe -\ifin@ - \bbl@redefine\@citex[#1]#2{% - \@safe@activestrue\edef\@tempa{#2}\@safe@activesfalse - \org@@citex[#1]{\@tempa}} - \AtBeginDocument{% - \@ifpackageloaded{natbib}{% - \def\@citex[#1][#2]#3{% - \@safe@activestrue\edef\@tempa{#3}\@safe@activesfalse - \org@@citex[#1][#2]{\@tempa}}% - }{}} - \AtBeginDocument{% - \@ifpackageloaded{cite}{% - \def\@citex[#1]#2{% - \@safe@activestrue\org@@citex[#1]{#2}\@safe@activesfalse}% - }{}} - \bbl@redefine\nocite#1{% - \@safe@activestrue\org@nocite{#1}\@safe@activesfalse} - \bbl@redefine\bibcite{% - \bbl@cite@choice - \bibcite} - \def\bbl@bibcite#1#2{% - \org@bibcite{#1}{\@safe@activesfalse#2}} - \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} - \AtBeginDocument{\bbl@cite@choice} - \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 -\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@}}}}}% - \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 -\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}% - }% - }{}% - } - \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}% - \expandafter\def\csname Ref \endcsname#1{% - \protected@edef\@tempa{\org@ref{#1}}\expandafter\MakeUppercase\@tempa} - }{}% - } -\fi -\AtEndOfPackage{% - \AtBeginDocument{% - \@ifpackageloaded{hhline}% - {\expandafter\ifx\csname normal@char\string:\endcsname\relax - \else - \makeatletter - \def\@currname{hhline}\input{hhline.sty}\makeatother - \fi}% - {}}} -\AtBeginDocument{% - \ifx\pdfstringdefDisableCommands\@undefined\else - \pdfstringdefDisableCommands{\languageshorthands{system}}% - \fi} -\DeclareRobustCommand{\FOREIGNLANGUAGE}[1]{% - \lowercase{\foreignlanguage{#1}}} -\def\substitutefontfamily#1#2#3{% - \lowercase{\immediate\openout15=#1#2.fd\relax}% - \immediate\write15{% - \string\ProvidesFile{#1#2.fd}% - [\the\year/\two@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 -\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} -\AtEndOfPackage{\edef\latinencoding{\cf@encoding}} -\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}} -\DeclareRobustCommand{\latintext}{% - \fontencoding{\latinencoding}\selectfont - \def\encodingdefault{\latinencoding}} -\ifx\@undefined\DeclareTextFontCommand - \DeclareRobustCommand{\textlatin}[1]{\leavevmode{\latintext #1}} -\else - \DeclareTextFontCommand{\textlatin}{\latintext} -\fi -\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}% +\@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}} +\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} - \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 -\DeclareRobustCommand\babelsublr[1]{\leavevmode{\bbl@textdir\z@#1}} -\AtBeginDocument{% - \ifx\pdfstringdefDisableCommands\@undefined\else - \ifx\pdfstringdefDisableCommands\relax\else - \pdfstringdefDisableCommands{\let\babelsublr\@firstofone}% - \fi - \fi} -\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 -\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 + \endinput %% %% End of file `babel.def'. diff --git a/Master/texmf-dist/tex/generic/babel/babel.sty b/Master/texmf-dist/tex/generic/babel/babel.sty index 3d6be430945..bfa5ab18295 100644 --- a/Master/texmf-dist/tex/generic/babel/babel.sty +++ b/Master/texmf-dist/tex/generic/babel/babel.sty @@ -33,21 +33,12 @@ %% \NeedsTeXFormat{LaTeX2e}[2005/12/01] -\ProvidesPackage{babel}[2020/03/22 3.42 The Babel package] +\ProvidesPackage{babel}[2020/04/28 3.43 The Babel package] \@ifpackagewith{babel}{debug} {\providecommand\bbl@trace[1]{\message{^^J[ #1 ]}}% \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 -\ifx\directlua\@undefined\else - \ifx\bbl@luapatterns\@undefined - \input luababel.def - \fi -\fi \bbl@trace{Basic macros} \def\bbl@stripslash{\expandafter\@gobble\string} \def\bbl@add#1#2{% @@ -196,6 +187,64 @@ \else \@ne \fi + % 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 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}% \ifx\bbl@languages\@undefined\else @@ -215,7 +264,27 @@ \def\bbl@elt##1##2##3##4{}% \fi}% \bbl@languages -\fi +\fi% +\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}{}% \ifodd\bbl@engine \def\bbl@activate@preotf{% \let\bbl@activate@preotf\relax % only once @@ -271,21 +340,6 @@ \bbl@activate@preotf \fi \fi -\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}{}% \bbl@trace{key=value and another general options} \bbl@csarg\let{tempa\expandafter}\csname opt@babel.sty\endcsname \def\bbl@tempb#1.#2{% @@ -315,6 +369,9 @@ \DeclareOption{shorthands=off}{\bbl@tempa shorthands=\bbl@tempa} \newif\ifbbl@single \DeclareOption{selectors=off}{\bbl@singletrue} +\DeclareOption{safe=none}{\let\bbl@opt@safe\@empty} +\DeclareOption{safe=bib}{\def\bbl@opt@safe{B}} +\DeclareOption{safe=ref}{\def\bbl@opt@safe{R}} \DeclareOption{math=active}{} \DeclareOption{math=normal}{\def\bbl@mathnormal{\noexpand\textormath}} \DeclareOption{nocase}{} @@ -327,9 +384,6 @@ \DeclareOption{hyphenmap=select}{\chardef\bbl@opt@hyphenmap\tw@} \DeclareOption{hyphenmap=other}{\chardef\bbl@opt@hyphenmap\thr@@} \DeclareOption{hyphenmap=other*}{\chardef\bbl@opt@hyphenmap4\relax} -\DeclareOption{safe=none}{\let\bbl@opt@safe\@empty} -\DeclareOption{safe=bib}{\def\bbl@opt@safe{B}} -\DeclareOption{safe=ref}{\def\bbl@opt@safe{R}} \ifodd\bbl@engine \DeclareOption{bidi=basic-r}% {\ExecuteOptions{bidi=basic}} @@ -396,11 +450,12 @@ \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} \let\bbl@language@opts\@empty \DeclareOption*{% @@ -465,6 +520,447 @@ \expandafter\@secondoftwo \fi} \fi +\input babel.def +\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}}} + \CheckCommand*\@testdef[3]{% + \def\reserved@a{#3}% + \expandafter\ifx\csname#1@#2\endcsname\reserved@a + \else + \@tempswatrue + \fi} + \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 +\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 +\bbl@xin@{B}\bbl@opt@safe +\ifin@ + \bbl@redefine\@citex[#1]#2{% + \@safe@activestrue\edef\@tempa{#2}\@safe@activesfalse + \org@@citex[#1]{\@tempa}} + \AtBeginDocument{% + \@ifpackageloaded{natbib}{% + \def\@citex[#1][#2]#3{% + \@safe@activestrue\edef\@tempa{#3}\@safe@activesfalse + \org@@citex[#1][#2]{\@tempa}}% + }{}} + \AtBeginDocument{% + \@ifpackageloaded{cite}{% + \def\@citex[#1]#2{% + \@safe@activestrue\org@@citex[#1]{#2}\@safe@activesfalse}% + }{}} + \bbl@redefine\nocite#1{% + \@safe@activestrue\org@nocite{#1}\@safe@activesfalse} + \bbl@redefine\bibcite{% + \bbl@cite@choice + \bibcite} + \def\bbl@bibcite#1#2{% + \org@bibcite{#1}{\@safe@activesfalse#2}} + \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} + \AtBeginDocument{\bbl@cite@choice} + \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 +\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@}}}}}% + \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 +\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}% + }% + }{}% + } + \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}% + \expandafter\def\csname Ref \endcsname#1{% + \protected@edef\@tempa{\org@ref{#1}}\expandafter\MakeUppercase\@tempa} + }{}% + } +\fi +\AtEndOfPackage{% + \AtBeginDocument{% + \@ifpackageloaded{hhline}% + {\expandafter\ifx\csname normal@char\string:\endcsname\relax + \else + \makeatletter + \def\@currname{hhline}\input{hhline.sty}\makeatother + \fi}% + {}}} +\AtBeginDocument{% + \ifx\pdfstringdefDisableCommands\@undefined\else + \pdfstringdefDisableCommands{\languageshorthands{system}}% + \fi} +\DeclareRobustCommand{\FOREIGNLANGUAGE}[1]{% + \lowercase{\foreignlanguage{#1}}} +\def\substitutefontfamily#1#2#3{% + \lowercase{\immediate\openout15=#1#2.fd\relax}% + \immediate\write15{% + \string\ProvidesFile{#1#2.fd}% + [\the\year/\two@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 +\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} +\AtEndOfPackage{\edef\latinencoding{\cf@encoding}} +\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}} +\DeclareRobustCommand{\latintext}{% + \fontencoding{\latinencoding}\selectfont + \def\encodingdefault{\latinencoding}} +\ifx\@undefined\DeclareTextFontCommand + \DeclareRobustCommand{\textlatin}[1]{\leavevmode{\latintext #1}} +\else + \DeclareTextFontCommand{\textlatin}{\latintext} +\fi +\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} + \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 +\DeclareRobustCommand\babelsublr[1]{\leavevmode{\bbl@textdir\z@#1}} +\AtBeginDocument{% + \ifx\pdfstringdefDisableCommands\@undefined\else + \ifx\pdfstringdefDisableCommands\relax\else + \pdfstringdefDisableCommands{\let\babelsublr\@firstofone}% + \fi + \fi} +\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 +\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 \bbl@trace{Language options} \let\bbl@afterlang\relax \let\BabelModifiers\relax @@ -541,6 +1037,7 @@ \bbl@ifsamestring\CurrentOption{#1}{\global\bbl@add\bbl@afterlang}{}} \DeclareOption*{} \ProcessOptions* +\bbl@trace{Option 'main'} \ifx\bbl@opt@main\@nnil \edef\bbl@tempa{\@classoptionslist,\bbl@language@opts} \let\bbl@tempc\@empty @@ -573,6 +1070,7 @@ as the main language. Reported} \bbl@load@language{nil} \fi + \endinput %% %% End of file `babel.sty'. diff --git a/Master/texmf-dist/tex/generic/babel/blplain.tex b/Master/texmf-dist/tex/generic/babel/blplain.tex index a649c5d17ed..d3cc84fec65 100644 --- a/Master/texmf-dist/tex/generic/babel/blplain.tex +++ b/Master/texmf-dist/tex/generic/babel/blplain.tex @@ -47,6 +47,7 @@ \fi \a lplain.tex \def\fmtname{babel-lplain} + \endinput %% %% End of file `blplain.tex'. diff --git a/Master/texmf-dist/tex/generic/babel/bplain.tex b/Master/texmf-dist/tex/generic/babel/bplain.tex index 67bb6c63ab9..43ddb01bdd9 100644 --- a/Master/texmf-dist/tex/generic/babel/bplain.tex +++ b/Master/texmf-dist/tex/generic/babel/bplain.tex @@ -47,6 +47,7 @@ \fi \a plain.tex \def\fmtname{babel-plain} + \endinput %% %% End of file `bplain.tex'. diff --git a/Master/texmf-dist/tex/generic/babel/hyphen.cfg b/Master/texmf-dist/tex/generic/babel/hyphen.cfg index 5299d74cad3..a66ac1fbcda 100644 --- a/Master/texmf-dist/tex/generic/babel/hyphen.cfg +++ b/Master/texmf-dist/tex/generic/babel/hyphen.cfg @@ -37,8 +37,10 @@ \wlog{File: #1 #4 #3 <#2>}% \let\ProvidesFile\@undefined} \fi -\ProvidesFile{hyphen.cfg}[2020/03/22 3.42 Babel hyphens] +\ProvidesFile{hyphen.cfg}[2020/04/28 3.43 Babel hyphens] \xdef\bbl@format{\jobname} +\def\bbl@version{3.43} +\def\bbl@date{2020/04/28} \ifx\AtBeginDocument\@undefined \def\@empty{} \let\orig@dump\dump @@ -127,7 +129,45 @@ \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 @@ -194,6 +234,7 @@ \let\bbl@hook@everylanguage\@undefined \let\bbl@hook@loadpatterns\@undefined \let\bbl@hook@loadexceptions\@undefined + \endinput %% %% End of file `hyphen.cfg'. diff --git a/Master/texmf-dist/tex/generic/babel/locale/as/babel-as.ini b/Master/texmf-dist/tex/generic/babel/locale/as/babel-as.ini index 240a2e3dee7..19f4e7458de 100644 --- a/Master/texmf-dist/tex/generic/babel/locale/as/babel-as.ini +++ b/Master/texmf-dist/tex/generic/babel/locale/as/babel-as.ini @@ -8,11 +8,12 @@ ; * Common Locale Data Repository (license Unicode): ; http://cldr.unicode.org/ ; http://unicode.org/copyright.html +; * Contributors: Navanath Saharia [identification] charset = utf8 -version = 1.4 -date = 2020-03-22 +version = 1.5 +date = 2020-04-07 name.local = অসমীয়া name.english = Assamese name.babel = assamese @@ -27,50 +28,27 @@ encodings = derivate = no [captions] -preface = -ref = -abstract = -bib = -chapter = -appendix = -contents = -listfigure = -listtable = -index = -figure = -table = -part = -encl = -cc = -headto = -page = -see = -also = -proof = -glossary = - -[captions.licr] -preface = -ref = -abstract = -bib = -chapter = -appendix = -contents = -listfigure = -listtable = -index = -figure = -table = -part = -encl = -cc = -headto = -page = -see = -also = -proof = -glossary = +preface = পাতনি +ref = প্ৰসংগ +abstract = মূলভাৱ +bib = তথ্যসূত্ৰ +chapter = অধ্যায় +appendix = পৰিশিষ্ট +contents = সমল +listfigure = চিত্ৰসূচী +listtable = তালিকাসূচী +index = বিষয়সূচী +figure = চিত্ৰ +table = তালিকা +part = অংশ +encl = সংযোজিত +cc = প্ৰতিলিপি +headto = মুখে +page = পৃষ্ঠা +see = চাওক +also = ও +proof = প্ৰমাণ +glossary = অৰ্থকোষ [date.gregorian] date.long = [y] [MMMM] [d] @@ -87,18 +65,18 @@ months.wide.9 = ছেপ্তেম্বৰ months.wide.10 = অক্টোবৰ months.wide.11 = নৱেম্বৰ months.wide.12 = ডিচেম্বৰ -months.narrow.1 = 1 -months.narrow.2 = 2 -months.narrow.3 = 3 -months.narrow.4 = 4 -months.narrow.5 = 5 -months.narrow.6 = 6 -months.narrow.7 = 7 -months.narrow.8 = 8 -months.narrow.9 = 9 -months.narrow.10 = 10 -months.narrow.11 = 11 -months.narrow.12 = 12 +months.narrow.1 = ১ +months.narrow.2 = ২ +months.narrow.3 = ৩ +months.narrow.4 = ৪ +months.narrow.5 = ৫ +months.narrow.6 = ৬ +months.narrow.7 = ৭ +months.narrow.8 = ৮ +months.narrow.9 = ৯ +months.narrow.10 = ১০ +months.narrow.11 = ১১ +months.narrow.12 = ১২ days.wide.mon = সোমবাৰ days.wide.tue = মঙ্গলবাৰ days.wide.wed = বুধবাৰ @@ -109,17 +87,17 @@ days.wide.sun = দেওবাৰ days.abbreviated.mon = সোম days.abbreviated.tue = মঙ্গল days.abbreviated.wed = বুধ -days.abbreviated.thu = বৃহষ্পতি +days.abbreviated.thu = বৃহ days.abbreviated.fri = শুক্ৰ days.abbreviated.sat = শনি days.abbreviated.sun = ৰবি -days.narrow.mon = M -days.narrow.tue = T -days.narrow.wed = W -days.narrow.thu = T -days.narrow.fri = F -days.narrow.sat = S -days.narrow.sun = S +days.narrow.mon = সো +days.narrow.tue = ম +days.narrow.wed = বু +days.narrow.thu = বৃ +days.narrow.fri = শু +days.narrow.sat = শ +days.narrow.sun = ৰ dayPeriods.abbreviated.am = পূৰ্বাহ্ণ dayPeriods.abbreviated.pm = অপৰাহ্ণ dayPeriods.narrow.am = পূৰ্বাহ্ণ @@ -150,7 +128,7 @@ hyphenate.other = "200C "200D delimiters.quotes = “”‘’ auxiliary = [\u200C\u200D ৲] exemplarCharacters = [\u09BC অ আ ই ঈ উ ঊ ঋ এ ঐ ও ঔ ং \u0981 ঃ ক খ গ ঘ ঙ চ ছ জ ঝ ঞ ট ঠ ড {ড\u09BC} ঢ {ঢ\u09BC} ণ ত থ দ ধ ন প ফ ব ভ ম য {য\u09BC} ৰ ল ৱ শ ষ স হ {ক\u09CDষ} া ি ী \u09C1 \u09C2 \u09C3 ে ৈ ো ৌ \u09CD] -punctuation = [\\- , ; \\: ! ? . ( ) \\[ \\] \\{ \\}] +punctuation = [\\- , ; \\: ! ? . । ( ) \\[ \\] \\{ \\}] [numbers] defaultNumberingSystem = beng @@ -168,4 +146,4 @@ percentSign = % plusSign = + superscriptingExponent = × -[counters] +[counters] \ No newline at end of file diff --git a/Master/texmf-dist/tex/generic/babel/locale/bn/babel-bn.ini b/Master/texmf-dist/tex/generic/babel/locale/bn/babel-bn.ini index 3d68f923827..9025457047f 100644 --- a/Master/texmf-dist/tex/generic/babel/locale/bn/babel-bn.ini +++ b/Master/texmf-dist/tex/generic/babel/locale/bn/babel-bn.ini @@ -11,8 +11,8 @@ [identification] charset = utf8 -version = 1.4 -date = 2020-03-22 +version = 1.5 +date = 2020-04-22 name.local = বাংলা name.english = Bangla name.babel = bengali @@ -148,3 +148,4 @@ plusSign = + superscriptingExponent = × [counters] +alphabetic = ক খ গ ঘ ঙ চ ছ জ ঝ ঞ ট ঠ ড ঢ ণ ত থ দ ধ ন প ফ ব ভ \ No newline at end of file diff --git a/Master/texmf-dist/tex/generic/babel/locale/fi/babel-fi.ini b/Master/texmf-dist/tex/generic/babel/locale/fi/babel-fi.ini index 5cec65ce8c3..71a8cd2f3a3 100644 --- a/Master/texmf-dist/tex/generic/babel/locale/fi/babel-fi.ini +++ b/Master/texmf-dist/tex/generic/babel/locale/fi/babel-fi.ini @@ -8,11 +8,12 @@ ; * Common Locale Data Repository (license Unicode): ; http://cldr.unicode.org/ ; http://unicode.org/copyright.html +; * Contributors: Teemu Likonen [identification] charset = utf8 -version = 1.1 -date = 2020-03-22 +version = 1.2 +date = 2020-04-08 name.local = suomi name.english = Finnish name.babel = finnish @@ -34,7 +35,7 @@ abstract = Tiivistelmä bib = Kirjallisuutta chapter = Luku appendix = Liite -contents = Sisältö +contents = Sisällys listfigure = Kuvat listtable = Taulukot index = Hakemisto @@ -57,7 +58,7 @@ abstract = Tiivistelm\"a bib = Kirjallisuutta chapter = Luku appendix = Liite -contents = Sis\"alt\"o +contents = Sis\"allys listfigure = Kuvat listtable = Taulukot index = Hakemisto diff --git a/Master/texmf-dist/tex/generic/babel/locale/hy/babel-hy.ini b/Master/texmf-dist/tex/generic/babel/locale/hy/babel-hy.ini index 935d452a205..5bedc981d83 100644 --- a/Master/texmf-dist/tex/generic/babel/locale/hy/babel-hy.ini +++ b/Master/texmf-dist/tex/generic/babel/locale/hy/babel-hy.ini @@ -13,8 +13,8 @@ [identification] charset = utf8 -version = 1.3 -date = 2020-03-22 +version = 1.4 +date = 2020-04-20 name.local = հայերեն name.english = Armenian name.babel = armenian @@ -171,12 +171,12 @@ plusSign = + superscriptingExponent = × [counters] -lower.1 = ա բ գ դ ե զ է ը թ -lower.2 = ժ ի լ խ ծ կ հ ձ ղ -lower.3 = ճ մ յ ն շ ո չ պ ջ -lower.4 = ռ ս վ տ ր ց ւ փ ք -upper.1 = Ա Բ Գ Դ Ե Զ Է Ը Թ -upper.2 = Ժ Ի Լ Խ Ծ Կ Հ Ձ Ղ -upper.3 = Ճ Մ Յ Ն Շ Ո Չ Պ Ջ -upper.4 = Ռ Ս Վ Տ Ր Ց Ւ Փ Ք +lower.letters.1 = ա բ գ դ ե զ է ը թ +lower.letters.2 = ժ ի լ խ ծ կ հ ձ ղ +lower.letters.3 = ճ մ յ ն շ ո չ պ ջ +lower.letters.4 = ռ ս վ տ ր ց ւ փ ք +upper.letters.1 = Ա Բ Գ Դ Ե Զ Է Ը Թ +upper.letters.2 = Ժ Ի Լ Խ Ծ Կ Հ Ձ Ղ +upper.letters.3 = Ճ Մ Յ Ն Շ Ո Չ Պ Ջ +upper.letters.4 = Ռ Ս Վ Տ Ր Ց Ւ Փ Ք diff --git a/Master/texmf-dist/tex/generic/babel/locale/lb/babel-lb.ini b/Master/texmf-dist/tex/generic/babel/locale/lb/babel-lb.ini index d2b7e343119..577f168f306 100644 --- a/Master/texmf-dist/tex/generic/babel/locale/lb/babel-lb.ini +++ b/Master/texmf-dist/tex/generic/babel/locale/lb/babel-lb.ini @@ -8,11 +8,12 @@ ; * Common Locale Data Repository (license Unicode): ; http://cldr.unicode.org/ ; http://unicode.org/copyright.html +; * Contributors: Sam Mersch. [identification] charset = utf8 -version = 1.1 -date = 2020-03-22 +version = 1.2 +date = 2020-04-20 name.local = Lëtzebuergesch name.english = Luxembourgish name.babel = luxembourgish @@ -27,50 +28,50 @@ encodings = T1 OT1 LY1 derivate = no [captions] -preface = -ref = -abstract = -bib = -chapter = -appendix = -contents = -listfigure = -listtable = -index = -figure = -table = -part = -encl = -cc = -headto = -page = -see = -also = -proof = -glossary = +preface = Virwuert +ref = Literatur +abstract = Resümee +bib = Bibliographie +chapter = Kapitel +appendix = Annex +contents = Contenue +listfigure = Lëscht vun de Biller +listtable = Lëscht vun den Tabellen +index = Index +figure = Bild +table = Tabell +part = Deel +encl = Annex(en) +cc = Distributeur +headto = Un +page = Säit +see = kuck +also = kuck och +proof = Beweis +glossary = Glossär [captions.licr] -preface = -ref = -abstract = -bib = -chapter = -appendix = -contents = -listfigure = -listtable = -index = -figure = -table = -part = -encl = -cc = -headto = -page = -see = -also = -proof = -glossary = +preface = Virwuert +ref = Literatur +abstract = Res\"umee +bib = Bibliographie +chapter = Kapitel +appendix = Annex +contents = Contenue +listfigure = L\"escht vun de Biller +listtable = L\"escht vun den Tabellen +index = Index +figure = Bild +table = Tabell +part = Deel +encl = Annex(en) +cc = Distributeur +headto = Un +page = Säit +see = kuck +also = kuck och +proof = Beweis +glossary = Glossär [date.gregorian] date.long = [d]. [MMMM] [y] @@ -106,13 +107,13 @@ days.wide.thu = Donneschdeg days.wide.fri = Freideg days.wide.sat = Samschdeg days.wide.sun = Sonndeg -days.abbreviated.mon = Méi. -days.abbreviated.tue = Dën. +days.abbreviated.mon = Méin. +days.abbreviated.tue = Dë. days.abbreviated.wed = Mët. -days.abbreviated.thu = Don. -days.abbreviated.fri = Fre. -days.abbreviated.sat = Sam. -days.abbreviated.sun = Son. +days.abbreviated.thu = Do. +days.abbreviated.fri = Fr. +days.abbreviated.sat = Sa. +days.abbreviated.sun = So. days.narrow.mon = M days.narrow.tue = D days.narrow.wed = M @@ -122,8 +123,8 @@ days.narrow.sat = S days.narrow.sun = S dayPeriods.abbreviated.am = moies dayPeriods.abbreviated.pm = nomëttes -dayPeriods.narrow.am = mo. -dayPeriods.narrow.pm = nomë. +dayPeriods.narrow.am = moies +dayPeriods.narrow.pm = nomëttes dayPeriods.wide.am = moies dayPeriods.wide.pm = nomëttes @@ -146,10 +147,10 @@ time.medium = [HH]:[mm]:[ss] time.short = [HH]:[mm] [typography] -frenchspacing = -hyphenrules = -lefthyphenmin = -righthyphenmin = +frenchspacing = yes +hyphenrules = ngerman +lefthyphenmin = 2 +righthyphenmin = 2 hyphenchar = prehyphenchar = posthyphenchar = diff --git a/Master/texmf-dist/tex/generic/babel/locale/mr/babel-mr.ini b/Master/texmf-dist/tex/generic/babel/locale/mr/babel-mr.ini index e5759fadc28..2456c009893 100644 --- a/Master/texmf-dist/tex/generic/babel/locale/mr/babel-mr.ini +++ b/Master/texmf-dist/tex/generic/babel/locale/mr/babel-mr.ini @@ -8,11 +8,12 @@ ; * Common Locale Data Repository (license Unicode): ; http://cldr.unicode.org/ ; http://unicode.org/copyright.html +; * With some suggestions by NiranjanTambe [identification] charset = utf8 -version = 1.4 -date = 2020-03-22 +version = 1.5 +date = 2020-04-23 name.local = मराठी name.english = Marathi name.babel = marathi @@ -42,13 +43,13 @@ figure = आक्रुती table = कोष्टक part = भाग encl = समाविष्ट -cc = सि.सि. +cc = प्रत headto = प्रति page = पान see = पहा also = हे सुध्दा पहा proof = कसोटी -glossary = स्पष्टीकरणकोश +glossary = संज्ञांची सूची [date.gregorian] date.long = [d] [MMMM], [y] @@ -148,3 +149,4 @@ plusSign = + superscriptingExponent = × [counters] +alphabetic = क ख ग घ ङ च छ ज झ ञ ट ठ ड ढ ण त थ द ध न प फ ब भ म य र ल व श ष स ह ळ diff --git a/Master/texmf-dist/tex/generic/babel/luababel.def b/Master/texmf-dist/tex/generic/babel/luababel.def index 1ee7214a546..1767810fa08 100644 --- a/Master/texmf-dist/tex/generic/babel/luababel.def +++ b/Master/texmf-dist/tex/generic/babel/luababel.def @@ -32,7 +32,7 @@ %% extension |.ins|) which are part of the distribution. %% -\ifx\AddBabelHook\@undefined +\ifx\AddBabelHook\@undefined % When plain.def, babel.sty starts \bbl@trace{Read language.dat} \ifx\bbl@readstream\@undefined \csname newread\endcsname\bbl@readstream @@ -120,27 +120,30 @@ \bbl@trace{Macros for reading patterns files} \def\bbl@get@enc#1:#2:#3\@@@{\def\bbl@hyph@enc{#2}} \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}% @@ -173,6 +176,25 @@ {\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 @@ -280,19 +302,6 @@ \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}} \@onlypreamble\babelpatterns \AtEndOfPackage{% \newcommand\babelpatterns[2][\@empty]{% @@ -522,36 +531,6 @@ \ifx\bbl@KVP@intrapenalty\@nil\else \expandafter\bbl@intrapenalty\bbl@KVP@intrapenalty\@@ \fi}} -\AddBabelHook{luatex}{loadkernel}{% - \begingroup - % Reset chars "80-"C0 to category "other", no case mapping: - \catcode`\@=11 \count@=128 - \loop\ifnum\count@<192 - \global\uccode\count@=0 \global\lccode\count@=0 - \global\catcode\count@=12 \global\sfcode\count@=1000 - \advance\count@ by 1 \repeat - % Other: - \def\O ##1 {% - \global\uccode"##1=0 \global\lccode"##1=0 - \global\catcode"##1=12 \global\sfcode"##1=1000 }% - % Letter: - \def\L ##1 ##2 ##3 {\global\catcode"##1=11 - \global\uccode"##1="##2 - \global\lccode"##1="##3 - % Uppercase letters have sfcode=999: - \ifnum"##1="##3 \else \global\sfcode"##1=999 \fi }% - % Letter without case mappings: - \def\l ##1 {\L ##1 ##1 ##1 }% - \l 00AA - \L 00B5 039C 00B5 - \l 00BA - \O 00D7 - \l 00DF - \O 00F7 - \L 00FF 0178 00FF - \endgroup - \input #1\relax} -\ifx\DisableBabelHook\@undefined\endinput\fi \AddBabelHook{babel-fontspec}{afterextras}{\bbl@switchfont} \AddBabelHook{babel-fontspec}{beforestart}{\bbl@ckeckstdfonts} \DisableBabelHook{babel-fontspec} @@ -1291,6 +1270,7 @@ end \babelsublr{% \LaTeX\kern.15em2\bbl@nextfake$_{\textstyle\varepsilon}$}}}} {} + \endinput %% %% End of file `luababel.def'. diff --git a/Master/texmf-dist/tex/generic/babel/nil.ldf b/Master/texmf-dist/tex/generic/babel/nil.ldf index 90a88f9eaea..bb6319588c7 100644 --- a/Master/texmf-dist/tex/generic/babel/nil.ldf +++ b/Master/texmf-dist/tex/generic/babel/nil.ldf @@ -32,7 +32,7 @@ %% extension |.ins|) which are part of the distribution. %% -\ProvidesLanguage{nil}[2020/03/22 3.42 Nil language] +\ProvidesLanguage{nil}[2020/04/28 3.43 Nil language] \LdfInit{nil}{datenil} \ifx\l@nil\@undefined \newlanguage\l@nil @@ -45,6 +45,7 @@ \let\captionsnil\@empty \let\datenil\@empty \ldf@finish{nil} + \endinput %% %% End of file `nil.ldf'. diff --git a/Master/texmf-dist/tex/generic/babel/plain.def b/Master/texmf-dist/tex/generic/babel/plain.def index cba847617b0..723c3cb41c6 100644 --- a/Master/texmf-dist/tex/generic/babel/plain.def +++ b/Master/texmf-dist/tex/generic/babel/plain.def @@ -32,329 +32,8 @@ %% extension |.ins|) which are part of the distribution. %% -\def\@empty{} -\def\loadlocalcfg#1{% - \openin0#1.cfg - \ifeof0 - \closein0 - \else - \closein0 - {\immediate\write16{*************************************}% - \immediate\write16{* Local config file #1.cfg used}% - \immediate\write16{*}% - } - \input #1.cfg\relax - \fi - \@endofldf} -\long\def\@firstofone#1{#1} -\long\def\@firstoftwo#1#2{#1} -\long\def\@secondoftwo#1#2{#2} -\def\@nnil{\@nil} -\def\@gobbletwo#1#2{} -\def\@ifstar#1{\@ifnextchar *{\@firstoftwo{#1}}} -\def\@star@or@long#1{% - \@ifstar - {\let\l@ngrel@x\relax#1}% - {\let\l@ngrel@x\long#1}} -\let\l@ngrel@x\relax -\def\@car#1#2\@nil{#1} -\def\@cdr#1#2\@nil{#2} -\let\@typeset@protect\relax -\let\protected@edef\edef -\long\def\@gobble#1{} -\edef\@backslashchar{\expandafter\@gobble\string\\} -\def\strip@prefix#1>{} -\def\g@addto@macro#1#2{{% - \toks@\expandafter{#1#2}% - \xdef#1{\the\toks@}}} -\def\@namedef#1{\expandafter\def\csname #1\endcsname} -\def\@nameuse#1{\csname #1\endcsname} -\def\@ifundefined#1{% - \expandafter\ifx\csname#1\endcsname\relax - \expandafter\@firstoftwo - \else - \expandafter\@secondoftwo - \fi} -\def\@expandtwoargs#1#2#3{% - \edef\reserved@a{\noexpand#1{#2}{#3}}\reserved@a} -\def\zap@space#1 #2{% - #1% - \ifx#2\@empty\else\expandafter\zap@space\fi - #2} -\ifx\@preamblecmds\@undefined - \def\@preamblecmds{} -\fi -\def\@onlypreamble#1{% - \expandafter\gdef\expandafter\@preamblecmds\expandafter{% - \@preamblecmds\do#1}} -\@onlypreamble\@onlypreamble -\def\begindocument{% - \@begindocumenthook - \global\let\@begindocumenthook\@undefined - \def\do##1{\global\let##1\@undefined}% - \@preamblecmds - \global\let\do\noexpand} -\ifx\@begindocumenthook\@undefined - \def\@begindocumenthook{} -\fi -\@onlypreamble\@begindocumenthook -\def\AtBeginDocument{\g@addto@macro\@begindocumenthook} -\def\AtEndOfPackage#1{\g@addto@macro\@endofldf{#1}} -\@onlypreamble\AtEndOfPackage -\def\@endofldf{} -\@onlypreamble\@endofldf -\let\bbl@afterlang\@empty -\chardef\bbl@opt@hyphenmap\z@ -\ifx\if@filesw\@undefined - \expandafter\let\csname if@filesw\expandafter\endcsname - \csname iffalse\endcsname -\fi -\def\newcommand{\@star@or@long\new@command} -\def\new@command#1{% - \@testopt{\@newcommand#1}0} -\def\@newcommand#1[#2]{% - \@ifnextchar [{\@xargdef#1[#2]}% - {\@argdef#1[#2]}} -\long\def\@argdef#1[#2]#3{% - \@yargdef#1\@ne{#2}{#3}} -\long\def\@xargdef#1[#2][#3]#4{% - \expandafter\def\expandafter#1\expandafter{% - \expandafter\@protected@testopt\expandafter #1% - \csname\string#1\expandafter\endcsname{#3}}% - \expandafter\@yargdef \csname\string#1\endcsname - \tw@{#2}{#4}} -\long\def\@yargdef#1#2#3{% - \@tempcnta#3\relax - \advance \@tempcnta \@ne - \let\@hash@\relax - \edef\reserved@a{\ifx#2\tw@ [\@hash@1]\fi}% - \@tempcntb #2% - \@whilenum\@tempcntb <\@tempcnta - \do{% - \edef\reserved@a{\reserved@a\@hash@\the\@tempcntb}% - \advance\@tempcntb \@ne}% - \let\@hash@##% - \l@ngrel@x\expandafter\def\expandafter#1\reserved@a} -\def\providecommand{\@star@or@long\provide@command} -\def\provide@command#1{% - \begingroup - \escapechar\m@ne\xdef\@gtempa{{\string#1}}% - \endgroup - \expandafter\@ifundefined\@gtempa - {\def\reserved@a{\new@command#1}}% - {\let\reserved@a\relax - \def\reserved@a{\new@command\reserved@a}}% - \reserved@a}% -\def\DeclareRobustCommand{\@star@or@long\declare@robustcommand} -\def\declare@robustcommand#1{% - \edef\reserved@a{\string#1}% - \def\reserved@b{#1}% - \edef\reserved@b{\expandafter\strip@prefix\meaning\reserved@b}% - \edef#1{% - \ifx\reserved@a\reserved@b - \noexpand\x@protect - \noexpand#1% - \fi - \noexpand\protect - \expandafter\noexpand\csname - \expandafter\@gobble\string#1 \endcsname - }% - \expandafter\new@command\csname - \expandafter\@gobble\string#1 \endcsname -} -\def\x@protect#1{% - \ifx\protect\@typeset@protect\else - \@x@protect#1% - \fi -} -\def\@x@protect#1\fi#2#3{% - \fi\protect#1% -} -\def\bbl@tempa{\csname newif\endcsname\ifin@} -\ifx\in@\@undefined - \def\in@#1#2{% - \def\in@@##1#1##2##3\in@@{% - \ifx\in@##2\in@false\else\in@true\fi}% - \in@@#2#1\in@\in@@} -\else - \let\bbl@tempa\@empty -\fi -\bbl@tempa -\def\@ifpackagewith#1#2#3#4{#3} -\def\@ifl@aded#1#2#3#4{} -\ifx\@tempcnta\@undefined - \csname newcount\endcsname\@tempcnta\relax -\fi -\ifx\@tempcntb\@undefined - \csname newcount\endcsname\@tempcntb\relax -\fi -\ifx\bye\@undefined - \advance\count10 by -2\relax -\fi -\ifx\@ifnextchar\@undefined - \def\@ifnextchar#1#2#3{% - \let\reserved@d=#1% - \def\reserved@a{#2}\def\reserved@b{#3}% - \futurelet\@let@token\@ifnch} - \def\@ifnch{% - \ifx\@let@token\@sptoken - \let\reserved@c\@xifnch - \else - \ifx\@let@token\reserved@d - \let\reserved@c\reserved@a - \else - \let\reserved@c\reserved@b - \fi - \fi - \reserved@c} - \def\:{\let\@sptoken= } \: % this makes \@sptoken a space token - \def\:{\@xifnch} \expandafter\def\: {\futurelet\@let@token\@ifnch} -\fi -\def\@testopt#1#2{% - \@ifnextchar[{#1}{#1[#2]}} -\def\@protected@testopt#1{% - \ifx\protect\@typeset@protect - \expandafter\@testopt - \else - \@x@protect#1% - \fi} -\long\def\@whilenum#1\do #2{\ifnum #1\relax #2\relax\@iwhilenum{#1\relax - #2\relax}\fi} -\long\def\@iwhilenum#1{\ifnum #1\expandafter\@iwhilenum - \else\expandafter\@gobble\fi{#1}} -\def\DeclareTextCommand{% - \@dec@text@cmd\providecommand -} -\def\ProvideTextCommand{% - \@dec@text@cmd\providecommand -} -\def\DeclareTextSymbol#1#2#3{% - \@dec@text@cmd\chardef#1{#2}#3\relax -} -\def\@dec@text@cmd#1#2#3{% - \expandafter\def\expandafter#2% - \expandafter{% - \csname#3-cmd\expandafter\endcsname - \expandafter#2% - \csname#3\string#2\endcsname - }% - \expandafter#1\csname#3\string#2\endcsname -} -\def\@current@cmd#1{% - \ifx\protect\@typeset@protect\else - \noexpand#1\expandafter\@gobble - \fi -} -\def\@changed@cmd#1#2{% - \ifx\protect\@typeset@protect - \expandafter\ifx\csname\cf@encoding\string#1\endcsname\relax - \expandafter\ifx\csname ?\string#1\endcsname\relax - \expandafter\def\csname ?\string#1\endcsname{% - \@changed@x@err{#1}% - }% - \fi - \global\expandafter\let - \csname\cf@encoding \string#1\expandafter\endcsname - \csname ?\string#1\endcsname - \fi - \csname\cf@encoding\string#1% - \expandafter\endcsname - \else - \noexpand#1% - \fi -} -\def\@changed@x@err#1{% - \errhelp{Your command will be ignored, type to proceed}% - \errmessage{Command \protect#1 undefined in encoding \cf@encoding}} -\def\DeclareTextCommandDefault#1{% - \DeclareTextCommand#1?% -} -\def\ProvideTextCommandDefault#1{% - \ProvideTextCommand#1?% -} -\expandafter\let\csname OT1-cmd\endcsname\@current@cmd -\expandafter\let\csname?-cmd\endcsname\@changed@cmd -\def\DeclareTextAccent#1#2#3{% - \DeclareTextCommand#1{#2}[1]{\accent#3 ##1} -} -\def\DeclareTextCompositeCommand#1#2#3#4{% - \expandafter\let\expandafter\reserved@a\csname#2\string#1\endcsname - \edef\reserved@b{\string##1}% - \edef\reserved@c{% - \expandafter\@strip@args\meaning\reserved@a:-\@strip@args}% - \ifx\reserved@b\reserved@c - \expandafter\expandafter\expandafter\ifx - \expandafter\@car\reserved@a\relax\relax\@nil - \@text@composite - \else - \edef\reserved@b##1{% - \def\expandafter\noexpand - \csname#2\string#1\endcsname####1{% - \noexpand\@text@composite - \expandafter\noexpand\csname#2\string#1\endcsname - ####1\noexpand\@empty\noexpand\@text@composite - {##1}% - }% - }% - \expandafter\reserved@b\expandafter{\reserved@a{##1}}% - \fi - \expandafter\def\csname\expandafter\string\csname - #2\endcsname\string#1-\string#3\endcsname{#4} - \else - \errhelp{Your command will be ignored, type to proceed}% - \errmessage{\string\DeclareTextCompositeCommand\space used on - inappropriate command \protect#1} - \fi -} -\def\@text@composite#1#2#3\@text@composite{% - \expandafter\@text@composite@x - \csname\string#1-\string#2\endcsname -} -\def\@text@composite@x#1#2{% - \ifx#1\relax - #2% - \else - #1% - \fi -} -\def\@strip@args#1:#2-#3\@strip@args{#2} -\def\DeclareTextComposite#1#2#3#4{% - \def\reserved@a{\DeclareTextCompositeCommand#1{#2}{#3}}% - \bgroup - \lccode`\@=#4% - \lowercase{% - \egroup - \reserved@a @% - }% -} -\def\UseTextSymbol#1#2{% - #2% -} -\def\UseTextAccent#1#2#3{% -} -\def\@use@text@encoding#1{% -} -\def\DeclareTextSymbolDefault#1#2{% - \DeclareTextCommandDefault#1{\UseTextSymbol{#2}#1}% -} -\def\DeclareTextAccentDefault#1#2{% - \DeclareTextCommandDefault#1{\UseTextAccent{#2}#1}% -} -\def\cf@encoding{OT1} -\DeclareTextAccent{\"}{OT1}{127} -\DeclareTextAccent{\'}{OT1}{19} -\DeclareTextAccent{\^}{OT1}{94} -\DeclareTextAccent{\`}{OT1}{18} -\DeclareTextAccent{\~}{OT1}{126} -\DeclareTextSymbol{\textquotedblleft}{OT1}{92} -\DeclareTextSymbol{\textquotedblright}{OT1}{`\"} -\DeclareTextSymbol{\textquoteleft}{OT1}{`\`} -\DeclareTextSymbol{\textquoteright}{OT1}{`\'} -\DeclareTextSymbol{\i}{OT1}{16} -\DeclareTextSymbol{\ss}{OT1}{25} -\ifx\scriptsize\@undefined - \let\scriptsize\sevenrm -\fi +\input babel.def + \endinput %% %% End of file `plain.def'. diff --git a/Master/texmf-dist/tex/generic/babel/switch.def b/Master/texmf-dist/tex/generic/babel/switch.def index 8bb59d6bf2b..7ff780ce5a1 100644 --- a/Master/texmf-dist/tex/generic/babel/switch.def +++ b/Master/texmf-dist/tex/generic/babel/switch.def @@ -32,452 +32,10 @@ %% extension |.ins|) which are part of the distribution. %% -\ifx\ProvidesFile\@undefined - \def\ProvidesFile#1[#2 #3 #4]{% - \wlog{File: #1 #4 #3 <#2>}% - \let\ProvidesFile\@undefined} -\fi -\ProvidesFile{switch.def}[2020/03/22 3.42 Babel switching mechanism] -\ifx\AtBeginDocument\@undefined - \input plain.def\relax -\fi -\ifx\language\@undefined - \csname newcount\endcsname\language -\fi -\ifx\newlanguage\@undefined - \csname newcount\endcsname\last@language - \def\addlanguage#1{% - \global\advance\last@language\@ne - \ifnum\last@language<\@cclvi - \else - \errmessage{No room for a new \string\language!}% - \fi - \global\chardef#1\last@language - \wlog{\string#1 = \string\language\the\last@language}} -\else - \countdef\last@language=19 - \def\addlanguage{\alloc@9\language\chardef\@cclvi} -\fi -\def\bbl@version{3.42} -\def\bbl@date{2020/03/22} -\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} -\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} -\def\iflanguage#1{% - \bbl@iflanguage{#1}{% - \ifnum\csname l@#1\endcsname=\language - \expandafter\@firstoftwo - \else - \expandafter\@secondoftwo - \fi}} -\let\bbl@select@type\z@ -\edef\selectlanguage{% - \noexpand\protect - \expandafter\noexpand\csname selectlanguage \endcsname} -\ifx\@undefined\protect\let\protect\relax\fi -\ifx\documentclass\@undefined - \def\xstring{\string\string\string} -\else - \let\xstring\string -\fi -\def\bbl@language@stack{} -\def\bbl@push@language{% - \xdef\bbl@language@stack{\languagename+\bbl@language@stack}} -\def\bbl@pop@lang#1+#2-#3{% - \edef\languagename{#1}\xdef#3{#2}} -\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} -\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@}} -\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}} -\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}} -\let\select@language@x\select@language -\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 \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- - % > 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} -\long\def\otherlanguage#1{% - \ifnum\bbl@hymapsel=\@cclv\let\bbl@hymapsel\thr@@\fi - \csname selectlanguage \endcsname{#1}% - \ignorespaces} -\long\def\endotherlanguage{% - \global\@ignoretrue\ignorespaces} -\expandafter\def\csname otherlanguage*\endcsname#1{% - \ifnum\bbl@hymapsel=\@cclv\chardef\bbl@hymapsel4\relax\fi - \foreign@language{#1}} -\expandafter\let\csname endotherlanguage*\endcsname\relax -\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} -\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}}} -\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}} -\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 -\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} -\ifx\ProvidesFile\@undefined - \def\ProvidesLanguage#1[#2 #3 #4]{% - \wlog{Language: #1 #4 #3 <#2>}% - } -\else - \def\ProvidesLanguage#1{% - \begingroup - \catcode`\ 10 % - \@makeother\/% - \@ifnextchar[%] - {\@provideslanguage{#1}}{\@provideslanguage{#1}[]}} - \def\@provideslanguage#1[#2]{% - \wlog{Language: #1 #2}% - \expandafter\xdef\csname ver@#1.ldf\endcsname{#2}% - \endgroup} -\fi -\def\LdfInit{% - \chardef\atcatcode=\catcode`\@ - \catcode`\@=11\relax - \input babel.def\relax - \catcode`\@=\atcatcode \let\atcatcode\relax - \LdfInit} -\ifx\originalTeX\@undefined\let\originalTeX\@empty\fi -\ifx\babel@beginsave\@undefined\let\babel@beginsave\relax\fi -\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 -\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 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 +\let\bbl@onlyswitch\@empty +\input babel.def +\let\bbl@onlyswitch\@undefined + \endinput %% %% End of file `switch.def'. diff --git a/Master/texmf-dist/tex/generic/babel/txtbabel.def b/Master/texmf-dist/tex/generic/babel/txtbabel.def index 9f7b0550311..bf6f6a3285c 100644 --- a/Master/texmf-dist/tex/generic/babel/txtbabel.def +++ b/Master/texmf-dist/tex/generic/babel/txtbabel.def @@ -150,6 +150,7 @@ \def\@roman#1{\babelsublr{\ensureascii{\bbl@asciiroman#1}}}% \let\bbl@asciiRoman=\@Roman \def\@Roman#1{\babelsublr{\ensureascii{\bbl@asciiRoman#1}}}}{} + \endinput %% %% End of file `txtbabel.def'. diff --git a/Master/texmf-dist/tex/generic/babel/xebabel.def b/Master/texmf-dist/tex/generic/babel/xebabel.def index e3c943e2c8c..1b0c1bb36d6 100644 --- a/Master/texmf-dist/tex/generic/babel/xebabel.def +++ b/Master/texmf-dist/tex/generic/babel/xebabel.def @@ -91,35 +91,6 @@ \expandafter\bbl@toglobal\csname selectfont \endcsname}% \fi}% \fi} -\AddBabelHook{xetex}{loadkernel}{% - \begingroup - % Reset chars "80-"C0 to category "other", no case mapping: - \catcode`\@=11 \count@=128 - \loop\ifnum\count@<192 - \global\uccode\count@=0 \global\lccode\count@=0 - \global\catcode\count@=12 \global\sfcode\count@=1000 - \advance\count@ by 1 \repeat - % Other: - \def\O ##1 {% - \global\uccode"##1=0 \global\lccode"##1=0 - \global\catcode"##1=12 \global\sfcode"##1=1000 }% - % Letter: - \def\L ##1 ##2 ##3 {\global\catcode"##1=11 - \global\uccode"##1="##2 - \global\lccode"##1="##3 - % Uppercase letters have sfcode=999: - \ifnum"##1="##3 \else \global\sfcode"##1=999 \fi }% - % Letter without case mappings: - \def\l ##1 {\L ##1 ##1 ##1 }% - \l 00AA - \L 00B5 039C 00B5 - \l 00BA - \O 00D7 - \l 00DF - \O 00F7 - \L 00FF 0178 00FF - \endgroup - \input #1\relax} \ifx\DisableBabelHook\@undefined\endinput\fi \AddBabelHook{babel-fontspec}{afterextras}{\bbl@switchfont} \AddBabelHook{babel-fontspec}{beforestart}{\bbl@ckeckstdfonts} @@ -307,6 +278,7 @@ \babel@save\bbl@langfeatures \edef\bbl@langfeatures{#2,}}} \input txtbabel.def + \endinput %% %% End of file `xebabel.def'. -- cgit v1.2.3