From deb71b2066bcd0091e3e677b6bae59d4f7e07acf Mon Sep 17 00:00:00 2001
From: Hans Hagen <pragma@wxs.nl>
Date: Fri, 23 Aug 2013 13:16:00 +0200
Subject: beta 2013.08.23 13:16

---
 tex/context/base/cont-new.mkiv                     |   2 +-
 tex/context/base/context-version.pdf               | Bin 4106 -> 4102 bytes
 tex/context/base/context.mkiv                      |   2 +-
 tex/context/base/m-database.lua                    |   2 +-
 tex/context/base/m-spreadsheet.mkiv                |   3 +
 tex/context/base/page-txt.mkvi                     |   2 +-
 tex/context/base/status-files.pdf                  | Bin 24730 -> 24743 bytes
 tex/context/base/status-lua.log                    |   2 +-
 tex/context/base/typo-fln.mkiv                     |   7 ++-
 tex/context/base/util-str.lua                      |  62 ++++++++++++++++++++-
 tex/generic/context/luatex/luatex-fonts-merged.lua |  41 +++++++++++++-
 11 files changed, 113 insertions(+), 10 deletions(-)

(limited to 'tex')

diff --git a/tex/context/base/cont-new.mkiv b/tex/context/base/cont-new.mkiv
index 6c801bb4a..d9bd31615 100644
--- a/tex/context/base/cont-new.mkiv
+++ b/tex/context/base/cont-new.mkiv
@@ -11,7 +11,7 @@
 %C therefore copyrighted by \PRAGMA. See mreadme.pdf for
 %C details.
 
-\newcontextversion{2013.08.21 10:55}
+\newcontextversion{2013.08.23 13:16}
 
 %D This file is loaded at runtime, thereby providing an excellent place for
 %D hacks, patches, extensions and new features.
diff --git a/tex/context/base/context-version.pdf b/tex/context/base/context-version.pdf
index 0fa8b1170..c4f7512db 100644
Binary files a/tex/context/base/context-version.pdf and b/tex/context/base/context-version.pdf differ
diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv
index e32839863..b10febbb4 100644
--- a/tex/context/base/context.mkiv
+++ b/tex/context/base/context.mkiv
@@ -25,7 +25,7 @@
 %D up and the dependencies are more consistent.
 
 \edef\contextformat {\jobname}
-\edef\contextversion{2013.08.22 15:28}
+\edef\contextversion{2013.08.23 13:16}
 \edef\contextkind   {beta}
 
 %D For those who want to use this:
diff --git a/tex/context/base/m-database.lua b/tex/context/base/m-database.lua
index 31e87ad40..91e9636ee 100644
--- a/tex/context/base/m-database.lua
+++ b/tex/context/base/m-database.lua
@@ -6,7 +6,7 @@ if not modules then modules = { } end modules ['m-database'] = {
     license   = "see context related readme files"
 }
 
-local sub, gmatch, format = string.sub, string.gmatch, string.format
+local sub, gmatch = string.sub, string.gmatch
 local concat = table.concat
 local lpegpatterns, lpegmatch, lpegsplitat = lpeg.patterns, lpeg.match, lpeg.splitat
 local lpegP, lpegC, lpegS, lpegCt, lpegCc, lpegCs = lpeg.P, lpeg.C, lpeg.S, lpeg.Ct, lpeg.Cc, lpeg.Cs
diff --git a/tex/context/base/m-spreadsheet.mkiv b/tex/context/base/m-spreadsheet.mkiv
index a05968990..5e0499184 100644
--- a/tex/context/base/m-spreadsheet.mkiv
+++ b/tex/context/base/m-spreadsheet.mkiv
@@ -120,12 +120,15 @@
    \let\stopcell \module_spreadsheet_cell_stop
    \doifassignmentelse{#1}
      {\module_spreadsheet_start
+      \directsetup{spreadsheet:before:\currentspreadsheet}%
       \bTABLE[\c!align=\v!flushright,#1]}
      {\module_spreadsheet_start[#1]%
+      \directsetup{spreadsheet:before:\currentspreadsheet}%
       \bTABLE[\c!align=\v!flushright,#2]}}
 
 \unexpanded\def\stopspreadsheettable
    {\eTABLE
+    \directsetup{spreadsheet:after:\currentspreadsheet}%
     \stopspreadsheet
     \egroup}
 
diff --git a/tex/context/base/page-txt.mkvi b/tex/context/base/page-txt.mkvi
index 707af25e9..240f0e00b 100644
--- a/tex/context/base/page-txt.mkvi
+++ b/tex/context/base/page-txt.mkvi
@@ -269,7 +269,7 @@
 \let\m_page_layouts_element_content\empty
 
 \unexpanded\def\page_layouts_process_element_single#style#color#width#content%
-  {\edef\m_page_layouts_element_content{\detokenize{#content}}%
+  {\edef\m_page_layouts_element_content{\detokenize{#content}}% so no \v!xxx
    \ifx\m_page_layouts_element_content\empty
      % should not happen too often
    \else
diff --git a/tex/context/base/status-files.pdf b/tex/context/base/status-files.pdf
index 7e7cc02bd..2c1009b02 100644
Binary files a/tex/context/base/status-files.pdf and b/tex/context/base/status-files.pdf differ
diff --git a/tex/context/base/status-lua.log b/tex/context/base/status-lua.log
index 83bb6385c..064c85656 100644
--- a/tex/context/base/status-lua.log
+++ b/tex/context/base/status-lua.log
@@ -1,6 +1,6 @@
 (cont-yes.mkiv
 
-ConTeXt  ver: 2013.08.21 10:55 MKIV beta  fmt: 2013.8.21  int: english/english
+ConTeXt  ver: 2013.08.23 13:16 MKIV beta  fmt: 2013.8.23  int: english/english
 
 system          > 'cont-new.mkiv' loaded
 (cont-new.mkiv)
diff --git a/tex/context/base/typo-fln.mkiv b/tex/context/base/typo-fln.mkiv
index 98577d91e..10b99c809 100644
--- a/tex/context/base/typo-fln.mkiv
+++ b/tex/context/base/typo-fln.mkiv
@@ -80,8 +80,11 @@
 \to \everydefinefirstline
 
 \unexpanded\def\setfirstline[#1]%
-  {\edef\typo_firstline_set
-     {\typo_firstline_set_indeed{\number\csname\??firstline:#1\endcsname}}}
+  {\ifcsname\??firstline:#1\endcsname
+     \edef\typo_firstline_set{\typo_firstline_set_indeed{\number\csname\??firstline:#1\endcsname}}%
+   \else
+     \let\typo_firstline_set\relax
+   \fi}
 
 \unexpanded\def\typo_firstline_set_indeed#1%
   {\dontleavehmode
diff --git a/tex/context/base/util-str.lua b/tex/context/base/util-str.lua
index 13e1e0922..295fc0044 100644
--- a/tex/context/base/util-str.lua
+++ b/tex/context/base/util-str.lua
@@ -281,6 +281,7 @@ local tracedchar = string.tracedchar
 local autosingle = string.autosingle
 local autodouble = string.autodouble
 local sequenced = table.sequenced
+local formattednumber = number.formatted
 ]]
 
 local template = [[
@@ -520,6 +521,61 @@ local format_W = function(f) -- handy when doing depth related indent
     return format("nspaces[%s]",tonumber(f) or 0)
 end
 
+-- maybe to util-num
+
+local digit  = patterns.digit
+local period = patterns.period
+local three  = digit * digit * digit
+
+local splitter = Cs (
+    (((1 - (three^1 * period))^1 + C(three)) * (Carg(1) * three)^1 + C((1-period)^1))
+  * (P(1)/"" * Carg(2)) * C(2)
+)
+
+patterns.formattednumber = splitter
+
+function number.formatted(n,sep1,sep2)
+    local s = type(s) == "string" and n or format("%0.2f",n)
+    if sep1 == true then
+        return lpegmatch(splitter,s,1,".",",")
+    elseif sep1 == "." then
+        return lpegmatch(splitter,s,1,sep1,sep2 or ",")
+    elseif sep1 == "," then
+        return lpegmatch(splitter,s,1,sep1,sep2 or ".")
+    else
+        return lpegmatch(splitter,s,1,sep1 or ",",sep2 or ".")
+    end
+end
+
+-- print(number.formatted(1))
+-- print(number.formatted(12))
+-- print(number.formatted(123))
+-- print(number.formatted(1234))
+-- print(number.formatted(12345))
+-- print(number.formatted(123456))
+-- print(number.formatted(1234567))
+-- print(number.formatted(12345678))
+-- print(number.formatted(12345678,true))
+-- print(number.formatted(1234.56,"!","?"))
+
+local format_m = function(f)
+    n = n + 1
+    if not f or f == "" then
+        f = ","
+    end
+    return format([[formattednumber(a%s,%q,".")]],n,f)
+end
+
+local format_M = function(f)
+    n = n + 1
+    if not f or f == "" then
+        f = "."
+    end
+    return format([[formattednumber(a%s,%q,",")]],n,f)
+end
+
+--
+
 local format_rest = function(s)
     return format("%q",s) -- catches " and \n and such
 end
@@ -574,6 +630,7 @@ local builder = Cs { "start",
               + V("W") -- new
               + V("a") -- new
               + V("A") -- new
+              + V("m") + V("M") -- new
               --
               + V("*") -- ignores probably messed up %
             )
@@ -617,6 +674,9 @@ local builder = Cs { "start",
     ["w"] = (prefix_any * P("w")) / format_w, -- %w => n spaces (optional prefix is added)
     ["W"] = (prefix_any * P("W")) / format_W, -- %W => mandate prefix, no specifier
     --
+    ["m"] = (prefix_tab * P("m")) / format_m, -- %m => xxx.xxx.xxx,xx (optional prefix instead of .)
+    ["M"] = (prefix_tab * P("M")) / format_M, -- %M => xxx,xxx,xxx.xx (optional prefix instead of ,)
+    --
     ["a"] = (prefix_any * P("a")) / format_a, -- %a => '...' (forces tostring)
     ["A"] = (prefix_any * P("A")) / format_A, -- %A => "..." (forces tostring)
     --
@@ -647,7 +707,7 @@ local function make(t,str)
         p = lpegmatch(builder,str,1,"..",t._extensions_) -- after this we know n
         if n > 0 then
             p = format(template,preamble,t._preamble_,arguments[n],p)
---           print("builder>",p)
+--                 print("builder>",p)
             f = loadstripped(p)()
         else
             f = function() return str end
diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua
index eb4194713..9632faec5 100644
--- a/tex/generic/context/luatex/luatex-fonts-merged.lua
+++ b/tex/generic/context/luatex/luatex-fonts-merged.lua
@@ -1,6 +1,6 @@
 -- merged file : luatex-fonts-merged.lua
 -- parent file : luatex-fonts.lua
--- merge date  : 08/22/13 15:28:35
+-- merge date  : 08/23/13 13:16:33
 
 do -- begin closure to overcome local limits and interference
 
@@ -2621,6 +2621,7 @@ local tracedchar = string.tracedchar
 local autosingle = string.autosingle
 local autodouble = string.autodouble
 local sequenced = table.sequenced
+local formattednumber = number.formatted
 ]]
 local template=[[
 %s
@@ -2817,6 +2818,39 @@ end
 local format_W=function(f) 
   return format("nspaces[%s]",tonumber(f) or 0)
 end
+local digit=patterns.digit
+local period=patterns.period
+local three=digit*digit*digit
+local splitter=Cs (
+  (((1-(three^1*period))^1+C(three))*(Carg(1)*three)^1+C((1-period)^1))*(P(1)/""*Carg(2))*C(2)
+)
+patterns.formattednumber=splitter
+function number.formatted(n,sep1,sep2)
+  local s=type(s)=="string" and n or format("%0.2f",n)
+  if sep1==true then
+    return lpegmatch(splitter,s,1,".",",")
+  elseif sep1=="." then
+    return lpegmatch(splitter,s,1,sep1,sep2 or ",")
+  elseif sep1=="," then
+    return lpegmatch(splitter,s,1,sep1,sep2 or ".")
+  else
+    return lpegmatch(splitter,s,1,sep1 or ",",sep2 or ".")
+  end
+end
+local format_m=function(f)
+  n=n+1
+  if not f or f=="" then
+    f=","
+  end
+  return format([[formattednumber(a%s,%q,".")]],n,f)
+end
+local format_M=function(f)
+  n=n+1
+  if not f or f=="" then
+    f="."
+  end
+  return format([[formattednumber(a%s,%q,",")]],n,f)
+end
 local format_rest=function(s)
   return format("%q",s) 
 end
@@ -2854,7 +2888,8 @@ local builder=Cs { "start",
 +V("w") 
 +V("W") 
 +V("a") 
-+V("A")
++V("A") 
++V("m")+V("M")
 +V("*") 
       )+V("*")
     )*(P(-1)+Carg(1))
@@ -2890,6 +2925,8 @@ local builder=Cs { "start",
   ["I"]=(prefix_any*P("I"))/format_I,
   ["w"]=(prefix_any*P("w"))/format_w,
   ["W"]=(prefix_any*P("W"))/format_W,
+  ["m"]=(prefix_tab*P("m"))/format_m,
+  ["M"]=(prefix_tab*P("M"))/format_M,
   ["a"]=(prefix_any*P("a"))/format_a,
   ["A"]=(prefix_any*P("A"))/format_A,
   ["*"]=Cs(((1-P("%"))^1+P("%%")/"%%")^1)/format_rest,
-- 
cgit v1.2.3