[latex3-commits] [latex3/babel] main: \localeprehyphenation (to transforms strings) (534d443)
github at latex-project.org
github at latex-project.org
Sat Jul 8 17:09:13 CEST 2023
Repository : https://github.com/latex3/babel
On branch : main
Link : https://github.com/latex3/babel/commit/534d443b1aa85bf3cf4e1712d741d3d3d40f3c32
>---------------------------------------------------------------
commit 534d443b1aa85bf3cf4e1712d741d3d3d40f3c32
Author: Javier <email at localhost>
Date: Sat Jul 8 17:09:13 2023 +0200
\localeprehyphenation (to transforms strings)
>---------------------------------------------------------------
534d443b1aa85bf3cf4e1712d741d3d3d40f3c32
README.md | 4 +++-
babel-code.pdf | Bin 625351 -> 627237 bytes
babel.dtx | 46 ++++++++++++++++++++++++++++++++++++++++++++--
babel.pdf | Bin 404509 -> 404642 bytes
bbcompat.dtx | 2 +-
5 files changed, 48 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index 78480cf..6831c25 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-## Babel 3.90.18929
+## Babel 3.90.18967
**Draft**
@@ -54,6 +54,8 @@ respective authors.
- #241
- #246
- #208
+ * Experimental: transforming strings with
+ `\localeprehyphenation`.
3.90 2023-06-26
* Main language selected at begindocument/before (#240).
diff --git a/babel-code.pdf b/babel-code.pdf
index 8a6cf58..ed7e3c5 100644
Binary files a/babel-code.pdf and b/babel-code.pdf differ
diff --git a/babel.dtx b/babel.dtx
index c505600..261b01a 100644
--- a/babel.dtx
+++ b/babel.dtx
@@ -32,7 +32,7 @@
%
% \iffalse
%<*filedriver>
-\ProvidesFile{babel.dtx}[2023/07/08 v3.90.18929 The Babel package]
+\ProvidesFile{babel.dtx}[2023/07/08 v3.90.18967 The Babel package]
\documentclass{ltxdoc}
\GetFileInfo{babel.dtx}
\usepackage{fontspec}
@@ -5466,7 +5466,7 @@ wouldn’t exist.
% \section{Tools}
%
% \begin{macrocode}
-%<<version=3.90.18929>>
+%<<version=3.90.18967>>
%<<date=2023/07/08>>
% \end{macrocode}
%
@@ -15075,6 +15075,19 @@ end
}}
% \end{macrocode}
%
+% The following experimental (an unfinished) macro applies the
+% prehyphenation transforms for the current locale to a string (letters
+% and spaces) and processes it in a fully expandable way (among other
+% limitations, the string can’t contain |]==]|). The way it operates is
+% admittedly rather cumbersome: it converts the string to a node list,
+% processes it, and converts it back to a string. The lua code is in the
+% lua file below.
+%
+% \begin{macrocode}
+\newcommand\localeprehyphenation[1]{%
+ \directlua{ Babel.string_prehyphenation([==[#1]==], \the\localeid) }}
+% \end{macrocode}
+%
% \subsection{Bidi}
%
% As a first step, add a handler for bidi and digits (and potentially
@@ -16213,6 +16226,35 @@ function Babel.capture_kashida(key, wt)
end
return 'kashida = ' .. wt
end
+
+-- Experimental: applies prehyphenation transforms to a string (letters
+-- and spaces).
+function Babel.string_prehyphenation(str, locale)
+ local n, head, last, res
+ head = node.new(8, 0) -- dummy (hack just to start)
+ last = head
+ for s in string.utfvalues(str) do
+ if s == 20 then
+ n = node.new(12, 0)
+ else
+ n = node.new(29, 0)
+ n.char = s
+ end
+ node.set_attribute(n, Babel.attr_locale, locale)
+ last.next = n
+ last = n
+ end
+ head = Babel.hyphenate_replace(head, 0)
+ res = ''
+ for n in node.traverse(head) do
+ if n.id == 12 then
+ res = res .. ' '
+ elseif n.id == 29 then
+ res = res .. unicode.utf8.char(n.char)
+ end
+ end
+ tex.print(res)
+end
%</transforms>
% \end{macrocode}
%
diff --git a/babel.pdf b/babel.pdf
index 605540c..83494eb 100644
Binary files a/babel.pdf and b/babel.pdf differ
diff --git a/bbcompat.dtx b/bbcompat.dtx
index 719be29..6bbd907 100644
--- a/bbcompat.dtx
+++ b/bbcompat.dtx
@@ -30,7 +30,7 @@
%
% \iffalse
%<*dtx>
-\ProvidesFile{bbcompat.dtx}[2023/07/08 v3.90.18929]
+\ProvidesFile{bbcompat.dtx}[2023/07/08 v3.90.18967]
%</dtx>
%
%% File 'bbcompat.dtx'
More information about the latex3-commits
mailing list.