1 % \iffalse meta-comment
3 % Copyright 2012-2016 Javier Bezos and Johannes L. Braams.
4 % Copyright 1989-2012 Johannes L. Braams and any individual authors
5 % listed elsewhere in this file.
8 % This file is part of the Babel system.
9 % --------------------------------------
11 % It may be distributed and/or modified under the
12 % conditions of the LaTeX Project Public License, either version 1.3
13 % of this license or (at your option) any later version.
14 % The latest version of this license is in
15 % http://www.latex-project.org/lppl.txt
16 % and version 1.3 or later is part of all distributions of LaTeX
17 % version 2003/12/01 or later.
19 % This work has the LPPL maintenance status "maintained".
21 % The Current Maintainer of this work is Javier Bezos.
23 % The list of all files belonging to the Babel system is
24 % given in the file `manifest.bbl. See also `legal.bbl' for additional
27 % The list of derived (unpacked) files belonging to the distribution
28 % and covered by LPPL is defined by the unpacking scripts (with
29 % extension |.ins|) which are part of the distribution.
33 % \def\filename{babel.dtx}
34 % \let\thisfilename\filename
39 %%\ProvidesFile{babel.dtx}[2016/02/01 v3.9o The Babel package]
42 % Babel DOCUMENT-STYLE option for LaTeX version 2.09 or plain TeX;
43 %% Babel package for LaTeX2e.
45 %% Copyright (C) 1989-2008 by Johannes Braams,
47 %% all rights reserved.
48 %% Copyright (C) 2013-2014 by Johannes Braams
51 %% all rights reserved.
54 \documentclass{ltxdoc}
57 \addtolength{\textwidth}{25pt}
58 \addtolength{\textheight}{3.5cm}
59 \addtolength{\topmargin}{-2cm}
60 \font\manual=logo10 % font used for the METAFONT logo, etc.
61 \newcommand*\MF{{\manual META}\-{\manual FONT}}
62 \newcommand*\babel{\textsf{babel}}
63 \newcommand*\Babel{\textsf{Babel}}
64 \newcommand*\xetex{\textsf{xetex}}
65 \newcommand*\luatex{\textsf{luatex}}
67 \newcommand*\m[1]{\mbox{$\langle$\normalfont\itshape#1\/$\rangle$}}
68 \newcommand*\langlist{%
69 \meta{language}\texttt{,}\meta{language}\texttt{,}...}
70 \newcommand*\langvar{\m{lang}}
71 \newcommand*\note[1]{}
72 \newcommand*\bsl{\protect\bslash}
73 \newcommand*\Lopt[1]{\textsf{#1}}
74 \newcommand*\Lenv[1]{\textsf{#1}}
75 \newcommand*\menv[1]{\char`\{#1\char`\}}
76 \newcommand*\Eenv[1]{%
78 \texttt{\color{thered}\string\end\menv{#1}}}
79 \newcommand*\file[1]{\texttt{#1}}
80 \newcommand*\cls[1]{\texttt{#1}}
81 \newcommand*\pkg[1]{\texttt{#1}}
82 \addtolength{\oddsidemargin}{1em}
83 % Stolen and adapted from microtype:
84 \usepackage{color,colortbl}
86 \colorbox[rgb]{.92, .86, .73}{New #1}\enspace\ignorespaces}
87 \definecolor{thered} {rgb}{0.65,0.04,0.07}
88 \definecolor{thegreen}{rgb}{0.06,0.44,0.08}
89 \definecolor{thegrey} {gray}{0.8}
90 \definecolor{theshade}{rgb}{1,1,0.97}
91 \definecolor{theframe}{gray}{0.6}
92 \definecolor{lightgray}{gray}{0.95}
93 \IfFileExists{listings.sty}{
99 basicstyle=\MacroFont,
100 keywords=[0]{\selectlanguage,\foreignlanguage,\defineshorthand,
101 \babelhyphen,\babelhyphenation,\spanishhyphenmins,\addto,
102 \StartBabelCommands,\SetString,\EndBabelCommands,\shorthandoff,
103 \languageshorthands,\useshorthands,\AddBabelHook,\SetStringLoop,
104 \SetCase,\AfterBabelLanguage,\SetHyphenMap,\BabelLowerMM,
105 \babelensure,\babeltags},
106 keywordstyle=[0]\color{thered},
107 keywords=[1]{ngerman,italian,dutch,english,main,esperanto,
108 frenchb,shorthands,extrasfrench,extrasrussian,extrasenglish,
109 stringprocess,afterextras,latin,medieval,spanish,notilde,
111 keywordstyle=[1]\color{thegreen},
113 commentstyle=\color{thegrey}\itshape,
114 alsoother={0123456789_},
116 backgroundcolor=\color{theshade},
117 rulecolor=\color{theframe},
121 \lstnewenvironment{verbatim}[1][]{\lstset{##1}}{}
123 \def\PrintDescribeMacro#1{%
124 \strut\MacroFont\color{thered}\normalsize\string#1}
126 \par\penalty-500\vskip3ex\noindent
127 \DescribeMacro{#1}\args}
128 \def\DescribeOther{\vskip-4ex\Describe}
132 \ifx\bbl@tempa\@empty\else#1\vskip1ex\fi\ignorespaces}
133 \begingroup % Changes to ltxdoc
136 \gdef\check@plus@etc{%
137 \let\bbl@next\pm@module
139 \let\bbl@next\star@module
141 \let\bbl@next\slash@module
143 \let\bbl@next\var@module
146 \gdef\var@module#1#2#3>>{%
147 $\langle$\pm@module#2#3>$\rangle$%
148 \ifx*#2\ $\equiv$\fi}
150 \renewcommand*\l@section[2]{%
151 \ifnum \c@tocdepth >\z@
152 \addpenalty\@secpenalty
153 \addvspace{1.0em \@plus\p@}%
154 \setlength\@tempdima{2em}%
156 \parindent \z@ \rightskip \@pnumwidth
157 \parfillskip -\@pnumwidth
158 \leavevmode \bfseries
159 \advance\leftskip\@tempdima
161 #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
164 \renewcommand*\l@subsection{\@dottedtocline{2}{2em}{3em}}
165 \renewcommand*\l@subsubsection{\@dottedtocline{3}{5em}{4em}}
166 \renewcommand*\l@paragraph{\@dottedtocline{4}{9em}{4.5em}}
167 \renewcommand\partname{Part}
170 \title{Babel, a multilingual package for use with \LaTeX's standard
171 document classes\thanks{During the development ideas from Nico
172 Poppelier, Piet van Oostrum and many others have been used.
173 Bernd Raichle has provided many helpful suggestions.}}
174 \author{Johannes Braams\\
178 \normalsize For version 3.9, Javier Bezos\\
179 \normalsize \texttt{www.tex-tipografia.com}}
181 \date{Typeset \today}
183 \begin{minipage}[t][0pt]{30cm}
184 \vspace{-3cm}\hspace{-7cm}
186 \begin{tabular}{p{8cm}p{15cm}}
187 \cellcolor[rgb]{.86,.73,.67}
188 &\cellcolor[rgb]{.95,.95,.95}
190 \color[rgb]{.55,.4,.35}
192 \sffamily\fontsize{72}{72}\selectfont Babel
195 \cellcolor[rgb]{.95,.95,.95}
196 \vspace{2cm}\hspace{1.5cm}
197 \begin{minipage}{5cm}
203 \textit{Original author}\newline
207 \textit{Current maintainer}\newline
210 &\cellcolor[rgb]{.92, .86, .73}
213 \begin{minipage}{10cm}
214 \large\setlength\parskip{3mm}\raggedright
215 The standard distribution of \LaTeX\ contains a number of document
216 classes that are meant to be used, but also serve as examples for
217 other users to create their own document classes. These document
218 classes have become very popular among \LaTeX\ users. But it should
219 be kept in mind that they were designed for American tastes and
220 typography. At one time they even contained a number of hard-wired
223 This manual describes \babel{}, a package that makes use of the
224 capabilities of \TeX\ version 3 and, to some extent, \xetex{} and
225 \luatex, to provide an environment in which documents can be typeset
226 in a language other than US English, or in more than one language or
229 However, no attempt has been done to take full advantage of the
230 features provided by the latter, which would require a completely
231 new core (as for example \file{polyglossia} or as part of \LaTeX3).
243 \section{The user interface}\label{U-I}
245 The basic user interface of this package is quite simple. It consists
246 of a set of commands that switch from one language to another, and a
247 set of commands that deal with shorthands. It is also possible to find
248 out what the current language is.
250 In most cases, a single language is required, and then all you need in
251 \LaTeX{} is to load the package using its standand mechanism for this
252 purpose, namely, passing that language as an optional argument.
254 In multilingual documents, just use several option. So, in \LaTeX2e\
255 the preamble of the document:
257 \documentclass{article}
258 \usepackage[dutch,english]{babel}
260 would tell \LaTeX\ that the document would be written in two
261 languages, Dutch and English, and that English would be the first
262 language in use, and the main one. You can also set the main language
265 \documentclass{article}
266 \usepackage[main=english,dutch]{babel}
268 Another approach is making \Lopt{dutch} and \Lopt{english} global
269 options in order to let other packages detect and use them:
272 \documentclass[dutch,english]{article}
274 \usepackage{varioref}
277 In this last example, the package \texttt{varioref} will also see
278 the options and will be able to use them.
280 Languages may be set as global and as package option at the same
281 time, but in such a case you should set explicitly the main language
282 with the package option |main|:
284 \documentclass[italian]{book}
285 \usepackage[ngerman,main=italian]{babel}
288 \New{3.9c} The basic behaviour of some languages can be modified when
289 loading \babel{} by means of \textit{modifiers}. They are set after
290 the language name, and are prefixed with a dot (only when the language
291 is set as package option -- neither global options nor the |main| key
292 accept them). An example is (spaces are not significant and they can
293 be added or removed):\footnote{No predefined ``axis'' for modifiers
294 are provided because languages and their scripts have quite different
297 \usepackage[latin.medieval, spanish.notilde.lcroman, danish]{babel}
300 Attributes (described below) are considered modifiers, ie, you can
301 set an attribute by including it in the list of modifiers. However,
302 modifiers is a more general mechanism.
304 Because of the way \babel{} has evolved, ``language'' can refer to (1)
305 a set of hyphenation patterns as preloaded into the format, (2) a
306 package option, (3) an |ldf| file, and (4) a name used in the document
307 to select a language or dialect. So, a package option refers to a
308 language in a generic way -- sometimes it is the actual language name
309 used to select it, sometimes it is a file name loading a language with
310 a different name, sometimes it is a file name loading several
311 languages. Please, read the documentation for specific languages for
314 Loading directly |sty| files in \LaTeX{} (ie,
315 |\usepackage|\marg{language}) is deprecated and you will get the
316 error:\footnote{In former versions the error read ``You have used an
317 old interface to call babel'', not very helpful.}
319 ! Package babel Error: You are loading directly a language style.
320 (babel) This syntax is deprecated and you must use
321 (babel) \usepackage[language]{babel}.
324 Another typical error when using \babel{} is the
325 following:\footnote{In former versions the error read ``You haven't
326 loaded the language LANG yet''.}
328 ! Package babel Error: Unknown language `LANG'. Either you have misspelled
329 (babel) its name, it has not been installed, or you requested
330 (babel) it in a previous run. Fix its name, install it or just
331 (babel) rerun the file, respectively
333 The most frequent reason is, by far, the latest (for example, you
334 included |spanish|, but you realized this language is not used after
335 all, and therefore you removed it from the option list). In most cases,
336 the error vanishes when the document is typeset again, but in more
337 severe ones you will need to remove the |aux| file.
339 In Plain, load languages styles with |\input| and then use
340 |\begindocument| (the latter is defined by \babel):
341 \begin{verbatim}[morekeywords={[0]{\input,\begindocument}}]
345 Note not all languages provide a |sty| file and some of them are
346 not compatible with Plain.\footnote{Even in the \babel{} kernel there
347 were some macros not compatible with plain. Hopefully these issues will
350 \subsection{Selecting languages}
352 This section describes the commands to be used in the document to
353 switch the language in multilingual document.
355 The main language is selected automatically when the |document|
356 environment begins. In the preamble it has \textit{not} been selected,
357 except hyphenation patterns and the name assigned to |\languagename|
358 (in particular, shorthands, captions and date are not activated). If
359 you need to define boxes and the like in the preamble, you might want
360 to use some of the following commands.
362 \Describe\selectlanguage{\marg{language}}
363 When a user wants to switch from one language to another he can
364 do so using the macro |\selectlanguage|. This macro takes the
365 language, defined previously by a language definition file, as
366 its argument. It calls several macros that should be defined in
367 the language definition files to activate the special definitions
368 for the language chosen. For ``historical reasons'', a macro name is
369 converted to a language name without the leading |\|; in other words,
370 the two following declarations are equivalent:
372 \selectlanguage{german}
373 \selectlanguage{\german}
375 Using a macro instead of a ``real'' name is deprecated.
377 If used inside braces there might be some non-local changes, as this
378 would be roughly equivalent to:
380 {\selectlanguage{<inner-language>} ...}\selectlanguage{<outer-language>}
382 If you want a change which is really local, you must enclose this
383 code with an additional grouping level.
385 This command can be used as environment, too.
387 \Describe{\begin\menv{otherlanguage}}{\marg{language}\Eenv{otherlanguage}}
389 The environment \Lenv{otherlanguage} does basically the same as
390 |\selectlanguage|, except the language change is (mostly) local to
393 Actually, there might be some non-local changes, as this environment
394 is roughly equivalent to:
397 \selectlanguage{<inner-language>}
400 \selectlanguage{<outer-language>}
402 If you want a change which is really local, you must enclose this
403 environment with an additional grouping, like braces |{}|.
405 Spaces after the environment are ignored.
407 \Describe\foreignlanguage{\marg{language}\marg{text}}
408 The command |\foreignlanguage| takes two arguments; the second
409 argument is a phrase to be typeset according to the rules of the
410 language named in its first argument. This command (1) only
411 switches the extra definitions and the hyphenation rules for the
412 language, \emph{not} the names and dates, (2) does not send
413 information about the language to auxiliary files (i.e., the
414 surrounding language is still in force), and (3) it works even if
415 the language has not been set as package option (but in such a
416 case it only sets the hyphenation patterns and a warning is shown).
418 \Describe{\begin\menv{otherlanguage*}}%
419 {\marg{language}\Eenv{otherlanguage*}}
421 Same as |\foreignlanguage| but as environment. Spaces after the
422 environment are \textit{not} ignored.
424 This environment (or in some cases |otherlanguage|) may be required for
425 intermixing left-to-right typesetting with right-to-left typesetting
426 in engines not supporting a change in the writing direction inside a
429 \Describe{\begin\menv{hyphenrules}}{\marg{language}\Eenv{hyphenrules}}
431 The environment \Lenv{hyphenrules} can be used to select \emph{only}
432 the hyphenation rules to be used (it can be used as command,
433 too). This can for instance be used to select `nohyphenation',
434 provided that in \file{language.dat} the `language'
435 \textsf{nohyphenation} is defined by loading \file{zerohyph.tex}. It
436 deactivates language shorthands, too (but not user shorthands).
438 Except for these simple uses, |hyphenrules| is discouraged and
439 |otherlanguage*| (the starred version) is preferred, as the former
440 does not take into account possible changes in encodings or characters
441 like, say, |'| done by some languages (eg, \textsf{italian},
442 \textsf{frenchb}, \textsf{ukraineb}). To set hyphenation exceptions,
443 use |\babelhyphenation| (see below).
445 \subsection{More on selection}
447 \Describe\babeltags{\char`\{\m{tag1} \texttt{=} \m{language1}, \m{tag2}
448 \texttt{=} \m{language2}, \dots\char`\}}
450 \New{3.9i} In multilingual documents with many language switches the commands
451 above can be cumbersome. With this tool shorter names can be
452 defined. It adds nothing really new -- it is just syntactical sugar.
454 It defines |\text|\m{tag1}\marg{text} to be
455 |\foreignlanguage|\marg{language1}\marg{text}, and |\begin|\marg{tag1}
456 to be |\begin{otherlanguage*}|\marg{language1}, and so on. Note
457 |\|\m{tag1} is also allowed, but remember set it locally inside a
460 \babeltags{de = german}
464 text \textde{German text} text
475 \Describe\babelensure{|[include=|\m{commands}|,exclude=|\m{commands}%
476 |,fontenc=|\m{encoding}|]|\marg{language}}
478 \New{3.9i} Except in a few languages, like Russian, captions and
479 dates are just strings, and do not switch the language. That means
480 you should set it explicitly if you want to use them, or hyphenation
481 (and in some cases the text itself) will be wrong. For example:
483 \foreignlanguage{russian}{text \foreignlanguage{polish}{\seename} text}
486 Of course, \TeX{} can do it for you. To avoid switching the language
487 all the while, |\babelensure| redefines the captions for a given
488 language to wrap them with a selector. By default only the basic
489 captions and |\today| are redefined, but you can add further macros
490 with the key |include| in the optional argument (without
491 commas). Macros not to be modified are listed in |exclude|. You can
492 also enforce a font encoding with |fontenc|.\footnote{With it encoded
493 string may not work as expected.} A couple of examples:
495 \babelensure[include=\Today]{spanish}
496 \babelensure[fontenc=T5]{vietnamese}
499 They are activated when the language is selected (at the |afterextras|
500 event), and it makes some assumptions which could not be fulfilled in
501 some languages. Note also you should include only macros defined by
502 the language, not global macros (eg, |\TeX| of |\dag|).
504 \subsection{Getting the current language name}
506 \Describe\languagename{}
507 The control sequence |\languagename| contains the name of the
508 current language. However, due to some internal inconsistencies in
509 catcodes it should \textit{not} be used to test its value (use
510 \textsf{iflang}, by Heiko Oberdiek).
512 \Describe\iflanguage{\marg{language}\marg{true}\marg{false}}
514 If more than one language is used, it might be necessary to know which
515 language is active at a specific time. This can be checked by a call
516 to |\iflanguage|, but note here ``language'' is used in the \TeX\
517 sense, as a set of hyphenation patterns, and \textit{not} as its
518 \textsf{babel} name. This macro takes three arguments. The first
519 argument is the name of a language; the second and third arguments are
520 the actions to take if the result of the test is true or false
521 respectively. The advice about |\languagename| also applies here --
522 use \textsf{iflang} instead of |\iflanguage| if possible.
524 \subsection{Selecting scripts}
526 Currently \babel{} provides no standard interface to select
527 scripts, because they are best selected with either |\fontencoding|
528 (low level) or a language name (high level). Even the Latin script may
529 require different encodings (ie, sets of glyphs) depending on the
530 language, and therefore such a switch would be in a sense
531 incomplete.\footnote{The so-called Unicode fonts does not improve the
532 situation either. So, a font suited for Vietnamese is not necessarily
533 suited for, say, romanization of Indic languages, and the fact it
534 contains glyphs for Modern Greek does not mean it includes them for
535 Classic Greek. As to directionality, it poses special challenges
536 because it also affects individual characters and layout elements.}
538 Some languages sharing the same script define macros to switch it (eg,
539 |\textcyrillic|), but be aware they may also set the language to a
540 certain default. Even the \babel{} core defined |\textlatin|, but is
541 was somewhat buggy because in some cases it messed up encodings and
542 fonts (for example, if the main latin encoding was |LY1|), and
543 therefore it has been deprecated.\footnote{But still defined for
544 backwards compatibility.}
546 \Describe{\ensureascii}{\marg{text}}
548 \New{3.9i} This macro makes sure \m{text} is typeset with a
549 LICR-savvy encoding in the ASCII range. It is used to redefine |\TeX|
550 and |\LaTeX| so that they are correctly typeset even with |LGR| or
551 |X2| (the complete list is stored in |\BabelNonASCII|, which by default
552 is |LGR|, |X2|, |OT2|, |OT3|, |OT6|, |LHE|, |LWN|, |LMA|, |LMC|,
553 |LMS|, |LMU|, but you can modify it). So, in some sense it fixes the
554 bug described in the previous paragraph.
556 If non-ASCII encodings are not loaded (or no encoding at all), it is
557 no-op (also |\TeX| and |\LaTeX| are not redefined); otherwise,
558 |\ensureascii| switches to the encoding at the beginning of the
559 document if ASCII-savvy, or else the last ASCII-savvy encoding
560 loaded. For example, if you load |LY1,LGR|, then it is set to |LY1|,
561 but if you load |LY1,T2A| it is set to |T2A|. The symbol encodings
562 |TS1|, |T3|, and |TS3| are not taken into account, since they are not
563 used for ``ordinary'' text.
565 The foregoing rules (which are applied ``at begin document'') cover
566 most of cases. Note no asumption is made on characters above
567 127, which may not follow the LICR conventions -- the goal is just
568 to ensure most of the ASCII letters and symbols are the right ones.
570 \subsection{Shorthands}
572 A \textit{shorthand} is a sequence of one or two characters that
573 expands to arbitrary \TeX{} code.
575 Shorthands can be used for different kinds of things, as for example:
576 (1) in some languages shorthands such as |"a| are defined to be able
577 to hyphenate the word if the encoding is |OT1|; (2) in some languages
578 shorthands such as |!| are used to insert the right amount of white
579 space; (3) several kinds of discretionaries and breaks can be inserted
580 easily with |"-|, |"=|, etc.
582 The package \textsf{inputenc} as well as \xetex{} an \luatex{} have
583 alleviated entering non-ASCII characters, but minority languages and
584 some kinds of text can still require characters not directly
585 available in the keyboards (and sometimes not even as separated or
586 precomposed Unicode characters). As to the point 2, now
587 \textsf{pdfTeX} provides |\knbccode|. Tools of point 3 can be still
588 very useful in general.
590 There are three levels of shorthands: \textit{user},
591 \textit{language}, and \textit{system} (by order of
592 precedence). Version 3.9 introduces the \textit{language user} level
593 on top of the user level, as described below. In most cases, you will
594 use only shorthands provided by languages.
596 Please, note the following:
598 \item Activated chars used for two-char shorthands cannot be followed
599 by a closing brace |}| and the spaces following are gobbled. With
600 one-char shorthands (eg,~|:|), they are preserved.
601 \item If on a certain level (system, language, user) there is a
602 one-char shorthand, two-char ones starting with that
603 char and on the same level are ignored.
606 A typical error when using shorthands is the following:
608 ! Argument of \language@active@arg" has an extra }.
610 It means there is a closing brace just after a shorthand, which is not
611 allowed (eg,~|"}|). Just add |{}| after (eg,~|"{}}|).
613 \Describe{\shorthandon}{\marg{shorthands-list}}
614 \DescribeOther{\shorthandoff}{%
615 \colorbox{thegrey}{\ttfamily\hskip-.2em*\hskip-.2em}%
616 \marg{shorthands-list}}
617 It is sometimes necessary to switch a shorthand
618 character off temporarily, because it must be used in an
619 entirely different way. For this purpose, the user commands
620 |\shorthandoff| and |\shorthandon| are provided. They each take a
621 list of characters as their arguments.
623 The command |\shorthandoff| sets the |\catcode| for each of the
624 characters in its argument to other (12); the command |\shorthandon|
625 sets the |\catcode| to active (13). Both commands only work on `known'
626 shorthand characters. If a character is not known to be a shorthand
627 character its category code will be left unchanged.
629 \New{3.9a} Note however, |\shorthandoff| does not behave as
630 you would expect with characters like |~| or |^|, because they
631 usually are not ``other''. For them |\shorthandoff*| is provided,
636 |~| is still active, very likely with the meaning of a non-breaking
637 space, and |^| is the superscript character. The catcodes used are
638 those when the shorthands are defined, usually when language files are
641 \Describe{\useshorthands}{%
642 \colorbox{thegrey}{\ttfamily\hskip-.2em*\hskip-.2em}%
645 The command |\useshorthands| initiates the definition of user-defined
646 shorthand sequences. It has one argument, the character that starts
647 these personal shorthands.
649 \New{3.9a} However, user shorthands are not always alive, as they may
650 be deactivated by languages (for example, if you use |"| for your user
651 shorthands and switch from \textsf{german} to \textsf{french}, they
652 stop working). Therefore, a starred version
653 |\useshorthands*|\marg{char} is provided, which makes sure shorthands
654 are always activated.
656 Currently, if the package option |shorthands| is used, you must include any
657 character to be activated with |\useshorthands|. This restriction will
658 be lifted in a future release.
660 \Describe\defineshorthand{\texttt{[}\langlist\texttt{]}%^^A
661 \marg{shorthand}\marg{code}}
663 The command |\defineshorthand| takes two arguments: the first is
664 a one- or two-character shorthand sequence, and the second is the
665 code the shorthand should expand to.
667 \New{3.9a} An optional argument allows to (re)define language
668 and system shorthands (some languages do not activate shorthands,
669 so you may want to add |\languageshorthands|\marg{lang} to the
670 corresponding |\extras|\m{lang}). By default, user shorthands are
673 User shorthands override language ones, which in turn override
674 system shorthands. Language-dependent user shorthands (new in
675 3.9) take precedence over ``normal'' user shorthands.
677 As an example of their applications, let's assume you want a
678 unified set of shorthand for discretionaries (languages do not
679 define shorthands consistently, and |"-|, |\-|, |"=| have
680 different meanings). You could start with, say:
683 \defineshorthand{"*}{\babelhyphen{soft}}
684 \defineshorthand{"-}{\babelhyphen{hard}}
686 However, behaviour of hyphens is language dependent. For example, in
687 languages like Polish and Portugese, a hard hyphen inside compound
688 words are repeated at the beginning of the next line. You could then
690 \begin{verbatim}[morekeywords={[1]{polish,portugese}}]
691 \defineshorthand[*polish,*portugese]{"-}{\babelhyphen{repeat}}
693 Here, options with |*| set a language-dependent user shorthand, which
694 means the generic one above only applies for the rest of languages;
695 without |*| they would (re)define the language shorthands instead,
696 which are overriden by user ones.
698 Now, you have a single unified shorthand (|"-|), with a content-based
699 meaning (`compound word hyphen') whose visual behavior is that
700 expected in each context.
702 \Describe\aliasshorthand{\marg{original}\marg{alias}}
704 The command |\aliasshorthand| can be used to let another
705 character perform the same functions as the default shorthand
706 character. If one prefers for example to use the character |/|
707 over |"| in typing Polish texts, this can be achieved by entering
708 |\aliasshorthand{"}{/}|. \emph{Please note} the substitute
709 character must \textit{not} have been declared before as
710 shorthand (in such case, |\aliashorthands| is ignored).
712 The following example shows how to replace a shorthand by another
713 \begin{verbatim}[morekeywords={[0]{\aliasshorthand}}]
714 \aliasshorthand{~}{^}
715 \AtBeginDocument{\shorthandoff*{~}}
717 However, shorthands remember somehow the original character, and the
718 fallback value is that of the latter. So, in this example, if no
719 shorthand if found, |^| expands to a non-breaking space, because this
720 is the value of |~| (internally, |^| calls |\active@char~| or
721 |\normal@char~|). Furthermore, if you change the |system| value of |^|
722 with |\defineshorthand| nothing happens.
724 \Describe\languageshorthands{\marg{language}} The command
725 |\languageshorthands| can be used to switch the shorthands on the
726 language level. It takes one argument, the name of a language or
727 |none| (the latter does what its name suggests).\footnote{Actually,
728 any name not corresponding to a language group does the same as
729 \texttt{none}. However, follow this convention because it might be
730 enforced in future releases of \babel{} to catch possible errors.}
731 Note that for this to work the language should have been specified as
732 an option when loading the \babel\ package. For example, you can use
733 in \textsf{english} the shorthands defined by \textsf{ngerman} with
735 \addto\extrasenglish{\languageshorthands{ngerman}}
737 (You may also need to activate them with, for example,
740 Very often, this is a more convenient way to deactivate shorthands
741 than |\shorthandoff|, as for example if you want to define a macro
742 to easy typing phonetic characters with \textsf{tipa}:
744 \newcommand{\myipa}[1]{{\languageshorthands{none}\tipaencoding#1}}
747 \Describe\babelshorthand{\marg{shorthand}}
748 With this command you can use a shorthand even if (1) not activated in
749 \texttt{shorthands} (in this case only shorthands for the current
750 language are taken into account, ie, not user shorthands), (2) turned
751 off with |\shorthandoff| or (3) deactivated with the internal
752 |\bbl@deactivate|; for example, \verb|\babelshorthand{"u}| or
753 \verb|\babelshorthand{:}|. (You can conveniently define your own
754 macros, or even you own user shorthands provided they do not ovelap.)
756 For your records, here is a list of shorthands, but you must check
757 them, as they may change:\footnote{Thanks to Enrico Gregorio}
761 \item[Languages with no shorthands] Croatian, English (any variety),
762 Indonesian, Hebrew, Interlingua, Irish, Lower Sorbian, Malaysian,
763 North Sami, Romanian, Scottish, Welsh
764 \item[Languages with only \texttt{"} as defined shorthand character]
765 Albanian, Bulgarian, Danish, Dutch, Finnish, German (old and new
766 orthography, also Austrian), Icelandic, Italian, Norwegian, Polish,
767 Portuguese (also Brazilian), Russian, Serbian (with Latin script),
768 Slovene, Swedish, Ukrainian, Upper Sorbian
769 \item[Basque] |" ' ~|
770 \item[Breton] |: ; ? !|
771 \item[Catalan] |" ' `|
774 \item[Estonian] |" ~|
775 \item[French] (all varieties) |: ; ? !|
776 \item[Galician] |" . ' ~ < >|
781 \item[Slovak] |" ^ ' -|
782 \item[Spanish] |" . < > '|
783 \item[Turkish] |: ! =|
785 In addition, the \babel{} core declares |~| as a one-char shorthand
786 which is let, like the standard |~|, to a non breaking
787 space.\footnote{This declaration serves to nothing, but it is
788 preserved for backward compatibility.}
791 \subsection{Package options}
794 These package options are processed before language options, so
795 that they are taken into account irrespective of its order. The first
796 three options have been available in previous versions.
798 \Describe{KeepShorthandsActive}{}
799 Tells babel not to deactivate shorthands after loading a language
800 file, so that they are also availabe in the preamble.
802 \Describe{activeacute}{} For some languages \babel\ supports this
803 options to set |'| as a shorthand in case it is not done by default.
805 \Describe{activegrave}{}
808 \Describe{shorthands=}{\meta{char}\meta{char}...
809 $\string|$ \texttt{off}}
810 The only language shorthands activated
811 are those given, like, eg:
813 \usepackage[esperanto,frenchb,shorthands=:;!?]{babel}
815 If \verb|'| is included, \texttt{activeacute} is set; if \verb|`| is
816 included, \texttt{activegrave} is set. Active characters (like
817 \verb|~|) should be preceded by \verb|\string| (otherwise they will be
818 expanded by \LaTeX{} before they are passed to the package and
819 therefore they will not be recognized); however, |t| is provided for
820 the common case of |~| (as well as |c| for not so common case of the
823 With |shorthands=off| no language shorthands are defined,
824 As some languages use this mechanism for tools not available
825 otherwise, a macro \verb|\babelshorthand| is defined, which allows
826 using them; see above.
828 \Describe{safe=}{\texttt{none} $\string|$ \texttt{ref} $\string|$
829 \texttt{bib}} Some \LaTeX{} macros are redefined so that using
830 shorthands is safe. With \texttt{safe=bib} only |\nocite|, |\bibcite|
831 and |\bibitem| are redefined. With |safe=ref| only |\newlabel|, |\ref|
832 and |\pageref| are redefined (as well as a few macros from
833 \textsf{varioref} and \textsf{ifthen}). With |safe=none| no macro is
834 redefined. This option is strongly recommended, because a good deal of
835 incompatibilities and errors are related to these redefinitions -- of
836 course, in such a case you cannot use shorthands in these macros, but
837 this is not a real problem (just use ``allowed'' characters).
839 \Describe{math=}{\texttt{active} $\string|$ \texttt{normal}}
840 Shorthands are mainly intended for text, not for math. By setting this
841 option with the value |normal| they are deactivated in math mode
842 (default is |active|) and things like |${a'}$| (a closing brace after
843 a shorthand) are not a source of trouble any more.
845 \Describe{config=}{\meta{file}} Load \meta{file}\texttt{.cfg} instead
846 of the default config file |bblopts.cfg| (the file is loaded even
849 \Describe{main=}{\meta{language}} Sets the main language, as explained
850 above, ie, this language is always loaded last. If it is not given as
851 package or global option, it is added to the list of requested
854 \Describe{headfoot=}{\meta{language}} By default, headlines and
855 footlines are not touched (only marks), and if they contain language
856 dependent macros (which is not usual) there may be unexpected
857 results. With this option you may set the language in heads and foots.
859 \Describe{noconfigs}{} Global and language default config files are
860 not loaded, so you can make sure your document is not spoilt by an
861 unexpected \texttt{.cfg} file. However, if the key |config| is set,
864 \Describe{showlanguages}{} Prints to the log the list of languages
865 loaded when the format was created: number (remember dialects can
866 share it), name, hyphenation file and exceptions file.
868 \Describe{nocase}{} \New{3.9l} Language settings for uppercase and
869 lowercase mapping (as set by |\SetCase|) are ignored. Use only if there
870 are incompatibilities with other packages.
872 \Describe{silent}{} \New{3.9l} No warnings and no \textit{infos} are
873 written to the log file.\footnote{You can use alternatively the
874 package \textsf{silence}.}
876 \Describe{strings=}{\texttt{generic} $\string|$ \texttt{unicode}
877 $\string|$ \texttt{encoded} $\string|$ \meta{label} $\string|$
878 \meta{font encoding}} Selects the encoding of strings in languages
879 supporting this feature. Predefined labels are |generic| (for
880 traditional \TeX, LICR and ASCII strings), |unicode| (for engines like
881 \xetex{} and \luatex) and |encoded| (for special cases requiring mixed
882 encodings). Other allowed values are font encoding codes (|T1|, |T2A|,
883 |LGR|, |L7X|...), but only in languages supporting them. Be aware with
884 |encoded| captions are protected, but they work in |\MakeUppercase|
887 \Describe{hyphenmap=}{\texttt{off} $\string|$ \texttt{main}
888 $\string|$ \texttt{select} $\string|$ \texttt{other} $\string|$
891 \New{3.9g} Sets the behaviour of case mapping for hyphenation,
892 provided the language defines it.\footnote{Turned off in plain.} It
893 can take the following values:
895 \renewcommand\makelabel[1]{%
896 \hspace\labelsep\normalfont\ttfamily\color{thered}#1}
898 \item[off] deactivates this feature and no case mapping is applied;
899 \item[first] sets it at the first switching commands in the
900 current or parent scope (typically, when the aux file is first read
901 and at |\begin{document}|, but also the first |\selectlanguage| in
902 the preamble), and it's the default if a single
903 language option has been stated;\footnote{Duplicated options count
905 \item[select] sets it only at |\selectlanguage|;
906 \item[other] also sets it at |otherlanguage|;
907 \item[other*] also sets it at |otherlanguage*| as well as in heads and
908 foots (if the option |headfoot| is used) and in auxiliary files (ie,
909 at |\select@language|), and it's the default if several language
910 options have been stated. The option |first| can be regarded as an
911 optimized version of \texttt{other*} for monolingual
912 documents.\footnote{Providing |foreign| is pointless, because the
913 case mapping applied is that at the end of paragraph, but if either
914 \xetex{} or \luatex{} change this behaviour it might be added. On
915 the other hand, |other| is provided even if I [JBL] think it isn't
916 really useful, but who knows.}
919 \subsection{The \texttt{base} option}
921 With this package option \babel{} just loads some basic macros (those
922 in |switch.def|), defines |\AfterBabelLanguage| and exits. It also
923 selects the hyphenations patterns for the last language passed as
924 option (by its name in |language.dat|). There are two main uses:
925 classes and packages, and as a last resort in case there are, for some
926 reason, incompatible languages. It can be used if you just want to
927 select the hyphenations patterns of a single language, too.
929 \Describe\AfterBabelLanguage{\marg{option-name}\marg{code}}
931 This command is currently the only provided by |base|. Executes
932 \meta{code} when the file loaded by the corresponding package option
933 is finished (at |\ldf@finish|). The setting is global. So
935 \AfterBabelLanguage{frenchb}{...}
937 does ... at the end of |frenchb.ldf|. It can be used in |ldf| files,
938 too, but in such a case the code is executed only if
939 \meta{option-name} is the same as |\CurrentOption| (which could not
940 be the same as the option name as set in |\usepackage|!).
942 For example, consider two languages \textsf{foo} and \textsf{bar}
943 defining the same |\macro| with |\newcommand|. An error is raised if
944 you attempt to load both. Here is a way to overcome this problem:
946 \usepackage[base]{babel}
947 \AfterBabelLanguage{foo}{%
950 \usepackage[foo,bar]{babel}
955 \New{3.9a} A hook is a piece of code to be executed at certain
956 events. Some hooks are predefined when \luatex{} and \xetex{} are
959 \Describe\AddBabelHook{\marg{name}\marg{event}\marg{code}}
961 The same name can be applied to several events. Hooks may be enabled
962 and disabled for all defined events with
963 |\EnableBabelHook|\marg{name}, |\DisableBabelHook|\marg{name}. Names
964 containing the string |babel| are reserved (they are used, for
965 example, by |\useshortands*| to add a hook for the event
968 Current events are the following; in some of them you can use one to
969 three \TeX{} parameters (|#1|, |#2|, |#3|), with the meaning given:
971 \renewcommand\makelabel[1]{%
972 \hspace\labelsep\normalfont\ttfamily\color{thered}#1}
974 \item[adddialect] (language name, dialect name) Used by
975 \file{luababel.def} to load the patterns if not preloaded.
976 \item[patterns] (language name, language with encoding) Executed just
977 after the |\language| has been set. The second argument has the
978 patterns name actually selected (in the form of either |lang:ENC| or
980 \item[hyphenation] (language name, language with encoding) Executed
981 locally just before exceptions given in |\babelhyphenation| are
983 \item[defaultcommands] Used (locally) in |\StartBabelCommands|.
984 \item[encodedcommands] (input, font encodings) Used (locally) in
985 |\StartBabelCommands|. Both \xetex{} and \luatex{} make sure the
986 encoded text is read correctly.
987 \item[stopcommands] Used to reset the the above, if necessary.
988 \item[write] This event comes just after the switching commands are
989 written to the |aux| file.
990 \item[beforeextras] Just before executing |\extras|\m{language}. This
991 event and the next one should not contain language-dependent code
992 (for that, add it to |\extras|\m{language}).
993 \item[afterextras] Just after executing |\extras|\m{language}. For
994 example, the following deactivates shorthands in all languages:
996 \AddBabelHook{noshort}{afterextras}{\languageshorthands{none}}
998 \item[stringprocess] Instead of a parameter, you can manipulate the
999 macro |\BabelString| containing the string to be defined with
1000 |\SetString|. For example, to use an expanded version of the string
1001 in the definition, write:
1003 \AddBabelHook{myhook}{stringprocess}{%
1004 \protected@edef\BabelString{\BabelString}}
1006 \item[initiateactive] (char as active, char as other, original char)
1007 \New{3.9i} Executed just after a shorthand has been `initiated'. The three
1008 parameters are the same character with different catcodes: active,
1009 other (|\string|'ed) and the original one.
1010 \item[afterreset] \New{3.9i} Executed when selecting a language just after
1011 |\originalTeX| is run and reset to its base value, before executing
1012 |\captions|\m{language} and |\date|\m{language}.
1015 Four events are used in \file{hyphen.cfg}, which are handled in a
1016 quite different way for efficiency reasons -- unlike the precedent
1017 ones, they only have a single hook and replace a default definition.
1019 \renewcommand\makelabel[1]{%
1020 \hspace\labelsep\normalfont\ttfamily\color{thered}#1}
1022 \item[everylanguage] (language) Executed before every language patterns are loaded.
1023 \item[loadkernel] (file) By default loads |switch.def|. It can be used
1024 to load a different version of this files or to load nothing.
1025 \item[loadpatterns] (patterns file) Loads the patterns file. Used by
1026 \file{luababel.def}.
1027 \item[loadexceptions] (exceptions file) Loads the exceptions
1028 file. Used by \file{luababel.def}.
1031 \Describe\BabelContentsFiles{}
1032 \New{3.9a} This macro contains a list of ``toc'' types which
1033 require a command to switch the language. Its default value is
1034 |toc,lof,lot|, but you may redefine it with |\renewcommand| (it's up
1035 to you to make sure no toc type is duplicated).
1037 \subsection{Hyphenation tools}
1039 \Describe\babelhyphen{%
1040 \colorbox{thegrey}{\ttfamily\hskip-.2em*\hskip-.2em}\marg{type}}
1041 \DescribeOther\babelhyphen{%
1042 \colorbox{thegrey}{\ttfamily\hskip-.2em*\hskip-.2em}\marg{text}}
1044 \New{3.9a} It is customary to classify hyphens in two types: (1)
1045 \textit{explicit} or \textit{hard hyphens}, which in \TeX\ are
1046 entered as \verb|-|, and (2) \textit{optional} or \textit{soft
1047 hyphens}, which are entered as \verb|\-|. Strictly, a \textit{soft
1048 hyphen} is not a hyphen, but just a breaking oportunity or, in
1049 \TeX\ terms, a ``discretionary''; a \textit{hard hyphen} is a hyphen
1050 with a breaking oportunity after it. A further type is a
1051 \textit{non-breaking hyphen}, a hyphen without a breaking
1054 In \TeX, \verb|-| and \verb|\-| forbid further breaking oportunities
1055 in the word. This is the desired behaviour very often, but not
1056 always, and therefore many languages provide shorthands for these
1057 cases. Unfortunately, this has not been done consistently: for
1058 example, in Dutch, Portugese, Catalan or Danish, \verb|"-| is a hard
1059 hyphen, while in German, Spanish, Norwegian, Slovak or Russian, it
1060 is a soft hyphen. Furthermore, some of them even redefine |\-|, so
1061 that you cannot insert a soft hyphen without breaking oportunities
1062 in the rest of the word.
1064 Therefore, some macros are provide with a set of basic ``hyphens''
1065 which can be used by themselves, to define a user shorthand, or even
1068 \item |\babelhyphen{soft}| and |\babelhyphen{hard}| are self
1070 \item |\babelhyphen{repeat}| inserts a hard hyphen which is repeated
1071 at the beginning of the next line, as done in languages like
1072 Polish, Portugese and Spanish.
1073 \item |\babelhyphen{nobreak}| inserts a hard hyphen without a break
1074 after it (even if a space follows).
1075 \item |\babelhyphen{empty}| inserts a break oportunity without
1077 \item |\babelhyphen|\marg{text} is a hard ``hyphen'' using \m{text}
1078 instead. A typical case is |\babelhyphen{/}|.
1080 With all of them hyphenation in the rest of the word is enabled. If
1081 you don't want enabling it, there is a starred counterpart:
1082 |\babelhyphen*{soft}| (which in most cases is equivalent to the
1083 original |\-|), |\babelhyphen*{hard}|, etc.
1085 Note |hard| is also good for isolated prefixes (eg, \textit{anti-})
1086 and |nobreak| for isolated suffixes (eg, \textit{-ism}), but in both
1087 cases |\babelhyphen*{nobreak}| is usually better.
1089 There are also some differences with \LaTeX: (1) the character used is
1090 that set for the current font, while in \LaTeX{} it is hardwired to
1091 |-| (a typical value); (2) the hyphen to be used in fonts with a
1092 negative |\hyphenchar| is |-|, like in \LaTeX, but it can be changed to
1093 another value by redefining |\babelnullhyphen|; (3) a break after the
1094 hyphen is forbidden if preceded by a glue ${>}0$~pt (at the beginning
1095 of a word, provided it is not immediately preceded by, say, a
1098 \Describe\babelhyphenation{\texttt{[}\langlist\texttt{]}%^^A
1101 \New{3.9a} Sets hyphenation exceptions for the languages given
1102 or, without the optional argument, for \textit{all} languages (eg,
1103 proper nouns or common loan words, and of course monolingual
1104 documents). Language exceptions take precedence over global ones.
1106 It can be used only in the preamble, and exceptions are set when the
1107 language is first selected, thus taking into account changes of
1108 |\lccodes|'s done in |\extras|\m{lang} as well as the language specific
1109 encoding (not set in the preamble by default). Multiple
1110 |\babelhyphenation|'s are allowed. For example:
1112 \babelhyphenation{Wal-hal-la Dar-bhan-ga}
1115 Listed words are saved expanded and therefore it relies on the
1116 LICR. Of course, it also works without the LICR if the input and the
1117 font encodings are the same, like in Unicode based engines.
1119 \Describe\babelpatterns{\texttt{[}\langlist\texttt{]}%^^A
1122 \New{3.9m} \textit{In \textsf{luatex} only},\footnote{With
1123 \textsf{luatex} exceptions and patterns can be modified almost
1124 freely. However, this is very likely a task for a separate package
1125 and \texttt{babel} only provides the most basic tools.} adds or
1126 replaces patterns for the languages given or, without the optional
1127 argument, for \textit{all} languages. If a pattern for a certain
1128 combination already exists, it gets replaced by the new one.
1130 It can be used only in the preamble, and patterns are added when the
1131 language is first selected, thus taking into account changes of
1132 |\lccodes|'s done in |\extras|\m{lang} as well as the language specific
1133 encoding (not set in the preamble by default). Multiple
1134 |\babelpatterns|'s are allowed.
1136 Listed patterns are saved expanded and therefore it relies on the
1137 LICR. Of course, it also works without the LICR if the input and the
1138 font encodings are the same, like in Unicode based engines.
1140 \subsection{Language attributes}
1142 \DescribeMacro{\languageattribute}
1143 This is a user-level command, to be used in the preamble of a
1144 document (after |\usepackage[...]{babel}|), that declares which
1145 attributes are to be used for a given language. It takes two
1146 arguments: the first is the name of the language; the second,
1147 a (list of) attribute(s) to be used. Attributes must be set in the
1148 preamble and only once -- they cannot be turned on and off.
1149 The command checks whether the language is known in this document
1150 and whether the attribute(s) are known for this language.
1152 Very often, using a \textit{modifier} in a package option is better.
1154 Several language definition files use their own methods to set
1155 options. For example, \textsf{frenchb} uses |\frenchbsetup|,
1156 \textsf{magyar} (1.5) uses |\magyarOptions|; modifiers provided by
1157 |spanish| have no attribute counterparts. Macros settting
1158 options are also used (eg, |\ProsodicMarksOn| in \textsf{latin}).
1160 \subsection{Languages supported by \babel}
1162 In the following table most of the languages supported by \babel\ are
1163 listed, together with the names of the options which you can load
1164 \babel\ with for each language. Note this list is open and the
1165 current options may be different.
1170 \item[Afrikaans] afrikaans
1171 \item[Bahasa] bahasa, indonesian, indon, bahasai,
1172 bahasam, malay, melayu
1173 \item[Basque] basque
1174 \item[Breton] breton
1175 \item[Bulgarian] bulgarian
1176 \item[Catalan] catalan
1177 \item[Croatian] croatian
1179 \item[Danish] danish
1181 \item[English] english, USenglish, american, UKenglish,
1182 british, canadian, australian, newzealand
1183 \item[Esperanto] esperanto
1184 \item[Estonian] estonian
1185 \item[Finnish] finnish
1186 \item[French] french, francais, canadien, acadian
1187 \item[Galician] galician
1188 \item[German] austrian, german, germanb, ngerman, naustrian
1189 \item[Greek] greek, polutonikogreek
1190 \item[Hebrew] hebrew
1191 \item[Icelandic] icelandic
1192 \item[Interlingua] interlingua
1193 \item[Irish Gaelic] irish
1194 \item[Italian] italian
1196 \item[Lower Sorbian] lowersorbian
1197 \item[North Sami] samin
1198 \item[Norwegian] norsk, nynorsk
1199 \item[Polish] polish
1200 \item[Portuguese] portuges, portuguese, brazilian, brazil
1201 \item[Romanian] romanian
1202 \item[Russian] russian
1203 \item[Scottish Gaelic] scottish
1204 \item[Spanish] spanish
1205 \item[Slovakian] slovak
1206 \item[Slovenian] slovene
1207 \item[Swedish] swedish
1208 \item[Serbian] serbian
1209 \item[Turkish] turkish
1210 \item[Ukrainian] ukrainian
1211 \item[Upper Sorbian] uppersorbian
1215 There are more languages not listed above, including \textsf{hindi,
1216 thai, thaicjk, latvian, turkmen, magyar, mongolian, romansh,
1217 lithuanian, spanglish, vietnamese, japanese, pinyin, arabic, farsi,
1218 ibygreek, bgreek, serbianc, frenchle, ethiop} and \textsf{friulan}.
1220 Most of them work out of the box, but some may require extra fonts,
1221 encoding files, a preprocessor or even a complete framework (like
1222 CJK). For example, if you have got the \textsf{velthuis/devnag} package,
1223 you can create a file with extension |.dn|:
1225 \documentclass{article}
1226 \usepackage[hindi]{babel}
1228 {\dn devaanaa.m priya.h}
1231 Then you preprocess it with |devnag| \m{file}, which creates
1232 \m{file}|.tex|; you can then typeset the latter with \LaTeX.
1234 \subsection{Tips, workarounds, know issues and notes}
1237 \item If you use the document class \cls{book} \emph{and} you use
1238 |\ref| inside the argument of |\chapter| (or just use |\ref| inside
1239 |\MakeUppercase|), \LaTeX\ will keep complaining about an undefined
1240 label. To prevent such problems, you could revert to using
1241 uppercase labels, you can use |\lowercase{\ref{foo}}| inside the
1242 argument of |\chapter|, or, if you will not use shorthands in
1243 labels, set the |safe| option to |none| or |bib|.
1245 \item\catcode`\|=12\relax Both \textsf{ltxdoc} and \textsf{babel} use
1246 \verb|\AtBeginDocument| to change some catcodes, and babel reloads
1247 \textsf{hhline} to make sure \verb|:| has the right one, so if you
1248 want to change the catcode of \verb/|/ it has to be done using the
1249 same method at the proper place, with
1251 \AtBeginDocument{\DeleteShortVerb{\|}}
1253 \textit{before} loading babel. This way, when the document begins
1254 the sequence is (1) make \verb/|/ active (\textsf{ltxdoc}); (2) make
1255 it unactive (your settings); (3) make babel shorthands active
1256 (\textsf{babel)}; (4) reload \textsf{hhline} (\textsf{babel}, now
1257 with the correct catcodes for \verb/|/ and
1258 \verb|:|).\catcode`\|=\active
1260 \item Documents with several input encodings are not frequent, but
1261 sometimes are useful. You can set different encodings for different
1262 languages as the following example shows:
1264 \addto\extrasfrench{\inputencoding{latin1}}
1265 \addto\extrasrussian{\inputencoding{koi8-r}}
1267 (A recent version of \textsf{inputenc} is required.)
1268 \item For the hyphenation to work correctly, lccodes cannot change,
1269 because \TeX{} only takes into account the values when the
1270 paragraph is hyphenated, i.e., when it has been
1271 finished.\footnote{This explains why \LaTeX{} assumes the lowercase
1272 mapping of T1 and does not provide a tool for multiple
1273 mappings. Unfortunately, \cs{savinghyphcodes} is not a solution
1274 either, because lccodes for hyphenation are frozen in the format
1275 and cannot be changed.} So, if you write a chunk of French text
1276 with |\foreinglanguage|, the apostrophes might not be taken into
1277 account. This is a limitation of \TeX, not of
1278 \babel. Alternatively, you may use |\useshorthands| to activate |'|
1279 and |\defineshorthand|, or redefine |\textquoteright| (the latter
1280 is called by the non-ASCII right quote).
1281 \item \verb|\bibitem| is out of sync with \verb|\selectlanguage| in
1282 the \file{.aux} file. The reason is \verb|\bibitem| uses
1283 \verb|\immediate| (and others, in fact), while
1284 \verb|\selectlanguage| doesn't. There is no known workaround.
1285 \item Babel does not take into account |\normalsfcodes| and
1286 (non-)French spacing is not always properly (un)set by
1287 languages. However, problems are unlikely to happen and therefore
1288 this part remains untouched in version 3.9 (but it is in the `to
1290 \item Using a character mathematically active (ie, with math code
1291 |"8000|) as a shorthand can make \TeX{} enter in an infinite loop in
1292 some rare cases. (Another issue in the `to do' list, although there
1293 is a partial solution.)
1294 \item Plain \luatex{} does not load patterns on the fly. Since this
1295 format is not based on \babel{} but on \file{etex.src} further
1296 investigation is required. This is another task in the `to do' list.
1299 The following packages can be useful, too (the list is still
1303 \item[csquotes] Logical markup for quotes.
1304 \item[iflang] Tests correctly the current language.
1305 \item[hyphsubst] Selects a different set of patterns for a language.
1306 \item[translator] An open platform for packages that need to be
1308 \item[siunitx] Typesetting of numbers and physical quantities.
1309 \item[biblatex] Programmable bibliographies and citations.
1310 \item[bicaption] Bilingual captions.
1311 \item[babelbib] Multilingual bibliographies.
1312 \item[microtype] Adjusts the typesetting according to
1313 some languages (kerning and spacing). Ligatures can be disabled.
1314 \item[substitutefont] Combines fonts in several encodings.
1315 \item[mkpattern] Generates hyphenation patterns.
1316 \item[tracklang] Tracks which languages have been requested.
1319 \subsection{Future work}
1321 Useful additions would be, for example, time, currency, addresses and
1322 personal names.\footnote{See for example POSIX, ISO 14652 and the
1323 Unicode Common Locale Data Repository (CLDR).}. But that is the easy
1324 part, because they don't require modifying the \LaTeX{} internals.
1326 More interesting are differences in the sentence structure or related to
1327 it. For example, in Basque the number precedes the name (including
1328 chapters), in Hungarian ``from (1)'' is ``(1)-b\H{o}l'', but ``from (3)''
1329 is ``(3)-b\'{o}l'', in Spanish an item labelled
1330 ``3.$^{\textrm{\scriptsize o}}$'' may
1331 be referred to as either ``\'{\i}tem 3.$^{\textrm{\scriptsize o}}$'' or ``3.$^{\textrm{\scriptsize er}}$ \'{\i}tem'', and so on.
1333 Even more interesting is right-to-left, vertical and bidi
1334 typesetting. Babel provided a basic support for bidi text as part of
1335 the style for Hebrew, but it is somewhat unsatisfactory and internally
1336 replaces some hardwired commands by other hardwired commands
1337 (generic changes would be much better).
1339 Handling of ``Unicode'' fonts is also problematic. There is
1340 \textsf{fontspec}, but special macros are required (not only the NFSS
1341 ones) and it doesn't provide ``orthogonal axis'' for features,
1342 including those related to the language (mainly language and
1343 script). A couple of tentative macros, which solve the two main cases,
1344 are provided by \babel{} ($\ge$3.9g) with a partial solution (only
1345 \xetex{} and \luatex, for obvious reasons), but use them at your own
1346 risk, as they might be removed in the future. For this very reason,
1347 they are described here:
1349 \item |\babelFSstore|\marg{babel-language} sets the current three
1350 basic families (rm, sf, tt) as the default for the language
1351 given. In most cases, this macro will be enough.
1352 \item |\babelFSdefault|\marg{babel-language}\marg{fontspec-features}
1353 patches |\fontspec| so that the given features are always passed as
1354 the optional argument or added to it (not an ideal solution). Use it
1355 only if you select some fonts in the document with |\fontspec|.
1359 \setmainfont[Language=Turkish]{Minion Pro}
1360 \setsansfont[Language=Turkish]{Myriad Pro}
1361 \babelFSstore{turkish}
1362 \setmainfont{Minion Pro}
1363 \setsansfont{Myriad Pro}
1364 \babelFSfeatures{turkish}{Language=Turkish}
1366 Note you can set any feature required for the language -- not only
1367 |Language|, but also |Script| or a local |.fea|. This makes those macros
1368 a bit more verbose, but also more powerful.
1370 \section{Loading languages with \file{language.dat}}
1372 \TeX{} and most engines based on it (pdf\TeX, \xetex, $\epsilon$-\TeX,
1373 the main exception being \luatex) require hyphenation patterns to be
1374 preloaded when a format is created (eg, \LaTeX, Xe\LaTeX,
1375 pdf\LaTeX). \babel{} provides a tool which has become standand in many
1376 distributions and based on a ``configuration file'' named
1377 \file{language.dat}. The exact way this file is used depends on the
1378 distribution, so please, read the documentation for the latter (note
1379 also some distributions generate the file with some tool).
1381 \New{3.9o} With \luatex, however, patterns are loaded on the fly when
1382 requested by the language (except the ``0th'' language,
1383 \textsf{english}, which is preloaded always). Until 3.9n, this task
1384 was delegated to the package \textsf{luatex-hyphen}, by Khaled Hosny,
1385 \'Elie Roux, and Manuel P\'egouri\'e-Gonnard, and required an extra
1386 file named |language.dat.lua|, but now a new mechanism has been
1387 devised based solely on |language.dat|. \textbf{You must rebuild the
1388 formats} if upgrading from a previous version. You may want to have a
1389 local |language.dat| for a particular project (for example, a book on
1394 In that file the person who maintains a \TeX\ environment has to record
1395 for which languages he has hyphenation patterns \emph{and} in which
1396 files these are stored\footnote{This is because different operating
1397 systems sometimes use \emph{very} different file-naming
1398 conventions.}. When hyphenation exceptions are stored in a separate
1399 file this can be indicated by naming that file \emph{after} the file
1400 with the hyphenation patterns.
1402 The file can contain empty lines and comments, as well as lines which
1403 start with an equals (\texttt{=}) sign. Such a line will instruct
1404 \LaTeX\ that the hyphenation patterns just processed have to be known
1405 under an alternative name. Here is an example:
1407 % File : language.dat
1408 % Purpose : tell iniTeX what files with patterns to load.
1409 english english.hyphenations
1412 dutch hyphen.dutch exceptions.dutch % Nederlands
1416 You may also set the font encoding the patterns are intended for by
1417 following the language name by a colon and the encoding
1418 code.\footnote{This in not a new feature, but in former versions it
1419 didn't work correctly.} For example:
1421 german:T1 hyphenT1.ger
1424 With the previous settings, if the enconding when the language is
1425 selected is |T1| then the patterns in \file{hyphenT1.ger} are
1426 used, but otherwise use those in \file{hyphen.ger} (note the encoding
1427 could be set in |\extras|\m{lang}).
1429 A typical error when using \babel{} is the following:
1431 No hyphenation patterns were preloaded for
1432 the language `<lang>' into the format.
1433 Please, configure your TeX system to add them and
1434 rebuild the format. Now I will use the patterns
1435 preloaded for english instead}}
1437 It simply means you must reconfigure \file{language.dat}, either by
1438 hand or with the tools provided by your distribution.
1440 \section{The interface between the core of \babel{} and the language
1443 The \textit{language definition files} (ldf) must conform to a
1444 number of conventions, because these files have to fill in the gaps
1445 left by the common code in \file{babel.def}, i.\,e., the
1446 definitions of the macros that produce texts. Also the
1447 language-switching possibility which has been built into the
1448 \babel{} system has its implications.
1450 The following assumptions are made:
1452 \item Some of the language-specific definitions might be used by plain
1453 \TeX\ users, so the files have to be coded so that they can be read
1454 by both \LaTeX\ and plain \TeX. The current format can be checked by
1455 looking at the value of the macro |\fmtname|.
1456 \item The common part of the \babel{} system redefines a number of
1457 macros and environments (defined previously in the document style)
1458 to put in the names of macros that replace the previously hard-wired
1459 texts. These macros have to be defined in the language definition
1461 \item The language definition files must define five macros, used to
1462 activate and deactivate the language-specific definitions. These
1463 macros are |\|\langvar|hyphenmins|, |\captions|\langvar,
1464 |\date|\langvar, |\extras|\langvar\ and |\noextras|\langvar (the
1465 last two may be left empty); where \langvar\ is either the name of
1466 the language definition file or the name of the \LaTeX\ option that
1467 is to be used. These macros and their functions are discussed
1468 below. You must define all or none for a language (or a dialect);
1469 defining, say, |\date|\langvar\ but not |\captions|\langvar\ does
1470 not raise an error but can lead to unexpected results.
1471 \item When a language definition file is loaded, it can define
1472 |\l@|\langvar\ to be a dialect of |\language0| when |\l@|\langvar\
1474 \item Language names must be all lowercase. If an unknow language is
1475 selected, \babel{} will attempt setting it after lowercasing its
1477 \item The semantics of modifiers is not defined (on purpose). In
1478 most cases, they will just be simple separated options (eg.,
1479 \texttt{spanish}), but a language might require, say, a set of
1480 options organized as a tree with suboptions (in such a case, the
1481 recommended separator is \verb|/|).
1484 Some recommendations:
1486 \item The preferred shorthand is |"|, which is not used in \LaTeX{}
1487 (quotes are entered as |``| and |''|). Other good choices are
1488 characters which are not used in a certain context (eg, |=| in an
1489 ancient language). Note however |=|, |<|, |>|, |:| and the like
1490 can be dangerous, because they may be used as part of the syntax
1491 of some elements (numeric expressions, key/value pairs, etc.).
1492 \item Captions should not contain shorthands or encoding dependent
1493 commands (the latter is not always possible, but should be clearly
1494 documented). They should be defined using the LICR. You may
1495 also use the new tools for encoded strings, described below.
1496 \item Avoid adding things to |\noextras|\m{lang} except for umlauthigh
1497 and friends, |\bbl@deactivate|, |\bbl@(non)frenchspacing|, and
1498 language specific macros. Use always, if possible, |\bbl@save| and
1499 |\bbl@savevariable| (except if you still want to have access to the
1500 previous value). Do not reset a macro or a setting to a hardcoded
1501 value. Never. Instead save its value in |\extras|\m{lang}.
1502 \item Do not switch scripts. If you want to make sure a set of glyphs
1503 is used, switch either the font encoding (low level) or the language
1504 (high level, which in turn may switch the font encoding). Usage of things
1505 like |\latintext| is deprecated.\footnote{But not removed, for backward
1509 There are no special requirements for documenting your language
1510 files. Now they are not included in the base \babel{} manual, so
1511 provide a standalone document suited for your needs (and the
1512 corresponding PDF, if you like), as well as other files you think can
1513 be useful (eg, samples, readme).
1515 \subsection{Basic macros}
1517 In the core of the \babel{} system, several macros are defined for use
1518 in language definition files. Their purpose is to make a new language
1519 known. The first two are related to hyphenation patterns.
1521 \DescribeMacro{\addlanguage}
1522 The macro |\addlanguage| is a non-outer version of the macro
1523 |\newlanguage|, defined in \file{plain.tex} version~3.x. For older
1524 versions of \file{plain.tex} and \file{lplain.tex} a substitute
1525 definition is used. Here ``language'' is used in the \TeX{} sense of
1526 set of hyphenation patterns.
1528 \DescribeMacro{\adddialect}
1529 The macro |\adddialect| can be used when two languages can (or
1530 must) use the same hyphenation patterns. This can also be useful
1531 for languages for which no patterns are preloaded in the
1532 format. In such cases the default behaviour of the \babel{}
1533 system is to define this language as a `dialect' of the language
1534 for which the patterns were loaded as |\language0|. Here
1535 ``language'' is used in the \TeX{} sense of set of hyphenation
1538 \DescribeMacro{\<lang>hyphenmins}
1539 The macro |\|\langvar|hyphenmins| is used to store the values of
1540 the |\lefthyphenmin| and |\righthyphenmin|. Redefine this macro
1541 to set your own values, with two numbers corresponding to these
1542 two parameters. For example:
1544 \renewcommand\spanishhyphenmins{34}
1546 (Assigning |\lefthyphenmin| and |\righthyphenmin| directly in
1547 |\extras<lang>| has no effect.)
1549 \DescribeMacro{\providehyphenmins}
1550 The macro |\providehyphenmins| should be used in the language
1551 definition files to set |\lefthyphenmin| and
1552 |\righthyphenmin|. This macro will check whether these parameters
1553 were provided by the hyphenation file before it takes any action.
1554 If these values have been already set, this command is ignored
1555 (currenty, default pattern files do \textit{not} set them).
1557 \DescribeMacro{\captions\langvar}
1558 The macro |\captions|\langvar\ defines the macros that
1559 hold the texts to replace the original hard-wired texts.
1561 \DescribeMacro{\date\langvar}
1562 The macro |\date|\langvar\ defines |\today|.
1564 \DescribeMacro{\extras\langvar}
1565 The macro |\extras|\langvar\ contains all the extra definitions needed
1566 for a specific language. This macro, like the following, is a hook --
1567 you can add things to it, but it must not be used directly.
1569 \DescribeMacro{\noextras\langvar}
1570 Because we want to let the user switch
1571 between languages, but we do not know what state \TeX\ might be in
1572 after the execution of |\extras|\langvar, a macro that brings
1573 \TeX\ into a predefined state is needed. It will be no surprise
1574 that the name of this macro is |\noextras|\langvar.
1576 \DescribeMacro{\bbl@declare@ttribute}
1577 This is a command to be used in the language definition files for
1578 declaring a language attribute. It takes three arguments: the
1579 name of the language, the attribute to be defined, and the code
1580 to be executed when the attribute is to be used.
1582 \DescribeMacro{\main@language}
1583 To postpone the activation of the definitions needed for a
1584 language until the beginning of a document, all language
1585 definition files should use |\main@language| instead of
1586 |\selectlanguage|. This will just store the name of the language,
1587 and the proper language will be activated at the start of the
1590 \DescribeMacro{\ProvidesLanguage}
1591 The macro |\ProvidesLanguage| should be used to identify the
1592 language definition files. Its syntax is similar to the syntax
1593 of the \LaTeX\ command |\ProvidesPackage|.
1595 \DescribeMacro{\LdfInit}
1596 The macro |\LdfInit| performs a couple of standard checks that
1597 must be made at the beginning of a language definition file,
1598 such as checking the category code of the @-sign, preventing
1599 the \file{.ldf} file from being processed twice, etc.
1601 \DescribeMacro{\ldf@quit}
1602 The macro |\ldf@quit| does work needed
1603 if a \file{.ldf} file was processed
1604 earlier. This includes resetting the category code
1605 of the @-sign, preparing the language to be activated at
1606 |\begin{document}| time, and ending the input stream.
1608 \DescribeMacro{\ldf@finish}
1609 The macro |\ldf@finish| does work needed
1610 at the end of each \file{.ldf} file. This
1611 includes resetting the category code of the @-sign,
1612 loading a local configuration file, and preparing the language
1613 to be activated at |\begin{document}| time.
1615 \DescribeMacro{\loadlocalcfg}
1616 After processing a language definition file,
1617 \LaTeX\ can be instructed to load a local configuration
1618 file. This file can, for instance, be used to add strings to
1619 |\captions|\langvar\ to support local document
1620 classes. The user will be informed that this
1621 configuration file has been loaded. This macro is called by
1624 \DescribeMacro{\substitutefontfamily}
1625 (Deprecated.) This command takes three arguments, a font encoding and
1626 two font family names. It creates a font description file for the
1627 first font in the given encoding. This \file{.fd} file will instruct
1628 \LaTeX\ to use a font from the second family when a font from the
1629 first family in the given encoding seems to be needed.
1631 \subsection{Skeleton}
1633 Here is the basic structure of an |ldf| file, with a language, a
1634 dialect and an attribute. Strings are best defined using the method
1635 explained in in sec. \ref{s:strings} (\babel{} 3.9 and later).
1638 \ProvidesLanguage{<language>}
1639 [0000/00/00 v0.0 <Language> support from the babel system]
1640 \LdfInit{<language>}{captions<language>}
1642 \ifx\undefined\l@<language>
1643 \@nopatterns{<Language>}
1644 \adddialect\l@<language>0
1647 \adddialect\l@<dialect>\l@<language>
1649 \bbl@declare@ttribute{<language>}{<attrib>}{%
1650 \expandafter\addto\expandafter\extras<language>
1651 \expandafter{\extras<attrib><language>}%
1652 \let\captions<language>\captions<attrib><language>}
1654 \providehyphenmins{<language>}{\tw@\thr@@}
1656 \StartBabelCommands*{<language>}{captions}
1657 \SetString\chaptername{<chapter name>}
1660 \StartBabelCommands*{<language>}{date}
1661 \SetString\monthiname{<name of first month>}
1664 \StartBabelCommands*{<dialect>}{captions}
1665 \SetString\chaptername{<chapter name>}
1668 \StartBabelCommands*{<dialect>}{date}
1669 \SetString\monthiname{<name of first month>}
1674 \addto\extras<language>{}
1675 \addto\noextras<language>{}
1676 \let\extras<dialect>\extras<language>
1677 \let\noextras<dialect>\noextras<language>
1679 \ldf@finish{<language>}
1682 \subsection{Support for active characters}
1684 In quite a number of language definition files, active characters are
1685 introduced. To facilitate this, some support macros are provided.
1687 \DescribeMacro{\initiate@active@char}
1688 The internal macro |\initiate@active@char| is used in language
1689 definition files to instruct \LaTeX\ to give a character the category
1690 code `active'. When a character has been made active it will remain
1691 that way until the end of the document. Its definition may vary.
1693 \DescribeMacro{\bbl@activate}
1694 \DescribeMacro{\bbl@deactivate}
1695 The command |\bbl@activate| is used to change the way an active
1696 character expands. |\bbl@activate| `switches on' the active behaviour
1697 of the character. |\bbl@deactivate| lets the active character expand
1698 to its former (mostly) non-active self.
1700 \DescribeMacro{\declare@shorthand}
1701 The macro |\declare@shorthand| is used to define the various
1702 shorthands. It takes three arguments: the name for the collection of
1703 shorthands this definition belongs to; the character (sequence) that
1704 makes up the shorthand, i.e.\ |~| or |"a|; and the code to be executed
1705 when the shorthand is encountered. (It does \textit{not} raise an
1706 error if the shorthand character has not been ``initiated''.)
1708 \DescribeMacro{\bbl@add@special}
1709 \DescribeMacro{\bbl@remove@special}
1710 The \TeX book states: ``Plain \TeX\ includes a macro called
1711 |\dospecials| that is essentially a set macro, representing the set of
1712 all characters that have a special category code.'' \cite[p.~380]{DEK}
1713 It is used to set text `verbatim'. To make this work if more
1714 characters get a special category code, you have to add this character
1715 to the macro |\dospecial|. \LaTeX\ adds another macro called
1716 |\@sanitize| representing the same character set, but without the
1717 curly braces. The macros |\bbl@add@special|\meta{char} and
1718 |\bbl@remove@special|\meta{char} add and remove the character
1719 \meta{char} to these two sets.
1721 \subsection{Support for saving macro definitions}
1723 Language definition files may want to \emph{re}define macros that
1724 already exist. Therefore a mechanism for saving (and restoring) the
1725 original definition of those macros is provided. We provide two macros
1726 for this\footnote{This mechanism was introduced by Bernd Raichle.}.
1728 \DescribeMacro{\babel@save}
1729 To save the current meaning of any control sequence, the macro
1730 |\babel@save| is provided. It takes one argument, \meta{csname}, the
1731 control sequence for which the meaning has to be saved.
1733 \DescribeMacro{\babel@savevariable}
1734 A second macro is provided to save the current value of a variable.
1735 In this context, anything that is allowed after the |\the| primitive
1736 is considered to be a variable. The macro takes one argument, the
1739 The effect of the preceding macros is to append a piece of code to
1740 the current definition of |\originalTeX|. When |\originalTeX| is
1741 expanded, this code restores the previous definition of the control
1742 sequence or the previous value of the variable.
1744 \subsection{Support for extending macros}
1746 \DescribeMacro{\addto}
1747 The macro |\addto{|\meta{control sequence}|}{|\meta{\TeX\ code}|}| can
1748 be used to extend the definition of a macro. The macro need not be
1749 defined (ie, it can be undefined or |\relax|). This macro can, for
1750 instance, be used in adding instructions to a macro like
1753 Be careful when using this macro, because depending on the case the
1754 assignment could be either global (usually) or local (sometimes). That
1755 does not seem very consistent, but this behaviour is preserved for
1756 backward compatibility. If you are using \pkg{etoolbox}, by Philipp
1757 Lehman, consider using the tools provided by this package instead of
1760 \subsection{Macros common to a number of languages}
1762 \DescribeMacro{\bbl@allowhyphens}
1763 In several languages compound words are used. This means that when
1764 \TeX\ has to hyphenate such a compound word, it only does so at the
1765 `\texttt{-}' that is used in such words. To allow hyphenation in the
1766 rest of such a compound word, the macro |\bbl@allowhyphens| can be
1769 \DescribeMacro{\allowhyphens}
1770 Same as |\bbl@allowhyphens|, but does nothing if the encoding is
1771 |T1|. It is intended mainly for characters provided as real glyphs by
1772 this encoding but constructed with |\accent| in |OT1|.
1774 Note the previous command (|\bbl@allowhyphens|) has different
1775 applications (hyphens and discretionaries) than this one (composite
1776 chars). Note also prior to version 3.7, |\allowhyphens| had the
1777 behaviour of |\bbl@allowhyphens|.
1779 \DescribeMacro{\set@low@box}
1780 For some languages, quotes need to be lowered to the baseline. For
1781 this purpose the macro |\set@low@box| is available. It takes one
1782 argument and puts that argument in an |\hbox|, at the baseline. The
1783 result is available in |\box0| for further processing.
1785 \DescribeMacro{\save@sf@q}
1786 Sometimes it is necessary to preserve the |\spacefactor|. For this
1787 purpose the macro |\save@sf@q| is available. It takes one argument,
1788 saves the current spacefactor, executes the argument, and restores the
1791 \DescribeMacro{\bbl@frenchspacing}
1792 \DescribeMacro{\bbl@nonfrenchspacing}
1793 The commands |\bbl@frenchspacing| and |\bbl@nonfrenchspacing| can be
1794 used to properly switch French spacing on and off.
1796 \subsection{Encoding-dependent strings}
1799 \New{3.9a} Babel 3.9 provides a way of defining strings in several
1800 encodings, intended mainly for \luatex{} and \xetex. This is the only new
1801 feature requiring changes in language files if you want to make use of
1804 Furthermore, it must be activated explicitly, with the package option
1805 |strings|. If there is no |strings|, these blocks are ignored, except
1806 |\SetCase|s (and except if forced as described below). In other words,
1807 the old way of defining/switching strings still works and it's used by
1810 It consist is a series of blocks started with
1811 |\StartBabelCommands|. The last block is closed with
1812 |\EndBabelCommands|. Each block is a single group (ie, local
1813 declarations apply until the next |\StartBabelCommands| or
1814 |\EndBabelCommands|). An |ldf| may contain several series of this
1817 Thanks to this new feature, string values and string language
1818 switching are not mixed any more. No need of |\addto|. If the language
1819 is |french|, just redefine |\frenchchaptername|.
1821 \Describe\StartBabelCommands
1822 {\marg{language-list}\marg{category}\oarg{selector}}
1824 The \m{language-list} specifies which languages the block is
1825 intended for. A block is taken into account only if the
1826 |\CurrentOption| is listed here. Alternatively, you can define
1827 |\BabelLanguages| to a comma-separated list of languages to be
1828 defined (if undefined, |\StartBabelCommands| sets it to
1829 |\CurrentOption|). You may write |\CurrentOption| as the language,
1830 but this is discouraged -- a explicit name (or names) is much better
1833 A ``selector'' is a name to be used as value in package option
1834 |strings|, optionally followed by extra info about the encodings to be
1835 used. The name |unicode| must be used for \xetex{} and \luatex{} (the
1836 key |strings| has also other two special values: |generic| and
1839 If a string is set several times (because several blocks are read),
1840 the first one take precedence (ie, it works much like
1843 Encoding info is |charset=| followed by a charset, which if given sets
1844 how the strings should be traslated to the internal representation
1845 used by the engine, typically |utf8|, which is the only value
1846 supported currently (default is no traslations). Note |charset| is
1847 applied by \luatex{} and \xetex{} when reading the file, not when the
1848 macro or string is used in the document.
1850 A list of font encodings which the strings are expected to work with
1851 can be given after |fontenc=| (separated with spaces, if two or more) --
1852 recommended, but not mandatory, although blocks without this key are
1853 not taken into account if you have requested |strings=encoded|.
1855 Blocks without a selector are read always if the key |strings| has
1856 been used. They provide fallback values, and therefore must be the
1857 last blocks; they should be provided always if possible and all
1858 strings should be defined somehow inside it; they can be the only
1859 blocks (mainly LGC scripts using the LICR). Blocks without a selector
1860 can be activated explicitly with |strings=generic| (no block is taken
1861 into account except those). With |strings=encoded|, strings in those
1862 blocks are set as default (internally, |?|). With |strings=encoded|
1863 strings are protected, but they are correctly expanded in
1864 |\MakeUppercase| and the like. If there is no key |strings|, string
1865 definitions are ignored, but |\SetCase|s are still honoured (in a
1868 The \m{category} is either |captions|, |date| or |extras|. You must
1869 stick to these three categories, even if no error is raised when using
1870 other name.\footnote{In future releases further categories may be
1871 added.\nb{like `monetary', `time', `address', `name', `case' or
1872 `numeric'}} It may be empty, too, but in such a case using
1873 |\SetString| is an error (but not |\SetCase|).
1876 \StartBabelCommands{language}{captions}
1877 [unicode, fontenc=EU1 EU2, charset=utf8]
1878 \SetString{\chaptername}{utf8-string}
1880 \StartBabelCommands{language}{captions}
1881 \SetString{\chaptername}{ascii-maybe-LICR-string}
1887 \begin{verbatim}[escapechar=\&]
1888 \StartBabelCommands{austrian}{date}
1889 [unicode, fontenc=EU1 EU2, charset=utf8]
1890 \SetString\monthiname{J&\"a&nner}
1892 \StartBabelCommands{german,austrian}{date}
1893 [unicode, fontenc=EU1 EU2, charset=utf8]
1894 \SetString\monthiiiname{M&\"a&rz}
1896 \StartBabelCommands{austrian}{date}
1897 \SetString\monthiname{J\"{a}nner}
1899 \StartBabelCommands{german}{date}
1900 \SetString\monthiname{Januar}
1902 \StartBabelCommands{german,austrian}{date}
1903 \SetString\monthiiname{Februar}
1904 \SetString\monthiiiname{M\"{a}rz}
1905 \SetString\monthivname{April}
1906 \SetString\monthvname{Mai}
1907 \SetString\monthviname{Juni}
1908 \SetString\monthviiname{Juli}
1909 \SetString\monthviiiname{August}
1910 \SetString\monthixname{September}
1911 \SetString\monthxname{Oktober}
1912 \SetString\monthxiname{November}
1913 \SetString\monthxiiname{Dezenber}
1914 \SetString\today{\number\day.~%
1915 \csname month\romannumeral\month name\endcsname\space
1918 \StartBabelCommands{german,austrian}{captions}
1919 \SetString\prefacename{Vorwort}
1925 When used in |ldf| files, previous values of |\|\m{category}\m{language}
1926 are overriden, which means the old way to define strings still works
1927 and used by default (to be precise, is first set to undefined and then
1928 strings are added). However, when used in the preamble or in a
1929 package, new settings are added to the previous ones, if the language
1930 exists (in the \babel{} sense, ie, if |\date|\m{language} exists).
1932 \Describe\StartBabelCommands{%
1933 \colorbox{thegrey}{\ttfamily\hskip-.2em*\hskip-.2em}%
1934 \marg{language-list}\marg{category}\oarg{selector}}
1935 The starred version just forces |strings| to take a value -- if not set
1936 as package option, then the default for the engine is used. This is
1937 not done by default to prevent backward incompatibilities, but if you
1938 are creating a new language this version is better. It's up to
1939 the maintainers of the current languages to decide if using it is
1940 appropiate.\footnote{This replaces in 3.9g a short-lived
1941 \texttt{\string\UseStrings} which has been removed because it did
1944 \Describe\EndBabelCommands{}
1945 Marks the end of the series of blocks.
1947 \Describe\AfterBabelCommands{\marg{code}}
1948 The code is delayed and executed at the global scope just after |\EndBabelCommands|.
1950 \Describe\SetString{\marg{macro-name}\marg{string}}
1951 Adds \meta{macro-name} to the current category, and defines globally
1952 \meta{lang-macro-name} to \meta{code} (after applying the
1953 transformation corresponding to the current charset or defined with
1954 the hook |stringprocess|).
1956 Use this command to define strings, without including any ``logic'' if
1957 possible, which should be a separated macro. See the example above for
1960 \Describe\SetStringLoop{\marg{macro-name}\marg{string-list}}
1961 A convenient way to define several ordered names at once. For example,
1962 to define |\abmoniname|, |\abmoniiname|, etc. (and similarly with
1965 \SetStringLoop{abmon#1name}{en,fb,mr,ab,my,jn,jl,ag,sp,oc,nv,dc}
1966 \SetStringLoop{abday#1name}{lu,ma,mi,ju,vi,sa,do}
1968 |#1| is replaced by the roman numeral.
1970 \Describe\SetCase{\oarg{map-list}\marg{toupper-code}\marg{tolower-code}}
1971 Sets globally code to be executed at |\MakeUppercase| and
1972 |\MakeLowercase|. The code would be typically things like |\let\BB\bb|
1973 and |\uccode| or |\lccode| (although for the reasons explained above,
1974 changes in lc/uc codes may not work). A \meta{map-list} is a series of
1975 macros using the internal format of |\@uclclist| (eg,
1976 |\bb\BB\cc\CC|). The mandatory arguments take precedence over the
1977 optional one. This command, unlike |\SetString|, is executed always
1978 (even without |strings|), and it is intented for minor readjustments
1981 For example, as |T1| is the default case mapping in \LaTeX, we could
1983 \begin{verbatim}[escapechar=\&]
1984 \StartBabelCommands{turkish}{}[ot1enc, fontenc=OT1]
1986 {\uccode"10=`I\relax}
1987 {\lccode`I="10\relax}
1989 \StartBabelCommands{turkish}{}[unicode, fontenc=EU1 EU2, charset=utf8]
1991 {\uccode`i=`&\rmfamily\.{\ttfamily I}&\relax
1992 \uccode`&\i&=`I\relax}
1993 {\lccode`&\rmfamily\.{\ttfamily I}&=`i\relax
1994 \lccode`I=`&\i&\relax}
1996 \StartBabelCommands{turkish}{}
1998 {\uccode`i="9D\relax
1999 \uccode"19=`I\relax}
2000 {\lccode"9D=`i\relax
2001 \lccode`I="19\relax}
2005 (Note the mapping for |OT1| is not complete.)
2007 \Describe\SetHyphenMap{\marg{to-lower-macros}}
2008 \New{3.9g} Case mapping serves in \TeX{} for two unrelated purposes: case
2009 transforms (upper/lower) and hyphenation. |\SetCase| handles the
2010 former, while hyphenation is handled by |\SetHyphenMap| and controlled
2011 with the package option |hyphenmap|. So, even if internally they are based
2012 on the same \TeX{} primitive (|\lccode|), \babel{} sets them separately.
2014 There are three helper macros to
2015 be used inside |\SetHyphenMap|:
2017 \item |\BabelLower|\marg{uccode}\marg{lccode} is
2018 similar to |\lccode| but it's ignored if the char has been set and
2019 saves the original lccode to restore it when switching the language
2020 (except with |hyphenmap=first|).
2021 \item |\BabelLowerMM|\marg{uccode-from}\marg{uccode-to}%
2022 \marg{step}\marg{lccode-from} loops though the given uppercase
2023 codes, using the step, and assigns them the lccode, which is also
2024 increased (|MM| stands for \textit{many-to-many}).
2025 \item |\BabelLowerMO|\marg{uccode-from}\marg{uccode-to}%
2026 \marg{step}\marg{lccode} loops though the given uppercase
2027 codes, using the step, and assigns them the lccode, which is fixed
2028 (|MO| stands for \textit{many-to-one}).
2030 An example is (which is redundant, because these assignments are done
2031 by both \luatex{} and \xetex{}):
2033 \SetHyphenMap{\BabelLowerMM{"100}{"11F}{2}{"101}}
2036 This macro is not intended to fix wrong mappings done by Unicode
2037 (which are the default in both \xetex{} and \luatex{}) -- if an
2038 assignment is wrong, fix it directly.
2041 \section{Compatibility and changes}
2043 \subsection{Compatibility with \file{german.sty}}\label{l-h}
2045 The file \file{german.sty} has been one of the sources of inspiration
2046 for the \babel{} system. Because of this I wanted to include
2047 \file{german.sty} in the \babel{} system. To be able to do that I had
2048 to allow for one incompatibility: in the definition of the macro
2049 |\selectlanguage| in \file{german.sty} the argument is used as the
2050 {$\langle \it number \rangle$} for an |\ifcase|. So in this case a
2051 call to |\selectlanguage| might look like |\selectlanguage{\german}|.
2053 In the definition of the macro |\selectlanguage| in \file{babel.def}
2054 the argument is used as a part of other macronames, so a call to
2055 |\selectlanguage| now looks like |\selectlanguage{german}|. Notice
2056 the absence of the escape character. As of version~3.1a of \babel{}
2057 both syntaxes are allowed.
2059 All other features of the original \file{german.sty} have been copied
2060 into a new file, called \file{germanb.sty}\footnote{The `b' is added
2061 to the name to distinguish the file from Partls' file.}.
2063 Although the \babel{} system was developed to be used with \LaTeX,
2064 some of the features implemented in the language definition files
2065 might be needed by plain \TeX\ users. Care has been taken that all
2066 files in the system can be processed by plain \TeX.
2068 \subsection{Compatibility with \file{ngerman.sty}}
2070 When used with the options \Lopt{ngerman} or \Lopt{naustrian},
2071 \babel{} will provide all features of the package \pkg{ngerman}.
2072 There is however one exception: The commands for special hyphenation
2073 of double consonants (|"ff| etc.) and ck (|"ck|), which are no longer
2074 required with the new German orthography, are undefined. With the
2075 \pkg{ngerman} package, however, these commands will generate
2076 appropriate warning messages only.
2078 \subsection{Compatibility with the \pkg{french} package}
2080 It has been reported to me that the package \pkg{french} by Bernard
2081 Gaulle (\texttt{gaulle@idris.fr}) works together with \babel. On the
2082 other hand, it seems \emph{not} to work well together with a lot of
2083 other packages. Therefore I have decided to no longer load
2084 \file{french.ldf} by default. Instead, when you want to use the
2085 package by Bernard Gaulle, you will have to request it specifically,
2086 by passing either \Lopt{frenchle} or \Lopt{frenchpro} as an option to
2089 \subsection{Changes in \babel\ version 3.9}
2091 Most of changes in version 3.9 are related to bugs, either to fix them
2092 (there were lots), or to provide some alternatives. Even new features
2093 like |\babelhyphen| are intended to solve a certain problem (in this
2094 case, the lacking of a uniform syntax and behaviour for shorthands
2095 across languages). These changes are described in this manual in the
2098 \subsection{Changes in \babel\ version 3.7}
2100 In \babel\ version 3.7 a number of bugs that were found in
2101 version~3.6 are fixed. Also a number of changes and additions
2104 \item Shorthands are expandable again. The disadvantage is that
2105 one has to type |'{}a| when the acute accent is used as a
2106 shorthand character. The advantage is that a number of other
2107 problems (such as the breaking of ligatures, etc.) have
2109 \item Two new commands, |\shorthandon| and |\shorthandoff| have
2110 been introduced to enable to temporarily switch off one or more
2112 \item Support for typesetting Greek has been enhanced. Code from
2113 the \pkg{kdgreek} package (suggested by the author) was added
2114 and |\greeknumeral| has been added.
2115 \item Support for typesetting Basque is now available thanks to
2116 Juan Aguirregabiria.
2117 \item Support for typesetting Serbian with Latin script is now
2118 available thanks to Dejan Muhamedagi\'{c} and Jankovic
2120 \item Support for typesetting Hebrew (and potential support for
2121 typesetting other right-to-left written languages) is now
2122 available thanks to Rama Porrat and Boris Lavva.
2123 \item Support for typesetting Bulgarian is now available thanks to
2125 \item Support for typesetting Latin is now available, thanks to
2126 Claudio Beccari and Krzysztof Konrad \.Zelechowski.
2127 \item Support for typesetting North Sami is now available, thanks
2128 to Regnor Jernsletten.
2129 \item The options \Lopt{canadian}, \Lopt{canadien} and
2130 \Lopt{acadien} have been added for Canadian English and French
2132 \item A language attribute has been added to the |\mark...|
2133 commands in order to make sure that a Greek header line comes
2134 out right on the last page before a language switch.
2135 \item Hyphenation pattern files are now read \emph{inside a
2136 group}; therefore any changes a pattern file needs to make to
2137 lowercase codes, uppercase codes, and category codes are kept
2138 local to that group. If they are needed for the language, these
2139 changes will need to be repeated and stored in |\extras...|
2140 \item The concept of language attributes is introduced. It is
2141 intended to give the user some control over the
2142 features a language-definition file provides. Its
2143 first use is for the Greek language, where the user can choose
2144 the $\pi o\lambda\upsilon\tau o\nu\kappa\acute{o}$
2145 (``Polutoniko'' or multi-accented) Greek way of typesetting
2146 texts. These attributes will possibly find wider use in future
2148 \item The environment \Lenv{hyphenrules} is introduced.
2149 \item The syntax of the file \file{language.dat} has been
2150 extended to allow (optionally) specifying the font
2151 encoding to be used while processing the patterns file.
2152 \item The command |\providehyphenmins| should now be used in
2153 language definition files in order to be able to keep any
2154 settings provided by the pattern file.
2157 \subsection{Changes in \babel\ version 3.6}
2159 In \babel\ version 3.6 a number of bugs that were found in
2160 version~3.5 are fixed. Also a number of changes and additions
2163 \item A new environment \Lenv{otherlanguage*} is introduced. it
2164 only switches the `specials', but leaves the `captions'
2166 \item The shorthands are no longer fully expandable. Some
2167 problems could only be solved by peeking at the token following
2168 an active character. The advantage is that |'{}a| works as
2169 expected for languages that have the |'| active.
2170 \item Support for typesetting french texts is much enhanced; the
2171 file \file{francais.ldf} is now replaced by \file{frenchb.ldf}
2172 which is maintained by Daniel Flipo.
2173 \item Support for typesetting the russian language is again
2174 available. The language definition file was originally
2175 developed by Olga Lapko from CyrTUG. The fonts needed to
2176 typeset the russian language are now part of the \babel\
2177 distribution. The support is not yet up to the level which is
2178 needed according to Olga, but this is a start.
2179 \item Support for typesetting greek texts is now also
2180 available. What is offered in this release is a first attempt;
2181 it will be enhanced later on by Yannis Haralambous.
2182 \item in \babel\ 3.6j some hooks have been added for the
2183 development of support for Hebrew typesetting.
2184 \item Support for typesetting texts in Afrikaans (a variant of
2185 Dutch, spoken in South Africa) has been added to
2187 \item Support for typesetting Welsh texts is now available.
2188 \item A new command |\aliasshorthand| is introduced. It seems
2189 that in Poland various conventions are used to type the
2190 necessary Polish letters. It is now possible to use the
2191 character~|/| as a shorthand character instead of the
2192 character~|"|, by issuing the command |\aliasshorthand{"}{/}|.
2193 \item The shorthand mechanism now deals correctly with characters
2194 that are already active.
2195 \item Shorthand characters are made active at |\begin{document}|,
2196 not earlier. This is to prevent problems with other packages.
2197 \item A \emph{preambleonly} command |\substitutefontfamily| has
2198 been added to create \file{.fd} files on the fly when the font
2199 families of the Latin text differ from the families used for
2200 the Cyrillic or Greek parts of the text.
2201 \item Three new commands |\LdfInit|, |\ldf@quit| and
2202 |\ldf@finish| are introduced that perform a number of standard
2204 \item In babel 3.6k the language Ukrainian has been added and the
2205 support for Russian typesetting has been adapted to the package
2206 'cyrillic' to be released with the December 1998 release of
2210 \subsection{Changes in \babel\ version 3.5}
2212 In \babel\ version 3.5 a lot of changes have been made when compared
2213 with the previous release. Here is a list of the most important ones:
2215 \item the selection of the language is delayed until
2216 |\begin{document}|, which means you must add appropriate
2217 |\selectlanguage| commands if you include |\hyphenation| lists in
2218 the preamble of your document.
2219 \item \babel\ now has a \Lenv{language} environment and a new
2220 command |\foreignlanguage|;
2221 \item the way active characters are dealt with is completely
2222 changed. They are called `shorthands'; one can have three
2223 levels of shorthands: on the user level, the language level,
2224 and on `system level'. A consequence of the new way of handling
2225 active characters is that they are now written to auxiliary
2227 \item A language change now also writes information in the
2228 \file{.aux} file, as the change might also affect typesetting
2229 the table of contents. The consequence is that an \file{.aux} file
2230 generated by a \LaTeX format with babel preloaded gives errors
2231 when read with a \LaTeX format without babel; but I think this
2232 probably doesn't occur;
2233 \item \babel\ is now compatible with the \pkg{inputenc} and
2234 \pkg{fontenc} packages;
2235 \item the language definition files now have a new extension,
2237 \item the syntax of the file \file{language.dat} is extended to
2238 be compatible with the \pkg{french} package by Bernard Gaulle;
2239 \item each language definition file looks for a configuration
2240 file which has the same name, but the extension \file{.cfg}. It
2241 can contain any valid \LaTeX\ code.
2244 \DocInput{babel.dtx}
2245 \DocInput{bbunicode.dtx}
2247 \section{Conclusion}
2249 A system of document options has been presented that enable the user
2250 of \LaTeX\ to adapt the standard document classes of \LaTeX\ to the
2251 language he or she prefers to use. These options offer the possibility
2252 of switching between languages in one document. The basic interface
2253 consists of using one option, which is the same for \emph{all}
2254 standard document classes.
2256 In some cases the language definition files provide macros that can be
2257 useful to plain \TeX\ users as well as to \LaTeX\ users. The \babel{}
2258 system has been implemented so that it can be used by both groups of
2261 \section{Acknowledgements}
2263 I would like to thank all who volunteered as $\beta$-testers for their
2264 time. I would like to mention Julio Sanchez who supplied the option
2265 file for the Spanish language and Maurizio Codogno who supplied the
2266 option file for the Italian language. Michel Goossens supplied
2267 contributions for most of the other languages. Nico Poppelier helped
2268 polish the text of the documentation and supplied parts of the macros
2269 for the Dutch language. Paul Wackers and Werenfried Spit helped find
2272 During the further development of the babel system I received much
2273 help from Bernd Raichle, for which I am grateful.
2275 \begin{thebibliography}{9}
2276 \bibitem{DEK} Donald E. Knuth,
2277 \emph{The \TeX book}, Addison-Wesley, 1986.
2278 \bibitem{LLbook} Leslie Lamport,
2279 \emph{\LaTeX, A document preparation System}, Addison-Wesley,
2281 \bibitem{treebus} K.F. Treebus.
2282 \emph{Tekstwijzer, een gids voor het grafisch verwerken van
2284 SDU Uitgeverij ('s-Gravenhage, 1988). A Dutch book on layout
2285 design and typography.
2286 \bibitem{HP} Hubert Partl,
2287 \emph{German \TeX}, \emph{TUGboat} 9 (1988) \#1, p.~70--72.
2288 \bibitem{LLth} Leslie Lamport,
2289 in: \TeX hax Digest, Volume 89, \#13, 17 February 1989.
2290 \bibitem{BEP} Johannes Braams, Victor Eijkhout and Nico Poppelier,
2291 \emph{The development of national \LaTeX\ styles},
2292 \emph{TUGboat} 10 (1989) \#3, p.~401--406.
2293 \bibitem{ilatex} Joachim Schrod,
2294 \emph{International \LaTeX\ is ready to use},
2295 \emph{TUGboat} 11 (1990) \#1, p.~87--90.
2296 \bibitem{ilatex} Apostolos Syropoulos, Antonis Tsolomitis and Nick
2298 \emph{Digital typography using \LaTeX},
2299 Springer, 2002, p.~301--373.
2300 \bibitem{FE} Yannis Haralambous,
2301 \emph{Fonts \& Encodings}, O'Reilly, 2007.
2302 \end{thebibliography}
2306 % \changes{babel~3.7a}{1997/04/16}{Make multiple loading of
2307 % \file{babel.def} impossible}
2308 % \changes{babel~3.9a}{2012/05/16}{Now using \cs{ldf@quit} for the test}
2311 \ifx\ldf@quit\@undefined
2313 \expandafter\endinput
2318 \ProvidesFile{babel.dtx}
2322 % \GetFileInfo{babel.dtx}
2324 % \changes{babel~2.0a}{1990/04/02}{Added text about \file{german.sty}}
2325 % \changes{babel~2.0b}{1990/04/18}{Changed order of code to prevent
2326 % plain \TeX from seeing all of it}
2327 % \changes{babel~2.1}{1990/04/24}{Modified user interface,
2328 % \cs{langTeX} no longer necessary}
2329 % \changes{babel~2.1a}{1990/05/01}{Incorporated Nico's comments}
2330 % \changes{babel~2.1b}{1990/05/01}{rename \cs{language} to
2331 % \cs{current@language}}
2332 % \changes{babel~2.1c}{1990/05/22}{abstract for report fixed, missing
2333 % \texttt{\}}, found by Nicolas Brouard}
2334 % \changes{babel~2.1d}{1990/07/04}{Missing right brace in definition of
2335 % abstract environment, found by Werenfried Spit}
2336 % \changes{babel~2.1e}{1990/07/16}{Incorporated more comments from
2338 % \changes{babel~2.2}{1990/07/17}{Renamed \cs{newlanguage} to
2340 % \changes{babel~2.2a}{1990/08/27}{Modified the documentation
2342 % \changes{babel~3.0}{1991/04/23}{Moved part of the code to hyphen.doc
2343 % in preparation for \TeX~3.0}
2344 % \changes{babel~3.0a}{1991/05/21}{Updated comments in various places}
2345 % \changes{babel~3.0b}{1991/05/25}{Removed some problems in change log}
2346 % \changes{babel~3.0c}{1991/07/15}{Renamed \file{babel.sty} and
2347 % \file{latexhax.sty} to \file{.com}}
2348 % \changes{babel~3.1}{1991/10/31}{Added the support for active
2349 % characters and for extending a macro}
2350 % \changes{babel~3.1}{1991/11/05}{Removed the need for
2352 % \changes{babel~3.2}{1991/11/10}{Some Changes by br}
2353 % \changes{babel~3.2a}{1992/02/15}{Fixups of the code and
2355 % \changes{babel~3.3}{1993/07/06}{Included driver file, and prepared
2357 % \changes{babel~3.4}{1994/01/30}{Updated for \LaTeXe}
2358 % \changes{babel~3.4}{1994/02/28}{Added language definition file for
2360 % \changes{babel~3.4b}{1994/05/18}{Added a small driver to be able to
2361 % process just this file}
2362 % \changes{babel~3.5a}{1995/02/03}{Provided common code to handle the
2363 % active double quote}
2364 % \changes{babel~3.5c}{1995/06/14}{corrected a few typos (PR1652)}
2365 % \changes{babel~3.5d}{1995/07/02}{Merged glyphs.dtx into this file}
2366 % \changes{babel~3.5f}{1995/07/13}{repaired a typo}
2367 % \changes{babel~3.5f}{1996/01/09}{replaced \cs{tmp}, \cs{bbl@tmp} and
2368 % \cs{bbl@temp} with \cs{bbl@tempa}}
2369 % \changes{babel~3.5g}{1996/07/09}{replaced \cs{undefined} with
2370 % \cs{@undefined} to be consistent with \LaTeX}
2371 % \changes{babel~3.7d}{1999/05/05}{Fixed a few typos in \cs{changes}
2372 % entries which made typesetting the code impossible}
2373 % \changes{babel~3.7h}{2001/03/01}{Added a number of missing comment
2374 % characters which caused spurious white space}
2375 % \changes{babel~3.8e}{2005/03/24}{Many enhancements to the text by
2377 % \changes{babel~3.9c}{2013/04/04}{Added the ``modifiers'' mechanism}
2378 % \changes{babel~3.9g}{2013/06/01}{bbplain merged}
2379 % \changes{babel~3.9k}{2014/03/23}{Code and doc reorganized, and some
2380 % minor enhancements}
2382 % \catcode`<=\active%
2383 % \catcode`>=\active
2385 % \gdef\MakePrivateLetters{%
2386 % \catcode`@=11\relax
2387 % \gdef<##1{\ifx##1@$\langle\langle$\bgroup\itshape\rmfamily
2388 % \expandafter\bblref
2389 % \else\string<##1\fi}%
2390 % \gdef\bblref##1@>{##1\/\egroup$\rangle\rangle$}}%
2395 % \section{Identification and loading of required files}
2397 % \textit{Code documentation is still under revision.}
2399 % The \babel{} package after unpacking it consists of the following files:
2400 % \begin{description}
2401 % \itemsep=-\parskip
2402 % \item[switch.def] defines macros to set and switch languages.
2403 % \item[babel.def] defines the rest of macros. It has tow parts: a
2404 % generic one and a second one only for LaTeX{}.
2405 % \item[babel.sty] is the \LaTeX{} package, which set options and
2406 % load language styles.
2407 % \item[plain.def] defines some \LaTeX{} macros required by
2408 % \file{babel.def} and provides a few tools for Plain.
2409 % \item[hyphen.cfg] is the file to be used when generating the
2410 % formats to load hyphenation patterns. By default it also loads
2411 % \file{switch.def}.
2414 % The \babel{} installer extends \textsf{docstrip} with a few
2415 % ``pseudo-guards'' to set ``variables'' used at installation time.
2416 % They are used with |<||@name@>| at the appropiated places in the
2417 % source code and shown below with
2418 % $\langle\langle$\textit{name}$\rangle\rangle$. That brings a
2419 % little bit of literate programming.
2423 %<<date=2016/02/01>>
2426 % We define some basic macros which just make the code cleaner.
2427 % |\bbl@add| is now used internally instead of |\addto| because of
2428 % the unpredictable behaviour of the latter. Used in
2429 % \file{babel.def} and in \file{babel.sty}, which means in \LaTeX{}
2430 % is executed twice, but we need them when defining options and
2431 % \file{babel.def} cannot be load until options have been defined.
2432 % \changes{babel~3.9i}{2014/02/16}{\cs{@for} didn't work with
2433 % Plain. Added \cs{bbl@loop}}
2437 \@ifundefined{\expandafter\@gobble\string#1}%
2439 {\expandafter\def\expandafter#1\expandafter{#1#2}}}
2440 \def\bbl@csarg#1#2{\expandafter#1\csname bbl@#2\endcsname}%
2441 \long\def\bbl@afterelse#1\else#2\fi{\fi#1}
2442 \long\def\bbl@afterfi#1\fi{\fi#1}
2443 \def\bbl@loop#1#2#3{\bbl@@loop#1{#3}#2,\@nnil,}
2444 \def\bbl@loopx#1#2{\expandafter\bbl@loop\expandafter#1\expandafter{#2}}
2445 \def\bbl@@loop#1#2#3,{%
2446 \ifx\@nnil#3\relax\else
2447 \def#1{#3}#2\bbl@afterfi\bbl@@loop#1{#2}%
2449 \def\bbl@for#1#2#3{\bbl@loopx#1{#2}{\ifx#1\@empty\else#3\fi}}
2453 % Some files identify themselves with a \LaTeX{} macro. The following
2454 % code is placed before them to define (and then undefine) if not in
2458 %<<*Make sure ProvidesFile is defined>>
2459 \ifx\ProvidesFile\@undefined
2460 \def\ProvidesFile#1[#2 #3 #4]{%
2461 \wlog{File: #1 #4 #3 <#2>}%
2462 \let\ProvidesFile\@undefined}
2464 %<</Make sure ProvidesFile is defined>>
2467 % The following code is used in \file{babel.sty} and
2468 % \file{babel.def}, and makes sure the current version of
2469 % |switch.ldf| is used, if different from that in the format.
2472 %<<*Load switch if newer>>
2473 \def\bbl@tempa{<@version@>}%
2474 \ifx\bbl@version\bbl@tempa\else
2475 \input switch.def\relax
2477 %<</Load switch if newer>>
2480 % The following code is used in \file{babel.def} and
2481 % \file{switch.def}.
2484 %<<*Load macros for plain if not LaTeX>>
2485 \ifx\AtBeginDocument\@undefined
2486 \input plain.def\relax
2488 %<</Load macros for plain if not LaTeX>>
2491 % \subsection{Multiple languages}
2493 % \begin{macro}{\language}
2494 % Plain \TeX\ version~3.0 provides the primitive |\language| that
2495 % is used to store the current language. When used with a pre-3.0
2496 % version this function has to be implemented by allocating a
2497 % counter. The following block is used in \file{switch.def} and
2498 % \file{hyphen.cfg}; the latter may seem redundant, but remember
2499 % \babel{} doesn't requires loading \file{switch.def} in the format.
2501 %<<*Define core switching macros>>
2502 \ifx\language\@undefined
2503 \csname newcount\endcsname\language
2505 %<</Define core switching macros>>
2509 % \begin{macro}{\last@language}
2510 % Another counter is used to store the last language defined. For
2511 % pre-3.0 formats an extra counter has to be allocated.
2513 % \begin{macro}{\addlanguage}
2515 % To add languages to \TeX's memory plain \TeX\ version~3.0
2516 % supplies |\newlanguage|, in a pre-3.0 environment a similar macro
2517 % has to be provided. For both cases a new macro is defined here,
2518 % because the original |\newlanguage| was defined to be |\outer|.
2520 % For a format based on plain version~2.x, the definition of
2521 % |\newlanguage| can not be copied because |\count 19| is used for
2522 % other purposes in these formats. Therefore |\addlanguage| is
2523 % defined using a definition based on the macros used to define
2524 % |\newlanguage| in plain \TeX\ version~3.0.
2525 % \changes{babel~3.2}{1991/11/11}{Added a \texttt{\%}, removed
2528 % For formats based on plain version~3.0 the definition of
2529 % |\newlanguage| can be simply copied, removing |\outer|.
2530 % Plain \TeX\ version 3.0 uses |\count 19| for this purpose.
2532 %<<*Define core switching macros>>
2533 \ifx\newlanguage\@undefined
2534 \csname newcount\endcsname\last@language
2535 \def\addlanguage#1{%
2536 \global\advance\last@language\@ne
2537 \ifnum\last@language<\@cclvi
2539 \errmessage{No room for a new \string\language!}%
2541 \global\chardef#1\last@language
2542 \wlog{\string#1 = \string\language\the\last@language}}
2544 \countdef\last@language=19
2545 \def\addlanguage{\alloc@9\language\chardef\@cclvi}
2547 %<</Define core switching macros>>
2552 % Identify each file that is produced from this source file.
2553 % \changes{babel~3.4c}{1995/04/28}{lhyphen.cfg has become
2555 % \changes{babel~3.5b}{1995/01/25}{lthyphen.cfg has become hyphen.cfg}
2558 \ProvidesFile{babel.drv}[<@date@> <@version@>]
2561 \ProvidesFile{user.drv}[<@date@> <@version@>]
2565 % Now we make sure all required files are loaded. When the command
2566 % |\AtBeginDocument| doesn't exist we assume that we are dealing
2567 % with a plain-based format or \LaTeX2.09. In that case the file
2568 % \file{plain.def} is needed (which also defines
2569 % |\AtBeginDocument|, and therefore it is not loaded twice). We
2570 % need the first part when the format is created, and |\orig@dump|
2571 % is used as a flag. Otherwise, we need to use the second part, so
2572 % |\orig@dump| is not defined (\file{plain.def} undefines it).
2574 % \changes{babel~3.9a}{2012/12/21}{Use \cs{orig@dump} as flag instead
2575 % of \cs{adddialect}}
2577 % Check if the current version of \file{switch.def} has been
2578 % previously loaded (mainly, \file{hyphen.cfg}). If not, load it
2579 % now. We cannot load |babel.def| here because we first need to
2580 % declare and process the package options.
2581 % \changes{babel~3.0d}{1991/10/29}{Removed use of \cs{@ifundefined}}
2582 % \changes{babel~3.9a}{2012/08/11}{Now switch.def is loaded always, so
2583 % that there is no need to rebuild formats just to update babel}
2584 % \changes{babel~3.9a}{2012/12/13}{But switch.def is loaded only if
2585 % loaded in a different version (or not loaded)}
2586 % \changes{babel~3.9a}{2013/01/14}{Added the debug option}
2587 % \changes{babel~3.9a}{2013/02/05}{Added \cs{bbl@add}}
2588 % \changes{babel~3.6a}{1996/11/02}{Removed \cs{babel@core@loaded}, no
2589 % longer needed with the advent of \cs{LdfInit}}
2591 % \section{The Package File (\LaTeX)}
2593 % In order to make use of the features of \LaTeXe, the \babel\
2594 % system contains a package file, \file{babel.sty}. This file is
2595 % loaded by the |\usepackage| command and defines all the language
2596 % options whose name is different from that of the |.ldf| file
2597 % (like variant spellings). It also takes care of a number of
2598 % compatibility issues with other packages an defines a few
2599 % aditional package options.
2602 % Apart from all the language options below we also have a few options
2603 % that influence the behaviour of language definition files.
2605 % Many of the following options don't do anything themselves, they
2606 % are just defined in order to make it possible for babel and
2607 % language definition files to check if one of them was specified
2610 % \subsection{\texttt{base}}
2612 % The first option to be processed is |base|, which set the
2613 % hyphenation patterns then resets |ver@babel.sty| so that
2614 % \LaTeX forgets about the first loading. After |switch.def| has
2615 % been loaded (above) and |\AfterBabelLanguage| defined, exits.
2617 % \changes{babel~3.5d}{1995/07/04}{Added options to influence
2618 % behaviour of active acute and grave accents}
2619 % \changes{babel~3.9a}{2012/10/05}{preset option started,
2620 % party stolen from fontenc}
2621 % \changes{babel~3.9a}{2012/10/17}{Hooks started}
2622 % \changes{babel~3.9a}{2013/02/07}{Rejected preset, and replaced by
2624 % \changes{babel~3.5g}{1996/10/10}{We need at least \LaTeX\ from
2626 % \changes{babel~3.6k}{1999/03/18}{We need at least \LaTeX\ from
2630 \NeedsTeXFormat{LaTeX2e}[2005/12/01]
2631 \ProvidesPackage{babel}[<@date@> <@version@> The Babel package]
2632 \@ifpackagewith{babel}{debug}
2633 {\input switch.def\relax}
2634 {<@Load switch if newer@>}
2636 \def\AfterBabelLanguage#1{%
2637 \global\expandafter\bbl@add\csname#1.ldf-h@@k\endcsname}%
2638 \@ifpackagewith{babel}{base}{%
2639 \DeclareOption*{\bbl@patterns{\CurrentOption}}%
2640 \DeclareOption{base}{}%
2642 \global\expandafter\let\csname opt@babel.sty\endcsname\relax
2643 \global\expandafter\let\csname ver@babel.sty\endcsname\relax
2644 \global\let\@ifl@ter@@\@ifl@ter
2645 \def\@ifl@ter#1#2#3#4#5{\global\let\@ifl@ter\@ifl@ter@@}%
2649 % \subsection{\texttt{key=value} options and other general option}
2651 % The following macros extract language modifiers, and only real
2652 % package options are kept in the option list. Modifiers are saved
2653 % and assigned to |\BabelModifiers| at |\bbl@load@language|; when
2654 % no modifiers have been given, the former is |\relax|. How
2655 % modifiers are handled are left to language styles; they can use
2656 % |\in@|, loop them with |\@for| o load |keyval|).
2657 % \changes{babel~3.9e}{2013/04/15}{Bug fixed - a dot was added in
2661 \bbl@csarg\let{tempa\expandafter}\csname opt@babel.sty\endcsname
2662 \def\bbl@tempb#1.#2{%
2663 #1\ifx\@empty#2\else,\bbl@afterfi\bbl@tempb#2\fi}%
2664 \def\bbl@tempd#1.#2\@nnil{%
2666 \edef\bbl@tempc{\ifx\bbl@tempc\@empty\else\bbl@tempc,\fi#1}%
2669 \edef\bbl@tempc{\ifx\bbl@tempc\@empty\else\bbl@tempc,\fi#1.#2}%
2671 \edef\bbl@tempc{\ifx\bbl@tempc\@empty\else\bbl@tempc,\fi#1}%
2672 \bbl@csarg\edef{mod@#1}{\bbl@tempb#2}%
2675 \let\bbl@tempc\@empty
2676 \bbl@for\bbl@tempa\bbl@tempa{%
2677 \expandafter\bbl@tempd\bbl@tempa.\@empty\@nnil}
2678 \expandafter\let\csname opt@babel.sty\endcsname\bbl@tempc
2680 % The next option tells \babel\ to leave shorthand characters
2681 % active at the end of processing the package. This is \emph{not}
2682 % the default as it can cause problems with other packages, but for
2683 % those who want to use the shorthand characters in the preamble of
2684 % their documents this can help.
2685 % \changes{babel~3.6f}{1997/01/14}{Added option
2686 % \Lopt{KeepShorthandsActive}}
2687 % \changes{babel~3.7a}{1997/03/21}{No longer define the control
2688 % sequence \cs{KeepShorthandsActive}}
2689 % \changes{babel~3.9a}{2012/08/14}{Implemented the \texttt{noconfigs}
2691 % \changes{babel~3.9a}{2012/09/26}{Implemented the
2692 % \texttt{showlanguages} option}
2693 % \changes{babel~3.9g}{2013/08/07}{Options for hyphenmap}
2694 % \changes{babel~3.9l}{2014/07/29}{Option \texttt{silent}}
2696 \DeclareOption{KeepShorthandsActive}{}
2697 \DeclareOption{activeacute}{}
2698 \DeclareOption{activegrave}{}
2699 \DeclareOption{debug}{}
2700 \DeclareOption{noconfigs}{}
2701 \DeclareOption{showlanguages}{}
2702 \DeclareOption{silent}{}
2703 \DeclareOption{shorthands=off}{\bbl@tempa shorthands=\bbl@tempa}
2704 <@More package options@>
2707 % Handling of package options is done in three passes. (I [JBL] am not
2708 % very happy with the idea, anyway.) The first one processes
2709 % options which has been declared above or follow the syntax
2710 % |<key>=<value>|, the second one
2711 % loads the requested languages, except the main one if set with
2712 % the key |main|, and the third one loads the latter. First, we
2713 % ``flag'' valid keys with a nil value.
2714 % \changes{babel~3.9a}{2012/08/10}{Added the `safe' key, including code
2715 % below for selecting the redefined macros}
2717 \let\bbl@opt@shorthands\@nnil
2718 \let\bbl@opt@config\@nnil
2719 \let\bbl@opt@main\@nnil
2720 \let\bbl@opt@headfoot\@nnil
2722 % The following tool is defined temporarily to store the values of
2725 \def\bbl@tempa#1=#2\bbl@tempa{%
2726 \expandafter\ifx\csname bbl@opt@#1\endcsname\@nnil
2727 \expandafter\edef\csname bbl@opt@#1\endcsname{#2}%
2730 Bad option `#1=#2'. Either you have misspelled the\\%
2731 key or there is a previous setting of `#1'}{%
2732 Valid keys are `shorthands', `config', `strings', `main',\\%
2733 `headfoot', `safe', `math'}
2736 % Now the option list is processed, taking into account only
2737 % currently declared options (including those declared with a |=|),
2738 % and |<key>=<value>| options (the former take precedence).
2739 % Unrecognized options are saved in |\bbl@language@opts|, because
2740 % they are language options.
2742 \let\bbl@language@opts\@empty
2744 \@expandtwoargs\in@{\string=}{\CurrentOption}%
2746 \expandafter\bbl@tempa\CurrentOption\bbl@tempa
2748 \edef\bbl@language@opts{%
2749 \ifx\bbl@language@opts\@empty\else\bbl@language@opts,\fi
2753 % Now we finish the first pass (and start over).
2758 % \subsection{Conditional loading of shorthands}
2760 % If there is no |shorthands=<chars>|, the original \textsf{babel}
2761 % macros are left untouched, but if there is, these macros are
2762 % wrapped (in |babel.def|) to define only those given.
2764 % A bit of optimization: if there is no |shorthands=|, then
2765 % |\bbl@ifshorthands| is always true, and it is always false if
2766 % |shorthands| is empty. Also, some code makes sense only with
2768 % \changes{babel~3.9c}{2013/04/07}{Added t and c for tilde and comma}
2770 \def\bbl@sh@string#1{%
2773 \else\ifx#1c\string,%
2776 \expandafter\bbl@sh@string
2778 \ifx\bbl@opt@shorthands\@nnil
2779 \def\bbl@ifshorthand#1#2#3{#2}%
2780 \else\ifx\bbl@opt@shorthands\@empty
2781 \def\bbl@ifshorthand#1#2#3{#3}%
2784 % The following macro tests if a shortand is one of the allowed
2787 \def\bbl@ifshorthand#1{%
2788 \@expandtwoargs\in@{\string#1}{\bbl@opt@shorthands}%
2790 \expandafter\@firstoftwo
2792 \expandafter\@secondoftwo
2795 % We make sure all chars in the string are `other', with the help
2796 % of an auxiliary macro defined above (which also zaps spaces).
2798 \edef\bbl@opt@shorthands{%
2799 \expandafter\bbl@sh@string\bbl@opt@shorthands\@empty}%
2802 % The following is ignored with |shorthands=off|, since it is
2803 % intended to take some aditional actions for certain chars.
2806 \bbl@ifshorthand{'}%
2807 {\PassOptionsToPackage{activeacute}{babel}}{}
2808 \bbl@ifshorthand{`}%
2809 {\PassOptionsToPackage{activegrave}{babel}}{}
2812 % \changes{babel~3.9a}{2012/07/30}{Code setting language in
2813 % head/foots. Related to babel/3796}
2814 % With |headfoot=lang| we can set the language used in heads/foots.
2815 % For example, in babel/3796 just adds |headfoot=english|. It
2816 % misuses \cs{@resetactivechars} but seems to work.
2818 \ifx\bbl@opt@headfoot\@nnil\else
2819 \g@addto@macro\@resetactivechars{%
2820 \set@typeset@protect
2821 \expandafter\select@language@x\expandafter{\bbl@opt@headfoot}%
2822 \let\protect\noexpand}
2825 % For the option safe we use a different approach --
2826 % |\bbl@opt@safe| says which macros are redefined (B for bibs and R
2827 % for refs). By default, both are set.
2829 \@ifundefined{bbl@opt@safe}{\def\bbl@opt@safe{BR}}{}
2830 \ifx\bbl@opt@main\@nnil\else
2831 \edef\bbl@language@opts{%
2832 \ifx\bbl@language@opts\@empty\else\bbl@language@opts,\fi
2836 % If the format created a list of loaded languages (in
2837 % |\bbl@languages|), get the name of the 0-th to show the actual
2840 \ifx\bbl@languages\@undefined\else
2843 \@ifpackagewith{babel}{showlanguages}{%
2845 \def\bbl@elt#1#2#3#4{\wlog{#2^^I#1^^I#3^^I#4}}%
2846 \wlog{<*languages>}%
2848 \wlog{</languages>}%
2851 \def\bbl@elt#1#2#3#4{%
2853 \gdef\bbl@nulllanguage{#1}%
2854 \def\bbl@elt##1##2##3##4{}%
2860 % \subsection{Language options}
2862 % \changes{babel~3.6c}{1997/01/05}{When \cs{LdfInit} is undefined we
2863 % need to load \file{babel.def} from \file{babel.sty}}
2864 % \changes{babel~3.6l}{1999/04/03}{Don't load \file{babel.def} now,
2865 % but rather define \cs{LdfInit} temporarily in order to load
2866 % \file{babel.def} at the right time, preventing problems with the
2867 % temporary definition of \cs{bbl@redefine}}
2868 % \changes{babel~3.6r}{1999/04/12}{We \textbf{do} need to load
2869 % \file{babel.def} right now as \cs{ProvidesLanguage} needs to be
2870 % defined before the \file{.ldf} files are read and the reason for
2871 % for 3.6l has been removed}
2872 % \changes{babel~3.9a}{2012/06/15}{Rewritten the loading mechanism, so
2873 % that languages not declared are also correctly recognized, even
2874 % if given as global options}
2875 % \changes{babel~3.9a}{2012/08/12}{Revised the loading mechanism}
2876 % \changes{babel~3.5a}{1995/03/14}{Changed extension of language
2877 % definition files to \texttt{ldf}}
2878 % \changes{babel~3.5d}{1995/07/02}{Load language definition files
2879 % \emph{after} the check for the hyphenation patterns}
2880 % \changes{babel~3.5g}{1996/10/04}{Added option \Lopt{afrikaans}}
2881 % \changes{babel~3.7g}{2001/02/09}{Added option \Lopt{acadian}}
2882 % \changes{babel~3.8c}{2004/06/12}{Added option \Lopt{australian}}
2883 % \changes{babel~3.8h}{2005/11/23}{Added option \Lopt{albanian}}
2884 % \changes{babel~3.6i}{1997/02/20}{Added the \Lopt{Basque} option}
2885 % \changes{babel~3.8h}{2005/11/23}{added synonyms \Lopt{indonesian},
2886 % \Lopt{indon} and \Lopt{bahasai} for the original bahasa
2887 % (indonesia) support}
2888 % \changes{babel~3.8h}{2005/11/23}{added \Lopt{malay}, \Lopt{meyalu}
2889 % and \Lopt{bahasam} for the Bahasa Malaysia support}
2890 % \changes{babel~3.5b}{1995/05/25}{Added \Lopt{brazilian} as
2891 % alternative for \Lopt{brazil}}
2892 % \changes{babel~3.5d}{1995/07/02}{Added \Lopt{british} as an
2893 % alternative for \Lopt{english} with a preference for british
2895 % \changes{babel~3.7f}{2000/09/21}{Added the \Lopt{bulgarian} option}
2896 % \changes{babel~3.7g}{2001/02/07}{Added option \Lopt{canadian}}
2897 % \changes{babel~3.7g}{2001/02/09}{Added option \Lopt{canadien}}
2898 % \changes{babel~3.5b}{1995/06/06}{Added the \Lopt{estonian} option}
2899 % \changes{babel~3.5f}{1996/01/10}{Now use the file \file{frenchb.ldf}
2900 % from Daniel Flipo for french support}
2901 % \changes{babel~3.6e}{1997/01/08}{Added option \Lopt{frenchb} an
2902 % alias for \Lopt{francais}}
2903 % \changes{babel~3.5d}{1995/07/02}{Load \file{french.ldf} when it is
2904 % found instead of \file{frenchb.ldf}}
2905 % \changes{babel~3.7j}{2003/06/07}{\emph{only} load
2906 % \file{frenchb.ldf}}
2907 % \changes{babel~3.5f}{1996/05/31}{Added the \Lopt{greek} option}
2908 % \changes{babel~3.7a}{1997/11/13}{Added the \Lopt{polutonikogreek}
2910 % \changes{babel~3.7c}{1999/04/22}{set the correct language attribute
2911 % for polutoniko greek}
2912 % \changes{babel~3.7a}{1998/03/27}{Added the \Lopt{hebrew} option}
2913 % \changes{babel~3.7b}{1998/06/25}{Added the \Lopt{latin} option}
2914 % \changes{babel~3.7m}{2003/11/13}{Added the \Lopt{interlingua}
2916 % \changes{babel~3.6p}{1999/04/10}{Added the \Lopt{ngerman} and
2917 % \Lopt{naustrian} options}
2918 % \changes{babel~3.7f}{2000/09/26}{Added the \Lopt{samin} option}
2919 % \changes{babel~3.8c}{2004/06/12}{Added the \Lopt{newzealand} option}
2920 % \changes{babel~3.6e}{1997/01/08}{Added options \Lopt{UKenglish} and
2922 % \changes{babel~3.9i}{2014/03/01}{Removed German options, because
2923 % they are now loaded directly}
2924 % \changes{babel~3.9m}{2015/07/28}{Added melayu (meyalu preserved for
2927 % Languages are loaded when processing the corresponding option
2928 % \textit{except} if a |main| language has been set. In such a
2929 % case, it is not loaded until all options has been processed.
2930 % The following macro inputs the ldf file and does some additional
2931 % checks (|\input| works, too, but possible errors are not catched).
2933 \let\bbl@afterlang\relax
2934 \let\BabelModifiers\relax
2935 \let\bbl@loaded\@empty
2936 \def\bbl@load@language#1{%
2937 \InputIfFileExists{#1.ldf}%
2938 {\edef\bbl@loaded{\CurrentOption
2939 \ifx\bbl@loaded\@empty\else,\bbl@loaded\fi}%
2940 \expandafter\let\expandafter\bbl@afterlang
2941 \csname\CurrentOption.ldf-h@@k\endcsname
2942 \expandafter\let\expandafter\BabelModifiers
2943 \csname bbl@mod@\CurrentOption\endcsname}%
2945 Unknown option `\CurrentOption'. Either you misspelled it\\%
2946 or the language definition file \CurrentOption.ldf was not found}{%
2947 Valid options are: shorthands=, KeepShorthandsActive,\\%
2948 activeacute, activegrave, noconfigs, safe=, main=, math=\\%
2949 headfoot=, strings=, config=, hyphenmap=, or a language name.}}}
2951 % Now, we set language options whose names are different from |ldf| files.
2953 \DeclareOption{acadian}{\bbl@load@language{frenchb}}
2954 \DeclareOption{afrikaans}{\bbl@load@language{dutch}}
2955 \DeclareOption{american}{\bbl@load@language{english}}
2956 \DeclareOption{australian}{\bbl@load@language{english}}
2957 \DeclareOption{bahasa}{\bbl@load@language{bahasai}}
2958 \DeclareOption{bahasai}{\bbl@load@language{bahasai}}
2959 \DeclareOption{bahasam}{\bbl@load@language{bahasam}}
2960 \DeclareOption{brazil}{\bbl@load@language{portuges}}
2961 \DeclareOption{brazilian}{\bbl@load@language{portuges}}
2962 \DeclareOption{british}{\bbl@load@language{english}}
2963 \DeclareOption{canadian}{\bbl@load@language{english}}
2964 \DeclareOption{canadien}{\bbl@load@language{frenchb}}
2965 \DeclareOption{francais}{\bbl@load@language{frenchb}}
2966 \DeclareOption{french}{\bbl@load@language{frenchb}}%
2967 \DeclareOption{hebrew}{%
2968 \input{rlbabel.def}%
2969 \bbl@load@language{hebrew}}
2970 \DeclareOption{hungarian}{\bbl@load@language{magyar}}
2971 \DeclareOption{indon}{\bbl@load@language{bahasai}}
2972 \DeclareOption{indonesian}{\bbl@load@language{bahasai}}
2973 \DeclareOption{lowersorbian}{\bbl@load@language{lsorbian}}
2974 \DeclareOption{malay}{\bbl@load@language{bahasam}}
2975 \DeclareOption{meyalu}{\bbl@load@language{bahasam}}
2976 \DeclareOption{melayu}{\bbl@load@language{bahasam}}
2977 \DeclareOption{newzealand}{\bbl@load@language{english}}
2978 \DeclareOption{nynorsk}{\bbl@load@language{norsk}}
2979 \DeclareOption{polutonikogreek}{%
2980 \bbl@load@language{greek}%
2981 \languageattribute{greek}{polutoniko}}
2982 \DeclareOption{portuguese}{\bbl@load@language{portuges}}
2983 \DeclareOption{russian}{\bbl@load@language{russianb}}
2984 \DeclareOption{UKenglish}{\bbl@load@language{english}}
2985 \DeclareOption{ukrainian}{\bbl@load@language{ukraineb}}
2986 \DeclareOption{uppersorbian}{\bbl@load@language{usorbian}}
2987 \DeclareOption{USenglish}{\bbl@load@language{english}}
2990 % Another way to extend the list of `known' options for \babel\ is
2991 % to create the file \file{bblopts.cfg} in which one can add option
2992 % declarations. However, this mechanism is deprecated -- if you
2993 % want an alternative name for a language, just create a new |.ldf|
2994 % file loading the actual one. You can also set the name
2995 % of the file with the package option |config=<name>|, which will
2996 % load |<name>.cfg| instead.
2997 % \changes{babel~3.6i}{1997/03/15}{Added the possibility to have a
2998 % \file{bblopts.cfg} file with option declarations.}
2999 % \changes{babel~3.9a}{2012/06/28}{Added the \cs{AfterBabelLanguage}
3000 % mechanism, to be used mainly with the local cfg file.}
3001 % \changes{babel~3.9a}{2012/06/31}{Now you can set the name of the
3004 \ifx\bbl@opt@config\@nnil
3005 \@ifpackagewith{babel}{noconfigs}{}%
3006 {\InputIfFileExists{bblopts.cfg}%
3007 {\typeout{*************************************^^J%
3008 * Local config file bblopts.cfg used^^J%
3012 \InputIfFileExists{\bbl@opt@config.cfg}%
3013 {\typeout{*************************************^^J%
3014 * Local config file \bbl@opt@config.cfg used^^J%
3017 Local config file `\bbl@opt@config.cfg' not found}{%
3018 Perhaps you misspelled it.}}%
3022 % Recognizing global options in packages not having a closed set of
3023 % them is not trivial, as for them to be processed they must be
3024 % defined explicitly. So, package options not yet taken into
3025 % account and stored in |bbl@language@opts| are assumed to be
3026 % languages (note this list also contains the language given with
3027 % |main|). If not declared above, the name of the option and the
3028 % file are the same.
3030 \bbl@for\bbl@tempa\bbl@language@opts{%
3031 \@ifundefined{ds@\bbl@tempa}%
3033 \noexpand\DeclareOption
3035 {\noexpand\bbl@load@language{\bbl@tempa}}}%
3039 % Now, we make sure an option is explicitly declared for any
3040 % language set as global option, by checking if an |ldf|
3041 % exists. The previous step was, in fact, somewhat redundant, but
3042 % that way we minimize accesing the file system just to see if the
3043 % option could be a language.
3045 \bbl@for\bbl@tempa\@classoptionslist{%
3046 \@ifundefined{ds@\bbl@tempa}%
3047 {\IfFileExists{\bbl@tempa.ldf}%
3049 \noexpand\DeclareOption
3051 {\noexpand\bbl@load@language{\bbl@tempa}}}%
3056 % If a main language has been set, store it for the third pass.
3058 \ifx\bbl@opt@main\@nnil\else
3060 \let\expandafter\bbl@loadmain\csname ds@\bbl@opt@main\endcsname
3061 \DeclareOption{\bbl@opt@main}{}
3064 % And we are done, because all options for this pass has been
3065 % declared. Those already processed in the first pass are just ignored.
3066 % \changes{babel~3.6i}{1997/03/12}{Added default option}
3067 % \changes{babel~3.9a}{2012/12/22}{Default option does nothing}
3069 % The options have to be processed in the order in which the user
3070 % specified them (except, of course, global options, which \LaTeX{}
3071 % processes before):
3073 \def\AfterBabelLanguage#1{%
3074 \bbl@ifsamestring\CurrentOption{#1}{\global\bbl@add\bbl@afterlang}{}}
3078 % This finished the second pass. Now the third one begins, which
3079 % loads the main language set with the key |main|. A warning is
3080 % raised if the main language is not the same as the last named
3081 % one, or if the value of the key |main| is not a language. Then
3082 % execute directly the option (because it could be used only in
3083 % |main|). After loading all languages, we deactivate
3084 % |\AfterBabelLanguage|.
3086 \ifx\bbl@opt@main\@nnil
3087 \edef\bbl@tempa{\@classoptionslist,\bbl@language@opts}
3088 \let\bbl@tempc\@empty
3089 \bbl@for\bbl@tempb\bbl@tempa{%
3090 \@expandtwoargs\in@{,\bbl@tempb,}{,\bbl@loaded,}%
3091 \ifin@\edef\bbl@tempc{\bbl@tempb}\fi}
3092 \def\bbl@tempa#1,#2\@nnil{\def\bbl@tempb{#1}}
3093 \expandafter\bbl@tempa\bbl@loaded,\@nnil
3094 \ifx\bbl@tempb\bbl@tempc\else
3096 Last declared language option is `\bbl@tempc',\\%
3097 but the last processed one was `\bbl@tempb'.\\%
3098 The main language cannot be set as both a global\\%
3099 and a package option. Use `main=\bbl@tempc' as\\%
3103 \DeclareOption{\bbl@opt@main}{\bbl@loadmain}
3104 \ExecuteOptions{\bbl@opt@main}
3108 \def\AfterBabelLanguage{%
3110 {Too late for \string\AfterBabelLanguage}%
3111 {Languages have been loaded, so I can do nothing}}
3113 % \changes{babel~3.7c}{1999/03/13}{Added an error message for when no
3114 % language option was specified}
3115 % In order to catch the case where the user forgot to specify a
3116 % language we check whether |\bbl@main@language|, has become
3117 % defined. If not, no language has been loaded and an error
3118 % message is displayed.
3119 % \changes{babel~3.7c}{1999/04/09}{No longer us a redefinition of an
3120 % internal macro, just check \cs{bbl@main@language} and load
3122 % \changes{babel~3.9a}{2012/06/24}{Now babel is not loaded to prevent
3123 % the document from raising errors after fixing it}
3125 \ifx\bbl@main@language\@undefined
3127 You haven't specified a language option}{%
3128 You need to specify a language, either as a global option\\%
3129 or as an optional argument to the \string\usepackage\space
3131 You shouldn't try to proceed from here, type x to quit.}
3136 % \section{The kernel of Babel (common)}
3138 % The kernel of the \babel\ system is stored in either
3139 % \file{hyphen.cfg} or \file{switch.def} and \file{babel.def}. The
3140 % file \file{babel.def} contains most of the code, while
3141 % \file{switch.def} defines the language switching commands; both
3142 % can be read at run time. The file \file{hyphen.cfg} is a file
3143 % that can be loaded into the format, which is necessary when you
3144 % want to be able to switch hyphenation patterns (by default, it
3145 % also inputs \file{switch.def}, for ``historical reasons'', but it
3146 % is not necessary). When \file{babel.def} is loaded it checks if
3147 % the current version of \file{switch.def} is in the format; if not
3148 % it is loaded. A further file, \file{babel.sty}, contains
3149 % \LaTeX-specific stuff.
3151 % Because plain \TeX\ users might want to use some of the features
3152 % of the \babel{} system too, care has to be taken that plain \TeX\
3153 % can process the files. For this reason the current format will
3154 % have to be checked in a number of places. Some of the code below
3155 % is common to plain \TeX\ and \LaTeX, some of it is for the
3156 % \LaTeX\ case only.
3158 % Plain formats based on etex (etex, xetex, luatex) don't load
3159 % |hyphen.cfg| but |etex.src|, which follows a different naming
3160 % convention, so we need to define the babel names. It presumes
3161 % |language.def| exists and it is the same file used when
3162 % formats were created.
3164 % \changes{babel~3.9a}{2013/01/11}{Added \cs{bbl@for} for loops
3166 % \changes{babel~3.9c}{2013/04/06}{Normalize \cs{bbl@afterlang} to
3168 % \changes{babel~3.9i}{2014/03/10}{Make sure \cs{bbl@language@opts}
3170 % \changes{babel~3.9i}{2014/03/11}{Define \cs{l@} values from
3171 % \cs{lang@} values set in Plain etex/xetex/luatex}
3173 % \subsection{Tools}
3175 % |\bbl@engine| takes the following values: 0 is pdf\TeX, 1 is
3176 % \luatex, and 2 is \xetex. You may use it in your language style
3179 % \changes{babel~3.9k}{2014/03/24}{Added definition for
3181 % \changes{babel~3.9n}{2015/12/21}{Define a few macros for 2.09}
3185 <@Make sure ProvidesFile is defined@>
3186 \ProvidesFile{babel.def}[<@date@> <@version@> Babel common definitions]
3187 <@Load macros for plain if not LaTeX@>
3188 \ifx\bbl@ifshorthand\@undefined
3189 \def\bbl@ifshorthand#1#2#3{#2}%
3190 \def\bbl@opt@safe{BR}
3191 \def\AfterBabelLanguage#1#2{}
3192 \let\bbl@afterlang\relax
3193 \let\bbl@language@opts\@empty
3195 <@Load switch if newer@>
3196 \ifx\bbl@languages\@undefined
3197 \openin1 = language.def
3200 \message{I couldn't find the file language.def}
3204 \def\addlanguage#1#2#3#4#5{%
3205 \expandafter\ifx\csname lang@#1\endcsname\relax\else
3206 \global\expandafter\let\csname l@#1\expandafter\endcsname
3207 \csname lang@#1\endcsname
3209 \def\uselanguage#1{}%
3213 \chardef\l@english\z@
3216 \def\bbl@csarg#1#2{\expandafter#1\csname bbl@#2\endcsname}%
3217 \chardef\bbl@engine=%
3218 \ifx\directlua\@undefined
3219 \ifx\XeTeXinputencoding\@undefined
3229 % \begin{macro}{\bbl@afterelse}
3230 % \begin{macro}{\bbl@afterfi}
3231 % Because the code that is used in the handling of active
3232 % characters may need to look ahead, we take extra care to `throw'
3233 % it over the |\else| and |\fi| parts of an
3234 % |\if|-statement\footnote{This code is based on code presented in
3235 % TUGboat vol. 12, no2, June 1991 in ``An expansion Power Lemma''
3236 % by Sonja Maus.}. These macros will break if another |\if...\fi|
3237 % statement appears in one of the arguments and it is not enclosed
3239 % \changes{babel~3.6i}{1997/02/20}{Made \cs{bbl@afterelse} and
3240 % \cs{bbl@afterfi} \cs{long}}
3242 \long\def\bbl@afterelse#1\else#2\fi{\fi#1}
3243 \long\def\bbl@afterfi#1\fi{\fi#1}
3248 % \begin{macro}{\addto}
3249 % For each language four control sequences have to be defined that
3250 % control the language-specific definitions. To be able to add
3251 % something to these macro once they have been defined the macro
3252 % |\addto| is introduced. It takes two arguments, a \meta{control
3253 % sequence} and \TeX-code to be added to the \meta{control
3256 % If the \meta{control sequence} has not been defined before it is
3257 % defined now. The control sequence could also expand to |\relax|,
3258 % in which case a circular definition results. The net result is a
3259 % stack overflow. Otherwise the replacement text for the
3260 % \meta{control sequence} is expanded and stored in a token
3261 % register, together with the \TeX-code to be added. Finally the
3262 % \meta{control sequence} is \emph{re}defined, using the contents
3263 % of the token register.
3265 % \changes{babel~3.1}{1991/11/05}{Added macro}
3266 % \changes{babel~3.4}{1994/02/04}{Changed to use toks register}
3267 % \changes{babel~3.6b}{1996/12/30}{Also check if control sequence
3268 % expands to \cs{relax}}
3277 {\toks@\expandafter{#1#2}%
3278 \xdef#1{\the\toks@}}%
3284 % \changes{babel~3.9a}{2012/08/10}{Removed the \cs{peek@token} and
3285 % \textsc{test@token} stuff}
3286 % The macro |\initiate@active@char| takes all the necessary actions
3287 % to make its argument a shorthand character. The real work is
3288 % performed once for each character.
3289 % \changes{babel~3.7c}{1999/04/30}{Only execute
3290 % \cs{initiate@active@char} once for each character}
3291 % \changes{babel~3.9a}{1999/04/30}{Added \cs{bbl@withactive}}
3293 \def\bbl@withactive#1#2{%
3296 \lowercase{\endgroup#1~}}
3300 % \begin{macro}{\bbl@redefine}
3301 % \changes{babel~3.5f}{1995/11/15}{Macro added}
3302 % To redefine a command, we save the old meaning of the macro.
3303 % Then we redefine it to call the original macro with the
3304 % `sanitized' argument. The reason why we do it this way is that
3305 % we don't want to redefine the \LaTeX\ macros completely in case
3306 % their definitions change (they have changed in the past).
3308 % Because we need to redefine a number of commands we define the
3309 % command |\bbl@redefine| which takes care of this. It creates a
3310 % new control sequence, |\org@...|
3312 \def\bbl@redefine#1{%
3313 \edef\bbl@tempa{\expandafter\@gobble\string#1}%
3314 \expandafter\let\csname org@\bbl@tempa\endcsname#1%
3315 \expandafter\def\csname\bbl@tempa\endcsname}
3318 % This command should only be used in the preamble of the document.
3320 \@onlypreamble\bbl@redefine
3324 % \begin{macro}{\bbl@redefine@long}
3325 % \changes{babel~3.6f}{1997/01/14}{Macro added}
3326 % This version of |\babel@redefine| can be used to redefine |\long|
3327 % commands such as |\ifthenelse|.
3329 \def\bbl@redefine@long#1{%
3330 \edef\bbl@tempa{\expandafter\@gobble\string#1}%
3331 \expandafter\let\csname org@\bbl@tempa\endcsname#1%
3332 \expandafter\long\expandafter\def\csname\bbl@tempa\endcsname}
3333 \@onlypreamble\bbl@redefine@long
3337 % \begin{macro}{\bbl@redefinerobust}
3338 % \changes{babel~3.5f}{1995/11/15}{Macro added}
3339 % \changes{babel~3.5f}{1996/04/09}{Define \cs*{foo } instead of
3341 % For commands that are redefined, but which \textit{might} be
3342 % robust we need a slightly more intelligent macro. A robust
3343 % command |foo| is defined to expand to |\protect|\verb*|\foo |. So
3344 % it is necessary to check whether \verb*|\foo | exists. The result
3345 % is that the command that is being redefined is always robust
3346 % afterwards. Therefore all we need to do now is define \verb*|\foo |.
3348 \def\bbl@redefinerobust#1{%
3349 \edef\bbl@tempa{\expandafter\@gobble\string#1}%
3350 \expandafter\ifx\csname\bbl@tempa\space\endcsname\relax
3351 \expandafter\let\csname org@\bbl@tempa\endcsname#1%
3352 \expandafter\edef\csname\bbl@tempa\endcsname{\noexpand\protect
3353 \expandafter\noexpand\csname\bbl@tempa\space\endcsname}%
3355 \expandafter\let\csname org@\bbl@tempa\expandafter\endcsname
3356 \csname\bbl@tempa\space\endcsname
3358 \expandafter\def\csname\bbl@tempa\space\endcsname}
3361 % This command should only be used in the preamble of the document.
3363 \@onlypreamble\bbl@redefinerobust
3367 % \subsection{Hooks}
3369 % Note they are loaded in babel.def. switch.def only provides a
3370 % ``hook'' for hooks (with a default value which is a no-op,
3371 % below). Admittedly, the current implementation is a somewhat
3372 % simplistic and does vety little to catch errors, but it is intended
3373 % for developpers, after all. |\bbl@usehooks| is the commands used by
3374 % babel to execute hooks defined for an event.
3375 % \changes{babel~3.9k}{2014/03/23}{Removed a \cs{newcommand},
3376 % undefined in Plain}
3379 \def\AddBabelHook#1#2{%
3380 \@ifundefined{bbl@hk@#1}{\EnableBabelHook{#1}}{}%
3381 \def\bbl@tempa##1,#2=##2,##3\@empty{\def\bbl@tempb{##2}}%
3382 \expandafter\bbl@tempa\bbl@evargs,#2=,\@empty
3383 \@ifundefined{bbl@ev@#1@#2}%
3384 {\bbl@csarg\bbl@add{ev@#2}{\bbl@elt{#1}}%
3385 \bbl@csarg\newcommand}%
3386 {\bbl@csarg\let{ev@#1@#2}\relax
3387 \bbl@csarg\newcommand}%
3388 {ev@#1@#2}[\bbl@tempb]}
3389 \def\EnableBabelHook#1{\bbl@csarg\let{hk@#1}\@firstofone}
3390 \def\DisableBabelHook#1{\bbl@csarg\let{hk@#1}\@gobble}
3391 \def\bbl@usehooks#1#2{%
3393 \@nameuse{bbl@hk@##1}{\@nameuse{bbl@ev@##1@#1}#2}}%
3394 \@nameuse{bbl@ev@#1}}
3396 % To ensure forward compatibility, arguments in hooks are set
3397 % implicitly. So, if a further argument is added in the future,
3398 % there is no need to change the existing code. Note events
3399 % intended for \textsf{hyphen.cfg} are also loaded (just in
3400 % case you need them for some reason).
3402 \def\bbl@evargs{,% don't delete the comma
3403 everylanguage=1,loadkernel=1,loadpatterns=1,loadexceptions=1,%
3404 adddialect=2,patterns=2,defaultcommands=0,encodedcommands=2,write=0,%
3405 beforeextras=0,afterextras=0,stopcommands=0,stringprocess=0,%
3406 hyphenation=2,initiateactive=3,afterreset=0}
3409 % \begin{macro}{\babelensure}
3411 % The user command just parses the optional argument and creates a
3412 % new macro named |\bbl@ens@|\m{language}. We register a hook at the
3413 % |afterextras| event which just executes this macro in a
3414 % ``complete'' selection (which, if undefined, is |\relax| and does
3415 % nothing). This part is somewhat involved because we have to make
3416 % sure things are expanded the correct number of times.
3418 % The macro |\bbl@ens@|\m{language} contains
3419 % |\bbl@ensure|\marg{include}\marg{exclude}\marg{fontenc}, which
3420 % in turn loops over the macros names in |\bbl@ensured|, excluding
3421 % (with the help of |\in@|) those in the |exclude| list. If the
3422 % |fontenc| is given (and not |\relax|), the |\fontencoding| is
3423 % also added. Then we loop over the |include| list, but if the
3424 % macro already contains |\foreignlanguage|, nothing is done.
3425 % Note this macro (1) is not restricted to the preamble, and (2)
3426 % changes are local.
3428 % |\bbl@ensured| is the list of macros supposed to be ``ensured''.
3429 % \changes{babel~3.9i}{2014/02/14}{Macro \cs{babelensure} added}
3430 % \changes{babel~3.9k}{2014/03/23}{Encapsulate \cs{foreignlanguage} in
3431 % \cs{bbl@ensure@}language, to "protect" strings}
3434 \newcommand\babelensure[2][]{%
3435 \AddBabelHook{babel-ensure}{afterextras}{%
3436 \ifcase\bbl@select@type
3437 \@nameuse{bbl@e@\languagename}%
3440 \let\bbl@ens@include\@empty
3441 \let\bbl@ens@exclude\@empty
3442 \def\bbl@ens@fontenc{\relax}%
3444 \ifx\@empty##1\else\noexpand##1\expandafter\bbl@tempb\fi}%
3445 \edef\bbl@tempa{\bbl@tempb#1\@empty}%
3446 \def\bbl@tempb##1=##2\@@{\@namedef{bbl@ens@##1}{##2}}%
3447 \bbl@for\bbl@tempa\bbl@tempa{\expandafter\bbl@tempb\bbl@tempa\@@}%
3448 \def\bbl@tempc{\bbl@ensure}%
3449 \expandafter\bbl@add\expandafter\bbl@tempc\expandafter{%
3450 \expandafter{\bbl@ens@include}}%
3451 \expandafter\bbl@add\expandafter\bbl@tempc\expandafter{%
3452 \expandafter{\bbl@ens@exclude}}%
3453 \toks@\expandafter{\bbl@tempc}%
3456 \noexpand\@namedef{bbl@e@#2}{\the\toks@{\bbl@ens@fontenc}}}%
3458 \def\bbl@ensure#1#2#3{%
3459 \def\bbl@tempb##1{% elt for \bbl@ensured list
3463 \toks@\expandafter{##1}%
3465 \noexpand\DeclareRobustCommand
3466 \bbl@csarg\noexpand{ensure@\languagename}[1]{%
3467 \noexpand\foreignlanguage{\languagename}%
3469 \noexpand\fontencoding{#3}\noexpand\selectfont
3474 \bbl@csarg\noexpand{ensure@\languagename}%
3477 \expandafter\bbl@tempb
3479 \expandafter\bbl@tempb\bbl@ensured\@empty
3480 \def\bbl@tempa##1{% elt for include list
3482 \bbl@csarg\in@{ensure@\languagename\expandafter}\expandafter{##1}%
3484 \bbl@tempb##1\@empty
3486 \expandafter\bbl@tempa
3488 \bbl@tempa#1\@empty}
3490 \prefacename\refname\abstractname\bibname\chaptername\appendixname
3491 \contentsname\listfigurename\listtablename\indexname\figurename
3492 \tablename\partname\enclname\ccname\headtoname\pagename\seename
3493 \alsoname\proofname\glossaryname\today}
3497 % \subsection{Setting up language files}
3499 % \begin{macro}{\LdfInit}
3500 % The second version of |\LdfInit| macro takes two arguments. The first
3501 % argument is the name of the language that will be defined in the
3502 % language definition file; the second argument is either a control
3503 % sequence or a string from which a control sequence should be
3504 % constructed. The existence of the control sequence indicates that
3505 % the file has been processed before.
3507 % At the start of processing a language definition file we always
3508 % check the category code of the at-sign. We make sure that it is
3509 % a `letter' during the processing of the file. We also save its
3510 % name as the last called option, even if not loaded.
3512 % Another character that needs to have the correct category code
3513 % during processing of language definition files is the equals sign,
3514 % `=', because it is sometimes used in constructions with the
3515 % |\let| primitive. Therefore we store its current catcode and
3516 % restore it later on.
3517 % \changes{babel~3.7o}{2003/11/26}{make sure the equals sign has its
3518 % default category code}
3520 % Now we check whether we should perhaps stop the processing of
3521 % this file. To do this we first need to check whether the second
3522 % argument that is passed to |\LdfInit| is a control sequence. We
3523 % do that by looking at the first token after passing |#2| through
3524 % |string|. When it is equal to |\@backslashchar| we are dealing
3525 % with a control sequence which we can compare with |\@undefined|.
3527 % \changes{babel~3.9a}{2012/08/11}{\cs{ldf@quit} is not delayed any
3528 % more after \cs{fi} , since \cs{endinput} is not executed
3530 % \changes{babel~3.9g}{2012/08/11}{Preset the ``family'' of macros
3532 % If so, we call |\ldf@quit| to set the main language, restore the
3533 % category code of the @-sign and call |\endinput|
3535 % When |#2| was \emph{not} a control sequence we construct one and
3536 % compare it with |\relax|.
3538 % Finally we check |\originalTeX|.
3541 \chardef\atcatcode=\catcode`\@
3542 \catcode`\@=11\relax
3543 \chardef\eqcatcode=\catcode`\=
3544 \catcode`\==12\relax
3545 \expandafter\if\expandafter\@backslashchar
3546 \expandafter\@car\string#2\@nil
3547 \ifx#2\@undefined\else
3551 \expandafter\ifx\csname#2\endcsname\relax\else
3555 \let\bbl@screset\@empty
3556 \let\BabelStrings\bbl@opt@strings
3557 \let\BabelOptions\@empty
3558 \let\BabelLanguages\relax
3559 \ifx\originalTeX\@undefined
3560 \let\originalTeX\@empty
3567 % \begin{macro}{\ldf@quit}
3568 % \changes{babel~3.6a}{1996/10/29}{Macro added}
3569 % This macro interrupts the processing of a language definition file.
3570 % \changes{babel~3.7o}{2003/11/26}{Also restore the category code of
3574 \expandafter\main@language\expandafter{#1}%
3575 \catcode`\@=\atcatcode \let\atcatcode\relax
3576 \catcode`\==\eqcatcode \let\eqcatcode\relax
3581 % \begin{macro}{\ldf@finish}
3582 % \changes{babel~3.6a}{1996/10/16}{Macro added}
3583 % This macro takes one argument. It is the name of the language
3584 % that was defined in the language definition file.
3586 % We load the local configuration file if one is present, we set
3587 % the main language (taking into account that the argument might be
3588 % a control sequence that needs to be expanded) and reset the
3589 % category code of the @-sign.
3590 % \changes{babel~3.7o}{2003/11/26}{Also restore the category code of
3592 % \changes{babel~3.9a}{2012/10/01}{Added \cs{bbl@afterlang} which
3593 % executes the code delayed with \cs{AfterBabelLanguage}}
3598 \let\bbl@afterlang\relax
3599 \let\BabelModifiers\relax
3600 \let\bbl@screset\relax
3601 \expandafter\main@language\expandafter{#1}%
3602 \catcode`\@=\atcatcode \let\atcatcode\relax
3603 \catcode`\==\eqcatcode \let\eqcatcode\relax}
3607 % After the preamble of the document the commands |\LdfInit|,
3608 % |\ldf@quit| and |\ldf@finish| are no longer needed. Therefore
3609 % they are turned into warning messages in \LaTeX.
3611 \@onlypreamble\LdfInit
3612 \@onlypreamble\ldf@quit
3613 \@onlypreamble\ldf@finish
3616 % \begin{macro}{\main@language}
3617 % \changes{babel~3.5a}{1995/02/17}{Macro added}
3618 % \changes{babel~3.6a}{1996/10/16}{\cs{main@language} now also sets
3619 % \cs{languagename} and \cs{l@languagename} for use by other
3620 % packages in the preamble of a document}
3621 % \begin{macro}{\bbl@main@language}
3622 % \changes{babel~3.5a}{1995/02/17}{Macro added}
3623 % This command should be used in the various language definition
3624 % files. It stores its argument in |\bbl@main@language|; to be used
3625 % to switch to the correct language at the beginning of the
3627 % \changes{babel~3.8l}{2008/07/06}{Use \cs{bbl@patterns}}
3629 \def\main@language#1{%
3630 \def\bbl@main@language{#1}%
3631 \let\languagename\bbl@main@language
3632 \bbl@patterns{\languagename}}
3635 % We also have to make sure that some code gets executed at the
3636 % beginning of the document.
3639 \expandafter\selectlanguage\expandafter{\bbl@main@language}}
3644 % \subsection{Shorthands}
3646 % \begin{macro}{\bbl@add@special}
3647 % \changes{babel~3.2}{1991/11/10}{Added macro}
3648 % The macro |\bbl@add@special| is used to add a new character (or
3649 % single character control sequence) to the macro |\dospecials|
3650 % (and |\@sanitize| if \LaTeX\ is used).
3652 % To keep all changes local, we begin a new group. Then we
3653 % redefine the macros |\do| and |\@makeother| to add themselves and
3654 % the given character without expansion.
3656 % To add the character to the macros, we expand the original macros
3657 % with the additional character inside the redefinition of the
3658 % macros. Because |\@sanitize| can be undefined, we put the
3659 % definition inside a conditional.
3661 \def\bbl@add@special#1{%
3663 \def\do{\noexpand\do\noexpand}%
3664 \def\@makeother{\noexpand\@makeother\noexpand}%
3666 \def\noexpand\dospecials{\dospecials\do#1}%
3667 \expandafter\ifx\csname @sanitize\endcsname\relax \else
3668 \def\noexpand\@sanitize{\@sanitize\@makeother#1}%
3672 % The macro |\x| contains at this moment the following:\\
3673 % |\endgroup\def\dospecials{|\textit{old contents}%
3674 % |\do|\meta{char}|}|.\\
3675 % If |\@sanitize| is defined, it contains an additional definition
3676 % of this macro. The last thing we have to do, is the expansion of
3677 % |\x|. Then |\endgroup| is executed, which restores the old
3678 % meaning of |\x|, |\do| and |\@makeother|. After the group is
3679 % closed, the new definition of |\dospecials| (and |\@sanitize|) is
3684 % \begin{macro}{\bbl@remove@special}
3685 % \changes{babel~3.2}{1991/11/10}{Added macro}
3686 % The companion of the former macro is |\bbl@remove@special|. It
3687 % is used to remove a character from the set macros |\dospecials|
3690 % To keep all changes local, we begin a new group. Then we define
3691 % a help macro |\x|, which expands to empty if the characters
3692 % match, otherwise it expands to its nonexpandable input. Because
3693 % \TeX\ inserts a |\relax|, if the corresponding |\else| or |\fi|
3694 % is scanned before the comparison is evaluated, we provide a `stop
3695 % sign' which should expand to nothing.
3697 % With the help of this macro we define |\do| and |\make@other|.
3699 % The rest of the work is similar to |\bbl@add@special|.
3701 \def\bbl@remove@special#1{%
3703 \def\x##1##2{\ifnum`#1=`##2\noexpand\@empty
3704 \else\noexpand##1\noexpand##2\fi}%
3706 \def\@makeother{\x\@makeother}%
3708 \def\noexpand\dospecials{\dospecials}%
3709 \expandafter\ifx\csname @sanitize\endcsname\relax \else
3710 \def\noexpand\@sanitize{\@sanitize}%
3717 % \begin{macro}{\initiate@active@char}
3718 % \changes{babel~3.5a}{1995/02/11}{Added macro}
3719 % \changes{babel~3.5b}{1995/03/03}{Renamed macro}
3720 % A language definition file can call this macro to make a
3721 % character active. This macro takes one argument, the character
3722 % that is to be made active. When the character was already active
3723 % this macro does nothing. Otherwise, this macro defines the
3724 % control sequence |\normal@char|\m{char} to expand to the
3725 % character in its `normal state' and it defines the active
3726 % character to expand to |\normal@char|\m{char} by default
3727 % (\m{char} being the character to be made active). Later its
3728 % definition can be changed to expand to |\active@char|\m{char}
3729 % by calling |\bbl@activate{|\m{char}|}|.
3731 % For example, to make the double quote character active one could
3732 % have |\initiate@active@char{"}| in a language definition file.
3733 % This defines |"| as |\active@prefix "\active@char"| (where the
3734 % first |"| is the character with its original catcode, when the
3735 % shorthand is created, and |\active@char"| is a single token). In
3736 % protected contexts, it expands to |\protect "| or |\noexpand "|
3737 % (ie, with the original |"|); otherwise |\active@char"| is
3738 % executed. This macro in turn expands to |\normal@char"| in
3739 % ``safe'' contexts (eg, |\label|), but |\user@active"| in normal
3740 % ``unsafe'' ones. The latter search a definition in the user,
3741 % language and system levels, in this order, but if none is found,
3742 % |\normal@char"| is used. However, a deactivated shorthand (with
3743 % |\bbl@deactivate| is defined as |\active@prefix "\normal@char"|.
3745 % The following macro is used to define shorthands in the three
3746 % levels. It takes 4 arguments: the (string'ed) character,
3747 % |\<level>@group|, |<level>@active| and |<next-level>@active|
3748 % (except in |system|).
3749 % \changes{babel~3.9a}{2012/08/18}{New macro, with code from
3750 % \cs{@initiate@active@char}}
3752 \def\bbl@active@def#1#2#3#4{%
3754 \expandafter\ifx\csname#2@sh@#1@\endcsname\relax
3755 \bbl@afterelse\bbl@sh@select#2#1{#3@arg#1}{#4#1}%
3757 \bbl@afterfi\csname#2@sh@#1@\endcsname
3760 % When there is also no current-level shorthand with an argument we
3761 % will check whether there is a next-level defined shorthand for
3762 % this active character.
3763 % \changes{babel~3.7e}{1999/09/24}{pass the argument on with braces in
3764 % order to prevent it from breaking up}
3765 % \changes{babel~3.7f}{2000/02/18}{remove the braces again}
3767 \long\@namedef{#3@arg#1}##1{%
3768 \expandafter\ifx\csname#2@sh@#1@\string##1@\endcsname\relax
3769 \bbl@afterelse\csname#4#1\endcsname##1%
3771 \bbl@afterfi\csname#2@sh@#1@\string##1@\endcsname
3774 % \changes{babel~3.9a}{2012/08/18}{Removed an extra hash. Now calls
3775 % \cs{@initiate@active@char} with 3 arguments.}
3776 % |\initiate@active@char| calls |\@initiate@active@char| with 3
3777 % arguments. All of them are the same character with different
3778 % catcodes: active, other (string'ed) and the original one.
3780 \def\initiate@active@char#1{%
3781 \expandafter\ifx\csname active@char\string#1\endcsname\relax
3783 {\expandafter\@initiate@active@char\expandafter}#1\string#1#1%
3786 % \changes{babel~3.9e}{2012/08/18}{Introduced the 3-argument
3787 % \cs{@initiate@active@char}, with different catcodes: active,
3788 % string'ed, and original. Reorganized}
3789 % \changes{babel~3.9a}{2012/08/19}{The catcode is saved}
3790 % \changes{babel~3.9a}{2012/09/09}{The original definition is saved,
3792 % \changes{babel~3.9a}{2012/12/27}{Take into account mathematically
3793 % active chars, to avoid infinite loops}
3794 % The very first thing to do is saving the original catcode and the
3795 % original definition, even if not active, which is possible
3796 % (undefined characters require a special treatement to avoid
3797 % making them |\relax|).
3799 \def\@initiate@active@char#1#2#3{%
3800 \expandafter\edef\csname bbl@oricat@#2\endcsname{%
3801 \catcode`#2=\the\catcode`#2\relax}%
3803 \expandafter\edef\csname bbl@oridef@#2\endcsname{%
3804 \let\noexpand#1\noexpand\@undefined}%
3806 \expandafter\let\csname bbl@oridef@@#2\endcsname#1%
3807 \expandafter\edef\csname bbl@oridef@#2\endcsname{%
3809 \expandafter\noexpand\csname bbl@oridef@@#2\endcsname}%
3812 % If the character is already active we provide the default
3813 % expansion under this shorthand mechanism. Otherwise we write a
3814 % message in the transcript file, and define |\normal@char|\m{char}
3815 % to expand to the character in its default state. If the character
3816 % is mathematically active when \babel{} is loaded (for example
3817 % |'|) the normal expansion is somewhat different to avoid an
3818 % infinite loop (but it does not prevent the loop if the mathcode
3819 % is set to |"8000| \textit{a posteriori}).
3822 \expandafter\let\csname normal@char#2\endcsname#3%
3824 \bbl@info{Making #2 an active character}%
3825 \ifnum\mathcode`#2="8000
3826 \@namedef{normal@char#2}{%
3827 \textormath{#3}{\csname bbl@oridef@@#2\endcsname}}%
3829 \@namedef{normal@char#2}{#3}%
3832 % To prevent problems with the loading of other packages after
3833 % \babel\ we reset the catcode of the character to the original one
3834 % at the end of the package and of each language file (except with
3835 % \textsf{KeepShorthandsActive}). It is re-activate again at
3836 % |\begin{document}|. We also need to make sure that the
3837 % shorthands are active during the processing of the \file{.aux}
3838 % file. Otherwise some citations may give unexpected results in
3839 % the printout when a shorthand was used in the optional argument
3840 % of |\bibitem| for example.
3841 % \changes{babel~3.6i}{1997/03/01}{Make shorthands active during
3842 % \file{.aux} file processing}. Then we
3843 % make it active (not strictly necessary, but done for backward
3845 % \changes{babel~3.5f}{1995/12/01}{Restore the category code of a
3846 % shorthand char at end of package}
3847 % \changes{babel~3.6f}{1997/01/14}{Made restoring of the category code
3848 % of shorthand characters optional}
3849 % \changes{babel~3.7a}{1997/03/21}{Use \cs{@ifpackagewith} to
3850 % determine whether shorthand characters need to remain active}
3852 \bbl@restoreactive{#2}%
3856 \immediate\write\@mainaux{\catcode`\string#2\active}%
3858 \expandafter\bbl@add@special\csname#2\endcsname
3862 % Now we have set |\normal@char|\m{char}, we must define
3863 % |\active@char|\m{char}, to be executed when the character is
3864 % activated. We define the first level expansion of
3865 % |\active@char|\m{char} to check the status of the |@safe@actives|
3866 % flag. If it is set to true we expand to the `normal' version of
3867 % this character, otherwise we call |\user@active|\m{char} to start
3868 % the search of a definition in the user, language and system
3869 % levels (or eventually |normal@char|\m{char}).
3870 % \changes{babel~3.9a}{2012/12/27}{Added code for option math=normal}
3871 % \changes{babel~3.9i}{2014/02/03}{Don't call directly
3872 % \cs{user@active}, but with an intermediate step}
3874 \let\bbl@tempa\@firstoftwo
3876 \def\bbl@tempa{\noexpand\textormath}%
3878 \ifx\bbl@mathnormal\@undefined\else
3879 \let\bbl@tempa\bbl@mathnormal
3882 \expandafter\edef\csname active@char#2\endcsname{%
3884 {\noexpand\if@safe@actives
3885 \noexpand\expandafter
3886 \expandafter\noexpand\csname normal@char#2\endcsname
3888 \noexpand\expandafter
3889 \expandafter\noexpand\csname bbl@doactive#2\endcsname
3891 {\expandafter\noexpand\csname normal@char#2\endcsname}}%
3892 \bbl@csarg\edef{doactive#2}{%
3893 \expandafter\noexpand\csname user@active#2\endcsname}%
3896 % \changes{babel~3.9a}{2012/12/27}{Shorthands are not defined
3897 % directly, but with a couple of intermediate macros}
3899 % We now define the default values which the shorthand is set to
3900 % when activated or deactivated. It is set to the deactivated form
3901 % (globally), so that the character expands to
3903 % |\active@prefix| \m{char} |\normal@char|\m{char}
3905 % (where |\active@char|\m{char} is \emph{one} control sequence!).
3908 \bbl@csarg\edef{active@#2}{%
3909 \noexpand\active@prefix\noexpand#1%
3910 \expandafter\noexpand\csname active@char#2\endcsname}%
3911 \bbl@csarg\edef{normal@#2}{%
3912 \noexpand\active@prefix\noexpand#1%
3913 \expandafter\noexpand\csname normal@char#2\endcsname}%
3914 \expandafter\let\expandafter#1\csname bbl@normal@#2\endcsname
3916 % The next level of the code checks whether a user has defined a
3917 % shorthand for himself with this character. First we check for a
3918 % single character shorthand. If that doesn't exist we check for a
3919 % shorthand with an argument.
3920 % \changes{babel~3.5d}{1995/07/02}{Skip the user-level active char
3921 % with argument if no shorthands with arguments were defined}
3922 % \changes{babel~3.8b}{2004/04/19}{Now use \cs{bbl@sh@select}}
3923 % \changes{babel~3.9a}{2012/08/18}{Instead of the ``copy-paste pattern''
3924 % a new macro is used}
3926 \bbl@active@def#2\user@group{user@active}{language@active}%
3927 \bbl@active@def#2\language@group{language@active}{system@active}%
3928 \bbl@active@def#2\system@group{system@active}{normal@char}%
3930 % In order to do the right thing when a shorthand with an argument
3931 % is used by itself at the end of the line we provide a definition
3932 % for the case of an empty argument. For that case we let the
3933 % shorthand character expand to its non-active self. Also, When a
3934 % shorthand combination such as |''| ends up in a heading \TeX\
3935 % would see |\protect'\protect'|. To prevent this from happening a
3936 % couple of shorthand needs to be defined at user level.
3937 % \changes{babel~3.7f}{1999/12/09}{Added an extra shorthand
3938 % combination on user level to catch an interfering \cs{protect}}
3939 % \changes{babel~3.9a}{2012/8/18}{Use \cs{user@group}, as above,
3940 % instead of the hardwired \texttt{user}}
3942 \expandafter\edef\csname\user@group @sh@#2@@\endcsname
3943 {\expandafter\noexpand\csname normal@char#2\endcsname}%
3944 \expandafter\edef\csname\user@group @sh@#2@\string\protect@\endcsname
3945 {\expandafter\noexpand\csname user@active#2\endcsname}%
3947 % Finally, a couple of special cases are taken care of. (1) If we
3948 % are making the right quote (|'|) active we need to change |\pr@m@s| as
3949 % well. Also, make sure that a single |'| in math mode `does the
3950 % right thing'. (2) If we are using the caret (|^|) as a shorthand
3951 % character special care should be taken to make sure math still
3952 % works. Therefore an extra level of expansion is introduced with a
3953 % check for math mode on the upper level.
3955 % \changes{babel~3.7f}{1999/12/18}{Insert a check for math mode in
3956 % the definition of \cs{normal@char'}}
3957 % \changes{babel~3.7g}{2000/10/02}{use \cs{textormath} to get rid
3958 % of the \cs{fi} (PR 3266)}
3959 % \changes{babel~3.7f}{1999/12/18}{The redefinition needs to take
3960 % place one level higher, \cs{prim@s} needs to be redefined.}
3961 % \changes{babel~3.7f}{1999/12/18}{Introduced an extra
3962 % level of expansion in the definition of an active caret}
3963 % \changes{babel~3.7f}{2000/09/25}{Make an exception for the active
3964 % caret which needs an extra level of expansion}
3965 % \changes{babel~3.9a}{2012/09/11}{The output routine resets the quote
3966 % to \cs{active@math@prime}, so we redefine the latter with the new
3968 % \changes{babel~3.9a}{2012/06/20}{Added a couple of missing
3969 % comment characters (PR 4146)}
3970 % \changes{babel~3.9a}{2012/07/29}{Use \cs{textormath} instead of
3972 % \changes{babel~3.9a}{2012/11/26}{Compare the char, irrespective of
3974 % \changes{babel~3.9a}{2012/12/27}{Removed the redeclaration of
3975 % \cs{normal@char'} because it is handled in a generic way above}
3976 % \changes{babel~3.9a}{2012/12/29}{Removed the intermediate step of
3977 % \cs{bbl@act@caret} and moved above}
3978 % \changes{babel~3.9i}{2012/12/29}{Added the event \cs{initiateactive}}
3981 \let\prim@s\bbl@prim@s
3982 \let\active@math@prime#1%
3984 \bbl@usehooks{initiateactive}{{#1}{#2}{#3}}}
3987 % The following package options control the behaviour of shorthands
3990 %<<*More package options>>
3991 \DeclareOption{math=active}{}
3992 \DeclareOption{math=normal}{\def\bbl@mathnormal{\noexpand\textormath}}
3993 %<</More package options>>
3995 % Initiating a shorthand makes active the char. That is not
3996 % strictly necessary but it is still done for backward
3997 % compatibility. So we need to restore the original catcode at the
3998 % end of package \textit{and} and the end of the |ldf|.
4000 % \changes{babel~3.9a}{2012/07/04}{Catcodes are also restored after
4001 % each language, to prevent incompatibilities. Use \cs{string} instead
4002 % of \cs{noexpand} and add \cs{relax}}
4003 % \changes{babel~3.9a}{2012/10/18}{Catcodes are deactivated in a separate
4004 % macro, which is made no-op when babel exits}
4007 \@ifpackagewith{babel}{KeepShorthandsActive}%
4008 {\let\bbl@restoreactive\@gobble}%
4009 {\def\bbl@restoreactive#1{%
4011 \noexpand\AfterBabelLanguage\noexpand\CurrentOption
4012 {\catcode`#1=\the\catcode`#1\relax}%
4013 \noexpand\AtEndOfPackage{\catcode`#1=\the\catcode`#1\relax}}%
4015 \AtEndOfPackage{\let\bbl@restoreactive\@gobble}}
4019 % \begin{macro}{\bbl@sh@select}
4020 % This command helps the shorthand supporting macros to select how
4021 % to proceed. Note that this macro needs to be expandable as do all
4022 % the shorthand macros in order for them to work in expansion-only
4023 % environments such as the argument of |\hyphenation|.
4025 % This macro expects the name of a group of shorthands in its first
4026 % argument and a shorthand character in its second argument. It
4027 % will expand to either |\bbl@firstcs| or |\bbl@scndcs|. Hence two
4028 % more arguments need to follow it.
4029 % \changes{babel~3.8b}{2004/04/19}{Added command}
4030 % \changes{babel~3.9a}{2012/08/18}{Removed \cs{string}s, because the
4031 % char are already string'ed}
4033 \def\bbl@sh@select#1#2{%
4034 \expandafter\ifx\csname#1@sh@#2@sel\endcsname\relax
4035 \bbl@afterelse\bbl@scndcs
4037 \bbl@afterfi\csname#1@sh@#2@sel\endcsname
4042 % \begin{macro}{\active@prefix}
4043 % The command |\active@prefix| which is used in the expansion of
4044 % active characters has a function similar to |\OT1-cmd| in that it
4045 % |\protect|s the active character whenever |\protect| is
4046 % \emph{not} |\@typeset@protect|.
4047 % \changes{babel~3.5d}{1995/07/02}{\cs{@protected@cmd} has vanished
4048 % from \file{ltoutenc.dtx}}
4049 % \changes{babel~3.7o}{2003/11/17}{Added handling of the situation
4050 % where \cs{protect} is set to \cs{@unexpandable@protect}}
4052 \def\active@prefix#1{%
4053 \ifx\protect\@typeset@protect
4056 % When |\protect| is set to |\@unexpandable@protect| we make sure
4057 % that the active character is als \emph{not} expanded by inserting
4058 % |\noexpand| in front of it. The |\@gobble| is needed to remove
4059 % a token such as |\activechar:| (when the double colon was the
4060 % active character to be dealt with).
4062 \ifx\protect\@unexpandable@protect
4067 \expandafter\@gobble
4072 % \begin{macro}{\if@safe@actives}
4073 % In some circumstances it is necessary to be able to change the
4074 % expansion of an active character on the fly. For this purpose the
4075 % switch |@safe@actives| is available. The setting of this switch
4076 % should be checked in the first level expansion of
4077 % |\active@char|\m{char}.
4079 \newif\if@safe@actives
4084 % \begin{macro}{\bbl@restore@actives}
4085 % \changes{babel~3.7m}{2003/11/15}{New macro added}
4086 % When the output routine kicks in while the
4087 % active characters were made ``safe'' this must be undone in
4088 % the headers to prevent unexpected typeset results. For this
4089 % situation we define a command to make them ``unsafe'' again.
4091 \def\bbl@restore@actives{\if@safe@actives\@safe@activesfalse\fi}
4095 % \begin{macro}{\bbl@activate}
4096 % \begin{macro}{\bbl@deactivate}
4097 % \changes{babel~3.5a}{1995/02/11}{Added macro}
4098 % \changes{babel~3.9a}{2013/01/11}{\cs{bbl@withactive} makes sure the
4099 % catcode is active}
4100 % Both macros take one argument, like |\initiate@active@char|. The
4101 % macro is used to change the definition of an active character to
4102 % expand to |\active@char|\m{char} in the case of |\bbl@activate|,
4103 % or |\normal@char|\m{char} in the case of
4104 % |\bbl@deactivate|.
4106 \def\bbl@activate#1{%
4107 \bbl@withactive{\expandafter\let\expandafter}#1%
4108 \csname bbl@active@\string#1\endcsname}
4109 \def\bbl@deactivate#1{%
4110 \bbl@withactive{\expandafter\let\expandafter}#1%
4111 \csname bbl@normal@\string#1\endcsname}
4116 % \begin{macro}{\bbl@firstcs}
4117 % \begin{macro}{\bbl@scndcs}
4118 % These macros have two arguments. They use one of their arguments
4119 % to build a control sequence from.
4121 \def\bbl@firstcs#1#2{\csname#1\endcsname}
4122 \def\bbl@scndcs#1#2{\csname#2\endcsname}
4127 % \begin{macro}{\declare@shorthand}
4128 % The command |\declare@shorthand| is used to declare a shorthand
4129 % on a certain level. It takes three arguments:
4131 % \item a name for the collection of shorthands, i.e. `system', or
4133 % \item the character (sequence) that makes up the shorthand,
4135 % \item the code to be executed when the shorthand is encountered.
4137 % \changes{babel~3.5d}{1995/07/02}{Make a `note' when a shorthand with
4138 % an argument is defined.}
4139 % \changes{babel~3.6i}{1997/02/23}{Make it possible to distinguish the
4140 % constructed control sequences for the case with argument}
4141 % \changes{babel~3.8b}{2004/04/19}{We need to support shorthands with
4142 % and without argument in different groups; added the name of the
4143 % group to the storage macro}
4144 % \changes{babel~3.9a}{2012/07/03}{Check if shorthands are redefined}
4146 \def\declare@shorthand#1#2{\@decl@short{#1}#2\@nil}
4147 \def\@decl@short#1#2#3\@nil#4{%
4149 \ifx\bbl@tempa\@empty
4150 \expandafter\let\csname #1@sh@\string#2@sel\endcsname\bbl@scndcs
4151 \@ifundefined{#1@sh@\string#2@}{}%
4152 {\def\bbl@tempa{#4}%
4153 \expandafter\ifx\csname#1@sh@\string#2@\endcsname\bbl@tempa
4156 {Redefining #1 shorthand \string#2\\%
4157 in language \CurrentOption}%
4159 \@namedef{#1@sh@\string#2@}{#4}%
4161 \expandafter\let\csname #1@sh@\string#2@sel\endcsname\bbl@firstcs
4162 \@ifundefined{#1@sh@\string#2@\string#3@}{}%
4163 {\def\bbl@tempa{#4}%
4164 \expandafter\ifx\csname#1@sh@\string#2@\string#3@\endcsname\bbl@tempa
4167 {Redefining #1 shorthand \string#2\string#3\\%
4168 in language \CurrentOption}%
4170 \@namedef{#1@sh@\string#2@\string#3@}{#4}%
4175 % \begin{macro}{\textormath}
4176 % Some of the shorthands that will be declared by the language
4177 % definition files have to be usable in both text and mathmode. To
4178 % achieve this the helper macro |\textormath| is provided.
4179 % \changes{babel~3.9a}{2012/12/29}{Failed if an argument had a
4180 % condicional. Use the more robust mechanism of \cs{XXXoftwo}}
4184 \expandafter\@secondoftwo
4186 \expandafter\@firstoftwo
4191 % \begin{macro}{\user@group}
4192 % \begin{macro}{\language@group}
4193 % \begin{macro}{\system@group}
4194 % The current concept of `shorthands' supports three levels or
4195 % groups of shorthands. For each level the name of the level or
4196 % group is stored in a macro. The default is to have a user group;
4197 % use language group `english' and have a system group called
4199 % \changes{babel~3.6i}{1997/02/24}{Have a user group called `user' by
4202 \def\user@group{user}
4203 \def\language@group{english}
4204 \def\system@group{system}
4210 % \begin{macro}{\useshorthands}
4211 % This is the user level command to tell \LaTeX\ that user level
4212 % shorthands will be used in the document. It takes one argument,
4213 % the character that starts a shorthand. First note that this is
4214 % user level, and then initialize and activate the character for
4215 % use as a shorthand character (ie, it's active in the
4216 % preamble). Languages can deactivate shorthands, so a starred
4217 % version is also provided which activates them always after the
4218 % language has been switched.
4220 % \changes{babel~3.7j}{2001/11/11}{When \TeX\ has seen a character
4221 % its category code is fixed; need to use a `stand-in' for the
4222 % call of \cs{bbl@activate}}
4223 % \changes{babel~3.7j}{2003/09/11}{The change from 11/112001 was
4225 % \changes{babel~3.9a}{2012/08/05}{Now \cs{bbl@activate} makes sure
4226 % the catcode is active, so this part is simplified}
4227 % \changes{babel~3.9a}{2012/08/12}{User shorhands can be
4228 % defined even with shorthands=off}
4230 \def\useshorthands{%
4231 \@ifstar\bbl@usesh@s{\bbl@usesh@x{}}}
4232 \def\bbl@usesh@s#1{%
4234 {\AddBabelHook{babel-sh-\string#1}{afterextras}{\bbl@activate{#1}}}%
4236 \def\bbl@usesh@x#1#2{%
4237 \bbl@ifshorthand{#2}%
4238 {\def\user@group{user}%
4239 \initiate@active@char{#2}%
4243 {Cannot declare a shorthand turned off (\string#2)}
4244 {Sorry, but you cannot use shorthands which have been\\%
4245 turned off in the package options}}}
4249 % \begin{macro}{\defineshorthand}
4250 % \changes{babel~3.9a}{2012/08/05}{Added optional argument, to provide
4251 % a way to (re)define language shorthands}
4252 % \changes{babel~3.9a}{2012/08/25}{Extended for language-dependent
4253 % user macros, with two new auxiliary macros}
4254 % Currently we only support two groups of user level shorthands,
4255 % named internally |user| and |user@<lang>| (language-dependent
4256 % user shorthands). By default, only the first one is taken into
4257 % account, but if the former is also used (in the optional argument
4258 % of |\defineshorthand|) a new level is inserted for it
4259 % (|user@generic|, done by |\bbl@set@user@generic|); we make also
4260 % sure |{}| and |\protect| are taken into account in this new top
4263 \def\user@language@group{user@\language@group}
4264 \def\bbl@set@user@generic#1#2{%
4265 \@ifundefined{user@generic@active#1}%
4266 {\bbl@active@def#1\user@language@group{user@active}{user@generic@active}%
4267 \bbl@active@def#1\user@group{user@generic@active}{language@active}%
4268 \expandafter\edef\csname#2@sh@#1@@\endcsname{%
4269 \expandafter\noexpand\csname normal@char#1\endcsname}%
4270 \expandafter\edef\csname#2@sh@#1@\string\protect@\endcsname{%
4271 \expandafter\noexpand\csname user@active#1\endcsname}}%
4273 \newcommand\defineshorthand[3][user]{%
4274 \edef\bbl@tempa{\zap@space#1 \@empty}%
4275 \bbl@for\bbl@tempb\bbl@tempa{%
4276 \if*\expandafter\@car\bbl@tempb\@nil
4277 \edef\bbl@tempb{user@\expandafter\@gobble\bbl@tempb}%
4279 \bbl@set@user@generic{\expandafter\string\@car#2\@nil}\bbl@tempb
4281 \declare@shorthand{\bbl@tempb}{#2}{#3}}}
4285 % \begin{macro}{\languageshorthands}
4286 % A user level command to change the language from which shorthands
4287 % are used. Unfortunately, \babel{} currently does not keep track
4288 % of defined groups, and therefore there is no way to catch a
4289 % possible change in casing.
4291 \def\languageshorthands#1{\def\language@group{#1}}
4295 % \begin{macro}{\aliasshorthand}
4296 % \changes{babel~3.5f}{1996/01/25}{New command}
4297 % First the new shorthand needs to be initialized,
4299 \def\aliasshorthand#1#2{%
4300 \bbl@ifshorthand{#2}%
4301 {\expandafter\ifx\csname active@char\string#2\endcsname\relax
4302 \ifx\document\@notprerr
4305 \initiate@active@char{#2}%
4307 % \changes{babel~3.9a}{2012/08/06}{Instead of letting the new shorthand to
4308 % the original char, which very often didn't work, we define it
4310 % \changes{babel~3.9a}{2012/08/20}{Make sure both characters (old an
4312 % Then, we define the new shorthand in terms of the original
4313 % one, but note with |\aliasshorthands{"}{/}| is
4314 % |\active@prefix /\active@char/|, so we still need to let the
4315 % lattest to |\active@char"|.
4317 \expandafter\let\csname active@char\string#2\expandafter\endcsname
4318 \csname active@char\string#1\endcsname
4319 \expandafter\let\csname normal@char\string#2\expandafter\endcsname
4320 \csname normal@char\string#1\endcsname
4325 {Cannot declare a shorthand turned off (\string#2)}
4326 {Sorry, but you cannot use shorthands which have been\\%
4327 turned off in the package options}}}
4331 % \begin{macro}{\@notshorthand}
4332 % \changes{v3.8d}{2004/11/20}{Error message added}
4335 \def\@notshorthand#1{%
4337 The character `\string #1' should be made a shorthand character;\\%
4338 add the command \string\useshorthands\string{#1\string} to
4340 I will ignore your instruction}%
4341 {You may proceed, but expect unexpected results}}
4345 % \begin{macro}{\shorthandon}
4346 % \changes{babel~3.7a}{1998/06/07}{Added command}
4347 % \begin{macro}{\shorthandoff}
4348 % \changes{babel~3.7a}{1998/06/07}{Added command}
4349 % \changes{babel~3.9a}{2012/09/08}{Added code for the starred variant
4350 % of \cs{shorthandoff}}
4351 % The first level definition of these macros just passes the
4352 % argument on to |\bbl@switch@sh|, adding |\@nil| at the end to
4353 % denote the end of the list of characters.
4355 \newcommand*\shorthandon[1]{\bbl@switch@sh\@ne#1\@nnil}
4356 \DeclareRobustCommand*\shorthandoff{%
4357 \@ifstar{\bbl@shorthandoff\tw@}{\bbl@shorthandoff\z@}}
4358 \def\bbl@shorthandoff#1#2{\bbl@switch@sh#1#2\@nnil}
4361 % \begin{macro}{\bbl@switch@sh}
4362 % \changes{babel~3.7a}{1998/06/07}{Added command}
4363 % \changes{babel~3.9a}{2013/02/21}{Code revised}
4364 % The macro |\bbl@switch@sh| takes the list of characters apart one
4365 % by one and subsequently switches the category code of the
4366 % shorthand character according to the first argument of
4369 % But before any of this switching takes place we make sure that
4370 % the character we are dealing with is known as a shorthand
4371 % character. If it is, a macro such as |\active@char"| should
4374 % Switching off and on is easy -- we just set the category
4375 % code to `other' (12) and |\active|. With the starred version, the
4376 % original catcode and the original definition, saved
4377 % in |@initiate@active@char|, are restored.
4380 \def\bbl@switch@sh#1#2{%
4382 \@ifundefined{bbl@active@\string#2}%
4384 {I cannot switch `\string#2' on or off--not a shorthand}%
4385 {This character is not a shorthand. Maybe you made\\%
4386 a typing mistake? I will ignore your instruction}}%
4392 \csname bbl@oricat@\string#2\endcsname
4393 \csname bbl@oridef@\string#2\endcsname
4395 \bbl@afterfi\bbl@switch@sh#1%
4402 % \changes{babel~3.9a}{2012/06/16}{Added code}
4404 % Note the value is that at the expansion time, eg, in the preample
4405 % shorhands are usually deactivated.
4407 \def\babelshorthand{\active@prefix\babelshorthand\bbl@putsh}
4409 \@ifundefined{bbl@active@\string#1}%
4410 {\bbl@putsh@i#1\@empty\@nnil}%
4411 {\csname bbl@active@\string#1\endcsname}}
4412 \def\bbl@putsh@i#1#2\@nnil{%
4413 \csname\languagename @sh@\string#1@%
4414 \ifx\@empty#2\else\string#2@\fi\endcsname}
4415 \ifx\bbl@opt@shorthands\@nnil\else
4416 \let\bbl@s@initiate@active@char\initiate@active@char
4417 \def\initiate@active@char#1{%
4418 \bbl@ifshorthand{#1}{\bbl@s@initiate@active@char{#1}}{}}
4419 \let\bbl@s@switch@sh\bbl@switch@sh
4420 \def\bbl@switch@sh#1#2{%
4423 \bbl@ifshorthand{#2}{\bbl@s@switch@sh#1{#2}}{\bbl@switch@sh#1}%
4425 \let\bbl@s@activate\bbl@activate
4426 \def\bbl@activate#1{%
4427 \bbl@ifshorthand{#1}{\bbl@s@activate{#1}}{}}
4428 \let\bbl@s@deactivate\bbl@deactivate
4429 \def\bbl@deactivate#1{%
4430 \bbl@ifshorthand{#1}{\bbl@s@deactivate{#1}}{}}
4434 % \changes{babel~3.9a}{2012/12/27}{Removed redundant system declarations}
4436 % \begin{macro}{\bbl@prim@s}
4437 % \changes{babel~3.7f}{1999/12/01}{Need to redefine \cs{prim@s} as
4438 % well as plain \TeX's definition uses \cs{next}}
4439 % \begin{macro}{\bbl@pr@m@s}
4440 % \changes{babel~3.5a}{1995/03/10}{Added macro}
4441 % \changes{babel~3.9a}{2012/07/29}{\cs{bbl@pr@m@s} rewritten to
4442 % take into account catcodes for both the quote and the hat}
4443 % One of the internal macros that are involved in substituting
4444 % |\prime| for each right quote in mathmode is |\prim@s|. This
4445 % checks if the next character is a right quote. When the right
4446 % quote is active, the definition of this macro needs to be adapted
4447 % to look also for an active right quote; the hat could be active,
4451 \prime\futurelet\@let@token\bbl@pr@m@s}
4452 \def\bbl@if@primes#1#2{%
4454 \expandafter\@firstoftwo
4455 \else\ifx#2\@let@token
4456 \bbl@afterelse\expandafter\@firstoftwo
4458 \bbl@afterfi\expandafter\@secondoftwo
4461 \catcode`\^=7 \catcode`\*=\active \lccode`\*=`\^
4462 \catcode`\'=12 \catcode`\"=\active \lccode`\"=`\'
4467 {\bbl@if@primes*^\pr@@@t\egroup}}}
4473 % Usually the |~| is active and expands to \verb*=\penalty\@M\ =.
4474 % When it is written to the \file{.aux} file it is written
4475 % expanded. To prevent that and to be able to use the character |~|
4476 % as a start character for a shorthand, it is redefined here as a
4477 % one character shorthand on system level. The system declaration
4478 % is in most cases redundant (when |~| is still a non-break space),
4479 % and in some cases is inconvenient (if |~| has been redefined);
4480 % however, for backward compatibility it is maintained (some
4481 % existing documents may rely on the \babel{} value).
4482 % \changes{babel~3.9i}{2014/02/06}{Moved from above, after
4483 % \cs{bbl@usehook} has been defined}
4484 % \changes{babel~3.9k}{2014/02/06}{Moved again at the original place}
4486 \initiate@active@char{~}
4487 \declare@shorthand{system}{~}{\leavevmode\nobreak\ }
4491 % \begin{macro}{\OT1dqpos}
4492 % \begin{macro}{\T1dqpos}
4493 % The position of the double quote character is different for the
4494 % OT1 and T1 encodings. It will later be selected using the
4495 % |\f@encoding| macro. Therefore we define two macros here to store
4496 % the position of the character in these encodings.
4498 \expandafter\def\csname OT1dqpos\endcsname{127}
4499 \expandafter\def\csname T1dqpos\endcsname{4}
4501 % When the macro |\f@encoding| is undefined (as it is in plain
4502 % \TeX) we define it here to expand to \texttt{OT1}
4504 \ifx\f@encoding\@undefined
4505 \def\f@encoding{OT1}
4511 % \subsection{Language attributes}
4513 % Language attributes provide a means to give the user control over
4514 % which features of the language definition files he wants to
4516 % \changes{babel~3.7c}{1998/07/02}{Added support for language
4518 % \begin{macro}{\languageattribute}
4519 % \changes{babel~3.9a}{2012/09/07}{Use \cs{@expandtwoargs} with \cs{in@}}
4520 % The macro |\languageattribute| checks whether its arguments are
4521 % valid and then activates the selected language attribute.
4522 % First check whether the language is known, and then process each
4523 % attribute in the list.
4525 \newcommand\languageattribute[2]{%
4527 \bbl@fixname\bbl@tempc
4528 \bbl@iflanguage\bbl@tempc{%
4529 \bbl@loopx\bbl@attr{#2}{%
4531 % We want to make sure that each attribute is selected only once;
4532 % therefore we store the already selected attributes in
4533 % |\bbl@known@attribs|. When that control sequence is not yet
4534 % defined this attribute is certainly not selected before.
4536 \ifx\bbl@known@attribs\@undefined
4540 % Now we need to see if the attribute occurs in the list of
4541 % already selected attributes.
4543 \@expandtwoargs\in@{,\bbl@tempc-\bbl@attr,}{,\bbl@known@attribs,}%
4546 % When the attribute was in the list we issue a warning; this might
4547 % not be the users intention.
4551 You have more than once selected the attribute '\bbl@attr'\\%
4555 % When we end up here the attribute is not selected before. So, we
4556 % add it to the list of selected attributes and execute the
4557 % associated \TeX-code.
4560 \noexpand\bbl@add@list
4561 \noexpand\bbl@known@attribs{\bbl@tempc-\bbl@attr}}%
4563 \edef\bbl@tempa{\bbl@tempc-\bbl@attr}%
4564 \expandafter\bbl@ifknown@ttrib\expandafter{\bbl@tempa}\bbl@attributes%
4565 {\csname\bbl@tempc @attr@\bbl@attr\endcsname}%
4566 {\@attrerr{\bbl@tempc}{\bbl@attr}}%
4569 % This command should only be used in the preamble of a document.
4571 \@onlypreamble\languageattribute
4573 % The error text to be issued when an unknown attribute is
4576 \newcommand*{\@attrerr}[2]{%
4578 {The attribute #2 is unknown for language #1.}%
4579 {Your command will be ignored, type <return> to proceed}}
4583 % \begin{macro}{\bbl@declare@ttribute}
4584 % This command adds the new language/attribute combination to the
4585 % list of known attributes.
4587 % Then it defines a control sequence to be executed when the
4588 % attribute is used in a document. The result of this should be
4589 % that the macro |\extras...| for the current language is extended,
4590 % otherwise the attribute will not work as its code is removed from
4591 % memory at |\begin{document}|.
4593 \def\bbl@declare@ttribute#1#2#3{%
4594 \@expandtwoargs\in@{,#2,}{,\BabelModifiers,}%
4596 \AfterBabelLanguage{#1}{\languageattribute{#1}{#2}}%
4598 \bbl@add@list\bbl@attributes{#1-#2}%
4599 \expandafter\def\csname#1@attr@#2\endcsname{#3}}
4603 % \begin{macro}{\bbl@ifattributeset}
4604 % \changes{babel~3.7f}{2000/02/12}{macro added}
4605 % This internal macro has 4 arguments. It can be used to interpret
4606 % \TeX\ code based on whether a certain attribute was set. This
4607 % command should appear inside the argument to |\AtBeginDocument|
4608 % because the attributes are set in the document preamble,
4609 % \emph{after} \babel\ is loaded.
4611 % The first argument is the language, the second argument the
4612 % attribute being checked, and the third and fourth arguments are
4613 % the true and false clauses.
4615 \def\bbl@ifattributeset#1#2#3#4{%
4617 % First we need to find out if any attributes were set; if not
4620 \ifx\bbl@known@attribs\@undefined
4624 % The we need to check the list of known attributes.
4626 \@expandtwoargs\in@{,#1-#2,}{,\bbl@known@attribs,}%
4629 % When we're this far |\ifin@| has a value indicating if the
4630 % attribute in question was set or not. Just to be safe the code to
4631 % be executed is `thrown over the |\fi|'.
4642 % \begin{macro}{\bbl@add@list}
4643 % This internal macro adds its second argument to a comma
4644 % separated list in its first argument. When the list is not
4645 % defined yet (or empty), it will be initiated
4647 \def\bbl@add@list#1#2{%
4661 % \begin{macro}{\bbl@ifknown@ttrib}
4662 % An internal macro to check whether a given language/attribute is
4663 % known. The macro takes 4 arguments, the language/attribute, the
4664 % attribute list, the \TeX-code to be executed when the attribute
4665 % is known and the \TeX-code to be executed otherwise.
4667 \def\bbl@ifknown@ttrib#1#2{%
4669 % We first assume the attribute is unknown.
4671 \let\bbl@tempa\@secondoftwo
4673 % Then we loop over the list of known attributes, trying to find a
4676 \bbl@loopx\bbl@tempb{#2}{%
4677 \expandafter\in@\expandafter{\expandafter,\bbl@tempb,}{,#1,}%
4680 % When a match is found the definition of |\bbl@tempa| is changed.
4682 \let\bbl@tempa\@firstoftwo
4686 % Finally we execute |\bbl@tempa|.
4693 % \begin{macro}{\bbl@clear@ttribs}
4694 % This macro removes all the attribute code from \LaTeX's memory at
4695 % |\begin{document}| time (if any is present).
4696 % \changes{babel~3.7e}{1999/09/24}{When \cs{bbl@attributes} is
4697 % undefined this should be a no-op}
4699 \def\bbl@clear@ttribs{%
4700 \ifx\bbl@attributes\@undefined\else
4701 \bbl@loopx\bbl@tempa{\bbl@attributes}{%
4702 \expandafter\bbl@clear@ttrib\bbl@tempa.
4704 \let\bbl@attributes\@undefined
4707 \def\bbl@clear@ttrib#1-#2.{%
4708 \expandafter\let\csname#1@attr@#2\endcsname\@undefined}
4709 \AtBeginDocument{\bbl@clear@ttribs}
4713 % \subsection{Support for saving macro definitions}
4715 % To save the meaning of control sequences using |\babel@save|, we
4716 % use temporary control sequences. To save hash table entries for
4717 % these control sequences, we don't use the name of the control
4718 % sequence to be saved to construct the temporary name. Instead we
4719 % simply use the value of a counter, which is reset to zero each time
4720 % we begin to save new values. This works well because we release
4721 % the saved meanings before we begin to save a new set of control
4722 % sequence meanings (see |\selectlanguage| and |\originalTeX|). Note
4723 % undefined macros are not undefined any more when saved -- they are
4726 % \begin{macro}{\babel@savecnt}
4727 % \changes{babel~3.2}{1991/11/10}{Added macro}
4728 % \begin{macro}{\babel@beginsave}
4729 % \changes{babel~3.2}{1991/11/10}{Added macro}
4730 % The initialization of a new save cycle: reset the counter to
4733 \def\babel@beginsave{\babel@savecnt\z@}
4735 % Before it's forgotten, allocate the counter and initialize all.
4737 \newcount\babel@savecnt
4743 % \begin{macro}{\babel@save}
4744 % \changes{babel~3.2}{1991/11/10}{Added macro}
4745 % The macro |\babel@save|\meta{csname} saves the current meaning of
4746 % the control sequence \meta{csname} to
4747 % |\originalTeX|\footnote{\cs{originalTeX} has to be
4748 % expandable, i.\,e.\ you shouldn't let it to \cs{relax}.}.
4749 % To do this, we let the current meaning to a temporary control
4750 % sequence, the restore commands are appended to |\originalTeX| and
4751 % the counter is incremented.
4752 % \changes{babel~3.2c}{1992/03/17}{missing backslash led to errors
4753 % when executing \cs{originalTeX}}
4754 % \changes{babel~3.2d}{1992/07/02}{saving in \cs{babel@i} and
4755 % restoring from \cs{@babel@i} doesn't work very well...}
4758 \expandafter\let\csname babel@\number\babel@savecnt\endcsname#1\relax
4760 \toks@\expandafter{\originalTeX\let#1=}%
4762 \def\noexpand\originalTeX{\the\toks@ \expandafter\noexpand
4763 \csname babel@\number\babel@savecnt\endcsname\relax}}%
4765 \advance\babel@savecnt\@ne}
4769 % \begin{macro}{\babel@savevariable}
4770 % \changes{babel~3.2}{1991/11/10}{Added macro}
4771 % The macro |\babel@savevariable|\meta{variable} saves the value of
4772 % the variable. \meta{variable} can be anything allowed after the
4775 \def\babel@savevariable#1{\begingroup
4776 \toks@\expandafter{\originalTeX #1=}%
4778 \def\noexpand\originalTeX{\the\toks@ \the#1\relax}}%
4783 % \begin{macro}{\bbl@frenchspacing}
4784 % \begin{macro}{\bbl@nonfrenchspacing}
4785 % Some languages need to have |\frenchspacing| in effect. Others
4786 % don't want that. The command |\bbl@frenchspacing| switches it on
4787 % when it isn't already in effect and |\bbl@nonfrenchspacing|
4788 % switches it off if necessary.
4790 \def\bbl@frenchspacing{%
4791 \ifnum\the\sfcode`\.=\@m
4792 \let\bbl@nonfrenchspacing\relax
4795 \let\bbl@nonfrenchspacing\nonfrenchspacing
4797 \let\bbl@nonfrenchspacing\nonfrenchspacing
4802 % \subsection{Short tags}
4804 % \begin{macro}{\babeltags}
4805 % This macro is straightforward. After zapping spaces, we
4806 % loop over the list and define the macros |\text|\m{tag} and
4807 % |\|\m{tag}. Definitions are first expanded so that they don't
4808 % contain |\csname| but the actual macro.
4809 % \changes{babel~3.9i}{2014/02/21}{Macro \cs{babeltags} added}
4813 \edef\bbl@tempa{\zap@space#1 \@empty}%
4814 \def\bbl@tempb##1=##2\@@{%
4816 \noexpand\newcommand
4817 \expandafter\noexpand\csname ##1\endcsname{%
4819 \expandafter\noexpand\csname otherlanguage*\endcsname{##2}}
4820 \noexpand\newcommand
4821 \expandafter\noexpand\csname text##1\endcsname{%
4822 \noexpand\foreignlanguage{##2}}}
4824 \bbl@for\bbl@tempa\bbl@tempa{%
4825 \expandafter\bbl@tempb\bbl@tempa\@@}}
4829 % \subsection{Hyphens}
4831 % \begin{macro}{\babelhyphenation}
4833 % This macro saves hyphenation exceptions. Two macros are used to
4834 % store them: |\bbl@hyphenation@| for the global ones and
4835 % |\bbl@hyphenation<lang>| for language ones. See |\bbl@patterns|
4836 % above for further details. We make sure there is a space between
4837 % words when multiple commands are used.
4838 % \changes{babel~3.9a}{2012/08/28}{Macro added}
4841 \@onlypreamble\babelhyphenation
4843 \newcommand\babelhyphenation[2][\@empty]{%
4844 \ifx\bbl@hyphenation@\relax
4845 \let\bbl@hyphenation@\@empty
4847 \ifx\bbl@hyphlist\@empty\else
4849 You must not intermingle \string\selectlanguage\space and\\%
4850 \string\babelhyphenation\space or some exceptions will not\\%
4851 be taken into account. Reported}%
4854 \protected@edef\bbl@hyphenation@{\bbl@hyphenation@\space#2}%
4856 \edef\bbl@tempb{\zap@space#1 \@empty}%
4857 \bbl@for\bbl@tempa\bbl@tempb{%
4858 \bbl@fixname\bbl@tempa
4859 \bbl@iflanguage\bbl@tempa{%
4860 \bbl@csarg\protected@edef{hyphenation@\bbl@tempa}{%
4861 \@ifundefined{bbl@hyphenation@\bbl@tempa}%
4863 {\csname bbl@hyphenation@\bbl@tempa\endcsname\space}%
4869 % \begin{macro}{\bbl@allowhyphens}
4870 % \changes{babel~3.2b}{1992/02/16}{Moved macro from language
4872 % \changes{babel~3.7a}{1998/03/12}{Make \cs{allowhyphens} a no-op for
4874 % \changes{babel-3.9a}{2012/07/28}{Replaced many \cs{allowhyphens} by
4875 % \cs{bbl@allowhyphen}. They were either no-op or executed always.}
4876 % \changes{babel-3.9i}{2014/01/29}{\cs{bbl@allowhyphens} must be
4877 % ignored at the beginning of a paragraph or table cell.}
4878 % This macro makes hyphenation possible. Basically its definition
4879 % is nothing more than |\nobreak| |\hskip| \texttt{0pt plus
4880 % 0pt}\footnote{\TeX\ begins and ends a word for hyphenation at a
4881 % glue node. The penalty prevents a linebreak at this glue node.}.
4883 \def\bbl@allowhyphens{\ifvmode\else\nobreak\hskip\z@skip\fi}
4885 \def\allowhyphens{\ifx\cf@encoding\bbl@t@one\else\bbl@allowhyphens\fi}
4889 % \changes{babel-3.9a}{2012/08/27}{Added \cs{babelhyphen} and related
4891 % \begin{macro}{\babelhyphen}
4892 % Macros to insert common hyphens. Note the space before |@| in
4893 % |\babelhyphen|. Instead of protecting it with
4894 % |\DeclareRobustCommand|, which could insert a |\relax|, we use
4895 % the same procedure as shorthands.
4897 \newcommand\babelnullhyphen{\char\hyphenchar\font}
4898 \def\babelhyphen{\active@prefix\babelhyphen\bbl@hyphen}
4900 \@ifstar{\bbl@hyphen@i @}{\bbl@hyphen@i\@empty}}
4901 \def\bbl@hyphen@i#1#2{%
4902 \@ifundefined{bbl@hy@#1#2\@empty}%
4903 {\csname bbl@#1usehyphen\endcsname{\discretionary{#2}{}{#2}}}%
4904 {\csname bbl@hy@#1#2\@empty\endcsname}}
4906 % The following two commands are used to wrap the ``hyphen'' and
4907 % set the behaviour of the rest of the word -- the version with a
4908 % single |@| is used when further hyphenation is allowed, while
4909 % that with |@@| if no more hyphen are allowed. In both cases, if
4910 % the hyphen is preceded by a positive space, breaking after the
4911 % hyphen is disallowed.
4913 % There should not be a discretionaty after a hyphen at the
4914 % beginning of a word, so it is prevented if preceded by a
4915 % skip. Unfortunately, this does handle cases like ``(-suffix)''.
4916 % |\nobreak| is always preceded by |\leavevmode|, in case the
4917 % shorthand starts a paragraph.
4919 \def\bbl@usehyphen#1{%
4921 \ifdim\lastskip>\z@\mbox{#1}\nobreak\else\nobreak#1\fi
4923 \def\bbl@@usehyphen#1{%
4924 \leavevmode\ifdim\lastskip>\z@\mbox{#1}\else#1\fi}
4926 % The following macro inserts the hyphen char.
4928 \def\bbl@hyphenchar{%
4929 \ifnum\hyphenchar\font=\m@ne
4932 \char\hyphenchar\font
4935 % Finally, we define the hyphen ``types''. Their names will not
4936 % change, so you may use them in |ldf|'s.
4938 \def\bbl@hy@soft{\bbl@usehyphen{\discretionary{\bbl@hyphenchar}{}{}}}
4939 \def\bbl@hy@@soft{\bbl@@usehyphen{\discretionary{\bbl@hyphenchar}{}{}}}
4940 \def\bbl@hy@hard{\bbl@usehyphen\bbl@hyphenchar}
4941 \def\bbl@hy@@hard{\bbl@@usehyphen\bbl@hyphenchar}
4942 \def\bbl@hy@nobreak{\bbl@usehyphen{\mbox{\bbl@hyphenchar}\nobreak}}
4943 \def\bbl@hy@@nobreak{\mbox{\bbl@hyphenchar}}
4944 \def\bbl@hy@repeat{%
4946 \discretionary{\bbl@hyphenchar}{\bbl@hyphenchar}{\bbl@hyphenchar}%
4948 \def\bbl@hy@@repeat{%
4950 \discretionary{\bbl@hyphenchar}{\bbl@hyphenchar}{\bbl@hyphenchar}}}
4951 \def\bbl@hy@empty{\hskip\z@skip}
4952 \def\bbl@hy@@empty{\discretionary{}{}{}}
4956 % \begin{macro}{\bbl@disc}
4957 % \changes{babel~3.5f}{1996/01/24}{Macro moved from language
4959 % For some languages the macro |\bbl@disc| is used to ease the
4960 % insertion of discretionaries for letters that behave `abnormally'
4963 \def\bbl@disc#1#2{\nobreak\discretionary{#2-}{}{#1}\bbl@allowhyphens}
4966 % \subsection{Multiencoding strings}
4968 % \changes{babel~3.9a}{2012/09/05}{Added tentative code for string
4970 % \changes{babel~3.9a}{2012/12/24}{Added hooks}
4972 % The aim following commands is to provide a commom interface for
4973 % strings in several encodings. They also contains several hooks which
4974 % can be ued by \luatex{} and \xetex. The code is organized here with
4975 % pseudo-guards, so we start with the basic commands.
4979 % But first, a couple of tools. The first one makes global a local
4980 % variable. This is not the best solution, but it works.
4982 \def\bbl@toglobal#1{\global\let#1#1}
4983 \def\bbl@recatcode#1{%
4986 \ifnum\@tempcnta>"FF\else
4987 \catcode\@tempcnta=#1\relax
4988 \advance\@tempcnta\@ne
4989 \expandafter\bbl@tempa
4994 % The second one. We need to patch |\@uclclist|, but it is done once
4995 % and only if |\SetCase| is used or if strings are encoded. The code
4996 % is far from satisfactory for several reasons, including the fact
4997 % |\@uclclist| is not a list any more. Therefore a package option is
4998 % added to ignore it. Instead of gobbling the macro
4999 % getting the next two elements (usually |\reserved@a|), we pass it as
5000 % argument to |\bbl@uclc|. The parser is restarted inside
5001 % |\|\m{lang}|@bbl@uclc| because we do not know how many expansions
5002 % are necessary (depends on whether strings are encoded). The last
5003 % part is tricky -- when uppercasing, we have:
5005 % \let\bbl@tolower\@empty\bbl@toupper\@empty
5007 % and starts over (and similarly when lowercasing).
5008 % \changes{babel~3.9l}{2014/07/29}{Now tries to catch the parsing
5009 % macro. Removed some redundant code. Option |nocase|.}
5011 \@ifpackagewith{babel}{nocase}%
5012 {\let\bbl@patchuclc\relax}%
5013 {\def\bbl@patchuclc{%
5014 \global\let\bbl@patchuclc\relax
5015 \g@addto@macro\@uclclist{\reserved@b{\reserved@b\bbl@uclc}}%
5017 \let\bbl@encoded\bbl@encoded@uclc
5018 \@ifundefined{\languagename @bbl@uclc}% and resumes it
5020 {\let\bbl@tempa##1\relax % Used by LANG@bbl@uclc
5021 \csname\languagename @bbl@uclc\endcsname}%
5022 {\bbl@tolower\@empty}{\bbl@toupper\@empty}}%
5023 \gdef\bbl@tolower{\csname\languagename @bbl@lc\endcsname}%
5024 \gdef\bbl@toupper{\csname\languagename @bbl@uc\endcsname}}}
5028 %<<*More package options>>
5029 \DeclareOption{nocase}{}
5030 %<</More package options>>
5033 % The following package options control the behaviour of |\SetString|.
5036 %<<*More package options>>
5037 \let\bbl@opt@strings\@nnil % accept strings=value
5038 \DeclareOption{strings}{\def\bbl@opt@strings{\BabelStringsDefault}}
5039 \DeclareOption{strings=encoded}{\let\bbl@opt@strings\relax}
5040 \def\BabelStringsDefault{generic}
5041 %<</More package options>>
5044 % \paragraph{Main command} This is the main command. With the
5045 % first use it is redefined to omit the basic setup in subsequent
5046 % blocks. We make sure strings contain actual letters in the range
5047 % 128-255, not active characters.
5048 % \changes{babel~3.9g}{2013/07/29}{Added starred variant. A bit of
5049 % clean up. Removed \cs{UseString}, which didn't work.}
5050 % \changes{babel~3.9g}{2013/08/01}{Now several languages can be
5051 % processed with \cs{BabelLanguages}, if set in the ldf.}
5053 \@onlypreamble\StartBabelCommands
5054 \def\StartBabelCommands{%
5057 <@Macros local to BabelCommands@>
5058 \def\bbl@provstring##1##2{%
5059 \providecommand##1{##2}%
5061 \global\let\bbl@scafter\@empty
5062 \let\StartBabelCommands\bbl@startcmds
5063 \ifx\BabelLanguages\relax
5064 \let\BabelLanguages\CurrentOption
5067 \let\bbl@screset\@nnil % local flag - disable 1st stopcommands
5068 \StartBabelCommands}
5069 \def\bbl@startcmds{%
5070 \ifx\bbl@screset\@nnil\else
5071 \bbl@usehooks{stopcommands}{}%
5076 {\ifx\bbl@opt@strings\@nnil
5077 \let\bbl@opt@strings\BabelStringsDefault
5081 \def\bbl@startcmds@i#1#2{%
5082 \edef\bbl@L{\zap@space#1 \@empty}%
5083 \edef\bbl@G{\zap@space#2 \@empty}%
5086 % Parse the encoding info to get the label, input, and font parts.
5088 % Select the behaviour of |\SetString|. Thre are two main cases,
5089 % depending of if there is an optional argument: without it and
5090 % |strings=encoded|, strings are defined
5091 % always; otherwise, they are set only if they are still undefined
5092 % (ie, fallback values). With labelled blocks and
5093 % |strings=encoded|, define the strings, but with another value,
5094 % define strings only if the current label or font encoding is the
5095 % value of |strings|; otherwise (ie, no |strings| or a block whose
5096 % label is not in |strings=|) do nothing.
5098 % We presume the current block is not loaded, and therefore set
5099 % (above) a couple of default values to gobble the arguments. Then,
5100 % these macros are redefined if necessary according to several
5102 % \changes{babel~3.9g}{2013/08/04}{Use \cs{ProvideTextCommand}, which
5103 % does with encoded strings what the manual says.}
5104 % \changes{babel~3.9h}{2013/11/08}{Tidied up code related to
5105 % \cs{bbl@scswitch}}
5108 \newcommand\bbl@startcmds@ii[1][\@empty]{%
5109 \let\SetString\@gobbletwo
5110 \let\bbl@stringdef\@gobbletwo
5111 \let\AfterBabelCommands\@gobble
5113 \def\bbl@sc@label{generic}%
5114 \def\bbl@encstring##1##2{%
5115 \ProvideTextCommandDefault##1{##2}%
5117 \expandafter\bbl@toglobal\csname\string?\string##1\endcsname}%
5118 \let\bbl@sctest\in@true
5120 \let\bbl@sc@charset\space % <- zapped below
5121 \let\bbl@sc@fontenc\space % <- " "
5122 \def\bbl@tempa##1=##2\@nil{%
5123 \bbl@csarg\edef{sc@\zap@space##1 \@empty}{##2 }}%
5124 \bbl@for\bbl@tempb{label=#1}{\expandafter\bbl@tempa\bbl@tempb\@nil}%
5125 \def\bbl@tempa##1 ##2{% space -> comma
5127 \ifx\@empty##2\else\ifx,##1,\else,\fi\bbl@afterfi\bbl@tempa##2\fi}%
5128 \edef\bbl@sc@fontenc{\expandafter\bbl@tempa\bbl@sc@fontenc\@empty}%
5129 \edef\bbl@sc@label{\expandafter\zap@space\bbl@sc@label\@empty}%
5130 \edef\bbl@sc@charset{\expandafter\zap@space\bbl@sc@charset\@empty}%
5131 \def\bbl@encstring##1##2{%
5132 \bbl@for\bbl@tempc\bbl@sc@fontenc{%
5133 \@ifundefined{T@\bbl@tempc}%
5135 {\ProvideTextCommand##1\bbl@tempc{##2}%
5138 \bbl@toglobal\csname\bbl@tempc\string##1\endcsname}}}%
5141 \in@{,\bbl@opt@strings,}{,\bbl@sc@label,\bbl@sc@fontenc,}}%
5143 \ifx\bbl@opt@strings\@nnil % ie, no strings key -> defaults
5144 \else\ifx\bbl@opt@strings\relax % ie, strings=encoded
5145 \let\AfterBabelCommands\bbl@aftercmds
5146 \let\SetString\bbl@setstring
5147 \let\bbl@stringdef\bbl@encstring
5148 \else % ie, strings=value
5151 \let\AfterBabelCommands\bbl@aftercmds
5152 \let\SetString\bbl@setstring
5153 \let\bbl@stringdef\bbl@provstring
5157 \def\SetString##1##2{%
5158 \bbl@error{Missing group for string \string##1}%
5159 {You must assign strings to some category, typically\\%
5160 captions or extras, but you set none}}%
5164 \bbl@usehooks{defaultcommands}{}%
5167 \bbl@usehooks{encodedcommands}{{\bbl@sc@charset}{\bbl@sc@fontenc}}%
5171 % There are two versions of |\bbl@scswitch|. The first version is
5172 % used when |ldf|s are read, and it makes sure
5173 % |\|\m{group}\m{language} is reset, but only once (|\bbl@screset|
5174 % is used to keep track of this). The second version is used in the
5175 % preamble and packages loaded after \babel{} and does nothing. The
5176 % macro |\bbl@forlang| loops |\bbl@L| but its body is executed only
5177 % if the value is in |\BabelLanguages| (inside \babel) or
5178 % |\date|\m{language} is defined (after \babel{} has been loaded).
5179 % There are also two version of |\bbl@forlang|. The first one skips
5180 % the current iteration if the language is not in |\BabelLanguages|
5181 % (used in |ldf|s), and the second one skips undefined languages
5182 % (after \babel{} has been loaded) .
5185 \def\bbl@forlang#1#2{%
5187 \@expandtwoargs\in@{,#1,}{,\BabelLanguages,}%
5190 \bbl@forlang\bbl@tempa{%
5191 \ifx\bbl@G\@empty\else
5192 \ifx\SetString\@gobbletwo\else
5193 \edef\bbl@GL{\bbl@G\bbl@tempa}%
5194 \@expandtwoargs\in@{,\bbl@GL,}{,\bbl@screset,}%
5196 \global\expandafter\let\csname\bbl@GL\endcsname\@undefined
5197 \xdef\bbl@screset{\bbl@screset,\bbl@GL}%
5202 \def\bbl@forlang#1#2{\bbl@for#1\bbl@L{\@ifundefined{date#1}{}{#2}}}%
5203 \let\bbl@scswitch\relax}
5204 \@onlypreamble\EndBabelCommands
5205 \def\EndBabelCommands{%
5206 \bbl@usehooks{stopcommands}{}%
5212 % Now we define commands to be used inside |\StartBabelCommands|.
5214 % \paragraph{Strings} The following macro is the actual definition
5215 % of |\SetString| when it is ``active''
5217 % First save the ``switcher''. Create it if undefined. Strings are
5218 % defined only if undefined (ie, like |\providescommmand|). With
5219 % the event |stringprocess| you can preprocess the string by
5220 % manipulating the value of |\BabelString|. If there are several
5221 % hooks assigned to this event, preprocessing is done in the same
5222 % order as defined. Finally, the string is set.
5223 % \changes{babel~3.9g}{2013/07/29}{Added \cs{bbl@forlang} to ignore in
5224 % the preamble unknown languages, as described in the doc.}
5227 \def\bbl@setstring#1#2{%
5228 \bbl@forlang\bbl@tempa{%
5229 \edef\bbl@LC{\bbl@tempa\expandafter\@gobble\string#1}%
5230 \@ifundefined{\bbl@LC}% eg, \germanchaptername
5231 {\global\expandafter
5232 \bbl@add\csname\bbl@G\bbl@tempa\expandafter\endcsname\expandafter
5233 {\expandafter\bbl@scset\expandafter#1\csname\bbl@LC\endcsname}}%
5235 \def\BabelString{#2}%
5236 \bbl@usehooks{stringprocess}{}%
5237 \expandafter\bbl@stringdef
5238 \csname\bbl@LC\expandafter\endcsname\expandafter{\BabelString}}}
5241 % Now, some addtional stuff to be used when encoded strings are
5242 % used. Captions then include |\bbl@encoded| for string to be
5243 % expanded in case transformations. It is |\relax| by default, but
5244 % in |\MakeUppercase| and |\MakeLowercase| its value is a modified
5245 % expandable |\@changed@cmd|.
5247 % \changes{babel~3.9i}{2014/03/13}{Added code to expand captions in
5248 % case transformations.}
5251 \ifx\bbl@opt@strings\relax
5252 \def\bbl@scset#1#2{\def#1{\bbl@encoded#2}}
5254 \let\bbl@encoded\relax
5255 \def\bbl@encoded@uclc#1{%
5257 \expandafter\ifx\csname\cf@encoding\string#1\endcsname\relax
5258 \expandafter\ifx\csname ?\string#1\endcsname\relax
5259 \TextSymbolUnavailable#1%
5261 \csname ?\string#1\endcsname
5264 \csname\cf@encoding\string#1\endcsname
5267 \def\bbl@scset#1#2{\def#1{#2}}
5271 % Define |\SetStringLoop|, which is actually set inside
5272 % |\StartBabelCommands|. The current definition is
5273 % somewhat complicated because we need a count, but |\count@| is
5274 % not under our control (remember |\SetString| may call hooks).
5276 % \changes{babel~3.9h}{2013/10/16}{Tidied up and bug fixed - first
5277 % element expanded prematurely.}
5280 %<<*Macros local to BabelCommands>>
5281 \def\SetStringLoop##1##2{%
5282 \def\bbl@templ####1{\expandafter\noexpand\csname##1\endcsname}%
5284 \bbl@loop\bbl@tempa{##2}{%
5286 \toks@\expandafter{\bbl@tempa}%
5288 \bbl@templ{\romannumeral\count@}{\the\toks@}%
5289 \count@=\the\count@\relax}%
5290 \expandafter\SetString\bbl@tempb}}%
5291 %<</Macros local to BabelCommands>>
5294 % \paragraph{Delaying code} Now the definition of
5295 % |\AfterBabelCommands| when it is activated.
5298 \def\bbl@aftercmds#1{%
5299 \toks@\expandafter{\bbl@scafter#1}%
5300 \xdef\bbl@scafter{\the\toks@}}
5303 % \paragraph{Case mapping}
5305 % The command |\SetCase| provides a way to change the behaviour of
5306 % |\MakeUppercase| and |\MakeLowercase|. |\bbl@tempa| is set by the
5307 % patched |\@uclclist| to the parsing command.
5309 % \changes{babel~3.9h}{2013/11/08}{Use \cs{bbl@encstrings} - they
5310 % should be defined always, even if no `strings'}
5312 %<<*Macros local to BabelCommands>>
5313 \newcommand\SetCase[3][]{%
5315 \bbl@forlang\bbl@tempa{%
5316 \expandafter\bbl@encstring
5317 \csname\bbl@tempa @bbl@uclc\endcsname{\bbl@tempa##1}%
5318 \expandafter\bbl@encstring
5319 \csname\bbl@tempa @bbl@uc\endcsname{##2}%
5320 \expandafter\bbl@encstring
5321 \csname\bbl@tempa @bbl@lc\endcsname{##3}}}%
5322 %<</Macros local to BabelCommands>>
5325 % Macros to deal with case mapping for hyphenation. To decide if the
5326 % document is monolingual or multilingual, we make a rough guess --
5327 % just see if there is a comma in the languages list, built in the
5328 % first pass of the package options.
5331 %<<*Macros local to BabelCommands>>
5332 \newcommand\SetHyphenMap[1]{%
5333 \bbl@forlang\bbl@tempa{%
5334 \expandafter\bbl@stringdef
5335 \csname\bbl@tempa @bbl@hyphenmap\endcsname{##1}}}
5336 %<</Macros local to BabelCommands>>
5339 % There are 3 helper macros which do most of the work for you.
5342 \newcommand\BabelLower[2]{% one to one.
5343 \ifnum\lccode#1=#2\else
5344 \babel@savevariable{\lccode#1}%
5347 \newcommand\BabelLowerMM[4]{% many-to-many
5351 \ifnum\@tempcnta>#2\else
5352 \@expandtwoargs\BabelLower{\the\@tempcnta}{\the\@tempcntb}%
5353 \advance\@tempcnta#3\relax
5354 \advance\@tempcntb#3\relax
5355 \expandafter\bbl@tempa
5358 \newcommand\BabelLowerMO[4]{% many-to-one
5361 \ifnum\@tempcnta>#2\else
5362 \@expandtwoargs\BabelLower{\the\@tempcnta}{#4}%
5363 \advance\@tempcnta#3
5364 \expandafter\bbl@tempa
5369 % The following package options control the behaviour of
5370 % hyphenation mapping.
5373 %<<*More package options>>
5374 \DeclareOption{hyphenmap=off}{\chardef\bbl@hymapopt\z@}
5375 \DeclareOption{hyphenmap=first}{\chardef\bbl@hymapopt\@ne}
5376 \DeclareOption{hyphenmap=select}{\chardef\bbl@hymapopt\tw@}
5377 \DeclareOption{hyphenmap=other}{\chardef\bbl@hymapopt\thr@@}
5378 \DeclareOption{hyphenmap=other*}{\chardef\bbl@hymapopt4\relax}
5379 %<</More package options>>
5382 % Initial setup to provide a default behaviour if |hypenmap|
5387 \ifx\bbl@hymapopt\@undefined
5388 \@expandtwoargs\in@{,}{\bbl@language@opts}%
5389 \chardef\bbl@hymapopt\ifin@4\else\@ne\fi
5393 % \subsection{Macros common to a number of languages}
5395 % \begin{macro}{\set@low@box}
5396 % \changes{babel~3.2b}{1992/02/16}{Moved macro from language
5398 % The following macro is used to lower quotes to the same level as
5399 % the comma. It prepares its argument in box register~0.
5401 \def\set@low@box#1{\setbox\tw@\hbox{,}\setbox\z@\hbox{#1}%
5402 \dimen\z@\ht\z@ \advance\dimen\z@ -\ht\tw@%
5403 \setbox\z@\hbox{\lower\dimen\z@ \box\z@}\ht\z@\ht\tw@ \dp\z@\dp\tw@}
5407 % \begin{macro}{\save@sf@q}
5408 % \changes{babel~3.2b}{1992/02/16}{Moved macro from language
5410 % The macro |\save@sf@q| is used to save and reset the current
5412 % \changes{babel~3.7f}{2000/09/19}{PR3119, don't start a paragraph in
5415 \def\save@sf@q#1{\leavevmode
5417 \edef\@SF{\spacefactor\the\spacefactor}#1\@SF
5422 % \changes{babel~3.5c}{1995/06/14}{Repaired a typo (itlaic, PR1652)}
5424 % \subsection{Making glyphs available}
5426 % This section makes a number of glyphs available that either do not
5427 % exist in the \texttt{OT1} encoding and have to be `faked', or
5428 % that are not accessible through \file{T1enc.def}.
5430 % \subsubsection{Quotation marks}
5432 % \begin{macro}{\quotedblbase}
5433 % In the \texttt{T1} encoding the opening double quote at the
5434 % baseline is available as a separate character, accessible via
5435 % |\quotedblbase|. In the \texttt{OT1} encoding it is not
5436 % available, therefore we make it available by lowering the normal
5437 % open quote character to the baseline.
5439 \ProvideTextCommand{\quotedblbase}{OT1}{%
5440 \save@sf@q{\set@low@box{\textquotedblright\/}%
5441 \box\z@\kern-.04em\bbl@allowhyphens}}
5443 % Make sure that when an encoding other than \texttt{OT1} or
5444 % \texttt{T1} is used this glyph can still be typeset.
5446 \ProvideTextCommandDefault{\quotedblbase}{%
5447 \UseTextSymbol{OT1}{\quotedblbase}}
5451 % \begin{macro}{\quotesinglbase}
5452 % We also need the single quote character at the baseline.
5454 \ProvideTextCommand{\quotesinglbase}{OT1}{%
5455 \save@sf@q{\set@low@box{\textquoteright\/}%
5456 \box\z@\kern-.04em\bbl@allowhyphens}}
5458 % Make sure that when an encoding other than \texttt{OT1} or
5459 % \texttt{T1} is used this glyph can still be typeset.
5461 \ProvideTextCommandDefault{\quotesinglbase}{%
5462 \UseTextSymbol{OT1}{\quotesinglbase}}
5466 % \begin{macro}{\guillemotleft}
5467 % \begin{macro}{\guillemotright}
5468 % The guillemet characters are not available in \texttt{OT1}
5469 % encoding. They are faked.
5471 \ProvideTextCommand{\guillemotleft}{OT1}{%
5476 \raise.2ex\hbox{$\scriptscriptstyle\ll$}\bbl@allowhyphens}%
5478 \ProvideTextCommand{\guillemotright}{OT1}{%
5483 \raise.2ex\hbox{$\scriptscriptstyle\gg$}\bbl@allowhyphens}%
5486 % Make sure that when an encoding other than \texttt{OT1} or
5487 % \texttt{T1} is used these glyphs can still be typeset.
5489 \ProvideTextCommandDefault{\guillemotleft}{%
5490 \UseTextSymbol{OT1}{\guillemotleft}}
5491 \ProvideTextCommandDefault{\guillemotright}{%
5492 \UseTextSymbol{OT1}{\guillemotright}}
5497 % \begin{macro}{\guilsinglleft}
5498 % \begin{macro}{\guilsinglright}
5499 % The single guillemets are not available in \texttt{OT1}
5500 % encoding. They are faked.
5502 \ProvideTextCommand{\guilsinglleft}{OT1}{%
5507 \raise.2ex\hbox{$\scriptscriptstyle<$}\bbl@allowhyphens}%
5509 \ProvideTextCommand{\guilsinglright}{OT1}{%
5514 \raise.2ex\hbox{$\scriptscriptstyle>$}\bbl@allowhyphens}%
5517 % Make sure that when an encoding other than \texttt{OT1} or
5518 % \texttt{T1} is used these glyphs can still be typeset.
5520 \ProvideTextCommandDefault{\guilsinglleft}{%
5521 \UseTextSymbol{OT1}{\guilsinglleft}}
5522 \ProvideTextCommandDefault{\guilsinglright}{%
5523 \UseTextSymbol{OT1}{\guilsinglright}}
5529 % \subsubsection{Letters}
5531 % \begin{macro}{\ij}
5532 % \begin{macro}{\IJ}
5533 % The dutch language uses the letter `ij'. It is available in
5534 % \texttt{T1} encoded fonts, but not in the \texttt{OT1} encoded
5535 % fonts. Therefore we fake it for the \texttt{OT1} encoding.
5536 % \changes{dutch-3.7a}{1995/02/04}{Changed the kerning in the faked ij
5537 % to match the dc-version of it}
5538 % \changes{babel~3.9a}{2012/07/28}{Removed the first \cs{allowhyphens}.
5539 % Moved the second one just after the kern.}
5541 \DeclareTextCommand{\ij}{OT1}{%
5542 i\kern-0.02em\bbl@allowhyphens j}
5543 \DeclareTextCommand{\IJ}{OT1}{%
5544 I\kern-0.02em\bbl@allowhyphens J}
5545 \DeclareTextCommand{\ij}{T1}{\char188}
5546 \DeclareTextCommand{\IJ}{T1}{\char156}
5548 % Make sure that when an encoding other than \texttt{OT1} or
5549 % \texttt{T1} is used these glyphs can still be typeset.
5551 \ProvideTextCommandDefault{\ij}{%
5552 \UseTextSymbol{OT1}{\ij}}
5553 \ProvideTextCommandDefault{\IJ}{%
5554 \UseTextSymbol{OT1}{\IJ}}
5559 % \begin{macro}{\dj}
5560 % \begin{macro}{\DJ}
5561 % The croatian language needs the letters |\dj| and |\DJ|; they are
5562 % available in the \texttt{T1} encoding, but not in the
5563 % \texttt{OT1} encoding by default.
5565 % Some code to construct these glyphs for the \texttt{OT1} encoding
5566 % was made available to me by Stipcevic Mario,
5567 % (\texttt{stipcevic@olimp.irb.hr}).
5568 % \changes{babel~3.5f}{1996/03/28}{New definition of \cs{dj}, see PR
5571 \def\crrtic@{\hrule height0.1ex width0.3em}
5572 \def\crttic@{\hrule height0.1ex width0.33em}
5574 \setbox0\hbox{d}\dimen@=\ht0
5577 \dimen@ii\expandafter\rem@pt\the\fontdimen\@ne\font\dimen@
5578 \advance\dimen@ii.5ex
5579 \leavevmode\rlap{\raise\dimen@\hbox{\kern\dimen@ii\vbox{\crrtic@}}}}
5581 \setbox0\hbox{D}\dimen@=.55\ht0
5582 \dimen@ii\expandafter\rem@pt\the\fontdimen\@ne\font\dimen@
5583 \advance\dimen@ii.15ex % correction for the dash position
5584 \advance\dimen@ii-.15\fontdimen7\font % correction for cmtt font
5585 \dimen\thr@@\expandafter\rem@pt\the\fontdimen7\font\dimen@
5586 \leavevmode\rlap{\raise\dimen@\hbox{\kern\dimen@ii\vbox{\crttic@}}}}
5588 \DeclareTextCommand{\dj}{OT1}{\ddj@ d}
5589 \DeclareTextCommand{\DJ}{OT1}{\DDJ@ D}
5591 % Make sure that when an encoding other than \texttt{OT1} or
5592 % \texttt{T1} is used these glyphs can still be typeset.
5594 \ProvideTextCommandDefault{\dj}{%
5595 \UseTextSymbol{OT1}{\dj}}
5596 \ProvideTextCommandDefault{\DJ}{%
5597 \UseTextSymbol{OT1}{\DJ}}
5602 % \begin{macro}{\SS}
5603 % For the \texttt{T1} encoding |\SS| is defined and selects a
5604 % specific glyph from the font, but for other encodings it is not
5605 % available. Therefore we make it available here.
5607 \DeclareTextCommand{\SS}{OT1}{SS}
5608 \ProvideTextCommandDefault{\SS}{\UseTextSymbol{OT1}{\SS}}
5612 % \subsubsection{Shorthands for quotation marks}
5614 % Shorthands are provided for a number of different quotation
5615 % marks, which make them usable both outside and inside mathmode.
5617 % \begin{macro}{\glq}
5618 % \begin{macro}{\grq}
5619 % \changes{babel~3.7a}{1997/04/25}{Make the definition of \cs{grq}
5620 % dependent on the font encoding}
5621 % \changes{babel~3.8b}{2004/05/02}{Made \cs{glq} fontencoding
5622 % dependent as well}
5623 % The `german' single quotes.
5625 \ProvideTextCommand{\glq}{OT1}{%
5626 \textormath{\quotesinglbase}{\mbox{\quotesinglbase}}}
5627 \ProvideTextCommand{\glq}{T1}{%
5628 \textormath{\quotesinglbase}{\mbox{\quotesinglbase}}}
5629 \ProvideTextCommandDefault{\glq}{\UseTextSymbol{OT1}\glq}
5631 % The definition of |\grq| depends on the fontencoding. With
5632 % \texttt{T1} encoding no extra kerning is needed.
5634 \ProvideTextCommand{\grq}{T1}{%
5635 \textormath{\textquoteleft}{\mbox{\textquoteleft}}}
5636 \ProvideTextCommand{\grq}{OT1}{%
5637 \save@sf@q{\kern-.0125em%
5638 \textormath{\textquoteleft}{\mbox{\textquoteleft}}%
5640 \ProvideTextCommandDefault{\grq}{\UseTextSymbol{OT1}\grq}
5645 % \begin{macro}{\glqq}
5646 % \begin{macro}{\grqq}
5647 % \changes{babel~3.7a}{1997/04/25}{Make the definition of \cs{grqq}
5648 % dependent on the font encoding}
5649 % \changes{babel~3.8b}{2004/05/02}{Made \cs{grqq} fontencoding
5650 % dependent as well}
5651 % The `german' double quotes.
5653 \ProvideTextCommand{\glqq}{OT1}{%
5654 \textormath{\quotedblbase}{\mbox{\quotedblbase}}}
5655 \ProvideTextCommand{\glqq}{T1}{%
5656 \textormath{\quotedblbase}{\mbox{\quotedblbase}}}
5657 \ProvideTextCommandDefault{\glqq}{\UseTextSymbol{OT1}\glqq}
5659 % The definition of |\grqq| depends on the % fontencoding. With
5660 % \texttt{T1} encoding no extra kerning is needed.
5662 \ProvideTextCommand{\grqq}{T1}{%
5663 \textormath{\textquotedblleft}{\mbox{\textquotedblleft}}}
5664 \ProvideTextCommand{\grqq}{OT1}{%
5665 \save@sf@q{\kern-.07em%
5666 \textormath{\textquotedblleft}{\mbox{\textquotedblleft}}%
5668 \ProvideTextCommandDefault{\grqq}{\UseTextSymbol{OT1}\grqq}
5673 % \begin{macro}{\flq}
5674 % \begin{macro}{\frq}
5675 % \changes{babel~3.5f}{1995/08/07}{corrected spelling of
5676 % \cs{quilsingl...}}
5677 % \changes{babel~3.5f}{1995/09/05}{now use \cs{textormath} in these
5679 % \changes{babel~3.8b}{2004/05/02}{Made \cs{flq} and \cs{frq}
5680 % fontencoding dependent}
5681 % The `french' single guillemets.
5683 \ProvideTextCommand{\flq}{OT1}{%
5684 \textormath{\guilsinglleft}{\mbox{\guilsinglleft}}}
5685 \ProvideTextCommand{\flq}{T1}{%
5686 \textormath{\guilsinglleft}{\mbox{\guilsinglleft}}}
5687 \ProvideTextCommandDefault{\flq}{\UseTextSymbol{OT1}\flq}
5691 \ProvideTextCommand{\frq}{OT1}{%
5692 \textormath{\guilsinglright}{\mbox{\guilsinglright}}}
5693 \ProvideTextCommand{\frq}{T1}{%
5694 \textormath{\guilsinglright}{\mbox{\guilsinglright}}}
5695 \ProvideTextCommandDefault{\frq}{\UseTextSymbol{OT1}\frq}
5700 % \begin{macro}{\flqq}
5701 % \begin{macro}{\frqq}
5702 % \changes{babel~3.5f}{1995/08/07}{corrected spelling of
5703 % \cs{quillemot...}}
5704 % \changes{babel~3.5f}{1995/09/05}{now use \cs{textormath} in these
5706 % \changes{babel~3.8b}{2004/05/02}{Made \cs{flqq} and \cs{frqq}
5707 % fontencoding dependent}
5708 % The `french' double guillemets.
5710 \ProvideTextCommand{\flqq}{OT1}{%
5711 \textormath{\guillemotleft}{\mbox{\guillemotleft}}}
5712 \ProvideTextCommand{\flqq}{T1}{%
5713 \textormath{\guillemotleft}{\mbox{\guillemotleft}}}
5714 \ProvideTextCommandDefault{\flqq}{\UseTextSymbol{OT1}\flqq}
5718 \ProvideTextCommand{\frqq}{OT1}{%
5719 \textormath{\guillemotright}{\mbox{\guillemotright}}}
5720 \ProvideTextCommand{\frqq}{T1}{%
5721 \textormath{\guillemotright}{\mbox{\guillemotright}}}
5722 \ProvideTextCommandDefault{\frqq}{\UseTextSymbol{OT1}\frqq}
5727 % \subsubsection{Umlauts and tremas}
5729 % The command |\"| needs to have a different effect for different
5730 % languages. For German for instance, the `umlaut' should be
5731 % positioned lower than the default position for placing it over
5732 % the letters a, o, u, A, O and U. When placed over an e, i, E or I
5733 % it can retain its normal position. For Dutch the same glyph is
5734 % always placed in the lower position.
5736 % \begin{macro}{\umlauthigh}
5737 % \changes{v3.8a}{2004/02/19}{Use \cs{leavevmode}\cs{bgroup} to
5738 % prevent problems when this command occurs in vertical mode.}
5739 % \begin{macro}{\umlautlow}
5740 % To be able to provide both positions of |\"| we provide two
5741 % commands to switch the positioning, the default will be
5742 % |\umlauthigh| (the normal positioning).
5745 \def\bbl@umlauta##1{\leavevmode\bgroup%
5746 \expandafter\accent\csname\f@encoding dqpos\endcsname
5747 ##1\bbl@allowhyphens\egroup}%
5748 \let\bbl@umlaute\bbl@umlauta}
5750 \def\bbl@umlauta{\protect\lower@umlaut}}
5752 \def\bbl@umlaute{\protect\lower@umlaut}}
5758 % \begin{macro}{\lower@umlaut}
5759 % The command |\lower@umlaut| is used to position the |\"| closer
5762 % We want the umlaut character lowered, nearer to the letter. To do
5763 % this we need an extra \meta{dimen} register.
5765 \expandafter\ifx\csname U@D\endcsname\relax
5766 \csname newdimen\endcsname\U@D
5769 % The following code fools \TeX's \texttt{make\_accent} procedure
5770 % about the current x-height of the font to force another placement
5771 % of the umlaut character.
5772 % First we have to save the current x-height of the font, because
5773 % we'll change this font dimension and this is always done
5775 % \changes{v3.8a}{2004/02/19}{Use \cs{leavevmode}\cs{bgroup} to
5776 % prevent problems when this command occurs in vertical mode.}
5778 % Then we compute the new x-height in such a way that the umlaut
5779 % character is lowered to the base character. The value of
5780 % \texttt{.45ex} depends on the \MF\ parameters with which the
5781 % fonts were built. (Just try out, which value will look best.)
5782 % If the new x-height is too low, it is not changed.
5783 % Finally we call the |\accent| primitive, reset the old x-height
5784 % and insert the base character in the argument.
5785 % \changes{babel~3.5f}{1996/04/02}{Added a \cs{allowhyphens}}
5786 % \changes{babel~3.5f}{1996/06/25}{removed \cs{allowhyphens}}
5788 \def\lower@umlaut#1{%
5792 \expandafter\char\csname\f@encoding dqpos\endcsname}%
5793 \dimen@ -.45ex\advance\dimen@\ht\z@
5794 \ifdim 1ex<\dimen@ \fontdimen5\font\dimen@ \fi}%
5795 \expandafter\accent\csname\f@encoding dqpos\endcsname
5796 \fontdimen5\font\U@D #1%
5801 % For all vowels we declare |\"| to be a composite command which
5802 % uses |\bbl@umlauta| or |\bbl@umlaute| to position the umlaut
5803 % character. We need to be sure that these definitions override the
5804 % ones that are provided when the package \pkg{fontenc} with
5805 % option \Lopt{OT1} is used. Therefore these declarations are
5806 % postponed until the beginning of the document. Note these
5807 % definitions only apply to some languages, but
5808 % babel sets them for \textit{all} languages -- you may want to
5809 % redefine |\bbl@umlauta| and/or |\bbl@umlaute| for a language
5810 % in the corresponding |ldf| (using the babel switching mechanism,
5814 \DeclareTextCompositeCommand{\"}{OT1}{a}{\bbl@umlauta{a}}%
5815 \DeclareTextCompositeCommand{\"}{OT1}{e}{\bbl@umlaute{e}}%
5816 \DeclareTextCompositeCommand{\"}{OT1}{i}{\bbl@umlaute{\i}}%
5817 \DeclareTextCompositeCommand{\"}{OT1}{\i}{\bbl@umlaute{\i}}%
5818 \DeclareTextCompositeCommand{\"}{OT1}{o}{\bbl@umlauta{o}}%
5819 \DeclareTextCompositeCommand{\"}{OT1}{u}{\bbl@umlauta{u}}%
5820 \DeclareTextCompositeCommand{\"}{OT1}{A}{\bbl@umlauta{A}}%
5821 \DeclareTextCompositeCommand{\"}{OT1}{E}{\bbl@umlaute{E}}%
5822 \DeclareTextCompositeCommand{\"}{OT1}{I}{\bbl@umlaute{I}}%
5823 \DeclareTextCompositeCommand{\"}{OT1}{O}{\bbl@umlauta{O}}%
5824 \DeclareTextCompositeCommand{\"}{OT1}{U}{\bbl@umlauta{U}}%
5828 % Finally, the default is to use English as the main language.
5829 % \changes{babel~3.6c}{1997/01/05}{When \file{hyphen.cfg} is not
5830 % loaded in the format \cs{l@english} might not be defined; assume
5831 % english is language 0}
5832 % \changes{babel~3.9a}{2012-05-17}{Languages are best assigned with
5833 % \cs{chardef}, not \cs{let}}
5835 \ifx\l@english\@undefined
5836 \chardef\l@english\z@
5838 \main@language{english}
5841 % Now we load definition files for engines.
5844 \ifcase\bbl@engine\or
5851 % \section{The kernel of Babel (only \LaTeX)}
5853 % \subsection{The redefinition of the style commands}
5855 % The rest of the code in this file can only be processed by
5856 % \LaTeX, so we check the current format. If it is plain \TeX,
5857 % processing should stop here. But, because of the need to limit
5858 % the scope of the definition of |\format|, a macro that is used
5859 % locally in the following |\if|~statement, this comparison is done
5860 % inside a group. To prevent \TeX\ from complaining about an
5861 % unclosed group, the processing of the command |\endinput| is
5862 % deferred until after the group is closed. This is accomplished by
5863 % the command |\aftergroup|.
5865 {\def\format{lplain}
5868 \def\format{LaTeX2e}
5871 \aftergroup\endinput
5876 % \subsection{Cross referencing macros}
5878 % The \LaTeX\ book states:
5880 % The \emph{key} argument is any sequence of letters, digits, and
5881 % punctuation symbols; upper- and lowercase letters are regarded as
5884 % When the above quote should still be true when a document is
5885 % typeset in a language that has active characters, special care
5886 % has to be taken of the category codes of these characters when
5887 % they appear in an argument of the cross referencing macros.
5889 % When a cross referencing command processes its argument, all
5890 % tokens in this argument should be character tokens with category
5891 % `letter' or `other'.
5893 % The only way to accomplish this in most cases is to use the trick
5894 % described in the \TeX book~\cite{DEK} (Appendix~D, page~382).
5895 % The primitive |\meaning| applied to a token expands to the
5896 % current meaning of this token. For example, `|\meaning\A|' with
5897 % |\A| defined as `|\def\A#1{\B}|' expands to the characters
5898 % `|macro:#1->\B|' with all category codes set to `other' or
5900 % \begin{macro}{\newlabel}
5901 % \changes{babel~3.5f}{1995/11/15}{Now use \cs{bbl@redefine}}
5902 % The macro |\label| writes a line with a |\newlabel| command
5903 % into the |.aux| file to define labels.
5905 %\bbl@redefine\newlabel#1#2{%
5906 % \@safe@activestrue\org@newlabel{#1}{#2}\@safe@activesfalse}
5910 % \begin{macro}{\@newl@bel}
5911 % \changes{babel~3.6i}{1997/03/01}{Now redefine \cs{@newl@bel} instead
5912 % of \cs{@lbibitem} and \cs{newlabel}}
5913 % We need to change the definition of the \LaTeX-internal macro
5914 % |\@newl@bel|. This is needed because we need to make sure that
5915 % shorthand characters expand to their non-active version.
5917 % The following package options control which macros are to be
5920 %<<*More package options>>
5921 \DeclareOption{safe=none}{\let\bbl@opt@safe\@empty}
5922 \DeclareOption{safe=bib}{\def\bbl@opt@safe{B}}
5923 \DeclareOption{safe=ref}{\def\bbl@opt@safe{R}}
5924 %<</More package options>>
5927 % First we open a new group to keep the changed setting of
5928 % |\protect| local and then we set the |@safe@actives| switch to
5929 % true to make sure that any shorthand that appears in any of the
5930 % arguments immediately expands to its non-active self.
5931 % \changes{babel~3.7a}{1997/12/19}{Call \cs{@safe@activestrue}
5934 \ifx\bbl@opt@safe\@empty\else
5935 \def\@newl@bel#1#2#3{%
5937 \@ifundefined{#1@#2}%
5939 {\gdef\@multiplelabels{%
5940 \@latex@warning@no@line{There were multiply-defined labels}}%
5941 \@latex@warning@no@line{Label `#2' multiply defined}}%
5942 \global\@namedef{#1@#2}{#3}}}
5946 % \begin{macro}{\@testdef}
5947 % An internal \LaTeX\ macro used to test if the labels that have
5948 % been written on the |.aux| file have changed. It is called by
5949 % the |\enddocument| macro. This macro needs to be completely
5950 % rewritten, using |\meaning|. The reason for this is that in some
5951 % cases the expansion of |\#1@#2| contains the same characters as
5952 % the |#3|; but the character codes differ. Therefore \LaTeX\ keeps
5953 % reporting that the labels may have changed.
5954 % \changes{babel~3.4g}{1994/08/30}{Moved the \cs{def} inside the
5955 % macrocode environment}
5956 % \changes{babel~3.5f}{1995/11/15}{Now use \cs{bbl@redefine}}
5957 % \changes{babel~3.5f}{1996/01/09}{Complete rewrite of this macro as
5958 % the same character ended up with different category codes in the
5959 % labels that are being compared. Now use \cs{meaning}}
5960 % \changes{babel~3.5f}{1996/01/16}{Use \cs{strip@prefix} only on
5961 % \cs{bbl@tempa} when it is not \cs{relax}}
5962 % \changes{babel~3.6i}{1997/02/28}{Make sure that shorthands don't get
5963 % expanded at the wrong moment.}
5964 % \changes{babel~3.6i}{1997/03/01}{\cs{@safe@activesfalse} is now
5965 % part of the label definition}
5966 % \changes{babel~3.7a}{1998/03/13}{Removed \cs{@safe@activesfalse}
5967 % from the label definition}
5969 \CheckCommand*\@testdef[3]{%
5970 \def\reserved@a{#3}%
5971 \expandafter\ifx\csname#1@#2\endcsname\reserved@a
5976 % Now that we made sure that |\@testdef| still has the same
5977 % definition we can rewrite it. First we make the shorthands
5980 \def\@testdef#1#2#3{%
5983 % Then we use |\bbl@tempa| as an `alias' for the macro that
5984 % contains the label which is being checked.
5986 \expandafter\let\expandafter\bbl@tempa\csname #1@#2\endcsname
5988 % Then we define |\bbl@tempb| just as |\@newl@bel| does it.
5993 % When the label is defined we replace the definition of
5994 % |\bbl@tempa| by its meaning.
5996 \ifx\bbl@tempa\relax
5998 \edef\bbl@tempa{\expandafter\strip@prefix\meaning\bbl@tempa}%
6001 % We do the same for |\bbl@tempb|.
6003 \edef\bbl@tempb{\expandafter\strip@prefix\meaning\bbl@tempb}%
6005 % If the label didn't change, |\bbl@tempa| and |\bbl@tempb| should
6006 % be identical macros.
6008 \ifx\bbl@tempa\bbl@tempb
6016 % \begin{macro}{\ref}
6017 % \begin{macro}{\pageref}
6018 % The same holds for the macro |\ref| that references a label
6019 % and |\pageref| to reference a page. So we redefine |\ref| and
6020 % |\pageref|. While we change these macros, we make them robust as
6021 % well (if they weren't already) to prevent problems if they should
6022 % become expanded at the wrong moment.
6023 % \changes{babel~3.5b}{1995/03/07}{Made \cs{ref} and \cs{pageref}
6025 % \changes{babel~3.5d}{1995/07/04}{use a different control sequence
6026 % while making \cs{ref} and \cs{pageref} robust}
6027 % \changes{babel~3.5f}{1995/11/06}{redefine \cs*{ref } if it exists
6028 % instead of \cs{ref}}
6029 % \changes{babel~3.5f}{1995/11/15}{Now use \cs{bbl@redefinerobust}}
6030 % \changes{babel~3.5f}{1996/01/19}{redefine \cs{\@setref} instead of
6031 % \cs{ref} and \cs{pageref} in \LaTeXe.}
6032 % \changes{babel~3.5f}{1996/01/21}{Reverse the previous change as it
6033 % inhibits the use of active characters in labels}
6035 \@expandtwoargs\in@{R}\bbl@opt@safe
6037 \bbl@redefinerobust\ref#1{%
6038 \@safe@activestrue\org@ref{#1}\@safe@activesfalse}
6039 \bbl@redefinerobust\pageref#1{%
6040 \@safe@activestrue\org@pageref{#1}\@safe@activesfalse}
6043 \let\org@pageref\pageref
6049 % \begin{macro}{\@citex}
6050 % \changes{babel~3.5f}{1995/11/15}{Now use \cs{bbl@redefine}}
6051 % The macro used to cite from a bibliography, |\cite|, uses an
6052 % internal macro, |\@citex|.
6053 % It is this internal macro that picks up the argument(s),
6054 % so we redefine this internal macro and leave |\cite| alone. The
6055 % first argument is used for typesetting, so the shorthands need
6056 % only be deactivated in the second argument.
6057 % \changes{babel~3.7g}{2000/10/01}{The shorthands need to be
6058 % deactivated for the second argument of \cs{@citex} only.}
6060 \@expandtwoargs\in@{B}\bbl@opt@safe
6062 \bbl@redefine\@citex[#1]#2{%
6063 \@safe@activestrue\edef\@tempa{#2}\@safe@activesfalse
6064 \org@@citex[#1]{\@tempa}}
6066 % Unfortunately, the packages \pkg{natbib} and \pkg{cite} need a
6067 % different definition of |\@citex|...
6068 % To begin with, \pkg{natbib} has a definition for |\@citex| with
6069 % \emph{three} arguments... We only know that a package is loaded
6070 % when |\begin{document}| is executed, so we need to postpone the
6071 % different redefinition.
6074 \@ifpackageloaded{natbib}{%
6076 % Notice that we use |\def| here instead of |\bbl@redefine| because
6077 % |\org@@citex| is already defined and we don't want to overwrite
6078 % that definition (it would result in parameter stack overflow
6079 % because of a circular definition).
6081 % (Recent versions of natbib change dynamically |\@citex|, so PR4087
6082 % doesn't seem fixable in a simple way. Just load natbib before.)
6084 \def\@citex[#1][#2]#3{%
6085 \@safe@activestrue\edef\@tempa{#3}\@safe@activesfalse
6086 \org@@citex[#1][#2]{\@tempa}}%
6089 % The package \pkg{cite} has a definition of |\@citex| where the
6090 % shorthands need to be turned off in both arguments.
6093 \@ifpackageloaded{cite}{%
6095 \@safe@activestrue\org@@citex[#1]{#2}\@safe@activesfalse}%
6100 % \begin{macro}{\nocite}
6101 % \changes{babel~3.5f}{1995/11/15}{Now use \cs{bbl@redefine}}
6102 % The macro |\nocite| which is used to instruct BiB\TeX\ to
6103 % extract uncited references from the database.
6105 \bbl@redefine\nocite#1{%
6106 \@safe@activestrue\org@nocite{#1}\@safe@activesfalse}
6110 % \begin{macro}{\bibcite}
6111 % \changes{babel~3.5f}{1995/11/15}{Now use \cs{bbl@redefine}}
6112 % The macro that is used in the |.aux| file to define citation
6113 % labels. When packages such as \pkg{natbib} or \pkg{cite} are not
6114 % loaded its second argument is used to typeset the citation
6115 % label. In that case, this second argument can contain active
6116 % characters but is used in an environment where
6117 % |\@safe@activestrue| is in effect. This switch needs to be reset
6118 % inside the |\hbox| which contains the citation label. In order to
6119 % determine during \file{.aux} file processing which definition of
6120 % |\bibcite| is needed we define |\bibcite| in such a way that it
6121 % redefines itself with the proper definition.
6122 % \changes{babel~3.6s}{1999/04/13}{Need to determine `online' which
6123 % definition of \cs{bibcite} is needed}
6124 % \changes{babel~3.6v}{1999/04/21}{Also check for \pkg{cite} it can't
6125 % handle \cs{@safe@activesfalse} in its second argument}
6127 \bbl@redefine\bibcite{%
6129 % We call |\bbl@cite@choice| to select the proper definition for
6130 % |\bibcite|. This new definition is then activated.
6137 % \begin{macro}{\bbl@bibcite}
6138 % \changes{babel~3.6v}{1999/04/21}{Macro \cs{bbl@bibcite} added}
6139 % The macro |\bbl@bibcite| holds the definition of |\bibcite|
6140 % needed when neither \pkg{natbib} nor \pkg{cite} is loaded.
6142 \def\bbl@bibcite#1#2{%
6143 \org@bibcite{#1}{\@safe@activesfalse#2}}
6147 % \begin{macro}{\bbl@cite@choice}
6148 % \changes{babel~3.6v}{1999/04/21}{Macro \cs{bbl@cite@choice} added}
6149 % The macro |\bbl@cite@choice| determines which definition of
6150 % |\bibcite| is needed.
6152 \def\bbl@cite@choice{%
6154 % First we give |\bibcite| its default definition.
6156 \global\let\bibcite\bbl@bibcite
6158 % Then, when \pkg{natbib} is loaded we restore the original
6159 % definition of |\bibcite|.
6161 \@ifpackageloaded{natbib}{\global\let\bibcite\org@bibcite}{}%
6163 % For \pkg{cite} we do the same.
6165 \@ifpackageloaded{cite}{\global\let\bibcite\org@bibcite}{}%
6167 % Make sure this only happens once.
6169 \global\let\bbl@cite@choice\relax}
6172 % When a document is run for the first time, no \file{.aux} file is
6173 % available, and |\bibcite| will not yet be properly defined. In
6174 % this case, this has to happen before the document starts.
6176 \AtBeginDocument{\bbl@cite@choice}
6180 % \begin{macro}{\@bibitem}
6181 % \changes{babel~3.5f}{1995/11/15}{Now use \cs{bbl@redefine}}
6182 % One of the two internal \LaTeX\ macros called by |\bibitem|
6183 % that write the citation label on the |.aux| file.
6185 \bbl@redefine\@bibitem#1{%
6186 \@safe@activestrue\org@@bibitem{#1}\@safe@activesfalse}
6188 \let\org@nocite\nocite
6189 \let\org@@citex\@citex
6190 \let\org@bibcite\bibcite
6191 \let\org@@bibitem\@bibitem
6196 % \subsection{Marks}
6198 % \begin{macro}{\markright}
6199 % \changes{babel~3.6i}{1997/03/15}{Added redefinition of \cs{mark...}
6201 % Because the output routine is asynchronous, we must
6202 % pass the current language attribute to the head lines, together
6203 % with the text that is put into them. To achieve this we need to
6204 % adapt the definition of |\markright| and |\markboth| somewhat.
6205 % \changes{babel~3.7c}{1999/04/08}{Removed the use of \cs{head@lang}
6207 % \changes{babel~3.7c}{1999/04/09}{Avoid expanding the arguments by
6208 % storing them in token registers}
6209 % \changes{babel~3.7m}{2003/11/15}{added \cs{bbl@restore@actives} to
6211 % \changes{babel~3.8c}{2004/05/26}{No need to add \emph{anything} to
6212 % an empty mark; prevented this by checking the contents of the
6214 % \changes{babel~3.8f}{2005/05/15}{Make the definition independent of
6215 % the original definition; expand \cs{languagename} before passing
6216 % it into the token registers}
6218 \bbl@redefine\markright#1{%
6220 % First of all we temporarily store the language switching command,
6221 % using an expanded definition in order to get the current value of
6224 \edef\bbl@tempb{\noexpand\protect
6225 \noexpand\foreignlanguage{\languagename}}%
6227 % Then, we check whether the argument is empty; if it is, we
6228 % just make sure the scratch token register is empty.
6235 % Next, we store the argument to |\markright| in the scratch token
6236 % register, together with the expansion of |\bbl@tempb| (containing
6237 % the language switching command) as defined before. This way
6238 % these commands will not be expanded by using |\edef| later
6239 % on, and we make sure that the text is typeset using the
6240 % correct language settings. While doing so, we make sure that
6241 % active characters that may end up in the mark are not disabled by
6242 % the output routine kicking in while \cs{@safe@activestrue} is in
6245 \expandafter\toks@\expandafter{%
6246 \bbl@tempb{\protect\bbl@restore@actives#1}}%
6249 % Then we define a temporary control sequence using |\edef|.
6253 % When |\bbl@tempa| is executed, only |\languagename| will be
6254 % expanded, because of the way the token register was filled.
6256 \noexpand\org@markright{\the\toks@}}%
6262 % \begin{macro}{\markboth}
6263 % \begin{macro}{\@mkboth}
6264 % The definition of |\markboth| is equivalent to that of
6265 % |\markright|, except that we need two token registers. The
6266 % documentclasses \cls{report} and \cls{book} define and set the
6267 % headings for the page. While doing so they also store a copy of
6268 % |\markboth| in |\@mkboth|. Therefore we need to check whether
6269 % |\@mkboth| has already been set. If so we neeed to do that again
6270 % with the new definition of |\makrboth|.
6271 % \changes{babel~3.7m}{2003/11/15}{added \cs{bbl@restore@actives} to
6273 % \changes{babel~3.8c}{2004/05/26}{No need to add \emph{anything} to
6274 % an empty mark, prevented this by checking the contents of the
6276 % \changes{babel~3.8f}{2005/05/15}{Make the definition independent of
6277 % the original definition; expand \cs{languagename} before passing
6278 % it into the token registers}
6279 % \changes{babel~3.8j}{2008/03/21}{Added setting of \cs{@mkboth} (PR
6282 \ifx\@mkboth\markboth
6283 \def\bbl@tempc{\let\@mkboth\markboth}
6288 % Now we can start the new definition of |\markboth|
6290 \bbl@redefine\markboth#1#2{%
6291 \edef\bbl@tempb{\noexpand\protect
6292 \noexpand\foreignlanguage{\languagename}}%
6297 \expandafter\toks@\expandafter{%
6298 \bbl@tempb{\protect\bbl@restore@actives#1}}%
6304 \expandafter\toks8\expandafter{%
6305 \bbl@tempb{\protect\bbl@restore@actives#2}}%
6308 \noexpand\org@markboth{\the\toks@}{\the\toks8}}%
6312 % and copy it to |\@mkboth| if necesary.
6319 % \subsection{Preventing clashes with other packages}
6321 % \subsubsection{\pkg{ifthen}}
6323 % \begin{macro}{\ifthenelse}
6324 % \changes{babel~3.5g}{1996/08/11}{Redefinition of \cs{ifthenelse}
6325 % added to circumvent problems with \cs{pageref} in the argument of
6327 % \changes{babel~3.9a}{2012/09/07}{Redefine only if `ref' is `safe'}%
6328 % \changes{babel~3.9a}{2013/01/03}{Moved to babel.def}
6329 % Sometimes a document writer wants to create a special effect
6330 % depending on the page a certain fragment of text appears on. This
6331 % can be achieved by the following piece of code:
6333 % \ifthenelse{\isodd{\pageref{some:label}}}
6334 % {code for odd pages}
6335 % {code for even pages}
6337 % In order for this to work the argument of |\isodd| needs to be
6338 % fully expandable. With the above redefinition of |\pageref| it is
6339 % not in the case of this example. To overcome that, we add some
6340 % code to the definition of |\ifthenelse| to make things work.
6342 % The first thing we need to do is check if the package
6343 % \pkg{ifthen} is loaded. This should be done at |\begin{document}|
6346 \@expandtwoargs\in@{R}\bbl@opt@safe
6349 \@ifpackageloaded{ifthen}{%
6351 % Then we can redefine |\ifthenelse|:
6352 % \changes{babel~3.6f}{1997/01/14}{\cs{ifthenelse} needs to be long}
6353 % \changes{babel~3.9a}{2012/06/22}{\cs{ref} is also taken into account}
6354 % \changes{babel~3.9n}{2015/12/14}{Don't use generic temp
6355 % macros. babel/4441}
6357 \bbl@redefine@long\ifthenelse#1#2#3{%
6359 % We want to revert the definition of |\pageref| and |\ref| to
6360 % their original definition for the first argument of |\ifthenelse|,
6361 % so we first need to store their current meanings.
6363 \let\bbl@temp@pref\pageref
6364 \let\pageref\org@pageref
6365 \let\bbl@temp@ref\ref
6368 % Then we can set the |\@safe@actives| switch and call the original
6369 % |\ifthenelse|. In order to be able to use shorthands in the
6370 % second and third arguments of |\ifthenelse| the resetting of the
6371 % switch \emph{and} the definition of |\pageref| happens inside
6372 % those arguments. When the package wasn't loaded we do nothing.
6373 % \changes{babel~3.6i}{1997/02/25}{Now reset the @safe@actives switch
6374 % inside the 2nd and 3rd arguments of \cs{ifthenelse}}
6375 % \changes{babel~3.7f}{2000/06/29}{\cs{pageref} needs to have its
6376 % babel definition reinstated in the second and third arguments}
6379 \org@ifthenelse{#1}{%
6380 \let\pageref\bbl@temp@pref
6381 \let\ref\bbl@temp@ref
6384 \let\pageref\bbl@temp@pref
6385 \let\ref\bbl@temp@ref
6394 % \subsubsection{\pkg{varioref}}
6396 % \begin{macro}{\@@vpageref}
6397 % \changes{babel~3.6a}{1996/10/29}{Redefinition of \cs{@@vpageref}
6398 % added to circumvent problems with active \texttt{:} in the
6399 % argument of \cs{vref} when \pkg{varioref} is used}
6400 % \begin{macro}{\vrefpagenum}
6401 % \changes{babel~3.7o}{2003/11/18}{Added redefinition of
6402 % \cs{vrefpagenum} which deals with ranges of pages}
6403 % \begin{macro}{\Ref}
6404 % \changes{babel~3.8g}{2005/05/21}{We also need to adapt \cs{Ref}
6405 % which needs to be able to uppercase the first letter of the
6406 % expansion of \cs{ref}}
6407 % When the package varioref is in use we need to modify its
6408 % internal command |\@@vpageref| in order to prevent problems when
6409 % an active character ends up in the argument of |\vref|.
6412 \@ifpackageloaded{varioref}{%
6413 \bbl@redefine\@@vpageref#1[#2]#3{%
6415 \org@@@vpageref{#1}[#2]{#3}%
6416 \@safe@activesfalse}%
6418 % The same needs to happen for |\vrefpagenum|.
6420 \bbl@redefine\vrefpagenum#1#2{%
6422 \org@vrefpagenum{#1}{#2}%
6423 \@safe@activesfalse}%
6425 % The package \pkg{varioref} defines |\Ref| to be a robust command
6426 % wich uppercases the first character of the reference text. In
6427 % order to be able to do that it needs to access the exandable form
6428 % of |\ref|. So we employ a little trick here. We redefine the
6429 % (internal) command \verb*|\Ref | to call |\org@ref| instead of
6430 % |\ref|. The disadvantgage of this solution is that whenever the
6431 % derfinition of |\Ref| changes, this definition needs to be updated
6434 \expandafter\def\csname Ref \endcsname#1{%
6435 \protected@edef\@tempa{\org@ref{#1}}\expandafter\MakeUppercase\@tempa}
6444 % \subsubsection{\pkg{hhline}}
6446 % \begin{macro}{\hhline}
6447 % Delaying the activation of the shorthand characters has introduced
6448 % a problem with the \pkg{hhline} package. The reason is that it
6449 % uses the `:' character which is made active by the french support
6450 % in \babel. Therefore we need to \emph{reload} the package when
6451 % the `:' is an active character.
6453 % So at |\begin{document}| we check whether \pkg{hhline} is loaded.
6457 \@ifpackageloaded{hhline}%
6459 % Then we check whether the expansion of |\normal@char:| is not
6460 % equal to |\relax|.
6461 % \changes{babel~3.8b}{2004/04/19}{added \cs{string} to prevent
6462 % unwanted expansion of the colon}
6464 {\expandafter\ifx\csname normal@char\string:\endcsname\relax
6467 % In that case we simply reload the package. Note that this happens
6468 % \emph{after} the category code of the @-sign has been changed to
6469 % other, so we need to temporarily change it to letter again.
6472 \def\@currname{hhline}\input{hhline.sty}\makeatother
6478 % \subsubsection{\pkg{hyperref}}
6480 % \begin{macro}{\pdfstringdefDisableCommands}
6481 % \changes{babel~3.8j}{2008/03/16}{Inform \pkg{hyperref} to use
6482 % shorthands at system level (PR4006)}
6484 % A number of interworking problems between \pkg{babel} and
6485 % \pkg{hyperref} are tackled by \pkg{hyperref} itself. The
6486 % following code was introduced to prevent some annoying warnings
6487 % but it broke bookmarks. This was quickly fixed in \pkg{hyperref},
6488 % which essentially made it no-op. However, it will not removed for
6489 % the moment because \pkg{hyperref} is expecting it.
6493 \@ifundefined{pdfstringdefDisableCommands}%
6495 {\pdfstringdefDisableCommands{%
6496 \languageshorthands{system}}%
6502 % \subsubsection{\pkg{fancyhdr}}
6504 % \begin{macro}{\FOREIGNLANGUAGE}
6505 % The package \pkg{fancyhdr} treats the running head and fout lines
6506 % somewhat differently as the standard classes. A symptom of this is
6507 % that the command |\foreignlanguage| which \babel\ adds to the
6508 % marks can end up inside the argument of |\MakeUppercase|. To
6509 % prevent unexpected results we need to define |\FOREIGNLANGUAGE|
6511 % \changes{babel~3.7j}{2003/05/23}{Define \cs{FOREIGNLANGUAGE}
6514 \DeclareRobustCommand{\FOREIGNLANGUAGE}[1]{%
6515 \lowercase{\foreignlanguage{#1}}}
6519 % \begin{macro}{\substitutefontfamily}
6520 % The command |\substitutefontfamily| creates an
6521 % \file{.fd} file on the fly. The first argument is an encoding
6522 % mnemonic, the second and third arguments are font family names.
6523 % \changes{babel~3.7j}{2003/06/15}{create file with lowercase name}
6525 \def\substitutefontfamily#1#2#3{%
6526 \lowercase{\immediate\openout15=#1#2.fd\relax}%
6527 \immediate\write15{%
6528 \string\ProvidesFile{#1#2.fd}%
6529 [\the\year/\two@digits{\the\month}/\two@digits{\the\day}
6530 \space generated font description file]^^J
6531 \string\DeclareFontFamily{#1}{#2}{}^^J
6532 \string\DeclareFontShape{#1}{#2}{m}{n}{<->ssub * #3/m/n}{}^^J
6533 \string\DeclareFontShape{#1}{#2}{m}{it}{<->ssub * #3/m/it}{}^^J
6534 \string\DeclareFontShape{#1}{#2}{m}{sl}{<->ssub * #3/m/sl}{}^^J
6535 \string\DeclareFontShape{#1}{#2}{m}{sc}{<->ssub * #3/m/sc}{}^^J
6536 \string\DeclareFontShape{#1}{#2}{b}{n}{<->ssub * #3/bx/n}{}^^J
6537 \string\DeclareFontShape{#1}{#2}{b}{it}{<->ssub * #3/bx/it}{}^^J
6538 \string\DeclareFontShape{#1}{#2}{b}{sl}{<->ssub * #3/bx/sl}{}^^J
6539 \string\DeclareFontShape{#1}{#2}{b}{sc}{<->ssub * #3/bx/sc}{}^^J
6544 % This command should only be used in the preamble of a document.
6546 \@onlypreamble\substitutefontfamily
6550 % \subsection{Encoding issues}
6552 % Because documents may use non-ASCII font encodings, we make sure
6553 % that the logos of \TeX\ and \LaTeX\ always come out in the right
6554 % encoding. There is a list of non-ASCII encodings. Unfortunately,
6555 % \textsf{fontenc} deletes its package options, so we must guess
6556 % which encodings has been loaded by traversing |\@filelist| to
6557 % search for \m{enc}|enc.def|. If a non-ASCII has been loaded, we
6558 % define versions of |\TeX| and |\LaTeX| for them using
6559 % |\ensureascii|. The default ASCII encoding is set, too (in reverse
6560 % order): the ``main'' encoding (when the document begins), the last
6563 % \begin{macro}{\ensureascii}
6564 % \changes{babel~3.9i}{2014/02/14}{Macro added, to replace
6565 % \cs{textlatin} and friends}
6566 % \changes{babel~3.9j}{2014/03/17}{Moved mispaced code - it should be
6567 % executed only with LaTeX}
6569 \newcommand\BabelNonASCII{LGR,X2,OT2,OT3,OT6,LHE,LWN,LMA,LMC,LMS,LMU,}
6571 \let\org@LaTeX\LaTeX
6572 \let\ensureascii\@firstofone
6575 \bbl@loopx\bbl@tempa\BabelNonASCII{% is there a non-ascii enc?
6577 \edef\bbl@tempb{{,\bbl@tempa enc.def,}{,\@filelist,}}%
6578 \lowercase\expandafter{\expandafter\in@\bbl@tempb}%
6580 \ifin@ % if a non-ascii has been loaded
6581 \def\ensureascii#1{{\fontencoding{OT1}\selectfont#1}}%
6582 \DeclareTextCommandDefault{\TeX}{\org@TeX}%
6583 \DeclareTextCommandDefault{\LaTeX}{\org@LaTeX}%
6584 \def\bbl@tempb#1\@@{\uppercase{\bbl@tempc#1}ENC.DEF\@empty\@@}%
6585 \def\bbl@tempc#1ENC.DEF#2\@@{%
6587 \@ifundefined{T@#1}%
6589 {\@expandtwoargs\in@{,#1,}{,\BabelNonASCII,}%
6591 \DeclareTextCommand{\TeX}{#1}{\ensureascii{\org@TeX}}%
6592 \DeclareTextCommand{\LaTeX}{#1}{\ensureascii{\org@LaTeX}}%
6594 \def\ensureascii##1{{\fontencoding{#1}\selectfont##1}}%
6597 \bbl@loopx\bbl@tempa\@filelist{\expandafter\bbl@tempb\bbl@tempa\@@}%
6598 \@expandtwoargs\in@{,\cf@encoding,}{,\BabelNonASCII,}%
6600 \edef\ensureascii#1{{%
6601 \noexpand\fontencoding{\cf@encoding}\noexpand\selectfont#1}}%
6607 % Now comes the old deprecated stuff (with a little change in 3.9l,
6608 % for \textsf{fontspec}). The first thing we need to do is to
6609 % determine, at |\begin{document}|, which latin fontencoding to use.
6611 % \begin{macro}{\latinencoding}
6612 % \changes{babel~3.6i}{1997/03/15}{Macro added, moved from
6613 % \file{.ldf} files}
6614 % When text is being typeset in an encoding other than `latin'
6615 % (\texttt{OT1} or \texttt{T1}), it would be nice to still have
6616 % Roman numerals come out in the Latin encoding.
6617 % So we first assume that the current encoding at the end
6618 % of processing the package is the Latin encoding.
6620 \AtEndOfPackage{\edef\latinencoding{\cf@encoding}}
6622 % But this might be overruled with a later loading of the package
6623 % \pkg{fontenc}. Therefore we check at the execution of
6624 % |\begin{document}| whether it was loaded with the \Lopt{T1}
6625 % option. The normal way to do this (using |\@ifpackageloaded|) is
6626 % disabled for this package. Now we have to revert to parsing the
6627 % internal macro |\@filelist| which contains all the filenames
6629 % \changes{babel~3.6k}{1999/03/15}{Use T1 encoding when it is a known
6631 % \changes{babel~3.6m}{1999/04/06}{Can't use \cs{@ifpackageloaded}
6632 % need to parse \cs{@filelist}}
6633 % \changes{babel~3.6n}{1999/04/07}{moved checking for fontenc right to
6634 % the top of \file{babel.sty}}
6635 % \changes{babel~3.6n}{1999/04/07}{Added a check for `manual' selection
6636 % of \texttt{T1} encoding, without loading \pkg{fontenc}}
6637 % \changes{babel~3.6q}{1999/04/12}{Better solution than parsing
6638 % \cs{@filelist}, use \cs{@ifl@aded}}
6639 % \changes{babel~3.6u}{1999/04/20}{Moved this code to
6641 % \changes{babel~3.9l}{2014/08/02}{fontspec used to set
6642 % \cs{latinencoding} to EUx, but now it doesn't. So, it's done
6644 % \changes{babel~3.9o}{2016/01/27}{With fontspec, first check if
6645 % \cs{UTFencname} exists.}
6648 \@ifpackageloaded{fontspec}%
6649 {\xdef\latinencoding{%
6650 \@ifundefined{UTFencname}%
6651 {EU\ifcase\bbl@engine\or2\or1\fi}%
6653 {\gdef\latinencoding{OT1}%
6654 \ifx\cf@encoding\bbl@t@one
6655 \xdef\latinencoding{\bbl@t@one}%
6657 \@ifl@aded{def}{t1enc}{\xdef\latinencoding{\bbl@t@one}}{}%
6662 % \begin{macro}{\latintext}
6663 % \changes{babel~3.6i}{1997/03/15}{Macro added, moved from
6664 % \file{.ldf} files}
6665 % Then we can define the command |\latintext| which is a
6666 % declarative switch to a latin font-encoding. Usage of this macro
6669 \DeclareRobustCommand{\latintext}{%
6670 \fontencoding{\latinencoding}\selectfont
6671 \def\encodingdefault{\latinencoding}}
6675 % \begin{macro}{\textlatin}
6676 % \changes{babel~3.6i}{1997/03/15}{Macro added, moved from
6677 % \file{.ldf} files}
6678 % \changes{babel~3.7j}{2003/03/19}{added \cs{leavevmode} to prevent a
6679 % paragraph starting \emph{inside} the group}
6680 % \changes{babel~3.7k}{2003/10/12}{Use \cs{DeclareTextFontComand}}
6681 % This command takes an argument which is then typeset using the
6682 % requested font encoding. In order to avoid many encoding switches
6683 % it operates in a local scope.
6685 \ifx\@undefined\DeclareTextFontCommand
6686 \DeclareRobustCommand{\textlatin}[1]{\leavevmode{\latintext #1}}
6688 \DeclareTextFontCommand{\textlatin}{\latintext}
6693 % \subsection{Local Language Configuration}
6695 % \begin{macro}{\loadlocalcfg}
6696 % At some sites it may be necessary to add site-specific actions to
6697 % a language definition file. This can be done by creating a file
6698 % with the same name as the language definition file, but with the
6699 % extension \file{.cfg}. For instance the file \file{norsk.cfg}
6700 % will be loaded when the language definition file \file{norsk.ldf}
6703 % \changes{babel~3.5d}{1995/06/22}{Added macro}
6704 % For plain-based formats we don't want to override the definition
6705 % of |\loadlocalcfg| from \file{plain.def}.
6707 \ifx\loadlocalcfg\@undefined
6708 \@ifpackagewith{babel}{noconfigs}%
6709 {\let\loadlocalcfg\@gobble}%
6710 {\def\loadlocalcfg#1{%
6711 \InputIfFileExists{#1.cfg}%
6712 {\typeout{*************************************^^J%
6713 * Local config file #1.cfg used^^J%
6718 % Just to be compatible with \LaTeX$\:$2.09 we add a few more lines
6721 \ifx\@unexpandable@protect\@undefined
6722 \def\@unexpandable@protect{\noexpand\protect\noexpand}
6723 \long\def\protected@write#1#2#3{%
6727 \let\protect\@unexpandable@protect
6728 \edef\reserved@a{\write#1{#3}}%
6731 \if@nobreak\ifvmode\nobreak\fi\fi}
6737 % \section{Internationalizing \LaTeX{} 2.09}
6739 % Now that we're sure that the code is seen by \LaTeX\ only, we
6740 % have to find out what the main (primary) document style is
6741 % because we want to redefine some macros. This is only necessary
6742 % for releases of \LaTeX\ dated before December~1991. Therefore
6743 % this part of the code can optionally be included in
6744 % \file{babel.def} by specifying the \texttt{docstrip} option
6747 % The standard styles can be distinguished by checking whether some
6748 % macros are defined. In table~\ref{styles} an overview is given of
6749 % the macros that can be used for this purpose.
6750 % \begin{table}[htb]
6752 % \DeleteShortVerb{\|}
6753 % \begin{tabular}{|lcp{8cm}|}
6755 % article & : & both the \verb+\chapter+ and \verb+\opening+
6756 % macros are undefined\\
6757 % report and book & : & the \verb+\chapter+ macro is defined and
6758 % the \verb+\opening+ is undefined\\
6759 % letter & : & the \verb+\chapter+ macro is undefined and
6760 % the \verb+\opening+ is defined\\
6763 % \caption{How to determine the main document style}\label{styles}
6764 % \MakeShortVerb{\|}
6768 % \noindent The macros that have to be redefined for the
6769 % \texttt{report} and \texttt{book} document styles happen to be
6770 % the same, so there is no need to distinguish between those two
6773 % \begin{macro}{\doc@style}
6774 % First a parameter |\doc@style| is defined to identify the current
6775 % document style. This parameter might have been defined by a
6776 % document style that already uses macros instead of hard-wired
6777 % texts, such as \file{artikel1.sty}~\cite{BEP}, so the existence of
6778 % |\doc@style| is checked. If this macro is undefined, i.\,e., if
6779 % the document style is unknown and could therefore contain
6780 % hard-wired texts, |\doc@style| is defined to the default
6782 % \changes{babel~3.0d}{1991/10/29}{Removed use of \cs{@ifundefined}}
6785 \ifx\@undefined\doc@style
6788 % This parameter is defined in the following \texttt{if}
6789 % construction (see table~\ref{styles}):
6792 \ifx\@undefined\opening
6793 \ifx\@undefined\chapter
6805 % \changes{babel~3.1}{1991/11/05}{Removed definition of
6806 % \cs{if@restonecol}}
6808 % Now here comes the real work: we start to redefine things and
6809 % replace hard-wired texts by macros. These redefinitions should be
6810 % carried out conditionally, in case it has already been done.
6812 % For the \texttt{figure} and \texttt{table} environments we have
6815 \@ifundefined{figurename}{\def\fnum@figure{\figurename{} \thefigure}}{}
6816 \@ifundefined{tablename}{\def\fnum@table{\tablename{} \thetable}}{}
6819 % The rest of the macros have to be treated differently for each
6820 % style. When |\doc@style| still has its default value nothing
6823 \ifcase \doc@style\relax
6827 % This means that \file{babel.def} is read after the
6828 % \texttt{article} style, where no |\chapter| and |\opening|
6829 % commands are defined\footnote{A fact that was pointed out to me
6830 % by Nico Poppelier and was already used in Piet van Oostrum's
6831 % document style option~\texttt{nl}.}.
6833 % First we have the |\tableofcontents|,
6834 % |\listoffigures| and |\listoftables|:
6836 \@ifundefined{contentsname}%
6837 {\def\tableofcontents{\section*{\contentsname\@mkboth
6838 {\uppercase{\contentsname}}{\uppercase{\contentsname}}}%
6840 \@ifundefined{listfigurename}%
6841 {\def\listoffigures{\section*{\listfigurename\@mkboth
6842 {\uppercase{\listfigurename}}{\uppercase{\listfigurename}}}%
6844 \@ifundefined{listtablename}%
6845 {\def\listoftables{\section*{\listtablename\@mkboth
6846 {\uppercase{\listtablename}}{\uppercase{\listtablename}}}%
6850 % Then the |\thebibliography| and |\theindex| environments.
6853 \@ifundefined{refname}%
6854 {\def\thebibliography#1{\section*{\refname
6855 \@mkboth{\uppercase{\refname}}{\uppercase{\refname}}}%
6856 \list{[\arabic{enumi}]}{\settowidth\labelwidth{[#1]}%
6857 \leftmargin\labelwidth
6858 \advance\leftmargin\labelsep
6859 \usecounter{enumi}}%
6860 \def\newblock{\hskip.11em plus.33em minus.07em}%
6861 \sloppy\clubpenalty4000\widowpenalty\clubpenalty
6862 \sfcode`\.=1000\relax}}{}
6863 \@ifundefined{indexname}%
6864 {\def\theindex{\@restonecoltrue\if@twocolumn\@restonecolfalse\fi
6866 \columnsep 35pt\twocolumn[\section*{\indexname}]%
6867 \@mkboth{\uppercase{\indexname}}{\uppercase{\indexname}}%
6868 \thispagestyle{plain}%
6869 \parskip\z@ plus.3pt\parindent\z@\let\item\@idxitem}}{}
6872 % The |abstract| environment:
6875 \@ifundefined{abstractname}%
6876 {\def\abstract{\if@twocolumn
6877 \section*{\abstractname}%
6880 {\bf \abstractname\vspace{-.5em}\vspace{\z@}}%
6886 % And last but not least, the macro |\part|:
6889 \@ifundefined{partname}%
6890 {\def\@part[#1]#2{\ifnum \c@secnumdepth >\m@ne
6891 \refstepcounter{part}%
6892 \addcontentsline{toc}{part}{\thepart
6893 \hspace{1em}#1}\else
6894 \addcontentsline{toc}{part}{#1}\fi
6895 {\parindent\z@ \raggedright
6896 \ifnum \c@secnumdepth >\m@ne
6897 \Large \bf \partname{} \thepart
6901 #2\markboth{}{}\par}%
6903 \vskip 3ex\@afterheading}%
6907 % This is all that needs to be done for the \texttt{article} style.
6913 % The next case is formed by the two styles \texttt{book} and
6914 % \texttt{report}. Basically we have to do the same as for the
6915 % \texttt{article} style, except now we must also change the
6916 % |\chapter| command.
6918 % The tables of contents, figures and tables:
6920 \@ifundefined{contentsname}%
6921 {\def\tableofcontents{\@restonecolfalse
6922 \if@twocolumn\@restonecoltrue\onecolumn
6923 \fi\chapter*{\contentsname\@mkboth
6924 {\uppercase{\contentsname}}{\uppercase{\contentsname}}}%
6926 \csname if@restonecol\endcsname\twocolumn
6927 \csname fi\endcsname}}{}
6928 \@ifundefined{listfigurename}%
6929 {\def\listoffigures{\@restonecolfalse
6930 \if@twocolumn\@restonecoltrue\onecolumn
6931 \fi\chapter*{\listfigurename\@mkboth
6932 {\uppercase{\listfigurename}}{\uppercase{\listfigurename}}}%
6934 \csname if@restonecol\endcsname\twocolumn
6935 \csname fi\endcsname}}{}
6936 \@ifundefined{listtablename}%
6937 {\def\listoftables{\@restonecolfalse
6938 \if@twocolumn\@restonecoltrue\onecolumn
6939 \fi\chapter*{\listtablename\@mkboth
6940 {\uppercase{\listtablename}}{\uppercase{\listtablename}}}%
6942 \csname if@restonecol\endcsname\twocolumn
6943 \csname fi\endcsname}}{}
6946 % Again, the |bibliography| and |index| environments; notice that
6947 % in this case we use |\bibname| instead of |\refname| as in the
6948 % definitions for the \texttt{article} style. The reason for this
6949 % is that in the \texttt{article} document style the term
6950 % `References' is used in the definition of |\thebibliography|. In
6951 % the \texttt{report} and \texttt{book} document styles the term
6952 % `Bibliography' is used.
6954 \@ifundefined{bibname}%
6955 {\def\thebibliography#1{\chapter*{\bibname
6956 \@mkboth{\uppercase{\bibname}}{\uppercase{\bibname}}}%
6957 \list{[\arabic{enumi}]}{\settowidth\labelwidth{[#1]}%
6958 \leftmargin\labelwidth \advance\leftmargin\labelsep
6959 \usecounter{enumi}}%
6960 \def\newblock{\hskip.11em plus.33em minus.07em}%
6961 \sloppy\clubpenalty4000\widowpenalty\clubpenalty
6962 \sfcode`\.=1000\relax}}{}
6963 \@ifundefined{indexname}%
6964 {\def\theindex{\@restonecoltrue\if@twocolumn\@restonecolfalse\fi
6966 \columnsep 35pt\twocolumn[\@makeschapterhead{\indexname}]%
6967 \@mkboth{\uppercase{\indexname}}{\uppercase{\indexname}}%
6968 \thispagestyle{plain}%
6969 \parskip\z@ plus.3pt\parindent\z@ \let\item\@idxitem}}{}
6972 % Here is the |abstract| environment:
6974 \@ifundefined{abstractname}%
6975 {\def\abstract{\titlepage
6978 {\bf \abstractname}%
6982 % And last but not least the |\chapter|, |\appendix| and
6985 \@ifundefined{chaptername}{\def\@chapapp{\chaptername}}{}
6987 \@ifundefined{appendixname}%
6989 \setcounter{chapter}{0}%
6990 \setcounter{section}{0}%
6991 \def\@chapapp{\appendixname}%
6992 \def\thechapter{\Alph{chapter}}}}{}
6994 \@ifundefined{partname}%
6995 {\def\@part[#1]#2{\ifnum \c@secnumdepth >-2\relax
6996 \refstepcounter{part}%
6997 \addcontentsline{toc}{part}{\thepart
6998 \hspace{1em}#1}\else
6999 \addcontentsline{toc}{part}{#1}\fi
7002 \ifnum \c@secnumdepth >-2\relax
7003 \huge\bf \partname{} \thepart
7007 #1\par}\@endpart}}{}%
7014 % Now we address the case where \file{babel.def} is read after the
7015 % \texttt{letter} style. The \texttt{letter} document style
7016 % defines the macro |\opening| and some other macros that are
7017 % specific to \texttt{letter}. This means that we have to redefine
7018 % other macros, compared to the previous two cases.
7020 % First two macros for the material at the end of a letter, the
7021 % |\cc| and |\encl| macros.
7023 \@ifundefined{ccname}%
7024 {\def\cc#1{\par\noindent
7025 \parbox[t]{\textwidth}%
7026 {\@hangfrom{\rm \ccname : }\ignorespaces #1\strut}\par}}{}
7027 \@ifundefined{enclname}%
7028 {\def\encl#1{\par\noindent
7029 \parbox[t]{\textwidth}%
7030 {\@hangfrom{\rm \enclname : }\ignorespaces #1\strut}\par}}{}
7033 % The last thing we have to do here is to redefine the
7034 % \texttt{headings} pagestyle:
7035 % \changes{babel~3.3}{1993/07/11}{\cs{headpagename} should be
7038 \@ifundefined{headtoname}%
7040 \def\@oddhead{\sl \headtoname{} \ignorespaces\toname \hfil
7041 \@date \hfil \pagename{} \thepage}%
7045 % This was the last of the four standard document styles, so if
7046 % |\doc@style| has another value we do nothing and just close the
7047 % \texttt{if} construction.
7052 % Here ends the code that can be optionally included when a version
7053 % of \LaTeX\ is in use that is dated \emph{before} December~1991.
7056 % We also need to redefine a number of commands to ensure that the
7057 % right font encoding is used, but this can't be done before
7058 % \file{babel.def} is loaded.
7059 % \changes{babel~3.6o}{1999/04/07}{Moved the rest of the font encoding
7060 % related definitions to their original place}
7062 % \section{Multiple languages}
7064 % Plain \TeX\ version~3.0 provides the primitive |\language| that
7065 % is used to store the current language. When used with a pre-3.0
7066 % version this function has to be implemented by allocating a
7070 <@Make sure ProvidesFile is defined@>
7071 \ProvidesFile{switch.def}[<@date@> <@version@> Babel switching mechanism]
7072 <@Load macros for plain if not LaTeX@>
7073 <@Define core switching macros@>
7076 % \begin{macro}{\adddialect}
7077 % The macro |\adddialect| can be used to add the name of a dialect
7078 % or variant language, for which an already defined hyphenation
7079 % table can be used.
7080 % \changes{babel~3.2}{1991/11/11}{Added \cs{relax}}
7082 \def\bbl@version{<@version@>}
7083 \def\bbl@date{<@date@>}
7084 \def\adddialect#1#2{%
7085 \global\chardef#1#2\relax
7086 \bbl@usehooks{adddialect}{{#1}{#2}}%
7087 \wlog{\string#1 = a dialect from \string\language#2}}
7090 % \changes{babel~3.9a}{2012/09/07}{Added macro}
7091 % \changes{babel~3.9a}{2013/01/23}{New macro to normalize
7092 % a macro (eg, \cs{languagename}) to lowercase if necessary}
7094 % |\bbl@iflanguage| executes code only of the language
7095 % exists. Otherwise raises and error.
7097 % The argument of |\bbl@fixname| has to be a macro name, as it may get
7098 % ``fixed'' if casing (lc/uc) is wrong. It's intented to fix a
7099 % long-standing bug when |\foreignlanguage| and the like appear in
7100 % a |\MakeXXXcase|. However, a lowercase form is not imposed to
7101 % improve backward compatibility (perhaps you defined a language
7102 % named |MYLANG|, but unfortunately mixed case names cannot be
7105 \def\bbl@fixname#1{%
7108 \edef\bbl@tempd{\noexpand\@ifundefined{\noexpand\bbl@tempe#1}}%
7110 {\lowercase\expandafter{\bbl@tempd}%
7111 {\uppercase\expandafter{\bbl@tempd}%
7113 {\edef\bbl@tempd{\def\noexpand#1{#1}}%
7114 \uppercase\expandafter{\bbl@tempd}}}%
7115 {\edef\bbl@tempd{\def\noexpand#1{#1}}%
7116 \lowercase\expandafter{\bbl@tempd}}}%
7118 \edef\bbl@tempd{\endgroup\def\noexpand#1{#1}}%
7120 \def\bbl@iflanguage#1{%
7121 \@ifundefined{l@#1}{\@nolanerr{#1}\@gobble}\@firstofone}
7124 % \begin{macro}{\iflanguage}
7125 % Users might want to test (in a private package for instance)
7126 % which language is currently active. For this we provide a test
7127 % macro, |\iflanguage|, that has three arguments. It checks
7128 % whether the first argument is a known language. If so, it
7129 % compares the first argument with the value of |\language|. Then,
7130 % depending on the result of the comparison, it executes either the
7131 % second or the third argument.
7132 % \changes{babel~3.2}{1991/11/11}{Rephrased \cs{ifnum} test}
7133 % \changes{babel~3.7a}{1998/06/10}{Now evaluate the \cs{ifnum} test
7134 % \emph{after} the \cs{fi} from the \cs{ifx} test and use
7135 % \cs{@firstoftwo} and \cs{@secondoftwo}}
7138 \bbl@iflanguage{#1}{%
7139 \ifnum\csname l@#1\endcsname=\language
7140 \expandafter\@firstoftwo
7142 \expandafter\@secondoftwo
7147 % \subsection{Selecting the language}
7149 % \begin{macro}{\selectlanguage}
7150 % The macro |\selectlanguage| checks whether the language is
7151 % already defined before it performs its actual task, which is to
7152 % update |\language| and activate language-specific definitions.
7154 % To allow the call of |\selectlanguage| either with a control
7155 % sequence name or with a simple string as argument, we have to use
7156 % a trick to delete the optional escape character.
7158 % To convert a control sequence to a string, we use the |\string|
7159 % primitive. Next we have to look at the first character of this
7160 % string and compare it with the escape character. Because this
7161 % escape character can be changed by setting the internal integer
7162 % |\escapechar| to a character number, we have to compare this
7163 % number with the character of the string. To do this we have to
7164 % use \TeX's backquote notation to specify the character as a
7167 % If the first character of the |\string|'ed argument is the
7168 % current escape character, the comparison has stripped this
7169 % character and the rest in the `then' part consists of the rest of
7170 % the control sequence name. Otherwise we know that either the
7171 % argument is not a control sequence or |\escapechar| is set to a
7172 % value outside of the character range~$0$--$255$.
7174 % If the user gives an empty argument, we provide a default
7175 % argument for |\string|. This argument should expand to nothing.
7177 % \changes{babel~3.0c}{1991/06/06}{Made \cs{selectlanguage}
7179 % \changes{babel~3.2}{1991/11/11}{Modified to allow arguments that
7180 % start with an escape character}
7181 % \changes{babel~3.2a}{1991/11/17}{Simplified the modification to
7182 % allow the use in a \cs{write} command}
7183 % \changes{babel~3.5b}{1995/05/13}{Store the name of the current
7184 % language in a control sequence instead of passing the whole macro
7185 % construct to strip the escape character in the argument of
7186 % \cs{selectlanguage }.}
7187 % \changes{babel~3.5f}{1995/11/16}{Moved check for escape character
7188 % one level down in the expansion}
7189 % \changes{babel~3.9a}{2012/11/16}{\cs{bbl@select@type} keep tracks of
7190 % the selection method: 0 is select, 1 is foreign}
7192 \let\bbl@select@type\z@
7193 \edef\selectlanguage{%
7195 \expandafter\noexpand\csname selectlanguage \endcsname}
7197 % Because the command |\selectlanguage| could be used in a moving
7198 % argument it expands to \verb*=\protect\selectlanguage =.
7199 % Therefore, we have to make sure that a macro |\protect| exists.
7200 % If it doesn't it is |\let| to |\relax|.
7202 \ifx\@undefined\protect\let\protect\relax\fi
7204 % As \LaTeX$\:$2.09 writes to files \textit{expanded} whereas
7205 % \LaTeXe\ takes care \textit{not} to expand the arguments of
7206 % |\write| statements we need to be a bit clever about the way we
7207 % add information to \file{.aux} files. Therefore we introduce the
7208 % macro |\xstring| which should expand to the right amount of
7211 \ifx\documentclass\@undefined
7212 \def\xstring{\string\string\string}
7219 % \changes{babel~3.5b}{1995/03/04}{Changed the name of the internal
7220 % macro to \cs{selectlanguage }.}
7221 % \changes{babel~3.5b}{1995/03/05}{Added an extra level of expansion to
7222 % separate the switching mechanism from writing to aux files}
7223 % \changes{babel~3.7f}{2000/09/25}{Use \cs{aftergroup} to keep the
7224 % language grouping correct in auxiliary files {PR3091}}
7225 % Since version 3.5 \babel\ writes entries to the auxiliary files in
7226 % order to typeset table of contents etc. in the correct language
7228 % \begin{macro}{\bbl@pop@language}
7229 % \emph{But} when the language change happens \emph{inside} a group
7230 % the end of the group doesn't write anything to the auxiliary
7231 % files. Therefore we need \TeX's |aftergroup| mechanism to help
7232 % us. The command |\aftergroup| stores the token immediately
7233 % following it to be executed when the current group is closed. So
7234 % we define a temporary control sequence |\bbl@pop@language| to be
7235 % executed at the end of the group. It calls |\bbl@set@language|
7236 % with the name of the current language as its argument.
7238 % \changes{babel~3.7j}{2003/03/18}{Introduce the language stack
7240 % \begin{macro}{\bbl@language@stack}
7241 % The previous solution works for one level of nesting groups, but
7242 % as soon as more levels are used it is no longer adequate. For
7243 % that case we need to keep track of the nested languages using a
7244 % stack mechanism. This stack is called |\bbl@language@stack| and
7247 \def\bbl@language@stack{}
7249 % When using a stack we need a mechanism to push an element on the
7250 % stack and to retrieve the information afterwards.
7251 % \begin{macro}{\bbl@push@language}
7252 % \begin{macro}{\bbl@pop@language}
7253 % The stack is simply a list of languagenames, separated with a `+'
7254 % sign; the push function can be simple:
7256 \def\bbl@push@language{%
7257 \xdef\bbl@language@stack{\languagename+\bbl@language@stack}}
7259 % Retrieving information from the stack is a little bit less simple,
7260 % as we need to remove the element from the stack while storing it
7261 % in the macro |\languagename|. For this we first define a helper function.
7262 % \begin{macro}{\bbl@pop@lang}
7263 % This macro stores its first element (which is delimited by the
7264 % `+'-sign) in |\languagename| and stores the rest of the string
7265 % (delimited by `-') in its third argument.
7267 \def\bbl@pop@lang#1+#2-#3{%
7268 \edef\languagename{#1}\xdef#3{#2}}
7271 % The reason for the somewhat weird arrangement of arguments to the
7272 % helper function is the fact it is called in the following way.
7273 % This means that before |\bbl@pop@lang| is executed \TeX\ first
7274 % \emph{expands} the stack, stored in |\bbl@language@stack|. The
7275 % result of that is that the argument string of |\bbl@pop@lang|
7276 % contains one or more language names, each followed by a `+'-sign
7277 % (zero language names won't occur as this macro will only be
7278 % called after something has been pushed on the stack) followed by
7279 % the `-'-sign and finally the reference to the stack.
7281 \def\bbl@pop@language{%
7282 \expandafter\bbl@pop@lang\bbl@language@stack-\bbl@language@stack
7283 \expandafter\bbl@set@language\expandafter{\languagename}}
7285 % Once the name of the previous language is retrieved from the stack,
7286 % it is fed to |\bbl@set@language| to do the actual work of
7287 % switching everything that needs switching.
7292 % \changes{babel~3.7j}{2003/03/18}{Now use the language stack mechanism}
7294 \expandafter\def\csname selectlanguage \endcsname#1{%
7295 \ifnum\bbl@hymapsel=\@cclv\let\bbl@hymapsel\tw@\fi
7297 \aftergroup\bbl@pop@language
7298 \bbl@set@language{#1}}
7300 % \changes{babel~3.7m}{2003/11/12}{Removed the superfluous empty
7301 % definition of \cs{bbl@pop@language}}
7304 % \begin{macro}{\bbl@set@language}
7305 % \changes{babel~3.7f}{2000/09/25}{Macro \cs{bbl@set@language}
7308 % The macro |\bbl@set@language| takes care of switching the
7309 % language environment \emph{and} of writing entries on the
7310 % auxiliary files. For historial reasons, language names can be
7311 % either |language| of |\language|. To catch either form a trick is
7312 % used, but unfortunately as a side effect the catcodes of letters
7313 % in |\languagename| are not well defined. The list of auxiliary
7314 % files can be extended by redefining |\BabelContentsFiles|, but
7315 % make sure they are loaded inside a group (as |aux|, |toc|,
7316 % |lof|, and |lot| do) or the last language of the document will
7317 % remain active afterwards.
7319 % We also write a command to change the current language in the
7321 % \changes{babel~3.5a}{1995/02/17}{Write the language change to the
7323 % \changes{babel~3.9a}{2012/09/09}{Added hook}
7324 % \changes{babel~3.9a}{2012/11/07}{Use a loop for contents files, with
7325 % the help of \cs{BabelContentsFiles}}
7326 % \changes{babel~3.9a}{2013/03/08}{Don't write to aux if language is
7328 % \changes{babel~3.9h}{2013/11/20}{Error with a more helpful text }
7330 \def\BabelContentsFiles{toc,lof,lot}
7331 \def\bbl@set@language#1{%
7332 \edef\languagename{%
7333 \ifnum\escapechar=\expandafter`\string#1\@empty
7334 \else\string#1\@empty\fi}%
7335 \select@language{\languagename}%
7336 \expandafter\ifx\csname date\languagename\endcsname\relax\else
7338 \protected@write\@auxout{}{\string\select@language{\languagename}}%
7339 \bbl@for\bbl@tempa\BabelContentsFiles{%
7340 \addtocontents{\bbl@tempa}{\xstring\select@language{\languagename}}}%
7341 \bbl@usehooks{write}{}%
7344 \def\select@language#1{%
7345 \ifnum\bbl@hymapsel=\@cclv\chardef\bbl@hymapsel4\relax\fi
7346 \edef\languagename{#1}%
7347 \bbl@fixname\languagename
7348 \bbl@iflanguage\languagename{%
7349 \expandafter\ifx\csname date\languagename\endcsname\relax
7351 {Unknown language `#1'. Either you have\\%
7352 misspelled its name, it has not been installed,\\%
7353 or you requested it in a previous run. Fix its name,\\%
7354 install it or just rerun the file, respectively}%
7355 {You may proceed, but expect unexpected results}%
7357 \let\bbl@select@type\z@
7358 \expandafter\bbl@switch\expandafter{\languagename}%
7360 % A bit of optimization:
7361 \def\select@language@x#1{%
7362 \ifcase\bbl@select@type
7363 \bbl@ifsamestring\languagename{#1}{}{\select@language{#1}}%
7365 \select@language{#1}%
7370 % First, check if the user asks for a known language. If so,
7371 % update the value of |\language| and call |\originalTeX|
7372 % to bring \TeX\ in a certain pre-defined state.
7373 % \changes{babel~3.0a}{1991/05/29}{Added \cs{@bsphack} and
7375 % \changes{babel~3.0d}{1991/08/08}{Removed superfluous
7377 % \changes{babel~3.0d}{1991/10/07}{Removed space hacks and use of
7378 % \cs{@ifundefined}}
7379 % \changes{babel~3.2a}{1991/11/17}{Added \cs{relax} as first command
7380 % to stop an expansion if \cs{protect} is empty}
7381 % \changes{babel~3.6a}{1996/11/07}{Check for the existence of
7382 % \cs{date...} instead of \cs{l@...}}
7383 % \changes{babel~3.7m}{2003/11/16}{Check for the existence of both
7384 % \cs{l@...} and \cs{date...}}
7385 % \changes{babel~3.8l}{2008/07/06}{Use \cs{bbl@patterns}}
7386 % \changes{babel~3.9a}{2012/07/27}{Moved \cs{bbl@patterns} to the
7387 % correct place, after setting the extras for the current
7389 % \changes{babel~3.9a}{2012/08/01}{Created \cs{bbl@swith} with code
7390 % shared by \cs{select@language} and \cs{foreing@language}}
7393 % The name of the language is stored in the control sequence
7396 % Then we have to \emph{re}define |\originalTeX| to compensate for
7397 % the things that have been activated. To save memory space for
7398 % the macro definition of |\originalTeX|, we construct the control
7399 % sequence name for the |\noextras|\langvar\ command at definition
7400 % time by expanding the |\csname| primitive.
7402 % Now activate the language-specific definitions. This is done by
7403 % constructing the names of three macros by concatenating three
7404 % words with the argument of |\selectlanguage|, and calling these
7405 % macros. \nb{What if \cs{hyphenation} was used in |extras|? Patch
7406 % temply set@hyphenmins and hyphenation. It can be done in hooks if
7408 % \changes{babel~3.5b}{1995/05/13}{Separated the setting of the
7409 % hyphenmin values}%
7410 % \changes{babel~3.9c}{2013/04/08}{Removed an extra empty line}
7412 % The switching of the values of |\lefthyphenmin| and
7413 % |\righthyphenmin| is somewhat different. First we save their
7414 % current values, then we check if |\|\langvar|hyphenmins| is
7415 % defined. If it is not, we set default values (2 and 3), otherwise
7416 % the values in |\|\langvar|hyphenmins| will be used.
7417 % \changes{babel~3.5b}{1995/06/05}{Addedd default setting of hyphenmin
7419 % \changes{babel~3.9a}{2012/08/01}{Adddd \cs{bbl@iflanguagename} and
7420 % \cs{select@language@x}, which is no-op if the language is the same}
7421 % \changes{babel~3.9a}{2013/01/23}{\cs{select@language} sets
7422 % \textsc{languagename} so that it has the correct value in the aux
7423 % file (eg, shorthand expansion was wrong)}
7424 % \changes{babel~3.0a}{1991/06/06}{Replaced \cs{gdef} with \cs{def}}
7425 % \changes{babel~3.1}{1991/10/31}{\cs{originalTeX} should only be
7427 % \changes{babel~3.2a}{1991/11/17}{Added three \cs{expandafter}s
7428 % to save macro space for \cs{originalTeX}}
7429 % \changes{babel~3.2a}{1991/11/20}{Moved definition of
7430 % \cs{originalTeX} before \cs{extras\langvar}}
7431 % \changes{babel~3.2a}{1991/11/24}{Set \cs{originalTeX} to
7432 % \cs{empty}, because it should be expandable.}
7433 % \changes{babel~3.6d}{1997/01/07}{set the language shorthands to
7434 % `none' before switching on the extras}
7435 % \changes{babel~3.9a}{2012/08/14}{Make sure the save counter is reset
7436 % even if \cs{originalTeX} is used in other contexts}
7437 % \changes{babel~3.9h}{2013/11/29}{Use \cs{def} instead of
7438 % \cs{renewcommand} for \cs{BabelLower}}
7439 % \changes{babel~3.9i}{2014/03/04}{Added `afterreset' hook}
7443 \expandafter\def\expandafter\originalTeX\expandafter{%
7444 \csname noextras#1\endcsname
7445 \let\originalTeX\@empty
7447 \bbl@usehooks{afterreset}{}%
7448 \languageshorthands{none}%
7449 \ifcase\bbl@select@type
7450 \csname captions#1\endcsname
7451 \csname date#1\endcsname
7453 \bbl@usehooks{beforeextras}{}%
7454 \csname extras#1\endcsname\relax
7455 \bbl@usehooks{afterextras}{}%
7456 \ifcase\bbl@hymapopt\or
7457 \def\BabelLower##1##2{\lccode##1=##2\relax}%
7458 \ifnum\bbl@hymapsel>4\else
7459 \csname\languagename @bbl@hyphenmap\endcsname
7461 \chardef\bbl@hymapopt\z@
7463 \ifnum\bbl@hymapsel>\bbl@hymapopt\else
7464 \csname\languagename @bbl@hyphenmap\endcsname
7467 \global\let\bbl@hymapsel\@cclv
7469 \babel@savevariable\lefthyphenmin
7470 \babel@savevariable\righthyphenmin
7471 \expandafter\ifx\csname #1hyphenmins\endcsname\relax
7472 \set@hyphenmins\tw@\thr@@\relax
7474 \expandafter\expandafter\expandafter\set@hyphenmins
7475 \csname #1hyphenmins\endcsname\relax
7479 \def\bbl@ifsamestring#1#2{%
7480 \protected@edef\bbl@tempb{#1}%
7481 \edef\bbl@tempb{\expandafter\strip@prefix\meaning\bbl@tempb}%
7482 \protected@edef\bbl@tempc{#2}%
7483 \edef\bbl@tempc{\expandafter\strip@prefix\meaning\bbl@tempc}%
7484 \ifx\bbl@tempb\bbl@tempc
7485 \expandafter\@firstoftwo
7487 \expandafter\@secondoftwo
7491 % \begin{environment}{otherlanguage}
7492 % The \Lenv{otherlanguage} environment can be used as an
7493 % alternative to using the |\selectlanguage| declarative
7494 % command. When you are typesetting a document which mixes
7495 % left-to-right and right-to-left typesetting you have to use this
7496 % environment in order to let things work as you expect them to.
7498 % The first thing this environment does is store the name of the
7499 % language in |\languagename|; it then calls
7500 % \verb*=\selectlanguage = to switch on everything that is needed for
7501 % this language The |\ignorespaces| command is necessary to hide
7502 % the environment when it is entered in horizontal mode.
7503 % \changes{babel~3.5d}{1995/06/22}{environment added}
7504 % \changes{babel~3.5e}{1995/07/07}{changed name}
7505 % \changes{babel~3.7j}{2003/03/18}{rely on \cs{selectlanguage } to
7506 % keep track of the nesting}
7507 % \changes{babel~3.9a}{2012/07/31}{Removed \cs{originalTeX}}
7509 \long\def\otherlanguage#1{%
7510 \ifnum\bbl@hymapsel=\@cclv\let\bbl@hymapsel\thr@@\fi
7511 \csname selectlanguage \endcsname{#1}%
7514 % The |\endotherlanguage| part of the environment tries to hide
7515 % itself when it is called in horizontal mode.
7517 \long\def\endotherlanguage{%
7518 \global\@ignoretrue\ignorespaces}
7522 % \begin{environment}{otherlanguage*}
7523 % The \Lenv{otherlanguage} environment is meant to be used when a
7524 % large part of text from a different language needs to be typeset,
7525 % but without changing the translation of words such as `figure'.
7526 % This environment makes use of |\foreign@language|.
7527 % \changes{babel~3.5f}{1996/05/29}{environment added}
7528 % \changes{babel~3.6d}{1997/01/07}{Introduced \cs{foreign@language}}
7530 \expandafter\def\csname otherlanguage*\endcsname#1{%
7531 \ifnum\bbl@hymapsel=\@cclv\chardef\bbl@hymapsel4\relax\fi
7532 \foreign@language{#1}}
7534 % At the end of the environment we need to switch off the extra
7535 % definitions. The grouping mechanism of the environment will take
7536 % care of resetting the correct hyphenation rules and ``extras''.
7538 \expandafter\let\csname endotherlanguage*\endcsname\relax
7542 % \begin{macro}{\foreignlanguage}
7543 % The |\foreignlanguage| command is another substitute for the
7544 % |\selectlanguage| command. This command takes two arguments, the
7545 % first argument is the name of the language to use for typesetting
7546 % the text specified in the second argument.
7548 % Unlike |\selectlanguage| this command doesn't switch
7549 % \emph{everything}, it only switches the hyphenation rules and the
7550 % extra definitions for the language specified. It does this within
7551 % a group and assumes the |\extras|\langvar\ command doesn't make
7552 % any |\global| changes. The coding is very similar to part of
7553 % |\selectlanguage|.
7554 % \changes{babel~3.5d}{1995/06/22}{Macro added}
7555 % \changes{babel~3.6d}{1997/01/07}{Introduced \cs{foreign@language}}
7556 % \changes{babel~3.7a}{1998/03/12}{Added executing \cs{originalTeX}}
7557 % \changes{babel~3.9a}{2012/07/30}{Removed unnecesary \cs{noextras}
7558 % just before closing the group}
7559 % \changes{babel~3.9a}{2012/07/31}{Moved \cs{originalTeX} to
7560 % \cs{foreing@language} so that it's also used in
7561 % \texttt{otherlanguage*}}
7562 % \changes{babel~3.9a}{2012/12/24}{\cs{foreignlanguage} defined
7563 % similarly to \cs{selectlanguage}, protecting the whole macro}
7565 \edef\foreignlanguage{%
7567 \expandafter\noexpand\csname foreignlanguage \endcsname}
7568 \expandafter\def\csname foreignlanguage \endcsname#1#2{%
7570 \foreign@language{#1}%
7576 % \begin{macro}{\foreign@language}
7577 % \changes{babel~3.6d}{1997/01/07}{New macro} This macro does the
7578 % work for |\foreignlanguage| and the \Lenv{otherlanguage*}
7579 % environment. First we need to store the name of the language and
7580 % check that it is a known language. Then it just calls
7582 % \changes{babel~3.9h}{2013/11/29}{The warning shows the language
7583 % actually selected (with fixed case)}
7585 \def\foreign@language#1{%
7586 \edef\languagename{#1}%
7587 \bbl@fixname\languagename
7588 \bbl@iflanguage\languagename{%
7589 \expandafter\ifx\csname date\languagename\endcsname\relax
7591 {You haven't loaded the language \languagename\space yet\\%
7592 I'll proceed, but expect unexpected results.\\%
7595 \let\bbl@select@type\@ne
7596 \expandafter\bbl@switch\expandafter{\languagename}}}
7600 % \begin{macro}{\bbl@patterns}
7601 % \changes{babel~3.8l}{2008/07/06}{Macro added}
7602 % \changes{babel~3.9a}{2012/08/28}{Extended to set hyphenation
7603 % exceptions as defined with \cs{babelhyphenation}}
7604 % \changes{babel~3.9m}{2015/07/25}{Preset \cs{bbl@pttnlist} and
7605 % \cs{bbl@patterns@} to relax, for luatex.}
7606 % This macro selects the hyphenation patterns by changing the
7607 % \cs{language} register. If special hyphenation patterns
7608 % are available specifically for the current font encoding,
7609 % use them instead of the default.
7611 % It also sets hyphenation exceptions, but only once, because they
7612 % are global (here language |\lccode|'s has been set,
7613 % too). |\bbl@hyphenation@| is set to relax until the very first
7614 % |\babelhyphenation|, so do nothing with this value. If the
7615 % exceptions for a language (by its number, not its name, so that
7616 % |:ENC| is taken into account) has been set, then use
7617 % |\hyphenation| with both global and language exceptions and empty
7618 % the latter to mark they must not be set again.
7620 \let\bbl@hyphlist\@empty
7621 \let\bbl@hyphenation@\relax
7622 \let\bbl@pttnlist\@empty
7623 \let\bbl@patterns@\relax
7624 \let\bbl@hymapsel=\@cclv
7625 \def\bbl@patterns#1{%
7626 \language=\expandafter\ifx\csname l@#1:\f@encoding\endcsname\relax
7627 \csname l@#1\endcsname
7628 \edef\bbl@tempa{#1}%
7630 \csname l@#1:\f@encoding\endcsname
7631 \edef\bbl@tempa{#1:\f@encoding}%
7633 \@expandtwoargs\bbl@usehooks{patterns}{{#1}{\bbl@tempa}}%
7634 \@ifundefined{bbl@hyphenation@}{}{%
7636 \@expandtwoargs\in@{,\number\language,}{,\bbl@hyphlist}%
7638 \@expandtwoargs\bbl@usehooks{hyphenation}{{#1}{\bbl@tempa}}%
7641 \@ifundefined{bbl@hyphenation@#1}%
7643 {\space\csname bbl@hyphenation@#1\endcsname}}%
7644 \xdef\bbl@hyphlist{\bbl@hyphlist\number\language,}%
7650 % \begin{environment}{hyphenrules}
7651 % \changes{babel~3.7e}{2000/01/28}{Added environment hyphenrules}
7652 % The environment \Lenv{hyphenrules} can be used to select
7653 % \emph{just} the hyphenation rules. This environment does
7654 % \emph{not} change |\languagename| and when the hyphenation rules
7655 % specified were not loaded it has no effect. Note however,
7656 % |\lccode|'s and font encodings are not set at all, so in most
7657 % cases you should use |otherlanguage*|.
7658 % \changes{babel~3.8j}{2008/03/16}{Also set the hyphenmin parameters to
7659 % the correct value (PR3997)}
7660 % \changes{babel~3.8l}{2008/07/06}{Use \cs{bbl@patterns}}
7662 \def\hyphenrules#1{%
7663 \edef\languagename{#1}%
7664 \bbl@fixname\languagename
7665 \bbl@iflanguage\languagename{%
7666 \expandafter\bbl@patterns\expandafter{\languagename}%
7667 \languageshorthands{none}%
7668 \expandafter\ifx\csname\languagename hyphenmins\endcsname\relax
7669 \set@hyphenmins\tw@\thr@@\relax
7671 \expandafter\expandafter\expandafter\set@hyphenmins
7672 \csname\languagename hyphenmins\endcsname\relax
7674 \let\endhyphenrules\@empty
7678 % \begin{macro}{\providehyphenmins}
7679 % \changes{babel~3.7f}{2000/02/18}{added macro}
7680 % The macro |\providehyphenmins| should be used in the language
7681 % definition files to provide a \emph{default} setting for the
7682 % hyphenation parameters |\lefthyphenmin| and |\righthyphenmin|. If
7683 % the macro |\|\langvar|hyphenmins| is already defined this command
7686 \def\providehyphenmins#1#2{%
7687 \expandafter\ifx\csname #1hyphenmins\endcsname\relax
7688 \@namedef{#1hyphenmins}{#2}%
7693 % \begin{macro}{\set@hyphenmins}
7694 % This macro sets the values of |\lefthyphenmin| and
7695 % |\righthyphenmin|. It expects two values as its argument.
7697 \def\set@hyphenmins#1#2{\lefthyphenmin#1\relax\righthyphenmin#2\relax}
7701 % \begin{macro}{\ProvidesLanguage}
7702 % \changes{babel~3.7a}{1997/03/18}{Added macro to prevent problems
7703 % with unexpected \cs{ProvidesFile} in plain formats because of
7705 % The identification code for each file is something that was
7706 % introduced in \LaTeXe. When the command |\ProvidesFile| does not
7707 % exist, a dummy definition is provided temporarily. For use in the
7708 % language definition file the command |\ProvidesLanguage| is
7709 % defined by \babel.
7711 % Depending on the format, ie, on if the former is defined, we use
7712 % a similar definition or not.
7713 % \changes{babel~3.4e}{1994/06/24}{Redid the identification code,
7714 % provided dummy definition of \cs{ProvidesFile} for plain \TeX}
7715 % \changes{babel~3.5f}{1995/07/26}{Store version in
7716 % \cs{fileversion}} \changes{babel~3.5f}{1995/12/18}{Need to
7717 % temporarily change the definition of \cs{ProvidesFile} for
7718 % December 1995 release} \changes{babel~3.5g}{1996/07/09}{Save a
7719 % few csnames; use \cs{bbl@tempa} instead of \cs{\@ProvidesFile}
7720 % and store message in \cs{toks8}}
7721 % \changes{babel~3.9a}{2012/12/09}{Save info about the babel
7722 % version in the format (switch.def) so that it can be checked
7723 % later if necessary}
7725 \ifx\ProvidesFile\@undefined
7726 \def\ProvidesLanguage#1[#2 #3 #4]{%
7727 \wlog{Language: #1 #4 #3 <#2>}%
7730 \def\ProvidesLanguage#1{%
7735 {\@provideslanguage{#1}}{\@provideslanguage{#1}[]}}
7736 \def\@provideslanguage#1[#2]{%
7737 \wlog{Language: #1 #2}%
7738 \expandafter\xdef\csname ver@#1.ldf\endcsname{#2}%
7744 % \begin{macro}{\LdfInit}
7745 % \changes{babel~3.6a}{1996/10/16}{Macro added}
7746 % This macro is defined in two versions. The first version is to be
7747 % part of the `kernel' of \babel, ie. the part that is loaded in
7748 % the format; the second version is defined in \file{babel.def}.
7749 % The version in the format just checks the category code of the
7750 % ampersand and then loads \file{babel.def}.
7752 % The category code of the ampersand is restored and the macro
7753 % calls itself again with the new definition from
7757 \chardef\atcatcode=\catcode`\@
7758 \catcode`\@=11\relax
7759 \input babel.def\relax
7760 \catcode`\@=\atcatcode \let\atcatcode\relax
7765 % \begin{macro}{\originalTeX}
7766 % The macro|\originalTeX| should be known to \TeX\ at this moment.
7767 % As it has to be expandable we |\let| it to |\@empty| instead of
7769 % \changes{babel~3.2a}{1991/11/24}{Set \cs{originalTeX} to
7770 % \cs{empty}, because it should be expandable.}
7772 \ifx\originalTeX\@undefined\let\originalTeX\@empty\fi
7774 % Because this part of the code can be included in a format, we
7775 % make sure that the macro which initialises the save mechanism,
7776 % |\babel@beginsave|, is not considered to be undefined.
7778 \ifx\babel@beginsave\@undefined\let\babel@beginsave\relax\fi
7782 % \subsection{Errors}
7784 % \begin{macro}{\@nolanerr}
7785 % \changes{babel~3.4e}{1994/06/25}{Use \cs{PackageError} in \LaTeXe\
7787 % \begin{macro}{\@nopatterns}
7788 % \changes{babel~3.4e}{1994/06/25}{Macro added}
7789 % The \babel\ package will signal an error when a documents tries
7790 % to select a language that hasn't been defined earlier. When a
7791 % user selects a language for which no hyphenation patterns were
7792 % loaded into the format he will be given a warning about that
7793 % fact. We revert to the patterns for |\language|=0 in that case.
7794 % In most formats that will be (US)english, but it might also be
7796 % \begin{macro}{\@noopterr}
7797 % \changes{babel~3.7m}{2003/11/16}{Macro added}
7798 % When the package was loaded without options not everything will
7799 % work as expected. An error message is issued in that case.
7801 % When the format knows about |\PackageError| it must be \LaTeXe,
7802 % so we can safely use its error handling interface. Otherwise
7803 % we'll have to `keep it simple'.
7804 % \changes{babel~3.0d}{1991/10/07}{Added a percent sign to remove
7805 % unwanted white space}
7806 % \changes{babel~3.5a}{1995/02/15}{Added \cs{@activated} to log active
7808 % \changes{babel~3.5c}{1995/06/19}{Added missing closing brace}
7809 % \changes{babel~3.9a}{2012/07/30}{\cs{newcommand}s replaced by
7810 % \cs{def}'s, so that the file can be loaded twice}
7811 % \changes{babel~3.9a}{2013/01/26}{Define generic variants instead of
7812 % duplicating each predefined message}
7814 \edef\bbl@nulllanguage{\string\language=0}
7815 \ifx\PackageError\@undefined
7816 \def\bbl@error#1#2{%
7819 \def\\{^^J(babel) }%
7820 \errhelp{#2}\errmessage{\\#1}%
7822 \def\bbl@warning#1{%
7825 \def\\{^^J(babel) }%
7835 \def\bbl@error#1#2{%
7837 \def\\{\MessageBreak}%
7838 \PackageError{babel}{#1}{#2}%
7840 \def\bbl@warning#1{%
7842 \def\\{\MessageBreak}%
7843 \PackageWarning{babel}{#1}%
7847 \def\\{\MessageBreak}%
7848 \PackageInfo{babel}{#1}%
7851 \@ifpackagewith{babel}{silent}
7852 {\let\bbl@info\@gobble
7853 \let\bbl@warning\@gobble}
7857 {You haven't defined the language #1\space yet}%
7858 {Your command will be ignored, type <return> to proceed}}
7859 \def\@nopatterns#1{%
7861 {No hyphenation patterns were preloaded for\\%
7862 the language `#1' into the format.\\%
7863 Please, configure your TeX system to add them and\\%
7864 rebuild the format. Now I will use the patterns\\%
7865 preloaded for \bbl@nulllanguage\space instead}}
7866 \let\bbl@usehooks\@gobbletwo
7873 % \section{Loading hyphenation patterns}
7875 % The following code is meant to be read by ini\TeX\ because it
7876 % should instruct \TeX\ to read hyphenation patterns. To this end the
7877 % \texttt{docstrip} option \texttt{patterns} can be used to include
7878 % this code in the file \file{hyphen.cfg}. Code is written with lower
7881 % |toks8| stores info to be shown when the program is run.
7883 % \changes{babel~3.9g}{2013/05/30}{Code moved from plain.def}
7884 % \changes{bbplain-1.0c}{1995/11/08}{Moved the \cs{dump} code here from
7886 % \changes{bbplain-0.1}{1991/10/31}{Added redefinition of \cs{dump} to
7887 % add a message to \cs{everyjob}}
7888 % We want to add a message to the message \LaTeX$\:$2.09 puts in
7889 % the |\everyjob| register. This could be done by the following
7892 % \let\orgeveryjob\everyjob
7895 % \orgeveryjob\expandafter{\the\orgeveryjob\immediate\write16{%
7896 % hyphenation patterns for \the\loaded@patterns loaded.}}%
7897 % \let\everyjob\orgeveryjob\let\orgeveryjob\@undefined}
7899 % The code above redefines the control sequence \cs{everyjob}
7900 % in order to be able to add something to the current contents of
7901 % the register. This is necessary because the processing of
7902 % hyphenation patterns happens long before \LaTeX\ fills the
7905 % There are some problems with this approach though.
7907 % \item When someone wants to use several hyphenation patterns with
7908 % \SliTeX\ the above scheme won't work. The reason is that \SliTeX\
7909 % overwrites the contents of the |\everyjob| register with its own
7911 % \item Plain \TeX\ does not use the |\everyjob| register so the
7912 % message would not be displayed.
7914 % To circumvent this a `dirty trick' can be used. As this code is
7915 % only processed when creating a new format file there is one
7916 % command that is sure to be used, |\dump|. Therefore the original
7917 % |\dump| is saved in |\org@dump| and a new definition is supplied.
7919 % To make sure that \LaTeX$\:$2.09 executes the
7920 % |\@begindocumenthook| we would want to alter |\begin{document}|,
7921 % but as this done too often already, we add the new code at the
7922 % front of |\@preamblecmds|. But we can only do that after it has
7923 % been defined, so we add this piece of code to |\dump|.
7924 % \changes{bbplain-1.0c}{1995/11/19}{Add execution of
7925 % \cs{@begindocumenthook} to \cs{@preamblecmds}}
7926 % \changes{bbplain-1.0i}{1997/01/02}{\cs{document} is not a
7927 % \LaTeX2.09-only command; AMS\TeX defines it too; now use
7928 % \cs{@ztryfc} to detect \LaTeX2.09}
7929 % \changes{bbplain-1.0j}{1997/01/07}{Add the definition of
7930 % \cs{@begindocumenthook} to the \LaTeX2.09 format}
7932 % This new definition starts by adding an instruction to write a
7933 % message on the terminal and in the transcript file to inform the
7934 % user of the preloaded hyphenation patterns.
7935 % \changes{bbplain-1.0f}{1996/07/09}{Use \cs{toks8} instead of
7936 % \cs{patterns@loaded}}
7938 % Then everything is restored to the old situation and the format
7943 <@Make sure ProvidesFile is defined@>
7944 \ProvidesFile{hyphen.cfg}[<@date@> <@version@> Babel hyphens]
7945 \xdef\bbl@format{\jobname}
7946 \ifx\AtBeginDocument\@undefined
7950 \ifx\@ztryfc\@undefined
7952 \toks0=\expandafter{\@preamblecmds}%
7953 \edef\@preamblecmds{\noexpand\@begindocumenthook\the\toks0}%
7954 \def\@begindocumenthook{}%
7956 \let\dump\orig@dump\let\orig@dump\@undefined\dump}
7958 <@Define core switching macros@>
7959 \toks8{Babel <<@version@>> and hyphenation patterns for }%
7962 % \changes{babel~3.5g}{1996/07/09}{Removed the use of
7963 % \cs{patterns@loaded} altogether}
7965 % \begin{macro}{\process@line}
7966 % \changes{babel~3.5b}{1995/04/28}{added macro}
7967 % Each line in the file \file{language.dat} is processed by
7968 % |\process@line| after it is read. The first thing this macro does
7969 % is to check whether the line starts with \texttt{=}.
7970 % When the first token of a line is an \texttt{=}, the macro
7971 % |\process@synonym| is called; otherwise the macro
7972 % |\process@language| will continue.
7973 % \changes{babel~3.5g}{1996/07/09}{Simplified code, removing
7975 % \changes{babel~3.9a}{2012/12/12}{Use spaces as delimiters, to avoid
7976 % extra spaces. Once parsed, pass them in the traditional way}
7978 \def\process@line#1#2 #3 #4 {%
7980 \process@synonym{#2}%
7982 \process@language{#1#2}{#3}{#4}%
7988 % \begin{macro}{\process@synonym}
7989 % \changes{babel~3.5b}{1995/04/28}{added macro}
7990 % \changes{babel~3.7c}{1999/04/27}{Use a token register to temporarily
7991 % store a command to set hyphenmin parameters for the synonym which
7992 % is defined \emph{before} the first pattern file is processed}
7994 % This macro takes care of the lines which start with an
7995 % \texttt{=}. It needs an empty token register to begin with.
7996 % |\bbl@languages| is also set to empty.
7999 \def\bbl@languages{}
8001 % When no languages have been loaded yet, the name following the
8002 % \texttt{=} will be a synonym for hyphenation register 0. So, it is stored
8003 % in a token register and executed when the first pattern file has
8004 % been processed. (The |\relax| just helps to the |\if| below
8005 % catching synonyms without a language.)
8007 % Otherwise the name will be a synonym for the language loaded last.
8009 % We also need to copy the hyphenmin parameters for the synonym.
8010 % \changes{babel~3.7c}{1999/04/22}{Now also store hyphenmin parameters
8011 % for language synonyms}
8012 % \changes{babel~3.9a}{2012/06/25}{Added \cs{bbl@languages}}
8014 \def\process@synonym#1{%
8015 \ifnum\last@language=\m@ne
8016 \toks@\expandafter{\the\toks@\relax\process@synonym{#1}}%
8018 \expandafter\chardef\csname l@#1\endcsname\last@language
8019 \wlog{\string\l@#1=\string\language\the\last@language}%
8020 \expandafter\let\csname #1hyphenmins\expandafter\endcsname
8021 \csname\languagename hyphenmins\endcsname
8023 \edef\bbl@languages{\bbl@languages\bbl@elt{#1}{\the\last@language}{}{}}%
8028 % \begin{macro}{\process@language}
8029 % The macro |\process@language| is used to process a non-empty line
8030 % from the `configuration file'. It has three arguments, each
8031 % delimited by white space. The first argument is the `name' of a
8032 % language; the second is the name of the file that contains the
8033 % patterns. The optional third argument is the name of a file
8034 % containing hyphenation exceptions.
8036 % The first thing to do is call |\addlanguage| to allocate a
8037 % pattern register and to make that register `active'.
8038 % \changes{babel~3.0d}{1991/08/08}{Removed superfluous
8040 % \changes{babel~3.0d}{1991/08/21}{Reinserted \cs{expandafter}}
8041 % \changes{babel~3.0d}{1991/10/27}{Added the collection of pattern
8043 % \changes{babel~3.7c}{1999/04/22}{Also store \cs{languagename} for
8044 % possible later use in \cs{process@synonym}}
8045 % Then the `name' of the language that will be loaded now is
8046 % added to the token register |\toks8|. and finally
8047 % the pattern file is read.
8048 % \changes{babel~3.7f}{2000/02/18}{Allow for the encoding to be used
8049 % as part of the language name}
8050 % \changes{babel~3.9a}{2012/12/10}{Removed \cs{selectfont} (I presume
8051 % it was intended to catch wrong encoding codes, but I don't think
8052 % this is necessary and as a side effect it might preload fonts)}
8054 % For some hyphenation patterns it is needed to load them with a
8055 % specific font encoding selected. This can be specified in the
8056 % file \file{language.dat} by adding for instance `\texttt{:T1}' to
8057 % the name of the language. The macro |\bbl@get@enc| extracts the
8058 % font encoding from the language name and stores it in
8059 % |\bbl@hyph@enc|. The latter can be used in hyphenation files if
8060 % you need to set a behaviour depending on the given encoding (it
8061 % is set to empty if no encoding is given).
8063 % \changes{babel~3.4e}{1994/06/24}{Added code to detect assignments to
8064 % left- and righthyphenmin in the patternfile.}
8065 % \changes{babel~3.7a}{1998/03/27}{Read pattern files in a group}
8066 % \changes{babel~3.7c}{1999/04/05}{need to set hyphenmin values
8068 % \changes{babel~3.7c}{1999/04/22}{Set \cs{lefthyphenmin} to \cs{m@ne}
8069 % \emph{inside} the group; explicitly set the hyphenmin parameters
8071 % \changes{babel~3.7c}{1999/04/25}{Only set hyphenmin values when the
8072 % pattern file changed them}
8073 % Pattern files may contain assignments to |\lefthyphenmin| and
8074 % |\righthyphenmin|. \TeX\ does not keep track of these
8075 % assignments. Therefore we try to detect such assignments and
8076 % store them in the |\|\langvar|hyphenmins| macro. When no
8077 % assignments were made we provide a default setting.
8079 % Some pattern files contain changes to the |\lccode| en |\uccode|
8080 % arrays. Such changes should remain local to the language;
8081 % therefore we process the pattern file in a group; the |\patterns|
8082 % command acts globally so its effect will be remembered.
8084 % Then we globally store the settings of |\lefthyphenmin| and
8085 % |\righthyphenmin| and close the group.
8087 % When the hyphenation patterns have been processed we need to see
8088 % if a file with hyphenation exceptions needs to be read. This is
8089 % the case when the third argument is not empty and when it does
8090 % not contain a space token. (Note however there is no need to save
8091 % hyphenation exceptions into the format.)
8092 % \changes{babel~3.5b}{1995/04/28}{Added optional reading of file with
8093 % hyphenation exceptions}
8094 % \changes{babel~3.5f}{1995/07/25}{Use \cs{empty} instead of
8095 % \cs{@empty} as the latter is unknown in plain}
8097 % \changes{babel~3.9a}{2012/06/25}{Added \cs{bbl@languages}}
8098 % \changes{babel~3.9f}{2013/05/16}{Restored code to set default
8099 % hyphenmins, which was deleted mistakenly}
8100 % \cs{bbl@languages} saves a snapshot of the loaded languagues in the
8101 % form \cs{bbl@elt}\marg{language-name}\marg{number}%
8102 % \marg{patterns-file}\marg{exceptions-file}. Note the last 2
8103 % arguments are empty in `dialects' defined in |language.dat| with
8104 % |=|. Note also the language name can have encoding info.
8106 % \changes{babel~3.7c}{1999/04/27}{Added the execution of the contents
8108 % Finally, if the counter |\language| is equal to zero we execute the
8111 \def\process@language#1#2#3{%
8112 \expandafter\addlanguage\csname l@#1\endcsname
8113 \expandafter\language\csname l@#1\endcsname
8114 \edef\languagename{#1}%
8115 \bbl@hook@everylanguage{#1}%
8116 \bbl@get@enc#1::\@@@
8119 \bbl@hook@loadpatterns{#2}%
8120 \ifnum\lefthyphenmin=\m@ne
8122 \expandafter\xdef\csname #1hyphenmins\endcsname{%
8123 \the\lefthyphenmin\the\righthyphenmin}%
8127 \ifx\bbl@tempa\@empty\else
8128 \bbl@hook@loadexceptions{#3}%
8131 \edef\bbl@languages{%
8132 \bbl@languages\bbl@elt{#1}{\the\language}{#2}{\bbl@tempa}}%
8133 \ifnum\the\language=\z@
8134 \expandafter\ifx\csname #1hyphenmins\endcsname\relax
8135 \set@hyphenmins\tw@\thr@@\relax
8137 \expandafter\expandafter\expandafter\set@hyphenmins
8138 \csname #1hyphenmins\endcsname
8145 % \begin{macro}{\bbl@get@enc}
8146 % \changes{babel~3.7f}{2000/02/18}{Added macro}
8147 % \changes{babel~3.9a}{2012/12/11}{Code much simplified}
8148 % \begin{macro}{\bbl@hyph@enc}
8149 % The macro |\bbl@get@enc| extracts the font encoding from the
8150 % language name and stores it in |\bbl@hyph@enc|. It uses delimited
8151 % arguments to achieve this.
8153 \def\bbl@get@enc#1:#2:#3\@@@{\def\bbl@hyph@enc{#2}}
8159 % Now, hooks are defined. For efficiency reasons, they are dealt
8160 % here in a special way. Besides \luatex, format specific
8161 % configuration files are taken into account.
8162 % \changes{babel~3.9b}{2013/03/25}{Fixed an idiot slip: \cs{def}
8163 % intead of \cs{let}}
8165 \def\bbl@hook@everylanguage#1{}
8166 \def\bbl@hook@loadpatterns#1{\input #1\relax}
8167 \let\bbl@hook@loadexceptions\bbl@hook@loadpatterns
8168 \let\bbl@hook@loadkernel\bbl@hook@loadpatterns
8170 \def\AddBabelHook#1#2{%
8171 \expandafter\ifx\csname bbl@hook@#2\endcsname\relax
8174 \def\next{\expandafter\gdef\csname bbl@hook@#2\endcsname####1}%
8177 \ifx\directlua\@undefined
8178 \ifx\XeTeXinputencoding\@undefined\else
8184 \openin1 = babel-\bbl@format.cfg
8187 \input babel-\bbl@format.cfg\relax
8191 \bbl@hook@loadkernel{switch.def}
8193 % \begin{macro}{\readconfigfile}
8194 % The configuration file can now be opened for reading.
8196 \openin1 = language.dat
8199 % See if the file exists, if not, use the default hyphenation file
8200 % \file{hyphen.tex}. The user will be informed about this.
8203 \def\languagename{english}%
8205 \message{I couldn't find the file language.dat,\space
8206 I will try the file hyphen.tex}
8207 \input hyphen.tex\relax
8208 \chardef\l@english\z@
8212 % Pattern registers are allocated using count register
8213 % |\last@language|. Its initial value is~0. The definition of the
8214 % macro |\newlanguage| is such that it first increments the count
8215 % register and then defines the language. In order to have the
8216 % first patterns loaded in pattern register number~0 we initialize
8217 % |\last@language| with the value~$-1$.
8219 % \changes{babel~3.1}{1991/05/21}{Removed use of \cs{toks0}}
8224 % We now read lines from the file until the end is found
8230 % While reading from the input, it is useful to switch off
8231 % recognition of the end-of-line character. This saves us stripping
8232 % off spaces from the contents of the control sequence.
8240 % \changes{babel~3.9a}{2012/12/14}{Test simplified and moved}
8241 % \changes{babel~3.9a}{2012/12/12}{Use only spaces as delimiters and
8242 % not /, as previouly done}
8244 % If the file has reached its end, exit from the loop here. If not,
8245 % empty lines are skipped. Add 3 space characters to the end of
8246 % |\bbl@line|. This is needed to be able to recognize the arguments
8247 % of |\process@line| later on. The default language should be the
8251 \if T\ifeof1F\fi T\relax
8252 \ifx\bbl@line\@empty\else
8253 \edef\bbl@line{\bbl@line\space\space\space}%
8254 \expandafter\process@line\bbl@line\relax
8259 % Check for the end of the file. We must reverse the test for
8260 % |\ifeof| without |\else|. Then reactivate the default patterns,
8261 % \changes{babel~3.8m}{2008/07/08}{Also restore the name of the
8262 % language in \cs{languagename} (PR 4039)}
8265 \def\bbl@elt#1#2#3#4{%
8266 \global\language=#2\relax
8267 \gdef\languagename{#1}%
8268 \def\bbl@elt##1##2##3##4{}}%
8273 % and close the configuration file.
8274 % \changes{babel~3.2a}{1991/11/20}{Free macro space for
8275 % \cs{process@language}}
8280 % \changes{babel~3.5f}{1995/11/08}{Moved the fiddling with \cs{dump}
8281 % to \file{bbplain.dtx} as it is no longer needed for \LaTeX}
8282 % We add a message about the fact that babel is loaded in the
8283 % format and with which language patterns to the \cs{everyjob}
8285 % \changes{babel~3.6h}{1997/01/23}{Added a couple of \cs{expandafter}s
8286 % to copy the contents of \cs{toks8} into \cs{everyjob} instead of
8288 % \changes{babel~3.9a}{2012/09/25}{The list of languages is not
8289 % printed every job any more (it is saved in \cs{bbl@languages}).}
8290 % \changes{babel~3.9g}{2013/07/28}{In non-LaTeX formats the number of
8291 % languages were not printed. Moved from \cs{dump} and cleaned up:
8292 % now \cs{toks}8 is expanded here.}
8293 % \changes{babel~3.9o}{2016/01/25}{The number of languages loaded was
8296 \if/\the\toks@/\else
8297 \errhelp{language.dat loads no language, only synonyms}
8298 \errmessage{Orphan language synonym}
8300 \advance\last@language\@ne
8304 \ifx\typeout\@undefined
8309 {\the\toks8 \the\last@language\space language(s) loaded.}}}
8310 \advance\last@language\m@ne
8313 % Also remove some macros from memory and raise an error
8314 % if |\toks@| is not empty. Finally load \file{switch.def}, but the
8315 % letter is not required and the line inputting it may be commented out.
8316 % \changes{babel~3.9a}{2012/12/11}{Raise error if there are synonyms
8317 % without languages}
8319 \let\bbl@line\@undefined
8320 \let\process@line\@undefined
8321 \let\process@synonym\@undefined
8322 \let\process@language\@undefined
8323 \let\bbl@get@enc\@undefined
8324 \let\bbl@hyph@enc\@undefined
8325 \let\bbl@tempa\@undefined
8326 \let\bbl@hook@loadkernel\@undefined
8327 \let\bbl@hook@everylanguage\@undefined
8328 \let\bbl@hook@loadpatterns\@undefined
8329 \let\bbl@hook@loadexceptions\@undefined
8332 % Here the code for ini\TeX\ ends.
8335 % \section{The `nil' language}
8337 % This `language' does nothing, except setting the hyphenation patterns to
8340 % For this language currently no special definitions are needed or
8343 % The macro |\LdfInit| takes care of preventing that this file is
8344 % loaded more than once, checking the category code of the
8345 % \texttt{@} sign, etc.
8348 \ProvidesLanguage{nil}[<@date@> <@version@> Nil language]
8349 \LdfInit{nil}{datenil}
8352 % When this file is read as an option, i.e. by the |\usepackage|
8353 % command, \texttt{nil} could be an `unknown' language in which
8354 % case we have to make it known.
8356 \ifx\l@nohyphenation\@undefined
8360 \let\l@nil\l@nohyphenation
8363 % This macro is used to store the values of the hyphenation
8364 % parameters |\lefthyphenmin| and |\righthyphenmin|.
8366 \providehyphenmins{\CurrentOption}{\m@ne\m@ne}
8369 % The next step consists of defining commands to switch to (and
8370 % from) the `nil' language.
8371 % \begin{macro}{\captionnil}
8372 % \begin{macro}{\datenil}
8374 \let\captionsnil\@empty
8380 % The macro |\ldf@finish| takes care of looking for a
8381 % configuration file, setting the main language to be switched on
8382 % at |\begin{document}| and resetting the category code of
8383 % \texttt{@} to its original value.
8389 % \changes{bbplain-1.0n}{1998/06/08}{Added the source for the format
8392 % \section{Support for Plain \TeX}
8394 % \subsection{Not renaming \file{hyphen.tex}}
8395 % As Don Knuth has declared that the filename \file{hyphen.tex} may
8396 % only be used to designate \emph{his} version of the american
8397 % English hyphenation patterns, a new solution has to be found in
8398 % order to be able to load hyphenation patterns for other languages
8399 % in a plain-based \TeX-format.
8400 % When asked he responded:
8402 % That file name is ``sacred'', and if anybody changes it they will
8403 % cause severe upward/downward compatibility headaches.
8405 % People can have a file localhyphen.tex or whatever they like,
8406 % but they mustn't diddle with hyphen.tex (or plain.tex except to
8407 % preload additional fonts).
8410 % The files \file{bplain.tex} and \file{blplain.tex} can be used as
8411 % replacement wrappers around \file{plain.tex} and
8412 % \file{lplain.tex} to acheive the desired effect, based on the
8413 % \pkg{babel} package. If you load each of them with ini\TeX, you
8414 % will get a file called either \file{bplain.fmt} or
8415 % \file{blplain.fmt}, which you can use as replacements for
8416 % \file{plain.fmt} and \file{lplain.fmt}.
8418 % As these files are going to be read as the first thing ini\TeX\
8419 % sees, we need to set some category codes just to be able to
8420 % change the definition of |\input|
8423 \catcode`\{=1 % left brace is begin-group character
8424 \catcode`\}=2 % right brace is end-group character
8425 \catcode`\#=6 % hash mark is macro parameter character
8427 % Now let's see if a file called \file{hyphen.cfg} can be found
8428 % somewhere on \TeX's input path by trying to open it for
8431 \openin 0 hyphen.cfg
8433 % If the file wasn't found the following test turns out true.
8438 % When \file{hyphen.cfg} could be opened we make sure that
8439 % \emph{it} will be read instead of the file \file{hyphen.tex}
8440 % which should (according to Don Knuth's ruling) contain the
8441 % american English hyphenation patterns and nothing else.
8443 % We do this by first saving the original meaning of |\input| (and
8444 % I use a one letter control sequence for that so as not to waste
8445 % multi-letter control sequence on this in the format).
8449 % Then |\input| is defined to forget about its argument and load
8450 % \file{hyphen.cfg} instead.
8456 % Once that's done the original meaning of |\input| can be restored
8457 % and the definition of |\a| can be forgotten.
8464 % Now that we have made sure that \file{hyphen.cfg} will be loaded
8465 % at the right moment it is time to load \file{plain.tex}.
8467 %<bplain>\a plain.tex
8468 %<blplain>\a lplain.tex
8470 % Finally we change the contents of |\fmtname| to indicate that
8471 % this is \emph{not} the plain format, but a format based on plain
8472 % with the \pkg{babel} package preloaded.
8474 %<bplain>\def\fmtname{babel-plain}
8475 %<blplain>\def\fmtname{babel-lplain}
8478 % When you are using a different format, based on plain.tex you can
8479 % make a copy of blplain.tex, rename it and replace \file{plain.tex}
8480 % with the name of your format file.
8482 % \subsection{Emulating some \LaTeX{} features}
8484 % The following code duplicates or emulates parts of \LaTeXe\ that
8485 % are needed for \babel.
8487 % \changes{bbplain-1.0f}{1996/07/09}{Consistently use \cs{@undefined}
8488 % instead of \cs{undefined}}
8489 % \changes{bbplain-1.0f}{1996/07/09}{added \cs{@empty}}
8490 % \changes{bbplain-1.0h}{1996/10/07}{Only load the necessary parts
8491 % into the format, let this file be read agian by babel.def}
8492 % \changes{bbplain-1.0h}{2012/12/21}{Use \cs{orig@dump} as flag to
8493 % decide if we are building the format, defined in hyphen.cfg}
8495 % We need to define |\loadlocalcfg| for plain users as the
8496 % \LaTeX\ definition uses |\InputIfFileExists|. We have to execute
8497 % \cs{@endofldf} in this case.
8498 % \changes{bbplain-1.0c}{1995/07/26}{Added definition of
8499 % \cs{loadlocalcfg}}
8500 % \changes{bbplain-1.0d}{1996/01/08}{Also reset category codes after
8501 % loading the configuration file as \cs{AtEndOfPackage} is
8502 % undefined in this case}
8503 % \changes{bbplain-1.0s}{2012/12/21}{\cs{loadlocalcfg} not loaded in
8508 \def\loadlocalcfg#1{%
8514 {\immediate\write16{*************************************}%
8515 \immediate\write16{* Local config file #1.cfg used}%
8516 \immediate\write16{*}%
8523 % \subsection{General tools}
8525 % A number of \LaTeX\ macro's that are needed later on.
8526 % \changes{bbplain-1.0n}{1998/06/10}{Added \cs{@secondoftwo}}
8527 % \changes{bbplain-1.0q}{1999/09/16}{Added \cs{@ifundefined}}
8528 % \changes{bbplain-1.0t}{2013/04/10}{Added \cs{@expandtwoargs}}
8529 % \changes{babel~3.9h}{2013/12/02}{Added \cs{zap@space}}
8530 % \changes{babel~3.9k}{2014/03/22}{Added \cs{@nnil}}
8531 % \changes{babel~3.9k}{2014/03/22}{Added \cs{@gobbletwo}}
8532 % \changes{babel~3.9k}{2014/03/22}{Added \cs{protected@edef}}
8534 \long\def\@firstofone#1{#1}
8535 \long\def\@firstoftwo#1#2{#1}
8536 \long\def\@secondoftwo#1#2{#2}
8538 \def\@gobbletwo#1#2{}
8539 \def\@ifstar#1{\@ifnextchar *{\@firstoftwo{#1}}}
8540 \def\@star@or@long#1{%
8542 {\let\l@ngrel@x\relax#1}%
8543 {\let\l@ngrel@x\long#1}}
8544 \let\l@ngrel@x\relax
8545 \def\@car#1#2\@nil{#1}
8546 \def\@cdr#1#2\@nil{#2}
8547 \let\@typeset@protect\relax
8548 \let\protected@edef\edef
8549 \long\def\@gobble#1{}
8550 \edef\@backslashchar{\expandafter\@gobble\string\\}
8551 \def\strip@prefix#1>{}
8552 \def\g@addto@macro#1#2{{%
8553 \toks@\expandafter{#1#2}%
8554 \xdef#1{\the\toks@}}}
8555 \def\@namedef#1{\expandafter\def\csname #1\endcsname}
8556 \def\@nameuse#1{\csname #1\endcsname}
8557 \def\@ifundefined#1{%
8558 \expandafter\ifx\csname#1\endcsname\relax
8559 \expandafter\@firstoftwo
8561 \expandafter\@secondoftwo
8563 \def\@expandtwoargs#1#2#3{%
8564 \edef\reserved@a{\noexpand#1{#2}{#3}}\reserved@a}
8565 \def\zap@space#1 #2{%
8567 \ifx#2\@empty\else\expandafter\zap@space\fi
8570 % \LaTeXe\ has the command |\@onlypreamble| which adds commands to
8571 % a list of commands that are no longer needed after
8572 % |\begin{document}|.
8574 \ifx\@preamblecmds\@undefined
8575 \def\@preamblecmds{}
8577 \def\@onlypreamble#1{%
8578 \expandafter\gdef\expandafter\@preamblecmds\expandafter{%
8579 \@preamblecmds\do#1}}
8580 \@onlypreamble\@onlypreamble
8582 % Mimick \LaTeX's |\AtBeginDocument|; for this to work the user
8583 % needs to add |\begindocument| to his file.
8585 \def\begindocument{%
8587 \global\let\@begindocumenthook\@undefined
8588 \def\do##1{\global\let##1\@undefined}%
8590 \global\let\do\noexpand}
8593 % \changes{bbplain-1.0j}{1997/01/07}{\cs{@begindocumenthook} might
8594 % already be defined}
8595 % \changes{bbplain-1.0k}{1997/01/14}{missing \cs{@undefined} added}
8597 \ifx\@begindocumenthook\@undefined
8598 \def\@begindocumenthook{}
8600 \@onlypreamble\@begindocumenthook
8601 \def\AtBeginDocument{\g@addto@macro\@begindocumenthook}
8603 % We also have to mimick \LaTeX's |\AtEndOfPackage|. Our
8604 % replacement macro is much simpler; it stores its argument in
8606 % \changes{babel~3.9h}{2013/11/28}{Set \cs{bbl@hymapopt} to 0 - we
8607 % presume hyphenmap=off in plain}
8609 \def\AtEndOfPackage#1{\g@addto@macro\@endofldf{#1}}
8610 \@onlypreamble\AtEndOfPackage
8612 \@onlypreamble\@endofldf
8613 \let\bbl@afterlang\@empty
8614 \chardef\bbl@hymapopt\z@
8616 % \LaTeX\ needs to be able to switch off writing to its auxiliary
8617 % files; plain doesn't have them by default.
8618 % \changes{bbplain-1.0m}{1997/04/28}{Set \cs{if@filesw} to
8619 % \cs{iffalse} only for plain \TeX}
8620 % \changes{bbplain-1.0n}{1997/09/11}{Repaired typo and added missing
8623 \ifx\if@filesw\@undefined
8624 \expandafter\let\csname if@filesw\expandafter\endcsname
8625 \csname iffalse\endcsname
8628 % Mimick \LaTeX's commands to define control sequences.
8629 % \changes{bbplain-1.0e}{1996/02/22}{Provide a more complete emulation
8630 % of \cs{DeclareRobustCommand} and \cs{newcommand}}
8632 \def\newcommand{\@star@or@long\new@command}
8633 \def\new@command#1{%
8634 \@testopt{\@newcommand#1}0}
8635 \def\@newcommand#1[#2]{%
8636 \@ifnextchar [{\@xargdef#1[#2]}%
8638 \long\def\@argdef#1[#2]#3{%
8639 \@yargdef#1\@ne{#2}{#3}}
8640 \long\def\@xargdef#1[#2][#3]#4{%
8641 \expandafter\def\expandafter#1\expandafter{%
8642 \expandafter\@protected@testopt\expandafter #1%
8643 \csname\string#1\expandafter\endcsname{#3}}%
8644 \expandafter\@yargdef \csname\string#1\endcsname
8646 \long\def\@yargdef#1#2#3{%
8648 \advance \@tempcnta \@ne
8650 \edef\reserved@a{\ifx#2\tw@ [\@hash@1]\fi}%
8652 \@whilenum\@tempcntb <\@tempcnta
8654 \edef\reserved@a{\reserved@a\@hash@\the\@tempcntb}%
8655 \advance\@tempcntb \@ne}%
8657 \l@ngrel@x\expandafter\def\expandafter#1\reserved@a}
8658 \def\providecommand{\@star@or@long\provide@command}
8659 \def\provide@command#1{%
8661 \escapechar\m@ne\xdef\@gtempa{{\string#1}}%
8663 \expandafter\@ifundefined\@gtempa
8664 {\def\reserved@a{\new@command#1}}%
8665 {\let\reserved@a\relax
8666 \def\reserved@a{\new@command\reserved@a}}%
8671 \def\DeclareRobustCommand{\@star@or@long\declare@robustcommand}
8672 \def\declare@robustcommand#1{%
8673 \edef\reserved@a{\string#1}%
8674 \def\reserved@b{#1}%
8675 \edef\reserved@b{\expandafter\strip@prefix\meaning\reserved@b}%
8677 \ifx\reserved@a\reserved@b
8682 \expandafter\noexpand\csname
8683 \expandafter\@gobble\string#1 \endcsname
8685 \expandafter\new@command\csname
8686 \expandafter\@gobble\string#1 \endcsname
8689 \ifx\protect\@typeset@protect\else
8693 \def\@x@protect#1\fi#2#3{%
8698 % The following little macro |\in@| is taken from \file{latex.ltx};
8699 % it checks whether its first argument is part of its second
8700 % argument. It uses the boolean |\in@|; allocating a new boolean
8701 % inside conditionally executed code is not possible, hence the
8702 % construct with the temporary definition of |\bbl@tempa|.
8703 % \changes{bbplain-1.0o}{1998/07/02}{Added definition of \cs{in@}}
8704 % \changes{bbplain-1.0s}{2013/01/15}{Use \cs{bbl@tempa} as
8707 \def\bbl@tempa{\csname newif\endcsname\ifin@}
8710 \def\in@@##1#1##2##3\in@@{%
8711 \ifx\in@##2\in@false\else\in@true\fi}%
8714 \let\bbl@tempa\@empty
8719 % \LaTeX\ has a macro to check whether a certain package was loaded
8720 % with specific options. The command has two extra arguments which
8721 % are code to be executed in either the true or false case.
8722 % This is used to detect whether the document needs one of the
8723 % accents to be activated (\Lopt{activegrave} and
8724 % \Lopt{activeacute}). For plain \TeX\ we assume that the user
8725 % wants them to be active by default. Therefore the only thing we
8726 % do is execute the third argument (the code for the true case).
8729 \def\@ifpackagewith#1#2#3#4{#3}
8731 % The \LaTeX\ macro |\@ifl@aded| checks whether a file was
8732 % loaded. This functionality is not needed for plain \TeX\ but we
8733 % need the macro to be defined as a no-op.
8734 % \changes{bbplain-1.0p}{1999/04/27}{Added \cs{@ifl@aded} as a no-op}
8736 \def\@ifl@aded#1#2#3#4{}
8739 % \changes{bbplain-1.0e}{1996/01/15}{Added the \cs{newcommand} code}
8740 % For the following code we need to make sure that the commands
8741 % |\newcommand| and |\providecommand| exist with some sensible
8742 % definition. They are not fully equivalent to their \LaTeXe\
8743 % versions; just enough to make things work in plain~\TeX
8746 % \changes{bbplain-1.0k}{1997/01/14}{\cs{newcount} is an \cs{outer}
8747 % command, can't use it inside an \cs{if} construct}
8748 % \changes{bbplain-1.0l}{1997/01/19}{Mixed up the definition of
8751 \ifx\@tempcnta\@undefined
8752 \csname newcount\endcsname\@tempcnta\relax
8754 \ifx\@tempcntb\@undefined
8755 \csname newcount\endcsname\@tempcntb\relax
8758 % To prevent wasting two counters in \LaTeX$\:$2.09 (because
8759 % counters with the same name are allocated later by it) we reset
8760 % the counter that holds the next free counter (|\count10|).
8763 \advance\count10 by -2\relax
8765 \ifx\@ifnextchar\@undefined
8766 \def\@ifnextchar#1#2#3{%
8768 \def\reserved@a{#2}\def\reserved@b{#3}%
8769 \futurelet\@let@token\@ifnch}
8771 \ifx\@let@token\@sptoken
8772 \let\reserved@c\@xifnch
8774 \ifx\@let@token\reserved@d
8775 \let\reserved@c\reserved@a
8777 \let\reserved@c\reserved@b
8781 \def\:{\let\@sptoken= } \: % this makes \@sptoken a space token
8782 \def\:{\@xifnch} \expandafter\def\: {\futurelet\@let@token\@ifnch}
8785 \@ifnextchar[{#1}{#1[#2]}}
8786 \def\@protected@testopt#1{%%
8787 \ifx\protect\@typeset@protect
8788 \expandafter\@testopt
8792 \long\def\@whilenum#1\do #2{\ifnum #1\relax #2\relax\@iwhilenum{#1\relax
8794 \long\def\@iwhilenum#1{\ifnum #1\expandafter\@iwhilenum
8795 \else\expandafter\@gobble\fi{#1}}
8798 % \subsection{Encoding related macros}
8800 % Code from \file{ltoutenc.dtx}, adapted for use in the plain \TeX\
8803 \def\DeclareTextCommand{%
8804 \@dec@text@cmd\providecommand
8806 \def\ProvideTextCommand{%
8807 \@dec@text@cmd\providecommand
8809 \def\DeclareTextSymbol#1#2#3{%
8810 \@dec@text@cmd\chardef#1{#2}#3\relax
8812 \def\@dec@text@cmd#1#2#3{%
8813 \expandafter\def\expandafter#2%
8815 \csname#3-cmd\expandafter\endcsname
8817 \csname#3\string#2\endcsname
8819 % \let\@ifdefinable\@rc@ifdefinable
8820 \expandafter#1\csname#3\string#2\endcsname
8822 \def\@current@cmd#1{%
8823 \ifx\protect\@typeset@protect\else
8824 \noexpand#1\expandafter\@gobble
8827 \def\@changed@cmd#1#2{%
8828 \ifx\protect\@typeset@protect
8829 \expandafter\ifx\csname\cf@encoding\string#1\endcsname\relax
8830 \expandafter\ifx\csname ?\string#1\endcsname\relax
8831 \expandafter\def\csname ?\string#1\endcsname{%
8832 \@changed@x@err{#1}%
8835 \global\expandafter\let
8836 \csname\cf@encoding \string#1\expandafter\endcsname
8837 \csname ?\string#1\endcsname
8839 \csname\cf@encoding\string#1%
8840 \expandafter\endcsname
8845 \def\@changed@x@err#1{%
8846 \errhelp{Your command will be ignored, type <return> to proceed}%
8847 \errmessage{Command \protect#1 undefined in encoding \cf@encoding}}
8848 \def\DeclareTextCommandDefault#1{%
8849 \DeclareTextCommand#1?%
8851 \def\ProvideTextCommandDefault#1{%
8852 \ProvideTextCommand#1?%
8854 \expandafter\let\csname OT1-cmd\endcsname\@current@cmd
8855 \expandafter\let\csname?-cmd\endcsname\@changed@cmd
8856 \def\DeclareTextAccent#1#2#3{%
8857 \DeclareTextCommand#1{#2}[1]{\accent#3 ##1}
8859 \def\DeclareTextCompositeCommand#1#2#3#4{%
8860 \expandafter\let\expandafter\reserved@a\csname#2\string#1\endcsname
8861 \edef\reserved@b{\string##1}%
8863 \expandafter\@strip@args\meaning\reserved@a:-\@strip@args}%
8864 \ifx\reserved@b\reserved@c
8865 \expandafter\expandafter\expandafter\ifx
8866 \expandafter\@car\reserved@a\relax\relax\@nil
8869 \edef\reserved@b##1{%
8870 \def\expandafter\noexpand
8871 \csname#2\string#1\endcsname####1{%
8872 \noexpand\@text@composite
8873 \expandafter\noexpand\csname#2\string#1\endcsname
8874 ####1\noexpand\@empty\noexpand\@text@composite
8878 \expandafter\reserved@b\expandafter{\reserved@a{##1}}%
8880 \expandafter\def\csname\expandafter\string\csname
8881 #2\endcsname\string#1-\string#3\endcsname{#4}
8883 \errhelp{Your command will be ignored, type <return> to proceed}%
8884 \errmessage{\string\DeclareTextCompositeCommand\space used on
8885 inappropriate command \protect#1}
8888 \def\@text@composite#1#2#3\@text@composite{%
8889 \expandafter\@text@composite@x
8890 \csname\string#1-\string#2\endcsname
8892 \def\@text@composite@x#1#2{%
8900 \def\@strip@args#1:#2-#3\@strip@args{#2}
8901 \def\DeclareTextComposite#1#2#3#4{%
8902 \def\reserved@a{\DeclareTextCompositeCommand#1{#2}{#3}}%
8911 \def\UseTextSymbol#1#2{%
8912 % \let\@curr@enc\cf@encoding
8913 % \@use@text@encoding{#1}%
8915 % \@use@text@encoding\@curr@enc
8917 \def\UseTextAccent#1#2#3{%
8918 % \let\@curr@enc\cf@encoding
8919 % \@use@text@encoding{#1}%
8920 % #2{\@use@text@encoding\@curr@enc\selectfont#3}%
8921 % \@use@text@encoding\@curr@enc
8923 \def\@use@text@encoding#1{%
8924 % \edef\f@encoding{#1}%
8926 % \csname\curr@fontshape/\f@size\endcsname
8932 \def\DeclareTextSymbolDefault#1#2{%
8933 \DeclareTextCommandDefault#1{\UseTextSymbol{#2}#1}%
8935 \def\DeclareTextAccentDefault#1#2{%
8936 \DeclareTextCommandDefault#1{\UseTextAccent{#2}#1}%
8938 \def\cf@encoding{OT1}
8940 % Currently we only use the \LaTeXe\ method for accents for those
8941 % that are known to be made active in \emph{some} language
8944 \DeclareTextAccent{\"}{OT1}{127}
8945 \DeclareTextAccent{\'}{OT1}{19}
8946 \DeclareTextAccent{\^}{OT1}{94}
8947 \DeclareTextAccent{\`}{OT1}{18}
8948 \DeclareTextAccent{\~}{OT1}{126}
8950 % The following control sequences are used in \file{babel.def}
8951 % but are not defined for \textsc{plain} \TeX.
8952 % \changes{bbplain-1.0f}{1996/07/10}{Added \cs{textquotedblright} and
8953 % \cs{textquoteright}}
8954 % \changes{bbplain-1.0g}{1996/08/15}{Added \cs{ss} and \cs{i}}
8955 % \changes{bbplain-1.0r}{2000/10/02}{Added \cs{textquotedblleft} and
8956 % \cs{textquoteleft}}
8958 \DeclareTextSymbol{\textquotedblleft}{OT1}{92}
8959 \DeclareTextSymbol{\textquotedblright}{OT1}{`\"}
8960 \DeclareTextSymbol{\textquoteleft}{OT1}{`\`}
8961 \DeclareTextSymbol{\textquoteright}{OT1}{`\'}
8962 \DeclareTextSymbol{\i}{OT1}{16}
8963 \DeclareTextSymbol{\ss}{OT1}{25}
8965 % For a couple of languages we need the \LaTeX-control sequence
8966 % |\scriptsize| to be available. Because plain \TeX\ doesn't have
8967 % such a sofisticated font mechanism as \LaTeX\ has, we just |\let|
8969 % \changes{bbplain-1.0f}{1996/07/10}{Added definition of
8972 \ifx\scriptsize\@undefined
8973 \let\scriptsize\sevenrm
8977 % \subsection{Babel options}
8979 % \changes{babel~3.9k}{2014/03/22}{Moved code from babel.def, and add
8980 % some new tools (not yet documented)}
8982 % The file |babel.def| expects some definitions made in the \LaTeX{}
8983 % style file. So we must provide them at least some predefined values as
8984 % well some tools to set them (even if not all options are
8985 % available). There in no package options, and therefore and alternative
8986 % mechanism is provided. For the moment, only |\babeloptionstrings| and
8987 % |\babeloptionmath| are provided, which can be defined before loading
8988 % \babel. |\BabelModifiers| can be set too (but not sure it works).
8991 \let\bbl@opt@shorthands\@nnil
8992 \def\bbl@ifshorthand#1#2#3{#2}%
8993 \ifx\babeloptionstrings\@undefined
8994 \let\bbl@opt@strings\@nnil
8996 \let\bbl@opt@strings\babeloptionstrings
8998 \def\bbl@tempa{normal}
8999 \ifx\babeloptionmath\bbl@tempa
9000 \def\bbl@mathnormal{\noexpand\textormath}
9002 \def\BabelStringsDefault{generic}
9003 \ifx\BabelModifiers\@undefined\let\BabelModifiers\relax\fi
9004 \let\bbl@afterlang\relax
9005 \let\bbl@language@opts\@empty
9006 \ifx\@uclclist\@undefined\let\@uclclist\@empty\fi
9007 \def\AfterBabelLanguage#1#2{}
9015 %% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
9016 %% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
9017 %% Digits \0\1\2\3\4\5\6\7\8\9
9018 %% Exclamation \! Double quote \" Hash (number) \#
9019 %% Dollar \$ Percent \% Ampersand \&
9020 %% Acute accent \' Left paren \( Right paren \)
9021 %% Asterisk \* Plus \+ Comma \,
9022 %% Minus \- Point \. Solidus \/
9023 %% Colon \: Semicolon \; Less than \<
9024 %% Equals \= Greater than \> Question mark \?
9025 %% Commercial at \@ Left bracket \[ Backslash \\
9026 %% Right bracket \] Circumflex \^ Underscore \_
9027 %% Grave accent \` Left brace \{ Vertical bar \|
9028 %% Right brace \} Tilde \~}