% \iffalse
% This document requires lualatex
%%
%% Copyright (C) 2012-2025 Javier Bezos and Johannes L. Braams.
%% Copyright (C) 1989-2012 Johannes L. Braams and
%% any individual authors listed elsewhere in this file.
%% All rights reserved.
%%
%%
%% This file is part of the Babel system.
%% --------------------------------------
%%
%% It may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%
http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2003/12/01 or later.
%%
%% This work has the LPPL maintenance status "maintained".
%%
%% The Current Maintainer of this work is Javier Bezos.
%%
%% The list of derived (unpacked) files belonging to the distribution
%% and covered by LPPL is defined by the unpacking scripts (with
%% extension |.ins|) which are part of the distribution.
%%
% \fi
%
% \CheckSum{5011}
%
% \iffalse
%<*filedriver>
\DocumentMetadata{
% testphase = {sec,toc,text},
lang = en-001,
}
\ProvidesFile{babel.dtx}%
[2025/08/03 v25.12
The multilingual framework for pdfLaTeX, LuaLaTeX and XeLaTeX]
\documentclass{ltxdoc}
\GetFileInfo{babel.dtx}
\usepackage{fontspec}
\setmainfont[
Scale=.88,
BoldFont = NotoSerif-Bold.ttf,
ItalicFont = NotoSerif-Italic.ttf,
BoldItalicFont = NotoSerif-BoldItalic.ttf]
{NotoSerif-Regular.ttf}
\setsansfont[
Scale=.88,
BoldFont = NotoSans-Bold.ttf,
ItalicFont = NotoSans-Italic.ttf,
BoldItalicFont = NotoSans-BoldItalic.ttf]
{NotoSans-Regular.ttf}
\setmonofont[Scale=.86, FakeStretch=.97]{DejaVu Sans Mono}
\raggedright
\setlength{\parindent}{.8em}
\frenchspacing
\addtolength{\oddsidemargin}{-2em}
\addtolength{\textwidth}{25.5pt}
\addtolength{\textheight}{3.5cm}
\addtolength{\topmargin}{-2cm}
\font\manual=logo10 % font used for the METAFONT logo, etc.
\newcommand*\MF{{\manual META}\-{\manual FONT}}
\newcommand*\babel{\textsf{babel}}
\newcommand*\Babel{\textsf{Babel}}
\newcommand*\xetex{\textsf{xetex}}
\newcommand*\pdftex{\textsf{pdftex}}
\newcommand*\luatex{\textsf{luatex}}
\newcommand\largetex{T\kern -.1517em\lower .45ex\hbox {E}\kern -.09emX}
\newcommand*\nb[1]{}
\newcommand*\m[1]{\mbox{{\fontspec{FreeSerif}〈}\normalfont\itshape#1\/}{\fontspec{FreeSerif}〉}}
\newcommand*\langlist{%
\meta{language}\texttt{,}\meta{language}\texttt{,}...}
\newcommand*\langvar{\m{language}}
\newcommand*\Lopt[1]{\textsf{#1}}
\newcommand*\Lenv[1]{\texttt{#1}}
\newcommand*\menv[1]{\char`\{#1\char`\}}
\newcommand*\Eenv[1]{%
\quad...\quad
\texttt{\color{thered}\string\end\menv{#1}}}
\newcommand*\file[1]{\texttt{#1}}
\newcommand*\cls[1]{\texttt{#1}}
\newcommand*\pkg[1]{\texttt{#1}}
\setlength{\leftmargini}{1.5em}
\usepackage{framed}
\usepackage{multicol}
\usepackage{color,colortbl}
\usepackage[linkcolor=blue,urlcolor=blue,colorlinks=true]{hyperref}
\hypersetup{%
pdfsubject={LaTeX Multilingual documents and localization for pdfTeX,
LuaTeX and XeTeX.},
pdfauthor={Javier Bezos, Johannes Braams},
pdftitle={Babel},
pdfkeywords={TeX, LaTeX, pdfTeX, LuaTeX, XeTeX, internationalization,
localization}}
\ExplSyntaxOn
\normalmarginpar
\newcommand\New[1]{%
\regex_extract_once:nnN{(\d\d?)\.(\d\d?)}{#1}\bbltempa
\seq_pop_right:NN\bbltempa\bbltempb
\seq_pop_right:NN\bbltempa\bbltempa
\leavevmode%\marginpar
{\scriptsize
% \enspace
\colorbox[rgb]{.92, .86, .73}%
{%New~
#1%
\quark_if_no_value:NTF\bbltempb{}%
{~
\ifnum\bbltempa>2 \ifnum\bbltempb>34
\href{
https://latex3.github.io/babel/news/%
whats-new-in-babel-\bbltempa.\bbltempb.html}%
{\scriptsize ※}%
\fi\fi
\ifnum\bbltempa>23
\href{
https://latex3.github.io/babel/news/%
whats-new-in-babel-\bbltempa.\bbltempb.html}%
{\scriptsize ※}%
\fi}}}\enspace\ignorespaces}
\ExplSyntaxOff
\definecolor{thered}{rgb}{0.65,0.04,0.07}
\definecolor{thegrey}{gray}{0.8}
\definecolor{thegreyed}{gray}{0.6}
\definecolor{shadecolor}{rgb}{1,1,0.97}
\definecolor{messages}{rgb}{.66,.13,.27}
\makeatletter
\def\@seccntformat#1{%
\llap{\makebox[1.7cm][l]{\csname the#1\endcsname.}}%
\hspace{-.7cm}}
\def\@begintheorem#1#2{%
\list{}{}%
\global\advance\@listdepth\m@ne
\item[{\sffamily\bfseries\color{messages}\hspace*{1.4em}%\hspace*{2.8em}%
\MakeUppercase{#1}}]}%
\makeatother
\newtheorem{warning}{Warning}
\newtheorem{note}{Note}
\newtheorem{example}{Example}
\newtheorem{troubleshooting}{Troubleshooting}
\let\bblxv\verbatim
\let\bblexv\endverbatim
\newcommand\setengine{\def\engine}
\let\engine\relax
\begingroup
\catcode`\<=13
\catcode`\>=13
\catcode`\|=13
\AtBeginDocument{%
\gdef|{\verb|\def<##1>{{\fontspec{FreeSerif}〈}{\rmfamily\itshape##1}{\fontspec{FreeSerif}〉}}}}
\endgroup
\def\verbatim{%
\fboxsep=.8em
\begin{snugshade*}%
\ifx\engine\relax\else
\vskip-.75\baselineskip
\leavevmode\llap{%
\fboxsep=2pt\fbox{\scriptsize\textsc{\engine}}\hskip2.8em}%
\vskip-1.6\baselineskip
\vskip0pt
\global\let\engine\relax
\fi
\bblxv\vskip0pt }
\def\endverbatim{%
\bblexv\vskip-7.5ex \end{snugshade*}}
\catcode`\_=\active
\def_{\bgroup\let_\egroup\leavevmode\color{thered}}
\def\MacroFont{\fontencoding \encodingdefault \fontfamily\ttdefault
\fontseries\mddefault \fontshape\updefault \small \catcode`\_=\active}
\definecolor{shadecolor}{rgb}{0.96,0.96,0.93}
%
\makeatletter
\def\Describe#1#2{%
\@startsection{subsubsection}{100}{\z@}%
{2.5ex\@plus .7ex \@minus .2ex}%
{1.5ex \@plus .2ex}%
{\hspace{-2cm}\color{thegreyed}\normalsize\ttfamily}*%
{\underline{\strut{\color{thered}\string#1}\color{black}#2}}}
\def\DescribeOther{\addvspace{-1.5ex}\Describe}
\AtBeginDocument{\def\DescribeMacro#1{{\ttfamily\color{thered}\string#1}}}
\def\macro#1{%
\if@noskipsec\leavevmode\vskip-1.2\baselineskip\vskip0pt\fi
\@startsection{paragraph}{101}{\z@}%
{3.25ex \@plus1ex \@minus.2ex}%
{-1em}%
{\sffamily\bfseries\color{thered}}*{\hspace*{-1em}\string#1}}
\let\environment\macro
\def\optstar{%
\kern1pt\relax
\colorbox{thegrey}{\ttfamily\hskip-.2em*\hskip-.2em}%
\kern1pt}
\def\trouble#1{\addcontentsline{tsh}{trouble}{#1}}
\def\toclevel@trouble{0}
\def\listoftroubles{\section*{Troubleshoooting}\@starttoc{tsh}}
\let\l@trouble\l@figure
\def\@tocrmarg{3.5em plus 1000em}
\let\saved@check@percent\check@percent
\let\check@percent\relax
% Changes to doc.sty (add <<...>> syntax)
\def\Module#1{%
\mod@math@codes$\langle${\color{thered}$\mathsf{#1}$}〉}
\begingroup
\catcode`\<\active
\catcode`\>\active
\gdef\check@plus@etc{%
\let\bbl@next\pm@module
\ifx*\next
\let\bbl@next\star@module
\else\ifx/\next
\let\bbl@next\slash@module
\else\ifx<\next
\let\bbl@next\var@module
\fi\fi\fi
\bbl@next}
\gdef\var@module#1#2#3>>{%
$\langle$\pm@module#2#3>$\rangle$%
\ifx*#2\ $\equiv$\fi}
\endgroup
\def\toc@usehook#1#2#3{%
\UseHookWithArguments{contentsline/#1}{4}%
{\toclevel@section}%
{#2}{#3}{\@contentsline@destination}}
\renewcommand*\l@section[2]{%
\ifnum\c@tocdepth>\z@
\addpenalty\@secpenalty
\addvspace{1.0em\@plus\p@}%
\setlength\@tempdima{2em}%
\begingroup
\parindent\z@ \rightskip\@pnumwidth
\parfillskip-\@pnumwidth
\leavevmode\bfseries
\advance\leftskip\@tempdima
\hskip-\leftskip
\toc@usehook{text/before}{#1}{#2}%
\csname contentsline@text@1@format\endcsname{#1}
\toc@usehook{text/after}{#1}{#2}%
\nobreak\hfil\nobreak \hb@xt@\@pnumwidth
{\hss
\toc@usehook{page/before}{#1}{#2}%
#2%
\toc@usehook{page/after}{#1}{#2}%
\kern-\p@\kern\p@}%
\par
\endgroup
\fi}
\renewcommand*\l@subsection{\@dottedtocline{2}{2em}{3em}}
\renewcommand*\l@subsubsection{\@dottedtocline{3}{5em}{4em}}
\renewcommand*\l@paragraph{\@dottedtocline{4}{9em}{4.5em}}
\renewcommand\partname{Part}
\def\@pnumwidth{3em}
\makeatother
\begin{document}
\title{Babel, a multilingual package for use with \LaTeX's standard
document classes.}
\author{Johannes Braams\\
Javier Bezos}
\date{Typeset \today}
\begin{titlepage}
\begin{minipage}[t][0pt]{30cm}
\vspace{-3cm}\hspace{-6cm}
\sffamily
\begin{tabular}{p{8cm}p{15cm}}
\cellcolor[rgb]{.86,.73,.67}
&\cellcolor[rgb]{.95,.95,.95}
\vspace{3.6cm}%
\color[rgb]{.55,.4,.35}
\leftskip5mm
\sffamily\fontsize{72}{72}\selectfont Babel
\vspace{1.8cm}
\\
\cellcolor[rgb]{.95,.95,.95}
\vspace{2cm}\hspace{1.5cm}
\begin{minipage}{5cm}
\Huge
\ifx\babelcode\undefined
User guide
\else
Code
\fi
\Large
\vspace{1.2cm}
Version \csname @gobble\expandafter\endcsname\fileversion\newline
\filedate
\LARGE
\vspace{1.2cm}
Javier Bezos\\[-.5ex]
{\large Current maintainer}
\vspace{.3cm}
Johannes L. Braams\\[-.5ex]
{\large Original author}
\end{minipage}
&\cellcolor[rgb]{.92, .86, .73}
\vspace{2cm}
\leftskip5mm
\begin{minipage}{10cm}
\fontsize{35}{45}\selectfont
\setlength\parskip{3mm}\raggedright
Localization and internationalization\\[1cm]
Unicode\\
\largetex\\
Lua\largetex\\
pdf\largetex\\
Xe\largetex
\vspace{20cm}
\end{minipage}
\end{tabular}
\end{minipage}
\end{titlepage}
\tableofcontents
\ifx\babelcode\undefined
\listoftroubles
\fi
\clearpage
\ifx\babelcode\undefined
\begin{description}
\item[\sffamily\color{messages}What is this document about?] This user
guide focuses on internationalization and localization with \LaTeX{}
and \luatex{}, \pdftex{} and \xetex{} with the \babel{} package. There
are also some notes on its use with e-Plain and pdf-Plain \TeX.
\item[\sffamily\color{messages}I only need learn the most basic
features.] The first subsections (1.1-1.6) describe the ways
of loading a language, which is usually all you need.
\item[\sffamily\color{messages}I don’t like manuals. I prefer sample
files.] This manual contains lots of examples and tips, but in GitHub
there are many
\href{
https://github.com/latex3/babel/tree/master/samples}{sample
files}.
\item[\sffamily\color{messages}What if I’m interested only in the
latest changes?] Changes and new features with relation to version 3.8
are highlighted with \New{X.XX}\hspace{-.5em}
({\scriptsize ※} is a link to the \babel{} site), and there
are some notes for the latest versions in
\href{
https://latex3.github.io/babel/}{the \babel{} site}. The most
recent features can still be unstable. Remember version 24.1 follows
3.99, because of a new numbering scheme.
\item[\sffamily\color{messages}Can I help?] Sure! You can follow the
development of \babel{} in
\href{
https://github.com/latex3/babel}{GitHub} and make suggestions,
including requirements for some language or script. Feel free to fork
it and make pull requests. If you are the author of a package, send
me a few test files which I'll add to mine, so that possible issues can
be caught in the development phase.
\item[\sffamily\color{messages}It doesn't work for me!] You can ask for
help in some forums like \textsf{tex.stackexchange}, but if you have
found a bug, I strongly beg you to report it in
\href{
https://github.com/latex3/babel/issues}{GitHub}, which is much
better than just complaining on an e-mail list or a web forum. Remember
\textit{warnings are not errors} by themselves, they just warn about
possible problems or incompatibilities. Hyphenation rules are
maintained separately
\href{
https://github.com/hyphenation/tex-hyphen}{here}.
\item[\sffamily\color{messages}How can I contribute a new
language?] See section \ref{contribute} for contributing a language.
\item[\sffamily\color{messages}Where is the code?]
Run |lualatex --jobname=babel-code \let\babelcode\relax\input{babel.dtx}|.
\end{description}
\begin{note}
Now that the recommend engine for \LaTeX\ is \luatex, you can read
\href{
https://latex3.github.io/babel/guides/migrating-pdftex-luatex.html}%
{Migrating from pdfTeX to LuaTeX} and
\href{
https://latex3.github.io/babel/guides/migrating-xetex-luatex.html}%
{Migrating from XeTeX to LuaTeX}.
\end{note}
\section{The basic user interface}\label{U-I}
There are two ways to load a language with babel, namely, the old good
‘classical’ one, based on mostly self-contained declarations in a file
with |ldf| extension, and the ‘modern’ one, based on a brand new
mechanism based on descriptive |ini| files.
‘Classical’ doesn’t mean outdated or obsolete. In fact, this is the
recommended method in most languages where an |ldf| file exists. Below
is a list of the supported languages. See also
\href{
https://latex3.github.io/%
babel/guides/which-method-for-which-language.html}{Which
method for which language} in the \babel{} site.
Basically, what you need is typically:
\begin{itemize}
\bfseries
\item Tell \babel{} which language or languages are required.
\item With non-Latin scripts and Unicode engines (\luatex\ is the
preferred one), select a suitable font (sec.~\ref{fonts})
\item In multilingual documents, switch the language in the text body
(sec.~\ref{selectors}).
\end{itemize}
You can find basic info and minimal \luatex{} example files for about
300 locales in the
\href{
https://latex3.github.io/babel/guides/index-locale.html}{GitHub
repository}. There are also some videos on \href{
https://www.youtube.com/playlist?list=PLVc2cHCI6zpJcaa1x-yK9iRjqtE3Ct2Ja}{Youtube}.
\subsection{Monolingual documents: the ‘classical’ way}
In most cases, a single language is required, and then all you need in
\LaTeX{} is to load the package using its standard mechanism for this
purpose, namely, passing that language as an optional argument. In
addition, you may want to set the font and input encodings.
Another approach is making the language a global option in order to let
other packages detect and use it. This is the standard way in \LaTeX{}
for an option – in this case a language – to be recognized by several
packages (in other words, \babel{} doesn’t set the languages, it just
recognizes the options passed to the class or the package).
Many languages are compatible with \textsf{luatex} and \textsf{xetex},
but a few only work with \pdftex. When these engines are used, the
Latin script is covered by default in current \LaTeX{} (provided the
document encoding is UTF-8). Other scripts require loading
\textsf{fontspec}, although \babel{} provides a higher level interface
(see |\babelfont| below).
\New{25.8} The PDF document language can also be set with
|\DocumentMetadata| before |\documentclass|. See the liked news page
for further info. For example, the following setting will pass
\texttt{british} as the main language to \babel:
\begin{verbatim}
\DocumentMetadata{_lang=en-GB_}
\documentclass{article}
\usepackage{babel}
\end{verbatim}
The basic tag lookup explained below is applied here, so that
\texttt{fr-Latn-FR} is valid and mapped to \texttt{fr}, which is in
turn mapped to \texttt{french}. This eases the localization of
automatically generated documents.
\begin{warning}
This is a \textbf{breaking change}, because until now with this
example the dummy language \texttt{nil} was loaded. Tags are not
validated, which means mistakes like |en-UK| or wrong tags like
|de-AUS| or |la-x-classical| might be accepted without complaining.
\end{warning}
\begin{example}
Here is a simple full example for “traditional” \TeX{} engines (see
below for \luatex{} and \xetex{}). The package |fontenc| does not
belong to \babel, but it is included in the example because typically
you will need it. It assumes UTF-8, the default encoding:
\setengine{pdftex}
\begin{verbatim}
\documentclass{article}
\usepackage[T1]{fontenc}
_\usepackage[french]{babel}_
\begin{document}
Plus ça change, plus c'est la même chose!
\end{document}
\end{verbatim}
Now consider something like:
\begin{verbatim}
_\documentclass[french]{article}_
\usepackage{babel}
\usepackage{varioref}
\end{verbatim}
With this setting, the package \texttt{varioref} will also see
the option |french| and will be able to use it.
\end{example}
\begin{example}
Now a simple monolingual document in Russian (text from the Wikipedia)
with \luatex{} or \xetex{}. Note neither \textsf{fontenc} nor
\textsf{inputenc} is necessary, and a so-called Unicode font must be
loaded (in this example with the help of |\babelfont|, described below).
\setengine{luatex/xetex}
\begin{verbatim}
_\documentclass[russian]{article}_
\usepackage{babel}
_\babelfont{rm}{DejaVu Serif}_
\begin{document}
Россия, находящаяся на пересечении множества культур, а также
с учётом многонационального характера её населения, — отличается
высокой степенью этнокультурного многообразия и способностью к
межкультурному диалогу.
\end{document}
\end{verbatim}
\end{example}
\begin{note}
Because of the way \babel{} has evolved, “language” can refer to
(1) a set of hyphenation patterns as preloaded into the format, (2) a
package option, (3) an |ldf| file, and (4) a name used in the
document to select a language. Please, read the documentation for
specific languages for further info.
\end{note}
\begin{note}
\Babel{} does not make any readjustments by default in font size,
vertical positioning or line height. This is on purpose
because the optimal solution depends on the document layout and the
font, and very likely the most appropriate one is a combination of
these settings.
\end{note}
\begin{note}
Although it has been customary to recommend placing |\title|,
|\author| and other elements printed by |\maketitle| after
|\begin{document}|, mainly because of shorthands, it is advisable to
keep them in the preamble. Currently there is no real need to use
shorthands in those macros.
\end{note}
\begin{note}
With \textsf{hyperref} you may want to set the PDF document language
with something like:
\begin{verbatim}
\usepackage[_pdflang=es-MX_]{hyperref}
\end{verbatim}
This is not currently done by \babel{} and you must set it by hand.
\end{note}
\begin{warning}
In the preamble, \textit{no} language has been selected, except
hyphenation patterns and the name assigned to |\localename| (and
|\languagename|) (in particular, shorthands, captions and date are not
activated). If you need to define boxes and the like in the preamble,
you might want to use some of the language selectors described below.
\end{warning}
\begin{troubleshooting}
\trouble{Package inputenc Error: Invalid UTF-8 byte ...}
\textit{Package inputenc Error: Invalid UTF-8 byte ...}
A common source of trouble is a wrong setting of the input encoding.
Make sure you set the encoding actually used by your editor, or
even better, make sure the encoding in your editor is set to UTF-8.
\end{troubleshooting}
\begin{troubleshooting}
Another typical error when using \babel{} is the following:
\trouble{Unknown language 'LANG'}
\begin{verbatim}
! Package babel Error: Unknown language 'LANG'. Either you have
(babel) misspelled its name, it has not been installed,
(babel) or you requested it in a previous run. Fix its name,
(babel) install it or just rerun the file, respectively. In
(babel) some cases, you may need to remove the aux file
\end{verbatim}
The most frequent reason is, by far, the latest (for example, you
included |spanish|, but you realized this language is not used after
all, and therefore you removed it from the option list). In most
cases, the error vanishes when the document is typeset again, but in
more severe ones you will need to remove the |aux| file.
\end{troubleshooting}
\begin{troubleshooting}
\textit{No hyphenation patterns were preloaded...}
The following warning is about hyphenation patterns, which are
not under the direct control of \babel:
\trouble{No hyphenation patterns were preloaded for (babel) the
language 'LANG' into the format}
\begin{verbatim}
Package babel Warning: No hyphenation patterns were preloaded for
(babel) the language `LANG' into the format.
(babel) Please, configure your TeX system to add them and
(babel) rebuild the format. Now I will use the patterns
(babel) preloaded for \language=0 instead on input line 57.
\end{verbatim}
The document will be typeset, but very likely the text will not be
correctly hyphenated. Some languages in some system may be raising
this warning wrongly (because they are not hyphenated) -- just ignore
it. See the manual of your distribution (Mac\TeX, Mik\TeX, \TeX Live,
etc.)\ for further info about how to configure it.
\end{troubleshooting}
\begin{troubleshooting}
\textit{You are loading directly a language style.}
Loading directly
|sty| files in \LaTeX{} (i.e., |\usepackage{<language>}|) was deprecated
many years ago and you will get the error: \trouble{You are loading
directly a language style}
\begin{verbatim}
! Package babel Error: You are loading directly a language style.
(babel) This syntax is deprecated and you must use
(babel) \usepackage[language]{babel}.
\end{verbatim}
\end{troubleshooting}
\begin{note}
You will see an ‘info’ in the log file stating some data is being
loaded from an |ini| file. It includes standardized names for
language and script used by |\babelfont|, and the BCP 47 tag, required in
some cases by |\Make<Xxxxx>case|.
\end{note}
\subsection{Monolingual documents: the ‘modern’ way}
When, for whatever reason, the ‘classical’ way with the |ldf| is not
suitable for the needs of a document or a document system, you have to
resort to a different mechanism, which is activated with the package
option |provide=*| (in monolingual documents).
\begin{example}
Although Georgian has its own \texttt{ldf} file, here is how to
declare this language in Unicode engines. Here, as in a previous
example, we resort to |\babelfont| to set the font for this language
(with the |Harfbuzz| renderer, just to show how to set it, because
here the |Node| renderer should be fine).
\setengine{luatex/xetex}
\begin{verbatim}
\documentclass{book}
\usepackage[_georgian, provide=*_]{babel}
_\babelfont{rm}[Renderer=Harfbuzz]{DejaVu Sans}_
\begin{document}
\tableofcontents
\chapter{სამზარეულო და სუფრის ტრადიციები}
ქართული ტრადიციული სამზარეულო ერთ-ერთი უმდიდრესია მთელ მსოფლიოში.
\end{document}
\end{verbatim}
And with a global option:
\begin{verbatim}
\documentclass[_georgian_]{book}
\usepackage[_provide=*_]{babel}
\babelfont{rm}[Renderer=Harfbuzz]{DejaVu Sans}
\end{verbatim}
\end{example}
\begin{note}
This option actually loads the language with |\babelprovide| and the
|import| option, described below. Instead of an asterisk, you may
provide a list of options for |\babelprovide| enclosed in braces
(|import| is included by default).
\end{note}
\begin{example}
For a text in Chinese, you can write in the preamble:
\setengine{luatex/xetex}
\begin{verbatim}
\usepackage[_chinese, provide=*_]{babel}
_\babelfont{rm}{FandolSong}_
\end{verbatim}
The skip between characters is 0 pt plus .1 pt, which can be modified
with an option (explained below) in |provide|. For example:
\setengine{luatex/xetex}
\begin{verbatim}
\usepackage[chinese, provide=_{ intraspace=0 .2 0 }_]{babel}
\end{verbatim}
\end{example}
\subsection{Mostly monolingual documents: lazy loading}
\label{mostlymono}
\New{3.39} Very often, multilingual documents consist of a main
language with small pieces of text in another languages (words, idioms,
short sentences). Typically, all you need is to set the line breaking
rules and, perhaps, the font. In such a case, there is no need to
clutter the preamble (particularly the class and package options)
because \babel{} does not require declaring these secondary languages
explicitly — the basic settings are loaded on the fly when the language
is first selected.
This is particularly useful in documents with many languages, and also
when there are short texts of this kind coming from an external source
whose contents are not known beforehand (for example, titles in a
bibliography). In this regard, it is worth remembering that
|\babelfont| does \textit{not} load any font until required, so that it
can be used just in case.
\New{3.84} With \pdftex, when a language is loaded on the fly
(internally it's loaded with |\babelprovide|) selectors now set the
font encoding based on the list provided when loading |fontenc|. Not
all scripts have an associated encoding, so this feature works only
with Latin, Cyrillic, Greek, Arabic, Hebrew, Cherokee, Armenian, and
Georgian, provided a suitable font is found.
\begin{example}
A trivial document with the default font in English and Spanish, and
FreeSerif in Russian is:
\setengine{luatex/xetex}
\begin{verbatim}
\documentclass[english]{article}
\usepackage{babel}
_\babelfont[russian]{rm}{FreeSerif}_
\begin{document}
English. _\foreignlanguage{russian}{Русский}_.
_\foreignlanguage{spanish}{Español}_.
\end{document}
\end{verbatim}
If you need the ‘modern’ way to load the main language set as global
option, just write:
\begin{verbatim}
\usepackage[provide=*]{babel}
\end{verbatim}
\end{example}
\begin{note}
Instead of its name, you may prefer to select the language with the
corresponding BCP 47 tag. This alternative, however, must be activated
explicitly, because a two- or three-letter word is a valid name for a
language (e.g., |lu| can be the locale name with tag |khb| or the tag
for |lubakatanga|). See section \ref{bcp47} for further details.
\end{note}
\subsection{Multilingual documents: the ‘classical’ way}
In multilingual documents, just use a list of the required languages
either as package or as class options. The last language is considered the
main one, activated by default. Sometimes, the main language changes
the document layout (e.g., |spanish| and |french|).
To switch the language there are two basic macros, described below in
detail: |\selectlanguage| is used for blocks of text, while
|\foreignlanguage| is for chunks of text inside paragraphs.
\begin{example}
In \LaTeX, the preamble of the document:
\begin{verbatim}
\documentclass{article}
\usepackage[dutch,english]{babel}
\end{verbatim}
would tell \LaTeX{} that the document would be written in two
languages, Dutch and English, and that English would be the first
language in use, and the main one.
\end{example}
\begin{example}
A full bilingual document with \pdftex{} follows. The main language is
|french|, which is activated when the document begins. It assumes UTF-8:
\setengine{pdftex}
\begin{verbatim}
\documentclass{article}
\usepackage[T1]{fontenc}
_\usepackage[english,french]{babel}_
\begin{document}
Plus ça change, plus c'est la même chose!
_\selectlanguage{english}_
And an English paragraph, with a short text in
_\foreignlanguage{french}{français}_.
\end{document}
\end{verbatim}
\end{example}
\begin{example}
With \luatex{} and \xetex, the following bilingual, single script
document in UTF-8 encoding just prints a couple of ‘captions’ and
|\today| in Danish and Vietnamese. No additional packages are
required, because the default font supports both languages.
\setengine{luatex/xetex}
\begin{verbatim}
\documentclass{article}
_\usepackage[vietnamese,danish]{babel}_
\begin{document}
Danish: \prefacename, \alsoname, \today.
\selectlanguage{vietnamese}
Vietnamese: \prefacename, \alsoname, \today.
\end{document}
\end{verbatim}
\end{example}
\begin{note}
Although strongly discouraged, languages can be set as global and as
package option at the same time, but in such a case you should set
explicitly the main language with the package option |main|,
described below:
\begin{verbatim}
\documentclass[_italian_]{book}
\usepackage[ngerman,_main=italian_]{babel}
\end{verbatim}
\end{note}
\begin{note}
Once a language is loaded, you can select it with the corresponding
BCP 47 tag. See section \ref{bcp47} for further details.
\end{note}
\begin{note}
Documents with several input encodings are not frequent, but
sometimes are useful. You can set different encodings for different
languages as the following example shows:
\begin{verbatim}
\addto\extrasfrench{\inputencoding{latin1}}
\addto\extrasrussian{\inputencoding{koi8-r}}
\end{verbatim}
\end{note}
\subsection{Multilingual documents: the ‘modern’ way}
If lazy loading is not enough for your purposes, you can still tell
which languages should be loaded as either class or package options.
You can combine the ‘classical’ and the ‘modern’ ways with three
options to set which method you want, which cover the most typical
cases:
\begin{itemize}
\item |provide=*| is the option explained above for monolingual
documents. If there are more languages, it applies only to the main
language, while the rest will be loaded in the ‘classical’ way.
\item |provide+=*| loads the main language in the ‘classical’ way,
and the rest in the ‘modern’ one.
\item |provide*=*| is the same for all languages, i.e., main and
secondary ones are loaded in the ‘modern’ way.
\end{itemize}
More complex combinations can be handled with |\babelprovide|,
explained below.
\begin{example}
Your document is written in Thai with large chunks in Dutch and German,
and you want the |ldf| files in the latter because, for example, you
need their shorthands. The font is Norasi, which covers the three
languages:
\setengine{luatex/xetex}
\begin{verbatim}
\usepackage[dutch,ngerman,thai,_provide=*_]{babel}
\babelfont{rm}{Norasi}
\end{verbatim}
This will load |dutch| and |ngerman| in the classical |ldf| mode, but
|thai| in the modern |ini| mode. Other options are:
\begin{verbatim}
\usepackage[dutch,ngerman,thai]{babel}
\end{verbatim}
which will use the classical mode for in languages (as decribed in the
previous section, but note |thai.ldf| is not supported in Unicode
engines), and:
\begin{verbatim}
\usepackage[dutch,german,thai,_provide*=*_]{babel}
\end{verbatim}
which will use the modern mode in all languages (note the correct name
here is |german|. (The option
|\usepackage||[dutch,ngerman,thai,provide+=*]||{babel}| doesn’t make
much sense in this case.)
\end{example}
\subsection{Languages supported by \babel{} in the ‘classical’ mode}
(To be updated.) In the following table most of the languages supported
by \babel{} with an |ldf| file are listed, together with the names of
the options which you can load \babel\ with for each language. Note this
list is open and the current options may be different. It does not
include |ini| files (see below).
Except in a few cases (e.g., |ngerman|, |serbianc|, |acadian|) names are
those of the Unicode CLDR (or based on them).
Most of them work out of the box, but some may require extra fonts,
encoding files, a preprocessor or even a complete framework (like
\textsf{CJK} or \textsf{luatexja}).
\begingroup
\bigskip\hrule\nobreak
\makeatletter
\newcommand\tag[3][?]{\par
\hspace{-2em}\textcolor{thered}{\texttt{#2}}#3\enspace
\ifx\relax#1\relax\else
\ifx?#1%
\href{
https://ctan.org/pkg/babel-#2}{\scriptsize ※}%
\else
\href{
https://ctan.org/pkg/#1}{\scriptsize ※}%
\fi
\fi}
\def\subtag#1#2{\par
\hspace{-1em}\texttt{#1}#2\enspace}
\def\subtagalt#1#2{\par
\hspace{-1em}\textcolor{thered}{\texttt{#1}}#2\enspace}
\def\tagmin#1#2{\par
\hspace{-2em}\textcolor[gray]{.4}{\texttt{#1}}#2\enspace}
\def\subtagmin#1#2{\par
\hspace{-1em}\textcolor[gray]{.4}{\texttt{#1}}#2\enspace}
\def\note#1{\par{\footnotesize#1\par}}
\small
\bigskip
\textit{This list is still under revision.}\\
Recommended names are set in \textcolor{thered}{red}.\\
Additional languages are set in \textcolor[gray]{.4}{gray}.\\
Discouraged and deprecated names are not included.\\
There are some notes in a few languages.\\
The reference mark ({\scriptsize ※}) is a link to CTAN.
\bigskip\hrule\nobreak
\begin{multicols}{2}
\leftskip2em\parindent0pt
\tag[babel-dutch]{afrikaans}{}
\tag{albanian}{}
\tag[arabi]{arabic}{}
\note{Requires \textsf{arabi}.}
\tag{azerbaijani}{}
\tag{basque}{}
\tag{belarusian}{}
\tag{bosnian}{}
\tag{breton}{}
\tag{bulgarian}{}
\tag{catalan}{}
\tag{croatian}{}
\tag{czech}{}
\tag{danish}{}
\tag{dutch}{}
\tag{english}{}
\subtagalt{american}{}
\subtag{USenglish}{}{}
\subtagalt{australian}{}
\subtagalt{british}{}
\subtag{UKenglish}{}
\subtagalt{canadian}{}
\subtagalt{newzealand}{}
\tag{esperanto}{}
\tag{estonian}{}
\tagmin{ethiop}{} %%%%%%
\tag[arabi]{farsi}{}
\note{Requires \textsf{arabi}.}
\tag{finnish}{}
\tag{french}{}
\subtagalt{acadian}{}
\tag[babel-friulan]{friulian}{}
\tag{galician}{}
\tag{georgian}{}
\note{Requires \textsf{geotex}.}
\tag{german}{}
\note{This block refers to the old ortography. For the modern one, use
the names in the block \textsf{ngerman}.}
\subtagalt{austrian}{}
\subtagalt{swissgerman}{}
\note{Swiss High German}
\tag{greek}{}
% \subtagalt{polutonicogreek}{}
\subtagmin{ibycus}{}
\subtagmin{bgreek}{}
\tag{hebrew}{}
\tag[devanagari]{hindi}{}
\note{Requires \textsf{velthuis}.}
\tag{hungarian}{}
\subtag{magyar}{}
\tag{icelandic}{}
\tag{indonesian}{}
\tag{interlingua}{}
\tag{irish}{}
\tag{italian}{}
\tag{japanese}{}
\tag{kurmanji}{}
\tag{latin}{}
\subtagalt{classicallatin}{}
\subtagalt{medievallatin}{}
\subtagalt{ecclesiasticallatin}{}
\tag{latvian}{}
\tag{lithuanian}{}
\tag[babel-sorbian]{lowersorbian}{}
\tag{macedonian}{}
\tag{malay}{}
\tag[mongolian-babel]{mongolian}{}
\tag[babel-german]{ngerman}{}
\note{This block refers to the new ortography.}
\subtagalt{naustrian}{}
\subtagalt{nswissgerman}{}
\note{Swiss High German}
\tag[babel-samin]{northernsami}{}
\tag[babel-norsk]{norwegian}{}
\subtag{norsk}{}
\tag[babel-norsk]{nynorsk}{}
\tag{occitan}{}
\tag{piedmontese}{}
\tagmin{pinyin}{}
\tag{polish}{}
\tag[babel-portuges]{portuguese}{}
\subtagalt{brazilian}{}
\tag{romanian}{}
\tag{romansh}{}
\tag{russian}{}
\tag[babel-scottish]{scottishgaelic}{}
\subtag{scottish}{}
\tag{serbianc}{}
\note{Cyrillic script}
\subtagalt{serbian}{}
\note{Latin script}
\tag{slovak}{}
% \tag[]{slovene}{}
\tag{slovenian}{} %%%%%% <- and ini
\tag{spanglish}{}
\tag{spanish}{}
\tag{swedish}{}
\tag{thai}{}
\subtagmin{thaicjk}{}
\tag{turkish}{}
\tag[turkmen]{turkmen}{}
\tag{ukrainian}{}
\tag[sorbian]{uppersorbian}{}
\tag{vietnamese}{}
\tag{welsh}{}
\end{multicols}
\endgroup
\hrule
\bigskip
\begin{example}
An example of a language requiring a preprocessor and a separate
package is \texttt{hindi}. If you have got the
\textsf{velthuis/devnag} package, create a file with
extension |.dn|:
\begin{verbatim}
\documentclass{article}
\usepackage[hindi]{babel}
\begin{document}
{\dn devaanaa.m priya.h}
\end{document}
\end{verbatim}
Then preprocess it with |devnag| \m{file}, which creates
\m{file}|.tex|; you can then typeset the latter with \LaTeX.
\end{example}
\subsection{Languages supported by \babel{} in the ‘modern’ mode}
Here is the list of the names currently supported with |ini| locale
files, with |\babelprovide| (or |provide=|). With these languages,
|\babelfont| loads (if not done before) the language and script names
(even if the language is defined as a package option with an
\textsf{ldf} file). These are also the names recognized by
|\babelprovide| with a valueless |import|, which will load the |ini|
file with the tag given in parenthesis.
Following the current common practice (for example, the Unicode CLDR),
all locales are organized in a flat structure. This eases their
identification and customization.
Many locale are quite usable, provided captions and dates are not
required (which is a very frequent case, particularly in ancient
languages). So, they are included in the default \babel{} distribution.
This can serve to encourage contributions, too. A warning will remember
they are ‘bare minimum locales’. They are set in
\textcolor[gray]{.4}{gray} in the following list.
\begingroup
\bigskip\hrule\nobreak
\makeatletter
\def\tag#1#2#3{\par
\hspace{-2em}\textcolor{thered}{\texttt{#1}}#2\enspace
\mbox{\footnotesize(#3)}\enspace
\href{
https://latex3.github.io/babel/guides/locale-#1.html}{\scriptsize ※}}
\def\subtag#1#2#3{\par
\hspace{-1em}\texttt{#1}#2\enspace
\mbox{\footnotesize(#3)}}
\def\subtagalt#1#2#3{\par
\hspace{-1em}\textcolor{thered}{\texttt{#1}}#2\enspace
\mbox{\footnotesize(#3)}}
\def\tagmin#1#2#3{\par
\hspace{-2em}\textcolor[gray]{.4}{\texttt{#1}}#2\enspace
\mbox{\footnotesize(#3)}\enspace
\href{
https://latex3.github.io/babel/guides/locale-#1.html}{\scriptsize ※}}
\def\subtagmin#1#2#3{\par
\hspace{-1em}\textcolor[gray]{.4}{\texttt{#1}}#2\enspace
\mbox{\footnotesize(#3)}}
\def\hascapu{\textsuperscript{u}}
\def\hascapl{\textsuperscript{l}}
\def\note#1{\par{\footnotesize#1\par}}
\small
\bigskip
Recommended names are set in \textcolor{thered}{red}.\\
In variants with the region or the script name (which are not
highlighted), prefer the full forms.\\
Bare minimum locales are set in \textcolor[gray]{.4}{gray}.\\
Discouraged and deprecated names are not included.\\
\hascapu{} means Unicode captions; \hascapl{} means LICR captions.\\
There are some notes in a few locales.\\
The reference mark ({\scriptsize ※}) is a link to the \babel{} site.
\bigskip\hrule\nobreak
\begin{multicols}{2}
\leftskip2em\parindent0pt
\tag{abkhazian}{}{ab}
\tag{afar}{}{aa}
\tag{afrikaans}{\hascapu\hascapl}{af}
\tag{aghem}{}{agq}
\tag{akan}{}{ak}
\tagmin{akkadian}{}{akk}
\tag{albanian}{\hascapu\hascapl}{sq}
\tagmin{algerianarabic}{}{arq}
\note{Darija or Lahja Djazairia, with tag \texttt{arq}, different
from Standard Arabic as spoken in Alger, with tag \texttt{ar-DZ}.}
\tag{amharic}{\hascapu\hascapl}{am}
\tagmin{ancientegyptian}{}{egy}
\tag{ancientgreek}{\hascapu\hascapl}{grc}\note{It’s a different
language from \texttt{greek}.}
\tagmin{ancienthebrew}{}{hbo}
\tag{arabic}{\hascapu}{ar}
\subtag{arabic-algeria}{\hascapu}{ar-DZ}
\subtag{arabic-dz}{\hascapu}{ar-DZ}
\subtag{arabic-egypt}{\hascapu}{ar-EG}
\subtag{arabic-eg}{\hascapu}{ar-EG}
\subtag{arabic-iraq}{\hascapu}{ar-IQ}
\subtag{arabic-iq}{\hascapu}{ar-IQ}
\subtag{arabic-jordan}{\hascapu}{ar-JO}
\subtag{arabic-jo}{\hascapu}{ar-JO}
\subtag{arabic-lebanon}{\hascapu}{ar-LB}
\subtag{arabic-lb}{\hascapu}{ar-LB}
\subtag{arabic-morocco}{\hascapu}{ar-MA}
\subtag{arabic-ma}{\hascapu}{ar-MA}
\subtag{arabic-palestinianterritories}{\hascapu}{ar-PS}
\subtag{arabic-ps}{\hascapu}{ar-PS}
\subtag{arabic-saudiarabia}{\hascapu}{ar-SA}
\subtag{arabic-sa}{\hascapu}{ar-SA}
\subtag{arabic-syria}{\hascapu}{ar-SY}
\subtag{arabic-sy}{\hascapu}{ar-SY}
\subtag{arabic-tunisia}{\hascapu}{ar-TN}
\subtag{arabic-tn}{\hascapu}{ar-TN}
\tagmin{aramaic}{}{arc}
\subtagmin{aramaic-nabataean}{}{arc-nbat}
\subtagmin{aramaic-nbat}{}{arc-nbat}
\subtagmin{aramaic-palmyrene}{}{arc-palm}
\subtagmin{aramaic-palm}{}{arc-palm}
\tag{armenian}{\hascapu\hascapl}{hy}
\tag{assamese}{\hascapu}{as}
\tag{asturian}{\hascapu\hascapl}{ast}
\tag{asu}{}{asa}
\tag{atsam}{}{cch}
\tagmin{avestan}{}{ae}
\tag{awadhi}{}{awa}
\tagmin{aymara}{}{ay}
\tag{azerbaijani}{\hascapu\hascapl}{az}
\subtag{azerbaijani-cyrillic}{}{az-Cyrl}
\subtag{azerbaijani-cyrl}{}{az-Cyrl}
\subtag{azerbaijani-latin}{}{az-Latn}
\subtag{azerbaijani-latn}{}{az-Latn}
\tag{bafia}{}{ksf}
\tagmin{balinese}{}{ban}
\tag{baluchi}{}{bal}
\tag{bambara}{}{bm}
\tag{bangla}{\hascapu}{bn}
\subtag{bengali}{\hascapu}{bn}
\tag{basaa}{}{bas}
\tagmin{bashkir}{}{ba}
\tag{basque}{\hascapu\hascapl}{eu}
\tagmin{bataktoba}{}{bbc}
\tagmin{bavarian}{}{bar}
\tag{belarusian}{\hascapu\hascapl}{be}
\tag{bemba}{}{bem}
\tag{bena}{}{bez}
\tag{betawi}{}{bew}
\tag{bhojpuri}{}{bho}
\tag{blin}{}{byn}
\tag{bodo}{}{brx}
\tag{bosnian}{\hascapu\hascapl}{bs}
\subtag{bosnian-cyrillic}{}{bs-Cyrl}
\subtag{bosnian-cyrl}{}{bs-Cyrl}
\subtag{bosnian-latin}{\hascapu\hascapl}{bs-Latn}
\subtag{bosnian-latn}{\hascapu\hascapl}{bs-Latn}
\tag{breton}{\hascapu\hascapl}{br}
\tag{bulgarian}{\hascapu\hascapl}{bg}
\tag{buriat}{\hascapu\hascapl}{bua}
\tag{burmese}{}{my}
\tag{cantonese}{}{yue}
\tagmin{carian}{}{xcr}
\tag{catalan}{\hascapu\hascapl}{ca}
\tag{cebuano}{}{ceb}
\tag{centralatlastamazight}{}{tzm}
\tag{centralkurdish}{\hascapu}{ckb}
\subtag{sorani}{\hascapu}{ckb}
\subtag{centralkurdish-latin}{\hascapu}{ckb-Latn}
\subtag{centralkurdish-latn}{\hascapu}{ckb-Latn}
\tag{chakma}{}{ccp}
\tag{chechen}{}{ce}
\tag{cherokee}{}{chr}
\tag{chiga}{}{cgg}
\tag{chinese}{\hascapu}{zh}
\subtag{chinese-simplified}{\hascapu}{zh-Hans}
\subtag{chinese-hans}{\hascapu}{zh-Hans}
\subtag{chinese-traditional}{\hascapu}{zh-Hant}
\subtag{chinese-hant}{\hascapu}{zh-Hant}
\subtag{chinese-simplified-hongkongsarchina}{}{zh-Hans-HK}
\subtag{chinese-hans-hk}{}{zh-Hans-HK}
\subtag{chinese-simplified-macausarchina}{}{zh-Hans-MO}
\subtag{chinese-hans-mo}{}{zh-Hans-MO}
\subtag{chinese-simplified-singapore}{}{zh-Hans-SG}
\subtag{chinese-hans-sg}{}{zh-Hans-SG}
\subtag{chinese-hant-hk}{}{zh-Hant-HK}
\subtag{chinese-traditional-hongkongsarchina}{}{zh-Hant-HK}
\subtag{chinese-hant-mo}{}{zh-Hant-MO}
\subtag{chinese-traditional-macausarchina}{}{zh-Hant-MO}
\tag{churchslavic}{\hascapu}{cu}
\subtag{churchslavic-cyrs}{\hascapu}{cu-Cyrs}
\subtag{churchslavic-glag}{}{cu-Glag}
\subtag{churchslavic-glagolitic}{}{cu-Glag}
\subtag{churchslavic-oldcyrillic}{\hascapu}{cu-Cyrs}
% \tag{churchslavonic}{\hascapu}{cu}
\tag{chuvash}{}{cv}
\tagmin{classicalmandaic}{}{myz}
% \tag{classiclatin}{\hascapu\hascapl}{la-x-classic}
\tag{colognian}{}{ksh}
\tag{coptic}{}{cop}
\tag{cornish}{}{kw}
\tag{corsican}{}{co}
\tag{croatian}{\hascapu\hascapl}{hr}
\tag{czech}{\hascapu\hascapl}{cs}
\tag{danish}{\hascapu\hascapl}{da}
\tagmin{divehi}{}{dv}
\tag{dogri}{}{doi}
\tag{duala}{}{dua}
\tag{dutch}{\hascapu\hascapl}{nl}
\tag{dzongkha}{}{dz}
% \tag{ecclesiasticlatin}{\hascapu\hascapl}{la-x-ecclesia}
\tagmin{egyptianarabic}{}{arz}\note{Masri or Colloquial Egyptian, with tag
\texttt{arz}, different from Standard Arabic as spoken in
Egypt, with tag \texttt{ar-EG}.}
\tag{embu}{}{ebu}
\tag{english}{\hascapu\hascapl}{en}
\subtagalt{american}{\hascapu\hascapl}{en-US}
\subtag{americanenglish}{\hascapu\hascapl}{en-US}
\subtag{usenglish}{\hascapu\hascapl}{en-US}
\subtagalt{australian}{\hascapu\hascapl}{en-AU}
\subtag{australianenglish}{\hascapu\hascapl}{en-AU}
\subtagalt{british}{\hascapu\hascapl}{en-GB}
\subtag{britishenglish}{\hascapu\hascapl}{en-GB}
\subtag{ukenglish}{\hascapu\hascapl}{en-GB}
\subtagalt{canadian}{\hascapu\hascapl}{en-CA}
\subtag{canadianenglish}{\hascapu\hascapl}{en-CA}
\subtag{english-australia}{\hascapu\hascapl}{en-AU}
\subtag{english-au}{\hascapu\hascapl}{en-AU}
\subtag{english-canada}{\hascapu\hascapl}{en-CA}
\subtag{english-ca}{\hascapu\hascapl}{en-CA}
\subtag{english-unitedkingdom}{\hascapu\hascapl}{en-GB}
\subtag{english-gb}{\hascapu\hascapl}{en-GB}
\subtag{english-newzealand}{\hascapu\hascapl}{en-NZ}
\subtag{newzealand}{\hascapu\hascapl}{en-NZ}
\subtag{english-unitedstates}{\hascapu\hascapl}{en-US}
\subtag{english-nz}{\hascapu\hascapl}{en-NZ}
\subtag{english-us}{\hascapu\hascapl}{en-US}
\tag{erzya}{}{myv}
\tag{esperanto}{\hascapu\hascapl}{eo}
\tag{estonian}{\hascapu\hascapl}{et}
\tagmin{etruscan}{}{ett}
\tag{ewe}{}{ee}
\tag{ewondo}{}{ewo}
\tag{faroese}{}{fo}
\tag{filipino}{}{fil}
\tag{finnish}{\hascapu\hascapl}{fi}
\tag{french}{\hascapu\hascapl}{fr}
\subtagalt{acadian}{\hascapu\hascapl}{fr-x-acadian}
\subtag{canadianfrench}{\hascapu\hascapl}{fr-CA}
\subtag{swissfrench}{\hascapu\hascapl}{fr-CH}
\subtag{french-belgium}{\hascapu\hascapl}{fr-BE}
\subtag{french-be}{\hascapu\hascapl}{fr-BE}
\subtag{french-canada}{\hascapu\hascapl}{fr-CA}
\subtag{french-ca}{\hascapu\hascapl}{fr-CA}
\subtag{french-luxembourg}{\hascapu\hascapl}{fr-LU}
\subtag{french-lu}{\hascapu\hascapl}{fr-LU}
\subtag{french-switzerland}{\hascapu\hascapl}{fr-CH}
\subtag{french-ch}{\hascapu\hascapl}{fr-CH}
\tag{friulian}{\hascapu\hascapl}{fur}
\tag{fulah}{}{ff}
\tag{ga}{}{gaa}
\tag{galician}{\hascapu\hascapl}{gl}
\tag{ganda}{}{lg}
\tag{geez}{}{gez}
\tag{georgian}{\hascapu}{ka}
\tag{german}{\hascapu\hascapl}{de}
\note{Note the \texttt{ldf} names differ. See note above.}
\subtag{german-traditional}{\hascapu\hascapl}{de-1901}
\subtagalt{austrian}{\hascapu\hascapl}{de-AT}
\subtag{german-austria}{\hascapu\hascapl}{de-AT}
\subtag{german-at}{\hascapu\hascapl}{de-AT}
\subtag{german-austria-traditional}{\hascapu\hascapl}{de-AT-1901}
\subtagalt{swisshighgerman}{\hascapu\hascapl}{de-CH}\note{\texttt{swissgerman},
with tag \texttt{gsw} is a different language.}
\subtag{german-switzerland}{\hascapu\hascapl}{de-CH}
\subtag{german-ch}{\hascapu\hascapl}{de-CH}
\subtag{german-switzerland-traditional}{\hascapu\hascapl}{de-CH-1901}
\tagmin{gothic}{}{got}
\tag{greek}{\hascapu\hascapl}{el}
\subtag{monotonicgreek}{\hascapu\hascapl}{el}
\subtagalt{polytonicgreek}{\hascapu\hascapl}{el-polyton}
\tag{guarani}{}{gn}
\tag{gujarati}{\hascapu}{gu}
\tag{gusii}{}{guz}
\tag{haryanvi}{}{bgc}
\tag{hausa}{\hascapu\hascapl}{ha}
\subtag{hausa-ghana}{}{ha-GH}
\subtag{hausa-gh}{}{ha-GH}
\subtag{hausa-niger}{}{ha-NE}
\subtag{hausa-ne}{}{ha-NE}
\tag{hawaiian}{}{haw}
\tag{hebrew}{\hascapu\hascapl}{he}
\tag{hindi}{\hascapu}{hi}
\tag{hmongnjua}{}{hnj}
\tag{hungarian}{\hascapu\hascapl}{hu}
\subtag{magyar}{\hascapu\hascapl}{hu}
\tag{icelandic}{\hascapu\hascapl}{is}
\tag{igbo}{}{ig}
\tag{inarisami}{}{smn}
\tag{indonesian}{\hascapu\hascapl}{id}
\tagmin{ingush}{}{inh}
\tag{interlingua}{\hascapu\hascapl}{ia}
\tag{interslavic}{\hascapu\hascapl}{isv}
\tag{inuktitut}{}{iu}
\tag{irish}{\hascapu\hascapl}{ga}
\tag{italian}{\hascapu\hascapl}{it}
\tag{japanese}{\hascapu}{ja}
\tag{javanese}{}{jv}
\tag{jju}{}{kaj}
\tag{jolafonyi}{}{dyo}
\tag{kabuverdianu}{}{kea}
\tag{kabyle}{}{kab}
\tag{kaingang}{}{kgp}
\tag{kako}{}{kkj}
\tag{kalaallisut}{}{kl}
\tag{kalenjin}{}{kln}
\tag{kamba}{}{kam}
\tag{kangri}{}{xnr}
\tag{kannada}{\hascapu}{kn}
\tag{kashmiri}{}{ks}
\tag{kazakh}{}{kk}
\tag{khmer}{\hascapu}{km}
\tag{kikuyu}{}{ki}
\tag{kinyarwanda}{}{rw}
\tagmin{komi}{}{kv}
\tag{konkani}{}{kok}
\tag{korean}{\hascapu}{ko}
\subtag{korean-han}{\hascapu}{ko-Hani}
\subtag{korean-hani}{\hascapu}{ko-Hani}
\tag{koyraborosenni}{}{ses}
\tag{koyrachiini}{}{khq}
\tag{kwasio}{}{nmg}
\tag{kyrgyz}{}{ky}
\tagmin{ladino}{}{lad}
\tag{lakota}{}{lkt}
\tag{langi}{}{lag}
\tag{lao}{\hascapu}{lo}
\tag{latin}{\hascapu\hascapl}{la}
\subtagalt{ecclesiasticallatin}{\hascapu\hascapl}{la-x-ecclesia}
\subtagalt{classicallatin}{\hascapu\hascapl}{la-x-classic}
\subtagalt{medievallatin}{\hascapu\hascapl}{la-x-medieval}
\tag{latvian}{\hascapu\hascapl}{lv}
\tagmin{lepcha}{}{lep}
\tag{ligurian}{}{lij}
\tagmin{limbu}{}{lif}
\subtagmin{limbu-limb}{}{lif-limb}
\subtagmin{limbu-limbu}{}{lif-limb}
\tagmin{lineara}{}{lab}
\tag{lingala}{}{ln}
\tag{lithuanian}{\hascapu\hascapl\hascapl\hascapl}{lt}
\tagmin{lombard}{}{lmo}
\tag{lowersorbian}{\hascapu\hascapl}{dsb}
\tag{lowgerman}{}{nds}
% \tag{lsorbian}{\hascapu\hascapl}{dsb}
\tagmin{lu}{}{khb}
\tagmin{lycian}{}{xlc}
\tagmin{lydian}{}{xld}
\tag{lubakatanga}{}{lu}
\tag{luo}{}{luo}
\tag{luxembourgish}{\hascapu\hascapl}{lb}
\tag{luyia}{}{luy}
\tag{macedonian}{\hascapu\hascapl}{mk}
\tag{machame}{}{jmc}
\tag{maithili}{}{mai}
\tagmin{makasar}{}{mak}
\subtagmin{makasar-bugi}{}{mak-Bugi}
\subtagmin{makasar-buginese}{}{mak-Bugi}
\tag{makhuwa}{}{vmw}
\tag{makhuwameetto}{}{mgh}
\tag{makonde}{}{kde}
\tag{malagasy}{}{mg}
\tag{malay}{\hascapu\hascapl}{ms}
\subtag{malay-brunei}{}{ms-BN}
\subtag{malay-bn}{}{ms-BN}
\subtag{malay-singapore}{}{ms-SG}
\subtag{malay-sg}{}{ms-SG}
\tag{malayalam}{\hascapu}{ml}
\tag{maltese}{}{mt}
\tag{manipuri}{}{mni}
\tag{manx}{}{gv}
\tag{maori}{}{mi}
\tag{marathi}{\hascapu}{mr}
\tag{masai}{}{mas}
\tag{mazanderani}{}{mzn}
\tag{meru}{}{mer}
\tag{meta}{}{mgo}
\tag{mongolian}{}{mn}
\tag{monotonicgreek}{\hascapu\hascapl}{el}
\tag{morisyen}{}{mfe}
\tag{mundang}{}{mua}
\tag{muscogee}{}{mus}
\tag{nama}{}{naq}
% \tag{naustrian}{\hascapu\hascapl}{de-AT}
\tagmin{navajo}{}{nv}
\tag{nepali}{}{ne}
\tagmin{newari}{}{new}
% \tag{ngerman}{\hascapu\hascapl}{de}
\tag{ngiemboon}{}{nnh}
\tag{ngomba}{}{jgo}
\tag{nheengatu}{}{yrl}
\tag{nigerianpidgin}{}{pcm}
\tag{nko}{}{nqo}
\tag{northernfrisian}{}{frr}
\tag{northernkurdish}{\hascapu\hascapl}{kmr}
\subtag{kurmanji}{\hascapu\hascapl}{kmr}
\subtag{northernkurdish-arab}{\hascapu}{kmr-Arab}
\subtag{northernkurdish-arabic}{\hascapu}{kmr-Arab}
\tag{northernluri}{}{lrc}
\tag{northernsami}{\hascapu\hascapl}{se}
\subtag{samin}{\hascapu\hascapl}{se}
\tag{northernsotho}{}{nso}
\tag{northndebele}{}{nd}
\tag{norwegian}{\hascapu\hascapl}{no}
\subtag{norsk}{\hascapu\hascapl}{no}
\note{In the CLDR, \texttt{norwegianbokmal} (nb) just inherites from
\texttt{norwegian}, so use the latter.}
% \tag{norwegianbokmal}{\hascapu\hascapl}{nb}
\tag{nuer}{}{nus}
\tag{nyanja}{}{ny}
\tag{nyankole}{}{nyn}
\tag{nynorsk}{\hascapu\hascapl}{nn}
\subtag{norwegiannynorsk}{\hascapu\hascapl}{nn}
\tag{occitan}{\hascapu\hascapl}{oc}
\tag{odia}{\hascapu}{or}
\note{Preferred to \texttt{oriya}.}
\tagmin{oldirish}{}{sga}
\tagmin{oldnorse}{}{non}
\tagmin{oldpersian}{}{peo}
\tagmin{olduighur}{}{oui}
% \tag{oriya}{\hascapu}{or}
\tag{oromo}{}{om}
\tag{osage}{}{osa}
\tag{ossetic}{}{os}
\tag{papiamento}{}{pap}
\tag{pashto}{}{ps}
\tag{persian}{\hascapu}{fa}
\subtag{farsi}{\hascapu}{fa}
\tagmin{phoenician}{}{phn}
\tag{piedmontese}{\hascapu\hascapl}{pms}
\tag{polish}{\hascapu\hascapl}{pl}
\tag{portuguese}{\hascapu\hascapl}{pt}
\subtagalt{brazilian}{\hascapu\hascapl}{pt-BR}
\subtag{brazilianportuguese}{\hascapu\hascapl}{pt-BR}
\subtag{portuguese-brazil}{\hascapu\hascapl}{pt-BR}
\subtag{portuguese-br}{\hascapu\hascapl}{pt-BR}
\subtag{europeanportuguese}{\hascapu\hascapl}{pt-PT}
\subtag{portuguese-portugal}{\hascapu\hascapl}{pt-PT}
\subtag{portuguese-pt}{\hascapu\hascapl}{pt-PT}
\tag{prussian}{}{prg}
\tag{punjabi}{\hascapu}{pa}
\subtag{punjabi-arabic}{}{pa-Arab}
\subtag{punjabi-arab}{}{pa-Arab}
\subtag{punjabi-gurmukhi}{\hascapu}{pa-Guru}
\subtag{punjabi-guru}{\hascapu}{pa-Guru}
\tag{quechua}{}{qu}
\tag{rajasthani}{}{raj}
\tag{romanian}{\hascapu\hascapl}{ro}
\subtagalt{moldavian}{\hascapu\hascapl}{ro-MD}
\subtag{romanian-moldova}{\hascapu\hascapl}{ro-MD}
\subtag{romanian-md}{\hascapu\hascapl}{ro-MD}
\tag{romansh}{\hascapu\hascapl}{rm}
\tag{rombo}{}{rof}
\tag{rundi}{}{rn}
\tag{russian}{\hascapu\hascapl}{ru}
\tag{rwa}{}{rwk}
\tagmin{sabaean}{}{xsa}
\tag{saho}{}{ssy}
\tag{sakha}{}{sah}
\tagmin{samaritan}{}{smp}
\tag{samburu}{}{saq}
\tag{sango}{}{sg}
\tag{sangu}{}{sbp}
\tag{sanskrit}{}{sa}
\subtag{sanskrit-bangla}{}{sa-Beng}
\subtag{sanskrit-beng}{}{sa-Beng}
% \subtag{sanskrit-bengali}{}{sa-Beng}
\subtag{sanskrit-devanagari}{}{sa-Deva}
\subtag{sanskrit-deva}{}{sa-Deva}
\subtag{sanskrit-gujarati}{}{sa-Gujr}
\subtag{sanskrit-gujr}{}{sa-Gujr}
\subtag{sanskrit-kannada}{}{sa-Knda}
\subtag{sanskrit-knda}{}{sa-Knda}
\subtag{sanskrit-malayalam}{}{sa-Mlym}
\subtag{sanskrit-mlym}{}{sa-Mlym}
\subtag{sanskrit-telugu}{}{sa-Telu}
\subtag{sanskrit-telu}{}{sa-Telu}
\tag{santali}{}{sat}
\tag{saraiki}{}{skr}
\tag{sardinian}{}{sc}
\tag{scottishgaelic}{\hascapu\hascapl}{gd}
\tag{sena}{}{seh}
\tag{serbian}{\hascapu\hascapl}{sr}
\note{Note the \texttt{ldf} names differ. See note above.}
\subtag{serbian-cyrillic}{\hascapu\hascapl}{sr-Cyrl}
\subtag{serbian-cyrl}{\hascapu\hascapl}{sr-Cyrl}
\subtag{serbian-cyrillic-bosniaherzegovina}{\hascapu\hascapl}{sr-Cyrl-BA}
\subtag{serbian-cyrl-ba}{\hascapu\hascapl}{sr-Cyrl-BA}
\subtag{serbian-cyrillic-kosovo}{\hascapu\hascapl}{sr-Cyrl-XK}
\subtag{serbian-cyrl-xk}{\hascapu\hascapl}{sr-Cyrl-XK}
\subtag{serbian-cyrillic-montenegro}{\hascapu\hascapl}{sr-Cyrl-ME}
\subtag{serbian-cyrl-me}{\hascapu\hascapl}{sr-Cyrl-ME}
\subtag{serbian-latin}{\hascapu\hascapl}{sr-Latn}
\subtag{serbian-latn}{\hascapu\hascapl}{sr-Latn}
\subtag{serbian-latin-bosniaherzegovina}{\hascapu\hascapl}{sr-Latn-BA}
\subtag{serbian-latn-ba}{\hascapu\hascapl}{sr-Latn-BA}
\subtag{serbian-latin-kosovo}{\hascapu\hascapl}{sr-Latn-XK}
\subtag{serbian-latn-xk}{\hascapu\hascapl}{sr-Latn-XK}
\subtag{serbian-latin-montenegro}{\hascapu\hascapl}{sr-Latn-ME}
\subtag{serbian-latn-me}{\hascapu\hascapl}{sr-Latn-ME}
\subtag{serbian-ijekavsk}{\hascapu\hascapl}{sr-ijekavsk}
\subtag{serbian-latn-ijekavsk}{\hascapu\hascapl}{sr-Latn-ijekavsk}
% \tag{serbianc}{\hascapu\hascapl}{sr}
\tag{shambala}{}{ksb}
\tag{shona}{}{sn}
\tag{sichuanyi}{}{ii}
\tag{sicilian}{}{scn}
\tag{silesian}{}{szl}
\tag{sindhi}{}{sd}
\subtag{sindhi-devanagari}{}{sd-deva}
\subtag{sindhi-deva}{}{sd-deva}
\subtag{sindhi-khojki}{}{sd-khoj}
\subtag{sindhi-khoj}{}{sd-khoj}
\subtag{sindhi-khudawadi}{}{sd-sind}
\subtag{sindhi-sind}{}{sd-sind}
\tag{sinhala}{\hascapu}{si}
\tagmin{sinteromani}{}{rmo}
\tag{slovak}{\hascapu\hascapl}{sk}
\tag{slovenian}{\hascapu\hascapl}{sl}
\subtag{slovene}{\hascapu\hascapl}{sl}
\tag{soga}{}{xog}
\tag{somali}{}{so}
\tagmin{southernaltai}{}{alt}
\tag{southernsotho}{}{st}
\tag{southndebele}{}{nr}
\tag{spanish}{\hascapu\hascapl}{es}
\subtagalt{mexican}{\hascapu\hascapl}{es-MX}
\subtag{mexicanspanish}{\hascapu\hascapl}{es-MX}
\subtag{spanish-mexico}{\hascapu\hascapl}{es-MX}
\subtag{spanish-mx}{\hascapu\hascapl}{es-MX}
\tag{standardmoroccantamazight}{}{zgh}
\tag{sundanese}{}{su}
\tag{swahili}{}{sw}
\tag{swati}{}{ss}
\tag{swedish}{\hascapu\hascapl}{sv}
\tag{swissgerman}{}{gsw}
\note{Different from \texttt{swisshighgerman} (de-CH), which is German as spoken
in Switzerland.}
\tag{syriac}{}{syr}
\tag{tachelhit}{}{shi}
\subtag{tachelhit-latin}{}{shi-Latn}
\subtag{tachelhit-latn}{}{shi-Latn}
\subtag{tachelhit-tifinagh}{}{shi-Tfng}
\subtag{tachelhit-tfng}{}{shi-Tfng}
\tagmin{tainua}{}{tdd}
\tag{taita}{}{dav}
\tag{tajik}{}{tg}
\tag{tamil}{\hascapu}{ta}
\tagmin{tangut}{}{txg}
\tag{taroko}{}{trv}
\tag{tasawaq}{}{twq}
\tag{tatar}{}{tt}
\tag{telugu}{\hascapu}{te}
\tag{teso}{}{teo}
\tag{thai}{\hascapu\hascapl}{th}
\tag{tibetan}{\hascapu}{bo}
\tag{tigre}{}{tig}
\tag{tigrinya}{}{ti}
\tag{tokpisin}{}{tpi}
\tag{tongan}{}{to}
\tag{tsonga}{}{ts}
\tag{tswana}{}{tn}
\tag{turkish}{\hascapu\hascapl}{tr}
\tag{turkmen}{\hascapu\hascapl}{tk}
\tag{tyap}{}{kcg}
\tagmin{ugaritic}{}{uga}
\tag{ukrainian}{\hascapu\hascapl}{uk}
\tag{uppersorbian}{\hascapu\hascapl}{hsb}
\tag{urdu}{\hascapu}{ur}
\tag{uyghur}{\hascapu}{ug}
\tag{uzbek}{}{uz}
\subtag{uzbek-arabic}{}{uz-Arab}
\subtag{uzbek-arab}{}{uz-Arab}
\subtag{uzbek-cyrillic}{}{uz-Cyrl}
\subtag{uzbek-cyrl}{}{uz-Cyrl}
\subtag{uzbek-latin}{}{uz-Latn}
\subtag{uzbek-latn}{}{uz-Latn}
\tag{vai}{}{vai}
\subtag{vai-latin}{}{vai-Latn}
\subtag{vai-latn}{}{vai-Latn}
\subtag{vai-vai}{}{vai-Vaii}
\subtag{vai-vaii}{}{vai-Vaii}
\tag{venda}{}{ve}
\tag{venetian}{}{vec}
\tag{vietnamese}{\hascapu\hascapl}{vi}
\tag{volapuk}{}{vo}
\tag{vunjo}{}{vun}
\tag{walser}{}{wae}
\tagmin{waray}{}{war}
\tag{welsh}{\hascapu\hascapl}{cy}
\tag{westernfrisian}{}{fy}
\tag{wolaytta}{}{wal}
\tag{wolof}{}{wo}
\tag{xhosa}{}{xh}
\tag{yangben}{}{yav}
\tag{yiddish}{}{yi}
\tag{yoruba}{}{yo}
\tag{zarma}{}{dje}
\tag{zhuang}{}{za}
\tag{zulu}{}{zu}
\end{multicols}
\endgroup
\hrule
\bigskip
\subsection{Fonts in Unicode engines}
\label{fonts}
\begin{note}
For \textsf{pdflatex} and the standard \textsf{fontenc} mechanism,
refer to the \LaTeX{} manuals or \textit{The \LaTeX{} Companion},
vol.~I, ch.~9, and vol.~II, ch.~10.
\end{note}
\New{3.15} \Babel{} has native support for Unicode fonts (OpenType and
TrueType) in \luatex{} and \xetex{} by means of a high level interface
on top of |fontspec|. This makes it easier to handle a wide range of
languages and scripts, and simplifies the process of typesetting
multilingual documents. As described below, with \luatex{} the font can
be switched automatically based on the script without explicit markup.
There is no need to load \textsf{fontspec} explicitly – \babel{} does
it for you with the first |\babelfont|. (See also the package
\textsf{combofont} for a complementary approach.)
\Describe\babelfont{\oarg{language-list}\marg{font-family}%
\oarg{font-options}\marg{font-name}}
The main purpose of |\babelfont| is to define at once the fonts
required by the different languages, with their corresponding language
systems (script and language). So, if you load, say, 4 languages,
|\babelfont{rm}{FreeSerif}| defines 4 fonts (with their variants, of
course), which are switched with the language by \babel. It is a tool
to make things easier and transparent to the user.
Here \textit{font-family} is |rm|, |sf| or |tt| (or newly defined
ones, as explained below), and \textit{font-name} is the same as in
\textsf{fontspec} and the like.
If no language is given, then it is considered the default font for the
family. On the other hand, if there is one or more languages in the
optional argument, the font will be assigned to all of them, overriding
the default one. Alternatively, you may set a font for a script -- just
precede its name (lowercase) with a star (e.g., |*devanagari|).
With the optional argument, the font is \textit{not} yet loaded, but
just predeclared. In other words, font loading is lazy, which means you
may define as many fonts as you want ‘just in case’, because if the
language is never selected, the corresponding |\babelfont| declaration
is just ignored.
\Babel{} takes care of the font language and the font script when
languages are selected (as well as the writing direction). In other
words, there is usually no need to set the |Language| and the |Script|
explicitly; in fact, it’s even discouraged. In most cases, you will not
need \textit{font-options}, which is the same as in \textsf{fontspec},
but you may add further key/value pairs if necessary.
|\babelfont| can be used to implicitly define a new font family. Just
write its name instead of |rm|, |sf| or |tt|. This is the preferred way
to select fonts in addition to the three basic families.
\New{24.14} With \luatex, \Babel\ selects the renderer in the following
way:
\begin{itemize}
\item The default renderer in alphabetic scripts, so that the tools
provided by \textsf{luaotfload} for ligatures, kerning and the like,
which are essential typographical features in these scripts, are
directly available: Armenian, Coptic, Cyrillic, Georgian, Glagolitic,
Gothic, Greek, Latin, Old Church Slavonic Cyrillic.
\item Harfbuzz in the rest of scripts, particularly complex scripts with
heavy contextual analysis (like Arabic and Devanagari).
\end{itemize}
You can still select a different renderer with the \textsf{fontspec}
key |Renderer|. Note also the same font can be loaded with different
renderers. See
\href{
https://github.com/latex3/luaotfload/wiki/Comparing-the-modes}{Comparing
the modes} for further info.
\begin{note}
There is a list of fonts in
\href{
https://latex3.github.io/babel/guides/which-method-for-which-language.html}{Which
method for which language}. If you know the codepoint of a character
in the script you need, you can find fonts containing it with
\textsf{albatross} (requires Java) or with something like
\texttt{fc-list :charset=1033C family} in the commands line (in this
case, a Gothic character, the script required by the |gothic|
language).
\end{note}
\begin{note}
As \babel{} sets the font language system, the following setup is
redundant, so avoid it and use only the first line:
\begin{verbatim}
\babelfont{rm}{DejaVu Serif}
\babelfont[armenian]{rm}[Script=Armenian, Language=Armenian]{DejaVu Serif}
\end{verbatim}
\end{note}
\begin{example}
Usage in most cases is very simple. Let us assume you are setting up
a document in Swedish, with some words in Hebrew, with a font suited
for both languages. Here the option |bidi=default| activates a simple
(or, rather, simplistic) bidirectional mode.
\begingroup
% If you are looking at the code to see how it has been written, you
% will be disappointed :-). The following example is built ad hoc to
% emulate the final result to avoid dependencies, and therefore it's
% not "real" code.
\catcode`@=13
\def@#1{\ifcase#1\relax \egroup \or \bgroup\textdir TLT \else
\bgroup\textdir TRT \fontspec[Scale=.87,Script=Hebrew]{Liberation
Mono} \fi}
\setengine{luatex/xetex}
\begin{verbatim}
\documentclass{article}
\usepackage[swedish, bidi=default]{babel}
\babelprovide[import]{hebrew}
_\babelfont{rm}{FreeSerif}_
\begin{document}
Svenska \foreignlanguage{hebrew}{@2עִבְרִית@0} svenska.
\end{document}
\end{verbatim}
\endgroup
If on the other hand you have to resort to different fonts, you can
replace the red line above with, say:
\setengine{luatex/xetex}
\begin{verbatim}
\babelfont{rm}{Iwona}
\babelfont[hebrew]{rm}{FreeSerif}
\end{verbatim}
\end{example}
\begin{example}
Thanks to this high level interface to |fontspec|, the roman fonts for
all secondary languages in the Cyrillic and Greek scripts can be set
at once with the following single line:
\setengine{luatex/xetex}
\begin{verbatim}
\babelfont[_*cyrillic, *greek_]{rm}{NewComputerModern10}
\end{verbatim}
And if you need, say, Arabic and Devanagari:
\begin{verbatim}
\babelfont[_*arabic, *devanagari_]{rm}{FreeSerif}
\end{verbatim}
\Babel{} does the rest for you, including setting the font script
\textit{and} language.
\end{example}
\begin{example}
Since each locale is a separate ‘language’, they can be assigned
different fonts. In this example, we set Simplified and Tradicional
Chinese:
\begin{verbatim}
\babelfont[chinese-_simplified_]{rm}{Noto Serif CJK _SC_}
\babelfont[chinese-_simplified_]{sf}{Noto Sans CJK _SC_}
\babelfont[chinese-_traditional_]{rm}{Noto Serif CJK _TC_}
\babelfont[chinese-_traditional_]{sf}{Noto Sans CJK _TC_}
\end{verbatim}
\end{example}
\begin{example}
Here is how to declare a new family:
\setengine{luatex/xetex}
\begin{verbatim}
\babelfont{_kai_}{FandolKai}
\end{verbatim}
Now, |\kaifamily| and |\kaidefault|, as well as |\textkai| are at
your disposal.
\end{example}
\begin{note}
You may load \textsf{fontspec} explicitly. For example:
\setengine{luatex/xetex}
\begin{verbatim}
\usepackage{fontspec}
\newfontscript{Devanagari}{deva}
\babelfont[hindi]{rm}{Shobhika}
\end{verbatim}
This makes sure the OpenType script for Devanagari is |deva| and not
|dev2|, in case you need it.
\end{note}
\begin{note}
|\fontspec| is not touched at all, only the preset font families
(|rm|, |sf|, |tt|, and the like). If a language is switched when an
\textit{ad hoc} font is active, or you select the font with this
command, neither the script nor the language is passed. You must
add them by hand. This is by design, for several reasons —for
example, each font has its own set of features and a generic setting
for several of them can be problematic, and also preserving a
“lower-level” font selection is useful.
\end{note}
\begin{note}
Directionality is a property affecting margins, indentation, column
order, etc., not just text. Therefore, it is under the direct control
of the language, which applies both the script and the direction to
the text. As a consequence, there is no need to set \texttt{Script}
when declaring a font with |\babelfont| (nor \texttt{Language}). In
fact, it is even discouraged.
\end{note}
\begin{note}
The keys |Language| and |Script| just pass these values to the
\textit{font}, and do \textit{not} set the script for the
\textit{language} (and therefore the writing direction). In other
words, the |ini| file or |\babelprovide| provides default values for
|\babelfont| if omitted, but the opposite is not true. See the note
above for the reasons of this behavior.
\end{note}
\begin{note}
|\babelfont| is a high level interface to \textsf{fontspec}, and
therefore in \xetex{} you can apply |Mapping|s. For example, there is
a set of
\href{
https://github.com/davidmjones/brahmic-maps}{transliterations
for Brahmic scripts} by David M. Jones. After installing
them in you distribution, just set the map as you would do with
\textsf{fontspec}.
\end{note}
\begin{warning}
Using |\set|\textit{xxxx}|font| and |\babelfont| at the same time is
discouraged, but very often works as expected. However, be aware with
|\set|\textit{xxxx}|font| the language system will not be set by
\babel{} and should be set with |fontspec| if necessary.
\end{warning}
\begin{troubleshooting}
\trouble{Package fontspec Info: Language '<lang>' not explicitly
supported within font '<font>' with script '<script>'.}
\textit{Package fontspec Info: Language '<lang>' not explicitly
supported within font '<font>' with script '<script>'.}.
\textbf{This is \textit{not} and error.} This info is shown by
\textsf{fontspec}, not by \babel. If everything is okay in your
document (and almost always it is), the best thing you can do is just
to ignore it altogether.
In some forums you can find the advice to set, more or less
mechanically, |Language=Default|. \textit{Do not follow it}, because
font features for the language will not be applied, which can be
relevant for many languages, like Urdu and Turkish. Set the
|Language| explicitly only if there is a reason to do it. If you
really want to conceal this message, use instead:
\begin{verbatim}
\PassOptionsToPackage{silent}{fontspec}
\end{verbatim}
\end{troubleshooting}
\begin{troubleshooting}
\trouble{Package babel Info: The following fonts are not babel
standard families} \textit{Package babel Info: The following fonts
are not babel standard families}.
\textbf{This is \textit{not} an error.} \babel{} assumes that if you
are using |\babelfont| for a family, very likely you want to define
the rest of them. If you don't, you can find some inconsistencies
between families. This checking is done at the beginning of the
document, at a point where we cannot know which families will be
used.
Actually, there is no real need to use |\babelfont| in a monolingual
document, if you set the language system in |\setmainfont| (or not,
depending on what you want).
As the message explains, \textit{there is nothing intrinsically
wrong} with not defining all the families. In fact, there is nothing
intrinsically wrong with not using |\babelfont| at all. But you must
be aware that this may lead to some problems.
\end{troubleshooting}
\subsection{Basic language selectors}
\label{selectors}
This section describes the commands to be used in the document to
switch the language in multilingual documents. In most cases, only the
two basic macros |\selectlanguage| and |\foreignlanguage| are
necessary. The environments |otherlanguage|, |otherlanguage*| are
auxiliary, and described in the next section.
The main language is selected automatically when the |document|
environment begins.
\Describe{\selectlanguage}{\marg{language}}
\DescribeOther{\begin\menv{selectlanguage}}%
{\marg{language}\Eenv{selectlanguage}}
When a user wants to switch from one language to another he can do so
using the macro |\selectlanguage|. It is meant for blocks of texts, and
therefore should be used mainly in vertical mode, although it also
works in horizontal mode.
\begin{verbatim}
\selectlanguage{german}
\end{verbatim}
This command can be used as environment, too, in case there are
relatively short texts and you do not want to reset the language with a
hardcode value.
\begin{note}
Bear in mind |\selectlanguage| can be automatically executed, in some
cases, in the auxiliary files, at heads and foots, and after the
environment |otherlanguage*|.
\end{note}
\begin{warning}
If used inside braces or a group there might be some non-local
changes, as it would be roughly equivalent to:
\begin{verbatim}
\bgroup
\selectlanguage{<inner-language>}
..
\egroup
\selectlanguage{<outer-language>}
\end{verbatim}
If you want a change which is really local, you must enclose this
code with an additional grouping level. The same applies to the
environment version.
\end{warning}
\begin{warning}
There are a couple of issues related to the way the language
information is written to the auxiliary files:
\begin{itemize}
\item |\selectlanguage| should not be used inside some boxed environments
(like floats or |minipage|) to switch the language if you need the
information written to the |aux| be correctly synchronized. This
rarely happens, but if it were the case, you must use the
environment version or |otherlanguage| instead.
\item In addition, this macro inserts a |\write| in vertical mode,
which may break the vertical spacing in some cases (for example,
between lists or at the beginning of a table cell). \New{3.64} The
behavior can be adjusted with
|\babeladjust{select.write=<mode>}|, where \m{mode} is:
\begin{itemize}
\item |keep|, the default – with it the |\write| and the skips are
kept in the order they are written);
\item |shift|, which shifts the skips down and adds a |\penalty|;
\item |omit|, which may seem a too drastic solution, because
nothing is written, but more often than not this command is applied
to more or less shorts texts with no sectioning or similar
commands, and therefore no language synchronization is necessary.
In a table cell, a |\leavevmode| just before the selector may be
enough.
\end{itemize}
\end{itemize}
\end{warning}
\Describe{\foreignlanguage}{\oarg{option-list}\marg{language}\marg{text}}
It takes two mandatory arguments; the second argument is a phrase to be
typeset according to the rules of the language named in its first one.
This command (1) only switches the extra definitions and the
hyphenation rules for the language, \emph{not} the names and dates, (2)
does not send information about the language to auxiliary files (i.e.,
the surrounding language is still in force), and (3) it works even if
the language has not been set as package option (but in such a case it
only sets the hyphenation patterns and a warning is shown). With the
|bidi| option, it also enters in horizontal mode (this is not done
always for backwards compatibility), and since it is meant for phrases
only the text direction (and not the paragraph one) is set.
\New{3.44} As already said, captions and dates are not switched.
However, with the optional argument you can switch them, too. So, you
can write:
\begin{verbatim}
\foreignlanguage[date]{polish}{\today}
\end{verbatim}
In addition, captions can be switched with |captions| (or both, of
course, with |date,| |captions|). Until 3.43 you had to write something
like |{\selectlanguage{..} ..}|, which was not always the most
convenient way.
\begin{note}
|\bibitem| is out of sync with |\selectlanguage| in the \file{aux}
file. The reason is |\bibitem| uses |\immediate| (and others, in
fact), while |\selectlanguage| doesn't. There is a similar issue with
floats, too. There is no known workaround, but it’s not usually a
real issue.
\end{note}
\subsection{Auxiliary language selectors}
\Describe{\begin\menv{otherlanguage}}{\marg{language}\Eenv{otherlanguage}}
Same as |selectlanguage| as environment, except spaces after the
|\begin| and |\end| commands are ignored. (Very likely, and because of
the limitations of many old editors with bidi text, the idea was
\cs{end}\texttt{\{otherlanguage\}} had to be a line by itself.) The
warning above about the internal |\write| also applies here. The
current mode (vertical or horizontal) also remains unchanged.
\Describe{\begin\menv{otherlanguage*}}%
{\oarg{option-list}\marg{language}\Eenv{otherlanguage*}}
Same as |\foreignlanguage| but as environment. Spaces are \textit{not}
ignored.
It was originally devised for intermixing left-to-right
typesetting with right-to-left typesetting in engines not supporting a
change in the writing direction inside a line. However, by default it
never complied with the documented behavior and it is just a version as
environment of |\foreignlanguage|, except when the package option
|bidi| is set -- in this case, |\foreignlanguage| emits a
|\leavevmode|, while |otherlanguage*| does not. Like |\foreignlanguage|
it is a \textit{text} command, and therefore it doesn’t change the
paragraph direction.
\begin{example}
Here is a document putting in practice some of the techniques described,
which shows how to deal neatly with complex multilingual documents
in \luatex{} and \xetex, with the help of logical markup. You are
writing a book on Indic literature with many extracts in several
languages, which fits in the category of ‘mostly monolingual’. Loading
of locales and fonts is lazy, which greatly simplifies the preamble.
\catcode`@=13 \def@#1@{{\fontspec[Script=Devanagari]{FreeSans}#1}}
\begin{verbatim}
\documentclass{article}
_\usepackage[english]{babel}_
_\babelfont[*devanagari]{rm}{FreeSans}_
\newenvironment{excerpt}[1]
{\begin{quote}_\begin{otherlanguage*}{#1}_}
{_\end{otherlanguage*}_\end{quote}}
\begin{document}
\section{Sanskrit literature}
Here is an excerpt:
\begin{excerpt}{sanskrit}
@संस्कृतम्@
\end{excerpt}
\section{Hindi literature}
Here is an excerpt:
\begin{excerpt}{hindi}
@हिन्दी@
\end{excerpt}
\section{Marathi literature}
Here is an excerpt:
\begin{excerpt}{marathi}
@मराठी@
\end{excerpt}
\section{Nepali literature}
Here is an excerpt:
\begin{excerpt}{nepali}
@नेपाली@
\end{excerpt}
\section{Rajasthani literature}
Here is an excerpt:
\begin{excerpt}{rajasthani}
@संस्कृतम्@
\end{excerpt}
\end{document}
\end{verbatim}
\end{example}
\subsection{Plain}
In e-Plain and pdf-Plain, load languages styles with |\input| and then use
|\begindocument| (the latter is defined by \babel):
\begin{verbatim}
\input estonian.sty
\begindocument
\end{verbatim}
\begin{warning}
Not all languages provide a |sty| file and some of them are not
compatible with those formats. Please, refer to
\href{
https://latex3.github.io/babel/guides/using-babel-with-plain.html}%
{Using babel with Plain} for further details.
\end{warning}
\section{More on language loading and selection}
\subsection{A few tools}
% Also Plain
\Describe{\babeltags}{\char`\{\m{tag1} \texttt{=} \m{language1}, \m{tag2}
\texttt{=} \m{language2}, \dots\char`\}}
\New{3.9i} In multilingual documents with many language-switches the
commands above can be cumbersome. With this tool shorter names can be
defined. It adds nothing really new -- it is just syntactical sugar.
It defines |\text<tag1>{<text>}| to be
|\foreignlanguage{<language1>}{<text>}|, and |\begin{<tag1>}|
to be |\begin{otherlanguage*}{<language1>}|, and so on. Note
|\<tag1>| is also allowed, but remember to set it locally inside a
group.
\begin{warning}
There is a clear drawback to this feature, namely, the ‘prefix’
|\text...| is heavily overloaded in \LaTeX{} and conflicts with
existing macros may arise (|\textlatin|, |\textbar|, |\textit|,
|\textcolor| and many others). The same applies to environments,
because |arabic| conflicts with |\arabic|. Furthermore, and because of
this overloading, detecting the language of a chunk of text by
external tools can become unfeasible (is |\textga| the locale for the
African language Gã or something else?). Except if there is a reason for
this ‘syntactical sugar’, the best option is to stick to the default
selectors or even to define your own alternatives.
\end{warning}
\begin{example}
With
\begin{verbatim}
\babeltags{de = german}
\end{verbatim}
you can write
\begin{verbatim}
text \textde{German text} text
\end{verbatim}
and
\begin{verbatim}
text
\begin{de}
German text
\end{de}
text
\end{verbatim}
\end{example}
\begin{note}
Something like \verb|\babeltags{finnish = finnish}| is legitimate --
it defines |\textfinnish| and |\finnish| (and, of course,
|\begin{finnish}|).
\end{note}
% Also Plain
\Describe{\babelensure}{|[include=|\m{commands}|,exclude=|\m{commands}%
|,fontenc=|\m{encoding}|]|\marg{language}}
\New{3.9i} Except in a few languages, like \textsf{russian},
captions and dates are just strings, and do not switch the
language. That means you should set it explicitly if you want to use
them, or hyphenation (and in some cases the text itself) will be
wrong. For example:
\begin{verbatim}
\foreignlanguage{russian}{text \foreignlanguage{polish}{\seename} text}
\end{verbatim}
Of course, \TeX{} can do it for you. To avoid switching the language
all the while, |\babelensure| redefines the captions for a given
language to wrap them with a selector:
\begin{verbatim}
\babelensure{polish}
\end{verbatim}
By default only the basic captions and |\today| are redefined, but you
can add further macros with the key |include| in the optional argument
(without commas). Macros not to be modified are listed in
|exclude|. You can also enforce a font encoding with the option
|fontenc| (with it, encoded strings may not work as expected).
A couple of examples:
\begin{verbatim}
\babelensure[include=\Today]{spanish}
\babelensure[fontenc=T5]{vietnamese}
\end{verbatim}
They are activated when the language is selected (at the |afterextras|
event), and it makes some assumptions which could not be fulfilled in
some languages. Note also you should include only macros defined by
the language, not global macros (e.g., |\TeX| of |\dag|).
With |ini| files (see below), captions are ensured by default.
\Describe\AfterBabelLanguage{\marg{option-name}\marg{code}}
Executes \meta{code} when the file loaded by the corresponding package
option is finished (at |\ldf@finish|). The setting is global. So
\begin{verbatim}
\AfterBabelLanguage{french}{...}
\end{verbatim}
does |...|\ at the end of |french.ldf|. It can be used in |ldf| files,
too, but in such a case the code is executed only if
\meta{option-name} is the same as |\CurrentOption| (which could not
be the same as the option name as set in |\usepackage|!).
\begin{example}
Consider two languages \textsf{foo} and \textsf{bar} defining the
same |\macro| with |\newcommand|. An error is raised if you attempt
to load both. Here is a way to overcome this problem, with the help
of the \texttt{presets} hook (which has to be set before loading
\babel):
\begin{verbatim}
\AddToHook{babel/presets}{%
\AfterBabelLanguage{foo}{%
\let\macroFoo\macro
\let\macro\relax}}
\usepackage[foo, bar]{babel}
\end{verbatim}
\end{example}
\begin{note}
An alternative method to execute some code just after an |ldf| file
is loaded is with the hook |file/<language>.ldf/after|. You can also
execute some code before with |file/<language>.ldf/before|.
\end{note}
\subsection{Accessing language info}
% Also Plain
\Describe{\localename}{}
\DescribeOther{\mainlocalename}{}
\DescribeOther{\languagename}{}
\New{24.10} The control sequence |\localename| contains the name of the current
locale. This is now the recommended way to retrieve the current
language. In addtion, |\mainlocalename| contains the main language.
|\languagename| is still used internally, but it is now discouraged at
the user level.
\begin{warning}
Due to a bug, which led to some internal inconsistencies in
catcodes, |\languagename| should \textit{not} be used to test which
is the current language. Rely on |\localename| or, if you still need
|\languagename| for some reason, on \textsf{iflang}, by Heiko Oberdiek.
\end{warning}
\Describe{\iflanguage}{\marg{language}\marg{true}\marg{false}}
Here “language” is used in the \TeX{} sense, as a set of hyphenation
patterns, and \textit{not} as its \textsf{babel} name. The first
argument is the name of a language.
\Describe{\localeinfo}{\optstar{\marg{field}}}
\New{3.38} If an |ini| file has been loaded for the current language,
you may access the information stored in it. Note with the ‘classical’
|ldf| files the corresponding |ini| ones are also loaded, but only some
basic data required for fonts, casing and a few more.
This macro is fully expandable, but raises an error if the info doesn’t
exist. \New{3.75} Sometimes, it comes in handy to be able to use
|\localeinfo| in a quite fully expandable way even if something went
wrong (for example, the locale currently active is undefined). For
these cases, |localeinfo*| just returns an empty string instead of
raising an error.
The available fields are:
\begin{description}
\itemsep=-\parskip
\item[|name.english|] as provided by the Unicode CLDR.
\item[|tag.ini|] is the tag of the |ini| file (the way this
file is identified in its name).
\item[|tag.bcp47|] is the full BCP 47 tag. This
is the value to be used for the ‘real' provided tag (\babel{} may
fill other fields if they are considered necessary).
\item[|language.tag.bcp47|] is the BCP 47 language tag.
\item[|tag.opentype|] is the tag used by OpenType (usually, but not
always, the same as BCP 47). It can be useful when customizing fonts
with \textsf{luaotfload}.
\item[|script.name|], as provided by the Unicode CLDR.
\item[|script.tag.bcp47|] is the BCP 47 tag of the script
used by this locale. This is a required field for the fonts to be
correctly set up, and therefore it should always be defined.
\item[|script.tag.opentype|] is the tag used by OpenType (usually,
but not always, the same as BCP 47). It can be useful when
customizing fonts with \textsf{luaotfload}.
\item[|region.tag.bcp47|] is the BCP 47 tag of the region or territory.
Defined only if the locale loaded actually contains it (e.g., |es-MX|
does, but |es| doesn’t), which is how locales behave in the CLDR.
\New{3.75}
\item[|variant.tag.bcp47|] is the BCP 47 tag of the variant (in the BCP 47
sense, like |1901| for German). \New{3.75}
\item[|extension.|\m{s}|.tag.bcp47|] is the BCP 47 value of the
extension whose singleton is \m{s} (currently the recognized
singletons are |x|, |t| and |u|). The internal syntax can be somewhat
complex, and this feature is still somewhat tentative. An example is
\textsf{classicallatin} which sets |extension.x.tag.bcp47| to |classic|.
\New{3.75}
\end{description}
% All of these keys can be preceded by |main.| (e.g., |main.tag.ini|),
% which retrieves the values of the main locale.
\begin{note}
Currently, |x| is used for two separate functions, namely,
identifying a \babel{} locale without a BCP 47 tag and setting an
alternative set of rules for casing.
\end{note}
\begin{note}
Bear in mind that \babel{}, following the CLDR, may leave the region
unset, which means |\getlocaleproperty*|, described below, is the
preferred command, so that the existence of a field can be checked
before. This also means building a string with the language and the
region with something like
|\localeinfo*{language.tab.bcp47}|\allowbreak |-|\allowbreak
|\localeinfo*{region.tab.bcp47}| is not usually a good idea (because
of the hyphen).
\end{note}
\begin{warning}
\New{3.46} As of version 3.46 |tag.bcp47| returns the full BCP 47
tag. Formerly it returned just the language subtag, which was clearly
counterintuitive.
\end{warning}
\Describe{\getlocaleproperty}{%
\optstar\marg{macro}\marg{locale}\marg{property}}
\New{3.42} The value of any locale property as set by the |ini| files
(or added/modified with |\babelprovide|) can be retrieved and stored in
a macro with this command. For example, after:
\begin{verbatim}
\getlocaleproperty\hechap{hebrew}{captions/chapter}
\end{verbatim}
the macro |\hechap| will contain the string
{\fontspec[Scale=.87,Script=Hebrew]{Liberation Mono}\textdir TRT פרק}.
If the key does not exist, the macro is set to |\relax| and an error is
raised. \New{3.47} With the starred version no error is raised, so that
you can take your own actions with undefined properties.
\Describe{\localeid}{}
Each language in the \babel{} sense has its own unique numeric
identifier, which can be retrieved with |\localeid|.
The |\localeid| is not the same as the |\language| identifier, which
refers to a set of hyphenation patterns (which, in turn, is just a
component of the line breaking algorithm described in the next
section). The data about preloaded patterns are store in an internal
macro named |\bbl@languages| (see the code for further details), but
note several locales may share a single |\language|, so they are
separated concepts. In \luatex, the |\localeid| is saved in each node
(when it makes sense) as an attribute, too.
\Describe{\ShowLocaleProperties}{\marg{language}}
\New{3.98} Prints to the |log| file all the loaded key/value pairs from
the |ini| locale file for \meta{language}.
\Describe{\LocaleForEach}{\marg{code}}
\Babel{} remembers which |ini| files have been loaded. There is a loop
named |\LocaleForEach| to traverse the list, where |#1| is the name of
the current item, so that |\LocaleForEach{\message{ **#1** }}| just
shows the loaded |ini|’s.
\subsection{Package options}
\New{3.9a}
These package options are processed before language options, so
that they are taken into account irrespective of their order. The first
three options have been available in previous versions.
\Describe{KeepShorthandsActive}{}
Tells \babel{} not to deactivate shorthands after loading a language
file, so that they are also available in the preamble.
\Describe{headfoot=}{\meta{language}} By default, headlines and
footlines are not touched (only marks), and if they contain
language-dependent macros (which is not usual) there may be unexpected
results. With this option you may set the language in heads and feet.
An alternative is to set the language explicitly when heads and feet
are redefined.
\Describe{noconfigs}{} Global and language default config files are
not loaded, so you can make sure your document is not spoilt by an
unexpected \texttt{.cfg} file. However, if the key |config| is set,
this file is loaded.
\Describe{config=}{\meta{file}} Load \meta{file}\texttt{.cfg} instead
of the default config file |bblopts.cfg| (forced even with
|noconfigs|).
\Describe{showlanguages}{} Prints to the log the list of languages
loaded when the format was created: number (remember dialects can
share it), name, hyphenation file and exceptions file.
\Describe{silent}{} \New{3.9l} No warnings and no \textit{infos} are
written to the log file.\footnote{You can use alternatively the
package \textsf{silence}.}
\Describe{hyphenmap=}{\texttt{off} $\string|$ \texttt{first}
$\string|$ \texttt{select} $\string|$ \texttt{other} $\string|$
\texttt{other*}}
\New{3.9g} Sets the behavior of case mapping for hyphenation,
provided the language defines it.\footnote{Turned off in plain.} It
can take the following values:
\begin{description}
\renewcommand\makelabel[1]{%
\hspace\labelsep\normalfont\ttfamily\color{thered}#1}
\itemsep=-\parskip
\item[off] deactivates this feature and no case mapping is applied;
\item[first] sets it at the first switching commands in the
current or parent scope (typically, when the |aux| file is first read
and at |\begin{document}|, but also the first |\selectlanguage| in
the preamble), and it's the default if a single language option has
been stated. If a language option is repeated (e.g., |malay, malay|),
it counts as several ones, even if there is only a language.
\item[select] sets it only at |\selectlanguage|;
\item[other] also sets it at |otherlanguage|;
\item[other*] also sets it at |otherlanguage*| as well as in heads and
feet (if the option |headfoot| is used) and in auxiliary files (i.e.,
at |\select@language|), and it's the default if several language
options have been stated. The option |first| can be regarded as an
optimized version of \texttt{other*} for monolingual
documents.\footnote{Providing |foreign| is pointless, because the
case mapping applied is that at the end of the paragraph, but if either
\luatex{} or \xetex{} change this behavior it might be added. On
the other hand, |other| is provided even if I [JBL] think it isn't
really useful, but who knows.}
\end{description}
\Describe{bidi=}{\texttt{default} $\string|$ \texttt{basic}
$\string|$ \texttt{basic-r} $\string|$ \texttt{bidi-l} $\string|$
\texttt{bidi-r}}
\New{3.14} Selects the bidi algorithm to be used in \luatex{} and
\xetex{}. See sec.~\ref{bidi}.
\Describe{layout=}{}
\New{3.16} Selects which layout elements are adapted in bidi
documents. See sec.~\ref{bidi}.
\Describe{provide=}{\texttt{*} $\string|$ \meta{option-list}}
\New{3.49} An alternative to |\babelprovide| for languages passed as
options. See section~\ref{inifiles}, which describes also the variants
|provide+=| and |provide*=|.
\Describe{main=}{\meta{language}} Forces the main language, but this
option should not be used except if there a need to do it. If the
language is not given as such as package or global option, it is added
to the list of requested languages. For example:
\begin{verbatim}
\documentclass{article}
\usepackage[_main=english_,dutch]{babel}
\end{verbatim}
Some classes load \babel{} with a hardcoded language option. Sometimes,
the main language can be overridden with something like that before
|\documentclass|:
\begin{verbatim}
\PassOptionsToPackage{main=english}{babel}
\end{verbatim}
\subsection{The \texttt{base} option}
With this package option \babel{} just loads some basic macros (mainly
the selectors), defines |\AfterBabelLanguage| and exits. It also
selects the hyphenation patterns for the last language passed as option
(by its name in |language.dat|).
\begin{warning}
Currently this option is not compatible with languages loaded on the
fly.
\end{warning}
\subsection{\texttt{provide} and \cs{babelprovide} – \texttt{ini} files}
\label{inifiles}
An alternative approach to define a language (or, more precisely, a
\textit{locale}) is by means of an \texttt{ini} file. Currently
\babel{} provides about 380 of these files containing the basic data
required for a locale, covering about 300 languages and 40 scripts,
plus basic templates for about 400 locales.
|ini| files are not meant only for \babel, and they has been devised as
a resource for other packages. To ease interoperability between \TeX{}
and other systems, they are identified with the BCP 47 codes as
preferred by the Unicode Common Locale Data Repository, which was
used as source for most of the data provided by these files, where
available.
Most of them set the date, and many also the captions (Unicode and
LICR). They will be evolving with the time to add more features
(something to keep in mind if backward compatibility is important). The
following section shows how to make use of them by means of
|\babelprovide|.
Not all languages in the CLDR are complete, and therefore neither are
the |ini| files. A few languages may show a warning about the current
lack of suitability of some features.
\begin{example}
There is an example of how to use an |ini| template file
\href{
https://github.com/latex3/babel/issues/176#issuecomment-1080846575}{here},
for Phoenician (although currently this locale is bundled with
\babel).
\end{example}
\begin{note}
The \texttt{ini} files just define and set some parameters, but the
corresponding behavior is not always implemented. Also, there are
some limitations in the engines. A few remarks follow (which could no
longer be valid when you read this manual, if the packages involved
have been updated).
\begin{description}
\itemsep=-\parskip
\item[Arabic] Math and graphical elements like |picture| are complex
and requires some additional fine tuning. In \xetex{} \babel{}
resorts to the \textsf{bidi} package, which seems to work.
\item[Southeast scripts] Thai works in both \luatex{} and \xetex{}, but
line breaking differs (rules are hard-coded in \xetex, but they can
be modified in \luatex). Lao seems to work, too, but there are no
patterns for the latter in \luatex{}. Some quick patterns can
help, with something similar to:
\begin{verbatim}
\babelprovide[import, hyphenrules=+]{lao}
\babelpatterns[lao]{1ດ 1ມ 1ອ 1ງ 1ກ 1າ} % Random
\end{verbatim}
\item[East Asia scripts] Settings for either Simplified of Traditional
(Chinese) should work out of the box, with basic line breaking with any
renderer. 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 the class |ltjbook| does with \luatex, which can
be used in conjunction with the |ldf| for |japanese|, because the
following piece of code loads \textsf{luatexja}:
\begin{verbatim}
\documentclass[japanese]{ltjbook}
\usepackage{babel}
\end{verbatim}
\item[Latin, Greek, Cyrillic] Combining chars with the default
\luatex{} font renderer might be wrong; on the other hand, with the
Harfbuzz renderer diacritics are stacked correctly, but many
hyphenations points are discarded (this bug is related to kerning,
so it depends on the font). With \xetex{} both combining characters
and hyphenation work as expected (not quite, but in most cases it
works; the problem here are font clusters).
\end{description}
\end{note}
\begin{note}
Wikipedia defines a \textit{locale} as follows: “In computing, a
locale is a set of parameters that defines the user’s language,
region and any special variant preferences that the user wants to see
in their user interface. Usually a locale identifier consists of at
least a language code and a country/region code.” \Babel{} is moving
gradually from the old and fuzzy concept of \textit{language} to the
more modern of \textit{locale}. Note each locale is by itself a
separate “language”, which explains why there are so many files. This
is on purpose, so that possible variants can be created and/or
redefined easily.
\end{note}
\subsection{Selection based on BCP 47 tags}
\label{bcp47}
\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 documents (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 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 is not
hardcoded in \babel. Instead the data is taken from the \texttt{ini}
files, which means currently about 350 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}
Chapter in Danish: \chaptername.
_\selectlanguage{de-AT}_
\localedate{2020}{1}{30}
\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 behavior 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|; \New{24.14} |import| by default (features defined in
the corresponding |babel-...tex| file might not be available), but
you can set it to another value (even empty).
\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}
\New{3.46} If an |ldf| file has been loaded, you can enable the
corresponding language tags as selector names with:
\begin{verbatim}
\babeladjust{ bcp47.toname = on }
\end{verbatim}
(You can deactivate it with |off|.) So, if |dutch| is one of the
package (or class) options, you can write |\selectlanguage{nl}|. Note
the language name does not change (in this example is still |dutch|),
but you can get it with |\localeinfo| or |\getlocaleproperty|. It
must be turned on explicitly for similar reasons to those explained
above.
\section{Tailoring, customizing and modifying a language}
Modifying the behavior of a language (say, the chapter
“caption”) is sometimes necessary.
Several language definition files use their own methods to set
options. For example, \textsf{french} uses |\frenchsetup|,
\textsf{magyar} (1.5) uses |\magyarOptions|; modifiers provided by
|spanish| have no attribute counterparts. Macros setting
options are also used (e.g., |\ProsodicMarksOn| in \textsf{latin}).
This section describes the general tools provided by the \babel{} core.
\subsection{Captions}
This is perhaps the most frequent change, so a specific macro is
provided.
\Describe{\setlocalecaption}{%
\marg{language-name}\marg{caption-name}\marg{string}}
\New{3.51} Here \textit{caption-name} is the name as string without the
trailing |name|. An example, which also shows caption names are often a
stylistic choice, is:
\begin{verbatim}
\setlocalecaption{english}{contents}{Table of Contents}
\end{verbatim}
This works not only with existing caption names, because it also serves to
define new ones by setting the \textit{caption-name} to the name of
your choice (|name| will be postpended). Captions so defined or
redefined behave with the ‘new way’ described in the following note.
Note the string should not contain a language selector or changes in
the text direction, which is done by \babel{} when necessary. With
|arabic|, all you need is:
\begingroup
% If you are looking at the code to see how it has been written, you
% will be disappointed :-). The following example is built ad hoc to
% emulate the final result to avoid dependencies, and therefore it's
% not "real" code.
\setmonofont[Scale=.86, FakeStretch=.97,Script=Arabic]{DejaVu Sans Mono}
\catcode`@=13
\def@#1{\ifcase#1\relax \egroup \or \bgroup\textdir TLT \else
\bgroup\textdir TRT \pardir TRT \fi}
\begin{verbatim}
\setlocalecaption{arabic}{part}{@2القسم@0}
\end{verbatim}
\endgroup
\begin{note}
There are a few alternative methods:
\begin{itemize}
\item With data |import|’ed from |ini| files, you can modify the values
of specific keys when loaded, like:
\begin{verbatim}
\babelprovide[import, _captions/listtable = Lista de tablas_]{spanish}
\end{verbatim}
(In this particular case, instead of the |captions| group you may need
to modify the |captions.licr| one.)
\item The low-level ‘old way’ to redefine a caption, still valid for
many languages but discouraged in general, is the following:
\begin{verbatim}
\addto\captionsenglish{%
\renewcommand\contentsname{Foo}%
}
\end{verbatim}
As of 3.15, there is no need to hide spaces with \texttt{\%%
} (\babel{} removes them), but it is advisable to do so. This
redefinition is not activated until the language is selected.
\item The ‘new way’, which is found in |bulgarian|, |azerbaijani|,
|spanish|, |french|, |turkish|, |icelandic|, |vietnamese| and a few
more, as well as in languages created with |\babelprovide| and its
key |import|, or with the package option |provide=|, is:
\begin{verbatim}
\renewcommand\spanishchaptername{Foo}
\end{verbatim}
This redefinition is immediate.
\end{itemize}
\end{note}
\begin{note} Do \textit{not} redefine a caption in the following way:
\begin{verbatim}
\AtBeginDocument{\renewcommand\contentsname{Foo}}
\end{verbatim}
The changes may be discarded with a language selector, and the original
value restored.
\end{note}
Macros to be run when a language is selected can be added to
|\extras<language>|:
\begin{verbatim}
\addto\extrasrussian{\mymacro}
\end{verbatim}
There is a counterpart for code to be run when a language is
unselected: |\noextras<language>|.
\begin{note}
These macros (|\captions<language>|, |\extras<language>|) may be
redefined, but \textit{must not} be used as such -- they just pass
information to \babel{}, which executes them in the proper context.
\end{note}
Another way to modify a language loaded as a package or class option
is by means of |\babelprovide|, described below in depth. So,
something like:
\begin{verbatim}
\usepackage[danish]{babel}
\babelprovide[_hyphenrules=nohyphenation_]{danish}
\end{verbatim}
first loads |danish.ldf|, and then prevents hyphenation for this
locale. The rest of the language definitions are not touched. Without
the optional argument it just loads some additional tools if provided
by the |ini| file, like extra counters.
\subsection{Modifiers}
\New{3.9c} The basic behavior of some languages can be modified when
loading \babel{} by means of \textit{modifiers}. They are set after
the language name, and are prefixed with a dot (only when the language
is set as package option -- neither global options nor the |main| key
accepts them). An example is (spaces are not significant and they can
be added or removed):\footnote{No predefined “axis” for modifiers
is provided because languages and their scripts have quite different
needs.}
\begin{verbatim}
\usepackage[latin_.lowercasemonth_, spanish_.notilde.lcroman_, danish]{babel}
\end{verbatim}
Attributes (described below) are considered modifiers, i.e., you can
set an attribute by including it in the list of modifiers.
\New{3.89} Alternatively, modifiers can be set with a separate option,
with the keyword |modifiers| followed by a dot and the language name
(note the language is not selected or loaded with this option). It is
useful to activate some feature when the language is declared as a
class option:
\begin{verbatim}
\documentclass[spanish]{report}
\usepackage[_modifiers.spanish = notilde.lcroman_]{babel}
\end{verbatim}
\subsection{Language attributes}
\Describe{\languageattribute}{\marg{language}}
This is a user-level command, to be used in the preamble of a
document (after |\usepackage[...]{babel}|), that declares which
attributes are to be used for a given language. It takes two
arguments: the first is the name of the language; the second,
a (list of) attribute(s) to be used. Attributes must be set in the
preamble and only once -- they cannot be turned on and off.
The command checks whether the language is known in this document
and whether the attribute(s) are known for this language.
\subsection{Casing}
\Describe{\BabelUppercaseMapping}
{\marg{locale-name}\marg{codepoint}\marg{output}}
\DescribeOther{\BabelLowercaseMapping}
{\marg{locale-name}\marg{codepoint}\marg{output}}
\DescribeOther{\BabelTitlecaseMapping}
{\marg{locale-name}\marg{codepoint}\marg{output}}
\New{3.90} These macros are devised as a high level interface for
declaring case mappings, based on the locale name as declared by or
with \babel. They are the equivalent of |\DeclareUppercaseMapping|,
|\DeclareLowercaseMapping|, and |\DeclareTitlecaseMapping| (see
\textsf{usrguide.pdf}). The purpose is twofold: (1) a user-friendly way
to declare them, because often BCP 47 tags are not known (and sometimes
can be complex); (2) if for some reason the tag changes (e.g., you decide
to tag |english| as |en-001| instead of |en-US|), the new mappings will
still be assigned to that language.
\begin{example} For Classical Latin (no need to know the tag is
\texttt{la-x-classic}):
\begin{verbatim}
\BabelUppercaseMapping{classicallatin}{`u}{V}
\end{verbatim}
\end{example}
\begin{note}
There are still some rough edges when declaring a mapping with the
|x| extension, or when two \babel{} languages share the same BCP 47
tag. These issues are expected be sorted out in future releases.
\end{note}
\subsection{Modifying and adding values to \texttt{ini} files}
\New{3.39} There is a way to modify or even add values of |ini| files
when they are imported with |\babelprovide| or |provide=|. This can be
used to create private variants easily. All you need is to import the
same |ini| file with a different locale name and different parameters.
Without |import| you may still modify the identification keys.
Examples of the fine-grained control you have at your disposal are the
following. All of them assume |\usepackage[english]{babel}|.
\begin{example}
Here is how to change the hyphenation rules because there are several
criteria, or you must follow an editorial style. The following
example just uses the default Spanish rules in English:
\begin{verbatim}
\babelprovide[hyphenrules=spanish]{english}
\end{verbatim}
\end{example}
\begin{example}
The required native digits are already defined in the corresponding
|ini| files, but they can be modified and even added as shown:
\begin{verbatim}
\babelprovide[numbers/digits.native=abcdefghij]{english}
\end{verbatim}
This example is somewhat absurd, but now |\englishdigits{264}| will
print ‘cge’. (It doesn't work with \pdftex.)
\end{example}
\begin{example}
Currently the date format can be changed only with imported data, but
with its high level interface it’s quite straightforward:
\begin{verbatim}
\babelprovide[
import,
date.gregorian/date.long = {[d] ([MMMM]) [y]}]
{english}
\end{verbatim}
Here |[d]| is the day number, |[MMMM]| the month name and |[y]| the
year. It will print something like ‘5 (October) 2024’.
\end{example}
\begin{example}
To set the hyphen to ‘none’ (only \luatex).
\begin{verbatim}
\babelprovide[typography/prehyphenchar = 0]{english}
\end{verbatim}
This setting \textit{may} work with |xetex|, but getting rid of the
hyphen char in this engine is not trivial, because you must rely on the
font, and not all fonts behave the same.
\end{example}
\begin{example}
You can define new counters freely, and assign them to |\alph|:
\begin{verbatim}
\babelprovide[
counters/acute = á é í ó ú, % Define a counter named `acute`
alph = acute % Assign it to \alph
]{english}
\end{verbatim}
You can choose the name, and instead of |acute| it can be another one.
\end{example}
\subsection{Hooks}
\New{3.9a} A hook is a piece of code to be executed at certain
events. Some hooks are predefined when \luatex{} and \xetex{} are
used.
\New{3.64} This is not the only way to inject code at those points. The
events listed below can be used as a hook name in |\AddToHook| in the
form |babel/<language-name>/<event-name>| (with |*| it’s applied to
all languages), but there is a limitation, because the parameters
passed with the \babel{} mechanism are not allowed. The |\AddToHook|
mechanism does \textit{not} replace the current one in \babel. Its
main advantage is you can reconfigure \babel\ even before loading it.
See the example below.
\Describe{\AddBabelHook}{\oarg{language}\marg{name}\marg{event}\marg{code}}
The same name can be applied to several events. Hooks with a certain
\marg{name} may be enabled and disabled for all defined events with
|\EnableBabelHook|\marg{name}, |\DisableBabelHook|\marg{name}. Names
containing the string |babel| are reserved (they are used, for example,
by |\useshortands*| to add a hook for the event |afterextras|).
\New{3.33} They may be also applied to a specific language with the
optional argument; language-specific settings are executed after global
ones.
Current events are the following; in some of them you can use one to
three \TeX{} parameters (|#1|, |#2|, |#3|), with the meaning given:
\begin{description}
\renewcommand\makelabel[1]{%
\hspace\labelsep\normalfont\ttfamily\color{thered}#1}
\itemsep=-\parskip
\item[adddialect] (language name, dialect name) Used by
\file{luababel.def} to load the patterns if not preloaded.
\item[patterns] (language name, language with encoding) Executed just
after the |\language| has been set. The second argument has the
patterns name actually selected (in the form of either |lang:ENC| or
|lang|).
\item[hyphenation] (language name, language with encoding) Executed
locally just before exceptions given in |\babelhyphenation| are
actually set.
\item[defaultcommands] Used (locally) in |\StartBabelCommands|.
\item[encodedcommands] (input, font encodings) Used (locally) in
|\StartBabelCommands|. Both \luatex{} and \xetex{} make sure the
encoded text is read correctly.
\item[stopcommands] Used to reset the above, if necessary.
\item[write] This event comes just after the switching commands are
written to the |aux| file.
\item[beforeextras] Just before executing |\extras<language>|. This
event and the next one should not contain language-dependent code
(for that, add it to |\extras<language>|).
\item[afterextras] Just after executing |\extras<language>|. For
example, the following deactivates shorthands in all languages:
\begin{verbatim}
\AddBabelHook{noshort}{afterextras}{\languageshorthands{none}}
\end{verbatim}
\item[stringprocess] Instead of a parameter, you can manipulate the
macro |\BabelString| containing the string to be defined with
|\SetString|. For example, to use an expanded version of the string
in the definition, write:
\begin{verbatim}
\AddBabelHook{myhook}{stringprocess}{%
\protected@edef\BabelString{\BabelString}}
\end{verbatim}
\item[initiateactive] (char as active, char as other, original char)
\New{3.9i} Executed just after a shorthand has been ‘initiated’. The three
parameters are the same character with different catcodes: active,
other (|\string|'ed) and the original one.
\item[afterreset] \New{3.9i} Executed when selecting a language just after
|\originalTeX| is run and reset to its base value, before executing
|\captions<language>| and |\date<language>|.
\item[begindocument] \New{3.88} Executed before the code written by
|ldf| files with |\AtBeginDocument|. The optional argument with the
language in this particular case is the language that wrote the code.
The special value |/| means ‘return to the core \babel{} definitions’
(in other words, what follows hasn’t been written by any language).
\item[foreign] \New{24.8} Executed by |\foreignlanguage| after the
language has been set up and just before typesetting the text from the
second argument. Its main purpose it to wrap the text with some
code, with the help of |\BabelWrapText|. For example, with:
\begin{verbatim}
\AddBabelHook{one}{foreign}{\BabelWrapText{\textit{##1}}
\AddBabelHook{two}{foreign}{\BabelWrapText{\parse{##1}}
\end{verbatim}
the text becomes |\textit{\parse{<text>}}|.
\begin{example}
PDF tagging is still a work in progress, but language tags are already
possible in short texts with |\foreignlanguage|. Here is an example:
\begin{verbatim}
\AddBabelHook[indonesian]{meta}{foreign}{%
\BabelWrapText{\tagmcbegin{tag=Span, raw=/Lang (id)}##1\tagmcend}}
\end{verbatim}
Be aware the behavior related to tagging can and very likely will change.
\end{example}
\end{description}
Four events are used in \file{hyphen.cfg}, which are handled in a
quite different way for efficiency reasons -- unlike the precedent
ones, they only have a single hook and replace a default definition.
\begin{description}
\renewcommand\makelabel[1]{%
\hspace\labelsep\normalfont\ttfamily\color{thered}#1}
\itemsep=-\parskip
\item[everylanguage] (language) Executed before every language patterns
are loaded.
\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
file. Used by \file{luababel.def}.
\end{description}
\begin{example}
The generic unlocalized \LaTeX{} hooks are predefined, so that you can
write:
\begin{verbatim}
\AddToHook{babel/*/afterextras}{\frenchspacing}
\end{verbatim}
which is executed always after the extras for the language being
selected (and just before the non-localized hooks defined with
|\AddBabelHook|).
In addition, locale-specific hooks in the form
|babel/<language-name>/<event-name>| are \textit{recognized}
(executed just before the localized \babel{} hooks), but they are
\textit{not predefined}. You have to do it yourself. For example, to
set |\frenchspacing| only in |bengali|:
\begin{verbatim}
\ActivateGenericHook{babel/bengali/afterextras}
\AddToHook{babel/bengali/afterextras}{\frenchspacing}
\end{verbatim}
\end{example}
\subsection{Manage auxiliary files}
\Describe{\BabelContentsFiles}{}
\New{3.9a} This macro contains a list of “toc” types requiring a
command to switch the language. Its default value is |toc,lof,lot|, but
you may redefine it with |\renewcommand| to add further types in case
you need or there is a package enabling additional files, e.g., for
theorems, algorithms, notation (it's up to you to make sure no toc type
is duplicated).
\subsection{Code based on the selector}
\Describe{\IfBabelSelectorTF}{\marg{selectors}\marg{true}\marg{false}}
\New{3.67} Sometimes a different setup is desired depending on the
selector used. Values allowed in \m{selectors} are |select|, |other|,
|foreign|, |other*| (and also |foreign*| for the tentative starred
version), and it can consist of a comma-separated list. For example:
\begin{verbatim}
\IfBabelSelectorTF{other, other*}{A}{B}
\end{verbatim}
is true with any of these two environment selectors.
Its natural place of use is in hooks or in |\extras<language>|.
\subsection{Presets}
\New{24.12} Apart from configuration files, which are loaded before the
locale files, you can preset some options even before loading \babel.
One on the aims of this feature is to ease the integration with
automated document generation or conversion workflows.
\Describe{\AddToHook\{babel/presets\}}{\marg{settings}}
This \LaTeX{} hook is executed just before locale files (either
\texttt{ini} or \texttt{ldf}) are loaded. It’s in fact, similar to the
config files, but it’s executed a little later and there is no need for
a separate file. The following command has been devised for this hook,
but other candidates are |\AfterBabelLanguage| and |\DeclareOption|
(although the latter can be somewhat dangerous).
Note these declarations are valid ‘just in case’. If \babel{} is not
loaded, they are ignored.
\Describe{\PassOptionsToLocale}{\marg{option-list}\marg{locale-name}}
Its purpose is what its name suggests, and it was devised to be used
with the previous hook.
\begin{example}
You are writing a class and expect lazy loading of secondary
languages. You also want to make sure |french|, if used, activates
its rules for punctuation spacing, and |malayalam|, if used, maps
digits to the native ones (with \luatex):
\setengine{luatex}
\begin{verbatim}
\AddToHook{babel/presets}{%
\PassOptionsToLocale{transforms=punctuation.space}{french}%
\PassOptionsToLocale{mapdigits}{malayalam}}
\end{verbatim}
If you want to take a step further and force \babel{} to always use
|ini| files in all secondary languages, you can resort to the \LaTeX{}
mechanism to pass options to packages:
\begin{verbatim}
\PassOptionsToPackage{provide+=*}{babel}
\end{verbatim}
\end{example}
\begin{note}
Remember localized fonts are preset, too, with lazy loading. In
the previous example you can set, for example,
|\babelfont[malayalam]{rm}{FreeSerif}|.
\end{note}
\section{Creating a language}
\New{3.10} And what if there is no style for your language or none fits
your needs? You may then define quickly a language with the help of the
following macro in the preamble (which may be used to modify an
existing language, too, as explained in the previous subsection).
\Describe{\babelprovide}{\oarg{options}\marg{language-name}}
If the language \m{language-name} has not been loaded as class or
package option and there are no \m{options}, it creates an “empty” one
with some defaults in its internal structure: the hyphen rules, if not
available, are set to the current ones, left and right hyphen mins are
set to 2 and 3. In either case, caption, date and language system are
not defined.
If no |ini| file is imported with |import|, \m{language-name} is still
relevant because in such a case the hyphenation and like breaking rules
(including those for South East Asian and CJK) are based on it as
provided in the |ini| file corresponding to that name; the same applies
to OpenType language and script.
Conveniently, some options allow to fill the language, and \babel{}
warns you about what to do if there is a missing string. Very likely
you will find alerts like this in the |log| file:
\begin{verbatim}
Package babel Warning: \chaptername not set for 'mylang'. Please,
(babel) define it after the language has been loaded
(babel) (typically in the preamble) with:
(babel) \setlocalecaption{mylang}{chapter}{..}
(babel) Reported on input line 26.
\end{verbatim}
In most cases, you will only need to define a few macros. Note
languages loaded on the fly are not yet available in the preamble.
\begin{example}
If you need a language named |arhinish|:
\begin{verbatim}
\usepackage[danish]{babel}
\babelprovide{arhinish}
\setlocalecaption{arhinish}{chapter}{Chapitula}
\setlocalecaption{arhinish}{refname}{Refirenke}
\babelhyphenmins[arhinish]{2}{2}
\end{verbatim}
\end{example}
\begin{example}
Sometimes treating the IPA as a language makes sense:
\begin{verbatim}
\documentclass{article}
\usepackage[english]{babel}
\babelprovide{ipa}
\babelfont[ipa]{rm}{DejaVu Sans}
\begin{document}
Blah \foreignlanguage{ipa}{ɔːlˈðəʊ} Blah.
\end{document}
\end{verbatim}
Then you can define shorthands, transforms (with \luatex), interchars
(with \xetex) and so on, specific to this new ‘language’.
\end{example}
\begin{example}
Locales with names based on BCP 47 codes can be created with
something like:
\begin{verbatim}
\babelprovide[import=en-US]{en-US}
\end{verbatim}
Note, however, mixing ways to identify locales can lead to problems.
For example, is \verb|yi| the name of the language spoken by the Yi
people or is it the code for Yiddish?
\end{example}
The main language is not changed (\texttt{danish} in this example).
So, you must add |\selectlanguage{arhinish}| or other selectors where
necessary.
If the language has been loaded as an argument in |\documentclass| or
|\usepackage|, then |\babelprovide| redefines the requested data.
\Describe{import=}{\meta{locale-tag}} The |<language-tag>| is optional.
It imports the full data from the |ini| file corresponding to the locale
being loaded, as set in |babel-<locale>.tex| (where |<locale>| is the
last argument in |\babelprovide|), including captions and date (and
also line breaking rules in newly defined languages). Unicode engines
load the UTF-8 variants, while 8-bit engines load the LICR (i.e., with
macros like |\'| or |\ss|) ones.
However, in some cases you may want to load a different |ini| file. In
such a case, you can set its value.
\begin{example}
For example, the locale |ar-DZ| is named |arabic-algeria|. You may
prefer the shorter name |arabic| if there are no conflicts:
\begin{verbatim}
\babelprovide[_import=ar-DZ_]{arabic}
\end{verbatim}
\end{example}
Besides |\today|, this option defines an additional command for dates:
|\<language>date|, which takes three arguments, namely, year, month and
day numbers. In fact, |\today| calls |\<language>today|, which in turn
calls |\<language>date{\the\year}{\the\month}{\the\day}|. \New{3.44}
More convenient is usually |\localedate|, which prints the date for the
current locale.
\Describe{hyphenrules=}{\meta{language-list}} With this option, with a
space-separated list of hyphenation rules, \babel{} assigns to the
language the first valid hyphenation rules in the list. For example:
\begin{verbatim}
\babelprovide[_hyphenrules=chavacano spanish italian_]{chavacano}
\end{verbatim}
If none of the listed hyphenrules exist, the default behavior applies.
Note in this example we set |chavacano| as first option, which can seem
redundant, but without it, it would select |spanish| even if
|chavacano| exists.
A special value is |+|, which allocates a new language (in the \TeX{}
sense). It only makes sense as the last value (or the only one; the
subsequent ones are silently ignored). It is mostly useful with
\luatex, because you can add some patterns with |\babelpatterns|, as
for example:
\begin{verbatim}
\babelprovide[hyphenrules=+]{neo}
\babelpatterns[neo]{a1 e1 i1 o1 u1}
\end{verbatim}
In other engines it just suppresses hyphenation (because the pattern
list is empty).
\New{3.58} Another special value is |unhyphenated|, which is an
alternative to |justification=unhyphenated|.
\Describe{main}{} This valueless option makes the language the main one
(thus overriding that set when \babel\ is loaded).
\begin{example}
Let's assume your document (\luatex{} or \xetex{}) is mainly in
Polytonic Greek but with some sections in Italian. Then, the
first attempt should be:
\begin{verbatim}
\usepackage[italian, greek.polutoniko]{babel}
\end{verbatim}
But if, say, accents in Greek are not shown correctly, you can try
\begin{verbatim}
\usepackage[italian, polytonicgreek, provide=*]{babel}
\end{verbatim}
Remember there is an alternative syntax for the latter:
\begin{verbatim}
\usepackage[italian]{babel}
\babelprovide[import, main]{polytonicgreek}
\end{verbatim}
Finally, also remember you might not need to load |italian| at all if
there are only a few word in this language (see~\ref{mostlymono}).
\end{example}
\Describe{script=}{\meta{script-name}}
\New{3.15} Sets the script name to be used by \textsf{fontspec} (e.g.,
|Devanagari|). Overrides the value in the |ini| file. If
\textsf{fontspec} does not define it, then \babel{} sets its tag to
that provided by the |ini| file. This value is particularly important
because it sets the writing direction, so you must use it if for some
reason the default value is wrong.
\Describe{language=}{\meta{language-name}} \New{3.15}
Sets the language name to be used by \textsf{fontspec} (e.g., |Hindi|).
Overrides the value in the |ini| file. If \textsf{fontspec} does not
define it, then \babel{} sets its tag to that provided by the |ini|
file. Not so important, but sometimes still relevant.
\Describe{alph=}{\meta{counter-name}} Assigns to |\alph| that counter.
See the next section.
\Describe{Alph=}{\meta{counter-name}} Same for |\Alph|.
\Describe{casing=}{\meta{rules}} \New{3.90} Selects the casing rules in a few
languages. The first ones are predefined by \LaTeX{} (see
\textsf{interface3.pdf}), while the following are defined by \babel:
\begin{description}
\item[Armenian] |yiwn| maps U+0587 to capital ech and yiwn on
uppercasing.
\item[German] |eszett| maps the lowercase \textit{Eszett} to a
\textit{großes Eszett}.
\item[Greek] |iota| converts the \textit{ypogegrammeni} (subscript muted
iota) to capital iota when uppercasing.
\item[Latin] |nouv| in |classicallatin| and |medievallatin| reverts
the default rules, which maps u $\leftrightarrow$ V; |uv| in
|ecclesiasticallatin| and the basic |latin| locale applies the map
u $\leftrightarrow$ V (by default it’s u $\leftrightarrow$ U and v
$\leftrightarrow$ V).
\end{description}
\begin{example} For the latter:
\begin{verbatim}
\usepackage[greek]{babel}
\babelprovide[_casing=iota_]{greek}
\end{verbatim}
\end{example}
\smallskip
\makebox[\linewidth][c]{*\qquad*\qquad*}
\smallskip
A few options (only \luatex) set some properties of the writing system
used by the language. These properties are \textit{always} applied to
the script, no matter which language is active. Although somewhat
inconsistent, this makes setting a language up easier in most typical
cases.
\Describe{onchar=}{\texttt{ids} $\string|$ \texttt{fonts}
$\string|$ \texttt{letters}}
\New{3.38} This option is much like an ‘event’ called when a character
belonging to the script of this locale is found (as its name implies,
it acts on characters, not on spaces).
This option is particularly useful in pure Unicode multilingual text,
because you can intermingle with no explicit markup differents scripts,
each of which with its own hyphenation rules and font, and even its
characteristic writing direction.
There are currently 3 ‘actions’, which can be used at the same time
(separated by spaces):
\begin{itemize}
\item With |ids|, both |\language| and |\localeid| are set to the values
associated with this locale, affecting the hyphenation rules, as well
as any transforms declared for it.
\item With |fonts|, the fonts are switched to those specified for this
locale (as set with |\babelfont|). Characters assigned to a locale can
be customized with |\babelcharproperty|.
\item \New{3.81} Option |letters| restricts the ‘actions’ to letters, in
the \TeX{} sense (i.e., with catcode 11). Digits and punctuation are
then considered part of current locale (as set by a selector). This
option is useful when the main script is non-Latin and there is a
secondary one whose script is Latin.
\end{itemize}
\begin{note}
An alternative approach with \luatex{} and Harfbuzz is the font
option |RawFeature={multiscript=auto}|. It does not switch the
\babel{} language and therefore the line breaking rules, but in many
cases it can be enough.
\end{note}
\begin{note}
\newcommand\artxt[1]{{%
\fontspec[Script=Arabic]{FreeSerif}\textdir TRT #1}}
There is no general rule to set the font for a punctuation mark,
because it is a semantic decision and not a typographical one.
Consider the following sentence: “\artxt{یک}, \artxt{دو}, and
\artxt{سه} are Persian numbers”. In this case the punctuation font
must be the English one, even if the commas are surrounded by
non-Latin letters. Quotation marks, parenthesis, etc., are even more
complex. Several criteria are possible, like the main language (the
default in \babel), the first letter in the paragraph, or the
surrounding letters, among others, but even so manual switching can
still be necessary.
\end{note}
\Describe{transforms=}{\meta{transform-list}}
See section~\ref{transforms}.
\Describe{interchar=}{\meta{interchar-list}}
See section~\ref{interchar}.
\begin{note}
(1) If you need shorthands, you can define them with |\useshorthands|
and |\defineshorthand| as described above. (2) Captions and |\today|
are “ensured” with |\babelensure| (this is the default in
|ini|-based languages).
\end{note}
\begin{example} When creating a locale from another locale, you may want
to reset some properties, like the BCP 47 tags. Here is an example of
how to do it:
\begin{verbatim}
\babelprovide{spanish} % import=es by default
\babelprovide[
import=es,
_identification/tag.bcp47 = es-x-medieval_,
_identification/extension.x.tag.bcp47 = medieval_]
{medievalspanish}
\end{verbatim}
\end{example}
\section{Locale features}
\subsection{Hyphenation and line breaking – 1. Commands}
\Babel{} deals with three kinds of line breaking rules: Western,
typically the LGC group, South East Asian, like Thai, and CJK, but
support depends on the engine: \textsf{pdftex} only deals with the
former, \xetex{} also with the second one (although in a limited way)
and CJK, while \luatex{} provides basic rules for all of them, as well
as additional rules (like Uyghur and Tibetan). With \luatex{} there are
also tools for non-standard hyphenation and line breaking rules,
explained in the next section.
\Describe{\babelhyphenation}{\texttt{[}\langlist\texttt{]}%
\marg{exceptions}}
\New{3.9a} Sets hyphenation exceptions for the languages given
or, without the optional argument, for \textit{all} languages (e.g.,
proper nouns or common loan words, and of course monolingual
documents). Multiple declarations work much like |\hyphenation| (last
wins), but language exceptions take precedence over global ones.
It can be used only in the preamble, and exceptions are set when the
language is first selected, thus taking into account changes of
|\lccodes|'s done in |\extras<language>| as well as the language-specific
encoding (not set in the preamble by default). For example:
\begin{verbatim}
\babelhyphenation{Wal-hal-la Dar-bhan-ga}
\end{verbatim}
Listed words are saved expanded and therefore it relies on the
LICR\@. Of course, it also works without the LICR if the input and the
font encodings are the same, like in Unicode based engines.
\begin{note}
Using |\babelhyphenation| with Southeast Asian scripts is mostly
pointless. But with |\babelpatterns| (below) you may fine-tune line
breaking (only \luatex). For example:
\begingroup
\catcode`@=13
\def@#1@{{\fontspec{Loma}#1}}
\begin{verbatim}
\babelpatterns[thai]{@ศึก@2@ษา@}
\end{verbatim}
\endgroup
Even if there are no patterns for the language, you can add at least
some typical cases.
\end{note}
\begin{note}
Use |\babelhyphenation| instead of |\hyphenation| to set hyphenation
exceptions in the preamble before any language is explicitly set with
a selector. In the preamble the hyphenation rules are not always
fully set up and an error can be raised.
\end{note}
\Describe{\babelpatterns}{\texttt{[}\langlist\texttt{]}%
\marg{patterns}}
\New{3.9m} \textit{In \textsf{luatex} only},\footnote{With
\textsf{luatex} exceptions and patterns can be modified almost
freely. However, this is very likely a task for a separate package
and \texttt{babel} only provides the most basic tools.} adds or
replaces patterns for the languages given or, without the optional
argument, for \textit{all} languages. If a pattern for a certain
combination already exists, it gets replaced by the new one.
It can be used only in the preamble, and patterns are added when the
language is first selected, thus taking into account changes of
|\lccodes|’s done in |\extras<language>| as well as the language-specific
encoding (not set in the preamble by default). Multiple
|\babelpatterns|’s are allowed.
Listed patterns are saved expanded and therefore it relies on the
LICR\@. Of course, it also works without the LICR if the input and the
font encodings are the same, like in Unicode based engines.
\New{3.31} (Only \luatex.) With |\babelprovide| and |import|ed CJK
languages, a simple generic line breaking algorithm (push-out-first) is
applied, based on a selection of the Unicode rules (\New{3.32} it is
disabled in verbatim mode, or more precisely when the hyphenrules
are set to |nohyphenation|). It can be activated alternatively by
setting explicitly the |intraspace|.
\New{3.27} Interword spacing for Thai, Lao and Khmer is activated
automatically if a language with one of those scripts is loaded with
|\babelprovide|. See the sample on the \babel{} repository. With both
Unicode engines, spacing is based on the “current” em unit (the size
of the previous char in \luatex, and the font size set by the last
|\selectfont| in \xetex).
\begin{note}
With Unicode engines, a line break can happen just before an explicit
combining char (e.g., \textit{\~{g}}, used in Guarani and Filipino, is
not included as a combined char and it’s represented in Unicode as
|U+0067|~|U+0303|. This issue is not directly related to \babel, but
to the hyphenation patterns and/or the font renderer. However, at
least with \luatex{} there is a workaround (change the language name
to what you are using):
\begin{verbatim}
\babelposthyphenation{guarani}{ | [{0300}-{036F}] }{ remove, {} }
\end{verbatim}
The Lua pattern means ‘a discretionary followed by a character in the
range |U+0300|--|U+0367| (which contains combining chars)’. An
alternative to a transform is |\babelpatterns|.
\end{note}
\Describe{\babelhyphenmins}{%
\optstar\texttt{[}\langlist\texttt{]}%
\marg{left}\marg{right}\oarg{hyphenationmin}}
\New{24.10} See the news page for the rationale for this command. It
sets the corresponding values for the given languages (all languages
without the optional argument). With the star, the values are also
applied immediately (the optional argument and the star are currently
incompatible). The optional argument is available only in \luatex.
\begin{example}
You are typesetting a book with wide lines and want to limit the
number of hyphens in all languages:
\begin{verbatim}
\babelhyphenmins{3}{4}
\end{verbatim}
But there is also some 3-column text and you want to be more flexible:
\begin{verbatim}
\begin{multicols}{3}
\babelhyphenmins*{2}{3}
...
\end{multicols}
\end{verbatim}
\end{example}
\Describe{\babelhyphen}{\optstar\marg{type}}
\DescribeOther{\babelhyphen}{\optstar\marg{text}}
\New{3.9a} It is customary to classify hyphens in two types: (1)
\textit{explicit} or \textit{hard hyphens}, which in \TeX\ are
entered as \verb|-|, and (2) \textit{optional} or \textit{soft
hyphens}, which are entered as \verb|\-|. Strictly, a \textit{soft
hyphen} is not a hyphen, but just a breaking opportunity or, in
\TeX\ terms, a “discretionary”; a \textit{hard hyphen} is a hyphen
with a breaking opportunity after it. A further type is a
\textit{non-breaking hyphen}, a hyphen without a breaking
opportunity.
In \TeX, \verb|-| and \verb|\-| forbid further breaking opportunities
in the word. This is the desired behavior very often, but not always,
and therefore many languages provide shorthands for these
cases. Unfortunately, this has not been done consistently: for
example, \verb|"-| in Dutch, Portuguese, Catalan or Danish is a hard
hyphen, while in German, Spanish, Norwegian, Slovak or Russian it is a
soft hyphen. Furthermore, some of them even redefine |\-|, so that you
cannot insert a soft hyphen without breaking opportunities in the rest
of the word.
Therefore, some macros are provided with a set of basic “hyphens”
which can be used by themselves, to define a user shorthand, or even
in language files.
\begin{itemize}
\item |\babelhyphen{soft}| and |\babelhyphen{hard}| are self
explanatory.
\item |\babelhyphen{repeat}| inserts a hard hyphen which is repeated
at the beginning of the next line, as done in languages like
Polish, Portuguese and Spanish.
\item |\babelhyphen{nobreak}| inserts a hard hyphen without a break
after it (even if a space follows).
\item |\babelhyphen{empty}| inserts a break opportunity without
a hyphen at all.
\item |\babelhyphen|\marg{text} is a hard “hyphen” using \m{text}
instead. A typical case is |\babelhyphen{/}|.
\end{itemize}
With all of them, hyphenation in the rest of the word is enabled. If
you don't want to enable it, there is a starred counterpart:
|\babelhyphen*{soft}| (which in most cases is equivalent to the
original |\-|), |\babelhyphen*{hard}|, etc.
Note |hard| is also good for isolated prefixes (e.g., \textit{anti-})
and |nobreak| for isolated suffixes (e.g., \textit{-ism}), but in both
cases |\babelhyphen*{nobreak}| is usually better.
There are also some differences with \LaTeX: (1) the character used is
that set for the current font, while in \LaTeX{} it is hardwired to
|-| (a typical value); (2) the hyphen to be used in fonts with a
negative |\hyphenchar| is |-|, as in \LaTeX, but it can be changed to
another value by redefining |\babelnullhyphen|; (3) a break after the
hyphen is forbidden if preceded by a glue ${>}0$~pt (at the beginning
of a word, provided it is not immediately preceded by, say, a
parenthesis).
\Describe{\begin\menv{hyphenrules}}{\marg{language}\Eenv{hyphenrules}}
The environment \Lenv{hyphenrules} can be used to select \emph{only} the
hyphenation rules to be used (it can be used as command, too). This can
for instance be used to select ‘nohyphenation’, provided that in
\file{language.dat} the ‘language’ \textsf{nohyphenation} is defined by
loading \file{zerohyph.tex}. It deactivates language shorthands, too
(but not user shorthands).
Except for these simple uses, |hyphenrules| is deprecated and
|otherlanguage*| (the starred version) is preferred, because the former
does not take into account possible changes in encodings of characters
like, say, |'| done by some languages (e.g., \textsf{italian},
\textsf{french}, \textsf{ukrainian}).
\begin{note}
For the hyphenation to work correctly, lccodes cannot change, because
\TeX{} only takes into account the values when the paragraph is
hyphenated, i.e., when it has been finished.\footnote{This explains
why \LaTeX{} assumes the lowercase mapping of T1 and does not provide
a tool for multiple mappings. Unfortunately, \cs{savinghyphcodes} is
not a solution either, because lccodes for hyphenation are frozen in
the format and cannot be changed.} So, if you write a chunk of French
text with |\foreignlanguage|, the apostrophes might not be taken into
account. This is a limitation of \TeX, not of \babel. Alternatively,
you may use |\useshorthands| to activate |'| and |\defineshorthand|,
or redefine |\textquoteright| (the latter is called by the non-ASCII
right quote).
\end{note}
\subsection{Hyphenation and line breaking – 2. ‘Provide’ options}
\Describe{justification=}{\texttt{unhyphenated} $\string|$
\texttt{kashida} $\string|$ \texttt{elongated} $\string|$
\texttt{padding}}
\New{3.59} There are currently 4 options. Note they are language
dependent, so that they will not be applied to other languages.
The first one (|unhyphenated|) activates a line breaking mode that
allows breaks only at spaces, which can be stretched to arbitrary
amounts. Although for European standards the result may look odd, in
some writing systems, like Malayalam and other Indic scripts, this has
been the customary (although not always the desired) practice. Because
of that, no locale enables currently this mode by default (Amharic is an
exception). Unlike |\sloppy|, the |\hfuzz| and the |\vfuzz| are not
changed, because this line breaking mode is not really ‘sloppy’ (in
other words, overfull boxes are reported as usual).
The second and the third are for the Arabic script. It sets the
linebreaking and justification method, which can be based on the
\textsc{arabic tatweel} character or in the ‘justification
alternatives’ OpenType table (\texttt{jalt}). For an explanation see
the
\href{
https://latex3.github.io/babel/news/whats-new-in-babel-3.59.html}%
{\babel\ site}.
\New{3.81} The option |padding| has been devised primarily for Tibetan.
It’s still somewhat experimental. Again, there is an explanation in the
\href{
https://latex3.github.io/babel/news/whats-new-in-babel-3.81.html}%
{\babel\ site}.
\Describe{linebreaking=}{}
\New{3.59} Just a synonymous for \texttt{justification}. Depending on
the language, this name can make more sense.
\Describe{intraspace=}{\meta{base} \meta{shrink} \meta{stretch}}
Sets the interword space for the writing system of the language, in em
units (so, |0 .1 0| is |0em plus .1em|). Like |\spaceskip|, the em unit
applied is that of the current text (more precisely, the previous
glyph). Currently used only in Southeast Asian scripts, like Thai, and
CJK.
\Describe{intrapenalty=}{\meta{penalty}}
Sets the interword penalty for the writing system of this language.
Currently used only in Southeast Asian scripts, like Thai. If 0, which
is the default value, no penalty is inserted.
\subsection{Shorthands – 1. Commands}
A \textit{shorthand} is a sequence of one or two characters that
expands to arbitrary \TeX{} code.
Shorthands can be used for different kinds of things; for example:
(1) in some languages shorthands such as |"a| are defined to be able
to hyphenate the word if the encoding is |OT1|; (2) in some languages
shorthands such as |!| are used to insert the right amount of white
space; (3) several kinds of discretionaries and breaks can be inserted
easily with |"-|, |"=|, etc.
The package \textsf{inputenc} as well as \luatex{} and \xetex{} have
alleviated entering non-ASCII characters, but minority languages and
some kinds of text can still require characters not directly available
on the keyboards (and sometimes not even as separated or precomposed
Unicode characters). As to the point 2, now \textsf{pdfTeX} provides
|\knbccode|, and \luatex{} can manipulate the glyph list. Tools for
point 3 can still be very useful in general.
There are four levels of shorthands: \textit{user}, \textit{language},
\textit{system}, and \textit{language user} (by order of precedence).
In most cases, you will use only shorthands provided by languages.
\begin{note} Keep in mind the following:
\begin{enumerate}
\item Activated chars used for two-char shorthands cannot be followed
by a closing brace |}| and the spaces following are gobbled. With
one-char shorthands (e.g.,~|:|), they are preserved.
\item If on a certain level (system, language, user, language user)
there is a one-char shorthand, two-char ones starting with that char
and on the same level are ignored.
\item Since they are active, a shorthand cannot contain the same
character in its definition (except if deactivated with, e.g.,
|\string|).
\end{enumerate}
\end{note}
\begin{troubleshooting}
\trouble{Argument of \textbackslash language@active@arg"
has an extra \textbraceright}
A typical error when using shorthands is the following:
\begin{verbatim}
! Argument of \language@active@arg" has an extra }.
\end{verbatim}
It means there is a closing brace just after a shorthand, which is not
allowed (e.g.,~|"}|). Just add |{}| after (e.g.,~|"{}}|).
\end{troubleshooting}
\Describe{\shorthandon}{\marg{shorthands-list}}
\DescribeOther{\shorthandoff}{\optstar\marg{shorthands-list}}
It is sometimes necessary to switch a shorthand
character off temporarily, because it must be used in an
entirely different way. For this purpose, the user commands
|\shorthandoff| and |\shorthandon| are provided. They each take a
list of characters as their arguments.
The command |\shorthandoff| sets the |\catcode| for each of the
characters in its argument to other (12); the command |\shorthandon|
sets the |\catcode| to active (13). Both commands work on only `known'
shorthand characters, and an error will be raised otherwise. You can
check if a character is a shorthand with |\ifbabelshorthand| (see
below).
\New{3.9a} However, |\shorthandoff| does not behave as
you would expect with characters like |~| or |^|, because they
usually are not “other”. For them |\shorthandoff*| is provided,
so that with
\begin{verbatim}
\shorthandoff*{~^}
\end{verbatim}
|~| is still active, very likely with the meaning of a non-breaking
space, and |^| is the superscript character. The catcodes used are
those when the shorthands are defined, usually when language files are
loaded.
If you do not need shorthands, or prefer an alternative approach of
your own, you may want to switch them off with the package option
|shorthands=off|, as described below.
\begin{warning}
It is worth emphasizing that these macros are meant for temporary changes.
Whenever possible, shorthands must be always enabled or disabled.
\end{warning}
\Describe{\useshorthands}{\optstar\marg{char}}
It initiates the definition of user-defined
shorthand sequences. It has one argument, the character that starts
these personal shorthands.
\New{3.9a} User shorthands are not always alive, as they may
be deactivated by languages (for example, if you use |"| for your user
shorthands and switch from \textsf{german} to \textsf{french}, they
stop working). Therefore, a starred version
|\useshorthands*|\marg{char} is provided, which makes sure shorthands
are always activated.
If the package option |shorthands| is used, you must include any
character to be activated with |\useshorthands|.
\Describe\defineshorthand{\texttt{[}\langlist\texttt{]}%
\marg{shorthand}\marg{code}}
It takes two arguments: the first is a one- or two-character shorthand
sequence, and the second is the code the shorthand should expand to.
\New{3.9a} An optional argument allows to (re)define language and
system shorthands (some languages do not activate shorthands, so you
may want to add |\languageshorthands|\marg{language} to the corresponding
|\extras<language>|, as explained below). By default, user shorthands
are (re)defined.
User shorthands override language ones, which in turn override system
shorthands. Language-dependent user shorthands take precedence over
“normal” user shorthands.
\begin{example}
Let's assume you want a unified set of shorthands for discretionaries
(languages do not define shorthands consistently, and |"-|, |\-|,
|"=| have different meanings). You can start with, say:
\begin{verbatim}
\useshorthands*{"}
\defineshorthand{"*}{\babelhyphen{soft}}
\defineshorthand{"-}{\babelhyphen{hard}}
\end{verbatim}
However, the behavior of hyphens is language-dependent. For example, in
languages like Polish and Portuguese, a hard hyphen inside compound
words are repeated at the beginning of the next line. You can then
set:
\begin{verbatim}
\defineshorthand[*polish,*portuguese]{"-}{\babelhyphen{repeat}}
\end{verbatim}
Here, options with |*| set a language-dependent user shorthand, which
means the generic declarations above for |"-| apply to all languages
\textit{except} |polish| and |portuguese|; without |*| they would
(re)define the language shorthands instead, which are overridden by
user ones.
Now, you have a single unified shorthand (|"-|), with a
content-based meaning (`compound word hyphen') whose visual behavior
is that expected in each context.
\end{example}
\Describe{\languageshorthands}{\marg{language}}
Used to switch the shorthands on the
language level. It takes one argument, the name of a language or
|none| (the latter does what its name suggests).\footnote{Actually,
any name not corresponding to a language group does the same as
\texttt{none}. However, follow this convention because it might be
enforced in future releases of \babel{} to catch possible errors.}
Note that for this to work the language should have been specified as
an option when loading the \babel\ package. For example, you can use
in \textsf{english} the shorthands defined by \textsf{ngerman} with
\begin{verbatim}
\addto\extrasenglish{\languageshorthands{ngerman}}
\end{verbatim}
(You may also need to activate them as user shorthands in the preamble
with, for example, |\useshorthands| or |\useshorthands*|.)
\begin{example}
Very often, this is a more convenient way to deactivate shorthands
than |\shorthandoff|, for example if you want to define a macro
to ease typing phonetic characters with \textsf{tipa}:
\begin{verbatim}
\newcommand{\myipa}[1]{{_\languageshorthands{none}_\tipaencoding#1}}
\end{verbatim}
\end{example}
\Describe{\babelshorthand}{\marg{shorthand}}
With this command you can use a shorthand even if (1) not activated in
\texttt{shorthands} (in this case only shorthands for the current
language are taken into account, i.e., not user shorthands), (2) turned
off with |\shorthandoff| or (3) deactivated with the internal
|\bbl@deactivate|; for example, \verb|\babelshorthand{"u}| or
\verb|\babelshorthand{:}|. (You can conveniently define your own
macros, or even your own user shorthands provided they do not overlap.)
\begin{example}
Since by default shorthands are not activated until
|\begin{document}|, you may use this macro when defining the |\title|
in the preamble:
\begin{verbatim}
\title{Documento científico_\babelshorthand{"-}_técnico}
\end{verbatim}
\end{example}
\bigskip
For your records, here is a list of shorthands, but you must double
check them, as they may change:\footnote{Thanks to Enrico Gregorio.}
\begin{description}
\itemsep=-\parskip
\item[Languages with no shorthands] Croatian, English (any variety),
Indonesian, Hebrew, Interlingua, Irish, Lower Sorbian, Malaysian,
North Sami, Romanian, Scottish, Welsh
\item[Languages with only \texttt{"} as defined shorthand character]
Albanian, Bulgarian, Danish, Dutch, Finnish, German (old and new
orthography, also Austrian), Icelandic, Italian, Norwegian, Polish,
Portuguese (also Brazilian), Russian, Serbian (with Latin script),
Slovene, Swedish, Ukrainian, Upper Sorbian
\item[Basque] |" ' ~|
\item[Breton] |: ; ? !|
\item[Catalan] |" ' `|
\item[Czech] |" -|
\item[Esperanto] |^|
\item[Estonian] |" ~|
\item[French] (all varieties) |: ; ? !|
\item[Galician] |" . ' ~ < >|
\item[Greek] (ancient, polutoniko, only 8-bit \TeX) |~|, (optional, see
the manual for Greek) |;|
\item[Hungarian] |`|
\item[Kurmanji] |^|
\item[Latin] |" ^ ' =|
\item[Slovak] |" ^ ' -|
\item[Spanish] |" . < > ' ~|
\item[Turkish] |: ! =|
\end{description}
In addition, the \babel{} core declares |~| as a one-char shorthand
which is let, like the standard |~|, to a non breaking space. Actually,
this declaration serves to nothing, but it is preserved for backward
compatibility.
\Describe\ifbabelshorthand{\marg{character}\marg{true}\marg{false}}
\New{3.23} Tests if a character has been made a shorthand.
\begin{note}
\catcode`\|=12\relax Both \textsf{ltxdoc} and \textsf{babel} use
\verb|\AtBeginDocument| to change some catcodes, and \babel{} reloads
\textsf{hhline} to make sure \verb|:| has the right one, so if you
want to change the catcode of \verb/|/ it has to be done using the
same method at the proper place, with
\begin{verbatim}
\AtBeginDocument{\DeleteShortVerb{\|}}
\end{verbatim}
\textit{before} loading \babel. This way, when the document begins
the sequence is (1) make \verb/|/ active (\textsf{ltxdoc}); (2) make
it inactive (your settings); (3) make \babel{} shorthands active
(\textsf{babel}); (4) reload \textsf{hhline} (\textsf{babel}, now
with the correct catcodes for \verb/|/ and
\verb|:|).\catcode`\|=\active
\end{note}
\begin{note}
Using a character mathematically active (i.e., with math code |"8000|) as
a shorthand can make \TeX{} enter in an infinite loop in some rare
cases. (There is a partial solution.)
\end{note}
\subsection{Shorthands – 2. Package options}
\Describe{activeacute}{}
\DescribeOther{activegrave}{}
For some languages \babel\ supports these options to set |'| and |`|,
respectively, as a shorthand in case it is not done by default.
\Describe{shorthands=}{\meta{char}\meta{char}...
$\string|$ \texttt{off}}
The only language shorthands activated
are those given, like, e.g.:
\begin{verbatim}
\usepackage[esperanto,french,_shorthands=:;!?_]{babel}
\end{verbatim}
If \verb|'| is included, \texttt{activeacute} is set; if \verb|`| is
included, \texttt{activegrave} is set. Active characters (like
\verb|~|) should be preceded by \verb|\string| (otherwise they will be
expanded by \LaTeX{} before they are passed to the package and
therefore they will not be recognized); however, |t| is provided for
the common case of |~| (as well as |c| for not so common case of the
comma).
With |shorthands=off| no language shorthands are defined.
As some languages use this mechanism for tools not available
otherwise, a macro \verb|\babelshorthand| is defined, which allows
using them; see above.
\Describe{safe=}{\texttt{none} $\string|$ \texttt{ref} $\string|$
\texttt{bib}} Some \LaTeX{} macros are redefined so that using
shorthands is safe. With \texttt{safe=bib} only |\nocite|, |\bibcite|
and |\bibitem| are redefined. With |safe=ref| only |\newlabel|, |\ref|
and |\pageref| are redefined (as well as a few macros from
\textsf{varioref} and \textsf{ifthen}).
With |safe=none| no macro is redefined. This option is strongly
recommended, because a good deal of incompatibilities and errors are
related to these redefinitions. As of \New{3.34}, in $\varepsilon$-\TeX{}
based engines (i.e., almost every engine except the oldest ones)
shorthands can be used in these macros (formerly you could not).
\Describe{math=}{\texttt{active} $\string|$ \texttt{normal}}
Shorthands are mainly intended for text, not for math. By setting this
option with the value |normal| they are deactivated in math mode
(default is |active|) and things like |${a'}$| (a closing brace after
a shorthand) are not a source of trouble anymore.
\subsection{Digits and counters}
\New{3.20} About thirty |ini| files define a field named
|digits.native|. When it is present, two macros are created:
|\<language>digits| and |\<language>counter| (only \luatex{} and
\xetex{}). With the first, a string of ‘Latin’ digits are converted to
the native digits of that language; the second takes a counter name as
argument. With the option |maparabic| in |\babelprovide|, |\arabic| is
redefined to produce the native digits (this is done \textit{globally},
to avoid inconsistencies in, for example, page numbering; note as
well dates do not rely on |\arabic|.)
For example:
\begin{verbatim}
\usepackage[telugu, provide=*]{babel}
% Or also, if you want, with:
% provide={ maparabic }
\babelfont{rm}{Gautami}
\begin{document}
_\telugudigits{1234}_
_\telugucounter{section}_
\end{document}
\end{verbatim}
Languages providing native digits in all or some variants are:
\begin{multicols}{5}
\parindent0pt
Arabic\\
Assamese\\
Bangla\\
Bhojpuri\\
Bodo\\
Burmese\\
Cantonese\\
Central Kurdish\\
Chinese\\
Dogri\\
Dzongkha\\
Gujarati\\
Haryanvi\\
Hindi\\
Hmong Njua\\
Kannada\\
Kashmiri\\
Khmer\\
Konkani\\
Korean\\
Lao\\
Maithili\\
Malayalam\\
Manipuri\\
Marathi\\
Mazanderani\\
Nepali\\
Northern Kurdish\\
Northern Luri\\
Odia\\
Pashto\\
Persian\\
Punjabi\\
Rajasthani\\
Sanskrit\\
Santali\\
Sindhi\\
Tamil\\
Telugu\\
Thai\\
Tibetan\\
Urdu\\
Uyghur\\
Uzbek\\
Vai
\end{multicols}
\New{3.30} With \luatex{} there is an alternative approach for mapping
digits, namely, |mapdigits|. Conversion is based on the language and it
is applied to the typeset text (not math, PDF bookmarks, etc.)\ before
bidi and fonts are processed (i.e., to the node list as generated by the
\TeX{} code). This means the local digits have the correct
bidirectional behavior (unlike |Numbers=Arabic| in \textsf{fontspec},
which is deprecated). Another option is the transform |digits.native|.
\begin{note}
With \xetex{} you can use the option |Mapping| when defining a
font.
\end{note}
\Describe{\localenumeral}{\marg{style}\marg{number}}
\DescribeOther{\localecounter}{\marg{style}\marg{counter}}
\New{3.41} Many |ini| locale files provide information
about non-positional numerical systems, based on those predefined in
CSS\@. They only work with \luatex{} and \xetex{} and are fully
expandable (even inside an unprotected |\edef|). Currently, they are
limited to numbers below 10000.
There are several ways to use them (for the available styles in each
language, see the list below):
\begin{itemize}
\item |\localenumeral|\marg{style}\marg{number}, like
|\localenumeral{abjad}{15}|
\item |\localecounter|\marg{style}\marg{counter}, like
|\localecounter{lower}{section}|
\item In |\babelprovide|, as an argument to the keys |alph| and |Alph|,
which redefine what |\alph| and |\Alph| print. For example:
\begin{verbatim}
\babelprovide[_alph=alphabetic_]{thai}
\end{verbatim}
\end{itemize}
The styles are:
\begin{description}
\itemsep=-\parskip
\item[Ancient Greek] |lower.ancient|, |upper.ancient|
\item[Amharic] |afar|, |agaw|, |ari|, |blin|, |dizi|, |gedeo|, |gumuz|,
|hadiyya|, |harari|, |kaffa|, |kebena|, |kembata|, |konso|, |kunama|,
|meen|, |oromo|, |saho|, |sidama|, |silti|, |tigre|, |wolaita|, |yemsa|
\item[Arabic] |abjad|, |maghrebi.abjad|
\item[Armenian] |lower.letter|, |upper.letter|
\item[Belarusan, Bulgarian, Church Slavic, Macedonian, Serbian] |lower|, |upper|
\item[Bangla] |alphabetic|
\item[Central Kurdish] |alphabetic|
\item[Chinese] |cjk-earthly-branch|, |cjk-heavenly-stem|,
|circled.ideograph|, |parenthesized.ideograph|,
|fullwidth.lower.alpha|, |fullwidth.upper.alpha|
\item[Church Slavic (Glagolitic)] |letters|
\item[Coptic] |epact|, |lower.letters|
\item[French] |date.day| (mainly for internal use).
\item[Georgian] |letters|
\item[Greek] |lower.modern|, |upper.modern|, |lower.ancient|,
|upper.ancient| (all with keraia)
\item[Hebrew] |letters| (\New{3.93} if the language is loaded
explicitly, also |letters.plain|, |letters.gershayim|, |letters.final|)
\item[Hindi] |alphabetic|
\item[Italian] |lower.legal|, |upper.legal|
\item[Japanese] |hiragana|, |hiragana.iroha|, |katakana|,
|katakana.iroha|, |circled.katakana|, |informal|, |formal|,
|cjk-earthly-branch|, |cjk-heavenly-stem|, |circled.ideograph|,
|parenthesized.ideograph|, |fullwidth.lower.alpha|,
|fullwidth.upper.alpha|
\item[Khmer] |consonant|
\item[Korean] |consonant|, |syllable|, |hanja.informal|, |hanja.formal|,
|hangul.formal|, |cjk-earthly-branch|, |cjk-heavenly-stem|,
|circled.ideograph|, |parenthesized.ideograph|,
|fullwidth.lower.alpha|, |fullwidth.upper.alpha|
\item[Marathi] |alphabetic|
\item[Persian] |abjad|, |alphabetic|
\item[Russian] |lower|, |lower.full|, |upper|, |upper.full|
\item[Syriac] |letters|
\item[Tamil] |ancient|
\item[Thai] |alphabetic|
\item[Ukrainian] |lower| , |lower.full|, |upper| , |upper.full|
\end{description}
\New{3.45} In addition, native digits (in languages defining them) may
be printed with the numeral style |digits|.
\New{25.12} With |mapdot=|\m{text} as an option in ‘provide’, the
standard counters (those starting with |\the...|) are traversed to
replace each dot by the provided \m{text} in a locale-dependent way.
Without a value, a default is used — currenty the only default value is
for the Arabic (\texttt{ar}) locales, which is set to a hyphen (because
the zero and the dot are very similar in this script). See the news
page for further details.
\subsection{Dates}
\New{3.45} When the data is taken from an |ini| file, you may print the
date corresponding to the Gregorian calendar and other lunisolar systems
with the following command.
\Describe{\localedate}{\oarg{calendar=.., variant=.., convert}%
{\marg{year}\marg{month}\marg{day}}}
By default the calendar is the Gregorian, but an |ini| file may define
strings for other calendars: |am| (|ethiopic|), |ar| and
|ar-|* (|islamic|), |cop| (|coptic|), |fa| (|islamic|, |persian|), |he|
(|hebrew|), |hi| (|indian|), |th| (|buddhist|).
In the latter case, the three arguments are the year, the month, and
the day for those in the corresponding calendar. They are \textit{not}
the Gregorian date to be converted (which means, say, 13 is a valid
month number with |calendar=hebrew| and |calendar=coptic|). However,
with the option |convert| it’s converted (using internally the
following command).
Even with a certain calendar there may be variants. In Kurmanji the
default variant prints something like \textit{30. Çileya Pêşîn 2019},
but with |variant=izafa| it prints \textit{31’ê Çileya Pêşînê 2019}.
The default calendar for a language can be set in |\babelprovide|, with
the key |calendar| (an empty value is the same as |gregorian|). In this
case, |\today| always converts the date. Variants are preceded by a
dot, so that |calendar = .genitive| in |serbian| |\today| selects the
date in this variant (more explicitly is |gregorian.genitive|).
\begin{example}
By default, |thai| prints the date with |\today| in the Buddhist
calendar, but if you need a date in the Gregorian one, write:
\begin{verbatim}
\localedate[calendar=gregorian]{\year}{\month}{\day}
\end{verbatim}
(Remember |\year|, |\month| and |\day| is the current Gregorian date,
so no conversion is necessary.)
\end{example}
\begin{example}
On the other hand (and following the CLDR), the preferred calendar in
most locales for Arabic is |gregorian| (in |ar-SA| is
|islamic-umalqura|), so to set |islamic-civil| as the
default one:
\begin{verbatim}
\babelprovide[import, calendar=islamic-civil]{arabic}
\end{verbatim}
\end{example}
\Describe{\babelcalendar}{\oarg{date}%
\marg{calendar}\marg{year-macro}\m{month-macro}\m{day-macro}}
\New{3.76} Although calendars aren’t the primary concern of \babel, the
package should be able to, at least, generate correctly the current
date in the way users would expect in their own culture. Currently,
|\localedate| can print dates in a few calendars (provided the
\textsf{ini} locale file has been imported), but year, month and day
had to be entered by hand, which is inconvenient. With this macro,
the current date is converted and stored in the three last arguments,
which must be macros. Allowed calendars are:
\begin{multicols}{4}
|buddhist|\\
|chinese| \New{3.94}\\
|coptic|\\
|ethiopic|\\
|hebrew|\\
|islamic-civil|\\
|islamic-umalqura|\\
|persian|
\end{multicols}
The optional argument converts the given date, in the form
‘\m{year}-\m{month}-\m{day}’, although for practical reasons most
calendars accept only a restricted range of years. Please, refer to the
page on the news for 3.76 in the \babel{} site for further details.
\subsection{Transforms}
\label{transforms}
Transforms (only \luatex) provide a way to process the text on the
typesetting level in several language-dependent ways, like non-standard
hyphenation, special line breaking rules, script to script conversion,
spacing conventions and so on.
\begin{note}
They are similar in concept, but not the same, as those in Unicode.
Actually, the main inspiration for this feature is the Omega
transformation processes.
\end{note}
It currently embraces |\babelprehyphenation| and
|\babelposthyphenation|.
\New{3.57} Several \textsf{ini} files predefine some transforms. They
are activated with the key |transforms| in |\babelprovide|, either if
the locale is being defined with this macro or the languages has been
previously loaded as a class or package option, as the following example
illustrates:
\begin{verbatim}
\usepackage[hungarian]{babel}
\babelprovide[_transforms = digraphs.hyphen_]{hungarian}
\end{verbatim}
\New{3.67} Transforms predefined in the |ini| locale files can be made
attribute-dependent, too. When an attribute between parenthesis is
inserted subsequent transforms will be assigned to it (up to the list
end or another attribute). For example,
and provided an attribute called |\withsigmafinal| has been declared:
\begin{verbatim}
transforms = transliteration.omega (\withsigmafinal) sigma.final
\end{verbatim}
This applies |transliteration.omega| always, but |sigma.final| only when
|\withsigmafinal| is set.
Here are the transforms currently predefined. (A few may still require
some fine-tuning. More to follow in future releases.)
\begingroup
\def\trans#1#2#3{%
\vspace{1.5mm}%
\parbox[t]{2.2cm}{\raggedright\strut#1}%
\hspace{2mm}%
\parbox[t]{4.0cm}{\strut\ttfamily#2}%
\hspace{2mm}%
\parbox[t]{6.6cm}{\strut#3}\par}
\bigskip\hrule\nobreak\vspace{.5mm}\parindent0pt
\trans{}{digits.native}{\New{24.9} An alternative to |mapdigits|,
available in the same locales. This transform is applied before the
first prehyphenation, while |mapdigits| is applied after the last
posthyphenation. Another difference is |mapdigits| cannot be disabled
in the middle of a paragraph. (This transform is \textit{not} declared
explicitly in |ini| files. Instead, it’s defined by |babel| if the key
\texttt{numbers/digits.native} exists.)}
\trans{Arabic}{transliteration.dad}{Applies the transliteration system
devised by Yannis Haralambous for \textsf{dad} (simple and
\TeX-friendly). Not yet complete, but sufficient for most texts.}
\trans{Arabic, Persian}{kashida.base}{\New{3.94}. Much like the
following, but with diacritics stacked in the actual base character and
not the kashida extension. With evenly inserted tatweels results are
better.}
\trans{Arabic, Persian}{kashida.plain}{A very simple and basic
transform for ‘plain’ Arabic fonts, which attempts to distribute the
tatweel as evenly as possible (starting at the end of the line). See
the news for version 3.59.}
\trans{Chinese, Japanese}{input.nospaces}{With it, and just for
convenience, spaces (and new lines) in the input are ignored.}
\trans{Chinese, Japanese}{spacing.basic}{Basic rules for readjusting
spacing. See \New{25.6} for further details.}
\trans{Croatian}{digraphs.ligatures}{Ligatures \textit{DŽ}, \textit{Dž},
\textit{dž}, \textit{LJ}, \textit{Lj}, \textit{lj}, \textit{NJ},
\textit{Nj}, \textit{nj}. It assumes they exist. This is not the
recommended way to make these transformations (the best way is with
OTF features), but it can get you out in a hurry.}
\trans{Croatian, Czech, Polish, Portuguese, Slovak,
Spanish}{hyphen.repeat}{Explicit hyphens behave like
|\string\babelhyphen|\allowbreak|\{repeat\}|.}
\trans{Czech, Polish, Slovak}{oneletter.nobreak}{Converts a space after
a non-syllabic preposition or conjunction into a non-breaking space.}
\trans{Dutch}{diaeresis.hyphen}{Removes the diaeresis above a vowel if
hyphenated just before.}
\trans{Finnish}{prehyphen.nobreak}{Line breaks just after hyphens
prepended to words are prevented, as in “pakastekaapit ja -arkut”.}
\trans{French}{punctuation.space}{Rules for proper spacing with
characters \textit{;:!?«»} are applied.}
\trans{German}{longs.unifraktur}{Implements the basic heuristic rules
for the long s (ſ) from those in Unifraktur Maguntia. Although
discretionaries aren’t taken into account, the transform is declared in
the posthyphenation group, to ease if necessary fine tuning the rules
for, e.g., prefixes and compound words. They are available in all
German locales. See \New{25.5} for further details and an example.}
\trans{Greek}{diaeresis.hyphen}{Removes the diaeresis above iota and
upsilon if hyphenated just before. It works with the three variants.}
\trans{Greek}{transliteration.omega}{Although the provided combinations
are not the full set, this transform follows the syntax of Omega:
|=| for the circumflex, |v| for digamma, and so on. For better
compatibility with Levy’s system, \texttt{\string~} (as ‘string’) is an
alternative to |=|. |'| is tonos in Monotonic Greek, but oxia in
Polytonic and Ancient Greek.}
\trans{Greek}{sigma.final}{The transliteration system above does not
convert the sigma at the end of a word (on purpose). This transform
does it. To prevent the conversion (an abbreviation, for example), write
|"s|.}
\trans{Hebrew, Yiddish, Ladino, Ancient Hebrew}{transliteration.cj}{A
transliteration system based on that devised by Christian Justen for
`cjhebrew`. Final letters are not converted, and the furtive patah is
not shifted.}
\trans{Hebrew, Yiddish, Ladino, Ancient
Hebrew}{justification.interletter}{\hspace*{2em}Hebrew
justification is based on variations in the spacing between individual
letters within words. This transform activates this justification
method. See \New{25.8} for further details and an example.}
\trans{Hindi, Sanskrit}{punctuation.space}{Inserts a space before the
following four characters: \textit{!?:;}\,.}
\trans{Hindi, Sanskrit}{transliteration.hk}{The Harvard-Kyoto system to
romanize Devanagari.}
\trans{Hindi, Sanskrit}{transliteration.iast}{The IAST system to
romanize Devanagari (thanks to Maximilian Mehner).}
\trans{Hungarian}{digraphs.hyphen}{Hyphenates the long digraphs
\textit{ccs}, \textit{ddz}, \textit{ggy}, \textit{lly}, \textit{nny},
\textit{ssz}, \textit{tty} and \textit{zzs} as \textit{cs-cs},
\textit{dz-dz}, etc.}
\trans{Indic scripts}{danda.nobreak}{Prevents a line break before a
danda or double danda if there is a space. For Assamese, Bengali,
Gujarati, Hindi, Kannada, Malayalam, Marathi, Odia, Tamil, Telugu.}
\trans{Japanese}{linebreak.strict}{Prevents line breaks before small
kana variants.}
\trans{Latin}{digraphs.ligatures}{Replaces the groups \textit{ae},
\textit{AE}, \textit{oe}, \textit{OE} with \textit{æ}, \textit{Æ},
\textit{œ}, \textit{Œ}.}
\trans{Latin}{letters.noj}{Replaces \textit{j}, \textit{J} with
\textit{i}, \textit{I}.}
\trans{Latin}{letters.uv}{Replaces \textit{v}, \textit{U} with
\textit{u}, \textit{V}.}
\trans{Russian}{transliteration.gost779b}{The GOST 7.79-2000 System B for
the romanization of Russian. \New{25.10}}
\trans{Serbian}{transliteration.gajica}{(Note |serbian| with |ini|
files refers to the Cyrillic script, which is here the target.) The
standard system devised by Ljudevit Gaj.}
\vspace{2mm}\hrule\nobreak
\endgroup
\Describe{\babelposthyphenation}{\oarg{options}\marg{hyphenrules-name}%
\marg{lua-pattern}\marg{replacement}}
\New{3.37-3.39} \textit{With \luatex{}} it is possible to define
non-standard hyphenation rules, like |f-f| $\to$ |ff-f|, repeated
hyphens, ranked ruled (or more precisely, ‘penalized’ hyphenation
points), and so on. A few rules are currently provided (see above), but
they can be defined as shown in the following example, where |{1}| is
the first captured char (between |()| in the pattern):
\begin{verbatim}
\babelposthyphenation{german}{([fmtrp]) | {1}}
{
{ no = {1}, pre = {1}{1}- }, % Replace first char with disc
remove, % Remove automatic disc (2nd node)
{} % Keep last char, untouched
}
\end{verbatim}
In the replacements, a captured char may be mapped to another, too. For
example, if the first capture reads |([ΐΰ])|, the replacement could be
\verb+{1|ΐΰ|ίύ}+, which maps \textit{ΐ} to \textit{ί}, and \textit{ΰ}
to \textit{ύ}, so that the diaeresis is removed.
This feature is activated with the first |\babelposthyphenation| or
|\babelprehyphenation|.
\New{3.67} With the optional argument you can associate a user-defined
transform to an attribute, so that it’s active only when it’s set
(currently its attribute value is ignored). With this mechanism
transforms can be set or unset even in the middle of paragraphs, and
applied to single words. To define, set and unset the attribute, the
\LaTeX{} kernel provides the macros |\newattribute|, |\setattribute| and
|\unsetattribute|. The following example shows how to use it, provided
an attribute named |\latinnoj| has been declared:
\begin{verbatim}
\babelprehyphenation[attribute=\latinnoj]{latin}{ J }{ string = I }
\end{verbatim}
See the
\href{
https://latex3.github.io/babel/guides/%
non-standard-hyphenation-with-luatex.html}{\babel\ site} for a more
detailed description and some examples. It also describes a few
additional replacement types (|string|, |penalty|).
\New{3.85} Another option is |label|, which takes a value similar to
those in |\babelprovide| key |transforms| (in fact, the latter just
applies this option). This label can be used to turn on and off
transforms with a higher level interface, by means of
|\enablelocaletransform| and |\disablelocaletransform| (see below).
\New{3.85} When used in conjunction with |label|, this key makes a
transform font dependent. As an example, the rules for Arabic kashida
can differ depending on the font design. The value consists in a list
of space-separated font tags:
\begin{verbatim}
\babelprehyphenation[label=transform.name, fonts=rm sf]{..}{..}
\end{verbatim}
Tags can adopt two forms: a family, such as |rm| or |tt|, or the set
family/series/shape. If a font matches one of these conditions, the
transform is enabled. The second tag in |rm rm/n/it| is redundant.
There are no wildcards; so, for italics you may want to write something
like |sf/m/it sf/b/it|.
Transforms set for specific fonts (at least once in any language) are
always reset with a font selector.
In |\babelprovide|, transform labels can be tagged before their name,
with a list separated with colons, like:
\begin{verbatim}
transforms = _rm:sf:_transform.name
\end{verbatim}
Tranforms are executed in the same order they are declared. \New{25.9}
They can be also added at the beginning with the key |prepend|, which
is particularly useful with predefined transforms. For example:
\begin{verbatim}
\babelprehyphenation[prepend]{hebrew}{-}{ string = ־ } % hyphen to maqaf
\end{verbatim}
Although the main purpose of post-hyphenation transforms was
non-standard hyphenation, they may actually be used for other
transformations.
\Describe{\babelprehyphenation}{\oarg{options}\marg{locale-name}%
\marg{lua-pattern}\marg{replacement}}
\New{3.44-3-52} It is similar to the latter, but (as its name implies)
applied before hyphenation, which is particularly useful in
transliterations. There are other differences: (1) the first argument
is the locale instead of the name of the hyphenation patterns; (2) in the
search patterns |=| has no special meaning, while \verb+|+ stands for
an ordinary space; (3) in the replacement, discretionaries are not
accepted.
See the description above for the optional argument.
This feature is activated with the first |\babelposthyphenation| or
|\babelprehyphenation|.
\begin{example}
You can replace a character (or series of them) by another character
(or series of them). Thus, to enter \textit{ž} as |zh| and \textit{š}
as |sh| in a newly created locale for transliterated Russian:
\begin{verbatim}
\babelprovide[hyphenrules=+]{russian-latin} % Create locale
\babelprehyphenation{russian-latin}{([sz])h} % Create rule
{
string = _{1|sz|šž}_,
remove
}
\end{verbatim}
\end{example}
\begin{example}
The following rule prevent the word “a” from being at the
end of a line:
\begin{verbatim}
\babelprehyphenation{english}{|a|}
{}, {}, % Keep first space and a
{ insert, penalty = 10000 }, % Insert penalty
{} % Keep last space
}
\end{verbatim}
\end{example}
\begin{note}
With \luatex{} there is another approach to make text
transformations, with the function |fonts.handlers.otf.addfeature|,
which adds new features to an OTF font (substitution and
positioning). These features can be made language-dependent, and
\babel{} by default recognizes this setting if the font has been
declared with |\babelfont|. The \textit{transforms} mechanism
supplements rather than replaces OTF features.
With \xetex{}, where \textit{transforms} are not available, there is
still another approach, with font mappings, mainly meant to perform
encoding conversions and transliterations. Mappings, however, are
linked to fonts, not to languages.
\end{note}
\Describe{\enablelocaletransform}{\marg{label}}
\DescribeOther{\disablelocaletransform}{\marg{label}}
\New{3.85} Enables and disables the transform with the given label in
the current language. Font dependent transforms are always enabled and
cannot be disabled.
\Describe{\SetTrasformValue}{\marg{locale-name}\marg{variable-name}\marg{value}}
This command allows adjustments (specifically numeric parameters in
prehyphenation) in transform, which can be useful in those predeclared
in \texttt{ini} files. Something like
\verb+{<variable-name>|<default>}+
employs the variable as set by this macro. The following variables are
currently defined:
\begin{itemize}
\item For French and \texttt{punctuation.space}: \texttt{guillemet.natural},
\texttt{guillemet.plus}, \texttt{guillemet.minus},
\texttt{colon.natural}, \texttt{colon.plus}, \texttt{colon.minus},
\texttt{high.natural}, \texttt{high.plus}, \texttt{high.minus}. A
value of 1 is the current ordinary space. \New{24.13}
\item For languages in the Hebrew script and \texttt{justification.interletter}:
|interletter.plus|, which sets the factor for the glue ‘plus’ value. By
default, .5. \New{25.8}
\item For Japanese and \texttt{linebreak.strict}:
\texttt{small.natural}, \texttt{small.plus} and \texttt{small.minus}.
They are set when the transform is activated to the intraspace values.
In addition, the penalty, by default 10000, can be set with
\texttt{small.penalty}. \New{24.14}
\end{itemize}
\begin{example}
With:
\begin{verbatim}
\SetTransformValue{french}{colon.natural}{.8}
\end{verbatim}
the natural spacing with the colon is made slightly smaller (default is 1).
\end{example}
\Describe{\ShowBabelTransforms}{\marg{string}}
\New{25.7} Applies the current transforms to the string and shows in
the |log| the transformations performed. Don’t rely on the current
format, because it may change. In the process, penalties,
discretionaries, etc., can be inserted, which are currently printed as
a boxed ‘?’, as a boxed ‘US’ (because it’s the ‘unit separator’) or in
another way. With this macros you can better understand what’s going
on, so that you can debug the transforms. Use it only in the document
body.
\subsection{Support for \xetex{} interchar}
\label{interchar}
\New{3.97} A few macros are provided to deal with locale dependent
inter-character rules (aka ‘interchar’).
\Describe{\babelcharclass}{\marg{locale}\marg{name}\marg{char-list}}
Declares a new character class, which is assigned to the characters in
\marg{char-list}, entered either as characters or in macro form
(e.g.,~|\}|). If you need to enter them by their numeric value, use the
\TeX{} |^|-notation (e.g.,~|^^^^1fa0|). Ranges are allowed, with a
hyphen (e.g.,~|.,;a-zA-Z|). If you need the hyphen to be assigned a
class, write it at the very beginning of the list.
There are several predefined ‘global’ classes, namely |default|,
|cjkideogram|, |cjkleftpunctuation|, |cjkrightpunctuation|, |boundary|,
and |ignore|, which are described in the \xetex{} manual. These classes
are used by the |linebreak.basic|, described below.
\Describe{\babelinterchar}{\oarg{options}\marg{locale}
\marg{class-first}\marg{class-second}\marg{code}}
\marg{class-first} and \marg{class-second} can be comma separated lists
of char classes, and all combinations are defined (so that 2 first
classes with 2 second classes, define 4 combinations). In the
\meta{options} field a key named |label| is available, which allows to
enable or to disable the rule with the following two commands. Like
prehyphenation transforms in \luatex{}, interchars are not applied if the
current hyphenation rules are |nohyphenation|.
\Describe{\enablelocaleinterchar}{\marg{label}}
\DescribeOther{\disablelocaleinterchar}{\marg{label}}
Enable or disable the interchar rules with the given label for the
current language.
\begin{example}
Not very useful, but illustrative (taken from the unfortunately
obsolete \textsf{interchar} package, by Zou Ho), to colorize the
letters ‘x’ and ‘y’ (this way to group text is usually not a
good idea, however).
\begin{verbatim}
\usepackage{color}
\babelcharclass{english}{colored}{xy}
\babelinterchar{english}{default, boundary}{colored}{\bgroup\color{red}}
\babelinterchar{english}{colored}{default, boundary}{\egroup}
\end{verbatim}
A more realistic example follows, which inserts a thin space
between a digit and a percent sign. Note the former is entered as a
range, and the latter in command form:
\begin{verbatim}
\babelcharclass{english}{digit}{0-9}
\babelcharclass{english}{percent}{\%}
\babelinterchar[label=percent]{english}{digit}{percent}{\,}
\end{verbatim}
\end{example}
\begin{warning}
Keep in mind two points: (1) a character can be assigned a single
class; this is a limitation in the interchar mechanisms that often
leads to incompatibilities; (2) since the character classes set with
|\babelcharclass| are saved (so that they can be restored), there is a
limit in the number of characters in the \marg{char-list} (which,
however, must be large enough for many uses).
\end{warning}
\Describe{interchar=}{\meta{interchar-list}}
\New{24.1} This key in |\babelprovide| activates predefined rules for
the ‘provided’ locale. Currently the following |interchar|’s are defined:
\begingroup
\def\trans#1#2#3{%
\vspace{1.5mm}%
\parbox[t]{2.2cm}{\raggedright\strut#1}%
\hspace{2mm}%
\parbox[t]{4.0cm}{\strut\ttfamily#2}%
\hspace{2mm}%
\parbox[t]{6.6cm}{\strut#3}\par}
\bigskip\hrule\nobreak\vspace{.5mm}\parindent0pt
\trans{Cantonese, Chinese, Japanese,
Korean}{linebreak.basic}{\New{24.4} Basic settings for CJK
defined in (plain) \xetex. See the linked news page for details.}
\trans{French}{punctuation.space}{Rules for proper spacing with
characters \textit{;:!?«»} are applied.}
\vspace{2mm}\hrule\nobreak
\endgroup
\begin{warning}
This feature requires |import|.
\end{warning}
\begin{note}
You can use |transforms| and |interchar| at the same time. Only the
relevant key for the current engine is taken into account.
\end{note}
\subsection{Scripts}
\Babel{} provides no standard interface to select scripts, because they
are best selected with languages tied to them. In \pdftex, scripts are
indirectly managed by means of the low-level |\fontencoding|, whose
direct use is discouraged — even the Latin script may require different
encodings (i.e., sets of glyphs) depending on the language, and
therefore such a switch would be in a sense incomplete. Note the
so-called Unicode fonts (in \luatex\ and \xetex) do not improve the
situation either. So, a font suited for Vietnamese is not necessarily
suited for, say, the romanization of Indic languages, and the fact it
contains glyphs for Modern Greek does not mean it includes them for
Classic Greek.
\begin{note}
Some languages sharing the same script define macros to switch it
(e.g., |\textcyrillic|), but be aware they may also set the language
to a certain default. Even the \babel{} core defined |\textlatin|,
but it was somewhat buggy because in some cases it messed up
encodings and fonts (for example, if the main Latin encoding was
|LY1|), and therefore it has been deprecated (but still defined for
backwards compatibility).
\end{note}
The locales currently available cover the following scripts:
\begin{multicols}{4}
\parindent-.5em
\leftskip.5em
Arabic\\
Armenian\\
Bangla\\
Bengali\\
Cherokee\\
Coptic\\
Cyrillic\\
Devanagari\\
Egyptian hieroglyphs\\
Ethiopic\\
Georgian\\
Glagolitic\\
Gothic\\
Greek\\
Gujarati\\
Gurmukhi\\
Han\\
Hebrew\\
Japanese\\
Kannada\\
Khmer\\
Khojki\\
Khudawadi\\
Korean\\
Lao\\
Latin\\
Malayalam\\
Myanmar\\
Nyiakeng Puachue Hmong\\
N’Ko\\
Ol Chiki\\
Old Church Slavonic Cyrillic\\
Oriya\\
Phoenician\\
Runic\\
Simplified\\
Sinhala\\
Sumero-Akkadian Cuneiform\\
Tamil\\
Telugu\\
Thaana\\
Thai\\
Tibetan\\
Tifinagh\\
Traditional\\
Unified Canadian Aboriginal Syllabics\\
Vai\\
Yi
\end{multicols}
\Describe{\ensureascii}{\marg{text}}
\New{3.9i} This macro makes sure \m{text} is typeset with a
LICR-savvy encoding in the ASCII range. It is used to redefine |\TeX|
and |\LaTeX| so that they are correctly typeset even with |LGR| or
|X2| (the complete list is stored in |\BabelNonASCII|, which by default
is |LGR|, |LGI|, |X2|, |OT2|, |OT3|, |OT6|, |LHE|, |LWN|, |LMA|, |LMC|,
|LMS|, |LMU|, but you can modify it). So, in some sense it fixes the
bug described in the previous paragraph.
If non-ASCII encodings are not loaded (or no encoding at all), it is
no-op (also |\TeX| and |\LaTeX| are not redefined); otherwise,
|\ensureascii| switches to the encoding at the beginning of the
document if ASCII-savvy, or else the last ASCII-savvy encoding
loaded. For example, if you load |LY1,LGR|, then it is set to |LY1|,
but if you load |LY1,T2A| it is set to |T2A|. The symbol encodings
|TS1|, |T3|, and |TS3| are not taken into account, since they are not
used for “ordinary” text (they are stored in |\BabelNonText|, used
in some special cases when no Latin encoding is explicitly set).
The foregoing rules (which are applied “at begin document”) cover
most of the cases. No assumption is made on characters above
127, which may not follow the LICR conventions -- the goal is just
to ensure most of the ASCII letters and symbols are the right ones.
\subsection{Bidirectional and right-to-left text}
\label{bidi}
No macros to select the writing direction are provided, either --
writing direction is intrinsic to each script and therefore it is best
set by the language (which can be a dummy one). Furthermore, there
are in fact two right-to-left modes, depending on the language, which
differ in the way `weak' numeric characters are ordered (e.g., Arabic
\%123 \textit{vs} Hebrew 123\%).
\begin{warning}
The current code for \textbf{text} in \luatex{} should be considered
essentially stable, but, of course, it is not bug-free and there can
be improvements in the future, because setting bidi text has many
subtleties (see for example <
https://www.w3.org/TR/html-bidi/>). A
basic stable version for other engines must wait. This applies to
text; there is a basic support for \textbf{graphical} elements,
including the |picture| environment (with \textsf{pict2e}) and
\textsf{pfg/tikz}. Also, indexes and the like are under study, as
well as math (there are progresses in the latter, including
\textsf{amsmath} and \textsf{mathtools} too, but for example
|gathered| may fail).
An effort is being made to avoid incompatibilities in the future
(this one of the reasons currently bidi must be explicitly requested
as a package option, with a certain bidi model, and also the |layout|
options described below).
\end{warning}
\begin{warning}
If characters to be mirrored are shown without changes with \luatex,
try with the following line:
\begin{verbatim}
\babeladjust{bidi.mirroring=off}
\end{verbatim}
\end{warning}
There are some package options controlling bidi writing.
\Describe{bidi=}{\texttt{default} $\string|$ \texttt{basic}
$\string|$ \texttt{basic-r} $\string|$ \texttt{bidi-l} $\string|$
\texttt{bidi-r}}
\New{3.14} Selects the bidi algorithm to be used.
With |default| the bidi mechanism is just activated (by default it is
not), but every change must be marked up. In \pdftex{} this is the only
option. If the RL text consists of only letters and punctuation, it
will be fine in most cases, but numbers, for example, will be rendered
in the wrong order.
In \luatex, the preferred method is |basic|, which supports both L and
R text. |basic-r| was a first attempt to create a bidi algorithm and
provides a simple and fast method for R text in some typical cases.
(They are named \texttt{basic} mainly because they consider only the
intrinsic direction of scripts and weak directionality.)
In \xetex, |bidi-r| and |bidi-l| resort to the package \textsf{bidi}
(by Vafa Khalighi). For RL documents use the former, and for LR ones
use the latter.
\begin{warning}
The package \textsf{bidi} patches heavily lots of macros and packages
even if the RL script is not the main one, which can lead to some
surprising results, so for short and simple texts (letters and
punctuation) the |default| method is more often than not much
preferable.
\end{warning}
There are samples on GitHub, under \texttt{/required/babel/samples}.
See particularly |lua-bidibasic.tex| and |lua-secenum.tex|.
\begin{example}
The following text comes from the Arabic Wikipedia (article about
Arabia). Copy-pasting some text from the Wikipedia is a good way to
test this feature. Remember |basic| is available in \luatex{}
only.
\begingroup
% If you are looking at the code to see how it has been written, you
% will be disappointed :-). The following example is built ad hoc to
% emulate the final result to avoid dependencies, and therefore it's
% not "real" code.
\setmonofont[Scale=.86, FakeStretch=.97,Script=Arabic]{DejaVu Sans Mono}
\catcode`@=13
\def@#1{\ifcase#1\relax \egroup \or \bgroup\textdir TLT \else
\bgroup\textdir TRT \pardir TRT \fi}
\setengine{luatex}
\begin{verbatim}
\documentclass[arabic]{article}
\usepackage[_bidi=basic_, provide=*]{babel}
\babelfont{rm}{FreeSerif}
\begin{document}
@9وقد عرفت شبه جزيرة العرب طيلة العصر الهيليني )الاغريقي( بـ
@1Arabia@0 أو @1Aravia@0 )بالاغريقية @1Αραβία@0(، استخدم الرومان ثلاث
بادئات بـ@1“Arabia”@0 على ثلاث مناطق من شبه الجزيرة العربية، إلا أنها
حقيقةً كانت أكبر مما تعرف عليه اليوم.
@0\end{document}
\end{verbatim}
\endgroup
\end{example}
\begin{example}
With |bidi=basic| \textit{both} L and R text can be
mixed without explicit markup (the latter will be necessary only in
some special cases where the Unicode algorithm fails). It is used much
like |bidi=basic-r|, but with R text inside L text you may want to map
the font so that the correct features are in force. This is accomplished
with an option in |\babelprovide|, as illustrated:
\begingroup
% If you are looking at the code to see how it has been written, you
% will be disappointed :-). The following example is built ad hoc to
% emulate the final result to avoid dependencies, and therefore it's
% not "real" code.
\setmonofont[Scale=.86, FakeStretch=.97,Script=Arabic]{DejaVu Sans Mono}
\catcode`@=13
\def@#1{\ifcase#1\relax \egroup \or \bgroup\textdir TRT \else
\bgroup\textdir TLT \pardir TLT \fi}
\begin{verbatim}
\documentclass{book}
\usepackage[english, _bidi=basic_]{babel}
\babelprovide[_onchar=ids fonts_]{arabic}
\babelfont{rm}{Crimson}
\babelfont[*arabic]{rm}{FreeSerif}
\begin{document}
Most Arabic speakers consider the two varieties to be two registers
of one language, although the two registers can be referred to in
Arabic as @1فصحى العصر@0 \textit{fuṣḥā l-ʻaṣr} (MSA) and
@1فصحى التراث@0 \textit{fuṣḥā t-turāth} (CA).
\end{document}
\end{verbatim}
\endgroup
In this example, and thanks to |onchar=ids fonts|, any Arabic letter
(because the language is |arabic|) changes its font to that set for
this language (here defined via |*arabic|, because Crimson does not
provide Arabic letters).
\end{example}
\begin{note}
Boxes are “black boxes”. Numbers inside an |\hbox| (for example
in a |\ref|) do not know anything about the surrounding chars. So,
|\ref{A}-\ref{B}| are not rendered in the visual order A-B, but in the
wrong one B-A (because the hyphen does not “see” the digits inside the
|\hbox|’es). If you need |\ref| ranges, the best option is to define
a dedicated macro like this (to avoid explicit direction changes in the
body; here |\texthe| must be defined to select the main language):
\begin{verbatim}
\newcommand\refrange[2]{\babelsublr{\texthe{\ref{#1}}-\texthe{\ref{#2}}}}
\end{verbatim}
In the future a more complete method, reading recursively boxed text,
may be added.
\end{note}
\Describe{layout=}{\texttt{sectioning} $\string|$
\texttt{counters} $\string|$
\texttt{lists} $\string|$
\texttt{contents} $\string|$
\texttt{footnotes} $\string|$
\texttt{captions} $\string|$}
\DescribeOther{ }{\phantom{layout=}\texttt{columns} $\string|$
\texttt{graphics} $\string|$
\texttt{extras} $\string|$
\texttt{pars} $\string|$
\texttt{nopars}}
\New{3.16} \textit{To be expanded}. Selects which layout elements are
adapted in bidi documents, including some text elements (except with
options loading the |bidi| package, which provides its own mechanism to
control these elements). You may use several options with a
space-separated list, like |layout=counters contents sectioning| (in
\New{3.85} spaces are to be preferred over dots, which was the former
syntax). This list will be expanded in future releases. Note not all
options are required by all engines.
\begin{description}
\renewcommand\makelabel[1]{%
\hspace\labelsep\normalfont\ttfamily\color{thered}#1}
\itemsep=-\parskip
\item[sectioning] makes sure the sectioning macros are typeset in the
main language, but with the title text in the current language (see
below |\BabelPatchSection| for further details).
\item[counters] required in all engines (except \luatex{} with
|bidi=basic|) to reorder section numbers and the like (e.g.,
\m{subsection}.\m{section}); required in \xetex{} and \pdftex{} for
counters in general, as well as in \luatex{} with |bidi=default|;
required in \luatex{} for numeric footnote marks $>$9 with
|bidi=basic-r| (but \textit{not} with |bidi=basic|); note, however,
it can depend on the counter format.
With |counters|, |\arabic| is not only considered L text always (with
|\babelsublr|, see below), but also an “isolated” block which does
not interact with the surrounding chars. So, while |1.2| in R text is
rendered in that order with |bidi=basic| (as a decimal number), in
|\arabic{c1}.\arabic{c2}| the visual order is \textit{c2.c1}. Of
course, you may always adjust the order by changing the language, if
necessary.
\New{3.84} Since |\thepage| is (indirectly) redefined, |makeindex|
will reject many entries as invalid. With |counters*| \babel{}
attempts to remove the conflicting macros.
\item[lists] required in \xetex{} and \pdftex{}, but only in
bidirectional (with both R and L paragraphs) documents in \luatex{}.
\begin{warning}
As of April 2019 there is a bug with |\parshape| in \luatex{} (a
\TeX{} primitive) which makes lists to be horizontally misplaced if
they are inside a |\vbox| (like |minipage|) and the current direction
is different from the main one. A workaround is to restore the main
language before the box and then set the local one inside.
\end{warning}
\item[contents] required in \xetex{} and \pdftex{}; in \luatex{}
toc entries are R by default if the main language is R.
\item[columns] required in \xetex{} and \pdftex{} to reverse the
column order (currently only the standard two-column mode); in
\luatex{} they are R by default if the main language is R (including
\textsf{multicol}).
\item[footnotes] not required in monolingual documents, but it may be
useful in bidirectional documents (with both R and L paragraphs) in
all engines, as well as in multilingual documents in general; you may
use alternatively |\BabelFootnote| described below (what this option
does exactly is also explained there).
\item[captions] is similar to |sectioning|, but for |\caption|; not
required in monolingual documents with \luatex{}, but may be
required in \xetex{} and \pdftex{} in some styles (support for the
latter two engines is still experimental) \New{3.18}.
\item[tabular] required in \luatex{} for R |tabular|, so that the first
column is the right one (it has been tested only with simple tables,
so expect some readjustments in the future); ignored in \pdftex{} or
\xetex{} (which will not support a similar option in the short term).
It patches an internal command, so it might be ignored by some
packages and classes (or even raise an error). \New{3.18}.
\item[graphics] modifies the |picture| environment so that the whole
figure is L but the text is R\@. It \textit{does not} work with the
standard |picture|, and \textit{pict2e} is required. It attempts to do
the same for \textsf{pgf/tikz}. Somewhat experimental. \New{3.32}.
\item[extras] is used for miscellaneous readjustments which do not fit into
the previous groups. Currently redefines in \luatex{} |\underline| and
|\LaTeX2e| \New{3.19}.
\item[pars, nopars] When \texttt{layout} is used with any options
in bidi documents, there are a few changes in |\@hangfrom| and also
(only \xetex, as it’s unnecesary in \luatex) in |\raggedright|
and |\raggedleft|. Using |pars| applies these adjustments even without
other options; conversely, |nopars| prevents these adjustments even
when other options are specified \New{25.9}.
\end{description}
\begin{example}
Typically, in an Arabic document you would need:
\setengine{luatex}
\begin{verbatim}
\usepackage[bidi=basic,
layout=counters tabular]{babel}
\end{verbatim}
or
\setengine{xetex}
\begin{verbatim}
\usepackage[bidi=bidi,
layout=counters tabular]{babel}
\end{verbatim}
\end{example}
\Describe{\babelsublr}{\marg{lr-text}}
Digits in \pdftex{} must be marked up explicitly (unlike \luatex{} with
|bidi=basic| or |bidi=basic-r| and, usually, \xetex{}). This command is
provided to set \marg{lr-text} in L mode if necessary. It's intended
for what Unicode calls weak characters, because words are best set with
the corresponding language. For this reason, there is no |rl|
counterpart.
Any |\babelsublr| in \textit{explicit} L mode is ignored. However, with
|bidi=basic| and \textit{implicit} L, it first returns to R and then
switches to explicit L. To clarify this point, consider, in an R
context:
\begin{verbatim}
RTL A ltr text \thechapter{} and still ltr RTL B
\end{verbatim}
There are \textit{three} R blocks and \textit{two} L blocks, and the
order is \textit{RTL B and still ltr 1 ltr text RTL A}. This is by
design to provide the proper behavior in the most usual cases — but if
you need to use |\ref| in an L text inside R, the L text must be marked
up explicitly; for example:
\begin{verbatim}
RTL A \foreignlanguage{english}{ltr text \thechapter{} and still ltr} RTL B
\end{verbatim}
\Describe{\localerestoredirs}{}
\New{3.86} \textit{LuaTeX}. This command resets the internal text,
paragraph and body directions to those of the current locale (if
different). Sometimes changing these values directly can be useful for
some hacks, and this command helps in restoring the directions to the
correct ones. It can be used in |>| arguments of \textsf{array}, too.
\Describe{\BabelPatchSection}{\marg{section-name}}
Mainly for bidi text, but it can be useful in other cases.
|\BabelPatchSection| and the corresponding option |layout=sectioning|
takes a more logical approach (at least in many cases) because it
applies the global language to the section format (including the
|\chaptername| in |\chapter|), while the section text is still the
current language. The latter is passed to tocs and marks, too,
and with |sectioning| in |layout| they both reset the “global” language
to the main one, while the text uses the “local” language.
With |layout=sectioning| all the standard sectioning commands are
redefined (it also “isolates” the page number in heads, for a proper
bidi behavior), but with this command you can set them individually if
necessary (but note then tocs and marks are not touched).
\Describe{\BabelFootnote}{\marg{cmd}\marg{local-language}%
\marg{before}\marg{after}}
\New{3.17} Something like:
\begin{verbatim}
\BabelFootnote{\parsfootnote}{\localename}{(}{)}
\end{verbatim}
defines |\parsfootnote| so that |\parsfootnote{note}| is equivalent to:
\begin{verbatim}
\footnote{(\foreignlanguage{\localename}{note})}
\end{verbatim}
but the footnote itself is typeset in the main language (to unify its
direction as well as the footnote mark). In addition,
|\parsfootnotetext| is defined. The option |footnotes| just does the
following:
\begin{verbatim}
\BabelFootnote{\footnote}{\localename}{}{}%
\BabelFootnote{\localfootnote}{\localename}{}{}%
\BabelFootnote{\mainfootnote}{}{}{}
\end{verbatim}
(which also redefine |\footnotetext| and define |\localfootnotetext|
and |\mainfootnotetext|). If the language argument is empty, then no
language is selected inside the argument of the footnote. (\New{25.9}
Formerly only available in bidi documents and Unicode engines, now it’s
always available in all engines.)
\begin{example}
If you want to preserve directionality in footnotes and there are
many footnotes entirely in English, you can define:
\begin{verbatim}
\BabelFootnote{\enfootnote}{english}{}{.}
\end{verbatim}
It adds a period outside the English part, so that it is placed
at the left in the last line. This means the dot at the end of the
footnote text should be omitted.
\end{example}
\subsection{Unicode character properties in \luatex}
\New{3.32} Part of the \babel{} job is to apply Unicode rules to some
script-specific features based on some properties. Currently, they are
3, namely, direction (i.e., bidi class), mirroring glyphs, and line
breaking for CJK scripts. These properties are stored in \textsf{lua}
tables, which you can modify with the following macro (for example,
to set them for glyphs in the PUA).
\Describe{\babelcharproperty}{\marg{char-code}\oarg{to-char-code}%
\marg{property}\marg{value}}
\New{3.32} Here, \marg{char-code} is a number (with \TeX{} syntax).
With the optional argument, you can set a range of values. There are
three properties (with a short name, taken from Unicode): |direction|
(|bc|), |mirror| (|bmg|), |linebreak| (|lb|). The settings are global,
and this command is allowed only in vertical mode (the preamble or
between paragraphs).
For example:
\begin{verbatim}
\babelcharproperty{`¿}{mirror}{`?}
\babelcharproperty{`-}{direction}{l} % or al, r, en, an, on, et, cs
\babelcharproperty{`)}{linebreak}{cl} % or id, op, cl, ns, ex, in, hy
\end{verbatim}
Please, refer to the Unicode standard (Annex \#9 and Annex \#14) for
the meaning of the available codes. For example, |en| is ‘European
number’ and |id| is ‘ideographic’.
\New{3.39} Another property is |locale|, which adds characters to the
list used by |onchar| in |\babelprovide|, or, if the last argument is
empty, removes them. The last argument is the locale name:
\begin{verbatim}
\babelcharproperty{`,}{locale}{english}
\end{verbatim}
\subsection{Tweaking some \babel{} features}
\Describe{\babeladjust}{\marg{key-value-list}}
\New{3.36} Sometimes you might need to disable some \babel{} features.
Currently this macro understands the following keys, with values |on|
or |off|:
\begin{multicols}{3}
\ttfamily
autoload.bcp47\\
bcp47.toname\\
bidi.mirroring\\
bidi.text\\
bidi.math\\%
% bidi.mapdigits\\
linebreak.sea\\
linebreak.cjk\\
justify.arabic\\
layout.tabular\\
layout.lists
\end{multicols}
The first four are documented elsewhere. The following are by default
|on|, but with |off| can disable some features: |bidi.math| (only
preamble) changes for math or \textsf{amsmath}, |linebreak.sea|,
|linebreak.cjk| and |justify.arabic| the corresponding algorithms,
|layout.tabular| and |layout.lists| changes for tabular and lists.
Some of them are reverted only to some extent.
Other keys are:
\begin{multicols}{3}
\ttfamily
autoload.options\\
autoload.bcp47.prefix\\
autoload.bcp47.options\\
prehyphenation.disable\\
interchar.disable\\
select.write\\
select.encoding\\
\end{multicols}
Most of them are documented elsewhere. With |select.encoding=off|, the
encoding is not set when loading a language on the fly with \pdftex{}
(only |off|). |prehyphenation.disable| is by default |nohyphenation|,
which means \luatex{} prehyphenation transforms are not applied if the current
hyphenation rules are |nohyphenation|; with |off| they are never
disabled. |interchar.disable| takes the same values, but for the
\xetex{} interchar mechanism.
For example, you can set |\babeladjust{bidi.text=off}| if you are using
an alternative algorithm or with large sections not requiring it. Use
with care, because these options do not deactivate other related
options (like paragraph direction with |bidi.text|).
\section{Relation with other packages}
\subsection{Compatibility}
There are compatibility issues with the following packages.
\begingroup
\parindent0pt
\def\trans#1#2{%
\vspace{1.5mm}%
\parbox[t]{3.0cm}{\strut\sffamily#1}%
\hspace{2mm}%
\parbox[t]{10cm}{\strut#2}\par}
\bigskip\hrule\nobreak\vspace{.5mm}
\trans{polyglossia}{This package is not compatible at all with \babel.
They should never be used together, because macros are different, and
even those with the same name don’t behave in the same way. Also,
languages are organized quite differently (\babel{} treats all locales
on an equal footing).}
\trans{tikz/pgf}{There are some issues with shorthands, which are
usually solved with \texttt{\string\usetikzlibrary\{babel\}}.}
\trans{cleveref}{Because of a long standing bug in this package, some
languages can raise an error (particularly |spanish| and |greek|).}
\trans{natbib}{Load it before \babel.}
\trans{bidi}{\Babel\ relies on \textsc{bidi} with \xetex{} and
|bidi=bidi|, which has a multitude of incompatibilities. Please, refer
to its manual, and remember for short and simple texts you can rely on
|bidi=default| instead.}
\vspace{2mm}\hrule\nobreak\bigskip
\endgroup
\subsection{Related packages}
The following packages can be useful in multilingual contexts (the list
is far from exhaustive):
\begin{description}
\itemsep=-\parskip
\item[\sffamily babelbib] Multilingual bibliographies.
\item[\sffamily biblatex] Programmable bibliographies and citations.
\item[\sffamily bicaption] Bilingual captions.
\item[\sffamily csquotes] Logical markup for quotes.
\item[\sffamily hyphsubst] Selects a different set of patterns for a language.
\item[\sffamily iflang] Tests correctly the current language.
\item[\sffamily microtype] Adjusts the typesetting according to
some languages (kerning and spacing). Ligatures can be disabled.
Search in its manual for |babel| and |DeclareMicrotypeBabelHook|.
\item[\sffamily mkpattern] Generates hyphenation patterns.
\item[\sffamily siunitx] Typesetting of numbers and physical quantities.
\item[\sffamily substitutefont] Combines fonts in several encodings.
\item[\sffamily tracklang] Tracks which languages have been requested.
\item[\sffamily translator] An open platform for packages that need to be
localized.
\item[\sffamily ucharclasses] (\xetex) Switches fonts when you switch from one
Unicode block to another. Note it doesn’t work with RTL scripts.
\item[\sffamily zhspacing] Spacing for CJK documents in \xetex.
\end{description}
\subsection{Indexing}
For multilingual indexing, see \textsf{upmendex} and \textsf{xindex},
currently preferred to \textsf{xindy}.
\section{Tentative and experimental code}
See the code section for |\foreignlanguage*| (a new starred
version of |\foreignlanguage|).
For old and deprecated functions, see the \babel{} site.
\medskip
\textbf{Options for locales loaded on the fly}
\New{3.51} |\babeladjust{ autoload.options = ... }| sets the options
when a language is loaded on the fly. \New{24.14} By default, it is
|import|, which defines captions, date, numerals, etc., but ignores the
code in the |tex| file (for example, extended numerals in Greek). It
can be set to empty.
\medskip
\textbf{Labels}
\New{3.48} There is some work in progress for \babel{} to deal with
labels, both with the relation to captions (chapters, part), and how
counters are used to define them. It is still somewhat tentative
because it is far from trivial -- see the \babel{} site for further
details.
\section{Loading language hyphenation rules with \file{language.dat}}
\TeX{} and most engines based on it (pdf\TeX, \xetex, $\varepsilon$-\TeX,
the main exception being \luatex) require hyphenation patterns to be
preloaded when a format is created (e.g., \LaTeX, Xe\LaTeX, pdf\LaTeX).
\babel{} provides a tool which has become standard in many
distributions and based on a “configuration file” named
\file{language.dat}. The exact way this file is used depends on the
distribution, so please, read the documentation for the latter (note
also some distributions generate the file with some tool).
\New{3.9q} With \luatex, however, patterns are loaded on the fly when
requested by the language (except the “0th” language, typically
\textsf{english}, which is preloaded always). You may want to have a
local |language.dat| for a particular project (for example, a book on
Chemistry). The loader for lua(e)tex is slightly different as it's not
based on \babel{}, but on \texttt{etex.src}; however, \babel{} reloads
the data so that it works as expected.
\subsection{Format}
In that file the person who maintains a \TeX\ environment has to record
for which languages he has hyphenation patterns \emph{and} in which
files these are stored (this was because different operating systems
sometimes used \emph{very} different file-naming conventions, but this
issue is not currently so serious as before). When hyphenation
exceptions are stored in a separate file this can be indicated by
naming that file \emph{after} the file with the hyphenation patterns.
The file can contain empty lines and comments, as well as lines which
start with an equals (\texttt{=}) sign. Such a line will instruct
\LaTeX\ that the hyphenation patterns just processed have to be known
under an alternative name. Here is an example:
\begin{verbatim}
% File : language.dat
% Purpose : tell iniTeX what files with patterns to load.
english english.hyphenations
=british
dutch hyphen.dutch exceptions.dutch % Nederlands
german hyphen.ger
\end{verbatim}
You may also set the font encoding that the patterns are intended for by
following the language name by a colon and the encoding code. For
example:
\begin{verbatim}
german:T1 hyphenT1.ger
german hyphen.ger
\end{verbatim}
With the previous settings, if the encoding when the language is
selected is |T1| then the patterns in \file{hyphenT1.ger} are
used, but otherwise use those in \file{hyphen.ger} (note the encoding
can be set in |\extras<language>|).
\section{The interface between the core of \babel{} and the language
definition files}
The \textit{language definition files} (ldf) must conform to a
number of conventions, because these files have to fill in the gaps
left by the common code in \file{babel.def}, i.e., the
definitions of the macros that produce texts. Also the
language-switching possibility which has been built into the
\babel{} system has its implications.
The following assumptions are made:
\begin{itemize}
\item Some of the language-specific definitions might be used by plain
\TeX\ users, so the files have to be coded so that they can be read
by both \LaTeX\ and plain \TeX. The current format can be checked by
looking at the value of the macro |\fmtname|.
\item The common part of the \babel{} system redefines a number of
macros and environments (defined previously in the document style)
to put in the names of macros that replace the previously hard-wired
texts. These macros have to be defined in the language definition
files.
\item The language definition files must define five macros, used to
activate and deactivate the language-specific definitions. These
macros are |\|\langvar|hyphenmins|, |\captions|\langvar,
|\date|\langvar, |\extras|\langvar\ and |\noextras|\langvar (the
last two may be left empty); where \langvar\ is either the name of
the language definition file or the name of the \LaTeX\ option that
is to be used. These macros and their functions are discussed
below. You must define all or none for a language;
defining, say, |\date|\langvar\ but not |\captions|\langvar\ does
not raise an error but can lead to unexpected results.
\item When a language definition file is loaded, it can define
|\l@|\langvar\ to be a dialect of |\language0| when |\l@|\langvar\
is undefined.
\item Language names must be all lowercase. If an unknown language is
selected, \babel{} will attempt setting it after lowercasing its
name.
\item The semantics of modifiers is not defined (on purpose). In most
cases, they will just be simple separated options (e.g.,
\texttt{spanish}), but a language might require, say, a set of
options organized as a tree with suboptions (in such a case, the
recommended separator is \verb|/|). How modifiers (saved in
|\BabelModifiers|) are handled are left to language styles; they can
use |\in@|, loop them with |\@for| or load |keyval|, for example.
\end{itemize}
Some recommendations:
\begin{itemize}
\item The preferred shorthand is |"|, which is not used in \LaTeX{}
(quotes are entered as |``| and |''|). Other good choices are
characters which are not used in a certain context (e.g., |=| in an
ancient language). Note however |=|, \texttt{<}, |>|, |:| and the like
can be dangerous, because they may be used as part of the syntax
of some elements (numeric expressions, key/value pairs, etc.).
\item Captions should not contain shorthands or encoding-dependent
commands (the latter is not always possible, but should be clearly
documented). They should be defined using the LICR\@. You may
also use the new tools for encoded strings, described below.
\item Avoid adding things to |\noextras<language>| except for umlauthigh
and friends, |\bbl@deactivate|, |\bbl@(non)frenchspacing|, and
language-specific macros. Use always, wherever possible, |\babel@save| and
|\babel@savevariable| (except if you still want to have access to the
previous value). Do not reset a macro or a setting to a hardcoded
value. Never. Instead save its value in |\extras<language>|.
\item Do not switch scripts. If you want to make sure a set of glyphs
is used, switch either the font encoding (low-level) or the language
(high-level, which in turn may switch the font encoding). Usage of things
like |\latintext| is deprecated (but not removed, for backward
compatibility).
\item Please, for “private” internal macros do not use the |\bbl@|
prefix. It is used by \babel{} and it can lead to incompatibilities.
\end{itemize}
There are no special requirements for documenting your language files.
Just provide a standalone document suited to your needs, as well as
other files you think can be useful. A PDF and a “readme” are
strongly recommended.
\subsection{Guidelines for contributed languages}
\label{contribute}
Currently, the easiest way to contribute a new language is by taking
one of the 500 or so |ini| templates available on GitHub as a basis.
Just make a pull request or download it, and then, after filling out the
fields, sent it to me. Feel free to ask for help or to make feature
requests.
As to \texttt{ldf} files, now language files are “outsourced” and are
located in a separate directory
(\texttt{/macros/latex/contrib/babel-contrib}), so that they are
contributed directly to CTAN (please, do not send to me language styles
just to upload them to CTAN).
Of course, placing your style files in this directory is not mandatory,
but if you want to do it, here are a few guidelines.
\begin{itemize}
\item Do not hesitate stating on the file heads you are the author and the
maintainer, if you actually are. There is no need to state the \babel{}
maintainer(s) as author(s) if they have not contributed significantly
to your language files.
\item Fonts are not strictly part of a language, so they are best placed
in the corresponding TeX tree. This includes not only \texttt{tfm},
\texttt{vf}, \texttt{ps1}, \texttt{otf}, \texttt{mf} files and the
like, but also \texttt{fd} ones.
\item Font and input encodings are usually best placed in the
corresponding tree, too, but sometimes they belong more naturally to
the \babel{} style. Note you may also need to define a LICR
(\textit{TLC3}, I, 757f.).
\item \Babel{} \texttt{ldf} files may just interface a framework, as it
happens often with Oriental languages/scripts. This framework is best
placed in its own directory.
\end{itemize}
The following page provides a starting point for \texttt{ldf} files:
\texttt{
http://www.texnia.com/incubator.html}. See also
\texttt{
https://latex3.github.io/babel/guides/list-of-locale-templates.html}.
If you need further assistance and technical advice in the development
of language styles, I will be happy to help you. And of course, you can
make any suggestion you like.
\subsection{Basic macros}
In the core of the \babel{} system, several macros are defined for use
in language definition files. Their purpose is to make a new language
known. The first two are related to hyphenation patterns.
\DescribeMacro{\addlanguage}
The macro |\addlanguage| is a non-outer version of the macro
|\newlanguage|, defined in \file{plain.tex} version~3.x. Here
“language” is used in the \TeX{} sense of set of hyphenation
patterns.
\DescribeMacro{\adddialect}
The macro |\adddialect| can be used when two languages can (or must)
use the same hyphenation patterns. This can also be useful for
languages for which no patterns are preloaded in the format. In such
cases the default behavior of the \babel{} system is to define this
language as a ‘dialect’ of the language for which the patterns were
loaded as |\language0|. Here “language” is used in the \TeX{} sense
of set of hyphenation patterns, while “dialect”, which is misnomer,
refers just to a language with the same hyphenation patterns as another
(there is no relation with its linguistic meaning).
\DescribeMacro{\<lang>hyphenmins}
The macro |\|\langvar|hyphenmins| is used to store the values of
the |\lefthyphenmin| and |\righthyphenmin|. Redefine this macro
to set your own values, with two numbers corresponding to these
two parameters. For example:
\begin{verbatim}
\renewcommand\spanishhyphenmins{34}
\end{verbatim}
(Assigning |\lefthyphenmin| and |\righthyphenmin| directly in
|\extras<language>| has no effect.) This is a low-level setting. In
documents you should rely on |\babelhyphenmins|.
\DescribeMacro{\providehyphenmins}
The macro |\providehyphenmins| should be used in the language
definition files to set |\lefthyphenmin| and |\righthyphenmin|. This
macro will check whether these parameters were provided by the
hyphenation file before it takes any action. If these values have been
already set, this command is ignored (currently, default pattern files
do \textit{not} set them).
\DescribeMacro{\captions\langvar}
The macro |\captions|\langvar\ defines the macros that
hold the texts to replace the original hard-wired texts.
\DescribeMacro{\date\langvar}
The macro |\date|\langvar\ defines |\today|.
\DescribeMacro{\extras\langvar}
The macro |\extras|\langvar\ contains all the extra definitions needed
for a specific language. This macro, like the following, is a hook --
you can add things to it, but it must not be used directly.
\DescribeMacro{\noextras\langvar}
Because we want to let the user switch
between languages, but we do not know what state \TeX\ might be in
after the execution of |\extras|\langvar, a macro that brings
\TeX\ into a predefined state is needed. It will be no surprise
that the name of this macro is |\noextras|\langvar.
\DescribeMacro{\bbl@declare@ttribute}
This is a command to be used in the language definition files for
declaring a language attribute. It takes three arguments: the
name of the language, the attribute to be defined, and the code
to be executed when the attribute is to be used.
\DescribeMacro{\main@language}
To postpone the activation of the definitions needed for a
language until the beginning of a document, all language
definition files should use |\main@language| instead of
|\selectlanguage|. This will just store the name of the language,
and the proper language will be activated at the start of the
document.
\DescribeMacro{\ProvidesLanguage}
The macro |\ProvidesLanguage| should be used to identify the
language definition files. Its syntax is similar to the syntax
of the \LaTeX\ command |\ProvidesPackage|.
\DescribeMacro{\LdfInit}
The macro |\LdfInit| performs a couple of standard checks that
must be made at the beginning of a language definition file,
such as checking the category code of the @-sign, preventing
the \file{ldf} file from being processed twice, etc.
\DescribeMacro{\ldf@quit}
The macro |\ldf@quit| does work needed if an \file{ldf} file was
processed earlier. This includes resetting the category code of the
@-sign, preparing the language to be activated at |\begin{document}|
time, and ending the input stream.
\DescribeMacro{\ldf@finish}
The macro |\ldf@finish| does work needed at the end of each \file{ldf}
file. This includes resetting the category code of the @-sign, loading
a local configuration file, and preparing the language to be activated
at |\begin{document}| time.
\DescribeMacro{\loadlocalcfg}
After processing a language definition file,
\LaTeX\ can be instructed to load a local configuration
file. This file can, for instance, be used to add strings to
|\captions|\langvar\ to support local document
classes. The user will be informed that this
configuration file has been loaded. This macro is called by
|\ldf@finish|.
\subsection{Skeleton}
Here is the basic structure of an |ldf| file, with a language, a
dialect and an attribute. Strings are best defined using the method
explained in sec. \ref{s:strings} (\babel{} 3.9 and later).
\begin{verbatim}
\ProvidesLanguage{<language>}
[2016/04/23 v0.0 <Language> support from the babel system]
\LdfInit{<language>}{captions<language>}
\ifx\undefined\l@<language>
\@nopatterns{<Language>}
\adddialect\l@<language>0
\fi
\adddialect\l@<dialect>\l@<language>
\bbl@declare@ttribute{<language>}{<attrib>}{%
\expandafter\addto\expandafter\extras<language>
\expandafter{\extras<attrib><language>}%
\let\captions<language>\captions<attrib><language>}
\providehyphenmins{<language>}{\tw@\thr@@}
\StartBabelCommands*{<language>}{captions}
\SetString\chaptername{<chapter name>}
% More strings
\StartBabelCommands*{<language>}{date}
\SetString\monthiname{<name of first month>}
% More strings
\StartBabelCommands*{<dialect>}{captions}
\SetString\chaptername{<chapter name>}
% More strings
\StartBabelCommands*{<dialect>}{date}
\SetString\monthiname{<name of first month>}
% More strings
\EndBabelCommands
\addto\extras<language>{}
\addto\noextras<language>{}
\let\extras<dialect>\extras<language>
\let\noextras<dialect>\noextras<language>
\ldf@finish{<language>}
\end{verbatim}
\begin{note}
If for some reason you want to load a package in your style, you
should be aware it cannot be done directly in the \texttt{ldf} file,
but it can be delayed with |\AtEndOfPackage|. Macros from external
packages can be used \textit{inside} definitions in the \textsf{ldf}
itself (for example, |\extras<language>|), but if executed directly,
the code must be placed inside |\AtEndOfPackage|. A trivial example
illustrating these points is:
\begin{verbatim}
\AtEndOfPackage{%
\RequirePackage{dingbat}% Delay package
\savebox{\myeye}{\eye}}% And direct usage
\newsavebox{\myeye}
\newcommand\myanchor{\anchor}% But OK inside command
\end{verbatim}
\end{note}
\subsection{Support for active characters}
In quite a number of language definition files, active characters are
introduced. To facilitate this, some support macros are provided.
\DescribeMacro{\initiate@active@char}
Used in language
definition files to instruct \LaTeX\ to give a character the category
code `active'. When a character has been made active it will remain
that way until the end of the document. Its definition may vary.
\DescribeMacro{\bbl@activate}
\DescribeMacro{\bbl@deactivate}
Used to change the way an active
character expands. |\bbl@activate| `switches on' the active behavior
of the character. |\bbl@deactivate| lets the active character expand
to its former (mostly) non-active self.
\DescribeMacro{\declare@shorthand}
Used to define the various
shorthands. It takes three arguments: the name for the collection of
shorthands this definition belongs to; the character (sequence) that
makes up the shorthand, i.e., |~| or |"a|; and the code to be executed
when the shorthand is encountered. (It does \textit{not} raise an
error if the shorthand character has not been “initiated”.)
\DescribeMacro{\bbl@add@special} The \TeX book states: “Plain \TeX\
includes a macro called |\dospecials| that is essentially a set macro,
representing the set of all characters that have a special category
code.” \cite[p.~380]{DEK} It is used to set text `verbatim'. To make
this work if more characters get a special category code, you have to
add this character to the macro |\dospecials|. \LaTeX\ adds another
macro called |\@sanitize| representing the same character set, but
without the curly braces. The macros |\bbl@add@special|\meta{char} add
the character \meta{char} to these two sets.
\DescribeMacro{\@safe@activestrue}
\DescribeMacro{\@safe@activesfalse}
Enables and disables the “safe” mode. It is a tool for package and class
authors. See the description below.
\subsection{Support for saving macro definitions}
Language definition files may want to \emph{re}define macros that
already exist. Therefore a mechanism for saving (and restoring) the
original definition of those macros is provided. We provide two macros
for this.\footnote{This mechanism was introduced by Bernd Raichle.}
\DescribeMacro{\babel@save}
To save the current meaning of any control sequence, the macro
|\babel@save| is provided. It takes one argument, \meta{csname}, the
control sequence for which the meaning has to be saved.
\DescribeMacro{\babel@savevariable}
A second macro is provided to save the current value of a variable.
In this context, anything that is allowed after the |\the| primitive
is considered to be a variable. The macro takes one argument, the
\meta{variable}.
The effect of the preceding macros is to append a piece of code to
the current definition of |\originalTeX|. When |\originalTeX| is
expanded, this code restores the previous definition of the control
sequence or the previous value of the variable.
\subsection{Support for extending macros}
\DescribeMacro{\addto}
The macro |\addto{|\meta{control sequence}|}{|\meta{\TeX\ code}|}| can
be used to extend the definition of a macro. The macro need not be
defined (i.e., it can be undefined or |\relax|). This macro can, for
instance, be used in adding instructions to a macro like
|\extrasenglish|.
Be careful when using this macro, because depending on the case the
assignment can be either global (usually) or local (sometimes). That
does not seem very consistent, but this behavior is preserved for
backward compatibility. If you are using \pkg{etoolbox}, by Philipp
Lehman, consider using the tools provided by this package instead of
|\addto|.
\subsection{Macros common to a number of languages}
\DescribeMacro{\bbl@allowhyphens}
In several languages compound words are used. This means that when
\TeX\ has to hyphenate such a compound word, it only does so at the
`\texttt{-}' that is used in such words. To allow hyphenation in the
rest of such a compound word, the macro |\bbl@allowhyphens| can be
used.
\DescribeMacro{\allowhyphens}
Same as |\bbl@allowhyphens|, but does nothing if the encoding is
|T1|. It is intended mainly for characters provided as real glyphs by
this encoding but constructed with |\accent| in |OT1|.
Note the previous command (|\bbl@allowhyphens|) has different
applications (hyphens and discretionaries) than this one (composite
chars). Note also prior to version 3.7, |\allowhyphens| had the
behavior of |\bbl@allowhyphens|.
\DescribeMacro{\set@low@box}
For some languages, quotes need to be lowered to the baseline. For
this purpose the macro |\set@low@box| is available. It takes one
argument and puts that argument in an |\hbox|, at the baseline. The
result is available in |\box0| for further processing.
\DescribeMacro{\save@sf@q}
Sometimes it is necessary to preserve the |\spacefactor|. For this
purpose the macro |\save@sf@q| is available. It takes one argument,
saves the current spacefactor, executes the argument, and restores the
spacefactor.
\DescribeMacro{\bbl@frenchspacing}
\DescribeMacro{\bbl@nonfrenchspacing}
Those commands can be
used to properly switch French spacing on and off.
\begin{note}
With |ldf| files, \babel{} does not take into account |\normalsfcodes|
and (non-)French spacing is not always properly (un)set by languages
However, problems are unlikely to happen and therefore this part
remains untouched. With |ini| files, this issue has been addressed.
\end{note}
\subsection{Encoding-dependent strings}
\label{s:strings}
\New{3.9a} Babel 3.9 provides a way of defining strings in several
encodings, intended mainly for \luatex{} and \xetex, although the old
way of defining/switching strings still works and it's used by default.
It consists in a series of blocks started with
|\StartBabelCommands|. The last block is closed with
|\EndBabelCommands|. Each block is a single group (i.e., local
declarations apply until the next |\StartBabelCommands| or
|\EndBabelCommands|). An |ldf| may contain several series of this
kind.
Thanks to this new feature, string values and string language switching
are not mixed any more. Furthermore, strings do not need to be wrapped
with formatting commands (e.g., to select the writing direction)
because \babel{} takes care of it automatically. (See also
|\setlocalecaption|.)
\Describe\StartBabelCommands
{\marg{language-list}\marg{category}\oarg{selector}}
The \m{language-list} specifies which languages the block is
intended for. A block is taken into account only if the
|\CurrentOption| is listed here. Alternatively, you can define
|\BabelLanguages| to a comma-separated list of languages to be
defined (if undefined, |\StartBabelCommands| sets it to
|\CurrentOption|). You may write |\CurrentOption| as the language,
but this is discouraged -- an explicit name (or names) is much better
and clearer.
A “selector” selects a group of definition that are to be used, optionally
followed by extra info about the encodings to be used. The name
|unicode| must be used for \luatex{} and \xetex{}. Without a selector,
the LICR representation (i.e., with macros like |\~{n}| instead of |ñ|)
is assumed.
If a string is set several times (because several blocks are read),
the first one takes precedence (i.e., it works much like
|\providecommand|).
Encoding info is |charset=| followed by a charset, which, if given, sets
how the strings should be translated to the internal representation
used by the engine, typically |utf8|, which is the only value
supported currently (default is no translations). Note |charset| is
applied by \luatex{} and \xetex{} when reading the file, not when the
macro or string is used in the document.
A list of font encodings which the strings are expected to work with
can be given after |fontenc=| (separated with spaces, if two or more) --
recommended, but not mandatory, although blocks without this key are
not taken into account if you have requested |strings=encoded|.
Blocks without a selector are read always. They provide fallback
values, and therefore they must be the last ones; they should be
provided always if possible and all strings should be defined somehow
inside it; they can be the only blocks (mainly LGC scripts using the
LICR).
The \m{category} is either |captions|, |date| or |extras|. You must
stick to these three categories, even if no error is raised when using
other names.\footnote{In future releases further categories may be
added.\nb{like `monetary', `time', `address', `name', `case' or
`numeric'}} It may be empty, too, but in such a case using
|\SetString| is an error.
\begin{verbatim}
\StartBabelCommands{language}{captions}
[unicode, fontenc=TU EU1 EU2, charset=utf8]
\SetString{\chaptername}{utf8-string}
\StartBabelCommands{language}{captions}
\SetString{\chaptername}{ascii-maybe-LICR-string}
\EndBabelCommands
\end{verbatim}
A real example can be:
\begin{verbatim}
\StartBabelCommands{austrian}{date}
[unicode, fontenc=TU, charset=utf8]
\SetString\monthiname{Jänner}
\StartBabelCommands{german,austrian}{date}
[unicode, fontenc=TU, charset=utf8]
\SetString\monthiiiname{März}
\StartBabelCommands{austrian}{date}
\SetString\monthiname{J\"{a}nner}
\StartBabelCommands{german}{date}
\SetString\monthiname{Januar}
\StartBabelCommands{german,austrian}{date}
\SetString\monthiiname{Februar}
\SetString\monthiiiname{M\"{a}rz}
\SetString\monthivname{April}
\SetString\monthvname{Mai}
\SetString\monthviname{Juni}
\SetString\monthviiname{Juli}
\SetString\monthviiiname{August}
\SetString\monthixname{September}
\SetString\monthxname{Oktober}
\SetString\monthxiname{November}
\SetString\monthxiiname{Dezenber}
\SetString\today{\number\day.~%
\csname month\romannumeral\month name\endcsname\space
\number\year}
\StartBabelCommands{german,austrian}{captions}
\SetString\prefacename{Vorwort}
[etc.]
\EndBabelCommands
\end{verbatim}
When used in |ldf| files, previous values of |\<category><language>|
are overridden, which means the old way to define strings still works
and used by default (to be precise, is first set to undefined and then
strings are added). However, when used in the preamble or in a
package, new settings are added to the previous ones, if the language
exists (in the \babel{} sense, i.e., if |\date<language>| exists).
\begin{note}
The package option |strings| introduced in version 3.9 (around 2013)
when Unicode engines were still of marginal use, is now deprecated.
\end{note}
\begin{note}
Captions and other strings defined in |ini| files (in other words,
when a locale is loaded with |\babelprovide|) are internally set
with the help of these macros.
\end{note}
\Describe\StartBabelCommands{\optstar
\marg{language-list}\marg{category}\oarg{selector}}
The starred version just forces |strings| to take a value -- if not set
as package option (which is now deprecated), then the default for the
engine is used. This is not done by default to prevent backward
incompatibilities, but if you are creating a new language this version
is better. It's up to the maintainers of the current languages to
decide if using it is appropriate.
\Describe{\EndBabelCommands}{}
Marks the end of the series of blocks.
\Describe{\AfterBabelCommands}{\marg{code}}
The code is delayed and executed at the global scope just after
|\EndBabelCommands|.
\Describe{\SetString}{\marg{macro-name}\marg{string}}
Adds \meta{macro-name} to the current category, and defines globally
\meta{lang-macro-name} to \meta{code} (after applying the
transformation corresponding to the current charset or defined with
the hook |stringprocess|).
Use this command to define strings, without including any “logic” if
possible, which should be a separate macro. See the example above for
the date.
\Describe{\SetStringLoop}{\marg{macro-name}\marg{string-list}}
A convenient way to define several ordered names at once. For example,
to define |\abmoniname|, |\abmoniiname|, etc. (and similarly with
|abday|):
\begin{verbatim}
\SetStringLoop{abmon#1name}{en,fb,mr,ab,my,jn,jl,ag,sp,oc,nv,dc}
\SetStringLoop{abday#1name}{lu,ma,mi,ju,vi,sa,do}
\end{verbatim}
|#1| is replaced by the roman numeral.
\Describe{\SetHyphenMap}{\marg{to-lower-macros}}
\New{3.9g} Case mapping for hyphenation is handled with |\SetHyphenMap|
and controlled with the package option |hyphenmap|.
There are three helper macros to be used inside |\SetHyphenMap|:
\begin{itemize}
\item |\BabelLower|\marg{uccode}\marg{lccode} is
similar to |\lccode| but it's ignored if the char has been set and
saves the original lccode to restore it when switching the language
(except with |hyphenmap=first|).
\item |\BabelLowerMM|\marg{uccode-from}\marg{uccode-to}%
\marg{step}\marg{lccode-from} loops though the given uppercase
codes, using the step, and assigns them the lccode, which is also
increased (|MM| stands for \textit{many-to-many}).
\item |\BabelLowerMO|\marg{uccode-from}\marg{uccode-to}%
\marg{step}\marg{lccode} loops though the given uppercase
codes, using the step, and assigns them the lccode, which is fixed
(|MO| stands for \textit{many-to-one}).
\end{itemize}
An example is (which is redundant, because these assignments are done
by both \luatex{} and \xetex{}):
\begin{verbatim}
\SetHyphenMap{\BabelLowerMM{"100}{"11F}{2}{"101}}
\end{verbatim}
\begin{note}
This macro is not intended to fix wrong mappings done by Unicode
(which are the default in both \luatex{} and \xetex{}) -- if an
assignment is wrong, fix it directly.
\end{note}
\else
\DocInput{babel.dtx}
\fi
\section{Acknowledgements}
In the initial stages of the development of \babel, Bernd Raichle
provided many helpful suggestions and Michel Goossens supplied
contributions for many languages. Ideas from Nico Poppelier, Piet van
Oostrum and many others have been used. Paul Wackers and Werenfried
Spit helped find and repair bugs.
More recently, there are significant contributions by Salim Bou, Ulrike
Fischer, Loren Davis and Udi Fogiel.
Barbara Beeton has helped in improving the manual.
There are also many contributors for specific languages, which are
mentioned in the respective files. Without them, \babel{} just
wouldn’t exist.
\begin{thebibliography}{9}
\bibitem{AT} Huda Smitshuijzen Abifares, \textit{Arabic Typography},
Saqi, 2001.
\bibitem{BEP} Johannes Braams, Victor Eijkhout and Nico Poppelier,
\emph{The development of national \LaTeX\ styles},
\emph{TUGboat} 10 (1989) \#3, pp.~401--406.
\bibitem{FE} Yannis Haralambous,
\emph{Fonts \& Encodings}, O'Reilly, 2007.
\bibitem{DEK} Donald E. Knuth,
\emph{The \TeX book}, Addison-Wesley, 1986.
\bibitem{UE} Jukka K. Korpela,
\textit{Unicode Explained}, O'Reilly, 2006.
\bibitem{LLbook} Leslie Lamport,
\emph{\LaTeX, A document preparation System}, Addison-Wesley,
1986.
\bibitem{LLth} Leslie Lamport,
in: \TeX hax Digest, Volume 89, \#13, 17 February 1989.
\bibitem{CJKV} Ken Lunde,
\textit{CJKV Information Processing}, O'Reilly, 2nd ed., 2009.
\bibitem{ReinDersh} Edward M. Reingold and Nachum Dershowitz,
\emph{Calendrical Calculations: The Ultimate Edition},
Cambridge University Press, 2018
\bibitem{HP} Hubert Partl,
\emph{German \TeX},
\emph{TUGboat} 9 (1988) \#1, pp.~70--72.
\bibitem{ilatex} Joachim Schrod,
\emph{International \LaTeX\ is ready to use},
\emph{TUGboat} 11 (1990) \#1, pp.~87--90.
\bibitem{STS} Apostolos Syropoulos, Antonis Tsolomitis and Nick
Sofroniu,
\emph{Digital typography using \LaTeX},
Springer, 2002, pp.~301--373.
\bibitem{treebus} K.F. Treebus.
\emph{Tekstwijzer, een gids voor het grafisch verwerken van
tekst},
SDU Uitgeverij ('s-Gravenhage, 1988).
\end{thebibliography}
\end{document}
%</filedriver>
% \fi
%
% \addtolength{\oddsidemargin}{-5pt}
% \addtolength{\textwidth}{50pt}
% \reversemarginpar
%
% \small
%
% The \babel{} package is being developed incrementally, which means
% parts of the code are under development and therefore incomplete.
% Only documented features are considered complete. In other words, use
% \babel{} in real documents only as documented (except, of course, if
% you want to explore and test them).
%
% \section{Identification and loading of required files}
%
% The \babel{} package after unpacking consists of the following files:
% \begin{description}
% \itemsep=-\parskip
% \item[babel.sty] is the \LaTeX{} package, which set options and
% load language styles.
% \item[babel.def] is loaded by Plain.
% \item[switch.def] defines macros to set and switch languages (it loads
% part |babel.def|).
% \item[plain.def] is not used, and just loads babel.def, for
% compatibility.
% \item[hyphen.cfg] is the file to be used when generating the
% formats to load hyphenation patterns.
% \end{description}
% There some additional |tex|, |def| and |lua| files.
%
% The \babel{} installer extends \textsf{docstrip} with a few
% “pseudo-guards” to set “variables” used at installation time.
% They are used with \texttt{<@name@>} at the appropriate places in the
% source code and defined with either
% $\langle\langle$\textit{name}=\textit{value}$\rangle\rangle$, or with
% a series of lines between
% $\langle\langle$|*|\textit{name}$\rangle\rangle$ and
% $\langle\langle$|/|\textit{name}$\rangle\rangle$. The latter is
% cumulative (e.g., with \textit{More package options}). That brings a
% little bit of literate programming. The guards \texttt{<-name>} and
% \texttt{<+name>} have been redefined, too. See |babel.ins| for further
% details.
%
% \section{\texttt{locale} directory}
%
% A required component of \babel{} is a set of |ini| files with basic
% definitions for about 300 languages. They are distributed as a
% separate |zip| file, not packed as |dtx|. Many of them are
% essentially finished (except bugs and mistakes, of course). Some of
% them are still incomplete (but they will be usable), and there are
% some omissions (e.g., there are no geographic areas in Spanish). Not
% all include LICR variants.
%
% |babel-*.ini| files contain the actual data; |babel-*.tex| files are
% basically proxies to the corresponding ini files.
%
% See \href{
https://latex3.github.io/babel/guides/keys-in-ini-files.html}{Keys
% in \texttt{ini} files} in the the \babel{} site.
%
% \section{Tools}
%
% \begin{macrocode}
%<<version=25.12>>
%<<date=2025/08/03>>
% \end{macrocode}
%
% \textbf{Do not use the following macros in \texttt{ldf} files. They
% may change in the future.} This applies mainly to those recently
% added for replacing, trimming and looping. The older ones, like
% |\bbl@afterfi|, will not change.
% We define some basic macros which just make the code cleaner.
% |\bbl@add| is now used internally instead of |\addto| because of
% the unpredictable behavior of the latter. Used in
% \file{babel.def} and in \file{babel.sty}, which means in \LaTeX{}
% is executed twice, but we need them when defining options and
% \file{babel.def} cannot be load until options have been defined.
% This does not hurt, but should be fixed somehow.
%
% \begin{macrocode}
%<<*Basic macros>>
\bbl@trace{Basic macros}
\def\bbl@stripslash{\expandafter\@gobble\string}
\def\bbl@add#1#2{%
\bbl@ifunset{\bbl@stripslash#1}%
{\def#1{#2}}%
{\expandafter\def\expandafter#1\expandafter{#1#2}}}
\def\bbl@xin@{\@expandtwoargs\in@}
\def\bbl@carg#1#2{\expandafter#1\csname#2\endcsname}%
\def\bbl@ncarg#1#2#3{\expandafter#1\expandafter#2\csname#3\endcsname}%
\def\bbl@ccarg#1#2#3{%
\expandafter#1\csname#2\expandafter\endcsname\csname#3\endcsname}%
\def\bbl@csarg#1#2{\expandafter#1\csname bbl@#2\endcsname}%
\def\bbl@cs#1{\csname bbl@#1\endcsname}
\def\bbl@cl#1{\csname bbl@#1@\languagename\endcsname}
\def\bbl@loop#1#2#3{\bbl@@loop#1{#3}#2,\@nnil,}
\def\bbl@loopx#1#2{\expandafter\bbl@loop\expandafter#1\expandafter{#2}}
\def\bbl@@loop#1#2#3,{%
\ifx\@nnil#3\relax\else
\def#1{#3}#2\bbl@afterfi\bbl@@loop#1{#2}%
\fi}
\def\bbl@for#1#2#3{\bbl@loopx#1{#2}{\ifx#1\@empty\else#3\fi}}
% \end{macrocode}
%
% \macro{\bbl@add@list}
% This internal macro adds its second argument to a comma separated
% list in its first argument. When the list is not defined yet (or
% empty), it will be initiated. It presumes expandable character
% strings.
%
% \begin{macrocode}
\def\bbl@add@list#1#2{%
\edef#1{%
\bbl@ifunset{\bbl@stripslash#1}%
{}%
{\ifx#1\@empty\else#1,\fi}%
#2}}
% \end{macrocode}
%
% \macro{\bbl@afterelse}
% \macro{\bbl@afterfi}
% Because the code that is used in the handling of active characters
% may need to look ahead, we take extra care to `throw' it over the
% |\else| and |\fi| parts of an |\if|-statement\footnote{This code is
% based on code presented in TUGboat vol. 12, no2, June 1991 in “An
% expansion Power Lemma” by Sonja Maus.}. These macros will break if
% another |\if...\fi| statement appears in one of the arguments and it
% is not enclosed in braces.
%
% \begin{macrocode}
\long\def\bbl@afterelse#1\else#2\fi{\fi#1}
\long\def\bbl@afterfi#1\fi{\fi#1}
% \end{macrocode}
%
% \macro{\bbl@exp}
%
% Now, just syntactical sugar, but it makes partial expansion of some
% code a lot more simple and readable. Here |\\| stands for
% |\noexpand|, |\<..>| for |\noexpand| applied to a built macro name
% (which does not define the macro if undefined to |\relax|, because it
% is created locally), and |\[..]| for one-level expansion (where |..|
% is the macro name without the backslash). The result may be followed
% by extra arguments, if necessary.
%
% \begin{macrocode}
\def\bbl@exp#1{%
\begingroup
\let\\\noexpand
\let\<\bbl@exp@en
\let\[\bbl@exp@ue
\edef\bbl@exp@aux{\endgroup#1}%
\bbl@exp@aux}
\def\bbl@exp@en#1>{\expandafter\noexpand\csname#1\endcsname}%
\def\bbl@exp@ue#1]{%
\unexpanded\expandafter\expandafter\expandafter{\csname#1\endcsname}}%
% \end{macrocode}
%
% \macro{\bbl@trim}
% The following piece of code is stolen (with some changes) from
% \textsf{keyval}, by David Carlisle. It defines two macros:
% |\bbl@trim| and |\bbl@trim@def|. The first one strips the leading and
% trailing spaces from the second argument and then applies the first
% argument (a macro, |\toks@| and the like). The second one, as its
% name suggests, defines the first argument as the stripped second
% argument.
%
% \begin{macrocode}
\def\bbl@tempa#1{%
\long\def\bbl@trim##1##2{%
\futurelet\bbl@trim@a\bbl@trim@c##2\@nil\@nil#1\@nil\relax{##1}}%
\def\bbl@trim@c{%
\ifx\bbl@trim@a\@sptoken
\expandafter\bbl@trim@b
\else
\expandafter\bbl@trim@b\expandafter#1%
\fi}%
\long\def\bbl@trim@b#1##1 \@nil{\bbl@trim@i##1}}
\bbl@tempa{ }
\long\def\bbl@trim@i#1\@nil#2\relax#3{#3{#1}}
\long\def\bbl@trim@def#1{\bbl@trim{\def#1}}
% \end{macrocode}
%
% \macro{\bbl@ifunset}
% To check if a macro is defined, we create a new macro, which does the
% same as |\@ifundefined|. However, in an $\varepsilon$-tex engine, it is
% based on |\ifcsname|, which is more efficient, and does not waste
% memory. Defined inside a group, to avoid \cs{ifcsname} being
% implicitly set to |\relax| by the |\csname| test.
%
% \begin{macrocode}
\begingroup
\gdef\bbl@ifunset#1{%
\expandafter\ifx\csname#1\endcsname\relax
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi}
\bbl@ifunset{ifcsname}%
{}%
{\gdef\bbl@ifunset#1{%
\ifcsname#1\endcsname
\expandafter\ifx\csname#1\endcsname\relax
\bbl@afterelse\expandafter\@firstoftwo
\else
\bbl@afterfi\expandafter\@secondoftwo
\fi
\else
\expandafter\@firstoftwo
\fi}}
\endgroup
% \end{macrocode}
%
% \macro{\bbl@ifblank}
% A tool from \textsf{url}, by Donald Arseneau, which tests if a string
% is empty or space. The companion macros tests if a macro is defined
% with some `real' value, i.e., not |\relax| and not empty,
%
% \begin{macrocode}
\def\bbl@ifblank#1{%
\bbl@ifblank@i#1\@nil\@nil\@secondoftwo\@firstoftwo\@nil}
\long\def\bbl@ifblank@i#1#2\@nil#3#4#5\@nil{#4}
\def\bbl@ifset#1#2#3{%
\bbl@ifunset{#1}{#3}{\bbl@exp{\\\bbl@ifblank{\@nameuse{#1}}}{#3}{#2}}}
% \end{macrocode}
%
% For each element in the comma separated <key>|=|<value> list,
% execute <code> with |#1| and |#2| as the key and the value of
% current item (trimmed). In addition, the item is passed verbatim as
% |#3|. With the <key> alone, it passes |\@empty| as value (i.e., the
% macro thus named, not an empty argument, which is what you get with
% <key>|=| and no value).
%
% \begin{macrocode}
\def\bbl@forkv#1#2{%
\def\bbl@kvcmd##1##2##3{#2}%
\bbl@kvnext#1,\@nil,}
\def\bbl@kvnext#1,{%
\ifx\@nil#1\relax\else
\bbl@ifblank{#1}{}{\bbl@forkv@eq#1=\@empty=\@nil{#1}}%
\expandafter\bbl@kvnext
\fi}
\def\bbl@forkv@eq#1=#2=#3\@nil#4{%
\bbl@trim@def\bbl@forkv@a{#1}%
\bbl@trim{\expandafter\bbl@kvcmd\expandafter{\bbl@forkv@a}}{#2}{#4}}
% \end{macrocode}
%
% A \textit{for} loop. Each item (trimmed) is |#1|. It cannot be
% nested (it's doable, but we don't need it).
%
% \begin{macrocode}
\def\bbl@vforeach#1#2{%
\def\bbl@forcmd##1{#2}%
\bbl@fornext#1,\@nil,}
\def\bbl@fornext#1,{%
\ifx\@nil#1\relax\else
\bbl@ifblank{#1}{}{\bbl@trim\bbl@forcmd{#1}}%
\expandafter\bbl@fornext
\fi}
\def\bbl@foreach#1{\expandafter\bbl@vforeach\expandafter{#1}}
% \end{macrocode}
%
% Some code should be executed once. The first argument is a flag.
%
% \begin{macrocode}
\global\let\bbl@done\@empty
\def\bbl@once#1#2{%
\bbl@xin@{,#1,}{,\bbl@done,}%
\ifin@\else
#2%
\xdef\bbl@done{\bbl@done,#1,}%
\fi}
% \end{macrode}
%
% \macro{\bbl@replace}
%
% Returns implicitly |\toks@| with the modified string.
%
% \begin{macrocode}
\def\bbl@replace#1#2#3{% in #1 -> repl #2 by #3
\toks@{}%
\def\bbl@replace@aux##1#2##2#2{%
\ifx\bbl@nil##2%
\toks@\expandafter{\the\toks@##1}%
\else
\toks@\expandafter{\the\toks@##1#3}%
\bbl@afterfi
\bbl@replace@aux##2#2%
\fi}%
\expandafter\bbl@replace@aux#1#2\bbl@nil#2%
\edef#1{\the\toks@}}
% \end{macrocode}
%
% An extension to the previous macro. It takes into account the
% parameters, and it is string based (i.e., if you replace |elax| by
% |ho|, then |\relax| becomes |\rho|). No checking is done at all,
% because it is not a general purpose macro, and it is used by \babel{}
% only when it works (an example where it does \textit{not} work is in
% |\bbl@TG@@date|, and also fails if there are macros with spaces,
% because they are retokenized). It may change! (or even merged with
% |\bbl@replace|; I'm not sure checking the replacement is really
% necessary or just paranoia).
%
% \begin{macrocode}
\ifx\detokenize\@undefined\else % Unused macros if old Plain TeX
\bbl@exp{\def\\\bbl@parsedef##1\detokenize{macro:}}#2->#3\relax{%
\def\bbl@tempa{#1}%
\def\bbl@tempb{#2}%
\def\bbl@tempe{#3}}
\def\bbl@sreplace#1#2#3{%
\begingroup
\expandafter\bbl@parsedef\meaning#1\relax
\def\bbl@tempc{#2}%
\edef\bbl@tempc{\expandafter\strip@prefix\meaning\bbl@tempc}%
\def\bbl@tempd{#3}%
\edef\bbl@tempd{\expandafter\strip@prefix\meaning\bbl@tempd}%
\bbl@xin@{\bbl@tempc}{\bbl@tempe}% If not in macro, do nothing
\ifin@
\bbl@exp{\\\bbl@replace\\\bbl@tempe{\bbl@tempc}{\bbl@tempd}}%
\def\bbl@tempc{% Expanded an executed below as 'uplevel'
\\\makeatletter % "internal" macros with @ are assumed
\\\scantokens{%
\bbl@tempa\\\@namedef{\bbl@stripslash#1}\bbl@tempb{\bbl@tempe}%
\noexpand\noexpand}%
\catcode64=\the\catcode64\relax}% Restore @
\else
\let\bbl@tempc\@empty % Not \relax
\fi
\bbl@exp{% For the 'uplevel' assignments
\endgroup
\bbl@tempc}} % empty or expand to set #1 with changes
\fi
% \end{macrocode}
%
% Two further tools. |\bbl@ifsamestring| first expand its arguments and
% then compare their expansion (sanitized, so that the catcodes do not
% matter). |\bbl@engine| takes the following values: 0 is pdf\TeX, 1
% is \luatex, and 2 is \xetex. You may use the latter it in your
% language style if you want.
%
% \begin{macrocode}
\def\bbl@ifsamestring#1#2{%
\begingroup
\protected@edef\bbl@tempb{#1}%
\edef\bbl@tempb{\expandafter\strip@prefix\meaning\bbl@tempb}%
\protected@edef\bbl@tempc{#2}%
\edef\bbl@tempc{\expandafter\strip@prefix\meaning\bbl@tempc}%
\ifx\bbl@tempb\bbl@tempc
\aftergroup\@firstoftwo
\else
\aftergroup\@secondoftwo
\fi
\endgroup}
\chardef\bbl@engine=%
\ifx\directlua\@undefined
\ifx\XeTeXinputencoding\@undefined
\z@
\else
\tw@
\fi
\else
\@ne
\fi
% \end{macrocode}
%
% A somewhat hackish tool (hence its name) to avoid spurious spaces in
% some contexts.
%
% \begin{macrocode}
\def\bbl@bsphack{%
\ifhmode
\hskip\z@skip
\def\bbl@esphack{\loop\ifdim\lastskip>\z@\unskip\repeat\unskip}%
\else
\let\bbl@esphack\@empty
\fi}
% \end{macrocode}
%
% Another hackish tool, to apply case changes inside a protected
% macros. It's based on the internal |\let|'s made by |\MakeUppercase|
% and |\MakeLowercase| between things like |\oe| and |\OE|.
%
% \begin{macrocode}
\def\bbl@cased{%
\ifx\oe\OE
\expandafter\in@\expandafter
{\expandafter\OE\expandafter}\expandafter{\oe}%
\ifin@
\bbl@afterelse\expandafter\MakeUppercase
\else
\bbl@afterfi\expandafter\MakeLowercase
\fi
\else
\expandafter\@firstofone
\fi}
% \end{macrocode}
%
% The following adds some code to |\extras...| both before and after,
% while avoiding doing it twice. It's somewhat convoluted, to deal with
% |#|'s. Used to deal with alph, Alph and frenchspacing when there are
% already changes (with |\babel@save|).
%
% \begin{macrocode}
\def\bbl@extras@wrap#1#2#3{% 1:in-test, 2:before, 3:after
\toks@\expandafter\expandafter\expandafter{%
\csname extras\languagename\endcsname}%
\bbl@exp{\\\in@{#1}{\the\toks@}}%
\ifin@\else
\@temptokena{#2}%
\edef\bbl@tempc{\the\@temptokena\the\toks@}%
\toks@\expandafter{\bbl@tempc#3}%
\expandafter\edef\csname extras\languagename\endcsname{\the\toks@}%
\fi}
%<</Basic macros>>
% \end{macrocode}
%
% Some files identify themselves with a \LaTeX{} macro. The following
% code is placed before them to define (and then undefine) if not in
% \LaTeX.
%
% \begin{macrocode}
%<<*Make sure ProvidesFile is defined>>
\ifx\ProvidesFile\@undefined
\def\ProvidesFile#1[#2 #3 #4]{%
\wlog{File: #1 #4 #3 <#2>}%
\let\ProvidesFile\@undefined}
\fi
%<</Make sure ProvidesFile is defined>>
% \end{macrocode}
%
% \subsection{A few core definitions}
%
% \macro{\language}
%
% Just for compatibility, for not to touch |hyphen.cfg|.
%
% \begin{macrocode}
%<<*Define core switching macros>>
\ifx\language\@undefined
\csname newcount\endcsname\language
\fi
%<</Define core switching macros>>
% \end{macrocode}
%
% \macro{\last@language}
%
% Another counter is used to keep track of the allocated languages.
% \TeX{} and \LaTeX{} reserves for this purpose the count 19.
%
% \macro{\addlanguage}
%
% This macro was introduced for \TeX{} $<$ 2. Preserved for
% compatibility.
%
% \begin{macrocode}
%<<*Define core switching macros>>
\countdef\last@language=19
\def\addlanguage{\csname newlanguage\endcsname}
%<</Define core switching macros>>
% \end{macrocode}
%
% Now we make sure all required files are loaded. When the command
% |\AtBeginDocument| doesn't exist we assume that we are dealing with a
% plain-based format. In that case the file \file{plain.def} is needed
% (which also defines |\AtBeginDocument|, and therefore it is not
% loaded twice). We need the first part when the format is created, and
% |\orig@dump| is used as a flag. Otherwise, we need to use the second
% part, so |\orig@dump| is not defined (\file{plain.def} undefines it).
%
% Check if the current version of \file{switch.def} has been previously
% loaded (mainly, \file{hyphen.cfg}). If not, load it now. We cannot
% load |babel.def| here because we first need to declare and process
% the package options.
%
% \subsection{\LaTeX: \texttt{babel.sty} (start)}
%
% Here starts the style file for \LaTeX. It also takes care of a number
% of compatibility issues with other packages.
%
% \begin{macrocode}
%<*package>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{babel}%
[<@date@> v<@version@>
The multilingual framework for LuaLaTeX, pdfLaTeX and XeLaTeX]
% \end{macrocode}
%
% Start with some “private” debugging tools, and then define macros for
% errors. The global lua ‘space’ |Babel| is declared here, too (inside
% the test for |debug|).
%
% \begin{macrocode}
\@ifpackagewith{babel}{debug}
{\providecommand\bbl@trace[1]{\message{^^J[ #1 ]}}%
\let\bbl@debug\@firstofone
\ifx\directlua\@undefined\else
\directlua{
Babel = Babel or {}
Babel.debug = true }%
\input{babel-debug.tex}%
\fi}
{\providecommand\bbl@trace[1]{}%
\let\bbl@debug\@gobble
\ifx\directlua\@undefined\else
\directlua{
Babel = Babel or {}
Babel.debug = false }%
\fi}
% \end{macrocode}
%
% Macros to deal with errors, warnings, etc. Errors are stored in a
% separate file.
%
% \begin{macrocode}
\def\bbl@error#1{% Implicit #2#3#4
\begingroup
\catcode`\\=0 \catcode`\==12 \catcode`\`=12
\input errbabel.def
\endgroup
\bbl@error{#1}}
\def\bbl@warning#1{%
\begingroup
\def\\{\MessageBreak}%
\PackageWarning{babel}{#1}%
\endgroup}
\def\bbl@infowarn#1{%
\begingroup
\def\\{\MessageBreak}%
\PackageNote{babel}{#1}%
\endgroup}
\def\bbl@info#1{%
\begingroup
\def\\{\MessageBreak}%
\PackageInfo{babel}{#1}%
\endgroup}
% \end{macrocode}
%
% 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.
%
% But first, include here the \textit{Basic macros} defined above.
%
% \begin{macrocode}
<@Basic macros@>
\@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. Also available with |base|, because it just shows
% info.
%
% \begin{macrocode}
\ifx\bbl@languages\@undefined\else
\begingroup
\catcode`\^^I=12
\@ifpackagewith{babel}{showlanguages}{%
\begingroup
\def\bbl@elt#1#2#3#4{\wlog{#2^^I#1^^I#3^^I#4}}%
\wlog{<*languages>}%
\bbl@languages
\wlog{</languages>}%
\endgroup}{}
\endgroup
\def\bbl@elt#1#2#3#4{%
\ifnum#2=\z@
\gdef\bbl@nulllanguage{#1}%
\def\bbl@elt##1##2##3##4{}%
\fi}%
\bbl@languages
\fi%
% \end{macrocode}
% \subsection{\texttt{base}}
%
% The first `real' option to be processed is |base|, which set the
% hyphenation patterns then resets |
[email protected]| 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 interested 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
[email protected]\endcsname\relax
\global\expandafter\let\csname
[email protected]\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
% package options are kept in the option list. Modifiers are saved and
% assigned to |\BabelModifiers| at |\bbl@load@language|; when no
% modifiers have been given, the former is |\relax|.
%
% \begin{macrocode}
\bbl@trace{key=value and another general options}
\bbl@csarg\let{tempa\expandafter}\csname
[email protected]\endcsname
\def\bbl@tempb#1.#2{% Removes trailing dot
#1\ifx\@empty#2\else,\bbl@afterfi\bbl@tempb#2\fi}%
\def\bbl@tempe#1=#2\@@{%
\bbl@csarg\edef{mod@#1}{\bbl@tempb#2}}
\def\bbl@tempd#1.#2\@nnil{%
\ifx\@empty#2%
\edef\bbl@tempc{\ifx\bbl@tempc\@empty\else\bbl@tempc,\fi#1}%
\else
\in@{,provide=}{,#1}%
\ifin@
\edef\bbl@tempc{%
\ifx\bbl@tempc\@empty\else\bbl@tempc,\fi#1.\bbl@tempb#2}%
\else
\in@{$modifiers$}{$#1$}%
\ifin@
\bbl@tempe#2\@@
\else
\in@{=}{#1}%
\ifin@
\edef\bbl@tempc{\ifx\bbl@tempc\@empty\else\bbl@tempc,\fi#1.#2}%
\else
\edef\bbl@tempc{\ifx\bbl@tempc\@empty\else\bbl@tempc,\fi#1}%
\bbl@csarg\edef{mod@#1}{\bbl@tempb#2}%
\fi
\fi
\fi
\fi}
\let\bbl@tempc\@empty
\bbl@foreach\bbl@tempa{\bbl@tempd#1.\@empty\@nnil}
\expandafter\let\csname
[email protected]\endcsname\bbl@tempc
% \end{macrocode}
%
% 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
% this can help.
%
% \begin{macrocode}
\DeclareOption{KeepShorthandsActive}{}
\DeclareOption{activeacute}{}
\DeclareOption{activegrave}{}
\DeclareOption{debug}{}
\DeclareOption{noconfigs}{}
\DeclareOption{showlanguages}{}
\DeclareOption{silent}{}
\DeclareOption{shorthands=off}{\bbl@tempa shorthands=\bbl@tempa}
\chardef\bbl@iniflag\z@
\DeclareOption{provide=*}{\chardef\bbl@iniflag\@ne} % main = 1
\DeclareOption{provide+=*}{\chardef\bbl@iniflag\tw@} % second = 2
\DeclareOption{provide*=*}{\chardef\bbl@iniflag\thr@@} % second + main
% Don't use. Experimental.
\newif\ifbbl@single
\DeclareOption{selectors=off}{\bbl@singletrue}
<@More package options@>
% \end{macrocode}
%
% Handling of package options is done in three passes. (I [JBL] am not
% very happy with the idea, anyway.) The first one processes options
% which has been declared above or follow the syntax |<key>=<value>|,
% the second one loads the requested languages, except the main one if
% set with the key |main|, and the third one loads the latter. First,
% we “flag” valid keys with a nil value.
%
% \begin{macrocode}
\let\bbl@opt@shorthands\@nnil
\let\bbl@opt@config\@nnil
\let\bbl@opt@main\@nnil
\let\bbl@opt@headfoot\@nnil
\let\bbl@opt@layout\@nnil
\let\bbl@opt@provide\@nnil
% \end{macrocode}
%
% The following tool is defined temporarily to store the values of
% options.
%
% \begin{macrocode}
\def\bbl@tempa#1=#2\bbl@tempa{%
\bbl@csarg\ifx{opt@#1}\@nnil
\bbl@csarg\edef{opt@#1}{#2}%
\else
\bbl@error{bad-package-option}{#1}{#2}{}%
\fi}
% \end{macrocode}
%
% Now the option list is processed, taking into account only currently
% declared options (including those declared with a |=|), and
% |<key>=<value>| options (the former take precedence). Unrecognized
% options are saved in |\bbl@language@opts|, because they are language
% options.
%
% \begin{macrocode}
\let\bbl@language@opts\@empty
\DeclareOption*{%
\bbl@xin@{\string=}{\CurrentOption}%
\ifin@
\expandafter\bbl@tempa\CurrentOption\bbl@tempa
\else
\bbl@add@list\bbl@language@opts{\CurrentOption}%
\fi}
% \end{macrocode}
%
% Now we finish the first pass (and start over).
%
% \begin{macrocode}
\ProcessOptions*
% \end{macrocode}
%
% \subsection{Post-process some options}
%
% \begin{macrocode}
\ifx\bbl@opt@provide\@nnil
\let\bbl@opt@provide\@empty % %%% MOVE above
\else
\chardef\bbl@iniflag\@ne
\bbl@exp{\\\bbl@forkv{\@nameuse{@raw@
[email protected]}}}{%
\in@{,provide,}{,#1,}%
\ifin@
\def\bbl@opt@provide{#2}%
\fi}
\fi
% \end{macrocode}
%
% If there is no |shorthands=<chars>|, the original \textsf{babel}
% macros are left untouched, but if there is, these macros are
% wrapped (in |babel.def|) to define only those given.
%
% A bit of optimization: if there is no |shorthands=|, then
% |\bbl@ifshorthand| is always true, and it is always false if
% |shorthands| is empty. Also, some code makes sense only with
% |shorthands=...|.
%
% \begin{macrocode}
\bbl@trace{Conditional loading of shorthands}
\def\bbl@sh@string#1{%
\ifx#1\@empty\else
\ifx#1t\string~%
\else\ifx#1c\string,%
\else\string#1%
\fi\fi
\expandafter\bbl@sh@string
\fi}
\ifx\bbl@opt@shorthands\@nnil
\def\bbl@ifshorthand#1#2#3{#2}%
\else\ifx\bbl@opt@shorthands\@empty
\def\bbl@ifshorthand#1#2#3{#3}%
\else
% \end{macrocode}
%
% The following macro tests if a shorthand is one of the allowed ones.
%
% \begin{macrocode}
\def\bbl@ifshorthand#1{%
\bbl@xin@{\string#1}{\bbl@opt@shorthands}%
\ifin@
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi}
% \end{macrocode}
%
% We make sure all chars in the string are `other', with the help
% of an auxiliary macro defined above (which also zaps spaces).
%
% \begin{macrocode}
\edef\bbl@opt@shorthands{%
\expandafter\bbl@sh@string\bbl@opt@shorthands\@empty}%
% \end{macrocode}
%
% The following is ignored with |shorthands=off|, since it is
% intended to take some additional actions for certain chars.
%
% \begin{macrocode}
\bbl@ifshorthand{'}%
{\PassOptionsToPackage{activeacute}{babel}}{}
\bbl@ifshorthand{`}%
{\PassOptionsToPackage{activegrave}{babel}}{}
\fi\fi
% \end{macrocode}
%
% With |headfoot=lang| we can set the language used in heads/feet.
% For example, in babel/3796 just add |headfoot=english|. It
% misuses \cs{@resetactivechars}, but seems to work.
%
% \begin{macrocode}
\ifx\bbl@opt@headfoot\@nnil\else
\g@addto@macro\@resetactivechars{%
\set@typeset@protect
\expandafter\select@language@x\expandafter{\bbl@opt@headfoot}%
\let\protect\noexpand}
\fi
% \end{macrocode}
%
% For the option safe we use a different approach -- |\bbl@opt@safe|
% says which macros are redefined (B for bibs and R for refs). By
% default, both are currently set, but in a future release it will be set to
% |none|.
%
% \begin{macrocode}
\ifx\bbl@opt@safe\@undefined
\def\bbl@opt@safe{BR}
% \let\bbl@opt@safe\@empty % Pending of \cite
\fi
% \end{macrocode}
%
% For |layout| an auxiliary macro is provided, available for packages
% and language styles. Optimization: if there is no |layout|, just do
% nothing.
%
% \begin{macrocode}
\bbl@trace{Defining IfBabelLayout}
\ifx\bbl@opt@layout\@nnil
\newcommand\IfBabelLayout[3]{#3}%
\else
\bbl@exp{\\\bbl@forkv{\@nameuse{@raw@
[email protected]}}}{%
\in@{,layout,}{,#1,}%
\ifin@
\def\bbl@opt@layout{#2}%
\bbl@replace\bbl@opt@layout{ }{.}%
\fi}
\newcommand\IfBabelLayout[1]{%
\@expandtwoargs\in@{.#1.}{.\bbl@opt@layout.}%
\ifin@
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi}
\fi
%</package>
% \end{macrocode}
%
% \subsection{Plain: \texttt{babel.def} (start)}
%
% Because of the way \pkg{docstrip} works, we need to insert some code
% for Plain here. However, the tools provided by the \babel{}
% installer for literate programming makes this section a short
% interlude, because the actual code is below, tagged as
% \textit{Emulate LaTeX}.
%
% First, exit immediately if previouly loaded.
%
% \begin{macrocode}
%<*core>
\ifx\ldf@quit\@undefined\else
\endinput\fi % Same line!
<@Make sure ProvidesFile is defined@>
\ProvidesFile{babel.def}[<@date@> v<@version@> Babel common definitions]
\ifx\AtBeginDocument\@undefined
<@Emulate LaTeX@>
\fi
<@Basic macros@>
%</core>
% \end{macrocode}
%
% That is all for the moment. Now follows some common stuff, for both
% Plain and \LaTeX{}. After it, we will resume the \LaTeX-only stuff.
%
% \section{\texttt{babel.sty} and \texttt{babel.def} (common)}
%
% \begin{macrocode}
%<*package|core>
\def\bbl@version{<@version@>}
\def\bbl@date{<@date@>}
<@Define core switching macros@>
% \end{macrocode}
%
% \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\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
\edef\bbl@tempa{\expandafter\@gobbletwo\string#1}%
\bbl@info{Hyphen rules for '\expandafter\@gobble\bbl@tempa'
set to \expandafter\string\csname l@##1\endcsname\\%
(\string\language\the\count@). Reported}%
\def\bbl@elt####1####2####3####4{}%
\fi}%
\bbl@cs{languages}%
\endgroup}
% \end{macrocode}
%
% |\bbl@iflanguage| executes code only if the language |l@| exists.
% Otherwise raises an 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 an attempt to fix a
% long-standing bug when |\foreignlanguage| and the like appear in a
% |\MakeXXXcase|. However, a lowercase form is not imposed to improve
% backward compatibility (perhaps you defined a language named
% |MYLANG|, but unfortunately mixed case names cannot be trapped). Note
% |l@| is encapsulated, so that its case does not change.
%
% \begin{macrocode}
\def\bbl@fixname#1{%
\begingroup
\def\bbl@tempe{l@}%
\edef\bbl@tempd{\noexpand\@ifundefined{\noexpand\bbl@tempe#1}}%
\bbl@tempd
{\lowercase\expandafter{\bbl@tempd}%
{\uppercase\expandafter{\bbl@tempd}%
\@empty
{\edef\bbl@tempd{\def\noexpand#1{#1}}%
\uppercase\expandafter{\bbl@tempd}}}%
{\edef\bbl@tempd{\def\noexpand#1{#1}}%
\lowercase\expandafter{\bbl@tempd}}}%
\@empty
\edef\bbl@tempd{\endgroup\def\noexpand#1{#1}}%
\bbl@tempd
\bbl@exp{\\\bbl@usehooks{languagename}{{\languagename}{#1}}}}
\def\bbl@iflanguage#1{%
\@ifundefined{l@#1}{\@nolanerr{#1}\@gobble}\@firstofone}
% \end{macrocode}
%
% After a name has been ‘fixed’, the selectors will try to load the
% language. If even the fixed name is not defined, will load it on the
% fly, either based on its name, or if activated, its BCP 47 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| tag or it is
% |\relax|.
%
% \begin{macrocode}
\def\bbl@bcpcase#1#2#3#4\@@#5{%
\ifx\@empty#3%
\uppercase{\def#5{#1#2}}%
\else
\uppercase{\def#5{#1}}%
\lowercase{\edef#5{#5#2#3#4}}%
\fi}
\def\bbl@bcplookup#1-#2-#3-#4\@@{%
\let\bbl@bcp\relax
\lowercase{\def\bbl@tempa{#1}}%
\ifx\@empty#2%
\IfFileExists{babel-\
[email protected]}{\let\bbl@bcp\bbl@tempa}{}%
\else\ifx\@empty#3%
\bbl@bcpcase#2\@empty\@empty\@@\bbl@tempb
\IfFileExists{babel-\bbl@tempa-\
[email protected]}%
{\edef\bbl@bcp{\bbl@tempa-\bbl@tempb}}%
{}%
\ifx\bbl@bcp\relax
\IfFileExists{babel-\
[email protected]}{\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-\
[email protected]}%
{\edef\bbl@bcp{\bbl@tempa-\bbl@tempb-\bbl@tempc}}%
{}%
\ifx\bbl@bcp\relax
\IfFileExists{babel-\bbl@tempa-\
[email protected]}%
{\edef\bbl@bcp{\bbl@tempa-\bbl@tempc}}%
{}%
\fi
\ifx\bbl@bcp\relax
\IfFileExists{babel-\bbl@tempa-\
[email protected]}%
{\edef\bbl@bcp{\bbl@tempa-\bbl@tempc}}%
{}%
\fi
\ifx\bbl@bcp\relax
\IfFileExists{babel-\
[email protected]}{\let\bbl@bcp\bbl@tempa}{}%
\fi
\fi\fi}
\let\bbl@initoload\relax
% \end{macrocode}
%
% \macro{\iflanguage}
% Users might want to test (in a private package for instance)
% which language is currently active. For this we provide a test
% macro, |\iflanguage|, that has three arguments. It checks
% whether the first argument is a known language. If so, it
% compares the first argument with the value of |\language|. Then,
% depending on the result of the comparison, it executes either the
% second or the third argument.
%
% \begin{macrocode}
\def\iflanguage#1{%
\bbl@iflanguage{#1}{%
\ifnum\csname l@#1\endcsname=\language
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi}}
% \end{macrocode}
%
% \subsection{Selecting the language}
%
% \macro{\selectlanguage}
%
% It checks whether the language is
% already defined before it performs its actual task, which is to
% update |\language| and activate language-specific definitions.
%
% \begin{macrocode}
\let\bbl@select@type\z@
\edef\selectlanguage{%
\noexpand\protect
\expandafter\noexpand\csname selectlanguage \endcsname}
% \end{macrocode}
%
% Because the command |\selectlanguage| could be used in a moving
% argument it expands to \verb*=\protect\selectlanguage =.
% Therefore, we have to make sure that a macro |\protect| exists.
% If it doesn't it is |\let| to |\relax|.
%
% \begin{macrocode}
\ifx\@undefined\protect\let\protect\relax\fi
% \end{macrocode}
%
% The following definition is preserved for backwards compatibility
% (e.g., \textsf{arabi}, \textsf{koma}). It is related to a trick for
% 2.09, now discarded.
%
% \begin{macrocode}
\let\xstring\string
% \end{macrocode}
%
% Since version 3.5 \babel\ writes entries to the auxiliary files in
% order to typeset table of contents etc. in the correct language
% environment.
%
% \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.
%
% \macro{\bbl@language@stack}
% The previous solution works for one level of nesting groups, but
% as soon as more levels are used it is no longer adequate. For
% that case we need to keep track of the nested languages using a
% stack mechanism. This stack is called |\bbl@language@stack| and
% initially empty.
%
% \begin{macrocode}
\def\bbl@language@stack{}
% \end{macrocode}
%
% When using a stack we need a mechanism to push an element on the
% stack and to retrieve the information afterwards.
%
% \macro{\bbl@push@language}
% \macro{\bbl@pop@language}
% The stack is simply a list of languagenames, separated with a `+'
% sign; the push function can be simple:
%
% \begin{macrocode}
\def\bbl@push@language{%
\ifx\languagename\@undefined\else
\ifx\currentgrouplevel\@undefined
\xdef\bbl@language@stack{\languagename+\bbl@language@stack}%
\else
\ifnum\currentgrouplevel=\z@
\xdef\bbl@language@stack{\languagename+}%
\else
\xdef\bbl@language@stack{\languagename+\bbl@language@stack}%
\fi
\fi
\fi}
% \end{macrocode}
%
% Retrieving information from the stack is a little bit less simple, as
% we need to remove the element from the stack while storing it in the
% macro |\languagename|. For this we first define a helper function.
%
% \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 in
% |\bbl@language@stack|.
%
% \begin{macrocode}
\def\bbl@pop@lang#1+#2\@@{%
\edef\languagename{#1}%
\xdef\bbl@language@stack{#2}}
% \end{macrocode}
%
% 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).
%
% \begin{macrocode}
\let\bbl@ifrestoring\@secondoftwo
\def\bbl@pop@language{%
\expandafter\bbl@pop@lang\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.
%
% An alternative way to identify languages (in the \babel{} sense)
% with a numerical value is introduced in 3.30. This is one of the
% first steps for a new interface based on the concept of locale,
% which explains the name of |\localeid|. This means |\l@...| will be
% reserved for hyphenation patterns (so that two locales can share the
% same rules).
%
% \begin{macrocode}
\chardef\localeid\z@
\gdef\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
\global\bbl@csarg\chardef{id@@\languagename}\count@
\xdef\bbl@id@last{\the\count@}%
\ifcase\bbl@engine\or
\directlua{
Babel.locale_props[\bbl@id@last] = {}
Babel.locale_props[\bbl@id@last].name = '\languagename'
Babel.locale_props[\bbl@id@last].vars = {}
}%
\fi}%
{}%
\chardef\localeid\bbl@cl{id@}}
% \end{macrocode}
%
% The unprotected part of |\selectlanguage|. In case it is used as
% environment, declare |\endselectlaguage|, just for safety.
%
% \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}}
\let\endselectlanguage\relax
% \end{macrocode}
%
% \macro{\bbl@set@language}
%
% The macro |\bbl@set@language| takes care of switching the language
% environment \emph{and} of writing entries on the auxiliary files.
% For historical reasons, language names can be either |language| of
% |\language|. To catch either form a trick is used, but
% unfortunately as a side effect the catcodes of letters in
% |\languagename| are messed up. This is a bug, but preserved for
% backwards compatibility. The list of auxiliary files can be
% extended by redefining |\BabelContentsFiles|, but make sure they
% are loaded inside a group (as |aux|, |toc|, |lof|, and |lot| do)
% or the last language of the document will remain active
% afterwards.
%
% We also write a command to change the current language in the
% auxiliary files.
%
% |\bbl@savelastskip| is used to deal with skips before the write
% whatsit (as suggested by U Fischer). Adapted from \textsf{hyperref},
% but it might fail, so I'll consider it a temporary hack, while I
% study other options (the ideal, but very likely unfeasible except
% perhaps in \luatex, is to avoid the |\write| altogether when not
% needed).
%
% \begin{macrocode}
\def\BabelContentsFiles{toc,lof,lot}
\def\bbl@set@language#1{% from selectlanguage, pop@
% The old buggy way. Preserved for compatibility, but simplified
\edef\languagename{\expandafter\string#1\@empty}%
\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
\bbl@savelastskip
\protected@write\@auxout{}{\string\babel@aux{\bbl@auxname}{}}%
\bbl@restorelastskip
\fi
\bbl@usehooks{write}{}%
\fi
\fi}
%
\let\bbl@restorelastskip\relax
\let\bbl@savelastskip\relax
%
\def\select@language#1{% from set@, babel@aux, babel@toc
\ifx\bbl@selectorname\@empty
\def\bbl@selectorname{select}%
\fi
% set hymap
\ifnum\bbl@hymapsel=\@cclv\chardef\bbl@hymapsel4\relax\fi
% set name (when coming from babel@aux)
\edef\languagename{#1}%
\bbl@fixname\languagename
% define \localename when coming from set@, with a trick
\ifx\scantokens\@undefined
\def\localename{??}%
\else
\bbl@exp{\\\scantokens{\def\\\localename{\languagename}\\\noexpand}\relax}%
\fi
\bbl@provide@locale
\bbl@iflanguage\languagename{%
\let\bbl@select@type\z@
\expandafter\bbl@switch\expandafter{\languagename}}}
\def\babel@aux#1#2{%
\select@language{#1}%
\bbl@foreach\BabelContentsFiles{% \relax -> don't assume vertical mode
\@writefile{##1}{\babel@toc{#1}{#2}\relax}}}%
\def\babel@toc#1#2{%
\select@language{#1}}
% \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.
%
% 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.
%
% No text is supposed to be added with switching captions and date, so
% we remove any spurious spaces with |\bbl@bsphack| and |\bbl@esphack|.
%
% \begin{macrocode}
\newif\ifbbl@usedategroup
\let\bbl@savedextras\@empty
\def\bbl@switch#1{% from select@, foreign@
% 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
\bbl@bsphack
\ifcase\bbl@select@type
\csname captions#1\endcsname\relax
\csname date#1\endcsname\relax
\else
\bbl@xin@{,captions,}{,\bbl@select@opts,}%
\ifin@
\csname captions#1\endcsname\relax
\fi
\bbl@xin@{,date,}{,\bbl@select@opts,}%
\ifin@ % if \foreign... within \<language>date
\csname date#1\endcsname\relax
\fi
\fi
\bbl@esphack
% switch extras
\csname bbl@preextras@#1\endcsname
\bbl@usehooks{beforeextras}{}%
\csname extras#1\endcsname\relax
\bbl@usehooks{afterextras}{}%
% > babel-ensure
% > babel-sh-<short>
% > babel-bidi
% > babel-fontspec
\let\bbl@savedextras\@empty
% 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
\let\bbl@hymapsel\@cclv
% hyphenation - select rules
\ifnum\csname l@\languagename\endcsname=\l@unhyphenated
\edef\bbl@tempa{u}%
\else
\edef\bbl@tempa{\bbl@cl{lnbrk}}%
\fi
% linebreaking - handle u, e, k (v in the future)
\bbl@xin@{/u}{/\bbl@tempa}%
\ifin@\else\bbl@xin@{/e}{/\bbl@tempa}\fi % elongated forms
\ifin@\else\bbl@xin@{/k}{/\bbl@tempa}\fi % only kashida
\ifin@\else\bbl@xin@{/p}{/\bbl@tempa}\fi % padding (e.g., Tibetan)
\ifin@\else\bbl@xin@{/v}{/\bbl@tempa}\fi % variable font
% hyphenation - save mins
\babel@savevariable\lefthyphenmin
\babel@savevariable\righthyphenmin
\ifnum\bbl@engine=\@ne
\babel@savevariable\hyphenationmin
\fi
\ifin@
% unhyphenated/kashida/elongated/padding = allow stretching
\language\l@unhyphenated
\babel@savevariable\emergencystretch
\emergencystretch\maxdimen
\babel@savevariable\hbadness
\hbadness\@M
\else
% other = select patterns
\bbl@patterns{#1}%
\fi
% hyphenation - set mins
\expandafter\ifx\csname #1hyphenmins\endcsname\relax
\set@hyphenmins\tw@\thr@@\relax
\@nameuse{bbl@hyphenmins@}%
\else
\expandafter\expandafter\expandafter\set@hyphenmins
\csname #1hyphenmins\endcsname\relax
\fi
\@nameuse{bbl@hyphenmins@}%
\@nameuse{bbl@hyphenmins@\languagename}%
\@nameuse{bbl@hyphenatmin@}%
\@nameuse{bbl@hyphenatmin@\languagename}%
\let\bbl@selectorname\@empty}
% \end{macrocode}
%
% \environment{otherlanguage}
% It can be used as an alternative to
% using the |\selectlanguage| declarative command. The |\ignorespaces|
% command is necessary to hide the environment when it is entered in
% horizontal mode.
%
% \begin{macrocode}
\long\def\otherlanguage#1{%
\def\bbl@selectorname{other}%
\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{\@ignoretrue\ignorespaces}
% \end{macrocode}
%
% \environment{otherlanguage*}
% It 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'.
% It makes use of |\foreign@language|.
%
% \begin{macrocode}
\expandafter\def\csname otherlanguage*\endcsname{%
\@ifnextchar[\bbl@otherlanguage@s{\bbl@otherlanguage@s[]}}
\def\bbl@otherlanguage@s[#1]#2{%
\def\bbl@selectorname{other*}%
\ifnum\bbl@hymapsel=\@cclv\chardef\bbl@hymapsel4\relax\fi
\def\bbl@select@opts{#1}%
\foreign@language{#2}}
% \end{macrocode}
%
% At the end of the environment we need to switch off the extra
% definitions. The grouping mechanism of the environment will take
% care of resetting the correct hyphenation rules and “extras”.
%
% \begin{macrocode}
\expandafter\let\csname endotherlanguage*\endcsname\relax
% \end{macrocode}
%
% \macro{\foreignlanguage}
%
% This command takes two arguments, the first argument is the name of
% the language to use for typesetting the text specified in the second
% argument.
%
% Unlike |\selectlanguage| this command doesn't switch
% \emph{everything}, it only switches the hyphenation rules and the
% extra definitions for the language specified. It does this within
% a group and assumes the |\extras|\langvar\ command doesn't make
% any |\global| changes. The coding is very similar to part of
% |\selectlanguage|.
%
% |\bbl@beforeforeign| is a trick to fix a bug in bidi
% texts. |\foreignlanguage| is supposed to be a `text' command, and
% therefore it must emit a |\leavevmode|, but it does not, and
% therefore the indent is placed on the opposite margin. For
% backward compatibility, however, it is done only if a
% right-to-left script is requested; otherwise, it is no-op.
%
% (3.11) |\foreignlanguage*| is a temporary, experimental macro for
% a few lines with a different script direction, while preserving
% the paragraph format (thank the braces around |\par|, things like
% |\hangindent| are not reset). Do not use it in production,
% because its semantics and its syntax may change (and very likely
% will, or even it could be removed altogether). Currently it
% enters in vmode and then selects the language (which in turn sets the
% paragraph direction).
%
% (3.11) Also experimental are the hook |foreign| and |foreign*|.
% With them you can redefine |\BabelText| which by default does
% nothing. Its behavior is not well defined yet. So, use it in
% horizontal mode only if you do not want surprises.
%
% In other words, at the beginning of a paragraph |\foreignlanguage|
% enters into hmode with the surrounding lang, and with
% |\foreignlanguage*| with the new lang.
%
% \begin{macrocode}
\providecommand\bbl@beforeforeign{}
\edef\foreignlanguage{%
\noexpand\protect
\expandafter\noexpand\csname foreignlanguage \endcsname}
\expandafter\def\csname foreignlanguage \endcsname{%
\@ifstar\bbl@foreign@s\bbl@foreign@x}
\providecommand\bbl@foreign@x[3][]{%
\begingroup
\def\bbl@selectorname{foreign}%
\def\bbl@select@opts{#1}%
\let\BabelText\@firstofone
\bbl@beforeforeign
\foreign@language{#2}%
\bbl@usehooks{foreign}{}%
\BabelText{#3}% Now in horizontal mode!
\endgroup}
\def\bbl@foreign@s#1#2{%
\begingroup
{\par}%
\def\bbl@selectorname{foreign*}%
\let\bbl@select@opts\@empty
\let\BabelText\@firstofone
\foreign@language{#1}%
\bbl@usehooks{foreign*}{}%
\bbl@dirparastext
\BabelText{#2}% Still in vertical mode!
{\par}%
\endgroup}
\providecommand\BabelWrapText[1]{%
\def\bbl@tempa{\def\BabelText####1}%
\expandafter\bbl@tempa\expandafter{\BabelText{#1}}}
% \end{macrocode}
%
% \macro{\foreign@language}
%
% This macro does the work for |\foreignlanguage| and the
% \Lenv{otherlanguage*} environment. First we need to store the name
% of the language and check that it is a known language. Then it
% just calls |bbl@switch|.
%
% \begin{macrocode}
\def\foreign@language#1{%
% set name
\edef\languagename{#1}%
\ifbbl@usedategroup
\bbl@add\bbl@select@opts{,date,}%
\bbl@usedategroupfalse
\fi
\bbl@fixname\languagename
\let\localename\languagename
\bbl@provide@locale
\bbl@iflanguage\languagename{%
\let\bbl@select@type\@ne
\expandafter\bbl@switch\expandafter{\languagename}}}
% \end{macrocode}
%
% The following macro executes conditionally some code based on the
% selector being used.
%
% \begin{macrocode}
\def\IfBabelSelectorTF#1{%
\bbl@xin@{,\bbl@selectorname,}{,\zap@space#1 \@empty,}%
\ifin@
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi}
% \end{macrocode}
%
% \macro{\bbl@patterns}
%
% This macro selects the hyphenation patterns by changing the
% \cs{language} register. If special hyphenation patterns
% are available specifically for the current font encoding,
% use them instead of the default.
%
% It also sets hyphenation exceptions, but only once, because they
% are global (here language |\lccode|'s has been set, too).
% |\bbl@hyphenation@| is set to relax until the very first
% |\babelhyphenation|, so do nothing with this value. If the
% exceptions for a language (by its number, not its name, so that
% |:ENC| is taken into account) has been set, then use
% |\hyphenation| with both global and language exceptions and empty
% the latter to mark they must not be set again.
%
% \begin{macrocode}
\let\bbl@hyphlist\@empty
\let\bbl@hyphenation@\relax
\let\bbl@pttnlist\@empty
\let\bbl@patterns@\relax
\let\bbl@hymapsel=\@cclv
\def\bbl@patterns#1{%
\language=\expandafter\ifx\csname l@#1:\f@encoding\endcsname\relax
\csname l@#1\endcsname
\edef\bbl@tempa{#1}%
\else
\csname l@#1:\f@encoding\endcsname
\edef\bbl@tempa{#1:\f@encoding}%
\fi
\@expandtwoargs\bbl@usehooks{patterns}{{#1}{\bbl@tempa}}%
% > luatex
\@ifundefined{bbl@hyphenation@}{}{% Can be \relax!
\begingroup
\bbl@xin@{,\number\language,}{,\bbl@hyphlist}%
\ifin@\else
\@expandtwoargs\bbl@usehooks{hyphenation}{{#1}{\bbl@tempa}}%
\hyphenation{%
\bbl@hyphenation@
\@ifundefined{bbl@hyphenation@#1}%
\@empty
{\space\csname bbl@hyphenation@#1\endcsname}}%
\xdef\bbl@hyphlist{\bbl@hyphlist\number\language,}%
\fi
\endgroup}}
% \end{macrocode}
%
% \environment{hyphenrules}
%
% It can be used to select
% \emph{just} the hyphenation rules. It does
% \emph{not} change |\languagename| and when the hyphenation rules
% specified were not loaded it has no effect. Note however,
% |\lccode|'s and font encodings are not set at all, so in most
% cases you should use |otherlanguage*|.
%
% \begin{macrocode}
\def\hyphenrules#1{%
\edef\bbl@tempf{#1}%
\bbl@fixname\bbl@tempf
\bbl@iflanguage\bbl@tempf{%
\expandafter\bbl@patterns\expandafter{\bbl@tempf}%
\ifx\languageshorthands\@undefined\else
\languageshorthands{none}%
\fi
\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}
%
% \macro{\providehyphenmins}
% The macro |\providehyphenmins| should be used in the language
% definition files to provide a \emph{default} setting for the
% hyphenation parameters |\lefthyphenmin| and |\righthyphenmin|. If
% the macro |\|\langvar|hyphenmins| is already defined this command
% has no effect.
%
% \begin{macrocode}
\def\providehyphenmins#1#2{%
\expandafter\ifx\csname #1hyphenmins\endcsname\relax
\@namedef{#1hyphenmins}{#2}%
\fi}
% \end{macrocode}
%
% \macro{\set@hyphenmins}
% This macro sets the values of |\lefthyphenmin| and |\righthyphenmin|.
% It expects two values as its argument.
%
% \begin{macrocode}
\def\set@hyphenmins#1#2{%
\lefthyphenmin#1\relax
\righthyphenmin#2\relax}
% \end{macrocode}
%
% \macro{\ProvidesLanguage}
% The identification code for each file is something that was
% introduced in \LaTeXe. When the command |\ProvidesFile| does not
% exist, a dummy definition is provided temporarily. For use in the
% language definition file the command |\ProvidesLanguage| is
% defined by \babel.
%
% Depending on the format, i.e., or if the former is defined, we use
% a similar definition or not.
%
% \begin{macrocode}
\ifx\ProvidesFile\@undefined
\def\ProvidesLanguage#1[#2 #3 #4]{%
\wlog{Language: #1 #4 #3 <#2>}%
}
\else
\def\ProvidesLanguage#1{%
\begingroup
\catcode`\ 10 %
\@makeother\/%
\@ifnextchar[%]
{\@provideslanguage{#1}}{\@provideslanguage{#1}[]}}
\def\@provideslanguage#1[#2]{%
\wlog{Language: #1 #2}%
\expandafter\xdef\csname ver@#1.ldf\endcsname{#2}%
\endgroup}
\fi
% \end{macrocode}
%
% \macro{\originalTeX}
% The macro|\originalTeX| should be known to \TeX\ at this moment. As
% it has to be expandable we |\let| it to |\@empty| instead of
% |\relax|.
%
% \begin{macrocode}
\ifx\originalTeX\@undefined\let\originalTeX\@empty\fi
% \end{macrocode}
%
% Because this part of the code can be included in a format, we make
% sure that the macro which initializes the save mechanism,
% |\babel@beginsave|, is not considered to be undefined.
%
% \begin{macrocode}
\ifx\babel@beginsave\@undefined\let\babel@beginsave\relax\fi
% \end{macrocode}
%
% A few macro names are reserved for future releases of \babel, which
% will use the concept of `locale':
%
% \begin{macrocode}
\providecommand\setlocale{\bbl@error{not-yet-available}{}{}{}}
\let\uselocale\setlocale
\let\locale\setlocale
\let\selectlocale\setlocale
\let\textlocale\setlocale
\let\textlanguage\setlocale
\let\languagetext\setlocale
% \end{macrocode}
%
% \subsection{Errors}
%
% \macro{\@nolanerr}
% \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.
%
% \macro{\@noopterr}
% When the package was loaded without options not everything will
% work as expected. An error message is issued in that case.
%
% When the format knows about |\PackageError| it must be \LaTeXe,
% so we can safely use its error handling interface. Otherwise
% we'll have to `keep it simple'.
%
% Infos are not written to the console, but on the other hand many
% people think warnings are errors, so a further message type is
% defined: an important info which is sent to the console.
%
% \begin{macrocode}
\edef\bbl@nulllanguage{\string\language=0}
\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}%
\edef\bbl@tempa{#1}%
\bbl@sreplace\bbl@tempa{name}{}%
\bbl@warning{%
\@backslashchar#1 not set for '\languagename'. Please,\\%
define it after the language has been loaded\\%
(typically in the preamble) with:\\%
\string\setlocalecaption{\languagename}{\bbl@tempa}{..}\\%
Feel free to contribute on github.com/latex3/babel.\\%
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{undefined-language}{#1}{}{}}
\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
% \end{macrocode}
%
% Here ended the now discarded |switch.def|.
%
% Here also (currently) ends the \textsf{base} option.
%
% \begin{macrocode}
\ifx\bbl@onlyswitch\@empty\endinput\fi
% \end{macrocode}
%
% \subsection{More on selection}
%
% \macro{\babelensure}
%
% The user command just parses the optional argument and creates a
% new macro named |\bbl@e@<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.
%
% The macro |\bbl@e@<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}
\bbl@trace{Defining babelensure}
\newcommand\babelensure[2][]{%
\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\<bbl@e@#2>{\the\toks@{\bbl@ens@fontenc}}}}
\def\bbl@ensure#1#2#3{% 1: include 2: exclude 3: fontenc
\def\bbl@tempb##1{% elt for (excluding) \bbl@captionslist list
\ifx##1\@undefined % 3.32 - Don't assume the 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\<bbl@ensure@\languagename>[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}
% \end{macrocode}
%
% \subsection{Short tags}
%
% \macro{\babeltags}
% This macro is straightforward. After zapping spaces, we
% loop over the list and define the macros |\text<tag>| and
% |\<tag>|. Definitions are first expanded so that they don't
% contain |\csname| but the actual macro.
%
% \begin{macrocode}
\bbl@trace{Short tags}
\newcommand\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}
%
% \subsection{Compatibility with language.def}
%
% Plain e-\TeX{} doesn’t rely on language.dat, but babel can be made
% compatible with this format easily.
%
% \begin{macrocode}
\bbl@trace{Compatibility with language.def}
\ifx\directlua\@undefined\else
\ifx\bbl@luapatterns\@undefined
\input luababel.def
\fi
\fi
\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
% \end{macrocode}
%
% \macro{\addto}
% It takes two arguments, a \meta{control sequence} and \TeX-code to
% be added to the \meta{control sequence}.
%
% If the \meta{control sequence} has not been defined before it is
% defined now. The control sequence could also expand to |\relax|,
% in which case a circular definition results. The net result is a
% stack overflow. Note there is an inconsistency, because the
% assignment in the last branch is global.
%
% \begin{macrocode}
\def\addto#1#2{%
\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}
%
% \subsection{Hooks}
%
% Admittedly, the current implementation is a somewhat simplistic and
% does very little to catch errors, but it is meant for developers,
% after all. |\bbl@usehooks| is the commands used by \babel{} to execute
% hooks defined for an event.
%
% \begin{macrocode}
\bbl@trace{Hooks}
\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@elth{#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{\bbl@usehooks@lang\languagename}
\def\bbl@usehooks@lang#1#2#3{% Test for Plain
\ifx\UseHook\@undefined\else\UseHook{babel/*/#2}\fi
\def\bbl@elth##1{%
\bbl@cs{hk@##1}{\bbl@cs{ev@##1@#2@}#3}}%
\bbl@cs{ev@#2@}%
\ifx\languagename\@undefined\else % Test required for Plain (?)
\ifx\UseHook\@undefined\else\UseHook{babel/#1/#2}\fi
\def\bbl@elth##1{%
\bbl@cs{hk@##1}{\bbl@cs{ev@##1@#2@#1}#3}}%
\bbl@cs{ev@#2@#1}%
\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=2,begindocument=1}
\ifx\NewHook\@undefined\else % Test for Plain (?)
\def\bbl@tempa#1=#2\@@{\NewHook{babel/#1}}
\bbl@foreach\bbl@evargs{\bbl@tempa#1\@@}
\fi
% \end{macrocode}
%
% Since the following command is meant for a hook (although a \LaTeX{}
% one), it’s placed here.
%
% \begin{macrocode}
\providecommand\PassOptionsToLocale[2]{%
\bbl@csarg\bbl@add@list{passto@#2}{#1}}
% \end{macrocode}
%
% \subsection{Setting up language files}
%
% \macro{\LdfInit}
%
% |\LdfInit| macro takes two arguments. The first
% argument is the name of the language that will be defined in the
% language definition file; the second argument is either a control
% sequence or a string from which a control sequence should be
% constructed. The existence of the control sequence indicates that
% the file has been processed before.
%
% At the start of processing a language definition file we always
% check the category code of the at-sign. We make sure that it is
% a ‘letter’ during the processing of the file. We also save its
% name as the last called option, even if not loaded.
%
% Another character that needs to have the correct category code
% during processing of language definition files is the equals sign,
% `=', because it is sometimes used in constructions with the
% |\let| primitive. Therefore we store its current catcode and
% restore it later on.
%
% Now we check whether we should perhaps stop the processing of
% this file. To do this we first need to check whether the second
% argument that is passed to |\LdfInit| is a control sequence. We
% do that by looking at the first token after passing |#2| through
% |string|. When it is equal to |\@backslashchar| we are dealing
% with a control sequence which we can compare with |\@undefined|.
%
% If so, we call |\ldf@quit| to set the main language, restore the
% category code of the @-sign and call |\endinput|
%
% When |#2| was \emph{not} a control sequence we construct one and
% compare it with |\relax|.
%
% Finally we check |\originalTeX|.
%
% \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
\@ifpackagewith{babel}{ensureinfo=off}{}%
{\ifx\InputIfFileExists\@undefined\else
\bbl@ifunset{bbl@lname@#1}%
{{\let\bbl@ensuring\@empty % Flag used in babel-serbianc.tex
\def\languagename{#1}%
\bbl@id@assign
\bbl@load@info{#1}}}%
{}%
\fi}%
\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}
%
% \macro{\ldf@quit}
% This macro interrupts the processing of a language definition file.
% Remember |\endinput| is not executed immediately, but delayed to
% the end of the current line in the input file.
%
% \begin{macrocode}
\def\ldf@quit#1{%
\expandafter\main@language\expandafter{#1}%
\catcode`\@=\atcatcode \let\atcatcode\relax
\catcode`\==\eqcatcode \let\eqcatcode\relax
\endinput}
% \end{macrocode}
%
% \macro{\ldf@finish}
% This macro takes one argument. It is the name of the language that
% was defined in the language definition file.
%
% 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}
\def\bbl@afterldf{%
\bbl@afterlang
\let\bbl@afterlang\relax
\let\BabelModifiers\relax
\let\bbl@screset\relax}%
\def\ldf@finish#1{%
\loadlocalcfg{#1}%
\bbl@afterldf
\expandafter\main@language\expandafter{#1}%
\catcode`\@=\atcatcode \let\atcatcode\relax
\catcode`\==\eqcatcode \let\eqcatcode\relax}
% \end{macrocode}
%
% 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}
\@onlypreamble\LdfInit
\@onlypreamble\ldf@quit
\@onlypreamble\ldf@finish
% \end{macrocode}
%
% \macro{\main@language}
% \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}
\def\main@language#1{%
\def\bbl@main@language{#1}%
\let\languagename\bbl@main@language
\let\localename\bbl@main@language
\let\mainlocalename\bbl@main@language
\bbl@id@assign
\bbl@patterns{\languagename}}
% \end{macrocode}
%
% We also have to make sure that some code gets executed at the
% beginning of the document, 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|.
%
% The code written to the |aux| file attempts to avoid errors if
% \babel\ is removed from the document.
%
% \begin{macrocode}
\def\bbl@beforestart{%
\def\@nolanerr##1{%
\bbl@carg\chardef{l@##1}\z@
\bbl@warning{Undefined language '##1' in aux.\\Reported}}%
\bbl@usehooks{beforestart}{}%
\global\let\bbl@beforestart\relax}
\AtBeginDocument{%
{\@nameuse{bbl@beforestart}}% Group!
\if@filesw
\providecommand\babel@aux[2]{}%
\immediate\write\@mainaux{\unexpanded{%
\providecommand\babel@aux[2]{\global\let\babel@toc\@gobbletwo}}}%
\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
\AtBeginDocument{\pagedir\bodydir}
\fi
% \end{macrocode}
%
% A bit of optimization. Select in heads/feet the language only if
% necessary.
%
% \begin{macrocode}
\def\select@language@x#1{%
\ifcase\bbl@select@type
\bbl@ifsamestring\languagename{#1}{}{\select@language{#1}}%
\else
\select@language{#1}%
\fi}
% \end{macrocode}
%
% \subsection{Shorthands}
%
% 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.
%
% \begin{macrocode}
\bbl@trace{Shorhands}
\def\bbl@withactive#1#2{%
\begingroup
\lccode`~=`#2\relax
\lowercase{\endgroup#1~}}
% \end{macrocode}
%
% \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}
\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
\begingroup
\catcode`#1\active
\nfss@catcodes
\ifnum\catcode`#1=\active
\endgroup
\bbl@add\nfss@catcodes{\@makeother#1}%
\else
\endgroup
\fi
\fi}
% \end{macrocode}
%
% \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<char>| to expand to the character in its `normal
% state' and it defines the active character to expand to
% |\normal@char<char>| by default (\m{char} being the character to be
% made active). Later its definition can be changed to expand to
% |\active@char<char>| by calling |\bbl@activate{<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 "| (i.e., with the
% original |"|); otherwise |\active@char"| is executed. This macro in
% turn expands to |\normal@char"| in “safe” contexts (e.g., |\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"|.
%
% The following macro is used to define shorthands in the three levels.
% It takes 4 arguments: the (string'ed) character, |\<level>@group|,
% |<level>@active| and |<next-level>@active| (except in |system|).
%
% \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}
%
% 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}
\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}
%
% |\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}
\def\initiate@active@char#1{%
\bbl@ifunset{active@char\string#1}%
{\bbl@withactive
{\expandafter\@initiate@active@char\expandafter}#1\string#1#1}%
{}}
% \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 treatment to avoid making them |\relax|
% and preserving some degree of protection).
%
% \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\def{oridef@#2}{\def#1{\active@prefix#1\@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}
%
% 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<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}
\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}
%
% 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}
\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}
%
% Now we have set |\normal@char<char>|, we must define
% |\active@char<char>|, to be executed when the character is
% activated. We define the first level expansion of
% |\active@char<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<char>| to start the
% search of a definition in the user, language and system levels (or
% eventually |normal@char<char>|).
%
% \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<char>|
% \end{center}
% (where |\active@char<char>| is \emph{one} control sequence!).
%
% \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}%
\bbl@ncarg\let#1{bbl@normal@#2}%
% \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.
%
% \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}
%
% 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}
\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}
%
% 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.
%
% \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 following package options control the behavior of shorthands in
% math mode.
%
% \begin{macrocode}
%<<*More package options>>
\DeclareOption{math=active}{}
\DeclareOption{math=normal}{\def\bbl@mathnormal{\noexpand\textormath}}
%<</More package options>>
% \end{macrocode}
%
% 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}
\@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}
%
% \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|.
%
% 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}
\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}
%
% \macro{\active@prefix}
% 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}
\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
% \end{macrocode}
%
% \macro{if@safe@actives}
%
% In some circumstances it is necessary to be able to reset the
% shorthand to its ‘normal’ value (usually the character with catcode
% ‘other’) 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<char>|. When this expansion mode
% is active (with |\@safe@activestrue|), something like
% |"|$\sb{13}$|"|$\sb{13}$ becomes |"|$\sb{12}$|"|$\sb{12}$ in an
% |\edef| (in other words, shorthands are |\string|’ed). This contrasts
% with |\protected@edef|, where catcodes are always left unchanged.
% Once converted, they can be used safely even after this expansion
% mode is deactivated (with |\@safe@activefalse|).
%
% \begin{macrocode}
\newif\if@safe@actives
\@safe@activesfalse
% \end{macrocode}
%
% \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}
\def\bbl@restore@actives{\if@safe@actives\@safe@activesfalse\fi}
% \end{macrocode}
%
% \macro{\bbl@activate}
% \macro{\bbl@deactivate}
%
% 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<char>| in the case of |\bbl@activate|,
% or |\normal@char<char>| in the case of |\bbl@deactivate|.
%
% \begin{macrocode}
\chardef\bbl@activated\z@
\def\bbl@activate#1{%
\chardef\bbl@activated\@ne
\bbl@withactive{\expandafter\let\expandafter}#1%
\csname bbl@active@\string#1\endcsname}
\def\bbl@deactivate#1{%
\chardef\bbl@activated\tw@
\bbl@withactive{\expandafter\let\expandafter}#1%
\csname bbl@normal@\string#1\endcsname}
% \end{macrocode}
%
% \macro{\bbl@firstcs}
% \macro{\bbl@scndcs}
%
% These macros are used only as a trick when declaring shorthands.
%
% \begin{macrocode}
\def\bbl@firstcs#1#2{\csname#1\endcsname}
\def\bbl@scndcs#1#2{\csname#2\endcsname}
% \end{macrocode}
%
% \macro{\declare@shorthand}
% 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}
%
% The auxiliary macro |\babel@texpdf| improves the interoperativity with
% \textsf{hyperref} and takes 4 arguments: (1) The \TeX{} code in text
% mode, (2) the string for \textsf{hyperref}, (3) the \TeX{} code in
% math mode, and (4), which is currently ignored, but it's meant for a
% string in math mode, like a minus sign instead of an hyphen
% (currently \textsf{hyperref} doesn't discriminate the mode). This
% macro may be used in |ldf| files.
%
% \begin{macrocode}
\def\babel@texpdf#1#2#3#4{%
\ifx\texorpdfstring\@undefined
\textormath{#1}{#3}%
\else
\texorpdfstring{\textormath{#1}{#3}}{#2}%
% \texorpdfstring{\textormath{#1}{#3}}{\textormath{#2}{#4}}%
\fi}
%
\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}
%
% \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\textormath{%
\ifmmode
\expandafter\@secondoftwo
\else
\expandafter\@firstoftwo
\fi}
% \end{macrocode}
%
% \macro{\user@group}
% \macro{\language@group}
% \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\user@group{user}
\def\language@group{english}
\def\system@group{system}
% \end{macrocode}
%
% \macro{\useshorthands}
%
% This is the user level macro. It initializes and activates the
% character for use as a shorthand character (i.e., 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}
\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{shorthand-is-off}{}{#2}{}}}
% \end{macrocode}
%
% \macro{\defineshorthand}
%
% Currently we only support two groups of user level shorthands,
% named internally |user| and |user@<language>| (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\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}
%
% \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 to fix it in the same way languages names are fixed.
%
% \begin{macrocode}
\def\languageshorthands#1{%
\bbl@ifsamestring{none}{#1}{}{%
\bbl@once{short-\localename-#1}{%
\bbl@info{'\localename' activates '#1' shorthands.\\Reported}}}%
\def\language@group{#1}}
% \end{macrocode}
%
% \macro{\aliasshorthand}
%
% \textit{Deprecated}. 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
% latter to |\active@char"|.
%
% \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}%
\bbl@ccarg\let{active@char\string#2}{active@char\string#1}%
\bbl@ccarg\let{normal@char\string#2}{normal@char\string#1}%
\bbl@activate{#2}%
\fi
\fi}%
{\bbl@error{shorthand-is-off}{}{#2}{}}}
% \end{macrocode}
%
% \macro{\@notshorthand}
%
% \begin{macrocode}
\def\@notshorthand#1{\bbl@error{not-a-shorthand}{#1}{}{}}
% \end{macrocode}
%
% \macro{\shorthandon}
% \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}
\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}
%
% \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.
%
% \begin{macrocode}
\def\bbl@switch@sh#1#2{%
\ifx#2\@nnil\else
\bbl@ifunset{bbl@active@\string#2}%
{\bbl@error{not-a-shorthand-b}{}{#2}{}}%
{\ifcase#1% off, on, off*
\catcode`#212\relax
\or
\catcode`#2\active
\bbl@ifunset{bbl@shdef@\string#2}%
{}%
{\bbl@withactive{\expandafter\let\expandafter}#2%
\csname bbl@shdef@\string#2\endcsname
\bbl@csarg\let{shdef@\string#2}\relax}%
\ifcase\bbl@activated\or
\bbl@activate{#2}%
\else
\bbl@deactivate{#2}%
\fi
\or
\bbl@ifunset{bbl@shdef@\string#2}%
{\bbl@withactive{\bbl@csarg\let{shdef@\string#2}}#2}%
{}%
\csname bbl@oricat@\string#2\endcsname
\csname bbl@oridef@\string#2\endcsname
\fi}%
\bbl@afterfi\bbl@switch@sh#1%
\fi}
% \end{macrocode}
%
% Note the value is that at the expansion time; e.g., in the preamble
% shorthands are usually deactivated.
%
% \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\language@group @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}
%
% 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\ifbabelshorthand[3]{\bbl@ifunset{bbl@active@\string#1}{#3}{#2}}
% \end{macrocode}
%
% \macro{\bbl@prim@s}
% \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}
\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}
%
% 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}
\initiate@active@char{~}
\declare@shorthand{system}{~}{\leavevmode\nobreak\ }
\bbl@activate{~}
% \end{macrocode}
%
% \macro{\OT1dqpos}
% \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}
\expandafter\def\csname OT1dqpos\endcsname{127}
\expandafter\def\csname T1dqpos\endcsname{4}
% \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}
%
% \subsection{Language attributes}
%
% Language attributes provide a means to give the user control over
% which features of the language definition files he wants to enable.
%
% \macro{\languageattribute}
%
% 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}
\bbl@trace{Language attributes}
\newcommand\languageattribute[2]{%
\def\bbl@tempc{#1}%
\bbl@fixname\bbl@tempc
\bbl@iflanguage\bbl@tempc{%
\bbl@vforeach{#2}{%
% \end{macrocode}
%
% To make sure each attribute is selected only once, 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}
\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}
%
% 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}
\bbl@info{Activated '##1' attribute for\\%
'\bbl@tempc'. Reported}%
\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}
%
% The error text to be issued when an unknown attribute is selected.
%
% \begin{macrocode}
\newcommand*{\@attrerr}[2]{%
\bbl@error{unknown-attribute}{#1}{#2}{}}
% \end{macrocode}
%
% \macro{\bbl@declare@ttribute}
% This command adds the new language/attribute combination to the list
% of known attributes.
%
% 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}
\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}
%
% \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{macrocode}
\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}
%
% \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.
%
% We first assume the attribute is unknown. Then we loop over the list
% of known attributes, trying to find a match.
%
% \begin{macrocode}
\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}
%
% \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\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}
%
% \subsection{Support for saving and redefining macros}
%
% 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.
%
% \macro{\babel@savecnt}
% \macro{\babel@beginsave}
% The initialization of a new save cycle: reset the counter to zero.
%
% \begin{macrocode}
\bbl@trace{Macros for saving definitions}
\def\babel@beginsave{\babel@savecnt\z@}
% \end{macrocode}
%
% Before it's forgotten, allocate the counter and initialize all.
%
% \begin{macrocode}
\newcount\babel@savecnt
\babel@beginsave
% \end{macrocode}
%
% \macro{\babel@save}
% \macro{\babel@savevariable}
%
% The macro |\babel@save|\meta{csname} saves the current meaning of the
% control sequence \meta{csname} to |\originalTeX| (which 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. To avoid messing saved definitions up, they are
% saved only the very first time.
%
% \begin{macrocode}
\def\babel@save#1{%
\def\bbl@tempa{{,#1,}}% Clumsy, for Plain
\expandafter\bbl@add\expandafter\bbl@tempa\expandafter{%
\expandafter{\expandafter,\bbl@savedextras,}}%
\expandafter\in@\bbl@tempa
\ifin@\else
\bbl@add\bbl@savedextras{,#1,}%
\bbl@carg\let{babel@\number\babel@savecnt}#1\relax
\toks@\expandafter{\originalTeX\let#1=}%
\bbl@exp{%
\def\\\originalTeX{\the\toks@\<babel@\number\babel@savecnt>\relax}}%
\advance\babel@savecnt\@ne
\fi}
\def\babel@savevariable#1{%
\toks@\expandafter{\originalTeX #1=}%
\bbl@exp{\def\\\originalTeX{\the\toks@\the#1\relax}}}
% \end{macrocode}
%
% \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). A macro named
% |\macro| will be saved new control sequences named |\org@macro|.
%
% \begin{macrocode}
\def\bbl@redefine#1{%
\edef\bbl@tempa{\bbl@stripslash#1}%
\expandafter\let\csname org@\bbl@tempa\endcsname#1%
\expandafter\def\csname\bbl@tempa\endcsname}
\@onlypreamble\bbl@redefine
% \end{macrocode}
%
% \macro{\bbl@redefine@long}
% This version of |\babel@redefine| can be used to redefine |\long|
% commands such as |\ifthenelse|.
%
% \begin{macrocode}
\def\bbl@redefine@long#1{%
\edef\bbl@tempa{\bbl@stripslash#1}%
\expandafter\let\csname org@\bbl@tempa\endcsname#1%
\long\expandafter\def\csname\bbl@tempa\endcsname}
\@onlypreamble\bbl@redefine@long
% \end{macrocode}
%
% \macro{\bbl@redefinerobust}
% For commands that are redefined, but which \textit{might} be
% robust we need a slightly more intelligent macro. A robust
% command |foo| is defined to expand to |\protect|\verb*|\foo |. So
% it is necessary to check whether \verb*|\foo | exists. The result
% is that the command that is being redefined is always robust
% afterwards. Therefore all we need to do now is define \verb*|\foo |.
%
% \begin{macrocode}
\def\bbl@redefinerobust#1{%
\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\<org@\bbl@tempa>\<\bbl@tempa\space>}}%
\@namedef{\bbl@tempa\space}}
\@onlypreamble\bbl@redefinerobust
% \end{macrocode}
%
% \subsection{French spacing}
%
% \macro{\bbl@frenchspacing}
% \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@frenchspacing{%
\ifnum\the\sfcode`\.=\@m
\let\bbl@nonfrenchspacing\relax
\else
\frenchspacing
\let\bbl@nonfrenchspacing\nonfrenchspacing
\fi}
\let\bbl@nonfrenchspacing\nonfrenchspacing
% \end{macrocode}
%
% A more refined way to switch the catcodes is done with |ini| files.
% Here an auxiliary macro is defined, but the main part is in
% |\babelprovide|. This new method should be ideally the default one.
%
% \begin{macrocode}
\let\bbl@elt\relax
\edef\bbl@fs@chars{%
\bbl@elt{\string.}\@m{3000}\bbl@elt{\string?}\@m{3000}%
\bbl@elt{\string!}\@m{3000}\bbl@elt{\string:}\@m{2000}%
\bbl@elt{\string;}\@m{1500}\bbl@elt{\string,}\@m{1250}}
\def\bbl@pre@fs{%
\def\bbl@elt##1##2##3{\sfcode`##1=\the\sfcode`##1\relax}%
\edef\bbl@save@sfcodes{\bbl@fs@chars}}%
\def\bbl@post@fs{%
\bbl@save@sfcodes
\edef\bbl@tempa{\bbl@cl{frspc}}%
\edef\bbl@tempa{\expandafter\@car\bbl@tempa\@nil}%
\if u\bbl@tempa % do nothing
\else\if n\bbl@tempa % non french
\def\bbl@elt##1##2##3{%
\ifnum\sfcode`##1=##2\relax
\babel@savevariable{\sfcode`##1}%
\sfcode`##1=##3\relax
\fi}%
\bbl@fs@chars
\else\if y\bbl@tempa % french
\def\bbl@elt##1##2##3{%
\ifnum\sfcode`##1=##3\relax
\babel@savevariable{\sfcode`##1}%
\sfcode`##1=##2\relax
\fi}%
\bbl@fs@chars
\fi\fi\fi}
% \end{macrocode}
%
% \subsection{Hyphens}
%
% \macro{\babelhyphenation}
%
% This macro saves hyphenation exceptions. Two macros are used to
% store them: |\bbl@hyphenation@| for the global ones and
% |\bbl@hyphenation@<language>| for language ones. See |\bbl@patterns|
% above for further details. We make sure there is a space between
% words when multiple commands are used.
%
% \begin{macrocode}
\bbl@trace{Hyphens}
\@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}%
{}%
{\csname bbl@hyphenation@\bbl@tempa\endcsname\space}%
#2}}}%
\fi}}
% \end{macrocode}
%
% \macro{\babelhyphenmins}
%
% Only \LaTeX{} (basically because it’s defined with a \LaTeX{} tool).
%
% \begin{macrocode}
\ifx\NewDocumentCommand\@undefined\else
\NewDocumentCommand\babelhyphenmins{sommo}{%
\IfNoValueTF{#2}%
{\protected@edef\bbl@hyphenmins@{\set@hyphenmins{#3}{#4}}%
\IfValueT{#5}{%
\protected@edef\bbl@hyphenatmin@{\hyphenationmin=#5\relax}}%
\IfBooleanT{#1}{%
\lefthyphenmin=#3\relax
\righthyphenmin=#4\relax
\IfValueT{#5}{\hyphenationmin=#5\relax}}}%
{\edef\bbl@tempb{\zap@space#2 \@empty}%
\bbl@for\bbl@tempa\bbl@tempb{%
\@namedef{bbl@hyphenmins@\bbl@tempa}{\set@hyphenmins{#3}{#4}}%
\IfValueT{#5}{%
\@namedef{bbl@hyphenatmin@\bbl@tempa}{\hyphenationmin=#5\relax}}}%
\IfBooleanT{#1}{\bbl@error{hyphenmins-args}{}{}{}}}}
\fi
% \end{macrocode}
%
% \macro{\bbl@allowhyphens}
%
% This macro makes hyphenation possible. Basically its definition is
% nothing more than |\nobreak| |\hskip| \texttt{0pt plus 0pt}. \TeX\
% begins and ends a word for hyphenation at a glue node. The penalty
% prevents a linebreak at this glue node.
%
% \begin{macrocode}
\def\bbl@allowhyphens{\ifvmode\else\nobreak\hskip\z@skip\fi}
\def\bbl@t@one{T1}
\def\allowhyphens{\ifx\cf@encoding\bbl@t@one\else\bbl@allowhyphens\fi}
% \end{macrocode}
%
% \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|.
%
% \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{%
\lowercase{\bbl@ifunset{bbl@hy@#1#2\@empty}}%
{\csname bbl@#1usehyphen\endcsname{\discretionary{#2}{}{#2}}}%
{\lowercase{\csname bbl@hy@#1#2\@empty\endcsname}}}
% \end{macrocode}
%
% The following two commands are used to wrap the “hyphen” and
% set the behavior of the rest of the word -- the version with a
% single |@| is used when further hyphenation is allowed, while
% that with |@@| if no more hyphens are allowed. In both cases, if
% the hyphen is preceded by a positive space, breaking after the
% hyphen is disallowed.
%
% There should not be a discretionary after a hyphen at the
% beginning of a word, so it is prevented if preceded by a
% skip. Unfortunately, this does handle cases like “(-suffix)”.
% |\nobreak| is always preceded by |\leavevmode|, in case the
% shorthand starts a paragraph.
%
% \begin{macrocode}
\def\bbl@usehyphen#1{%
\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 following macro inserts the hyphen char.
%
% \begin{macrocode}
\def\bbl@hyphenchar{%
\ifnum\hyphenchar\font=\m@ne
\babelnullhyphen
\else
\char\hyphenchar\font
\fi}
% \end{macrocode}
%
% Finally, we define the hyphen “types”. Their names will not change,
% so you may use them in |ldf|'s. After a space, the |\mbox| in
% |\bbl@hy@nobreak| is redundant.
%
% \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{}{}{}}
% \end{macrocode}
%
% \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}
\def\bbl@disc#1#2{\nobreak\discretionary{#2-}{}{#1}\bbl@allowhyphens}
% \end{macrocode}
%
% \subsection{Multiencoding strings}
%
% The aim following commands is to provide a common 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}
%
% But first, a tool. It makes global a local variable. This is not the
% best solution, but it works.
%
% \begin{macrocode}
\bbl@trace{Multiencoding strings}
\def\bbl@toglobal#1{\global\let#1#1}
% \end{macrocode}
%
% The following option is currently no-op. It was meant for the
% deprecated |\SetCase|.
%
% \begin{macrocode}
%<<*More package options>>
\DeclareOption{nocase}{}
%<</More package options>>
% \end{macrocode}
%
% The following package options control the behavior of |\SetString|.
%
% \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}
%<</More package options>>
% \end{macrocode}
%
% \paragraph{Main command} This is the main command. With the first
% use it is redefined to omit the basic setup in subsequent blocks.
% We make sure strings contain actual letters in the range 128-255,
% not active characters.
%
% \begin{macrocode}
\@onlypreamble\StartBabelCommands
\def\StartBabelCommands{%
\begingroup
\@tempcnta="7F
\def\bbl@tempa{%
\ifnum\@tempcnta>"FF\else
\catcode\@tempcnta=11
\advance\@tempcnta\@ne
\expandafter\bbl@tempa
\fi}%
\bbl@tempa
<@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}
%
% Parse the encoding info to get the label, input, and font parts.
%
% Select the behavior of |\SetString|. There 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
% (i.e., 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 (i.e., 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}
\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 % i.e., no strings key -> defaults
\else\ifx\bbl@opt@strings\relax % i.e., strings=encoded
\let\AfterBabelCommands\bbl@aftercmds
\let\SetString\bbl@setstring
\let\bbl@stringdef\bbl@encstring
\else % i.e., 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}{##1}{}{}}%
\fi
\ifx\@empty#1%
\bbl@usehooks{defaultcommands}{}%
\else
\@expandtwoargs
\bbl@usehooks{encodedcommands}{{\bbl@sc@charset}{\bbl@sc@fontenc}}%
\fi}
% \end{macrocode}
%
% There are two versions of |\bbl@scswitch|. The first version is used
% when |ldf|s are read, and it makes sure |\<group><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<language>| is defined (after \babel{} has been loaded).
% There are also two version of |\bbl@forlang|. The first one skips the
% current iteration if the language is not in |\BabelLanguages| (used
% in |ldf|s), and the second one skips undefined languages (after
% \babel{} has been loaded) .
%
% \begin{macrocode}
\def\bbl@forlang#1#2{%
\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}
%
% 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 (i.e., like |\providescommmand|). With
% the event |stringprocess| you can preprocess the string by
% manipulating the value of |\BabelString|. If there are several
% hooks assigned to this event, preprocessing is done in the same
% order as defined. Finally, the string is set.
%
% \begin{macrocode}
\def\bbl@setstring#1#2{% e.g., \prefacename{<string>}
\bbl@forlang\bbl@tempa{%
\edef\bbl@LC{\bbl@tempa\bbl@stripslash#1}%
\bbl@ifunset{\bbl@LC}% e.g., \germanchaptername
{\bbl@exp{%
\global\\\bbl@add\<\bbl@G\bbl@tempa>{\\\bbl@scset\\#1\<\bbl@LC>}}}%
{}%
\def\BabelString{#2}%
\bbl@usehooks{stringprocess}{}%
\expandafter\bbl@stringdef
\csname\bbl@LC\expandafter\endcsname\expandafter{\BabelString}}}
% \end{macrocode}
%
% A little auxiliary command sets the string. Formerly used with
% casing. Very likely no longer necessary, although it’s used in
% |\setlocalecaption|.
%
% \begin{macrocode}
\def\bbl@scset#1#2{\def#1{#2}}
% \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.
%
% \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}}}%
%<</Macros local to BabelCommands>>
% \end{macrocode}
%
% \paragraph{Delaying code} Now the definition of |\AfterBabelCommands|
% when it is activated.
%
% \begin{macrocode}
\def\bbl@aftercmds#1{%
\toks@\expandafter{\bbl@scafter#1}%
\xdef\bbl@scafter{\the\toks@}}
% \end{macrocode}
%
% \paragraph{Case mapping}
%
% The command |\SetCase| is deprecated. Currently it consists in a
% definition with a hack just for backward compatibility in the macro
% mapping.
%
% \begin{macrocode}
%<<*Macros local to BabelCommands>>
\newcommand\SetCase[3][]{%
\def\bbl@tempa####1####2{%
\ifx####1\@empty\else
\bbl@carg\bbl@add{extras\CurrentOption}{%
\bbl@carg\babel@save{c__text_uppercase_\string####1_tl}%
\bbl@carg\def{c__text_uppercase_\string####1_tl}{####2}%
\bbl@carg\babel@save{c__text_lowercase_\string####2_tl}%
\bbl@carg\def{c__text_lowercase_\string####2_tl}{####1}}%
\expandafter\bbl@tempa
\fi}%
\bbl@tempa##1\@empty\@empty
\bbl@carg\bbl@toglobal{extras\CurrentOption}}%
%<</Macros local to BabelCommands>>
% \end{macrocode}
%
% 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.
%
% \begin{macrocode}
%<<*Macros local to BabelCommands>>
\newcommand\SetHyphenMap[1]{%
\bbl@forlang\bbl@tempa{%
\expandafter\bbl@stringdef
\csname\bbl@tempa @bbl@hyphenmap\endcsname{##1}}}%
%<</Macros local to BabelCommands>>
% \end{macrocode}
%
% 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}
%<</More package options>>
% \end{macrocode}
%
% Initial setup to provide a default behavior if |hyphenmap| is not
% set.
%
% \begin{macrocode}
\AtEndOfPackage{%
\ifx\bbl@opt@hyphenmap\@undefined
\bbl@xin@{,}{\bbl@language@opts}%
\chardef\bbl@opt@hyphenmap\ifin@4\else\@ne\fi
\fi}
% \end{macrocode}
%
% \subsection{Tailor captions}
%
% A general tool for resetting the caption
% names with a unique interface. With the old way, which mixes the
% switcher and the string, we convert it to the new one, which
% separates these two steps.
%
% \begin{macrocode}
\newcommand\setlocalecaption{%
\@ifstar\bbl@setcaption@s\bbl@setcaption@x}
\def\bbl@setcaption@x#1#2#3{% language caption-name string
\bbl@trim@def\bbl@tempa{#2}%
\bbl@xin@{.template}{\bbl@tempa}%
\ifin@
\bbl@ini@captions@template{#3}{#1}%
\else
\edef\bbl@tempd{%
\expandafter\expandafter\expandafter
\strip@prefix\expandafter\meaning\csname captions#1\endcsname}%
\bbl@xin@
{\expandafter\string\csname #2name\endcsname}%
{\bbl@tempd}%
\ifin@ % Renew caption
\bbl@xin@{\string\bbl@scset}{\bbl@tempd}%
\ifin@
\bbl@exp{%
\\\bbl@ifsamestring{\bbl@tempa}{\languagename}%
{\\\bbl@scset\<#2name>\<#1#2name>}%
{}}%
\else % Old way converts to new way
\bbl@ifunset{#1#2name}%
{\bbl@exp{%
\\\bbl@add\<captions#1>{\def\<#2name>{\<#1#2name>}}%
\\\bbl@ifsamestring{\bbl@tempa}{\languagename}%
{\def\<#2name>{\<#1#2name>}}%
{}}}%
{}%
\fi
\else
\bbl@xin@{\string\bbl@scset}{\bbl@tempd}% New
\ifin@ % New way
\bbl@exp{%
\\\bbl@add\<captions#1>{\\\bbl@scset\<#2name>\<#1#2name>}%
\\\bbl@ifsamestring{\bbl@tempa}{\languagename}%
{\\\bbl@scset\<#2name>\<#1#2name>}%
{}}%
\else % Old way, but defined in the new way
\bbl@exp{%
\\\bbl@add\<captions#1>{\def\<#2name>{\<#1#2name>}}%
\\\bbl@ifsamestring{\bbl@tempa}{\languagename}%
{\def\<#2name>{\<#1#2name>}}%
{}}%
\fi%
\fi
\@namedef{#1#2name}{#3}%
\toks@\expandafter{\bbl@captionslist}%
\bbl@exp{\\\in@{\<#2name>}{\the\toks@}}%
\ifin@\else
\bbl@exp{\\\bbl@add\\\bbl@captionslist{\<#2name>}}%
\bbl@toglobal\bbl@captionslist
\fi
\fi}
% \end{macrocode}
%
% \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}.
%
% \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@}
% \end{macrocode}
%
% \macro{\save@sf@q}
% The macro |\save@sf@q| is used to save and reset the current space
% factor.
%
% \begin{macrocode}
\def\save@sf@q#1{\leavevmode
\begingroup
\edef\@SF{\spacefactor\the\spacefactor}#1\@SF
\endgroup}
% \end{macrocode}
%
% \subsubsection{Quotation marks}
%
% \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}
%
% Make sure that when an encoding other than \texttt{OT1} or
% \texttt{T1} is used this glyph can still be typeset.
%
% \begin{macrocode}
\ProvideTextCommandDefault{\quotedblbase}{%
\UseTextSymbol{OT1}{\quotedblbase}}
% \end{macrocode}
%
% \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.
%
% \begin{macrocode}
\ProvideTextCommandDefault{\quotesinglbase}{%
\UseTextSymbol{OT1}{\quotesinglbase}}
% \end{macrocode}
%
% \macro{\guillemetleft}
% \macro{\guillemetright}
% The guillemet characters are not available in \texttt{OT1}
% encoding. They are faked. (Wrong names with o preserved for
% compatibility.)
%
% \begin{macrocode}
\ProvideTextCommand{\guillemetleft}{OT1}{%
\ifmmode
\ll
\else
\save@sf@q{\nobreak
\raise.2ex\hbox{$\scriptscriptstyle\ll$}\bbl@allowhyphens}%
\fi}
\ProvideTextCommand{\guillemetright}{OT1}{%
\ifmmode
\gg
\else
\save@sf@q{\nobreak
\raise.2ex\hbox{$\scriptscriptstyle\gg$}\bbl@allowhyphens}%
\fi}
\ProvideTextCommand{\guillemotleft}{OT1}{%
\ifmmode
\ll
\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}
%
% Make sure that when an encoding other than \texttt{OT1} or
% \texttt{T1} is used these glyphs can still be typeset.
%
% \begin{macrocode}
\ProvideTextCommandDefault{\guillemetleft}{%
\UseTextSymbol{OT1}{\guillemetleft}}
\ProvideTextCommandDefault{\guillemetright}{%
\UseTextSymbol{OT1}{\guillemetright}}
\ProvideTextCommandDefault{\guillemotleft}{%
\UseTextSymbol{OT1}{\guillemotleft}}
\ProvideTextCommandDefault{\guillemotright}{%
\UseTextSymbol{OT1}{\guillemotright}}
% \end{macrocode}
%
% \macro{\guilsinglleft}
% \macro{\guilsinglright}
% The single guillemets are not available in \texttt{OT1} encoding.
% They are faked.
%
% \begin{macrocode}
\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}
\ProvideTextCommandDefault{\guilsinglleft}{%
\UseTextSymbol{OT1}{\guilsinglleft}}
\ProvideTextCommandDefault{\guilsinglright}{%
\UseTextSymbol{OT1}{\guilsinglright}}
% \end{macrocode}
%
% \subsubsection{Letters}
%
% \macro{\ij}
% \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}
\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}}
% \end{macrocode}
%
% \macro{\dj}
% \macro{\DJ}
% The croatian language needs the letters |\dj| and |\DJ|; they are
% available in the \texttt{T1} encoding, but not in the
% \texttt{OT1} encoding by default.
%
% Some code to construct these glyphs for the \texttt{OT1} encoding
% was made available to me by Stipčević Mario,
% (\texttt{
[email protected]}).
%
% \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
\
[email protected]\dimen@
\dimen@ii\expandafter\rem@pt\the\fontdimen\@ne\font\dimen@
\advance\
[email protected]
\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\
[email protected] % correction for the dash position
\advance\
[email protected]\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}
%
% Make sure that when an encoding other than \texttt{OT1} or
% \texttt{T1} is used these glyphs can still be typeset.
%
% \begin{macrocode}
\ProvideTextCommandDefault{\dj}{%
\UseTextSymbol{OT1}{\dj}}
\ProvideTextCommandDefault{\DJ}{%
\UseTextSymbol{OT1}{\DJ}}
% \end{macrocode}
%
% \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}
\DeclareTextCommand{\SS}{OT1}{SS}
\ProvideTextCommandDefault{\SS}{\UseTextSymbol{OT1}{\SS}}
% \end{macrocode}
%
% \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.
%
% \macro{\glq}
% \macro{\grq}
%
% The `german' single quotes.
%
% \begin{macrocode}
\ProvideTextCommandDefault{\glq}{%
\textormath{\quotesinglbase}{\mbox{\quotesinglbase}}}
% \end{macrocode}
%
% The definition of |\grq| depends on the fontencoding. With
% \texttt{T1} encoding no extra kerning is needed.
%
% \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}
% \end{macrocode}
%
% \macro{\glqq}
% \macro{\grqq}
%
% The `german' double quotes.
%
% \begin{macrocode}
\ProvideTextCommandDefault{\glqq}{%
\textormath{\quotedblbase}{\mbox{\quotedblbase}}}
% \end{macrocode}
%
% The definition of |\grqq| depends on the fontencoding. With
% \texttt{T1} encoding no extra kerning is needed.
%
% \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}
% \end{macrocode}
%
% \macro{\flq}
% \macro{\frq}
%
% The `french' single guillemets.
%
% \begin{macrocode}
\ProvideTextCommandDefault{\flq}{%
\textormath{\guilsinglleft}{\mbox{\guilsinglleft}}}
\ProvideTextCommandDefault{\frq}{%
\textormath{\guilsinglright}{\mbox{\guilsinglright}}}
% \end{macrocode}
%
% \macro{\flqq}
% \macro{\frqq}
%
% The `french' double guillemets.
%
% \begin{macrocode}
\ProvideTextCommandDefault{\flqq}{%
\textormath{\guillemetleft}{\mbox{\guillemetleft}}}
\ProvideTextCommandDefault{\frqq}{%
\textormath{\guillemetright}{\mbox{\guillemetright}}}
% \end{macrocode}
%
% \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.
%
% \macro{\umlauthigh}
%
% \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\umlauthigh{%
\def\bbl@umlauta##1{\leavevmode\bgroup%
\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}
%
% \macro{\lower@umlaut}
% 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{%
\char\csname\f@encoding dqpos\endcsname}%
\dimen@ -.45ex\advance\dimen@\ht\z@
\ifdim 1ex<\dimen@ \fontdimen5\font\dimen@ \fi}%
\accent\csname\f@encoding dqpos\endcsname
\fontdimen5\font\U@D #1%
\egroup}
% \end{macrocode}
%
% 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). For internal use, another empty |\language| is defined.
% Currently used in Amharic.
%
% \begin{macrocode}
\ifx\l@english\@undefined
\chardef\l@english\z@
\fi
% The following is used to cancel rules in ini files (see Amharic).
\ifx\l@unhyphenated\@undefined
\newlanguage\l@unhyphenated
\fi
% \end{macrocode}
%
% \subsection{Layout}
%
% 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}%
% \end{macrocode}
%
% \subsection{Load engine specific macros}
%
% Some macros are not defined in all engines, so, after loading the
% files define them if necessary to raise an error.
%
% \begin{macrocode}
\bbl@trace{Input engine specific macros}
\ifcase\bbl@engine
\input txtbabel.def
\or
\input luababel.def
\or
\input xebabel.def
\fi
\providecommand\babelfont{\bbl@error{only-lua-xe}{}{}{}}
\providecommand\babelprehyphenation{\bbl@error{only-lua}{}{}{}}
\ifx\babelposthyphenation\@undefined
\let\babelposthyphenation\babelprehyphenation
\let\babelpatterns\babelprehyphenation
\let\babelcharproperty\babelprehyphenation
\fi
%</package|core>
% \end{macrocode}
%
% \subsection{Creating and modifying languages}
%
% Continue with \LaTeX{} only.
%
% |\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 previously
% loaded |ldf| files.
%
% \begin{macrocode}
%<*package>
\bbl@trace{Creating languages and reading ini files}
\let\bbl@extend@ini\@gobble
\newcommand\babelprovide[2][]{%
\let\bbl@savelangname\languagename
\edef\bbl@savelocaleid{\the\localeid}%
% Set name and locale id
\edef\languagename{#2}%
\bbl@id@assign
% Initialize keys
\bbl@vforeach{captions,date,import,main,script,language,%
hyphenrules,linebreaking,justification,mapfont,maparabic,%
mapdigits,intraspace,intrapenalty,onchar,transforms,alph,%
Alph,labels,labels*,mapdot,calendar,date,casing,interchar,%
@import}%
{\bbl@csarg\let{KVP@##1}\@nnil}%
\global\let\bbl@release@transforms\@empty
\global\let\bbl@release@casing\@empty
\let\bbl@calendars\@empty
\global\let\bbl@inidata\@empty
\global\let\bbl@extend@ini\@gobble
\global\let\bbl@included@inis\@empty
\gdef\bbl@key@list{;}%
\bbl@ifunset{bbl@passto@#2}%
{\def\bbl@tempa{#1}}%
{\bbl@exp{\def\\\bbl@tempa{\[bbl@passto@#2],\unexpanded{#1}}}}%
\expandafter\bbl@forkv\expandafter{\bbl@tempa}{%
\in@{/}{##1}% With /, (re)sets a value in the ini
\ifin@
\bbl@renewinikey##1\@@{##2}%
\else
\bbl@csarg\ifx{KVP@##1}\@nnil\else
\bbl@error{unknown-provide-key}{##1}{}{}%
\fi
\bbl@csarg\def{KVP@##1}{##2}%
\fi}%
\chardef\bbl@howloaded=% 0:none; 1:ldf without ini; 2:ini
\bbl@ifunset{date#2}\z@{\bbl@ifunset{bbl@llevel@#2}\@ne\tw@}%
% == init ==
\ifx\bbl@screset\@undefined
\bbl@ldfinit
\fi
% ==
% If there is no import (last wins), use @import (internal, there
% must be just one). To consider any order (because
% \PassOptionsToLocale).
\ifx\bbl@KVP@import\@nnil
\let\bbl@KVP@import\bbl@KVP@@import
\fi
% == date (as option) ==
% \ifx\bbl@KVP@date\@nnil\else
% \fi
% ==
\let\bbl@lbkflag\relax % \@empty = do setup linebreak, only in 3 cases:
\ifcase\bbl@howloaded
\let\bbl@lbkflag\@empty % new
\else
\ifx\bbl@KVP@hyphenrules\@nnil\else
\let\bbl@lbkflag\@empty
\fi
\ifx\bbl@KVP@import\@nnil\else
\let\bbl@lbkflag\@empty
\fi
\fi
% == import, captions ==
\ifx\bbl@KVP@import\@nnil\else
\bbl@exp{\\\bbl@ifblank{\bbl@KVP@import}}%
{\ifx\bbl@initoload\relax
\begingroup
\def\BabelBeforeIni##1##2{\gdef\bbl@KVP@import{##1}\endinput}%
\bbl@input@texini{#2}%
\endgroup
\else
\xdef\bbl@KVP@import{\bbl@initoload}%
\fi}%
{}%
\let\bbl@KVP@date\@empty
\fi
\let\bbl@KVP@captions@@\bbl@KVP@captions
\ifx\bbl@KVP@captions\@nnil
\let\bbl@KVP@captions\bbl@KVP@import
\fi
% ==
\ifx\bbl@KVP@transforms\@nnil\else
\bbl@replace\bbl@KVP@transforms{ }{,}%
\fi
% ==
\ifx\bbl@KVP@mapdot\@nnil\else
\def\bbl@tempa{\@empty}%
\ifx\bbl@KVP@mapdot\bbl@tempa\else
\bbl@exp{\gdef\<bbl@map@@.@@\languagename>{\[bbl@KVP@mapdot]}}%
\fi
\fi
% Load ini
% --------
\ifcase\bbl@howloaded
\bbl@provide@new{#2}%
\else
\bbl@ifblank{#1}%
{}% With \bbl@load@basic below
{\bbl@provide@renew{#2}}%
\fi
% Post tasks
% ----------
% == subsequent calls after the first provide for a locale ==
\ifx\bbl@inidata\@empty\else
\bbl@extend@ini{#2}%
\fi
% == ensure captions ==
\ifx\bbl@KVP@captions\@nnil\else
\bbl@ifunset{bbl@extracaps@#2}%
{\bbl@exp{\\\babelensure[exclude=\\\today]{#2}}}%
{\bbl@exp{\\\babelensure[exclude=\\\today,
include=\[bbl@extracaps@#2]}]{#2}}%
\bbl@ifunset{bbl@ensure@\languagename}%
{\bbl@exp{%
\\\DeclareRobustCommand\<bbl@ensure@\languagename>[1]{%
\\\foreignlanguage{\languagename}%
{####1}}}}%
{}%
\bbl@exp{%
\\\bbl@toglobal\<bbl@ensure@\languagename>%
\\\bbl@toglobal\<bbl@ensure@\languagename\space>}%
\fi
% \end{macrocode}
%
% 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 set the basic parameters, but still loading the
% whole ini file.
%
% \begin{macrocode}
\bbl@load@basic{#2}%
% == script, language ==
% Override the values from ini or defines them
\ifx\bbl@KVP@script\@nnil\else
\bbl@csarg\edef{sname@#2}{\bbl@KVP@script}%
\fi
\ifx\bbl@KVP@language\@nnil\else
\bbl@csarg\edef{lname@#2}{\bbl@KVP@language}%
\fi
\ifcase\bbl@engine\or
\bbl@ifunset{bbl@chrng@\languagename}{}%
{\directlua{
Babel.set_chranges_b('\bbl@cl{sbcp}', '\bbl@cl{chrng}') }}%
\fi
% == Line breaking: intraspace, intrapenalty ==
% For CJK, East Asian, Southeast Asian, if interspace in ini
\ifx\bbl@KVP@intraspace\@nnil\else % We can override the ini or set
\bbl@csarg\edef{intsp@#2}{\bbl@KVP@intraspace}%
\fi
\bbl@provide@intraspace
% == Line breaking: justification ==
\ifx\bbl@KVP@justification\@nnil\else
\let\bbl@KVP@linebreaking\bbl@KVP@justification
\fi
\ifx\bbl@KVP@linebreaking\@nnil\else
\bbl@xin@{,\bbl@KVP@linebreaking,}%
{,elongated,kashida,cjk,padding,unhyphenated,}%
\ifin@
\bbl@csarg\xdef
{lnbrk@\languagename}{\expandafter\@car\bbl@KVP@linebreaking\@nil}%
\fi
\fi
\bbl@xin@{/e}{/\bbl@cl{lnbrk}}%
\ifin@\else\bbl@xin@{/k}{/\bbl@cl{lnbrk}}\fi
\ifin@\bbl@arabicjust\fi
\bbl@xin@{/p}{/\bbl@cl{lnbrk}}%
\ifin@\AtBeginDocument{\@nameuse{bbl@tibetanjust}}\fi
% == Line breaking: hyphenate.other.(locale|script) ==
\ifx\bbl@lbkflag\@empty
\bbl@ifunset{bbl@hyotl@\languagename}{}%
{\bbl@csarg\bbl@replace{hyotl@\languagename}{ }{,}%
\bbl@startcommands*{\languagename}{}%
\bbl@csarg\bbl@foreach{hyotl@\languagename}{%
\ifcase\bbl@engine
\ifnum##1<257
\SetHyphenMap{\BabelLower{##1}{##1}}%
\fi
\else
\SetHyphenMap{\BabelLower{##1}{##1}}%
\fi}%
\bbl@endcommands}%
\bbl@ifunset{bbl@hyots@\languagename}{}%
{\bbl@csarg\bbl@replace{hyots@\languagename}{ }{,}%
\bbl@csarg\bbl@foreach{hyots@\languagename}{%
\ifcase\bbl@engine
\ifnum##1<257
\global\lccode##1=##1\relax
\fi
\else
\global\lccode##1=##1\relax
\fi}}%
\fi
% == Counters: 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\@nnil\else
\ifx\bbl@latinarabic\@undefined
\expandafter\let\expandafter\@arabic
\csname bbl@counter@\languagename\endcsname
\else % i.e., if layout=counters, which redefines \@arabic
\expandafter\let\expandafter\bbl@latinarabic
\csname bbl@counter@\languagename\endcsname
\fi
\fi
\fi}%
\fi
% == Counters: mapdigits ==
% > luababel.def
% == Counters: alph, Alph ==
\ifx\bbl@KVP@alph\@nnil\else
\bbl@exp{%
\\\bbl@add\<bbl@preextras@\languagename>{%
\\\babel@save\\\@alph
\let\\\@alph\<bbl@cntr@\bbl@KVP@alph @\languagename>}}%
\fi
\ifx\bbl@KVP@Alph\@nnil\else
\bbl@exp{%
\\\bbl@add\<bbl@preextras@\languagename>{%
\\\babel@save\\\@Alph
\let\\\@Alph\<bbl@cntr@\bbl@KVP@Alph @\languagename>}}%
\fi
% == Counters: mapdot ==
\ifx\bbl@KVP@mapdot\@nnil\else
\bbl@foreach\bbl@list@the{%
\bbl@ifunset{the##1}{}%
{{\bbl@ncarg\let\bbl@tempd{the##1}%
\bbl@carg\bbl@sreplace{the##1}{.}{\bbl@map@lbl{.}}%
\expandafter\ifx\csname the##1\endcsname\bbl@tempd\else
\bbl@exp{\gdef\<the##1>{{\[the##1]}}}%
\fi}}}%
\edef\bbl@tempb{enumi,enumii,enumiii,enumiv}%
\bbl@foreach\bbl@tempb{%
\bbl@ifunset{label##1}{}%
{{\bbl@ncarg\let\bbl@tempd{label##1}%
\bbl@carg\bbl@sreplace{label##1}{.}{\bbl@map@lbl{.}}%
\expandafter\ifx\csname label##1\endcsname\bbl@tempd\else
\bbl@exp{\gdef\<label##1>{{\[label##1]}}}%
\fi}}}%
\fi
% == Casing ==
\bbl@release@casing
\ifx\bbl@KVP@casing\@nnil\else
\bbl@csarg\xdef{casing@\languagename}%
{\@nameuse{bbl@casing@\languagename}\bbl@maybextx\bbl@KVP@casing}%
\fi
% == Calendars ==
\ifx\bbl@KVP@calendar\@nnil
\edef\bbl@KVP@calendar{\bbl@cl{calpr}}%
\fi
\def\bbl@tempe##1 ##2\@@{% Get first calendar
\def\bbl@tempa{##1}}%
\bbl@exp{\\\bbl@tempe\bbl@KVP@calendar\space\\\@@}%
\def\bbl@tempe##1.##2.##3\@@{%
\def\bbl@tempc{##1}%
\def\bbl@tempb{##2}}%
\expandafter\bbl@tempe\bbl@tempa..\@@
\bbl@csarg\edef{calpr@\languagename}{%
\ifx\bbl@tempc\@empty\else
calendar=\bbl@tempc
\fi
\ifx\bbl@tempb\@empty\else
,variant=\bbl@tempb
\fi}%
% == engine specific extensions ==
% Defined in XXXbabel.def
\bbl@provide@extra{#2}%
% == require.babel in ini ==
% To load or reaload the babel-*.tex, if require.babel in ini
\ifx\bbl@beforestart\relax\else % But not in doc aux or body
\bbl@ifunset{bbl@rqtex@\languagename}{}%
{\expandafter\ifx\csname bbl@rqtex@\languagename\endcsname\@empty\else
\let\BabelBeforeIni\@gobbletwo
\chardef\atcatcode=\catcode`\@
\catcode`\@=11\relax
\def\CurrentOption{#2}%
\bbl@input@texini{\bbl@cs{rqtex@\languagename}}%
\catcode`\@=\atcatcode
\let\atcatcode\relax
\global\bbl@csarg\let{rqtex@\languagename}\relax
\fi}%
\bbl@foreach\bbl@calendars{%
\bbl@ifunset{bbl@ca@##1}{%
\chardef\atcatcode=\catcode`\@
\catcode`\@=11\relax
\InputIfFileExists{babel-ca-##1.tex}{}{}%
\catcode`\@=\atcatcode
\let\atcatcode\relax}%
{}}%
\fi
% == frenchspacing ==
\ifcase\bbl@howloaded\in@true\else\in@false\fi
\ifin@\else\bbl@xin@{typography/frenchspacing}{\bbl@key@list}\fi
\ifin@
\bbl@extras@wrap{\\\bbl@pre@fs}%
{\bbl@pre@fs}%
{\bbl@post@fs}%
\fi
% == transforms ==
% > luababel.def
\def\CurrentOption{#2}%
\@nameuse{bbl@icsave@#2}%
% == main ==
\ifx\bbl@KVP@main\@nnil % Restore only if not 'main'
\let\languagename\bbl@savelangname
\chardef\localeid\bbl@savelocaleid\relax
\fi
% == hyphenrules (apply if current) ==
\ifx\bbl@KVP@hyphenrules\@nnil\else
\ifnum\bbl@savelocaleid=\localeid
\language\@nameuse{l@\languagename}%
\fi
\fi}
% \end{macrocode}
%
% Depending on whether or not the language exists (based on
% |\date<language>|), we define two macros. Remember
% |\bbl@startcommands| opens a group.
%
% \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\@nnil % and also if import, implicit
\def\bbl@tempb##1{% elt for \bbl@captionslist
\ifx##1\@nnil\else
\bbl@exp{%
\\\SetString\\##1{%
\\\bbl@nocaption{\bbl@stripslash##1}{#1\bbl@stripslash##1}}}%
\expandafter\bbl@tempb
\fi}%
\expandafter\bbl@tempb\bbl@captionslist\@nnil
\else
\ifx\bbl@initoload\relax
\bbl@read@ini{\bbl@KVP@captions}2% % Here letters cat = 11
\else
\bbl@read@ini{\bbl@initoload}2% % Same
\fi
\fi
\StartBabelCommands*{#1}{date}%
\ifx\bbl@KVP@date\@nnil
\bbl@exp{%
\\\SetString\\\today{\\\bbl@nocaption{today}{#1today}}}%
\else
\bbl@savetoday
\bbl@savedate
\fi
\bbl@endcommands
\bbl@load@basic{#1}%
% == hyphenmins == (only if new)
\bbl@exp{%
\gdef\<#1hyphenmins>{%
{\bbl@ifunset{bbl@lfthm@#1}{2}{\bbl@cs{lfthm@#1}}}%
{\bbl@ifunset{bbl@rgthm@#1}{3}{\bbl@cs{rgthm@#1}}}}}%
% == hyphenrules (also in renew) ==
\bbl@provide@hyphens{#1}%
\ifx\bbl@KVP@main\@nnil\else
\expandafter\main@language\expandafter{#1}%
\fi}
%
\def\bbl@provide@renew#1{%
\ifx\bbl@KVP@captions\@nnil\else
\StartBabelCommands*{#1}{captions}%
\bbl@read@ini{\bbl@KVP@captions}2% % Here all letters cat = 11
\EndBabelCommands
\fi
\ifx\bbl@KVP@date\@nnil\else
\StartBabelCommands*{#1}{date}%
\bbl@savetoday
\bbl@savedate
\EndBabelCommands
\fi
% == hyphenrules (also in new) ==
\ifx\bbl@lbkflag\@empty
\bbl@provide@hyphens{#1}%
\fi}
% \end{macrocode}
%
% Load the basic parameters (ids, typography, counters, and a few
% more), while captions and dates are left out. But it may happen some
% data has been loaded before automatically, so we first discard the
% saved values.
%
% \begin{macrocode}
\def\bbl@load@basic#1{%
\ifcase\bbl@howloaded\or\or
\ifcase\csname bbl@llevel@\languagename\endcsname
\bbl@csarg\let{lname@\languagename}\relax
\fi
\fi
\bbl@ifunset{bbl@lname@#1}%
{\def\BabelBeforeIni##1##2{%
\begingroup
\let\bbl@ini@captions@aux\@gobbletwo
\def\bbl@inidate ####1.####2.####3.####4\relax ####5####6{}%
\bbl@read@ini{##1}1%
\ifx\bbl@initoload\relax\endinput\fi
\endgroup}%
\begingroup % boxed, to avoid extra spaces:
\ifx\bbl@initoload\relax
\bbl@input@texini{#1}%
\else
\setbox\z@\hbox{\BabelBeforeIni{\bbl@initoload}{}}%
\fi
\endgroup}%
{}}
% \end{macrocode}
%
% The following |ini| reader ignores everything but the
% |identification| section. It is called when a font is defined (i.e.,
% 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}
\def\bbl@load@info#1{%
\def\BabelBeforeIni##1##2{%
\begingroup
\bbl@read@ini{##1}0%
\endinput % babel- .tex may contain onlypreamble's
\endgroup}% boxed, to avoid extra spaces:
{\bbl@input@texini{#1}}}
% \end{macrocode}
%
% The |hyphenrules| option is handled with an auxiliary macro. This
% macro is called in three cases: when a language is first declared
% with |\babelprovide|, with |hyphenrules| and with |import|.
%
% \begin{macrocode}
\def\bbl@provide@hyphens#1{%
\@tempcnta\m@ne % a flag
\ifx\bbl@KVP@hyphenrules\@nnil\else
\bbl@replace\bbl@KVP@hyphenrules{ }{,}%
\bbl@foreach\bbl@KVP@hyphenrules{%
\ifnum\@tempcnta=\m@ne % if not yet found
\bbl@ifsamestring{##1}{+}%
{\bbl@carg\addlanguage{l@##1}}%
{}%
\bbl@ifunset{l@##1}% After a possible +
{}%
{\@tempcnta\@nameuse{l@##1}}%
\fi}%
\ifnum\@tempcnta=\m@ne
\bbl@warning{%
Requested 'hyphenrules' for '\languagename' not found:\\%
\bbl@KVP@hyphenrules.\\%
Using the default value. Reported}%
\fi
\fi
\ifnum\@tempcnta=\m@ne % if no opt or no language in opt found
\ifx\bbl@KVP@captions@@\@nnil
\bbl@ifunset{bbl@hyphr@#1}{}% use value in ini, if exists
{\bbl@exp{\\\bbl@ifblank{\bbl@cs{hyphr@#1}}}%
{}%
{\bbl@ifunset{l@\bbl@cl{hyphr}}%
{}% if hyphenrules found:
{\@tempcnta\@nameuse{l@\bbl@cl{hyphr}}}}}%
\fi
\fi
\bbl@ifunset{l@#1}%
{\ifnum\@tempcnta=\m@ne
\bbl@carg\adddialect{l@#1}\language
\else
\bbl@carg\adddialect{l@#1}\@tempcnta
\fi}%
{\ifnum\@tempcnta=\m@ne\else
\global\bbl@carg\chardef{l@#1}\@tempcnta
\fi}}
% \end{macrocode}
%
% The reader of |babel-...tex| files. We reset temporarily some
% catcodes (and make sure no space is accidentally inserted).
%
% \begin{macrocode}
\def\bbl@input@texini#1{%
\bbl@bsphack
\bbl@exp{%
\catcode`\\\%=14 \catcode`\\\\=0
\catcode`\\\{=1 \catcode`\\\}=2
\lowercase{\\\InputIfFileExists{babel-#1.tex}{}{}}%
\catcode`\\\%=\the\catcode`\%\relax
\catcode`\\\\=\the\catcode`\\\relax
\catcode`\\\{=\the\catcode`\{\relax
\catcode`\\\}=\the\catcode`\}\relax}%
\bbl@esphack}
% \end{macrocode}
%
% The following macros read and store |ini| files (but don't process
% them). For each line, there are 3 possible actions: ignore if starts
% with |;|, switch section if starts with |[|, and store otherwise.
% There are used in the first step of |\bbl@read@ini|.
%
% \begin{macrocode}
\def\bbl@iniline#1\bbl@iniline{%
\@ifnextchar[\bbl@inisect{\@ifnextchar;\bbl@iniskip\bbl@inistore}#1\@@}% ]
\def\bbl@inisect[#1]#2\@@{\def\bbl@section{#1}}
\def\bbl@iniskip#1\@@{}% if starts with ;
\def\bbl@inistore#1=#2\@@{% full (default)
\bbl@trim@def\bbl@tempa{#1}%
\bbl@trim\toks@{#2}%
\bbl@ifsamestring{\bbl@tempa}{@include}%
{\bbl@read@subini{\the\toks@}}%
{\bbl@xin@{;\bbl@section/\bbl@tempa;}{\bbl@key@list}%
\ifin@\else
\bbl@xin@{,identification/include.}%
{,\bbl@section/\bbl@tempa}%
\ifin@\xdef\bbl@included@inis{\the\toks@}\fi
\bbl@exp{%
\\\g@addto@macro\\\bbl@inidata{%
\\\bbl@elt{\bbl@section}{\bbl@tempa}{\the\toks@}}}%
\fi}}
\def\bbl@inistore@min#1=#2\@@{% minimal (maybe set in \bbl@read@ini)
\bbl@trim@def\bbl@tempa{#1}%
\bbl@trim\toks@{#2}%
\bbl@xin@{.identification.}{.\bbl@section.}%
\ifin@
\bbl@exp{\\\g@addto@macro\\\bbl@inidata{%
\\\bbl@elt{identification}{\bbl@tempa}{\the\toks@}}}%
\fi}
% \end{macrocode}
%
% \subsection{Main loop in ‘provide’}
%
% Now, the ‘main loop’, |\bbl@read@ini|, which \textbf{**must be
% executed inside a group**}. At this point, |\bbl@inidata| may contain
% data declared in |\babelprovide|, with ‘slashed’ keys. There are 3
% steps: first read the ini file and store it; then traverse the stored
% values, and process some groups if required (date, captions, labels,
% counters); finally, ‘export’ some values by defining global macros
% (identification, typography, characters, numbers). The second
% argument is 0 when called to read the minimal data for fonts; with
% |\babelprovide| it's either 1 (without \texttt{import}) or 2 (which
% |import|). The value $-$1 is used with |\DocumentMetadata|.
%
% |\bbl@loop@ini| is the reader, line by line (1: stream), and calls
% |\bbl@iniline| to save the key/value pairs. If |\bbl@inistore| finds
% the |@include| directive, the input stream is switched temporarily and
% |\bbl@read@subini| is called.
%
% When the language is being set based on the document metadata (\#2 in
% |\bbl@read@ini| is $-$1), there is an interlude to get the name,
% after the data have been collected, and before it’s processed.
%
% \begin{macrocode}
\def\bbl@loop@ini#1{%
\loop
\if T\ifeof#1 F\fi T\relax % Trick, because inside \loop
\endlinechar\m@ne
\read#1 to \bbl@line
\endlinechar`\^^M
\ifx\bbl@line\@empty\else
\expandafter\bbl@iniline\bbl@line\bbl@iniline
\fi
\repeat}
%
\def\bbl@read@subini#1{%
\ifx\bbl@readsubstream\@undefined
\csname newread\endcsname\bbl@readsubstream
\fi
\openin\bbl@readsubstream=babel-#1.ini
\ifeof\bbl@readsubstream
\bbl@error{no-ini-file}{#1}{}{}%
\else
{\bbl@loop@ini\bbl@readsubstream}%
\fi
\closein\bbl@readsubstream}
%
\ifx\bbl@readstream\@undefined
\csname newread\endcsname\bbl@readstream
\fi
\def\bbl@read@ini#1#2{%
\global\let\bbl@extend@ini\@gobble
\openin\bbl@readstream=babel-#1.ini
\ifeof\bbl@readstream
\bbl@error{no-ini-file}{#1}{}{}%
\else
% == Store ini data in \bbl@inidata ==
\catcode`\ =10 \catcode`\"=12
\catcode`\[=12 \catcode`\]=12 \catcode`\==12 \catcode`\&=12
\catcode`\;=12 \catcode`\|=12 \catcode`\%=14 \catcode`\-=12
\ifnum#2=\m@ne % Just for the info
\edef\languagename{tag \bbl@metalang}%
\fi
\bbl@info{Importing
\ifcase#2font and identification \or basic \fi
data for \languagename\\%
from babel-#1.ini. Reported}%
\ifnum#2<\@ne
\global\let\bbl@inidata\@empty
\let\bbl@inistore\bbl@inistore@min % Remember it's local
\fi
\def\bbl@section{identification}%
\bbl@exp{%
\\\bbl@inistore tag.ini=#1\\\@@
\\\bbl@inistore load.level=\ifnum#2<\@ne 0\else #2\fi\\\@@}%
\bbl@loop@ini\bbl@readstream
% == Process stored data ==
\ifnum#2=\m@ne
\def\bbl@tempa##1 ##2\@@{##1}% Get first name
\def\bbl@elt##1##2##3{%
\bbl@ifsamestring{identification/name.babel}{##1/##2}%
{\edef\languagename{\bbl@tempa##3 \@@}%
\bbl@id@assign
\def\bbl@elt####1####2####3{}}%
{}}%
\bbl@inidata
\fi
\bbl@csarg\xdef{lini@\languagename}{#1}%
\bbl@read@ini@aux
% == 'Export' data ==
\bbl@ini@exports{#2}%
\global\bbl@csarg\let{inidata@\languagename}\bbl@inidata
\global\let\bbl@inidata\@empty
\bbl@exp{\\\bbl@add@list\\\bbl@ini@loaded{\languagename}}%
\bbl@toglobal\bbl@ini@loaded
\fi
\closein\bbl@readstream}
\def\bbl@read@ini@aux{%
\let\bbl@savestrings\@empty
\let\bbl@savetoday\@empty
\let\bbl@savedate\@empty
\def\bbl@elt##1##2##3{%
\def\bbl@section{##1}%
\in@{=date.}{=##1}% Find a better place
\ifin@
\bbl@ifunset{bbl@inikv@##1}%
{\bbl@ini@calendar{##1}}%
{}%
\fi
\bbl@ifunset{bbl@inikv@##1}{}%
{\csname bbl@inikv@##1\endcsname{##2}{##3}}}%
\bbl@inidata}
% \end{macrocode}
%
% A variant to be used when the ini file has been already loaded,
% because it's not the first |\babelprovide| for this language.
%
% \begin{macrocode}
\def\bbl@extend@ini@aux#1{%
\bbl@startcommands*{#1}{captions}%
% Activate captions/... and modify exports
\bbl@csarg\def{
[email protected]}##1##2{%
\setlocalecaption{#1}{##1}{##2}}%
\def\bbl@inikv@captions##1##2{%
\bbl@ini@captions@aux{##1}{##2}}%
\def\bbl@stringdef##1##2{\gdef##1{##2}}%
\def\bbl@exportkey##1##2##3{%
\bbl@ifunset{bbl@@kv@##2}{}%
{\expandafter\ifx\csname bbl@@kv@##2\endcsname\@empty\else
\bbl@exp{\global\let\<bbl@##1@\languagename>\<bbl@@kv@##2>}%
\fi}}%
% As with \bbl@read@ini, but with some changes
\bbl@read@ini@aux
\bbl@ini@exports\tw@
% Update inidata@lang by pretending the ini is read.
\def\bbl@elt##1##2##3{%
\def\bbl@section{##1}%
\bbl@iniline##2=##3\bbl@iniline}%
\csname bbl@inidata@#1\endcsname
\global\bbl@csarg\let{inidata@#1}\bbl@inidata
\StartBabelCommands*{#1}{date}% And from the import stuff
\def\bbl@stringdef##1##2{\gdef##1{##2}}%
\bbl@savetoday
\bbl@savedate
\bbl@endcommands}
% \end{macrocode}
%
% A somewhat hackish tool to handle calendar sections.
%
% \begin{macrocode}
\def\bbl@ini@calendar#1{%
\lowercase{\def\bbl@tempa{=#1=}}%
\bbl@replace\bbl@tempa{=date.gregorian}{}%
\bbl@replace\bbl@tempa{=date.}{}%
\in@{.licr=}{#1=}%
\ifin@
\ifcase\bbl@engine
\bbl@replace\bbl@tempa{.licr=}{}%
\else
\let\bbl@tempa\relax
\fi
\fi
\ifx\bbl@tempa\relax\else
\bbl@replace\bbl@tempa{=}{}%
\ifx\bbl@tempa\@empty\else
\xdef\bbl@calendars{\bbl@calendars,\bbl@tempa}%
\fi
\bbl@exp{%
\def\<bbl@inikv@#1>####1####2{%
\\\bbl@inidate####1...\relax{####2}{\bbl@tempa}}}%
\fi}
% \end{macrocode}
%
% A key with a slash in |\babelprovide| replaces the value in the |ini|
% file (which is ignored altogether). The mechanism is simple (but
% suboptimal): add the data to the |ini| one (at this point the |ini|
% file has not yet been read), and define a dummy macro. When the |ini|
% file is read, just skip the corresponding key and reset the macro (in
% |\bbl@inistore| above).
%
% \begin{macrocode}
\def\bbl@renewinikey#1/#2\@@#3{%
\global\let\bbl@extend@ini\bbl@extend@ini@aux
\edef\bbl@tempa{\zap@space #1 \@empty}% section
\edef\bbl@tempb{\zap@space #2 \@empty}% key
\bbl@trim\toks@{#3}% value
\bbl@exp{%
\edef\\\bbl@key@list{\bbl@key@list \bbl@tempa/\bbl@tempb;}%
\\\g@addto@macro\\\bbl@inidata{%
\\\bbl@elt{\bbl@tempa}{\bbl@tempb}{\the\toks@}}}}%
% \end{macrocode}
%
% The previous assignments are local, so we need to export them. If
% the value is empty, we can provide a default value.
%
% \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\<bbl@#1@\languagename>\<bbl@@kv@#2>}%
\fi}}
% \end{macrocode}
%
% 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@ini@exports|
% is called always (via |\bbl@inisec|), while |\bbl@after@ini| must be
% called explicitly after |\bbl@read@ini| if necessary.
%
% Although BCP 47 doesn’t treat ‘-x-’ as an extension, the CLDR and
% many other sources do (as a \textit{private use extension}). For
% consistency with other single-letter subtags or ‘singletons’, here
% is considered an extension, too.
%
% The identification section is used internally by \babel\ in the
% following places [to be completed]: BCP 47 script tag in the Unicode
% ranges, which is in turn used by |onchar|; the language system is set
% with the names, and then \textsf{fontspec} maps them to the opentype
% tags, but if the latter package doesn’t define them, then \babel\
% does it; |encodings| are used in \pdftex{} to select a font encoding
% valid (and preloaded) for a language loaded on the fly.
%
% \begin{macrocode}
\def\bbl@iniwarning#1{%
\bbl@ifunset{bbl@@
[email protected]#1}{}%
{\bbl@warning{%
From babel-\bbl@cs{lini@\languagename}.ini:\\%
\bbl@cs{@
[email protected]#1}\\%
Reported}}}
%
\let\bbl@release@transforms\@empty
\let\bbl@release@casing\@empty
% \end{macrocode}
%
% Relevant keys are ‘exported’, i.e., global macros with short names
% are created with values taken from the corresponding keys. The
% number of exported keys depends on the loading level (\#1): $-$1 and
% 0 only info (the identificacion section), 1 also basic (like
% linebreaking or character ranges), 2 also (re)new (with date and
% captions).
%
% \begin{macrocode}
\def\bbl@ini@exports#1{%
% Identification always exported
\bbl@iniwarning{}%
\ifcase\bbl@engine
\bbl@iniwarning{.pdflatex}%
\or
\bbl@iniwarning{.lualatex}%
\or
\bbl@iniwarning{.xelatex}%
\fi%
\bbl@exportkey{llevel}{identification.load.level}{}%
\bbl@exportkey{elname}{identification.name.english}{}%
\bbl@exp{\\\bbl@exportkey{lname}{identification.name.opentype}%
{\csname bbl@elname@\languagename\endcsname}}%
\bbl@exportkey{tbcp}{identification.tag.bcp47}{}%
\bbl@exportkey{casing}{identification.tag.bcp47}{}%
\bbl@exportkey{lbcp}{identification.language.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}%
\bbl@exportkey{rbcp}{identification.region.tag.bcp47}{}%
\bbl@exportkey{vbcp}{identification.variant.tag.bcp47}{}%
\bbl@exportkey{extt}{identification.extension.t.tag.bcp47}{}%
\bbl@exportkey{extu}{identification.extension.u.tag.bcp47}{}%
\bbl@exportkey{extx}{identification.extension.x.tag.bcp47}{}%
% Also maps bcp47 -> languagename
\bbl@csarg\xdef{bcp@map@\bbl@cl{tbcp}}{\languagename}%
\ifcase\bbl@engine\or
\directlua{%
Babel.locale_props[\the\bbl@cs{id@@\languagename}].script
= '\bbl@cl{sbcp}'}%
\fi
% Conditional
\ifnum#1>\z@ % -1 or 0 = only info, 1 = basic, 2 = (re)new
\bbl@exportkey{calpr}{date.calendar.preferred}{}%
\bbl@exportkey{lnbrk}{typography.linebreaking}{h}%
\bbl@exportkey{hyphr}{typography.hyphenrules}{}%
\bbl@exportkey{lfthm}{typography.lefthyphenmin}{2}%
\bbl@exportkey{rgthm}{typography.righthyphenmin}{3}%
\bbl@exportkey{prehc}{typography.prehyphenchar}{}%
\bbl@exportkey{hyotl}{typography.hyphenate.other.locale}{}%
\bbl@exportkey{hyots}{typography.hyphenate.other.script}{}%
\bbl@exportkey{intsp}{typography.intraspace}{}%
\bbl@exportkey{frspc}{typography.frenchspacing}{u}%
\bbl@exportkey{chrng}{characters.ranges}{}%
\bbl@exportkey{quote}{characters.delimiters.quotes}{}%
\bbl@exportkey{dgnat}{numbers.digits.native}{}%
\ifnum#1=\tw@ % only (re)new
\bbl@exportkey{rqtex}{identification.require.babel}{}%
\bbl@toglobal\bbl@savetoday
\bbl@toglobal\bbl@savedate
\bbl@savestrings
\fi
\fi}
% \end{macrocode}
%
% \subsection{Processing keys in \texttt{ini}}
%
% A shared handler for key=val lines to be stored in
% |\bbl@@kv@<section>.<key>|.
%
% \begin{macrocode}
\def\bbl@inikv#1#2{% key=value
\toks@{#2}% This hides #'s from ini values
\bbl@csarg\edef{@kv@\bbl@section.#1}{\the\toks@}}
% \end{macrocode}
%
% By default, the following sections are just read. Actions are taken
% later.
%
% \begin{macrocode}
\let\bbl@inikv@identification\bbl@inikv
\let\bbl@inikv@date\bbl@inikv
\let\bbl@inikv@typography\bbl@inikv
\let\bbl@inikv@numbers\bbl@inikv
% \end{macrocode}
%
% The |characters| section also stores the values, but |casing| is
% treated in a different fashion. Much like transforms, a set of
% commands calling the parser are stored in |\bbl@release@casing|,
% which is executed in |\babelprovide|.
%
% \begin{macrocode}
\def\bbl@maybextx{-\bbl@csarg\ifx{extx@\languagename}\@empty x-\fi}
\def\bbl@inikv@characters#1#2{%
\bbl@ifsamestring{#1}{casing}% e.g., casing = uV
{\bbl@exp{%
\\\g@addto@macro\\\bbl@release@casing{%
\\\bbl@casemapping{}{\languagename}{\unexpanded{#2}}}}}%
{\in@{$casing.}{$#1}% e.g., casing.Uv = uV
\ifin@
\lowercase{\def\bbl@tempb{#1}}%
\bbl@replace\bbl@tempb{casing.}{}%
\bbl@exp{\\\g@addto@macro\\\bbl@release@casing{%
\\\bbl@casemapping
{\\\bbl@maybextx\bbl@tempb}{\languagename}{\unexpanded{#2}}}}%
\else
\bbl@inikv{#1}{#2}%
\fi}}
% \end{macrocode}
%
% Additive numerals require an additional definition. When |.1| is
% found, two macros are defined -- the basic one, without |.1| called
% by |\localenumeral|, and another one preserving the trailing |.1| for
% the ‘units’.
%
% \begin{macrocode}
\def\bbl@inikv@counters#1#2{%
\bbl@ifsamestring{#1}{digits}%
{\bbl@error{digits-is-reserved}{}{}{}}%
{}%
\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
\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}
% \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.
%
% \begin{macrocode}
\ifcase\bbl@engine
\bbl@csarg\def{
[email protected]}#1#2{%
\bbl@ini@captions@aux{#1}{#2}}
\else
\def\bbl@inikv@captions#1#2{%
\bbl@ini@captions@aux{#1}{#2}}
\fi
% \end{macrocode}
%
% The auxiliary macro for captions define |\<caption>name|.
%
% \begin{macrocode}
\def\bbl@ini@captions@template#1#2{% string language tempa=capt-name
\bbl@replace\bbl@tempa{.template}{}%
\def\bbl@toreplace{#1{}}%
\bbl@replace\bbl@toreplace{[ ]}{\nobreakspace{}}%
\bbl@replace\bbl@toreplace{[[}{\csname}%
\bbl@replace\bbl@toreplace{[}{\csname the}%
\bbl@replace\bbl@toreplace{]]}{name\endcsname{}}%
\bbl@replace\bbl@toreplace{]}{\endcsname{}}%
\bbl@xin@{,\bbl@tempa,}{,chapter,appendix,part,}%
\ifin@
\@nameuse{bbl@patch\bbl@tempa}%
\global\bbl@csarg\let{\bbl@tempa fmt@#2}\bbl@toreplace
\fi
\bbl@xin@{,\bbl@tempa,}{,figure,table,}%
\ifin@
\global\bbl@csarg\let{\bbl@tempa fmt@#2}\bbl@toreplace
\bbl@exp{\gdef\<fnum@\bbl@tempa>{%
\\\bbl@ifunset{bbl@\bbl@tempa fmt@\\\languagename}%
{\[fnum@\bbl@tempa]}%
{\\\@nameuse{bbl@\bbl@tempa fmt@\\\languagename}}}}%
\fi}
%
\def\bbl@ini@captions@aux#1#2{%
\bbl@trim@def\bbl@tempa{#1}%
\bbl@xin@{.template}{\bbl@tempa}%
\ifin@
\bbl@ini@captions@template{#2}\languagename
\else
\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@}}}%
\toks@\expandafter{\bbl@captionslist}%
\bbl@exp{\\\in@{\<\bbl@tempa name>}{\the\toks@}}%
\ifin@\else
\bbl@exp{%
\\\bbl@add\<bbl@extracaps@\languagename>{\<\bbl@tempa name>}%
\\\bbl@toglobal\<bbl@extracaps@\languagename>}%
\fi
\fi}
% \end{macrocode}
%
% \textbf{Labels.} Captions must contain just strings, no
% format at all, so there is new group in ini files.
%
% \begin{macrocode}
\def\bbl@list@the{%
part,chapter,section,subsection,subsubsection,paragraph,%
subparagraph,enumi,enumii,enumiii,enumiv,equation,figure,%
table,page,footnote,mpfootnote,mpfn}
%
\def\bbl@map@cnt#1{% #1:roman,etc, // #2:enumi,etc
\bbl@ifunset{bbl@map@#1@\languagename}%
{\@nameuse{#1}}%
{\@nameuse{bbl@map@#1@\languagename}}}
%
\def\bbl@map@lbl#1{% #1:a sign, eg, .
\ifincsname#1\else
\bbl@ifunset{bbl@map@@#1@@\languagename}%
{#1}%
{\@nameuse{bbl@map@@#1@@\languagename}}%
\fi}
%
\def\bbl@inikv@labels#1#2{%
\in@{.map}{#1}%
\ifin@
\in@{,dot.map,}{,#1,}%
\ifin@
\global\@namedef{bbl@map@@.@@\languagename}{#2}%
\fi
\ifx\bbl@KVP@labels\@nnil\else
\bbl@xin@{ map }{ \bbl@KVP@labels\space}%
\ifin@
\def\bbl@tempc{#1}%
\bbl@replace\bbl@tempc{.map}{}%
\in@{,#2,}{,arabic,roman,Roman,alph,Alph,fnsymbol,}%
\bbl@exp{%
\gdef\<bbl@map@\bbl@tempc @\languagename>%
{\ifin@\<#2>\else\\\localecounter{#2}\fi}}%
\bbl@foreach\bbl@list@the{%
\bbl@ifunset{the##1}{}%
{\bbl@ncarg\let\bbl@tempd{the##1}%
\bbl@exp{%
\\\bbl@sreplace\<the##1>%
{\<\bbl@tempc>{##1}}%
{\\\bbl@map@cnt{\bbl@tempc}{##1}}%
\\\bbl@sreplace\<the##1>%
{\<\@empty @\bbl@tempc>\<c@##1>}%
{\\\bbl@map@cnt{\bbl@tempc}{##1}}%
\\\bbl@sreplace\<the##1>%
{\\\csname @\bbl@tempc\\\endcsname\<c@##1>}%
{{\\\bbl@map@cnt{\bbl@tempc}{##1}}}}%
\expandafter\ifx\csname the##1\endcsname\bbl@tempd\else
\bbl@exp{\gdef\<the##1>{{\[the##1]}}}%
\fi}}%
\fi
\fi
%
\else
% The following code is still under study. You can test it and make
% suggestions. E.g., enumerate.2 = ([enumi]).([enumii]). It's
% language dependent.
\in@{enumerate.}{#1}%
\ifin@
\def\bbl@tempa{#1}%
\bbl@replace\bbl@tempa{enumerate.}{}%
\def\bbl@toreplace{#2}%
\bbl@replace\bbl@toreplace{[ ]}{\nobreakspace{}}%
\bbl@replace\bbl@toreplace{[}{\csname the}%
\bbl@replace\bbl@toreplace{]}{\endcsname{}}%
\toks@\expandafter{\bbl@toreplace}%
\bbl@exp{%
\\\bbl@add\<extras\languagename>{%
\\\babel@save\<labelenum\romannumeral\bbl@tempa>%
\def\<labelenum\romannumeral\bbl@tempa>{\the\toks@}}%
\\\bbl@toglobal\<extras\languagename>}%
\fi
\fi}
% \end{macrocode}
%
% To show correctly some captions in a few languages, we need to patch
% some internal macros, because the order is hardcoded. For example, in
% Japanese the chapter number is surrounded by two string, while in
% Hungarian is placed after. These replacement works in many classes,
% but not all. Actually, the following lines are somewhat tentative.
%
% \begin{macrocode}
\def\bbl@chaptype{chapter}
\ifx\@makechapterhead\@undefined
\let\bbl@patchchapter\relax
\else\ifx\thechapter\@undefined
\let\bbl@patchchapter\relax
\else\ifx\ps@headings\@undefined
\let\bbl@patchchapter\relax
\else
\def\bbl@patchchapter{%
\global\let\bbl@patchchapter\relax
\gdef\bbl@chfmt{%
\bbl@ifunset{bbl@\bbl@chaptype fmt@\languagename}%
{\@chapapp\space\thechapter}%
{\@nameuse{bbl@\bbl@chaptype fmt@\languagename}}}%
\bbl@add\appendix{\def\bbl@chaptype{appendix}}% Not harmful, I hope
\bbl@sreplace\ps@headings{\@chapapp\ \thechapter}{\bbl@chfmt}%
\bbl@sreplace\chaptermark{\@chapapp\ \thechapter}{\bbl@chfmt}%
\bbl@sreplace\@makechapterhead{\@chapapp\space\thechapter}{\bbl@chfmt}%
\bbl@toglobal\appendix
\bbl@toglobal\ps@headings
\bbl@toglobal\chaptermark
\bbl@toglobal\@makechapterhead}
\let\bbl@patchappendix\bbl@patchchapter
\fi\fi\fi
\ifx\@part\@undefined
\let\bbl@patchpart\relax
\else
\def\bbl@patchpart{%
\global\let\bbl@patchpart\relax
\gdef\bbl@partformat{%
\bbl@ifunset{bbl@partfmt@\languagename}%
{\partname\nobreakspace\thepart}%
{\@nameuse{bbl@partfmt@\languagename}}}%
\bbl@sreplace\@part{\partname\nobreakspace\thepart}{\bbl@partformat}%
\bbl@toglobal\@part}
\fi
% \end{macrocode}
%
% \textbf{Date.} Arguments (year, month, day) are \textit{not}
% protected, on purpose. In |\today|, arguments are always gregorian,
% and therefore always converted with other calendars.
%
% \begin{macrocode}
\let\bbl@calendar\@empty
\DeclareRobustCommand\localedate[1][]{\bbl@localedate{#1}}
\def\bbl@localedate#1#2#3#4{%
\begingroup
\edef\bbl@they{#2}%
\edef\bbl@them{#3}%
\edef\bbl@thed{#4}%
\edef\bbl@tempe{%
\bbl@ifunset{bbl@calpr@\languagename}{}{\bbl@cl{calpr}},%
#1}%
\bbl@exp{\lowercase{\edef\\\bbl@tempe{\bbl@tempe}}}%
\bbl@replace\bbl@tempe{ }{}%
\bbl@replace\bbl@tempe{convert}{convert=}%
\let\bbl@ld@calendar\@empty
\let\bbl@ld@variant\@empty
\let\bbl@ld@convert\relax
\def\bbl@tempb##1=##2\@@{\@namedef{bbl@ld@##1}{##2}}%
\bbl@foreach\bbl@tempe{\bbl@tempb##1\@@}%
\bbl@replace\bbl@ld@calendar{gregorian}{}%
\ifx\bbl@ld@calendar\@empty\else
\ifx\bbl@ld@convert\relax\else
\babelcalendar[\bbl@they-\bbl@them-\bbl@thed]%
{\bbl@ld@calendar}\bbl@they\bbl@them\bbl@thed
\fi
\fi
\@nameuse{bbl@precalendar}% Remove, e.g., +, -civil (-ca-islamic)
\edef\bbl@calendar{% Used in \month..., too
\bbl@ld@calendar
\ifx\bbl@ld@variant\@empty\else
.\bbl@ld@variant
\fi}%
\bbl@cased
{\@nameuse{bbl@date@\languagename @\bbl@calendar}%
\bbl@they\bbl@them\bbl@thed}%
\endgroup}
%
\def\bbl@printdate#1{%
\@ifnextchar[{\bbl@printdate@i{#1}}{\bbl@printdate@i{#1}[]}}
\def\bbl@printdate@i#1[#2]#3#4#5{%
\bbl@usedategrouptrue
\@nameuse{bbl@ensure@#1}{\localedate[#2]{#3}{#4}{#5}}}
%
% e.g.: 1=months, 2=wide, 3=1, 4=dummy, 5=value, 6=calendar
\def\bbl@inidate#1.#2.#3.#4\relax#5#6{%
\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}%
\@temptokena\expandafter{\bbl@savedate}%
\bbl@exp{% Reverse order - in ini last wins
\def\\\bbl@savedate{%
\\\SetString\<month\romannumeral\bbl@tempa#6name>{\the\toks@}%
\the\@temptokena}}}%
{\bbl@ifsamestring{\bbl@tempa}{date.long}% defined now
{\lowercase{\def\bbl@tempb{#6}}%
\bbl@trim@def\bbl@toreplace{#5}%
\bbl@TG@@date
\global\bbl@csarg\let{date@\languagename @\bbl@tempb}\bbl@toreplace
\ifx\bbl@savetoday\@empty
\bbl@exp{%
\\\AfterBabelCommands{%
\gdef\<\languagename date>{\\\protect\<\languagename date >}%
\gdef\<\languagename date >{\\\bbl@printdate{\languagename}}}%
\def\\\bbl@savetoday{%
\\\SetString\\\today{%
\<\languagename date>[convert]%
{\\\the\year}{\\\the\month}{\\\the\day}}}}%
\fi}%
{}}}
% \end{macrocode}
%
% \textbf{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. Note after
% |\bbl@replace| |\toks@| contains the resulting string, which is used
% by |\bbl@replace@finish@iii| (this implicit behavior doesn't seem a
% good idea, but it’s efficient).
%
% \begin{macrocode}
\let\bbl@calendar\@empty
\newcommand\babelcalendar[2][\the\year-\the\month-\the\day]{%
\@nameuse{bbl@ca@#2}#1\@@}
\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{limit-two-digits}{}{}{}%
\fi\fi\fi\fi}}
\newcommand\BabelDateyyyy[1]{{\number#1}}
\newcommand\BabelDateU[1]{{\number#1}}%
\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}}%
\bbl@replace\bbl@toreplace{[U]}{\BabelDateU{####1}}%
\bbl@replace\bbl@toreplace{[y|}{\bbl@datecntr[####1|}%
\bbl@replace\bbl@toreplace{[U|}{\bbl@datecntr[####1|}%
\bbl@replace\bbl@toreplace{[m|}{\bbl@datecntr[####2|}%
\bbl@replace\bbl@toreplace{[d|}{\bbl@datecntr[####3|}%
\bbl@replace@finish@iii\bbl@toreplace}
\def\bbl@datecntr{\expandafter\bbl@xdatecntr\expandafter}
\def\bbl@xdatecntr[#1|#2]{\localenumeral{#2}{#1}}
% \end{macrocode}
%
% \subsection{French spacing (again)}
%
% For the following declarations, see issue \#240. |\nonfrenchspacing|
% is set by |document| too early, so it’s a hack.
%
% \begin{macrocode}
\AddToHook{begindocument/before}{%
\let\bbl@normalsf\normalsfcodes
\let\normalsfcodes\relax}
\AtBeginDocument{%
\ifx\bbl@normalsf\@empty
\ifnum\sfcode`\.=\@m
\let\normalsfcodes\frenchspacing
\else
\let\normalsfcodes\nonfrenchspacing
\fi
\else
\let\normalsfcodes\bbl@normalsf
\fi}
% \end{macrocode}
%
% \textbf{Transforms.}
%
% Process the transforms read from |ini| files, converts them to a form
% close to the user interface (with |\babelprehyphenation| and
% |\babelprehyphenation|), wrapped with |\bbl@transforms@aux| \ldots
% |\relax|, and stores them in |\bbl@release@transforms|. However,
% since building a list enclosed in braces isn’t trivial, the
% replacements are added after a comma, and then |\bbl@transforms@aux|
% adds the braces.
%
% \begin{macrocode}
\bbl@csarg\let{
[email protected]}\bbl@inikv
\bbl@csarg\let{
[email protected]}\bbl@inikv
\def\bbl@transforms@aux#1#2#3#4,#5\relax{%
#1[#2]{#3}{#4}{#5}}
\begingroup
\catcode`\%=12
\catcode`\&=14
\gdef\bbl@transforms#1#2#3{&%
\directlua{
local str = [==[#2]==]
str = str:gsub('%.%d+%.%d+$', '')
token.set_macro('babeltempa', str)
}&%
\def\babeltempc{}&%
\bbl@xin@{,\babeltempa,}{,\bbl@KVP@transforms,}&%
\ifin@\else
\bbl@xin@{:\babeltempa,}{,\bbl@KVP@transforms,}&%
\fi
\ifin@
\bbl@foreach\bbl@KVP@transforms{&%
\bbl@xin@{:\babeltempa,}{,##1,}&%
\ifin@ &% font:font:transform syntax
\directlua{
local t = {}
for m in string.gmatch('##1'..':', '(.-):') do
table.insert(t, m)
end
table.remove(t)
token.set_macro('babeltempc', ',fonts=' .. table.concat(t, ' '))
}&%
\fi}&%
\in@{.0$}{#2$}&%
\ifin@
\directlua{&% (\attribute) syntax
local str = string.match([[\bbl@KVP@transforms]],
'%(([^%(]-)%)[^%)]-\babeltempa')
if str == nil then
token.set_macro('babeltempb', '')
else
token.set_macro('babeltempb', ',attribute=' .. str)
end
}&%
\toks@{#3}&%
\bbl@exp{&%
\\\g@addto@macro\\\bbl@release@transforms{&%
\relax &% Closes previous \bbl@transforms@aux
\\\bbl@transforms@aux
\\#1{label=\babeltempa\babeltempb\babeltempc}&%
{\languagename}{\the\toks@}}}&%
\else
\g@addto@macro\bbl@release@transforms{, {#3}}&%
\fi
\fi}
\endgroup
% \end{macrocode}
%
% \subsection{Handle language system}
%
% The language system (i.e., |Language| and |Script|) to be used when
% defining a font or setting the direction are set with the following
% macros. It also deals with unhyphenated line breaking in \xetex\
% (e.g., Thai and traditional Sanskrit), which is done with a hack at
% the font level because this engine doesn’t support it.
%
% \begin{macrocode}
\def\bbl@provide@lsys#1{%
\bbl@ifunset{bbl@lname@#1}%
{\bbl@load@info{#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}}}%
{}%
{\ifx\bbl@xenohyph\@undefined
\global\let\bbl@xenohyph\bbl@xenohyph@d
\ifx\AtBeginDocument\@notprerr
\expandafter\@secondoftwo % to execute right now
\fi
\AtBeginDocument{%
\bbl@patchfont{\bbl@xenohyph}%
{\expandafter\select@language\expandafter{\languagename}}}%
\fi}}%
\fi
\bbl@csarg\bbl@toglobal{lsys@#1}}
% \end{macrocode}
%
% \subsection{Numerals}
%
% 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. Non-digits characters are kept. The
% first macro is the generic “localized” command.
%
% \begin{macrocode}
\def\bbl@setdigits#1#2#3#4#5{%
\bbl@exp{%
\def\<\languagename digits>####1{% i.e., \langdigits
\<bbl@digits@\languagename>####1\\\@nil}%
\let\<bbl@cntr@digits@\languagename>\<\languagename digits>%
\def\<\languagename counter>####1{% i.e., \langcounter
\\\expandafter\<bbl@counter@\languagename>%
\\\csname c@####1\endcsname}%
\def\<bbl@counter@\languagename>####1{% i.e., \bbl@counter@lang
\\\expandafter\<bbl@digits@\languagename>%
\\\number####1\\\@nil}}%
\def\bbl@tempa##1##2##3##4##5{%
\bbl@exp{% Wow, quite a lot of hashes! :-(
\def\<bbl@digits@\languagename>########1{%
\\\ifx########1\\\@nil % i.e., \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\<bbl@digits@\languagename>%
\\\fi}}}%
\bbl@tempa}
% \end{macrocode}
%
% 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{%
\<ifcase>####1\space\the\toks@\<else>\\\@ctrerr\<fi>}}%
\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{macrocode}
\newcommand\localenumeral[2]{\bbl@cs{cntr@#1@\languagename}{#2}}
\def\bbl@localecntr#1#2{\localenumeral{#2}{#1}}
\newcommand\localecounter[2]{%
\expandafter\bbl@localecntr
\expandafter{\number\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 % Currently <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@
\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-too-large}{#1}{}{}}
% \end{macrocode}
%
% \subsection{Casing}
%
% \begin{macrocode}
\newcommand\BabelUppercaseMapping[3]{%
\DeclareUppercaseMapping[\@nameuse{bbl@casing@#1}]{#2}{#3}}
\newcommand\BabelTitlecaseMapping[3]{%
\DeclareTitlecaseMapping[\@nameuse{bbl@casing@#1}]{#2}{#3}}
\newcommand\BabelLowercaseMapping[3]{%
\DeclareLowercaseMapping[\@nameuse{bbl@casing@#1}]{#2}{#3}}
% \end{macrocode}
%
% The parser for |casing| and |casing.|\meta{variant}.
%
% \begin{macrocode}
\ifcase\bbl@engine % Converts utf8 to its code (expandable)
\def\bbl@utftocode#1{\the\numexpr\decode@UTFviii#1\relax}
\else
\def\bbl@utftocode#1{\expandafter`\string#1}
\fi
\def\bbl@casemapping#1#2#3{% 1:variant
\def\bbl@tempa##1 ##2{% Loop
\bbl@casemapping@i{##1}%
\ifx\@empty##2\else\bbl@afterfi\bbl@tempa##2\fi}%
\edef\bbl@templ{\@nameuse{bbl@casing@#2}#1}% Language code
\def\bbl@tempe{0}% Mode (upper/lower...)
\def\bbl@tempc{#3 }% Casing list
\expandafter\bbl@tempa\bbl@tempc\@empty}
\def\bbl@casemapping@i#1{%
\def\bbl@tempb{#1}%
\ifcase\bbl@engine % Handle utf8 in pdftex, by surrounding chars with {}
\@nameuse{regex_replace_all:nnN}%
{[\x{c0}-\x{ff}][\x{80}-\x{bf}]*}{{\0}}\bbl@tempb
\else
\@nameuse{regex_replace_all:nnN}{.}{{\0}}\bbl@tempb
\fi
\expandafter\bbl@casemapping@ii\bbl@tempb\@@}
\def\bbl@casemapping@ii#1#2#3\@@{%
\in@{#1#3}{<>}% i.e., if <u>, <l>, <t>
\ifin@
\edef\bbl@tempe{%
\if#2u1 \else\if#2l2 \else\if#2t3 \fi\fi\fi}%
\else
\ifcase\bbl@tempe\relax
\DeclareUppercaseMapping[\bbl@templ]{\bbl@utftocode{#1}}{#2}%
\DeclareLowercaseMapping[\bbl@templ]{\bbl@utftocode{#2}}{#1}%
\or
\DeclareUppercaseMapping[\bbl@templ]{\bbl@utftocode{#1}}{#2}%
\or
\DeclareLowercaseMapping[\bbl@templ]{\bbl@utftocode{#1}}{#2}%
\or
\DeclareTitlecaseMapping[\bbl@templ]{\bbl@utftocode{#1}}{#2}%
\fi
\fi}
% \end{macrocode}
%
% \subsection{Getting info}
%
% The information in the identification section can be useful, so the
% following macro just exposes it with a user command.
%
% \begin{macrocode}
\def\bbl@localeinfo#1#2{%
\bbl@ifunset{bbl@info@#2}{#1}%
{\bbl@ifunset{bbl@\csname bbl@info@#2\endcsname @\languagename}{#1}%
{\bbl@cs{\csname bbl@info@#2\endcsname @\languagename}}}}
\newcommand\localeinfo[1]{%
\ifx*#1\@empty
\bbl@afterelse\bbl@localeinfo{}%
\else
\bbl@localeinfo
{\bbl@error{no-ini-info}{}{}{}}%
{#1}%
\fi}
% \@namedef{bbl@
[email protected]}{lcname}
\@namedef{bbl@
[email protected]}{lini}
\@namedef{bbl@
[email protected]}{elname}
\@namedef{bbl@
[email protected]}{lname}
\@namedef{bbl@
[email protected]}{tbcp}
\@namedef{bbl@
[email protected]}{lbcp}
\@namedef{bbl@
[email protected]}{lotf}
\@namedef{bbl@
[email protected]}{esname}
\@namedef{bbl@
[email protected]}{sname}
\@namedef{bbl@
[email protected]}{sbcp}
\@namedef{bbl@
[email protected]}{sotf}
\@namedef{bbl@
[email protected]}{rbcp}
\@namedef{bbl@
[email protected]}{vbcp}
\@namedef{bbl@
[email protected]}{extt}
\@namedef{bbl@
[email protected]}{extu}
\@namedef{bbl@
[email protected]}{extx}
% \end{macrocode}
%
% With version 3.75 |\BabelEnsureInfo| is executed always, but there is
% an option to disable it. Since the info in |ini| files are always
% loaded, it has be made no-op in version 25.8.
%
% \begin{macrocode}
%<<*More package options>>
\DeclareOption{ensureinfo=off}{}
%<</More package options>>
\let\BabelEnsureInfo\relax
% \end{macrocode}
%
% More general, but non-expandable, is |\getlocaleproperty|.
%
% \begin{macrocode}
\newcommand\getlocaleproperty{%
\@ifstar\bbl@getproperty@s\bbl@getproperty@x}
\def\bbl@getproperty@s#1#2#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}}%
\def\bbl@getproperty@x#1#2#3{%
\bbl@getproperty@s{#1}{#2}{#3}%
\ifx#1\relax
\bbl@error{unknown-locale-key}{#1}{#2}{#3}%
\fi}
% \end{macrocode}
%
% 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}
\let\bbl@ini@loaded\@empty
\newcommand\LocaleForEach{\bbl@foreach\bbl@ini@loaded}
\def\ShowLocaleProperties#1{%
\typeout{}%
\typeout{*** Properties for language '#1' ***}
\def\bbl@elt##1##2##3{\typeout{##1/##2 = \unexpanded{##3}}}%
\@nameuse{bbl@inidata@#1}%
\typeout{*******}}
% \end{macrocode}
%
% \subsection{BCP 47 related commands}
%
% This macro is called by language selectors when the language isn’t
% recognized. So, it’s the core for (1) mapping from a BCP 27 tag to
% the actual language, if |bcp47.toname| is enabled (i.e., if
% |bbl@bcptoname| is true), and (2) lazy loading. With |autoload.bcp47|
% enabled \textit{and} lazy loading, we must first build a name for the
% language, with the help of |autoload.bcp47.prefix|. Then we use
% |\provideprovide| passing the options set with
% |autoload.bcp47.options| (by default |import|). Finally, and if the
% locale has not been loaded before, we use |\provideprovide| with the
% language name as passed to the selector.
%
% \begin{macrocode}
\newif\ifbbl@bcpallowed
\bbl@bcpallowedfalse
\def\bbl@autoload@options{@import}
\def\bbl@provide@locale{%
\ifx\babelprovide\@undefined
\bbl@error{base-on-the-fly}{}{}{}%
\fi
\let\bbl@auxname\languagename
\ifbbl@bcptoname
\bbl@ifunset{bbl@bcp@map@\languagename}{}% Move uplevel??
{\edef\languagename{\@nameuse{bbl@bcp@map@\languagename}}%
\let\localename\languagename}%
\fi
\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}%
\let\localename\languagename
\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}
%
% \LaTeX{} needs to know the BCP 47 codes for some features. For that,
% it expects |\BCPdata| to be defined. While |language|, |region|,
% |script|, and |variant| are recognized, |extension.<s>| for
% singletons may change.
%
% Still somewhat hackish. Note |\str_if_eq:nnTF| is fully
% expandable (|\bbl@ifsamestring| isn’t). The argument is the prefix to
% tag.bcp47.
%
% \begin{macrocode}
\providecommand\BCPdata{}
\ifx\renewcommand\@undefined\else
\renewcommand\BCPdata[1]{\bbl@bcpdata@i#1\@empty\@empty\@empty}
\def\bbl@bcpdata@i#1#2#3#4#5#6\@empty{%
\@nameuse{str_if_eq:nnTF}{#1#2#3#4#5}{main.}%
{\bbl@bcpdata@ii{#6}\bbl@main@language}%
{\bbl@bcpdata@ii{#1#2#3#4#5#6}\languagename}}%
\def\bbl@bcpdata@ii#1#2{%
\bbl@ifunset{bbl@info@#1.tag.bcp47}%
{\bbl@error{unknown-ini-field}{#1}{}{}}%
{\bbl@ifunset{bbl@\csname bbl@info@#1.tag.bcp47\endcsname @#2}{}%
{\bbl@cs{\csname bbl@info@#1.tag.bcp47\endcsname @#2}}}}
\fi
\@namedef{bbl@
[email protected]}{casing}
\@namedef{bbl@
[email protected]}{tbcp} % For \BCPdata
% \end{macrocode}
%
% \section{Adjusting the Babel behavior}
%
% A generic high level interface is provided to adjust some global
% and general settings.
%
% \begin{macrocode}
\newcommand\babeladjust[1]{%
\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@
\directlua{ Babel.#2 }%
\expandafter\expandafter\expandafter\@gobble
\fi
\fi
{\bbl@error{adjust-only-vertical}{#1}{}{}}}% Gobbled if everything went ok.
\@namedef{bbl@
[email protected]@on}{%
\bbl@adjust@lua{bidi}{mirroring_enabled=true}}
\@namedef{bbl@
[email protected]@off}{%
\bbl@adjust@lua{bidi}{mirroring_enabled=false}}
\@namedef{bbl@
[email protected]@on}{%
\bbl@adjust@lua{bidi}{bidi_enabled=true}}
\@namedef{bbl@
[email protected]@off}{%
\bbl@adjust@lua{bidi}{bidi_enabled=false}}
\@namedef{bbl@
[email protected]@on}{%
\let\bbl@noamsmath\@empty}
\@namedef{bbl@
[email protected]@off}{%
\let\bbl@noamsmath\relax}
%
\@namedef{bbl@
[email protected]@on}{%
\bbl@adjust@lua{bidi}{digits_mapped=true}}
\@namedef{bbl@
[email protected]@off}{%
\bbl@adjust@lua{bidi}{digits_mapped=false}}
%
\@namedef{bbl@
[email protected]@on}{%
\bbl@adjust@lua{linebreak}{sea_enabled=true}}
\@namedef{bbl@
[email protected]@off}{%
\bbl@adjust@lua{linebreak}{sea_enabled=false}}
\@namedef{bbl@
[email protected]@on}{%
\bbl@adjust@lua{linebreak}{cjk_enabled=true}}
\@namedef{bbl@
[email protected]@off}{%
\bbl@adjust@lua{linebreak}{cjk_enabled=false}}
\@namedef{bbl@
[email protected]@on}{%
\bbl@adjust@lua{linebreak}{arabic.justify_enabled=true}}
\@namedef{bbl@
[email protected]@off}{%
\bbl@adjust@lua{linebreak}{arabic.justify_enabled=false}}
%
\def\bbl@adjust@layout#1{%
\ifvmode
#1%
\expandafter\@gobble
\fi
{\bbl@error{layout-only-vertical}{}{}{}}}% Gobbled if everything went ok.
\@namedef{bbl@
[email protected]@on}{%
\ifnum\bbl@tabular@mode=\tw@
\bbl@adjust@layout{\let\@tabular\bbl@NL@@tabular}%
\else
\chardef\bbl@tabular@mode\@ne
\fi}
\@namedef{bbl@
[email protected]@off}{%
\ifnum\bbl@tabular@mode=\tw@
\bbl@adjust@layout{\let\@tabular\bbl@OL@@tabular}%
\else
\chardef\bbl@tabular@mode\z@
\fi}
\@namedef{bbl@
[email protected]@on}{%
\bbl@adjust@layout{\let\list\bbl@NL@list}}
\@namedef{bbl@
[email protected]@off}{%
\bbl@adjust@layout{\let\list\bbl@OL@list}}
%
\@namedef{bbl@
[email protected]@on}{%
\bbl@bcpallowedtrue}
\@namedef{bbl@
[email protected]@off}{%
\bbl@bcpallowedfalse}
\@namedef{bbl@
[email protected]}#1{%
\def\bbl@bcp@prefix{#1}}
\def\bbl@bcp@prefix{bcp47-}
\@namedef{bbl@
[email protected]}#1{%
\def\bbl@autoload@options{#1}}
\def\bbl@autoload@bcpoptions{import}
\@namedef{bbl@
[email protected]}#1{%
\def\bbl@autoload@bcpoptions{#1}}
\newif\ifbbl@bcptoname
%
\@namedef{bbl@
[email protected]@on}{%
\bbl@bcptonametrue}
\@namedef{bbl@
[email protected]@off}{%
\bbl@bcptonamefalse}
%
\@namedef{bbl@
[email protected]@nohyphenation}{%
\directlua{ Babel.ignore_pre_char = function(node)
return (node.lang == \the\csname l@nohyphenation\endcsname)
end }}
\@namedef{bbl@
[email protected]@off}{%
\directlua{ Babel.ignore_pre_char = function(node)
return false
end }}
%
\@namedef{bbl@
[email protected]@nohyphenation}{%
\def\bbl@ignoreinterchar{%
\ifnum\language=\l@nohyphenation
\expandafter\@gobble
\else
\expandafter\@firstofone
\fi}}
\@namedef{bbl@
[email protected]@off}{%
\let\bbl@ignoreinterchar\@firstofone}
%
\@namedef{bbl@
[email protected]@shift}{%
\let\bbl@restorelastskip\relax
\def\bbl@savelastskip{%
\let\bbl@restorelastskip\relax
\ifvmode
\ifdim\lastskip=\z@
\let\bbl@restorelastskip\nobreak
\else
\bbl@exp{%
\def\\\bbl@restorelastskip{%
\skip@=\the\lastskip
\\\nobreak \vskip-\skip@ \vskip\skip@}}%
\fi
\fi}}
\@namedef{bbl@
[email protected]@keep}{%
\let\bbl@restorelastskip\relax
\let\bbl@savelastskip\relax}
\@namedef{bbl@
[email protected]@omit}{%
\AddBabelHook{babel-select}{beforestart}{%
\expandafter\babel@aux\expandafter{\bbl@main@language}{}}%
\let\bbl@restorelastskip\relax
\def\bbl@savelastskip##1\bbl@restorelastskip{}}
\@namedef{bbl@
[email protected]@off}{%
\let\bbl@encoding@select@off\@empty}
% \end{macrocode}
%
% \subsection{Cross referencing macros}
%
% The \LaTeX\ book states:
% \begin{quote}
% The \emph{key} argument is any sequence of letters, digits, and
% punctuation symbols; upper- and lowercase letters are regarded as
% different.
% \end{quote}
% When the above quote should still be true when a document is
% typeset in a language that has active characters, special care
% has to be taken of the category codes of these characters when
% they appear in an argument of the cross referencing macros.
%
% When a cross referencing command processes its argument, all
% tokens in this argument should be character tokens with category
% `letter' or `other'.
%
% The following package options control which macros are to be
% redefined.
%
% \begin{macrocode}
%<<*More package options>>
\DeclareOption{safe=none}{\let\bbl@opt@safe\@empty}
\DeclareOption{safe=bib}{\def\bbl@opt@safe{B}}
\DeclareOption{safe=ref}{\def\bbl@opt@safe{R}}
\DeclareOption{safe=refbib}{\def\bbl@opt@safe{BR}}
\DeclareOption{safe=bibref}{\def\bbl@opt@safe{BR}}
%<</More package options>>
% \end{macrocode}
%
% \macro{\@newl@bel}
%
% First we open a new group to keep the changed setting of
% |\protect| local and then we set the |@safe@actives| switch to
% true to make sure that any shorthand that appears in any of the
% arguments immediately expands to its non-active self.
%
% \begin{macrocode}
\bbl@trace{Cross referencing macros}
\ifx\bbl@opt@safe\@empty\else % i.e., if 'ref' and/or 'bib'
\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}
%
% \macro{\@testdef}
%
% An internal \LaTeX\ macro used to test if the labels that have
% been written on the |aux| file have changed. It is called by
% the |\enddocument| macro.
%
% \begin{macrocode}
\CheckCommand*\@testdef[3]{%
\def\reserved@a{#3}%
\expandafter\ifx\csname#1@#2\endcsname\reserved@a
\else
\@tempswatrue
\fi}
% \end{macrocode}
%
% Now that we made sure that |\@testdef| still has the same definition
% we can rewrite it. First we make the shorthands `safe'. Then we use
% |\bbl@tempa| as an `alias' for the macro that contains the label
% which is being checked. Then we define |\bbl@tempb| just as
% |\@newl@bel| does it. When the label is defined we replace the
% definition of |\bbl@tempa| by its meaning. If the label didn't
% change, |\bbl@tempa| and |\bbl@tempb| should be identical macros.
%
% \begin{macrocode}
\def\@testdef#1#2#3{%
\@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}
%
% \macro{\ref}
% \macro{\pageref}
%
% The same holds for the macro |\ref| that references a label and
% |\pageref| to reference a page. We make them robust as well (if
% they weren't already) to prevent problems if they should become
% expanded at the wrong moment.
%
% \begin{macrocode}
\bbl@xin@{R}\bbl@opt@safe
\ifin@
\edef\bbl@tempc{\expandafter\string\csname ref code\endcsname}%
\bbl@xin@{\expandafter\strip@prefix\meaning\bbl@tempc}%
{\expandafter\strip@prefix\meaning\ref}%
\ifin@
\bbl@redefine\@kernel@ref#1{%
\@safe@activestrue\org@@kernel@ref{#1}\@safe@activesfalse}
\bbl@redefine\@kernel@pageref#1{%
\@safe@activestrue\org@@kernel@pageref{#1}\@safe@activesfalse}
\bbl@redefine\@kernel@sref#1{%
\@safe@activestrue\org@@kernel@sref{#1}\@safe@activesfalse}
\bbl@redefine\@kernel@spageref#1{%
\@safe@activestrue\org@@kernel@spageref{#1}\@safe@activesfalse}
\else
\bbl@redefinerobust\ref#1{%
\@safe@activestrue\org@ref{#1}\@safe@activesfalse}
\bbl@redefinerobust\pageref#1{%
\@safe@activestrue\org@pageref{#1}\@safe@activesfalse}
\fi
\else
\let\org@ref\ref
\let\org@pageref\pageref
\fi
% \end{macrocode}
%
% \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\bbl@tempa{#2}\@safe@activesfalse
\org@@citex[#1]{\bbl@tempa}}
% \end{macrocode}
%
% Unfortunately, the packages \pkg{natbib} and \pkg{cite} need a
% different definition of |\@citex|...
% To begin with, \pkg{natbib} has a definition for |\@citex| with
% \emph{three} arguments... We only know that a package is loaded
% when |\begin{document}| is executed, so we need to postpone the
% different redefinition.
%
% 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}
\AtBeginDocument{%
\@ifpackageloaded{natbib}{%
\def\@citex[#1][#2]#3{%
\@safe@activestrue\edef\bbl@tempa{#3}\@safe@activesfalse
\org@@citex[#1][#2]{\bbl@tempa}}%
}{}}
% \end{macrocode}
%
% The package \pkg{cite} has a definition of |\@citex| where the
% shorthands need to be turned off in both arguments.
%
% \begin{macrocode}
\AtBeginDocument{%
\@ifpackageloaded{cite}{%
\def\@citex[#1]#2{%
\@safe@activestrue\org@@citex[#1]{#2}\@safe@activesfalse}%
}{}}
% \end{macrocode}
%
% \macro{\nocite}
%
% The macro |\nocite| which is used to instruct BiB\TeX\ to
% extract uncited references from the database.
%
% \begin{macrocode}
\bbl@redefine\nocite#1{%
\@safe@activestrue\org@nocite{#1}\@safe@activesfalse}
% \end{macrocode}
%
% \macro{\bibcite}
%
% The macro that is used in the |aux| file to
% define citation labels. When packages such as \pkg{natbib} or
% \pkg{cite} are not loaded its second argument is used to typeset the
% citation label. In that case, this second argument can contain
% active characters but is used in an environment where
% |\@safe@activestrue| is in effect. This switch needs to be reset
% inside the |\hbox| which contains the citation label. In order to
% determine during \file{aux} file processing which definition of
% |\bibcite| is needed we define |\bibcite| in such a way that it
% redefines itself with the proper definition. We call
% |\bbl@cite@choice| to select the proper definition for |\bibcite|.
% This new definition is then activated.
%
% \begin{macrocode}
\bbl@redefine\bibcite{%
\bbl@cite@choice
\bibcite}
% \end{macrocode}
%
% \macro{\bbl@bibcite}
%
% The macro |\bbl@bibcite| holds the definition of |\bibcite|
% needed when neither \pkg{natbib} nor \pkg{cite} is loaded.
%
% \begin{macrocode}
\def\bbl@bibcite#1#2{%
\org@bibcite{#1}{\@safe@activesfalse#2}}
% \end{macrocode}
%
% \macro{\bbl@cite@choice}
%
% The macro |\bbl@cite@choice| determines which definition of
% |\bibcite| is needed. First we give |\bibcite| its default
% definition.
%
% \begin{macrocode}
\def\bbl@cite@choice{%
\global\let\bibcite\bbl@bibcite
\@ifpackageloaded{natbib}{\global\let\bibcite\org@bibcite}{}%
\@ifpackageloaded{cite}{\global\let\bibcite\org@bibcite}{}%
\global\let\bbl@cite@choice\relax}
% \end{macrocode}
%
% When a document is run for the first time, no \file{aux} file is
% available, and |\bibcite| will not yet be properly defined. In
% this case, this has to happen before the document starts.
%
% \begin{macrocode}
\AtBeginDocument{\bbl@cite@choice}
% \end{macrocode}
%
% \macro{\@bibitem}
%
% One of the two internal \LaTeX\ macros called by |\bibitem|
% that write the citation label on the |aux| file.
%
% \begin{macrocode}
\bbl@redefine\@bibitem#1{%
\@safe@activestrue\org@@bibitem{#1}\@safe@activesfalse}
\else
\let\org@nocite\nocite
\let\org@@citex\@citex
\let\org@bibcite\bibcite
\let\org@@bibitem\@bibitem
\fi
% \end{macrocode}
%
% \subsection{Layout}
%
% \begin{macrocode}
\newcommand\BabelPatchSection[1]{%
\@ifundefined{#1}{}{%
\bbl@exp{\let\<bbl@ss@#1>\<#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}
%
% \macro{\BabelFootnote}
%
% Footnotes.
%
% \begin{macrocode}
\bbl@trace{Footnotes}
\def\bbl@footnote#1#2#3{%
\@ifnextchar[%
{\bbl@footnote@o{#1}{#2}{#3}}%
{\bbl@footnote@x{#1}{#2}{#3}}}
\long\def\bbl@footnote@x#1#2#3#4{%
\bgroup
\select@language@x{\bbl@main@language}%
\bbl@fn@footnote{#2#1{\ignorespaces#4}#3}%
\egroup}
\long\def\bbl@footnote@o#1#2#3[#4]#5{%
\bgroup
\select@language@x{\bbl@main@language}%
\bbl@fn@footnote[#4]{#2#1{\ignorespaces#5}#3}%
\egroup}
\def\bbl@footnotetext#1#2#3{%
\@ifnextchar[%
{\bbl@footnotetext@o{#1}{#2}{#3}}%
{\bbl@footnotetext@x{#1}{#2}{#3}}}
\long\def\bbl@footnotetext@x#1#2#3#4{%
\bgroup
\select@language@x{\bbl@main@language}%
\bbl@fn@footnotetext{#2#1{\ignorespaces#4}#3}%
\egroup}
\long\def\bbl@footnotetext@o#1#2#3[#4]#5{%
\bgroup
\select@language@x{\bbl@main@language}%
\bbl@fn@footnotetext[#4]{#2#1{\ignorespaces#5}#3}%
\egroup}
\def\BabelFootnote#1#2#3#4{%
\ifx\bbl@fn@footnote\@undefined
\let\bbl@fn@footnote\footnote
\fi
\ifx\bbl@fn@footnotetext\@undefined
\let\bbl@fn@footnotetext\footnotetext
\fi
\bbl@ifblank{#2}%
{\def#1{\bbl@footnote{\@firstofone}{#3}{#4}}
\@namedef{\bbl@stripslash#1text}%
{\bbl@footnotetext{\@firstofone}{#3}{#4}}}%
{\def#1{\bbl@exp{\\\bbl@footnote{\\\foreignlanguage{#2}}}{#3}{#4}}%
\@namedef{\bbl@stripslash#1text}%
{\bbl@exp{\\\bbl@footnotetext{\\\foreignlanguage{#2}}}{#3}{#4}}}}
\IfBabelLayout{footnotes}%
{\let\bbl@OL@footnote\footnote
\BabelFootnote\footnote\languagename{}{}%
\BabelFootnote\localfootnote\languagename{}{}%
\BabelFootnote\mainfootnote{}{}{}}
{}
% \end{macrocode}
%
% \subsection{Marks}
%
% \macro{\markright}
% Because the output routine is asynchronous, we must pass the
% current language attribute to the head lines. To achieve this we
% need to adapt the definition of |\markright| and |\markboth|
% somewhat. However, headlines and footlines can contain text
% outside marks; for that we must take some actions in the output
% routine if the 'headfoot' options is used.
%
% We need to make some redefinitions to the output routine
% to avoid an endless loop and to correctly handle the page number
% in bidi documents.
%
% \begin{macrocode}
\bbl@trace{Marks}
\IfBabelLayout{sectioning}
{\ifx\bbl@opt@headfoot\@nnil
\g@addto@macro\@resetactivechars{%
\set@typeset@protect
\expandafter\select@language@x\expandafter{\bbl@main@language}%
\let\protect\noexpand
\ifcase\bbl@bidimode\else % Only with bidi. See also above
\edef\thepage{%
\noexpand\babelsublr{\unexpanded\expandafter{\thepage}}}%
\fi}%
\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}
%
% \macro{\markboth}
% \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 need to do that again with the new definition of
% |\markboth|. (As of Oct 2019, \LaTeX{} stores the definition in an
% intermediate macro, so it's not necessary anymore, but it's preserved
% for older versions.)
%
% \begin{macrocode}
\ifx\@mkboth\markboth
\def\bbl@tempc{\let\@mkboth\markboth}%
\else
\def\bbl@tempc{}%
\fi
\bbl@ifunset{markboth }\bbl@redefine\bbl@redefinerobust
\markboth#1#2{%
\protected@edef\bbl@tempb##1{%
\protect\foreignlanguage
{\languagename}{\protect\bbl@restore@actives##1}}%
\bbl@ifblank{#1}%
{\toks@{}}%
{\toks@\expandafter{\bbl@tempb{#1}}}%
\bbl@ifblank{#2}%
{\@temptokena{}}%
{\@temptokena\expandafter{\bbl@tempb{#2}}}%
\bbl@exp{\\\org@markboth{\the\toks@}{\the\@temptokena}}}%
\bbl@tempc
\fi} % end ifbbl@single, end \IfBabelLayout
% \end{macrocode}
%
% \subsection{Other packages}
%
% \subsubsection{\pkg{ifthen}}
%
% \macro{\ifthenelse}
%
% Sometimes a document writer wants to create a special effect
% depending on the page a certain fragment of text appears on. This
% can be achieved by the following piece of code:
%\begin{verbatim}
% \ifthenelse{\isodd{\pageref{some-label}}}
% {code for odd pages}
% {code for even pages}
%\end{verbatim}
% In order for this to work the argument of |\isodd| needs to be
% fully expandable. With the above redefinition of |\pageref| it is
% not in the case of this example. To overcome that, we add some
% code to the definition of |\ifthenelse| to make things work.
%
% We want to revert the definition of |\pageref| and |\ref| to
% their original definition for the first argument of |\ifthenelse|,
% so we first need to store their current meanings.
%
% Then we can set the |\@safe@actives| switch and call the original
% |\ifthenelse|. In order to be able to use shorthands in the
% second and third arguments of |\ifthenelse| the resetting of the
% switch \emph{and} the definition of |\pageref| happens inside
% those arguments.
%
% \begin{macrocode}
\bbl@trace{Preventing clashes with other packages}
\ifx\org@ref\@undefined\else
\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}%
}%
}{}%
}
\fi
% \end{macrocode}
%
% \subsubsection{\pkg{varioref}}
%
% \macro{\@@vpageref}
% \macro{\vrefpagenum}
% \macro{\Ref}
%
% When the package \pkg{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
% which uppercases the first character of the reference text. In
% order to be able to do that it needs to access the expandable form
% of |\ref|. So we employ a little trick here. We redefine the
% (internal) command \verb*|\Ref | to call |\org@ref| instead of
% |\ref|. The disadvantage of this solution is that whenever the
% definition of |\Ref| changes, this definition needs to be updated
% as well.
%
% \begin{macrocode}
\expandafter\def\csname Ref \endcsname#1{%
\protected@edef\@tempa{\org@ref{#1}}\expandafter\MakeUppercase\@tempa}
}{}%
}
\fi
% \end{macrocode}
%
% \subsubsection{\pkg{hhline}}
%
% \macro{\hhline}
%
% Delaying the activation of the shorthand characters has introduced
% a problem with the \pkg{hhline} package. The reason is that it
% uses the `:' character which is made active by the french support
% in \babel. Therefore we need to \emph{reload} the package when
% the `:' is an active character. Note that this happens
% \emph{after} the category code of the @-sign has been changed to
% other, so we need to temporarily change it to letter again.
%
% \begin{macrocode}
\AtEndOfPackage{%
\AtBeginDocument{%
\@ifpackageloaded{hhline}%
{\expandafter\ifx\csname normal@char\string:\endcsname\relax
\else
\makeatletter
\def\@currname{hhline}\input{hhline.sty}\makeatother
\fi}%
{}}}
% \end{macrocode}
%
% \macro{\substitutefontfamily}
%
% \textit{Deprecated.} It creates an \file{fd} file on the fly. The
% first argument is an encoding mnemonic, the second and third
% arguments are font family names. Use the tools provided by \LaTeX\
% (|\DeclareFontFamilySubstitution|).
%
% \begin{macrocode}
\def\substitutefontfamily#1#2#3{%
\lowercase{\immediate\openout15=#1#2.fd\relax}%
\immediate\write15{%
\string\ProvidesFile{#1#2.fd}%
[\the\year/\two@digits{\the\month}/\two@digits{\the\day}
\space generated font description file]^^J
\string\DeclareFontFamily{#1}{#2}{}^^J
\string\DeclareFontShape{#1}{#2}{m}{n}{<->ssub * #3/m/n}{}^^J
\string\DeclareFontShape{#1}{#2}{m}{it}{<->ssub * #3/m/it}{}^^J
\string\DeclareFontShape{#1}{#2}{m}{sl}{<->ssub * #3/m/sl}{}^^J
\string\DeclareFontShape{#1}{#2}{m}{sc}{<->ssub * #3/m/sc}{}^^J
\string\DeclareFontShape{#1}{#2}{b}{n}{<->ssub * #3/bx/n}{}^^J
\string\DeclareFontShape{#1}{#2}{b}{it}{<->ssub * #3/bx/it}{}^^J
\string\DeclareFontShape{#1}{#2}{b}{sl}{<->ssub * #3/bx/sl}{}^^J
\string\DeclareFontShape{#1}{#2}{b}{sc}{<->ssub * #3/bx/sc}{}^^J
}%
\closeout15
}
\@onlypreamble\substitutefontfamily
% \end{macrocode}
%
% \subsection{Encoding and fonts}
%
% Because documents may use non-ASCII font encodings, we make sure
% that the logos of \TeX\ and \LaTeX\ always come out in the right
% encoding. There is a list of non-ASCII encodings. Requested
% encodings are currently stored in |\@fontenc@load@list|. 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|.
%
% \macro{\ensureascii}
%
% \begin{macrocode}
\bbl@trace{Encoding and fonts}
\newcommand\BabelNonASCII{LGR,LGI,X2,OT2,OT3,OT6,LHE,LWN,LMA,LMC,LMS,LMU}
\newcommand\BabelNonText{TS1,T3,TS3}
\let\org@TeX\TeX
\let\org@LaTeX\LaTeX
\let\ensureascii\@firstofone
\let\asciiencoding\@empty
\AtBeginDocument{%
\def\@elt#1{,#1,}%
\edef\bbl@tempa{\expandafter\@gobbletwo\@fontenc@load@list}%
\let\@elt\relax
\let\bbl@tempb\@empty
\def\bbl@tempc{OT1}%
\bbl@foreach\BabelNonASCII{% LGR loaded in a non-standard way
\bbl@ifunset{T@#1}{}{\def\bbl@tempb{#1}}}%
\bbl@foreach\bbl@tempa{%
\bbl@xin@{,#1,}{,\BabelNonASCII,}%
\ifin@
\def\bbl@tempb{#1}% Store last non-ascii
\else\bbl@xin@{,#1,}{,\BabelNonText,}% Pass
\ifin@\else
\def\bbl@tempc{#1}% Store last ascii
\fi
\fi}%
\ifx\bbl@tempb\@empty\else
\bbl@xin@{,\cf@encoding,}{,\BabelNonASCII,\BabelNonText,}%
\ifin@\else
\edef\bbl@tempc{\cf@encoding}% The default if ascii wins
\fi
\let\asciiencoding\bbl@tempc
\renewcommand\ensureascii[1]{%
{\fontencoding{\asciiencoding}\selectfont#1}}%
\DeclareTextCommandDefault{\TeX}{\ensureascii{\org@TeX}}%
\DeclareTextCommandDefault{\LaTeX}{\ensureascii{\org@LaTeX}}%
\fi}
% \end{macrocode}
%
% 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.
%
% \macro{\latinencoding}
% When text is being typeset in an encoding other than `latin'
% (\texttt{OT1} or \texttt{T1}), it would be nice to still have Roman
% numerals come out in the Latin encoding. So we first assume that the
% current encoding at the end of processing the package is the Latin
% encoding.
%
% \begin{macrocode}
\AtEndOfPackage{\edef\latinencoding{\cf@encoding}}
% \end{macrocode}
%
% But this might be overruled with a later loading of the package
% \pkg{fontenc}. Therefore we check at the execution of
% |\begin{document}| whether it was loaded with the \Lopt{T1} option.
% The normal way to do this (using |\@ifpackageloaded|) is disabled for
% this package. Now we have to revert to parsing the internal macro
% |\@filelist| which contains all the filenames loaded.
%
% \begin{macrocode}
\AtBeginDocument{%
\@ifpackageloaded{fontspec}%
{\xdef\latinencoding{%
\ifx\UTFencname\@undefined
EU\ifcase\bbl@engine\or2\or1\fi
\else
\UTFencname
\fi}}%
{\gdef\latinencoding{OT1}%
\ifx\cf@encoding\bbl@t@one
\xdef\latinencoding{\bbl@t@one}%
\else
\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}}
% \end{macrocode}
%
% \macro{\latintext}
% Then we can define the command |\latintext| which is a declarative
% switch to a latin font-encoding. Usage of this macro is deprecated.
%
% \begin{macrocode}
\DeclareRobustCommand{\latintext}{%
\fontencoding{\latinencoding}\selectfont
\def\encodingdefault{\latinencoding}}
% \end{macrocode}
%
% \macro{\textlatin}
% This command takes an argument which is then typeset using the
% requested font encoding. In order to avoid many encoding switches it
% operates in a local scope.
%
% \begin{macrocode}
\ifx\@undefined\DeclareTextFontCommand
\DeclareRobustCommand{\textlatin}[1]{\leavevmode{\latintext #1}}
\else
\DeclareTextFontCommand{\textlatin}{\latintext}
\fi
% \end{macrocode}
%
% For several functions, we need to execute some code with
% |\selectfont|. With \LaTeX\ 2021-06-01, there is a hook for this
% purpose.
%
% \begin{macrocode}
\def\bbl@patchfont#1{\AddToHook{selectfont}{#1}}
% \end{macrocode}
%
% \subsection{Basic bidi support}
%
% This code is currently placed here for
% practical reasons. It will be moved to the correct place soon, I
% hope.
%
% It is loosely based on |rlbabel.def|, but most of it has been
% developed from scratch. This \babel{} module (by Johannes Braams and
% Boris Lavva) has served the purpose of typesetting R documents for
% two decades, and despite its flaws I think it is still a good starting
% point (some parts have been copied here almost verbatim), partly
% thanks to its simplicity. I've also looked at \textsc{arabi} (by
% Youssef Jabri), which is compatible with \babel{}.
%
% There are two ways of modifying macros to make them “bidi”, namely,
% by patching the internal low-level macros (which is what I have done
% with lists, columns, counters, tocs, much like |rlbabel| did), and
% by introducing a “middle layer” just below the user interface
% (sectioning, footnotes).
%
% \begin{itemize}
% \item pdftex provides a minimal support for bidi text, and it
% must be done by hand. Vertical typesetting is not possible.
% \item \xetex{} is somewhat better, thanks to its font engine
% (even if not always reliable) and a few additional tools. However,
% very little is done at the paragraph level. Another challenging
% problem is text direction does not honour \TeX{} grouping.
% \item \luatex{} can provide the most complete solution, as we can
% manipulate almost freely the node list, the generated lines,
% and so on, but bidi text does not work out of the box and some
% development is necessary. It also provides tools to properly
% set left-to-right and right-to-left page layouts. As Lua\TeX-ja
% shows, vertical typesetting is possible, too.
% \end{itemize}
%
% \begin{macrocode}
\bbl@trace{Loading basic (internal) bidi support}
\ifodd\bbl@engine
\else % Any xe+lua bidi
\ifnum\bbl@bidimode>100 \ifnum\bbl@bidimode<200
\bbl@error{bidi-only-lua}{}{}{}%
\let\bbl@beforeforeign\leavevmode
\AtEndOfPackage{%
\EnableBabelHook{babel-bidi}%
\bbl@xebidipar}
\fi\fi
\def\bbl@loadxebidi#1{%
\ifx\RTLfootnotetext\@undefined
\AtEndOfPackage{%
\EnableBabelHook{babel-bidi}%
\ifx\fontspec\@undefined
\usepackage{fontspec}% bidi needs fontspec
\fi
\usepackage#1{bidi}%
\let\bbl@digitsdotdash\DigitsDotDashInterCharToks
\def\DigitsDotDashInterCharToks{% See the 'bidi' package
\ifnum\@nameuse{bbl@wdir@\languagename}=\tw@ % 'AL' bidi
\bbl@digitsdotdash % So ignore in 'R' bidi
\fi}}%
\fi}
\ifnum\bbl@bidimode>200 % Any xe bidi=
\ifcase\expandafter\@gobbletwo\the\bbl@bidimode\or
\bbl@tentative{bidi=bidi}
\bbl@loadxebidi{}
\or
\bbl@loadxebidi{[rldocument]}
\or
\bbl@loadxebidi{}
\fi
\fi
\fi
\ifnum\bbl@bidimode=\@ne % bidi=default
\let\bbl@beforeforeign\leavevmode
\ifodd\bbl@engine % lua
\newattribute\bbl@attr@dir
\directlua{ Babel.attr_dir = luatexbase.registernumber'bbl@attr@dir' }
\bbl@exp{\output{\bodydir\pagedir\the\output}}
\fi
\AtEndOfPackage{%
\EnableBabelHook{babel-bidi}% pdf/lua/xe
\ifodd\bbl@engine\else % pdf/xe
\bbl@xebidipar
\fi}
\fi
% \end{macrocode}
%
% Now come the macros used to set the direction when a language is
% switched. Testing are based on script names, because it’s the user
% interface (including |language| and |script| in |\babelprovide|.
% First the (mostly) common macros.
%
% \begin{macrocode}
\bbl@trace{Macros to switch the text direction}
\def\bbl@alscripts{%
,Arabic,Syriac,Thaana,Hanifi Rohingya,Hanifi,Sogdian,}
\def\bbl@rscripts{%
Adlam,Avestan,Chorasmian,Cypriot,Elymaic,Garay,%
Hatran,Hebrew,Imperial Aramaic,Inscriptional Pahlavi,%
Inscriptional Parthian,Kharoshthi,Lydian,Mandaic,Manichaean,%
Mende Kikakui,Meroitic Cursive,Meroitic Hieroglyphs,Nabataean,%
Nko,Old Hungarian,Old North Arabian,Old Sogdian,%
Old South Arabian,Old Turkic,Old Uyghur,Palmyrene,Phoenician,%
Psalter Pahlavi,Samaritan,Yezidi,Mandaean,%
Meroitic,N'Ko,Orkhon,Todhri}
%
\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@
\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{%
\ifcase\bbl@select@type
\bbl@bodydir{#1}%
\bbl@pardir{#1}% <- Must precede \bbl@textdir
\fi
\bbl@textdir{#1}}
\ifnum\bbl@bidimode>\z@
\AddBabelHook{babel-bidi}{afterextras}{\bbl@switchdir}
\DisableBabelHook{babel-bidi}
\fi
% \end{macrocode}
%
% Now the engine-dependent macros.
%
% \begin{macrocode}
\ifodd\bbl@engine % luatex=1
\else % pdftex=0, xetex=2
\newcount\bbl@dirlevel
\chardef\bbl@thetextdir\z@
\chardef\bbl@thepardir\z@
\def\bbl@textdir#1{%
\ifcase#1\relax
\chardef\bbl@thetextdir\z@
\@nameuse{setlatin}%
\bbl@textdir@i\beginL\endL
\else
\chardef\bbl@thetextdir\@ne
\@nameuse{setnonlatin}%
\bbl@textdir@i\beginR\endR
\fi}
\def\bbl@textdir@i#1#2{%
\ifhmode
\ifnum\currentgrouplevel>\z@
\ifnum\currentgrouplevel=\bbl@dirlevel
\bbl@error{multiple-bidi}{}{}{}%
\bgroup\aftergroup#2\aftergroup\egroup
\else
\ifcase\currentgrouptype\or % 0 bottom
\aftergroup#2% 1 simple {}
\or
\bgroup\aftergroup#2\aftergroup\egroup % 2 hbox
\or
\bgroup\aftergroup#2\aftergroup\egroup % 3 adj hbox
\or\or\or % vbox vtop align
\or
\bgroup\aftergroup#2\aftergroup\egroup % 7 noalign
\or\or\or\or\or\or % output math disc insert vcent mathchoice
\or
\aftergroup#2% 14 \begingroup
\else
\bgroup\aftergroup#2\aftergroup\egroup % 15 adj
\fi
\fi
\bbl@dirlevel\currentgrouplevel
\fi
#1%
\fi}
\def\bbl@pardir#1{\chardef\bbl@thepardir#1\relax}
\let\bbl@bodydir\@gobble
\let\bbl@pagedir\@gobble
\def\bbl@dirparastext{\chardef\bbl@thepardir\bbl@thetextdir}
% \end{macrocode}
%
% The following command is executed only if there is a right-to-left
% script (once). It activates the |\everypar| hack for \xetex, to
% properly handle the par direction. Note text and par dirs are
% decoupled to some extent (although not completely).
%
% \begin{macrocode}
\def\bbl@xebidipar{%
\let\bbl@xebidipar\relax
\TeXXeTstate\@ne
\def\bbl@xeeverypar{%
\ifcase\bbl@thepardir
\ifcase\bbl@thetextdir\else\beginR\fi
\else
{\setbox\z@\lastbox\beginR\box\z@}%
\fi}%
\AddToHook{para/begin}{\bbl@xeeverypar}}
\ifnum\bbl@bidimode>200 % Any xe bidi=
\let\bbl@textdir@i\@gobbletwo
\let\bbl@xebidipar\@empty
\AddBabelHook{bidi}{foreign}{%
\ifcase\bbl@thetextdir
\BabelWrapText{\LR{##1}}%
\else
\BabelWrapText{\RL{##1}}%
\fi}
\def\bbl@pardir#1{\ifcase#1\relax\setLR\else\setRL\fi}
\fi
\fi
% \end{macrocode}
%
% A tool for weak L (mainly digits). We also disable warnings with
% \textsf{hyperref}.
%
% \begin{macrocode}
\DeclareRobustCommand\babelsublr[1]{\leavevmode{\bbl@textdir\z@#1}}
\AtBeginDocument{%
\ifx\pdfstringdefDisableCommands\@undefined\else
\ifx\pdfstringdefDisableCommands\relax\else
\pdfstringdefDisableCommands{\let\babelsublr\@firstofone}%
\fi
\fi}
% \end{macrocode}
%
% \subsection{Local Language Configuration}
%
% \macro{\loadlocalcfg}
%
% At some sites it may be necessary to add site-specific actions to
% a language definition file. This can be done by creating a file
% with the same name as the language definition file, but with the
% extension \file{.cfg}. For instance the file \file{norsk.cfg}
% will be loaded when the language definition file \file{norsk.ldf}
% is loaded.
%
% For plain-based formats we don't want to override the definition
% of |\loadlocalcfg| from \file{plain.def}.
%
% \begin{macrocode}
\bbl@trace{Local Language Configuration}
\ifx\loadlocalcfg\@undefined
\@ifpackagewith{babel}{noconfigs}%
{\let\loadlocalcfg\@gobble}%
{\def\loadlocalcfg#1{%
\InputIfFileExists{#1.cfg}%
{\typeout{*************************************^^J%
* Local config file #1.cfg used^^J%
*}}%
\@empty}}
\fi
% \end{macrocode}
%
% \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 caught).
%
% \begin{macrocode}
\bbl@trace{Language options}
\def\BabelDefinitionFile#1#2#3{}
\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@exp{\\\AtBeginDocument{%
\\\bbl@usehooks@lang{\CurrentOption}{begindocument}{{\CurrentOption}}}}}%
{\IfFileExists{babel-#1.tex}%
{\def\bbl@tempa{%
.\\There is a locale ini file for this language.\\%
If it’s the main language, try adding `provide=*'\\%
to the babel package options}}%
{\let\bbl@tempa\empty}%
\bbl@error{unknown-package-option}{}{}{}}}
% \end{macrocode}
%
% Now, we set a few language options whose names are different from
% |ldf| files. These declarations are preserved for backwards
% compatibility, but they must be eventually removed. Use proxy files
% instead.
%
% \begin{macrocode}
\def\bbl@try@load@lang#1#2#3{%
\IfFileExists{\CurrentOption.ldf}%
{\bbl@load@language{\CurrentOption}}%
{#1\bbl@load@language{#2}#3}}
%
\DeclareOption{friulian}{\bbl@try@load@lang{}{friulan}{}}
\DeclareOption{hebrew}{%
\ifcase\bbl@engine\or
\bbl@error{only-pdftex-lang}{hebrew}{luatex}{}%
\fi
\input{rlbabel.def}%
\bbl@load@language{hebrew}}
\DeclareOption{hungarian}{\bbl@try@load@lang{}{magyar}{}}
\DeclareOption{lowersorbian}{\bbl@try@load@lang{}{lsorbian}{}}
% \DeclareOption{northernkurdish}{\bbl@try@load@lang{}{kurmanji}{}}
\DeclareOption{polutonikogreek}{%
\bbl@try@load@lang{}{greek}{\languageattribute{greek}{polutoniko}}}
\DeclareOption{russian}{\bbl@try@load@lang{}{russianb}{}}
\DeclareOption{ukrainian}{\bbl@try@load@lang{}{ukraineb}{}}
\DeclareOption{uppersorbian}{\bbl@try@load@lang{}{usorbian}{}}
% \end{macrocode}
%
% 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=<name>|, which will
% load |<name>.cfg| instead.
%
% If the language as been set as metadata, read the info from the
% corresponding \texttt{ini} file and extract the \babel\ name. Then
% added it as a package option at the end, so that it becomes the main
% language. The behavior of a metatag with a global language option is
% not well defined, so if there is not a |main| option we set here
% explicitly.
%
% Tagging PDF Span elements requires horizontal mode. With
% |DocumentMetada| we also force it with |\foreignlanguage| (this is
% also done in bidi texts).
%
% \begin{macrocode}
\ifx\GetDocumentProperties\@undefined\else
\let\bbl@beforeforeign\leavevmode
\edef\bbl@metalang{\GetDocumentProperties{document/lang}}%
\ifx\bbl@metalang\@empty\else
\begingroup
\expandafter
\bbl@bcplookup\bbl@metalang-\@empty-\@empty-\@empty\@@
\ifx\bbl@bcp\relax
\ifx\bbl@opt@main\@nnil
\bbl@error{no-locale-for-meta}{\bbl@metalang}{}{}%
\fi
\else
\bbl@read@ini{\bbl@bcp}\m@ne
\xdef\bbl@language@opts{\bbl@language@opts,\languagename}%
\ifx\bbl@opt@main\@nnil
\global\let\bbl@opt@main\languagename
\fi
\bbl@info{Passing \languagename\space to babel}%
\fi
\endgroup
\fi
\fi
\ifx\bbl@opt@config\@nnil
\@ifpackagewith{babel}{noconfigs}{}%
{\InputIfFileExists{bblopts.cfg}%
{\typeout{*************************************^^J%
* Local config file bblopts.cfg used^^J%
*}}%
{}}%
\else
\InputIfFileExists{\bbl@
[email protected]}%
{\typeout{*************************************^^J%
* Local config file \bbl@
[email protected] used^^J%
*}}%
{\bbl@error{config-not-found}{}{}{}}%
\fi
% \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. If not declared
% above, the names of the option and the file are the same. We first
% pre-process the class and package options to determine the main
% language, which is processed in the third ‘main’ pass,
% \textit{except} if all files are \texttt{ldf} \textit{and} there is
% no |main| key. In the latter case (|\bbl@opt@main| is still
% |\@nnil|), the traditional way to set the main language is kept — the
% last loaded is the main language.
%
% For efficiency, first preprocess the class options to remove those
% with |=|, which are becoming increasingly frequent (no language
% should contain this character).
%
% \begin{macrocode}
\def\bbl@tempf{,}
\bbl@foreach\@raw@classoptionslist{%
\in@{=}{#1}%
\ifin@\else
\edef\bbl@tempf{\bbl@tempf\zap@space#1 \@empty,}%
\fi}
\ifx\bbl@opt@main\@nnil
\ifnum\bbl@iniflag>\z@ % if all ldf's: set implicitly, no main pass
\let\bbl@tempb\@empty
\edef\bbl@tempa{\bbl@tempf,\bbl@language@opts}%
\bbl@foreach\bbl@tempa{\edef\bbl@tempb{#1,\bbl@tempb}}%
\bbl@foreach\bbl@tempb{% \bbl@tempb is a reversed list
\ifx\bbl@opt@main\@nnil % i.e., if not yet assigned
\ifodd\bbl@iniflag % = *=
\IfFileExists{babel-#1.tex}{\def\bbl@opt@main{#1}}{}%
\else % n +=
\IfFileExists{#1.ldf}{\def\bbl@opt@main{#1}}{}%
\fi
\fi}%
\fi
\else
\ifx\bbl@metalang\@undefined\else\ifx\bbl@metalang\@empty\else
\bbl@afterfi\expandafter\@gobble
\fi\fi % except if explicit lang metatag:
{\bbl@info{Main language set with 'main='. Except if you have\\%
problems, prefer the default mechanism for setting\\%
the main language, i.e., as the last declared.\\%
Reported}}
\fi
% \end{macrocode}
%
% A few languages are still defined explicitly. They are stored in case
% they are needed in the ‘main’ pass (the value can be |\relax|).
%
% \begin{macrocode}
\ifx\bbl@opt@main\@nnil\else
\bbl@ncarg\let\bbl@loadmain{ds@\bbl@opt@main}%
\expandafter\let\csname ds@\bbl@opt@main\endcsname\relax
\fi
% \end{macrocode}
%
% Now define the corresponding loaders. With package options, assume
% the language exists. With class options, check if the option is a
% language by checking if the corresponding file exists.
%
% \begin{macrocode}
\bbl@foreach\bbl@language@opts{%
\def\bbl@tempa{#1}%
\ifx\bbl@tempa\bbl@opt@main\else
\ifnum\bbl@iniflag<\tw@ % 0 ø (other = ldf)
\bbl@ifunset{ds@#1}%
{\DeclareOption{#1}{\bbl@load@language{#1}}}%
{}%
\else % + * (other = ini)
\DeclareOption{#1}{%
\bbl@ldfinit
\babelprovide[@import]{#1}% %%%%%
\bbl@afterldf}%
\fi
\fi}
\bbl@foreach\bbl@tempf{%
\def\bbl@tempa{#1}%
\ifx\bbl@tempa\bbl@opt@main\else
\ifnum\bbl@iniflag<\tw@ % 0 ø (other = ldf)
\bbl@ifunset{ds@#1}%
{\IfFileExists{#1.ldf}%
{\DeclareOption{#1}{\bbl@load@language{#1}}}%
{}}%
{}%
\else % + * (other = ini)
\IfFileExists{babel-#1.tex}%
{\DeclareOption{#1}{%
\bbl@ldfinit
\babelprovide[@import]{#1}% %%%%%%
\bbl@afterldf}}%
{}%
\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. There is
% still room for last minute changes with a \LaTeX{} hook (not a
% \Babel{} one).
%
% The options have to be processed in the order in which the user
% specified them (but remember class options are processes before):
%
% \begin{macrocode}
\NewHook{babel/presets}
\UseHook{babel/presets}
\def\AfterBabelLanguage#1{%
\bbl@ifsamestring\CurrentOption{#1}{\global\bbl@add\bbl@afterlang}{}}
\DeclareOption*{}
\ProcessOptions*
% \end{macrocode}
%
% 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. With some options in |provide|,
% the package |luatexbase| is loaded (and immediately used), and
% therefore |\babelprovide| can’t go inside a |\DeclareOption|; this
% explains why it’s executed directly, with a dummy declaration. Then
% all languages have been loaded, so we deactivate
% |\AfterBabelLanguage|.
%
% \begin{macrocode}
\bbl@trace{Option 'main'}
\ifx\bbl@opt@main\@nnil
\edef\bbl@tempa{\bbl@tempf,\bbl@language@opts}
\let\bbl@tempc\@empty
\edef\bbl@templ{,\bbl@loaded,}
\edef\bbl@templ{\expandafter\strip@prefix\meaning\bbl@templ}
\bbl@for\bbl@tempb\bbl@tempa{%
\edef\bbl@tempd{,\bbl@tempb,}%
\edef\bbl@tempd{\expandafter\strip@prefix\meaning\bbl@tempd}%
\bbl@xin@{\bbl@tempd}{\bbl@templ}%
\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 can't be set as both a global\\%
and a package option. Use 'main=\bbl@tempc' as\\%
option. Reported}
\fi
\else
\ifodd\bbl@iniflag % case 1,3 (main is ini)
\bbl@ldfinit
\let\CurrentOption\bbl@opt@main
\bbl@exp{% \bbl@opt@provide = empty if *
\\\babelprovide
[\bbl@opt@provide,@import,main]% %%%%%
{\bbl@opt@main}}%
\bbl@afterldf
\DeclareOption{\bbl@opt@main}{}
\else % case 0,2 (main is ldf)
\ifx\bbl@loadmain\relax
\DeclareOption{\bbl@opt@main}{\bbl@load@language{\bbl@opt@main}}
\else
\DeclareOption{\bbl@opt@main}{\bbl@loadmain}
\fi
\ExecuteOptions{\bbl@opt@main}
\@namedef{ds@\bbl@opt@main}{}%
\fi
\DeclareOption*{}
\ProcessOptions*
\fi
\bbl@exp{%
\\\AtBeginDocument{\\\bbl@usehooks@lang{/}{begindocument}{{}}}}%
\def\AfterBabelLanguage{\bbl@error{late-after-babel}{}{}{}}
% \end{macrocode}
%
% In order to catch the case where the user didn’t specify a
% language we check whether |\bbl@main@language|, has become
% defined. If not, the |nil| language is loaded.
%
% \begin{macrocode}
\ifx\bbl@main@language\@undefined
\bbl@info{%
You haven't specified a language as a class or package\\%
option. I'll load 'nil'. Reported}
\bbl@load@language{nil}
\fi
%</package>
% \end{macrocode}
%
% \section{The kernel of Babel}
%
% The kernel of the \babel\ system is currently stored in
% \file{babel.def}. The file \file{babel.def} contains most of the
% code. The file \file{hyphen.cfg} is a file that can be loaded into
% the format, which is necessary when you want to be able to switch
% hyphenation patterns.
%
% Because plain \TeX\ users might want to use some of the features of
% the \babel{} system too, care has to be taken that plain \TeX\ can
% 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.
%
% A proxy file for switch.def
%
% \begin{macrocode}
%<*kernel>
\let\bbl@onlyswitch\@empty
\input babel.def
\let\bbl@onlyswitch\@undefined
%</kernel>
% \end{macrocode}
%
% \section{Error messages}
%
% They are loaded when |\bll@error| is first called. To save space, the
% main code just identifies them with a tag, and messages are stored in
% a separate file. Since it can be loaded anywhere, you make sure some
% catcodes have the right value, although those for |\|, |`|, |^^M|,
% |%| and |=| are reset before loading the file.
%
% \begin{macrocode}
%<*errors>
\catcode`\{=1 \catcode`\}=2 \catcode`\#=6
\catcode`\:=12 \catcode`\,=12 \catcode`\.=12 \catcode`\-=12
\catcode`\'=12 \catcode`\(=12 \catcode`\)=12
\catcode`\@=11 \catcode`\^=7
%
\ifx\MessageBreak\@undefined
\gdef\bbl@error@i#1#2{%
\begingroup
\newlinechar=`\^^J
\def\\{^^J(babel) }%
\errhelp{#2}\errmessage{\\#1}%
\endgroup}
\else
\gdef\bbl@error@i#1#2{%
\begingroup
\def\\{\MessageBreak}%
\PackageError{babel}{#1}{#2}%
\endgroup}
\fi
\def\bbl@errmessage#1#2#3{%
\expandafter\gdef\csname bbl@err@#1\endcsname##1##2##3{%
\bbl@error@i{#2}{#3}}}
% Implicit #2#3#4:
\gdef\bbl@error#1{\csname bbl@err@#1\endcsname}
%
\bbl@errmessage{not-yet-available}
{Not yet available}%
{Find an armchair, sit down and wait}
\bbl@errmessage{bad-package-option}%
{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.}
\bbl@errmessage{base-on-the-fly}
{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.}
\bbl@errmessage{undefined-language}
{You haven't defined the language '#1' yet.\\%
Perhaps you misspelled it or your installation\\%
is not complete}%
{Your command will be ignored, type <return> to proceed}
\bbl@errmessage{shorthand-is-off}
{I can't declare a shorthand turned off (\string#2)}
{Sorry, but you can't use shorthands which have been\\%
turned off in the package options}
\bbl@errmessage{not-a-shorthand}
{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}
\bbl@errmessage{not-a-shorthand-b}
{I can't 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.}
\bbl@errmessage{unknown-attribute}
{The attribute #2 is unknown for language #1.}%
{Your command will be ignored, type <return> to proceed}
\bbl@errmessage{missing-group}
{Missing group for string \string#1}%
{You must assign strings to some category, typically\\%
captions or extras, but you set none}
\bbl@errmessage{only-lua-xe}
{This macro is available only in LuaLaTeX and XeLaTeX.}%
{Consider switching to these engines.}
\bbl@errmessage{only-lua}
{This macro is available only in LuaLaTeX}%
{Consider switching to that engine.}
\bbl@errmessage{unknown-provide-key}
{Unknown key '#1' in \string\babelprovide}%
{See the manual for valid keys}%
\bbl@errmessage{unknown-mapfont}
{Option '\bbl@KVP@mapfont' unknown for\\%
mapfont. Use 'direction'}%
{See the manual for details.}
\bbl@errmessage{no-ini-file}
{There is no ini file for the requested language\\%
(#1: \languagename). Perhaps you misspelled it or your\\%
installation is not complete}%
{Fix the name or reinstall babel.}
\bbl@errmessage{digits-is-reserved}
{The counter name 'digits' is reserved for mapping\\%
decimal digits}%
{Use another name.}
\bbl@errmessage{limit-two-digits}
{Currently two-digit years are restricted to the\\
range 0-9999}%
{There is little you can do. Sorry.}
\bbl@errmessage{alphabetic-too-large}
{Alphabetic numeral too large (#1)}%
{Currently this is the limit.}
\bbl@errmessage{no-ini-info}
{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@errmessage{unknown-ini-field}
{Unknown field '#1' in \string\BCPdata.\\%
Perhaps you misspelled it}%
{See the manual for details.}
\bbl@errmessage{unknown-locale-key}
{Unknown key for locale '#2':\\%
#3\\%
\string#1 will be set to \string\relax}%
{Perhaps you misspelled it.}%
\bbl@errmessage{adjust-only-vertical}
{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.}
\bbl@errmessage{layout-only-vertical}
{Currently, layout related features can be adjusted only\\%
in vertical mode}%
{Maybe things change in the future, but this is what it is.}
\bbl@errmessage{bidi-only-lua}
{The bidi method 'basic' is available only in\\%
luatex. I'll continue with 'bidi=default', so\\%
expect wrong results}%
{See the manual for further details.}
\bbl@errmessage{multiple-bidi}
{Multiple bidi settings inside a group}%
{I'll insert a new group, but expect wrong results.}
\bbl@errmessage{unknown-package-option}
{Unknown option '\CurrentOption'. Either you misspelled it\\%
or the language definition file \CurrentOption.ldf\\%
was not found%
\bbl@tempa}
{Valid options are, among others: shorthands=, KeepShorthandsActive,\\%
activeacute, activegrave, noconfigs, safe=, main=, math=\\%
headfoot=, strings=, config=, hyphenmap=, or a language name.}
\bbl@errmessage{config-not-found}
{Local config file '\bbl@
[email protected]' not found}%
{Perhaps you misspelled it.}
\bbl@errmessage{late-after-babel}
{Too late for \string\AfterBabelLanguage}%
{Languages have been loaded, so I can do nothing}
\bbl@errmessage{double-hyphens-class}
{Double hyphens aren't allowed in \string\babelcharclass\\%
because it's potentially ambiguous}%
{See the manual for further info}
\bbl@errmessage{unknown-interchar}
{'#1' for '\languagename' cannot be enabled.\\%
Maybe there is a typo}%
{See the manual for further details.}
\bbl@errmessage{unknown-interchar-b}
{'#1' for '\languagename' cannot be disabled.\\%
Maybe there is a typo}%
{See the manual for further details.}
\bbl@errmessage{charproperty-only-vertical}
{\string\babelcharproperty\space can be used only in\\%
vertical mode (preamble or between paragraphs)}%
{See the manual for further info}
\bbl@errmessage{unknown-char-property}
{No property named '#2'. Allowed values are\\%
direction (bc), mirror (bmg), and linebreak (lb)}%
{See the manual for further info}
\bbl@errmessage{bad-transform-option}
{Bad option '#1' in a transform.\\%
I’ll ignore it but expect more errors}%
{See the manual for further info.}
\bbl@errmessage{font-conflict-transforms}
{Transforms cannot be re-assigned to different\\%
fonts. The conflict is in '\bbl@kv@label'.\\%
Apply the same fonts or use a different label}%
{See the manual for further details.}
\bbl@errmessage{transform-not-available}
{'#1' for '\languagename' cannot be enabled.\\%
Maybe there is a typo or it’s a font-dependent transform}%
{See the manual for further details.}
\bbl@errmessage{transform-not-available-b}
{'#1' for '\languagename' cannot be disabled.\\%
Maybe there is a typo or it’s a font-dependent transform}%
{See the manual for further details.}
\bbl@errmessage{year-out-range}
{Year out of range.\\%
The allowed range is #1}%
{See the manual for further details.}
\bbl@errmessage{only-pdftex-lang}
{The '#1' ldf style doesn't work with #2,\\%
but you can use the ini locale instead.\\%
Try adding 'provide=*' to the option list. You may\\%
also want to set 'bidi=' to some value}%
{See the manual for further details.}
\bbl@errmessage{hyphenmins-args}
{\string\babelhyphenmins\ accepts either the optional\\%
argument or the star, but not both at the same time}%
{See the manual for further details.}
\bbl@errmessage{no-locale-for-meta}
{There isn't currently a locale for the 'lang' requested\\%
in the PDF metadata ('#1'). To fix it, you can\\%
set explicitly a similar language (using the same\\%
script) with the key main= when loading babel. If you\\%
continue, I'll fallback to the 'nil' language, with\\%
tag 'und' and script 'Latn', but expect a bad font\\%
rendering with other scripts. You may also need set\\%
explicitly captions and date, too}%
{See the manual for further details.}
%</errors>
%<*patterns>
% \end{macrocode}
%
% \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} is used to include
% this code in the file \file{hyphen.cfg}. Code is written with lower
% level macros.
%
% \begin{macrocode}
<@Make sure ProvidesFile is defined@>
\ProvidesFile{hyphen.cfg}[<@date@> v<@version@> Babel hyphens]
\xdef\bbl@format{\jobname}
\def\bbl@version{<@version@>}
\def\bbl@date{<@date@>}
\ifx\AtBeginDocument\@undefined
\def\@empty{}
\fi
<@Define core switching macros@>
% \end{macrocode}
%
% \macro{\process@line}
% Each line in the file \file{language.dat} is processed by
% |\process@line| after it is read. The first thing this macro does is
% to check whether the line starts with \texttt{=}. When the first
% token of a line is an \texttt{=}, the macro |\process@synonym| is
% called; otherwise the macro |\process@language| will continue.
%
% \begin{macrocode}
\def\process@line#1#2 #3 #4 {%
\ifx=#1%
\process@synonym{#2}%
\else
\process@language{#1#2}{#3}{#4}%
\fi
\ignorespaces}
% \end{macrocode}
%
% \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.
%
% \begin{macrocode}
\toks@{}
\def\bbl@languages{}
% \end{macrocode}
%
% When no languages have been loaded yet, the name following the
% \texttt{=} will be a synonym for hyphenation register 0. So, it is
% stored in a token register and executed when the first pattern file
% has been processed. (The |\relax| just helps to the |\if| below
% catching synonyms without a language.)
%
% Otherwise the name will be a synonym for the language loaded last.
%
% We also need to copy the hyphenmin parameters for the synonym.
%
% \begin{macrocode}
\def\process@synonym#1{%
\ifnum\last@language=\m@ne
\toks@\expandafter{\the\toks@\relax\process@synonym{#1}}%
\else
\expandafter\chardef\csname l@#1\endcsname\last@language
\wlog{\string\l@#1=\string\language\the\last@language}%
\expandafter\let\csname #1hyphenmins\expandafter\endcsname
\csname\languagename hyphenmins\endcsname
\let\bbl@elt\relax
\edef\bbl@languages{\bbl@languages\bbl@elt{#1}{\the\last@language}{}{}}%
\fi}
% \end{macrocode}
%
% \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{%
\expandafter\addlanguage\csname l@#1\endcsname
\expandafter\language\csname l@#1\endcsname
\edef\languagename{#1}%
\bbl@hook@everylanguage{#1}%
% > luatex
\bbl@get@enc#1::\@@@
\begingroup
\lefthyphenmin\m@ne
\bbl@hook@loadpatterns{#2}%
% > luatex
\ifnum\lefthyphenmin=\m@ne
\else
\expandafter\xdef\csname #1hyphenmins\endcsname{%
\the\lefthyphenmin\the\righthyphenmin}%
\fi
\endgroup
\def\bbl@tempa{#3}%
\ifx\bbl@tempa\@empty\else
\bbl@hook@loadexceptions{#3}%
% > luatex
\fi
\let\bbl@elt\relax
\edef\bbl@languages{%
\bbl@languages\bbl@elt{#1}{\the\language}{#2}{\bbl@tempa}}%
\ifnum\the\language=\z@
\expandafter\ifx\csname #1hyphenmins\endcsname\relax
\set@hyphenmins\tw@\thr@@\relax
\else
\expandafter\expandafter\expandafter\set@hyphenmins
\csname #1hyphenmins\endcsname
\fi
\the\toks@
\toks@{}%
\fi}
% \end{macrocode}
%
% \macro{\bbl@get@enc}
%
% \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}
%
% 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
\def\bbl@hook@loadkernel#1{%
\def\addlanguage{\csname newlanguage\endcsname}%
\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{No multilingual package has been loaded}}%
\let\foreignlanguage\selectlanguage
\let\otherlanguage\selectlanguage
\expandafter\let\csname otherlanguage*\endcsname\selectlanguage
\def\bbl@usehooks##1##2{}%
\def\setlocale{%
\errhelp{Find an armchair, sit down and wait}%
\errmessage{(babel) 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
\def\next{\toks1}%
\else
\def\next{\expandafter\gdef\csname bbl@hook@#2\endcsname####1}%
\fi
\next}
\ifx\directlua\@undefined
\ifx\XeTeXinputencoding\@undefined\else
\input xebabel.def
\fi
\else
\input luababel.def
\fi
\openin1 = babel-\
[email protected]
\ifeof1
\else
\input babel-\
[email protected]\relax
\fi
\closein1
\endgroup
\bbl@hook@loadkernel{switch.def}
% \end{macrocode}
%
% \macro{\readconfigfile}
% The configuration file can now be opened for reading.
%
% \begin{macrocode}
\openin1 = language.dat
% \end{macrocode}
%
% See if the file exists, if not, use the default hyphenation file
% \file{hyphen.tex}. The user will be informed about this.
%
% \begin{macrocode}
\def\languagename{english}%
\ifeof1
\message{I couldn't find the file language.dat,\space
I will try the file hyphen.tex}
\input hyphen.tex\relax
\chardef\l@english\z@
\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$.
%
% \begin{macrocode}
\last@language\m@ne
% \end{macrocode}
%
% 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
\endlinechar\m@ne
\read1 to \bbl@line
\endlinechar`\^^M
% \end{macrocode}
%
% If the file has reached its end, exit from the loop here. If not,
% empty lines are skipped. Add 3 space characters to the end of
% |\bbl@line|. This is needed to be able to recognize the arguments of
% |\process@line| later on. The default language should be the very
% first one.
%
% \begin{macrocode}
\if T\ifeof1F\fi T\relax
\ifx\bbl@line\@empty\else
\edef\bbl@line{\bbl@line\space\space\space}%
\expandafter\process@line\bbl@line\relax
\fi
\repeat
% \end{macrocode}
%
% 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
\def\bbl@elt#1#2#3#4{%
\global\language=#2\relax
\gdef\languagename{#1}%
\def\bbl@elt##1##2##3##4{}}%
\bbl@languages
\endgroup
\fi
\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.
%
% \begin{macrocode}
\if/\the\toks@/\else
\errhelp{language.dat loads no language, only synonyms}
\errmessage{Orphan language synonym}
\fi
% \end{macrocode}
%
% Also remove some macros from memory and raise an error if |\toks@| is
% not empty. Finally load \file{switch.def}, but the latter is not
% required and the line inputting it may be commented out.
%
% \begin{macrocode}
\let\bbl@line\@undefined
\let\process@line\@undefined
\let\process@synonym\@undefined
\let\process@language\@undefined
\let\bbl@get@enc\@undefined
\let\bbl@hyph@enc\@undefined
\let\bbl@tempa\@undefined
\let\bbl@hook@loadkernel\@undefined
\let\bbl@hook@everylanguage\@undefined
\let\bbl@hook@loadpatterns\@undefined
\let\bbl@hook@loadexceptions\@undefined
%</patterns>
% \end{macrocode}
%
% Here the code for ini\TeX\ ends.
%
% \section{\luatex{} + \xetex{}: common stuff}
%
% Add the bidi handler just before luaotfload, which is loaded by default
% by LaTeX. Just in case, consider the possibility it has not been
% loaded. First, a couple of definitions related to bidi (although
% |default| also applies to \pdftex).
%
% \begin{macrocode}
%<<*More package options>>
\chardef\bbl@bidimode\z@
\DeclareOption{bidi=default}{\chardef\bbl@bidimode=\@ne}
\DeclareOption{bidi=basic}{\chardef\bbl@bidimode=101 }
\DeclareOption{bidi=basic-r}{\chardef\bbl@bidimode=102 }
\DeclareOption{bidi=bidi}{\chardef\bbl@bidimode=201 }
\DeclareOption{bidi=bidi-r}{\chardef\bbl@bidimode=202 }
\DeclareOption{bidi=bidi-l}{\chardef\bbl@bidimode=203 }
%<</More package options>>
% \end{macrocode}
%
% \macro{\babelfont}
%
% With explicit languages, we could define the font at once, but we
% don't. Just wait and see if the language is actually activated.
% |bbl@font| replaces hardcoded font names inside |\..family| by the
% corresponding macro |\..default|.
%
% \begin{macrocode}
%<<*Font selection>>
\bbl@trace{Font handling with fontspec}
\AddBabelHook{babel-fontspec}{afterextras}{\bbl@switchfont}
\AddBabelHook{babel-fontspec}{beforestart}{\bbl@ckeckstdfonts}
\DisableBabelHook{babel-fontspec}
\@onlypreamble\babelfont
\newcommand\babelfont[2][]{% 1=langs/scripts 2=fam
\ifx\fontspec\@undefined
\usepackage{fontspec}%
\fi
\EnableBabelHook{babel-fontspec}%
\edef\bbl@tempa{#1}%
\def\bbl@tempb{#2}% Used by \bbl@bblfont
\bbl@bblfont}
\newcommand\bbl@bblfont[2][]{% 1=features 2=fontname, @font=rm|sf|tt
\bbl@ifunset{\bbl@tempb family}%
{\bbl@providefam{\bbl@tempb}}%
{}%
% For the default font, just in case:
\bbl@ifunset{bbl@lsys@\languagename}{\bbl@provide@lsys{\languagename}}{}%
\expandafter\bbl@ifblank\expandafter{\bbl@tempa}%
{\bbl@csarg\edef{\bbl@tempb dflt@}{<>{#1}{#2}}% save bbl@rmdflt@
\bbl@exp{%
\let\<bbl@\bbl@tempb dflt@\languagename>\<bbl@\bbl@tempb dflt@>%
\\\bbl@font@set\<bbl@\bbl@tempb dflt@\languagename>%
\<\bbl@tempb default>\<\bbl@tempb family>}}%
{\bbl@foreach\bbl@tempa{% i.e., bbl@rmdflt@lang / *scrt
\bbl@csarg\def{\bbl@tempb dflt@##1}{<>{#1}{#2}}}}}%
% \end{macrocode}
%
% If the family in the previous command does not exist, it must be
% defined. Here is how:
%
% \begin{macrocode}
\def\bbl@providefam#1{%
\bbl@exp{%
\\\newcommand\<#1default>{}% Just define it
\\\bbl@add@list\\\bbl@font@fams{#1}%
\\\NewHook{#1family}%
\\\DeclareRobustCommand\<#1family>{%
\\\not@math@alphabet\<#1family>\relax
% \\\prepare@family@series@update{#1}\<#1default>% TODO. Fails
\\\fontfamily\<#1default>%
\\\UseHook{#1family}%
\\\selectfont}%
\\\DeclareTextFontCommand{\<text#1>}{\<#1family>}}}
% \end{macrocode}
%
% The following macro is activated when the hook |babel-fontspec| is
% enabled. But before, we define a macro for a warning, which sets a
% flag to avoid duplicate them.
%
% \begin{macrocode}
\def\bbl@nostdfont#1{%
\bbl@ifunset{bbl@WFF@\f@family}%
{\bbl@csarg\gdef{WFF@\f@family}{}% Flag, to avoid dupl warns
\bbl@infowarn{The current font is not a babel standard family:\\%
#1%
\fontname\font\\%
There is nothing intrinsically wrong with this warning, and\\%
you can ignore it altogether if you do not need these\\%
families. But if they are used in the document, you should be\\%
aware 'babel' will not set Script and Language for them, so\\%
you may consider defining a new family with \string\babelfont.\\%
See the manual for further details about \string\babelfont.\\%
Reported}}
{}}%
\gdef\bbl@switchfont{%
\bbl@ifunset{bbl@lsys@\languagename}{\bbl@provide@lsys{\languagename}}{}%
\bbl@exp{% e.g., Arabic -> arabic
\lowercase{\edef\\\bbl@tempa{\bbl@cl{sname}}}}%
\bbl@foreach\bbl@font@fams{%
\bbl@ifunset{bbl@##1dflt@\languagename}% (1) language?
{\bbl@ifunset{bbl@##1dflt@*\bbl@tempa}% (2) from script?
{\bbl@ifunset{bbl@##1dflt@}% 2=F - (3) from generic?
{}% 123=F - nothing!
{\bbl@exp{% 3=T - from generic
\global\let\<bbl@##1dflt@\languagename>%
\<bbl@##1dflt@>}}}%
{\bbl@exp{% 2=T - from script
\global\let\<bbl@##1dflt@\languagename>%
\<bbl@##1dflt@*\bbl@tempa>}}}%
{}}% 1=T - language, already defined
\def\bbl@tempa{\bbl@nostdfont{}}%
\bbl@foreach\bbl@font@fams{% don't gather with prev for
\bbl@ifunset{bbl@##1dflt@\languagename}%
{\bbl@cs{famrst@##1}%
\global\bbl@csarg\let{famrst@##1}\relax}%
{\bbl@exp{% order is relevant.
\\\bbl@add\\\originalTeX{%
\\\bbl@font@rst{\bbl@cl{##1dflt}}%
\<##1default>\<##1family>{##1}}%
\\\bbl@font@set\<bbl@##1dflt@\languagename>% the main part!
\<##1default>\<##1family>}}}%
\bbl@ifrestoring{}{\bbl@tempa}}%
% \end{macrocode}
%
% The following is executed at the beginning of the aux file or the
% document to warn about fonts not defined with |\babelfont|.
%
% \begin{macrocode}
\ifx\f@family\@undefined\else % if latex
\ifcase\bbl@engine % if pdftex
\let\bbl@ckeckstdfonts\relax
\else
\def\bbl@ckeckstdfonts{%
\begingroup
\global\let\bbl@ckeckstdfonts\relax
\let\bbl@tempa\@empty
\bbl@foreach\bbl@font@fams{%
\bbl@ifunset{bbl@##1dflt@}%
{\@nameuse{##1family}%
\bbl@csarg\gdef{WFF@\f@family}{}% Flag
\bbl@exp{\\\bbl@add\\\bbl@tempa{* \<##1family>= \f@family\\\\%
\space\space\fontname\font\\\\}}%
\bbl@csarg\xdef{##1dflt@}{\f@family}%
\expandafter\xdef\csname ##1default\endcsname{\f@family}}%
{}}%
\ifx\bbl@tempa\@empty\else
\bbl@infowarn{The following font families will use the default\\%
settings for all or some languages:\\%
\bbl@tempa
There is nothing intrinsically wrong with it, but\\%
'babel' will no set Script and Language, which could\\%
be relevant in some languages. If your document uses\\%
these families, consider redefining them with \string\babelfont.\\%
Reported}%
\fi
\endgroup}
\fi
\fi
% \end{macrocode}
%
% Now the macros defining the font with \textsf{fontspec}.
%
% When there are repeated keys in \textsf{fontspec}, the last value
% wins. So, we just place the ini settings at the beginning, and user
% settings will take precedence. We must deactivate temporarily
% |\bbl@mapselect| because |\selectfont| is called internally when a
% font is defined.
%
% For historical reasons, \LaTeX{} can select two different series
% (|bx| and |b|), for what is conceptually a single one. This can
% lead to problems when a single family requires several fonts,
% depending on the language, mainly because ‘substitutions’ with some
% combinations are not done consistently -- sometimes |bx/sc| is the
% correct font, but sometimes points to |b/n|, even if |b/sc| exists.
% So, some substitutions are redefined (in a somewhat hackish way, by
% inspecting if the variant declaration contains |>ssub*|).
%
% \begin{macrocode}
\def\bbl@font@set#1#2#3{% e.g., \bbl@rmdflt@lang \rmdefault \rmfamily
\bbl@xin@{<>}{#1}%
\ifin@
\bbl@exp{\\\bbl@fontspec@set\\#1\expandafter\@gobbletwo#1\\#3}%
\fi
\bbl@exp{% 'Unprotected' macros return prev values
\def\\#2{#1}% e.g., \rmdefault{\bbl@rmdflt@lang}
\\\bbl@ifsamestring{#2}{\f@family}%
{\\#3%
\\\bbl@ifsamestring{\f@series}{\bfdefault}{\\\bfseries}{}%
\let\\\bbl@tempa\relax}%
{}}}
% \end{macrocode}
%
% Loaded locally, which does its job, but very must be global. The
% problem is how. This actually defines a font predeclared with
% |\babelfont|, making sure |Script| and |Language| names are defined.
% If they are not, the corresponding data in the ini file is used. The
% font is actually set temporarily to get the family name
% (|\f@family|). There is also a hack because by default some
% replacements related to the bold series are sometimes assigned to the
% wrong font (see issue \#92).
%
% \begin{macrocode}
\def\bbl@fontspec@set#1#2#3#4{% eg \bbl@rmdflt@lang fnt-opt fnt-nme \xxfamily
\let\bbl@tempe\bbl@mapselect
\edef\bbl@tempb{\bbl@stripslash#4/}% Catcodes hack (better pass it).
\bbl@exp{\\\bbl@replace\\\bbl@tempb{\bbl@stripslash\family/}{}}%
\let\bbl@mapselect\relax
\let\bbl@temp@fam#4% e.g., '\rmfamily', to be restored below
\let#4\@empty % Make sure \renewfontfamily is valid
\bbl@set@renderer
\bbl@exp{%
\let\\\bbl@temp@pfam\<\bbl@stripslash#4\space>% e.g., '\rmfamily '
\<keys_if_exist:nnF>{fontspec-opentype}{Script/\bbl@cl{sname}}%
{\\\newfontscript{\bbl@cl{sname}}{\bbl@cl{sotf}}}%
\<keys_if_exist:nnF>{fontspec-opentype}{Language/\bbl@cl{lname}}%
{\\\newfontlanguage{\bbl@cl{lname}}{\bbl@cl{lotf}}}%
\\\renewfontfamily\\#4%
[\bbl@cl{lsys},% xetex removes unknown features :-(
\ifcase\bbl@engine\or RawFeature={family=\bbl@tempb},\fi
#2]}{#3}% i.e., \bbl@exp{..}{#3}
\bbl@unset@renderer
\begingroup
#4%
\xdef#1{\f@family}% e.g., \bbl@rmdflt@lang{FreeSerif(0)}
\endgroup
\bbl@xin@{\string>\string s\string s\string u\string b\string*}%
{\expandafter\meaning\csname TU/#1/bx/sc\endcsname}%
\ifin@
\global\bbl@ccarg\let{TU/#1/bx/sc}{TU/#1/b/sc}%
\fi
\bbl@xin@{\string>\string s\string s\string u\string b\string*}%
{\expandafter\meaning\csname TU/#1/bx/scit\endcsname}%
\ifin@
\global\bbl@ccarg\let{TU/#1/bx/scit}{TU/#1/b/scit}%
\fi
\let#4\bbl@temp@fam
\bbl@exp{\let\<\bbl@stripslash#4\space>}\bbl@temp@pfam
\let\bbl@mapselect\bbl@tempe}%
% \end{macrocode}
%
% |font@rst| and |famrst| are only used when there is no global
% settings, to save and restore de previous families. Not really
% necessary, but done for optimization.
%
% \begin{macrocode}
\def\bbl@font@rst#1#2#3#4{%
\bbl@csarg\def{famrst@#4}{\bbl@font@set{#1}#2#3}}
% \end{macrocode}
%
% The default font families. They are eurocentric, but the list can be
% expanded easily with |\babelfont|.
%
% \begin{macrocode}
\def\bbl@font@fams{rm,sf,tt}
%<</Font selection>>
% \end{macrocode}
%
% \section{Hooks for XeTeX and LuaTeX}
%
% \subsection{XeTeX}
%
% Unfortunately, the current encoding cannot be retrieved and
% therefore it is reset always to |utf8|, which seems a sensible
% default.
%
% Now, the code.
%
% \begin{macrocode}
%<*xetex>
\def\BabelStringsDefault{unicode}
\let\xebbl@stop\relax
\AddBabelHook{xetex}{encodedcommands}{%
\def\bbl@tempa{#1}%
\ifx\bbl@tempa\@empty
\XeTeXinputencoding"bytes"%
\else
\XeTeXinputencoding"#1"%
\fi
\def\xebbl@stop{\XeTeXinputencoding"utf8"}}
\AddBabelHook{xetex}{stopcommands}{%
\xebbl@stop
\let\xebbl@stop\relax}
\def\bbl@input@classes{% Used in CJK intraspaces
\input{load-unicode-xetex-classes.tex}%
\let\bbl@input@classes\relax}
\def\bbl@intraspace#1 #2 #3\@@{%
\bbl@csarg\gdef{xeisp@\languagename}%
{\XeTeXlinebreakskip #1em plus #2em minus #3em\relax}}
\def\bbl@intrapenalty#1\@@{%
\bbl@csarg\gdef{xeipn@\languagename}%
{\XeTeXlinebreakpenalty #1\relax}}
\def\bbl@provide@intraspace{%
\bbl@xin@{/s}{/\bbl@cl{lnbrk}}%
\ifin@\else\bbl@xin@{/c}{/\bbl@cl{lnbrk}}\fi
\ifin@
\bbl@ifunset{bbl@intsp@\languagename}{}%
{\expandafter\ifx\csname bbl@intsp@\languagename\endcsname\@empty\else
\ifx\bbl@KVP@intraspace\@nnil
\bbl@exp{%
\\\bbl@intraspace\bbl@cl{intsp}\\\@@}%
\fi
\ifx\bbl@KVP@intrapenalty\@nnil
\bbl@intrapenalty0\@@
\fi
\fi
\ifx\bbl@KVP@intraspace\@nnil\else % We may override the ini
\expandafter\bbl@intraspace\bbl@KVP@intraspace\@@
\fi
\ifx\bbl@KVP@intrapenalty\@nnil\else
\expandafter\bbl@intrapenalty\bbl@KVP@intrapenalty\@@
\fi
\bbl@exp{%
\\\bbl@add\<extras\languagename>{%
\XeTeXlinebreaklocale "\bbl@cl{tbcp}"%
\<bbl@xeisp@\languagename>%
\<bbl@xeipn@\languagename>}%
\\\bbl@toglobal\<extras\languagename>%
\\\bbl@add\<noextras\languagename>{%
\XeTeXlinebreaklocale ""}%
\\\bbl@toglobal\<noextras\languagename>}%
\ifx\bbl@ispacesize\@undefined
\gdef\bbl@ispacesize{\bbl@cl{xeisp}}%
\ifx\AtBeginDocument\@notprerr
\expandafter\@secondoftwo % to execute right now
\fi
\AtBeginDocument{\bbl@patchfont{\bbl@ispacesize}}%
\fi}%
\fi}
\ifx\DisableBabelHook\@undefined\endinput\fi
\let\bbl@set@renderer\relax
\let\bbl@unset@renderer\relax
<@Font selection@>
\def\bbl@provide@extra#1{}
% \end{macrocode}
%
% Hack for unhyphenated line breaking. See |\bbl@provide@lsys| in the
% common code.
%
% \begin{macrocode}
\def\bbl@xenohyph@d{%
\bbl@ifset{bbl@prehc@\languagename}%
{\ifnum\hyphenchar\font=\defaulthyphenchar
\iffontchar\font\bbl@cl{prehc}\relax
\hyphenchar\font\bbl@cl{prehc}\relax
\else\iffontchar\font"200B
\hyphenchar\font"200B
\else
\bbl@warning
{Neither 0 nor ZERO WIDTH SPACE are available\\%
in the current font, and therefore the hyphen\\%
will be printed. Try changing the fontspec's\\%
'HyphenChar' to another value, but be aware\\%
this setting is not safe (see the manual).\\%
Reported}%
\hyphenchar\font\defaulthyphenchar
\fi\fi
\fi}%
{\hyphenchar\font\defaulthyphenchar}}
% \end{macrocode}
%
% \subsection{Support for interchar}
%
% \xetex{} reserves some values for CJK (although they are not set in
% \textsc{xelatex}), so we make sure they are skipped. Define some user
% names for the global classes, too.
%
% \begin{macrocode}
\ifnum\xe@alloc@intercharclass<\thr@@
\xe@alloc@intercharclass\thr@@
\fi
\chardef\bbl@xeclass@default@=\z@
\chardef\bbl@xeclass@cjkideogram@=\@ne
\chardef\bbl@xeclass@cjkleftpunctuation@=\tw@
\chardef\bbl@xeclass@cjkrightpunctuation@=\thr@@
\chardef\bbl@xeclass@boundary@=4095
\chardef\bbl@xeclass@ignore@=4096
% \end{macrocode}
%
% The machinery is activated with a hook (enabled only if actually
% used). Here |\bbl@tempc| is pre-set with |\bbl@usingxeclass|, defined
% below. The standard mechanism based on |\originalTeX| to save, set
% and restore values is used. |\count@| stores the previous char to be
% set, except at the beginning (0) and after |\bbl@upto|, which is the
% previous char negated, as a flag to mark a range.
%
% \begin{macrocode}
\AddBabelHook{babel-interchar}{beforeextras}{%
\@nameuse{bbl@xechars@\languagename}}
\DisableBabelHook{babel-interchar}
\protected\def\bbl@charclass#1{%
\ifnum\count@<\z@
\count@-\count@
\loop
\bbl@exp{%
\\\babel@savevariable{\XeTeXcharclass`\Uchar\count@}}%
\XeTeXcharclass\count@ \bbl@tempc
\ifnum\count@<`#1\relax
\advance\count@\@ne
\repeat
\else
\babel@savevariable{\XeTeXcharclass`#1}%
\XeTeXcharclass`#1 \bbl@tempc
\fi
\count@`#1\relax}
% \end{macrocode}
%
% Now the two user macros. Char classes are declared implicitly, and
% then the macro to be executed at the |babel-interchar| hook is
% created. The list of chars to be handled by the hook defined above
% has internally the form
% |\bbl@usingxeclass\bbl@xeclass@punct@english||\bbl@charclass{.}|%
% |\bbl@charclass{,}| (etc.), where |\bbl@usingxeclass| stores the class to be
% applied to the subsequent characters. The \cs{ifcat} part deals with
% the alternative way to enter characters as macros (e.g., |\}|). As a
% special case, hyphens are stored as |\bbl@upto|, to deal with ranges.
%
% \begin{macrocode}
\newcommand\bbl@ifinterchar[1]{%
\let\bbl@tempa\@gobble % Assume to ignore
\edef\bbl@tempb{\zap@space#1 \@empty}%
\ifx\bbl@KVP@interchar\@nnil\else
\bbl@replace\bbl@KVP@interchar{ }{,}%
\bbl@foreach\bbl@tempb{%
\bbl@xin@{,##1,}{,\bbl@KVP@interchar,}%
\ifin@
\let\bbl@tempa\@firstofone
\fi}%
\fi
\bbl@tempa}
\newcommand\IfBabelIntercharT[2]{%
\bbl@carg\bbl@add{bbl@icsave@\CurrentOption}{\bbl@ifinterchar{#1}{#2}}}%
\newcommand\babelcharclass[3]{%
\EnableBabelHook{babel-interchar}%
\bbl@csarg\newXeTeXintercharclass{xeclass@#2@#1}%
\def\bbl@tempb##1{%
\ifx##1\@empty\else
\ifx##1-%
\bbl@upto
\else
\bbl@charclass{%
\ifcat\noexpand##1\relax\bbl@stripslash##1\else\string##1\fi}%
\fi
\expandafter\bbl@tempb
\fi}%
\bbl@ifunset{bbl@xechars@#1}%
{\toks@{%
\babel@savevariable\XeTeXinterchartokenstate
\XeTeXinterchartokenstate\@ne
}}%
{\toks@\expandafter\expandafter\expandafter{%
\csname bbl@xechars@#1\endcsname}}%
\bbl@csarg\edef{xechars@#1}{%
\the\toks@
\bbl@usingxeclass\csname bbl@xeclass@#2@#1\endcsname
\bbl@tempb#3\@empty}}
\protected\def\bbl@usingxeclass#1{\count@\z@ \let\bbl@tempc#1}
\protected\def\bbl@upto{%
\ifnum\count@>\z@
\advance\count@\@ne
\count@-\count@
\else\ifnum\count@=\z@
\bbl@charclass{-}%
\else
\bbl@error{double-hyphens-class}{}{}{}%
\fi\fi}
% \end{macrocode}
%
% And finally, the command with the code to be inserted. If the language
% doesn’t define a class, then use the global one, as defined above.
% For the definition there is a intermediate macro, which can be
% ‘disabled’ with |\bbl@ic@<label>@<language>|.
%
% \begin{macrocode}
\def\bbl@ignoreinterchar{%
\ifnum\language=\l@nohyphenation
\expandafter\@gobble
\else
\expandafter\@firstofone
\fi}
\newcommand\babelinterchar[5][]{%
\let\bbl@kv@label\@empty
\bbl@forkv{#1}{\bbl@csarg\edef{kv@##1}{##2}}%
\@namedef{\zap@space bbl@xeinter@\bbl@kv@label @#3@#4@#2 \@empty}%
{\bbl@ignoreinterchar{#5}}%
\bbl@csarg\let{ic@\bbl@kv@label @#2}\@firstofone
\bbl@exp{\\\bbl@for\\\bbl@tempa{\zap@space#3 \@empty}}{%
\bbl@exp{\\\bbl@for\\\bbl@tempb{\zap@space#4 \@empty}}{%
\XeTeXinterchartoks
\@nameuse{bbl@xeclass@\bbl@tempa @%
\bbl@ifunset{bbl@xeclass@\bbl@tempa @#2}{}{#2}} %
\@nameuse{bbl@xeclass@\bbl@tempb @%
\bbl@ifunset{bbl@xeclass@\bbl@tempb @#2}{}{#2}} %
= \expandafter{%
\csname bbl@ic@\bbl@kv@label @#2\expandafter\endcsname
\csname\zap@space bbl@xeinter@\bbl@kv@label
@#3@#4@#2 \@empty\endcsname}}}}
\DeclareRobustCommand\enablelocaleinterchar[1]{%
\bbl@ifunset{bbl@ic@#1@\languagename}%
{\bbl@error{unknown-interchar}{#1}{}{}}%
{\bbl@csarg\let{ic@#1@\languagename}\@firstofone}}
\DeclareRobustCommand\disablelocaleinterchar[1]{%
\bbl@ifunset{bbl@ic@#1@\languagename}%
{\bbl@error{unknown-interchar-b}{#1}{}{}}%
{\bbl@csarg\let{ic@#1@\languagename}\@gobble}}
%</xetex>
% \end{macrocode}
%
% \subsection{Layout}
%
% Note elements like headlines and margins can be modified easily with
% packages like \textsf{fancyhdr}, \textsf{typearea} or
% \textsf{titleps}, and \textsf{geometry}.
%
% |\bbl@startskip| and |\bbl@endskip| are available to package
% authors. Thanks to the \TeX{} expansion mechanism the following
% constructs are valid: |\adim\bbl@startskip|,
% |\advance\bbl@startskip\adim|, |\bbl@startskip\adim|.
%
% Consider |txtbabel| as a shorthand for \textit{tex--xet babel},
% which is the bidi model in both \pdftex{} and \xetex{}.
%
% \begin{macrocode}
%<*xetex|texxet>
\providecommand\bbl@provide@intraspace{}
\bbl@trace{Redefinitions for bidi layout}
% \end{macrocode}
%
% Finish here if there in no |layout|.
%
% \begin{macrocode}
\ifx\bbl@opt@layout\@nnil\else % if layout=..
\IfBabelLayout{nopars}
{}
{\edef\bbl@opt@layout{\bbl@
[email protected].}}%
\def\bbl@startskip{\ifcase\bbl@thepardir\leftskip\else\rightskip\fi}
\def\bbl@endskip{\ifcase\bbl@thepardir\rightskip\else\leftskip\fi}
\ifnum\bbl@bidimode>\z@
\IfBabelLayout{pars}
{\def\@hangfrom#1{%
\setbox\@tempboxa\hbox{{#1}}%
\hangindent\ifcase\bbl@thepardir\wd\@tempboxa\else-\wd\@tempboxa\fi
\noindent\box\@tempboxa}
\def\raggedright{%
\let\\\@centercr
\bbl@startskip\z@skip
\@rightskip\@flushglue
\bbl@endskip\@rightskip
\parindent\z@
\parfillskip\bbl@startskip}
\def\raggedleft{%
\let\\\@centercr
\bbl@startskip\@flushglue
\bbl@endskip\z@skip
\parindent\z@
\parfillskip\bbl@endskip}}
{}
\fi
\IfBabelLayout{lists}
{\bbl@sreplace\list
{\@totalleftmargin\leftmargin}{\@totalleftmargin\bbl@listleftmargin}%
\def\bbl@listleftmargin{%
\ifcase\bbl@thepardir\leftmargin\else\rightmargin\fi}%
\ifcase\bbl@engine
\def\labelenumii{)\theenumii(}% pdftex doesn't reverse ()
\def\p@enumiii{\p@enumii)\theenumii(}%
\fi
\bbl@sreplace\@verbatim
{\leftskip\@totalleftmargin}%
{\bbl@startskip\textwidth
\advance\bbl@startskip-\linewidth}%
\bbl@sreplace\@verbatim
{\rightskip\z@skip}%
{\bbl@endskip\z@skip}}%
{}
\IfBabelLayout{contents}
{\bbl@sreplace\@dottedtocline{\leftskip}{\bbl@startskip}%
\bbl@sreplace\@dottedtocline{\rightskip}{\bbl@endskip}}
{}
\IfBabelLayout{columns}
{\bbl@sreplace\@outputdblcol{\hb@xt@\textwidth}{\bbl@outputhbox}%
\def\bbl@outputhbox#1{%
\hb@xt@\textwidth{%
\hskip\columnwidth
\hfil
{\normalcolor\vrule \@width\columnseprule}%
\hfil
\hb@xt@\columnwidth{\box\@leftcolumn \hss}%
\hskip-\textwidth
\hb@xt@\columnwidth{\box\@outputbox \hss}%
\hskip\columnsep
\hskip\columnwidth}}}%
{}
% \end{macrocode}
%
% Implicitly reverses sectioning labels in |bidi=basic|, because the
% full stop is not in contact with L numbers any more. I think there
% must be a better way.
%
% \begin{macrocode}
\IfBabelLayout{counters*}%
{\bbl@add\bbl@opt@layout{.counters.}%
\AddToHook{shipout/before}{%
\let\bbl@tempa\babelsublr
\let\babelsublr\@firstofone
\let\bbl@save@thepage\thepage
\protected@edef\thepage{\thepage}%
\let\babelsublr\bbl@tempa}%
\AddToHook{shipout/after}{%
\let\thepage\bbl@save@thepage}}{}
\IfBabelLayout{counters}%
{\let\bbl@latinarabic=\@arabic
\def\@arabic#1{\babelsublr{\bbl@latinarabic#1}}%
\let\bbl@asciiroman=\@roman
\def\@roman#1{\babelsublr{\ensureascii{\bbl@asciiroman#1}}}%
\let\bbl@asciiRoman=\@Roman
\def\@Roman#1{\babelsublr{\ensureascii{\bbl@asciiRoman#1}}}}{}
\fi % end if layout
%</xetex|texxet>
% \end{macrocode}
%
% \subsection{8-bit TeX}
%
% Which start just above, because some code is shared with \xetex. Now,
% 8-bit specific stuff. If just one encoding has been declared, then
% assume no switching is necessary (1).
%
% \begin{macrocode}
%<*texxet>
\def\bbl@provide@extra#1{%
% == auto-select encoding ==
\ifx\bbl@encoding@select@off\@empty\else
\bbl@ifunset{bbl@encoding@#1}%
{\def\@elt##1{,##1,}%
\edef\bbl@tempe{\expandafter\@gobbletwo\@fontenc@load@list}%
\count@\z@
\bbl@foreach\bbl@tempe{%
\def\bbl@tempd{##1}% Save last declared
\advance\count@\@ne}%
\ifnum\count@>\@ne % (1)
\getlocaleproperty*\bbl@tempa{#1}{identification/encodings}%
\ifx\bbl@tempa\relax \let\bbl@tempa\@empty \fi
\bbl@replace\bbl@tempa{ }{,}%
\global\bbl@csarg\let{encoding@#1}\@empty
\bbl@xin@{,\bbl@tempd,}{,\bbl@tempa,}%
\ifin@\else % if main encoding included in ini, do nothing
\let\bbl@tempb\relax
\bbl@foreach\bbl@tempa{%
\ifx\bbl@tempb\relax
\bbl@xin@{,##1,}{,\bbl@tempe,}%
\ifin@\def\bbl@tempb{##1}\fi
\fi}%
\ifx\bbl@tempb\relax\else
\bbl@exp{%
\global\<bbl@add>\<bbl@preextras@#1>{\<bbl@encoding@#1>}%
\gdef\<bbl@encoding@#1>{%
\\\babel@save\\\f@encoding
\\\bbl@add\\\originalTeX{\\\selectfont}%
\\\fontencoding{\bbl@tempb}%
\\\selectfont}}%
\fi
\fi
\fi}%
{}%
\fi}
%</texxet>
% \end{macrocode}
%
% \subsection{LuaTeX}
%
% 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
% hyphenmins stuff, which is under the direct control of \babel).
%
% The names |\l@<language>| are defined and take some value from the
% beginning because all \texttt{ldf} files assume this for the
% corresponding language to be considered valid, but patterns are not
% loaded (except the first one). This is done later, when the language
% is first selected (which usually means when the \texttt{ldf}
% finishes). If a language has been loaded, |\bbl@hyphendata@<num>|
% exists (with the names of the files read).
%
% The default setup preloads the first language into the format. This
% is intended mainly for `english', so that it's available without
% further intervention from the user. To avoid duplicating it, the
% following rule applies: if the “0th” language and the first
% language in |language.dat| have the same name then just ignore the
% latter. If there are new synonymous, the are added, but note if the
% language patterns have not been preloaded they won't at run time.
%
% Other preloaded languages could be read twice, if they have been
% preloaded into the format. This is not optimal, but it shouldn't
% happen very often -- with \luatex{} patterns are best loaded when
% the document is typeset, and the “0th” language is preloaded just
% for backwards compatibility.
%
% As of 1.1b, lua(e)tex is taken into account. Formerly, loading of
% patterns on the fly didn't work in this format, but with the new
% loader it does. Unfortunately, the format is not based on \babel,
% and data could be duplicated, because languages are reassigned above
% those in the format (nothing serious, anyway). Note even with this
% format |language.dat| is used (under the principle of a single
% source), instead of |language.def|.
%
% Of course, there is room for improvements, like tools to read and
% reassign languages, which would require modifying the language list,
% and better error handling.
%
% We need catcode tables, but no format (targeted by \babel) provide a
% command to allocate them (although there are packages like
% \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| (e.g.,
% |\babelpatterns|).
%
% \begin{macrocode}
%<*luatex>
\directlua{ Babel = Babel or {} } % DL2
\ifx\AddBabelHook\@undefined % When plain.def, babel.sty starts
\bbl@trace{Read language.dat}
\ifx\bbl@readstream\@undefined
\csname newread\endcsname\bbl@readstream
\fi
\begingroup
\toks@{}
\count@\z@ % 0=start, 1=0th, 2=normal
\def\bbl@process@line#1#2 #3 #4 {%
\ifx=#1%
\bbl@process@synonym{#2}%
\else
\bbl@process@language{#1#2}{#3}{#4}%
\fi
\ignorespaces}
\def\bbl@manylang{%
\ifnum\bbl@last>\@ne
\bbl@info{Non-standard hyphenation setup}%
\fi
\let\bbl@manylang\relax}
\def\bbl@process@language#1#2#3{%
\ifcase\count@
\@ifundefined{zth@#1}{\count@\tw@}{\count@\@ne}%
\or
\count@\tw@
\fi
\ifnum\count@=\tw@
\expandafter\addlanguage\csname l@#1\endcsname
\language\allocationnumber
\chardef\bbl@last\allocationnumber
\bbl@manylang
\let\bbl@elt\relax
\xdef\bbl@languages{%
\bbl@languages\bbl@elt{#1}{\the\language}{#2}{#3}}%
\fi
\the\toks@
\toks@{}}
\def\bbl@process@synonym@aux#1#2{%
\global\expandafter\chardef\csname l@#1\endcsname#2\relax
\let\bbl@elt\relax
\xdef\bbl@languages{%
\bbl@languages\bbl@elt{#1}{#2}{}{}}}%
\def\bbl@process@synonym#1{%
\ifcase\count@
\toks@\expandafter{\the\toks@\relax\bbl@process@synonym{#1}}%
\or
\@ifundefined{zth@#1}{\bbl@process@synonym@aux{#1}{0}}{}%
\else
\bbl@process@synonym@aux{#1}{\the\bbl@last}%
\fi}
\ifx\bbl@languages\@undefined % Just a (sensible?) guess
\chardef\l@english\z@
\chardef\l@USenglish\z@
\chardef\bbl@last\z@
\global\@namedef{bbl@hyphendata@0}{{hyphen.tex}{}}
\gdef\bbl@languages{%
\bbl@elt{english}{0}{hyphen.tex}{}%
\bbl@elt{USenglish}{0}{}{}}
\else
\global\let\bbl@languages@format\bbl@languages
\def\bbl@elt#1#2#3#4{% Remove all except language 0
\ifnum#2>\z@\else
\noexpand\bbl@elt{#1}{#2}{#3}{#4}%
\fi}%
\xdef\bbl@languages{\bbl@languages}%
\fi
\def\bbl@elt#1#2#3#4{\@namedef{zth@#1}{}} % Define flags
\bbl@languages
\openin\bbl@readstream=language.dat
\ifeof\bbl@readstream
\bbl@warning{I couldn't find language.dat. No additional\\%
patterns loaded. Reported}%
\else
\loop
\endlinechar\m@ne
\read\bbl@readstream to \bbl@line
\endlinechar`\^^M
\if T\ifeof\bbl@readstream F\fi T\relax
\ifx\bbl@line\@empty\else
\edef\bbl@line{\bbl@line\space\space\space}%
\expandafter\bbl@process@line\bbl@line\relax
\fi
\repeat
\fi
\closein\bbl@readstream
\endgroup
\bbl@trace{Macros for reading patterns files}
\def\bbl@get@enc#1:#2:#3\@@@{\def\bbl@hyph@enc{#2}}
\ifx\babelcatcodetablenum\@undefined
\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
\savecatcodetable\babelcatcodetablenum\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}%
\ifx\bbl@tempa\@empty\else
\input #2\relax
\fi
\egroup}%
\def\bbl@patterns@lua#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\relax
\@namedef{lu@texhyphen@loaded@\the\language}{}% Temp
\@ifundefined{bbl@hyphendata@\the\language}%
{\def\bbl@elt##1##2##3##4{%
\ifnum##2=\csname l@\bbl@tempa\endcsname % #2=spanish, dutch:OT1...
\def\bbl@tempb{##3}%
\ifx\bbl@tempb\@empty\else % if not a synonymous
\def\bbl@tempc{{##3}{##4}}%
\fi
\bbl@csarg\xdef{hyphendata@##2}{\bbl@tempc}%
\fi}%
\bbl@languages
\@ifundefined{bbl@hyphendata@\the\language}%
{\bbl@info{No hyphenation patterns were set for\\%
language '\bbl@tempa'. Reported}}%
{\expandafter\expandafter\expandafter\bbl@luapatterns
\csname bbl@hyphendata@\the\language\endcsname}}{}}
\endinput\fi
% \end{macrocode}
%
% Here ends |\ifx\AddBabelHook\@undefined|. A few lines are only read
% by \textsc{hyphen.cfg}.
%
% \begin{macrocode}
\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
% \end{macrocode}
%
% Here stops reading code for \textsc{hyphen.cfg}. The following is
% read the 2nd time it's loaded. First, global declarations for lua.
%
% \begin{macrocode}
\begingroup
\catcode`\%=12
\catcode`\'=12
\catcode`\"=12
\catcode`\:=12
\directlua{
Babel.locale_props = Babel.locale_props or {}
function Babel.lua_error(e, a)
tex.print([[\noexpand\csname bbl@error\endcsname{]] ..
e .. '}{' .. (a or '') .. '}{}{}')
end
function Babel.bytes(line)
return line:gsub("(.)",
function (chr) return unicode.utf8.char(string.byte(chr)) end)
end
function Babel.priority_in_callback(name,description)
for i,v in ipairs(luatexbase.callback_descriptions(name)) do
if v == description then return i end
end
return false
end
function Babel.begin_process_input()
if luatexbase and luatexbase.add_to_callback then
luatexbase.add_to_callback('process_input_buffer',
Babel.bytes,'Babel.bytes')
else
Babel.callback = callback.find('process_input_buffer')
callback.register('process_input_buffer',Babel.bytes)
end
end
function Babel.end_process_input ()
if luatexbase and luatexbase.remove_from_callback then
luatexbase.remove_from_callback('process_input_buffer','Babel.bytes')
else
callback.register('process_input_buffer',Babel.callback)
end
end
function Babel.str_to_nodes(fn, matches, base)
local n, head, last
if fn == nil then return nil end
for s in string.utfvalues(fn(matches)) do
if base.id == 7 then
base = base.replace
end
n = node.copy(base)
n.char = s
if not head then
head = n
else
last.next = n
end
last = n
end
return head
end
Babel.linebreaking = Babel.linebreaking or {}
Babel.linebreaking.before = {}
Babel.linebreaking.after = {}
Babel.locale = {}
function Babel.linebreaking.add_before(func, pos)
tex.print([[\noexpand\csname bbl@luahyphenate\endcsname]])
if pos == nil then
table.insert(Babel.linebreaking.before, func)
else
table.insert(Babel.linebreaking.before, pos, func)
end
end
function Babel.linebreaking.add_after(func)
tex.print([[\noexpand\csname bbl@luahyphenate\endcsname]])
table.insert(Babel.linebreaking.after, func)
end
function Babel.addpatterns(pp, lg)
local lg = lang.new(lg)
local pats = lang.patterns(lg) or ''
lang.clear_patterns(lg)
for p in pp:gmatch('[^%s]+') do
ss = ''
for i in string.utfcharacters(p:gsub('%d', '')) do
ss = ss .. '%d?' .. i
end
ss = ss:gsub('^%%d%?%.', '%%.') .. '%d?'
ss = ss:gsub('%.%%d%?$', '%%.')
pats, n = pats:gsub('%s' .. ss .. '%s', ' ' .. p .. ' ')
if n == 0 then
tex.sprint(
[[\string\csname\space bbl@info\endcsname{New pattern: ]]
.. p .. [[}]])
pats = pats .. ' ' .. p
else
tex.sprint(
[[\string\csname\space bbl@info\endcsname{Renew pattern: ]]
.. p .. [[}]])
end
end
lang.patterns(lg, pats)
end
Babel.characters = Babel.characters or {}
Babel.ranges = Babel.ranges or {}
function Babel.hlist_has_bidi(head)
local has_bidi = false
local ranges = Babel.ranges
for item in node.traverse(head) do
if item.id == node.id'glyph' then
local itemchar = item.char
local chardata = Babel.characters[itemchar]
local dir = chardata and chardata.d or nil
if not dir then
for nn, et in ipairs(ranges) do
if itemchar < et[1] then
break
elseif itemchar <= et[2] then
dir = et[3]
break
end
end
end
if dir and (dir == 'al' or dir == 'r') then
has_bidi = true
end
end
end
return has_bidi
end
function Babel.set_chranges_b (script, chrng)
if chrng == '' then return end
texio.write('Replacing ' .. script .. ' script ranges')
Babel.script_blocks[script] = {}
for s, e in string.gmatch(chrng..' ', '(.-)%.%.(.-)%s') do
table.insert(
Babel.script_blocks[script], {tonumber(s,16), tonumber(e,16)})
end
end
function Babel.discard_sublr(str)
if str:find( [[\string\indexentry]] ) and
str:find( [[\string\babelsublr]] ) then
str = str:gsub( [[\string\babelsublr%s*(%b{})]],
function(m) return m:sub(2,-2) end )
end
return str
end
}
\endgroup
\ifx\newattribute\@undefined\else % Test for plain
\newattribute\bbl@attr@locale % DL4
\directlua{ Babel.attr_locale = luatexbase.registernumber'bbl@attr@locale' }
\AddBabelHook{luatex}{beforeextras}{%
\setattribute\bbl@attr@locale\localeid}
\fi
%
\def\BabelStringsDefault{unicode}
\let\luabbl@stop\relax
\AddBabelHook{luatex}{encodedcommands}{%
\def\bbl@tempa{utf8}\def\bbl@tempb{#1}%
\ifx\bbl@tempa\bbl@tempb\else
\directlua{Babel.begin_process_input()}%
\def\luabbl@stop{%
\directlua{Babel.end_process_input()}}%
\fi}%
\AddBabelHook{luatex}{stopcommands}{%
\luabbl@stop
\let\luabbl@stop\relax}
%
\AddBabelHook{luatex}{patterns}{%
\@ifundefined{bbl@hyphendata@\the\language}%
{\def\bbl@elt##1##2##3##4{%
\ifnum##2=\csname l@#2\endcsname % #2=spanish, dutch:OT1...
\def\bbl@tempb{##3}%
\ifx\bbl@tempb\@empty\else % if not a synonymous
\def\bbl@tempc{{##3}{##4}}%
\fi
\bbl@csarg\xdef{hyphendata@##2}{\bbl@tempc}%
\fi}%
\bbl@languages
\@ifundefined{bbl@hyphendata@\the\language}%
{\bbl@info{No hyphenation patterns were set for\\%
language '#2'. Reported}}%
{\expandafter\expandafter\expandafter\bbl@luapatterns
\csname bbl@hyphendata@\the\language\endcsname}}{}%
\@ifundefined{bbl@patterns@}{}{%
\begingroup
\bbl@xin@{,\number\language,}{,\bbl@pttnlist}%
\ifin@\else
\ifx\bbl@patterns@\@empty\else
\directlua{ Babel.addpatterns(
[[\bbl@patterns@]], \number\language) }%
\fi
\@ifundefined{bbl@patterns@#1}%
\@empty
{\directlua{ Babel.addpatterns(
[[\space\csname bbl@patterns@#1\endcsname]],
\number\language) }}%
\xdef\bbl@pttnlist{\bbl@pttnlist\number\language,}%
\fi
\endgroup}%
\bbl@exp{%
\bbl@ifunset{bbl@prehc@\languagename}{}%
{\\\bbl@ifblank{\bbl@cs{prehc@\languagename}}{}%
{\prehyphenchar=\bbl@cl{prehc}\relax}}}}
% \end{macrocode}
%
% \macro{\babelpatterns}
%
% This macro adds patterns. Two macros are used to store them:
% |\bbl@patterns@| for the global ones and |\bbl@patterns@<language>| for
% language ones. We make sure there is a space between words when
% multiple commands are used.
%
% \begin{macrocode}
\@onlypreamble\babelpatterns
\AtEndOfPackage{%
\newcommand\babelpatterns[2][\@empty]{%
\ifx\bbl@patterns@\relax
\let\bbl@patterns@\@empty
\fi
\ifx\bbl@pttnlist\@empty\else
\bbl@warning{%
You must not intermingle \string\selectlanguage\space and\\%
\string\babelpatterns\space or some patterns will not\\%
be taken into account. Reported}%
\fi
\ifx\@empty#1%
\protected@edef\bbl@patterns@{\bbl@patterns@\space#2}%
\else
\edef\bbl@tempb{\zap@space#1 \@empty}%
\bbl@for\bbl@tempa\bbl@tempb{%
\bbl@fixname\bbl@tempa
\bbl@iflanguage\bbl@tempa{%
\bbl@csarg\protected@edef{patterns@\bbl@tempa}{%
\@ifundefined{bbl@patterns@\bbl@tempa}%
\@empty
{\csname bbl@patterns@\bbl@tempa\endcsname\space}%
#2}}}%
\fi}}
% \end{macrocode}
%
% \subsection{Southeast Asian scripts}
%
% First, some general code for line breaking, used by
% |\babelposthyphenation|.
%
% Replace regular (i.e., implicit) discretionaries by spaceskips, based
% on the previous glyph (which I think makes sense, because the hyphen
% and the previous char go always together). Other discretionaries are
% not touched. See Unicode UAX 14.
%
% \begin{macrocode}
\def\bbl@intraspace#1 #2 #3\@@{%
\directlua{
Babel.intraspaces = Babel.intraspaces or {}
Babel.intraspaces['\csname bbl@sbcp@\languagename\endcsname'] = %
{b = #1, p = #2, m = #3}
Babel.locale_props[\the\localeid].intraspace = %
{b = #1, p = #2, m = #3}
}}
\def\bbl@intrapenalty#1\@@{%
\directlua{
Babel.intrapenalties = Babel.intrapenalties or {}
Babel.intrapenalties['\csname bbl@sbcp@\languagename\endcsname'] = #1
Babel.locale_props[\the\localeid].intrapenalty = #1
}}
\begingroup
\catcode`\%=12
\catcode`\&=14
\catcode`\'=12
\catcode`\~=12
\gdef\bbl@seaintraspace{&
\let\bbl@seaintraspace\relax
\directlua{
Babel.sea_enabled = true
Babel.sea_ranges = Babel.sea_ranges or {}
function Babel.set_chranges (script, chrng)
local c = 0
for s, e in string.gmatch(chrng..' ', '(.-)%.%.(.-)%s') do
Babel.sea_ranges[script..c]={tonumber(s,16), tonumber(e,16)}
c = c + 1
end
end
function Babel.sea_disc_to_space (head)
local sea_ranges = Babel.sea_ranges
local last_char = nil
local quad = 655360 &% 10 pt = 655360 = 10 * 65536
for item in node.traverse(head) do
local i = item.id
if i == node.id'glyph' then
last_char = item
elseif i == 7 and item.subtype == 3 and last_char
and last_char.char > 0x0C99 then
quad = font.getfont(last_char.font).size
for lg, rg in pairs(sea_ranges) do
if last_char.char > rg[1] and last_char.char < rg[2] then
lg = lg:sub(1, 4) &% Remove trailing number of, e.g., Cyrl1
local intraspace = Babel.intraspaces[lg]
local intrapenalty = Babel.intrapenalties[lg]
local n
if intrapenalty ~= 0 then
n = node.new(14, 0) &% penalty
n.penalty = intrapenalty
node.insert_before(head, item, n)
end
n = node.new(12, 13) &% (glue, spaceskip)
node.setglue(n, intraspace.b * quad,
intraspace.p * quad,
intraspace.m * quad)
node.insert_before(head, item, n)
node.remove(head, item)
end
end
end
end
end
}&
\bbl@luahyphenate}
% \end{macrocode}
%
% \subsection{CJK line breaking}
%
% Minimal line breaking for CJK scripts, mainly intended for simple
% documents and short texts as a secondary language. Only line
% breaking, with a little stretching for justification, without any
% attempt to adjust the spacing. It is based on (but does not strictly
% follow) the Unicode algorithm.
%
% We first need a little table with the corresponding line breaking
% properties. A few characters have an additional key for the width
% (fullwidth \textit{vs.} halfwidth), not yet used. There is a separate
% file, defined below.
%
% \begin{macrocode}
\catcode`\%=14
\gdef\bbl@cjkintraspace{%
\let\bbl@cjkintraspace\relax
\directlua{
require('babel-data-cjk.lua')
Babel.cjk_enabled = true
function Babel.cjk_linebreak(head)
local GLYPH = node.id'glyph'
local last_char = nil
local quad = 655360 % 10 pt = 655360 = 10 * 65536
local last_class = nil
local last_lang = nil
for item in node.traverse(head) do
if item.id == GLYPH then
local lang = item.lang
local LOCALE = node.get_attribute(item,
Babel.attr_locale)
local props = Babel.locale_props[LOCALE] or {}
local class = Babel.cjk_class[item.char].c
if props.cjk_quotes and props.cjk_quotes[item.char] then
class = props.cjk_quotes[item.char]
end
if class == 'cp' then class = 'cl' % )] as CL
elseif class == 'id' then class = 'I'
elseif class == 'cj' then class = 'I' % loose
end
local br = 0
if class and last_class and Babel.cjk_breaks[last_class][class] then
br = Babel.cjk_breaks[last_class][class]
end
if br == 1 and props.linebreak == 'c' and
lang ~= \the\l@nohyphenation\space and
last_lang ~= \the\l@nohyphenation then
local intrapenalty = props.intrapenalty
if intrapenalty ~= 0 then
local n = node.new(14, 0) % penalty
n.penalty = intrapenalty
node.insert_before(head, item, n)
end
local intraspace = props.intraspace
local n = node.new(12, 13) % (glue, spaceskip)
node.setglue(n, intraspace.b * quad,
intraspace.p * quad,
intraspace.m * quad)
node.insert_before(head, item, n)
end
if font.getfont(item.font) then
quad = font.getfont(item.font).size
end
last_class = class
last_lang = lang
else % if penalty, glue or anything else
last_class = nil
end
end
lang.hyphenate(head)
end
}%
\bbl@luahyphenate}
\gdef\bbl@luahyphenate{%
\let\bbl@luahyphenate\relax
\directlua{
luatexbase.add_to_callback('hyphenate',
function (head, tail)
if Babel.linebreaking.before then
for k, func in ipairs(Babel.linebreaking.before) do
func(head)
end
end
lang.hyphenate(head)
if Babel.cjk_enabled then
Babel.cjk_linebreak(head)
end
if Babel.linebreaking.after then
for k, func in ipairs(Babel.linebreaking.after) do
func(head)
end
end
if Babel.set_hboxed then
Babel.set_hboxed(head)
end
if Babel.sea_enabled then
Babel.sea_disc_to_space(head)
end
end,
'Babel.hyphenate')
}}
\endgroup
%
\def\bbl@provide@intraspace{%
\bbl@ifunset{bbl@intsp@\languagename}{}%
{\expandafter\ifx\csname bbl@intsp@\languagename\endcsname\@empty\else
\bbl@xin@{/c}{/\bbl@cl{lnbrk}}%
\ifin@ % cjk
\bbl@cjkintraspace
\directlua{
Babel.locale_props = Babel.locale_props or {}
Babel.locale_props[\the\localeid].linebreak = 'c'
}%
\bbl@exp{\\\bbl@intraspace\bbl@cl{intsp}\\\@@}%
\ifx\bbl@KVP@intrapenalty\@nnil
\bbl@intrapenalty0\@@
\fi
\else % sea
\bbl@seaintraspace
\bbl@exp{\\\bbl@intraspace\bbl@cl{intsp}\\\@@}%
\directlua{
Babel.sea_ranges = Babel.sea_ranges or {}
Babel.set_chranges('\bbl@cl{sbcp}',
'\bbl@cl{chrng}')
}%
\ifx\bbl@KVP@intrapenalty\@nnil
\bbl@intrapenalty0\@@
\fi
\fi
\fi
\ifx\bbl@KVP@intrapenalty\@nnil\else
\expandafter\bbl@intrapenalty\bbl@KVP@intrapenalty\@@
\fi}}
% \end{macrocode}
%
% \subsection{Arabic justification}
%
% WIP. |\bbl@arabicjust| is executed with both elongated an kashida.
% This must be fine tuned. The attribute kashida is set by transforms
% with |kashida|.
%
% \begin{macrocode}
\ifnum\bbl@bidimode>100 \ifnum\bbl@bidimode<200
\def\bblar@chars{%
0628,0629,062A,062B,062C,062D,062E,062F,0630,0631,0632,0633,%
0634,0635,0636,0637,0638,0639,063A,063B,063C,063D,063E,063F,%
0640,0641,0642,0643,0644,0645,0646,0647,0649}
\def\bblar@elongated{%
0626,0628,062A,062B,0633,0634,0635,0636,063B,%
063C,063D,063E,063F,0641,0642,0643,0644,0646,%
0649,064A}
\begingroup
\catcode`_=11 \catcode`:=11
\gdef\bblar@nofswarn{\gdef\msg_warning:nnx##1##2##3{}}
\endgroup
\gdef\bbl@arabicjust{%
\let\bbl@arabicjust\relax
\newattribute\bblar@kashida
\directlua{ Babel.attr_kashida = luatexbase.registernumber'bblar@kashida' }%
\bblar@kashida=\z@
\bbl@patchfont{{\bbl@parsejalt}}%
\directlua{
Babel.arabic.elong_map = Babel.arabic.elong_map or {}
Babel.arabic.elong_map[\the\localeid] = {}
luatexbase.add_to_callback('post_linebreak_filter',
Babel.arabic.justify, 'Babel.arabic.justify')
luatexbase.add_to_callback('hpack_filter',
Babel.arabic.justify_hbox, 'Babel.arabic.justify_hbox')
}}%
% \end{macrocode}
%
% Save both node lists to make replacement.
%
% \begin{macrocode}
\def\bblar@fetchjalt#1#2#3#4{%
\bbl@exp{\\\bbl@foreach{#1}}{%
\bbl@ifunset{bblar@JE@##1}%
{\setbox\z@\hbox{\textdir TRT ^^^^200d\char"##1#2}}%
{\setbox\z@\hbox{\textdir TRT ^^^^200d\char"\@nameuse{bblar@JE@##1}#2}}%
\directlua{%
local last = nil
for item in node.traverse(tex.box[0].head) do
if item.id == node.id'glyph' and item.char > 0x600 and
not (item.char == 0x200D) then
last = item
end
end
Babel.arabic.#3['##1#4'] = last.char
}}}
% \end{macrocode}
%
% Elongated forms. Brute force. No rules at all, yet. The ideal: look
% at jalt table. And perhaps other tables (falt?, cswh?). What about
% kaf? And diacritic positioning?
%
% \begin{macrocode}
\gdef\bbl@parsejalt{%
\ifx\addfontfeature\@undefined\else
\bbl@xin@{/e}{/\bbl@cl{lnbrk}}%
\ifin@
\directlua{%
if Babel.arabic.elong_map[\the\localeid][\fontid\font] == nil then
Babel.arabic.elong_map[\the\localeid][\fontid\font] = {}
tex.print([[\string\csname\space bbl@parsejalti\endcsname]])
end
}%
\fi
\fi}
\gdef\bbl@parsejalti{%
\begingroup
\let\bbl@parsejalt\relax % To avoid infinite loop
\edef\bbl@tempb{\fontid\font}%
\bblar@nofswarn
\bblar@fetchjalt\bblar@elongated{}{from}{}%
\bblar@fetchjalt\bblar@chars{^^^^064a}{from}{a}% Alef maksura
\bblar@fetchjalt\bblar@chars{^^^^0649}{from}{y}% Yeh
\addfontfeature{RawFeature=+jalt}%
% \@namedef{bblar@JE@0643}{06AA}% todo: catch medial kaf
\bblar@fetchjalt\bblar@elongated{}{dest}{}%
\bblar@fetchjalt\bblar@chars{^^^^064a}{dest}{a}%
\bblar@fetchjalt\bblar@chars{^^^^0649}{dest}{y}%
\directlua{%
for k, v in pairs(Babel.arabic.from) do
if Babel.arabic.dest[k] and
not (Babel.arabic.from[k] == Babel.arabic.dest[k]) then
Babel.arabic.elong_map[\the\localeid][\bbl@tempb]
[Babel.arabic.from[k]] = Babel.arabic.dest[k]
end
end
}%
\endgroup}
% \end{macrocode}
%
% The actual justification (inspired by \textsc{chickenize}).
%
% \begin{macrocode}
\begingroup
\catcode`#=11
\catcode`~=11
\directlua{
Babel.arabic = Babel.arabic or {}
Babel.arabic.from = {}
Babel.arabic.dest = {}
Babel.arabic.justify_factor = 0.95
Babel.arabic.justify_enabled = true
Babel.arabic.kashida_limit = -1
function Babel.arabic.justify(head)
if not Babel.arabic.justify_enabled then return head end
for line in node.traverse_id(node.id'hlist', head) do
Babel.arabic.justify_hlist(head, line)
end
% In case the very first item is a line (eg, in \vbox):
while head.prev do head = head.prev end
return head
end
function Babel.arabic.justify_hbox(head, gc, size, pack)
local has_inf = false
if Babel.arabic.justify_enabled and pack == 'exactly' then
for n in node.traverse_id(12, head) do
if n.stretch_order > 0 then has_inf = true end
end
if not has_inf then
Babel.arabic.justify_hlist(head, nil, gc, size, pack)
end
end
return head
end
function Babel.arabic.justify_hlist(head, line, gc, size, pack)
local d, new
local k_list, k_item, pos_inline
local width, width_new, full, k_curr, wt_pos, goal, shift
local subst_done = false
local elong_map = Babel.arabic.elong_map
local cnt
local last_line
local GLYPH = node.id'glyph'
local KASHIDA = Babel.attr_kashida
local LOCALE = Babel.attr_locale
if line == nil then
line = {}
line.glue_sign = 1
line.glue_order = 0
line.head = head
line.shift = 0
line.width = size
end
% Exclude last line. todo. But-- it discards one-word lines, too!
% ? Look for glue = 12:15
if (line.glue_sign == 1 and line.glue_order == 0) then
elongs = {} % Stores elongated candidates of each line
k_list = {} % And all letters with kashida
pos_inline = 0 % Not yet used
for n in node.traverse_id(GLYPH, line.head) do
pos_inline = pos_inline + 1 % To find where it is. Not used.
% Elongated glyphs
if elong_map then
local locale = node.get_attribute(n, LOCALE)
if elong_map[locale] and elong_map[locale][n.font] and
elong_map[locale][n.font][n.char] then
table.insert(elongs, {node = n, locale = locale} )
node.set_attribute(n.prev, KASHIDA, 0)
end
end
% Tatwil. First create a list of nodes marked with kashida. The
% rest of nodes can be ignored. The list of used weigths is build
% when transforms with the key kashida= are declared.
if Babel.kashida_wts then
local k_wt = node.get_attribute(n, KASHIDA)
if k_wt > 0 then % todo. parameter for multi inserts
table.insert(k_list, {node = n, weight = k_wt, pos = pos_inline})
end
end
end % of node.traverse_id
if #elongs == 0 and #k_list == 0 then goto next_line end
full = line.width
shift = line.shift
goal = full * Babel.arabic.justify_factor % A bit crude
width = node.dimensions(line.head) % The 'natural' width
% == Elongated ==
% Original idea taken from 'chikenize'
while (#elongs > 0 and width < goal) do
subst_done = true
local x = #elongs
local curr = elongs[x].node
local oldchar = curr.char
curr.char = elong_map[elongs[x].locale][curr.font][curr.char]
width = node.dimensions(line.head) % Check if the line is too wide
% Substitute back if the line would be too wide and break:
if width > goal then
curr.char = oldchar
break
end
% If continue, pop the just substituted node from the list:
table.remove(elongs, x)
end
% == Tatwil ==
% Traverse the kashida node list so many times as required, until
% the line if filled. The first pass adds a tatweel after each
% node with kashida in the line, the second pass adds another one,
% and so on. In each pass, add first the kashida with the highest
% weight, then with lower weight and so on.
if #k_list == 0 then goto next_line end
width = node.dimensions(line.head) % The 'natural' width
k_curr = #k_list % Traverse backwards, from the end
wt_pos = 1
while width < goal do
subst_done = true
k_item = k_list[k_curr].node
if k_list[k_curr].weight == Babel.kashida_wts[wt_pos] then
d = node.copy(k_item)
d.char = 0x0640
d.yoffset = 0 % TODO. From the prev char. But 0 seems safe.
d.xoffset = 0
line.head, new = node.insert_after(line.head, k_item, d)
width_new = node.dimensions(line.head)
if width > goal or width == width_new then
node.remove(line.head, new) % Better compute before
break
end
if Babel.fix_diacr then
Babel.fix_diacr(k_item.next)
end
width = width_new
end
if k_curr == 1 then
k_curr = #k_list
wt_pos = (wt_pos >= table.getn(Babel.kashida_wts)) and 1 or wt_pos+1
else
k_curr = k_curr - 1
end
end
% Limit the number of tatweel by removing them. Not very efficient,
% but it does the job in a quite predictable way.
if Babel.arabic.kashida_limit > -1 then
cnt = 0
for n in node.traverse_id(GLYPH, line.head) do
if n.char == 0x0640 then
cnt = cnt + 1
if cnt > Babel.arabic.kashida_limit then
node.remove(line.head, n)
end
else
cnt = 0
end
end
end
::next_line::
% Must take into account marks and ins, see luatex manual.
% Have to be executed only if there are changes. Investigate
% what's going on exactly.
if subst_done and not gc then
d = node.hpack(line.head, full, 'exactly')
d.shift = shift
node.insert_before(head, line, d)
node.remove(head, line)
end
end % if process line
end
}
\endgroup
\fi\fi % ends Arabic just block: \ifnum\bbl@bidimode>100...
% \end{macrocode}
%
% \subsection{Common stuff}
%
% First, a couple of auxiliary macros to set the renderer according
% to the script. This is done by patching temporarily the low-level
% \textsf{fontspec} macro containing the current features set with
% |\defaultfontfeatures|. Admittedly this is somewhat dangerous, but
% that way the latter command still works as expected, because the
% renderer is set just before other settings. In \xetex\ they are set
% to |\relax|.
%
% \begin{macrocode}
\def\bbl@scr@node@list{%
,Armenian,Coptic,Cyrillic,Georgian,,Glagolitic,Gothic,%
,Greek,Latin,Old Church Slavonic Cyrillic,}
\ifnum\bbl@bidimode=102 % bidi-r
\bbl@add\bbl@scr@node@list{Arabic,Hebrew,Syriac}
\fi
\def\bbl@set@renderer{%
\bbl@xin@{\bbl@cl{sname}}{\bbl@scr@node@list}%
\ifin@
\let\bbl@unset@renderer\relax
\else
\bbl@exp{%
\def\\\bbl@unset@renderer{%
\def\<g__fontspec_default_fontopts_clist>{%
\[g__fontspec_default_fontopts_clist]}}%
\def\<g__fontspec_default_fontopts_clist>{%
Renderer=Harfbuzz,\[g__fontspec_default_fontopts_clist]}}%
\fi}
<@Font selection@>
% \end{macrocode}
%
% \subsection{Automatic fonts and ids switching}
%
% After defining the blocks for a number of scripts (must be extended
% and very likely fine tuned), we define a the function
% |Babel.locale_map|, which just traverse the node list to carry out
% the replacements. The table |loc_to_scr| stores the script range for
% each locale (whose id is the key), copied from this table (so that it
% can be modified on a locale basis); there is an intermediate table
% named |chr_to_loc| built on the fly for optimization, which maps a
% char to the locale. This locale is then used to get the |\language|
% as stored in |locale_props|, as well as the font (as requested). In
% the latter table a key starting with |/| maps the font from the
% global one (the key) to the local one (the value). Maths are skipped
% and discretionaries are handled in a special way.
%
% \begin{macrocode}
\directlua{% DL6
Babel.script_blocks = {
['dflt'] = {},
['Arab'] = {{0x0600, 0x06FF}, {0x08A0, 0x08FF}, {0x0750, 0x077F},
{0xFE70, 0xFEFF}, {0xFB50, 0xFDFF}, {0x1EE00, 0x1EEFF}},
['Armn'] = {{0x0530, 0x058F}},
['Beng'] = {{0x0980, 0x09FF}},
['Cher'] = {{0x13A0, 0x13FF}, {0xAB70, 0xABBF}},
['Copt'] = {{0x03E2, 0x03EF}, {0x2C80, 0x2CFF}, {0x102E0, 0x102FF}},
['Cyrl'] = {{0x0400, 0x04FF}, {0x0500, 0x052F}, {0x1C80, 0x1C8F},
{0x2DE0, 0x2DFF}, {0xA640, 0xA69F}},
['Deva'] = {{0x0900, 0x097F}, {0xA8E0, 0xA8FF}},
['Ethi'] = {{0x1200, 0x137F}, {0x1380, 0x139F}, {0x2D80, 0x2DDF},
{0xAB00, 0xAB2F}},
['Geor'] = {{0x10A0, 0x10FF}, {0x2D00, 0x2D2F}},
% Don't follow strictly Unicode, which places some Coptic letters in
% the 'Greek and Coptic' block
['Grek'] = {{0x0370, 0x03E1}, {0x03F0, 0x03FF}, {0x1F00, 0x1FFF}},
['Hans'] = {{0x2E80, 0x2EFF}, {0x3000, 0x303F}, {0x31C0, 0x31EF},
{0x3300, 0x33FF}, {0x3400, 0x4DBF}, {0x4E00, 0x9FFF},
{0xF900, 0xFAFF}, {0xFE30, 0xFE4F}, {0xFF00, 0xFFEF},
{0x20000, 0x2A6DF}, {0x2A700, 0x2B73F},
{0x2B740, 0x2B81F}, {0x2B820, 0x2CEAF},
{0x2CEB0, 0x2EBEF}, {0x2F800, 0x2FA1F}},
['Hebr'] = {{0x0590, 0x05FF},
{0xFB1F, 0xFB4E}}, % <- Includes some <reserved>
['Jpan'] = {{0x3000, 0x303F}, {0x3040, 0x309F}, {0x30A0, 0x30FF},
{0x4E00, 0x9FAF}, {0xFF00, 0xFFEF}},
['Khmr'] = {{0x1780, 0x17FF}, {0x19E0, 0x19FF}},
['Knda'] = {{0x0C80, 0x0CFF}},
['Kore'] = {{0x1100, 0x11FF}, {0x3000, 0x303F}, {0x3130, 0x318F},
{0x4E00, 0x9FAF}, {0xA960, 0xA97F}, {0xAC00, 0xD7AF},
{0xD7B0, 0xD7FF}, {0xFF00, 0xFFEF}},
['Laoo'] = {{0x0E80, 0x0EFF}},
['Latn'] = {{0x0000, 0x007F}, {0x0080, 0x00FF}, {0x0100, 0x017F},
{0x0180, 0x024F}, {0x1E00, 0x1EFF}, {0x2C60, 0x2C7F},
{0xA720, 0xA7FF}, {0xAB30, 0xAB6F}},
['Mahj'] = {{0x11150, 0x1117F}},
['Mlym'] = {{0x0D00, 0x0D7F}},
['Mymr'] = {{0x1000, 0x109F}, {0xAA60, 0xAA7F}, {0xA9E0, 0xA9FF}},
['Orya'] = {{0x0B00, 0x0B7F}},
['Sinh'] = {{0x0D80, 0x0DFF}, {0x111E0, 0x111FF}},
['Syrc'] = {{0x0700, 0x074F}, {0x0860, 0x086F}},
['Taml'] = {{0x0B80, 0x0BFF}},
['Telu'] = {{0x0C00, 0x0C7F}},
['Tfng'] = {{0x2D30, 0x2D7F}},
['Thai'] = {{0x0E00, 0x0E7F}},
['Tibt'] = {{0x0F00, 0x0FFF}},
['Vaii'] = {{0xA500, 0xA63F}},
['Yiii'] = {{0xA000, 0xA48F}, {0xA490, 0xA4CF}}
}
Babel.script_blocks.Cyrs = Babel.script_blocks.Cyrl
Babel.script_blocks.Hant = Babel.script_blocks.Hans
Babel.script_blocks.Kana = Babel.script_blocks.Jpan
function Babel.locale_map(head)
if not Babel.locale_mapped then return head end
local LOCALE = Babel.attr_locale
local GLYPH = node.id('glyph')
local inmath = false
local toloc_save
for item in node.traverse(head) do
local toloc
if not inmath and item.id == GLYPH then
% Optimization: build a table with the chars found
if Babel.chr_to_loc[item.char] then
toloc = Babel.chr_to_loc[item.char]
else
for lc, maps in pairs(Babel.loc_to_scr) do
for _, rg in pairs(maps) do
if item.char >= rg[1] and item.char <= rg[2] then
Babel.chr_to_loc[item.char] = lc
toloc = lc
break
end
end
end
% Treat composite chars in a different fashion, because they
% 'inherit' the previous locale.
if (item.char >= 0x0300 and item.char <= 0x036F) or
(item.char >= 0x1AB0 and item.char <= 0x1AFF) or
(item.char >= 0x1DC0 and item.char <= 0x1DFF) then
Babel.chr_to_loc[item.char] = -2000
toloc = -2000
end
if not toloc then
Babel.chr_to_loc[item.char] = -1000
end
end
if toloc == -2000 then
toloc = toloc_save
elseif toloc == -1000 then
toloc = nil
end
if toloc and Babel.locale_props[toloc] and
Babel.locale_props[toloc].letters and
tex.getcatcode(item.char) \string~= 11 then
toloc = nil
end
if toloc and Babel.locale_props[toloc].script
and Babel.locale_props[node.get_attribute(item, LOCALE)].script
and Babel.locale_props[toloc].script ==
Babel.locale_props[node.get_attribute(item, LOCALE)].script then
toloc = nil
end
if toloc then
if Babel.locale_props[toloc].lg then
item.lang = Babel.locale_props[toloc].lg
node.set_attribute(item, LOCALE, toloc)
end
if Babel.locale_props[toloc]['/'..item.font] then
item.font = Babel.locale_props[toloc]['/'..item.font]
end
end
toloc_save = toloc
elseif not inmath and item.id == 7 then % Apply recursively
item.replace = item.replace and Babel.locale_map(item.replace)
item.pre = item.pre and Babel.locale_map(item.pre)
item.post = item.post and Babel.locale_map(item.post)
elseif item.id == node.id'math' then
inmath = (item.subtype == 0)
end
end
return head
end
}
% \end{macrocode}
%
% The code for |\babelcharproperty| is straightforward. Just note the
% modified lua table can be different.
%
% \begin{macrocode}
\newcommand\babelcharproperty[1]{%
\count@=#1\relax
\ifvmode
\expandafter\bbl@chprop
\else
\bbl@error{charproperty-only-vertical}{}{}{}%
\fi}
\newcommand\bbl@chprop[3][\the\count@]{%
\@tempcnta=#1\relax
\bbl@ifunset{bbl@chprop@#2}% {unknown-char-property}
{\bbl@error{unknown-char-property}{}{#2}{}}%
{}%
\loop
\bbl@cs{chprop@#2}{#3}%
\ifnum\count@<\@tempcnta
\advance\count@\@ne
\repeat}
%
\def\bbl@chprop@direction#1{%
\directlua{
Babel.characters[\the\count@] = Babel.characters[\the\count@] or {}
Babel.characters[\the\count@]['d'] = '#1'
}}
\let\bbl@chprop@bc\bbl@chprop@direction
%
\def\bbl@chprop@mirror#1{%
\directlua{
Babel.characters[\the\count@] = Babel.characters[\the\count@] or {}
Babel.characters[\the\count@]['m'] = '\number#1'
}}
\let\bbl@chprop@bmg\bbl@chprop@mirror
%
\def\bbl@chprop@linebreak#1{%
\directlua{
Babel.cjk_characters[\the\count@] = Babel.cjk_characters[\the\count@] or {}
Babel.cjk_characters[\the\count@]['c'] = '#1'
}}
\let\bbl@chprop@lb\bbl@chprop@linebreak
%
\def\bbl@chprop@locale#1{%
\directlua{
Babel.chr_to_loc = Babel.chr_to_loc or {}
Babel.chr_to_loc[\the\count@] =
\bbl@ifblank{#1}{-1000}{\the\bbl@cs{id@@#1}}\space
}}
% \end{macrocode}
%
% Post-handling hyphenation patterns for non-standard rules, like |ff|
% to |ff-f|. There are still some issues with speed (not very slow, but
% still slow). The Lua code is below.
%
% \begin{macrocode}
\directlua{% DL7
Babel.nohyphenation = \the\l@nohyphenation
}
% \end{macrocode}
%
% Now the \TeX{} high level interface, which requires the function
% defined above for converting strings to functions returning a string.
% These functions handle the |{|\textit{n}|}| syntax. For example,
% |pre={1}{1}-| becomes |function(m) return m[1]..m[1]..'-' end|, where
% |m| are the matches returned after applying the pattern. With a
% mapped capture the functions are similar to
% |function(m) return Babel.capt_map(m[1],1) end|, where the last
% argument identifies the mapping to be applied to |m[1]|. The way it
% is carried out is somewhat tricky, but the effect in not dissimilar
% to lua |load| – save the code as string in a TeX macro, and expand
% this macro at the appropriate place. As |\directlua| does not take
% into account the current catcode of |@|, we just avoid this character
% in macro names (which explains the internal group, too).
%
% \begin{macrocode}
\begingroup
\catcode`\~=12
\catcode`\%=12
\catcode`\&=14
\catcode`\|=12
\gdef\babelprehyphenation{&%
\@ifnextchar[{\bbl@settransform{0}}{\bbl@settransform{0}[]}}
\gdef\babelposthyphenation{&%
\@ifnextchar[{\bbl@settransform{1}}{\bbl@settransform{1}[]}}
%
\gdef\bbl@settransform#1[#2]#3#4#5{&%
\ifcase#1
\bbl@activateprehyphen
\or
\bbl@activateposthyphen
\fi
\begingroup
\def\babeltempa{\bbl@add@list\babeltempb}&%
\let\babeltempb\@empty
\def\bbl@tempa{#5}&%
\bbl@replace\bbl@tempa{,}{ ,}&% TODO. Ugly trick to preserve {}
\expandafter\bbl@foreach\expandafter{\bbl@tempa}{&%
\bbl@ifsamestring{##1}{remove}&%
{\bbl@add@list\babeltempb{nil}}&%
{\directlua{
local rep = [=[##1]=]
local three_args = '%s*=%s*([%-%d%.%a{}|]+)%s+([%-%d%.%a{}|]+)%s+([%-%d%.%a{}|]+)'
&% Numeric passes directly: kern, penalty...
rep = rep:gsub('^%s*(remove)%s*$', 'remove = true')
rep = rep:gsub('^%s*(insert)%s*,', 'insert = true, ')
rep = rep:gsub('^%s*(after)%s*,', 'after = true, ')
rep = rep:gsub('(string)%s*=%s*([^%s,]*)', Babel.capture_func)
rep = rep:gsub('node%s*=%s*(%a+)%s*(%a*)', Babel.capture_node)
rep = rep:gsub( '(norule)' .. three_args,
'norule = {' .. '%2, %3, %4' .. '}')
if #1 == 0 or #1 == 2 then
rep = rep:gsub( '(space)' .. three_args,
'space = {' .. '%2, %3, %4' .. '}')
rep = rep:gsub( '(spacefactor)' .. three_args,
'spacefactor = {' .. '%2, %3, %4' .. '}')
rep = rep:gsub('(kashida)%s*=%s*([^%s,]*)', Babel.capture_kashida)
&% Transform values
rep, n = rep:gsub( '{([%a%-%.]+)|([%a%_%.]+)}',
function(v,d)
return string.format (
'{\the\csname bbl@id@@#3\endcsname,"%s",%s}',
v,
load( 'return Babel.locale_props'..
'[\the\csname bbl@id@@#3\endcsname].' .. d)() )
end )
rep, n = rep:gsub( '{([%a%-%.]+)|([%-%d%.]+)}',
'{\the\csname bbl@id@@#3\endcsname,"%1",%2}')
end
if #1 == 1 then
rep = rep:gsub( '(no)%s*=%s*([^%s,]*)', Babel.capture_func)
rep = rep:gsub( '(pre)%s*=%s*([^%s,]*)', Babel.capture_func)
rep = rep:gsub( '(post)%s*=%s*([^%s,]*)', Babel.capture_func)
end
tex.print([[\string\babeltempa{{]] .. rep .. [[}}]])
}}}&%
\bbl@foreach\babeltempb{&%
\bbl@forkv{{##1}}{&%
\in@{,####1,}{,nil,step,data,remove,insert,string,no,pre,no,&%
post,penalty,kashida,space,spacefactor,kern,node,after,norule,}&%
\ifin@\else
\bbl@error{bad-transform-option}{####1}{}{}&%
\fi}}&%
\let\bbl@kv@attribute\relax
\let\bbl@kv@label\relax
\let\bbl@kv@fonts\@empty
\let\bbl@kv@prepend\relax
\bbl@forkv{#2}{\bbl@csarg\edef{kv@##1}{##2}}&%
\ifx\bbl@kv@fonts\@empty\else\bbl@settransfont\fi
\ifx\bbl@kv@attribute\relax
\ifx\bbl@kv@label\relax\else
\bbl@exp{\\\bbl@trim@def\\\bbl@kv@fonts{\bbl@kv@fonts}}&%
\bbl@replace\bbl@kv@fonts{ }{,}&%
\edef\bbl@kv@attribute{bbl@ATR@\bbl@kv@label @#3@\bbl@kv@fonts}&%
\count@\z@
\def\bbl@elt##1##2##3{&%
\bbl@ifsamestring{#3,\bbl@kv@label}{##1,##2}&%
{\bbl@ifsamestring{\bbl@kv@fonts}{##3}&%
{\count@\@ne}&%
{\bbl@error{font-conflict-transforms}{}{}{}}}&%
{}}&%
\bbl@transfont@list
\ifnum\count@=\z@
\bbl@exp{\global\\\bbl@add\\\bbl@transfont@list
{\\\bbl@elt{#3}{\bbl@kv@label}{\bbl@kv@fonts}}}&%
\fi
\bbl@ifunset{\bbl@kv@attribute}&%
{\global\bbl@carg\newattribute{\bbl@kv@attribute}}&%
{}&%
\global\bbl@carg\setattribute{\bbl@kv@attribute}\@ne
\fi
\else
\edef\bbl@kv@attribute{\expandafter\bbl@stripslash\bbl@kv@attribute}&%
\fi
\directlua{
local lbkr = Babel.linebreaking.replacements[#1]
local u = unicode.utf8
local id, attr, label
if #1 == 0 then
id = \the\csname bbl@id@@#3\endcsname\space
else
id = \the\csname l@#3\endcsname\space
end
\ifx\bbl@kv@attribute\relax
attr = -1
\else
attr = luatexbase.registernumber'\bbl@kv@attribute'
\fi
\ifx\bbl@kv@label\relax\else &% Same refs:
label = [==[\bbl@kv@label]==]
\fi
&% Convert pattern:
local patt = string.gsub([==[#4]==], '%s', '')
if #1 == 0 then
patt = string.gsub(patt, '|', ' ')
end
if not u.find(patt, '()', nil, true) then
patt = '()' .. patt .. '()'
end
if #1 == 1 then
patt = string.gsub(patt, '%(%)%^', '^()')
patt = string.gsub(patt, '%$%(%)', '()$')
end
patt = u.gsub(patt, '{(.)}',
function (n)
return '%' .. (tonumber(n) and (tonumber(n)+1) or n)
end)
patt = u.gsub(patt, '{(%x%x%x%x+)}',
function (n)
return u.gsub(u.char(tonumber(n, 16)), '(%p)', '%%%1')
end)
lbkr[id] = lbkr[id] or {}
table.insert(lbkr[id], \ifx\bbl@kv@prepend\relax\else 1,\fi
{ label=label, attr=attr, pattern=patt, replace={\babeltempb} })
}&%
\endgroup}
\endgroup
%
\let\bbl@transfont@list\@empty
\def\bbl@settransfont{%
\global\let\bbl@settransfont\relax % Execute only once
\gdef\bbl@transfont{%
\def\bbl@elt####1####2####3{%
\bbl@ifblank{####3}%
{\count@\tw@}% Do nothing if no fonts
{\count@\z@
\bbl@vforeach{####3}{%
\def\bbl@tempd{########1}%
\edef\bbl@tempe{\bbl@transfam/\f@series/\f@shape}%
\ifx\bbl@tempd\bbl@tempe
\count@\@ne
\else\ifx\bbl@tempd\bbl@transfam
\count@\@ne
\fi\fi}%
\ifcase\count@
\bbl@csarg\unsetattribute{ATR@####2@####1@####3}%
\or
\bbl@csarg\setattribute{ATR@####2@####1@####3}\@ne
\fi}}%
\bbl@transfont@list}%
\AddToHook{selectfont}{\bbl@transfont}% Hooks are global.
\gdef\bbl@transfam{-unknown-}%
\bbl@foreach\bbl@font@fams{%
\AddToHook{##1family}{\def\bbl@transfam{##1}}%
\bbl@ifsamestring{\@nameuse{##1default}}\familydefault
{\xdef\bbl@transfam{##1}}%
{}}}
%
\DeclareRobustCommand\enablelocaletransform[1]{%
\bbl@ifunset{bbl@ATR@#1@\languagename @}%
{\bbl@error{transform-not-available}{#1}{}{}}%
{\bbl@csarg\setattribute{ATR@#1@\languagename @}\@ne}}
\DeclareRobustCommand\disablelocaletransform[1]{%
\bbl@ifunset{bbl@ATR@#1@\languagename @}%
{\bbl@error{transform-not-available-b}{#1}{}{}}%
{\bbl@csarg\unsetattribute{ATR@#1@\languagename @}}}
% \end{macrocode}
%
% The following two macros load the Lua code for transforms, but only
% once. The only difference is in |add_after| and |add_before|.
%
% \begin{macrocode}
\def\bbl@activateposthyphen{%
\let\bbl@activateposthyphen\relax
\ifx\bbl@attr@hboxed\@undefined
\newattribute\bbl@attr@hboxed
\fi
\directlua{
require('babel-transforms.lua')
Babel.linebreaking.add_after(Babel.post_hyphenate_replace)
}}
\def\bbl@activateprehyphen{%
\let\bbl@activateprehyphen\relax
\ifx\bbl@attr@hboxed\@undefined
\newattribute\bbl@attr@hboxed
\fi
\directlua{
require('babel-transforms.lua')
Babel.linebreaking.add_before(Babel.pre_hyphenate_replace)
}}
\newcommand\SetTransformValue[3]{%
\directlua{
Babel.locale_props[\the\csname bbl@id@@#1\endcsname].vars["#2"] = #3
}}
% \end{macrocode}
%
% The code in |babel-transforms.lua| prints at some points the current
% string being transformed. This macro first make sure this file is
% loaded. Then, activates temporarily this feature and typeset inside a
% box the text in the argument.
%
% \begin{macrocode}
\newcommand\ShowBabelTransforms[1]{%
\bbl@activateprehyphen
\bbl@activateposthyphen
\begingroup
\directlua{ Babel.show_transforms = true }%
\setbox\z@\vbox{#1}%
\directlua{ Babel.show_transforms = false }%
\endgroup}
% \end{macrocode}
%
% The following experimental (and unfinished) macro applies the
% prehyphenation transforms for the current locale to a string
% (characters and spaces) and processes it in a fully expandable way
% (among other limitations, the string can’t contain |]==]|). The way
% it operates is admittedly rather cumbersome: it converts the string
% to a node list, processes it, and converts it back to a string. The
% lua code is in the lua file below.
%
% \begin{macrocode}
\newcommand\localeprehyphenation[1]{%
\directlua{ Babel.string_prehyphenation([==[#1]==], \the\localeid) }}
% \end{macrocode}
%
% \subsection{Bidi}
%
% As a first step, add a handler for bidi and digits (and potentially
% other processes) just before \textsf{luaoftload} is applied, which is
% loaded by default by \LaTeX. Just in case, consider the possibility
% it has not been loaded.
%
% \begin{macrocode}
\def\bbl@activate@preotf{%
\let\bbl@activate@preotf\relax % only once
\directlua{
function Babel.pre_otfload_v(head)
if Babel.numbers and Babel.digits_mapped then
head = Babel.numbers(head)
end
if Babel.bidi_enabled then
head = Babel.bidi(head, false, dir)
end
return head
end
%
function Babel.pre_otfload_h(head, gc, sz, pt, dir)
if Babel.numbers and Babel.digits_mapped then
head = Babel.numbers(head)
end
if Babel.bidi_enabled then
head = Babel.bidi(head, false, dir)
end
return head
end
%
luatexbase.add_to_callback('pre_linebreak_filter',
Babel.pre_otfload_v,
'Babel.pre_otfload_v',
Babel.priority_in_callback('pre_linebreak_filter',
'luaotfload.node_processor') or nil)
%
luatexbase.add_to_callback('hpack_filter',
Babel.pre_otfload_h,
'Babel.pre_otfload_h',
Babel.priority_in_callback('hpack_filter',
'luaotfload.node_processor') or nil)
}}
% \end{macrocode}
%
% The basic setup. The output is modified at a very low level to set
% the |\bodydir| to the |\pagedir|. Sadly, we have to deal with boxes
% in math with basic, so the |\bbl@mathboxdir| hack is activated every
% math with the package option bidi=. The hack for the PUA is no longer
% necessary with |basic| (24.8), but it’s kept in |basic-r|.
%
% \begin{macrocode}
\breakafterdirmode=1
\ifnum\bbl@bidimode>\@ne % Any bidi= except default (=1)
\let\bbl@beforeforeign\leavevmode
\AtEndOfPackage{\EnableBabelHook{babel-bidi}}
\RequirePackage{luatexbase}
\bbl@activate@preotf
\directlua{
require('babel-data-bidi.lua')
\ifcase\expandafter\@gobbletwo\the\bbl@bidimode\or
require('babel-bidi-basic.lua')
\or
require('babel-bidi-basic-r.lua')
table.insert(Babel.ranges, {0xE000, 0xF8FF, 'on'})
table.insert(Babel.ranges, {0xF0000, 0xFFFFD, 'on'})
table.insert(Babel.ranges, {0x100000, 0x10FFFD, 'on'})
\fi}
\newattribute\bbl@attr@dir
\directlua{ Babel.attr_dir = luatexbase.registernumber'bbl@attr@dir' }
\bbl@exp{\output{\bodydir\pagedir\the\output}}
\fi
%
\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')
else
tex.sprint('0')
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}
% \end{macrocode}
%
% |\bbl@attr@dir| stores the directions with a mask: |..00PPTT|, with
% masks 0xC (|PP| is the par dir) and 0x3 (|TT| is the text dir).
%
% \begin{macrocode}
\def\bbl@thedir{0}
\def\bbl@textdir#1{%
\bbl@setluadir{text}\textdir{#1}%
\chardef\bbl@thetextdir#1\relax
\edef\bbl@thedir{\the\numexpr\bbl@thepardir*4+#1}%
\setattribute\bbl@attr@dir{\numexpr\bbl@thepardir*4+#1}}
\def\bbl@pardir#1{% Used twice
\bbl@setluadir{par}\pardir{#1}%
\chardef\bbl@thepardir#1\relax}
\def\bbl@bodydir{\bbl@setluadir{body}\bodydir}% Used once
\def\bbl@pagedir{\bbl@setluadir{page}\pagedir}% Unused
\def\bbl@dirparastext{\pardir\the\textdir\relax}% Used once
% \end{macrocode}
%
% RTL text inside math needs special attention. It affects not only to
% actual math stuff, but also to `tabular`, which is based on a fake
% math.
%
% \begin{macrocode}
\ifnum\bbl@bidimode>\z@ % Any bidi=
\def\bbl@insidemath{0}%
\def\bbl@everymath{\def\bbl@insidemath{1}}
\def\bbl@everydisplay{\def\bbl@insidemath{2}}
\frozen@everymath\expandafter{%
\expandafter\bbl@everymath\the\frozen@everymath}
\frozen@everydisplay\expandafter{%
\expandafter\bbl@everydisplay\the\frozen@everydisplay}
\AtBeginDocument{
\directlua{
function Babel.math_box_dir(head)
if not (token.get_macro('bbl@insidemath') == '0') then
if Babel.hlist_has_bidi(head) then
local d = node.new(node.id'dir')
d.dir = '+TRT'
node.insert_before(head, node.has_glyph(head), d)
local inmath = false
for item in node.traverse(head) do
if item.id == 11 then
inmath = (item.subtype == 0)
elseif not inmath then
node.set_attribute(item,
Babel.attr_dir, token.get_macro('bbl@thedir'))
end
end
end
end
return head
end
luatexbase.add_to_callback("hpack_filter", Babel.math_box_dir,
"Babel.math_box_dir", 0)
if Babel.unset_atdir then
luatexbase.add_to_callback("pre_linebreak_filter", Babel.unset_atdir,
"Babel.unset_atdir")
luatexbase.add_to_callback("hpack_filter", Babel.unset_atdir,
"Babel.unset_atdir")
end
}}%
\fi
% \end{macrocode}
%
% Experimental. Tentative name.
%
% \begin{macrocode}
\DeclareRobustCommand\localebox[1]{%
{\def\bbl@insidemath{0}%
\mbox{\foreignlanguage{\languagename}{#1}}}}
% \end{macrocode}
%
% \subsection{Layout}
%
% Unlike \xetex{}, \luatex{} requires only minimal changes for
% right-to-left layouts, particularly in monolingual documents (the
% engine itself reverses boxes -- including column order or headings
% --, margins, etc.)\ with |bidi=basic|, without having to patch
% almost any macro where text direction is relevant.
%
% Still, there are three areas deserving special attention, namely,
% tabular, math, and graphics, text and intrinsically left-to-right
% elements are intermingled. I've made some progress in graphics, but
% they're essentially hacks; I've also made some progress in `tabular`,
% but when I decided to tackle math (both standard math and `amsmath`)
% the nightmare began. I'm still not sure how `amsmath` should be
% modified, but the main problem is that, boxes are “generic”
% containers that can hold text, math, and graphics (even at the same
% time; remember that inline math is included in the list of text nodes
% marked with 'math' (11) nodes too).
%
% |\@hangfrom| is useful in many contexts and it is redefined always
% with the |layout| option.
%
% There are, however, a number of issues when the text direction is not
% the same as the box direction (as set by |\bodydir|), and when
% |\parbox| and |\hangindent| are involved. Fortunately, latest
% releases of \luatex{} simplify a lot the solution with |\shapemode|.
%
% With the issue \#15 I realized commands are best patched, instead of
% redefined. With a few lines, a modification could be applied to
% several classes and packages. Now, |tabular| seems to work (at least
% in simple cases) with \textsf{array}, \textsf{tabularx},
% \textsf{hhline}, \textsf{colortbl}, \textsf{longtable},
% \textsf{booktabs}, etc. However, \textsf{dcolumn} still fails.
%
% \begin{macrocode}
\bbl@trace{Redefinitions for bidi layout}
%
%<<*More package options>>
\chardef\bbl@eqnpos\z@
\DeclareOption{leqno}{\chardef\bbl@eqnpos\@ne}
\DeclareOption{fleqn}{\chardef\bbl@eqnpos\tw@}
%<</More package options>>
%
\ifnum\bbl@bidimode>\z@ % Any bidi=
\matheqdirmode\@ne % A luatex primitive
\let\bbl@eqnodir\relax
\def\bbl@eqdel{()}
\def\bbl@eqnum{%
{\normalfont\normalcolor
\expandafter\@firstoftwo\bbl@eqdel
\theequation
\expandafter\@secondoftwo\bbl@eqdel}}
\def\bbl@puteqno#1{\eqno\hbox{#1}}
\def\bbl@putleqno#1{\leqno\hbox{#1}}
\def\bbl@eqno@flip#1{%
\ifdim\predisplaysize=-\maxdimen
\eqno
\hb@
[email protected]{%
\hb@xt@\displaywidth{\hss{#1\glet\bbl@upset\@currentlabel}}\hss}%
\else
\leqno\hbox{#1\glet\bbl@upset\@currentlabel}%
\fi
\bbl@exp{\def\\\@currentlabel{\[bbl@upset]}}}
\def\bbl@leqno@flip#1{%
\ifdim\predisplaysize=-\maxdimen
\leqno
\hb@
[email protected]{%
\hss\hb@xt@\displaywidth{{#1\glet\bbl@upset\@currentlabel}\hss}}%
\else
\eqno\hbox{#1\glet\bbl@upset\@currentlabel}%
\fi
\bbl@exp{\def\\\@currentlabel{\[bbl@upset]}}}
%
\AtBeginDocument{%
\ifx\bbl@noamsmath\relax\else
\ifx\maketag@@@\@undefined % Normal equation, eqnarray
\AddToHook{env/equation/begin}{%
\ifnum\bbl@thetextdir>\z@
\def\bbl@mathboxdir{\def\bbl@insidemath{1}}%
\let\@eqnnum\bbl@eqnum
\edef\bbl@eqnodir{\noexpand\bbl@textdir{\the\bbl@thetextdir}}%
\chardef\bbl@thetextdir\z@
\bbl@add\normalfont{\bbl@eqnodir}%
\ifcase\bbl@eqnpos
\let\bbl@puteqno\bbl@eqno@flip
\or
\let\bbl@puteqno\bbl@leqno@flip
\fi
\fi}%
\ifnum\bbl@eqnpos=\tw@\else
\def\endequation{\bbl@puteqno{\@eqnnum}$$\@ignoretrue}%
\fi
\AddToHook{env/eqnarray/begin}{%
\ifnum\bbl@thetextdir>\z@
\def\bbl@mathboxdir{\def\bbl@insidemath{1}}%
\edef\bbl@eqnodir{\noexpand\bbl@textdir{\the\bbl@thetextdir}}%
\chardef\bbl@thetextdir\z@
\bbl@add\normalfont{\bbl@eqnodir}%
\ifnum\bbl@eqnpos=\@ne
\def\@eqnnum{%
\setbox\z@\hbox{\bbl@eqnum}%
\hbox to0.01pt{\hss\hbox to\displaywidth{\box\z@\hss}}}%
\else
\let\@eqnnum\bbl@eqnum
\fi
\fi}
% Hack for wrong vertical spacing with \[ \]. YA luatex bug?:
\expandafter\bbl@sreplace\csname] \endcsname{$$}{\eqno\kern.001pt$$}%
\else % amstex
\bbl@exp{% Hack to hide maybe undefined conditionals:
\chardef\bbl@eqnpos=0%
\<iftagsleft@>1\<else>\<if@fleqn>2\<fi>\<fi>\relax}%
\ifnum\bbl@eqnpos=\@ne
\let\bbl@ams@lap\hbox
\else
\let\bbl@ams@lap\llap
\fi
\ExplSyntaxOn % Required by \bbl@sreplace with \intertext@
\bbl@sreplace\intertext@{\normalbaselines}%
{\normalbaselines
\ifx\bbl@eqnodir\relax\else\bbl@pardir\@ne\bbl@eqnodir\fi}%
\ExplSyntaxOff
\def\bbl@ams@tagbox#1#2{#1{\bbl@eqnodir#2}}% #1=hbox|@lap|flip
\ifx\bbl@ams@lap\hbox % leqno
\def\bbl@ams@flip#1{%
\hbox to 0.01pt{\hss\hbox to\displaywidth{{#1}\hss}}}%
\else % eqno
\def\bbl@ams@flip#1{%
\hbox to 0.01pt{\hbox to\displaywidth{\hss{#1}}\hss}}%
\fi
\def\bbl@ams@preset#1{%
\def\bbl@mathboxdir{\def\bbl@insidemath{1}}%
\ifnum\bbl@thetextdir>\z@
\edef\bbl@eqnodir{\noexpand\bbl@textdir{\the\bbl@thetextdir}}%
\bbl@sreplace\textdef@{\hbox}{\bbl@ams@tagbox\hbox}%
\bbl@sreplace\maketag@@@{\hbox}{\bbl@ams@tagbox#1}%
\fi}%
\ifnum\bbl@eqnpos=\tw@\else
\def\bbl@ams@equation{%
\def\bbl@mathboxdir{\def\bbl@insidemath{1}}%
\ifnum\bbl@thetextdir>\z@
\edef\bbl@eqnodir{\noexpand\bbl@textdir{\the\bbl@thetextdir}}%
\chardef\bbl@thetextdir\z@
\bbl@add\normalfont{\bbl@eqnodir}%
\ifcase\bbl@eqnpos
\def\veqno##1##2{\bbl@eqno@flip{##1##2}}%
\or
\def\veqno##1##2{\bbl@leqno@flip{##1##2}}%
\fi
\fi}%
\AddToHook{env/equation/begin}{\bbl@ams@equation}%
\AddToHook{env/equation*/begin}{\bbl@ams@equation}%
\fi
\AddToHook{env/cases/begin}{\bbl@ams@preset\bbl@ams@lap}%
\AddToHook{env/multline/begin}{\bbl@ams@preset\hbox}%
\AddToHook{env/gather/begin}{\bbl@ams@preset\bbl@ams@lap}%
\AddToHook{env/gather*/begin}{\bbl@ams@preset\bbl@ams@lap}%
\AddToHook{env/align/begin}{\bbl@ams@preset\bbl@ams@lap}%
\AddToHook{env/align*/begin}{\bbl@ams@preset\bbl@ams@lap}%
\AddToHook{env/alignat/begin}{\bbl@ams@preset\bbl@ams@lap}%
\AddToHook{env/alignat*/begin}{\bbl@ams@preset\bbl@ams@lap}%
\AddToHook{env/eqnalign/begin}{\bbl@ams@preset\hbox}%
% Hackish, for proper alignment. Don’t ask me why it works!:
\bbl@exp{% Avoid a 'visible' conditional
\\\AddToHook{env/align*/end}{\<iftag@>\<else>\\\tag*{}\<fi>}%
\\\AddToHook{env/alignat*/end}{\<iftag@>\<else>\\\tag*{}\<fi>}}%
\AddToHook{env/flalign/begin}{\bbl@ams@preset\hbox}%
\AddToHook{env/split/before}{%
\def\bbl@mathboxdir{\def\bbl@insidemath{1}}%
\ifnum\bbl@thetextdir>\z@
\bbl@ifsamestring\@currenvir{equation}%
{\ifx\bbl@ams@lap\hbox % leqno
\def\bbl@ams@flip#1{%
\hbox to 0.01pt{\hbox to\displaywidth{{#1}\hss}\hss}}%
\else
\def\bbl@ams@flip#1{%
\hbox to 0.01pt{\hss\hbox to\displaywidth{\hss{#1}}}}%
\fi}%
{}%
\fi}%
\fi\fi}
\fi
% \end{macrocode}
%
% Declarations specific to lua, called by |\babelprovide|.
%
% \begin{macrocode}
\def\bbl@provide@extra#1{%
% == onchar ==
\ifx\bbl@KVP@onchar\@nnil\else
\bbl@luahyphenate
\bbl@exp{%
\\\AddToHook{env/document/before}{{\\\select@language{#1}{}}}}%
\directlua{
if Babel.locale_mapped == nil then
Babel.locale_mapped = true
Babel.linebreaking.add_before(Babel.locale_map, 1)
Babel.loc_to_scr = {}
Babel.chr_to_loc = Babel.chr_to_loc or {}
end
Babel.locale_props[\the\localeid].letters = false
}%
\bbl@xin@{ letters }{ \bbl@KVP@onchar\space}%
\ifin@
\directlua{
Babel.locale_props[\the\localeid].letters = true
}%
\fi
\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}}}%
\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].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{%
\bbl@patchfont{{\bbl@mapselect}}%
{\selectfont}}%
\def\bbl@mapselect{%
\let\bbl@mapselect\relax
\edef\bbl@prefontid{\fontid\font}}%
\def\bbl@mapdir##1{%
\begingroup
\setbox\z@\hbox{% Force text mode
\def\languagename{##1}%
\let\bbl@ifrestoring\@firstoftwo % To avoid font warning
\bbl@switchfont
\ifnum\fontid\font>\z@ % A hack, for the pgf nullfont hack
\directlua{
Babel.locale_props[\the\csname bbl@id@@##1\endcsname]%
['/\bbl@prefontid'] = \fontid\font\space}%
\fi}%
\endgroup}%
\fi
\bbl@exp{\\\bbl@add\\\bbl@mapselect{\\\bbl@mapdir{\languagename}}}%
\fi
\fi
% == mapfont ==
% For bidi texts, to switch the font based on direction. Deprecated
\ifx\bbl@KVP@mapfont\@nnil\else
\bbl@ifsamestring{\bbl@KVP@mapfont}{direction}{}%
{\bbl@error{unknown-mapfont}{}{}{}}%
\bbl@ifunset{bbl@lsys@\languagename}{\bbl@provide@lsys{\languagename}}{}%
\bbl@ifunset{bbl@wdir@\languagename}{\bbl@provide@dirs{\languagename}}{}%
\ifx\bbl@mapselect\@undefined
\AtBeginDocument{%
\bbl@patchfont{{\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
% == Line breaking: CJK quotes ==
\ifcase\bbl@engine\or
\bbl@xin@{/c}{/\bbl@cl{lnbrk}}%
\ifin@
\bbl@ifunset{bbl@quote@\languagename}{}%
{\directlua{
Babel.locale_props[\the\localeid].cjk_quotes = {}
local cs = 'op'
for c in string.utfvalues(%
[[\csname bbl@quote@\languagename\endcsname]]) do
if Babel.cjk_characters[c].c == 'qu' then
Babel.locale_props[\the\localeid].cjk_quotes[c] = cs
end
cs = ( cs == 'op') and 'cl' or 'op'
end
}}%
\fi
\fi
% == Counters: mapdigits ==
% Native digits
\ifx\bbl@KVP@mapdigits\@nnil\else
\bbl@ifunset{bbl@dgnat@\languagename}{}%
{\bbl@activate@preotf
\directlua{
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 = Babel.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
% == transforms ==
\ifx\bbl@KVP@transforms\@nnil\else
\def\bbl@elt##1##2##3{%
\in@{$transforms.}{$##1}%
\ifin@
\def\bbl@tempa{##1}%
\bbl@replace\bbl@tempa{transforms.}{}%
\bbl@carg\bbl@transforms{babel\bbl@tempa}{##2}{##3}%
\fi}%
\bbl@exp{%
\\\bbl@ifblank{\bbl@cl{dgnat}}%
{\let\\\bbl@tempa\relax}%
{\def\\\bbl@tempa{%
\\\bbl@elt{transforms.prehyphenation}%
{digits.native.1.0}{([0-9])}%
\\\bbl@elt{transforms.prehyphenation}%
{digits.native.1.1}{string={1\string|0123456789\string|\bbl@cl{dgnat}}}}}}%
\ifx\bbl@tempa\relax\else
\toks@\expandafter\expandafter\expandafter{%
\csname bbl@inidata@\languagename\endcsname}%
\bbl@csarg\edef{inidata@\languagename}{%
\unexpanded\expandafter{\bbl@tempa}%
\the\toks@}%
\fi
\csname bbl@inidata@\languagename\endcsname
\bbl@release@transforms\relax % \relax closes the last item.
\fi}
% \end{macrocode}
%
% Start tabular here:
%
% \begin{macrocode}
\def\localerestoredirs{%
\ifcase\bbl@thetextdir
\ifnum\textdirection=\z@\else\textdir TLT\fi
\else
\ifnum\textdirection=\@ne\else\textdir TRT\fi
\fi
\ifcase\bbl@thepardir
\ifnum\pardirection=\z@\else\pardir TLT\bodydir TLT\fi
\else
\ifnum\pardirection=\@ne\else\pardir TRT\bodydir TRT\fi
\fi}
%
\IfBabelLayout{tabular}%
{\chardef\bbl@tabular@mode\tw@}% All RTL
{\IfBabelLayout{notabular}%
{\chardef\bbl@tabular@mode\z@}%
{\chardef\bbl@tabular@mode\@ne}}% Mixed, with LTR cols
%
\ifnum\bbl@bidimode>\@ne % Any lua bidi= except default=1
% Redefine: vrules mess up dirs.
\def\@arstrut{\relax\copy\@arstrutbox}%
\ifcase\bbl@tabular@mode\or % 1 = Mixed - default
\let\bbl@parabefore\relax
\AddToHook{para/before}{\bbl@parabefore}
\AtBeginDocument{%
\bbl@replace\@tabular{$}{$%
\def\bbl@insidemath{0}%
\def\bbl@parabefore{\localerestoredirs}}%
\ifnum\bbl@tabular@mode=\@ne
\bbl@ifunset{@tabclassz}{}{%
\bbl@exp{% Hide conditionals
\\\bbl@sreplace\\\@tabclassz
{\<ifcase>\\\@chnum}%
{\\\localerestoredirs\<ifcase>\\\@chnum}}}%
\@ifpackageloaded{colortbl}%
{\bbl@sreplace\@classz
{\hbox\bgroup\bgroup}{\hbox\bgroup\bgroup\localerestoredirs}}%
{\@ifpackageloaded{array}%
{\bbl@exp{% Hide conditionals
\\\bbl@sreplace\\\@classz
{\<ifcase>\\\@chnum}%
{\bgroup\\\localerestoredirs\<ifcase>\\\@chnum}%
\\\bbl@sreplace\\\@classz
{\\\do@row@strut\<fi>}{\\\do@row@strut\<fi>\egroup}}}%
{}}%
\fi}%
\or % 2 = All RTL - tabular
\let\bbl@parabefore\relax
\AddToHook{para/before}{\bbl@parabefore}%
\AtBeginDocument{%
\@ifpackageloaded{colortbl}%
{\bbl@replace\@tabular{$}{$%
\def\bbl@insidemath{0}%
\def\bbl@parabefore{\localerestoredirs}}%
\bbl@sreplace\@classz
{\hbox\bgroup\bgroup}{\hbox\bgroup\bgroup\localerestoredirs}}%
{}}%
\fi
% \end{macrocode}
%
% Very likely the |\output| routine must be patched in a quite general
% way to make sure the |\bodydir| is set to |\pagedir|. Note outside
% |\output| they can be different (and often are). For the moment, two
% \textit{ad hoc} changes.
%
% \begin{macrocode}
\AtBeginDocument{%
\@ifpackageloaded{multicol}%
{\toks@\expandafter{\multi@column@out}%
\edef\multi@column@out{\bodydir\pagedir\the\toks@}}%
{}%
\@ifpackageloaded{paracol}%
{\edef\pcol@output{%
\bodydir\pagedir\unexpanded\expandafter{\pcol@output}}}%
{}}%
\fi
% \end{macrocode}
%
% Finish here if there in no |layout|.
%
% \begin{macrocode}
\ifx\bbl@opt@layout\@nnil\endinput\fi
% \end{macrocode}
%
% \textsc{Omega} provided a companion to |\mathdir| (|\nextfakemath|)
% for those cases where we did not want it to be applied, so that the
% writing direction of the main text was left unchanged.
% |\bbl@nextfake| is an attempt to emulate it, because \luatex{} has
% removed it without an alternative. Used in tabular, |\underline| and
% |\LaTeX|. Also, |\hangindent| does not honour direction changes by
% default, so we need to redefine |\@hangfrom|.
%
% \begin{macrocode}
\ifnum\bbl@bidimode>\z@ % Any bidi=
\def\bbl@nextfake#1{% non-local changes, use always inside a group!
\bbl@exp{%
\mathdir\the\bodydir
#1% Once entered in math, set boxes to restore values
\def\\\bbl@insidemath{0}%
\<ifmmode>%
\everyvbox{%
\the\everyvbox
\bodydir\the\bodydir
\mathdir\the\mathdir
\everyhbox{\the\everyhbox}%
\everyvbox{\the\everyvbox}}%
\everyhbox{%
\the\everyhbox
\bodydir\the\bodydir
\mathdir\the\mathdir
\everyhbox{\the\everyhbox}%
\everyvbox{\the\everyvbox}}%
\<fi>}}%
\IfBabelLayout{nopars}
{}
{\edef\bbl@opt@layout{\bbl@
[email protected].}}%
\IfBabelLayout{pars}
{\def\@hangfrom#1{%
\setbox\@tempboxa\hbox{{#1}}%
\hangindent\wd\@tempboxa
\ifnum\bbl@getluadir{page}=\bbl@getluadir{par}\else
\shapemode\@ne
\fi
\noindent\box\@tempboxa}}
{}
\fi
%
\IfBabelLayout{tabular}
{\let\bbl@OL@@tabular\@tabular
\bbl@replace\@tabular{$}{\bbl@nextfake$}%
\let\bbl@NL@@tabular\@tabular
\AtBeginDocument{%
\ifx\bbl@NL@@tabular\@tabular\else
\bbl@exp{\\\in@{\\\bbl@nextfake}{\[@tabular]}}%
\ifin@\else
\bbl@replace\@tabular{$}{\bbl@nextfake$}%
\fi
\let\bbl@NL@@tabular\@tabular
\fi}}
{}
%
\IfBabelLayout{lists}
{\let\bbl@OL@list\list
\bbl@sreplace\list{\parshape}{\bbl@listparshape}%
\let\bbl@NL@list\list
\def\bbl@listparshape#1#2#3{%
\parshape #1 #2 #3 %
\ifnum\bbl@getluadir{page}=\bbl@getluadir{par}\else
\shapemode\tw@
\fi}}
{}
%
\IfBabelLayout{graphics}
{\let\bbl@pictresetdir\relax
\def\bbl@pictsetdir#1{%
\ifcase\bbl@thetextdir
\let\bbl@pictresetdir\relax
\else
\ifcase#1\bodydir TLT % Remember this sets the inner boxes
\or\textdir TLT
\else\bodydir TLT \textdir TLT
\fi
% \(text|par)dir required in pgf:
\def\bbl@pictresetdir{\bodydir TRT\pardir TRT\textdir TRT\relax}%
\fi}%
\AddToHook{env/picture/begin}{\bbl@pictsetdir\tw@}%
\directlua{
Babel.get_picture_dir = true
Babel.picture_has_bidi = 0
%
function Babel.picture_dir (head)
if not Babel.get_picture_dir then return head end
if Babel.hlist_has_bidi(head) then
Babel.picture_has_bidi = 1
end
return head
end
luatexbase.add_to_callback("hpack_filter", Babel.picture_dir,
"Babel.picture_dir")
}%
\AtBeginDocument{%
\def\LS@rot{%
\setbox\@outputbox\vbox{%
\hbox dir TLT{\rotatebox{90}{\box\@outputbox}}}}%
\long\def\put(#1,#2)#3{%
\@killglue
% Try:
\ifx\bbl@pictresetdir\relax
\def\bbl@tempc{0}%
\else
\directlua{
Babel.get_picture_dir = true
Babel.picture_has_bidi = 0
}%
\setbox\z@\hb@xt@\z@{%
\@defaultunitsset\@tempdimc{#1}\unitlength
\kern\@tempdimc
#3\hss}%
\edef\bbl@tempc{\directlua{tex.print(Babel.picture_has_bidi)}}%
\fi
% Do:
\@defaultunitsset\@tempdimc{#2}\unitlength
\raise\@tempdimc\hb@xt@\z@{%
\@defaultunitsset\@tempdimc{#1}\unitlength
\kern\@tempdimc
{\ifnum\bbl@tempc>\z@\bbl@pictresetdir\fi#3}\hss}%
\ignorespaces}%
\MakeRobust\put}%
\AtBeginDocument
{\AddToHook{cmd/diagbox@pict/before}{\let\bbl@pictsetdir\@gobble}%
\ifx\pgfpicture\@undefined\else
\AddToHook{env/pgfpicture/begin}{\bbl@pictsetdir\@ne}%
\bbl@add\pgfinterruptpicture{\bbl@pictresetdir}%
\bbl@add\pgfsys@beginpicture{\bbl@pictsetdir\z@}%
\fi
\ifx\tikzpicture\@undefined\else
\AddToHook{env/tikzpicture/begin}{\bbl@pictsetdir\tw@}%
\bbl@add\tikz@atbegin@node{\bbl@pictresetdir}%
\bbl@sreplace\tikz{\begingroup}{\begingroup\bbl@pictsetdir\tw@}%
\bbl@sreplace\tikzpicture{\begingroup}{\begingroup\bbl@pictsetdir\tw@}%
\fi
\ifx\tcolorbox\@undefined\else
\def\tcb@drawing@env@begin{%
\csname tcb@before@\tcb@split@state\endcsname
\bbl@pictsetdir\tw@
\begin{\kvtcb@graphenv}%
\tcb@bbdraw
\tcb@apply@graph@patches}%
\def\tcb@drawing@env@end{%
\end{\kvtcb@graphenv}%
\bbl@pictresetdir
\csname tcb@after@\tcb@split@state\endcsname}%
\fi
}}
{}
% \end{macrocode}
%
% Implicitly reverses sectioning labels in bidi=basic-r, because the
% full stop is not in contact with L numbers any more. I think there
% must be a better way. Assumes |bidi=basic|, but there are some
% additional readjustments for |bidi=default|.
%
% \begin{macrocode}
\IfBabelLayout{counters*}%
{\bbl@add\bbl@opt@layout{.counters.}%
\directlua{
luatexbase.add_to_callback("process_output_buffer",
Babel.discard_sublr , "Babel.discard_sublr") }%
}{}
\IfBabelLayout{counters}%
{\let\bbl@OL@@textsuperscript\@textsuperscript
\bbl@sreplace\@textsuperscript{\m@th}{\m@th\mathdir\pagedir}%
\let\bbl@latinarabic=\@arabic
\let\bbl@OL@@arabic\@arabic
\def\@arabic#1{\babelsublr{\bbl@latinarabic#1}}%
\@ifpackagewith{babel}{bidi=default}%
{\let\bbl@asciiroman=\@roman
\let\bbl@OL@@roman\@roman
\def\@roman#1{\babelsublr{\ensureascii{\bbl@asciiroman#1}}}%
\let\bbl@asciiRoman=\@Roman
\let\bbl@OL@@roman\@Roman
\def\@Roman#1{\babelsublr{\ensureascii{\bbl@asciiRoman#1}}}%
\let\bbl@OL@labelenumii\labelenumii
\def\labelenumii{)\theenumii(}%
\let\bbl@OL@p@enumiii\p@enumiii
\def\p@enumiii{\p@enumii)\theenumii(}}{}}{}
% \end{macrocode}
%
% Some \LaTeX{} macros use internally the math mode for text
% formatting. They have very little in common and are grouped here, as
% a single option.
%
% \begin{macrocode}
\IfBabelLayout{extras}%
{\bbl@ncarg\let\bbl@OL@underline{underline }%
\bbl@carg\bbl@sreplace{underline }%
{$\@@underline}{\bgroup\bbl@nextfake$\@@underline}%
\bbl@carg\bbl@sreplace{underline }%
{\m@th$}{\m@th$\egroup}%
\let\bbl@OL@LaTeXe\LaTeXe
\DeclareRobustCommand{\LaTeXe}{\mbox{\m@th
\if b\expandafter\@car\f@series\@nil\boldmath\fi
\babelsublr{%
\LaTeX\kern.15em2\bbl@nextfake$_{\textstyle\varepsilon}$}}}}
{}
%</luatex>
% \end{macrocode}
%
% \subsection{Lua: transforms}
%
% After declaring the table containing the patterns with their
% replacements, we define some auxiliary functions: |str_to_nodes|
% converts the string returned by a function to a node list, taking the
% node at |base| as a model (font, language, etc.); |fetch_word|
% fetches a series of glyphs and discretionaries, which |pattern| is
% matched against (if there is a match, it is called again before
% trying other patterns, and this is very likely the main bottleneck).
%
% |post_hyphenate_replace| is the callback applied after
% |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
% we just remove it and add 1 to the resulting length. With |last| we
% must take into account the capture position points to the next
% character. Here |word_head| points to the starting node of the text
% to be matched.
%
% \begin{macrocode}
%<*transforms>
Babel.linebreaking.replacements = {}
Babel.linebreaking.replacements[0] = {} -- pre
Babel.linebreaking.replacements[1] = {} -- post
function Babel.tovalue(v)
if type(v) == 'table' then
return Babel.locale_props[v[1]].vars[v[2]] or v[3]
else
return v
end
end
Babel.attr_hboxed = luatexbase.registernumber'bbl@attr@hboxed'
function Babel.set_hboxed(head, gc)
for item in node.traverse(head) do
node.set_attribute(item, Babel.attr_hboxed, 1)
end
return head
end
Babel.fetch_subtext = {}
Babel.ignore_pre_char = function(node)
return (node.lang == Babel.nohyphenation)
end
Babel.show_transforms = false
-- Merging both functions doesn't seen feasible, because there are too
-- many differences.
Babel.fetch_subtext[0] = function(head)
local word_string = ''
local word_nodes = {}
local lang
local item = head
local inmath = false
while item do
if item.id == 11 then
inmath = (item.subtype == 0)
end
if inmath then
-- pass
elseif item.id == 29 then
local locale = node.get_attribute(item, Babel.attr_locale)
if lang == locale or lang == nil then
lang = lang or locale
if Babel.ignore_pre_char(item) then
word_string = word_string .. Babel.us_char
else
if node.has_attribute(item, Babel.attr_hboxed) then
word_string = word_string .. Babel.us_char
else
word_string = word_string .. unicode.utf8.char(item.char)
end
end
word_nodes[#word_nodes+1] = item
else
break
end
elseif item.id == 12 and item.subtype == 13 then
if node.has_attribute(item, Babel.attr_hboxed) then
word_string = word_string .. Babel.us_char
else
word_string = word_string .. ' '
end
word_nodes[#word_nodes+1] = item
-- Ignore leading unrecognized nodes, too.
elseif word_string ~= '' then
word_string = word_string .. Babel.us_char
word_nodes[#word_nodes+1] = item -- Will be ignored
end
item = item.next
end
-- Here and above we remove some trailing chars but not the
-- corresponding nodes. But they aren't accessed.
if word_string:sub(-1) == ' ' then
word_string = word_string:sub(1,-2)
end
if Babel.show_transforms then texio.write_nl(word_string) end
word_string = unicode.utf8.gsub(word_string, Babel.us_char .. '+$', '')
return word_string, word_nodes, item, lang
end
Babel.fetch_subtext[1] = function(head)
local word_string = ''
local word_nodes = {}
local lang
local item = head
local inmath = false
while item do
if item.id == 11 then
inmath = (item.subtype == 0)
end
if inmath then
-- pass
elseif item.id == 29 then
if item.lang == lang or lang == nil then
lang = lang or item.lang
if node.has_attribute(item, Babel.attr_hboxed) then
word_string = word_string .. Babel.us_char
elseif (item.char == 124) or (item.char == 61) then -- not =, not |
word_string = word_string .. Babel.us_char
else
word_string = word_string .. unicode.utf8.char(item.char)
end
word_nodes[#word_nodes+1] = item
else
break
end
elseif item.id == 7 and item.subtype == 2 then
if node.has_attribute(item, Babel.attr_hboxed) then
word_string = word_string .. Babel.us_char
else
word_string = word_string .. '='
end
word_nodes[#word_nodes+1] = item
elseif item.id == 7 and item.subtype == 3 then
if node.has_attribute(item, Babel.attr_hboxed) then
word_string = word_string .. Babel.us_char
else
word_string = word_string .. '|'
end
word_nodes[#word_nodes+1] = item
-- (1) Go to next word if nothing was found, and (2) implicitly
-- remove leading USs.
elseif word_string == '' then
-- pass
-- This is the responsible for splitting by words.
elseif (item.id == 12 and item.subtype == 13) then
break
else
word_string = word_string .. Babel.us_char
word_nodes[#word_nodes+1] = item -- Will be ignored
end
item = item.next
end
if Babel.show_transforms then texio.write_nl(word_string) end
word_string = unicode.utf8.gsub(word_string, Babel.us_char .. '+$', '')
return word_string, word_nodes, item, lang
end
function Babel.pre_hyphenate_replace(head)
Babel.hyphenate_replace(head, 0)
end
function Babel.post_hyphenate_replace(head)
Babel.hyphenate_replace(head, 1)
end
Babel.us_char = string.char(31)
function Babel.hyphenate_replace(head, mode)
local u = unicode.utf8
local lbkr = Babel.linebreaking.replacements[mode]
local tovalue = Babel.tovalue
local word_head = head
if Babel.show_transforms then
texio.write_nl('\n==== Showing ' .. (mode == 0 and 'pre' or 'post') .. 'hyphenation ====')
end
while true do -- for each subtext block
local w, w_nodes, nw, lang = Babel.fetch_subtext[mode](word_head)
if Babel.debug then
print()
print((mode == 0) and '@@@@<' or '@@@@>', w)
end
if nw == nil and w == '' then break end
if not lang then goto next end
if not lbkr[lang] then goto next end
-- For each saved (pre|post)hyphenation. TODO. Reconsider how
-- loops are nested.
for k=1, #lbkr[lang] do
local p = lbkr[lang][k].pattern
local r = lbkr[lang][k].replace
local attr = lbkr[lang][k].attr or -1
if Babel.debug then
print('*****', p, mode)
end
-- This variable is set in some cases below to the first *byte*
-- after the match, either as found by u.match (faster) or the
-- computed position based on sc if w has changed.
local last_match = 0
local step = 0
-- For every match.
while true do
if Babel.debug then
print('=====')
end
local new -- used when inserting and removing nodes
local dummy_node -- used by after
local matches = { u.match(w, p, last_match) }
if #matches < 2 then break end
-- Get and remove empty captures (with ()'s, which return a
-- number with the position), and keep actual captures
-- (from (...)), if any, in matches.
local first = table.remove(matches, 1)
local last = table.remove(matches, #matches)
-- Non re-fetched substrings may contain \31, which separates
-- subsubstrings.
if string.find(w:sub(first, last-1), Babel.us_char) then break end
local save_last = last -- with A()BC()D, points to D
-- Fix offsets, from bytes to unicode. Explained above.
first = u.len(w:sub(1, first-1)) + 1
last = u.len(w:sub(1, last-1)) -- now last points to C
-- This loop stores in a small table the nodes
-- corresponding to the pattern. Used by 'data' to provide a
-- predictable behavior with 'insert' (w_nodes is modified on
-- the fly), and also access to 'remove'd nodes.
local sc = first-1 -- Used below, too
local data_nodes = {}
local enabled = true
for q = 1, last-first+1 do
data_nodes[q] = w_nodes[sc+q]
if enabled
and attr > -1
and not node.has_attribute(data_nodes[q], attr)
then
enabled = false
end
end
-- This loop traverses the matched substring and takes the
-- corresponding action stored in the replacement list.
-- sc = the position in substr nodes / string
-- rc = the replacement table index
local rc = 0
------- TODO. dummy_node?
while rc < last-first+1 or dummy_node do -- for each replacement
if Babel.debug then
print('.....', rc + 1)
end
sc = sc + 1
rc = rc + 1
if Babel.debug then
Babel.debug_hyph(w, w_nodes, sc, first, last, last_match)
local ss = ''
for itt in node.traverse(head) do
if itt.id == 29 then
ss = ss .. unicode.utf8.char(itt.char)
else
ss = ss .. '{' .. itt.id .. '}'
end
end
print('*****************', ss)
end
local crep = r[rc]
local item = w_nodes[sc]
local item_base = item
local placeholder = Babel.us_char
local d
if crep and crep.data then
item_base = data_nodes[crep.data]
end
if crep then
step = crep.step or step
end
if crep and crep.after then
crep.insert = true
if dummy_node then
item = dummy_node
else -- TODO. if there is a node after?
d = node.copy(item_base)
head, item = node.insert_after(head, item, d)
dummy_node = item
end
end
if crep and not crep.after and dummy_node then
node.remove(head, dummy_node)
dummy_node = nil
end
if not enabled then
last_match = save_last
goto next
elseif crep and next(crep) == nil then -- = {}
if step == 0 then
last_match = save_last -- Optimization
else
last_match = utf8.offset(w, sc+step)
end
goto next
elseif crep == nil or crep.remove then
node.remove(head, item)
table.remove(w_nodes, sc)
w = u.sub(w, 1, sc-1) .. u.sub(w, sc+1)
sc = sc - 1 -- Nothing has been inserted.
last_match = utf8.offset(w, sc+1+step)
goto next
elseif crep and crep.kashida then -- Experimental
node.set_attribute(item,
Babel.attr_kashida,
crep.kashida)
last_match = utf8.offset(w, sc+1+step)
goto next
elseif crep and crep.string then
local str = crep.string(matches)
if str == '' then -- Gather with nil
node.remove(head, item)
table.remove(w_nodes, sc)
w = u.sub(w, 1, sc-1) .. u.sub(w, sc+1)
sc = sc - 1 -- Nothing has been inserted.
else
local loop_first = true
for s in string.utfvalues(str) do
d = node.copy(item_base)
d.char = s
if loop_first then
loop_first = false
head, new = node.insert_before(head, item, d)
if sc == 1 then
word_head = head
end
w_nodes[sc] = d
w = u.sub(w, 1, sc-1) .. u.char(s) .. u.sub(w, sc+1)
else
sc = sc + 1
head, new = node.insert_before(head, item, d)
table.insert(w_nodes, sc, new)
w = u.sub(w, 1, sc-1) .. u.char(s) .. u.sub(w, sc)
end
if Babel.debug then
print('.....', 'str')
Babel.debug_hyph(w, w_nodes, sc, first, last, last_match)
end
end -- for
node.remove(head, item)
end -- if ''
last_match = utf8.offset(w, sc+1+step)
goto next
elseif mode == 1 and crep and (crep.pre or crep.no or crep.post) then
d = node.new(7, 3) -- (disc, regular)
d.pre = Babel.str_to_nodes(crep.pre, matches, item_base)
d.post = Babel.str_to_nodes(crep.post, matches, item_base)
d.replace = Babel.str_to_nodes(crep.no, matches, item_base)
d.attr = item_base.attr
if crep.pre == nil then -- TeXbook p96
d.penalty = tovalue(crep.penalty) or tex.hyphenpenalty
else
d.penalty = tovalue(crep.penalty) or tex.exhyphenpenalty
end
placeholder = '|'
head, new = node.insert_before(head, item, d)
elseif mode == 0 and crep and (crep.pre or crep.no or crep.post) then
-- ERROR
elseif crep and crep.penalty then
d = node.new(14, 0) -- (penalty, userpenalty)
d.attr = item_base.attr
d.penalty = tovalue(crep.penalty)
head, new = node.insert_before(head, item, d)
elseif crep and crep.space then
-- 655360 = 10 pt = 10 * 65536 sp
d = node.new(12, 13) -- (glue, spaceskip)
local quad = font.getfont(item_base.font).size or 655360
node.setglue(d, tovalue(crep.space[1]) * quad,
tovalue(crep.space[2]) * quad,
tovalue(crep.space[3]) * quad)
if mode == 0 then
placeholder = ' '
end
head, new = node.insert_before(head, item, d)
elseif crep and crep.norule then
-- 655360 = 10 pt = 10 * 65536 sp
d = node.new(2, 3) -- (rule, empty) = \no*rule
local quad = font.getfont(item_base.font).size or 655360
d.width = tovalue(crep.norule[1]) * quad
d.height = tovalue(crep.norule[2]) * quad
d.depth = tovalue(crep.norule[3]) * quad
head, new = node.insert_before(head, item, d)
elseif crep and crep.spacefactor then
d = node.new(12, 13) -- (glue, spaceskip)
local base_font = font.getfont(item_base.font)
node.setglue(d,
tovalue(crep.spacefactor[1]) * base_font.parameters['space'],
tovalue(crep.spacefactor[2]) * base_font.parameters['space_stretch'],
tovalue(crep.spacefactor[3]) * base_font.parameters['space_shrink'])
if mode == 0 then
placeholder = ' '
end
head, new = node.insert_before(head, item, d)
elseif mode == 0 and crep and crep.space then
-- ERROR
elseif crep and crep.kern then
d = node.new(13, 1) -- (kern, user)
local quad = font.getfont(item_base.font).size or 655360
d.attr = item_base.attr
d.kern = tovalue(crep.kern) * quad
head, new = node.insert_before(head, item, d)
elseif crep and crep.node then
d = node.new(crep.node[1], crep.node[2])
d.attr = item_base.attr
head, new = node.insert_before(head, item, d)
end -- i.e., replacement cases
-- Shared by disc, space(factor), kern, node and penalty.
if sc == 1 then
word_head = head
end
if crep.insert then
w = u.sub(w, 1, sc-1) .. placeholder .. u.sub(w, sc)
table.insert(w_nodes, sc, new)
last = last + 1
else
w_nodes[sc] = d
node.remove(head, item)
w = u.sub(w, 1, sc-1) .. placeholder .. u.sub(w, sc+1)
end
last_match = utf8.offset(w, sc+1+step)
::next::
end -- for each replacement
if Babel.show_transforms then texio.write_nl('> ' .. w) end
if Babel.debug then
print('.....', '/')
Babel.debug_hyph(w, w_nodes, sc, first, last, last_match)
end
if dummy_node then
node.remove(head, dummy_node)
dummy_node = nil
end
end -- for match
end -- for patterns
::next::
word_head = nw
end -- for substring
if Babel.show_transforms then texio.write_nl(string.rep('-', 32) .. '\n') end
return head
end
-- This table stores capture maps, numbered consecutively
Babel.capture_maps = {}
-- The following functions belong to the next macro
function Babel.capture_func(key, cap)
local ret = "[[" .. cap:gsub('{([0-9])}', "]]..m[%1]..[[") .. "]]"
local cnt
local u = unicode.utf8
ret, cnt = ret:gsub('{([0-9])|([^|]+)|(.-)}', Babel.capture_func_map)
if cnt == 0 then
ret = u.gsub(ret, '{(%x%x%x%x+)}',
function (n)
return u.char(tonumber(n, 16))
end)
end
ret = ret:gsub("%[%[%]%]%.%.", '')
ret = ret:gsub("%.%.%[%[%]%]", '')
return key .. [[=function(m) return ]] .. ret .. [[ end]]
end
function Babel.capt_map(from, mapno)
return Babel.capture_maps[mapno][from] or from
end
-- Handle the {n|abc|ABC} syntax in captures
function Babel.capture_func_map(capno, from, to)
local u = unicode.utf8
from = u.gsub(from, '{(%x%x%x%x+)}',
function (n)
return u.char(tonumber(n, 16))
end)
to = u.gsub(to, '{(%x%x%x%x+)}',
function (n)
return u.char(tonumber(n, 16))
end)
local froms = {}
for s in string.utfcharacters(from) do
table.insert(froms, s)
end
local cnt = 1
table.insert(Babel.capture_maps, {})
local mlen = table.getn(Babel.capture_maps)
for s in string.utfcharacters(to) do
Babel.capture_maps[mlen][froms[cnt]] = s
cnt = cnt + 1
end
return "]]..Babel.capt_map(m[" .. capno .. "]," ..
(mlen) .. ").." .. "[["
end
-- Create/Extend reversed sorted list of kashida weights:
function Babel.capture_kashida(key, wt)
wt = tonumber(wt)
if Babel.kashida_wts then
for p, q in ipairs(Babel.kashida_wts) do
if wt == q then
break
elseif wt > q then
table.insert(Babel.kashida_wts, p, wt)
break
elseif table.getn(Babel.kashida_wts) == p then
table.insert(Babel.kashida_wts, wt)
end
end
else
Babel.kashida_wts = { wt }
end
return 'kashida = ' .. wt
end
function Babel.capture_node(id, subtype)
local sbt = 0
for k, v in pairs(node.subtypes(id)) do
if v == subtype then sbt = k end
end
return 'node = {' .. node.id(id) .. ', ' .. sbt .. '}'
end
-- Experimental: applies prehyphenation transforms to a string (letters
-- and spaces).
function Babel.string_prehyphenation(str, locale)
local n, head, last, res
head = node.new(8, 0) -- dummy (hack just to start)
last = head
for s in string.utfvalues(str) do
if s == 20 then
n = node.new(12, 0)
else
n = node.new(29, 0)
n.char = s
end
node.set_attribute(n, Babel.attr_locale, locale)
last.next = n
last = n
end
head = Babel.hyphenate_replace(head, 0)
res = ''
for n in node.traverse(head) do
if n.id == 12 then
res = res .. ' '
elseif n.id == 29 then
res = res .. unicode.utf8.char(n.char)
end
end
tex.print(res)
end
%</transforms>
% \end{macrocode}
%
% \subsection{Lua: Auto bidi with \texttt{basic} and \texttt{basic-r}}
%
% The file \textsf{babel-data-bidi.lua} currently only contains data. It is
% a large and boring file and it is not shown here (see the generated file),
% but here is a sample:
%\begin{verbatim}
% [0x25]={d='et'},
% [0x26]={d='on'},
% [0x27]={d='on'},
% [0x28]={d='on', m=0x29},
% [0x29]={d='on', m=0x28},
% [0x2A]={d='on'},
% [0x2B]={d='es'},
% [0x2C]={d='cs'},
%\end{verbatim}
% For the meaning of these codes, see the Unicode standard.
%
%\iffalse
% \begin{macrocode}
%<*bididata>
-- Data from Unicode and ConTeXt
Babel.ranges = {
{0x0590, 0x05FF, 'r'},
{0x0600, 0x07BF, 'al'},
{0x07C0, 0x085F, 'r'},
{0x0860, 0x086F, 'al'},
{0x08A0, 0x08FF, 'al'},
{0xFB1D, 0xFB4F, 'r'},
{0xFB50, 0xFDFF, 'al'},
{0xFE70, 0xFEFF, 'al'},
{0x10800, 0x10CFF, 'r'},
{0x10D00, 0x10D3F, 'al'},
{0x10D40, 0x10EBF, 'r'},
{0x10EC0, 0x10EFF, 'al'},
{0x10F00, 0x10F2F, 'r'},
{0x10F30, 0x10F6F, 'al'},
{0x10F70, 0x10FFF, 'r'},
{0x1E800, 0x1E95F, 'r'},
{0x1EE00, 0x1EEFF, 'al'},
{0x1F300, 0x1F9FF, 'on'}
}
Babel.characters = {
[0x0]={d='bn'},
[0x1]={d='bn'},
[0x2]={d='bn'},
[0x3]={d='bn'},
[0x4]={d='bn'},
[0x5]={d='bn'},
[0x6]={d='bn'},
[0x7]={d='bn'},
[0x8]={d='bn'},
[0x9]={d='s'},
[0xA]={d='b'},
[0xB]={d='s'},
[0xC]={d='ws'},
[0xD]={d='b'},
[0xE]={d='bn'},
[0xF]={d='bn'},
[0x10]={d='bn'},
[0x11]={d='bn'},
[0x12]={d='bn'},
[0x13]={d='bn'},
[0x14]={d='bn'},
[0x15]={d='bn'},
[0x16]={d='bn'},
[0x17]={d='bn'},
[0x18]={d='bn'},
[0x19]={d='bn'},
[0x1A]={d='bn'},
[0x1B]={d='bn'},
[0x1C]={d='b'},
[0x1D]={d='b'},
[0x1E]={d='b'},
[0x1F]={d='s'},
[0x20]={d='ws'},
[0x21]={d='on'},
[0x22]={d='on'},
[0x23]={d='et'},
[0x24]={d='et'},
[0x25]={d='et'},
[0x26]={d='on'},
[0x27]={d='on'},
[0x28]={d='on', m=0x29},
[0x29]={d='on', m=0x28},
[0x2A]={d='on'},
[0x2B]={d='es'},
[0x2C]={d='cs'},
[0x2D]={d='es'},
[0x2E]={d='cs'},
[0x2F]={d='cs'},
[0x30]={d='en'},
[0x31]={d='en'},
[0x32]={d='en'},
[0x33]={d='en'},
[0x34]={d='en'},
[0x35]={d='en'},
[0x36]={d='en'},
[0x37]={d='en'},
[0x38]={d='en'},
[0x39]={d='en'},
[0x3A]={d='cs'},
[0x3B]={d='on'},
[0x3C]={d='on', m=0x3E},
[0x3D]={d='on'},
[0x3E]={d='on', m=0x3C},
[0x3F]={d='on'},
[0x40]={d='on'},
[0x5B]={d='on', m=0x5D},
[0x5C]={d='on'},
[0x5D]={d='on', m=0x5B},
[0x5E]={d='on'},
[0x5F]={d='on'},
[0x60]={d='on'},
[0x7B]={d='on', m=0x7D},
[0x7C]={d='on'},
[0x7D]={d='on', m=0x7B},
[0x7E]={d='on'},
[0x7F]={d='bn'},
[0x80]={d='bn'},
[0x81]={d='bn'},
[0x82]={d='bn'},
[0x83]={d='bn'},
[0x84]={d='bn'},
[0x85]={d='b'},
[0x86]={d='bn'},
[0x87]={d='bn'},
[0x88]={d='bn'},
[0x89]={d='bn'},
[0x8A]={d='bn'},
[0x8B]={d='bn'},
[0x8C]={d='bn'},
[0x8D]={d='bn'},
[0x8E]={d='bn'},
[0x8F]={d='bn'},
[0x90]={d='bn'},
[0x91]={d='bn'},
[0x92]={d='bn'},
[0x93]={d='bn'},
[0x94]={d='bn'},
[0x95]={d='bn'},
[0x96]={d='bn'},
[0x97]={d='bn'},
[0x98]={d='bn'},
[0x99]={d='bn'},
[0x9A]={d='bn'},
[0x9B]={d='bn'},
[0x9C]={d='bn'},
[0x9D]={d='bn'},
[0x9E]={d='bn'},
[0x9F]={d='bn'},
[0xA0]={d='cs'},
[0xA1]={d='on'},
[0xA2]={d='et'},
[0xA3]={d='et'},
[0xA4]={d='et'},
[0xA5]={d='et'},
[0xA6]={d='on'},
[0xA7]={d='on'},
[0xA8]={d='on'},
[0xA9]={d='on'},
[0xAB]={d='on', m=0xBB},
[0xAC]={d='on'},
[0xAD]={d='bn'},
[0xAE]={d='on'},
[0xAF]={d='on'},
[0xB0]={d='et'},
[0xB1]={d='et'},
[0xB2]={d='en'},
[0xB3]={d='en'},
[0xB4]={d='on'},
[0xB6]={d='on'},
[0xB7]={d='on'},
[0xB8]={d='on'},
[0xB9]={d='en'},
[0xBB]={d='on', m=0xAB},
[0xBC]={d='on'},
[0xBD]={d='on'},
[0xBE]={d='on'},
[0xBF]={d='on'},
[0xD7]={d='on'},
[0xF7]={d='on'},
[0x2B9]={d='on'},
[0x2BA]={d='on'},
[0x2C2]={d='on'},
[0x2C3]={d='on'},
[0x2C4]={d='on'},
[0x2C5]={d='on'},
[0x2C6]={d='on'},
[0x2C7]={d='on'},
[0x2C8]={d='on'},
[0x2C9]={d='on'},
[0x2CA]={d='on'},
[0x2CB]={d='on'},
[0x2CC]={d='on'},
[0x2CD]={d='on'},
[0x2CE]={d='on'},
[0x2CF]={d='on'},
[0x2D2]={d='on'},
[0x2D3]={d='on'},
[0x2D4]={d='on'},
[0x2D5]={d='on'},
[0x2D6]={d='on'},
[0x2D7]={d='on'},
[0x2D8]={d='on'},
[0x2D9]={d='on'},
[0x2DA]={d='on'},
[0x2DB]={d='on'},
[0x2DC]={d='on'},
[0x2DD]={d='on'},
[0x2DE]={d='on'},
[0x2DF]={d='on'},
[0x2E5]={d='on'},
[0x2E6]={d='on'},
[0x2E7]={d='on'},
[0x2E8]={d='on'},
[0x2E9]={d='on'},
[0x2EA]={d='on'},
[0x2EB]={d='on'},
[0x2EC]={d='on'},
[0x2ED]={d='on'},
[0x2EF]={d='on'},
[0x2F0]={d='on'},
[0x2F1]={d='on'},
[0x2F2]={d='on'},
[0x2F3]={d='on'},
[0x2F4]={d='on'},
[0x2F5]={d='on'},
[0x2F6]={d='on'},
[0x2F7]={d='on'},
[0x2F8]={d='on'},
[0x2F9]={d='on'},
[0x2FA]={d='on'},
[0x2FB]={d='on'},
[0x2FC]={d='on'},
[0x2FD]={d='on'},
[0x2FE]={d='on'},
[0x2FF]={d='on'},
[0x300]={d='nsm'},
[0x301]={d='nsm'},
[0x302]={d='nsm'},
[0x303]={d='nsm'},
[0x304]={d='nsm'},
[0x305]={d='nsm'},
[0x306]={d='nsm'},
[0x307]={d='nsm'},
[0x308]={d='nsm'},
[0x309]={d='nsm'},
[0x30A]={d='nsm'},
[0x30B]={d='nsm'},
[0x30C]={d='nsm'},
[0x30D]={d='nsm'},
[0x30E]={d='nsm'},
[0x30F]={d='nsm'},
[0x310]={d='nsm'},
[0x311]={d='nsm'},
[0x312]={d='nsm'},
[0x313]={d='nsm'},
[0x314]={d='nsm'},
[0x315]={d='nsm'},
[0x316]={d='nsm'},
[0x317]={d='nsm'},
[0x318]={d='nsm'},
[0x319]={d='nsm'},
[0x31A]={d='nsm'},
[0x31B]={d='nsm'},
[0x31C]={d='nsm'},
[0x31D]={d='nsm'},
[0x31E]={d='nsm'},
[0x31F]={d='nsm'},
[0x320]={d='nsm'},
[0x321]={d='nsm'},
[0x322]={d='nsm'},
[0x323]={d='nsm'},
[0x324]={d='nsm'},
[0x325]={d='nsm'},
[0x326]={d='nsm'},
[0x327]={d='nsm'},
[0x328]={d='nsm'},
[0x329]={d='nsm'},
[0x32A]={d='nsm'},
[0x32B]={d='nsm'},
[0x32C]={d='nsm'},
[0x32D]={d='nsm'},
[0x32E]={d='nsm'},
[0x32F]={d='nsm'},
[0x330]={d='nsm'},
[0x331]={d='nsm'},
[0x332]={d='nsm'},
[0x333]={d='nsm'},
[0x334]={d='nsm'},
[0x335]={d='nsm'},
[0x336]={d='nsm'},
[0x337]={d='nsm'},
[0x338]={d='nsm'},
[0x339]={d='nsm'},
[0x33A]={d='nsm'},
[0x33B]={d='nsm'},
[0x33C]={d='nsm'},
[0x33D]={d='nsm'},
[0x33E]={d='nsm'},
[0x33F]={d='nsm'},
[0x340]={d='nsm'},
[0x341]={d='nsm'},
[0x342]={d='nsm'},
[0x343]={d='nsm'},
[0x344]={d='nsm'},
[0x345]={d='nsm'},
[0x346]={d='nsm'},
[0x347]={d='nsm'},
[0x348]={d='nsm'},
[0x349]={d='nsm'},
[0x34A]={d='nsm'},
[0x34B]={d='nsm'},
[0x34C]={d='nsm'},
[0x34D]={d='nsm'},
[0x34E]={d='nsm'},
[0x34F]={d='nsm'},
[0x350]={d='nsm'},
[0x351]={d='nsm'},
[0x352]={d='nsm'},
[0x353]={d='nsm'},
[0x354]={d='nsm'},
[0x355]={d='nsm'},
[0x356]={d='nsm'},
[0x357]={d='nsm'},
[0x358]={d='nsm'},
[0x359]={d='nsm'},
[0x35A]={d='nsm'},
[0x35B]={d='nsm'},
[0x35C]={d='nsm'},
[0x35D]={d='nsm'},
[0x35E]={d='nsm'},
[0x35F]={d='nsm'},
[0x360]={d='nsm'},
[0x361]={d='nsm'},
[0x362]={d='nsm'},
[0x363]={d='nsm'},
[0x364]={d='nsm'},
[0x365]={d='nsm'},
[0x366]={d='nsm'},
[0x367]={d='nsm'},
[0x368]={d='nsm'},
[0x369]={d='nsm'},
[0x36A]={d='nsm'},
[0x36B]={d='nsm'},
[0x36C]={d='nsm'},
[0x36D]={d='nsm'},
[0x36E]={d='nsm'},
[0x36F]={d='nsm'},
[0x374]={d='on'},
[0x375]={d='on'},
[0x37E]={d='on'},
[0x384]={d='on'},
[0x385]={d='on'},
[0x387]={d='on'},
[0x3F6]={d='on'},
[0x483]={d='nsm'},
[0x484]={d='nsm'},
[0x485]={d='nsm'},
[0x486]={d='nsm'},
[0x487]={d='nsm'},
[0x488]={d='nsm'},
[0x489]={d='nsm'},
[0x58A]={d='on'},
[0x58D]={d='on'},
[0x58E]={d='on'},
[0x58F]={d='et'},
[0x591]={d='nsm'},
[0x592]={d='nsm'},
[0x593]={d='nsm'},
[0x594]={d='nsm'},
[0x595]={d='nsm'},
[0x596]={d='nsm'},
[0x597]={d='nsm'},
[0x598]={d='nsm'},
[0x599]={d='nsm'},
[0x59A]={d='nsm'},
[0x59B]={d='nsm'},
[0x59C]={d='nsm'},
[0x59D]={d='nsm'},
[0x59E]={d='nsm'},
[0x59F]={d='nsm'},
[0x5A0]={d='nsm'},
[0x5A1]={d='nsm'},
[0x5A2]={d='nsm'},
[0x5A3]={d='nsm'},
[0x5A4]={d='nsm'},
[0x5A5]={d='nsm'},
[0x5A6]={d='nsm'},
[0x5A7]={d='nsm'},
[0x5A8]={d='nsm'},
[0x5A9]={d='nsm'},
[0x5AA]={d='nsm'},
[0x5AB]={d='nsm'},
[0x5AC]={d='nsm'},
[0x5AD]={d='nsm'},
[0x5AE]={d='nsm'},
[0x5AF]={d='nsm'},
[0x5B0]={d='nsm'},
[0x5B1]={d='nsm'},
[0x5B2]={d='nsm'},
[0x5B3]={d='nsm'},
[0x5B4]={d='nsm'},
[0x5B5]={d='nsm'},
[0x5B6]={d='nsm'},
[0x5B7]={d='nsm'},
[0x5B8]={d='nsm'},
[0x5B9]={d='nsm'},
[0x5BA]={d='nsm'},
[0x5BB]={d='nsm'},
[0x5BC]={d='nsm'},
[0x5BD]={d='nsm'},
[0x5BF]={d='nsm'},
[0x5C1]={d='nsm'},
[0x5C2]={d='nsm'},
[0x5C4]={d='nsm'},
[0x5C5]={d='nsm'},
[0x5C7]={d='nsm'},
[0x600]={d='an'},
[0x601]={d='an'},
[0x602]={d='an'},
[0x603]={d='an'},
[0x604]={d='an'},
[0x605]={d='an'},
[0x606]={d='on'},
[0x607]={d='on'},
[0x608]={d='al'},
[0x609]={d='et'},
[0x60A]={d='et'},
[0x60B]={d='al'},
[0x60C]={d='cs'},
[0x60D]={d='al'},
[0x60E]={d='on'},
[0x60F]={d='on'},
[0x610]={d='nsm'},
[0x611]={d='nsm'},
[0x612]={d='nsm'},
[0x613]={d='nsm'},
[0x614]={d='nsm'},
[0x615]={d='nsm'},
[0x616]={d='nsm'},
[0x617]={d='nsm'},
[0x618]={d='nsm'},
[0x619]={d='nsm'},
[0x61A]={d='nsm'},
[0x64B]={d='nsm'},
[0x64C]={d='nsm'},
[0x64D]={d='nsm'},
[0x64E]={d='nsm'},
[0x64F]={d='nsm'},
[0x650]={d='nsm'},
[0x651]={d='nsm'},
[0x652]={d='nsm'},
[0x653]={d='nsm'},
[0x654]={d='nsm'},
[0x655]={d='nsm'},
[0x656]={d='nsm'},
[0x657]={d='nsm'},
[0x658]={d='nsm'},
[0x659]={d='nsm'},
[0x65A]={d='nsm'},
[0x65B]={d='nsm'},
[0x65C]={d='nsm'},
[0x65D]={d='nsm'},
[0x65E]={d='nsm'},
[0x65F]={d='nsm'},
[0x660]={d='an'},
[0x661]={d='an'},
[0x662]={d='an'},
[0x663]={d='an'},
[0x664]={d='an'},
[0x665]={d='an'},
[0x666]={d='an'},
[0x667]={d='an'},
[0x668]={d='an'},
[0x669]={d='an'},
[0x66A]={d='et'},
[0x66B]={d='an'},
[0x66C]={d='an'},
[0x670]={d='nsm'},
[0x6D6]={d='nsm'},
[0x6D7]={d='nsm'},
[0x6D8]={d='nsm'},
[0x6D9]={d='nsm'},
[0x6DA]={d='nsm'},
[0x6DB]={d='nsm'},
[0x6DC]={d='nsm'},
[0x6DD]={d='an'},
[0x6DE]={d='on'},
[0x6DF]={d='nsm'},
[0x6E0]={d='nsm'},
[0x6E1]={d='nsm'},
[0x6E2]={d='nsm'},
[0x6E3]={d='nsm'},
[0x6E4]={d='nsm'},
[0x6E7]={d='nsm'},
[0x6E8]={d='nsm'},
[0x6E9]={d='on'},
[0x6EA]={d='nsm'},
[0x6EB]={d='nsm'},
[0x6EC]={d='nsm'},
[0x6ED]={d='nsm'},
[0x6F0]={d='en'},
[0x6F1]={d='en'},
[0x6F2]={d='en'},
[0x6F3]={d='en'},
[0x6F4]={d='en'},
[0x6F5]={d='en'},
[0x6F6]={d='en'},
[0x6F7]={d='en'},
[0x6F8]={d='en'},
[0x6F9]={d='en'},
[0x711]={d='nsm'},
[0x730]={d='nsm'},
[0x731]={d='nsm'},
[0x732]={d='nsm'},
[0x733]={d='nsm'},
[0x734]={d='nsm'},
[0x735]={d='nsm'},
[0x736]={d='nsm'},
[0x737]={d='nsm'},
[0x738]={d='nsm'},
[0x739]={d='nsm'},
[0x73A]={d='nsm'},
[0x73B]={d='nsm'},
[0x73C]={d='nsm'},
[0x73D]={d='nsm'},
[0x73E]={d='nsm'},
[0x73F]={d='nsm'},
[0x740]={d='nsm'},
[0x741]={d='nsm'},
[0x742]={d='nsm'},
[0x743]={d='nsm'},
[0x744]={d='nsm'},
[0x745]={d='nsm'},
[0x746]={d='nsm'},
[0x747]={d='nsm'},
[0x748]={d='nsm'},
[0x749]={d='nsm'},
[0x74A]={d='nsm'},
[0x7A6]={d='nsm'},
[0x7A7]={d='nsm'},
[0x7A8]={d='nsm'},
[0x7A9]={d='nsm'},
[0x7AA]={d='nsm'},
[0x7AB]={d='nsm'},
[0x7AC]={d='nsm'},
[0x7AD]={d='nsm'},
[0x7AE]={d='nsm'},
[0x7AF]={d='nsm'},
[0x7B0]={d='nsm'},
[0x7EB]={d='nsm'},
[0x7EC]={d='nsm'},
[0x7ED]={d='nsm'},
[0x7EE]={d='nsm'},
[0x7EF]={d='nsm'},
[0x7F0]={d='nsm'},
[0x7F1]={d='nsm'},
[0x7F2]={d='nsm'},
[0x7F3]={d='nsm'},
[0x7F6]={d='on'},
[0x7F7]={d='on'},
[0x7F8]={d='on'},
[0x7F9]={d='on'},
[0x816]={d='nsm'},
[0x817]={d='nsm'},
[0x818]={d='nsm'},
[0x819]={d='nsm'},
[0x81B]={d='nsm'},
[0x81C]={d='nsm'},
[0x81D]={d='nsm'},
[0x81E]={d='nsm'},
[0x81F]={d='nsm'},
[0x820]={d='nsm'},
[0x821]={d='nsm'},
[0x822]={d='nsm'},
[0x823]={d='nsm'},
[0x825]={d='nsm'},
[0x826]={d='nsm'},
[0x827]={d='nsm'},
[0x829]={d='nsm'},
[0x82A]={d='nsm'},
[0x82B]={d='nsm'},
[0x82C]={d='nsm'},
[0x82D]={d='nsm'},
[0x859]={d='nsm'},
[0x85A]={d='nsm'},
[0x85B]={d='nsm'},
[0x8D4]={d='nsm'},
[0x8D5]={d='nsm'},
[0x8D6]={d='nsm'},
[0x8D7]={d='nsm'},
[0x8D8]={d='nsm'},
[0x8D9]={d='nsm'},
[0x8DA]={d='nsm'},
[0x8DB]={d='nsm'},
[0x8DC]={d='nsm'},
[0x8DD]={d='nsm'},
[0x8DE]={d='nsm'},
[0x8DF]={d='nsm'},
[0x8E0]={d='nsm'},
[0x8E1]={d='nsm'},
[0x8E2]={d='an'},
[0x8E3]={d='nsm'},
[0x8E4]={d='nsm'},
[0x8E5]={d='nsm'},
[0x8E6]={d='nsm'},
[0x8E7]={d='nsm'},
[0x8E8]={d='nsm'},
[0x8E9]={d='nsm'},
[0x8EA]={d='nsm'},
[0x8EB]={d='nsm'},
[0x8EC]={d='nsm'},
[0x8ED]={d='nsm'},
[0x8EE]={d='nsm'},
[0x8EF]={d='nsm'},
[0x8F0]={d='nsm'},
[0x8F1]={d='nsm'},
[0x8F2]={d='nsm'},
[0x8F3]={d='nsm'},
[0x8F4]={d='nsm'},
[0x8F5]={d='nsm'},
[0x8F6]={d='nsm'},
[0x8F7]={d='nsm'},
[0x8F8]={d='nsm'},
[0x8F9]={d='nsm'},
[0x8FA]={d='nsm'},
[0x8FB]={d='nsm'},
[0x8FC]={d='nsm'},
[0x8FD]={d='nsm'},
[0x8FE]={d='nsm'},
[0x8FF]={d='nsm'},
[0x900]={d='nsm'},
[0x901]={d='nsm'},
[0x902]={d='nsm'},
[0x93A]={d='nsm'},
[0x93C]={d='nsm'},
[0x941]={d='nsm'},
[0x942]={d='nsm'},
[0x943]={d='nsm'},
[0x944]={d='nsm'},
[0x945]={d='nsm'},
[0x946]={d='nsm'},
[0x947]={d='nsm'},
[0x948]={d='nsm'},
[0x94D]={d='nsm'},
[0x951]={d='nsm'},
[0x952]={d='nsm'},
[0x953]={d='nsm'},
[0x954]={d='nsm'},
[0x955]={d='nsm'},
[0x956]={d='nsm'},
[0x957]={d='nsm'},
[0x962]={d='nsm'},
[0x963]={d='nsm'},
[0x981]={d='nsm'},
[0x9BC]={d='nsm'},
[0x9C1]={d='nsm'},
[0x9C2]={d='nsm'},
[0x9C3]={d='nsm'},
[0x9C4]={d='nsm'},
[0x9CD]={d='nsm'},
[0x9E2]={d='nsm'},
[0x9E3]={d='nsm'},
[0x9F2]={d='et'},
[0x9F3]={d='et'},
[0x9FB]={d='et'},
[0xA01]={d='nsm'},
[0xA02]={d='nsm'},
[0xA3C]={d='nsm'},
[0xA41]={d='nsm'},
[0xA42]={d='nsm'},
[0xA47]={d='nsm'},
[0xA48]={d='nsm'},
[0xA4B]={d='nsm'},
[0xA4C]={d='nsm'},
[0xA4D]={d='nsm'},
[0xA51]={d='nsm'},
[0xA70]={d='nsm'},
[0xA71]={d='nsm'},
[0xA75]={d='nsm'},
[0xA81]={d='nsm'},
[0xA82]={d='nsm'},
[0xABC]={d='nsm'},
[0xAC1]={d='nsm'},
[0xAC2]={d='nsm'},
[0xAC3]={d='nsm'},
[0xAC4]={d='nsm'},
[0xAC5]={d='nsm'},
[0xAC7]={d='nsm'},
[0xAC8]={d='nsm'},
[0xACD]={d='nsm'},
[0xAE2]={d='nsm'},
[0xAE3]={d='nsm'},
[0xAF1]={d='et'},
[0xB01]={d='nsm'},
[0xB3C]={d='nsm'},
[0xB3F]={d='nsm'},
[0xB41]={d='nsm'},
[0xB42]={d='nsm'},
[0xB43]={d='nsm'},
[0xB44]={d='nsm'},
[0xB4D]={d='nsm'},
[0xB56]={d='nsm'},
[0xB62]={d='nsm'},
[0xB63]={d='nsm'},
[0xB82]={d='nsm'},
[0xBC0]={d='nsm'},
[0xBCD]={d='nsm'},
[0xBF3]={d='on'},
[0xBF4]={d='on'},
[0xBF5]={d='on'},
[0xBF6]={d='on'},
[0xBF7]={d='on'},
[0xBF8]={d='on'},
[0xBF9]={d='et'},
[0xBFA]={d='on'},
[0xC00]={d='nsm'},
[0xC3E]={d='nsm'},
[0xC3F]={d='nsm'},
[0xC40]={d='nsm'},
[0xC46]={d='nsm'},
[0xC47]={d='nsm'},
[0xC48]={d='nsm'},
[0xC4A]={d='nsm'},
[0xC4B]={d='nsm'},
[0xC4C]={d='nsm'},
[0xC4D]={d='nsm'},
[0xC55]={d='nsm'},
[0xC56]={d='nsm'},
[0xC62]={d='nsm'},
[0xC63]={d='nsm'},
[0xC78]={d='on'},
[0xC79]={d='on'},
[0xC7A]={d='on'},
[0xC7B]={d='on'},
[0xC7C]={d='on'},
[0xC7D]={d='on'},
[0xC7E]={d='on'},
[0xC81]={d='nsm'},
[0xCBC]={d='nsm'},
[0xCCC]={d='nsm'},
[0xCCD]={d='nsm'},
[0xCE2]={d='nsm'},
[0xCE3]={d='nsm'},
[0xD01]={d='nsm'},
[0xD41]={d='nsm'},
[0xD42]={d='nsm'},
[0xD43]={d='nsm'},
[0xD44]={d='nsm'},
[0xD4D]={d='nsm'},
[0xD62]={d='nsm'},
[0xD63]={d='nsm'},
[0xDCA]={d='nsm'},
[0xDD2]={d='nsm'},
[0xDD3]={d='nsm'},
[0xDD4]={d='nsm'},
[0xDD6]={d='nsm'},
[0xE31]={d='nsm'},
[0xE34]={d='nsm'},
[0xE35]={d='nsm'},
[0xE36]={d='nsm'},
[0xE37]={d='nsm'},
[0xE38]={d='nsm'},
[0xE39]={d='nsm'},
[0xE3A]={d='nsm'},
[0xE3F]={d='et'},
[0xE47]={d='nsm'},
[0xE48]={d='nsm'},
[0xE49]={d='nsm'},
[0xE4A]={d='nsm'},
[0xE4B]={d='nsm'},
[0xE4C]={d='nsm'},
[0xE4D]={d='nsm'},
[0xE4E]={d='nsm'},
[0xEB1]={d='nsm'},
[0xEB4]={d='nsm'},
[0xEB5]={d='nsm'},
[0xEB6]={d='nsm'},
[0xEB7]={d='nsm'},
[0xEB8]={d='nsm'},
[0xEB9]={d='nsm'},
[0xEBB]={d='nsm'},
[0xEBC]={d='nsm'},
[0xEC8]={d='nsm'},
[0xEC9]={d='nsm'},
[0xECA]={d='nsm'},
[0xECB]={d='nsm'},
[0xECC]={d='nsm'},
[0xECD]={d='nsm'},
[0xF18]={d='nsm'},
[0xF19]={d='nsm'},
[0xF35]={d='nsm'},
[0xF37]={d='nsm'},
[0xF39]={d='nsm'},
[0xF3A]={d='on', m=0xF3B},
[0xF3B]={d='on', m=0xF3A},
[0xF3C]={d='on', m=0xF3D},
[0xF3D]={d='on', m=0xF3C},
[0xF71]={d='nsm'},
[0xF72]={d='nsm'},
[0xF73]={d='nsm'},
[0xF74]={d='nsm'},
[0xF75]={d='nsm'},
[0xF76]={d='nsm'},
[0xF77]={d='nsm'},
[0xF78]={d='nsm'},
[0xF79]={d='nsm'},
[0xF7A]={d='nsm'},
[0xF7B]={d='nsm'},
[0xF7C]={d='nsm'},
[0xF7D]={d='nsm'},
[0xF7E]={d='nsm'},
[0xF80]={d='nsm'},
[0xF81]={d='nsm'},
[0xF82]={d='nsm'},
[0xF83]={d='nsm'},
[0xF84]={d='nsm'},
[0xF86]={d='nsm'},
[0xF87]={d='nsm'},
[0xF8D]={d='nsm'},
[0xF8E]={d='nsm'},
[0xF8F]={d='nsm'},
[0xF90]={d='nsm'},
[0xF91]={d='nsm'},
[0xF92]={d='nsm'},
[0xF93]={d='nsm'},
[0xF94]={d='nsm'},
[0xF95]={d='nsm'},
[0xF96]={d='nsm'},
[0xF97]={d='nsm'},
[0xF99]={d='nsm'},
[0xF9A]={d='nsm'},
[0xF9B]={d='nsm'},
[0xF9C]={d='nsm'},
[0xF9D]={d='nsm'},
[0xF9E]={d='nsm'},
[0xF9F]={d='nsm'},
[0xFA0]={d='nsm'},
[0xFA1]={d='nsm'},
[0xFA2]={d='nsm'},
[0xFA3]={d='nsm'},
[0xFA4]={d='nsm'},
[0xFA5]={d='nsm'},
[0xFA6]={d='nsm'},
[0xFA7]={d='nsm'},
[0xFA8]={d='nsm'},
[0xFA9]={d='nsm'},
[0xFAA]={d='nsm'},
[0xFAB]={d='nsm'},
[0xFAC]={d='nsm'},
[0xFAD]={d='nsm'},
[0xFAE]={d='nsm'},
[0xFAF]={d='nsm'},
[0xFB0]={d='nsm'},
[0xFB1]={d='nsm'},
[0xFB2]={d='nsm'},
[0xFB3]={d='nsm'},
[0xFB4]={d='nsm'},
[0xFB5]={d='nsm'},
[0xFB6]={d='nsm'},
[0xFB7]={d='nsm'},
[0xFB8]={d='nsm'},
[0xFB9]={d='nsm'},
[0xFBA]={d='nsm'},
[0xFBB]={d='nsm'},
[0xFBC]={d='nsm'},
[0xFC6]={d='nsm'},
[0x102D]={d='nsm'},
[0x102E]={d='nsm'},
[0x102F]={d='nsm'},
[0x1030]={d='nsm'},
[0x1032]={d='nsm'},
[0x1033]={d='nsm'},
[0x1034]={d='nsm'},
[0x1035]={d='nsm'},
[0x1036]={d='nsm'},
[0x1037]={d='nsm'},
[0x1039]={d='nsm'},
[0x103A]={d='nsm'},
[0x103D]={d='nsm'},
[0x103E]={d='nsm'},
[0x1058]={d='nsm'},
[0x1059]={d='nsm'},
[0x105E]={d='nsm'},
[0x105F]={d='nsm'},
[0x1060]={d='nsm'},
[0x1071]={d='nsm'},
[0x1072]={d='nsm'},
[0x1073]={d='nsm'},
[0x1074]={d='nsm'},
[0x1082]={d='nsm'},
[0x1085]={d='nsm'},
[0x1086]={d='nsm'},
[0x108D]={d='nsm'},
[0x109D]={d='nsm'},
[0x135D]={d='nsm'},
[0x135E]={d='nsm'},
[0x135F]={d='nsm'},
[0x1390]={d='on'},
[0x1391]={d='on'},
[0x1392]={d='on'},
[0x1393]={d='on'},
[0x1394]={d='on'},
[0x1395]={d='on'},
[0x1396]={d='on'},
[0x1397]={d='on'},
[0x1398]={d='on'},
[0x1399]={d='on'},
[0x1400]={d='on'},
[0x1680]={d='ws'},
[0x169B]={d='on', m=0x169C},
[0x169C]={d='on', m=0x169B},
[0x1712]={d='nsm'},
[0x1713]={d='nsm'},
[0x1714]={d='nsm'},
[0x1732]={d='nsm'},
[0x1733]={d='nsm'},
[0x1734]={d='nsm'},
[0x1752]={d='nsm'},
[0x1753]={d='nsm'},
[0x1772]={d='nsm'},
[0x1773]={d='nsm'},
[0x17B4]={d='nsm'},
[0x17B5]={d='nsm'},
[0x17B7]={d='nsm'},
[0x17B8]={d='nsm'},
[0x17B9]={d='nsm'},
[0x17BA]={d='nsm'},
[0x17BB]={d='nsm'},
[0x17BC]={d='nsm'},
[0x17BD]={d='nsm'},
[0x17C6]={d='nsm'},
[0x17C9]={d='nsm'},
[0x17CA]={d='nsm'},
[0x17CB]={d='nsm'},
[0x17CC]={d='nsm'},
[0x17CD]={d='nsm'},
[0x17CE]={d='nsm'},
[0x17CF]={d='nsm'},
[0x17D0]={d='nsm'},
[0x17D1]={d='nsm'},
[0x17D2]={d='nsm'},
[0x17D3]={d='nsm'},
[0x17DB]={d='et'},
[0x17DD]={d='nsm'},
[0x17F0]={d='on'},
[0x17F1]={d='on'},
[0x17F2]={d='on'},
[0x17F3]={d='on'},
[0x17F4]={d='on'},
[0x17F5]={d='on'},
[0x17F6]={d='on'},
[0x17F7]={d='on'},
[0x17F8]={d='on'},
[0x17F9]={d='on'},
[0x1800]={d='on'},
[0x1801]={d='on'},
[0x1802]={d='on'},
[0x1803]={d='on'},
[0x1804]={d='on'},
[0x1805]={d='on'},
[0x1806]={d='on'},
[0x1807]={d='on'},
[0x1808]={d='on'},
[0x1809]={d='on'},
[0x180A]={d='on'},
[0x180B]={d='nsm'},
[0x180C]={d='nsm'},
[0x180D]={d='nsm'},
[0x180E]={d='bn'},
[0x1885]={d='nsm'},
[0x1886]={d='nsm'},
[0x18A9]={d='nsm'},
[0x1920]={d='nsm'},
[0x1921]={d='nsm'},
[0x1922]={d='nsm'},
[0x1927]={d='nsm'},
[0x1928]={d='nsm'},
[0x1932]={d='nsm'},
[0x1939]={d='nsm'},
[0x193A]={d='nsm'},
[0x193B]={d='nsm'},
[0x1940]={d='on'},
[0x1944]={d='on'},
[0x1945]={d='on'},
[0x19DE]={d='on'},
[0x19DF]={d='on'},
[0x19E0]={d='on'},
[0x19E1]={d='on'},
[0x19E2]={d='on'},
[0x19E3]={d='on'},
[0x19E4]={d='on'},
[0x19E5]={d='on'},
[0x19E6]={d='on'},
[0x19E7]={d='on'},
[0x19E8]={d='on'},
[0x19E9]={d='on'},
[0x19EA]={d='on'},
[0x19EB]={d='on'},
[0x19EC]={d='on'},
[0x19ED]={d='on'},
[0x19EE]={d='on'},
[0x19EF]={d='on'},
[0x19F0]={d='on'},
[0x19F1]={d='on'},
[0x19F2]={d='on'},
[0x19F3]={d='on'},
[0x19F4]={d='on'},
[0x19F5]={d='on'},
[0x19F6]={d='on'},
[0x19F7]={d='on'},
[0x19F8]={d='on'},
[0x19F9]={d='on'},
[0x19FA]={d='on'},
[0x19FB]={d='on'},
[0x19FC]={d='on'},
[0x19FD]={d='on'},
[0x19FE]={d='on'},
[0x19FF]={d='on'},
[0x1A17]={d='nsm'},
[0x1A18]={d='nsm'},
[0x1A1B]={d='nsm'},
[0x1A56]={d='nsm'},
[0x1A58]={d='nsm'},
[0x1A59]={d='nsm'},
[0x1A5A]={d='nsm'},
[0x1A5B]={d='nsm'},
[0x1A5C]={d='nsm'},
[0x1A5D]={d='nsm'},
[0x1A5E]={d='nsm'},
[0x1A60]={d='nsm'},
[0x1A62]={d='nsm'},
[0x1A65]={d='nsm'},
[0x1A66]={d='nsm'},
[0x1A67]={d='nsm'},
[0x1A68]={d='nsm'},
[0x1A69]={d='nsm'},
[0x1A6A]={d='nsm'},
[0x1A6B]={d='nsm'},
[0x1A6C]={d='nsm'},
[0x1A73]={d='nsm'},
[0x1A74]={d='nsm'},
[0x1A75]={d='nsm'},
[0x1A76]={d='nsm'},
[0x1A77]={d='nsm'},
[0x1A78]={d='nsm'},
[0x1A79]={d='nsm'},
[0x1A7A]={d='nsm'},
[0x1A7B]={d='nsm'},
[0x1A7C]={d='nsm'},
[0x1A7F]={d='nsm'},
[0x1AB0]={d='nsm'},
[0x1AB1]={d='nsm'},
[0x1AB2]={d='nsm'},
[0x1AB3]={d='nsm'},
[0x1AB4]={d='nsm'},
[0x1AB5]={d='nsm'},
[0x1AB6]={d='nsm'},
[0x1AB7]={d='nsm'},
[0x1AB8]={d='nsm'},
[0x1AB9]={d='nsm'},
[0x1ABA]={d='nsm'},
[0x1ABB]={d='nsm'},
[0x1ABC]={d='nsm'},
[0x1ABD]={d='nsm'},
[0x1ABE]={d='nsm'},
[0x1B00]={d='nsm'},
[0x1B01]={d='nsm'},
[0x1B02]={d='nsm'},
[0x1B03]={d='nsm'},
[0x1B34]={d='nsm'},
[0x1B36]={d='nsm'},
[0x1B37]={d='nsm'},
[0x1B38]={d='nsm'},
[0x1B39]={d='nsm'},
[0x1B3A]={d='nsm'},
[0x1B3C]={d='nsm'},
[0x1B42]={d='nsm'},
[0x1B6B]={d='nsm'},
[0x1B6C]={d='nsm'},
[0x1B6D]={d='nsm'},
[0x1B6E]={d='nsm'},
[0x1B6F]={d='nsm'},
[0x1B70]={d='nsm'},
[0x1B71]={d='nsm'},
[0x1B72]={d='nsm'},
[0x1B73]={d='nsm'},
[0x1B80]={d='nsm'},
[0x1B81]={d='nsm'},
[0x1BA2]={d='nsm'},
[0x1BA3]={d='nsm'},
[0x1BA4]={d='nsm'},
[0x1BA5]={d='nsm'},
[0x1BA8]={d='nsm'},
[0x1BA9]={d='nsm'},
[0x1BAB]={d='nsm'},
[0x1BAC]={d='nsm'},
[0x1BAD]={d='nsm'},
[0x1BE6]={d='nsm'},
[0x1BE8]={d='nsm'},
[0x1BE9]={d='nsm'},
[0x1BED]={d='nsm'},
[0x1BEF]={d='nsm'},
[0x1BF0]={d='nsm'},
[0x1BF1]={d='nsm'},
[0x1C2C]={d='nsm'},
[0x1C2D]={d='nsm'},
[0x1C2E]={d='nsm'},
[0x1C2F]={d='nsm'},
[0x1C30]={d='nsm'},
[0x1C31]={d='nsm'},
[0x1C32]={d='nsm'},
[0x1C33]={d='nsm'},
[0x1C36]={d='nsm'},
[0x1C37]={d='nsm'},
[0x1CD0]={d='nsm'},
[0x1CD1]={d='nsm'},
[0x1CD2]={d='nsm'},
[0x1CD4]={d='nsm'},
[0x1CD5]={d='nsm'},
[0x1CD6]={d='nsm'},
[0x1CD7]={d='nsm'},
[0x1CD8]={d='nsm'},
[0x1CD9]={d='nsm'},
[0x1CDA]={d='nsm'},
[0x1CDB]={d='nsm'},
[0x1CDC]={d='nsm'},
[0x1CDD]={d='nsm'},
[0x1CDE]={d='nsm'},
[0x1CDF]={d='nsm'},
[0x1CE0]={d='nsm'},
[0x1CE2]={d='nsm'},
[0x1CE3]={d='nsm'},
[0x1CE4]={d='nsm'},
[0x1CE5]={d='nsm'},
[0x1CE6]={d='nsm'},
[0x1CE7]={d='nsm'},
[0x1CE8]={d='nsm'},
[0x1CED]={d='nsm'},
[0x1CF4]={d='nsm'},
[0x1CF8]={d='nsm'},
[0x1CF9]={d='nsm'},
[0x1DC0]={d='nsm'},
[0x1DC1]={d='nsm'},
[0x1DC2]={d='nsm'},
[0x1DC3]={d='nsm'},
[0x1DC4]={d='nsm'},
[0x1DC5]={d='nsm'},
[0x1DC6]={d='nsm'},
[0x1DC7]={d='nsm'},
[0x1DC8]={d='nsm'},
[0x1DC9]={d='nsm'},
[0x1DCA]={d='nsm'},
[0x1DCB]={d='nsm'},
[0x1DCC]={d='nsm'},
[0x1DCD]={d='nsm'},
[0x1DCE]={d='nsm'},
[0x1DCF]={d='nsm'},
[0x1DD0]={d='nsm'},
[0x1DD1]={d='nsm'},
[0x1DD2]={d='nsm'},
[0x1DD3]={d='nsm'},
[0x1DD4]={d='nsm'},
[0x1DD5]={d='nsm'},
[0x1DD6]={d='nsm'},
[0x1DD7]={d='nsm'},
[0x1DD8]={d='nsm'},
[0x1DD9]={d='nsm'},
[0x1DDA]={d='nsm'},
[0x1DDB]={d='nsm'},
[0x1DDC]={d='nsm'},
[0x1DDD]={d='nsm'},
[0x1DDE]={d='nsm'},
[0x1DDF]={d='nsm'},
[0x1DE0]={d='nsm'},
[0x1DE1]={d='nsm'},
[0x1DE2]={d='nsm'},
[0x1DE3]={d='nsm'},
[0x1DE4]={d='nsm'},
[0x1DE5]={d='nsm'},
[0x1DE6]={d='nsm'},
[0x1DE7]={d='nsm'},
[0x1DE8]={d='nsm'},
[0x1DE9]={d='nsm'},
[0x1DEA]={d='nsm'},
[0x1DEB]={d='nsm'},
[0x1DEC]={d='nsm'},
[0x1DED]={d='nsm'},
[0x1DEE]={d='nsm'},
[0x1DEF]={d='nsm'},
[0x1DF0]={d='nsm'},
[0x1DF1]={d='nsm'},
[0x1DF2]={d='nsm'},
[0x1DF3]={d='nsm'},
[0x1DF4]={d='nsm'},
[0x1DF5]={d='nsm'},
[0x1DFB]={d='nsm'},
[0x1DFC]={d='nsm'},
[0x1DFD]={d='nsm'},
[0x1DFE]={d='nsm'},
[0x1DFF]={d='nsm'},
[0x1FBD]={d='on'},
[0x1FBF]={d='on'},
[0x1FC0]={d='on'},
[0x1FC1]={d='on'},
[0x1FCD]={d='on'},
[0x1FCE]={d='on'},
[0x1FCF]={d='on'},
[0x1FDD]={d='on'},
[0x1FDE]={d='on'},
[0x1FDF]={d='on'},
[0x1FED]={d='on'},
[0x1FEE]={d='on'},
[0x1FEF]={d='on'},
[0x1FFD]={d='on'},
[0x1FFE]={d='on'},
[0x2000]={d='ws'},
[0x2001]={d='ws'},
[0x2002]={d='ws'},
[0x2003]={d='ws'},
[0x2004]={d='ws'},
[0x2005]={d='ws'},
[0x2006]={d='ws'},
[0x2007]={d='ws'},
[0x2008]={d='ws'},
[0x2009]={d='ws'},
[0x200A]={d='ws'},
[0x200B]={d='bn'},
[0x200C]={d='bn'},
[0x200D]={d='bn'},
[0x200F]={d='r'},
[0x2010]={d='on'},
[0x2011]={d='on'},
[0x2012]={d='on'},
[0x2013]={d='on'},
[0x2014]={d='on'},
[0x2015]={d='on'},
[0x2016]={d='on'},
[0x2017]={d='on'},
[0x2018]={d='on'},
[0x2019]={d='on'},
[0x201A]={d='on'},
[0x201B]={d='on'},
[0x201C]={d='on'},
[0x201D]={d='on'},
[0x201E]={d='on'},
[0x201F]={d='on'},
[0x2020]={d='on'},
[0x2021]={d='on'},
[0x2022]={d='on'},
[0x2023]={d='on'},
[0x2024]={d='on'},
[0x2025]={d='on'},
[0x2026]={d='on'},
[0x2027]={d='on'},
[0x2028]={d='ws'},
[0x2029]={d='b'},
[0x202A]={d='lre'},
[0x202B]={d='rle'},
[0x202C]={d='pdf'},
[0x202D]={d='lro'},
[0x202E]={d='rlo'},
[0x202F]={d='cs'},
[0x2030]={d='et'},
[0x2031]={d='et'},
[0x2032]={d='et'},
[0x2033]={d='et'},
[0x2034]={d='et'},
[0x2035]={d='on'},
[0x2036]={d='on'},
[0x2037]={d='on'},
[0x2038]={d='on'},
[0x2039]={d='on', m=0x203A},
[0x203A]={d='on', m=0x2039},
[0x203B]={d='on'},
[0x203C]={d='on'},
[0x203D]={d='on'},
[0x203E]={d='on'},
[0x203F]={d='on'},
[0x2040]={d='on'},
[0x2041]={d='on'},
[0x2042]={d='on'},
[0x2043]={d='on'},
[0x2044]={d='cs'},
[0x2045]={d='on', m=0x2046},
[0x2046]={d='on', m=0x2045},
[0x2047]={d='on'},
[0x2048]={d='on'},
[0x2049]={d='on'},
[0x204A]={d='on'},
[0x204B]={d='on'},
[0x204C]={d='on'},
[0x204D]={d='on'},
[0x204E]={d='on'},
[0x204F]={d='on'},
[0x2050]={d='on'},
[0x2051]={d='on'},
[0x2052]={d='on'},
[0x2053]={d='on'},
[0x2054]={d='on'},
[0x2055]={d='on'},
[0x2056]={d='on'},
[0x2057]={d='on'},
[0x2058]={d='on'},
[0x2059]={d='on'},
[0x205A]={d='on'},
[0x205B]={d='on'},
[0x205C]={d='on'},
[0x205D]={d='on'},
[0x205E]={d='on'},
[0x205F]={d='ws'},
[0x2060]={d='bn'},
[0x2061]={d='bn'},
[0x2062]={d='bn'},
[0x2063]={d='bn'},
[0x2064]={d='bn'},
[0x2066]={d='lri'},
[0x2067]={d='rli'},
[0x2068]={d='fsi'},
[0x2069]={d='pdi'},
[0x206A]={d='bn'},
[0x206B]={d='bn'},
[0x206C]={d='bn'},
[0x206D]={d='bn'},
[0x206E]={d='bn'},
[0x206F]={d='bn'},
[0x2070]={d='en'},
[0x2074]={d='en'},
[0x2075]={d='en'},
[0x2076]={d='en'},
[0x2077]={d='en'},
[0x2078]={d='en'},
[0x2079]={d='en'},
[0x207A]={d='es'},
[0x207B]={d='es'},
[0x207C]={d='on'},
[0x207D]={d='on', m=0x207E},
[0x207E]={d='on', m=0x207D},
[0x2080]={d='en'},
[0x2081]={d='en'},
[0x2082]={d='en'},
[0x2083]={d='en'},
[0x2084]={d='en'},
[0x2085]={d='en'},
[0x2086]={d='en'},
[0x2087]={d='en'},
[0x2088]={d='en'},
[0x2089]={d='en'},
[0x208A]={d='es'},
[0x208B]={d='es'},
[0x208C]={d='on'},
[0x208D]={d='on', m=0x208E},
[0x208E]={d='on', m=0x208D},
[0x20A0]={d='et'},
[0x20A1]={d='et'},
[0x20A2]={d='et'},
[0x20A3]={d='et'},
[0x20A4]={d='et'},
[0x20A5]={d='et'},
[0x20A6]={d='et'},
[0x20A7]={d='et'},
[0x20A8]={d='et'},
[0x20A9]={d='et'},
[0x20AA]={d='et'},
[0x20AB]={d='et'},
[0x20AC]={d='et'},
[0x20AD]={d='et'},
[0x20AE]={d='et'},
[0x20AF]={d='et'},
[0x20B0]={d='et'},
[0x20B1]={d='et'},
[0x20B2]={d='et'},
[0x20B3]={d='et'},
[0x20B4]={d='et'},
[0x20B5]={d='et'},
[0x20B6]={d='et'},
[0x20B7]={d='et'},
[0x20B8]={d='et'},
[0x20B9]={d='et'},
[0x20BA]={d='et'},
[0x20BB]={d='et'},
[0x20BC]={d='et'},
[0x20BD]={d='et'},
[0x20BE]={d='et'},
[0x20D0]={d='nsm'},
[0x20D1]={d='nsm'},
[0x20D2]={d='nsm'},
[0x20D3]={d='nsm'},
[0x20D4]={d='nsm'},
[0x20D5]={d='nsm'},
[0x20D6]={d='nsm'},
[0x20D7]={d='nsm'},
[0x20D8]={d='nsm'},
[0x20D9]={d='nsm'},
[0x20DA]={d='nsm'},
[0x20DB]={d='nsm'},
[0x20DC]={d='nsm'},
[0x20DD]={d='nsm'},
[0x20DE]={d='nsm'},
[0x20DF]={d='nsm'},
[0x20E0]={d='nsm'},
[0x20E1]={d='nsm'},
[0x20E2]={d='nsm'},
[0x20E3]={d='nsm'},
[0x20E4]={d='nsm'},
[0x20E5]={d='nsm'},
[0x20E6]={d='nsm'},
[0x20E7]={d='nsm'},
[0x20E8]={d='nsm'},
[0x20E9]={d='nsm'},
[0x20EA]={d='nsm'},
[0x20EB]={d='nsm'},
[0x20EC]={d='nsm'},
[0x20ED]={d='nsm'},
[0x20EE]={d='nsm'},
[0x20EF]={d='nsm'},
[0x20F0]={d='nsm'},
[0x2100]={d='on'},
[0x2101]={d='on'},
[0x2103]={d='on'},
[0x2104]={d='on'},
[0x2105]={d='on'},
[0x2106]={d='on'},
[0x2108]={d='on'},
[0x2109]={d='on'},
[0x2114]={d='on'},
[0x2116]={d='on'},
[0x2117]={d='on'},
[0x2118]={d='on'},
[0x211E]={d='on'},
[0x211F]={d='on'},
[0x2120]={d='on'},
[0x2121]={d='on'},
[0x2122]={d='on'},
[0x2123]={d='on'},
[0x2125]={d='on'},
[0x2127]={d='on'},
[0x2129]={d='on'},
[0x212E]={d='et'},
[0x213A]={d='on'},
[0x213B]={d='on'},
[0x2140]={d='on'},
[0x2141]={d='on'},
[0x2142]={d='on'},
[0x2143]={d='on'},
[0x2144]={d='on'},
[0x214A]={d='on'},
[0x214B]={d='on'},
[0x214C]={d='on'},
[0x214D]={d='on'},
[0x2150]={d='on'},
[0x2151]={d='on'},
[0x2152]={d='on'},
[0x2153]={d='on'},
[0x2154]={d='on'},
[0x2155]={d='on'},
[0x2156]={d='on'},
[0x2157]={d='on'},
[0x2158]={d='on'},
[0x2159]={d='on'},
[0x215A]={d='on'},
[0x215B]={d='on'},
[0x215C]={d='on'},
[0x215D]={d='on'},
[0x215E]={d='on'},
[0x215F]={d='on'},
[0x2189]={d='on'},
[0x218A]={d='on'},
[0x218B]={d='on'},
[0x2190]={d='on'},
[0x2191]={d='on'},
[0x2192]={d='on'},
[0x2193]={d='on'},
[0x2194]={d='on'},
[0x2195]={d='on'},
[0x2196]={d='on'},
[0x2197]={d='on'},
[0x2198]={d='on'},
[0x2199]={d='on'},
[0x219A]={d='on'},
[0x219B]={d='on'},
[0x219C]={d='on'},
[0x219D]={d='on'},
[0x219E]={d='on'},
[0x219F]={d='on'},
[0x21A0]={d='on'},
[0x21A1]={d='on'},
[0x21A2]={d='on'},
[0x21A3]={d='on'},
[0x21A4]={d='on'},
[0x21A5]={d='on'},
[0x21A6]={d='on'},
[0x21A7]={d='on'},
[0x21A8]={d='on'},
[0x21A9]={d='on'},
[0x21AA]={d='on'},
[0x21AB]={d='on'},
[0x21AC]={d='on'},
[0x21AD]={d='on'},
[0x21AE]={d='on'},
[0x21AF]={d='on'},
[0x21B0]={d='on'},
[0x21B1]={d='on'},
[0x21B2]={d='on'},
[0x21B3]={d='on'},
[0x21B4]={d='on'},
[0x21B5]={d='on'},
[0x21B6]={d='on'},
[0x21B7]={d='on'},
[0x21B8]={d='on'},
[0x21B9]={d='on'},
[0x21BA]={d='on'},
[0x21BB]={d='on'},
[0x21BC]={d='on'},
[0x21BD]={d='on'},
[0x21BE]={d='on'},
[0x21BF]={d='on'},
[0x21C0]={d='on'},
[0x21C1]={d='on'},
[0x21C2]={d='on'},
[0x21C3]={d='on'},
[0x21C4]={d='on'},
[0x21C5]={d='on'},
[0x21C6]={d='on'},
[0x21C7]={d='on'},
[0x21C8]={d='on'},
[0x21C9]={d='on'},
[0x21CA]={d='on'},
[0x21CB]={d='on'},
[0x21CC]={d='on'},
[0x21CD]={d='on'},
[0x21CE]={d='on'},
[0x21CF]={d='on'},
[0x21D0]={d='on'},
[0x21D1]={d='on'},
[0x21D2]={d='on'},
[0x21D3]={d='on'},
[0x21D4]={d='on'},
[0x21D5]={d='on'},
[0x21D6]={d='on'},
[0x21D7]={d='on'},
[0x21D8]={d='on'},
[0x21D9]={d='on'},
[0x21DA]={d='on'},
[0x21DB]={d='on'},
[0x21DC]={d='on'},
[0x21DD]={d='on'},
[0x21DE]={d='on'},
[0x21DF]={d='on'},
[0x21E0]={d='on'},
[0x21E1]={d='on'},
[0x21E2]={d='on'},
[0x21E3]={d='on'},
[0x21E4]={d='on'},
[0x21E5]={d='on'},
[0x21E6]={d='on'},
[0x21E7]={d='on'},
[0x21E8]={d='on'},
[0x21E9]={d='on'},
[0x21EA]={d='on'},
[0x21EB]={d='on'},
[0x21EC]={d='on'},
[0x21ED]={d='on'},
[0x21EE]={d='on'},
[0x21EF]={d='on'},
[0x21F0]={d='on'},
[0x21F1]={d='on'},
[0x21F2]={d='on'},
[0x21F3]={d='on'},
[0x21F4]={d='on'},
[0x21F5]={d='on'},
[0x21F6]={d='on'},
[0x21F7]={d='on'},
[0x21F8]={d='on'},
[0x21F9]={d='on'},
[0x21FA]={d='on'},
[0x21FB]={d='on'},
[0x21FC]={d='on'},
[0x21FD]={d='on'},
[0x21FE]={d='on'},
[0x21FF]={d='on'},
[0x2200]={d='on'},
[0x2201]={d='on'},
[0x2202]={d='on'},
[0x2203]={d='on'},
[0x2204]={d='on'},
[0x2205]={d='on'},
[0x2206]={d='on'},
[0x2207]={d='on'},
[0x2208]={d='on', m=0x220B},
[0x2209]={d='on', m=0x220C},
[0x220A]={d='on', m=0x220D},
[0x220B]={d='on', m=0x2208},
[0x220C]={d='on', m=0x2209},
[0x220D]={d='on', m=0x220A},
[0x220E]={d='on'},
[0x220F]={d='on'},
[0x2210]={d='on'},
[0x2211]={d='on'},
[0x2212]={d='es'},
[0x2213]={d='et'},
[0x2214]={d='on'},
[0x2215]={d='on', m=0x29F5},
[0x2216]={d='on'},
[0x2217]={d='on'},
[0x2218]={d='on'},
[0x2219]={d='on'},
[0x221A]={d='on'},
[0x221B]={d='on'},
[0x221C]={d='on'},
[0x221D]={d='on'},
[0x221E]={d='on'},
[0x221F]={d='on'},
[0x2220]={d='on'},
[0x2221]={d='on'},
[0x2222]={d='on'},
[0x2223]={d='on'},
[0x2224]={d='on'},
[0x2225]={d='on'},
[0x2226]={d='on'},
[0x2227]={d='on'},
[0x2228]={d='on'},
[0x2229]={d='on'},
[0x222A]={d='on'},
[0x222B]={d='on'},
[0x222C]={d='on'},
[0x222D]={d='on'},
[0x222E]={d='on'},
[0x222F]={d='on'},
[0x2230]={d='on'},
[0x2231]={d='on'},
[0x2232]={d='on'},
[0x2233]={d='on'},
[0x2234]={d='on'},
[0x2235]={d='on'},
[0x2236]={d='on'},
[0x2237]={d='on'},
[0x2238]={d='on'},
[0x2239]={d='on'},
[0x223A]={d='on'},
[0x223B]={d='on'},
[0x223C]={d='on', m=0x223D},
[0x223D]={d='on', m=0x223C},
[0x223E]={d='on'},
[0x223F]={d='on'},
[0x2240]={d='on'},
[0x2241]={d='on'},
[0x2242]={d='on'},
[0x2243]={d='on', m=0x22CD},
[0x2244]={d='on'},
[0x2245]={d='on'},
[0x2246]={d='on'},
[0x2247]={d='on'},
[0x2248]={d='on'},
[0x2249]={d='on'},
[0x224A]={d='on'},
[0x224B]={d='on'},
[0x224C]={d='on'},
[0x224D]={d='on'},
[0x224E]={d='on'},
[0x224F]={d='on'},
[0x2250]={d='on'},
[0x2251]={d='on'},
[0x2252]={d='on', m=0x2253},
[0x2253]={d='on', m=0x2252},
[0x2254]={d='on', m=0x2255},
[0x2255]={d='on', m=0x2254},
[0x2256]={d='on'},
[0x2257]={d='on'},
[0x2258]={d='on'},
[0x2259]={d='on'},
[0x225A]={d='on'},
[0x225B]={d='on'},
[0x225C]={d='on'},
[0x225D]={d='on'},
[0x225E]={d='on'},
[0x225F]={d='on'},
[0x2260]={d='on'},
[0x2261]={d='on'},
[0x2262]={d='on'},
[0x2263]={d='on'},
[0x2264]={d='on', m=0x2265},
[0x2265]={d='on', m=0x2264},
[0x2266]={d='on', m=0x2267},
[0x2267]={d='on', m=0x2266},
[0x2268]={d='on', m=0x2269},
[0x2269]={d='on', m=0x2268},
[0x226A]={d='on', m=0x226B},
[0x226B]={d='on', m=0x226A},
[0x226C]={d='on'},
[0x226D]={d='on'},
[0x226E]={d='on', m=0x226F},
[0x226F]={d='on', m=0x226E},
[0x2270]={d='on', m=0x2271},
[0x2271]={d='on', m=0x2270},
[0x2272]={d='on', m=0x2273},
[0x2273]={d='on', m=0x2272},
[0x2274]={d='on', m=0x2275},
[0x2275]={d='on', m=0x2274},
[0x2276]={d='on', m=0x2277},
[0x2277]={d='on', m=0x2276},
[0x2278]={d='on', m=0x2279},
[0x2279]={d='on', m=0x2278},
[0x227A]={d='on', m=0x227B},
[0x227B]={d='on', m=0x227A},
[0x227C]={d='on', m=0x227D},
[0x227D]={d='on', m=0x227C},
[0x227E]={d='on', m=0x227F},
[0x227F]={d='on', m=0x227E},
[0x2280]={d='on', m=0x2281},
[0x2281]={d='on', m=0x2280},
[0x2282]={d='on', m=0x2283},
[0x2283]={d='on', m=0x2282},
[0x2284]={d='on', m=0x2285},
[0x2285]={d='on', m=0x2284},
[0x2286]={d='on', m=0x2287},
[0x2287]={d='on', m=0x2286},
[0x2288]={d='on', m=0x2289},
[0x2289]={d='on', m=0x2288},
[0x228A]={d='on', m=0x228B},
[0x228B]={d='on', m=0x228A},
[0x228C]={d='on'},
[0x228D]={d='on'},
[0x228E]={d='on'},
[0x228F]={d='on', m=0x2290},
[0x2290]={d='on', m=0x228F},
[0x2291]={d='on', m=0x2292},
[0x2292]={d='on', m=0x2291},
[0x2293]={d='on'},
[0x2294]={d='on'},
[0x2295]={d='on'},
[0x2296]={d='on'},
[0x2297]={d='on'},
[0x2298]={d='on', m=0x29B8},
[0x2299]={d='on'},
[0x229A]={d='on'},
[0x229B]={d='on'},
[0x229C]={d='on'},
[0x229D]={d='on'},
[0x229E]={d='on'},
[0x229F]={d='on'},
[0x22A0]={d='on'},
[0x22A1]={d='on'},
[0x22A2]={d='on', m=0x22A3},
[0x22A3]={d='on', m=0x22A2},
[0x22A4]={d='on'},
[0x22A5]={d='on'},
[0x22A6]={d='on', m=0x2ADE},
[0x22A7]={d='on'},
[0x22A8]={d='on', m=0x2AE4},
[0x22A9]={d='on', m=0x2AE3},
[0x22AA]={d='on'},
[0x22AB]={d='on', m=0x2AE5},
[0x22AC]={d='on'},
[0x22AD]={d='on'},
[0x22AE]={d='on'},
[0x22AF]={d='on'},
[0x22B0]={d='on', m=0x22B1},
[0x22B1]={d='on', m=0x22B0},
[0x22B2]={d='on', m=0x22B3},
[0x22B3]={d='on', m=0x22B2},
[0x22B4]={d='on', m=0x22B5},
[0x22B5]={d='on', m=0x22B4},
[0x22B6]={d='on', m=0x22B7},
[0x22B7]={d='on', m=0x22B6},
[0x22B8]={d='on'},
[0x22B9]={d='on'},
[0x22BA]={d='on'},
[0x22BB]={d='on'},
[0x22BC]={d='on'},
[0x22BD]={d='on'},
[0x22BE]={d='on'},
[0x22BF]={d='on'},
[0x22C0]={d='on'},
[0x22C1]={d='on'},
[0x22C2]={d='on'},
[0x22C3]={d='on'},
[0x22C4]={d='on'},
[0x22C5]={d='on'},
[0x22C6]={d='on'},
[0x22C7]={d='on'},
[0x22C8]={d='on'},
[0x22C9]={d='on', m=0x22CA},
[0x22CA]={d='on', m=0x22C9},
[0x22CB]={d='on', m=0x22CC},
[0x22CC]={d='on', m=0x22CB},
[0x22CD]={d='on', m=0x2243},
[0x22CE]={d='on'},
[0x22CF]={d='on'},
[0x22D0]={d='on', m=0x22D1},
[0x22D1]={d='on', m=0x22D0},
[0x22D2]={d='on'},
[0x22D3]={d='on'},
[0x22D4]={d='on'},
[0x22D5]={d='on'},
[0x22D6]={d='on', m=0x22D7},
[0x22D7]={d='on', m=0x22D6},
[0x22D8]={d='on', m=0x22D9},
[0x22D9]={d='on', m=0x22D8},
[0x22DA]={d='on', m=0x22DB},
[0x22DB]={d='on', m=0x22DA},
[0x22DC]={d='on', m=0x22DD},
[0x22DD]={d='on', m=0x22DC},
[0x22DE]={d='on', m=0x22DF},
[0x22DF]={d='on', m=0x22DE},
[0x22E0]={d='on', m=0x22E1},
[0x22E1]={d='on', m=0x22E0},
[0x22E2]={d='on', m=0x22E3},
[0x22E3]={d='on', m=0x22E2},
[0x22E4]={d='on', m=0x22E5},
[0x22E5]={d='on', m=0x22E4},
[0x22E6]={d='on', m=0x22E7},
[0x22E7]={d='on', m=0x22E6},
[0x22E8]={d='on', m=0x22E9},
[0x22E9]={d='on', m=0x22E8},
[0x22EA]={d='on', m=0x22EB},
[0x22EB]={d='on', m=0x22EA},
[0x22EC]={d='on', m=0x22ED},
[0x22ED]={d='on', m=0x22EC},
[0x22EE]={d='on'},
[0x22EF]={d='on'},
[0x22F0]={d='on', m=0x22F1},
[0x22F1]={d='on', m=0x22F0},
[0x22F2]={d='on', m=0x22FA},
[0x22F3]={d='on', m=0x22FB},
[0x22F4]={d='on', m=0x22FC},
[0x22F5]={d='on'},
[0x22F6]={d='on', m=0x22FD},
[0x22F7]={d='on', m=0x22FE},
[0x22F8]={d='on'},
[0x22F9]={d='on'},
[0x22FA]={d='on', m=0x22F2},
[0x22FB]={d='on', m=0x22F3},
[0x22FC]={d='on', m=0x22F4},
[0x22FD]={d='on', m=0x22F6},
[0x22FE]={d='on', m=0x22F7},
[0x22FF]={d='on'},
[0x2300]={d='on'},
[0x2301]={d='on'},
[0x2302]={d='on'},
[0x2303]={d='on'},
[0x2304]={d='on'},
[0x2305]={d='on'},
[0x2306]={d='on'},
[0x2307]={d='on'},
[0x2308]={d='on', m=0x2309},
[0x2309]={d='on', m=0x2308},
[0x230A]={d='on', m=0x230B},
[0x230B]={d='on', m=0x230A},
[0x230C]={d='on'},
[0x230D]={d='on'},
[0x230E]={d='on'},
[0x230F]={d='on'},
[0x2310]={d='on'},
[0x2311]={d='on'},
[0x2312]={d='on'},
[0x2313]={d='on'},
[0x2314]={d='on'},
[0x2315]={d='on'},
[0x2316]={d='on'},
[0x2317]={d='on'},
[0x2318]={d='on'},
[0x2319]={d='on'},
[0x231A]={d='on'},
[0x231B]={d='on'},
[0x231C]={d='on'},
[0x231D]={d='on'},
[0x231E]={d='on'},
[0x231F]={d='on'},
[0x2320]={d='on'},
[0x2321]={d='on'},
[0x2322]={d='on'},
[0x2323]={d='on'},
[0x2324]={d='on'},
[0x2325]={d='on'},
[0x2326]={d='on'},
[0x2327]={d='on'},
[0x2328]={d='on'},
[0x2329]={d='on', m=0x232A},
[0x232A]={d='on', m=0x2329},
[0x232B]={d='on'},
[0x232C]={d='on'},
[0x232D]={d='on'},
[0x232E]={d='on'},
[0x232F]={d='on'},
[0x2330]={d='on'},
[0x2331]={d='on'},
[0x2332]={d='on'},
[0x2333]={d='on'},
[0x2334]={d='on'},
[0x2335]={d='on'},
[0x237B]={d='on'},
[0x237C]={d='on'},
[0x237D]={d='on'},
[0x237E]={d='on'},
[0x237F]={d='on'},
[0x2380]={d='on'},
[0x2381]={d='on'},
[0x2382]={d='on'},
[0x2383]={d='on'},
[0x2384]={d='on'},
[0x2385]={d='on'},
[0x2386]={d='on'},
[0x2387]={d='on'},
[0x2388]={d='on'},
[0x2389]={d='on'},
[0x238A]={d='on'},
[0x238B]={d='on'},
[0x238C]={d='on'},
[0x238D]={d='on'},
[0x238E]={d='on'},
[0x238F]={d='on'},
[0x2390]={d='on'},
[0x2391]={d='on'},
[0x2392]={d='on'},
[0x2393]={d='on'},
[0x2394]={d='on'},
[0x2396]={d='on'},
[0x2397]={d='on'},
[0x2398]={d='on'},
[0x2399]={d='on'},
[0x239A]={d='on'},
[0x239B]={d='on'},
[0x239C]={d='on'},
[0x239D]={d='on'},
[0x239E]={d='on'},
[0x239F]={d='on'},
[0x23A0]={d='on'},
[0x23A1]={d='on'},
[0x23A2]={d='on'},
[0x23A3]={d='on'},
[0x23A4]={d='on'},
[0x23A5]={d='on'},
[0x23A6]={d='on'},
[0x23A7]={d='on'},
[0x23A8]={d='on'},
[0x23A9]={d='on'},
[0x23AA]={d='on'},
[0x23AB]={d='on'},
[0x23AC]={d='on'},
[0x23AD]={d='on'},
[0x23AE]={d='on'},
[0x23AF]={d='on'},
[0x23B0]={d='on'},
[0x23B1]={d='on'},
[0x23B2]={d='on'},
[0x23B3]={d='on'},
[0x23B4]={d='on'},
[0x23B5]={d='on'},
[0x23B6]={d='on'},
[0x23B7]={d='on'},
[0x23B8]={d='on'},
[0x23B9]={d='on'},
[0x23BA]={d='on'},
[0x23BB]={d='on'},
[0x23BC]={d='on'},
[0x23BD]={d='on'},
[0x23BE]={d='on'},
[0x23BF]={d='on'},
[0x23C0]={d='on'},
[0x23C1]={d='on'},
[0x23C2]={d='on'},
[0x23C3]={d='on'},
[0x23C4]={d='on'},
[0x23C5]={d='on'},
[0x23C6]={d='on'},
[0x23C7]={d='on'},
[0x23C8]={d='on'},
[0x23C9]={d='on'},
[0x23CA]={d='on'},
[0x23CB]={d='on'},
[0x23CC]={d='on'},
[0x23CD]={d='on'},
[0x23CE]={d='on'},
[0x23CF]={d='on'},
[0x23D0]={d='on'},
[0x23D1]={d='on'},
[0x23D2]={d='on'},
[0x23D3]={d='on'},
[0x23D4]={d='on'},
[0x23D5]={d='on'},
[0x23D6]={d='on'},
[0x23D7]={d='on'},
[0x23D8]={d='on'},
[0x23D9]={d='on'},
[0x23DA]={d='on'},
[0x23DB]={d='on'},
[0x23DC]={d='on'},
[0x23DD]={d='on'},
[0x23DE]={d='on'},
[0x23DF]={d='on'},
[0x23E0]={d='on'},
[0x23E1]={d='on'},
[0x23E2]={d='on'},
[0x23E3]={d='on'},
[0x23E4]={d='on'},
[0x23E5]={d='on'},
[0x23E6]={d='on'},
[0x23E7]={d='on'},
[0x23E8]={d='on'},
[0x23E9]={d='on'},
[0x23EA]={d='on'},
[0x23EB]={d='on'},
[0x23EC]={d='on'},
[0x23ED]={d='on'},
[0x23EE]={d='on'},
[0x23EF]={d='on'},
[0x23F0]={d='on'},
[0x23F1]={d='on'},
[0x23F2]={d='on'},
[0x23F3]={d='on'},
[0x23F4]={d='on'},
[0x23F5]={d='on'},
[0x23F6]={d='on'},
[0x23F7]={d='on'},
[0x23F8]={d='on'},
[0x23F9]={d='on'},
[0x23FA]={d='on'},
[0x23FB]={d='on'},
[0x23FC]={d='on'},
[0x23FD]={d='on'},
[0x23FE]={d='on'},
[0x2400]={d='on'},
[0x2401]={d='on'},
[0x2402]={d='on'},
[0x2403]={d='on'},
[0x2404]={d='on'},
[0x2405]={d='on'},
[0x2406]={d='on'},
[0x2407]={d='on'},
[0x2408]={d='on'},
[0x2409]={d='on'},
[0x240A]={d='on'},
[0x240B]={d='on'},
[0x240C]={d='on'},
[0x240D]={d='on'},
[0x240E]={d='on'},
[0x240F]={d='on'},
[0x2410]={d='on'},
[0x2411]={d='on'},
[0x2412]={d='on'},
[0x2413]={d='on'},
[0x2414]={d='on'},
[0x2415]={d='on'},
[0x2416]={d='on'},
[0x2417]={d='on'},
[0x2418]={d='on'},
[0x2419]={d='on'},
[0x241A]={d='on'},
[0x241B]={d='on'},
[0x241C]={d='on'},
[0x241D]={d='on'},
[0x241E]={d='on'},
[0x241F]={d='on'},
[0x2420]={d='on'},
[0x2421]={d='on'},
[0x2422]={d='on'},
[0x2423]={d='on'},
[0x2424]={d='on'},
[0x2425]={d='on'},
[0x2426]={d='on'},
[0x2440]={d='on'},
[0x2441]={d='on'},
[0x2442]={d='on'},
[0x2443]={d='on'},
[0x2444]={d='on'},
[0x2445]={d='on'},
[0x2446]={d='on'},
[0x2447]={d='on'},
[0x2448]={d='on'},
[0x2449]={d='on'},
[0x244A]={d='on'},
[0x2460]={d='on'},
[0x2461]={d='on'},
[0x2462]={d='on'},
[0x2463]={d='on'},
[0x2464]={d='on'},
[0x2465]={d='on'},
[0x2466]={d='on'},
[0x2467]={d='on'},
[0x2468]={d='on'},
[0x2469]={d='on'},
[0x246A]={d='on'},
[0x246B]={d='on'},
[0x246C]={d='on'},
[0x246D]={d='on'},
[0x246E]={d='on'},
[0x246F]={d='on'},
[0x2470]={d='on'},
[0x2471]={d='on'},
[0x2472]={d='on'},
[0x2473]={d='on'},
[0x2474]={d='on'},
[0x2475]={d='on'},
[0x2476]={d='on'},
[0x2477]={d='on'},
[0x2478]={d='on'},
[0x2479]={d='on'},
[0x247A]={d='on'},
[0x247B]={d='on'},
[0x247C]={d='on'},
[0x247D]={d='on'},
[0x247E]={d='on'},
[0x247F]={d='on'},
[0x2480]={d='on'},
[0x2481]={d='on'},
[0x2482]={d='on'},
[0x2483]={d='on'},
[0x2484]={d='on'},
[0x2485]={d='on'},
[0x2486]={d='on'},
[0x2487]={d='on'},
[0x2488]={d='en'},
[0x2489]={d='en'},
[0x248A]={d='en'},
[0x248B]={d='en'},
[0x248C]={d='en'},
[0x248D]={d='en'},
[0x248E]={d='en'},
[0x248F]={d='en'},
[0x2490]={d='en'},
[0x2491]={d='en'},
[0x2492]={d='en'},
[0x2493]={d='en'},
[0x2494]={d='en'},
[0x2495]={d='en'},
[0x2496]={d='en'},
[0x2497]={d='en'},
[0x2498]={d='en'},
[0x2499]={d='en'},
[0x249A]={d='en'},
[0x249B]={d='en'},
[0x24EA]={d='on'},
[0x24EB]={d='on'},
[0x24EC]={d='on'},
[0x24ED]={d='on'},
[0x24EE]={d='on'},
[0x24EF]={d='on'},
[0x24F0]={d='on'},
[0x24F1]={d='on'},
[0x24F2]={d='on'},
[0x24F3]={d='on'},
[0x24F4]={d='on'},
[0x24F5]={d='on'},
[0x24F6]={d='on'},
[0x24F7]={d='on'},
[0x24F8]={d='on'},
[0x24F9]={d='on'},
[0x24FA]={d='on'},
[0x24FB]={d='on'},
[0x24FC]={d='on'},
[0x24FD]={d='on'},
[0x24FE]={d='on'},
[0x24FF]={d='on'},
[0x2500]={d='on'},
[0x2501]={d='on'},
[0x2502]={d='on'},
[0x2503]={d='on'},
[0x2504]={d='on'},
[0x2505]={d='on'},
[0x2506]={d='on'},
[0x2507]={d='on'},
[0x2508]={d='on'},
[0x2509]={d='on'},
[0x250A]={d='on'},
[0x250B]={d='on'},
[0x250C]={d='on'},
[0x250D]={d='on'},
[0x250E]={d='on'},
[0x250F]={d='on'},
[0x2510]={d='on'},
[0x2511]={d='on'},
[0x2512]={d='on'},
[0x2513]={d='on'},
[0x2514]={d='on'},
[0x2515]={d='on'},
[0x2516]={d='on'},
[0x2517]={d='on'},
[0x2518]={d='on'},
[0x2519]={d='on'},
[0x251A]={d='on'},
[0x251B]={d='on'},
[0x251C]={d='on'},
[0x251D]={d='on'},
[0x251E]={d='on'},
[0x251F]={d='on'},
[0x2520]={d='on'},
[0x2521]={d='on'},
[0x2522]={d='on'},
[0x2523]={d='on'},
[0x2524]={d='on'},
[0x2525]={d='on'},
[0x2526]={d='on'},
[0x2527]={d='on'},
[0x2528]={d='on'},
[0x2529]={d='on'},
[0x252A]={d='on'},
[0x252B]={d='on'},
[0x252C]={d='on'},
[0x252D]={d='on'},
[0x252E]={d='on'},
[0x252F]={d='on'},
[0x2530]={d='on'},
[0x2531]={d='on'},
[0x2532]={d='on'},
[0x2533]={d='on'},
[0x2534]={d='on'},
[0x2535]={d='on'},
[0x2536]={d='on'},
[0x2537]={d='on'},
[0x2538]={d='on'},
[0x2539]={d='on'},
[0x253A]={d='on'},
[0x253B]={d='on'},
[0x253C]={d='on'},
[0x253D]={d='on'},
[0x253E]={d='on'},
[0x253F]={d='on'},
[0x2540]={d='on'},
[0x2541]={d='on'},
[0x2542]={d='on'},
[0x2543]={d='on'},
[0x2544]={d='on'},
[0x2545]={d='on'},
[0x2546]={d='on'},
[0x2547]={d='on'},
[0x2548]={d='on'},
[0x2549]={d='on'},
[0x254A]={d='on'},
[0x254B]={d='on'},
[0x254C]={d='on'},
[0x254D]={d='on'},
[0x254E]={d='on'},
[0x254F]={d='on'},
[0x2550]={d='on'},
[0x2551]={d='on'},
[0x2552]={d='on'},
[0x2553]={d='on'},
[0x2554]={d='on'},
[0x2555]={d='on'},
[0x2556]={d='on'},
[0x2557]={d='on'},
[0x2558]={d='on'},
[0x2559]={d='on'},
[0x255A]={d='on'},
[0x255B]={d='on'},
[0x255C]={d='on'},
[0x255D]={d='on'},
[0x255E]={d='on'},
[0x255F]={d='on'},
[0x2560]={d='on'},
[0x2561]={d='on'},
[0x2562]={d='on'},
[0x2563]={d='on'},
[0x2564]={d='on'},
[0x2565]={d='on'},
[0x2566]={d='on'},
[0x2567]={d='on'},
[0x2568]={d='on'},
[0x2569]={d='on'},
[0x256A]={d='on'},
[0x256B]={d='on'},
[0x256C]={d='on'},
[0x256D]={d='on'},
[0x256E]={d='on'},
[0x256F]={d='on'},
[0x2570]={d='on'},
[0x2571]={d='on'},
[0x2572]={d='on'},
[0x2573]={d='on'},
[0x2574]={d='on'},
[0x2575]={d='on'},
[0x2576]={d='on'},
[0x2577]={d='on'},
[0x2578]={d='on'},
[0x2579]={d='on'},
[0x257A]={d='on'},
[0x257B]={d='on'},
[0x257C]={d='on'},
[0x257D]={d='on'},
[0x257E]={d='on'},
[0x257F]={d='on'},
[0x2580]={d='on'},
[0x2581]={d='on'},
[0x2582]={d='on'},
[0x2583]={d='on'},
[0x2584]={d='on'},
[0x2585]={d='on'},
[0x2586]={d='on'},
[0x2587]={d='on'},
[0x2588]={d='on'},
[0x2589]={d='on'},
[0x258A]={d='on'},
[0x258B]={d='on'},
[0x258C]={d='on'},
[0x258D]={d='on'},
[0x258E]={d='on'},
[0x258F]={d='on'},
[0x2590]={d='on'},
[0x2591]={d='on'},
[0x2592]={d='on'},
[0x2593]={d='on'},
[0x2594]={d='on'},
[0x2595]={d='on'},
[0x2596]={d='on'},
[0x2597]={d='on'},
[0x2598]={d='on'},
[0x2599]={d='on'},
[0x259A]={d='on'},
[0x259B]={d='on'},
[0x259C]={d='on'},
[0x259D]={d='on'},
[0x259E]={d='on'},
[0x259F]={d='on'},
[0x25A0]={d='on'},
[0x25A1]={d='on'},
[0x25A2]={d='on'},
[0x25A3]={d='on'},
[0x25A4]={d='on'},
[0x25A5]={d='on'},
[0x25A6]={d='on'},
[0x25A7]={d='on'},
[0x25A8]={d='on'},
[0x25A9]={d='on'},
[0x25AA]={d='on'},
[0x25AB]={d='on'},
[0x25AC]={d='on'},
[0x25AD]={d='on'},
[0x25AE]={d='on'},
[0x25AF]={d='on'},
[0x25B0]={d='on'},
[0x25B1]={d='on'},
[0x25B2]={d='on'},
[0x25B3]={d='on'},
[0x25B4]={d='on'},
[0x25B5]={d='on'},
[0x25B6]={d='on'},
[0x25B7]={d='on'},
[0x25B8]={d='on'},
[0x25B9]={d='on'},
[0x25BA]={d='on'},
[0x25BB]={d='on'},
[0x25BC]={d='on'},
[0x25BD]={d='on'},
[0x25BE]={d='on'},
[0x25BF]={d='on'},
[0x25C0]={d='on'},
[0x25C1]={d='on'},
[0x25C2]={d='on'},
[0x25C3]={d='on'},
[0x25C4]={d='on'},
[0x25C5]={d='on'},
[0x25C6]={d='on'},
[0x25C7]={d='on'},
[0x25C8]={d='on'},
[0x25C9]={d='on'},
[0x25CA]={d='on'},
[0x25CB]={d='on'},
[0x25CC]={d='on'},
[0x25CD]={d='on'},
[0x25CE]={d='on'},
[0x25CF]={d='on'},
[0x25D0]={d='on'},
[0x25D1]={d='on'},
[0x25D2]={d='on'},
[0x25D3]={d='on'},
[0x25D4]={d='on'},
[0x25D5]={d='on'},
[0x25D6]={d='on'},
[0x25D7]={d='on'},
[0x25D8]={d='on'},
[0x25D9]={d='on'},
[0x25DA]={d='on'},
[0x25DB]={d='on'},
[0x25DC]={d='on'},
[0x25DD]={d='on'},
[0x25DE]={d='on'},
[0x25DF]={d='on'},
[0x25E0]={d='on'},
[0x25E1]={d='on'},
[0x25E2]={d='on'},
[0x25E3]={d='on'},
[0x25E4]={d='on'},
[0x25E5]={d='on'},
[0x25E6]={d='on'},
[0x25E7]={d='on'},
[0x25E8]={d='on'},
[0x25E9]={d='on'},
[0x25EA]={d='on'},
[0x25EB]={d='on'},
[0x25EC]={d='on'},
[0x25ED]={d='on'},
[0x25EE]={d='on'},
[0x25EF]={d='on'},
[0x25F0]={d='on'},
[0x25F1]={d='on'},
[0x25F2]={d='on'},
[0x25F3]={d='on'},
[0x25F4]={d='on'},
[0x25F5]={d='on'},
[0x25F6]={d='on'},
[0x25F7]={d='on'},
[0x25F8]={d='on'},
[0x25F9]={d='on'},
[0x25FA]={d='on'},
[0x25FB]={d='on'},
[0x25FC]={d='on'},
[0x25FD]={d='on'},
[0x25FE]={d='on'},
[0x25FF]={d='on'},
[0x2600]={d='on'},
[0x2601]={d='on'},
[0x2602]={d='on'},
[0x2603]={d='on'},
[0x2604]={d='on'},
[0x2605]={d='on'},
[0x2606]={d='on'},
[0x2607]={d='on'},
[0x2608]={d='on'},
[0x2609]={d='on'},
[0x260A]={d='on'},
[0x260B]={d='on'},
[0x260C]={d='on'},
[0x260D]={d='on'},
[0x260E]={d='on'},
[0x260F]={d='on'},
[0x2610]={d='on'},
[0x2611]={d='on'},
[0x2612]={d='on'},
[0x2613]={d='on'},
[0x2614]={d='on'},
[0x2615]={d='on'},
[0x2616]={d='on'},
[0x2617]={d='on'},
[0x2618]={d='on'},
[0x2619]={d='on'},
[0x261A]={d='on'},
[0x261B]={d='on'},
[0x261C]={d='on'},
[0x261D]={d='on'},
[0x261E]={d='on'},
[0x261F]={d='on'},
[0x2620]={d='on'},
[0x2621]={d='on'},
[0x2622]={d='on'},
[0x2623]={d='on'},
[0x2624]={d='on'},
[0x2625]={d='on'},
[0x2626]={d='on'},
[0x2627]={d='on'},
[0x2628]={d='on'},
[0x2629]={d='on'},
[0x262A]={d='on'},
[0x262B]={d='on'},
[0x262C]={d='on'},
[0x262D]={d='on'},
[0x262E]={d='on'},
[0x262F]={d='on'},
[0x2630]={d='on'},
[0x2631]={d='on'},
[0x2632]={d='on'},
[0x2633]={d='on'},
[0x2634]={d='on'},
[0x2635]={d='on'},
[0x2636]={d='on'},
[0x2637]={d='on'},
[0x2638]={d='on'},
[0x2639]={d='on'},
[0x263A]={d='on'},
[0x263B]={d='on'},
[0x263C]={d='on'},
[0x263D]={d='on'},
[0x263E]={d='on'},
[0x263F]={d='on'},
[0x2640]={d='on'},
[0x2641]={d='on'},
[0x2642]={d='on'},
[0x2643]={d='on'},
[0x2644]={d='on'},
[0x2645]={d='on'},
[0x2646]={d='on'},
[0x2647]={d='on'},
[0x2648]={d='on'},
[0x2649]={d='on'},
[0x264A]={d='on'},
[0x264B]={d='on'},
[0x264C]={d='on'},
[0x264D]={d='on'},
[0x264E]={d='on'},
[0x264F]={d='on'},
[0x2650]={d='on'},
[0x2651]={d='on'},
[0x2652]={d='on'},
[0x2653]={d='on'},
[0x2654]={d='on'},
[0x2655]={d='on'},
[0x2656]={d='on'},
[0x2657]={d='on'},
[0x2658]={d='on'},
[0x2659]={d='on'},
[0x265A]={d='on'},
[0x265B]={d='on'},
[0x265C]={d='on'},
[0x265D]={d='on'},
[0x265E]={d='on'},
[0x265F]={d='on'},
[0x2660]={d='on'},
[0x2661]={d='on'},
[0x2662]={d='on'},
[0x2663]={d='on'},
[0x2664]={d='on'},
[0x2665]={d='on'},
[0x2666]={d='on'},
[0x2667]={d='on'},
[0x2668]={d='on'},
[0x2669]={d='on'},
[0x266A]={d='on'},
[0x266B]={d='on'},
[0x266C]={d='on'},
[0x266D]={d='on'},
[0x266E]={d='on'},
[0x266F]={d='on'},
[0x2670]={d='on'},
[0x2671]={d='on'},
[0x2672]={d='on'},
[0x2673]={d='on'},
[0x2674]={d='on'},
[0x2675]={d='on'},
[0x2676]={d='on'},
[0x2677]={d='on'},
[0x2678]={d='on'},
[0x2679]={d='on'},
[0x267A]={d='on'},
[0x267B]={d='on'},
[0x267C]={d='on'},
[0x267D]={d='on'},
[0x267E]={d='on'},
[0x267F]={d='on'},
[0x2680]={d='on'},
[0x2681]={d='on'},
[0x2682]={d='on'},
[0x2683]={d='on'},
[0x2684]={d='on'},
[0x2685]={d='on'},
[0x2686]={d='on'},
[0x2687]={d='on'},
[0x2688]={d='on'},
[0x2689]={d='on'},
[0x268A]={d='on'},
[0x268B]={d='on'},
[0x268C]={d='on'},
[0x268D]={d='on'},
[0x268E]={d='on'},
[0x268F]={d='on'},
[0x2690]={d='on'},
[0x2691]={d='on'},
[0x2692]={d='on'},
[0x2693]={d='on'},
[0x2694]={d='on'},
[0x2695]={d='on'},
[0x2696]={d='on'},
[0x2697]={d='on'},
[0x2698]={d='on'},
[0x2699]={d='on'},
[0x269A]={d='on'},
[0x269B]={d='on'},
[0x269C]={d='on'},
[0x269D]={d='on'},
[0x269E]={d='on'},
[0x269F]={d='on'},
[0x26A0]={d='on'},
[0x26A1]={d='on'},
[0x26A2]={d='on'},
[0x26A3]={d='on'},
[0x26A4]={d='on'},
[0x26A5]={d='on'},
[0x26A6]={d='on'},
[0x26A7]={d='on'},
[0x26A8]={d='on'},
[0x26A9]={d='on'},
[0x26AA]={d='on'},
[0x26AB]={d='on'},
[0x26AD]={d='on'},
[0x26AE]={d='on'},
[0x26AF]={d='on'},
[0x26B0]={d='on'},
[0x26B1]={d='on'},
[0x26B2]={d='on'},
[0x26B3]={d='on'},
[0x26B4]={d='on'},
[0x26B5]={d='on'},
[0x26B6]={d='on'},
[0x26B7]={d='on'},
[0x26B8]={d='on'},
[0x26B9]={d='on'},
[0x26BA]={d='on'},
[0x26BB]={d='on'},
[0x26BC]={d='on'},
[0x26BD]={d='on'},
[0x26BE]={d='on'},
[0x26BF]={d='on'},
[0x26C0]={d='on'},
[0x26C1]={d='on'},
[0x26C2]={d='on'},
[0x26C3]={d='on'},
[0x26C4]={d='on'},
[0x26C5]={d='on'},
[0x26C6]={d='on'},
[0x26C7]={d='on'},
[0x26C8]={d='on'},
[0x26C9]={d='on'},
[0x26CA]={d='on'},
[0x26CB]={d='on'},
[0x26CC]={d='on'},
[0x26CD]={d='on'},
[0x26CE]={d='on'},
[0x26CF]={d='on'},
[0x26D0]={d='on'},
[0x26D1]={d='on'},
[0x26D2]={d='on'},
[0x26D3]={d='on'},
[0x26D4]={d='on'},
[0x26D5]={d='on'},
[0x26D6]={d='on'},
[0x26D7]={d='on'},
[0x26D8]={d='on'},
[0x26D9]={d='on'},
[0x26DA]={d='on'},
[0x26DB]={d='on'},
[0x26DC]={d='on'},
[0x26DD]={d='on'},
[0x26DE]={d='on'},
[0x26DF]={d='on'},
[0x26E0]={d='on'},
[0x26E1]={d='on'},
[0x26E2]={d='on'},
[0x26E3]={d='on'},
[0x26E4]={d='on'},
[0x26E5]={d='on'},
[0x26E6]={d='on'},
[0x26E7]={d='on'},
[0x26E8]={d='on'},
[0x26E9]={d='on'},
[0x26EA]={d='on'},
[0x26EB]={d='on'},
[0x26EC]={d='on'},
[0x26ED]={d='on'},
[0x26EE]={d='on'},
[0x26EF]={d='on'},
[0x26F0]={d='on'},
[0x26F1]={d='on'},
[0x26F2]={d='on'},
[0x26F3]={d='on'},
[0x26F4]={d='on'},
[0x26F5]={d='on'},
[0x26F6]={d='on'},
[0x26F7]={d='on'},
[0x26F8]={d='on'},
[0x26F9]={d='on'},
[0x26FA]={d='on'},
[0x26FB]={d='on'},
[0x26FC]={d='on'},
[0x26FD]={d='on'},
[0x26FE]={d='on'},
[0x26FF]={d='on'},
[0x2700]={d='on'},
[0x2701]={d='on'},
[0x2702]={d='on'},
[0x2703]={d='on'},
[0x2704]={d='on'},
[0x2705]={d='on'},
[0x2706]={d='on'},
[0x2707]={d='on'},
[0x2708]={d='on'},
[0x2709]={d='on'},
[0x270A]={d='on'},
[0x270B]={d='on'},
[0x270C]={d='on'},
[0x270D]={d='on'},
[0x270E]={d='on'},
[0x270F]={d='on'},
[0x2710]={d='on'},
[0x2711]={d='on'},
[0x2712]={d='on'},
[0x2713]={d='on'},
[0x2714]={d='on'},
[0x2715]={d='on'},
[0x2716]={d='on'},
[0x2717]={d='on'},
[0x2718]={d='on'},
[0x2719]={d='on'},
[0x271A]={d='on'},
[0x271B]={d='on'},
[0x271C]={d='on'},
[0x271D]={d='on'},
[0x271E]={d='on'},
[0x271F]={d='on'},
[0x2720]={d='on'},
[0x2721]={d='on'},
[0x2722]={d='on'},
[0x2723]={d='on'},
[0x2724]={d='on'},
[0x2725]={d='on'},
[0x2726]={d='on'},
[0x2727]={d='on'},
[0x2728]={d='on'},
[0x2729]={d='on'},
[0x272A]={d='on'},
[0x272B]={d='on'},
[0x272C]={d='on'},
[0x272D]={d='on'},
[0x272E]={d='on'},
[0x272F]={d='on'},
[0x2730]={d='on'},
[0x2731]={d='on'},
[0x2732]={d='on'},
[0x2733]={d='on'},
[0x2734]={d='on'},
[0x2735]={d='on'},
[0x2736]={d='on'},
[0x2737]={d='on'},
[0x2738]={d='on'},
[0x2739]={d='on'},
[0x273A]={d='on'},
[0x273B]={d='on'},
[0x273C]={d='on'},
[0x273D]={d='on'},
[0x273E]={d='on'},
[0x273F]={d='on'},
[0x2740]={d='on'},
[0x2741]={d='on'},
[0x2742]={d='on'},
[0x2743]={d='on'},
[0x2744]={d='on'},
[0x2745]={d='on'},
[0x2746]={d='on'},
[0x2747]={d='on'},
[0x2748]={d='on'},
[0x2749]={d='on'},
[0x274A]={d='on'},
[0x274B]={d='on'},
[0x274C]={d='on'},
[0x274D]={d='on'},
[0x274E]={d='on'},
[0x274F]={d='on'},
[0x2750]={d='on'},
[0x2751]={d='on'},
[0x2752]={d='on'},
[0x2753]={d='on'},
[0x2754]={d='on'},
[0x2755]={d='on'},
[0x2756]={d='on'},
[0x2757]={d='on'},
[0x2758]={d='on'},
[0x2759]={d='on'},
[0x275A]={d='on'},
[0x275B]={d='on'},
[0x275C]={d='on'},
[0x275D]={d='on'},
[0x275E]={d='on'},
[0x275F]={d='on'},
[0x2760]={d='on'},
[0x2761]={d='on'},
[0x2762]={d='on'},
[0x2763]={d='on'},
[0x2764]={d='on'},
[0x2765]={d='on'},
[0x2766]={d='on'},
[0x2767]={d='on'},
[0x2768]={d='on', m=0x2769},
[0x2769]={d='on', m=0x2768},
[0x276A]={d='on', m=0x276B},
[0x276B]={d='on', m=0x276A},
[0x276C]={d='on', m=0x276D},
[0x276D]={d='on', m=0x276C},
[0x276E]={d='on', m=0x276F},
[0x276F]={d='on', m=0x276E},
[0x2770]={d='on', m=0x2771},
[0x2771]={d='on', m=0x2770},
[0x2772]={d='on', m=0x2773},
[0x2773]={d='on', m=0x2772},
[0x2774]={d='on', m=0x2775},
[0x2775]={d='on', m=0x2774},
[0x2776]={d='on'},
[0x2777]={d='on'},
[0x2778]={d='on'},
[0x2779]={d='on'},
[0x277A]={d='on'},
[0x277B]={d='on'},
[0x277C]={d='on'},
[0x277D]={d='on'},
[0x277E]={d='on'},
[0x277F]={d='on'},
[0x2780]={d='on'},
[0x2781]={d='on'},
[0x2782]={d='on'},
[0x2783]={d='on'},
[0x2784]={d='on'},
[0x2785]={d='on'},
[0x2786]={d='on'},
[0x2787]={d='on'},
[0x2788]={d='on'},
[0x2789]={d='on'},
[0x278A]={d='on'},
[0x278B]={d='on'},
[0x278C]={d='on'},
[0x278D]={d='on'},
[0x278E]={d='on'},
[0x278F]={d='on'},
[0x2790]={d='on'},
[0x2791]={d='on'},
[0x2792]={d='on'},
[0x2793]={d='on'},
[0x2794]={d='on'},
[0x2795]={d='on'},
[0x2796]={d='on'},
[0x2797]={d='on'},
[0x2798]={d='on'},
[0x2799]={d='on'},
[0x279A]={d='on'},
[0x279B]={d='on'},
[0x279C]={d='on'},
[0x279D]={d='on'},
[0x279E]={d='on'},
[0x279F]={d='on'},
[0x27A0]={d='on'},
[0x27A1]={d='on'},
[0x27A2]={d='on'},
[0x27A3]={d='on'},
[0x27A4]={d='on'},
[0x27A5]={d='on'},
[0x27A6]={d='on'},
[0x27A7]={d='on'},
[0x27A8]={d='on'},
[0x27A9]={d='on'},
[0x27AA]={d='on'},
[0x27AB]={d='on'},
[0x27AC]={d='on'},
[0x27AD]={d='on'},
[0x27AE]={d='on'},
[0x27AF]={d='on'},
[0x27B0]={d='on'},
[0x27B1]={d='on'},
[0x27B2]={d='on'},
[0x27B3]={d='on'},
[0x27B4]={d='on'},
[0x27B5]={d='on'},
[0x27B6]={d='on'},
[0x27B7]={d='on'},
[0x27B8]={d='on'},
[0x27B9]={d='on'},
[0x27BA]={d='on'},
[0x27BB]={d='on'},
[0x27BC]={d='on'},
[0x27BD]={d='on'},
[0x27BE]={d='on'},
[0x27BF]={d='on'},
[0x27C0]={d='on'},
[0x27C1]={d='on'},
[0x27C2]={d='on'},
[0x27C3]={d='on', m=0x27C4},
[0x27C4]={d='on', m=0x27C3},
[0x27C5]={d='on', m=0x27C6},
[0x27C6]={d='on', m=0x27C5},
[0x27C7]={d='on'},
[0x27C8]={d='on', m=0x27C9},
[0x27C9]={d='on', m=0x27C8},
[0x27CA]={d='on'},
[0x27CB]={d='on', m=0x27CD},
[0x27CC]={d='on'},
[0x27CD]={d='on', m=0x27CB},
[0x27CE]={d='on'},
[0x27CF]={d='on'},
[0x27D0]={d='on'},
[0x27D1]={d='on'},
[0x27D2]={d='on'},
[0x27D3]={d='on'},
[0x27D4]={d='on'},
[0x27D5]={d='on', m=0x27D6},
[0x27D6]={d='on', m=0x27D5},
[0x27D7]={d='on'},
[0x27D8]={d='on'},
[0x27D9]={d='on'},
[0x27DA]={d='on'},
[0x27DB]={d='on'},
[0x27DC]={d='on'},
[0x27DD]={d='on', m=0x27DE},
[0x27DE]={d='on', m=0x27DD},
[0x27DF]={d='on'},
[0x27E0]={d='on'},
[0x27E1]={d='on'},
[0x27E2]={d='on', m=0x27E3},
[0x27E3]={d='on', m=0x27E2},
[0x27E4]={d='on', m=0x27E5},
[0x27E5]={d='on', m=0x27E4},
[0x27E6]={d='on', m=0x27E7},
[0x27E7]={d='on', m=0x27E6},
[0x27E8]={d='on', m=0x27E9},
[0x27E9]={d='on', m=0x27E8},
[0x27EA]={d='on', m=0x27EB},
[0x27EB]={d='on', m=0x27EA},
[0x27EC]={d='on', m=0x27ED},
[0x27ED]={d='on', m=0x27EC},
[0x27EE]={d='on', m=0x27EF},
[0x27EF]={d='on', m=0x27EE},
[0x27F0]={d='on'},
[0x27F1]={d='on'},
[0x27F2]={d='on'},
[0x27F3]={d='on'},
[0x27F4]={d='on'},
[0x27F5]={d='on'},
[0x27F6]={d='on'},
[0x27F7]={d='on'},
[0x27F8]={d='on'},
[0x27F9]={d='on'},
[0x27FA]={d='on'},
[0x27FB]={d='on'},
[0x27FC]={d='on'},
[0x27FD]={d='on'},
[0x27FE]={d='on'},
[0x27FF]={d='on'},
[0x2900]={d='on'},
[0x2901]={d='on'},
[0x2902]={d='on'},
[0x2903]={d='on'},
[0x2904]={d='on'},
[0x2905]={d='on'},
[0x2906]={d='on'},
[0x2907]={d='on'},
[0x2908]={d='on'},
[0x2909]={d='on'},
[0x290A]={d='on'},
[0x290B]={d='on'},
[0x290C]={d='on'},
[0x290D]={d='on'},
[0x290E]={d='on'},
[0x290F]={d='on'},
[0x2910]={d='on'},
[0x2911]={d='on'},
[0x2912]={d='on'},
[0x2913]={d='on'},
[0x2914]={d='on'},
[0x2915]={d='on'},
[0x2916]={d='on'},
[0x2917]={d='on'},
[0x2918]={d='on'},
[0x2919]={d='on'},
[0x291A]={d='on'},
[0x291B]={d='on'},
[0x291C]={d='on'},
[0x291D]={d='on'},
[0x291E]={d='on'},
[0x291F]={d='on'},
[0x2920]={d='on'},
[0x2921]={d='on'},
[0x2922]={d='on'},
[0x2923]={d='on'},
[0x2924]={d='on'},
[0x2925]={d='on'},
[0x2926]={d='on'},
[0x2927]={d='on'},
[0x2928]={d='on'},
[0x2929]={d='on'},
[0x292A]={d='on'},
[0x292B]={d='on'},
[0x292C]={d='on'},
[0x292D]={d='on'},
[0x292E]={d='on'},
[0x292F]={d='on'},
[0x2930]={d='on'},
[0x2931]={d='on'},
[0x2932]={d='on'},
[0x2933]={d='on'},
[0x2934]={d='on'},
[0x2935]={d='on'},
[0x2936]={d='on'},
[0x2937]={d='on'},
[0x2938]={d='on'},
[0x2939]={d='on'},
[0x293A]={d='on'},
[0x293B]={d='on'},
[0x293C]={d='on'},
[0x293D]={d='on'},
[0x293E]={d='on'},
[0x293F]={d='on'},
[0x2940]={d='on'},
[0x2941]={d='on'},
[0x2942]={d='on'},
[0x2943]={d='on'},
[0x2944]={d='on'},
[0x2945]={d='on'},
[0x2946]={d='on'},
[0x2947]={d='on'},
[0x2948]={d='on'},
[0x2949]={d='on'},
[0x294A]={d='on'},
[0x294B]={d='on'},
[0x294C]={d='on'},
[0x294D]={d='on'},
[0x294E]={d='on'},
[0x294F]={d='on'},
[0x2950]={d='on'},
[0x2951]={d='on'},
[0x2952]={d='on'},
[0x2953]={d='on'},
[0x2954]={d='on'},
[0x2955]={d='on'},
[0x2956]={d='on'},
[0x2957]={d='on'},
[0x2958]={d='on'},
[0x2959]={d='on'},
[0x295A]={d='on'},
[0x295B]={d='on'},
[0x295C]={d='on'},
[0x295D]={d='on'},
[0x295E]={d='on'},
[0x295F]={d='on'},
[0x2960]={d='on'},
[0x2961]={d='on'},
[0x2962]={d='on'},
[0x2963]={d='on'},
[0x2964]={d='on'},
[0x2965]={d='on'},
[0x2966]={d='on'},
[0x2967]={d='on'},
[0x2968]={d='on'},
[0x2969]={d='on'},
[0x296A]={d='on'},
[0x296B]={d='on'},
[0x296C]={d='on'},
[0x296D]={d='on'},
[0x296E]={d='on'},
[0x296F]={d='on'},
[0x2970]={d='on'},
[0x2971]={d='on'},
[0x2972]={d='on'},
[0x2973]={d='on'},
[0x2974]={d='on'},
[0x2975]={d='on'},
[0x2976]={d='on'},
[0x2977]={d='on'},
[0x2978]={d='on'},
[0x2979]={d='on'},
[0x297A]={d='on'},
[0x297B]={d='on'},
[0x297C]={d='on'},
[0x297D]={d='on'},
[0x297E]={d='on'},
[0x297F]={d='on'},
[0x2980]={d='on'},
[0x2981]={d='on'},
[0x2982]={d='on'},
[0x2983]={d='on', m=0x2984},
[0x2984]={d='on', m=0x2983},
[0x2985]={d='on', m=0x2986},
[0x2986]={d='on', m=0x2985},
[0x2987]={d='on', m=0x2988},
[0x2988]={d='on', m=0x2987},
[0x2989]={d='on', m=0x298A},
[0x298A]={d='on', m=0x2989},
[0x298B]={d='on', m=0x298C},
[0x298C]={d='on', m=0x298B},
[0x298D]={d='on', m=0x2990},
[0x298E]={d='on', m=0x298F},
[0x298F]={d='on', m=0x298E},
[0x2990]={d='on', m=0x298D},
[0x2991]={d='on', m=0x2992},
[0x2992]={d='on', m=0x2991},
[0x2993]={d='on', m=0x2994},
[0x2994]={d='on', m=0x2993},
[0x2995]={d='on', m=0x2996},
[0x2996]={d='on', m=0x2995},
[0x2997]={d='on', m=0x2998},
[0x2998]={d='on', m=0x2997},
[0x2999]={d='on'},
[0x299A]={d='on'},
[0x299B]={d='on'},
[0x299C]={d='on'},
[0x299D]={d='on'},
[0x299E]={d='on'},
[0x299F]={d='on'},
[0x29A0]={d='on'},
[0x29A1]={d='on'},
[0x29A2]={d='on'},
[0x29A3]={d='on'},
[0x29A4]={d='on'},
[0x29A5]={d='on'},
[0x29A6]={d='on'},
[0x29A7]={d='on'},
[0x29A8]={d='on'},
[0x29A9]={d='on'},
[0x29AA]={d='on'},
[0x29AB]={d='on'},
[0x29AC]={d='on'},
[0x29AD]={d='on'},
[0x29AE]={d='on'},
[0x29AF]={d='on'},
[0x29B0]={d='on'},
[0x29B1]={d='on'},
[0x29B2]={d='on'},
[0x29B3]={d='on'},
[0x29B4]={d='on'},
[0x29B5]={d='on'},
[0x29B6]={d='on'},
[0x29B7]={d='on'},
[0x29B8]={d='on', m=0x2298},
[0x29B9]={d='on'},
[0x29BA]={d='on'},
[0x29BB]={d='on'},
[0x29BC]={d='on'},
[0x29BD]={d='on'},
[0x29BE]={d='on'},
[0x29BF]={d='on'},
[0x29C0]={d='on', m=0x29C1},
[0x29C1]={d='on', m=0x29C0},
[0x29C2]={d='on'},
[0x29C3]={d='on'},
[0x29C4]={d='on', m=0x29C5},
[0x29C5]={d='on', m=0x29C4},
[0x29C6]={d='on'},
[0x29C7]={d='on'},
[0x29C8]={d='on'},
[0x29C9]={d='on'},
[0x29CA]={d='on'},
[0x29CB]={d='on'},
[0x29CC]={d='on'},
[0x29CD]={d='on'},
[0x29CE]={d='on'},
[0x29CF]={d='on', m=0x29D0},
[0x29D0]={d='on', m=0x29CF},
[0x29D1]={d='on', m=0x29D2},
[0x29D2]={d='on', m=0x29D1},
[0x29D3]={d='on'},
[0x29D4]={d='on', m=0x29D5},
[0x29D5]={d='on', m=0x29D4},
[0x29D6]={d='on'},
[0x29D7]={d='on'},
[0x29D8]={d='on', m=0x29D9},
[0x29D9]={d='on', m=0x29D8},
[0x29DA]={d='on', m=0x29DB},
[0x29DB]={d='on', m=0x29DA},
[0x29DC]={d='on'},
[0x29DD]={d='on'},
[0x29DE]={d='on'},
[0x29DF]={d='on'},
[0x29E0]={d='on'},
[0x29E1]={d='on'},
[0x29E2]={d='on'},
[0x29E3]={d='on'},
[0x29E4]={d='on'},
[0x29E5]={d='on'},
[0x29E6]={d='on'},
[0x29E7]={d='on'},
[0x29E8]={d='on'},
[0x29E9]={d='on'},
[0x29EA]={d='on'},
[0x29EB]={d='on'},
[0x29EC]={d='on'},
[0x29ED]={d='on'},
[0x29EE]={d='on'},
[0x29EF]={d='on'},
[0x29F0]={d='on'},
[0x29F1]={d='on'},
[0x29F2]={d='on'},
[0x29F3]={d='on'},
[0x29F4]={d='on'},
[0x29F5]={d='on', m=0x2215},
[0x29F6]={d='on'},
[0x29F7]={d='on'},
[0x29F8]={d='on', m=0x29F9},
[0x29F9]={d='on', m=0x29F8},
[0x29FA]={d='on'},
[0x29FB]={d='on'},
[0x29FC]={d='on', m=0x29FD},
[0x29FD]={d='on', m=0x29FC},
[0x29FE]={d='on'},
[0x29FF]={d='on'},
[0x2A00]={d='on'},
[0x2A01]={d='on'},
[0x2A02]={d='on'},
[0x2A03]={d='on'},
[0x2A04]={d='on'},
[0x2A05]={d='on'},
[0x2A06]={d='on'},
[0x2A07]={d='on'},
[0x2A08]={d='on'},
[0x2A09]={d='on'},
[0x2A0A]={d='on'},
[0x2A0B]={d='on'},
[0x2A0C]={d='on'},
[0x2A0D]={d='on'},
[0x2A0E]={d='on'},
[0x2A0F]={d='on'},
[0x2A10]={d='on'},
[0x2A11]={d='on'},
[0x2A12]={d='on'},
[0x2A13]={d='on'},
[0x2A14]={d='on'},
[0x2A15]={d='on'},
[0x2A16]={d='on'},
[0x2A17]={d='on'},
[0x2A18]={d='on'},
[0x2A19]={d='on'},
[0x2A1A]={d='on'},
[0x2A1B]={d='on'},
[0x2A1C]={d='on'},
[0x2A1D]={d='on'},
[0x2A1E]={d='on'},
[0x2A1F]={d='on'},
[0x2A20]={d='on'},
[0x2A21]={d='on'},
[0x2A22]={d='on'},
[0x2A23]={d='on'},
[0x2A24]={d='on'},
[0x2A25]={d='on'},
[0x2A26]={d='on'},
[0x2A27]={d='on'},
[0x2A28]={d='on'},
[0x2A29]={d='on'},
[0x2A2A]={d='on'},
[0x2A2B]={d='on', m=0x2A2C},
[0x2A2C]={d='on', m=0x2A2B},
[0x2A2D]={d='on', m=0x2A2E},
[0x2A2E]={d='on', m=0x2A2D},
[0x2A2F]={d='on'},
[0x2A30]={d='on'},
[0x2A31]={d='on'},
[0x2A32]={d='on'},
[0x2A33]={d='on'},
[0x2A34]={d='on', m=0x2A35},
[0x2A35]={d='on', m=0x2A34},
[0x2A36]={d='on'},
[0x2A37]={d='on'},
[0x2A38]={d='on'},
[0x2A39]={d='on'},
[0x2A3A]={d='on'},
[0x2A3B]={d='on'},
[0x2A3C]={d='on', m=0x2A3D},
[0x2A3D]={d='on', m=0x2A3C},
[0x2A3E]={d='on'},
[0x2A3F]={d='on'},
[0x2A40]={d='on'},
[0x2A41]={d='on'},
[0x2A42]={d='on'},
[0x2A43]={d='on'},
[0x2A44]={d='on'},
[0x2A45]={d='on'},
[0x2A46]={d='on'},
[0x2A47]={d='on'},
[0x2A48]={d='on'},
[0x2A49]={d='on'},
[0x2A4A]={d='on'},
[0x2A4B]={d='on'},
[0x2A4C]={d='on'},
[0x2A4D]={d='on'},
[0x2A4E]={d='on'},
[0x2A4F]={d='on'},
[0x2A50]={d='on'},
[0x2A51]={d='on'},
[0x2A52]={d='on'},
[0x2A53]={d='on'},
[0x2A54]={d='on'},
[0x2A55]={d='on'},
[0x2A56]={d='on'},
[0x2A57]={d='on'},
[0x2A58]={d='on'},
[0x2A59]={d='on'},
[0x2A5A]={d='on'},
[0x2A5B]={d='on'},
[0x2A5C]={d='on'},
[0x2A5D]={d='on'},
[0x2A5E]={d='on'},
[0x2A5F]={d='on'},
[0x2A60]={d='on'},
[0x2A61]={d='on'},
[0x2A62]={d='on'},
[0x2A63]={d='on'},
[0x2A64]={d='on', m=0x2A65},
[0x2A65]={d='on', m=0x2A64},
[0x2A66]={d='on'},
[0x2A67]={d='on'},
[0x2A68]={d='on'},
[0x2A69]={d='on'},
[0x2A6A]={d='on'},
[0x2A6B]={d='on'},
[0x2A6C]={d='on'},
[0x2A6D]={d='on'},
[0x2A6E]={d='on'},
[0x2A6F]={d='on'},
[0x2A70]={d='on'},
[0x2A71]={d='on'},
[0x2A72]={d='on'},
[0x2A73]={d='on'},
[0x2A74]={d='on'},
[0x2A75]={d='on'},
[0x2A76]={d='on'},
[0x2A77]={d='on'},
[0x2A78]={d='on'},
[0x2A79]={d='on', m=0x2A7A},
[0x2A7A]={d='on', m=0x2A79},
[0x2A7B]={d='on'},
[0x2A7C]={d='on'},
[0x2A7D]={d='on', m=0x2A7E},
[0x2A7E]={d='on', m=0x2A7D},
[0x2A7F]={d='on', m=0x2A80},
[0x2A80]={d='on', m=0x2A7F},
[0x2A81]={d='on', m=0x2A82},
[0x2A82]={d='on', m=0x2A81},
[0x2A83]={d='on', m=0x2A84},
[0x2A84]={d='on', m=0x2A83},
[0x2A85]={d='on'},
[0x2A86]={d='on'},
[0x2A87]={d='on'},
[0x2A88]={d='on'},
[0x2A89]={d='on'},
[0x2A8A]={d='on'},
[0x2A8B]={d='on', m=0x2A8C},
[0x2A8C]={d='on', m=0x2A8B},
[0x2A8D]={d='on'},
[0x2A8E]={d='on'},
[0x2A8F]={d='on'},
[0x2A90]={d='on'},
[0x2A91]={d='on', m=0x2A92},
[0x2A92]={d='on', m=0x2A91},
[0x2A93]={d='on', m=0x2A94},
[0x2A94]={d='on', m=0x2A93},
[0x2A95]={d='on', m=0x2A96},
[0x2A96]={d='on', m=0x2A95},
[0x2A97]={d='on', m=0x2A98},
[0x2A98]={d='on', m=0x2A97},
[0x2A99]={d='on', m=0x2A9A},
[0x2A9A]={d='on', m=0x2A99},
[0x2A9B]={d='on', m=0x2A9C},
[0x2A9C]={d='on', m=0x2A9B},
[0x2A9D]={d='on'},
[0x2A9E]={d='on'},
[0x2A9F]={d='on'},
[0x2AA0]={d='on'},
[0x2AA1]={d='on', m=0x2AA2},
[0x2AA2]={d='on', m=0x2AA1},
[0x2AA3]={d='on'},
[0x2AA4]={d='on'},
[0x2AA5]={d='on'},
[0x2AA6]={d='on', m=0x2AA7},
[0x2AA7]={d='on', m=0x2AA6},
[0x2AA8]={d='on', m=0x2AA9},
[0x2AA9]={d='on', m=0x2AA8},
[0x2AAA]={d='on', m=0x2AAB},
[0x2AAB]={d='on', m=0x2AAA},
[0x2AAC]={d='on', m=0x2AAD},
[0x2AAD]={d='on', m=0x2AAC},
[0x2AAE]={d='on'},
[0x2AAF]={d='on', m=0x2AB0},
[0x2AB0]={d='on', m=0x2AAF},
[0x2AB1]={d='on'},
[0x2AB2]={d='on'},
[0x2AB3]={d='on', m=0x2AB4},
[0x2AB4]={d='on', m=0x2AB3},
[0x2AB5]={d='on'},
[0x2AB6]={d='on'},
[0x2AB7]={d='on'},
[0x2AB8]={d='on'},
[0x2AB9]={d='on'},
[0x2ABA]={d='on'},
[0x2ABB]={d='on', m=0x2ABC},
[0x2ABC]={d='on', m=0x2ABB},
[0x2ABD]={d='on', m=0x2ABE},
[0x2ABE]={d='on', m=0x2ABD},
[0x2ABF]={d='on', m=0x2AC0},
[0x2AC0]={d='on', m=0x2ABF},
[0x2AC1]={d='on', m=0x2AC2},
[0x2AC2]={d='on', m=0x2AC1},
[0x2AC3]={d='on', m=0x2AC4},
[0x2AC4]={d='on', m=0x2AC3},
[0x2AC5]={d='on', m=0x2AC6},
[0x2AC6]={d='on', m=0x2AC5},
[0x2AC7]={d='on'},
[0x2AC8]={d='on'},
[0x2AC9]={d='on'},
[0x2ACA]={d='on'},
[0x2ACB]={d='on'},
[0x2ACC]={d='on'},
[0x2ACD]={d='on', m=0x2ACE},
[0x2ACE]={d='on', m=0x2ACD},
[0x2ACF]={d='on', m=0x2AD0},
[0x2AD0]={d='on', m=0x2ACF},
[0x2AD1]={d='on', m=0x2AD2},
[0x2AD2]={d='on', m=0x2AD1},
[0x2AD3]={d='on', m=0x2AD4},
[0x2AD4]={d='on', m=0x2AD3},
[0x2AD5]={d='on', m=0x2AD6},
[0x2AD6]={d='on', m=0x2AD5},
[0x2AD7]={d='on'},
[0x2AD8]={d='on'},
[0x2AD9]={d='on'},
[0x2ADA]={d='on'},
[0x2ADB]={d='on'},
[0x2ADC]={d='on'},
[0x2ADD]={d='on'},
[0x2ADE]={d='on', m=0x22A6},
[0x2ADF]={d='on'},
[0x2AE0]={d='on'},
[0x2AE1]={d='on'},
[0x2AE2]={d='on'},
[0x2AE3]={d='on', m=0x22A9},
[0x2AE4]={d='on', m=0x22A8},
[0x2AE5]={d='on', m=0x22AB},
[0x2AE6]={d='on'},
[0x2AE7]={d='on'},
[0x2AE8]={d='on'},
[0x2AE9]={d='on'},
[0x2AEA]={d='on'},
[0x2AEB]={d='on'},
[0x2AEC]={d='on', m=0x2AED},
[0x2AED]={d='on', m=0x2AEC},
[0x2AEE]={d='on'},
[0x2AEF]={d='on'},
[0x2AF0]={d='on'},
[0x2AF1]={d='on'},
[0x2AF2]={d='on'},
[0x2AF3]={d='on'},
[0x2AF4]={d='on'},
[0x2AF5]={d='on'},
[0x2AF6]={d='on'},
[0x2AF7]={d='on', m=0x2AF8},
[0x2AF8]={d='on', m=0x2AF7},
[0x2AF9]={d='on', m=0x2AFA},
[0x2AFA]={d='on', m=0x2AF9},
[0x2AFB]={d='on'},
[0x2AFC]={d='on'},
[0x2AFD]={d='on'},
[0x2AFE]={d='on'},
[0x2AFF]={d='on'},
[0x2B00]={d='on'},
[0x2B01]={d='on'},
[0x2B02]={d='on'},
[0x2B03]={d='on'},
[0x2B04]={d='on'},
[0x2B05]={d='on'},
[0x2B06]={d='on'},
[0x2B07]={d='on'},
[0x2B08]={d='on'},
[0x2B09]={d='on'},
[0x2B0A]={d='on'},
[0x2B0B]={d='on'},
[0x2B0C]={d='on'},
[0x2B0D]={d='on'},
[0x2B0E]={d='on'},
[0x2B0F]={d='on'},
[0x2B10]={d='on'},
[0x2B11]={d='on'},
[0x2B12]={d='on'},
[0x2B13]={d='on'},
[0x2B14]={d='on'},
[0x2B15]={d='on'},
[0x2B16]={d='on'},
[0x2B17]={d='on'},
[0x2B18]={d='on'},
[0x2B19]={d='on'},
[0x2B1A]={d='on'},
[0x2B1B]={d='on'},
[0x2B1C]={d='on'},
[0x2B1D]={d='on'},
[0x2B1E]={d='on'},
[0x2B1F]={d='on'},
[0x2B20]={d='on'},
[0x2B21]={d='on'},
[0x2B22]={d='on'},
[0x2B23]={d='on'},
[0x2B24]={d='on'},
[0x2B25]={d='on'},
[0x2B26]={d='on'},
[0x2B27]={d='on'},
[0x2B28]={d='on'},
[0x2B29]={d='on'},
[0x2B2A]={d='on'},
[0x2B2B]={d='on'},
[0x2B2C]={d='on'},
[0x2B2D]={d='on'},
[0x2B2E]={d='on'},
[0x2B2F]={d='on'},
[0x2B30]={d='on'},
[0x2B31]={d='on'},
[0x2B32]={d='on'},
[0x2B33]={d='on'},
[0x2B34]={d='on'},
[0x2B35]={d='on'},
[0x2B36]={d='on'},
[0x2B37]={d='on'},
[0x2B38]={d='on'},
[0x2B39]={d='on'},
[0x2B3A]={d='on'},
[0x2B3B]={d='on'},
[0x2B3C]={d='on'},
[0x2B3D]={d='on'},
[0x2B3E]={d='on'},
[0x2B3F]={d='on'},
[0x2B40]={d='on'},
[0x2B41]={d='on'},
[0x2B42]={d='on'},
[0x2B43]={d='on'},
[0x2B44]={d='on'},
[0x2B45]={d='on'},
[0x2B46]={d='on'},
[0x2B47]={d='on'},
[0x2B48]={d='on'},
[0x2B49]={d='on'},
[0x2B4A]={d='on'},
[0x2B4B]={d='on'},
[0x2B4C]={d='on'},
[0x2B4D]={d='on'},
[0x2B4E]={d='on'},
[0x2B4F]={d='on'},
[0x2B50]={d='on'},
[0x2B51]={d='on'},
[0x2B52]={d='on'},
[0x2B53]={d='on'},
[0x2B54]={d='on'},
[0x2B55]={d='on'},
[0x2B56]={d='on'},
[0x2B57]={d='on'},
[0x2B58]={d='on'},
[0x2B59]={d='on'},
[0x2B5A]={d='on'},
[0x2B5B]={d='on'},
[0x2B5C]={d='on'},
[0x2B5D]={d='on'},
[0x2B5E]={d='on'},
[0x2B5F]={d='on'},
[0x2B60]={d='on'},
[0x2B61]={d='on'},
[0x2B62]={d='on'},
[0x2B63]={d='on'},
[0x2B64]={d='on'},
[0x2B65]={d='on'},
[0x2B66]={d='on'},
[0x2B67]={d='on'},
[0x2B68]={d='on'},
[0x2B69]={d='on'},
[0x2B6A]={d='on'},
[0x2B6B]={d='on'},
[0x2B6C]={d='on'},
[0x2B6D]={d='on'},
[0x2B6E]={d='on'},
[0x2B6F]={d='on'},
[0x2B70]={d='on'},
[0x2B71]={d='on'},
[0x2B72]={d='on'},
[0x2B73]={d='on'},
[0x2B76]={d='on'},
[0x2B77]={d='on'},
[0x2B78]={d='on'},
[0x2B79]={d='on'},
[0x2B7A]={d='on'},
[0x2B7B]={d='on'},
[0x2B7C]={d='on'},
[0x2B7D]={d='on'},
[0x2B7E]={d='on'},
[0x2B7F]={d='on'},
[0x2B80]={d='on'},
[0x2B81]={d='on'},
[0x2B82]={d='on'},
[0x2B83]={d='on'},
[0x2B84]={d='on'},
[0x2B85]={d='on'},
[0x2B86]={d='on'},
[0x2B87]={d='on'},
[0x2B88]={d='on'},
[0x2B89]={d='on'},
[0x2B8A]={d='on'},
[0x2B8B]={d='on'},
[0x2B8C]={d='on'},
[0x2B8D]={d='on'},
[0x2B8E]={d='on'},
[0x2B8F]={d='on'},
[0x2B90]={d='on'},
[0x2B91]={d='on'},
[0x2B92]={d='on'},
[0x2B93]={d='on'},
[0x2B94]={d='on'},
[0x2B95]={d='on'},
[0x2B98]={d='on'},
[0x2B99]={d='on'},
[0x2B9A]={d='on'},
[0x2B9B]={d='on'},
[0x2B9C]={d='on'},
[0x2B9D]={d='on'},
[0x2B9E]={d='on'},
[0x2B9F]={d='on'},
[0x2BA0]={d='on'},
[0x2BA1]={d='on'},
[0x2BA2]={d='on'},
[0x2BA3]={d='on'},
[0x2BA4]={d='on'},
[0x2BA5]={d='on'},
[0x2BA6]={d='on'},
[0x2BA7]={d='on'},
[0x2BA8]={d='on'},
[0x2BA9]={d='on'},
[0x2BAA]={d='on'},
[0x2BAB]={d='on'},
[0x2BAC]={d='on'},
[0x2BAD]={d='on'},
[0x2BAE]={d='on'},
[0x2BAF]={d='on'},
[0x2BB0]={d='on'},
[0x2BB1]={d='on'},
[0x2BB2]={d='on'},
[0x2BB3]={d='on'},
[0x2BB4]={d='on'},
[0x2BB5]={d='on'},
[0x2BB6]={d='on'},
[0x2BB7]={d='on'},
[0x2BB8]={d='on'},
[0x2BB9]={d='on'},
[0x2BBD]={d='on'},
[0x2BBE]={d='on'},
[0x2BBF]={d='on'},
[0x2BC0]={d='on'},
[0x2BC1]={d='on'},
[0x2BC2]={d='on'},
[0x2BC3]={d='on'},
[0x2BC4]={d='on'},
[0x2BC5]={d='on'},
[0x2BC6]={d='on'},
[0x2BC7]={d='on'},
[0x2BC8]={d='on'},
[0x2BCA]={d='on'},
[0x2BCB]={d='on'},
[0x2BCC]={d='on'},
[0x2BCD]={d='on'},
[0x2BCE]={d='on'},
[0x2BCF]={d='on'},
[0x2BD0]={d='on'},
[0x2BD1]={d='on'},
[0x2BEC]={d='on'},
[0x2BED]={d='on'},
[0x2BEE]={d='on'},
[0x2BEF]={d='on'},
[0x2CE5]={d='on'},
[0x2CE6]={d='on'},
[0x2CE7]={d='on'},
[0x2CE8]={d='on'},
[0x2CE9]={d='on'},
[0x2CEA]={d='on'},
[0x2CEF]={d='nsm'},
[0x2CF0]={d='nsm'},
[0x2CF1]={d='nsm'},
[0x2CF9]={d='on'},
[0x2CFA]={d='on'},
[0x2CFB]={d='on'},
[0x2CFC]={d='on'},
[0x2CFD]={d='on'},
[0x2CFE]={d='on'},
[0x2CFF]={d='on'},
[0x2D7F]={d='nsm'},
[0x2DE0]={d='nsm'},
[0x2DE1]={d='nsm'},
[0x2DE2]={d='nsm'},
[0x2DE3]={d='nsm'},
[0x2DE4]={d='nsm'},
[0x2DE5]={d='nsm'},
[0x2DE6]={d='nsm'},
[0x2DE7]={d='nsm'},
[0x2DE8]={d='nsm'},
[0x2DE9]={d='nsm'},
[0x2DEA]={d='nsm'},
[0x2DEB]={d='nsm'},
[0x2DEC]={d='nsm'},
[0x2DED]={d='nsm'},
[0x2DEE]={d='nsm'},
[0x2DEF]={d='nsm'},
[0x2DF0]={d='nsm'},
[0x2DF1]={d='nsm'},
[0x2DF2]={d='nsm'},
[0x2DF3]={d='nsm'},
[0x2DF4]={d='nsm'},
[0x2DF5]={d='nsm'},
[0x2DF6]={d='nsm'},
[0x2DF7]={d='nsm'},
[0x2DF8]={d='nsm'},
[0x2DF9]={d='nsm'},
[0x2DFA]={d='nsm'},
[0x2DFB]={d='nsm'},
[0x2DFC]={d='nsm'},
[0x2DFD]={d='nsm'},
[0x2DFE]={d='nsm'},
[0x2DFF]={d='nsm'},
[0x2E00]={d='on'},
[0x2E01]={d='on'},
[0x2E02]={d='on', m=0x2E03},
[0x2E03]={d='on', m=0x2E02},
[0x2E04]={d='on', m=0x2E05},
[0x2E05]={d='on', m=0x2E04},
[0x2E06]={d='on'},
[0x2E07]={d='on'},
[0x2E08]={d='on'},
[0x2E09]={d='on', m=0x2E0A},
[0x2E0A]={d='on', m=0x2E09},
[0x2E0B]={d='on'},
[0x2E0C]={d='on', m=0x2E0D},
[0x2E0D]={d='on', m=0x2E0C},
[0x2E0E]={d='on'},
[0x2E0F]={d='on'},
[0x2E10]={d='on'},
[0x2E11]={d='on'},
[0x2E12]={d='on'},
[0x2E13]={d='on'},
[0x2E14]={d='on'},
[0x2E15]={d='on'},
[0x2E16]={d='on'},
[0x2E17]={d='on'},
[0x2E18]={d='on'},
[0x2E19]={d='on'},
[0x2E1A]={d='on'},
[0x2E1B]={d='on'},
[0x2E1C]={d='on', m=0x2E1D},
[0x2E1D]={d='on', m=0x2E1C},
[0x2E1E]={d='on'},
[0x2E1F]={d='on'},
[0x2E20]={d='on', m=0x2E21},
[0x2E21]={d='on', m=0x2E20},
[0x2E22]={d='on', m=0x2E23},
[0x2E23]={d='on', m=0x2E22},
[0x2E24]={d='on', m=0x2E25},
[0x2E25]={d='on', m=0x2E24},
[0x2E26]={d='on', m=0x2E27},
[0x2E27]={d='on', m=0x2E26},
[0x2E28]={d='on', m=0x2E29},
[0x2E29]={d='on', m=0x2E28},
[0x2E2A]={d='on'},
[0x2E2B]={d='on'},
[0x2E2C]={d='on'},
[0x2E2D]={d='on'},
[0x2E2E]={d='on'},
[0x2E2F]={d='on'},
[0x2E30]={d='on'},
[0x2E31]={d='on'},
[0x2E32]={d='on'},
[0x2E33]={d='on'},
[0x2E34]={d='on'},
[0x2E35]={d='on'},
[0x2E36]={d='on'},
[0x2E37]={d='on'},
[0x2E38]={d='on'},
[0x2E39]={d='on'},
[0x2E3A]={d='on'},
[0x2E3B]={d='on'},
[0x2E3C]={d='on'},
[0x2E3D]={d='on'},
[0x2E3E]={d='on'},
[0x2E3F]={d='on'},
[0x2E40]={d='on'},
[0x2E41]={d='on'},
[0x2E42]={d='on'},
[0x2E43]={d='on'},
[0x2E44]={d='on'},
[0x2E80]={d='on'},
[0x2E81]={d='on'},
[0x2E82]={d='on'},
[0x2E83]={d='on'},
[0x2E84]={d='on'},
[0x2E85]={d='on'},
[0x2E86]={d='on'},
[0x2E87]={d='on'},
[0x2E88]={d='on'},
[0x2E89]={d='on'},
[0x2E8A]={d='on'},
[0x2E8B]={d='on'},
[0x2E8C]={d='on'},
[0x2E8D]={d='on'},
[0x2E8E]={d='on'},
[0x2E8F]={d='on'},
[0x2E90]={d='on'},
[0x2E91]={d='on'},
[0x2E92]={d='on'},
[0x2E93]={d='on'},
[0x2E94]={d='on'},
[0x2E95]={d='on'},
[0x2E96]={d='on'},
[0x2E97]={d='on'},
[0x2E98]={d='on'},
[0x2E99]={d='on'},
[0x2E9B]={d='on'},
[0x2E9C]={d='on'},
[0x2E9D]={d='on'},
[0x2E9E]={d='on'},
[0x2E9F]={d='on'},
[0x2EA0]={d='on'},
[0x2EA1]={d='on'},
[0x2EA2]={d='on'},
[0x2EA3]={d='on'},
[0x2EA4]={d='on'},
[0x2EA5]={d='on'},
[0x2EA6]={d='on'},
[0x2EA7]={d='on'},
[0x2EA8]={d='on'},
[0x2EA9]={d='on'},
[0x2EAA]={d='on'},
[0x2EAB]={d='on'},
[0x2EAC]={d='on'},
[0x2EAD]={d='on'},
[0x2EAE]={d='on'},
[0x2EAF]={d='on'},
[0x2EB0]={d='on'},
[0x2EB1]={d='on'},
[0x2EB2]={d='on'},
[0x2EB3]={d='on'},
[0x2EB4]={d='on'},
[0x2EB5]={d='on'},
[0x2EB6]={d='on'},
[0x2EB7]={d='on'},
[0x2EB8]={d='on'},
[0x2EB9]={d='on'},
[0x2EBA]={d='on'},
[0x2EBB]={d='on'},
[0x2EBC]={d='on'},
[0x2EBD]={d='on'},
[0x2EBE]={d='on'},
[0x2EBF]={d='on'},
[0x2EC0]={d='on'},
[0x2EC1]={d='on'},
[0x2EC2]={d='on'},
[0x2EC3]={d='on'},
[0x2EC4]={d='on'},
[0x2EC5]={d='on'},
[0x2EC6]={d='on'},
[0x2EC7]={d='on'},
[0x2EC8]={d='on'},
[0x2EC9]={d='on'},
[0x2ECA]={d='on'},
[0x2ECB]={d='on'},
[0x2ECC]={d='on'},
[0x2ECD]={d='on'},
[0x2ECE]={d='on'},
[0x2ECF]={d='on'},
[0x2ED0]={d='on'},
[0x2ED1]={d='on'},
[0x2ED2]={d='on'},
[0x2ED3]={d='on'},
[0x2ED4]={d='on'},
[0x2ED5]={d='on'},
[0x2ED6]={d='on'},
[0x2ED7]={d='on'},
[0x2ED8]={d='on'},
[0x2ED9]={d='on'},
[0x2EDA]={d='on'},
[0x2EDB]={d='on'},
[0x2EDC]={d='on'},
[0x2EDD]={d='on'},
[0x2EDE]={d='on'},
[0x2EDF]={d='on'},
[0x2EE0]={d='on'},
[0x2EE1]={d='on'},
[0x2EE2]={d='on'},
[0x2EE3]={d='on'},
[0x2EE4]={d='on'},
[0x2EE5]={d='on'},
[0x2EE6]={d='on'},
[0x2EE7]={d='on'},
[0x2EE8]={d='on'},
[0x2EE9]={d='on'},
[0x2EEA]={d='on'},
[0x2EEB]={d='on'},
[0x2EEC]={d='on'},
[0x2EED]={d='on'},
[0x2EEE]={d='on'},
[0x2EEF]={d='on'},
[0x2EF0]={d='on'},
[0x2EF1]={d='on'},
[0x2EF2]={d='on'},
[0x2EF3]={d='on'},
[0x2F00]={d='on'},
[0x2F01]={d='on'},
[0x2F02]={d='on'},
[0x2F03]={d='on'},
[0x2F04]={d='on'},
[0x2F05]={d='on'},
[0x2F06]={d='on'},
[0x2F07]={d='on'},
[0x2F08]={d='on'},
[0x2F09]={d='on'},
[0x2F0A]={d='on'},
[0x2F0B]={d='on'},
[0x2F0C]={d='on'},
[0x2F0D]={d='on'},
[0x2F0E]={d='on'},
[0x2F0F]={d='on'},
[0x2F10]={d='on'},
[0x2F11]={d='on'},
[0x2F12]={d='on'},
[0x2F13]={d='on'},
[0x2F14]={d='on'},
[0x2F15]={d='on'},
[0x2F16]={d='on'},
[0x2F17]={d='on'},
[0x2F18]={d='on'},
[0x2F19]={d='on'},
[0x2F1A]={d='on'},
[0x2F1B]={d='on'},
[0x2F1C]={d='on'},
[0x2F1D]={d='on'},
[0x2F1E]={d='on'},
[0x2F1F]={d='on'},
[0x2F20]={d='on'},
[0x2F21]={d='on'},
[0x2F22]={d='on'},
[0x2F23]={d='on'},
[0x2F24]={d='on'},
[0x2F25]={d='on'},
[0x2F26]={d='on'},
[0x2F27]={d='on'},
[0x2F28]={d='on'},
[0x2F29]={d='on'},
[0x2F2A]={d='on'},
[0x2F2B]={d='on'},
[0x2F2C]={d='on'},
[0x2F2D]={d='on'},
[0x2F2E]={d='on'},
[0x2F2F]={d='on'},
[0x2F30]={d='on'},
[0x2F31]={d='on'},
[0x2F32]={d='on'},
[0x2F33]={d='on'},
[0x2F34]={d='on'},
[0x2F35]={d='on'},
[0x2F36]={d='on'},
[0x2F37]={d='on'},
[0x2F38]={d='on'},
[0x2F39]={d='on'},
[0x2F3A]={d='on'},
[0x2F3B]={d='on'},
[0x2F3C]={d='on'},
[0x2F3D]={d='on'},
[0x2F3E]={d='on'},
[0x2F3F]={d='on'},
[0x2F40]={d='on'},
[0x2F41]={d='on'},
[0x2F42]={d='on'},
[0x2F43]={d='on'},
[0x2F44]={d='on'},
[0x2F45]={d='on'},
[0x2F46]={d='on'},
[0x2F47]={d='on'},
[0x2F48]={d='on'},
[0x2F49]={d='on'},
[0x2F4A]={d='on'},
[0x2F4B]={d='on'},
[0x2F4C]={d='on'},
[0x2F4D]={d='on'},
[0x2F4E]={d='on'},
[0x2F4F]={d='on'},
[0x2F50]={d='on'},
[0x2F51]={d='on'},
[0x2F52]={d='on'},
[0x2F53]={d='on'},
[0x2F54]={d='on'},
[0x2F55]={d='on'},
[0x2F56]={d='on'},
[0x2F57]={d='on'},
[0x2F58]={d='on'},
[0x2F59]={d='on'},
[0x2F5A]={d='on'},
[0x2F5B]={d='on'},
[0x2F5C]={d='on'},
[0x2F5D]={d='on'},
[0x2F5E]={d='on'},
[0x2F5F]={d='on'},
[0x2F60]={d='on'},
[0x2F61]={d='on'},
[0x2F62]={d='on'},
[0x2F63]={d='on'},
[0x2F64]={d='on'},
[0x2F65]={d='on'},
[0x2F66]={d='on'},
[0x2F67]={d='on'},
[0x2F68]={d='on'},
[0x2F69]={d='on'},
[0x2F6A]={d='on'},
[0x2F6B]={d='on'},
[0x2F6C]={d='on'},
[0x2F6D]={d='on'},
[0x2F6E]={d='on'},
[0x2F6F]={d='on'},
[0x2F70]={d='on'},
[0x2F71]={d='on'},
[0x2F72]={d='on'},
[0x2F73]={d='on'},
[0x2F74]={d='on'},
[0x2F75]={d='on'},
[0x2F76]={d='on'},
[0x2F77]={d='on'},
[0x2F78]={d='on'},
[0x2F79]={d='on'},
[0x2F7A]={d='on'},
[0x2F7B]={d='on'},
[0x2F7C]={d='on'},
[0x2F7D]={d='on'},
[0x2F7E]={d='on'},
[0x2F7F]={d='on'},
[0x2F80]={d='on'},
[0x2F81]={d='on'},
[0x2F82]={d='on'},
[0x2F83]={d='on'},
[0x2F84]={d='on'},
[0x2F85]={d='on'},
[0x2F86]={d='on'},
[0x2F87]={d='on'},
[0x2F88]={d='on'},
[0x2F89]={d='on'},
[0x2F8A]={d='on'},
[0x2F8B]={d='on'},
[0x2F8C]={d='on'},
[0x2F8D]={d='on'},
[0x2F8E]={d='on'},
[0x2F8F]={d='on'},
[0x2F90]={d='on'},
[0x2F91]={d='on'},
[0x2F92]={d='on'},
[0x2F93]={d='on'},
[0x2F94]={d='on'},
[0x2F95]={d='on'},
[0x2F96]={d='on'},
[0x2F97]={d='on'},
[0x2F98]={d='on'},
[0x2F99]={d='on'},
[0x2F9A]={d='on'},
[0x2F9B]={d='on'},
[0x2F9C]={d='on'},
[0x2F9D]={d='on'},
[0x2F9E]={d='on'},
[0x2F9F]={d='on'},
[0x2FA0]={d='on'},
[0x2FA1]={d='on'},
[0x2FA2]={d='on'},
[0x2FA3]={d='on'},
[0x2FA4]={d='on'},
[0x2FA5]={d='on'},
[0x2FA6]={d='on'},
[0x2FA7]={d='on'},
[0x2FA8]={d='on'},
[0x2FA9]={d='on'},
[0x2FAA]={d='on'},
[0x2FAB]={d='on'},
[0x2FAC]={d='on'},
[0x2FAD]={d='on'},
[0x2FAE]={d='on'},
[0x2FAF]={d='on'},
[0x2FB0]={d='on'},
[0x2FB1]={d='on'},
[0x2FB2]={d='on'},
[0x2FB3]={d='on'},
[0x2FB4]={d='on'},
[0x2FB5]={d='on'},
[0x2FB6]={d='on'},
[0x2FB7]={d='on'},
[0x2FB8]={d='on'},
[0x2FB9]={d='on'},
[0x2FBA]={d='on'},
[0x2FBB]={d='on'},
[0x2FBC]={d='on'},
[0x2FBD]={d='on'},
[0x2FBE]={d='on'},
[0x2FBF]={d='on'},
[0x2FC0]={d='on'},
[0x2FC1]={d='on'},
[0x2FC2]={d='on'},
[0x2FC3]={d='on'},
[0x2FC4]={d='on'},
[0x2FC5]={d='on'},
[0x2FC6]={d='on'},
[0x2FC7]={d='on'},
[0x2FC8]={d='on'},
[0x2FC9]={d='on'},
[0x2FCA]={d='on'},
[0x2FCB]={d='on'},
[0x2FCC]={d='on'},
[0x2FCD]={d='on'},
[0x2FCE]={d='on'},
[0x2FCF]={d='on'},
[0x2FD0]={d='on'},
[0x2FD1]={d='on'},
[0x2FD2]={d='on'},
[0x2FD3]={d='on'},
[0x2FD4]={d='on'},
[0x2FD5]={d='on'},
[0x2FF0]={d='on'},
[0x2FF1]={d='on'},
[0x2FF2]={d='on'},
[0x2FF3]={d='on'},
[0x2FF4]={d='on'},
[0x2FF5]={d='on'},
[0x2FF6]={d='on'},
[0x2FF7]={d='on'},
[0x2FF8]={d='on'},
[0x2FF9]={d='on'},
[0x2FFA]={d='on'},
[0x2FFB]={d='on'},
[0x3000]={d='ws'},
[0x3001]={d='on'},
[0x3002]={d='on'},
[0x3003]={d='on'},
[0x3004]={d='on'},
[0x3008]={d='on', m=0x3009},
[0x3009]={d='on', m=0x3008},
[0x300A]={d='on', m=0x300B},
[0x300B]={d='on', m=0x300A},
[0x300C]={d='on', m=0x300D},
[0x300D]={d='on', m=0x300C},
[0x300E]={d='on', m=0x300F},
[0x300F]={d='on', m=0x300E},
[0x3010]={d='on', m=0x3011},
[0x3011]={d='on', m=0x3010},
[0x3012]={d='on'},
[0x3013]={d='on'},
[0x3014]={d='on', m=0x3015},
[0x3015]={d='on', m=0x3014},
[0x3016]={d='on', m=0x3017},
[0x3017]={d='on', m=0x3016},
[0x3018]={d='on', m=0x3019},
[0x3019]={d='on', m=0x3018},
[0x301A]={d='on', m=0x301B},
[0x301B]={d='on', m=0x301A},
[0x301C]={d='on'},
[0x301D]={d='on'},
[0x301E]={d='on'},
[0x301F]={d='on'},
[0x3020]={d='on'},
[0x302A]={d='nsm'},
[0x302B]={d='nsm'},
[0x302C]={d='nsm'},
[0x302D]={d='nsm'},
[0x3030]={d='on'},
[0x3036]={d='on'},
[0x3037]={d='on'},
[0x303D]={d='on'},
[0x303E]={d='on'},
[0x303F]={d='on'},
[0x3099]={d='nsm'},
[0x309A]={d='nsm'},
[0x309B]={d='on'},
[0x309C]={d='on'},
[0x30A0]={d='on'},
[0x30FB]={d='on'},
[0x31C0]={d='on'},
[0x31C1]={d='on'},
[0x31C2]={d='on'},
[0x31C3]={d='on'},
[0x31C4]={d='on'},
[0x31C5]={d='on'},
[0x31C6]={d='on'},
[0x31C7]={d='on'},
[0x31C8]={d='on'},
[0x31C9]={d='on'},
[0x31CA]={d='on'},
[0x31CB]={d='on'},
[0x31CC]={d='on'},
[0x31CD]={d='on'},
[0x31CE]={d='on'},
[0x31CF]={d='on'},
[0x31D0]={d='on'},
[0x31D1]={d='on'},
[0x31D2]={d='on'},
[0x31D3]={d='on'},
[0x31D4]={d='on'},
[0x31D5]={d='on'},
[0x31D6]={d='on'},
[0x31D7]={d='on'},
[0x31D8]={d='on'},
[0x31D9]={d='on'},
[0x31DA]={d='on'},
[0x31DB]={d='on'},
[0x31DC]={d='on'},
[0x31DD]={d='on'},
[0x31DE]={d='on'},
[0x31DF]={d='on'},
[0x31E0]={d='on'},
[0x31E1]={d='on'},
[0x31E2]={d='on'},
[0x31E3]={d='on'},
[0x321D]={d='on'},
[0x321E]={d='on'},
[0x3250]={d='on'},
[0x3251]={d='on'},
[0x3252]={d='on'},
[0x3253]={d='on'},
[0x3254]={d='on'},
[0x3255]={d='on'},
[0x3256]={d='on'},
[0x3257]={d='on'},
[0x3258]={d='on'},
[0x3259]={d='on'},
[0x325A]={d='on'},
[0x325B]={d='on'},
[0x325C]={d='on'},
[0x325D]={d='on'},
[0x325E]={d='on'},
[0x325F]={d='on'},
[0x327C]={d='on'},
[0x327D]={d='on'},
[0x327E]={d='on'},
[0x32B1]={d='on'},
[0x32B2]={d='on'},
[0x32B3]={d='on'},
[0x32B4]={d='on'},
[0x32B5]={d='on'},
[0x32B6]={d='on'},
[0x32B7]={d='on'},
[0x32B8]={d='on'},
[0x32B9]={d='on'},
[0x32BA]={d='on'},
[0x32BB]={d='on'},
[0x32BC]={d='on'},
[0x32BD]={d='on'},
[0x32BE]={d='on'},
[0x32BF]={d='on'},
[0x32CC]={d='on'},
[0x32CD]={d='on'},
[0x32CE]={d='on'},
[0x32CF]={d='on'},
[0x3377]={d='on'},
[0x3378]={d='on'},
[0x3379]={d='on'},
[0x337A]={d='on'},
[0x33DE]={d='on'},
[0x33DF]={d='on'},
[0x33FF]={d='on'},
[0x4DC0]={d='on'},
[0x4DC1]={d='on'},
[0x4DC2]={d='on'},
[0x4DC3]={d='on'},
[0x4DC4]={d='on'},
[0x4DC5]={d='on'},
[0x4DC6]={d='on'},
[0x4DC7]={d='on'},
[0x4DC8]={d='on'},
[0x4DC9]={d='on'},
[0x4DCA]={d='on'},
[0x4DCB]={d='on'},
[0x4DCC]={d='on'},
[0x4DCD]={d='on'},
[0x4DCE]={d='on'},
[0x4DCF]={d='on'},
[0x4DD0]={d='on'},
[0x4DD1]={d='on'},
[0x4DD2]={d='on'},
[0x4DD3]={d='on'},
[0x4DD4]={d='on'},
[0x4DD5]={d='on'},
[0x4DD6]={d='on'},
[0x4DD7]={d='on'},
[0x4DD8]={d='on'},
[0x4DD9]={d='on'},
[0x4DDA]={d='on'},
[0x4DDB]={d='on'},
[0x4DDC]={d='on'},
[0x4DDD]={d='on'},
[0x4DDE]={d='on'},
[0x4DDF]={d='on'},
[0x4DE0]={d='on'},
[0x4DE1]={d='on'},
[0x4DE2]={d='on'},
[0x4DE3]={d='on'},
[0x4DE4]={d='on'},
[0x4DE5]={d='on'},
[0x4DE6]={d='on'},
[0x4DE7]={d='on'},
[0x4DE8]={d='on'},
[0x4DE9]={d='on'},
[0x4DEA]={d='on'},
[0x4DEB]={d='on'},
[0x4DEC]={d='on'},
[0x4DED]={d='on'},
[0x4DEE]={d='on'},
[0x4DEF]={d='on'},
[0x4DF0]={d='on'},
[0x4DF1]={d='on'},
[0x4DF2]={d='on'},
[0x4DF3]={d='on'},
[0x4DF4]={d='on'},
[0x4DF5]={d='on'},
[0x4DF6]={d='on'},
[0x4DF7]={d='on'},
[0x4DF8]={d='on'},
[0x4DF9]={d='on'},
[0x4DFA]={d='on'},
[0x4DFB]={d='on'},
[0x4DFC]={d='on'},
[0x4DFD]={d='on'},
[0x4DFE]={d='on'},
[0x4DFF]={d='on'},
[0xA490]={d='on'},
[0xA491]={d='on'},
[0xA492]={d='on'},
[0xA493]={d='on'},
[0xA494]={d='on'},
[0xA495]={d='on'},
[0xA496]={d='on'},
[0xA497]={d='on'},
[0xA498]={d='on'},
[0xA499]={d='on'},
[0xA49A]={d='on'},
[0xA49B]={d='on'},
[0xA49C]={d='on'},
[0xA49D]={d='on'},
[0xA49E]={d='on'},
[0xA49F]={d='on'},
[0xA4A0]={d='on'},
[0xA4A1]={d='on'},
[0xA4A2]={d='on'},
[0xA4A3]={d='on'},
[0xA4A4]={d='on'},
[0xA4A5]={d='on'},
[0xA4A6]={d='on'},
[0xA4A7]={d='on'},
[0xA4A8]={d='on'},
[0xA4A9]={d='on'},
[0xA4AA]={d='on'},
[0xA4AB]={d='on'},
[0xA4AC]={d='on'},
[0xA4AD]={d='on'},
[0xA4AE]={d='on'},
[0xA4AF]={d='on'},
[0xA4B0]={d='on'},
[0xA4B1]={d='on'},
[0xA4B2]={d='on'},
[0xA4B3]={d='on'},
[0xA4B4]={d='on'},
[0xA4B5]={d='on'},
[0xA4B6]={d='on'},
[0xA4B7]={d='on'},
[0xA4B8]={d='on'},
[0xA4B9]={d='on'},
[0xA4BA]={d='on'},
[0xA4BB]={d='on'},
[0xA4BC]={d='on'},
[0xA4BD]={d='on'},
[0xA4BE]={d='on'},
[0xA4BF]={d='on'},
[0xA4C0]={d='on'},
[0xA4C1]={d='on'},
[0xA4C2]={d='on'},
[0xA4C3]={d='on'},
[0xA4C4]={d='on'},
[0xA4C5]={d='on'},
[0xA4C6]={d='on'},
[0xA60D]={d='on'},
[0xA60E]={d='on'},
[0xA60F]={d='on'},
[0xA66F]={d='nsm'},
[0xA670]={d='nsm'},
[0xA671]={d='nsm'},
[0xA672]={d='nsm'},
[0xA673]={d='on'},
[0xA674]={d='nsm'},
[0xA675]={d='nsm'},
[0xA676]={d='nsm'},
[0xA677]={d='nsm'},
[0xA678]={d='nsm'},
[0xA679]={d='nsm'},
[0xA67A]={d='nsm'},
[0xA67B]={d='nsm'},
[0xA67C]={d='nsm'},
[0xA67D]={d='nsm'},
[0xA67E]={d='on'},
[0xA67F]={d='on'},
[0xA69E]={d='nsm'},
[0xA69F]={d='nsm'},
[0xA6F0]={d='nsm'},
[0xA6F1]={d='nsm'},
[0xA700]={d='on'},
[0xA701]={d='on'},
[0xA702]={d='on'},
[0xA703]={d='on'},
[0xA704]={d='on'},
[0xA705]={d='on'},
[0xA706]={d='on'},
[0xA707]={d='on'},
[0xA708]={d='on'},
[0xA709]={d='on'},
[0xA70A]={d='on'},
[0xA70B]={d='on'},
[0xA70C]={d='on'},
[0xA70D]={d='on'},
[0xA70E]={d='on'},
[0xA70F]={d='on'},
[0xA710]={d='on'},
[0xA711]={d='on'},
[0xA712]={d='on'},
[0xA713]={d='on'},
[0xA714]={d='on'},
[0xA715]={d='on'},
[0xA716]={d='on'},
[0xA717]={d='on'},
[0xA718]={d='on'},
[0xA719]={d='on'},
[0xA71A]={d='on'},
[0xA71B]={d='on'},
[0xA71C]={d='on'},
[0xA71D]={d='on'},
[0xA71E]={d='on'},
[0xA71F]={d='on'},
[0xA720]={d='on'},
[0xA721]={d='on'},
[0xA788]={d='on'},
[0xA802]={d='nsm'},
[0xA806]={d='nsm'},
[0xA80B]={d='nsm'},
[0xA825]={d='nsm'},
[0xA826]={d='nsm'},
[0xA828]={d='on'},
[0xA829]={d='on'},
[0xA82A]={d='on'},
[0xA82B]={d='on'},
[0xA838]={d='et'},
[0xA839]={d='et'},
[0xA874]={d='on'},
[0xA875]={d='on'},
[0xA876]={d='on'},
[0xA877]={d='on'},
[0xA8C4]={d='nsm'},
[0xA8C5]={d='nsm'},
[0xA8E0]={d='nsm'},
[0xA8E1]={d='nsm'},
[0xA8E2]={d='nsm'},
[0xA8E3]={d='nsm'},
[0xA8E4]={d='nsm'},
[0xA8E5]={d='nsm'},
[0xA8E6]={d='nsm'},
[0xA8E7]={d='nsm'},
[0xA8E8]={d='nsm'},
[0xA8E9]={d='nsm'},
[0xA8EA]={d='nsm'},
[0xA8EB]={d='nsm'},
[0xA8EC]={d='nsm'},
[0xA8ED]={d='nsm'},
[0xA8EE]={d='nsm'},
[0xA8EF]={d='nsm'},
[0xA8F0]={d='nsm'},
[0xA8F1]={d='nsm'},
[0xA926]={d='nsm'},
[0xA927]={d='nsm'},
[0xA928]={d='nsm'},
[0xA929]={d='nsm'},
[0xA92A]={d='nsm'},
[0xA92B]={d='nsm'},
[0xA92C]={d='nsm'},
[0xA92D]={d='nsm'},
[0xA947]={d='nsm'},
[0xA948]={d='nsm'},
[0xA949]={d='nsm'},
[0xA94A]={d='nsm'},
[0xA94B]={d='nsm'},
[0xA94C]={d='nsm'},
[0xA94D]={d='nsm'},
[0xA94E]={d='nsm'},
[0xA94F]={d='nsm'},
[0xA950]={d='nsm'},
[0xA951]={d='nsm'},
[0xA980]={d='nsm'},
[0xA981]={d='nsm'},
[0xA982]={d='nsm'},
[0xA9B3]={d='nsm'},
[0xA9B6]={d='nsm'},
[0xA9B7]={d='nsm'},
[0xA9B8]={d='nsm'},
[0xA9B9]={d='nsm'},
[0xA9BC]={d='nsm'},
[0xA9E5]={d='nsm'},
[0xAA29]={d='nsm'},
[0xAA2A]={d='nsm'},
[0xAA2B]={d='nsm'},
[0xAA2C]={d='nsm'},
[0xAA2D]={d='nsm'},
[0xAA2E]={d='nsm'},
[0xAA31]={d='nsm'},
[0xAA32]={d='nsm'},
[0xAA35]={d='nsm'},
[0xAA36]={d='nsm'},
[0xAA43]={d='nsm'},
[0xAA4C]={d='nsm'},
[0xAA7C]={d='nsm'},
[0xAAB0]={d='nsm'},
[0xAAB2]={d='nsm'},
[0xAAB3]={d='nsm'},
[0xAAB4]={d='nsm'},
[0xAAB7]={d='nsm'},
[0xAAB8]={d='nsm'},
[0xAABE]={d='nsm'},
[0xAABF]={d='nsm'},
[0xAAC1]={d='nsm'},
[0xAAEC]={d='nsm'},
[0xAAED]={d='nsm'},
[0xAAF6]={d='nsm'},
[0xABE5]={d='nsm'},
[0xABE8]={d='nsm'},
[0xABED]={d='nsm'},
[0xFB1E]={d='nsm'},
[0xFB29]={d='es'},
[0xFD3E]={d='on'},
[0xFD3F]={d='on'},
[0xFDFD]={d='on'},
[0xFE10]={d='on'},
[0xFE11]={d='on'},
[0xFE12]={d='on'},
[0xFE13]={d='on'},
[0xFE14]={d='on'},
[0xFE15]={d='on'},
[0xFE16]={d='on'},
[0xFE17]={d='on'},
[0xFE18]={d='on'},
[0xFE19]={d='on'},
[0xFE20]={d='nsm'},
[0xFE21]={d='nsm'},
[0xFE22]={d='nsm'},
[0xFE23]={d='nsm'},
[0xFE24]={d='nsm'},
[0xFE25]={d='nsm'},
[0xFE26]={d='nsm'},
[0xFE27]={d='nsm'},
[0xFE28]={d='nsm'},
[0xFE29]={d='nsm'},
[0xFE2A]={d='nsm'},
[0xFE2B]={d='nsm'},
[0xFE2C]={d='nsm'},
[0xFE2D]={d='nsm'},
[0xFE2E]={d='nsm'},
[0xFE2F]={d='nsm'},
[0xFE30]={d='on'},
[0xFE31]={d='on'},
[0xFE32]={d='on'},
[0xFE33]={d='on'},
[0xFE34]={d='on'},
[0xFE35]={d='on'},
[0xFE36]={d='on'},
[0xFE37]={d='on'},
[0xFE38]={d='on'},
[0xFE39]={d='on'},
[0xFE3A]={d='on'},
[0xFE3B]={d='on'},
[0xFE3C]={d='on'},
[0xFE3D]={d='on'},
[0xFE3E]={d='on'},
[0xFE3F]={d='on'},
[0xFE40]={d='on'},
[0xFE41]={d='on'},
[0xFE42]={d='on'},
[0xFE43]={d='on'},
[0xFE44]={d='on'},
[0xFE45]={d='on'},
[0xFE46]={d='on'},
[0xFE47]={d='on'},
[0xFE48]={d='on'},
[0xFE49]={d='on'},
[0xFE4A]={d='on'},
[0xFE4B]={d='on'},
[0xFE4C]={d='on'},
[0xFE4D]={d='on'},
[0xFE4E]={d='on'},
[0xFE4F]={d='on'},
[0xFE50]={d='cs'},
[0xFE51]={d='on'},
[0xFE52]={d='cs'},
[0xFE54]={d='on'},
[0xFE55]={d='cs'},
[0xFE56]={d='on'},
[0xFE57]={d='on'},
[0xFE58]={d='on'},
[0xFE59]={d='on', m=0xFE5A},
[0xFE5A]={d='on', m=0xFE59},
[0xFE5B]={d='on', m=0xFE5C},
[0xFE5C]={d='on', m=0xFE5B},
[0xFE5D]={d='on', m=0xFE5E},
[0xFE5E]={d='on', m=0xFE5D},
[0xFE5F]={d='et'},
[0xFE60]={d='on'},
[0xFE61]={d='on'},
[0xFE62]={d='es'},
[0xFE63]={d='es'},
[0xFE64]={d='on', m=0xFE65},
[0xFE65]={d='on', m=0xFE64},
[0xFE66]={d='on'},
[0xFE68]={d='on'},
[0xFE69]={d='et'},
[0xFE6A]={d='et'},
[0xFE6B]={d='on'},
[0xFEFF]={d='bn'},
[0xFF01]={d='on'},
[0xFF02]={d='on'},
[0xFF03]={d='et'},
[0xFF04]={d='et'},
[0xFF05]={d='et'},
[0xFF06]={d='on'},
[0xFF07]={d='on'},
[0xFF08]={d='on', m=0xFF09},
[0xFF09]={d='on', m=0xFF08},
[0xFF0A]={d='on'},
[0xFF0B]={d='es'},
[0xFF0C]={d='cs'},
[0xFF0D]={d='es'},
[0xFF0E]={d='cs'},
[0xFF0F]={d='cs'},
[0xFF10]={d='en'},
[0xFF11]={d='en'},
[0xFF12]={d='en'},
[0xFF13]={d='en'},
[0xFF14]={d='en'},
[0xFF15]={d='en'},
[0xFF16]={d='en'},
[0xFF17]={d='en'},
[0xFF18]={d='en'},
[0xFF19]={d='en'},
[0xFF1A]={d='cs'},
[0xFF1B]={d='on'},
[0xFF1C]={d='on', m=0xFF1E},
[0xFF1D]={d='on'},
[0xFF1E]={d='on', m=0xFF1C},
[0xFF1F]={d='on'},
[0xFF20]={d='on'},
[0xFF3B]={d='on', m=0xFF3D},
[0xFF3C]={d='on'},
[0xFF3D]={d='on', m=0xFF3B},
[0xFF3E]={d='on'},
[0xFF3F]={d='on'},
[0xFF40]={d='on'},
[0xFF5B]={d='on', m=0xFF5D},
[0xFF5C]={d='on'},
[0xFF5D]={d='on', m=0xFF5B},
[0xFF5E]={d='on'},
[0xFF5F]={d='on', m=0xFF60},
[0xFF60]={d='on', m=0xFF5F},
[0xFF61]={d='on'},
[0xFF62]={d='on', m=0xFF63},
[0xFF63]={d='on', m=0xFF62},
[0xFF64]={d='on'},
[0xFF65]={d='on'},
[0xFFE0]={d='et'},
[0xFFE1]={d='et'},
[0xFFE2]={d='on'},
[0xFFE3]={d='on'},
[0xFFE4]={d='on'},
[0xFFE5]={d='et'},
[0xFFE6]={d='et'},
[0xFFE8]={d='on'},
[0xFFE9]={d='on'},
[0xFFEA]={d='on'},
[0xFFEB]={d='on'},
[0xFFEC]={d='on'},
[0xFFED]={d='on'},
[0xFFEE]={d='on'},
[0xFFF9]={d='on'},
[0xFFFA]={d='on'},
[0xFFFB]={d='on'},
[0xFFFC]={d='on'},
[0xFFFD]={d='on'},
[0x10101]={d='on'},
[0x10140]={d='on'},
[0x10141]={d='on'},
[0x10142]={d='on'},
[0x10143]={d='on'},
[0x10144]={d='on'},
[0x10145]={d='on'},
[0x10146]={d='on'},
[0x10147]={d='on'},
[0x10148]={d='on'},
[0x10149]={d='on'},
[0x1014A]={d='on'},
[0x1014B]={d='on'},
[0x1014C]={d='on'},
[0x1014D]={d='on'},
[0x1014E]={d='on'},
[0x1014F]={d='on'},
[0x10150]={d='on'},
[0x10151]={d='on'},
[0x10152]={d='on'},
[0x10153]={d='on'},
[0x10154]={d='on'},
[0x10155]={d='on'},
[0x10156]={d='on'},
[0x10157]={d='on'},
[0x10158]={d='on'},
[0x10159]={d='on'},
[0x1015A]={d='on'},
[0x1015B]={d='on'},
[0x1015C]={d='on'},
[0x1015D]={d='on'},
[0x1015E]={d='on'},
[0x1015F]={d='on'},
[0x10160]={d='on'},
[0x10161]={d='on'},
[0x10162]={d='on'},
[0x10163]={d='on'},
[0x10164]={d='on'},
[0x10165]={d='on'},
[0x10166]={d='on'},
[0x10167]={d='on'},
[0x10168]={d='on'},
[0x10169]={d='on'},
[0x1016A]={d='on'},
[0x1016B]={d='on'},
[0x1016C]={d='on'},
[0x1016D]={d='on'},
[0x1016E]={d='on'},
[0x1016F]={d='on'},
[0x10170]={d='on'},
[0x10171]={d='on'},
[0x10172]={d='on'},
[0x10173]={d='on'},
[0x10174]={d='on'},
[0x10175]={d='on'},
[0x10176]={d='on'},
[0x10177]={d='on'},
[0x10178]={d='on'},
[0x10179]={d='on'},
[0x1017A]={d='on'},
[0x1017B]={d='on'},
[0x1017C]={d='on'},
[0x1017D]={d='on'},
[0x1017E]={d='on'},
[0x1017F]={d='on'},
[0x10180]={d='on'},
[0x10181]={d='on'},
[0x10182]={d='on'},
[0x10183]={d='on'},
[0x10184]={d='on'},
[0x10185]={d='on'},
[0x10186]={d='on'},
[0x10187]={d='on'},
[0x10188]={d='on'},
[0x10189]={d='on'},
[0x1018A]={d='on'},
[0x1018B]={d='on'},
[0x1018C]={d='on'},
[0x10190]={d='on'},
[0x10191]={d='on'},
[0x10192]={d='on'},
[0x10193]={d='on'},
[0x10194]={d='on'},
[0x10195]={d='on'},
[0x10196]={d='on'},
[0x10197]={d='on'},
[0x10198]={d='on'},
[0x10199]={d='on'},
[0x1019A]={d='on'},
[0x1019B]={d='on'},
[0x101A0]={d='on'},
[0x101FD]={d='nsm'},
[0x102E0]={d='nsm'},
[0x102E1]={d='en'},
[0x102E2]={d='en'},
[0x102E3]={d='en'},
[0x102E4]={d='en'},
[0x102E5]={d='en'},
[0x102E6]={d='en'},
[0x102E7]={d='en'},
[0x102E8]={d='en'},
[0x102E9]={d='en'},
[0x102EA]={d='en'},
[0x102EB]={d='en'},
[0x102EC]={d='en'},
[0x102ED]={d='en'},
[0x102EE]={d='en'},
[0x102EF]={d='en'},
[0x102F0]={d='en'},
[0x102F1]={d='en'},
[0x102F2]={d='en'},
[0x102F3]={d='en'},
[0x102F4]={d='en'},
[0x102F5]={d='en'},
[0x102F6]={d='en'},
[0x102F7]={d='en'},
[0x102F8]={d='en'},
[0x102F9]={d='en'},
[0x102FA]={d='en'},
[0x102FB]={d='en'},
[0x10376]={d='nsm'},
[0x10377]={d='nsm'},
[0x10378]={d='nsm'},
[0x10379]={d='nsm'},
[0x1037A]={d='nsm'},
[0x1091F]={d='on'},
[0x10A01]={d='nsm'},
[0x10A02]={d='nsm'},
[0x10A03]={d='nsm'},
[0x10A05]={d='nsm'},
[0x10A06]={d='nsm'},
[0x10A0C]={d='nsm'},
[0x10A0D]={d='nsm'},
[0x10A0E]={d='nsm'},
[0x10A0F]={d='nsm'},
[0x10A38]={d='nsm'},
[0x10A39]={d='nsm'},
[0x10A3A]={d='nsm'},
[0x10A3F]={d='nsm'},
[0x10AE5]={d='nsm'},
[0x10AE6]={d='nsm'},
[0x10B39]={d='on'},
[0x10B3A]={d='on'},
[0x10B3B]={d='on'},
[0x10B3C]={d='on'},
[0x10B3D]={d='on'},
[0x10B3E]={d='on'},
[0x10B3F]={d='on'},
[0x10E60]={d='an'},
[0x10E61]={d='an'},
[0x10E62]={d='an'},
[0x10E63]={d='an'},
[0x10E64]={d='an'},
[0x10E65]={d='an'},
[0x10E66]={d='an'},
[0x10E67]={d='an'},
[0x10E68]={d='an'},
[0x10E69]={d='an'},
[0x10E6A]={d='an'},
[0x10E6B]={d='an'},
[0x10E6C]={d='an'},
[0x10E6D]={d='an'},
[0x10E6E]={d='an'},
[0x10E6F]={d='an'},
[0x10E70]={d='an'},
[0x10E71]={d='an'},
[0x10E72]={d='an'},
[0x10E73]={d='an'},
[0x10E74]={d='an'},
[0x10E75]={d='an'},
[0x10E76]={d='an'},
[0x10E77]={d='an'},
[0x10E78]={d='an'},
[0x10E79]={d='an'},
[0x10E7A]={d='an'},
[0x10E7B]={d='an'},
[0x10E7C]={d='an'},
[0x10E7D]={d='an'},
[0x10E7E]={d='an'},
[0x11001]={d='nsm'},
[0x11038]={d='nsm'},
[0x11039]={d='nsm'},
[0x1103A]={d='nsm'},
[0x1103B]={d='nsm'},
[0x1103C]={d='nsm'},
[0x1103D]={d='nsm'},
[0x1103E]={d='nsm'},
[0x1103F]={d='nsm'},
[0x11040]={d='nsm'},
[0x11041]={d='nsm'},
[0x11042]={d='nsm'},
[0x11043]={d='nsm'},
[0x11044]={d='nsm'},
[0x11045]={d='nsm'},
[0x11046]={d='nsm'},
[0x11052]={d='on'},
[0x11053]={d='on'},
[0x11054]={d='on'},
[0x11055]={d='on'},
[0x11056]={d='on'},
[0x11057]={d='on'},
[0x11058]={d='on'},
[0x11059]={d='on'},
[0x1105A]={d='on'},
[0x1105B]={d='on'},
[0x1105C]={d='on'},
[0x1105D]={d='on'},
[0x1105E]={d='on'},
[0x1105F]={d='on'},
[0x11060]={d='on'},
[0x11061]={d='on'},
[0x11062]={d='on'},
[0x11063]={d='on'},
[0x11064]={d='on'},
[0x11065]={d='on'},
[0x1107F]={d='nsm'},
[0x11080]={d='nsm'},
[0x11081]={d='nsm'},
[0x110B3]={d='nsm'},
[0x110B4]={d='nsm'},
[0x110B5]={d='nsm'},
[0x110B6]={d='nsm'},
[0x110B9]={d='nsm'},
[0x110BA]={d='nsm'},
[0x11100]={d='nsm'},
[0x11101]={d='nsm'},
[0x11102]={d='nsm'},
[0x11127]={d='nsm'},
[0x11128]={d='nsm'},
[0x11129]={d='nsm'},
[0x1112A]={d='nsm'},
[0x1112B]={d='nsm'},
[0x1112D]={d='nsm'},
[0x1112E]={d='nsm'},
[0x1112F]={d='nsm'},
[0x11130]={d='nsm'},
[0x11131]={d='nsm'},
[0x11132]={d='nsm'},
[0x11133]={d='nsm'},
[0x11134]={d='nsm'},
[0x11173]={d='nsm'},
[0x11180]={d='nsm'},
[0x11181]={d='nsm'},
[0x111B6]={d='nsm'},
[0x111B7]={d='nsm'},
[0x111B8]={d='nsm'},
[0x111B9]={d='nsm'},
[0x111BA]={d='nsm'},
[0x111BB]={d='nsm'},
[0x111BC]={d='nsm'},
[0x111BD]={d='nsm'},
[0x111BE]={d='nsm'},
[0x111CA]={d='nsm'},
[0x111CB]={d='nsm'},
[0x111CC]={d='nsm'},
[0x1122F]={d='nsm'},
[0x11230]={d='nsm'},
[0x11231]={d='nsm'},
[0x11234]={d='nsm'},
[0x11236]={d='nsm'},
[0x11237]={d='nsm'},
[0x1123E]={d='nsm'},
[0x112DF]={d='nsm'},
[0x112E3]={d='nsm'},
[0x112E4]={d='nsm'},
[0x112E5]={d='nsm'},
[0x112E6]={d='nsm'},
[0x112E7]={d='nsm'},
[0x112E8]={d='nsm'},
[0x112E9]={d='nsm'},
[0x112EA]={d='nsm'},
[0x11300]={d='nsm'},
[0x11301]={d='nsm'},
[0x1133C]={d='nsm'},
[0x11340]={d='nsm'},
[0x11366]={d='nsm'},
[0x11367]={d='nsm'},
[0x11368]={d='nsm'},
[0x11369]={d='nsm'},
[0x1136A]={d='nsm'},
[0x1136B]={d='nsm'},
[0x1136C]={d='nsm'},
[0x11370]={d='nsm'},
[0x11371]={d='nsm'},
[0x11372]={d='nsm'},
[0x11373]={d='nsm'},
[0x11374]={d='nsm'},
[0x11438]={d='nsm'},
[0x11439]={d='nsm'},
[0x1143A]={d='nsm'},
[0x1143B]={d='nsm'},
[0x1143C]={d='nsm'},
[0x1143D]={d='nsm'},
[0x1143E]={d='nsm'},
[0x1143F]={d='nsm'},
[0x11442]={d='nsm'},
[0x11443]={d='nsm'},
[0x11444]={d='nsm'},
[0x11446]={d='nsm'},
[0x114B3]={d='nsm'},
[0x114B4]={d='nsm'},
[0x114B5]={d='nsm'},
[0x114B6]={d='nsm'},
[0x114B7]={d='nsm'},
[0x114B8]={d='nsm'},
[0x114BA]={d='nsm'},
[0x114BF]={d='nsm'},
[0x114C0]={d='nsm'},
[0x114C2]={d='nsm'},
[0x114C3]={d='nsm'},
[0x115B2]={d='nsm'},
[0x115B3]={d='nsm'},
[0x115B4]={d='nsm'},
[0x115B5]={d='nsm'},
[0x115BC]={d='nsm'},
[0x115BD]={d='nsm'},
[0x115BF]={d='nsm'},
[0x115C0]={d='nsm'},
[0x115DC]={d='nsm'},
[0x115DD]={d='nsm'},
[0x11633]={d='nsm'},
[0x11634]={d='nsm'},
[0x11635]={d='nsm'},
[0x11636]={d='nsm'},
[0x11637]={d='nsm'},
[0x11638]={d='nsm'},
[0x11639]={d='nsm'},
[0x1163A]={d='nsm'},
[0x1163D]={d='nsm'},
[0x1163F]={d='nsm'},
[0x11640]={d='nsm'},
[0x11660]={d='on'},
[0x11661]={d='on'},
[0x11662]={d='on'},
[0x11663]={d='on'},
[0x11664]={d='on'},
[0x11665]={d='on'},
[0x11666]={d='on'},
[0x11667]={d='on'},
[0x11668]={d='on'},
[0x11669]={d='on'},
[0x1166A]={d='on'},
[0x1166B]={d='on'},
[0x1166C]={d='on'},
[0x116AB]={d='nsm'},
[0x116AD]={d='nsm'},
[0x116B0]={d='nsm'},
[0x116B1]={d='nsm'},
[0x116B2]={d='nsm'},
[0x116B3]={d='nsm'},
[0x116B4]={d='nsm'},
[0x116B5]={d='nsm'},
[0x116B7]={d='nsm'},
[0x1171D]={d='nsm'},
[0x1171E]={d='nsm'},
[0x1171F]={d='nsm'},
[0x11722]={d='nsm'},
[0x11723]={d='nsm'},
[0x11724]={d='nsm'},
[0x11725]={d='nsm'},
[0x11727]={d='nsm'},
[0x11728]={d='nsm'},
[0x11729]={d='nsm'},
[0x1172A]={d='nsm'},
[0x1172B]={d='nsm'},
[0x11C30]={d='nsm'},
[0x11C31]={d='nsm'},
[0x11C32]={d='nsm'},
[0x11C33]={d='nsm'},
[0x11C34]={d='nsm'},
[0x11C35]={d='nsm'},
[0x11C36]={d='nsm'},
[0x11C38]={d='nsm'},
[0x11C39]={d='nsm'},
[0x11C3A]={d='nsm'},
[0x11C3B]={d='nsm'},
[0x11C3C]={d='nsm'},
[0x11C3D]={d='nsm'},
[0x11C92]={d='nsm'},
[0x11C93]={d='nsm'},
[0x11C94]={d='nsm'},
[0x11C95]={d='nsm'},
[0x11C96]={d='nsm'},
[0x11C97]={d='nsm'},
[0x11C98]={d='nsm'},
[0x11C99]={d='nsm'},
[0x11C9A]={d='nsm'},
[0x11C9B]={d='nsm'},
[0x11C9C]={d='nsm'},
[0x11C9D]={d='nsm'},
[0x11C9E]={d='nsm'},
[0x11C9F]={d='nsm'},
[0x11CA0]={d='nsm'},
[0x11CA1]={d='nsm'},
[0x11CA2]={d='nsm'},
[0x11CA3]={d='nsm'},
[0x11CA4]={d='nsm'},
[0x11CA5]={d='nsm'},
[0x11CA6]={d='nsm'},
[0x11CA7]={d='nsm'},
[0x11CAA]={d='nsm'},
[0x11CAB]={d='nsm'},
[0x11CAC]={d='nsm'},
[0x11CAD]={d='nsm'},
[0x11CAE]={d='nsm'},
[0x11CAF]={d='nsm'},
[0x11CB0]={d='nsm'},
[0x11CB2]={d='nsm'},
[0x11CB3]={d='nsm'},
[0x11CB5]={d='nsm'},
[0x11CB6]={d='nsm'},
[0x16AF0]={d='nsm'},
[0x16AF1]={d='nsm'},
[0x16AF2]={d='nsm'},
[0x16AF3]={d='nsm'},
[0x16AF4]={d='nsm'},
[0x16B30]={d='nsm'},
[0x16B31]={d='nsm'},
[0x16B32]={d='nsm'},
[0x16B33]={d='nsm'},
[0x16B34]={d='nsm'},
[0x16B35]={d='nsm'},
[0x16B36]={d='nsm'},
[0x16F8F]={d='nsm'},
[0x16F90]={d='nsm'},
[0x16F91]={d='nsm'},
[0x16F92]={d='nsm'},
[0x1BC9D]={d='nsm'},
[0x1BC9E]={d='nsm'},
[0x1BCA0]={d='bn'},
[0x1BCA1]={d='bn'},
[0x1BCA2]={d='bn'},
[0x1BCA3]={d='bn'},
[0x1D167]={d='nsm'},
[0x1D168]={d='nsm'},
[0x1D169]={d='nsm'},
[0x1D173]={d='bn'},
[0x1D174]={d='bn'},
[0x1D175]={d='bn'},
[0x1D176]={d='bn'},
[0x1D177]={d='bn'},
[0x1D178]={d='bn'},
[0x1D179]={d='bn'},
[0x1D17A]={d='bn'},
[0x1D17B]={d='nsm'},
[0x1D17C]={d='nsm'},
[0x1D17D]={d='nsm'},
[0x1D17E]={d='nsm'},
[0x1D17F]={d='nsm'},
[0x1D180]={d='nsm'},
[0x1D181]={d='nsm'},
[0x1D182]={d='nsm'},
[0x1D185]={d='nsm'},
[0x1D186]={d='nsm'},
[0x1D187]={d='nsm'},
[0x1D188]={d='nsm'},
[0x1D189]={d='nsm'},
[0x1D18A]={d='nsm'},
[0x1D18B]={d='nsm'},
[0x1D1AA]={d='nsm'},
[0x1D1AB]={d='nsm'},
[0x1D1AC]={d='nsm'},
[0x1D1AD]={d='nsm'},
[0x1D200]={d='on'},
[0x1D201]={d='on'},
[0x1D202]={d='on'},
[0x1D203]={d='on'},
[0x1D204]={d='on'},
[0x1D205]={d='on'},
[0x1D206]={d='on'},
[0x1D207]={d='on'},
[0x1D208]={d='on'},
[0x1D209]={d='on'},
[0x1D20A]={d='on'},
[0x1D20B]={d='on'},
[0x1D20C]={d='on'},
[0x1D20D]={d='on'},
[0x1D20E]={d='on'},
[0x1D20F]={d='on'},
[0x1D210]={d='on'},
[0x1D211]={d='on'},
[0x1D212]={d='on'},
[0x1D213]={d='on'},
[0x1D214]={d='on'},
[0x1D215]={d='on'},
[0x1D216]={d='on'},
[0x1D217]={d='on'},
[0x1D218]={d='on'},
[0x1D219]={d='on'},
[0x1D21A]={d='on'},
[0x1D21B]={d='on'},
[0x1D21C]={d='on'},
[0x1D21D]={d='on'},
[0x1D21E]={d='on'},
[0x1D21F]={d='on'},
[0x1D220]={d='on'},
[0x1D221]={d='on'},
[0x1D222]={d='on'},
[0x1D223]={d='on'},
[0x1D224]={d='on'},
[0x1D225]={d='on'},
[0x1D226]={d='on'},
[0x1D227]={d='on'},
[0x1D228]={d='on'},
[0x1D229]={d='on'},
[0x1D22A]={d='on'},
[0x1D22B]={d='on'},
[0x1D22C]={d='on'},
[0x1D22D]={d='on'},
[0x1D22E]={d='on'},
[0x1D22F]={d='on'},
[0x1D230]={d='on'},
[0x1D231]={d='on'},
[0x1D232]={d='on'},
[0x1D233]={d='on'},
[0x1D234]={d='on'},
[0x1D235]={d='on'},
[0x1D236]={d='on'},
[0x1D237]={d='on'},
[0x1D238]={d='on'},
[0x1D239]={d='on'},
[0x1D23A]={d='on'},
[0x1D23B]={d='on'},
[0x1D23C]={d='on'},
[0x1D23D]={d='on'},
[0x1D23E]={d='on'},
[0x1D23F]={d='on'},
[0x1D240]={d='on'},
[0x1D241]={d='on'},
[0x1D242]={d='nsm'},
[0x1D243]={d='nsm'},
[0x1D244]={d='nsm'},
[0x1D245]={d='on'},
[0x1D300]={d='on'},
[0x1D301]={d='on'},
[0x1D302]={d='on'},
[0x1D303]={d='on'},
[0x1D304]={d='on'},
[0x1D305]={d='on'},
[0x1D306]={d='on'},
[0x1D307]={d='on'},
[0x1D308]={d='on'},
[0x1D309]={d='on'},
[0x1D30A]={d='on'},
[0x1D30B]={d='on'},
[0x1D30C]={d='on'},
[0x1D30D]={d='on'},
[0x1D30E]={d='on'},
[0x1D30F]={d='on'},
[0x1D310]={d='on'},
[0x1D311]={d='on'},
[0x1D312]={d='on'},
[0x1D313]={d='on'},
[0x1D314]={d='on'},
[0x1D315]={d='on'},
[0x1D316]={d='on'},
[0x1D317]={d='on'},
[0x1D318]={d='on'},
[0x1D319]={d='on'},
[0x1D31A]={d='on'},
[0x1D31B]={d='on'},
[0x1D31C]={d='on'},
[0x1D31D]={d='on'},
[0x1D31E]={d='on'},
[0x1D31F]={d='on'},
[0x1D320]={d='on'},
[0x1D321]={d='on'},
[0x1D322]={d='on'},
[0x1D323]={d='on'},
[0x1D324]={d='on'},
[0x1D325]={d='on'},
[0x1D326]={d='on'},
[0x1D327]={d='on'},
[0x1D328]={d='on'},
[0x1D329]={d='on'},
[0x1D32A]={d='on'},
[0x1D32B]={d='on'},
[0x1D32C]={d='on'},
[0x1D32D]={d='on'},
[0x1D32E]={d='on'},
[0x1D32F]={d='on'},
[0x1D330]={d='on'},
[0x1D331]={d='on'},
[0x1D332]={d='on'},
[0x1D333]={d='on'},
[0x1D334]={d='on'},
[0x1D335]={d='on'},
[0x1D336]={d='on'},
[0x1D337]={d='on'},
[0x1D338]={d='on'},
[0x1D339]={d='on'},
[0x1D33A]={d='on'},
[0x1D33B]={d='on'},
[0x1D33C]={d='on'},
[0x1D33D]={d='on'},
[0x1D33E]={d='on'},
[0x1D33F]={d='on'},
[0x1D340]={d='on'},
[0x1D341]={d='on'},
[0x1D342]={d='on'},
[0x1D343]={d='on'},
[0x1D344]={d='on'},
[0x1D345]={d='on'},
[0x1D346]={d='on'},
[0x1D347]={d='on'},
[0x1D348]={d='on'},
[0x1D349]={d='on'},
[0x1D34A]={d='on'},
[0x1D34B]={d='on'},
[0x1D34C]={d='on'},
[0x1D34D]={d='on'},
[0x1D34E]={d='on'},
[0x1D34F]={d='on'},
[0x1D350]={d='on'},
[0x1D351]={d='on'},
[0x1D352]={d='on'},
[0x1D353]={d='on'},
[0x1D354]={d='on'},
[0x1D355]={d='on'},
[0x1D356]={d='on'},
[0x1D6DB]={d='on'},
[0x1D715]={d='on'},
[0x1D74F]={d='on'},
[0x1D789]={d='on'},
[0x1D7C3]={d='on'},
[0x1D7CE]={d='en'},
[0x1D7CF]={d='en'},
[0x1D7D0]={d='en'},
[0x1D7D1]={d='en'},
[0x1D7D2]={d='en'},
[0x1D7D3]={d='en'},
[0x1D7D4]={d='en'},
[0x1D7D5]={d='en'},
[0x1D7D6]={d='en'},
[0x1D7D7]={d='en'},
[0x1D7D8]={d='en'},
[0x1D7D9]={d='en'},
[0x1D7DA]={d='en'},
[0x1D7DB]={d='en'},
[0x1D7DC]={d='en'},
[0x1D7DD]={d='en'},
[0x1D7DE]={d='en'},
[0x1D7DF]={d='en'},
[0x1D7E0]={d='en'},
[0x1D7E1]={d='en'},
[0x1D7E2]={d='en'},
[0x1D7E3]={d='en'},
[0x1D7E4]={d='en'},
[0x1D7E5]={d='en'},
[0x1D7E6]={d='en'},
[0x1D7E7]={d='en'},
[0x1D7E8]={d='en'},
[0x1D7E9]={d='en'},
[0x1D7EA]={d='en'},
[0x1D7EB]={d='en'},
[0x1D7EC]={d='en'},
[0x1D7ED]={d='en'},
[0x1D7EE]={d='en'},
[0x1D7EF]={d='en'},
[0x1D7F0]={d='en'},
[0x1D7F1]={d='en'},
[0x1D7F2]={d='en'},
[0x1D7F3]={d='en'},
[0x1D7F4]={d='en'},
[0x1D7F5]={d='en'},
[0x1D7F6]={d='en'},
[0x1D7F7]={d='en'},
[0x1D7F8]={d='en'},
[0x1D7F9]={d='en'},
[0x1D7FA]={d='en'},
[0x1D7FB]={d='en'},
[0x1D7FC]={d='en'},
[0x1D7FD]={d='en'},
[0x1D7FE]={d='en'},
[0x1D7FF]={d='en'},
[0x1DA00]={d='nsm'},
[0x1DA01]={d='nsm'},
[0x1DA02]={d='nsm'},
[0x1DA03]={d='nsm'},
[0x1DA04]={d='nsm'},
[0x1DA05]={d='nsm'},
[0x1DA06]={d='nsm'},
[0x1DA07]={d='nsm'},
[0x1DA08]={d='nsm'},
[0x1DA09]={d='nsm'},
[0x1DA0A]={d='nsm'},
[0x1DA0B]={d='nsm'},
[0x1DA0C]={d='nsm'},
[0x1DA0D]={d='nsm'},
[0x1DA0E]={d='nsm'},
[0x1DA0F]={d='nsm'},
[0x1DA10]={d='nsm'},
[0x1DA11]={d='nsm'},
[0x1DA12]={d='nsm'},
[0x1DA13]={d='nsm'},
[0x1DA14]={d='nsm'},
[0x1DA15]={d='nsm'},
[0x1DA16]={d='nsm'},
[0x1DA17]={d='nsm'},
[0x1DA18]={d='nsm'},
[0x1DA19]={d='nsm'},
[0x1DA1A]={d='nsm'},
[0x1DA1B]={d='nsm'},
[0x1DA1C]={d='nsm'},
[0x1DA1D]={d='nsm'},
[0x1DA1E]={d='nsm'},
[0x1DA1F]={d='nsm'},
[0x1DA20]={d='nsm'},
[0x1DA21]={d='nsm'},
[0x1DA22]={d='nsm'},
[0x1DA23]={d='nsm'},
[0x1DA24]={d='nsm'},
[0x1DA25]={d='nsm'},
[0x1DA26]={d='nsm'},
[0x1DA27]={d='nsm'},
[0x1DA28]={d='nsm'},
[0x1DA29]={d='nsm'},
[0x1DA2A]={d='nsm'},
[0x1DA2B]={d='nsm'},
[0x1DA2C]={d='nsm'},
[0x1DA2D]={d='nsm'},
[0x1DA2E]={d='nsm'},
[0x1DA2F]={d='nsm'},
[0x1DA30]={d='nsm'},
[0x1DA31]={d='nsm'},
[0x1DA32]={d='nsm'},
[0x1DA33]={d='nsm'},
[0x1DA34]={d='nsm'},
[0x1DA35]={d='nsm'},
[0x1DA36]={d='nsm'},
[0x1DA3B]={d='nsm'},
[0x1DA3C]={d='nsm'},
[0x1DA3D]={d='nsm'},
[0x1DA3E]={d='nsm'},
[0x1DA3F]={d='nsm'},
[0x1DA40]={d='nsm'},
[0x1DA41]={d='nsm'},
[0x1DA42]={d='nsm'},
[0x1DA43]={d='nsm'},
[0x1DA44]={d='nsm'},
[0x1DA45]={d='nsm'},
[0x1DA46]={d='nsm'},
[0x1DA47]={d='nsm'},
[0x1DA48]={d='nsm'},
[0x1DA49]={d='nsm'},
[0x1DA4A]={d='nsm'},
[0x1DA4B]={d='nsm'},
[0x1DA4C]={d='nsm'},
[0x1DA4D]={d='nsm'},
[0x1DA4E]={d='nsm'},
[0x1DA4F]={d='nsm'},
[0x1DA50]={d='nsm'},
[0x1DA51]={d='nsm'},
[0x1DA52]={d='nsm'},
[0x1DA53]={d='nsm'},
[0x1DA54]={d='nsm'},
[0x1DA55]={d='nsm'},
[0x1DA56]={d='nsm'},
[0x1DA57]={d='nsm'},
[0x1DA58]={d='nsm'},
[0x1DA59]={d='nsm'},
[0x1DA5A]={d='nsm'},
[0x1DA5B]={d='nsm'},
[0x1DA5C]={d='nsm'},
[0x1DA5D]={d='nsm'},
[0x1DA5E]={d='nsm'},
[0x1DA5F]={d='nsm'},
[0x1DA60]={d='nsm'},
[0x1DA61]={d='nsm'},
[0x1DA62]={d='nsm'},
[0x1DA63]={d='nsm'},
[0x1DA64]={d='nsm'},
[0x1DA65]={d='nsm'},
[0x1DA66]={d='nsm'},
[0x1DA67]={d='nsm'},
[0x1DA68]={d='nsm'},
[0x1DA69]={d='nsm'},
[0x1DA6A]={d='nsm'},
[0x1DA6B]={d='nsm'},
[0x1DA6C]={d='nsm'},
[0x1DA75]={d='nsm'},
[0x1DA84]={d='nsm'},
[0x1DA9B]={d='nsm'},
[0x1DA9C]={d='nsm'},
[0x1DA9D]={d='nsm'},
[0x1DA9E]={d='nsm'},
[0x1DA9F]={d='nsm'},
[0x1DAA1]={d='nsm'},
[0x1DAA2]={d='nsm'},
[0x1DAA3]={d='nsm'},
[0x1DAA4]={d='nsm'},
[0x1DAA5]={d='nsm'},
[0x1DAA6]={d='nsm'},
[0x1DAA7]={d='nsm'},
[0x1DAA8]={d='nsm'},
[0x1DAA9]={d='nsm'},
[0x1DAAA]={d='nsm'},
[0x1DAAB]={d='nsm'},
[0x1DAAC]={d='nsm'},
[0x1DAAD]={d='nsm'},
[0x1DAAE]={d='nsm'},
[0x1DAAF]={d='nsm'},
[0x1E000]={d='nsm'},
[0x1E001]={d='nsm'},
[0x1E002]={d='nsm'},
[0x1E003]={d='nsm'},
[0x1E004]={d='nsm'},
[0x1E005]={d='nsm'},
[0x1E006]={d='nsm'},
[0x1E008]={d='nsm'},
[0x1E009]={d='nsm'},
[0x1E00A]={d='nsm'},
[0x1E00B]={d='nsm'},
[0x1E00C]={d='nsm'},
[0x1E00D]={d='nsm'},
[0x1E00E]={d='nsm'},
[0x1E00F]={d='nsm'},
[0x1E010]={d='nsm'},
[0x1E011]={d='nsm'},
[0x1E012]={d='nsm'},
[0x1E013]={d='nsm'},
[0x1E014]={d='nsm'},
[0x1E015]={d='nsm'},
[0x1E016]={d='nsm'},
[0x1E017]={d='nsm'},
[0x1E018]={d='nsm'},
[0x1E01B]={d='nsm'},
[0x1E01C]={d='nsm'},
[0x1E01D]={d='nsm'},
[0x1E01E]={d='nsm'},
[0x1E01F]={d='nsm'},
[0x1E020]={d='nsm'},
[0x1E021]={d='nsm'},
[0x1E023]={d='nsm'},
[0x1E024]={d='nsm'},
[0x1E026]={d='nsm'},
[0x1E027]={d='nsm'},
[0x1E028]={d='nsm'},
[0x1E029]={d='nsm'},
[0x1E02A]={d='nsm'},
[0x1E8D0]={d='nsm'},
[0x1E8D1]={d='nsm'},
[0x1E8D2]={d='nsm'},
[0x1E8D3]={d='nsm'},
[0x1E8D4]={d='nsm'},
[0x1E8D5]={d='nsm'},
[0x1E8D6]={d='nsm'},
[0x1E944]={d='nsm'},
[0x1E945]={d='nsm'},
[0x1E946]={d='nsm'},
[0x1E947]={d='nsm'},
[0x1E948]={d='nsm'},
[0x1E949]={d='nsm'},
[0x1E94A]={d='nsm'},
[0x1EEF0]={d='on'},
[0x1EEF1]={d='on'},
[0x1F000]={d='on'},
[0x1F001]={d='on'},
[0x1F002]={d='on'},
[0x1F003]={d='on'},
[0x1F004]={d='on'},
[0x1F005]={d='on'},
[0x1F006]={d='on'},
[0x1F007]={d='on'},
[0x1F008]={d='on'},
[0x1F009]={d='on'},
[0x1F00A]={d='on'},
[0x1F00B]={d='on'},
[0x1F00C]={d='on'},
[0x1F00D]={d='on'},
[0x1F00E]={d='on'},
[0x1F00F]={d='on'},
[0x1F010]={d='on'},
[0x1F011]={d='on'},
[0x1F012]={d='on'},
[0x1F013]={d='on'},
[0x1F014]={d='on'},
[0x1F015]={d='on'},
[0x1F016]={d='on'},
[0x1F017]={d='on'},
[0x1F018]={d='on'},
[0x1F019]={d='on'},
[0x1F01A]={d='on'},
[0x1F01B]={d='on'},
[0x1F01C]={d='on'},
[0x1F01D]={d='on'},
[0x1F01E]={d='on'},
[0x1F01F]={d='on'},
[0x1F020]={d='on'},
[0x1F021]={d='on'},
[0x1F022]={d='on'},
[0x1F023]={d='on'},
[0x1F024]={d='on'},
[0x1F025]={d='on'},
[0x1F026]={d='on'},
[0x1F027]={d='on'},
[0x1F028]={d='on'},
[0x1F029]={d='on'},
[0x1F02A]={d='on'},
[0x1F02B]={d='on'},
[0x1F030]={d='on'},
[0x1F031]={d='on'},
[0x1F032]={d='on'},
[0x1F033]={d='on'},
[0x1F034]={d='on'},
[0x1F035]={d='on'},
[0x1F036]={d='on'},
[0x1F037]={d='on'},
[0x1F038]={d='on'},
[0x1F039]={d='on'},
[0x1F03A]={d='on'},
[0x1F03B]={d='on'},
[0x1F03C]={d='on'},
[0x1F03D]={d='on'},
[0x1F03E]={d='on'},
[0x1F03F]={d='on'},
[0x1F040]={d='on'},
[0x1F041]={d='on'},
[0x1F042]={d='on'},
[0x1F043]={d='on'},
[0x1F044]={d='on'},
[0x1F045]={d='on'},
[0x1F046]={d='on'},
[0x1F047]={d='on'},
[0x1F048]={d='on'},
[0x1F049]={d='on'},
[0x1F04A]={d='on'},
[0x1F04B]={d='on'},
[0x1F04C]={d='on'},
[0x1F04D]={d='on'},
[0x1F04E]={d='on'},
[0x1F04F]={d='on'},
[0x1F050]={d='on'},
[0x1F051]={d='on'},
[0x1F052]={d='on'},
[0x1F053]={d='on'},
[0x1F054]={d='on'},
[0x1F055]={d='on'},
[0x1F056]={d='on'},
[0x1F057]={d='on'},
[0x1F058]={d='on'},
[0x1F059]={d='on'},
[0x1F05A]={d='on'},
[0x1F05B]={d='on'},
[0x1F05C]={d='on'},
[0x1F05D]={d='on'},
[0x1F05E]={d='on'},
[0x1F05F]={d='on'},
[0x1F060]={d='on'},
[0x1F061]={d='on'},
[0x1F062]={d='on'},
[0x1F063]={d='on'},
[0x1F064]={d='on'},
[0x1F065]={d='on'},
[0x1F066]={d='on'},
[0x1F067]={d='on'},
[0x1F068]={d='on'},
[0x1F069]={d='on'},
[0x1F06A]={d='on'},
[0x1F06B]={d='on'},
[0x1F06C]={d='on'},
[0x1F06D]={d='on'},
[0x1F06E]={d='on'},
[0x1F06F]={d='on'},
[0x1F070]={d='on'},
[0x1F071]={d='on'},
[0x1F072]={d='on'},
[0x1F073]={d='on'},
[0x1F074]={d='on'},
[0x1F075]={d='on'},
[0x1F076]={d='on'},
[0x1F077]={d='on'},
[0x1F078]={d='on'},
[0x1F079]={d='on'},
[0x1F07A]={d='on'},
[0x1F07B]={d='on'},
[0x1F07C]={d='on'},
[0x1F07D]={d='on'},
[0x1F07E]={d='on'},
[0x1F07F]={d='on'},
[0x1F080]={d='on'},
[0x1F081]={d='on'},
[0x1F082]={d='on'},
[0x1F083]={d='on'},
[0x1F084]={d='on'},
[0x1F085]={d='on'},
[0x1F086]={d='on'},
[0x1F087]={d='on'},
[0x1F088]={d='on'},
[0x1F089]={d='on'},
[0x1F08A]={d='on'},
[0x1F08B]={d='on'},
[0x1F08C]={d='on'},
[0x1F08D]={d='on'},
[0x1F08E]={d='on'},
[0x1F08F]={d='on'},
[0x1F090]={d='on'},
[0x1F091]={d='on'},
[0x1F092]={d='on'},
[0x1F093]={d='on'},
[0x1F0A0]={d='on'},
[0x1F0A1]={d='on'},
[0x1F0A2]={d='on'},
[0x1F0A3]={d='on'},
[0x1F0A4]={d='on'},
[0x1F0A5]={d='on'},
[0x1F0A6]={d='on'},
[0x1F0A7]={d='on'},
[0x1F0A8]={d='on'},
[0x1F0A9]={d='on'},
[0x1F0AA]={d='on'},
[0x1F0AB]={d='on'},
[0x1F0AC]={d='on'},
[0x1F0AD]={d='on'},
[0x1F0AE]={d='on'},
[0x1F0B1]={d='on'},
[0x1F0B2]={d='on'},
[0x1F0B3]={d='on'},
[0x1F0B4]={d='on'},
[0x1F0B5]={d='on'},
[0x1F0B6]={d='on'},
[0x1F0B7]={d='on'},
[0x1F0B8]={d='on'},
[0x1F0B9]={d='on'},
[0x1F0BA]={d='on'},
[0x1F0BB]={d='on'},
[0x1F0BC]={d='on'},
[0x1F0BD]={d='on'},
[0x1F0BE]={d='on'},
[0x1F0BF]={d='on'},
[0x1F0C1]={d='on'},
[0x1F0C2]={d='on'},
[0x1F0C3]={d='on'},
[0x1F0C4]={d='on'},
[0x1F0C5]={d='on'},
[0x1F0C6]={d='on'},
[0x1F0C7]={d='on'},
[0x1F0C8]={d='on'},
[0x1F0C9]={d='on'},
[0x1F0CA]={d='on'},
[0x1F0CB]={d='on'},
[0x1F0CC]={d='on'},
[0x1F0CD]={d='on'},
[0x1F0CE]={d='on'},
[0x1F0CF]={d='on'},
[0x1F0D1]={d='on'},
[0x1F0D2]={d='on'},
[0x1F0D3]={d='on'},
[0x1F0D4]={d='on'},
[0x1F0D5]={d='on'},
[0x1F0D6]={d='on'},
[0x1F0D7]={d='on'},
[0x1F0D8]={d='on'},
[0x1F0D9]={d='on'},
[0x1F0DA]={d='on'},
[0x1F0DB]={d='on'},
[0x1F0DC]={d='on'},
[0x1F0DD]={d='on'},
[0x1F0DE]={d='on'},
[0x1F0DF]={d='on'},
[0x1F0E0]={d='on'},
[0x1F0E1]={d='on'},
[0x1F0E2]={d='on'},
[0x1F0E3]={d='on'},
[0x1F0E4]={d='on'},
[0x1F0E5]={d='on'},
[0x1F0E6]={d='on'},
[0x1F0E7]={d='on'},
[0x1F0E8]={d='on'},
[0x1F0E9]={d='on'},
[0x1F0EA]={d='on'},
[0x1F0EB]={d='on'},
[0x1F0EC]={d='on'},
[0x1F0ED]={d='on'},
[0x1F0EE]={d='on'},
[0x1F0EF]={d='on'},
[0x1F0F0]={d='on'},
[0x1F0F1]={d='on'},
[0x1F0F2]={d='on'},
[0x1F0F3]={d='on'},
[0x1F0F4]={d='on'},
[0x1F0F5]={d='on'},
[0x1F100]={d='en'},
[0x1F101]={d='en'},
[0x1F102]={d='en'},
[0x1F103]={d='en'},
[0x1F104]={d='en'},
[0x1F105]={d='en'},
[0x1F106]={d='en'},
[0x1F107]={d='en'},
[0x1F108]={d='en'},
[0x1F109]={d='en'},
[0x1F10A]={d='en'},
[0x1F10B]={d='on'},
[0x1F10C]={d='on'},
[0x1F16A]={d='on'},
[0x1F16B]={d='on'},
[0xE0001]={d='bn'},
[0xE0020]={d='bn'},
[0xE0021]={d='bn'},
[0xE0022]={d='bn'},
[0xE0023]={d='bn'},
[0xE0024]={d='bn'},
[0xE0025]={d='bn'},
[0xE0026]={d='bn'},
[0xE0027]={d='bn'},
[0xE0028]={d='bn'},
[0xE0029]={d='bn'},
[0xE002A]={d='bn'},
[0xE002B]={d='bn'},
[0xE002C]={d='bn'},
[0xE002D]={d='bn'},
[0xE002E]={d='bn'},
[0xE002F]={d='bn'},
[0xE0030]={d='bn'},
[0xE0031]={d='bn'},
[0xE0032]={d='bn'},
[0xE0033]={d='bn'},
[0xE0034]={d='bn'},
[0xE0035]={d='bn'},
[0xE0036]={d='bn'},
[0xE0037]={d='bn'},
[0xE0038]={d='bn'},
[0xE0039]={d='bn'},
[0xE003A]={d='bn'},
[0xE003B]={d='bn'},
[0xE003C]={d='bn'},
[0xE003D]={d='bn'},
[0xE003E]={d='bn'},
[0xE003F]={d='bn'},
[0xE0040]={d='bn'},
[0xE0041]={d='bn'},
[0xE0042]={d='bn'},
[0xE0043]={d='bn'},
[0xE0044]={d='bn'},
[0xE0045]={d='bn'},
[0xE0046]={d='bn'},
[0xE0047]={d='bn'},
[0xE0048]={d='bn'},
[0xE0049]={d='bn'},
[0xE004A]={d='bn'},
[0xE004B]={d='bn'},
[0xE004C]={d='bn'},
[0xE004D]={d='bn'},
[0xE004E]={d='bn'},
[0xE004F]={d='bn'},
[0xE0050]={d='bn'},
[0xE0051]={d='bn'},
[0xE0052]={d='bn'},
[0xE0053]={d='bn'},
[0xE0054]={d='bn'},
[0xE0055]={d='bn'},
[0xE0056]={d='bn'},
[0xE0057]={d='bn'},
[0xE0058]={d='bn'},
[0xE0059]={d='bn'},
[0xE005A]={d='bn'},
[0xE005B]={d='bn'},
[0xE005C]={d='bn'},
[0xE005D]={d='bn'},
[0xE005E]={d='bn'},
[0xE005F]={d='bn'},
[0xE0060]={d='bn'},
[0xE0061]={d='bn'},
[0xE0062]={d='bn'},
[0xE0063]={d='bn'},
[0xE0064]={d='bn'},
[0xE0065]={d='bn'},
[0xE0066]={d='bn'},
[0xE0067]={d='bn'},
[0xE0068]={d='bn'},
[0xE0069]={d='bn'},
[0xE006A]={d='bn'},
[0xE006B]={d='bn'},
[0xE006C]={d='bn'},
[0xE006D]={d='bn'},
[0xE006E]={d='bn'},
[0xE006F]={d='bn'},
[0xE0070]={d='bn'},
[0xE0071]={d='bn'},
[0xE0072]={d='bn'},
[0xE0073]={d='bn'},
[0xE0074]={d='bn'},
[0xE0075]={d='bn'},
[0xE0076]={d='bn'},
[0xE0077]={d='bn'},
[0xE0078]={d='bn'},
[0xE0079]={d='bn'},
[0xE007A]={d='bn'},
[0xE007B]={d='bn'},
[0xE007C]={d='bn'},
[0xE007D]={d='bn'},
[0xE007E]={d='bn'},
[0xE007F]={d='bn'}
}
%</bididata>
% \end{macrocode}
%\fi
%
% Now the |basic-r| bidi mode. One of the aims is to implement a fast
% and simple bidi algorithm, with a single loop. I managed to do it
% for R texts, with a second smaller loop for a special case. The code
% is still somewhat chaotic, but its behavior is essentially
% correct. I cannot resist copying the following text from
% \textsf{Emacs} |bidi.c| (which also attempts to implement the bidi
% algorithm with a single loop):
%
% \begin{quote}
% Arrrgh!! The UAX\#9 algorithm is too deeply entrenched in the
% assumption of batch-style processing [...]. May the fleas of a
% thousand camels infest the armpits of those who design supposedly
% general-purpose algorithms by looking at their own
% implementations, and fail to consider other possible
% implementations!
% \end{quote}
%
% Well, it took me some time to guess what the batch rules in UAX\#9
% actually mean (in other word, \textit{what} they do and \textit{why},
% and not only \textit{how}), but I think (or I hope) I've managed to
% understand them.
%
% In some sense, there are two bidi modes, one for numbers, and the
% other for text. Furthermore, setting just the direction in R text
% is not enough, because there are actually \textit{two} R modes (set
% explicitly in Unicode with RLM and ALM). In \babel{} the dir is set
% by a higher protocol based on the language/script, which in turn
% sets the correct dir (<l>, <r> or <al>).
%
% From UAX\#9: “Where available, markup should be used instead of the
% explicit formatting characters”. So, this simple version just
% ignores formatting characters. Actually, most of that annex is
% devoted to how to handle them.
%
% BD14-BD16 are not implemented. Unicode (and the W3C) are making a
% great effort to deal with some special problematic cases in
% “streamed” plain text. I don't think this is the way to go --
% particular issues should be fixed by a high level interface taking
% into account the needs of the document. And here is where \luatex{}
% excels, because everything related to bidi writing is under our
% control.
%
% \begin{macrocode}
%<*basic-r>
Babel.bidi_enabled = true
require('babel-data-bidi.lua')
local characters = Babel.characters
local ranges = Babel.ranges
local DIR = node.id("dir")
local function dir_mark(head, from, to, outer)
dir = (outer == 'r') and 'TLT' or 'TRT' -- i.e., reverse
local d = node.new(DIR)
d.dir = '+' .. dir
node.insert_before(head, from, d)
d = node.new(DIR)
d.dir = '-' .. dir
node.insert_after(head, to, d)
end
function Babel.bidi(head, ispar)
local first_n, last_n -- first and last char with nums
local last_es -- an auxiliary 'last' used with nums
local first_d, last_d -- first and last char in L/R block
local dir, dir_real
% \end{macrocode}
%
% Next also depends on script/lang (<al>/<r>). To be set by
% babel. |tex.pardir| is dangerous, could be (re)set but it
% should be changed only in vmode. There are two strong's --
% |strong| = l/al/r and |strong_lr| = l/r (there must be a better
% way):
%
% \begin{macrocode}
local strong = ('TRT' == tex.pardir) and 'r' or 'l'
local strong_lr = (strong == 'l') and 'l' or 'r'
local outer = strong
local new_dir = false
local first_dir = false
local inmath = false
local last_lr
local type_n = ''
for item in node.traverse(head) do
-- three cases: glyph, dir, otherwise
if item.id == node.id'glyph'
or (item.id == 7 and item.subtype == 2) then
local itemchar
if item.id == 7 and item.subtype == 2 then
itemchar = item.replace.char
else
itemchar = item.char
end
local chardata = characters[itemchar]
dir = chardata and chardata.d or nil
if not dir then
for nn, et in ipairs(ranges) do
if itemchar < et[1] then
break
elseif itemchar <= et[2] then
dir = et[3]
break
end
end
end
dir = dir or 'l'
if inmath then dir = ('TRT' == tex.mathdir) and 'r' or 'l' end
% \end{macrocode}
%
% Next is based on the assumption \babel{} sets the language
% \textit{and} switches the script with its dir. We treat a language
% block as a separate Unicode sequence. The following piece of code is
% executed at the first glyph after a `dir' node. We don't know the
% current language until then. This is not exactly true, as the math
% mode may insert explicit dirs in the node list, so, for the moment
% there is a hack by brute force (just above).
%
% \begin{macrocode}
if new_dir then
attr_dir = 0
for at in node.traverse(item.attr) do
if at.number == Babel.attr_dir then
attr_dir = at.value & 0x3
end
end
if attr_dir == 1 then
strong = 'r'
elseif attr_dir == 2 then
strong = 'al'
else
strong = 'l'
end
strong_lr = (strong == 'l') and 'l' or 'r'
outer = strong_lr
new_dir = false
end
if dir == 'nsm' then dir = strong end -- W1
% \end{macrocode}
%
% \textbf{Numbers.} The dual <al>/<r> system for R is somewhat
% cumbersome.
%
% \begin{macrocode}
dir_real = dir -- We need dir_real to set strong below
if dir == 'al' then dir = 'r' end -- W3
% \end{macrocode}
%
% By W2, there are no <en> <et> <es> if |strong == <al>|, only
% <an>. Therefore, there are not <et en> nor <en et>, W5 can be
% ignored, and W6 applied:
%
% \begin{macrocode}
if strong == 'al' then
if dir == 'en' then dir = 'an' end -- W2
if dir == 'et' or dir == 'es' then dir = 'on' end -- W6
strong_lr = 'r' -- W3
end
% \end{macrocode}
%
% Once finished the basic setup for glyphs, consider the two other
% cases: dir node and the rest.
%
% \begin{macrocode}
elseif item.id == node.id'dir' and not inmath then
new_dir = true
dir = nil
elseif item.id == node.id'math' then
inmath = (item.subtype == 0)
else
dir = nil -- Not a char
end
% \end{macrocode}
%
% Numbers in R mode. A sequence of <en>, <et>, <an>, <es> and <cs> is
% typeset (with some rules) in L mode. We store the starting and
% ending points, and only when anything different is found (including
% nil, i.e., a non-char), the textdir is set. This means you cannot
% insert, say, a whatsit, but this is what I would expect (with
% \textsf{luacolor} you may colorize some digits). Anyway, this
% behavior could be changed with a switch in the future. Note in the
% first branch only <an> is relevant if <al>.
%
% \begin{macrocode}
if dir == 'en' or dir == 'an' or dir == 'et' then
if dir ~= 'et' then
type_n = dir
end
first_n = first_n or item
last_n = last_es or item
last_es = nil
elseif dir == 'es' and last_n then -- W3+W6
last_es = item
elseif dir == 'cs' then -- it's right - do nothing
elseif first_n then -- & if dir = any but en, et, an, es, cs, inc nil
if strong_lr == 'r' and type_n ~= '' then
dir_mark(head, first_n, last_n, 'r')
elseif strong_lr == 'l' and first_d and type_n == 'an' then
dir_mark(head, first_n, last_n, 'r')
dir_mark(head, first_d, last_d, outer)
first_d, last_d = nil, nil
elseif strong_lr == 'l' and type_n ~= '' then
last_d = last_n
end
type_n = ''
first_n, last_n = nil, nil
end
% \end{macrocode}
%
% R text in L, or L text in R. Order of |dir_ mark|'s are relevant: d
% goes outside n, and therefore it's emitted after. See |dir_mark| to
% understand why (but is the nesting actually necessary or is a flat
% dir structure enough?). Only L, R (and AL) chars are taken into
% account -- everything else, including spaces, whatsits, etc., are
% ignored:
%
% \begin{macrocode}
if dir == 'l' or dir == 'r' then
if dir ~= outer then
first_d = first_d or item
last_d = item
elseif first_d and dir ~= strong_lr then
dir_mark(head, first_d, last_d, outer)
first_d, last_d = nil, nil
end
end
% \end{macrocode}
%
% \textbf{Mirroring.} Each chunk of text in a certain language is
% considered a “closed” sequence. If <r on r> and <l on l>, it's
% clearly <r> and <l>, resptly, but with other combinations depends on
% outer. From all these, we select only those resolving <on> $\to$
% <r>. At the beginning (when |last_lr| is nil) of an R text, they are
% mirrored directly. Numbers in R mode are processed. It should not be
% done, but it doesn't hurt.
%
% \begin{macrocode}
if dir and not last_lr and dir ~= 'l' and outer == 'r' then
item.char = characters[item.char] and
characters[item.char].m or item.char
elseif (dir or new_dir) and last_lr ~= item then
local mir = outer .. strong_lr .. (dir or outer)
if mir == 'rrr' or mir == 'lrr' or mir == 'rrl' or mir == 'rlr' then
for ch in node.traverse(node.next(last_lr)) do
if ch == item then break end
if ch.id == node.id'glyph' and characters[ch.char] then
ch.char = characters[ch.char].m or ch.char
end
end
end
end
% \end{macrocode}
%
% Save some values for the next iteration. If the current node is
% `dir', open a new sequence. Since dir could be changed, strong is
% set with its real value (|dir_real|).
%
% \begin{macrocode}
if dir == 'l' or dir == 'r' then
last_lr = item
strong = dir_real -- Don't search back - best save now
strong_lr = (strong == 'l') and 'l' or 'r'
elseif new_dir then
last_lr = nil
end
end
% \end{macrocode}
%
% Mirror the last chars if they are no directed. And make sure any
% open block is closed, too.
%
% \begin{macrocode}
if last_lr and outer == 'r' then
for ch in node.traverse_id(node.id'glyph', node.next(last_lr)) do
if characters[ch.char] then
ch.char = characters[ch.char].m or ch.char
end
end
end
if first_n then
dir_mark(head, first_n, last_n, outer)
end
if first_d then
dir_mark(head, first_d, last_d, outer)
end
% \end{macrocode}
%
% In boxes, the dir node could be added before the original head, so
% the actual head is the previous node.
%
% \begin{macrocode}
return node.prev(head) or head
end
%</basic-r>
% \end{macrocode}
%
% And here the Lua code for |bidi=basic|:
%
% \begin{macrocode}
%<*basic>
-- e.g., Babel.fontmap[1][<prefontid>]=<dirfontid>
Babel.fontmap = Babel.fontmap or {}
Babel.fontmap[0] = {} -- l
Babel.fontmap[1] = {} -- r
Babel.fontmap[2] = {} -- al/an
-- To cancel mirroring. Also OML, OMS, U?
Babel.symbol_fonts = Babel.symbol_fonts or {}
Babel.symbol_fonts[font.id('tenln')] = true
Babel.symbol_fonts[font.id('tenlnw')] = true
Babel.symbol_fonts[font.id('tencirc')] = true
Babel.symbol_fonts[font.id('tencircw')] = true
Babel.bidi_enabled = true
Babel.mirroring_enabled = true
require('babel-data-bidi.lua')
local characters = Babel.characters
local ranges = Babel.ranges
local DIR = node.id('dir')
local GLYPH = node.id('glyph')
local function insert_implicit(head, state, outer)
local new_state = state
if state.sim and state.eim and state.sim ~= state.eim then
dir = ((outer == 'r') and 'TLT' or 'TRT') -- i.e., reverse
local d = node.new(DIR)
d.dir = '+' .. dir
node.insert_before(head, state.sim, d)
local d = node.new(DIR)
d.dir = '-' .. dir
node.insert_after(head, state.eim, d)
end
new_state.sim, new_state.eim = nil, nil
return head, new_state
end
local function insert_numeric(head, state)
local new
local new_state = state
if state.san and state.ean and state.san ~= state.ean then
local d = node.new(DIR)
d.dir = '+TLT'
_, new = node.insert_before(head, state.san, d)
if state.san == state.sim then state.sim = new end
local d = node.new(DIR)
d.dir = '-TLT'
_, new = node.insert_after(head, state.ean, d)
if state.ean == state.eim then state.eim = new end
end
new_state.san, new_state.ean = nil, nil
return head, new_state
end
local function glyph_not_symbol_font(node)
if node.id == GLYPH then
return not Babel.symbol_fonts[node.font]
else
return false
end
end
-- TODO - \hbox with an explicit dir can lead to wrong results
-- <R \hbox dir TLT{<R>}> and <L \hbox dir TRT{<L>}>. A small attempt
-- was made to improve the situation, but the problem is the 3-dir
-- model in babel/Unicode and the 2-dir model in LuaTeX don't fit
-- well.
function Babel.bidi(head, ispar, hdir)
local d -- d is used mainly for computations in a loop
local prev_d = ''
local new_d = false
local nodes = {}
local outer_first = nil
local inmath = false
local glue_d = nil
local glue_i = nil
local has_en = false
local first_et = nil
local has_hyperlink = false
local ATDIR = Babel.attr_dir
local attr_d, temp
local locale_d
local save_outer
local locale_d = node.get_attribute(head, ATDIR)
if locale_d then
locale_d = locale_d & 0x3
save_outer = (locale_d == 0 and 'l') or
(locale_d == 1 and 'r') or
(locale_d == 2 and 'al')
elseif ispar then -- Or error? Shouldn't happen
-- when the callback is called, we are just _after_ the box,
-- and the textdir is that of the surrounding text
save_outer = ('TRT' == tex.pardir) and 'r' or 'l'
else -- Empty box
save_outer = ('TRT' == hdir) and 'r' or 'l'
end
local outer = save_outer
local last = outer
-- 'al' is only taken into account in the first, current loop
if save_outer == 'al' then save_outer = 'r' end
local fontmap = Babel.fontmap
for item in node.traverse(head) do
-- Mask: DxxxPPTT (Done, Pardir [0-2], Textdir [0-2])
locale_d = node.get_attribute(item, ATDIR)
node.set_attribute(item, ATDIR, 0x80)
-- In what follows, #node is the last (previous) node, because the
-- current one is not added until we start processing the neutrals.
-- three cases: glyph, dir, otherwise
if glyph_not_symbol_font(item)
or (item.id == 7 and item.subtype == 2) then
if locale_d == 0x80 then goto nextnode end
local d_font = nil
local item_r
if item.id == 7 and item.subtype == 2 then
item_r = item.replace -- automatic discs have just 1 glyph
else
item_r = item
end
local chardata = characters[item_r.char]
d = chardata and chardata.d or nil
if not d or d == 'nsm' then
for nn, et in ipairs(ranges) do
if item_r.char < et[1] then
break
elseif item_r.char <= et[2] then
if not d then d = et[3]
elseif d == 'nsm' then d_font = et[3]
end
break
end
end
end
d = d or 'l'
-- A short 'pause' in bidi for mapfont
-- %%%% TODO. move if fontmap here
d_font = d_font or d
d_font = (d_font == 'l' and 0) or
(d_font == 'nsm' and 0) or
(d_font == 'r' and 1) or
(d_font == 'al' and 2) or
(d_font == 'an' and 2) or nil
if d_font and fontmap and fontmap[d_font][item_r.font] then
item_r.font = fontmap[d_font][item_r.font]
end
if new_d then
table.insert(nodes, {nil, (outer == 'l') and 'l' or 'r', nil})
if inmath then
attr_d = 0
else
attr_d = locale_d & 0x3
end
if attr_d == 1 then
outer_first = 'r'
last = 'r'
elseif attr_d == 2 then
outer_first = 'r'
last = 'al'
else
outer_first = 'l'
last = 'l'
end
outer = last
has_en = false
first_et = nil
new_d = false
end
if glue_d then
if (d == 'l' and 'l' or 'r') ~= glue_d then
table.insert(nodes, {glue_i, 'on', nil})
end
glue_d = nil
glue_i = nil
end
elseif item.id == DIR then
d = nil
new_d = true
elseif item.id == node.id'glue' and item.subtype == 13 then
glue_d = d
glue_i = item
d = nil
elseif item.id == node.id'math' then
inmath = (item.subtype == 0)
elseif item.id == 8 and item.subtype == 19 then
has_hyperlink = true
else
d = nil
end
-- AL <= EN/ET/ES -- W2 + W3 + W6
if last == 'al' and d == 'en' then
d = 'an' -- W3
elseif last == 'al' and (d == 'et' or d == 'es') then
d = 'on' -- W6
end
-- EN + CS/ES + EN -- W4
if d == 'en' and #nodes >= 2 then
if (nodes[#nodes][2] == 'es' or nodes[#nodes][2] == 'cs')
and nodes[#nodes-1][2] == 'en' then
nodes[#nodes][2] = 'en'
end
end
-- AN + CS + AN -- W4 too, because uax9 mixes both cases
if d == 'an' and #nodes >= 2 then
if (nodes[#nodes][2] == 'cs')
and nodes[#nodes-1][2] == 'an' then
nodes[#nodes][2] = 'an'
end
end
-- ET/EN -- W5 + W7->l / W6->on
if d == 'et' then
first_et = first_et or (#nodes + 1)
elseif d == 'en' then
has_en = true
first_et = first_et or (#nodes + 1)
elseif first_et then -- d may be nil here !
if has_en then
if last == 'l' then
temp = 'l' -- W7
else
temp = 'en' -- W5
end
else
temp = 'on' -- W6
end
for e = first_et, #nodes do
if glyph_not_symbol_font(nodes[e][1]) then nodes[e][2] = temp end
end
first_et = nil
has_en = false
end
-- Force mathdir in math if ON (currently works as expected only
-- with 'l')
if inmath and d == 'on' then
d = ('TRT' == tex.mathdir) and 'r' or 'l'
end
if d then
if d == 'al' then
d = 'r'
last = 'al'
elseif d == 'l' or d == 'r' then
last = d
end
prev_d = d
table.insert(nodes, {item, d, outer_first})
end
outer_first = nil
::nextnode::
end -- for each node
-- TODO -- repeated here in case EN/ET is the last node. Find a
-- better way of doing things:
if first_et then -- dir may be nil here !
if has_en then
if last == 'l' then
temp = 'l' -- W7
else
temp = 'en' -- W5
end
else
temp = 'on' -- W6
end
for e = first_et, #nodes do
if glyph_not_symbol_font(nodes[e][1]) then nodes[e][2] = temp end
end
end
-- dummy node, to close things
table.insert(nodes, {nil, (outer == 'l') and 'l' or 'r', nil})
--------------- NEUTRAL -----------------
outer = save_outer
last = outer
local first_on = nil
for q = 1, #nodes do
local item
local outer_first = nodes[q][3]
outer = outer_first or outer
last = outer_first or last
local d = nodes[q][2]
if d == 'an' or d == 'en' then d = 'r' end
if d == 'cs' or d == 'et' or d == 'es' then d = 'on' end --- W6
if d == 'on' then
first_on = first_on or q
elseif first_on then
if last == d then
temp = d
else
temp = outer
end
for r = first_on, q - 1 do
nodes[r][2] = temp
item = nodes[r][1] -- MIRRORING
if Babel.mirroring_enabled and glyph_not_symbol_font(item)
and temp == 'r' and characters[item.char] then
local font_mode = ''
if item.font > 0 and font.fonts[item.font].properties then
font_mode = font.fonts[item.font].properties.mode
end
if font_mode ~= 'harf' and font_mode ~= 'plug' then
item.char = characters[item.char].m or item.char
end
end
end
first_on = nil
end
if d == 'r' or d == 'l' then last = d end
end
-------------- IMPLICIT, REORDER ----------------
outer = save_outer
last = outer
local state = {}
state.has_r = false
for q = 1, #nodes do
local item = nodes[q][1]
outer = nodes[q][3] or outer
local d = nodes[q][2]
if d == 'nsm' then d = last end -- W1
if d == 'en' then d = 'an' end
local isdir = (d == 'r' or d == 'l')
if outer == 'l' and d == 'an' then
state.san = state.san or item
state.ean = item
elseif state.san then
head, state = insert_numeric(head, state)
end
if outer == 'l' then
if d == 'an' or d == 'r' then -- im -> implicit
if d == 'r' then state.has_r = true end
state.sim = state.sim or item
state.eim = item
elseif d == 'l' and state.sim and state.has_r then
head, state = insert_implicit(head, state, outer)
elseif d == 'l' then
state.sim, state.eim, state.has_r = nil, nil, false
end
else
if d == 'an' or d == 'l' then
if nodes[q][3] then -- nil except after an explicit dir
state.sim = item -- so we move sim 'inside' the group
else
state.sim = state.sim or item
end
state.eim = item
elseif d == 'r' and state.sim then
head, state = insert_implicit(head, state, outer)
elseif d == 'r' then
state.sim, state.eim = nil, nil
end
end
if isdir then
last = d -- Don't search back - best save now
elseif d == 'on' and state.san then
state.san = state.san or item
state.ean = item
end
end
head = node.prev(head) or head
% \end{macrocode}
%
% Now direction nodes has been distributed with relation to characters
% and spaces, we need to take into account \TeX\-specific elements in
% the node list, to move them at an appropriate place. Firstly, with
% hyperlinks. Secondly, we avoid them between penalties and spaces, so
% that the latter are still discardable.
%
% \begin{macrocode}
--- FIXES ---
if has_hyperlink then
local flag, linking = 0, 0
for item in node.traverse(head) do
if item.id == DIR then
if item.dir == '+TRT' or item.dir == '+TLT' then
flag = flag + 1
elseif item.dir == '-TRT' or item.dir == '-TLT' then
flag = flag - 1
end
elseif item.id == 8 and item.subtype == 19 then
linking = flag
elseif item.id == 8 and item.subtype == 20 then
if linking > 0 then
if item.prev.id == DIR and
(item.prev.dir == '-TRT' or item.prev.dir == '-TLT') then
d = node.new(DIR)
d.dir = item.prev.dir
node.remove(head, item.prev)
node.insert_after(head, item, d)
end
end
linking = 0
end
end
end
for item in node.traverse_id(10, head) do
local p = item
local flag = false
while p.prev and p.prev.id == 14 do
flag = true
p = p.prev
end
if flag then
node.insert_before(head, p, node.copy(item))
node.remove(head,item)
end
end
return head
end
% \end{macrocode}
%
% \begin{macrocode}
function Babel.unset_atdir(head)
local ATDIR = Babel.attr_dir
for item in node.traverse(head) do
node.set_attribute(item, ATDIR, 0x80)
end
return head
end
%</basic>
% \end{macrocode}
%
% \section{Data for CJK}
%
% It is a boring file and it is not shown here (see the generated file),
% but here is a sample:
%\begin{verbatim}
% [0x0021]={c='ex'},
% [0x0024]={c='pr'},
% [0x0025]={c='po'},
% [0x0028]={c='op'},
% [0x0029]={c='cp'},
% [0x002B]={c='pr'},
%\end{verbatim}
% For the meaning of these codes, see the Unicode standard.
%
%\iffalse
% \begin{macrocode}
%<*cjkdata>
Babel.cjk_characters = {
[0x0021]={c='ex'},
[0x0022]={c='qu'},
[0x0024]={c='pr'},
[0x0025]={c='po'},
[0x0027]={c='qu'},
[0x0028]={c='op'},
[0x0029]={c='cp'},
[0x002B]={c='pr'},
[0x002C]={c='is'},
[0x002D]={c='hy'},
[0x002E]={c='is'},
[0x002F]={c='sy'},
[0x003A]={c='is'},
[0x003B]={c='is'},
[0x003F]={c='ex'},
[0x005B]={c='op'},
[0x005C]={c='pr'},
[0x005D]={c='cp'},
[0x007B]={c='op'},
[0x007D]={c='cl'},
[0x00A1]={c='op'},
[0x00A2]={c='po'},
[0x00A3]={c='pr'},
[0x00A4]={c='pr'},
[0x00A5]={c='pr'},
[0x00AB]={c='qu'},
[0x00B0]={c='po'},
[0x00B1]={c='pr'},
[0x00BB]={c='qu'},
[0x2018]={c='qu'},
[0x2019]={c='qu'},
[0x201A]={c='op'},
[0x201B]={c='qu'},
[0x201C]={c='qu'},
[0x201D]={c='qu'},
[0x201E]={c='op'},
[0x201F]={c='qu'},
[0x2024]={c='in'},
[0x2025]={c='in'},
[0x2026]={c='in'},
[0x2030]={c='po'},
[0x2031]={c='po'},
[0x2032]={c='po'},
[0x2033]={c='po'},
[0x2034]={c='po'},
[0x2035]={c='po'},
[0x2036]={c='po'},
[0x2037]={c='po'},
[0x2039]={c='qu'},
[0x203A]={c='qu'},
[0x203C]={c='ns'},
[0x203D]={c='ns'},
[0x2044]={c='is'},
[0x2045]={c='op'},
[0x2046]={c='cl'},
[0x2047]={c='ns'},
[0x2048]={c='ns'},
[0x2049]={c='ns'},
[0x207D]={c='op'},
[0x207E]={c='cl'},
[0x208D]={c='op'},
[0x208E]={c='cl'},
[0x20A7]={c='po'},
[0x20B6]={c='po'},
[0x20BB]={c='po'},
[0x20BE]={c='po'},
[0x2103]={c='po'},
[0x2109]={c='po'},
[0x2116]={c='pr'},
[0x2212]={c='pr'},
[0x2213]={c='pr'},
[0x22EF]={c='in'},
[0x2308]={c='op'},
[0x2309]={c='cl'},
[0x230A]={c='op'},
[0x230B]={c='cl'},
[0x2329]={c='op'},
[0x232A]={c='cl'},
[0x2983]={c='op'},
[0x2984]={c='cl'},
[0x2985]={c='op'},
[0x2986]={c='cl'},
[0x2987]={c='op'},
[0x2988]={c='cl'},
[0x2989]={c='op'},
[0x298A]={c='cl'},
[0x298B]={c='op'},
[0x298C]={c='cl'},
[0x298D]={c='op'},
[0x298E]={c='cl'},
[0x298F]={c='op'},
[0x2990]={c='cl'},
[0x2991]={c='op'},
[0x2992]={c='cl'},
[0x2993]={c='op'},
[0x2994]={c='cl'},
[0x2995]={c='op'},
[0x2996]={c='cl'},
[0x2997]={c='op'},
[0x2998]={c='cl'},
[0x29D8]={c='op'},
[0x29D9]={c='cl'},
[0x29DA]={c='op'},
[0x29DB]={c='cl'},
[0x29FC]={c='op'},
[0x29FD]={c='cl'},
[0x2CF9]={c='ex'},
[0x2CFE]={c='ex'},
[0x2E02]={c='qu'},
[0x2E03]={c='qu'},
[0x2E04]={c='qu'},
[0x2E05]={c='qu'},
[0x2E06]={c='qu'},
[0x2E07]={c='qu'},
[0x2E08]={c='qu'},
[0x2E09]={c='qu'},
[0x2E0A]={c='qu'},
[0x2E0B]={c='qu'},
[0x2E0C]={c='qu'},
[0x2E0D]={c='qu'},
[0x2E18]={c='op'},
[0x2E1C]={c='qu'},
[0x2E1D]={c='qu'},
[0x2E20]={c='qu'},
[0x2E21]={c='qu'},
[0x2E22]={c='op'},
[0x2E23]={c='cl'},
[0x2E24]={c='op'},
[0x2E25]={c='cl'},
[0x2E26]={c='op'},
[0x2E27]={c='cl'},
[0x2E28]={c='op'},
[0x2E29]={c='cl'},
[0x2E2E]={c='ex'},
[0x2E42]={c='op'},
[0x3001]={c='cl'},
[0x3002]={c='cl'},
[0x3005]={c='ns'},
[0x3008]={c='op'},
[0x3009]={c='cl'},
[0x300A]={c='op'},
[0x300B]={c='cl'},
[0x300C]={c='op'},
[0x300D]={c='cl'},
[0x300E]={c='op'},
[0x300F]={c='cl'},
[0x3010]={c='op'},
[0x3011]={c='cl'},
[0x3014]={c='op'},
[0x3015]={c='cl'},
[0x3016]={c='op'},
[0x3017]={c='cl'},
[0x3018]={c='op'},
[0x3019]={c='cl'},
[0x301A]={c='op'},
[0x301B]={c='cl'},
[0x301C]={c='ns'},
[0x301D]={c='op'},
[0x301E]={c='cl'},
[0x301F]={c='cl'},
[0x3043]={c='cj'},
[0x3045]={c='cj'},
[0x3047]={c='cj'},
[0x3049]={c='cj'},
[0x3063]={c='cj'},
[0x3083]={c='cj'},
[0x3085]={c='cj'},
[0x3087]={c='cj'},
[0x308E]={c='cj'},
[0x3095]={c='cj'},
[0x3096]={c='cj'},
[0x303B]={c='ns'},
[0x303C]={c='ns'},
[0x3041]={c='cj'},
[0x309B]={c='ns'},
[0x309C]={c='ns'},
[0x309D]={c='ns'},
[0x309E]={c='ns'},
[0x30A0]={c='ns'},
[0x30A1]={c='cj'},
[0x30A3]={c='cj'},
[0x30A5]={c='cj'},
[0x30A7]={c='cj'},
[0x30A9]={c='cj'},
[0x30C3]={c='cj'},
[0x30E3]={c='cj'},
[0x30E5]={c='cj'},
[0x30E7]={c='cj'},
[0x30EE]={c='cj'},
[0x30F5]={c='cj'},
[0x30F6]={c='cj'},
[0x30FB]={c='ns'},
[0x30FC]={c='cj'},
[0x30FD]={c='ns'},
[0x30FE]={c='ns'},
[0xA015]={c='ns'},
[0xA60E]={c='ex'},
[0xA838]={c='po'},
[0xFD3E]={c='cl'},
[0xFD3F]={c='op'},
[0xFDFC]={c='po'},
[0xFE10]={c='is'},
[0xFE11]={c='cl'},
[0xFE12]={c='cl'},
[0xFE13]={c='is'},
[0xFE14]={c='is'},
[0xFE15]={c='ex'},
[0xFE16]={c='ex'},
[0xFE17]={c='op'},
[0xFE18]={c='cl'},
[0xFE19]={c='in'},
[0xFE35]={c='op'},
[0xFE36]={c='cl'},
[0xFE37]={c='op'},
[0xFE38]={c='cl'},
[0xFE39]={c='op'},
[0xFE3A]={c='cl'},
[0xFE3B]={c='op'},
[0xFE3C]={c='cl'},
[0xFE3D]={c='op'},
[0xFE3E]={c='cl'},
[0xFE3F]={c='op'},
[0xFE40]={c='cl'},
[0xFE41]={c='op'},
[0xFE42]={c='cl'},
[0xFE43]={c='op'},
[0xFE44]={c='cl'},
[0xFE47]={c='op'},
[0xFE48]={c='cl'},
[0xFE50]={c='cl'},
[0xFE52]={c='cl'},
[0xFE54]={c='ns'},
[0xFE55]={c='ns'},
[0xFE56]={c='ex'},
[0xFE57]={c='ex'},
[0xFE59]={c='op'},
[0xFE5A]={c='cl'},
[0xFE5B]={c='op'},
[0xFE5C]={c='cl'},
[0xFE5D]={c='op'},
[0xFE5E]={c='cl'},
[0xFE69]={c='pr'},
[0xFE6A]={c='po'},
[0xFF01]={c='ex', w='f'},
[0xFF04]={c='pr', w='f'},
[0xFF05]={c='po', w='f'},
[0xFF08]={c='op', w='f'},
[0xFF09]={c='cl', w='f'},
[0xFF0C]={c='cl', w='f'},
[0xFF0E]={c='cl', w='f'},
[0xFF1A]={c='ns', w='f'},
[0xFF1B]={c='ns', w='f'},
[0xFF1F]={c='ex', w='f'},
[0xFF3B]={c='op', w='f'},
[0xFF3D]={c='cl', w='f'},
[0xFF5B]={c='op', w='f'},
[0xFF5D]={c='cl', w='f'},
[0xFF5F]={c='op', w='f'},
[0xFF60]={c='cl', w='f'},
[0xFF61]={c='cl', w='h'},
[0xFF62]={c='op', w='h'},
[0xFF63]={c='cl', w='h'},
[0xFF64]={c='cl', w='h'},
[0xFF70]={c='cj'}
}
Babel.cjk_class = setmetatable ( Babel.cjk_characters, {
__index = function(_, k)
if (k >= 0xAC00 and k <= 0xD7A3) -- H2/H3
or (k >= 0x2E80 and k <= 0x31E9) -- Skip small
or (k >= 0x3200 and k <= 0x9FFF)
or (k >= 0xA000 and k <= 0xA48F) -- Yi
or (k >= 0xA490 and k <= 0xA4CF) -- Yi
or (k >= 0xF900 and k <= 0xFAFF)
or (k >= 0xFE10 and k <= 0xFE1F)
or (k >= 0xFE30 and k <= 0xFE6F)
or (k >= 0xFF00 and k <= 0xFF66) -- Skip small
or (k >= 0xFF70 and k <= 0xFFEF)
or (k >= 0x1F000 and k <= 0x1FFFD)
or (k >= 0x20000 and k <= 0x2FFFD)
or (k >= 0x30000 and k <= 0x3FFFD) then
return {c='I'}
elseif (k >= 0x20A0 and k <= 0x20CF) then
return {c='pr'}
elseif (k >= 0x31F0 and k <= 0x31FF)
or (k >= 0xFF67 and k <= 0xFF6F)
or (k >= 0x1B150 and k <= 0x1B152)
or (k >= 0x1B164 and k <= 0x1B167) then
return {c='cj'}
else
return {c='O'}
end
end })
-- Note ns = ex = sy = is = po = hy. Here, 'I' and 'O' are
-- pseudo-classes for ideographic-like (id, h2, h3), and 'other',
-- respectively. Jamo is not considered yet, but very likely at least
-- jl must be.
Babel.cjk_breaks = {
['op'] = { },
['cl'] = { ['op']=1, ['pr']=1, ['in']=1, ['I']=1 },
['ns'] = { ['op']=1, ['pr']=1, ['po']=1, ['in']=1, ['I']=1 },
['ex'] = { ['op']=1, ['pr']=1, ['po']=1, ['in']=1, ['I']=1 },
['sy'] = { ['op']=1, ['pr']=1, ['po']=1, ['in']=1, ['I']=1 },
['is'] = { ['op']=1, ['pr']=1, ['po']=1, ['in']=1, ['I']=1 },
['pr'] = { ['pr']=1, ['po']=1, ['in']=1 },
['po'] = { ['op']=1, ['pr']=1, ['po']=1, ['in']=1, ['I']=1 },
['in'] = { ['op']=1, ['pr']=1, ['po']=1, ['I']=1 },
['hy'] = { ['op']=1, ['pr']=1, ['po']=1, ['in']=1, ['I']=1 },
['qu'] = { },
--
['I'] = { ['op']=1, ['pr']=1, ['I']=1, ['O']=1 },
['O'] = { ['I']=1 }
}
%</cjkdata>
% \end{macrocode}
%\fi
%
% \section{The `nil' language}
%
% This `language' does nothing, except setting the hyphenation patterns
% to nohyphenation. For this language currently no special definitions
% are needed or available.
%
% The macro |\LdfInit| takes care of preventing that this file is
% loaded more than once, checking the category code of the \texttt{@}
% sign, etc.
%
% \begin{macrocode}
%<*nil>
\ProvidesLanguage{nil}[<@date@> v<@version@> Nil language]
\LdfInit{nil}{datenil}
% \end{macrocode}
%
% When this file is read as an option, i.e., by the |\usepackage|
% command, \texttt{nil} could be an `unknown' language in which case we
% have to make it known.
%
% \begin{macrocode}
\ifx\l@nil\@undefined
\newlanguage\l@nil
\@namedef{bbl@hyphendata@\the\l@nil}{{}{}}% Remove warning
\let\bbl@elt\relax
\edef\bbl@languages{% Add it to the list of languages
\bbl@languages\bbl@elt{nil}{\the\l@nil}{}{}}
\fi
% \end{macrocode}
%
% This macro is used to store the values of the hyphenation parameters
% |\lefthyphenmin| and |\righthyphenmin|.
%
% \begin{macrocode}
\providehyphenmins{\CurrentOption}{\m@ne\m@ne}
% \end{macrocode}
%
% The next step consists of defining commands to switch to (and from)
% the `nil' language.
% \macro{\captionnil}
% \macro{\datenil}
%
% \begin{macrocode}
\let\captionsnil\@empty
\let\datenil\@empty
% \end{macrocode}
%
% There is no locale file for this pseudo-language, so the
% corresponding fields are defined here.
%
% \begin{macrocode}
\def\bbl@inidata@nil{%
\bbl@elt{identification}{tag.ini}{und}%
\bbl@elt{identification}{load.level}{0}%
\bbl@elt{identification}{charset}{utf8}%
\bbl@elt{identification}{version}{1.0}%
\bbl@elt{identification}{date}{2022-05-16}%
\bbl@elt{identification}{name.local}{nil}%
\bbl@elt{identification}{name.english}{nil}%
\bbl@elt{identification}{name.babel}{nil}%
\bbl@elt{identification}{tag.bcp47}{und}%
\bbl@elt{identification}{language.tag.bcp47}{und}%
\bbl@elt{identification}{tag.opentype}{dflt}%
\bbl@elt{identification}{script.name}{Latin}%
\bbl@elt{identification}{script.tag.bcp47}{Latn}%
\bbl@elt{identification}{script.tag.opentype}{DFLT}%
\bbl@elt{identification}{level}{1}%
\bbl@elt{identification}{encodings}{}%
\bbl@elt{identification}{derivate}{no}}
\@namedef{bbl@tbcp@nil}{und}
\@namedef{bbl@lbcp@nil}{und}
\@namedef{bbl@casing@nil}{und}
\@namedef{bbl@lotf@nil}{dflt}
\@namedef{bbl@elname@nil}{nil}
\@namedef{bbl@lname@nil}{nil}
\@namedef{bbl@esname@nil}{Latin}
\@namedef{bbl@sname@nil}{Latin}
\@namedef{bbl@sbcp@nil}{Latn}
\@namedef{bbl@sotf@nil}{latn}
% \end{macrocode}
%
% The macro |\ldf@finish| takes care of looking for a configuration
% file, setting the main language to be switched on at
% |\begin{document}| and resetting the category code of \texttt{@} to
% its original value.
%
% \begin{macrocode}
\ldf@finish{nil}
%</nil>
% \end{macrocode}
%
% \section{Calendars}
%
% The code for specific calendars are placed in the
% specific files, loaded when requested by an |ini| file in the
% |identification| section with |require.calendars|.
%
% Start with function to compute the Julian day. It’s based on the
% little library |calendar.js|, by John Walker, in the public domain.
% \begin{macrocode}
%<<*Compute Julian day>>
\def\bbl@fpmod#1#2{(#1-#2*floor(#1/#2))}
\def\bbl@cs@gregleap#1{%
(\bbl@fpmod{#1}{4} == 0) &&
(!((\bbl@fpmod{#1}{100} == 0) && (\bbl@fpmod{#1}{400} != 0)))}
\def\bbl@cs@jd#1#2#3{% year, month, day
\fp_eval:n{ 1721424.5 + (365 * (#1 - 1)) +
floor((#1 - 1) / 4) + (-floor((#1 - 1) / 100)) +
floor((#1 - 1) / 400) + floor((((367 * #2) - 362) / 12) +
((#2 <= 2) ? 0 : (\bbl@cs@gregleap{#1} ? -1 : -2)) + #3) }}
%<</Compute Julian day>>
% \end{macrocode}
% \subsection{Islamic}
% The code for the Civil calendar is based on it, too.
%
% \begin{macrocode}
%<*ca-islamic>
\ExplSyntaxOn
<@Compute Julian day@>
% == islamic (default)
% Not yet implemented
\def\bbl@ca@islamic#1-#2-#3\@@#4#5#6{}
% \end{macrocode}
%
% The Civil calendar.
%
% \begin{macrocode}
\def\bbl@cs@isltojd#1#2#3{ % year, month, day
((#3 + ceil(29.5 * (#2 - 1)) +
(#1 - 1) * 354 + floor((3 + (11 * #1)) / 30) +
1948439.5) - 1) }
\@namedef{bbl@ca@islamic-civil++}{\bbl@ca@islamicvl@x{+2}}
\@namedef{bbl@ca@islamic-civil+}{\bbl@ca@islamicvl@x{+1}}
\@namedef{bbl@ca@islamic-civil}{\bbl@ca@islamicvl@x{}}
\@namedef{bbl@ca@islamic-civil-}{\bbl@ca@islamicvl@x{-1}}
\@namedef{bbl@ca@islamic-civil--}{\bbl@ca@islamicvl@x{-2}}
\def\bbl@ca@islamicvl@x#1#2-#3-#4\@@#5#6#7{%
\edef\bbl@tempa{%
\fp_eval:n{ floor(\bbl@cs@jd{#2}{#3}{#4})+0.5 #1}}%
\edef#5{%
\fp_eval:n{ floor(((30*(\
[email protected])) + 10646)/10631) }}%
\edef#6{\fp_eval:n{
min(12,ceil((\bbl@tempa-(29+\bbl@cs@isltojd{#5}{1}{1}))/29.5)+1) }}%
\edef#7{\fp_eval:n{ \bbl@tempa - \bbl@cs@isltojd{#5}{#6}{1} + 1} }}
% \end{macrocode}
%
% The Umm al-Qura calendar, used mainly in Saudi Arabia, is based
% on \textsf{moment-hijri}, by Abdullah Alsigar (license MIT).
%
% Since the main aim is to provide a suitable |\today|, and maybe some
% close dates, data just covers Hijri $\sim$1435/$\sim$1460 (Gregorian
% $\sim$2014/$\sim$2038).
%
% \begin{macrocode}
\def\bbl@cs@umalqura@data{56660, 56690,56719,56749,56778,56808,%
56837,56867,56897,56926,56956,56985,57015,57044,57074,57103,%
57133,57162,57192,57221,57251,57280,57310,57340,57369,57399,%
57429,57458,57487,57517,57546,57576,57605,57634,57664,57694,%
57723,57753,57783,57813,57842,57871,57901,57930,57959,57989,%
58018,58048,58077,58107,58137,58167,58196,58226,58255,58285,%
58314,58343,58373,58402,58432,58461,58491,58521,58551,58580,%
58610,58639,58669,58698,58727,58757,58786,58816,58845,58875,%
58905,58934,58964,58994,59023,59053,59082,59111,59141,59170,%
59200,59229,59259,59288,59318,59348,59377,59407,59436,59466,%
59495,59525,59554,59584,59613,59643,59672,59702,59731,59761,%
59791,59820,59850,59879,59909,59939,59968,59997,60027,60056,%
60086,60115,60145,60174,60204,60234,60264,60293,60323,60352,%
60381,60411,60440,60469,60499,60528,60558,60588,60618,60648,%
60677,60707,60736,60765,60795,60824,60853,60883,60912,60942,%
60972,61002,61031,61061,61090,61120,61149,61179,61208,61237,%
61267,61296,61326,61356,61385,61415,61445,61474,61504,61533,%
61563,61592,61621,61651,61680,61710,61739,61769,61799,61828,%
61858,61888,61917,61947,61976,62006,62035,62064,62094,62123,%
62153,62182,62212,62242,62271,62301,62331,62360,62390,62419,%
62448,62478,62507,62537,62566,62596,62625,62655,62685,62715,%
62744,62774,62803,62832,62862,62891,62921,62950,62980,63009,%
63039,63069,63099,63128,63157,63187,63216,63246,63275,63305,%
63334,63363,63393,63423,63453,63482,63512,63541,63571,63600,%
63630,63659,63689,63718,63747,63777,63807,63836,63866,63895,%
63925,63955,63984,64014,64043,64073,64102,64131,64161,64190,%
64220,64249,64279,64309,64339,64368,64398,64427,64457,64486,%
64515,64545,64574,64603,64633,64663,64692,64722,64752,64782,%
64811,64841,64870,64899,64929,64958,64987,65017,65047,65076,%
65106,65136,65166,65195,65225,65254,65283,65313,65342,65371,%
65401,65431,65460,65490,65520}
\@namedef{bbl@ca@islamic-umalqura+}{\bbl@ca@islamcuqr@x{+1}}
\@namedef{bbl@ca@islamic-umalqura}{\bbl@ca@islamcuqr@x{}}
\@namedef{bbl@ca@islamic-umalqura-}{\bbl@ca@islamcuqr@x{-1}}
\def\bbl@ca@islamcuqr@x#1#2-#3-#4\@@#5#6#7{%
\ifnum#2>2014 \ifnum#2<2038
\bbl@afterfi\expandafter\@gobble
\fi\fi
{\bbl@error{year-out-range}{2014-2038}{}{}}%
\edef\bbl@tempd{\fp_eval:n{ % (Julian) day
\bbl@cs@jd{#2}{#3}{#4} + 0.5 - 2400000 #1}}%
\count@\@ne
\bbl@foreach\bbl@cs@umalqura@data{%
\advance\count@\@ne
\ifnum##1>\bbl@tempd\else
\edef\bbl@tempe{\the\count@}%
\edef\bbl@tempb{##1}%
\fi}%
\edef\bbl@templ{\fp_eval:n{ \bbl@tempe + 16260 + 949 }}% month~lunar
\edef\bbl@tempa{\fp_eval:n{ floor((\bbl@templ - 1 ) / 12) }}% annus
\edef#5{\fp_eval:n{ \bbl@tempa + 1 }}%
\edef#6{\fp_eval:n{ \bbl@templ - (12 * \bbl@tempa) }}%
\edef#7{\fp_eval:n{ \bbl@tempd - \bbl@tempb + 1 }}}
\ExplSyntaxOff
\bbl@add\bbl@precalendar{%
\bbl@replace\bbl@ld@calendar{-civil}{}%
\bbl@replace\bbl@ld@calendar{-umalqura}{}%
\bbl@replace\bbl@ld@calendar{+}{}%
\bbl@replace\bbl@ld@calendar{-}{}}
%</ca-islamic>
% \end{macrocode}
%
% \subsection{Hebrew}
%
% This is basically the set of macros written by Michail Rozman in
% 1991, with corrections and adaptions by Rama Porrat, Misha, Dan Haran
% and Boris Lavva. This must be eventually replaced by computations
% with \textsf{l3fp}. An explanation of what’s going on can be found in
% \texttt{hebcal.sty}
%
% \begin{macrocode}
%<*ca-hebrew>
\newcount\bbl@cntcommon
\def\bbl@remainder#1#2#3{%
#3=#1\relax
\divide #3 by #2\relax
\multiply #3 by -#2\relax
\advance #3 by #1\relax}%
\newif\ifbbl@divisible
\def\bbl@checkifdivisible#1#2{%
{\countdef\tmp=0
\bbl@remainder{#1}{#2}{\tmp}%
\ifnum \tmp=0
\global\bbl@divisibletrue
\else
\global\bbl@divisiblefalse
\fi}}
\newif\ifbbl@gregleap
\def\bbl@ifgregleap#1{%
\bbl@checkifdivisible{#1}{4}%
\ifbbl@divisible
\bbl@checkifdivisible{#1}{100}%
\ifbbl@divisible
\bbl@checkifdivisible{#1}{400}%
\ifbbl@divisible
\bbl@gregleaptrue
\else
\bbl@gregleapfalse
\fi
\else
\bbl@gregleaptrue
\fi
\else
\bbl@gregleapfalse
\fi
\ifbbl@gregleap}
\def\bbl@gregdayspriormonths#1#2#3{%
{#3=\ifcase #1 0 \or 0 \or 31 \or 59 \or 90 \or 120 \or 151 \or
181 \or 212 \or 243 \or 273 \or 304 \or 334 \fi
\bbl@ifgregleap{#2}%
\ifnum #1 > 2
\advance #3 by 1
\fi
\fi
\global\bbl@cntcommon=#3}%
#3=\bbl@cntcommon}
\def\bbl@gregdaysprioryears#1#2{%
{\countdef\tmpc=4
\countdef\tmpb=2
\tmpb=#1\relax
\advance \tmpb by -1
\tmpc=\tmpb
\multiply \tmpc by 365
#2=\tmpc
\tmpc=\tmpb
\divide \tmpc by 4
\advance #2 by \tmpc
\tmpc=\tmpb
\divide \tmpc by 100
\advance #2 by -\tmpc
\tmpc=\tmpb
\divide \tmpc by 400
\advance #2 by \tmpc
\global\bbl@cntcommon=#2\relax}%
#2=\bbl@cntcommon}
\def\bbl@absfromgreg#1#2#3#4{%
{\countdef\tmpd=0
#4=#1\relax
\bbl@gregdayspriormonths{#2}{#3}{\tmpd}%
\advance #4 by \tmpd
\bbl@gregdaysprioryears{#3}{\tmpd}%
\advance #4 by \tmpd
\global\bbl@cntcommon=#4\relax}%
#4=\bbl@cntcommon}
\newif\ifbbl@hebrleap
\def\bbl@checkleaphebryear#1{%
{\countdef\tmpa=0
\countdef\tmpb=1
\tmpa=#1\relax
\multiply \tmpa by 7
\advance \tmpa by 1
\bbl@remainder{\tmpa}{19}{\tmpb}%
\ifnum \tmpb < 7
\global\bbl@hebrleaptrue
\else
\global\bbl@hebrleapfalse
\fi}}
\def\bbl@hebrelapsedmonths#1#2{%
{\countdef\tmpa=0
\countdef\tmpb=1
\countdef\tmpc=2
\tmpa=#1\relax
\advance \tmpa by -1
#2=\tmpa
\divide #2 by 19
\multiply #2 by 235
\bbl@remainder{\tmpa}{19}{\tmpb}% \tmpa=years%19-years this cycle
\tmpc=\tmpb
\multiply \tmpb by 12
\advance #2 by \tmpb
\multiply \tmpc by 7
\advance \tmpc by 1
\divide \tmpc by 19
\advance #2 by \tmpc
\global\bbl@cntcommon=#2}%
#2=\bbl@cntcommon}
\def\bbl@hebrelapseddays#1#2{%
{\countdef\tmpa=0
\countdef\tmpb=1
\countdef\tmpc=2
\bbl@hebrelapsedmonths{#1}{#2}%
\tmpa=#2\relax
\multiply \tmpa by 13753
\advance \tmpa by 5604
\bbl@remainder{\tmpa}{25920}{\tmpc}% \tmpc == ConjunctionParts
\divide \tmpa by 25920
\multiply #2 by 29
\advance #2 by 1
\advance #2 by \tmpa
\bbl@remainder{#2}{7}{\tmpa}%
\ifnum \tmpc < 19440
\ifnum \tmpc < 9924
\else
\ifnum \tmpa=2
\bbl@checkleaphebryear{#1}% of a common year
\ifbbl@hebrleap
\else
\advance #2 by 1
\fi
\fi
\fi
\ifnum \tmpc < 16789
\else
\ifnum \tmpa=1
\advance #1 by -1
\bbl@checkleaphebryear{#1}% at the end of leap year
\ifbbl@hebrleap
\advance #2 by 1
\fi
\fi
\fi
\else
\advance #2 by 1
\fi
\bbl@remainder{#2}{7}{\tmpa}%
\ifnum \tmpa=0
\advance #2 by 1
\else
\ifnum \tmpa=3
\advance #2 by 1
\else
\ifnum \tmpa=5
\advance #2 by 1
\fi
\fi
\fi
\global\bbl@cntcommon=#2\relax}%
#2=\bbl@cntcommon}
\def\bbl@daysinhebryear#1#2{%
{\countdef\tmpe=12
\bbl@hebrelapseddays{#1}{\tmpe}%
\advance #1 by 1
\bbl@hebrelapseddays{#1}{#2}%
\advance #2 by -\tmpe
\global\bbl@cntcommon=#2}%
#2=\bbl@cntcommon}
\def\bbl@hebrdayspriormonths#1#2#3{%
{\countdef\tmpf= 14
#3=\ifcase #1
0 \or
0 \or
30 \or
59 \or
89 \or
118 \or
148 \or
148 \or
177 \or
207 \or
236 \or
266 \or
295 \or
325 \or
400
\fi
\bbl@checkleaphebryear{#2}%
\ifbbl@hebrleap
\ifnum #1 > 6
\advance #3 by 30
\fi
\fi
\bbl@daysinhebryear{#2}{\tmpf}%
\ifnum #1 > 3
\ifnum \tmpf=353
\advance #3 by -1
\fi
\ifnum \tmpf=383
\advance #3 by -1
\fi
\fi
\ifnum #1 > 2
\ifnum \tmpf=355
\advance #3 by 1
\fi
\ifnum \tmpf=385
\advance #3 by 1
\fi
\fi
\global\bbl@cntcommon=#3\relax}%
#3=\bbl@cntcommon}
\def\bbl@absfromhebr#1#2#3#4{%
{#4=#1\relax
\bbl@hebrdayspriormonths{#2}{#3}{#1}%
\advance #4 by #1\relax
\bbl@hebrelapseddays{#3}{#1}%
\advance #4 by #1\relax
\advance #4 by -1373429
\global\bbl@cntcommon=#4\relax}%
#4=\bbl@cntcommon}
\def\bbl@hebrfromgreg#1#2#3#4#5#6{%
{\countdef\tmpx= 17
\countdef\tmpy= 18
\countdef\tmpz= 19
#6=#3\relax
\global\advance #6 by 3761
\bbl@absfromgreg{#1}{#2}{#3}{#4}%
\tmpz=1 \tmpy=1
\bbl@absfromhebr{\tmpz}{\tmpy}{#6}{\tmpx}%
\ifnum \tmpx > #4\relax
\global\advance #6 by -1
\bbl@absfromhebr{\tmpz}{\tmpy}{#6}{\tmpx}%
\fi
\advance #4 by -\tmpx
\advance #4 by 1
#5=#4\relax
\divide #5 by 30
\loop
\bbl@hebrdayspriormonths{#5}{#6}{\tmpx}%
\ifnum \tmpx < #4\relax
\advance #5 by 1
\tmpy=\tmpx
\repeat
\global\advance #5 by -1
\global\advance #4 by -\tmpy}}
\newcount\bbl@hebrday \newcount\bbl@hebrmonth \newcount\bbl@hebryear
\newcount\bbl@gregday \newcount\bbl@gregmonth \newcount\bbl@gregyear
\def\bbl@ca@hebrew#1-#2-#3\@@#4#5#6{%
\bbl@gregday=#3\relax \bbl@gregmonth=#2\relax \bbl@gregyear=#1\relax
\bbl@hebrfromgreg
{\bbl@gregday}{\bbl@gregmonth}{\bbl@gregyear}%
{\bbl@hebrday}{\bbl@hebrmonth}{\bbl@hebryear}%
\edef#4{\the\bbl@hebryear}%
\edef#5{\the\bbl@hebrmonth}%
\edef#6{\the\bbl@hebrday}}
%</ca-hebrew>
% \end{macrocode}
%
% \subsection{Persian}
%
% There is an algorithm written in TeX by Jabri, Abolhassani, Pournader
% and Esfahbod, created for the first versions of the FarsiTeX system
% (no longer available), but the original license is GPL, so its use
% with LPPL is problematic. The code here follows loosely that by John
% Walker, which is free and accurate, but sadly very complex, so
% the relevant data for the years 2013-2050 have been pre-calculated
% and stored. Actually, all we need is the first day (either March 20 or
% March 21).
%
% \begin{macrocode}
%<*ca-persian>
\ExplSyntaxOn
<@Compute Julian day@>
\def\bbl@cs@firstjal@xx{2012,2016,2020,2024,2028,2029,% March 20
2032,2033,2036,2037,2040,2041,2044,2045,2048,2049}
\def\bbl@ca@persian#1-#2-#3\@@#4#5#6{%
\edef\bbl@tempa{#1}% 20XX-03-\bbl@tempe = 1 farvardin:
\ifnum\bbl@tempa>2012 \ifnum\bbl@tempa<2051
\bbl@afterfi\expandafter\@gobble
\fi\fi
{\bbl@error{year-out-range}{2013-2050}{}{}}%
\bbl@xin@{\bbl@tempa}{\bbl@cs@firstjal@xx}%
\ifin@\def\bbl@tempe{20}\else\def\bbl@tempe{21}\fi
\edef\bbl@tempc{\fp_eval:n{\bbl@cs@jd{\bbl@tempa}{#2}{#3}+.5}}% current
\edef\bbl@tempb{\fp_eval:n{\bbl@cs@jd{\bbl@tempa}{03}{\bbl@tempe}+.5}}% begin
\ifnum\bbl@tempc<\bbl@tempb
\edef\bbl@tempa{\fp_eval:n{\bbl@tempa-1}}% go back 1 year and redo
\bbl@xin@{\bbl@tempa}{\bbl@cs@firstjal@xx}%
\ifin@\def\bbl@tempe{20}\else\def\bbl@tempe{21}\fi
\edef\bbl@tempb{\fp_eval:n{\bbl@cs@jd{\bbl@tempa}{03}{\bbl@tempe}+.5}}%
\fi
\edef#4{\fp_eval:n{\bbl@tempa-621}}% set Jalali year
\edef#6{\fp_eval:n{\bbl@tempc-\bbl@tempb+1}}% days from 1 farvardin
\edef#5{\fp_eval:n{% set Jalali month
(#6 <= 186) ? ceil(#6 / 31) : ceil((#6 - 6) / 30)}}
\edef#6{\fp_eval:n{% set Jalali day
(#6 - ((#5 <= 7) ? ((#5 - 1) * 31) : (((#5 - 1) * 30) + 6)))}}}
\ExplSyntaxOff
%</ca-persian>
% \end{macrocode}
%
% \subsection{Coptic and Ethiopic}
%
% Adapted from \texttt{jquery.calendars.package-1.1.4}, written by Keith
% Wood, 2010. Dual license: GPL and MIT. The only difference is the
% epoch.
%
% \begin{macrocode}
%<*ca-coptic>
\ExplSyntaxOn
<@Compute Julian day@>
\def\bbl@ca@coptic#1-#2-#3\@@#4#5#6{%
\edef\bbl@tempd{\fp_eval:n{floor(\bbl@cs@jd{#1}{#2}{#3}) + 0.5}}%
\edef\bbl@tempc{\fp_eval:n{\bbl@tempd - 1825029.5}}%
\edef#4{\fp_eval:n{%
floor((\bbl@tempc - floor((\bbl@tempc+366) / 1461)) / 365) + 1}}%
\edef\bbl@tempc{\fp_eval:n{%
\bbl@tempd - (#4-1) * 365 - floor(#4/4) - 1825029.5}}%
\edef#5{\fp_eval:n{floor(\bbl@tempc / 30) + 1}}%
\edef#6{\fp_eval:n{\bbl@tempc - (#5 - 1) * 30 + 1}}}
\ExplSyntaxOff
%</ca-coptic>
%<*ca-ethiopic>
\ExplSyntaxOn
<@Compute Julian day@>
\def\bbl@ca@ethiopic#1-#2-#3\@@#4#5#6{%
\edef\bbl@tempd{\fp_eval:n{floor(\bbl@cs@jd{#1}{#2}{#3}) + 0.5}}%
\edef\bbl@tempc{\fp_eval:n{\bbl@tempd - 1724220.5}}%
\edef#4{\fp_eval:n{%
floor((\bbl@tempc - floor((\bbl@tempc+366) / 1461)) / 365) + 1}}%
\edef\bbl@tempc{\fp_eval:n{%
\bbl@tempd - (#4-1) * 365 - floor(#4/4) - 1724220.5}}%
\edef#5{\fp_eval:n{floor(\bbl@tempc / 30) + 1}}%
\edef#6{\fp_eval:n{\bbl@tempc - (#5 - 1) * 30 + 1}}}
\ExplSyntaxOff
%</ca-ethiopic>
% \end{macrocode}
%
% \subsection{Buddhist}
%
% That’s very simple.
%
% \begin{macrocode}
%<*ca-buddhist>
\def\bbl@ca@buddhist#1-#2-#3\@@#4#5#6{%
\edef#4{\number\numexpr#1+543\relax}%
\edef#5{#2}%
\edef#6{#3}}
%</ca-buddhist>
%
% \subsection{Chinese}
%
% Brute force, with the Julian day of first day of each month. The
% table has been computed with the help of \textsf{python-lunardate} by
% Ricky Yeung, GPLv2 (but the code itself has not been used). The range
% is 2015-2044.
%
% \begin{macrocode}
%<*ca-chinese>
\ExplSyntaxOn
<@Compute Julian day@>
\def\bbl@ca@chinese#1-#2-#3\@@#4#5#6{%
\edef\bbl@tempd{\fp_eval:n{%
\bbl@cs@jd{#1}{#2}{#3} - 2457072.5 }}%
\count@\z@
\@tempcnta=2015
\bbl@foreach\bbl@cs@chinese@data{%
\ifnum##1>\bbl@tempd\else
\advance\count@\@ne
\ifnum\count@>12
\count@\@ne
\advance\@tempcnta\@ne\fi
\bbl@xin@{,##1,}{,\bbl@cs@chinese@leap,}%
\ifin@
\advance\count@\m@ne
\edef\bbl@tempe{\the\numexpr\count@+12\relax}%
\else
\edef\bbl@tempe{\the\count@}%
\fi
\edef\bbl@tempb{##1}%
\fi}%
\edef#4{\the\@tempcnta}%
\edef#5{\bbl@tempe}%
\edef#6{\the\numexpr\bbl@tempd-\bbl@tempb+1\relax}}
\def\bbl@cs@chinese@leap{%
885,1920,2953,3809,4873,5906,6881,7825,8889,9893,10778}
\def\bbl@cs@chinese@data{0,29,59,88,117,147,176,206,236,266,295,325,
354,384,413,443,472,501,531,560,590,620,649,679,709,738,%
768,797,827,856,885,915,944,974,1003,1033,1063,1093,1122,%
1152,1181,1211,1240,1269,1299,1328,1358,1387,1417,1447,1477,%
1506,1536,1565,1595,1624,1653,1683,1712,1741,1771,1801,1830,%
1860,1890,1920,1949,1979,2008,2037,2067,2096,2126,2155,2185,%
2214,2244,2274,2303,2333,2362,2392,2421,2451,2480,2510,2539,%
2569,2598,2628,2657,2687,2717,2746,2776,2805,2835,2864,2894,%
2923,2953,2982,3011,3041,3071,3100,3130,3160,3189,3219,3248,%
3278,3307,3337,3366,3395,3425,3454,3484,3514,3543,3573,3603,%
3632,3662,3691,3721,3750,3779,3809,3838,3868,3897,3927,3957,%
3987,4016,4046,4075,4105,4134,4163,4193,4222,4251,4281,4311,%
4341,4370,4400,4430,4459,4489,4518,4547,4577,4606,4635,4665,%
4695,4724,4754,4784,4814,4843,4873,4902,4931,4961,4990,5019,%
5049,5079,5108,5138,5168,5197,5227,5256,5286,5315,5345,5374,%
5403,5433,5463,5492,5522,5551,5581,5611,5640,5670,5699,5729,%
5758,5788,5817,5846,5876,5906,5935,5965,5994,6024,6054,6083,%
6113,6142,6172,6201,6231,6260,6289,6319,6348,6378,6408,6437,%
6467,6497,6526,6556,6585,6615,6644,6673,6703,6732,6762,6791,%
6821,6851,6881,6910,6940,6969,6999,7028,7057,7087,7116,7146,%
7175,7205,7235,7264,7294,7324,7353,7383,7412,7441,7471,7500,%
7529,7559,7589,7618,7648,7678,7708,7737,7767,7796,7825,7855,%
7884,7913,7943,7972,8002,8032,8062,8092,8121,8151,8180,8209,%
8239,8268,8297,8327,8356,8386,8416,8446,8475,8505,8534,8564,%
8593,8623,8652,8681,8711,8740,8770,8800,8829,8859,8889,8918,%
8948,8977,9007,9036,9066,9095,9124,9154,9183,9213,9243,9272,%
9302,9331,9361,9391,9420,9450,9479,9508,9538,9567,9597,9626,%
9656,9686,9715,9745,9775,9804,9834,9863,9893,9922,9951,9981,%
10010,10040,10069,10099,10129,10158,10188,10218,10247,10277,%
10306,10335,10365,10394,10423,10453,10483,10512,10542,10572,%
10602,10631,10661,10690,10719,10749,10778,10807,10837,10866,%
10896,10926,10956,10986,11015,11045,11074,11103}
\ExplSyntaxOff
%</ca-chinese>
% \end{macrocode}
%
% \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 achieve the desired effect, based on the
% \pkg{babel} package. If you load each of them with ini\TeX, you
% will get a file called either \file{bplain.fmt} or
% \file{blplain.fmt}, which you can use as replacements for
% \file{plain.fmt} and \file{lplain.fmt}.
%
% As these files are going to be read as the first thing ini\TeX\
% sees, we need to set some category codes just to be able to
% change the definition of |\input|.
%
% \begin{macrocode}
%<*bplain|blplain>
\catcode`\{=1 % left brace is begin-group character
\catcode`\}=2 % right brace is end-group character
\catcode`\#=6 % hash mark is macro parameter character
% \end{macrocode}
%
% 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
\ifeof0
\else
\let\a\input
% \end{macrocode}
%
% 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
\let\a\undefined
}
\fi
%</bplain|blplain>
% \end{macrocode}
%
% Now that we have made sure that \file{hyphen.cfg} will be loaded
% at the right moment it is time to load \file{plain.tex}.
%
% \begin{macrocode}
%<bplain>\a plain.tex
%<blplain>\a lplain.tex
% \end{macrocode}
%
% Finally we change the contents of |\fmtname| to indicate that
% this is \emph{not} the plain format, but a format based on plain
% with the \pkg{babel} package preloaded.
%
% \begin{macrocode}
%<bplain>\def\fmtname{babel-plain}
%<blplain>\def\fmtname{babel-lplain}
% \end{macrocode}
%
% When you are using a different format, based on plain.tex you can
% make a copy of blplain.tex, rename it and replace \file{plain.tex}
% with the name of your format file.
%
% \subsection{Emulating some \LaTeX{} features}
%
% The file |babel.def| expects some definitions made in the \LaTeXe{}
% style file. So, in 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}
%<<*Emulate LaTeX>>
\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}
% \end{macrocode}
%
% \subsection{General tools}
%
% A number of \LaTeX\ macro's that are needed later on.
%
% \begin{macrocode}
\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
\def\bbl@error#1{% Implicit #2#3#4
\begingroup
\catcode`\\=0 \catcode`\==12 \catcode`\`=12
\catcode`\^^M=5 \catcode`\%=14
\input errbabel.def
\endgroup
\bbl@error{#1}}
\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}
% \end{macrocode}
%
% \LaTeXe\ has the command |\@onlypreamble| which adds commands to
% a list of commands that are no longer needed after
% |\begin{document}|.
%
% \begin{macrocode}
\ifx\@preamblecmds\@undefined
\def\@preamblecmds{}
\fi
\def\@onlypreamble#1{%
\expandafter\gdef\expandafter\@preamblecmds\expandafter{%
\@preamblecmds\do#1}}
\@onlypreamble\@onlypreamble
% \end{macrocode}
%
% Mimic \LaTeX's |\AtBeginDocument|; for this to work the user needs to
% add |\begindocument| to his file.
%
% \begin{macrocode}
\def\begindocument{%
\@begindocumenthook
\global\let\@begindocumenthook\@undefined
\def\do##1{\global\let##1\@undefined}%
\@preamblecmds
\global\let\do\noexpand}
% \end{macrocode}
%
% \begin{macrocode}
\ifx\@begindocumenthook\@undefined
\def\@begindocumenthook{}
\fi
\@onlypreamble\@begindocumenthook
\def\AtBeginDocument{\g@addto@macro\@begindocumenthook}
% \end{macrocode}
%
% We also have to mimic \LaTeX's |\AtEndOfPackage|. Our replacement
% macro is much simpler; it stores its argument in |\@endofldf|.
%
% \begin{macrocode}
\def\AtEndOfPackage#1{\g@addto@macro\@endofldf{#1}}
\@onlypreamble\AtEndOfPackage
\def\@endofldf{}
\@onlypreamble\@endofldf
\let\bbl@afterlang\@empty
\chardef\bbl@opt@hyphenmap\z@
% \end{macrocode}
%
% \LaTeX\ needs to be able to switch off writing to its auxiliary
% 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}
\catcode`\&=\z@
\ifx&if@filesw\@undefined
\expandafter\let\csname if@filesw\expandafter\endcsname
\csname iffalse\endcsname
\fi
\catcode`\&=4
% \end{macrocode}
%
% Mimic \LaTeX's commands to define control sequences.
%
% \begin{macrocode}
\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}%
% \end{macrocode}
%
% \begin{macrocode}
\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}
% \end{macrocode}
%
% The following little macro |\in@| is taken from \file{latex.ltx}; it
% checks whether its first argument is part of its second argument. It
% uses the boolean |\in@|; allocating a new boolean inside
% conditionally executed code is not possible, hence the construct with
% the temporary definition of |\bbl@tempa|.
%
% \begin{macrocode}
\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
% \end{macrocode}
%
% \LaTeX\ has a macro to check whether a certain package was loaded
% with specific options. The command has two extra arguments which are
% code to be executed in either the true or false case. This is used to
% detect whether the document needs one of the accents to be activated
% (\Lopt{activegrave} and \Lopt{activeacute}). For plain \TeX\ we
% assume that the user wants them to be active by default. Therefore
% the only thing we do is execute the third argument (the code for the
% true case).
%
% \begin{macrocode}
\def\@ifpackagewith#1#2#3#4{#3}
% \end{macrocode}
%
% The \LaTeX\ macro |\@ifl@aded| checks whether a file was loaded. This
% functionality is not needed for plain \TeX\ but we need the macro to
% be defined as a no-op.
%
% \begin{macrocode}
\def\@ifl@aded#1#2#3#4{}
% \end{macrocode}
%
% For the following code we need to make sure that the commands
% |\newcommand| and |\providecommand| exist with some sensible
% definition. They are not fully equivalent to their \LaTeXe\ versions;
% just enough to make things work in plain~\TeX environments.
%
% \begin{macrocode}
\ifx\@tempcnta\@undefined
\csname newcount\endcsname\@tempcnta\relax
\fi
\ifx\@tempcntb\@undefined
\csname newcount\endcsname\@tempcntb\relax
\fi
% \end{macrocode}
%
% To prevent wasting two counters in \LaTeX\ (because counters with the
% same name are allocated later by it) we reset the counter that holds
% the next free counter (|\count10|).
%
% \begin{macrocode}
\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}}
% \end{macrocode}
%
% \subsection{Encoding related macros}
%
% Code from \file{ltoutenc.dtx}, adapted for use in the plain \TeX\
% environment.
%
% \begin{macrocode}
\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
}%
% \let\@ifdefinable\@rc@ifdefinable
\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 <return> 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 <return> 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}
% \end{macrocode}
%
% Currently we only use the \LaTeXe\ method for accents for those that
% are known to be made active in \emph{some} language definition file.
%
% \begin{macrocode}
\DeclareTextAccent{\"}{OT1}{127}
\DeclareTextAccent{\'}{OT1}{19}
\DeclareTextAccent{\^}{OT1}{94}
\DeclareTextAccent{\`}{OT1}{18}
\DeclareTextAccent{\~}{OT1}{126}
% \end{macrocode}
%
% The following control sequences are used in \file{babel.def} but are
% not defined for \textsc{plain} \TeX.
%
% \begin{macrocode}
\DeclareTextSymbol{\textquotedblleft}{OT1}{92}
\DeclareTextSymbol{\textquotedblright}{OT1}{`\"}
\DeclareTextSymbol{\textquoteleft}{OT1}{`\`}
\DeclareTextSymbol{\textquoteright}{OT1}{`\'}
\DeclareTextSymbol{\i}{OT1}{16}
\DeclareTextSymbol{\ss}{OT1}{25}
% \end{macrocode}
%
% For a couple of languages we need the \LaTeX-control sequence
% |\scriptsize| to be available. Because plain \TeX\ doesn't have such
% a sophisticated font mechanism as \LaTeX\ has, we just |\let| it to
% |\sevenrm|.
%
% \begin{macrocode}
\ifx\scriptsize\@undefined
\let\scriptsize\sevenrm
\fi
% \end{macrocode}
%
% And a few more “dummy” definitions.
%
% \begin{macrocode}
\def\languagename{english}%
\let\bbl@opt@shorthands\@nnil
\def\bbl@ifshorthand#1#2#3{#2}%
\let\bbl@language@opts\@empty
\let\bbl@provide@locale\relax
\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
\chardef\bbl@bidimode\z@
%<</Emulate LaTeX>>
% \end{macrocode}
%
% A proxy file:
%
% \begin{macrocode}
%<*plain>
\input babel.def
%</plain>
% \end{macrocode}
% \Finale
%
\endinput
%
% Local Variables:
% mode: doctex
% coding: utf-8
% TeX-engine: luatex
% End: