summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/babel/babel.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/source/latex/babel/babel.dtx')
-rw-r--r--Master/texmf-dist/source/latex/babel/babel.dtx399
1 files changed, 268 insertions, 131 deletions
diff --git a/Master/texmf-dist/source/latex/babel/babel.dtx b/Master/texmf-dist/source/latex/babel/babel.dtx
index 73602cb01aa..ca43f71b84f 100644
--- a/Master/texmf-dist/source/latex/babel/babel.dtx
+++ b/Master/texmf-dist/source/latex/babel/babel.dtx
@@ -31,7 +31,7 @@
%
% \iffalse
%<*filedriver>
-\ProvidesFile{babel.dtx}[2018/11/13 v3.27 The Babel package]
+\ProvidesFile{babel.dtx}[2019/04/01 v3.28 The Babel package]
\documentclass{ltxdoc}
\GetFileInfo{babel.dtx}
\usepackage{fontspec}
@@ -362,6 +362,15 @@ You can also set the main language explicitly:
\usepackage[_main=english_,dutch]{babel}
\end{verbatim}
+\begin{note}
+Some classes load \babel{} with a hardcoded language option. Sometimes,
+the main language could be overridden with something like that before
+|\documentclass|:
+\begin{verbatim}
+\PassOptionsToPackage{main=english}{babel}
+\end{verbatim}
+\end{note}
+
\begin{warning}
Languages may be set as global and as package option at the same
time, but in such a case you should set explicitly the main language
@@ -380,7 +389,7 @@ You can also set the main language explicitly:
want to use some of the language selectors described below.
\end{warning}
-To switch the language there are two basic macros, decribed below in
+To switch the language there are two basic macros, described below in
detail: |\selectlanguage| is used for blocks of text, while
|\foreignlanguage| is for chunks of text inside paragraphs.
@@ -969,7 +978,7 @@ three options have been available in previous versions.
\Describe{KeepShorthandsActive}{}
Tells babel not to deactivate shorthands after loading a language
-file, so that they are also availabe in the preamble.
+file, so that they are also available in the preamble.
\Describe{activeacute}{} For some languages \babel\ supports this
options to set |'| as a shorthand in case it is not done by default.
@@ -1855,7 +1864,7 @@ replace the red line above with, say:
|\babelfont| can be used to implicitly define a new font family. Just
write its name instead of |rm|, |sf| or |tt|. This is the preferred way
-to select fonts in addition to the three basic ones.
+to select fonts in addition to the three basic families.
\begin{example}
Here is how to do it:
@@ -1877,13 +1886,17 @@ to select fonts in addition to the three basic ones.
|dev2| (\luatex{} does not detect automatically the correct
script\footnote{And even with the correct code some fonts could be
rendered incorrectly by \textsf{fontspec}, so double check the
- results. \xetex{} fares better, but some font are still problematic.}).
+ results. \xetex{} fares better, but some font are still
+ problematic.}). You may also pass some options to \textsf{fontspec}:
+ with |silent|, the warnings about unavailable scripts or languages
+ are not shown (they are only really useful when the document format
+ is being set up).
\end{note}
\begin{note}
- Directionality is a property affecting margins, intentation, column
+ Directionality is a property affecting margins, indentation, column
order, etc., not just text. Therefore, it is under the direct
- control of the language, which appplies both the script and the
+ control of the language, which applies both the script and the
direction to the text. As a consequence, there is no need to set
\texttt{Script} when declaring a font (nor \texttt{Language}). In
fact, it is even discouraged.
@@ -1954,16 +1967,28 @@ unselected: |\noextras|\m{lang}.
\end{itemize}
\begin{note}
- These macros (|\captions|\m{lang}, |\extras|\m{lang}) may be redefined, but
- must not be used as such -- they just pass information to \babel{},
- which executes them in the proper context.
+ These macros (|\captions|\m{lang}, |\extras|\m{lang}) may be
+ redefined, but \textit{must not} be used as such -- they just pass
+ information to \babel{}, which executes them in the proper context.
\end{note}
+Another way to modify a language loaded as a package or class option
+is by means of |\babelprovide|, described below in depth. So,
+something like:
+\begin{verbatim}
+\usepackage[danish]{babel}
+\babelprovide[captions=da,hyphenrules=nohyphenation]{danish}
+\end{verbatim}
+first loads |danish.ldf|, and then redefines the captions for
+\texttt{danish} (as provided by the |ini| file) and prevents
+hyphenation. The rest of the language definitions are not touched.
+
\subsection{Creating a language}
-\New{3.10} And what if there is no style for your language or none
-fits your needs? You may then define quickly a language with the
-help of the following macro in the preamble.
+\New{3.10} And what if there is no style for your language or none fits
+your needs? You may then define quickly a language with the help of the
+following macro in the preamble (which may be used to modify an
+existing language, too, as explained in the previous subsection).
\Describe{\babelprovide}{\oarg{options}\marg{language-name}}
@@ -2054,7 +2079,7 @@ for example:
\babelprovide[hyphenrules=+]{neo}
\babelpatterns[neo]{a1 e1 i1 o1 u1}
\end{verbatim}
-In other engines it just supresses hyphenation (because the pattern
+In other engines it just suppresses hyphenation (because the pattern
list is empty).
\Describe{main}{} This valueless option makes the language the main
@@ -2080,14 +2105,15 @@ inconsistent, this makes setting a language up easier in most typical
cases.
\Describe{mapfont=}{\texttt{direction}}
-Assigns the font for the writing direction of this language. More
-precisely, what |mapfont=direction| means is, ‘when a character has the
-same direction as the script for the “provided” language, then change
-its font to that set for this language’. There are 3 directions,
-following the bidi Unicode algorithm, namely, Arabic-like, Hebrew-like
-and left to right.\footnote{In future realeases an new value
-(\texttt{script}) will be added.} So, there should be at most 3
-directives of this kind.
+Assigns the font for the writing direction of this
+language.\footnote{There will be another value, \texttt{language}, not
+yet implemented.} More precisely, what |mapfont=direction| means is,
+‘when a character has the same direction as the script for the
+“provided” language, then change its font to that set for this
+language’. There are 3 directions, following the bidi Unicode
+algorithm, namely, Arabic-like, Hebrew-like and left to
+right.\footnote{In future releases an new value (\texttt{script}) will
+be added.} So, there should be at most 3 directives of this kind.
\Describe{intraspace=}{\meta{base} \meta{shrink} \meta{stretch}}
Sets the interword space for the writing system of the language, in em
@@ -2095,7 +2121,7 @@ units (so, |0 .1 0| is |0em plus .1em|). Like |\spaceskip|, the em unit
applied is that of the current text (more precisely, the previous
glyph). Currently used only in Southeast Asian scrips, like Thai.
-\Describe{intrapenalty}{\meta{penalty}}
+\Describe{intrapenalty=}{\meta{penalty}}
Sets the interword penalty for the writing system of this language.
Currently used only in Southeast Asian scrips, like Thai. Ignored if 0
(which is the default value).
@@ -2174,20 +2200,20 @@ respectively.
\textit{explicit} or \textit{hard hyphens}, which in \TeX\ are
entered as \verb|-|, and (2) \textit{optional} or \textit{soft
hyphens}, which are entered as \verb|\-|. Strictly, a \textit{soft
-hyphen} is not a hyphen, but just a breaking oportunity or, in
+hyphen} is not a hyphen, but just a breaking opportunity or, in
\TeX\ terms, a ``discretionary''; a \textit{hard hyphen} is a hyphen
-with a breaking oportunity after it. A further type is a
+with a breaking opportunity after it. A further type is a
\textit{non-breaking hyphen}, a hyphen without a breaking
-oportunity.
+opportunity.
-In \TeX, \verb|-| and \verb|\-| forbid further breaking oportunities
+In \TeX, \verb|-| and \verb|\-| forbid further breaking opportunities
in the word. This is the desired behavior very often, but not always,
and therefore many languages provide shorthands for these
cases. Unfortunately, this has not been done consistently: for
example, \verb|"-| in Dutch, Portugese, Catalan or Danish is a hard
hyphen, while in German, Spanish, Norwegian, Slovak or Russian is a
soft hyphen. Furthermore, some of them even redefine |\-|, so that you
-cannot insert a soft hyphen without breaking oportunities in the rest
+cannot insert a soft hyphen without breaking opportunities in the rest
of the word.
Therefore, some macros are provide with a set of basic ``hyphens''
@@ -2290,7 +2316,7 @@ Some languages sharing the same script define macros to switch it (eg,
|\textcyrillic|), but be aware they may also set the language to a
certain default. Even the \babel{} core defined |\textlatin|, but is
was somewhat buggy because in some cases it messed up encodings and
-fonts (for example, if the main latin encoding was |LY1|), and
+fonts (for example, if the main Latin encoding was |LY1|), and
therefore it has been deprecated.\footnote{But still defined for
backwards compatibility.}
@@ -2315,7 +2341,7 @@ used for ``ordinary'' text (they are stored in |\BabelNonText|, used
in some special cases when no Latin encoding is explicitly set).
The foregoing rules (which are applied ``at begin document'') cover
-most of cases. No asumption is made on characters above
+most of cases. No assumption is made on characters above
127, which may not follow the LICR conventions -- the goal is just
to ensure most of the ASCII letters and symbols are the right ones.
@@ -2337,8 +2363,8 @@ differ in the way `weak' numeric characters are ordered (eg, Arabic
A basic stable version for other engines must wait very likely until
(Northern) Winter. This applies to text, but \textbf{graphical}
elements, including the |picture| environment and PDF or PS based
- graphics, are not yet correctly handled. Also, indexes and the like
- are under study, as well as math.
+ graphics, are not yet correctly handled (far from trivial). Also,
+ indexes and the like are under study, as well as math.
An effort is being made to avoid incompatibilities in the future
(this one of the reason currently bidi must be explicitly requested
@@ -2406,7 +2432,7 @@ _\babelprovide[import, main]{arabic}_
mixed without explicit markup (the latter will be only necessary in
some special cases where the Unicode algorithm fails). It is used much
like |bidi=basic-r|, but with R text inside L text you may want to map
- the font so that the correct features are in force. This is accomplised
+ the font so that the correct features are in force. This is accomplished
with an option in |\babelprovide|, as illustrated:
\begingroup
% If you are looking at the code to see how it has been written, you
@@ -2469,7 +2495,7 @@ _\babelprovide[import, main]{arabic}_
\New{3.16} \textit{To be expanded}. Selects which layout elements are
adapted in bidi documents, including some text elements. You may use
-several options with a comma-separated list (eg,
+several options with a dot-separated list (eg,
|layout=counters.contents.sectioning|). This list will be expanded in
future releases (tables, captions, etc.). Note not all options are
required by all engines.
@@ -2526,7 +2552,7 @@ required by all engines.
future); ignored in \pdftex{} or \xetex{} (which will not support a
similar option in the short term) \New{3.18},
-\item[extras] is used for miscelaneous readjustments which do not fit into
+\item[extras] is used for miscellaneous readjustments which do not fit into
the previous groups. Currently redefines in \luatex{} |\underline| and
|\LaTeX2e| \New{3.19}.
\end{description}
@@ -2549,7 +2575,7 @@ RTL A ltr text \thechapter{} and still ltr RTL B
\end{verbatim}
There are \textit{three} R blocks and \textit{two} L blocks, and the
order is \textit{RTL B and still ltr 1 ltr text RTL A}. This is by
-design to provide the proper behaviour in the most usual cases — but if
+design to provide the proper behavior in the most usual cases — but if
you need to use |\ref| in an L text inside R, the L text must be marked
up explictly; for example:
\begin{verbatim}
@@ -2625,7 +2651,7 @@ Very often, using a \textit{modifier} in a package option is better.
Several language definition files use their own methods to set
options. For example, \textsf{french} uses |\frenchsetup|,
\textsf{magyar} (1.5) uses |\magyarOptions|; modifiers provided by
-|spanish| have no attribute counterparts. Macros settting
+|spanish| have no attribute counterparts. Macros setting
options are also used (eg, |\ProsodicMarksOn| in \textsf{latin}).
\subsection{Hooks}
@@ -2882,16 +2908,16 @@ some languages (kerning and spacing). Ligatures can be disabled.
\subsection{Current and future work}
Current work is focused on the so-called complex scripts in \luatex{}.
-In 8-bit engines, \babel{} provided a basic support for bidi text as part
-of the style for Hebrew, but it is somewhat unsatisfactory and
-internally replaces some hardwired commands by other hardwired
-commands (generic changes would be much better).
+In 8-bit engines, \babel{} provided a basic support for bidi text as
+part of the style for Hebrew, but it is somewhat unsatisfactory and
+internally replaces some hardwired commands by other hardwired commands
+(generic changes would be much better).
-It is possible now to typeset Arabic or Hebrew with numbers and L
-text. Next on the roadmap are line breaking in Thai and the like,
-as well as “non-European” digits. Also on the roadmap are R layouts
-(lists, footnotes, tables, column order), page and section numbering,
-and maybe kashida justification.
+It is possible now to typeset Arabic or Hebrew with numbers and L text.
+Next on the roadmap are line breaking in Thai and the like. Also on the
+roadmap are better support for R layouts (lists, footnotes, tables,
+column order), page and section numbering, and maybe kashida
+justification.
Useful additions would be, for example, time, currency, addresses and
personal names.\footnote{See for example POSIX, ISO 14652 and the
@@ -2975,7 +3001,7 @@ So, for example:
\TeX{} and most engines based on it (pdf\TeX, \xetex, $\epsilon$-\TeX,
the main exception being \luatex) require hyphenation patterns to be
preloaded when a format is created (eg, \LaTeX, Xe\LaTeX,
-pdf\LaTeX). \babel{} provides a tool which has become standand in many
+pdf\LaTeX). \babel{} provides a tool which has become standard in many
distributions and based on a ``configuration file'' named
\file{language.dat}. The exact way this file is used depends on the
distribution, so please, read the documentation for the latter (note
@@ -3029,7 +3055,7 @@ didn't work correctly.} For example:
german:T1 hyphenT1.ger
german hyphen.ger
\end{verbatim}
-With the previous settings, if the enconding when the language is
+With the previous settings, if the encoding when the language is
selected is |T1| then the patterns in \file{hyphenT1.ger} are
used, but otherwise use those in \file{hyphen.ger} (note the encoding
could be set in |\extras|\m{lang}).
@@ -3079,7 +3105,7 @@ The following assumptions are made:
\item When a language definition file is loaded, it can define
|\l@|\langvar\ to be a dialect of |\language0| when |\l@|\langvar\
is undefined.
-\item Language names must be all lowercase. If an unknow language is
+\item Language names must be all lowercase. If an unknown language is
selected, \babel{} will attempt setting it after lowercasing its
name.
\item The semantics of modifiers is not defined (on purpose). In
@@ -3197,7 +3223,7 @@ definition files to set |\lefthyphenmin| and
|\righthyphenmin|. This macro will check whether these parameters
were provided by the hyphenation file before it takes any action.
If these values have been already set, this command is ignored
-(currenty, default pattern files do \textit{not} set them).
+(currently, default pattern files do \textit{not} set them).
\DescribeMacro{\captions\langvar}
The macro |\captions|\langvar\ defines the macros that
@@ -3324,6 +3350,23 @@ explained in in sec. \ref{s:strings} (\babel{} 3.9 and later).
\ldf@finish{<language>}
\end{verbatim}
+\begin{note}
+ If for some reason you want to load a package in your style, you
+ should be aware it cannot be done directly in the \texttt{ldf} file,
+ but it can be delayed with |\AtEndOfPackage|. Macros from external
+ packages can be used \textit{inside} definitions in the \textsf{ldf}
+ itself (for example, |\extras<language>|), but if executed directly,
+ the code must be placed inside |\AtEndOfPackage|. A trivial example
+ illustrating these points is:
+\begin{verbatim}
+\AtEndOfPackage{%
+ \RequirePackage{dingbat}% Delay package
+ \savebox{\myeye}{\eye}}% And direct usage
+\newsavebox{\myeye}
+\newcommand\myanchor{\anchor}% But OK inside command
+\end{verbatim}
+\end{note}
+
\subsection{Support for active characters}
In quite a number of language definition files, active characters are
@@ -3486,9 +3529,9 @@ the first one take precedence (ie, it works much like
|\providecommand|).
Encoding info is |charset=| followed by a charset, which if given sets
-how the strings should be traslated to the internal representation
+how the strings should be translated to the internal representation
used by the engine, typically |utf8|, which is the only value
-supported currently (default is no traslations). Note |charset| is
+supported currently (default is no translations). Note |charset| is
applied by \luatex{} and \xetex{} when reading the file, not when the
macro or string is used in the document.
@@ -3507,7 +3550,7 @@ into account except those). With |strings=encoded|, strings in those
blocks are set as default (internally, |?|). With |strings=encoded|
strings are protected, but they are correctly expanded in
|\MakeUppercase| and the like. If there is no key |strings|, string
-definitions are ignored, but |\SetCase|s are still honoured (in a
+definitions are ignored, but |\SetCase|s are still honored (in a
|encoded| way).
The \m{category} is either |captions|, |date| or |extras|. You must
@@ -3568,7 +3611,7 @@ A real example is:
\end{verbatim}
When used in |ldf| files, previous values of |\|\m{category}\m{language}
-are overriden, which means the old way to define strings still works
+are overridden, which means the old way to define strings still works
and used by default (to be precise, is first set to undefined and then
strings are added). However, when used in the preamble or in a
package, new settings are added to the previous ones, if the language
@@ -3582,7 +3625,7 @@ as package option, then the default for the engine is used. This is
not done by default to prevent backward incompatibilities, but if you
are creating a new language this version is better. It's up to
the maintainers of the current languages to decide if using it is
-appropiate.\footnote{This replaces in 3.9g a short-lived
+appropriate.\footnote{This replaces in 3.9g a short-lived
\texttt{\string\UseStrings} which has been removed because it did
not work.}
@@ -3621,7 +3664,7 @@ changes in lc/uc codes may not work). A \meta{map-list} is a series of
macros using the internal format of |\@uclclist| (eg,
|\bb\BB\cc\CC|). The mandatory arguments take precedence over the
optional one. This command, unlike |\SetString|, is executed always
-(even without |strings|), and it is intented for minor readjustments
+(even without |strings|), and it is intended for minor readjustments
only.
For example, as |T1| is the default case mapping in \LaTeX, we could
@@ -3874,8 +3917,8 @@ help from Bernd Raichle, for which I am grateful.
% \section{Tools}
%
% \begin{macrocode}
-%<<version=3.27>>
-%<<date=2018/11/13>>
+%<<version=3.28>>
+%<<date=2019/04/01>>
% \end{macrocode}
%
% \textbf{Do not use the following macros in \texttt{ldf} files. They
@@ -7778,9 +7821,8 @@ help from Bernd Raichle, for which I am grateful.
{\bbl@ifblank{#1}%
{\bbl@error
{If you want to modify `#2' you must tell how in\\%
- the optional argument. Currently there are three\\%
- options: captions=lang-tag, hyphenrules=lang-list\\%
- import=lang-tag}%
+ the optional argument. See the manual for the\\%
+ available options.}%
{Use this macro as documented}}%
{\bbl@provide@renew{#2}}}%
% Post tasks
@@ -8080,9 +8122,9 @@ help from Bernd Raichle, for which I am grateful.
\@nameuse{bbl@secpost@\bbl@section}% ends previous section
\def\bbl@section{#1}%
\@nameuse{bbl@secpre@\bbl@section}% starts current section
- \bbl@ifunset{bbl@secline@#1}%
+ \bbl@ifunset{bbl@inikv@#1}%
{\let\bbl@inireader\bbl@iniskip}%
- {\bbl@exp{\let\\\bbl@inireader\<bbl@secline@#1>}}}
+ {\bbl@exp{\let\\\bbl@inireader\<bbl@inikv@#1>}}}
% \end{macrocode}
%
% Reads a key=val line and stores the trimmed val in
@@ -8114,7 +8156,7 @@ help from Bernd Raichle, for which I am grateful.
% |identification| and |typography|.
%
% \begin{macrocode}
-\let\bbl@secline@identification\bbl@inikv
+\let\bbl@inikv@identification\bbl@inikv
\def\bbl@secpost@identification{%
\bbl@exportkey{lname}{identification.name.english}{}%
\bbl@exportkey{lbcp}{identification.tag.bcp47}{}%
@@ -8122,9 +8164,9 @@ help from Bernd Raichle, for which I am grateful.
\bbl@exportkey{sname}{identification.script.name}{}%
\bbl@exportkey{sbcp}{identification.script.tag.bcp47}{}%
\bbl@exportkey{sotf}{identification.script.tag.opentype}{DFLT}}
-\let\bbl@secline@typography\bbl@inikv
-\let\bbl@secline@characters\bbl@inikv
-\let\bbl@secline@numbers\bbl@inikv
+\let\bbl@inikv@typography\bbl@inikv
+\let\bbl@inikv@characters\bbl@inikv
+\let\bbl@inikv@numbers\bbl@inikv
\def\bbl@after@ini{%
\bbl@exportkey{lfthm}{typography.lefthyphenmin}{2}%
\bbl@exportkey{rgthm}{typography.righthyphenmin}{3}%
@@ -8153,21 +8195,17 @@ help from Bernd Raichle, for which I am grateful.
% \end{macrocode}
%
% Now |captions| and |captions.licr|, depending on the engine. And
-% also for dates. They rely on a few auxilary macros.
+% below also for dates. They rely on a few auxiliary macros. It is
+% expected the ini file provides the complete set in Unicode and LICR,
+% in that order.
%
% \begin{macrocode}
\ifcase\bbl@engine
- \bbl@csarg\def{secline@captions.licr}#1=#2\@@{%
+ \bbl@csarg\def{inikv@captions.licr}#1=#2\@@{%
\bbl@ini@captions@aux{#1}{#2}}
- \bbl@csarg\def{secline@date.gregorian}#1=#2\@@{% for defaults
- \bbl@ini@dategreg#1...\relax{#2}}
- \bbl@csarg\def{secline@date.gregorian.licr}#1=#2\@@{% override
- \bbl@ini@dategreg#1...\relax{#2}}
\else
- \def\bbl@secline@captions#1=#2\@@{%
+ \def\bbl@inikv@captions#1=#2\@@{%
\bbl@ini@captions@aux{#1}{#2}}
- \bbl@csarg\def{secline@date.gregorian}#1=#2\@@{%
- \bbl@ini@dategreg#1...\relax{#2}}
\fi
% \end{macrocode}
%
@@ -8186,22 +8224,41 @@ help from Bernd Raichle, for which I am grateful.
% \end{macrocode}
%
% But dates are more complex. The full date format is stores in
-% |date.gregorian|, so we must read it in non-Unicode engines, too.
+% |date.gregorian|, so we must read it in non-Unicode engines, too
+% (saved months are just discarded when the LICR section is reached).
%
-% \changes{3.16}{2018/01/02}{Fix - dates were severely broken.}
+% TODO. Remove copypaste pattern.
%
-% \begin{macrocode}
-\bbl@csarg\def{secpre@date.gregorian.licr}{%
- \ifcase\bbl@engine\let\bbl@savedate\@empty\fi}
-\def\bbl@ini@dategreg#1.#2.#3.#4\relax#5{% TODO - ignore with 'captions'
+% \changes{3.16}{2018/01/02}{Fix - dates were severely broken.}
+% \changes{3.28}{2019/04/01}{Start work on calendars.}
+%
+% \begin{macrocode}
+\bbl@csarg\def{inikv@date.gregorian}#1=#2\@@{% for defaults
+ \bbl@inidate#1...\relax{#2}{}}
+\bbl@csarg\def{inikv@date.islamic}#1=#2\@@{%
+ \bbl@inidate#1...\relax{#2}{islamic}}
+\bbl@csarg\def{inikv@date.hebrew}#1=#2\@@{%
+ \bbl@inidate#1...\relax{#2}{hebrew}}
+\bbl@csarg\def{inikv@date.persian}#1=#2\@@{%
+ \bbl@inidate#1...\relax{#2}{persian}}
+\bbl@csarg\def{inikv@date.indian}#1=#2\@@{%
+ \bbl@inidate#1...\relax{#2}{indian}}
+\ifcase\bbl@engine
+ \bbl@csarg\def{inikv@date.gregorian.licr}#1=#2\@@{% override
+ \bbl@inidate#1...\relax{#2}{}}
+ \bbl@csarg\def{secpre@date.gregorian.licr}{% discard uni
+ \ifcase\bbl@engine\let\bbl@savedate\@empty\fi}
+\fi
+% eg: 1=months, 2=wide, 3=1, 4=dummy
+\def\bbl@inidate#1.#2.#3.#4\relax#5#6{% TODO - ignore with 'captions'
\bbl@trim@def\bbl@tempa{#1.#2}%
- \bbl@ifsamestring{\bbl@tempa}{months.wide}%
+ \bbl@ifsamestring{\bbl@tempa}{months.wide}% to savedate
{\bbl@trim@def\bbl@tempa{#3}%
\bbl@trim\toks@{#5}%
\bbl@exp{%
\\\bbl@add\\\bbl@savedate{%
- \\\SetString\<month\romannumeral\bbl@tempa name>{\the\toks@}}}}%
- {\bbl@ifsamestring{\bbl@tempa}{date.long}%
+ \\\SetString\<month\romannumeral\bbl@tempa#6name>{\the\toks@}}}}%
+ {\bbl@ifsamestring{\bbl@tempa}{date.long}% defined now
{\bbl@trim@def\bbl@toreplace{#5}%
\bbl@TG@@date
\global\bbl@csarg\let{date@\languagename}\bbl@toreplace
@@ -8220,9 +8277,10 @@ help from Bernd Raichle, for which I am grateful.
% Dates will require some macros for the basic formatting. They may be
% redefined by language, so ``semi-public'' names (camel case) are
% used. Oddly enough, the CLDR places particles like “de”
-% inconsistenly in either in the date or in the month name.
+% inconsistently in either in the date or in the month name.
%
% \begin{macrocode}
+\let\bbl@calendar\@empty
\newcommand\BabelDateSpace{\nobreakspace}
\newcommand\BabelDateDot{.\@}
\newcommand\BabelDated[1]{{\number#1}}
@@ -8230,7 +8288,7 @@ help from Bernd Raichle, for which I am grateful.
\newcommand\BabelDateM[1]{{\number#1}}
\newcommand\BabelDateMM[1]{{\ifnum#1<10 0\fi\number#1}}
\newcommand\BabelDateMMMM[1]{{%
- \csname month\romannumeral#1name\endcsname}}%
+ \csname month\romannumeral#1\bbl@calendar name\endcsname}}%
\newcommand\BabelDatey[1]{{\number#1}}%
\newcommand\BabelDateyy[1]{{%
\ifnum#1<10 0\number#1 %
@@ -9170,6 +9228,8 @@ help from Bernd Raichle, for which I am grateful.
% \changes{3.15}{2017/10/30}{Use an attribute instead of tex language
% (reserved for hyphenation).}
% \changes{3.15}{2017/10/30}{Store direction in @wdir@<lang>.}
+% \changes{3.28}{2019/04/01}{Dir in boxes within math and other
+% contexts (passim).}
%
% \begin{macrocode}
\bbl@trace{Basic (internal) bidi support}
@@ -9205,6 +9265,7 @@ help from Bernd Raichle, for which I am grateful.
\ifodd\bbl@engine % luatex=1
\AddBabelHook{babel-bidi}{afterextras}{\bbl@switchdir}
\DisableBabelHook{babel-bidi}
+ \chardef\bbl@thetextdir\z@
\chardef\bbl@thepardir\z@
\def\bbl@getluadir#1{%
\directlua{
@@ -9225,12 +9286,24 @@ help from Bernd Raichle, for which I am grateful.
\fi}
\def\bbl@textdir#1{%
\bbl@setluadir{text}\textdir{#1}% TODO - ?\linedir
+ \chardef\bbl@thetextdir#1\relax
\setattribute\bbl@attr@dir{\numexpr\bbl@thepardir*3+#1}}
- \def\bbl@pardir#1{\bbl@setluadir{par}\pardir{#1}%
+ \def\bbl@pardir#1{%
+ \bbl@setluadir{par}\pardir{#1}%
\chardef\bbl@thepardir#1\relax}
\def\bbl@bodydir{\bbl@setluadir{body}\bodydir}
\def\bbl@pagedir{\bbl@setluadir{page}\pagedir}
\def\bbl@dirparastext{\pardir\the\textdir\relax}% %%%%
+ % Sadly, we have to deal with boxes in math with basic:
+ \def\bbl@mathboxdir{%
+ \ifcase\bbl@thetextdir\relax
+ \everyhbox{\bgroup\aftergroup\egroup\textdir TLT\relax}%
+ \else
+ \everyhbox{\bgroup\aftergroup\egroup\textdir TRT\relax}%
+ \fi}
+ % TODO - the same trick as bbl@severypar
+ \everymath{\bbl@mathboxdir}
+ \everydisplay{\bbl@mathboxdir}
\else % pdftex=0, xetex=2
\AddBabelHook{babel-bidi}{afterextras}{\bbl@switchdir}
\DisableBabelHook{babel-bidi}
@@ -9316,12 +9389,19 @@ help from Bernd Raichle, for which I am grateful.
\fi
% \end{macrocode}
%
-% A tool for weak L (mainly digits).
+% A tool for weak L (mainly digits). We also disable warnings with
+% \textsf{hyperref}.
%
% \changes{3.16}{2018/01/02}{New macro \cs{babelsublr}}
%
% \begin{macrocode}
- \DeclareRobustCommand\babelsublr[1]{\leavevmode{\bbl@textdir\z@#1}}
+\DeclareRobustCommand\babelsublr[1]{\leavevmode{\bbl@textdir\z@#1}}
+\AtBeginDocument{%
+ \ifx\pdfstringdefDisableCommands\@undefined\else
+ \ifx\pdfstringdefDisableCommands\relax\else
+ \pdfstringdefDisableCommands{\let\babelsublr\@firstofone}%
+ \fi
+ \fi}
% \end{macrocode}
%
% \subsection{Local Language Configuration}
@@ -9613,16 +9693,17 @@ help from Bernd Raichle, for which I am grateful.
%
% \begin{macro}{\bbl@set@language}
%
-% The macro |\bbl@set@language| takes care of switching the
-% language environment \emph{and} of writing entries on the
-% auxiliary files. For historial reasons, language names can be
-% either |language| of |\language|. To catch either form a trick is
-% used, but unfortunately as a side effect the catcodes of letters
-% in |\languagename| are not well defined. The list of auxiliary
-% files can be extended by redefining |\BabelContentsFiles|, but
-% make sure they are loaded inside a group (as |aux|, |toc|,
-% |lof|, and |lot| do) or the last language of the document will
-% remain active afterwards.
+% The macro |\bbl@set@language| takes care of switching the language
+% environment \emph{and} of writing entries on the auxiliary files.
+% For historial reasons, language names can be either |language| of
+% |\language|. To catch either form a trick is used, but
+% unfortunately as a side effect the catcodes of letters in
+% |\languagename| are messed up. This is a bug, but preserved for
+% backwards compatibility. The list of auxiliary files can be
+% extended by redefining |\BabelContentsFiles|, but make sure they
+% are loaded inside a group (as |aux|, |toc|, |lof|, and |lot| do)
+% or the last language of the document will remain active
+% afterwards.
%
% We also write a command to change the current language in the
% auxiliary files.
@@ -9640,19 +9721,22 @@ help from Bernd Raichle, for which I am grateful.
%
% \begin{macrocode}
\def\BabelContentsFiles{toc,lof,lot}
-\def\bbl@set@language#1{%
+\def\bbl@set@language#1{% from selectlanguage, pop@
\edef\languagename{%
\ifnum\escapechar=\expandafter`\string#1\@empty
\else\string#1\@empty\fi}%
\select@language{\languagename}%
+ % write to auxs
\expandafter\ifx\csname date\languagename\endcsname\relax\else
\if@filesw
\protected@write\@auxout{}{\string\babel@aux{\languagename}{}}%
\bbl@usehooks{write}{}%
\fi
\fi}
-\def\select@language#1{%
+\def\select@language#1{% from set@, babel@aux
+ % set hymap
\ifnum\bbl@hymapsel=\@cclv\chardef\bbl@hymapsel4\relax\fi
+ % set name
\edef\languagename{#1}%
\bbl@fixname\languagename
\bbl@iflanguage\languagename{%
@@ -9665,6 +9749,7 @@ help from Bernd Raichle, for which I am grateful.
some cases, you may need to remove the aux file}%
{You may proceed, but expect wrong results}%
\else
+ % set type
\let\bbl@select@type\z@
\expandafter\bbl@switch\expandafter{\languagename}%
\fi}}
@@ -9744,7 +9829,8 @@ help from Bernd Raichle, for which I am grateful.
%
% \begin{macrocode}
\newif\ifbbl@usedategroup
-\def\bbl@switch#1{%
+\def\bbl@switch#1{% from select@, foreign@
+ % restore
\originalTeX
\expandafter\def\expandafter\originalTeX\expandafter{%
\csname noextras#1\endcsname
@@ -9752,6 +9838,7 @@ help from Bernd Raichle, for which I am grateful.
\babel@beginsave}%
\bbl@usehooks{afterreset}{}%
\languageshorthands{none}%
+ % switch captions, date
\ifcase\bbl@select@type
\ifhmode
\hskip\z@skip % trick to ignore spaces
@@ -9762,19 +9849,27 @@ help from Bernd Raichle, for which I am grateful.
\csname captions#1\endcsname\relax
\csname date#1\endcsname\relax
\fi
- \else\ifbbl@usedategroup
- \bbl@usedategroupfalse
- \ifhmode
- \hskip\z@skip % trick to ignore spaces
- \csname date#1\endcsname\relax
- \loop\ifdim\lastskip>\z@\unskip\repeat\unskip
- \else
- \csname date#1\endcsname\relax
+ \else
+ \ifbbl@usedategroup % if \foreign... within \<lang>date
+ \bbl@usedategroupfalse
+ \ifhmode
+ \hskip\z@skip % trick to ignore spaces
+ \csname date#1\endcsname\relax
+ \loop\ifdim\lastskip>\z@\unskip\repeat\unskip
+ \else
+ \csname date#1\endcsname\relax
+ \fi
\fi
- \fi\fi
+ \fi
+ % switch extras
\bbl@usehooks{beforeextras}{}%
\csname extras#1\endcsname\relax
\bbl@usehooks{afterextras}{}%
+ % > babel-ensure
+ % > babel-sh-<short>
+ % > babel-bidi
+ % > babel-fontspec
+ % hyphenation - case mapping
\ifcase\bbl@opt@hyphenmap\or
\def\BabelLower##1##2{\lccode##1=##2\relax}%
\ifnum\bbl@hymapsel>4\else
@@ -9787,7 +9882,9 @@ help from Bernd Raichle, for which I am grateful.
\fi
\fi
\global\let\bbl@hymapsel\@cclv
+ % hyphenation - patterns
\bbl@patterns{#1}%
+ % hyphenation - mins
\babel@savevariable\lefthyphenmin
\babel@savevariable\righthyphenmin
\expandafter\ifx\csname #1hyphenmins\endcsname\relax
@@ -9939,18 +10036,21 @@ help from Bernd Raichle, for which I am grateful.
%
% \begin{macrocode}
\def\foreign@language#1{%
+ % set name
\edef\languagename{#1}%
\bbl@fixname\languagename
\bbl@iflanguage\languagename{%
\expandafter\ifx\csname date\languagename\endcsname\relax
- \bbl@warning
+ \bbl@warning % TODO - why a warning, not an error?
{Unknown language `#1'. Either you have\\%
misspelled its name, it has not been installed,\\%
or you requested it in a previous run. Fix its name,\\%
- install it or just rerun the file, respectively.\\%
+ install it or just rerun the file, respectively. In\\%
+ some cases, you may need to remove the aux file.\\%
I'll proceed, but expect wrong results.\\%
Reported}%
\fi
+ % set type
\let\bbl@select@type\@ne
\expandafter\bbl@switch\expandafter{\languagename}}}
% \end{macrocode}
@@ -9994,6 +10094,7 @@ help from Bernd Raichle, for which I am grateful.
\edef\bbl@tempa{#1:\f@encoding}%
\fi
\@expandtwoargs\bbl@usehooks{patterns}{{#1}{\bbl@tempa}}%
+ % > luatex
\@ifundefined{bbl@hyphenation@}{}{% Can be \relax!
\begingroup
\bbl@xin@{,\number\language,}{,\bbl@hyphlist}%
@@ -10467,10 +10568,12 @@ help from Bernd Raichle, for which I am grateful.
\expandafter\language\csname l@#1\endcsname
\edef\languagename{#1}%
\bbl@hook@everylanguage{#1}%
+ % > luatex
\bbl@get@enc#1::\@@@
\begingroup
\lefthyphenmin\m@ne
\bbl@hook@loadpatterns{#2}%
+ % > luatex
\ifnum\lefthyphenmin=\m@ne
\else
\expandafter\xdef\csname #1hyphenmins\endcsname{%
@@ -10480,6 +10583,7 @@ help from Bernd Raichle, for which I am grateful.
\def\bbl@tempa{#3}%
\ifx\bbl@tempa\@empty\else
\bbl@hook@loadexceptions{#3}%
+ % > luatex
\fi
\let\bbl@elt\relax
\edef\bbl@languages{%
@@ -10831,20 +10935,27 @@ help from Bernd Raichle, for which I am grateful.
% |\bbl@mapselect| because |\selectfont| is called internally when a
% font is defined.
%
+% \changes{3.28}{2019/04/01}{\cs{babelfont} now based on
+% \cs{newfontfamily}.}
+%
% \begin{macrocode}
\def\bbl@font@set#1#2#3{% eg \bbl@rmdflt@lang \rmdefault \rmfamily
\bbl@xin@{<>}{#1}%
\ifin@
- \bbl@exp{\\\bbl@fontspec@set\\#1\expandafter\@gobbletwo#1}%
+ \bbl@exp{\\\bbl@fontspec@set\\#1\expandafter\@gobbletwo#1\\#3}%
\fi
\bbl@exp{%
- \def\\#2{#1}% eg, \rmdefault{\bbl@rmdflt@lang}
+ \def\\#2{#1}% eg, \rmdefault{\bbl@rmdflt@lang}
\\\bbl@ifsamestring{#2}{\f@family}{\\#3\let\\\bbl@tempa\relax}{}}}
-\def\bbl@fontspec@set#1#2#3{% eg \bbl@rmdflt@lang fnt-opt fnt-nme
+% TODO - next should be global?, but even local does its job. I'm
+% still not sure -- must investigate:
+\def\bbl@fontspec@set#1#2#3#4{% eg \bbl@rmdflt@lang fnt-opt fnt-nme \xxfamily
\let\bbl@tempe\bbl@mapselect
\let\bbl@mapselect\relax
- \bbl@exp{% TODO - should be global, but even local does its job
- % I'm still not sure -- must investigate
+ \let\bbl@temp@fam#4% eg, '\rmfamily', to be restored below
+ \let#4\relax % So that can be used with \newfontfamily
+ \bbl@exp{%
+ \let\\\bbl@temp@pfam\<\bbl@stripslash#4\space>% eg, '\rmfamily '
\<keys_if_exist:nnF>{fontspec-opentype}%
{Script/\bbl@cs{sname@\languagename}}%
{\\\newfontscript{\bbl@cs{sname@\languagename}}%
@@ -10853,10 +10964,15 @@ help from Bernd Raichle, for which I am grateful.
{Language/\bbl@cs{lname@\languagename}}%
{\\\newfontlanguage{\bbl@cs{lname@\languagename}}%
{\bbl@cs{lotf@\languagename}}}%
- \<fontspec_set_family:Nnn>\\#1%
- {\bbl@cs{lsys@\languagename},#2}}{#3}% ie \bbl@exp{..}{#3}
- \let\bbl@mapselect\bbl@tempe
- \bbl@toglobal#1}%
+ \\\newfontfamily\\#4%
+ [\bbl@cs{lsys@\languagename},#2]}{#3}% ie \bbl@exp{..}{#3}
+ \begingroup
+ #4%
+ \xdef#1{\f@family}% eg, \bbl@rmdflt@lang{FreeSerif(0)}
+ \endgroup
+ \let#4\bbl@temp@fam
+ \bbl@exp{\let\<\bbl@stripslash#4\space>}\bbl@temp@pfam
+ \let\bbl@mapselect\bbl@tempe}%
% \end{macrocode}
%
% font@rst and famrst are only used when there is no global settings,
@@ -11746,9 +11862,9 @@ help from Bernd Raichle, for which I am grateful.
\fi
\ifx\bbl@opt@layout\@nnil\endinput\fi % if no layout
\ifx\bbl@beforeforeign\leavevmode % A poor test for bidi=
- \def\bbl@nextfake#1{%
- \mathdir\bodydir % non-local, use always inside a group!
+ \def\bbl@nextfake#1{% non-local changes - always inside a group!
\bbl@exp{%
+ \mathdir\the\bodydir
#1% Once entered in math, set boxes to restore values
\everyvbox{%
\the\everyvbox
@@ -18046,6 +18162,7 @@ function Babel.bidi(head, ispar)
local new_dir = false
local first_dir = false
+ local inmath = false
local last_lr
@@ -18076,6 +18193,7 @@ function Babel.bidi(head, ispar)
end
end
dir = dir or 'l'
+ if inmath then dir = ('TRT' == tex.mathdir) and 'r' or 'l' end
% \end{macrocode}
%
% Next is based on the assumption babel sets the language AND
@@ -18128,12 +18246,14 @@ function Babel.bidi(head, ispar)
% \end{macrocode}
%
% Once finished the basic setup for glyphs, consider the two other
-% cases: dir node and the rest.
+% cases: dir node and the rest.
%
% \begin{macrocode}
- elseif item.id == node.id'dir' then
+ elseif item.id == node.id'dir' and not inmath then
new_dir = true
dir = nil
+ elseif item.id == node.id'math' then
+ inmath = (item.subtype == 0)
else
dir = nil -- Not a char
end
@@ -18326,8 +18446,11 @@ local function insert_numeric(head, state)
return head, new_state
end
--- \hbox with an explicit dir can lead to wrong results
--- <R \hbox dir TLT{<R>}> and <L \hbox dir TRT{<L>}>
+-- TODO - \hbox with an explicit dir can lead to wrong results
+-- <R \hbox dir TLT{<R>}> and <L \hbox dir TRT{<L>}>. A small attempt
+-- was s made to improve the situation, but the problem is the 3-dir
+-- model in babel/Unicode and the 2-dir model in LuaTeX don't fit
+-- well.
function Babel.bidi(head, ispar, hdir)
local d -- d is used mainly for computations in a loop
@@ -18336,6 +18459,7 @@ function Babel.bidi(head, ispar, hdir)
local nodes = {}
local outer_first = nil
+ local inmath = false
local glue_d = nil
local glue_i = nil
@@ -18354,9 +18478,14 @@ function Babel.bidi(head, ispar, hdir)
(temp == 2 and 'al')
elseif ispar then -- Or error? Shouldn't happen
save_outer = ('TRT' == tex.pardir) and 'r' or 'l'
- else
+ else -- Or error? Shouldn't happen
save_outer = ('TRT' == hdir) and 'r' or 'l'
end
+ -- when the callback is called, we are just _after_ the box,
+ -- and the textdir is that of the surrounding text
+ -- if not ispar and hdir ~= tex.textdir then
+ -- save_outer = ('TRT' == hdir) and 'r' or 'l'
+ -- end
local outer = save_outer
local last = outer
-- 'al' is only taken into account in the first, current loop
@@ -18395,6 +18524,7 @@ function Babel.bidi(head, ispar, hdir)
end
end
d = d or 'l'
+ if inmath then d = ('TRT' == tex.mathdir) and 'r' or 'l' end
d_font = d_font or d
d_font = (d_font == 'l' and 0) or
@@ -18442,6 +18572,9 @@ function Babel.bidi(head, ispar, hdir)
glue_d = d
glue_i = item
d = nil
+
+ elseif item.id == node.id'math' then
+ inmath = (item.subtype == 0)
else
d = nil
@@ -18606,7 +18739,11 @@ function Babel.bidi(head, ispar, hdir)
end
else
if d == 'an' or d == 'l' then
- state.sim = state.sim or item
+ if nodes[q][3] then -- nil except after an explicit dir
+ state.sim = item -- so we move sim 'inside' the group
+ else
+ state.sim = state.sim or item
+ end
state.eim = item
elseif d == 'r' and state.sim then
head, state = insert_implicit(head, state, outer)