[latex3-commits] [git/LaTeX3-latex3-babel] master: 'Transforms' for ini files. (75f956a)
Javier
email at dante.de
Mon Mar 22 17:34:34 CET 2021
Repository : https://github.com/latex3/babel
On branch : master
Link : https://github.com/latex3/babel/commit/75f956a0b51b236d40c38fc89bc03345166d05d6
>---------------------------------------------------------------
commit 75f956a0b51b236d40c38fc89bc03345166d05d6
Author: Javier <email at localhost>
Date: Mon Mar 22 17:34:34 2021 +0100
'Transforms' for ini files.
>---------------------------------------------------------------
75f956a0b51b236d40c38fc89bc03345166d05d6
README.md | 6 +-
babel.dtx | 140 ++++++++++++++++++++--------
babel.ins | 2 +-
babel.pdf | Bin 821452 -> 823156 bytes
bbcompat.dtx | 2 +-
news-guides/news/whats-new-in-babel-3.56.md | 41 +++++++-
6 files changed, 144 insertions(+), 47 deletions(-)
diff --git a/README.md b/README.md
index 0adcc9c..18809a6 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-## Babel 3.55.2315
+## Babel 3.55.2319
This package manages culturally-determined typographical (and other)
rules, and hyphenation patterns for a wide range of languages. Many
@@ -47,7 +47,9 @@ respective authors.
### Summary of Latest changes
```
3.56 2021-03-23??
- * Key 'space' in \babelprehyphenation.
+ * Two new keys in \babelprehyphenation.
+ - 'space', in em units.
+ - 'spacefactor', based on the current word separation.
* Multiple 'insert's allowed.
* Fixes:
- 'insert' and 'data' didn't always set/get the expected node.
diff --git a/babel.dtx b/babel.dtx
index 4881a5f..bfcd1ee 100644
--- a/babel.dtx
+++ b/babel.dtx
@@ -31,7 +31,7 @@
%
% \iffalse
%<*filedriver>
-\ProvidesFile{babel.dtx}[2021/03/18 v3.55.2315 The Babel package]
+\ProvidesFile{babel.dtx}[2021/03/22 v3.55.2319 The Babel package]
\documentclass{ltxdoc}
\GetFileInfo{babel.dtx}
\usepackage{fontspec}
@@ -750,29 +750,6 @@ environment of |\foreignlanguage|, except when the option |bidi| is
set -- in this case, |\foreignlanguage| emits a |\leavevmode|, while
|otherlanguage*| does not.
-\Describe{\begin\menv{hyphenrules}}{\marg{language}\Eenv{hyphenrules}}
-
-The environment \Lenv{hyphenrules} can be used to select \emph{only} the
-hyphenation rules to be used (it can be used as command, too). This can
-for instance be used to select `nohyphenation', provided that in
-\file{language.dat} the `language' \textsf{nohyphenation} is defined by
-loading \file{zerohyph.tex}. It deactivates language shorthands, too
-(but not user shorthands).
-
-Except for these simple uses, |hyphenrules| is deprecated and
-|otherlanguage*| (the starred version) is preferred, because the former
-does not take into account possible changes in encodings of characters
-like, say, |'| done by some languages (eg, \textsf{italian},
-\textsf{french}, \textsf{ukraineb}).
-
-\begin{note}
- To set hyphenation exceptions in the preamble before any language is
- explicitly set with a selector, use |\babelhyphenation| (see below)
- instead of |\hyphenation|. The reason is the same — in the preamble
- the hyphenation rules are not always fully set up and an error can by
- raised.
-\end{note}
-
\subsection{More on selection}
\Describe{\babeltags}{\char`\{\m{tag1} \texttt{=} \m{language1}, \m{tag2}
@@ -2974,6 +2951,28 @@ font encodings are the same, like in Unicode based engines.
language, you can add at least some typical cases.
\end{note}
+\begin{note}
+ To set hyphenation exceptions in the preamble before any language is
+ explicitly set with a selector, use |\babelhyphenation| instead of
+ |\hyphenation|. In the preamble the hyphenation rules are not always
+ fully set up and an error can be raised.
+\end{note}
+
+\Describe{\begin\menv{hyphenrules}}{\marg{language}\Eenv{hyphenrules}}
+
+The environment \Lenv{hyphenrules} can be used to select \emph{only} the
+hyphenation rules to be used (it can be used as command, too). This can
+for instance be used to select `nohyphenation', provided that in
+\file{language.dat} the `language' \textsf{nohyphenation} is defined by
+loading \file{zerohyph.tex}. It deactivates language shorthands, too
+(but not user shorthands).
+
+Except for these simple uses, |hyphenrules| is deprecated and
+|otherlanguage*| (the starred version) is preferred, because the former
+does not take into account possible changes in encodings of characters
+like, say, |'| done by some languages (eg, \textsf{italian},
+\textsf{french}, \textsf{ukraineb}).
+
\Describe{\babelpatterns}{\texttt{[}\langlist\texttt{]}%
\marg{patterns}}
@@ -3009,6 +3008,12 @@ Unicode engines, spacing is based on the ``current'' em unit (the size
of the previous char in \luatex, and the font size set by the last
|\selectfont| in \xetex).
+\subsection{Transforms}
+
+There are a couple of macros to define
+\textit{transforms}.\footnote{Similar in concept, but not the same, as
+those in Unicode.}
+
\Describe{\babelposthyphenation}{\marg{hyphenrules-name}%
\marg{lua-pattern}\marg{replacement}}
@@ -3050,19 +3055,14 @@ future implementation may alternatively accept \textsf{lpeg}.
\Describe{\babelprehyphenation}{\marg{locale-name}%
\marg{lua-pattern}\marg{replacement}}
-\New{3.44-3-52} This command is not strictly about hyphenation, but
-it is included here because it is a clear counterpart of
-|\babelposthyphenation|. It is similar to the latter, but (as its name
-implies) applied before hyphenation. There are other differences: (1)
-the first argument is the locale instead the name of hyphenation
-patterns; (2) in the search patterns |=| has no special meaning, while
-\verb+|+ stands for an ordinary space; (3) in the replacement,
-discretionaries are not accepted.
-
-It handles glyphs and spaces (but you can not insert spaces).
+\New{3.44-3-52} It is similar to the latter, but (as its name implies)
+applied before hyphenation. There are other differences: (1) the first
+argument is the locale instead the name of hyphenation patterns; (2) in
+the search patterns |=| has no special meaning, while \verb+|+ stands
+for an ordinary space; (3) in the replacement, discretionaries are not
+accepted.
-Performance is still somewhat poor in some cases, but it is fast in the
-typical ones.
+It handles glyphs and spaces.
This feature is activated with the first |\babelposthyphenation| or
|\babelprehyphenation|.
@@ -4856,8 +4856,8 @@ help from Bernd Raichle, for which I am grateful.
% \section{Tools}
%
% \begin{macrocode}
-%<<version=3.55.2315>>
-%<<date=2021/03/18>>
+%<<version=3.55.2319>>
+%<<date=2021/03/22>>
% \end{macrocode}
%
% \textbf{Do not use the following macros in \texttt{ldf} files. They
@@ -10664,6 +10664,7 @@ help from Bernd Raichle, for which I am grateful.
\let\bbl at KVP@intraspace\@nil
\let\bbl at KVP@intrapenalty\@nil
\let\bbl at KVP@onchar\@nil
+ \let\bbl at KVP@transforms\@nil
\let\bbl at KVP@alph\@nil
\let\bbl at KVP@Alph\@nil
\let\bbl at KVP@labels\@nil
@@ -10706,6 +10707,10 @@ help from Bernd Raichle, for which I am grateful.
\ifx\bbl at KVP@captions\@nil
\let\bbl at KVP@captions\bbl at KVP@import
\fi
+ % ==
+ \ifx\bbl at KVP@transforms\@nil\else
+ \bbl at replace\bbl at KVP@transforms{ }{,}%
+ \fi
% Load ini
\bbl at ifunset{date#2}%
{\bbl at provide@new{#2}}%
@@ -11301,6 +11306,8 @@ help from Bernd Raichle, for which I am grateful.
\bbl at cs{@kv at identification.warning#1}\\%
Reported }}}
%
+\let\bbl at release@transforms\@empty
+%
\def\bbl at ini@exports#1{%
% Identification always exported
\bbl at iniwarning{}%
@@ -11326,6 +11333,8 @@ help from Bernd Raichle, for which I am grateful.
\ifbbl at bcptoname
\bbl at csarg\xdef{bcp at map@\bbl at cl{tbcp}}{\languagename}%
\fi
+ % Finish here transforms, too
+ \bbl at release@transforms\relax % \relax closes the last item.
% Conditional
\ifnum#1>\z@ % 0 = only info, 1, 2 = basic, (re)new
\bbl at exportkey{lnbrk}{typography.linebreaking}{h}%
@@ -11683,6 +11692,39 @@ help from Bernd Raichle, for which I am grateful.
\def\bbl at xdatecntr[#1|#2]{\localenumeral{#2}{#1}}
% \end{macrocode}
%
+% \textbf{Transforms.}
+%
+% \begin{macrocode}
+\let\bbl at release@transforms\@empty
+\@namedef{bbl at inikv@transforms.prehyphenation}{%
+ \bbl at transforms\babelprehyphenation}
+\@namedef{bbl at inikv@transforms.posthyphenation}{%
+ \bbl at transforms\babelposthyphenation}
+\def\bbl at transforms@aux#1#2#3,#4\relax{#1{#2}{#3}{#4}}
+\begingroup % TODO - to a lua file
+ \catcode`\%=12
+ \catcode`\&=14
+ \gdef\bbl at transforms#1#2#3{&%
+ \ifx\bbl at KVP@transforms\@nil\else
+ \directlua{
+ str = [==[#2]==]
+ str = str:gsub('%.%d+%.%d+$', '')
+ tex.print([[\def\string\babeltempa{]] .. str .. [[}]])
+ }&%
+ \bbl at xin@{,\babeltempa,}{,\bbl at KVP@transforms,}&%
+ \ifin@
+ \in@{.0$}{#2$}&%
+ \ifin@
+ \bbl at add\bbl at release@transforms{&%
+ \relax\bbl at transforms@aux#1{french}{#3}}&%
+ \else
+ \bbl at add\bbl at release@transforms{, {#3}}&%
+ \fi
+ \fi
+ \fi}
+\endgroup
+% \end{macrocode}
+%
% Language and Script values to be used when defining a font or
% setting the direction are set with the following macros.
%
@@ -14097,6 +14139,18 @@ end
end
head, new = node.insert_before(head, item, d)
+ elseif crep and crep.spacefactor then
+ d = node.new(12, 13) &% (glue, spaceskip)
+ local base_font = font.getfont(item_base.font)
+ node.setglue(d,
+ crep.spacefactor[1] * base_font.parameters['space'],
+ crep.spacefactor[2] * base_font.parameters['space_stretch'],
+ crep.spacefactor[3] * base_font.parameters['space_shrink'])
+ if mode == 0 then
+ placeholder = '|'
+ end
+ head, new = node.insert_before(head, item, d)
+
elseif mode == 0 and crep and crep.space then
&% ERROR
@@ -14193,7 +14247,9 @@ end
\begingroup
\def\babeltempa{\bbl at add@list\babeltempb}&%
\let\babeltempb\@empty
- \bbl at foreach{#3}{&%
+ \def\bbl at tempa{#3}&% TODO. Ugly trick to preserve {}:
+ \bbl at replace\bbl at tempa{,}{ ,}&%
+ \expandafter\bbl at foreach\expandafter{\bbl at tempa}{&%
\bbl at ifsamestring{##1}{remove}&%
{\bbl at add@list\babeltempb{nil}}&%
{\directlua{
@@ -14230,7 +14286,9 @@ end
\begingroup
\def\babeltempa{\bbl at add@list\babeltempb}&%
\let\babeltempb\@empty
- \bbl at foreach{#3}{&%
+ \def\bbl at tempa{#3}&% TODO. Ugly trick to preserve {}:
+ \bbl at replace\bbl at tempa{,}{ ,}&%
+ \expandafter\bbl at foreach\expandafter{\bbl at tempa}{&%
\bbl at ifsamestring{##1}{remove}&%
{\bbl at add@list\babeltempb{nil}}&%
{\directlua{
@@ -14239,6 +14297,8 @@ end
rep = rep:gsub('(string)%s*=%s*([^%s,]*)', Babel.capture_func)
rep = rep:gsub( '(space)%s*=%s*([%d%.]+)%s+([%d%.]+)%s+([%d%.]+)',
'space = {' .. '%2, %3, %4' .. '}')
+ rep = rep:gsub( '(spacefactor)%s*=%s*([%d%.]+)%s+([%d%.]+)%s+([%d%.]+)',
+ 'spacefactor = {' .. '%2, %3, %4' .. '}')
tex.print([[\string\babeltempa{{]] .. rep .. [[}}]])
}}}&%
\directlua{
diff --git a/babel.ins b/babel.ins
index 6679dbc..5236551 100644
--- a/babel.ins
+++ b/babel.ins
@@ -26,7 +26,7 @@
%% and covered by LPPL is defined by the unpacking scripts (with
%% extension .ins) which are part of the distribution.
%%
-\def\filedate{2021/03/18}
+\def\filedate{2021/03/22}
\def\batchfile{babel.ins}
\input docstrip.tex
diff --git a/babel.pdf b/babel.pdf
index e7316dc..ba84818 100644
Binary files a/babel.pdf and b/babel.pdf differ
diff --git a/bbcompat.dtx b/bbcompat.dtx
index 21e4b99..ea8696a 100644
--- a/bbcompat.dtx
+++ b/bbcompat.dtx
@@ -30,7 +30,7 @@
%
% \iffalse
%<*dtx>
-\ProvidesFile{bbcompat.dtx}[2021/03/18 v3.55.2315]
+\ProvidesFile{bbcompat.dtx}[2021/03/22 v3.55.2319]
%</dtx>
%
%% File 'bbcompat.dtx'
diff --git a/news-guides/news/whats-new-in-babel-3.56.md b/news-guides/news/whats-new-in-babel-3.56.md
index da53928..89b9353 100644
--- a/news-guides/news/whats-new-in-babel-3.56.md
+++ b/news-guides/news/whats-new-in-babel-3.56.md
@@ -34,13 +34,48 @@ then matches):
}
```
+An alternative, which is more useful in many cases, is `spacefactor`,
+which takes 3 numbers, too, but they are factors to be applied to the
+word separation in the font.
+```tex
+\babelprehyphenation{french}{ «{a} }{
+ {},
+ { insert, penalty = 10000 },
+ { insert, spacefactor=.8 .3 .8, data = 1 },
+ {}
+}
+```
+
As you can see, now multiple insertions are allowed, which is often
necessary when a space is added.
In addition, the code has been refactored, to improve both stability
-with overlapping patterns and speed. With those changes, the next step
-is to will be new keys in `ini` files to define transformation rules.
-French spacing is a case in point.
+with overlapping patterns and speed. (There are still some issues,
+however.)
+
+## Transforms in `ini` files
+
+Based on the two macros above, there is a tentative and somewhat
+experimental code enabling the definition of ‘transforms’. They are
+conceptually similar to those in Unicode, but not the same, because in
+`babel` they are focused on the typographical level.
+```ini
+[transforms.prehyphenation]
+space.punctuation.1.0 = { «{a} }
+space.punctuation.1.1 = {}
+space.punctuation.1.2 = { insert, penalty = 10000 }
+space.punctuation.1.3 = { insert, spacefactor=.8 .3 .8, data = 1 }
+space.punctuation.1.4 = {}
+```
+
+`0` is the pattern. It must be activated with `transforms` in
+`\babelprovide`, eg:
+
+```tex
+\babelprovide[transforms = space.punctuation, import]{...}
+```
+(*To be expanded.*)
+
## Fixes
More information about the latex3-commits
mailing list.