[latex3-commits] [git/LaTeX3-latex3-babel] master: {1} refers to a capture. Now based on \language. See the wiki. (c402219)

Javier jbezos at dante.de
Sat Nov 30 08:33:12 CET 2019


Repository : https://github.com/latex3/babel
On branch  : master
Link       : https://github.com/latex3/babel/commit/c4022195d11272fc74698632e378c13298004304

>---------------------------------------------------------------

commit c4022195d11272fc74698632e378c13298004304
Author: Javier <jbezos at localhost>
Date:   Sat Nov 30 08:33:12 2019 +0100

    {1} refers to a capture. Now based on \language. See the wiki.


>---------------------------------------------------------------

c4022195d11272fc74698632e378c13298004304
 README.md    |   2 +-
 babel.dtx    | 290 +++++++++++++++++++++++++++++++----------------------------
 babel.ins    |   2 +-
 babel.pdf    | Bin 741603 -> 741643 bytes
 bbcompat.dtx |   2 +-
 5 files changed, 154 insertions(+), 142 deletions(-)

diff --git a/README.md b/README.md
index 9aab7fb..78156ac 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-## Babel 3.36.1837
+## Babel 3.36.1841
 
 This package manages culturally-determined typographical (and other)
 rules, and hyphenation patterns for a wide range of languages.  Many
diff --git a/babel.dtx b/babel.dtx
index ed4e010..1f9560f 100644
--- a/babel.dtx
+++ b/babel.dtx
@@ -31,7 +31,7 @@
 %
 % \iffalse
 %<*filedriver>
-\ProvidesFile{babel.dtx}[2019/11/26 v3.36.1837 The Babel package]
+\ProvidesFile{babel.dtx}[2019/11/30 v3.36.1841 The Babel package]
 \documentclass{ltxdoc}
 \GetFileInfo{babel.dtx}
 \usepackage{fontspec}
@@ -4135,8 +4135,8 @@ help from Bernd Raichle, for which I am grateful.
 % \section{Tools}
 %
 %    \begin{macrocode}
-%<<version=3.36.1837>>
-%<<date=2019/11/26>>
+%<<version=3.36.1841>>
+%<<date=2019/11/30>>
 %    \end{macrocode}
 %
 % \textbf{Do not use the following macros in \texttt{ldf} files. They
@@ -8827,6 +8827,17 @@ help from Bernd Raichle, for which I am grateful.
   \bbl at adjust@layout{\let\list\bbl at NL@list}}
 \@namedef{bbl at ADJ@layout.lists at on}{%
   \bbl at adjust@layout{\let\list\bbl at OL@list}}
+\@namedef{bbl at ADJ@hyphenation.extra at on}{%
+  \begingroup
+    \directlua{
+      Babel.linebreaking.add_after(Babel.post_hyphenate_replace)
+      Babel.hyphenate_ids = {}
+    }%  
+    \def\bbl at elt##1##2##3##4{%
+      \count@=##2\relax
+      \directlua{ Babel.hyphenate_ids['##1'] = \the\count@ }}%  
+    \bbl at languages
+  \endgroup}
 %    \end{macrocode}
 %
 % \section{The kernel of Babel (\texttt{babel.def} for \LaTeX only)}
@@ -12414,12 +12425,16 @@ help from Bernd Raichle, for which I am grateful.
       if Babel.cjk_enabled then
         Babel.cjk_linebreak(head)
       end
-      for k, func in ipairs(Babel.linebreaking.before)  do
-        func(head)
+      if Babel.linebreaking.before then
+        for k, func in ipairs(Babel.linebreaking.before)  do
+          func(head)
+        end
       end
       lang.hyphenate(head)
-      for k, func in ipairs(Babel.linebreaking.after)  do
-        func(head)
+      if Babel.linebreaking.after then
+        for k, func in ipairs(Babel.linebreaking.after)  do
+          func(head)
+        end
       end
       if Babel.sea_enabled then
         Babel.sea_disc_to_space(head)
@@ -12571,171 +12586,168 @@ help from Bernd Raichle, for which I am grateful.
   function Babel.fetch_word(head, funct)
     local word_string = ''
     local word_nodes = {}
-    local locale, last_locale
+    local lang
 
     for item in node.traverse(head) do
-      locale = Babel.get_locale(item)
-      last_locale = last_locale or locale
 
-      if item.id == 29 and not(item.char == 124) % ie, not |
-          and locale == last_locale
-          and not (item.lang == \the\l at nohyphenation) then
+      if item.id == 29
+          and not(item.char == 124) % ie, not |
+          and not(item.char == 61)  % ie, not =
+          and (item.lang == lang or lang == nil) then
+        lang = lang or item.lang
         word_string = word_string .. unicode.utf8.char(item.char)
-        table.insert(word_nodes, item)
-        last_locale = locale
-
-      elseif item.id == 7 and item.subtype == 2
-           and locale == last_locale
-           and not (item.lang == \the\l at nohyphenation) then
-         word_string = word_string .. '-'
-         table.insert(word_nodes, item)
-         last_locale = locale
-
-      elseif item.id == 7 and item.subtype == 3
-           and locale == last_locale
-           and not (item.lang == \the\l at nohyphenation) then
+        word_nodes[#word_nodes+1] = item
+
+      elseif item.id == 7 and item.subtype == 2 then
+         word_string = word_string .. '='
+         word_nodes[#word_nodes+1] = item
+
+      elseif item.id == 7 and item.subtype == 3 then
          word_string = word_string .. '|'       
-         table.insert(word_nodes, item)
-         last_locale = locale
+         word_nodes[#word_nodes+1] = item
 
       elseif word_string == '' then
         % pass
 
       else
-        return word_string, word_nodes, item
+        return word_string, word_nodes, item, lang
       end
     end
   end
 
+  function Babel.replace_capture (s, m)
+  if s == nil then return '' end
+  return unicode.utf8.gsub(s, '{([0-9])}',
+            function (d)
+              return m[tonumber(d)]
+            end)
+  end
+
   Babel.linebreaking.replacements = {}
+  Babel.hyphenate_ids = {}
 
-  function Babel.post_hyphenate_replace(head)
-  local u = unicode.utf8
-  local word_head = head
+ function Babel.post_hyphenate_replace(head)
+    local u = unicode.utf8
+    local lbk = Babel.linebreaking
+    local x = Babel.replace_capture
+    local word_head = head
     
-  while true do
-    local w, wn, nw = Babel.fetch_word(word_head)
-    if not nw then return head end
+    while true do
+      local w, wn, nw, lang = Babel.fetch_word(word_head)
+      if not lang then return head end
 
-    if not Babel.linebreaking.replacements[Babel.get_locale(wn[1])] then
-      break
-    end
+      if not lbk.replacements[lang] then
+        break
+      end
 
-    for _, reps in ipairs(Babel.linebreaking.replacements[Babel.get_locale(wn[1])]) do
-      local r = reps.replace
-      local p = reps.pattern 
+      for k=1, #lbk.replacements[lang] do
+        local r = lbk.replacements[lang][k].replace
+        local p = lbk.replacements[lang][k].pattern 
 
-      % This should be done when set:
-      if not u.find(p, '()', nil, true) then
-        p = '()' .. p .. '()'
-      end
-      p = u.gsub(p, '{(.)}',  % This should be done when set, too
-                 function (n)
-                    return '\@percentchar'
-                            .. (tonumber(n) and (tonumber(n)+1) or n)
-                 end)
-
-      while true do
-        first, A, B, C, E, F, G = u.match(w, p) 
-        if not A then break end
-
-        local last = {A, B, C, E, F, G} % Ugly. Must be a better way
-        last = last[#last]
-
-        % Fix offsets, from bytes to unicode
-        first = u.len(w:sub(1, first-1)) + 1
-        last  = u.len(w:sub(1, last-1))
-
-        % This EXpands {n} in replacement fields pre, post, no
-        local x = function (s)
-          if s == nil then return '' end
-          return u.gsub(s, '{([0-9])}',
-            function (n)
-              return u.sub(w, n+first-1, n+first-1)
-            end)
-        end
+        while true do
+          local matches = { u.match(w, p) }
+          if #matches < 2 then break end
 
-        local new  % used when inserting and removing nodes
-        local changed = 0
+          local first = table.remove(matches, 1)
+          local last =  table.remove(matches, #matches)
 
-        for q = first, last do   
-          local rep_i = r[q-first+1]
-          local char_node = wn[q]
-          local char_base = char_node
+          % Fix offsets, from bytes to unicode
+          first = u.len(w:sub(1, first-1)) + 1
+          last  = u.len(w:sub(1, last-1))
 
-          if rep_i and rep_i.data then
-            char_base = wn[rep_i.data]
-          end
-          if rep_i == nil then
-            rep_i = { string='' }
-          end
+          local new  % used when inserting and removing nodes
+          local changed = 0
+
+          for q = first, last do   
+            local rep_i = r[q-first+1]
+            local char_node = wn[q]
+            local char_base = char_node
 
-          if rep_i and (rep_i.pre or rep_i.no or rep_i.post) then
-            changed = changed + 1
-            d = node.new(7, 0)   % (disc, discretionary)
-            d.pre     = Babel.str_to_nodes(x(rep_i.pre), char_base)
-            d.post    = Babel.str_to_nodes(x(rep_i.post), char_base)
-            d.replace = Babel.str_to_nodes(x(rep_i.no), char_base)
-            d.attr    = char_base.attr
-            if rep_i.pre and not(rep_i.pre == '') then  % TeXbook p96
-              d.penalty  = rep_i.penalty or tex.hyphenpenalty
-            else
-              d.penalty  = rep_i.penalty or tex.exhyphenpenalty
+            if rep_i and rep_i.data then
+              char_base = wn[rep_i.data+first-1]
             end
-            head, new = node.insert_before(head, char_node, d)
-            node.remove(head, char_node)
-            if q == 1 then
-              word_head = new
+            if rep_i == nil then
+              rep_i = { string='' }
             end
-          elseif rep_i and rep_i.string then
-            changed = changed + 1
-            rep_i.string = x(rep_i.string, char_base) 
-            if rep_i.string == '' then 
+
+            if rep_i and (rep_i.pre or rep_i.no or rep_i.post) then
+              changed = changed + 1
+              d = node.new(7, 0)   % (disc, discretionary)
+              d.pre     = Babel.str_to_nodes(x(rep_i.pre, matches), char_base)
+              d.post    = Babel.str_to_nodes(x(rep_i.post, matches), char_base)
+              d.replace = Babel.str_to_nodes(x(rep_i.no, matches), char_base)
+              d.attr    = char_base.attr
+              if rep_i.pre and not(rep_i.pre == '') then  % TeXbook p96
+                d.penalty  = rep_i.penalty or tex.hyphenpenalty
+              else
+                d.penalty  = rep_i.penalty or tex.exhyphenpenalty
+              end
+              head, new = node.insert_before(head, char_node, d)
+              node.remove(head, char_node)
               if q == 1 then
-                word_head = char_node.next
+                word_head = new
               end
-              head, new = node.remove(head, char_node)
-            else
-              local n
-              for s in string.utfvalues(rep_i.string) do
-                if char_node.id == 7 then
-                  texio.write_nl('Automatic hyphens cannot be replaced, just removed.')
-                else
-                  n = node.copy(char_base)
-                end              
-                n.char = s
+            elseif rep_i and rep_i.string then
+              changed = changed + 1
+              rep_i.string = x(rep_i.string, matches)
+              if rep_i.string == '' then 
                 if q == 1 then
-                  head, new = node.insert_before(head, char_node, n)   
-                  word_head = new
-                else 
-                  node.insert_before(head, char_node, n)   
+                  word_head = char_node.next
+                end
+                head, new = node.remove(head, char_node)
+              elseif char_node.id == 29 and u.len(rep_i.string) == 1 then
+                char_node.char = string.utfvalue(rep_i.string)
+              else
+                local n
+                for s in string.utfvalues(rep_i.string) do
+                  if char_node.id == 7 then
+                    log('Automatic hyphens cannot be replaced, just removed.')
+                  else
+                    n = node.copy(char_base)
+                  end
+                  n.char = s
+                  if q == 1 then
+                    head, new = node.insert_before(head, char_node, n)   
+                    word_head = new
+                  else 
+                    node.insert_before(head, char_node, n)   
+                  end
                 end
-              end
 
-              node.remove(head, char_node)
-            end
-          end  % if char and char.string
-        end  % for char in match
-        if changed > 20 then
-          texio.write('Too many changes. Ignoring the rest.')
-        elseif changed > 0 then
-          w, wn, nw = Babel.fetch_word(word_head)   
-        end
+                node.remove(head, char_node)
+              end  % string length
+            end  % if char and char.string
+          end  % for char in match
+          if changed > 20 then
+            texio.write('Too many changes. Ignoring the rest.')
+          elseif changed > 0 then
+            w, wn, nw = Babel.fetch_word(word_head)   
+          end
 
-      end  % for match
-    end  % for patterns
-  word_head = nw
-  end  % for words
-  return head
-end
+        end  % for match
+      end  % for patterns
+      word_head = nw
+    end  % for words
+    return head
+  end
 
-function Babel.linebreaking.add_replacement(lang, patt, repl)
-  local lbk = Babel.linebreaking
-  lbk.replacements[Babel.locale_ids[lang]] =
-      lbk.replacements[Babel.locale_ids[lang]] or {}
-  table.insert(lbk.replacements[Babel.locale_ids[lang]],
-               { pattern = patt, replace = repl })
-end
+  function Babel.linebreaking.add_replacement(lang, patt, repl)
+    local lbk = Babel.linebreaking
+    if not Babel.hyphenate_ids[lang] then return end
+    local u = unicode.utf8
+    if not u.find(patt, '()', nil, true) then
+      patt = '()' .. patt .. '()'
+    end
+    patt = u.gsub(patt, '{(.)}', 
+               function (n)
+                  return '\@percentchar'
+                          .. (tonumber(n) and (tonumber(n)+1) or n)
+               end)
+    lbk.replacements[Babel.hyphenate_ids[lang]] =
+        lbk.replacements[Babel.hyphenate_ids[lang]] or {}
+    table.insert(lbk.replacements[Babel.hyphenate_ids[lang]],
+                 { pattern = patt, replace = repl })
+  end
 
 }
 \endgroup
diff --git a/babel.ins b/babel.ins
index f553836..6f87a92 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{2019/11/26}
+\def\filedate{2019/11/30}
 \def\batchfile{babel.ins}
 \input docstrip.tex
 
diff --git a/babel.pdf b/babel.pdf
index 01a444c..c9374e6 100644
Binary files a/babel.pdf and b/babel.pdf differ
diff --git a/bbcompat.dtx b/bbcompat.dtx
index 72838e8..a4b9338 100644
--- a/bbcompat.dtx
+++ b/bbcompat.dtx
@@ -30,7 +30,7 @@
 %
 % \iffalse
 %<*dtx>
-\ProvidesFile{bbcompat.dtx}[2019/11/26 v3.36.1837]
+\ProvidesFile{bbcompat.dtx}[2019/11/30 v3.36.1841]
 %</dtx>
 %
 %% File 'bbcompat.dtx'





More information about the latex3-commits mailing list