From b3f3cb27a35cd05a3c87e610cd616e19a8938359 Mon Sep 17 00:00:00 2001 From: Context Git Mirror Bot Date: Wed, 5 Nov 2014 16:15:04 +0100 Subject: 2014-11-05 15:24:00 --- tex/context/base/back-exp.lua | 2 +- tex/context/base/buff-ver.lua | 2 +- tex/context/base/cont-new.mkiv | 2 +- tex/context/base/context-version.pdf | Bin 4386 -> 4389 bytes tex/context/base/context.mkiv | 2 +- tex/context/base/font-ctx.lua | 2 +- tex/context/base/l-dir.lua | 4 +- tex/context/base/l-unicode.lua | 16 +- tex/context/base/lpdf-ano.lua | 33 +- tex/context/base/lxml-lpt.lua | 9 +- tex/context/base/lxml-tab.lua | 2 +- tex/context/base/m-matrix.mkiv | 512 +++++++++++++++++++++ tex/context/base/meta-tex.lua | 4 - tex/context/base/publ-imp-apa.lua | 55 ++- tex/context/base/publ-ini.lua | 2 +- tex/context/base/spac-chr.lua | 4 +- tex/context/base/status-files.pdf | Bin 24680 -> 24692 bytes tex/context/base/status-lua.pdf | Bin 334514 -> 333240 bytes tex/context/base/strc-bkm.lua | 29 +- tex/context/base/strc-doc.lua | 8 +- tex/context/base/trac-lmx.lua | 4 +- tex/context/base/trac-log.lua | 2 +- tex/context/base/typo-dub.lua | 2 +- tex/context/base/typo-prc.lua | 21 +- tex/context/base/typo-tal.lua | 105 +++-- tex/context/base/x-mathml.lua | 22 +- tex/generic/context/luatex/luatex-fonts-merged.lua | 2 +- 27 files changed, 694 insertions(+), 152 deletions(-) create mode 100644 tex/context/base/m-matrix.mkiv (limited to 'tex') diff --git a/tex/context/base/back-exp.lua b/tex/context/base/back-exp.lua index 0873e46b2..485a36e2f 100644 --- a/tex/context/base/back-exp.lua +++ b/tex/context/base/back-exp.lua @@ -1413,7 +1413,7 @@ do end end - function stripmath(di) + local function stripmath(di) if not di then -- elseif di.content then diff --git a/tex/context/base/buff-ver.lua b/tex/context/base/buff-ver.lua index 63f5bdfab..bc8ea6597 100644 --- a/tex/context/base/buff-ver.lua +++ b/tex/context/base/buff-ver.lua @@ -744,7 +744,7 @@ end -- needed in e.g. tabulate (manuals) local compact_all = Cs((P("\\") * ((1-S("\\ "))^1) * (P(" ")/"") * (P(-1) + S("[{")) + 1)^0) -local compact_absolute = Cs((P("\\") * ((1-S("\\ [{"))^1) * (P(" ")/"" * (S("[{\\"))) + 1) ^0) +local compact_absolute = Cs((P("\\") * ((1-S("\\ [{.,-_"))^1) * (P(" ")/"" * (S("[{\\.,-_"))) + 1) ^0) local compact_last = Cs((P(" ")^1 * P(-1)/"" + 1)^0) function commands.typestring(settings) diff --git a/tex/context/base/cont-new.mkiv b/tex/context/base/cont-new.mkiv index d76b46418..ee0f9c092 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{2014.11.04 19:10} +\newcontextversion{2014.11.05 15:22} %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 175cd14ea..5cee56c55 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 360233529..c90cac87b 100644 --- a/tex/context/base/context.mkiv +++ b/tex/context/base/context.mkiv @@ -28,7 +28,7 @@ %D up and the dependencies are more consistent. \edef\contextformat {\jobname} -\edef\contextversion{2014.11.04 19:10} +\edef\contextversion{2014.11.05 15:22} \edef\contextkind {beta} %D For those who want to use this: diff --git a/tex/context/base/font-ctx.lua b/tex/context/base/font-ctx.lua index ac0de42ec..2a12a807a 100644 --- a/tex/context/base/font-ctx.lua +++ b/tex/context/base/font-ctx.lua @@ -1313,7 +1313,7 @@ function constructors.calculatescale(tfmdata,scaledpoints,relativeid,specificati end end end - scaledpoints, delta = calculatescale(tfmdata,scaledpoints) + local scaledpoints, delta = calculatescale(tfmdata,scaledpoints) -- if enable_auto_r_scale and relativeid then -- for the moment this is rather context specific (we need to hash rscale then) -- local relativedata = fontdata[relativeid] -- local rfmdata = relativedata and relativedata.unscaled and relativedata.unscaled diff --git a/tex/context/base/l-dir.lua b/tex/context/base/l-dir.lua index bcf28d011..c56af1b73 100644 --- a/tex/context/base/l-dir.lua +++ b/tex/context/base/l-dir.lua @@ -156,7 +156,7 @@ end local function globpattern(path,patt,recurse,method) local kind = type(method) - if pattern and sub(patt,1,-3) == path then + if patt and sub(patt,1,-3) == path then patt = false end if kind == "function" then @@ -209,7 +209,7 @@ end dir.collectpattern = collectpattern -local separator +local separator, pattern if onwindows then -- we could sanitize here diff --git a/tex/context/base/l-unicode.lua b/tex/context/base/l-unicode.lua index 53a23260a..02dd1a003 100644 --- a/tex/context/base/l-unicode.lua +++ b/tex/context/base/l-unicode.lua @@ -727,7 +727,7 @@ local utf_32_le_linesplitter = utf_32_le_getbom * lpeg.tsplitat(patterns.utf_32_ -- return concat(result) -- end -- --- utf16_to_utf8_be_t = function(t) +-- local utf16_to_utf8_be_t = function(t) -- if not t then -- return nil -- elseif type(t) == "string" then @@ -786,7 +786,7 @@ local utf_32_le_linesplitter = utf_32_le_getbom * lpeg.tsplitat(patterns.utf_32_ -- return concat(result) -- end -- --- utf16_to_utf8_le_t = function(t) +-- local utf16_to_utf8_le_t = function(t) -- if not t then -- return nil -- elseif type(t) == "string" then @@ -819,7 +819,7 @@ local utf_32_le_linesplitter = utf_32_le_getbom * lpeg.tsplitat(patterns.utf_32_ -- return t -- end -- --- utf32_to_utf8_be_t = function(t) +-- local utf32_to_utf8_be_t = function(t) -- if not t then -- return nil -- elseif type(t) == "string" then @@ -846,7 +846,7 @@ local utf_32_le_linesplitter = utf_32_le_getbom * lpeg.tsplitat(patterns.utf_32_ -- return t -- end -- --- utf32_to_utf8_le_t = function(t) +-- local utf32_to_utf8_le_t = function(t) -- if not t then -- return nil -- elseif type(t) == "string" then @@ -928,7 +928,7 @@ utf16_to_utf8_be = function(s) end end -utf16_to_utf8_be_t = function(t) +local utf16_to_utf8_be_t = function(t) if not t then return nil elseif type(t) == "string" then @@ -951,7 +951,7 @@ utf16_to_utf8_le = function(s) end end -utf16_to_utf8_le_t = function(t) +local utf16_to_utf8_le_t = function(t) if not t then return nil elseif type(t) == "string" then @@ -974,7 +974,7 @@ utf32_to_utf8_be = function(s) end end -utf32_to_utf8_be_t = function(t) +local utf32_to_utf8_be_t = function(t) if not t then return nil elseif type(t) == "string" then @@ -997,7 +997,7 @@ utf32_to_utf8_le = function(s) end end -utf32_to_utf8_le_t = function(t) +local utf32_to_utf8_le_t = function(t) if not t then return nil elseif type(t) == "string" then diff --git a/tex/context/base/lpdf-ano.lua b/tex/context/base/lpdf-ano.lua index 7e43ad39a..dd83a44db 100644 --- a/tex/context/base/lpdf-ano.lua +++ b/tex/context/base/lpdf-ano.lua @@ -116,7 +116,7 @@ local pdf_border_style = pdfarray { 0, 0, 0 } -- radius radius linewidth local pdf_border_color = nil local set_border = false -function pdfborder() +local function pdfborder() border_set = true return pdf_border_style, pdf_border_color end @@ -1036,7 +1036,7 @@ function specials.action(var) end end -local function build(levels,start,parent,method) +local function build(levels,start,parent,method,nested) local startlevel = levels[start].level local i, n = start, 0 local child, entry, m, prev, first, last, f, l @@ -1073,14 +1073,19 @@ local function build(levels,start,parent,method) if variant == "unknown" then -- error, ignore i = i + 1 - elseif level < startlevel then - if entry then - pdfflushobject(child,entry) - else - -- some error + elseif level <= startlevel then + if level < startlevel then + if nested then -- could be an option but otherwise we quit too soon + if entry then + pdfflushobject(child,entry) + else + report_bookmark("error 1") + end + return i, n, first, last + else + report_bookmark("confusing level change at level %a around %a",level,title) + end end - return i, n, first, last - elseif level == startlevel then if trace_bookmarks then report_bookmark("%3i %w%s %s",reference.realpage,(level-1)*2,(opened and "+") or "-",title) end @@ -1109,7 +1114,7 @@ local function build(levels,start,parent,method) n = n + 1 i = i + 1 elseif i < #levels and level > startlevel then - i, m, f, l = build(levels,i,pdfreference(child),method) + i, m, f, l = build(levels,i,pdfreference(child),method,true) if entry then entry.Count = (opened and m) or -m if m > 0 then @@ -1117,11 +1122,11 @@ local function build(levels,start,parent,method) entry.Last = pdfreference(l) end else - -- some error + report_bookmark("error 2") end else -- missing intermediate level but ok - i, m, f, l = build(levels,i,pdfreference(child),method) + i, m, f, l = build(levels,i,pdfreference(child),method,true) if entry then entry.Count = (opened and m) or -m if m > 0 then @@ -1130,7 +1135,7 @@ local function build(levels,start,parent,method) end pdfflushobject(child,entry) else - -- some error + report_bookmark("error 3") end return i, n, first, last end @@ -1143,7 +1148,7 @@ end function codeinjections.addbookmarks(levels,method) if levels and #levels > 0 then local parent = pdfreserveobject() - local _, m, first, last = build(levels,1,pdfreference(parent),method or "internal") + local _, m, first, last = build(levels,1,pdfreference(parent),method or "internal",false) local dict = pdfdictionary { Type = pdfconstant("Outlines"), First = pdfreference(first), diff --git a/tex/context/base/lxml-lpt.lua b/tex/context/base/lxml-lpt.lua index d99688b8b..a914c43ca 100644 --- a/tex/context/base/lxml-lpt.lua +++ b/tex/context/base/lxml-lpt.lua @@ -544,12 +544,11 @@ local lp_builtin = P ( local lp_attribute = (P("@") + P("attribute::")) / "" * Cc("(ll.at and ll.at['") * ((R("az","AZ") + S("-_:"))^1) * Cc("'])") --- lp_fastpos_p = (P("+")^0 * R("09")^1 * P(-1)) / function(s) return "l==" .. s end --- lp_fastpos_n = (P("-") * R("09")^1 * P(-1)) / function(s) return "(" .. s .. "<0 and (#list+".. s .. "==l))" end - -lp_fastpos_p = P("+")^0 * R("09")^1 * P(-1) / "l==%0" -lp_fastpos_n = P("-") * R("09")^1 * P(-1) / "(%0<0 and (#list+%0==l))" +----- lp_fastpos_p = (P("+")^0 * R("09")^1 * P(-1)) / function(s) return "l==" .. s end +----- lp_fastpos_n = (P("-") * R("09")^1 * P(-1)) / function(s) return "(" .. s .. "<0 and (#list+".. s .. "==l))" end +local lp_fastpos_p = P("+")^0 * R("09")^1 * P(-1) / "l==%0" +local lp_fastpos_n = P("-") * R("09")^1 * P(-1) / "(%0<0 and (#list+%0==l))" local lp_fastpos = lp_fastpos_n + lp_fastpos_p local lp_reserved = C("and") + C("or") + C("not") + C("div") + C("mod") + C("true") + C("false") diff --git a/tex/context/base/lxml-tab.lua b/tex/context/base/lxml-tab.lua index 369ac91c7..6ab12c898 100644 --- a/tex/context/base/lxml-tab.lua +++ b/tex/context/base/lxml-tab.lua @@ -800,7 +800,7 @@ end -- Because we can have a crash (stack issues) with faulty xml, we wrap this one -- in a protector: -function xmlconvert(data,settings) +local function xmlconvert(data,settings) local ok, result = pcall(function() return _xmlconvert_(data,settings) end) if ok then return result diff --git a/tex/context/base/m-matrix.mkiv b/tex/context/base/m-matrix.mkiv new file mode 100644 index 000000000..8aa8074f7 --- /dev/null +++ b/tex/context/base/m-matrix.mkiv @@ -0,0 +1,512 @@ +%D \module +%D [ file=m-matrix, +%D version=2014.11.04, % already a year older +%D title=\CONTEXT\ Extra Modules, +%D subtitle=Matrices, +%D author={Jeong Dalyoung \& Hans Hagen}, +%D date=\currentdate, +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +%D This code is based on a post by Dalyoung on the context list. After that +%D we turned it into a module and improved the code a bit. Feel free to ask +%D us for more. Once we're satisfied, a more general helper l-matrix could +%D be made. Dalyoung does the clever bits, and Hans only cleanes up and +%D optimizes a bit. + +% \registerctxluafile{l-matrix}{1.001} % not yet + +\startmodule[matrix] + +\startluacode + +local settings_to_hash = utilities.parsers.settings_to_hash +local formatters = string.formatters +local copy = table.copy +local insert = table.insert +local remove = table.remove + +local matrix = { } +moduledata.matrix = matrix + +local f_matrix_slot = formatters["%s_{%s%s}"] + +function matrix.symbolic(sym, x, y, nx ,ny) -- symMatrix("a", "m", "n") + local nx = nx or 2 + local ny = ny or nx + local function filled(i,y) + local mrow = { } + for j=1,nx do + mrow[#mrow+1] = f_matrix_slot(sym,i,j) + end + mrow[#mrow+1] = "\\cdots" + mrow[#mrow+1] = f_matrix_slot(sym,i,y) + return mrow + end + local function dummy() + local mrow = { } + for j=1,nx do + mrow[#mrow+1] = "\\vdots" + end + mrow[#mrow+1] = "\\ddots" + mrow[#mrow+1] = "\\vdots" + return mrow + end + -- + local mm = { } + for i=1,ny do + mm[i] = filled(i,y) + end + mm[#mm+1] = dummy() + mm[#mm+1] = filled(x,y) + return mm +end + +-- todo: define a matrix at the tex end so that we have more control + +local fences_p = { + left = "\\left(\\,", + right = "\\,\\right)", +} + +local fences_b = { + left = "\\left[\\,", + right = "\\,\\right]", +} + +function matrix.typeset(m,options) + local options = settings_to_hash(options or "") + context.startmatrix(options.determinant and fences_b or fences_p) + for i=1, #m do + local mi = m[i] + for j=1,#mi do + context.NC(mi[j]) + end + context.NR() + end + context.stopmatrix() +end + +-- interchange two rows (i-th, j-th) + +function matrix.swap(t,i,j) + t[i], t[j] = t[j], t[i] +end + +-- replace i-th row with factor * (i-th row) + +function matrix.multiply(m,i,factor) + if m then + local mi = m[i] + for k=1,#mi do + mi[k] = factor * mi[k] + end + elseif i then + factor = i + for i=1,#m do + local mi = m[i] + for j=1,#mi do + mi[j] = factor * mi[j] + end + end + end + return m +end + +-- replace i-th row with i-th row + factor * (j-th row) + +function matrix.sumrow(m,i,j,factor) + local mi = m[i] + local mj = m[j] + for k=1,#mi do + mi[k] = mi[k] + factor * mj[k] + end +end + +-- transpose of a matrix + +function matrix.transpose(m) + local t = { } + for j=1,#m[1] do + local r = { } + for i=1,#m do + r[i] = m[i][j] + end + t[j] = r + end + return t +end + +-- inner product of two vectors + +function matrix.inner(u,v) + local nu = #u + if nu == 0 then + return 0 + end + local nv = #v + if nv ~= nu then + return 0 + end + local result = 0 + for i=1,nu do + result = result + u[i] * v[i] + end + return result +end + +-- product of two matrices + +function matrix.product(m1,m2) + local product = { } + if #m1[1] == #m2 then + for i=1,#m1 do + local m1i = m1[i] + local mrow = { } + for j=1,#m2[1] do + local temp = 0 + for k=1,#m1[1] do + temp = temp + m1i[k] * m2[k][j] + end + mrow[j] = temp + end + product[i] = mrow + end + end + return product +end + +function matrix.search(m,i) + for k=i+1,#m do -- searches from the next row + if m[k][i] == 0 then + k = k + 1 + else + return k + end + end + return 0 +end + +local function uppertri(m,sign) + local temp = copy(m) + for i=1,#temp-1 do + local pivot = temp[i][i] + if pivot == 0 then + local pRow = i +1 + while temp[pRow][i] == 0 do + pRow = pRow + 1 + if pRow > #temp then -- if there is no nonzero number + return temp + end + end + temp[i], temp[pRow] = temp[pRow], temp[i] + if sign then + sign = -sign + end + end + local mi = temp[i] + for k=i+1, #temp do + local factor = -temp[k][i]/mi[i] + local mk = temp[k] + for l=i,#mk do + mk[l] = mk[l] + factor * mi[l] + end + end + end + if sign then + return temp, sign + else + return temp + end +end + +matrix.uppertri = uppertri + +function matrix.determinant(m) + if #m == #m[1] then + local d = 1 + local t, s = uppertri(m,1) + for i=1,#t do + d = d * t[i][i] + end + return s*d + else + return 0 + end +end + +local function rowechelon(m,r) + local temp = copy(m) + local pRow = 1 + local pCol = 1 + while pRow <= #temp do + local pivot = temp[pRow][pCol] + if pivot == 0 then + local i = pRow + local n = #temp + while temp[i][pCol] == 0 do + -- context("search non zero element\\crlf current value is ") + -- context(i, pCol) + -- context("\\crlf") + i = i + 1 + if i > n then + -- no nonzero number in a column + pCol = pCol + 1 + if pCol > #temp[pRow] then + -- there is no nonzero number in a row + return temp + end + i = pRow + end + end + temp[pRow], temp[i] = temp[i], temp[pRow] + -- context("check the row value\\crlf") + -- matrix.typeset(temp) + -- context("\\crlf") + end + local row = temp[pRow] + pivot = row[pCol] + for l=pCol,#row do + row[l] = row[l]/pivot + end + -- context("divide row %d by pivot element\\ ", pRow) + -- context(pRow, pCol) + -- context("\\crlf") + -- matrix.typeset(temp) + -- context("\\crlf") + if r == 1 then + -- make the "reduced row echelon form" + local row = temp[pRow] + for k=1,pRow-1 do + local current = temp[k] + local factor = -current[pCol] + local mk = current + for l=pCol,#mk do + mk[l] = mk[l] + factor * row[l] + end + end + end + -- just row echelon form + local row = temp[pRow] + for k=pRow+1, #temp do + local current = temp[k] + local factor = -current[pCol] + local mk = current + for l=pCol,#mk do + mk[l] = mk[l] + factor * row[l] + end + end + pRow = pRow + 1 + pCol = pCol + 1 + -- context("make zeros\\crlf") + -- matrix.typeset(temp) + -- context("\\par") + if pRow > #temp or pCol > #temp[1] then + pRow = #temp + 1 + end + end + return temp +end + +matrix.rowechelon = rowechelon +matrix.rowEchelon = rowechelon + +local function solve(m,c) -- solve the linear equation m X = c + local n = #m + if n ~= #c then + return copy(m) + end + local newm = copy(m) + local temp = copy(c) + for i=1,n do + insert(newm[i],temp[i]) + end + return rowechelon(newm,1) +end + +matrix.solve = solve + +local function inverse(m) + local n = #m + local temp = copy(m) + if n ~= #m[1] then + return temp + end + for i=1,n do + for j=1,n do + insert(temp[i],j == i and 1 or 0) + end + end + temp = rowechelon(temp,1) + for i=1,n do + for j=1,n do + remove(temp[i], 1) + end + end + return temp +end + +matrix.inverse = inverse + +\stopluacode + +\stopmodule + +\unexpanded\def\ctxmodulematrix#1{\ctxlua{moduledata.matrix.#1}} + +\continueifinputfile{m-matrix.mkiv} + +\starttext + +\startluacode +document.DemoMatrixA = { + { 0, 2, 4, -4, 1 }, + { 0, 0, 2, 3, 4 }, + { 2, 2, -6, 2, 4 }, + { 2, 0, -6, 9, 7 }, + { 2, 3, 4, 5, 6 }, + { 6, 6, -6, 6, 6 }, +} + +document.DemoMatrixB = { + { 0, 2, 4, -4, 1 }, + { 0, 0, 2, 3, 4 }, + { 2, 2, -6, 2, 4 }, + { 2, 0, -6, 9, 7 }, + { 2, 2, -6, 2, 4 }, + { 2, 2, -6, 2, 4 }, +} +\stopluacode + +\startsubject[title={A symbolic matrix}] + +\ctxmodulematrix{typeset(moduledata.matrix.symbolic("a", "m", "n"))} +\ctxmodulematrix{typeset(moduledata.matrix.symbolic("a", "m", "n", 4, 8))} + +\stopsubject + +\startsubject[title={Swap two rows (2 and 4)}] + +\startluacode +moduledata.matrix.typeset(document.DemoMatrixA) +context.blank() +moduledata.matrix.swap(document.DemoMatrixA, 2, 4) +context.blank() +moduledata.matrix.typeset(document.DemoMatrixA) +\stopluacode + +\stopsubject + +\startsubject[title={Multiply $3 \times r_2$}] + +\startluacode +moduledata.matrix.typeset(document.DemoMatrixA) +context.blank() +moduledata.matrix.typeset(moduledata.matrix.multiply(document.DemoMatrixA, 2, 3)) +\stopluacode + +\stopsubject + +\startsubject[title={Row 2 + $3 \times r_4$}] + +\startluacode +moduledata.matrix.typeset(document.DemoMatrixA) +context.blank() +moduledata.matrix.sumrow(document.DemoMatrixA, 2, 3, 4) +context.blank() +moduledata.matrix.typeset(document.DemoMatrixA) +\stopluacode + +\stopsubject + +\startsubject[title={Transpose a matrix}] + +\startluacode +moduledata.matrix.typeset(document.DemoMatrixA) +context.blank() +moduledata.matrix.typeset(moduledata.matrix.transpose(document.DemoMatrixA)) +\stopluacode + +\stopsubject + +\startsubject[title={The inner product of two vectors}] + +\startluacode +context(moduledata.matrix.inner({ 1, 2, 3 }, { 3, 1, 2 })) +context.blank() +context(moduledata.matrix.inner({ 1, 2, 3 }, { 3, 1, 2, 4 })) +\stopluacode + +\startsubject[title={The product of two matrices}] + +\startluacode +moduledata.matrix.typeset(document.DemoMatrixA) +context.blank() +moduledata.matrix.typeset(moduledata.matrix.product(document.DemoMatrixA,document.DemoMatrixA)) +\stopluacode + +\stopsubject + +\startsubject[title={An Upper Triangular Matrix}] + +\ctxmodulematrix{typeset(moduledata.matrix.uppertri(document.DemoMatrixB))} + +\startsubject[title={A determinant}] + +\startluacode +local m = { + { 1, 2, 4 }, + { 0, 0, 2 }, + { 2, 2, -6 }, +} +context(moduledata.matrix.determinant(m)) +\stopluacode + +\stopsubject + +\startsubject[title={Row echelon form}] + +\startluacode +local m = { + { 1, 3, -2, 0, 2, 0, 0 }, + { 2, 6, -5, -2, 4, -3, -1 }, + { 0, 0, 5, 10, 0, 15, 5 }, + { 2, 6, 0, 8, 4, 18, 6 }, +} + +moduledata.matrix.typeset(m) +moduledata.matrix.typeset(moduledata.matrix.rowechelon(m,1)) +\stopluacode + +\stopsubject + +\startsubject[title={Solving linear equation}] + +\startluacode +local m = { + { 1, 3, -2, 0 }, + { 2, 0, 1, 2 }, + { 6, -5, -2, 4 }, + { -3, -1, 5, 10 }, +} + +local c = { 5, 2, 6, 8 } + +moduledata.matrix.typeset(moduledata.matrix.solve(m,c)) +\stopluacode + +\stopsubject + +\startsubject[title={Inverse matrix}] + +\startcombination[2*1] + {\ctxlua{moduledata.matrix.typeset { { 1, 1, 1 }, { 0, 2, 3 }, { 3, 2, 1 } }}} {} + {\ctxlua{moduledata.matrix.typeset(moduledata.matrix.inverse { { 1, 1, 1 }, { 0, 2, 3 }, { 3, 2, 1 } })}} {} +\stopcombination + +\stopsubject + +\stoptext diff --git a/tex/context/base/meta-tex.lua b/tex/context/base/meta-tex.lua index 7a4123abb..771841924 100644 --- a/tex/context/base/meta-tex.lua +++ b/tex/context/base/meta-tex.lua @@ -108,10 +108,6 @@ local enumber = number * S("eE") * number local cleaner = Cs((P("@@")/"@" + P("@")/"%%" + P(1))^0) -function format_n(fmt,...) - return -end - context = context or { exponent = function(...) print(...) end } function metapost.format_string(fmt,...) diff --git a/tex/context/base/publ-imp-apa.lua b/tex/context/base/publ-imp-apa.lua index e2ef62e25..47d9a4b80 100644 --- a/tex/context/base/publ-imp-apa.lua +++ b/tex/context/base/publ-imp-apa.lua @@ -29,32 +29,32 @@ return { categories = { article = { sets = { - author = { "author", "editor" }, + authors = { "author", "editor" }, + links = { "doi", "url" }, }, - required = { "author", "title" }, - optional = { "year", "type", "journal", "volume", "number", "pages", "url", "note", "doi" }, + required = { "authors", "title" }, + optional = { "year", "subtitle", "type", "journal", "volume", "number", "pages", "note", "links" }, }, magazine = { sets = { - author = { "author", "editor" }, + authors = { "author", "editor" }, }, - required = { "author", "editor", "title", "journal", "year" }, + required = { "authors", "title", "journal", "year" }, optional = { "volume", "number", "pages", "month", "day", "note", "url", "doi" }, }, newspaper = { sets = { - author = { "author", "editor" }, + authors = { "author", "editor" }, }, - required = { "author", "title", "journal", "year" }, + required = { "authors", "title", "journal", "year" }, optional = { "volume", "number", "pages", "month", "day", "note", "url", "doi" }, }, book = { sets = { - author = { "author", "editor", "publisher" }, + authors = { "author", "editor", "publisher" }, }, - virtual = { "authoryear" }, - required = { "author", "title" }, - optional = { "year", "month", "day", "title", "type", "edition", "series", "volume", "number", "pages", "address", "publisher", "url", "note", "ISBN" }, + required = { "authors", "title" }, + optional = { "year", "month", "day", "title", "type", "edition", "series", "volume", "number", "pages", "address", "url", "note", "ISBN" }, }, booklet = { required = { "title" }, @@ -62,28 +62,27 @@ return { }, inbook = { sets = { - author = { "author", "editor", "publisher" }, + authors = { "author", "editor", "publisher" }, }, - required = { "author", "title", "chapter", "pages", "year" }, + required = { "authors", "title", "chapter", "pages", "year" }, optional = { "volume", "number", "series", "type", "address", "edition", "month", "note", "ISBN" }, - author = { "author", "editor", "publisher" }, }, incollection = { sets = { - author = { "author", "editor", "publisher" }, + authors = { "author", "editor", "publisher" }, }, - required = { "author", "title", "booktitle", "publisher", "year" }, - optional = { "editor", "volume", "number", "series", "type", "chapter", "pages", "address", "edition", "month", "note", "ISBN" }, + required = { "authors", "title", "booktitle", "year" }, + optional = { "volume", "number", "series", "type", "chapter", "pages", "address", "edition", "month", "note", "ISBN" }, }, inproceedings = { sets = { - author = { "author", "editor", "publisher" }, + authors = { "author", "editor", "publisher" }, }, - required = { "author", "title", "booktitle", "year" }, - optional = { "editor", "volume", "number", "series", "pages", "address", "month", "organization", "publisher", "note", "ISBN" }, + required = { "authors", "title", "booktitle", "year" }, + optional = { "volume", "number", "series", "pages", "address", "month", "organization", "note", "ISBN" }, }, conference = - "inproceedings", -- Alan: does this work? Hans: I just made it work. + "inproceedings", manual = { required = { "title" }, optional = { "author", "organization", "address", "edition", "month", "year", "note" }, @@ -104,14 +103,12 @@ return { required = { }, optional = { "author", "title", "howpublished", "month", "year", "note" }, }, - -- Not sure yet how "periodical" is used... but "jabref" includes it as standard. - -- strangely, "jabref" does not include "author" as required nor optional.. periodical = { sets = { - author = { "editor", "publisher" }, + authors = { "editor", "publisher" }, }, required = { "title", "year" }, - optional = { "author", "editor", "month", "note", "number", "organization", "series", "volume" }, + optional = { "authors", "month", "note", "number", "organization", "series", "volume" }, }, proceedings = { required = { "title", "year" }, @@ -136,9 +133,9 @@ return { -- check this! standard = { sets = { - author = { "author", "institution", "organization" }, + authors = { "author", "institution", "organization" }, }, - required = { "author", "title", "year", "note", "url" }, + required = { "authors", "title", "year", "note", "url" }, optional = { "doi", }, }, unpublished = { @@ -150,7 +147,9 @@ return { optional = { }, virtual = false, }, - -- + -- + -- the following fields are for documentation and testing purposes + -- ["demo-a"] = { sets = { author = { "author", "institution", "organization" }, diff --git a/tex/context/base/publ-ini.lua b/tex/context/base/publ-ini.lua index 8e273be00..6485e880b 100644 --- a/tex/context/base/publ-ini.lua +++ b/tex/context/base/publ-ini.lua @@ -541,7 +541,7 @@ local concatstate = publications.concatstate local tobemarked = nil -function marknocite(dataset,tag,nofcitations) -- or just: ctx_btxdomarkcitation +local function marknocite(dataset,tag,nofcitations) -- or just: ctx_btxdomarkcitation ctx_btxstartcite() ctx_btxsetdataset(dataset) ctx_btxsettag(tag) diff --git a/tex/context/base/spac-chr.lua b/tex/context/base/spac-chr.lua index cdc56e552..3fcfafe17 100644 --- a/tex/context/base/spac-chr.lua +++ b/tex/context/base/spac-chr.lua @@ -18,9 +18,9 @@ local byte, lower = string.byte, string.lower local next = next -trace_characters = false trackers.register("typesetters.characters", function(v) trace_characters = v end) +local trace_characters = false trackers.register("typesetters.characters", function(v) trace_characters = v end) -report_characters = logs.reporter("typesetting","characters") +local report_characters = logs.reporter("typesetting","characters") local nodes, node = nodes, node diff --git a/tex/context/base/status-files.pdf b/tex/context/base/status-files.pdf index ec195ea83..35ad7a3e7 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.pdf b/tex/context/base/status-lua.pdf index aeaa95681..4de759648 100644 Binary files a/tex/context/base/status-lua.pdf and b/tex/context/base/status-lua.pdf differ diff --git a/tex/context/base/strc-bkm.lua b/tex/context/base/strc-bkm.lua index cfba5860e..527188f23 100644 --- a/tex/context/base/strc-bkm.lua +++ b/tex/context/base/strc-bkm.lua @@ -161,9 +161,14 @@ function bookmarks.place() if numbered[name] then local sectiondata = sections.collected[li.references.section] local numberdata = li.numberdata - if sectiondata and numberdata and not numberdata.hidenumber then + if sectiondata and numberdata then + if not numberdata.hidenumber then -- we could typeset the number and convert it - title = concat(sections.typesetnumber(sectiondata,"direct",numberspec,sectiondata)) .. " " .. title + local number = sections.typesetnumber(sectiondata,"direct",numberspec,sectiondata) + if number and #number > 0 then + title = concat(number) .. " " .. title + end + end end end noflevels = noflevels + 1 @@ -196,7 +201,18 @@ function bookmarks.flatten(levels) -- following code runs over section blocks as well. (bookmarks-007.tex) local noflevels = #levels if noflevels > 1 then + local function showthem() + for i=1,noflevels do + local level = levels[i] + report_bookmarks("%i > %s > %s",level.level,level.reference.block,level.title) + end + end + if trace_bookmarks then + report_bookmarks("checking structure") + showthem() + end local skip = false + local done = 0 local start = 1 local one = levels[1] local first = one.level @@ -223,10 +239,19 @@ function bookmarks.flatten(levels) if trace_bookmarks then report_bookmarks("promoting entry %a from level %a to %a: %s",j,old,new,previous.title) end + done = done + 1 end skip = true end end + if trace_bookmarks then + if done > 0 then + report_bookmarks("%a entries promoted") + showthem() + else + report_bookmarks("nothing promoted") + end + end end return levels end diff --git a/tex/context/base/strc-doc.lua b/tex/context/base/strc-doc.lua index 7d3be1620..87ad27986 100644 --- a/tex/context/base/strc-doc.lua +++ b/tex/context/base/strc-doc.lua @@ -658,10 +658,10 @@ function sections.typesetnumber(entry,kind,...) -- kind='section','number','pref criterium = 0 end -- - local firstprefix, lastprefix = 0, 16 + local firstprefix, lastprefix = 0, 16 -- too much, could max found level if segments then local f, l = match(tostring(segments),"^(.-):(.+)$") - if l == "*" then + if l == "*" or l == v_all then l = 100 -- new end if f and l then @@ -695,7 +695,7 @@ function sections.typesetnumber(entry,kind,...) -- kind='section','number','pref applyprocessor(starter) end end - if prefixlist and (kind == 'section' or kind == 'prefix' or kind == 'direct') then + if prefixlist and (kind == "section" or kind == "prefix" or kind == "direct") then -- find valid set (problem: for sectionnumber we should pass the level) -- no holes local b, e, bb, ee = 1, #prefixlist, 0, 0 @@ -763,7 +763,7 @@ function sections.typesetnumber(entry,kind,...) -- kind='section','number','pref if result then result[#result+1] = strippedprocessor(groupsuffix) else - applyprocessor(groupsuffix) + applyprocessor(groupsuffix) end end if stopper then diff --git a/tex/context/base/trac-lmx.lua b/tex/context/base/trac-lmx.lua index 41d930536..d85bd81d5 100644 --- a/tex/context/base/trac-lmx.lua +++ b/tex/context/base/trac-lmx.lua @@ -530,7 +530,7 @@ do_nested_include = function(data) -- also used in include return lpegmatch(pattern_1,data) end -function lmxnew(data,defaults,nocache,path) -- todo: use defaults in calling routines +local function lmxnew(data,defaults,nocache,path) -- todo: use defaults in calling routines data = data or "" local known = cache[data] if not known then @@ -608,7 +608,7 @@ function lmx.convertfile(templatefile,variables,nocache) return lmxresult(converter,variables) end -function lmxconvert(templatefile,resultfile,variables,nocache) -- or (templatefile,variables) +local function lmxconvert(templatefile,resultfile,variables,nocache) -- or (templatefile,variables) if trace_variables then -- will become templates report_lmx("converting file %a",templatefile) end diff --git a/tex/context/base/trac-log.lua b/tex/context/base/trac-log.lua index 90da5cfe4..ce620e6cf 100644 --- a/tex/context/base/trac-log.lua +++ b/tex/context/base/trac-log.lua @@ -102,7 +102,7 @@ setmetatableindex(logs, function(t,k) t[k] = ignore ; return ignore end) local report, subreport, status, settarget, setformats, settranslations -local direct, subdirect, writer, pushtarget, poptarget, setlogfile, settimedlog, setprocessor, setformatters +local direct, subdirect, writer, pushtarget, poptarget, setlogfile, settimedlog, setprocessor, setformatters, newline -- we use formatters but best check for % then because for simple messages but -- we don't want this overhead for single messages (not that there are that diff --git a/tex/context/base/typo-dub.lua b/tex/context/base/typo-dub.lua index 1abe5cef5..7437e2c44 100644 --- a/tex/context/base/typo-dub.lua +++ b/tex/context/base/typo-dub.lua @@ -326,7 +326,7 @@ end -- ש ( ל ( א ) כ ) 2-8,4-6 -- ש ( ל [ א ] כ ) 2-8,4-6 -function resolve_fences(list,size,start,limit) +local function resolve_fences(list,size,start,limit) -- N0: funny effects, not always better, so it's an options local stack = { } local top = 0 diff --git a/tex/context/base/typo-prc.lua b/tex/context/base/typo-prc.lua index 959cabbb8..3b94a0f10 100644 --- a/tex/context/base/typo-prc.lua +++ b/tex/context/base/typo-prc.lua @@ -6,14 +6,15 @@ if not modules then modules = { } end modules ['typo-prc'] = { license = "see context related readme files" } --- moved from strc-ini.lua - -local context, commands = context, commands -local formatters = string.formatters local lpegmatch, patterns, P, C, Cs = lpeg.match, lpeg.patterns, lpeg.P, lpeg.C, lpeg.Cs -- processors: syntax: processor->data ... not ok yet +local context = context +local commands = commands + +local formatters = string.formatters + typesetters.processors = typesetters.processors or { } local processors = typesetters.processors @@ -21,8 +22,8 @@ local trace_processors = false local report_processors = logs.reporter("processors") local registered = { } -context_applyprocessor = context.applyprocessor -context_firstofoneargument = context.firstofoneargument +local ctx_applyprocessor = context.applyprocessor +local ctx_firstofoneargument = context.firstofoneargument trackers.register("typesetters.processors", function(v) trace_processors = v end) @@ -58,7 +59,7 @@ function processors.apply(p,s) if trace_processors then report_processors("applying %s processor %a, argument: %s","known",p,s) end - context_applyprocessor(p,s) + ctx_applyprocessor(p,s) elseif s then if trace_processors then report_processors("applying %s processor %a, argument: %s","unknown",p,s) @@ -81,21 +82,21 @@ function processors.startapply(p,s) if trace_processors then report_processors("start applying %s processor %a","known",p) end - context_applyprocessor(p) + ctx_applyprocessor(p) context("{") return s elseif p then if trace_processors then report_processors("start applying %s processor %a","unknown",p) end - context_firstofoneargument() + ctx_firstofoneargument() context("{") return s else if trace_processors then report_processors("start applying %s processor","ignored") end - context_firstofoneargument() + ctx_firstofoneargument() context("{") return str end diff --git a/tex/context/base/typo-tal.lua b/tex/context/base/typo-tal.lua index d41a63dd5..c7c029ed5 100644 --- a/tex/context/base/typo-tal.lua +++ b/tex/context/base/typo-tal.lua @@ -92,6 +92,58 @@ local validsigns = { [0x2213] = 0x2213, -- minusplus } +-- If needed we can have more modes which then also means a faster simple handler +-- for non numbers. + +local function setcharacteralign(column,separator) + if not enabled then + nodes.tasks.enableaction("processors","typesetters.characteralign.handler") + enabled = true + end + if not datasets then + datasets = { } + end + local dataset = datasets[column] -- we can use a metatable + if not dataset then + local method, token + if separator then + method, token = splitmethod(separator) + if method and token then + separator = utfbyte(token) or comma + else + separator = utfbyte(separator) or comma + method = validseparators[separator] and v_number or v_text + end + else + separator = comma + method = v_number + end + dataset = { + separator = separator, + list = { }, + maxafter = 0, + maxbefore = 0, + collected = false, + method = method, + separators = validseparators, + signs = validsigns, + } + datasets[column] = dataset + used = true + end + return dataset +end + +local function resetcharacteralign() + datasets = false +end + +characteralign.setcharacteralign = setcharacteralign +characteralign.resetcharacteralign = resetcharacteralign + +commands.setcharacteralign = setcharacteralign +commands.resetcharacteralign = resetcharacteralign + local function traced_kern(w) return tracedrule(w,nil,nil,"darkgray") end @@ -327,56 +379,3 @@ function characteralign.handler(originalhead,where) end return tonode(head), true end - --- If needed we can have more modes which then also means a faster simple handler --- for non numbers. - -function setcharacteralign(column,separator) - if not enabled then - nodes.tasks.enableaction("processors","typesetters.characteralign.handler") - enabled = true - end - if not datasets then - datasets = { } - end - local dataset = datasets[column] -- we can use a metatable - if not dataset then - local method, token - if separator then - method, token = splitmethod(separator) - if method and token then - separator = utfbyte(token) or comma - else - separator = utfbyte(separator) or comma - method = validseparators[separator] and v_number or v_text - end - else - separator = comma - method = v_number - end - dataset = { - separator = separator, - list = { }, - maxafter = 0, - maxbefore = 0, - collected = false, - method = method, - separators = validseparators, - signs = validsigns, - } - datasets[column] = dataset - used = true - end - return dataset -end - -local function resetcharacteralign() - datasets = false -end - -characteralign.setcharacteralign = setcharacteralign -characteralign.resetcharacteralign = resetcharacteralign - -commands.setcharacteralign = setcharacteralign -commands.resetcharacteralign = resetcharacteralign - diff --git a/tex/context/base/x-mathml.lua b/tex/context/base/x-mathml.lua index 15739eec7..813f6d78a 100644 --- a/tex/context/base/x-mathml.lua +++ b/tex/context/base/x-mathml.lua @@ -20,6 +20,12 @@ local mathml = { } moduledata.mathml = mathml lxml.mathml = mathml -- for the moment +local context = context + +local ctx_enabledelimiter = context.enabledelimiter +local ctx_disabledelimiter = context.disabledelimiter +local ctx_xmlflush = context.xmlflush -- better xmlsprint + -- an alternative is to remap to private codes, where we can have -- different properties .. to be done; this will move and become -- generic; we can then make the private ones active in math mode @@ -502,13 +508,13 @@ function mathml.mi(id) context(rep) -- context.mi(rep) else - context.xmlflush(id) -- xmlsprint or so + ctx_xmlflush(id) -- xmlsprint or so end else - context.xmlflush(id) -- xmlsprint or so + ctx_xmlflush(id) -- xmlsprint or so end else - context.xmlflush(id) -- xmlsprint or so + ctx_xmlflush(id) -- xmlsprint or so end end @@ -516,14 +522,14 @@ function mathml.mfenced(id) -- multiple separators id = getid(id) local left, right, separators = id.at.open or "(", id.at.close or ")", id.at.separators or "," local l, r = l_replacements[left], r_replacements[right] - context.enabledelimiter() + ctx_enabledelimiter() if l then context(l_replacements[left] or o_replacements[left] or "") else context(o_replacements["@l"]) context(left) end - context.disabledelimiter() + ctx_disabledelimiter() local collected = lxml.filter(id,"/*") -- check the * if collected then local n = #collected @@ -551,14 +557,14 @@ function mathml.mfenced(id) -- multiple separators end end end - context.enabledelimiter() + ctx_enabledelimiter() if r then context(r_replacements[right] or o_replacements[right] or "") else context(right) context(o_replacements["@r"]) end - context.disabledelimiter() + ctx_disabledelimiter() end --~ local function flush(e,tag,toggle) @@ -616,7 +622,7 @@ function mathml.mmultiscripts(id) elseif done then toggle = flush(e,tag,toggle) else - xmlsprint(e.dt) + xmlsprint(e) done = true end end diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index d64b89c3c..5979c5749 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 : 11/04/14 19:10:15 +-- merge date : 11/05/14 15:22:17 do -- begin closure to overcome local limits and interference -- cgit v1.2.3