% \iffalse % This document requires lualatex %% %% Copyright (C) 2012-2024 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> \ProvidesFile{babel.dtx}[2024/03/29 v24.3 The Babel package] \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 \addtolength{\textwidth}{25pt} \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{$\langle$\normalfont\itshape#1\/$\rangle$}} \newcommand*\langlist{% \meta{language}\texttt{,}\meta{language}\texttt{,}...} \newcommand*\langvar{\m{lang}} \newcommand*\Lopt[1]{\textsf{#1}} \newcommand*\Lenv[1]{\texttt{#1}} \newcommand*\menv[1]{\char`\{#1\char`\}} \newcommand*\Eenv[1]{% \quad\ldots\quad \texttt{\color{thered}\string\end\menv{#1}}} \newcommand*\file[1]{\texttt{#1}} \newcommand*\cls[1]{\texttt{#1}} \newcommand*\pkg[1]{\texttt{#1}} \addtolength{\oddsidemargin}{1em} \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 \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 \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}% {\raisebox{.15ex}{$\oplus$}}% \fi\fi \ifnum\bbltempa>23 \href{https://latex3.github.io/babel/news/% whats-new-in-babel-\bbltempa.\bbltempb.html}% {\raisebox{.15ex}{$\oplus$}}% \fi}}\enspace\ignorespaces} \ExplSyntaxOff \definecolor{thered}{rgb}{0.65,0.04,0.07} \definecolor{thegrey}{gray}{0.8} \definecolor{shadecolor}{rgb}{1,1,0.97} \definecolor{messages}{rgb}{.66,.13,.27} \makeatletter \def\@begintheorem#1#2{% \list{}{}% \global\advance\@listdepth\m@ne \item[{\sffamily\bfseries\color{messages}\hspace*{1.3em}% \MakeUppercase{#1}}]}% \makeatother \newtheorem{warning}{Warning} \newtheorem{note}{Note} \newtheorem{example}{Example} \newtheorem{troubleshooting}{Troubleshooting} \newtheorem{more}{More} \let\bblxv\verbatim \let\bblexv\endverbatim \newcommand\setengine{\def\engine} \let\engine\relax \def\verbatim{% \begin{shaded*}% \ifx\engine\relax\else \vskip-1.08\baselineskip \leavevmode\llap{\fbox{\footnotesize\textsc{\engine}}\hskip2.8em}% \vskip-1.5\baselineskip \vskip0pt \global\let\engine\relax \fi \bblxv\vskip-\baselineskip\vskip2.5\parsep} \def\endverbatim{\bblexv\vskip-2\baselineskip\end{shaded*}} \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} \AtBeginDocument{% \def\PrintDescribeMacro#1{% \strut\MacroFont\color{thered}\normalsize\string#1}} \def\Describe#1{% \par\penalty-500\vskip3ex\noindent \DescribeMacro{#1}\args} \def\DescribeOther{\vskip-4ex\Describe} \makeatletter \def\trouble#1{\addcontentsline{tsh}{trouble}{#1}} \def\listoftroubles{\section*{Troubleshoooting}\@starttoc{tsh}} \let\l@trouble\l@figure \let\saved@check@percent\check@percent \let\check@percent\relax \def\args#1{% \def\bbl@tempa{#1}% \ifx\bbl@tempa\@empty\else#1\vskip1ex\fi\ignorespaces} \begingroup % Changes to ltxdoc \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 \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 #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\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\thanks{During the development ideas from Nico Poppelier, Piet van Oostrum and many others have been used. Bernd Raichle has provided many helpful suggestions.}} \author{Johannes Braams\\ Javier Bezos} \date{Typeset \today} \begin{titlepage} \begin{minipage}[t][0pt]{30cm} \vspace{-3cm}\hspace{-7cm} \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\\ pdf\largetex\\ Lua\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 \pdftex, \xetex{} and \luatex{} with the \babel{} package. There are also some notes on its use with e-Plain and pdf-Plain \TeX. \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} (\raisebox{.15ex}{$\oplus$} 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 be still unstable. Remember version 24.1 follows 3.99, because of a new numbering scheme. \item[\sffamily\color{messages}Can I help?] Sure! If you are interested in the \TeX{} multilingual support, please join the \href{http://tug.org/mailman/listinfo/kadingira}{kadingira mail list}. You can follow the development of \babel{} in \href{https://github.com/latex3/babel}{GitHub} and make suggestions; feel free to fork it and make pull requests. If you are the author of a package, send to 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}I only need learn the most basic features.] The first subsections (1.1-1.3) describe the traditional way of loading a language (with |ldf| files), which is usually all you need. The alternative way based on |ini| files, which complements the previous one (it does \textit{not} replace it, although it is still necessary in some languages), is described below; go to \ref{inifiles}. \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}Where is the code?] Run |lualatex --jobname=babel-code \let\babelcode\relax\input{babel.dtx}|. \end{description} \section{The user interface}\label{U-I} \subsection{Monolingual documents} 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. Many languages are compatible with \textsf{xetex} and \textsf{luatex}. With them you can use \babel{} to localize the documents. When these engines are used, the Latin script is covered by default in current \LaTeX{} (provided the document encoding is UTF-8), because the font loader is preloaded and the font is switched to |lmroman|. Other scripts require loading \textsf{fontspec}. You may want to set the font attributes with \textsf{fontspec}, too. \begin{example} Here is a simple full example for “traditional” \TeX{} engines (see below for \xetex{} and \luatex{}). The packages |fontenc| and |inputenc| do not belong to \babel, but they are included in the example because typically you will need them. 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} And now a simple monolingual document in Russian (text from the Wikipedia) with \xetex{} or \luatex{}. Note neither \textsf{fontenc} nor \textsf{inputenc} are necessary, but the document should be encoded in UTF-8 and a so-called Unicode font must be loaded (in this example |\babelfont| is used, 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{troubleshooting} \trouble{Paragraph ended before \textbackslash UTFviii@three@octets was complete} A common source of trouble is a wrong setting of the input encoding. Depending on the \LaTeX{} version you can get the following somewhat cryptic error: \begin{verbatim} ! Paragraph ended before \UTFviii@three@octets was complete. \end{verbatim} Or the more explanatory: \begin{verbatim} ! Package inputenc Error: Invalid UTF-8 byte ... \end{verbatim} Make sure you set the encoding actually used by your editor. \end{troubleshooting} \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 or dialect. So, a package option refers to a language in a generic way -- sometimes it is the actual language name used to select it, sometimes it is a file name loading a language with a different name, sometimes it is a file name loading several languages. Please, read the documentation for specific languages for further info. \end{note} \begin{troubleshooting} 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{note} With \textsf{hyperref} you may want to set the 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. The document language can be also set with |\DocumentMetadata|, before |\documentclass|; for example: \begin{verbatim} \DocumentMetadata{_lang=es-MX_} \end{verbatim} \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} \Babel{} does not make any readjustments by default in font size, vertical positioning or line height by default. 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} \subsection{Multilingual documents} In multilingual documents, just use a list of the required languages as package or class options. The last language is considered the main one, activated by default. Sometimes, the main language changes the document layout (eg, |spanish| and |french|). \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} You can also set the main language explicitly, but it is discouraged except if there is a real reason to do so: \begin{verbatim} \documentclass{article} \usepackage[_main=english_,dutch]{babel} \end{verbatim} Examples of cases where |main| is useful are the following. \begin{example} 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} \end{example} \begin{note} Languages may 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|: \begin{verbatim} \documentclass[_italian_]{book} \usepackage[ngerman,_main=italian_]{babel} \end{verbatim} \end{note} \begin{warning} In the preamble the main language has \textit{not} been selected, except hyphenation patterns and the name assigned to |\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} 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} 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 \xetex{} and \luatex, 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} \prefacename, \alsoname, \today. \selectlanguage{vietnamese} \prefacename, \alsoname, \today. \end{document} \end{verbatim} \end{example} \begin{note} Once loaded a language, you can select it with the corresponding BCP47 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{Mostly monolingual documents} \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, \babel{} now does not require declaring these secondary languages explicitly, because the basic settings are loaded on the fly when the language is selected (and also when provided in the optional argument of |\babelfont|, if used). This is particularly useful, too, when there are short texts of this kind coming from an external source whose contents are not known on beforehand (for example, titles in a bibliography). At 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 (actually, with |\babelprovide|, because this is the macro used internally to load it) 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} \end{example} \begin{note} Instead of its name, you may prefer to select the language with the corresponding BCP47 tag. This alternative, however, must be activated explicitly, because a two- or tree-letter word is a valid name for a language (eg, |lu| can be the locale name with tag |khb| or the tag for |lubakatanga|). See section \ref{bcp47} for further details. \end{note} \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 are provided because languages and their scripts have quite different needs.} \begin{verbatim} \usepackage[latin_.medieval_, spanish_.notilde.lcroman_, danish]{babel} \end{verbatim} Attributes (described below) are considered modifiers, ie, 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{Troubleshooting} \begin{itemize} \item Loading directly |sty| files in \LaTeX{} (ie, |\usepackage|\marg{language}) is deprecated and you will get the error:\footnote{In old versions the error read ``You have used an old interface to call babel'', not very helpful.} \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} \item Another typical error when using \babel{} is the following:\footnote{In old versions the error read ``You haven't loaded the language LANG yet''.} \trouble{Unknown language `LANG'} \begin{verbatim} ! Package babel Error: Unknown language `#1'. 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{itemize} \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} \subsection{Basic language 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*| and |hyphenrules| are auxiliary, and described in the next section. The main language is selected automatically when the |document| environment begins. \Describe{\selectlanguage}{\marg{language}} When a user wants to switch from one language to another he can do so using the macro |\selectlanguage|. This macro takes the language, defined previously by a language definition file, as its argument. It calls several macros that should be defined in the language definition files to activate the special definitions for the language chosen: \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} For ``historical reasons'', a macro name is converted to a language name without the leading |\|; in other words, |\selectlanguage{\german}| is equivalent to |\selectlanguage{german}|. Using a macro instead of a ``real'' name is deprecated. \New{3.43} However, if the macro name does not match any language, it will get expanded as expected. \end{note} \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 there might be some non-local changes, as this would be roughly equivalent to: \begin{verbatim} {\selectlanguage{} ...}\selectlanguage{} \end{verbatim} If you want a change which is really local, you must enclose this code with an additional grouping level. \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 |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=|\m{mode}|}|, where \m{mode} is |shift| (which shifts the skips down and adds a |\penalty|); |keep| (the default -- with it the |\write| and the skips are kept in the order they are written), and |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{warning} \Describe{\foreignlanguage}{\oarg{option-list}\marg{language}\marg{text}} The command |\foreignlanguage| takes two arguments; the second argument is a phrase to be typeset according to the rules of the language named in its first 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. \end{note} \subsection{Auxiliary language selectors} \Describe{\begin\menv{otherlanguage}}{\marg{language}\Eenv{otherlanguage}} The environment \Lenv{otherlanguage} does basically the same as |\selectlanguage|, except that language change is (mostly) local to the environment. Actually, there might be some non-local changes, as this environment is roughly equivalent to: \begin{verbatim} \begingroup \selectlanguage{} ... \endgroup \selectlanguage{} \end{verbatim} If you want a change which is really local, you must enclose this environment with an additional grouping, like braces |{}|. Spaces after the environment are ignored.\footnote{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.} If this behavior is not desired, you may use the environment \texttt{selectlanguage}. \begin{warning} Being similar to |\selectlanguage|, the warning above about the internal |\write| also applies here. The current mode (vertical or horizonal) is also not changed. \end{warning} \Describe{\begin\menv{otherlanguage*}}% {\oarg{option-list}\marg{language}\Eenv{otherlanguage*}} Same as |\foreignlanguage| but as environment. Spaces after the environment are \textit{not} ignored. This environment was originally intended for intermixing left-to-right typesetting with right-to-left typesetting in engines not supporting a change in the writing direction inside a line. However, by default it never complied with the documented behavior and it is just a version as environment of |\foreignlanguage|, except when the option |bidi| is set -- in this case, |\foreignlanguage| emits a |\leavevmode|, while |otherlanguage*| does not. \subsection{More on selection} \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|\m{tag1}\marg{text} to be |\foreignlanguage|\marg{language1}\marg{text}, and |\begin|\marg{tag1} to be |\begin{otherlanguage*}|\marg{language1}, and so on. Note |\|\m{tag1} is also allowed, but remember 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} \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|.\footnote{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 (eg, |\TeX| of |\dag|). With |ini| files (see below), captions are ensured by default. \subsection{Shorthands} 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 \xetex{} and \luatex{} 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 be still 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 (eg,~|:|), 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, eg, |\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 (eg,~|"}|). Just add |{}| after (eg,~|"{}}|). \end{troubleshooting} \Describe{\shorthandon}{\marg{shorthands-list}} \DescribeOther{\shorthandoff}{% \colorbox{thegrey}{\ttfamily\hskip-.2em*\hskip-.2em}% \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 only work on `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 these macros are meant for temporary changes. Whenever possible and if there are not conflicts with other packages, shorthands must be always enabled (or disabled). \end{warning} \Describe{\useshorthands}{% \colorbox{thegrey}{\ttfamily\hskip-.2em*\hskip-.2em}% \marg{char}} The command |\useshorthands| 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. Currently, if the package option |shorthands| is used, you must include any character to be activated with |\useshorthands|. This restriction will be lifted in a future release. % <- TODO \Describe\defineshorthand{\texttt{[}\langlist\texttt{]}% \marg{shorthand}\marg{code}} The command |\defineshorthand| 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{lang} to the corresponding |\extras|\m{lang}, 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 (new in 3.9) take precedence over ``normal'' user shorthands. \begin{example} Let's assume you want a unified set of shorthand 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 one above only applies for the rest of languages; 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}} The command |\languageshorthands| can be 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 easy 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, ie, 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.\footnote{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} \subsection{Package options} \New{3.9a} These package options are processed before language options, so that they are taken into account irrespective of its 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{activeacute}{} For some languages \babel\ supports this options to set |'| as a shorthand in case it is not done by default. \Describe{activegrave}{} Same for |`|. \Describe{shorthands=}{\meta{char}\meta{char}... $\string|$ \texttt{off}} The only language shorthands activated are those given, like, eg: \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 $\epsilon$\TeX{} based engines (ie, 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. \Describe{config=}{\meta{file}} Load \meta{file}\texttt{.cfg} instead of the default config file |bblopts.cfg| (the file is loaded even with |noconfigs|). \Describe{main=}{\meta{language}} Sets the main language, as explained above, ie, this language is always loaded last. If it is not given as package or global option, it is added to the list of requested languages. \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 foots. An alternative is to set the language explicitly when heads and foots 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{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{nocase}{} \New{3.9l} Language settings for uppercase and % lowercase mapping (as set by |\SetCase|) are ignored. Use only if there % are incompatibilities with other packages. \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;\footnote{Duplicated options count as several ones.} \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 foots (if the option |headfoot| is used) and in auxiliary files (ie, 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 \xetex{} or \luatex{} 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{*}} \New{3.49} An alternative to |\babelprovide| for languages passed as options. See section~\ref{inifiles}, which describes also the variants |provide+=| and |provide*=|. \subsection{The \texttt{base} option} With this package option \babel{} just loads some basic macros (those in |switch.def|), defines |\AfterBabelLanguage| and exits. It also selects the hyphenation patterns for the last language passed as option (by its name in |language.dat|). There are two main uses: classes and packages, and as a last resort in case there are, for some reason, incompatible languages. It can be used if you just want to select the hyphenation patterns of a single language, too. \Describe\AfterBabelLanguage{\marg{option-name}\marg{code}} This command is currently the only provided by |base|. 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: \begin{verbatim} \usepackage[base]{babel} \AfterBabelLanguage{foo}{% \let\macroFoo\macro \let\macro\relax} \usepackage[foo,bar]{babel} \end{verbatim} \end{example} \begin{note} With a recent version of \LaTeX, an alternative method to execute some code just after an |ldf| file is loaded is with |\AddToHook| and the hook |file/.ldf/after|. \Babel{} does not predeclare it, and you have to do it yourself with |\ActivateGenericHook|. \end{note} \begin{warning} Currently this option is not compatible with languages loaded on the fly. \end{warning} \subsection{\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 360 of these files containing the basic data required for a locale, covering about 270 languages, 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 easy 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, too (the main exception being the |\...name| strings). 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|. In other words, |\babelprovide| is mainly meant for auxiliary tasks, and as alternative when the |ldf|, for some reason, does not exists or does not work as expected. \begin{example} Although Georgian has its own \texttt{ldf} file, here is how to declare this language with an |ini| file in Unicode engines. \setengine{luatex/xetex} \begin{verbatim} \documentclass{book} \usepackage{babel} _\babelprovide[import, main]{georgian}_ \babelfont{rm}[Renderer=Harfbuzz]{DejaVu Sans} \begin{document} \tableofcontents \chapter{სამზარეულო და სუფრის ტრადიციები} ქართული ტრადიციული სამზარეულო ერთ-ერთი უმდიდრესია მთელ მსოფლიოში. \end{document} \end{verbatim} \end{example} \begin{more} There is an example of how to use a template |ini| file \href{https://github.com/latex3/babel/issues/176#issuecomment-1080846575}{here}, for Phoenician. \end{more} \New{3.49} Alternatively, you can tell babel to load all or some languages passed as options with |\babelprovide| and not from the |ldf| file in a few few typical cases. Thus, |provide=*| means ‘load the main language with the |\babelprovide| mechanism instead of the |ldf| file’ applying the basic features, which in this case means |import,| |main|. There are (currently) three options: \begin{itemize} \item |provide=*| is the option just explained, for the main language; \item |provide+=*| is the same for additional languages (the main language is still the |ldf| file); \item |provide*=*| is the same for all languages, ie, main and additional. \end{itemize} \begin{example} The preamble in the previous example can be more compactly written as: \begin{verbatim} \documentclass{book} \usepackage[_georgian, provide=*_]{babel} \babelfont{rm}[Renderer=Harfbuzz]{DejaVu Sans} \end{verbatim} Or also: \begin{verbatim} \documentclass[_georgian_]{book} \usepackage[_provide=*_]{babel} \babelfont{rm}[Renderer=Harfbuzz]{DejaVu Sans} \end{verbatim} \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). The Harfbuzz renderer still has some issues, so as a rule of thumb prefer the default renderer, and resort to Harfbuzz only if the former does not work for you. Fortunately, fonts can be loaded twice with different renderers; for example: \begin{verbatim} \babelfont[spanish]{rm}{FreeSerif} \babelfont[hindi]{rm}[Renderer=Harfbuzz]{FreeSerif} \end{verbatim} \begin{description} \itemsep=-\parskip \item[Arabic] Monolingual documents mostly work in \luatex, but it must be fine tuned, particularly math and graphical elements like |picture|. In \xetex{} \babel{} resorts to the \textsf{bidi} package, which seems to work. \item[Hebrew] Niqqud marks seem to work in both engines, but depending on the font cantillation marks might be misplaced (\xetex{} or \luatex{} with Harfbuzz seems better). \item[Devanagari] In \luatex{} and the default renderer many fonts work, but some others do not, the main issue being the ‘ra’. You may need to set explicitly the script to either |deva| or |dev2|, eg: \begin{verbatim} \newfontscript{Devanagari}{deva} \end{verbatim} Other Indic scripts are still under development in the default \luatex{} renderer, but should work with |Renderer=Harfbuzz|. They also work with \xetex{}, although unlike with \luatex{} fine tuning the font behavior is not always possible. \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{}. Khemer clusters are rendered wrongly with the default renderer. The comment about Indic scripts and \textsf{lualatex} also applies here. 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 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 then 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} \textbf{Modifying and adding values to |ini| files} \nobreak \New{3.39} There is a way to modify the values of |ini| files when they get loaded with |\babelprovide| and |import|. To set, say, |digits.native| in the |numbers| section, use something like |numbers/digits.native=abcdefghij|. Keys may be added, too. Without |import| you may modify the identification keys. 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. % \begin{example} % Let's assume you need only the basic features of `spanish`, so that % the |ini| file is enough, and also a variant with your own % hyphenation with % \end{example} \subsection{List of locales available in \cs{babelprovide}} 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. Many locale are quite useable, 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. \begin{note} Although the names of the corresponding |lfd| files match those in this list, there are some exceptions, particularly in German and Serbian. So, |ngerman| is called here |german|, which is the name in the CLDR and, actually, the most logical. \end{note} \begingroup \bigskip\hrule\nobreak \makeatletter \def\tag#1{\par\@hangfrom{\makebox[10em][l]{#1}}\ignorespaces} \def\tag#1#2#3{\par \hspace{-2em}\textcolor{thered}{\texttt{#1}}#2\enspace \mbox{\footnotesize(#3)}} \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)}} \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. \bigskip\hrule\nobreak \begin{multicols}{2} \leftskip2em \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} \tag{amharic}{\hascapu\hascapl}{am} \tagmin{ancientegyptian}{}{egy} \tag{ancientgreek}{\hascapu\hascapl}{grc}\note{It’s a different language from \texttt{greek}.} \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} \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{bengali}{\hascapu}{bn} \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} \tag{catalan}{\hascapu\hascapl}{ca} \tag{cebuano}{}{ceb} \tag{centralatlastamazight}{}{tzm} \tag{centralkurdish}{\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} \subtagalt{australian}{\hascapu\hascapl}{en-AU} \subtag{australianenglish}{\hascapu\hascapl}{en-AU} \subtagalt{british}{\hascapu\hascapl}{en-GB} \subtag{britishenglish}{\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{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} \tag{ewe}{}{ee} \tag{ewondo}{}{ewo} \tag{faroese}{}{fo} \tag{farsi}{\hascapu}{fa} \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\hascapl\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{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{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{kurmanji}{\hascapu\hascapl}{kmr} \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} \tag{lubakatanga}{}{lu} \tag{luo}{}{luo} \tag{luxembourgish}{\hascapu\hascapl}{lb} \tag{luyia}{}{luy} \tag{macedonian}{\hascapu\hascapl}{mk} \tag{machame}{}{jmc} \tag{magyar}{\hascapu\hascapl\hascapl\hascapl}{hu} \tag{maithili}{}{mai} \tagmin{makasar}{}{mak} \subtagmin{makasar-bugi}{}{mak-Bugi} \subtagmin{makasar-buginese}{}{mak-Bugi} \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{newzealand}{\hascapu\hascapl}{en-NZ} % \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{northernkurdish-arab}{\hascapu}{kmr-Arab} \subtag{northernkurdish-arabic}{\hascapu}{kmr-Arab} \tag{northernluri}{}{lrc} \tag{northernsami}{\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{nswissgerman}{\hascapu\hascapl}{de-CH} \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} \tagmin{oldnorse}{}{non} % \tag{oriya}{\hascapu}{or} \tag{oromo}{}{om} \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} \tag{saho}{}{ssy} \tag{sakha}{}{sah} \tagmin{samaritan}{}{smp} \tag{samburu}{}{saq} \tag{samin}{\hascapu\hascapl}{se} \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{slovene}{\hascapu\hascapl}{sl} \tag{slovenian}{\hascapu\hascapl}{sl} \tag{soga}{}{xog} \tag{somali}{}{so} \tag{sorani}{\hascapu}{ckb} \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} \tag{ukenglish}{\hascapu\hascapl}{en-GB} \tag{ukrainian}{\hascapu\hascapl}{uk} \tag{uppersorbian}{\hascapu\hascapl}{hsb} \tag{urdu}{\hascapu}{ur} \tag{usenglish}{\hascapu\hascapl}{en-US} \tag{usorbian}{\hascapu\hascapl}{hsb} \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{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{zulu}{}{zu} \end{multicols} \endgroup \hrule \bigskip \subsection{Selecting fonts} \New{3.15} Babel provides a high level interface on top of |fontspec| to select fonts. There is no need to load \textsf{fontspec} explicitly -- \babel{} does it for you with the first |\babelfont|.\footnote{See also the package \textsf{combofont} for a complementary approach.} \Describe\babelfont{\oarg{language-list}\marg{font-family}% \oarg{font-options}\marg{font-name}} \begin{note} See the note in the previous section about some issues in specific languages. \end{note} The main purpose of |\babelfont| is to define at once in a multilingual document 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, activated when a language is selected. On the other hand, if there is one or more languages in the optional argument, the font will be assigned to them, overriding the default one. Alternatively, you may set a font for a script -- just precede its name (lowercase) with a star (eg, |*devanagari|). With this optional argument, the font is \textit{not} yet defined, but just predeclared. This 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); see the recognized languages above. 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. \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. \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} |\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. \begin{example} Here is how to do it: \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 it is not detected correctly. % You may also pass some % options to \textsf{fontspec}: with |silent|, the warnings about % unavailable scripts or languages are not shown (they are only really % useful when the document format is being set up). \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{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 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} \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 Davis M. Jones. After installing them in you distribution, just set the map as you would do with \textsf{fontspec}. \end{note} \subsection{Modifying a language} Modifying the behavior of a language (say, the chapter “caption”), is sometimes necessary, but not always trivial. In the case of caption names a specific macro is provided, because this is perhaps the most frequent change: \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. \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, 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 ‘old way’, still valid for many languages, to redefine a caption 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|, 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 add to |\extras|\m{lang}: \begin{verbatim} \addto\extrasrussian{\mymacro} \end{verbatim} There is a counterpart for code to be run when a language is unselected: |\noextras|\m{lang}. \begin{note} These macros (|\captions|\m{lang}, |\extras|\m{lang}) 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[captions=da, hyphenrules=nohyphenation]{danish} \end{verbatim} first loads |danish.ldf|, and then redefines the captions for \texttt{danish} (as provided by the |ini| file) and prevents hyphenation. 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. \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 (eg, you decide to tag |english| as |en-001| instead of |en-US|), the new mappings will be still 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{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 that 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} \renewcommand\arhinishhyphenmins{22} \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), and so on. \end{example} \begin{example} Locales with names based on BCP 47 codes can be created with something like: \begin{verbatim} \babelprovide[import=en-US]{enUS} \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{language-tag}} \New{3.13} Imports data from an |ini| file, including captions and date (also line breaking rules in newly defined languages). For example: \begin{verbatim} \babelprovide[_import=hu_]{hungarian} \end{verbatim} Unicode engines load the UTF-8 variants, while 8-bit engines load the LICR (ie, with macros like |\'| or |\ss|) ones. \New{3.23} It may be used without a value, and that is often the recommended option. In such a case, the |ini| file set in the corresponding |babel-.tex| (where || is the last argument in |\babelprovide|) is imported. See the list of recognized languages above. So, the previous example is best written as: \begin{verbatim} \babelprovide[_import_]{hungarian} \end{verbatim} There are about 250 |ini| files, with data taken from the |ldf| files and the CLDR provided by Unicode. Not all languages in the latter 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. Besides |\today|, this option defines an additional command for dates: |\date|, which takes three arguments, namely, year, month and day numbers. In fact, |\today| calls |\today|, which in turn calls |\date{\the\year}{\the\month}{\the\day}|. \New{3.44} More convenient is usually |\localedate|, with prints the date for the current locale. \Describe{captions=}{\meta{language-tag}} Loads only the strings. For example: \begin{verbatim} \babelprovide[_captions=hu_]{hungarian} \end{verbatim} \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). Only in newly defined languages. \begin{example} Let's assume your document (\xetex{} or \luatex{}) is mainly in Polytonic Greek with 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} Remerber 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} (eg, |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} (eg, |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 ↔ V; |uv| in |ecclesianticallatin| and the basic |latin| locale applies the map u ↔ V (by default it’s u ↔ U and v ↔ 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). There are currently two ‘actions’, which can be used at the same time (separated by a space): with |ids| the |\language| and the |\localeid| are set to the values of this locale; with |fonts|, the fonts are changed to those of this locale (as set with |\babelfont|). Characters can be added or modified with |\babelcharproperty|. \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 in non-Latin and there is a secondary one whose script is Latin. \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 be still necessary. \end{note} \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 scrips, 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 scrips, like Thai. Ignored if 0 (which is the default value). \Describe{transforms=}{\meta{transform-list}} See section~\ref{transforms}. \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 spaces to 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 sets 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. \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} \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: |\digits| and |\counter| (only \xetex{} and \luatex{}). 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, and note as well dates do not rely on |\arabic|.) For example: \begin{verbatim} \babelprovide[import]{telugu} % Or also, if you want: % \babelprovide[import, maparabic]{telugu} \babelfont{rm}{Gautami} % With luatex, better with Harfbuzz \begin{document} _\telugudigits{1234}_ _\telugucounter{section}_ \end{document} \end{verbatim} Languages providing native digits in all or some variants are: \begin{multicols}{5} 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 (ie, 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). \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 \xetex{} and \luatex{} 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|. \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 in those in the corresponding calendar. They are \textit{not} the Gregorian data 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{Accessing language info} \Describe{\languagename}{} The control sequence |\languagename| contains the name of the current language. \begin{warning} Due to some internal inconsistencies in catcodes, it should \textit{not} be used to test its value. Use \textsf{iflang}, by Heiko Oberdiek. \end{warning} \Describe{\iflanguage}{\marg{language}\marg{true}\marg{false}} If more than one language is used, it might be necessary to know which language is active at a specific time. This can be checked by a call to |\iflanguage|, but note here ``language'' is used in the \TeX{} sense, as a set of hyphenation patterns, and \textit{not} as its \textsf{babel} name. This macro takes three arguments. The first argument is the name of a language; the second and third arguments are the actions to take if the result of the test is true or false respectively. \Describe{\localeinfo}{% \colorbox{thegrey}{\ttfamily\hskip-.2em*\hskip-.2em}{\marg{field}}} \New{3.38} If an |ini| file has been loaded for the current language, you may access the information stored in it. This macro is fully expandable, and the available fields are: \begin{description} \itemsep=-\parskip \item[|name.english|] as provided by the Unicode CLDR. %%% \item[|name.locale|] is the equivalent of |\languagename|. Not yet %%% activated because the bug in \languagename is far from trivial. \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 (see the warning below). 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). \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 be always defined. \item[|script.tag.opentype|] is the tag used by OpenType (usually, but not always, the same as BCP 47). \item[|region.tag.bcp47|] is the BCP 47 tag of the region or territory. Defined only if the locale loaded actually contains it (eg, |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} \begin{note} Currently, |x| is used for two separate functions, namely, identifying a \babel{} locale without a BCP47 tag and setting an alternative set of rules for casing. \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} \New{3.75} Sometimes, it comes in handy to be able to use |\localeinfo| in an 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. 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 |\localeinfo*{language.tab.bcp47}|\allowbreak |-|\allowbreak |\localeinfo*{region.tab.bcp47}| is not usually a good idea (because of the hyphen). \Describe{\getlocaleproperty}{% \colorbox{thegrey}{\ttfamily\hskip-.2em*\hskip-.2em}% \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 patters (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. \Describe{ensureinfo=off}{} \New{3.75} Previously, |ini| files were loaded only with |\babelprovide| and also when languages are selected if there is a |\babelfont| or they have not been explicitly declared. Now the |ini| files are loaded (and therefore the corresponding data) even if these two conditions are not met (in previous versions you had to enable it with |\BabelEnsureInfo| in the preamble). Because of the way this feature works, problems are very unlikely, but there is switch as a package option to turn the new behavior off (|ensureinfo=off|). \subsection{Hyphenation and line breaking} \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), while \luatex{} provides basic rules for the latter, too. With \luatex{} there are also tools for non-standard hyphenation rules, explained in the next section. \Describe{\babelhyphen}{% \colorbox{thegrey}{\ttfamily\hskip-.2em*\hskip-.2em}\marg{type}} \DescribeOther\babelhyphen{% \colorbox{thegrey}{\ttfamily\hskip-.2em*\hskip-.2em}\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 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 (eg, \textit{anti-}) and |nobreak| for isolated suffixes (eg, \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 |-|, like 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\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 (eg, 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|\m{lang} as well as the language-specific encoding (not set in the preamble by default). Multiple |\babelhyphenation|'s are allowed. 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). 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{\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 (eg, \textsf{italian}, \textsf{french}, \textsf{ukrainian}). \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|\m{lang} 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 Khemer is activated automatically if a language with one of those scripts are 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 (eg, \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} \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.\footnote{They are similar in concept, but not the same, as those in Unicode. The main inspiration for this feature is the Omega transformation processes.} 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} % \strut\hfil Transforms % \medskip\hrule\nobreak \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{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 of 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{Finnish}{prehyphen.nobreak}{Line breaks just after hyphens prepended to words are prevented, like in “pakastekaapit ja -arkut”.} \trans{French}{punctuation.space}{Rules for proper spacing with characters \textit{;:!?«»} are applied.} \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 transforms does it. To prevent the conversion (an abbreviation, for example), write |"s|.} \trans{Hebrew, Yiddish}{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{Hindi, Sanskrit}{transliteration.hk}{The Harvard-Kyoto system to romanize Devanagari.} \trans{Hindi, Sanskrit}{punctuation.space}{Inserts a space before the following four characters: \textit{!?:;}\,.} \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{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{Sanskrit}{transliteration.iast}{The IAST system to romanize Devanagari.\footnote{Thanks to Maximilian Mehner}} \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.} \trans{Arabic, Persian}{kashida.plain}{Experimental. A very simple and basic transform for ‘plain’ Arabic fonts, which attempts to distribute the tatwil as evenly as possible (starting at the end of the line). See the news for version 3.59.} \trans{Arabic, Persian}{kashida.base}{Experimental \New{3.94}. Much like the previous one, but with diacritics stacked in the actual base character and not the kashida extension. With evenly inserted tatweels results are better.} \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.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 its name, with a list separated with colons, like: \begin{verbatim} transforms = _rm:sf:_transform.name \end{verbatim} \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|). Although the main purpose of this command is non-standard hyphenation, it may actually be used for other transformations (after hyphenation is applied, so you must take discretionaries into account). You are limited to substitutions as done by \textsf{lua}, although a future implementation may alternatively accept \textsf{lpeg}. \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. \subsection{Support for \xetex{} 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 (eg,~|\}|). If you need to enter them by their numeric value, use the \TeX{} |^|-notation (eg,~|^^^^1fa0|). Ranges are allowed, with a hyphen (eg,~|.,;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 (currently CJK classes are ‘empty’, but they will be assigned in a future release). \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 there is a set of rules for French named |punctuation.space|, which applies proper spacing with characters \textit{;:!?«»}. \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{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 on beforehand which languages will be requested. It must be activated explicitly, because it is primarily meant for special tasks. Mapping from BCP 47 codes to locale names are not hardcoded in \babel. Instead the data is taken from the \texttt{ini} files, which means currently about 250 tags are already recognized. \Babel{} performs a simple lookup in the following way: |fr-Latn-FR| $\to$ |fr-Latn| $\to$ |fr-FR| $\to$ |fr|. Languages with the same resolved name are considered the same. Case is normalized before, so that |fr-latn-fr| $\to$ |fr-Latn-FR|. If a tag and a name overlap, the tag takes precedence. Here is a minimal example: \begin{verbatim} \documentclass{article} \usepackage[danish]{babel} _\babeladjust{_ _ autoload.bcp47 = on,_ _ autoload.bcp47.options = import_ _}_ \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 behaviour is adjusted with |\babeladjust| with the following parameters: \begin{description} \item \texttt{autoload.bcp47} with values |on| and |off|. \item \texttt{autoload.bcp47.options}, which are passed to |\babelprovide|; empty by default, but you may add \texttt{import} (features defined in the corresponding |babel-...tex| file might not be available). \item \texttt{autoload.bcp47.prefix}. Although the public name used in selectors is the tag, the internal name will be different and generated by prepending a prefix, which by default is \texttt{bcp47-}. You may change it with this key. \end{description} \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. \subsection{Selecting scripts} Currently \babel{} provides no standard interface to select scripts, because they are best selected with either |\fontencoding| (low-level) or a language name (high-level). Even the Latin script may require different encodings (ie, sets of glyphs) depending on the language, and therefore such a switch would be in a sense incomplete.\footnote{The so-called Unicode fonts 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.} Some languages sharing the same script define macros to switch it (eg, |\textcyrillic|), but be aware they may also set the language to a certain default. Even the \babel{} core defined |\textlatin|, but is 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.\footnote{But still defined for backwards compatibility.} \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{Selecting directions} \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 (eg, 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 ). 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 reason 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 \xetex{} and \pdftex{} this is the only option. In \luatex, |basic-r| provides a simple and fast method for R text, which handles numbers and unmarked L text within an R context many in typical cases. \New{3.19} Finally, |basic| supports both L and R text, and it is the preferred method (support for |basic-r| is currently limited). (They are named \texttt{basic} mainly because they only consider the intrinsic direction of scripts and weak directionality.) \New{3.29} In \xetex, |bidi-r| and |bidi-l| resort to the package \textsf{bidi} (by Vafa Khalighi). Integration is still somewhat tentative, but it mostly works. For RL documents use the former, and for LR ones use the latter. 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} \begin{verbatim} \documentclass{article} \usepackage[_bidi=basic_]{babel} _\babelprovide[import, main]{arabic}_ \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 only necessary 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|$ \texttt{columns} $\string|$ \texttt{graphics} $\string|$ \texttt{extras}} \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 (eg, \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; 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}. \end{description} \begin{example} Typically, in an Arabic document you would need: \begin{verbatim} \usepackage[bidi=basic, 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 explictly; 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 directly these values 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}{\languagename}{(}{)} \end{verbatim} defines |\parsfootnote| so that |\parsfootnote{note}| is equivalent to: \begin{verbatim} \footnote{(\foreignlanguage{\languagename}{note})} \end{verbatim} but the footnote itself is typeset in the main language (to unify its direction). In addition, |\parsfootnotetext| is defined. The option |footnotes| just does the following: \begin{verbatim} \BabelFootnote{\footnote}{\languagename}{}{}% \BabelFootnote{\localfootnote}{\languagename}{}{}% \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. Note this command is available always in bidi documents, even without |layout=footnotes|. \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 the end of the footnote text should be omitted. \end{example} \subsection{Language attributes} \DescribeMacro{\languageattribute} 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. Very often, using a \textit{modifier} in a package option is better. 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 (eg, |\ProsodicMarksOn| in \textsf{latin}). \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/|\m{language-name}|/|\m{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{lang}\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 \xetex{} and \luatex{} 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|\m{language}. This event and the next one should not contain language-dependent code (for that, add it to |\extras|\m{language}). \item[afterextras] Just after executing |\extras|\m{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|\m{language} and |\date|\m{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). % STILL UNDER STUDY: % \item[beforestart] \New{3.34} Executed either at the beginning of the % |aux| file (when read at the start of the document), or else at begin % document. In other words, it makes sure the code is executed always % and executed once. But be aware it is a somewhat dangerous, because % the scope in the first case is local, while in the second case is % global, so be careful with assignments. \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/|\m{language-name}|/|\m{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} \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| (it's up to you to make sure no toc type is duplicated). \subsection{Languages supported by \babel{} with \textsf{ldf} files} In the following table most of the languages supported by \babel{} with and |.ldf| file are listed, together with the names of the option 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 (eg, |ngerman|, |serbianc|, |acadian|) names are those of the Unicode CLDR (or based on them). \begin{description} \itemsep=-\parskip \sffamily \item[Afrikaans] afrikaans \item[Azerbaijani] azerbaijani \item[Basque] basque \item[Breton] breton \item[Bulgarian] bulgarian \item[Catalan] catalan \item[Croatian] croatian \item[Czech] czech \item[Danish] danish \item[Dutch] dutch \item[English] english, american (\textit{preferred to} USenglish), british (\textit{preferred to} UKenglish), canadian, australian, newzealand \item[Esperanto] esperanto \item[Estonian] estonian \item[Finnish] finnish \item[French] french, acadian \item[Galician] galician \item[German] ngerman, naustrian, german, austrian \item[Greek] greek, polutonikogreek \item[Hebrew] hebrew \item[Icelandic] icelandic \item[Indonesian] indonesian \item[Interlingua] interlingua \item[Irish Gaelic] irish \item[Italian] italian \item[Latin] latin \item[Lower Sorbian] lowersorbian \item[Malay] malay (\textit{preferred to} melayu) \item[Northern Sami] northernsami \item[Norwegian] norsk, nynorsk \item[Polish] polish \item[Portuguese] portuguese, brazilian \item[Romanian] romanian \item[Russian] russian \item[Scottish Gaelic] scottishgaelic (\textit{preferred to} scottish) \item[Spanish] spanish \item[Slovakian] slovak \item[Slovenian] slovene \item[Swedish] swedish \item[Serbian] serbian \item[Turkish] turkish \item[Ukrainian] ukrainian \item[Upper Sorbian] uppersorbian \item[Welsh] welsh \end{description} There are more languages not listed above, including \textsf{hindi, thai, thaicjk, latvian, turkmen, magyar, mongolian, romansh, lithuanian, spanglish, vietnamese, japanese, pinyin, arabic, farsi, ibygreek, bgreek, serbianc, frenchle, ethiop} and \textsf{friulan}. \begin{note} There are also some deprecated names (a few has been even removed): \textsf{frenchb} or \textsf{francais}, as well as \textsf{canadien} (\textsf{french}), \textsf{germanb} (\textsf{german}), \textsf{bahasa}, \textsf{indon} or \textsf{bahasai} (\textsf{indonesian}), \textsf{lsorbian} (\textsf{lowersorbian}), \textsf{bahasam} (\textsf{malay}), \textsf{portuges} (\textsf{portuguese}), \textsf{brazil} (\textsf{brazilian}), \textsf{russianb} (\textsf{russian}), \textsf{usorbian} (\textsf{uppersorbian}), \textsf{vietnam} (\textsf{vietnamese}), \textsf{samin} (\textsf{northernsami}), \textsf{ukraineb} (\textsf{ukrainian}). Deprecated names come in many cases from the times when they had to be shortened to 8 characters. \end{note} 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}). For example, if you have got the \textsf{velthuis/devnag} package, you can 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 you preprocess it with |devnag| \m{file}, which creates \m{file}|.tex|; you can then typeset the latter with \LaTeX. \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 (ie, 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 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 the 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|). \subsection{Tips, workarounds, known issues and notes} \begin{itemize} \item 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). \item 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 (but it is in the `to do' list). \item Using a character mathematically active (ie, with math code |"8000|) as a shorthand can make \TeX{} enter in an infinite loop in some rare cases. (Another issue in the ‘to do’ list, although there is a partial solution.) \end{itemize} The following packages can be useful, too (the list is still far from complete): \begin{description} \itemsep=-\parskip \item[csquotes] Logical markup for quotes. \item[iflang] Tests correctly the current language. \item[hyphsubst] Selects a different set of patterns for a language. \item[translator] An open platform for packages that need to be localized. \item[siunitx] Typesetting of numbers and physical quantities. \item[biblatex] Programmable bibliographies and citations. \item[bicaption] Bilingual captions. \item[babelbib] Multilingual bibliographies. \item[microtype] Adjusts the typesetting according to some languages (kerning and spacing). Ligatures can be disabled. \item[substitutefont] Combines fonts in several encodings. \item[mkpattern] Generates hyphenation patterns. \item[tracklang] Tracks which languages have been requested. \item[ucharclasses] (\xetex) Switches fonts when you switch from one Unicode block to another. \item[zhspacing] Spacing for CJK documents in \xetex. \end{description} \subsection{Current and future work} The current work is focused on the so-called complex scripts in \luatex{}. In 8-bit engines, \babel{} provided a basic support for bidi text as part of the style for Hebrew, but it is somewhat unsatisfactory and internally replaces some hardwired commands by other hardwired commands (generic changes would be much better). Useful additions would be, for example, time, currency, addresses and personal names.\footnote{See for example POSIX, ISO 14652 and the Unicode Common Locale Data Repository (CLDR). Those systems, however, have limited application to \TeX\ because their aim is just to display information and not fine typesetting.}. But that is the easy part, because they don't require modifying the \LaTeX{} internals. Calendars (Arabic, Persian, Indic, etc.) are under study. Also interesting are differences in the sentence structure or related to it. For example, in Basque the number precedes the name (including chapters), in Hungarian ``from (1)'' is ``(1)-b\H{o}l'', but ``from (3)'' is ``(3)-b\'{o}l'', in Spanish an item labelled ``3.$^{\textrm{\scriptsize o}}$'' may be referred to as either ``\'{\i}tem 3.$^{\textrm{\scriptsize o}}$'' or ``3.$^{\textrm{\scriptsize er}}$ \'{\i}tem'', and so on. An option to manage bidirectional document layout in \luatex{} (lists, footnotes, etc.) is almost finished, but \xetex{} required more work. Unfortunately, proper support for \xetex{} requires patching somehow lots of macros and packages (and some issues related to |\special|s remain, like color and hyperlinks), so \babel{} resorts to the \textsf{bidi} package (by Vafa Khalighi). See the \babel{} repository for a small example (|xe-bidi|). \subsection{Tentative and experimental code} See the code section for |\foreignlanguage*| (a new starred version of |\foreignlanguage|). For old an 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 (by default, no options). A typical value would be |import|, which defines captions, date, numerals, etc., but ignores the code in the |tex| file (for example, extended numerals in Greek). \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 languages with \file{language.dat}} \TeX{} and most engines based on it (pdf\TeX, \xetex, $\epsilon$-\TeX, the main exception being \luatex) require hyphenation patterns to be preloaded when a format is created (eg, \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).\footnote{This feature was added to 3.9o, but it was buggy. Both 3.9o and 3.9p are deprecated.} Until 3.9n, this task was delegated to the package \textsf{luatex-hyphen}, by Khaled Hosny, \'Elie Roux, and Manuel P\'egouri\'e-Gonnard, and required an extra file named |language.dat.lua|, but now a new mechanism has been devised based solely on |language.dat|. \textbf{You must rebuild the formats} if upgrading from a previous version. You may want to have a local |language.dat| for a particular project (for example, a book on Chemistry).\footnote{The loader for lua(e)tex is slightly different as it's not based on \babel{} but on \texttt{etex.src}. Until 3.9p it just didn't work, but thanks to the new code it works by reloading the data in the \babel{} way, i.e., with \texttt{language.dat}.} \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\footnote{This is because different operating systems sometimes use \emph{very} different file-naming conventions.}. 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 the patterns are intended for by following the language name by a colon and the encoding code.\footnote{This is not a new feature, but in former versions it didn't work correctly.} 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|\m{lang}). A typical error when using \babel{} is the following: \begin{verbatim} No hyphenation patterns were preloaded for the language `' into the format. Please, configure your TeX system to add them and rebuild the format. Now I will use the patterns preloaded for english instead}} \end{verbatim} It simply means you must reconfigure \file{language.dat}, either by hand or with the tools provided by your distribution. \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 (or a dialect); 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 (eg, \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|/|). \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 (eg, |=| in an ancient language). Note however |=|, |<|, |>|, |:| 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|\m{lang} except for umlauthigh and friends, |\bbl@deactivate|, |\bbl@(non)frenchspacing|, and language-specific macros. Use always, if 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|\m{lang}. \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.\footnote{But not removed, for backward compatibility.} \item Please, for ``private'' internal macros do not use the |\bbl@| prefix. It is used by \babel{} and it can lead to incompatibilities. \end{itemize} There are no special requirements for documenting your language files. Now they are not included in the base \babel{} manual, so provide a standalone document suited for your needs, 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 the fields, sent it to me. Fell 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 authors 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. \item \Babel{} 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 am willing 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. \DescribeMacro{\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| has no effect.) \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 a \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{} [2016/04/23 v0.0 support from the babel system] \LdfInit{}{captions} \ifx\undefined\l@ \@nopatterns{} \adddialect\l@0 \fi \adddialect\l@\l@ \bbl@declare@ttribute{}{}{% \expandafter\addto\expandafter\extras \expandafter{\extras}% \let\captions\captions} \providehyphenmins{}{\tw@\thr@@} \StartBabelCommands*{}{captions} \SetString\chaptername{} % More strings \StartBabelCommands*{}{date} \SetString\monthiname{} % More strings \StartBabelCommands*{}{captions} \SetString\chaptername{} % More strings \StartBabelCommands*{}{date} \SetString\monthiname{} % More strings \EndBabelCommands \addto\extras{} \addto\noextras{} \let\extras\extras \let\noextras\noextras \ldf@finish{} \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|), 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} The internal macro |\initiate@active@char| is 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} The command |\bbl@activate| is 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} The macro |\declare@shorthand| is 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} \DescribeMacro{\bbl@remove@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} and |\bbl@remove@special|\meta{char} add and remove 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 (ie, 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} The commands |\bbl@frenchspacing| and |\bbl@nonfrenchspacing| can be used to properly switch French spacing on and off. \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 consist is a series of blocks started with |\StartBabelCommands|. The last block is closed with |\EndBabelCommands|. Each block is a single group (ie, 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 no need to be wrapped with formatting commands (eg, 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 -- a explicit name (or names) is much better and clearer. A ``selector'' selects a group of definition are to be used, optionally followed by extra info about the encodings to be used. The name |unicode| must be used for \xetex{} and \luatex{}. Without a selector, the LICR representation (ie, 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 (ie, 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 |\|\m{category}\m{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, ie, if |\date|\m{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{% \colorbox{thegrey}{\ttfamily\hskip-.2em*\hskip-.2em}% \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.\footnote{This replaces in 3.9g a short-lived \texttt{\string\UseStrings} which has been removed because it did not work.} \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 separated 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 \xetex{} and \luatex{}) -- if an assignment is wrong, fix it directly. \end{note} \subsection{Executing 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|\m{language}. \else \DocInput{babel.dtx} \fi \section{Acknowledgements} I would like to thank all who volunteered as $\beta$-testers for their time. Michel Goossens supplied contributions for most of the other languages. Nico Poppelier helped polish the text of the documentation and supplied parts of the macros for the Dutch language. Paul Wackers and Werenfried Spit helped find and repair bugs. During the further development of the babel system I received much help from Bernd Raichle, for which I am grateful. 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, p.~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, p.~70--72. \bibitem{ilatex} Joachim Schrod, \emph{International \LaTeX\ is ready to use}, \emph{TUGboat} 11 (1990) \#1, p.~87--90. \bibitem{STS} Apostolos Syropoulos, Antonis Tsolomitis and Nick Sofroniu, \emph{Digital typography using \LaTeX}, Springer, 2002, p.~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} % % % \fi % % \addtolength{\oddsidemargin}{-15pt} % \addtolength{\textwidth}{50pt} % %\begingroup % \catcode`<=\active% % \catcode`>=\active % \makeatletter % \gdef\MakePrivateLetters{% % \catcode`@=11\relax % \gdef<##1{\ifx##1@$\langle\langle$\bgroup\itshape\rmfamily % \expandafter\bblref % \else\string<##1\fi}% % \gdef\bblref##1@>{##1\/\egroup$\rangle\rangle$}}% % \global\let\check@percent\saved@check@percent %\endgroup % % \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} % % \textit{Code documentation is still under revision.} % 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 |<||@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 (eg, with \textit{More package options}). That brings a % little bit of literate programming. The guards |<-name>| and % |<+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 250 languages. They are distributed as a % separate |zip| file, not packed as |dtx|. Most 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 (eg, 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} %<> %<> % \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} % % \begin{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} % % \end{macro} % % \begin{macro}{\bbl@afterelse} % \begin{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} % % \end{macro} % \end{macro} % % \begin{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} % \end{macro} % % \begin{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} % \end{macro} % % \begin{macro}{\bbl@ifunset} % To check if a macro is defined, we create a new macro, which does % the same as |\@ifundefined|. However, in an $\epsilon$-tex engine, % it is 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} % \end{macro} % % \begin{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, ie, 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} % \end{macro} % % For each element in the comma separated |=| list, % execute 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 alone, it passes |\@empty| (ie, the macro thus % named, not an empty argument, which is what you get with |=| % 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} % % \begin{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 (ie, 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}}% \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} % \end{macro} % % 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} %<> % \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 %<> % \end{macrocode} % % \subsection{Multiple languages} % % \begin{macro}{\language} % % Plain \TeX\ version~3.0 provides the primitive |\language| that % is used to store the current language. When used with a pre-3.0 % version this function has to be implemented by allocating a % counter. The following block is used in \file{switch.def} and % \file{hyphen.cfg}; the latter may seem redundant, but remember % \babel{} doesn't requires loading \file{switch.def} in the format. % % \begin{macrocode} %<<*Define core switching macros>> \ifx\language\@undefined \csname newcount\endcsname\language \fi %<> % \end{macrocode} % % \end{macro} % % \begin{macro}{\last@language} % % Another counter is used to keep track of the allocated languages. % \TeX{} and \LaTeX{} reserves for this purpose the count 19. % % \begin{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} %<> % \end{macrocode} % % \end{macro} % \end{macro} % % 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{The Package File (\LaTeX, \texttt{babel.sty})} % % \begin{macrocode} %<*package> \NeedsTeXFormat{LaTeX2e}[2005/12/01] \ProvidesPackage{babel}[<@date@> v<@version@> The Babel package] % \end{macrocode} % % Start with some “private” debugging tool, and then define macros for % errors. % % \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} \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} % % This file also takes care of a number of compatibility issues with % other packages an defines a few additional package options. Apart from % all the language options below we also have a few options that % influence the behavior of language definition files. % % Many of the following options don’t do anything themselves, they are % just defined in order to make it possible for babel and language % definition files to check if one of them was specified by the user. % % 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{}% \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 |ver@babel.sty| so that \LaTeX % forgets about the first loading. After a subset of |babel.def| has % been loaded (the old |switch.def|) and |\AfterBabelLanguage| defined, % it exits. % % Now the \texttt{base} option. With it we can define (and load, with % \luatex) hyphenation patterns, even if we are not 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 opt@babel.sty\endcsname\relax \global\expandafter\let\csname ver@babel.sty\endcsname\relax \global\let\@ifl@ter@@\@ifl@ter \def\@ifl@ter#1#2#3#4#5{\global\let\@ifl@ter\@ifl@ter@@}% \endinput}{}% % \end{macrocode} % % \subsection{\texttt{key=value} options and other general option} % % The following macros extract language modifiers, and only real % 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|. How % modifiers are handled are left to language styles; they can use % |\in@|, loop them with |\@for| or load |keyval|, for example. % % \begin{macrocode} \bbl@trace{key=value and another general options} \bbl@csarg\let{tempa\expandafter}\csname opt@babel.sty\endcsname \def\bbl@tempb#1.#2{% Remove 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{% TODO. Refactor lists? \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$}% TODO. Allow spaces. \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 opt@babel.sty\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{mono}{} \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@} % add = 2 \DeclareOption{provide*=*}{\chardef\bbl@iniflag\thr@@} % add + main % A separate option \let\bbl@autoload@options\@empty \DeclareOption{provide@=*}{\def\bbl@autoload@options{import}} % Don't use. Experimental. TODO. \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 |=|, % 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 % |=| 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} % % \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@opt@babel.sty}}}{% \in@{,provide,}{,#1,}% \ifin@ \def\bbl@opt@provide{#2}% \bbl@replace\bbl@opt@provide{;}{,}% \fi} \fi % % \end{macrocode} % % \subsection{Conditional loading of shorthands} % % If there is no |shorthands=|, 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/foots. % 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@opt@babel.sty}}}{% \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 % %<*core> % \end{macrocode} % % \subsection{Interlude for Plain} % % 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}. % % \begin{macrocode} \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 % TODO. change test. <@Emulate LaTeX@> \fi <@Basic macros@> % \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. % % \begin{macrocode} % %<*package|core> % \end{macrocode} % % \section{Multiple languages} % % This is not a separate file (\texttt{switch.def}) anymore. % % Plain \TeX\ version~3.0 provides the primitive |\language| that % is used to store the current language. When used with a pre-3.0 % version this function has to be implemented by allocating a % counter. % % \begin{macrocode} \def\bbl@version{<@version@>} \def\bbl@date{<@date@>} <@Define core switching macros@> % \end{macrocode} % % \begin{macro}{\adddialect} % The macro |\adddialect| can be used to add the name of a dialect % or variant language, for which an already defined hyphenation % table can be used. % % \begin{macrocode} \def\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} % % \end{macro} % % |\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 BCP47 code. % % We first need a couple of macros for a simple BCP 47 look up. It also % makes sure, with |\bbl@bcpcase|, casing is the correct one, so that % sr-latn-ba becomes fr-Latn-BA. Note |#4| may contain some % |\@empty|'s, but they are eventually removed. |\bbl@bcplookup| either % returns the found |ini| or it is |\relax|. % % \begin{macrocode} \def\bbl@bcpcase#1#2#3#4\@@#5{% \ifx\@empty#3% \uppercase{\def#5{#1#2}}% \else \uppercase{\def#5{#1}}% \lowercase{\edef#5{#5#2#3#4}}% \fi} \def\bbl@bcplookup#1-#2-#3-#4\@@{% \let\bbl@bcp\relax \lowercase{\def\bbl@tempa{#1}}% \ifx\@empty#2% \IfFileExists{babel-\bbl@tempa.ini}{\let\bbl@bcp\bbl@tempa}{}% \else\ifx\@empty#3% \bbl@bcpcase#2\@empty\@empty\@@\bbl@tempb \IfFileExists{babel-\bbl@tempa-\bbl@tempb.ini}% {\edef\bbl@bcp{\bbl@tempa-\bbl@tempb}}% {}% \ifx\bbl@bcp\relax \IfFileExists{babel-\bbl@tempa.ini}{\let\bbl@bcp\bbl@tempa}{}% \fi \else \bbl@bcpcase#2\@empty\@empty\@@\bbl@tempb \bbl@bcpcase#3\@empty\@empty\@@\bbl@tempc \IfFileExists{babel-\bbl@tempa-\bbl@tempb-\bbl@tempc.ini}% {\edef\bbl@bcp{\bbl@tempa-\bbl@tempb-\bbl@tempc}}% {}% \ifx\bbl@bcp\relax \IfFileExists{babel-\bbl@tempa-\bbl@tempc.ini}% {\edef\bbl@bcp{\bbl@tempa-\bbl@tempc}}% {}% \fi \ifx\bbl@bcp\relax \IfFileExists{babel-\bbl@tempa-\bbl@tempc.ini}% {\edef\bbl@bcp{\bbl@tempa-\bbl@tempc}}% {}% \fi \ifx\bbl@bcp\relax \IfFileExists{babel-\bbl@tempa.ini}{\let\bbl@bcp\bbl@tempa}{}% \fi \fi\fi} \let\bbl@initoload\relax %<-core> \def\bbl@provide@locale{% \ifx\babelprovide\@undefined \bbl@error{base-on-the-fly}{}{}{}% \fi \let\bbl@auxname\languagename % Still necessary. TODO \bbl@ifunset{bbl@bcp@map@\languagename}{}% Move uplevel?? {\edef\languagename{\@nameuse{bbl@bcp@map@\languagename}}}% \ifbbl@bcpallowed \expandafter\ifx\csname date\languagename\endcsname\relax \expandafter \bbl@bcplookup\languagename-\@empty-\@empty-\@empty\@@ \ifx\bbl@bcp\relax\else % Returned by \bbl@bcplookup \edef\languagename{\bbl@bcp@prefix\bbl@bcp}% \edef\localename{\bbl@bcp@prefix\bbl@bcp}% \expandafter\ifx\csname date\languagename\endcsname\relax \let\bbl@initoload\bbl@bcp \bbl@exp{\\\babelprovide[\bbl@autoload@bcpoptions]{\languagename}}% \let\bbl@initoload\relax \fi \bbl@csarg\xdef{bcp@map@\bbl@bcp}{\localename}% \fi \fi \fi \expandafter\ifx\csname date\languagename\endcsname\relax \IfFileExists{babel-\languagename.tex}% {\bbl@exp{\\\babelprovide[\bbl@autoload@options]{\languagename}}}% {}% \fi} %<+core> % \end{macrocode} % % \begin{macro}{\iflanguage} % Users might want to test (in a private package for instance) % which language is currently active. For this we provide a test % macro, |\iflanguage|, that has three arguments. It checks % whether the first argument is a known language. If so, it % compares the first argument with the value of |\language|. Then, % depending on the result of the comparison, it executes either the % second or the third argument. % % \begin{macrocode} \def\iflanguage#1{% \bbl@iflanguage{#1}{% \ifnum\csname l@#1\endcsname=\language \expandafter\@firstoftwo \else \expandafter\@secondoftwo \fi}} % \end{macrocode} % % \end{macro} % % \subsection{Selecting the language} % % \begin{macro}{\selectlanguage} % % The macro |\selectlanguage| checks whether the language is % already defined before it performs its actual task, which is to % update |\language| and activate language-specific definitions. % % \begin{macrocode} \let\bbl@select@type\z@ \edef\selectlanguage{% \noexpand\protect \expandafter\noexpand\csname selectlanguage \endcsname} % \end{macrocode} % % Because the command |\selectlanguage| could be used in a moving % argument it expands to \verb*=\protect\selectlanguage =. % Therefore, we have to make sure that a macro |\protect| exists. % If it doesn't it is |\let| to |\relax|. % % \begin{macrocode} \ifx\@undefined\protect\let\protect\relax\fi % \end{macrocode} % % The following definition is preserved for backwards compatibility % (eg, \textsf{arabi}, \textsf{koma}). It is related to a trick for % 2.09, now discarded. % % \begin{macrocode} \let\xstring\string % \end{macrocode} % % \end{macro} % % Since version 3.5 \babel\ writes entries to the auxiliary files in % order to typeset table of contents etc. in the correct language % environment. % % \begin{macro}{\bbl@pop@language} % % \emph{But} when the language change happens \emph{inside} a group % the end of the group doesn't write anything to the auxiliary % files. Therefore we need \TeX's |aftergroup| mechanism to help % us. The command |\aftergroup| stores the token immediately % following it to be executed when the current group is closed. So % we define a temporary control sequence |\bbl@pop@language| to be % executed at the end of the group. It calls |\bbl@set@language| % with the name of the current language as its argument. % % \begin{macro}{\bbl@language@stack} % The previous solution works for one level of nesting groups, but % as soon as more levels are used it is no longer adequate. For % that case we need to keep track of the nested languages using a % stack mechanism. This stack is called |\bbl@language@stack| and % initially empty. % % \begin{macrocode} \def\bbl@language@stack{} % \end{macrocode} % % When using a stack we need a mechanism to push an element on the % stack and to retrieve the information afterwards. % % \begin{macro}{\bbl@push@language} % \begin{macro}{\bbl@pop@language} % The stack is simply a list of languagenames, separated with a `+' % sign; the push function can be simple: % % \begin{macrocode} \def\bbl@push@language{% \ifx\languagename\@undefined\else \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. % % \begin{macro}{\bbl@pop@lang} % This macro stores its first element (which is delimited by the % `+'-sign) in |\languagename| and stores the rest of the string % in |\bbl@language@stack|. % % \begin{macrocode} \def\bbl@pop@lang#1+#2\@@{% \edef\languagename{#1}% \xdef\bbl@language@stack{#2}} % \end{macrocode} % % \end{macro} % The reason for the somewhat weird arrangement of arguments to the % helper function is the fact it is called in the following way. % This means that before |\bbl@pop@lang| is executed \TeX\ first % \emph{expands} the stack, stored in |\bbl@language@stack|. The % result of that is that the argument string of |\bbl@pop@lang| % contains one or more language names, each followed by a `+'-sign % (zero language names won't occur as this macro will only be % called after something has been pushed on the stack). % % \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. % \end{macro} % \end{macro} % \end{macro} % % An alternative way to identify languages (in the \babel{} sense) % with a numerical value is introduced in 3.30. This is one of the % first steps for a new interface based on the concept of locale, % which explains the name of |\localeid|. This means |\l@...| will be % reserved for hyphenation patterns (so that two locales can share the % same rules). % % \begin{macrocode} \chardef\localeid\z@ \def\bbl@id@last{0} % No real need for a new counter \def\bbl@id@assign{% \bbl@ifunset{bbl@id@@\languagename}% {\count@\bbl@id@last\relax \advance\count@\@ne \bbl@csarg\chardef{id@@\languagename}\count@ \edef\bbl@id@last{\the\count@}% \ifcase\bbl@engine\or \directlua{ Babel = Babel or {} Babel.locale_props = Babel.locale_props or {} Babel.locale_props[\bbl@id@last] = {} Babel.locale_props[\bbl@id@last].name = '\languagename' }% \fi}% {}% \chardef\localeid\bbl@cl{id@}} % \end{macrocode} % % The unprotected part of |\selectlanguage|. 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} % % \end{macro} % % \begin{macro}{\bbl@set@language} % % The macro |\bbl@set@language| takes care of switching the language % environment \emph{and} of writing entries on the auxiliary files. % For 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. \edef\languagename{% \ifnum\escapechar=\expandafter`\string#1\@empty \else\string#1\@empty\fi}% \ifcat\relax\noexpand#1% \expandafter\ifx\csname date\languagename\endcsname\relax \edef\languagename{#1}% \let\localename\languagename \else \bbl@info{Using '\string\language' instead of 'language' is\\% deprecated. If what you want is to use a\\% macro containing the actual locale, make\\% sure it does not not match any language.\\% Reported}% \ifx\scantokens\@undefined \def\localename{??}% \else \scantokens\expandafter{\expandafter \def\expandafter\localename\expandafter{\languagename}}% \fi \fi \else \def\localename{#1}% This one has the correct catcodes \fi \select@language{\languagename}% % write to auxs \expandafter\ifx\csname date\languagename\endcsname\relax\else \if@filesw \ifx\babel@aux\@gobbletwo\else % Set if single in the first, redundant \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 % \newif\ifbbl@bcpallowed \bbl@bcpallowedfalse \def\select@language#1{% from set@, babel@aux \ifx\bbl@selectorname\@empty \def\bbl@selectorname{select}% % set hymap \fi \ifnum\bbl@hymapsel=\@cclv\chardef\bbl@hymapsel4\relax\fi % set name \edef\languagename{#1}% \bbl@fixname\languagename % TODO. name@map must be here? \bbl@provide@locale \bbl@iflanguage\languagename{% \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}}}% TODO - plain? \def\babel@toc#1#2{% \select@language{#1}} % \end{macrocode} % % \end{macro} % % First, check if the user asks for a known language. If so, % update the value of |\language| and call |\originalTeX| % to bring \TeX\ in a certain pre-defined state. % % The name of the language is stored in the control sequence % |\languagename|. % % Then we have to \emph{re}define |\originalTeX| to compensate for % the things that have been activated. To save memory space for % the macro definition of |\originalTeX|, we construct the control % sequence name for the |\noextras|\langvar\ command at definition % time by expanding the |\csname| primitive. % % Now activate the language-specific definitions. This is done by % constructing the names of three macros by concatenating three % words with the argument of |\selectlanguage|, and calling these % macros. \nb{What if \cs{hyphenation} was used in |extras|? Patch % temporarily |\set@hyphenmins| and hyphenation. It can be done in % hooks if necessary.} % % The switching of the values of |\lefthyphenmin| and % |\righthyphenmin| is somewhat different. First we save their % current values, then we check if |\|\langvar|hyphenmins| is % defined. If it is not, we set default values (2 and 3), otherwise % the values in |\|\langvar|hyphenmins| will be used. % % 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@ % make sure there is info for the language if so requested \bbl@ensureinfo{#1}% % restore \originalTeX \expandafter\def\expandafter\originalTeX\expandafter{% \csname noextras#1\endcsname \let\originalTeX\@empty \babel@beginsave}% \bbl@usehooks{afterreset}{}% \languageshorthands{none}% % set the locale id \bbl@id@assign % switch captions, date \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 \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- % > 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 (eg, Tibetan) \ifin@\else\bbl@xin@{/v}{/\bbl@tempa}\fi % variable font \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 - mins \babel@savevariable\lefthyphenmin \babel@savevariable\righthyphenmin \expandafter\ifx\csname #1hyphenmins\endcsname\relax \set@hyphenmins\tw@\thr@@\relax \else \expandafter\expandafter\expandafter\set@hyphenmins \csname #1hyphenmins\endcsname\relax \fi % reset selector name \let\bbl@selectorname\@empty} % \end{macrocode} % % \begin{environment}{otherlanguage} % The \Lenv{otherlanguage} environment 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} % % \end{environment} % % \begin{environment}{otherlanguage*} % The \Lenv{otherlanguage} environment is meant to be used when a % large part of text from a different language needs to be typeset, % but without changing the translation of words such as `figure'. % This environment makes use of |\foreign@language|. % % \begin{macrocode} \expandafter\def\csname otherlanguage*\endcsname{% \@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} % % \end{environment} % % \begin{macro}{\foreignlanguage} % % The |\foreignlanguage| command is another substitute for the % |\selectlanguage| command. This command takes two arguments, the % first argument is the name of the language to use for typesetting % the text specified in the second argument. % % Unlike |\selectlanguage| this command doesn't switch % \emph{everything}, it only switches the hyphenation rules and the % extra definitions for the language specified. It does this within % a group and assumes the |\extras|\langvar\ command doesn't make % any |\global| changes. The coding is very similar to part of % |\selectlanguage|. % % |\bbl@beforeforeign| is a trick to fix a bug in bidi % texts. |\foreignlanguage| is supposed to be a `text' command, and % therefore it must emit a |\leavevmode|, but it does not, and % therefore the indent is placed on the opposite margin. For % backward compatibility, however, it is done only if a % right-to-left script is requested; otherwise, it is no-op. % % (3.11) |\foreignlanguage*| is a temporary, experimental macro for % a few lines with a different script direction, while preserving % the paragraph format (thank the braces around |\par|, things like % |\hangindent| are not reset). Do not use it in production, % because its semantics and its syntax may change (and very likely % will, or even it could be removed altogether). Currently it % enters in vmode and then selects the language (which in turn sets the % paragraph direction). % % (3.11) Also experimental are the hook |foreign| and |foreign*|. % With them you can redefine |\BabelText| which by default does % nothing. Its behavior is not well defined yet. So, use it in % horizontal mode only if you do not want surprises. % % In other words, at the beginning of a paragraph |\foreignlanguage| % enters into hmode with the surrounding lang, and with % |\foreignlanguage*| with the new lang. % % \begin{macrocode} \providecommand\bbl@beforeforeign{} \edef\foreignlanguage{% \noexpand\protect \expandafter\noexpand\csname foreignlanguage \endcsname} \expandafter\def\csname foreignlanguage \endcsname{% \@ifstar\bbl@foreign@s\bbl@foreign@x} \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{% TODO - \shapemode, \@setpar, ?\@@par \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} % \end{macrocode} % % \end{macro} % % \begin{macro}{\foreign@language} % % This macro does the work for |\foreignlanguage| and the % \Lenv{otherlanguage*} environment. First we need to store the name % of the language and check that it is a known language. Then it % just calls |bbl@switch|. % % \begin{macrocode} \def\foreign@language#1{% % set name \edef\languagename{#1}% \ifbbl@usedategroup \bbl@add\bbl@select@opts{,date,}% \bbl@usedategroupfalse \fi \bbl@fixname\languagename % TODO. name@map here? \bbl@provide@locale \bbl@iflanguage\languagename{% \let\bbl@select@type\@ne \expandafter\bbl@switch\expandafter{\languagename}}} % \end{macrocode} % % \end{macro} % % 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} % % \begin{macro}{\bbl@patterns} % % This macro selects the hyphenation patterns by changing the % \cs{language} register. If special hyphenation patterns % are available specifically for the current font encoding, % use them instead of the default. % % It also sets hyphenation exceptions, but only once, because they % are global (here language |\lccode|'s has been set, too). % |\bbl@hyphenation@| is set to relax until the very first % |\babelhyphenation|, so do nothing with this value. If the % exceptions for a language (by its number, not its name, so that % |:ENC| is taken into account) has been set, then use % |\hyphenation| with both global and language exceptions and empty % the latter to mark they must not be set again. % % \begin{macrocode} \let\bbl@hyphlist\@empty \let\bbl@hyphenation@\relax \let\bbl@pttnlist\@empty \let\bbl@patterns@\relax \let\bbl@hymapsel=\@cclv \def\bbl@patterns#1{% \language=\expandafter\ifx\csname l@#1:\f@encoding\endcsname\relax \csname l@#1\endcsname \edef\bbl@tempa{#1}% \else \csname l@#1:\f@encoding\endcsname \edef\bbl@tempa{#1:\f@encoding}% \fi \@expandtwoargs\bbl@usehooks{patterns}{{#1}{\bbl@tempa}}% % > luatex \@ifundefined{bbl@hyphenation@}{}{% Can be \relax! \begingroup \bbl@xin@{,\number\language,}{,\bbl@hyphlist}% \ifin@\else \@expandtwoargs\bbl@usehooks{hyphenation}{{#1}{\bbl@tempa}}% \hyphenation{% \bbl@hyphenation@ \@ifundefined{bbl@hyphenation@#1}% \@empty {\space\csname bbl@hyphenation@#1\endcsname}}% \xdef\bbl@hyphlist{\bbl@hyphlist\number\language,}% \fi \endgroup}} % \end{macrocode} % % \end{macro} % % \begin{environment}{hyphenrules} % % The environment \Lenv{hyphenrules} can be used to select % \emph{just} the hyphenation rules. This environment does % \emph{not} change |\languagename| and when the hyphenation rules % specified were not loaded it has no effect. Note however, % |\lccode|'s and font encodings are not set at all, so in most % cases you should use |otherlanguage*|. % % \begin{macrocode} \def\hyphenrules#1{% \edef\bbl@tempf{#1}% \bbl@fixname\bbl@tempf \bbl@iflanguage\bbl@tempf{% \expandafter\bbl@patterns\expandafter{\bbl@tempf}% \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} % % \end{environment} % % \begin{macro}{\providehyphenmins} % The macro |\providehyphenmins| should be used in the language % definition files to provide a \emph{default} setting for the % hyphenation parameters |\lefthyphenmin| and |\righthyphenmin|. If % the macro |\|\langvar|hyphenmins| is already defined this command % has no effect. % % \begin{macrocode} \def\providehyphenmins#1#2{% \expandafter\ifx\csname #1hyphenmins\endcsname\relax \@namedef{#1hyphenmins}{#2}% \fi} % \end{macrocode} % % \end{macro} % % \begin{macro}{\set@hyphenmins} % This macro sets the values of |\lefthyphenmin| and % |\righthyphenmin|. It expects two values as its argument. % % \begin{macrocode} \def\set@hyphenmins#1#2{% \lefthyphenmin#1\relax \righthyphenmin#2\relax} % \end{macrocode} % % \end{macro} % % \begin{macro}{\ProvidesLanguage} % The identification code for each file is something that was % introduced in \LaTeXe. When the command |\ProvidesFile| does not % exist, a dummy definition is provided temporarily. For use in the % language definition file the command |\ProvidesLanguage| is % defined by \babel. % % Depending on the format, ie, on if the former is defined, we use % a similar definition or not. % % \begin{macrocode} \ifx\ProvidesFile\@undefined \def\ProvidesLanguage#1[#2 #3 #4]{% \wlog{Language: #1 #4 #3 <#2>}% } \else \def\ProvidesLanguage#1{% \begingroup \catcode`\ 10 % \@makeother\/% \@ifnextchar[%] {\@provideslanguage{#1}}{\@provideslanguage{#1}[]}} \def\@provideslanguage#1[#2]{% \wlog{Language: #1 #2}% \expandafter\xdef\csname ver@#1.ldf\endcsname{#2}% \endgroup} \fi % \end{macrocode} % % \end{macro} % % \begin{macro}{\originalTeX} % The macro|\originalTeX| should be known to \TeX\ at this moment. % As it has to be expandable we |\let| it to |\@empty| instead of % |\relax|. % % \begin{macrocode} \ifx\originalTeX\@undefined\let\originalTeX\@empty\fi % \end{macrocode} % % Because this part of the code can be included in a format, we % make sure that the macro which initializes the save mechanism, % |\babel@beginsave|, is not considered to be undefined. % % \begin{macrocode} \ifx\babel@beginsave\@undefined\let\babel@beginsave\relax\fi % \end{macrocode} % % \end{macro} % % A few macro names are reserved for future releases of \babel, which % will use the concept of `locale': % % \begin{macrocode} \providecommand\setlocale{\bbl@error{not-yet-available}{}{}{}} \let\uselocale\setlocale \let\locale\setlocale \let\selectlocale\setlocale \let\textlocale\setlocale \let\textlanguage\setlocale \let\languagetext\setlocale % \end{macrocode} % % \subsection{Errors} % % \begin{macro}{\@nolanerr} % \begin{macro}{\@nopatterns} % % The \babel\ package will signal an error when a documents tries % to select a language that hasn't been defined earlier. When a % user selects a language for which no hyphenation patterns were % loaded into the format he will be given a warning about that % fact. We revert to the patterns for |\language|=0 in that case. % In most formats that will be (US)english, but it might also be % empty. % % \begin{macro}{\@noopterr} % When the package was loaded without options not everything will % work as expected. An error message is issued in that case. % % When the format knows about |\PackageError| it must be \LaTeXe, % so we can safely use its error handling interface. Otherwise % we'll have to `keep it simple'. % % Infos are not written to the console, but on the other hand many % people think warnings are errors, so a further message type is % defined: an important info which is sent to the console. % % \begin{macrocode} \edef\bbl@nulllanguage{\string\language=0} \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 \ifx\bbl@onlyswitch\@empty\endinput\fi % Here ended switch.def % \end{macrocode} % % Here ended the now discarded |switch.def|. Here also (currently) ends % the \textsf{base} option. % % \begin{macrocode} \ifx\directlua\@undefined\else \ifx\bbl@luapatterns\@undefined \input luababel.def \fi \fi \bbl@trace{Compatibility with language.def} \ifx\bbl@languages\@undefined \ifx\directlua\@undefined \openin1 = language.def % TODO. Remove hardcoded number \ifeof1 \closein1 \message{I couldn't find the file language.def} \else \closein1 \begingroup \def\addlanguage#1#2#3#4#5{% \expandafter\ifx\csname lang@#1\endcsname\relax\else \global\expandafter\let\csname l@#1\expandafter\endcsname \csname lang@#1\endcsname \fi}% \def\uselanguage#1{}% \input language.def \endgroup \fi \fi \chardef\l@english\z@ \fi % \end{macrocode} % % \begin{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} % % \end{macro} % % 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} \def\bbl@withactive#1#2{% \begingroup \lccode`~=`#2\relax \lowercase{\endgroup#1~}} % \end{macrocode} % % \begin{macro}{\bbl@redefine} % % To redefine a command, we save the old meaning of the macro. Then % we redefine it to call the original macro with the `sanitized' % argument. The reason why we do it this way is that we don't want % to redefine the \LaTeX\ macros completely in case their % definitions change (they have changed in the past). 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} % % \end{macro} % % \begin{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} % % \end{macro} % % \begin{macro}{\bbl@redefinerobust} % For commands that are redefined, but which \textit{might} be % robust we need a slightly more intelligent macro. A robust % command |foo| is defined to expand to |\protect|\verb*|\foo |. So % it is necessary to check whether \verb*|\foo | exists. The result % is that the command that is being redefined is always robust % afterwards. Therefore all we need to do now is define \verb*|\foo |. % % \begin{macrocode} \def\bbl@redefinerobust#1{% \edef\bbl@tempa{\bbl@stripslash#1}% \bbl@ifunset{\bbl@tempa\space}% {\expandafter\let\csname org@\bbl@tempa\endcsname#1% \bbl@exp{\def\\#1{\\\protect\<\bbl@tempa\space>}}}% {\bbl@exp{\let\\<\bbl@tempa\space>}}% \@namedef{\bbl@tempa\space}} \@onlypreamble\bbl@redefinerobust % \end{macrocode} % % \end{macro} % % \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} % % \begin{macro}{\babelensure} % % The user command just parses the optional argument and creates a % new macro named |\bbl@e@|\m{language}. We register a hook at the % |afterextras| event which just executes this macro in a % ``complete'' selection (which, if undefined, is |\relax| and does % nothing). This part is somewhat involved because we have to make % sure things are expanded the correct number of times. % % The macro |\bbl@e@|\m{language} contains % |\bbl@ensure|\marg{include}\marg{exclude}\marg{fontenc}, which in in % turn loops over the macros names in |\bbl@captionslist|, excluding % (with the help of |\in@|) those in the |exclude| list. If the % |fontenc| is given (and not |\relax|), the |\fontencoding| is also % added. Then we loop over the |include| list, but if the macro % already contains |\foreignlanguage|, nothing is done. Note this % macro (1) is not restricted to the preamble, and (2) changes are % local. % % \begin{macrocode} \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\{\the\toks@{\bbl@ens@fontenc}}}} \def\bbl@ensure#1#2#3{% 1: include 2: exclude 3: fontenc \def\bbl@tempb##1{% elt for (excluding) \bbl@captionslist list \ifx##1\@undefined % 3.32 - Don't assume the macro exists \edef##1{\noexpand\bbl@nocaption {\bbl@stripslash##1}{\languagename\bbl@stripslash##1}}% \fi \ifx##1\@empty\else \in@{##1}{#2}% \ifin@\else \bbl@ifunset{bbl@ensure@\languagename}% {\bbl@exp{% \\\DeclareRobustCommand\[1]{% \\\foreignlanguage{\languagename}% {\ifx\relax#3\else \\\fontencoding{#3}\\\selectfont \fi ########1}}}}% {}% \toks@\expandafter{##1}% \edef##1{% \bbl@csarg\noexpand{ensure@\languagename}% {\the\toks@}}% \fi \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} % % \end{macro} % % \subsection{Setting up language files} % % \begin{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 \expandafter\if\expandafter\@backslashchar \expandafter\@car\string#2\@nil \ifx#2\@undefined\else \ldf@quit{#1}% \fi \else \expandafter\ifx\csname#2\endcsname\relax\else \ldf@quit{#1}% \fi \fi \bbl@ldfinit} % \end{macrocode} % % \end{macro} % % \begin{macro}{\ldf@quit} % This macro interrupts the processing of a language definition 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} % % \end{macro} % % \begin{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#1{% TODO. Merge into the next macro? Unused elsewhere \bbl@afterlang \let\bbl@afterlang\relax \let\BabelModifiers\relax \let\bbl@screset\relax}% \def\ldf@finish#1{% \loadlocalcfg{#1}% \bbl@afterldf{#1}% \expandafter\main@language\expandafter{#1}% \catcode`\@=\atcatcode \let\atcatcode\relax \catcode`\==\eqcatcode \let\eqcatcode\relax} % \end{macrocode} % % \end{macro} % % After the preamble of the document the commands |\LdfInit|, % |\ldf@quit| and |\ldf@finish| are no longer needed. Therefore % they are turned into warning messages in \LaTeX. % % \begin{macrocode} \@onlypreamble\LdfInit \@onlypreamble\ldf@quit \@onlypreamble\ldf@finish % \end{macrocode} % % \begin{macro}{\main@language} % \begin{macro}{\bbl@main@language} % This command should be used in the various language definition % files. It stores its argument in |\bbl@main@language|; to be used % to switch to the correct language at the beginning of the % document. % % \begin{macrocode} \def\main@language#1{% \def\bbl@main@language{#1}% \let\languagename\bbl@main@language % TODO. Set localename \bbl@id@assign \bbl@patterns{\languagename}} % \end{macrocode} % % We also have to make sure that some code gets executed at the % beginning of the document, either when the |aux| file is read or, % if it does not exist, when the |\AtBeginDocument| is executed. % Languages do not set |\pagedir|, so we set here for the whole % document to the main |\bodydir|. % % \begin{macrocode} \def\bbl@beforestart{% \def\@nolanerr##1{% \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{% \string\providecommand\string\babel@aux[2]{}}% \immediate\write\@mainaux{\string\@nameuse{bbl@beforestart}}% \fi \expandafter\selectlanguage\expandafter{\bbl@main@language}% %<-core> \ifx\bbl@normalsf\@empty \ifnum\sfcode`\.=\@m \let\normalsfcodes\frenchspacing \else \let\normalsfcodes\nonfrenchspacing \fi \else \let\normalsfcodes\bbl@normalsf \fi %<+core> \ifbbl@single % must go after the line above. \renewcommand\selectlanguage[1]{}% \renewcommand\foreignlanguage[2]{#2}% \global\let\babel@aux\@gobbletwo % Also as flag \fi} %<-core> \AddToHook{begindocument/before}{% \let\bbl@normalsf\normalsfcodes \let\normalsfcodes\relax} % Hack, to delay the setting %<+core> \ifcase\bbl@engine\or \AtBeginDocument{\pagedir\bodydir} % TODO - a better place \fi % \end{macrocode} % % \end{macro} % \end{macro} % % A bit of optimization. Select in heads/foots 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} % % \begin{macro}{\bbl@add@special} % The macro |\bbl@add@special| is used to add a new character (or % single character control sequence) to the macro |\dospecials| % (and |\@sanitize| if \LaTeX\ is used). It is used only at one % place, namely when |\initiate@active@char| is called (which is % ignored if the char has been made active before). Because % |\@sanitize| can be undefined, we put the definition inside a % conditional. % % Items are added to the lists without checking its existence or % the original catcode. It does not hurt, but should be fixed. It's % already done with |\nfss@catcodes|, added in 3.10. % % \begin{macrocode} \bbl@trace{Shorhands} \def\bbl@add@special#1{% 1:a macro like \", \?, etc. \bbl@add\dospecials{\do#1}% test @sanitize = \relax, for back. compat. \bbl@ifunset{@sanitize}{}{\bbl@add\@sanitize{\@makeother#1}}% \ifx\nfss@catcodes\@undefined\else % TODO - same for above \begingroup \catcode`#1\active \nfss@catcodes \ifnum\catcode`#1=\active \endgroup \bbl@add\nfss@catcodes{\@makeother#1}% \else \endgroup \fi \fi} % \end{macrocode} % % \end{macro} % % \begin{macro}{\bbl@remove@special} % % The companion of the former macro is |\bbl@remove@special|. It % removes a character from the set macros |\dospecials| and % |\@sanitize|, but it is not used at all in the \babel{} core. % % \begin{macrocode} \def\bbl@remove@special#1{% \begingroup \def\x##1##2{\ifnum`#1=`##2\noexpand\@empty \else\noexpand##1\noexpand##2\fi}% \def\do{\x\do}% \def\@makeother{\x\@makeother}% \edef\x{\endgroup \def\noexpand\dospecials{\dospecials}% \expandafter\ifx\csname @sanitize\endcsname\relax\else \def\noexpand\@sanitize{\@sanitize}% \fi}% \x} % \end{macrocode} % % \end{macro} % % \begin{macro}{\initiate@active@char} % A language definition file can call this macro to make a % character active. This macro takes one argument, the character % that is to be made active. When the character was already active % this macro does nothing. Otherwise, this macro defines the % control sequence |\normal@char|\m{char} to expand to the % character in its `normal state' and it defines the active % character to expand to |\normal@char|\m{char} by default % (\m{char} being the character to be made active). Later its % definition can be changed to expand to |\active@char|\m{char} % by calling |\bbl@activate{|\m{char}|}|. % % For example, to make the double quote character active one could % have |\initiate@active@char{"}| in a language definition file. % This defines |"| as |\active@prefix "\active@char"| (where the % first |"| is the character with its original catcode, when the % shorthand is created, and |\active@char"| is a single token). In % protected contexts, it expands to |\protect "| or |\noexpand "| % (ie, with the original |"|); otherwise |\active@char"| is % executed. This macro in turn expands to |\normal@char"| in % ``safe'' contexts (eg, |\label|), but |\user@active"| in normal % ``unsafe'' ones. The latter search a definition in the user, % language and system levels, in this order, but if none is found, % |\normal@char"| is used. However, a deactivated shorthand (with % |\bbl@deactivate| is defined as |\active@prefix "\normal@char"|. % % The following macro is used to define shorthands in the three % levels. It takes 4 arguments: the (string'ed) character, % |\@group|, |@active| and |@active| % (except in |system|). % % \begin{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|\m{char} % to expand to the character in its default state. If the character % is mathematically active when \babel{} is loaded (for example % |'|) the normal expansion is somewhat different to avoid an % infinite loop (but it does not prevent the loop if the mathcode % is set to |"8000| \textit{a posteriori}). % % \begin{macrocode} \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|\m{char}, we must define % |\active@char|\m{char}, to be executed when the character is % activated. We define the first level expansion of % |\active@char|\m{char} to check the status of the |@safe@actives| % flag. If it is set to true we expand to the `normal' version of % this character, otherwise we call |\user@active|\m{char} to start % the search of a definition in the user, language and system % levels (or eventually |normal@char|\m{char}). % % \begin{macrocode} \let\bbl@tempa\@firstoftwo \if\string^#2% \def\bbl@tempa{\noexpand\textormath}% \else \ifx\bbl@mathnormal\@undefined\else \let\bbl@tempa\bbl@mathnormal \fi \fi \expandafter\edef\csname active@char#2\endcsname{% \bbl@tempa {\noexpand\if@safe@actives \noexpand\expandafter \expandafter\noexpand\csname normal@char#2\endcsname \noexpand\else \noexpand\expandafter \expandafter\noexpand\csname bbl@doactive#2\endcsname \noexpand\fi}% {\expandafter\noexpand\csname normal@char#2\endcsname}}% \bbl@csarg\edef{doactive#2}{% \expandafter\noexpand\csname user@active#2\endcsname}% % \end{macrocode} % % We now define the default values which the shorthand is set to % when activated or deactivated. It is set to the deactivated form % (globally), so that the character expands to % \begin{center} % |\active@prefix| \m{char} |\normal@char|\m{char} % \end{center} % (where |\active@char|\m{char} is \emph{one} control sequence!). % % \begin{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}} %<> % \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} % % \end{macro} % % \begin{macro}{\bbl@sh@select} % This command helps the shorthand supporting macros to select how % to proceed. Note that this macro needs to be expandable as do all % the shorthand macros in order for them to work in expansion-only % environments such as the argument of |\hyphenation|. % % 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} % % \end{macro} % % \begin{macro}{\active@prefix} % The command |\active@prefix| which is used in the expansion of % active characters has a function similar to |\OT1-cmd| in that it % |\protect|s the active character whenever |\protect| is % \emph{not} |\@typeset@protect|. The |\@gobble| is needed to remove % a token such as |\activechar:| (when the double colon was the % active character to be dealt with). There are two definitions, % depending of |\ifincsname| is available. If there is, the % expansion will be more robust. % % \begin{macrocode} \begingroup \bbl@ifunset{ifincsname}% TODO. Ugly. Correct? Only Plain? {\gdef\active@prefix#1{% \ifx\protect\@typeset@protect \else \ifx\protect\@unexpandable@protect \noexpand#1% \else \protect#1% \fi \expandafter\@gobble \fi}} {\gdef\active@prefix#1{% \ifincsname \string#1% \expandafter\@gobble \else \ifx\protect\@typeset@protect \else \ifx\protect\@unexpandable@protect \noexpand#1% \else \protect#1% \fi \expandafter\expandafter\expandafter\@gobble \fi \fi}} \endgroup % \end{macrocode} % % \end{macro} % % \begin{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|\m{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} % % \end{macro} % % \begin{macro}{\bbl@restore@actives} % When the output routine kicks in while the active characters were % made ``safe'' this must be undone in the headers to prevent % unexpected typeset results. For this situation we define a command to % make them ``unsafe'' again. % % \begin{macrocode} \def\bbl@restore@actives{\if@safe@actives\@safe@activesfalse\fi} % \end{macrocode} % % \end{macro} % % \begin{macro}{\bbl@activate} % \begin{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|\m{char} in the case of |\bbl@activate|, % or |\normal@char|\m{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} % % \end{macro} % \end{macro} % % \begin{macro}{\bbl@firstcs} % \begin{macro}{\bbl@scndcs} % % These macros are used only as a trick when declaring shorthands. % % \begin{macrocode} \def\bbl@firstcs#1#2{\csname#1\endcsname} \def\bbl@scndcs#1#2{\csname#2\endcsname} % \end{macrocode} % % \end{macro} % \end{macro} % % \begin{macro}{\declare@shorthand} % The command |\declare@shorthand| is used to declare a shorthand % on a certain level. It takes three arguments: % \begin{enumerate} % \item a name for the collection of shorthands, i.e. `system', or % `dutch'; % \item the character (sequence) that makes up the shorthand, % i.e. |~| or |"a|; % \item the code to be executed when the shorthand is encountered. % \end{enumerate} % % 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} % % \end{macro} % % \begin{macro}{\textormath} % Some of the shorthands that will be declared by the language % definition files have to be usable in both text and mathmode. To % achieve this the helper macro |\textormath| is provided. % % \begin{macrocode} \def\textormath{% \ifmmode \expandafter\@secondoftwo \else \expandafter\@firstoftwo \fi} % \end{macrocode} % % \end{macro} % % \begin{macro}{\user@group} % \begin{macro}{\language@group} % \begin{macro}{\system@group} % The current concept of `shorthands' supports three levels or % groups of shorthands. For each level the name of the level or % group is stored in a macro. The default is to have a user group; % use language group `english' and have a system group called % `system'. % % \begin{macrocode} \def\user@group{user} \def\language@group{english} % TODO. I don't like defaults \def\system@group{system} % \end{macrocode} % % \end{macro} % \end{macro} % \end{macro} % % \begin{macro}{\useshorthands} % % This is the user level macro. It initializes and activates the % character for use as a shorthand character (ie, it's active in the % preamble). Languages can deactivate shorthands, so a starred % version is also provided which activates them always after the % language has been switched. % % \begin{macrocode} \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} % % \end{macro} % % \begin{macro}{\defineshorthand} % % Currently we only support two groups of user level shorthands, % named internally |user| and |user@| (language-dependent % user shorthands). By default, only the first one is taken into % account, but if the former is also used (in the optional argument % of |\defineshorthand|) a new level is inserted for it % (|user@generic|, done by |\bbl@set@user@generic|); we make also % sure |{}| and |\protect| are taken into account in this new top % level. % % \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} % % \end{macro} % % \begin{macro}{\languageshorthands} % % A user level command to change the language from which shorthands % are used. Unfortunately, \babel{} currently does not keep track % of defined groups, and therefore there is no way to catch a % possible change in casing to fix it in the same way languages names % are fixed. [TODO]. % % % \begin{macrocode} \def\languageshorthands#1{\def\language@group{#1}} % \end{macrocode} % % \end{macro} % % \begin{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} % % \end{macro} % % \begin{macro}{\@notshorthand} % % \begin{macrocode} \def\@notshorthand#1{\bbl@error{not-a-shorthand}{#1}{}{}} % \end{macrocode} % % \end{macro} % % \begin{macro}{\shorthandon} % \begin{macro}{\shorthandoff} % % The first level definition of these macros just passes the % argument on to |\bbl@switch@sh|, adding |\@nil| at the end to % denote the end of the list of characters. % % \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} % % \begin{macro}{\bbl@switch@sh} % % The macro |\bbl@switch@sh| takes the list of characters apart one % by one and subsequently switches the category code of the % shorthand character according to the first argument of % |\bbl@switch@sh|. % % But before any of this switching takes place we make sure that the % character we are dealing with is known as a shorthand character. % If it is, a macro such as |\active@char"| should exist. % % Switching off and on is easy -- we just set the category code to % `other' (12) and |\active|. With the starred version, the original % catcode and the original definition, saved in % |@initiate@active@char|, are restored. % % \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} % % \end{macro} % \end{macro} % \end{macro} % % Note the value is that at the expansion time; eg, 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} % % \begin{macro}{\bbl@prim@s} % \begin{macro}{\bbl@pr@m@s} % % One of the internal macros that are involved in substituting |\prime| % for each right quote in mathmode is |\prim@s|. This checks if the % next character is a right quote. When the right quote is active, the % definition of this macro needs to be adapted to look also for an % active right quote; the hat could be active, too. % % \begin{macrocode} \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} % % \end{macro} % \end{macro} % % Usually the |~| is active and expands to \verb*=\penalty\@M\ =. % When it is written to the \file{.aux} file it is written % expanded. To prevent that and to be able to use the character |~| % as a start character for a shorthand, it is redefined here as a % one character shorthand on system level. The system declaration % is in most cases redundant (when |~| is still a non-break space), % and in some cases is inconvenient (if |~| has been redefined); % however, for backward compatibility it is maintained (some % existing documents may rely on the \babel{} value). % % \begin{macrocode} \initiate@active@char{~} \declare@shorthand{system}{~}{\leavevmode\nobreak\ } \bbl@activate{~} % \end{macrocode} % % \begin{macro}{\OT1dqpos} % \begin{macro}{\T1dqpos} % The position of the double quote character is different for the % OT1 and T1 encodings. It will later be selected using the % |\f@encoding| macro. Therefore we define two macros here to store % the position of the character in these encodings. % % \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} % % \end{macro} % \end{macro} % % \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. % % \begin{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@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} % % \end{macro} % % \begin{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} % % \end{macro} % % \begin{macro}{\bbl@ifattributeset} % This internal macro has 4 arguments. It can be used to interpret % \TeX\ code based on whether a certain attribute was set. This % command should appear inside the argument to |\AtBeginDocument| % because the attributes are set in the document preamble, % \emph{after} \babel\ is loaded. % % The first argument is the language, the second argument the % attribute being checked, and the third and fourth arguments are % the true and false clauses. % % \begin{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} % % \end{macro} % % \begin{macro}{\bbl@ifknown@ttrib} % An internal macro to check whether a given language/attribute is % known. The macro takes 4 arguments, the language/attribute, the % attribute list, the \TeX-code to be executed when the attribute % is known and the \TeX-code to be executed otherwise. % % 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} % % \end{macro} % % \begin{macro}{\bbl@clear@ttribs} % This macro removes all the attribute code from \LaTeX's memory at % |\begin{document}| time (if any is present). % % \begin{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} % % \end{macro} % % \subsection{Support for saving macro definitions} % % To save the meaning of control sequences using |\babel@save|, we % use temporary control sequences. To save hash table entries for % these control sequences, we don't use the name of the control % sequence to be saved to construct the temporary name. Instead we % simply use the value of a counter, which is reset to zero each time % we begin to save new values. This works well because we release % the saved meanings before we begin to save a new set of control % sequence meanings (see |\selectlanguage| and |\originalTeX|). Note % undefined macros are not undefined any more when saved -- they are % |\relax|'ed. % % \begin{macro}{\babel@savecnt} % \begin{macro}{\babel@beginsave} % The initialization of a new save cycle: reset the counter to % zero. % % \begin{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} % % \end{macro} % \end{macro} % % \begin{macro}{\babel@save} % \begin{macro}{\babel@savevariable} % % The macro |\babel@save|\meta{csname} saves the current meaning of the % control sequence \meta{csname} to % |\originalTeX|\footnote{\cs{originalTeX} has to be expandable, % i.\,e.\ you shouldn't let it to \cs{relax}.}. To do this, we let the % current meaning to a temporary control sequence, the restore commands % are appended to |\originalTeX| and the counter is incremented. The % macro |\babel@savevariable|\meta{variable} saves the value of the % variable. \meta{variable} can be anything allowed after the |\the| % primitive. 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@\\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} % % \end{macro} % \end{macro} % % \begin{macro}{\bbl@frenchspacing} % \begin{macro}{\bbl@nonfrenchspacing} % Some languages need to have |\frenchspacing| in effect. Others % don't want that. The command |\bbl@frenchspacing| switches it on % when it isn't already in effect and |\bbl@nonfrenchspacing| % switches it off if necessary. 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} \def\bbl@frenchspacing{% \ifnum\the\sfcode`\.=\@m \let\bbl@nonfrenchspacing\relax \else \frenchspacing \let\bbl@nonfrenchspacing\nonfrenchspacing \fi} \let\bbl@nonfrenchspacing\nonfrenchspacing \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} % % \end{macro} % \end{macro} % % \subsection{Short tags} % % \begin{macro}{\babeltags} % This macro is straightforward. After zapping spaces, we % loop over the list and define the macros |\text|\m{tag} and % |\|\m{tag}. Definitions are first expanded so that they don't % contain |\csname| but the actual macro. % % \begin{macrocode} \bbl@trace{Short tags} \def\babeltags#1{% \edef\bbl@tempa{\zap@space#1 \@empty}% \def\bbl@tempb##1=##2\@@{% \edef\bbl@tempc{% \noexpand\newcommand \expandafter\noexpand\csname ##1\endcsname{% \noexpand\protect \expandafter\noexpand\csname otherlanguage*\endcsname{##2}} \noexpand\newcommand \expandafter\noexpand\csname text##1\endcsname{% \noexpand\foreignlanguage{##2}}} \bbl@tempc}% \bbl@for\bbl@tempa\bbl@tempa{% \expandafter\bbl@tempb\bbl@tempa\@@}} % \end{macrocode} % % \end{macro} % % \subsection{Hyphens} % % \begin{macro}{\babelhyphenation} % % This macro saves hyphenation exceptions. Two macros are used to % store them: |\bbl@hyphenation@| for the global ones and % |\bbl@hyphenation| for language ones. See |\bbl@patterns| % above for further details. We make sure there is a space between % words when multiple commands are used. % % \begin{macrocode} \bbl@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} % % \end{macro} % % \begin{macro}{\bbl@allowhyphens} % % This macro makes hyphenation possible. Basically its definition % is nothing more than |\nobreak| |\hskip| \texttt{0pt plus % 0pt}\footnote{\TeX\ begins and ends a word for hyphenation at a % glue node. The penalty prevents a linebreak at this glue node.}. % % \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} % % \end{macro} % % \begin{macro}{\babelhyphen} % % Macros to insert common hyphens. Note the space before |@| in % |\babelhyphen|. Instead of protecting it with % |\DeclareRobustCommand|, which could insert a |\relax|, we use % the same procedure as shorthands, with |\active@prefix|. % % \begin{macrocode} \newcommand\babelnullhyphen{\char\hyphenchar\font} \def\babelhyphen{\active@prefix\babelhyphen\bbl@hyphen} \def\bbl@hyphen{% \@ifstar{\bbl@hyphen@i @}{\bbl@hyphen@i\@empty}} \def\bbl@hyphen@i#1#2{% \bbl@ifunset{bbl@hy@#1#2\@empty}% {\csname bbl@#1usehyphen\endcsname{\discretionary{#2}{}{#2}}}% {\csname bbl@hy@#1#2\@empty\endcsname}} % \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} % % \end{macro} % % \begin{macro}{\bbl@disc} % For some languages the macro |\bbl@disc| is used to ease the % insertion of discretionaries for letters that behave `abnormally' % at a breakpoint. % % \begin{macrocode} \def\bbl@disc#1#2{\nobreak\discretionary{#2-}{}{#1}\bbl@allowhyphens} % \end{macrocode} % % \end{macro} % % \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}{} %<> % \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} %<> % \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 % (ie, fallback values). With labelled blocks and % |strings=encoded|, define the strings, but with another value, % define strings only if the current label or font encoding is the % value of |strings|; otherwise (ie, no |strings| or a block whose % label is not in |strings=|) do nothing. % % We presume the current block is not loaded, and therefore set % (above) a couple of default values to gobble the arguments. Then, % these macros are redefined if necessary according to several % parameters. % % \begin{macrocode} \newcommand\bbl@startcmds@ii[1][\@empty]{% \let\SetString\@gobbletwo \let\bbl@stringdef\@gobbletwo \let\AfterBabelCommands\@gobble \ifx\@empty#1% \def\bbl@sc@label{generic}% \def\bbl@encstring##1##2{% \ProvideTextCommandDefault##1{##2}% \bbl@toglobal##1% \expandafter\bbl@toglobal\csname\string?\string##1\endcsname}% \let\bbl@sctest\in@true \else \let\bbl@sc@charset\space % <- zapped below \let\bbl@sc@fontenc\space % <- " " \def\bbl@tempa##1=##2\@nil{% \bbl@csarg\edef{sc@\zap@space##1 \@empty}{##2 }}% \bbl@vforeach{label=#1}{\bbl@tempa##1\@nil}% \def\bbl@tempa##1 ##2{% space -> comma ##1% \ifx\@empty##2\else\ifx,##1,\else,\fi\bbl@afterfi\bbl@tempa##2\fi}% \edef\bbl@sc@fontenc{\expandafter\bbl@tempa\bbl@sc@fontenc\@empty}% \edef\bbl@sc@label{\expandafter\zap@space\bbl@sc@label\@empty}% \edef\bbl@sc@charset{\expandafter\zap@space\bbl@sc@charset\@empty}% \def\bbl@encstring##1##2{% \bbl@foreach\bbl@sc@fontenc{% \bbl@ifunset{T@####1}% {}% {\ProvideTextCommand##1{####1}{##2}% \bbl@toglobal##1% \expandafter \bbl@toglobal\csname####1\string##1\endcsname}}}% \def\bbl@sctest{% \bbl@xin@{,\bbl@opt@strings,}{,\bbl@sc@label,\bbl@sc@fontenc,}}% \fi \ifx\bbl@opt@strings\@nnil % ie, no strings key -> defaults \else\ifx\bbl@opt@strings\relax % ie, strings=encoded \let\AfterBabelCommands\bbl@aftercmds \let\SetString\bbl@setstring \let\bbl@stringdef\bbl@encstring \else % ie, strings=value \bbl@sctest \ifin@ \let\AfterBabelCommands\bbl@aftercmds \let\SetString\bbl@setstring \let\bbl@stringdef\bbl@provstring \fi\fi\fi \bbl@scswitch \ifx\bbl@G\@empty \def\SetString##1##2{% \bbl@error{missing-group}{##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 |\|\m{group}\m{language} is % reset, but only once (|\bbl@screset| is used to keep track of this). % The second version is used in the preamble and packages loaded after % \babel{} and does nothing. % % The macro |\bbl@forlang| loops |\bbl@L| but its body is executed only % if the value is in |\BabelLanguages| (inside \babel) or % |\date|\m{language} is defined (after \babel{} has been loaded). % There are also two version of |\bbl@forlang|. The first one skips the % current iteration if the language is not in |\BabelLanguages| (used % in |ldf|s), and the second one skips undefined languages (after % \babel{} has been loaded) . % % \begin{macrocode} \def\bbl@forlang#1#2{% \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 (ie, like |\providescommmand|). With % the event |stringprocess| you can preprocess the string by % manipulating the value of |\BabelString|. If there are several % hooks assigned to this event, preprocessing is done in the same % order as defined. Finally, the string is set. % % \begin{macrocode} \def\bbl@setstring#1#2{% eg, \prefacename{} \bbl@forlang\bbl@tempa{% \edef\bbl@LC{\bbl@tempa\bbl@stripslash#1}% \bbl@ifunset{\bbl@LC}% eg, \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. TODO: 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}}}% %<> % \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}}% %<> % \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}}}% %<> % \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} %<> % \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} % % This sections ends with 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{% TODO. Catch typos. \@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\{\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\{\\\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\{\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} % \def\bbl@setcaption@s#1#2#3{} % TODO. Not yet implemented (w/o 'name') % \end{macrocode} % % \subsection{Macros common to a number of languages} % % \begin{macro}{\set@low@box} % % The following macro is used to lower quotes to the same level as % the comma. It prepares its argument in box register~0. % % \begin{macrocode} \bbl@trace{Macros related to glyphs} \def\set@low@box#1{\setbox\tw@\hbox{,}\setbox\z@\hbox{#1}% \dimen\z@\ht\z@ \advance\dimen\z@ -\ht\tw@% \setbox\z@\hbox{\lower\dimen\z@ \box\z@}\ht\z@\ht\tw@ \dp\z@\dp\tw@} % \end{macrocode} % % \end{macro} % % \begin{macro}{\save@sf@q} % The macro |\save@sf@q| is used to save and reset the current % space factor. % % \begin{macrocode} \def\save@sf@q#1{\leavevmode \begingroup \edef\@SF{\spacefactor\the\spacefactor}#1\@SF \endgroup} % \end{macrocode} % % \end{macro} % % \subsection{Making glyphs available} % % This section makes a number of glyphs available that either do not % exist in the \texttt{OT1} encoding and have to be `faked', or % that are not accessible through \file{T1enc.def}. % % \subsubsection{Quotation marks} % % \begin{macro}{\quotedblbase} % In the \texttt{T1} encoding the opening double quote at the % baseline is available as a separate character, accessible via % |\quotedblbase|. In the \texttt{OT1} encoding it is not % available, therefore we make it available by lowering the normal % open quote character to the baseline. % % \begin{macrocode} \ProvideTextCommand{\quotedblbase}{OT1}{% \save@sf@q{\set@low@box{\textquotedblright\/}% \box\z@\kern-.04em\bbl@allowhyphens}} % \end{macrocode} % % 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} % % \end{macro} % % \begin{macro}{\quotesinglbase} % We also need the single quote character at the baseline. % % \begin{macrocode} \ProvideTextCommand{\quotesinglbase}{OT1}{% \save@sf@q{\set@low@box{\textquoteright\/}% \box\z@\kern-.04em\bbl@allowhyphens}} % \end{macrocode} % % Make sure that when an encoding other than \texttt{OT1} or % \texttt{T1} is used this glyph can still be typeset. % % \begin{macrocode} \ProvideTextCommandDefault{\quotesinglbase}{% \UseTextSymbol{OT1}{\quotesinglbase}} % \end{macrocode} % % \end{macro} % % \begin{macro}{\guillemetleft} % \begin{macro}{\guillemetright} % The guillemet characters are not available in \texttt{OT1} % encoding. They are faked. (Wrong names with o preserved for % compatibility.) % % \begin{macrocode} \ProvideTextCommand{\guillemetleft}{OT1}{% \ifmmode \ll \else \save@sf@q{\nobreak \raise.2ex\hbox{$\scriptscriptstyle\ll$}\bbl@allowhyphens}% \fi} \ProvideTextCommand{\guillemetright}{OT1}{% \ifmmode \gg \else \save@sf@q{\nobreak \raise.2ex\hbox{$\scriptscriptstyle\gg$}\bbl@allowhyphens}% \fi} \ProvideTextCommand{\guillemotleft}{OT1}{% \ifmmode \ll \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} % % \end{macro} % \end{macro} % % \begin{macro}{\guilsinglleft} % \begin{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} % % \end{macro} % \end{macro} % % \subsubsection{Letters} % % \begin{macro}{\ij} % \begin{macro}{\IJ} % The dutch language uses the letter `ij'. It is available in % \texttt{T1} encoded fonts, but not in the \texttt{OT1} encoded % fonts. Therefore we fake it for the \texttt{OT1} encoding. % % \begin{macrocode} \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} % % \end{macro} % \end{macro} % % \begin{macro}{\dj} % \begin{macro}{\DJ} % The croatian language needs the letters |\dj| and |\DJ|; they are % available in the \texttt{T1} encoding, but not in the % \texttt{OT1} encoding by default. % % Some code to construct these glyphs for the \texttt{OT1} encoding % was made available to me by Stipčević Mario, % (\texttt{stipcevic@olimp.irb.hr}). % % \begin{macrocode} \def\crrtic@{\hrule height0.1ex width0.3em} \def\crttic@{\hrule height0.1ex width0.33em} \def\ddj@{% \setbox0\hbox{d}\dimen@=\ht0 \advance\dimen@1ex \dimen@.45\dimen@ \dimen@ii\expandafter\rem@pt\the\fontdimen\@ne\font\dimen@ \advance\dimen@ii.5ex \leavevmode\rlap{\raise\dimen@\hbox{\kern\dimen@ii\vbox{\crrtic@}}}} \def\DDJ@{% \setbox0\hbox{D}\dimen@=.55\ht0 \dimen@ii\expandafter\rem@pt\the\fontdimen\@ne\font\dimen@ \advance\dimen@ii.15ex % correction for the dash position \advance\dimen@ii-.15\fontdimen7\font % correction for cmtt font \dimen\thr@@\expandafter\rem@pt\the\fontdimen7\font\dimen@ \leavevmode\rlap{\raise\dimen@\hbox{\kern\dimen@ii\vbox{\crttic@}}}} % \DeclareTextCommand{\dj}{OT1}{\ddj@ d} \DeclareTextCommand{\DJ}{OT1}{\DDJ@ D} % \end{macrocode} % % 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} % % \end{macro} % \end{macro} % % \begin{macro}{\SS} % For the \texttt{T1} encoding |\SS| is defined and selects a % specific glyph from the font, but for other encodings it is not % available. Therefore we make it available here. % % \begin{macrocode} \DeclareTextCommand{\SS}{OT1}{SS} \ProvideTextCommandDefault{\SS}{\UseTextSymbol{OT1}{\SS}} % \end{macrocode} % % \end{macro} % % \subsubsection{Shorthands for quotation marks} % % Shorthands are provided for a number of different quotation % marks, which make them usable both outside and inside mathmode. % They are defined with |\ProvideTextCommandDefault|, but this is % very likely not required because their definitions are based on % encoding-dependent macros. % % \begin{macro}{\glq} % \begin{macro}{\grq} % % The `german' single quotes. % % \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} % % \end{macro} % \end{macro} % % \begin{macro}{\glqq} % \begin{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} % % \end{macro} % \end{macro} % % \begin{macro}{\flq} % \begin{macro}{\frq} % % The `french' single guillemets. % % \begin{macrocode} \ProvideTextCommandDefault{\flq}{% \textormath{\guilsinglleft}{\mbox{\guilsinglleft}}} \ProvideTextCommandDefault{\frq}{% \textormath{\guilsinglright}{\mbox{\guilsinglright}}} % \end{macrocode} % % \end{macro} % \end{macro} % % \begin{macro}{\flqq} % \begin{macro}{\frqq} % % The `french' double guillemets. % % \begin{macrocode} \ProvideTextCommandDefault{\flqq}{% \textormath{\guillemetleft}{\mbox{\guillemetleft}}} \ProvideTextCommandDefault{\frqq}{% \textormath{\guillemetright}{\mbox{\guillemetright}}} % \end{macrocode} % % \end{macro} % \end{macro} % % \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. % % \begin{macro}{\umlauthigh} % % \begin{macro}{\umlautlow} % To be able to provide both positions of |\"| we provide two % commands to switch the positioning, the default will be % |\umlauthigh| (the normal positioning). % % \begin{macrocode} \def\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} % % \end{macro} % \end{macro} % % \begin{macro}{\lower@umlaut} % The command |\lower@umlaut| is used to position the |\"| closer % to the letter. % % We want the umlaut character lowered, nearer to the letter. To do % this we need an extra \meta{dimen} register. % % \begin{macrocode} \expandafter\ifx\csname U@D\endcsname\relax \csname newdimen\endcsname\U@D \fi % \end{macrocode} % % The following code fools \TeX's \texttt{make\_accent} procedure % about the current x-height of the font to force another placement % of the umlaut character. % First we have to save the current x-height of the font, because % we'll change this font dimension and this is always done % globally. % % Then we compute the new x-height in such a way that the umlaut % character is lowered to the base character. The value of % \texttt{.45ex} depends on the \MF\ parameters with which the % fonts were built. (Just try out, which value will look best.) % If the new x-height is too low, it is not changed. % Finally we call the |\accent| primitive, reset the old x-height % and insert the base character in the argument. % % \begin{macrocode} \def\lower@umlaut#1{% \leavevmode\bgroup \U@D 1ex% {\setbox\z@\hbox{% \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} % % \end{macro} % % For all vowels we declare |\"| to be a composite command which % uses |\bbl@umlauta| or |\bbl@umlaute| to position the umlaut % character. We need to be sure that these definitions override the % ones that are provided when the package \pkg{fontenc} with % option \Lopt{OT1} is used. Therefore these declarations are % postponed until the beginning of the document. Note these % definitions only apply to some languages, but % babel sets them for \textit{all} languages -- you may want to % redefine |\bbl@umlauta| and/or |\bbl@umlaute| for a language % in the corresponding |ldf| (using the babel switching mechanism, % of course). % % \begin{macrocode} \AtBeginDocument{% \DeclareTextCompositeCommand{\"}{OT1}{a}{\bbl@umlauta{a}}% \DeclareTextCompositeCommand{\"}{OT1}{e}{\bbl@umlaute{e}}% \DeclareTextCompositeCommand{\"}{OT1}{i}{\bbl@umlaute{\i}}% \DeclareTextCompositeCommand{\"}{OT1}{\i}{\bbl@umlaute{\i}}% \DeclareTextCompositeCommand{\"}{OT1}{o}{\bbl@umlauta{o}}% \DeclareTextCompositeCommand{\"}{OT1}{u}{\bbl@umlauta{u}}% \DeclareTextCompositeCommand{\"}{OT1}{A}{\bbl@umlauta{A}}% \DeclareTextCompositeCommand{\"}{OT1}{E}{\bbl@umlaute{E}}% \DeclareTextCompositeCommand{\"}{OT1}{I}{\bbl@umlaute{I}}% \DeclareTextCompositeCommand{\"}{OT1}{O}{\bbl@umlauta{O}}% \DeclareTextCompositeCommand{\"}{OT1}{U}{\bbl@umlauta{U}}} % \end{macrocode} % % Finally, make sure the default hyphenrules are defined (even if % empty). 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}% %<-core> \newcommand\BabelPatchSection[1]{% \@ifundefined{#1}{}{% \bbl@exp{\let\\<#1>}% \@namedef{#1}{% \@ifstar{\bbl@presec@s{#1}}% {\@dblarg{\bbl@presec@x{#1}}}}}} \def\bbl@presec@x#1[#2]#3{% \bbl@exp{% \\\select@language@x{\bbl@main@language}% \\\bbl@cs{sspre@#1}% \\\bbl@cs{ss@#1}% [\\\foreignlanguage{\languagename}{\unexpanded{#2}}]% {\\\foreignlanguage{\languagename}{\unexpanded{#3}}}% \\\select@language@x{\languagename}}} \def\bbl@presec@s#1#2{% \bbl@exp{% \\\select@language@x{\bbl@main@language}% \\\bbl@cs{sspre@#1}% \\\bbl@cs{ss@#1}*% {\\\foreignlanguage{\languagename}{\unexpanded{#2}}}% \\\select@language@x{\languagename}}} \IfBabelLayout{sectioning}% {\BabelPatchSection{part}% \BabelPatchSection{chapter}% \BabelPatchSection{section}% \BabelPatchSection{subsection}% \BabelPatchSection{subsubsection}% \BabelPatchSection{paragraph}% \BabelPatchSection{subparagraph}% \def\babel@toc#1{% \select@language@x{\bbl@main@language}}}{} \IfBabelLayout{captions}% {\BabelPatchSection{caption}}{} %<+core> % \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 % \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*,calendar,date,casing,interchar}% {\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@forkv{#1}{% \in@{/}{##1}% With /, (re)sets a value in the ini \ifin@ \global\let\bbl@extend@ini\bbl@extend@ini@aux \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 % == 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 % TODO. A dirty hack \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 % == Load ini == \ifcase\bbl@howloaded \bbl@provide@new{#2}% \else \bbl@ifblank{#1}% {}% With \bbl@load@basic below {\bbl@provide@renew{#2}}% \fi % == include == TODO % \ifx\bbl@included@inis\@empty\else % \bbl@replace\bbl@included@inis{ }{,}% % \bbl@foreach\bbl@included@inis{% % \openin\bbl@readstream=babel-##1.ini % \bbl@extend@ini{#2}}% % \closein\bbl@readstream % \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\[1]{% \\\foreignlanguage{\languagename}% {####1}}}}% {}% \bbl@exp{% \\\bbl@toglobal\% \\\bbl@toglobal\}% \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 % == onchar == \ifx\bbl@KVP@onchar\@nnil\else \bbl@luahyphenate \bbl@exp{% \\\AddToHook{env/document/before}{{\\\select@language{#2}{}}}}% \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}}}% % TODO - error/warning if no script \directlua{ if Babel.script_blocks['\bbl@cl{sbcp}'] then Babel.loc_to_scr[\the\localeid] = Babel.script_blocks['\bbl@cl{sbcp}'] Babel.locale_props[\the\localeid].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 % TODO. almost the same as mapfont \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 % TODO - catch non-valid values \fi % == mapfont == % For bidi texts, to switch the font based on direction \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 % TODO. See onchar. \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: 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: CJK quotes == TODO -> @extras \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 % == 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 % ie, 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\{% \\\babel@save\\\@alph \let\\\@alph\}}% \fi \ifx\bbl@KVP@Alph\@nnil\else \bbl@exp{% \\\bbl@add\{% \\\babel@save\\\@Alph \let\\\@Alph\}}% \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 % == 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|), 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\@empty\else \bbl@exp{% \\\SetString\\##1{% \\\bbl@nocaption{\bbl@stripslash##1}{#1\bbl@stripslash##1}}}% \expandafter\bbl@tempb \fi}% \expandafter\bbl@tempb\bbl@captionslist\@empty \else \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. (TODO. But preserving previous values would be useful.) % % \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 |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 % TODO. Hackish. See above. \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. % % \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@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} % % Now, the ‘main loop’, 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 or 2. % % \begin{macrocode} \def\bbl@loop@ini{% \loop \if T\ifeof\bbl@readstream F\fi T\relax % Trick, because inside \loop \endlinechar\m@ne \read\bbl@readstream to \bbl@line \endlinechar`\^^M \ifx\bbl@line\@empty\else \expandafter\bbl@iniline\bbl@line\bbl@iniline \fi \repeat} \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`\[=12 \catcode`\]=12 \catcode`\==12 \catcode`\&=12 \catcode`\;=12 \catcode`\|=12 \catcode`\%=14 \catcode`\-=12 \bbl@info{Importing \ifcase#2font and identification \or basic \fi data for \languagename\\% from babel-#1.ini. Reported}% \ifnum#2=\z@ \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=#2\@@ \bbl@loop@ini % == Process stored data == \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{inikv@captions.licr}##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\\}% \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. TODO. To be improved. % % \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\####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{% \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\\}% \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. % % \begin{macrocode} \def\bbl@iniwarning#1{% \bbl@ifunset{bbl@@kv@identification.warning#1}{}% {\bbl@warning{% From babel-\bbl@cs{lini@\languagename}.ini:\\% \bbl@cs{@kv@identification.warning#1}\\% Reported }}} % \let\bbl@release@transforms\@empty \let\bbl@release@casing\@empty \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}{}% % Somewhat hackish. TODO: \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 \ifbbl@bcptoname \bbl@csarg\xdef{bcp@map@\bbl@cl{tbcp}}{\languagename}% \fi \ifcase\bbl@engine\or \directlua{% Babel.locale_props[\the\bbl@cs{id@@\languagename}].script = '\bbl@cl{sbcp}'}% \fi % Conditional \ifnum#1>\z@ % 0 = only info, 1, 2 = basic, (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} % % A shared handler for key=val lines to be stored in % |\bbl@@kv@
.|. % % \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}% eg, casing = uV {\bbl@exp{% \\\g@addto@macro\\\bbl@release@casing{% \\\bbl@casemapping{}{\languagename}{\unexpanded{#2}}}}}% {\in@{$casing.}{$#1}% eg, 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{inikv@captions.licr}#1#2{% \bbl@ini@captions@aux{#1}{#2}} \else \def\bbl@inikv@captions#1#2{% \bbl@ini@captions@aux{#1}{#2}} \fi % \end{macrocode} % % The auxiliary macro for captions define |\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\{% \\\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@tempa name>}% \\\bbl@toglobal\}% \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@inikv@labels#1#2{% \in@{.map}{#1}% \ifin@ \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\% {\ifin@\<#2>\else\\\localecounter{#2}\fi}}% \bbl@foreach\bbl@list@the{% \bbl@ifunset{the##1}{}% {\bbl@exp{\let\\\bbl@tempd\}% \bbl@exp{% \\\bbl@sreplace\% {\<\bbl@tempc>{##1}}{\\\bbl@map@cnt{\bbl@tempc}{##1}}% \\\bbl@sreplace\% {\<\@empty @\bbl@tempc>\}{\\\bbl@map@cnt{\bbl@tempc}{##1}}}% \expandafter\ifx\csname the##1\endcsname\bbl@tempd\else \toks@\expandafter\expandafter\expandafter{% \csname the##1\endcsname}% \expandafter\xdef\csname the##1\endcsname{{\the\toks@}}% \fi}}% \fi \fi % \else % % The following code is still under study. You can test it and make % suggestions. Eg, 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}% % TODO. Execute only once: \bbl@exp{% \\\bbl@add\{% \\\babel@save\% \def\{\the\toks@}}% \\\bbl@toglobal\}% \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. TODO. Document % % \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@replace\bbl@tempe{ }{}% \bbl@replace\bbl@tempe{CONVERT}{convert=}% Hackish \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, eg, +, -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} % eg: 1=months, 2=wide, 3=1, 4=dummy, 5=value, 6=calendar \def\bbl@inidate#1.#2.#3.#4\relax#5#6{% TODO - ignore with 'captions' \bbl@trim@def\bbl@tempa{#1.#2}% \bbl@ifsamestring{\bbl@tempa}{months.wide}% to savedate {\bbl@trim@def\bbl@tempa{#3}% \bbl@trim\toks@{#5}% \@temptokena\expandafter{\bbl@savedate}% \bbl@exp{% Reverse order - in ini last wins \def\\\bbl@savedate{% \\\SetString\{\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{% TODO. Move to a better place. \\\AfterBabelCommands{% \def\<\languagename date>{\\\protect\<\languagename date >}% \\\newcommand\<\languagename date >[4][]{% \\\bbl@usedategrouptrue \{% \\\localedate[####1]{####2}{####3}{####4}}}}% \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{.\@} % TODO. \let instead of repeating \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}} % TODO - add leading 0 \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} % % \textbf{Transforms.} % % \begin{macrocode} \bbl@csarg\let{inikv@transforms.prehyphenation}\bbl@inikv \bbl@csarg\let{inikv@transforms.posthyphenation}\bbl@inikv \def\bbl@transforms@aux#1#2#3#4,#5\relax{% #1[#2]{#3}{#4}{#5}} \begingroup % A hack. TODO. Don't require an specific order \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} % % Language and Script values to be used when defining a font or % setting the direction are set with the following macros. % % \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}} \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}} % \fi} % \end{macrocode} % % The following |ini| reader ignores everything but the % |identification| section. It is called when a font is defined (ie, % when the language is first selected) to know which script/language % must be enabled. This means we must make sure a few characters are % not active. The |ini| is not read directly, but with a proxy |tex| % file named as the language (which means any code in it must be % skipped, too). % % \begin{macrocode} \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} % % 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{% ie, \langdigits \####1\\\@nil}% \let\\<\languagename digits>% \def\<\languagename counter>####1{% ie, \langcounter \\\expandafter\% \\\csname c@####1\endcsname}% \def\####1{% ie, \bbl@counter@lang \\\expandafter\% \\\number####1\\\@nil}}% \def\bbl@tempa##1##2##3##4##5{% \bbl@exp{% Wow, quite a lot of hashes! :-( \def\########1{% \\\ifx########1\\\@nil % ie, \bbl@digits@lang \\\else \\\ifx0########1#1% \\\else\\\ifx1########1#2% \\\else\\\ifx2########1#3% \\\else\\\ifx3########1#4% \\\else\\\ifx4########1#5% \\\else\\\ifx5########1##1% \\\else\\\ifx6########1##2% \\\else\\\ifx7########1##3% \\\else\\\ifx8########1##4% \\\else\\\ifx9########1##5% \\\else########1% \\\fi\\\fi\\\fi\\\fi\\\fi\\\fi\\\fi\\\fi\\\fi\\\fi \\\expandafter\% \\\fi}}}% \bbl@tempa} % \end{macrocode} % % Alphabetic counters must be converted from a space separated list to % an |\ifcase| structure. % % \begin{macrocode} \def\bbl@buildifcase#1 {% Returns \bbl@tempa, requires \toks@={} \ifx\\#1% % \\ before, in case #1 is multiletter \bbl@exp{% \def\\\bbl@tempa####1{% \####1\space\the\toks@\\\\@ctrerr\}}% \else \toks@\expandafter{\the\toks@\or #1}% \expandafter\bbl@buildifcase \fi} % \end{macrocode} % % The code for additive counters is somewhat tricky and it's based on % the fact the arguments just before |\@@| collects digits which have % been left ‘unused’ in previous arguments, the first of them being the % number of digits in the number to be converted. This explains the % reverse set |76543210|. Digits above 10000 are not handled yet. When % the key contains the subkey |.F.|, the number after is treated as an % special case, for a fixed form (see |babel-he.ini|, for example). % % \begin{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@ % TODO. An ad hoc rule for Greek. Ugly. \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} % % 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 % TODO. A bit hackish to make it expandable. \bbl@afterelse\bbl@localeinfo{}% \else \bbl@localeinfo {\bbl@error{no-ini-info}{}{}{}}% {#1}% \fi} % \@namedef{bbl@info@name.locale}{lcname} \@namedef{bbl@info@tag.ini}{lini} \@namedef{bbl@info@name.english}{elname} \@namedef{bbl@info@name.opentype}{lname} \@namedef{bbl@info@tag.bcp47}{tbcp} \@namedef{bbl@info@language.tag.bcp47}{lbcp} \@namedef{bbl@info@tag.opentype}{lotf} \@namedef{bbl@info@script.name}{esname} \@namedef{bbl@info@script.name.opentype}{sname} \@namedef{bbl@info@script.tag.bcp47}{sbcp} \@namedef{bbl@info@script.tag.opentype}{sotf} \@namedef{bbl@info@region.tag.bcp47}{rbcp} \@namedef{bbl@info@variant.tag.bcp47}{vbcp} \@namedef{bbl@info@extension.t.tag.bcp47}{extt} \@namedef{bbl@info@extension.u.tag.bcp47}{extu} \@namedef{bbl@info@extension.x.tag.bcp47}{extx} % \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.|\m{s} for % singletons may change. % % \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 % Still somewhat hackish. WIP. Note |\str_if_eq:nnTF| is fully % expandable (|\bbl@ifsamestring| isn’t). \providecommand\BCPdata{} \ifx\renewcommand\@undefined\else % For plain. TODO. It’s a quick fix \renewcommand\BCPdata[1]{\bbl@bcpdata@i#1\@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@info@casing.tag.bcp47}{casing} \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} \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 % TODO. needed? \fi \expandafter\bbl@casemapping@ii\bbl@tempb\@@} \def\bbl@casemapping@ii#1#2#3\@@{% \in@{#1#3}{<>}% ie, if , , \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} % % With version 3.75 |\BabelEnsureInfo| is executed always, but there is % an option to disable it. % % \begin{macrocode} %<<*More package options>> \DeclareOption{ensureinfo=off}{} %<> \let\bbl@ensureinfo\@gobble \newcommand\BabelEnsureInfo{% \ifx\InputIfFileExists\@undefined\else \def\bbl@ensureinfo##1{% \bbl@ifunset{bbl@lname@##1}{\bbl@load@info{##1}}{}}% \fi \bbl@foreach\bbl@loaded{{% \let\bbl@ensuring\@empty % Flag used in a couple of babel-*.tex files \def\languagename{##1}% \bbl@ensureinfo{##1}}}} \@ifpackagewith{babel}{ensureinfo=off}{}% {\AtEndOfPackage{% Test for plain. \ifx\@undefined\bbl@loaded\else\BabelEnsureInfo\fi}} % \end{macrocode} % % More general, but non-expandable, is |\getlocaleproperty|. To inspect % every possible loaded |ini|, we define |\LocaleForEach|, where % |\bbl@ini@loaded| is a comma-separated list of locales, built by % |\bbl@read@ini|. % % \begin{macrocode} \newcommand\getlocaleproperty{% \@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} \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 = ##3}}% \@nameuse{bbl@inidata@#1}% \typeout{*******}} % \end{macrocode} % % \section{Adjusting the Babel bahavior} % % A generic high level interface is provided to adjust some global % and general settings. % % \begin{macrocode} \newcommand\babeladjust[1]{% TODO. Error handling. \bbl@forkv{#1}{% \bbl@ifunset{bbl@ADJ@##1@##2}% {\bbl@cs{ADJ@##1}{##2}}% {\bbl@cs{ADJ@##1@##2}}}} % \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@ADJ@bidi.mirroring@on}{% \bbl@adjust@lua{bidi}{mirroring_enabled=true}} \@namedef{bbl@ADJ@bidi.mirroring@off}{% \bbl@adjust@lua{bidi}{mirroring_enabled=false}} \@namedef{bbl@ADJ@bidi.text@on}{% \bbl@adjust@lua{bidi}{bidi_enabled=true}} \@namedef{bbl@ADJ@bidi.text@off}{% \bbl@adjust@lua{bidi}{bidi_enabled=false}} \@namedef{bbl@ADJ@bidi.math@on}{% \let\bbl@noamsmath\@empty} \@namedef{bbl@ADJ@bidi.math@off}{% \let\bbl@noamsmath\relax} \@namedef{bbl@ADJ@bidi.mapdigits@on}{% \bbl@adjust@lua{bidi}{digits_mapped=true}} \@namedef{bbl@ADJ@bidi.mapdigits@off}{% \bbl@adjust@lua{bidi}{digits_mapped=false}} % \@namedef{bbl@ADJ@linebreak.sea@on}{% \bbl@adjust@lua{linebreak}{sea_enabled=true}} \@namedef{bbl@ADJ@linebreak.sea@off}{% \bbl@adjust@lua{linebreak}{sea_enabled=false}} \@namedef{bbl@ADJ@linebreak.cjk@on}{% \bbl@adjust@lua{linebreak}{cjk_enabled=true}} \@namedef{bbl@ADJ@linebreak.cjk@off}{% \bbl@adjust@lua{linebreak}{cjk_enabled=false}} \@namedef{bbl@ADJ@justify.arabic@on}{% \bbl@adjust@lua{linebreak}{arabic.justify_enabled=true}} \@namedef{bbl@ADJ@justify.arabic@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@ADJ@layout.tabular@on}{% \ifnum\bbl@tabular@mode=\tw@ \bbl@adjust@layout{\let\@tabular\bbl@NL@@tabular}% \else \chardef\bbl@tabular@mode\@ne \fi} \@namedef{bbl@ADJ@layout.tabular@off}{% \ifnum\bbl@tabular@mode=\tw@ \bbl@adjust@layout{\let\@tabular\bbl@OL@@tabular}% \else \chardef\bbl@tabular@mode\z@ \fi} \@namedef{bbl@ADJ@layout.lists@on}{% \bbl@adjust@layout{\let\list\bbl@NL@list}} \@namedef{bbl@ADJ@layout.lists@off}{% \bbl@adjust@layout{\let\list\bbl@OL@list}} % \@namedef{bbl@ADJ@autoload.bcp47@on}{% \bbl@bcpallowedtrue} \@namedef{bbl@ADJ@autoload.bcp47@off}{% \bbl@bcpallowedfalse} \@namedef{bbl@ADJ@autoload.bcp47.prefix}#1{% \def\bbl@bcp@prefix{#1}} \def\bbl@bcp@prefix{bcp47-} \@namedef{bbl@ADJ@autoload.options}#1{% \def\bbl@autoload@options{#1}} \let\bbl@autoload@bcpoptions\@empty \@namedef{bbl@ADJ@autoload.bcp47.options}#1{% \def\bbl@autoload@bcpoptions{#1}} \newif\ifbbl@bcptoname \@namedef{bbl@ADJ@bcp47.toname@on}{% \bbl@bcptonametrue \BabelEnsureInfo} \@namedef{bbl@ADJ@bcp47.toname@off}{% \bbl@bcptonamefalse} \@namedef{bbl@ADJ@prehyphenation.disable@nohyphenation}{% \directlua{ Babel.ignore_pre_char = function(node) return (node.lang == \the\csname l@nohyphenation\endcsname) end }} \@namedef{bbl@ADJ@prehyphenation.disable@off}{% \directlua{ Babel.ignore_pre_char = function(node) return false end }} \@namedef{bbl@ADJ@interchar.disable@nohyphenation}{% \def\bbl@ignoreinterchar{% \ifnum\language=\l@nohyphenation \expandafter\@gobble \else \expandafter\@firstofone \fi}} \@namedef{bbl@ADJ@interchar.disable@off}{% \let\bbl@ignoreinterchar\@firstofone} \@namedef{bbl@ADJ@select.write@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@ADJ@select.write@keep}{% \let\bbl@restorelastskip\relax \let\bbl@savelastskip\relax} \@namedef{bbl@ADJ@select.write@omit}{% \AddBabelHook{babel-select}{beforestart}{% \expandafter\babel@aux\expandafter{\bbl@main@language}{}}% \let\bbl@restorelastskip\relax \def\bbl@savelastskip##1\bbl@restorelastskip{}} \@namedef{bbl@ADJ@select.encoding@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}} %<> % \end{macrocode} % % \begin{macro}{\@newl@bel} % % First we open a new group to keep the changed setting of % |\protect| local and then we set the |@safe@actives| switch to % true to make sure that any shorthand that appears in any of the % arguments immediately expands to its non-active self. % % \begin{macrocode} \bbl@trace{Cross referencing macros} \ifx\bbl@opt@safe\@empty\else % ie, 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} % % \end{macro} % % \begin{macro}{\@testdef} % % An internal \LaTeX\ macro used to test if the labels that have % been written on the |.aux| file have changed. It is called by % the |\enddocument| macro. % % \begin{macrocode} \CheckCommand*\@testdef[3]{% \def\reserved@a{#3}% \expandafter\ifx\csname#1@#2\endcsname\reserved@a \else \@tempswatrue \fi} % \end{macrocode} % % Now that we made sure that |\@testdef| still has the same definition % we can rewrite it. First we make the shorthands `safe'. Then we use % |\bbl@tempa| as an `alias' for the macro that contains the label % which is being checked. Then we define |\bbl@tempb| just as % |\@newl@bel| does it. When the label is defined we replace the % definition of |\bbl@tempa| by its meaning. If the label didn't % change, |\bbl@tempa| and |\bbl@tempb| should be identical macros. % % \begin{macrocode} \def\@testdef#1#2#3{% TODO. With @samestring? \@safe@activestrue \expandafter\let\expandafter\bbl@tempa\csname #1@#2\endcsname \def\bbl@tempb{#3}% \@safe@activesfalse \ifx\bbl@tempa\relax \else \edef\bbl@tempa{\expandafter\strip@prefix\meaning\bbl@tempa}% \fi \edef\bbl@tempb{\expandafter\strip@prefix\meaning\bbl@tempb}% \ifx\bbl@tempa\bbl@tempb \else \@tempswatrue \fi} \fi % \end{macrocode} % % \end{macro} % % \begin{macro}{\ref} % \begin{macro}{\pageref} % % The same holds for the macro |\ref| that references a label and % |\pageref| to reference a page. We make them robust as well (if % they weren't already) to prevent problems if they should become % expanded at the wrong moment. % % \begin{macrocode} \bbl@xin@{R}\bbl@opt@safe \ifin@ \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} % % \end{macro} % \end{macro} % % \begin{macro}{\@citex} % % The macro used to cite from a bibliography, |\cite|, uses an % internal macro, |\@citex|. % It is this internal macro that picks up the argument(s), % so we redefine this internal macro and leave |\cite| alone. The % first argument is used for typesetting, so the shorthands need % only be deactivated in the second argument. % % \begin{macrocode} \bbl@xin@{B}\bbl@opt@safe \ifin@ \bbl@redefine\@citex[#1]#2{% \@safe@activestrue\edef\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. % % \begin{macrocode} \AtBeginDocument{% \@ifpackageloaded{natbib}{% % \end{macrocode} % % Notice that we use |\def| here instead of |\bbl@redefine| because % |\org@@citex| is already defined and we don't want to overwrite % that definition (it would result in parameter stack overflow % because of a circular definition). % % (Recent versions of \pkg{natbib} change dynamically |\@citex|, so PR4087 % doesn't seem fixable in a simple way. Just load \pkg{natbib} before.) % % \begin{macrocode} \def\@citex[#1][#2]#3{% \@safe@activestrue\edef\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} % % \end{macro} % % \begin{macro}{\nocite} % % The macro |\nocite| which is used to instruct BiB\TeX\ to % extract uncited references from the database. % % \begin{macrocode} \bbl@redefine\nocite#1{% \@safe@activestrue\org@nocite{#1}\@safe@activesfalse} % \end{macrocode} % % \end{macro} % % \begin{macro}{\bibcite} % % The macro that is used in the |.aux| file to % define citation labels. When packages such as \pkg{natbib} or % \pkg{cite} are not loaded its second argument is used to typeset the % citation label. In that case, this second argument can contain % active characters but is used in an environment where % |\@safe@activestrue| is in effect. This switch needs to be reset % inside the |\hbox| which contains the citation label. In order to % determine during \file{.aux} file processing which definition of % |\bibcite| is needed we define |\bibcite| in such a way that it % redefines itself with the proper definition. We call % |\bbl@cite@choice| to select the proper definition for |\bibcite|. % This new definition is then activated. % % \begin{macrocode} \bbl@redefine\bibcite{% \bbl@cite@choice \bibcite} % \end{macrocode} % % \end{macro} % % \begin{macro}{\bbl@bibcite} % % The macro |\bbl@bibcite| holds the definition of |\bibcite| % needed when neither \pkg{natbib} nor \pkg{cite} is loaded. % % \begin{macrocode} \def\bbl@bibcite#1#2{% \org@bibcite{#1}{\@safe@activesfalse#2}} % \end{macrocode} % % \end{macro} % % \begin{macro}{\bbl@cite@choice} % % The macro |\bbl@cite@choice| determines which definition of % |\bibcite| is needed. First we give |\bibcite| its default % definition. % % \begin{macrocode} \def\bbl@cite@choice{% \global\let\bibcite\bbl@bibcite \@ifpackageloaded{natbib}{\global\let\bibcite\org@bibcite}{}% \@ifpackageloaded{cite}{\global\let\bibcite\org@bibcite}{}% \global\let\bbl@cite@choice\relax} % \end{macrocode} % % When a document is run for the first time, no \file{.aux} file is % available, and |\bibcite| will not yet be properly defined. In % this case, this has to happen before the document starts. % % \begin{macrocode} \AtBeginDocument{\bbl@cite@choice} % \end{macrocode} % % \end{macro} % % \begin{macro}{\@bibitem} % % One of the two internal \LaTeX\ macros called by |\bibitem| % that write the citation label on the |.aux| file. % % \begin{macrocode} \bbl@redefine\@bibitem#1{% \@safe@activestrue\org@@bibitem{#1}\@safe@activesfalse} \else \let\org@nocite\nocite \let\org@@citex\@citex \let\org@bibcite\bibcite \let\org@@bibitem\@bibitem \fi % \end{macrocode} % % \end{macro} % % \subsection{Marks} % % \begin{macro}{\markright} % Because the output routine is asynchronous, we must pass the % current language attribute to the head lines. To achieve this we % need to adapt the definition of |\markright| and |\markboth| % somewhat. However, headlines and footlines can contain text % outside marks; for that we must take some actions in the output % routine if the 'headfoot' options is used. % % We need to make some redefinitions to the output routine % to avoid an endless loop and to correctly handle the page number % in bidi documents. % % \begin{macrocode} \bbl@trace{Marks} \IfBabelLayout{sectioning} {\ifx\bbl@opt@headfoot\@nnil \g@addto@macro\@resetactivechars{% \set@typeset@protect \expandafter\select@language@x\expandafter{\bbl@main@language}% \let\protect\noexpand \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} % % \end{macro} % % \begin{macro}{\markboth} % \begin{macro}{\@mkboth} % The definition of |\markboth| is equivalent to that of % |\markright|, except that we need two token registers. The % documentclasses \cls{report} and \cls{book} define and set the % headings for the page. While doing so they also store a copy of % |\markboth| in |\@mkboth|. Therefore we need to check whether % |\@mkboth| has already been set. If so we neeed to do that again % with the new definition of |\markboth|. (As of Oct 2019, \LaTeX{} % stores the definition in an intermediate macro, so it's not % necessary anymore, but it's preserved for older versions.) % % \begin{macrocode} \ifx\@mkboth\markboth \def\bbl@tempc{\let\@mkboth\markboth}% \else \def\bbl@tempc{}% \fi \bbl@ifunset{markboth }\bbl@redefine\bbl@redefinerobust \markboth#1#2{% \protected@edef\bbl@tempb##1{% \protect\foreignlanguage {\languagename}{\protect\bbl@restore@actives##1}}% \bbl@ifblank{#1}% {\toks@{}}% {\toks@\expandafter{\bbl@tempb{#1}}}% \bbl@ifblank{#2}% {\@temptokena{}}% {\@temptokena\expandafter{\bbl@tempb{#2}}}% \bbl@exp{\\\org@markboth{\the\toks@}{\the\@temptokena}}}% \bbl@tempc \fi} % end ifbbl@single, end \IfBabelLayout % \end{macrocode} % % \end{macro} % \end{macro} % % \subsection{Preventing clashes with other packages} % % \subsubsection{\pkg{ifthen}} % % \begin{macro}{\ifthenelse} % % Sometimes a document writer wants to create a special effect % depending on the page a certain fragment of text appears on. This % can be achieved by the following piece of code: %\begin{verbatim} % \ifthenelse{\isodd{\pageref{some:label}}} % {code for odd pages} % {code for even pages} %\end{verbatim} % In order for this to work the argument of |\isodd| needs to be % fully expandable. With the above redefinition of |\pageref| it is % not in the case of this example. To overcome that, we add some % code to the definition of |\ifthenelse| to make things work. % % We want to revert the definition of |\pageref| and |\ref| to % their original definition for the first argument of |\ifthenelse|, % so we first need to store their current meanings. % % Then we can set the |\@safe@actives| switch and call the original % |\ifthenelse|. In order to be able to use shorthands in the % second and third arguments of |\ifthenelse| the resetting of the % switch \emph{and} the definition of |\pageref| happens inside % those arguments. % % \begin{macrocode} \bbl@trace{Preventing clashes with other packages} \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} % % \end{macro} % % \subsubsection{\pkg{varioref}} % % \begin{macro}{\@@vpageref} % \begin{macro}{\vrefpagenum} % \begin{macro}{\Ref} % % When the package varioref is in use we need to modify its % internal command |\@@vpageref| in order to prevent problems when % an active character ends up in the argument of |\vref|. The same % needs to happen for |\vrefpagenum|. % % \begin{macrocode} \AtBeginDocument{% \@ifpackageloaded{varioref}{% \bbl@redefine\@@vpageref#1[#2]#3{% \@safe@activestrue \org@@@vpageref{#1}[#2]{#3}% \@safe@activesfalse}% \bbl@redefine\vrefpagenum#1#2{% \@safe@activestrue \org@vrefpagenum{#1}{#2}% \@safe@activesfalse}% % \end{macrocode} % % The package \pkg{varioref} defines |\Ref| to be a robust command % wich uppercases the first character of the reference text. In % order to be able to do that it needs to access the expandable form % of |\ref|. So we employ a little trick here. We redefine the % (internal) command \verb*|\Ref | to call |\org@ref| instead of % |\ref|. The disadvantage of this solution is that whenever the % definition of |\Ref| changes, this definition needs to be updated % as well. % % \begin{macrocode} \expandafter\def\csname Ref \endcsname#1{% \protected@edef\@tempa{\org@ref{#1}}\expandafter\MakeUppercase\@tempa} }{}% } \fi % \end{macrocode} % % \end{macro} % \end{macro} % \end{macro} % % \subsubsection{\pkg{hhline}} % % \begin{macro}{\hhline} % % Delaying the activation of the shorthand characters has introduced % a problem with the \pkg{hhline} package. The reason is that it % uses the `:' character which is made active by the french support % in \babel. Therefore we need to \emph{reload} the package when % the `:' is an active character. Note that this happens % \emph{after} the category code of the @-sign has been changed to % other, so we need to temporarily change it to letter again. % % \begin{macrocode} \AtEndOfPackage{% \AtBeginDocument{% \@ifpackageloaded{hhline}% {\expandafter\ifx\csname normal@char\string:\endcsname\relax \else \makeatletter \def\@currname{hhline}\input{hhline.sty}\makeatother \fi}% {}}} % \end{macrocode} % % \end{macro} % % \begin{macro}{\substitutefontfamily} % % \textit{Deprecated.} Use the tools provides by \LaTeX. The command % |\substitutefontfamily| creates an \file{.fd} file on the fly. The % first argument is an encoding mnemonic, the second and third % arguments are font family names. % % \begin{macrocode} \def\substitutefontfamily#1#2#3{% \lowercase{\immediate\openout15=#1#2.fd\relax}% \immediate\write15{% \string\ProvidesFile{#1#2.fd}% [\the\year/\two@digits{\the\month}/\two@digits{\the\day} \space generated font description file]^^J \string\DeclareFontFamily{#1}{#2}{}^^J \string\DeclareFontShape{#1}{#2}{m}{n}{<->ssub * #3/m/n}{}^^J \string\DeclareFontShape{#1}{#2}{m}{it}{<->ssub * #3/m/it}{}^^J \string\DeclareFontShape{#1}{#2}{m}{sl}{<->ssub * #3/m/sl}{}^^J \string\DeclareFontShape{#1}{#2}{m}{sc}{<->ssub * #3/m/sc}{}^^J \string\DeclareFontShape{#1}{#2}{b}{n}{<->ssub * #3/bx/n}{}^^J \string\DeclareFontShape{#1}{#2}{b}{it}{<->ssub * #3/bx/it}{}^^J \string\DeclareFontShape{#1}{#2}{b}{sl}{<->ssub * #3/bx/sl}{}^^J \string\DeclareFontShape{#1}{#2}{b}{sc}{<->ssub * #3/bx/sc}{}^^J }% \closeout15 } \@onlypreamble\substitutefontfamily % \end{macrocode} % % \end{macro} % % \subsection{Encoding and fonts} % % Because documents may use non-ASCII font encodings, we make sure % that the logos of \TeX\ and \LaTeX\ always come out in the right % encoding. There is a list of non-ASCII encodings. 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|. % % \begin{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} % % \end{macro} % % Now comes the old deprecated stuff (with a little change in 3.9l, % for \textsf{fontspec}). The first thing we need to do is to % determine, at |\begin{document}|, which latin fontencoding to use. % % \begin{macro}{\latinencoding} % When text is being typeset in an encoding other than `latin' % (\texttt{OT1} or \texttt{T1}), it would be nice to still have % Roman numerals come out in the Latin encoding. % So we first assume that the current encoding at the end % of processing the package is the Latin encoding. % % \begin{macrocode} \AtEndOfPackage{\edef\latinencoding{\cf@encoding}} % \end{macrocode} % % But this might be overruled with a later loading of the package % \pkg{fontenc}. Therefore we check at the execution of % |\begin{document}| whether it was loaded with the \Lopt{T1} % option. The normal way to do this (using |\@ifpackageloaded|) is % disabled for this package. Now we have to revert to parsing the % internal macro |\@filelist| which contains all the filenames % loaded. % % \begin{macrocode} \AtBeginDocument{% \@ifpackageloaded{fontspec}% {\xdef\latinencoding{% \ifx\UTFencname\@undefined EU\ifcase\bbl@engine\or2\or1\fi \else \UTFencname \fi}}% {\gdef\latinencoding{OT1}% \ifx\cf@encoding\bbl@t@one \xdef\latinencoding{\bbl@t@one}% \else \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} % % \end{macro} % % \begin{macro}{\latintext} % Then we can define the command |\latintext| which is a % declarative switch to a latin font-encoding. Usage of this macro % is deprecated. % % \begin{macrocode} \DeclareRobustCommand{\latintext}{% \fontencoding{\latinencoding}\selectfont \def\encodingdefault{\latinencoding}} % \end{macrocode} % % \end{macro} % % \begin{macro}{\textlatin} % This command takes an argument which is then typeset using the % requested font encoding. In order to avoid many encoding switches % it operates in a local scope. % % \begin{macrocode} \ifx\@undefined\DeclareTextFontCommand \DeclareRobustCommand{\textlatin}[1]{\leavevmode{\latintext #1}} \else \DeclareTextFontCommand{\textlatin}{\latintext} \fi % \end{macrocode} % % 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} % % \end{macro} % % \subsection{Basic bidi support} % % \textbf{Work in progress.} This code is currently placed here for % practical reasons. It will be moved to the correct place soon, I % hope. % % It is loosely based on |rlbabel.def|, but most of it has been % developed from scratch. This \babel{} module (by Johannes Braams and % Boris Lavva) has served the purpose of typesetting R documents for % two decades, and despite its flaws I think it is still a good starting % point (some parts have been copied here almost verbatim), partly % thanks to its simplicity. I've also looked at \textsc{arabi} (by % Youssef Jabri), which is compatible with \babel{}. % % There are two ways of modifying macros to make them “bidi”, namely, % by patching the internal low-level macros (which is what I have done % with lists, columns, counters, tocs, much like |rlbabel| did), and % by introducing a “middle layer” just below the user interface % (sectioning, footnotes). % % \begin{itemize} % \item pdftex provides a minimal support for bidi text, and it % must be done by hand. Vertical typesetting is not possible. % \item \xetex{} is somewhat better, thanks to its font engine % (even if not always reliable) and a few additional tools. However, % very little is done at the paragraph level. Another challenging % problem is text direction does not honour \TeX{} grouping. % \item \luatex{} can provide the most complete solution, as we can % manipulate almost freely the node list, the generated lines, % and so on, but bidi text does not work out of the box and some % development is necessary. It also provides tools to properly % set left-to-right and right-to-left page layouts. As Lua\TeX-ja % shows, vertical typesetting is possible, too. % \end{itemize} % % \begin{macrocode} \bbl@trace{Loading basic (internal) bidi support} \ifodd\bbl@engine \else % TODO. Move to txtbabel \ifnum\bbl@bidimode>100 \ifnum\bbl@bidimode<200 % Any xe+lua bidi= \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}% \bbl@loadfontspec % bidi needs fontspec \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 % TODO? Separate: \ifnum\bbl@bidimode=\@ne % Any bidi= except default=1 \let\bbl@beforeforeign\leavevmode \ifodd\bbl@engine \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}% \ifodd\bbl@engine\else \bbl@xebidipar \fi} \fi % \end{macrocode} % % Now come the macros used to set the direction when a language is % switched. First the (mostly) common macros. % % \begin{macrocode} \bbl@trace{Macros to switch the text direction} \def\bbl@alscripts{,Arabic,Syriac,Thaana,} \def\bbl@rscripts{% TODO. Base on codes ?? ,Imperial Aramaic,Avestan,Cypriot,Hatran,Hebrew,% Old Hungarian,Lydian,Mandaean,Manichaean,% Meroitic Cursive,Meroitic,Old North Arabian,% Nabataean,N'Ko,Orkhon,Palmyrene,Inscriptional Pahlavi,% Psalter Pahlavi,Phoenician,Inscriptional Parthian,Samaritan,% Old South Arabian,}% \def\bbl@provide@dirs#1{% \bbl@xin@{\csname bbl@sname@#1\endcsname}{\bbl@alscripts\bbl@rscripts}% \ifin@ \global\bbl@csarg\chardef{wdir@#1}\@ne \bbl@xin@{\csname bbl@sname@#1\endcsname}{\bbl@alscripts}% \ifin@ \global\bbl@csarg\chardef{wdir@#1}\tw@ \fi \else \global\bbl@csarg\chardef{wdir@#1}\z@ \fi \ifodd\bbl@engine \bbl@csarg\ifcase{wdir@#1}% \directlua{ Babel.locale_props[\the\localeid].textdir = 'l' }% \or \directlua{ Babel.locale_props[\the\localeid].textdir = 'r' }% \or \directlua{ Babel.locale_props[\the\localeid].textdir = 'al' }% \fi \fi} \def\bbl@switchdir{% \bbl@ifunset{bbl@lsys@\languagename}{\bbl@provide@lsys{\languagename}}{}% \bbl@ifunset{bbl@wdir@\languagename}{\bbl@provide@dirs{\languagename}}{}% \bbl@exp{\\\bbl@setdirs\bbl@cl{wdir}}} \def\bbl@setdirs#1{% TODO - math \ifcase\bbl@select@type % TODO - strictly, not the right test \bbl@bodydir{#1}% \bbl@pardir{#1}% <- Must precede \bbl@textdir \fi \bbl@textdir{#1}} % TODO. Only if \bbl@bidimode > 0?: \AddBabelHook{babel-bidi}{afterextras}{\bbl@switchdir} \DisableBabelHook{babel-bidi} % \end{macrocode} % % Now the engine-dependent macros. TODO. Must be moved to the engine % files. % % \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}% \let\bbl@severypar\everypar \newtoks\everypar \everypar=\bbl@severypar \bbl@severypar{\bbl@xeeverypar\the\everypar}} \ifnum\bbl@bidimode>200 % Any xe bidi= \let\bbl@textdir@i\@gobbletwo \let\bbl@xebidipar\@empty \AddBabelHook{bidi}{foreign}{% \def\bbl@tempa{\def\BabelText####1}% \ifcase\bbl@thetextdir \expandafter\bbl@tempa\expandafter{\BabelText{\LR{##1}}}% \else \expandafter\bbl@tempa\expandafter{\BabelText{\RL{##1}}}% \fi} \def\bbl@pardir#1{\ifcase#1\relax\setLR\else\setRL\fi} \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} % % \begin{macro}{\loadlocalcfg} % % At some sites it may be necessary to add site-specific actions to % a language definition file. This can be done by creating a file % with the same name as the language definition file, but with the % extension \file{.cfg}. For instance the file \file{norsk.cfg} % will be loaded when the language definition file \file{norsk.ldf} % is loaded. % % For plain-based formats we don't want to override the definition % of |\loadlocalcfg| from \file{plain.def}. % % \begin{macrocode} \bbl@trace{Local Language Configuration} \ifx\loadlocalcfg\@undefined \@ifpackagewith{babel}{noconfigs}% {\let\loadlocalcfg\@gobble}% {\def\loadlocalcfg#1{% \InputIfFileExists{#1.cfg}% {\typeout{*************************************^^J% * Local config file #1.cfg used^^J% *}}% \@empty}} \fi % \end{macrocode}% % \end{macro} % % \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} \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{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{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=|, which will % load |.cfg| instead. % % \begin{macrocode} \ifx\bbl@opt@config\@nnil \@ifpackagewith{babel}{noconfigs}{}% {\InputIfFileExists{bblopts.cfg}% {\typeout{*************************************^^J% * Local config file bblopts.cfg used^^J% *}}% {}}% \else \InputIfFileExists{\bbl@opt@config.cfg}% {\typeout{*************************************^^J% * Local config file \bbl@opt@config.cfg used^^J% *}}% {\bbl@error{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 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. % % \begin{macrocode} \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{\@classoptionslist,\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 % ie, 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 \bbl@info{Main language set with 'main='. Except if you have\\% problems, prefer the default mechanism for setting\\% the main language, ie, 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\@classoptionslist{% \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. % % The options have to be processed in the order in which the user % specified them (but remember class options are processes before): % % \begin{macrocode} \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{\@classoptionslist,\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 % % \end{macrocode} % % \section{The kernel of Babel (\texttt{babel.def}, common)} % % 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 % % % \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. % %<*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 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 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 \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@opt@config.cfg' 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.} % %<*patterns> % \end{macrocode} % % \end{macro} % \end{macro} % \end{macro} % % \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} % % \begin{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} % % \end{macro} % % \begin{macro}{\process@synonym} % % This macro takes care of the lines which start with an % \texttt{=}. It needs an empty token register to begin with. % |\bbl@languages| is also set to empty. % % \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} % % \end{macro} % % \begin{macro}{\process@language} % % The macro |\process@language| is used to process a non-empty line % from the `configuration file'. It has three arguments, each % delimited by white space. The first argument is the `name' of a % language; the second is the name of the file that contains the % patterns. The optional third argument is the name of a file % containing hyphenation exceptions. % % The first thing to do is call |\addlanguage| to allocate a pattern % register and to make that register `active'. Then the pattern file % is read. % % For some hyphenation patterns it is needed to load them with a % specific font encoding selected. This can be specified in the % file \file{language.dat} by adding for instance `\texttt{:T1}' to % the name of the language. The macro |\bbl@get@enc| extracts the % font encoding from the language name and stores it in % |\bbl@hyph@enc|. The latter can be used in hyphenation files if % you need to set a behavior depending on the given encoding (it % is set to empty if no encoding is given). % % Pattern files may contain assignments to |\lefthyphenmin| and % |\righthyphenmin|. \TeX\ does not keep track of these % assignments. Therefore we try to detect such assignments and % store them in the |\|\langvar|hyphenmins| macro. When no % assignments were made we provide a default setting. % % Some pattern files contain changes to the |\lccode| en |\uccode| % arrays. Such changes should remain local to the language; % therefore we process the pattern file in a group; the |\patterns| % command acts globally so its effect will be remembered. % % Then we globally store the settings of |\lefthyphenmin| and % |\righthyphenmin| and close the group. % % When the hyphenation patterns have been processed we need to see % if a file with hyphenation exceptions needs to be read. This is % the case when the third argument is not empty and when it does % not contain a space token. (Note however there is no need to save % hyphenation exceptions into the format.) % % \cs{bbl@languages} saves a snapshot of the loaded languages in the % form \cs{bbl@elt}\marg{language-name}\marg{number}% % \marg{patterns-file}\marg{exceptions-file}. Note the last 2 % arguments are empty in `dialects' defined in |language.dat| with % |=|. Note also the language name can have encoding info. % % Finally, if the counter |\language| is equal to zero we execute the % synonyms stored. % % \begin{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} % % \begin{macro}{\bbl@get@enc} % % \begin{macro}{\bbl@hyph@enc} % The macro |\bbl@get@enc| extracts the font encoding from the % language name and stores it in |\bbl@hyph@enc|. It uses delimited % arguments to achieve this. % % \begin{macrocode} \def\bbl@get@enc#1:#2:#3\@@@{\def\bbl@hyph@enc{#2}} % \end{macrocode} % % \end{macro} % \end{macro} % \end{macro} % % Now, hooks are defined. For efficiency reasons, they are dealt % here in a special way. Besides \luatex, format-specific % configuration files are taken into account. |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{Not loaded}}% \let\foreignlanguage\selectlanguage \let\otherlanguage\selectlanguage \expandafter\let\csname otherlanguage*\endcsname\selectlanguage \def\bbl@usehooks##1##2{}% TODO. Temporary!! \def\setlocale{% \errhelp{Find an armchair, sit down and wait}% \errmessage{(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-\bbl@format.cfg \ifeof1 \else \input babel-\bbl@format.cfg\relax \fi \closein1 \endgroup \bbl@hook@loadkernel{switch.def} % \end{macrocode} % % \begin{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 % % \end{macrocode} % % Here the code for ini\TeX\ ends. % \end{macro} % % \section{Font handling with fontspec} % % Add the bidi handler just before luaoftload, 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 [misplaced]. % % \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 } %<> % \end{macrocode} % % 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|. % % At the time of this writing, \textsf{fontspec} shows a warning about % there are languages not available, which some people think refers to % \babel{}, even if there is nothing wrong. Here is hack to patch % \textsf{fontspec} to avoid the misleading (and mostly unuseful) % message. % % \begin{macrocode} %<<*Font selection>> \bbl@trace{Font handling with fontspec} \ifx\ExplSyntaxOn\@undefined\else \def\bbl@fs@warn@nx#1#2{% \bbl@tempfs is the original macro \in@{,#1,}{,no-script,language-not-exist,}% \ifin@\else\bbl@tempfs@nx{#1}{#2}\fi} \def\bbl@fs@warn@nxx#1#2#3{% \in@{,#1,}{,no-script,language-not-exist,}% \ifin@\else\bbl@tempfs@nxx{#1}{#2}{#3}\fi} \def\bbl@loadfontspec{% \let\bbl@loadfontspec\relax \ifx\fontspec\@undefined \usepackage{fontspec}% \fi}% \fi \@onlypreamble\babelfont \newcommand\babelfont[2][]{% 1=langs/scripts 2=fam \bbl@foreach{#1}{% \expandafter\ifx\csname date##1\endcsname\relax \IfFileExists{babel-##1.tex}% {\babelprovide{##1}}% {}% \fi}% \edef\bbl@tempa{#1}% \def\bbl@tempb{#2}% Used by \bbl@bblfont \bbl@loadfontspec \EnableBabelHook{babel-fontspec}% Just calls \bbl@switchfont \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@font@set\% \<\bbl@tempb default>\<\bbl@tempb family>}}% {\bbl@foreach\bbl@tempa{% ie 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}% \\\DeclareRobustCommand\<#1family>{% \\\not@math@alphabet\<#1family>\relax % \\\prepare@family@series@update{#1}\<#1default>% TODO. Fails \\\fontfamily\<#1default>% \\\\UseHooks\\\@undefined\\\\UseHook{#1family}\% \\\selectfont}% \\\DeclareTextFontCommand{\}{\<#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{% eg 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@exp{% 2=T - from script \global\let\% \}}}% {}}% 1=T - language, already defined \def\bbl@tempa{\bbl@nostdfont{}}% TODO. Don't use \bbl@tempa \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. TODO: but sometimes wrong! \\\bbl@add\\\originalTeX{% \\\bbl@font@rst{\bbl@cl{##1dflt}}% \<##1default>\<##1family>{##1}}% \\\bbl@font@set\% 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{% eg \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}% eg, \rmdefault{\bbl@rmdflt@lang} \\\bbl@ifsamestring{#2}{\f@family}% {\\#3% \\\bbl@ifsamestring{\f@series}{\bfdefault}{\\\bfseries}{}% \let\\\bbl@tempa\relax}% {}}} % TODO - next should be global?, but even local does its job. I'm % still not sure -- must investigate: \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% eg, '\rmfamily', to be restored below \let#4\@empty % Make sure \renewfontfamily is valid \bbl@exp{% \let\\\bbl@temp@pfam\<\bbl@stripslash#4\space>% eg, '\rmfamily ' \{fontspec-opentype}{Script/\bbl@cl{sname}}% {\\\newfontscript{\bbl@cl{sname}}{\bbl@cl{sotf}}}% \{fontspec-opentype}{Language/\bbl@cl{lname}}% {\\\newfontlanguage{\bbl@cl{lname}}{\bbl@cl{lotf}}}% \let\\\bbl@tempfs@nx\<__fontspec_warning:nx>% \let\<__fontspec_warning:nx>\\\bbl@fs@warn@nx \let\\\bbl@tempfs@nxx\<__fontspec_warning:nxx>% \let\<__fontspec_warning:nxx>\\\bbl@fs@warn@nxx \\\renewfontfamily\\#4% [\bbl@cl{lsys},% xetex removes unknown features :-( \ifcase\bbl@engine\or RawFeature={family=\bbl@tempb},\fi #2]}{#3}% ie \bbl@exp{..}{#3} \bbl@exp{% \let\<__fontspec_warning:nx>\\\bbl@tempfs@nx \let\<__fontspec_warning:nxx>\\\bbl@tempfs@nxx}% \begingroup #4% \xdef#1{\f@family}% eg, \bbl@rmdflt@lang{FreeSerif(0)} \endgroup % TODO. Find better tests: \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} %<> % \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. % % \begin{macrocode} %<<*Footnote changes>> \bbl@trace{Bidi footnotes} \ifnum\bbl@bidimode>\z@ % Any bidi= \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}}}} \fi %<> % \end{macrocode} % % 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@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{% % TODO. Execute only once (but redundant): \\\bbl@add\{% \XeTeXlinebreaklocale "\bbl@cl{tbcp}"% \% \}% \\\bbl@toglobal\% \\\bbl@add\{% \XeTeXlinebreaklocale ""}% \\\bbl@toglobal\}% \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 \AddBabelHook{babel-fontspec}{afterextras}{\bbl@switchfont} \AddBabelHook{babel-fontspec}{beforestart}{\bbl@ckeckstdfonts} \DisableBabelHook{babel-fontspec} <@Font selection@> \def\bbl@provide@extra#1{} % \end{macrocode} % % \section{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 (eg, |\}|). As a % special case, hyphens are stored as |\bbl@upto|, to deal with ranges. % % \begin{macrocode} \newcommand\IfBabelIntercharT[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\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@