From 056c9e0d93dfc35d66ade03b1f144afc319aeaac Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Mon, 26 Oct 2009 17:23:00 +0100 Subject: beta 2009.10.26 17:23 --- tex/context/base/cont-new.tex | 2 +- tex/context/base/context.tex | 2 +- tex/context/base/font-ini.mkiv | 26 ++-- tex/context/base/grph-inc.lua | 11 +- tex/context/base/l-file.lua | 1 + tex/context/base/lxml-xml.lua | 2 +- tex/context/base/mult-cld.lua | 74 ++++++---- tex/context/base/mult-de.tex | 1 + tex/context/base/mult-def.lua | 4 + tex/context/base/mult-en.tex | 1 + tex/context/base/mult-fr.tex | 1 + tex/context/base/mult-it.tex | 1 + tex/context/base/mult-nl.tex | 1 + tex/context/base/mult-ro.tex | 1 + tex/context/base/strc-des.mkiv | 9 +- tex/context/base/strc-reg.mkiv | 9 +- tex/context/base/x-cals.lua | 209 ++++++++++++++++++++++++++++ tex/context/base/x-cals.mkiv | 207 +-------------------------- tex/context/base/x-ct.lua | 182 ++++++++++++++++++++++++ tex/context/base/x-ct.mkiv | 148 +------------------- tex/context/interface/keys-cs.xml | 1 + tex/context/interface/keys-de.xml | 1 + tex/context/interface/keys-en.xml | 1 + tex/context/interface/keys-fr.xml | 1 + tex/context/interface/keys-it.xml | 1 + tex/context/interface/keys-nl.xml | 1 + tex/context/interface/keys-pe.xml | 1 + tex/context/interface/keys-ro.xml | 1 + tex/context/sample/demo-cld.cld | 74 ---------- tex/generic/context/luatex-fonts-merged.lua | 3 +- 30 files changed, 504 insertions(+), 473 deletions(-) create mode 100644 tex/context/base/x-cals.lua create mode 100644 tex/context/base/x-ct.lua delete mode 100644 tex/context/sample/demo-cld.cld (limited to 'tex') diff --git a/tex/context/base/cont-new.tex b/tex/context/base/cont-new.tex index 1ffd5cbd3..e042744f9 100644 --- a/tex/context/base/cont-new.tex +++ b/tex/context/base/cont-new.tex @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2009.10.24 16:44} +\newcontextversion{2009.10.26 17:23} %D This file is loaded at runtime, thereby providing an %D excellent place for hacks, patches, extensions and new diff --git a/tex/context/base/context.tex b/tex/context/base/context.tex index b822ec308..a1e671034 100644 --- a/tex/context/base/context.tex +++ b/tex/context/base/context.tex @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2009.10.24 16:44} +\edef\contextversion{2009.10.26 17:23} %D For those who want to use this: diff --git a/tex/context/base/font-ini.mkiv b/tex/context/base/font-ini.mkiv index 2b4dbdaf7..936b6e537 100644 --- a/tex/context/base/font-ini.mkiv +++ b/tex/context/base/font-ini.mkiv @@ -949,16 +949,8 @@ \def\setupfontsynonym {\dodoubleempty\dosetupfontsynonym} -\def\dosetupfontsynonym[#1][#2]% - {\edef\@@fontdata{#2}% - \ifx\@@fontdata\empty \else - \edef\@@fontfile{#1}% - \ifx\fontclass\empty - \getfontparameters - \else - \getglobalfontparameters - \fi - \fi} +\def\dosetupfontsynonym[#1][#2]% not yet supported, will do when needed + {} \def\truefontname#1% {\@EA\dotruefontname#1*\empty*\relax} @@ -1349,12 +1341,9 @@ % we test for em as we assume it to be set \else \def\docommand##1% -% fails: \def\checkbodyfontenvironment[#1]{! #1 ! \definebodyfontenvironment[\fontclass][#1][]} \setupbodyfont[8.5pt] -% {\normalizebodyfontsize\csname\??ft\s!default##1\endcsname\dimexpr#1\relax\to\tempbodyfontsize -% \letvalue{\??ft#2#1##1}\tempbodyfontsize}% - {\scratchdimen\csname\??ft\s!default##1\endcsname\dimexpr#1\relax - \normalizebodyfontsize\scratchdimen\to\tempbodyfontsize - \letvalue{\??ft#2#1##1}\tempbodyfontsize}% + {\scratchdimen\csname\??ft\s!default##1\endcsname\dimexpr#1\relax + \normalizebodyfontsize\scratchdimen\to\tempbodyfontsize + \letvalue{\??ft#2#1##1}\tempbodyfontsize}% \processcommacommand[\fontrelativesizelist]\docommand \copyparameters [\??ft#2#1][\??ft\s!default] @@ -1370,7 +1359,10 @@ \else % prevent loop (hence \empty) \letvalue{\@size@#1}\empty + \pushmacro\fontclass % new per 26102009 + \edef\fontclass{#2}% % new per 26102009 \defineunknownfont{#1}% + \popmacro\fontclass % new per 26102009 \fi\fi % so far \setvalue{\@size@#1}{\docompletefontswitch[#1]}} @@ -1686,7 +1678,7 @@ [\fontstylelist] {\dodefineunknownbodyfont{#1}}% \ifdone - \donefalse + \donefalse \setvalue{\@size@#1}{\docompletefontswitch[#1]}% \ifdefiningunknownfont \else \definingunknownfonttrue diff --git a/tex/context/base/grph-inc.lua b/tex/context/base/grph-inc.lua index db68d1f03..f0e2b4c10 100644 --- a/tex/context/base/grph-inc.lua +++ b/tex/context/base/grph-inc.lua @@ -104,7 +104,7 @@ figures.cachepaths = { figures.paths = table.copy(figures.localpaths) figures.order = { - "pdf", "mps", "jpg", "png", "jbig", "svg", "eps", "mov", "buffer", "tex" + "pdf", "mps", "jpg", "png", "jbig", "svg", "eps", "gif", "mov", "buffer", "tex", } figures.formats = { @@ -115,6 +115,7 @@ figures.formats = { ["jbig"] = { list = { "jbig", "jbig2", "jb2" } }, ["svg"] = { list = { "svg", "svgz" } }, ["eps"] = { list = { "eps", "ai" } }, + ["gif"] = { list = { "gif" } }, ["mov"] = { list = { "mov", "avi" } }, ["buffer"] = { list = { "tmp", "buffer", "buf" } }, ["tex"] = { list = { "tex" } }, @@ -777,12 +778,20 @@ function figures.converters.eps(oldname,newname) -- rlx as alternative local outputpath = file.dirname(newname) local outputbase = file.basename(newname) + if outputpath == "" then outputpath = "." end local command = format("mtxrun bin:pstopdf --outputpath=%s %s",outputpath,oldname) os.spawn(command) end figures.converters.svg = figures.converters.eps +function figures.converters.gif(oldname,newname) + -- hack, we need a lua based converter script, or better, we should use + -- rlx as alternative + local command = format("mtxrun bin:convert %s %s",oldname,newname) + os.spawn(command) +end + -- -- -- lowres -- -- -- --~ function figures.converters.pdf(oldname,newname) diff --git a/tex/context/base/l-file.lua b/tex/context/base/l-file.lua index 8cc50a6aa..a5c490fbf 100644 --- a/tex/context/base/l-file.lua +++ b/tex/context/base/l-file.lua @@ -112,6 +112,7 @@ function file.collapse_path(str) return str end +--~ print(file.collapse_path("/a")) --~ print(file.collapse_path("a/./b/..")) --~ print(file.collapse_path("a/aa/../b/bb")) --~ print(file.collapse_path("a/../..")) diff --git a/tex/context/base/lxml-xml.lua b/tex/context/base/lxml-xml.lua index 215635e78..2aaed94fc 100644 --- a/tex/context/base/lxml-xml.lua +++ b/tex/context/base/lxml-xml.lua @@ -96,7 +96,7 @@ end local function text(collected) if collected then - return xmltostring(collected[1]) -- only first as we cannot concat function + return xmltostring(collected[1].dt) -- only first as we cannot concat function else return "" end diff --git a/tex/context/base/mult-cld.lua b/tex/context/base/mult-cld.lua index 257921cb1..024d196e4 100644 --- a/tex/context/base/mult-cld.lua +++ b/tex/context/base/mult-cld.lua @@ -46,41 +46,50 @@ function context.trace(intercept) context.trace = function() end end +local trace_context = false trackers.register("context.flush", function(v) if v then context.trace() end end) +local trace_context = false trackers.register("context.intercept", function(v) if v then context.trace(true) end end) + local function writer(k,...) flush(ctxcatcodes,k) local t = { ... } - if next(t) then - for i=1,#t do + local nt = #t + if nt > 0 then + for i=1,nt do local ti = t[i] local typ, force = type(ti), nil local saved_flush = flush - flush = cached_flush - while typ == "function" do - cache = { } - ti, force = ti() - if force then - typ = false -- force special cases - else - typ = type(ti) - if typ == "nil" then - typ = "string" - ti = concat(cache) - elseif typ == "string" then - ti = concat(cache) + if typ == "function" then + flush = cached_flush + while true do + cache = { } + ti, force = ti() + if force then + typ = false -- force special cases + else + typ = type(ti) + if typ == "nil" then + typ = "string" + ti = concat(cache) + elseif typ == "string" then + ti = concat(cache) + end + end + if typ ~= "function" then + break end end + flush = saved_flush end - flush = saved_flush if ti == nil then -- next elseif typ == "string" or typ == "number" then flush(ctxcatcodes,"{",ti,"}") elseif typ == "table" then - flush(ctxcatcodes,"[") local c = concat(ti,",") if c ~= "" then - flush(ctxcatcodes,c) + flush(ctxcatcodes,"[",c,"]") else + flush(ctxcatcodes,"[") local done = false for k, v in next, ti do if done then @@ -90,8 +99,8 @@ local function writer(k,...) done = true end end + flush(ctxcatcodes,"]") end - flush(ctxcatcodes,"]") -- elseif typ == "boolean" then -- flush(ctxcatcodes,"\n") elseif ti == true then @@ -107,15 +116,32 @@ local function writer(k,...) end end +--~ local function indexer(t,k) +--~ local f = function(...) return writer("\\"..k.." ",...) end +--~ t[k] = f +--~ return f +--~ end + local function indexer(t,k) - local f = function(...) return writer("\\"..k.." ",...) end -- building the cs here saves time + local c = "\\" .. k .. " " + local f = function(...) return writer(c,...) end t[k] = f return f end -local function caller(t,f,...) - if f then - flush(ctxcatcodes,format(f,...)) +--~ local function caller(t,f,...) +--~ if f then +--~ flush(ctxcatcodes,format(f,...)) +--~ else +--~ flush(ctxcatcodes,"\n") +--~ end +--~ end + +local function caller(t,f,a,...) + if a then + flush(ctxcatcodes,format(f,a,...)) + elseif f then + flush(ctxcatcodes,f) else flush(ctxcatcodes,"\n") end @@ -167,7 +193,7 @@ end) function context.enabletrackers (str) trackers.enable (str) end function context.disabletrackers(str) trackers.disable(str) end --- see demo-lud.lud for an example +-- see demo-cld.cld for an example -- context.starttext(true) -- context.chapter({ "label" }, "title", true) diff --git a/tex/context/base/mult-de.tex b/tex/context/base/mult-de.tex index c36777887..8715a65ba 100644 --- a/tex/context/base/mult-de.tex +++ b/tex/context/base/mult-de.tex @@ -656,6 +656,7 @@ \setinterfaceconstant{global}{global} \setinterfaceconstant{grid}{gritter} \setinterfaceconstant{hang}{haengend} +\setinterfaceconstant{headalign}{headalign} \setinterfaceconstant{headcolor}{kopffarbe} \setinterfaceconstant{headcommand}{headcommand} \setinterfaceconstant{headconversion}{headconversion} diff --git a/tex/context/base/mult-def.lua b/tex/context/base/mult-def.lua index cd80c23c9..618c28c3b 100644 --- a/tex/context/base/mult-def.lua +++ b/tex/context/base/mult-def.lua @@ -6540,6 +6540,10 @@ return { }, }, ["constants"]={ + ["headalign"]={ + ["en"]="headalign", + ["nl"]="kopuitlijnen", + }, ["export"]={ ["en"]="export", ["nl"]="exporteer", diff --git a/tex/context/base/mult-en.tex b/tex/context/base/mult-en.tex index 27e8105e5..148d43f35 100644 --- a/tex/context/base/mult-en.tex +++ b/tex/context/base/mult-en.tex @@ -656,6 +656,7 @@ \setinterfaceconstant{global}{global} \setinterfaceconstant{grid}{grid} \setinterfaceconstant{hang}{hang} +\setinterfaceconstant{headalign}{headalign} \setinterfaceconstant{headcolor}{headcolor} \setinterfaceconstant{headcommand}{headcommand} \setinterfaceconstant{headconversion}{headconversion} diff --git a/tex/context/base/mult-fr.tex b/tex/context/base/mult-fr.tex index 80c2c48c1..1942984f1 100644 --- a/tex/context/base/mult-fr.tex +++ b/tex/context/base/mult-fr.tex @@ -656,6 +656,7 @@ \setinterfaceconstant{global}{global} \setinterfaceconstant{grid}{grille} \setinterfaceconstant{hang}{suspend} +\setinterfaceconstant{headalign}{headalign} \setinterfaceconstant{headcolor}{couleurtete} \setinterfaceconstant{headcommand}{commandetete} \setinterfaceconstant{headconversion}{conversiontete} diff --git a/tex/context/base/mult-it.tex b/tex/context/base/mult-it.tex index c7857e29b..339d51579 100644 --- a/tex/context/base/mult-it.tex +++ b/tex/context/base/mult-it.tex @@ -656,6 +656,7 @@ \setinterfaceconstant{global}{globale} \setinterfaceconstant{grid}{griglia} \setinterfaceconstant{hang}{sospendi} +\setinterfaceconstant{headalign}{headalign} \setinterfaceconstant{headcolor}{coloretesta} \setinterfaceconstant{headcommand}{headcommand} \setinterfaceconstant{headconversion}{conversionetesta} diff --git a/tex/context/base/mult-nl.tex b/tex/context/base/mult-nl.tex index a42d9c80f..75dff8bb1 100644 --- a/tex/context/base/mult-nl.tex +++ b/tex/context/base/mult-nl.tex @@ -656,6 +656,7 @@ \setinterfaceconstant{global}{globaal} \setinterfaceconstant{grid}{grid} \setinterfaceconstant{hang}{hang} +\setinterfaceconstant{headalign}{kopuitlijnen} \setinterfaceconstant{headcolor}{kopkleur} \setinterfaceconstant{headcommand}{kopcommando} \setinterfaceconstant{headconversion}{kopconversie} diff --git a/tex/context/base/mult-ro.tex b/tex/context/base/mult-ro.tex index 17f23e3ca..babe464f3 100644 --- a/tex/context/base/mult-ro.tex +++ b/tex/context/base/mult-ro.tex @@ -656,6 +656,7 @@ \setinterfaceconstant{global}{global} \setinterfaceconstant{grid}{grid} \setinterfaceconstant{hang}{suspenda} +\setinterfaceconstant{headalign}{headalign} \setinterfaceconstant{headcolor}{culoaretitlu} \setinterfaceconstant{headcommand}{headcommand} \setinterfaceconstant{headconversion}{conversietitlu} diff --git a/tex/context/base/strc-des.mkiv b/tex/context/base/strc-des.mkiv index a837318cc..6fe72a54f 100644 --- a/tex/context/base/strc-des.mkiv +++ b/tex/context/base/strc-des.mkiv @@ -1,5 +1,5 @@ %D \module -%D [ file=strc-blk, +%D [ file=strc-des, %D version=2008.10.20, %D title=\CONTEXT\ Structure Macros, %D subtitle=Descriptions, @@ -155,7 +155,7 @@ \hsize\descriptionsheadwidth \leftskip\zeropoint \rightskip\zeropoint - #1\setupalign[\descriptionparameter\c!align]% + #1\setupalign[\descriptionparameter\c!headalign]% \ifhbox\descriptionheadbox\unhcopy\else\copy\fi\descriptionheadbox}% \ht\descriptionheadbox\strutht \dp\descriptionheadbox\strutdp} @@ -191,7 +191,7 @@ {\forgetall \dontcomplain \hsize\descriptionsheadwidth - #1\setupalign[\descriptionparameter\c!align]#2% + #1\setupalign[\descriptionparameter\c!headalign]#2% \ifhbox\descriptionheadbox\unhcopy\else\copy\fi\descriptionheadbox}% \ht\descriptionheadbox\strutht \dp\descriptionheadbox\strutdp @@ -334,10 +334,12 @@ {\dodescriptionhandler {\vtop {\hsize\dimexpr\descriptionsheadwidth-\descriptionsheaddistance\relax + \doifsomething{\descriptionparameter\c!headalign}{\setupalign[\descriptionparameter\c!headalign]}% \begstrut\descriptionparameter\c!text\ignorespaces\currentdescriptiontext\endstrut}}}}% \doifelse{\descriptionparameter\c!aligntitle}\v!no {\leftdescriptionskip\leftskip\rightdescriptionskip\rightskip} {\ifcase\nesteddescriptionstate\leftdescriptionskip\leftskip\rightdescriptionskip\rightskip\fi}% + \doifsomething{\descriptionparameter\c!align}{\setupalign[\descriptionparameter\c!align]}% \normalexpanded{\noexpand\indenting[\descriptionparameter\c!indenting]}% % better a system mode \ifcase\nesteddescriptionstate @@ -961,6 +963,7 @@ \c!hang=, \c!sample=, \c!align=, + \c!headalign=, \c!margin=\v!no, \c!before=\blank, \c!inbetween=\blank, diff --git a/tex/context/base/strc-reg.mkiv b/tex/context/base/strc-reg.mkiv index 5de28c394..7cae98742 100644 --- a/tex/context/base/strc-reg.mkiv +++ b/tex/context/base/strc-reg.mkiv @@ -213,7 +213,14 @@ \c!keys:1=,\c!keys:2=,\c!keys:3=, \c!alternative=] -\def\doregisterstructurepageregister#1#2#3% register data userdata +\def\doregisterstructurepageregister + {\iftrialtypesetting + \expandafter\gobblethreearguments + \else + \expandafter\dodoregisterstructurepageregister + \fi} + +\def\dodoregisterstructurepageregister#1#2#3% register data userdata {\begingroup \edef\currentregister{#1}% %getparameters[\??id][\c!entries=,\c!label=,\c!keys=,\c!alternative=,#2]% diff --git a/tex/context/base/x-cals.lua b/tex/context/base/x-cals.lua new file mode 100644 index 000000000..f09fd4fb5 --- /dev/null +++ b/tex/context/base/x-cals.lua @@ -0,0 +1,209 @@ +if not modules then modules = { } end modules ['x-cals'] = { + version = 1.001, + comment = "companion to x-cals.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +local format, lower = string.format, string.lower +local texsprint, ctxcatcodes = tex.sprint, tex.ctxcatcodes +local xmlsprint, xmlcprint, xmlcollected = xml.sprint, xml.cprint, xml.collected +local n_todimen, s_todimen = number.todimen, string.todimen + +-- there is room for speedups as well as cleanup (using context functions) + +lxml.cals = lxml.cals or { } + +local cals = lxml.cals + +cals.ignore_widths = false +cals.shrink_widths = false +cals.stretch_widths = false + +-- the following flags only apply to columns that have a specified width +-- +-- proportional : shrink or stretch proportionally to the width +-- equal : shrink or stretch equaly distributed +-- n < 1 : shrink or stretch proportionally to the width but multiplied by n +-- +-- more clever things, e.g. the same but applied to unspecified widths +-- has to happen at the core-ntb level (todo) + +local halignments = { + left = "flushleft", + right = "flushright", + center = "middle", + centre = "middle", + justify = "normal", +} + +local valignments = { + top = "high", + bottom = "low", + middle = "lohi", +} + +local function adapt(widths,b,w,delta,sum,n,what) + if b == "equal" then + delta = delta/n + for k, v in pairs(w) do + widths[k] = n_todimen(v - delta) + end + elseif b == "proportional" then + delta = delta/sum + for k, v in pairs(w) do + widths[k] = n_todimen(v - v*delta) + end + elseif type(b) == "number" and b < 1 then + delta = b*delta/sum + for k, v in pairs(w) do + widths[k] = n_todimen(v - v*delta) + end + end +end + +local function getspecs(root, pattern, names, widths) + -- here, but actually we need this in core-ntb.tex + -- but ideally we need an mkiv enhanced core-ntb.tex + local ignore_widths = cals.ignore_widths + local shrink_widths = cals.shrink_widths + local stretch_widths = cals.stretch_widths + for e in xmlcollected(root,pattern) do + local at = e.at + local column = at.colnum + if column then + if not ignore_widths then + local width = at.colwidth + if width then + widths[tonumber(column)] = lower(width) + end + end + local name = at.colname + if name then + names[name] = tonumber(column) + end + end + end + if ignore_width then + -- forget about it + elseif shrink_widths or stretch_widths then + local sum, n, w = 0, 0, { } + for _, v in pairs(widths) do + n = n + 1 + v = (type(v) == "string" and s_todimen(v)) or v + if v then + w[n] = v + sum = sum + v + end + end + local hsize = tex.hsize + if type(hsize) == "string" then + hsize = s_todimen(hsize) + end + local delta = sum - hsize + if shrink_widths and delta > 0 then + adapt(widths,shrink_widths,w,delta,sum,n,"shrink") + elseif stretch_widths and delta < 0 then + adapt(widths,stretch_widths,w,delta,sum,n,"stretch") + end + end +end + +local function getspans(root, pattern, names, spans) + for e in xmlcollected(root,pattern) do + local at = e.at + local name, namest, nameend = at.colname, names[at.namest or "?"], names[at.nameend or "?"] + if name and namest and nameend then + spans[name] = tonumber(nameend) - tonumber(namest) + 1 + end + end +end + +--local function texsprint(a,b) print(b) end +--local function xmlsprint(a) print(a) end + +function cals.table(root,namespace) + + local prefix = (namespace or "cals") .. ":" + local p = "/" .. prefix + + local tgroupspec = p .. "tgroup" + local colspec = p .. "colspec" + local spanspec = p .. "spanspec" + local hcolspec = p .. "thead" .. p .. "colspec" + local bcolspec = p .. "tbody" .. p .. "colspec" + local fcolspec = p .. "tfoot" .. p .. "colspec" + local entryspec = p .. "entry" .. "|" ..prefix .. "entrytbl" + local hrowspec = p .. "thead" .. p .. "row" + local browspec = p .. "tbody" .. p .. "row" + local frowspec = p .. "tfoot" .. p .. "row" + + local function tablepart(root, xcolspec, xrowspec, before, after) -- move this one outside + texsprint(ctxcatcodes,before) + local at = root.at + local pphalign, ppvalign = at.align, at.valign + local names, widths, spans = { }, { }, { } + getspecs(root, colspec , names, widths) + getspecs(root, xcolspec, names, widths) + getspans(root, spanspec, names, spans) + for r, d, k in xml.elements(root,xrowspec) do + texsprint(ctxcatcodes,"\\bTR") + local dk = d[k] + local at = dk.at + local phalign, pvalign = at.align or pphalign, at.valign or ppvalign -- todo: __p__ test + local col = 1 + for rr, dd, kk in xml.elements(dk,entryspec) do + local dk = dd[kk] + if dk.tg == "entrytbl" then + texsprint(ctxcatcodes,"\\bTD{") + cals.table(dk) + texsprint(ctxcatcodes,"}\\eTD") + col = col + 1 + else + local at = dk.at + local b, e, s, m = names[at.namest or "?"], names[at.nameend or "?"], spans[at.spanname or "?"], at.morerows + local halign, valign = at.align or phalign, at.valign or pvalign + if b and e then + s = e - b + 1 + end + if halign then + halign = halignments[halign] + end + if valign then + valign = valignments[valign] + end + local width = widths[col] + if s or m or halign or valign or width then -- only english interface ! + texsprint(ctxcatcodes,format("\\bTD[nx=%s,ny=%s,align={%s,%s},width=%s]", + s or 1, (m or 0)+1, halign or "flushleft", valign or "high", width or "fit")) + -- texsprint(ctxcatcodes,"\\bTD[nx=",s or 1,"ny=",(m or 0)+1,"align={",halign or "flushleft",",",valign or "high","},width=",width or "fit","]") + else + texsprint(ctxcatcodes,"\\bTD[align={flushleft,high},width=fit]") -- else problems with vertical material + end + xmlcprint(dk) + texsprint(ctxcatcodes,"\\eTD") + col = col + (s or 1) + end + end + texsprint(ctxcatcodes,"\\eTR") + end + texsprint(ctxcatcodes,after) + end + + for tgroup in lxml.collected(root,tgroupspec) do + texsprint(ctxcatcodes, "\\directsetup{cals:table:before}") + lxml.directives.before(root,"cdx") -- "cals:table" + texsprint(ctxcatcodes, "\\bgroup") + lxml.directives.setup(root,"cdx") -- "cals:table" + texsprint(ctxcatcodes, "\\bTABLE") + tablepart(tgroup, hcolspec, hrowspec, "\\bTABLEhead", "\\eTABLEhead") + tablepart(tgroup, bcolspec, browspec, "\\bTABLEbody", "\\eTABLEbody") + tablepart(tgroup, fcolspec, frowspec, "\\bTABLEfoot", "\\eTABLEfoot") + texsprint(ctxcatcodes, "\\eTABLE") + texsprint(ctxcatcodes, "\\egroup") + lxml.directives.after(root,"cdx") -- "cals:table" + texsprint(ctxcatcodes, "\\directsetup{cals:table:after}") + end + +end diff --git a/tex/context/base/x-cals.mkiv b/tex/context/base/x-cals.mkiv index 3d2644045..32d5767c1 100644 --- a/tex/context/base/x-cals.mkiv +++ b/tex/context/base/x-cals.mkiv @@ -13,210 +13,9 @@ \writestatus{loading}{ConTeXt XML Macros / Cals Tables} -\startluacode -do +\startmodule [cals] - lxml.cals = { } - lxml.cals.ignore_widths = false - - -- the following flags only apply to columns that have a specified width - -- - -- proportional : shrink or stretch proportionally to the width - -- equal : shrink or stretch equaly distributed - -- n < 1 : shrink or stretch proportionally to the width but multiplied by n - -- - -- more clever things, e.g. the same but applied to unspecified widths - -- has to happen at the core-ntb level (todo) - - lxml.cals.shrink_widths = false - lxml.cals.stretch_widths = false - - local format = string.format - local texsprint = tex.sprint - local xmlsprint = xml.sprint - local xmlcprint = xml.cprint - - local halignments = { - left = "flushleft", - right = "flushright", - center = "middle", - centre = "middle", - justify = "normal", - } - - local valignments = { - top = "high", - bottom = "low", - middle = "lohi", - } - - local function getspecs(root, pattern, names, widths) - -- here, but actually we need this in core-ntb.tex - -- but ideally we need an mkiv enhanced core-ntb.tex - local ignore_widths = lxml.cals.ignore_widths - local shrink_widths = lxml.cals.shrink_widths - local stretch_widths = lxml.cals.stretch_widths - for r, d, k in xml.elements(root,pattern) do - local dk = d[k] - local at = dk.at - local column = at.colnum - if column then - if not ignore_widths then - local width = at.colwidth - if width then - widths[tonumber(column)] = width:lower() - end - end - local name = at.colname - if name then - names[name] = tonumber(column) - end - end - end - local function adapt(b,w,delta,sum,n,what) - if b == "equal" then - delta = delta/n - for k, v in pairs(w) do - widths[k] = number.todimen(v - delta) - end - elseif b == "proportional" then - delta = delta/sum - for k, v in pairs(w) do - widths[k] = number.todimen(v - v*delta) - end - elseif type(b) == "number" and b < 1 then - delta = b*delta/sum - for k, v in pairs(w) do - widths[k] = number.todimen(v - v*delta) - end - end - end - if ignore_width then - -- forget about it - elseif shrink_widths or stretch_widths then - local sum, n, w = 0, 0, { } - for _, v in pairs(widths) do - n = n + 1 - v = (type(v) == "string" and v:todimen()) or v - if v then - w[n] = v - sum = sum + v - end - end - local hsize = tex.hsize - if type(hsize) == "string" then - hsize = hsize:todimen() - end - local delta = sum - hsize - if shrink_widths and delta > 0 then - adapt(shrink_widths,w,delta,sum,n,"shrink") - elseif stretch_widths and delta < 0 then - adapt(stretch_widths,w,delta,sum,n,"stretch") - end - end - end - - local function getspans(root, pattern, names, spans) - for r, d, k in xml.elements(root,pattern) do - local dk = d[k] - local at = dk.at - local name, namest, nameend = at.colname, names[at.namest or "?"], names[at.nameend or "?"] - if name and namest and nameend then - spans[name] = tonumber(nameend) - tonumber(namest) + 1 - end - end - end - - --local function texsprint(a,b) print(b) end - --local function xmlsprint(a) print(a) end - - function lxml.cals.table(root,namespace) - - local prefix = (namespace or "cals") .. ":" - local p = "/" .. prefix - - local tgroupspec = p .. "tgroup" - local colspec = p .. "colspec" - local spanspec = p .. "spanspec" - local hcolspec = p .. "thead" .. p .. "colspec" - local bcolspec = p .. "tbody" .. p .. "colspec" - local fcolspec = p .. "tfoot" .. p .. "colspec" - local entryspec = p .. "entry" .. "|" ..prefix .. "entrytbl" - local hrowspec = p .. "thead" .. p .. "row" - local browspec = p .. "tbody" .. p .. "row" - local frowspec = p .. "tfoot" .. p .. "row" - - local function tablepart(root, xcolspec, xrowspec, before, after) - texsprint(tex.ctxcatcodes,before) - local at = root.at - local pphalign, ppvalign = at.align, at.valign - local names, widths, spans = { }, { }, { } - getspecs(root, colspec , names, widths) - getspecs(root, xcolspec, names, widths) - getspans(root, spanspec, names, spans) - for r, d, k in xml.elements(root,xrowspec) do - texsprint(tex.ctxcatcodes,"\\bTR") - local dk = d[k] - local at = dk.at - local phalign, pvalign = at.align or pphalign, at.valign or ppvalign -- todo: __p__ test - local col = 1 - for rr, dd, kk in xml.elements(dk,entryspec) do - local dk = dd[kk] - if dk.tg == "entrytbl" then - texsprint(tex.ctxcatcodes,"\\bTD{") - lxml.cals.table(dk) - texsprint(tex.ctxcatcodes,"}\\eTD") - col = col + 1 - else - local at = dk.at - local b, e, s, m = names[at.namest or "?"], names[at.nameend or "?"], spans[at.spanname or "?"], at.morerows - local halign, valign = at.align or phalign, at.valign or pvalign - if b and e then - s = e - b + 1 - end - if halign then - halign = halignments[halign] - end - if valign then - valign = valignments[valign] - end - local width = widths[col] - if s or m or halign or valign or width then -- only english interface ! - texsprint(tex.ctxcatcodes,format("\\bTD[nx=%s,ny=%s,align={%s,%s},width=%s]", - s or 1, (m or 0)+1, halign or "flushleft", valign or "high", width or "fit")) - else - texsprint(tex.ctxcatcodes,"\\bTD[align={flushleft,high},width=fit]") -- else problems with vertical material - end - -- xmlsprint(dk) - xmlcprint(dk) - texsprint(tex.ctxcatcodes,"\\eTD") - col = col + (s or 1) - end - end - texsprint(tex.ctxcatcodes,"\\eTR") - end - texsprint(tex.ctxcatcodes,after) - end - - for r, d, k in xml.elements(lxml.id(root),tgroupspec) do - local tgroup = d[k] - texsprint(tex.ctxcatcodes, "\\directsetup{cals:table:before}") - lxml.directives.before(root,"cdx") -- "cals:table" - texsprint(tex.ctxcatcodes, "\\bgroup") - lxml.directives.setup(root,"cdx") -- "cals:table" - texsprint(tex.ctxcatcodes, "\\bTABLE") - tablepart(tgroup, hcolspec, hrowspec, "\\bTABLEhead", "\\eTABLEhead") - tablepart(tgroup, bcolspec, browspec, "\\bTABLEbody", "\\eTABLEbody") - tablepart(tgroup, fcolspec, frowspec, "\\bTABLEfoot", "\\eTABLEfoot") - texsprint(tex.ctxcatcodes, "\\eTABLE") - texsprint(tex.ctxcatcodes, "\\egroup") - lxml.directives.after(root,"cdx") -- "cals:table" - texsprint(tex.ctxcatcodes, "\\directsetup{cals:table:after}") - end - end - -end -\stopluacode +\ctxloadluafile{x-cals}{} % \startxmlsetups xml:cals:process % \xmlsetsetup {\xmldocument} {cals:table} {*} @@ -234,4 +33,4 @@ end \xmlregisterns{cals}{cals} -\endinput +\stopmodule diff --git a/tex/context/base/x-ct.lua b/tex/context/base/x-ct.lua new file mode 100644 index 000000000..06566a464 --- /dev/null +++ b/tex/context/base/x-ct.lua @@ -0,0 +1,182 @@ +if not modules then modules = { } end modules ['x-ct'] = { + version = 1.001, + comment = "companion to x-ct.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +local xmlsprint, xmlfilter, xmlcollected = xml.sprint, xml.filter, xml.collected +local texsprint, ctxcatcodes = tex.sprint, tex.ctxcatcodes +local format, concat, rep = string.format, table.concat, string.rep + +lxml.context = { } + +local halignments = { + left = 'l', + flushleft = 'l', + right = 'r', + flushright = 'r', + center = 'c', + middle = 'c', + centre = 'c', + justify = '', +} + +local function roottemplate(root) + local rt = root.at.template + if rt then + if not rt:find("|") then + rt = rt:gsub(",","|") + end + if not rt:find("^|") then rt = "|" .. rt end + if not rt:find("|$") then rt = rt .. "|" end + end + return rt +end + +local function specifiedtemplate(root,templatespec) + local template = { } + for e in xmlcollected(root,templatespec) do + local at = e.at + local tm = halignments[at.align] or "" + if toboolean(at.paragraph) then + tm = tm .. "p" + end + template[#template+1] = tm + end + if #template > 0 then + return "|" .. concat(template,"|") .. "|" + else + return nil + end +end + +local function autotemplate(root,rowspec,cellspec) + local max = 0 + for e in xmlcollected(root,rowspec) do + local n = xml.count(e,cellspec) + if n > max then max = n end + end + if max == 2 then + return "|l|p|" + elseif max > 0 then + return "|" .. rep("p|",max) + else + return nil + end +end + +local defaulttemplate = "|l|p|" + +function lxml.context.tabulate(root,namespace) + if not root then + return + else + root = lxml.id(root) + end + + local prefix = (namespace or "context") .. ":" + + local templatespec = "/" .. prefix .. "template" .. "/" .. prefix .. "column" + local bodyrowspec = "/" .. prefix .. "body" .. "/" .. prefix .. "row" + local cellspec = "/" .. prefix .. "cell" + + local template = + roottemplate (root) or + specifiedtemplate (root,templatespec) or + autotemplate (root,bodyrowspec,cellspec) or + defaulttemplate + + -- todo: head and foot + +--~ lxml.directives.before(root,'cdx') +--~ texsprint(ctxcatcodes, "\\bgroup") +--~ lxml.directives.setup(root,'cdx') +--~ texsprint(ctxcatcodes, format("\\starttabulate[%s]",template)) +--~ for e in xmlcollected(root,bodyrowspec) do +--~ texsprint(ctxcatcodes, "\\NC ") +--~ for e in xmlcollected(e,cellspec) do +--~ texsprint(xml.content(e)) -- use some xmlprint +--~ texsprint(ctxcatcodes, "\\NC") +--~ end +--~ texsprint(ctxcatcodes, "\\NR") +--~ end +--~ texsprint(ctxcatcodes, "\\stoptabulate") +--~ texsprint(ctxcatcodes, "\\egroup") +--~ lxml.directives.after(root,'cdx') + + local NC, NR = context.NC, context.NR + + lxml.directives.before(root,'cdx') + context.bgroup() + lxml.directives.setup(root,'cdx') + context.starttabulate { template } + for e in xmlcollected(root,bodyrowspec) do + NC() + for e in xmlcollected(e,cellspec) do + texsprint(xml.content(e)) -- test: xmlcprint(e) + NC() + end + NR() + end + context.stoptabulate() + context.egroup() + lxml.directives.after(root,'cdx') + +end + +function lxml.context.combination(root,namespace) + + if not root then + return + else + root = lxml.id(root) + end + + local prefix = (namespace or "context") .. ":" + + local pairspec = "/" .. prefix .. "pair" + local contentspec = "/" .. prefix .. "content" .. "/text()" + local captionspec = "/" .. prefix .. "caption" .. "/text()" + + local nx, ny = root.at.nx, root.at.ny + + if not (nx or ny) then + nx = xml.count(root,pairspec) or 2 + end + local template = format("%s*%s", nx or 1, ny or 1) + + -- todo: alignments + +--~ lxml.directives.before(root,'cdx') +--~ texsprint(ctxcatcodes, "\\bgroup") +--~ lxml.directives.setup(root,'cdx') +--~ texsprint(ctxcatcodes, "\\startcombination[",template,"]") +--~ for e in xmlcollected(root,pairspec) do +--~ texsprint(ctxcatcodes,"{") +--~ xmlfilter(e,contentspec) +--~ texsprint(ctxcatcodes,"}{") +--~ xmlfilter(e,captionspec) +--~ texsprint(ctxcatcodes,"}") +--~ end +--~ texsprint(ctxcatcodes, "\\stopcombination") +--~ texsprint(ctxcatcodes, "\\egroup") +--~ lxml.directives.after(root,'cdx') + + lxml.directives.before(root,'cdx') + context.bgroup() + lxml.directives.setup(root,'cdx') + context.startcombination { template } + for e in xmlcollected(root,pairspec) do + texsprint(ctxcatcodes,"{") + xmlfilter(e,contentspec) + texsprint(ctxcatcodes,"}{") + xmlfilter(e,captionspec) + texsprint(ctxcatcodes,"}") + end + context.stopcombination() + context.egroup() + lxml.directives.after(root,'cdx') + +end diff --git a/tex/context/base/x-ct.mkiv b/tex/context/base/x-ct.mkiv index 7836f5060..d282193a1 100644 --- a/tex/context/base/x-ct.mkiv +++ b/tex/context/base/x-ct.mkiv @@ -13,151 +13,9 @@ \writestatus{loading}{ConTeXt XML Macros / Basics} -\startluacode -do - lxml.context = { } +\startmodule [ct] - local halignments = { - left = 'l', - flushleft = 'l', - right = 'r', - flushright = 'r', - center = 'c', - middle = 'c', - centre = 'c', - justify = '', - } - - local texsprint = tex.sprint - local xmlsprint = xml.sprint - local xmlfilter = xml.filter - local ctxcatcodes = tex.ctxcatcodes - - local function roottemplate(root) - local rt = root.at.template - if rt then - if not rt:find("|") then - rt = rt:gsub(",","|") - end - if not rt:find("^|") then rt = "|" .. rt end - if not rt:find("|$") then rt = rt .. "|" end - end - return rt - end - - local function specifiedtemplate(root,templatespec) - local template = { } - for e in xml.collected(root,templatespec) do - local at = e.at - local tm = halignments[at.align] or "" - if toboolean(at.paragraph) then - tm = tm .. "p" - end - template[#template+1] = tm - end - if #template > 0 then - return "|" .. table.concat(template,"|") .. "|" - else - return nil - end - end - - local function autotemplate(root,rowspec,cellspec) - local max = 0 - for e in xml.collected(root,rowspec) do - local n = xml.count(e,cellspec) - if n > max then max = n end - end - if max == 2 then - return "|l|p|" - elseif max > 0 then - return "|" .. string.rep("p|",max) - else - return nil - end - end - - local defaulttemplate = "|l|p|" - - function lxml.context.tabulate(root,namespace) - if not root then - return - else - root = lxml.id(root) - end - - local prefix = (namespace or "context") .. ":" - - local templatespec = "/" .. prefix .. "template" .. "/" .. prefix .. "column" - local bodyrowspec = "/" .. prefix .. "body" .. "/" .. prefix .. "row" - local cellspec = "/" .. prefix .. "cell" - - local template = - roottemplate (root) or - specifiedtemplate (root,templatespec) or - autotemplate (root,bodyrowspec,cellspec) or - defaulttemplate - - lxml.directives.before(root,'cdx') - texsprint(ctxcatcodes, "\\bgroup") - lxml.directives.setup(root,'cdx') - -- todo: head and foot - texsprint(ctxcatcodes, string.format("\\starttabulate[%s]",template)) - for e in xml.collected(root,bodyrowspec) do - texsprint(ctxcatcodes, "\\NC ") - for e in xml.collected(e,cellspec) do - texsprint(xml.content(e)) - texsprint(ctxcatcodes, "\\NC") - end - texsprint(ctxcatcodes, "\\NR") - end - texsprint(ctxcatcodes, "\\stoptabulate") - texsprint(ctxcatcodes, "\\egroup") - lxml.directives.after(root,'cdx') - - end - - function lxml.context.combination(root,namespace) - - if not root then - return - else - root = lxml.id(root) - end - - local prefix = (namespace or "context") .. ":" - - local pairspec = "/" .. prefix .. "pair" - local contentspec = "/" .. prefix .. "content" .. "/text()" - local captionspec = "/" .. prefix .. "caption" .. "/text()" - - local nx, ny = root.at.nx, root.at.ny - - if not (nx or ny) then - nx = xml.count(root,pairspec) or 2 - end - local template = string.format("%s*%s", nx or 1, ny or 1) - - lxml.directives.before(root,'cdx') - texsprint(ctxcatcodes, "\\bgroup") - lxml.directives.setup(root,'cdx') - -- todo: alignments - texsprint(ctxcatcodes, "\\startcombination[",template,"]") - for e in xml.collected(root,pairspec) do - texsprint(ctxcatcodes,"{") - xmlfilter(e,contentspec) - texsprint(ctxcatcodes,"}{") - xmlfilter(e,captionspec) - texsprint(ctxcatcodes,"}") - end - texsprint(ctxcatcodes, "\\stopcombination") - texsprint(ctxcatcodes, "\\egroup") - lxml.directives.after(root,'cdx') - - end - -end -\stopluacode +\ctxloadluafile{x-ct}{} \startxmlsetups xml:context:process \xmlsetfunction {\xmldocument} {context:tabulate} {lxml.context.tabulate} @@ -168,4 +26,4 @@ end \xmlregisterns{context}{context} -\endinput +\stopmodule diff --git a/tex/context/interface/keys-cs.xml b/tex/context/interface/keys-cs.xml index 7bbc18d57..45c7a0889 100644 --- a/tex/context/interface/keys-cs.xml +++ b/tex/context/interface/keys-cs.xml @@ -662,6 +662,7 @@ + diff --git a/tex/context/interface/keys-de.xml b/tex/context/interface/keys-de.xml index 753f6a737..a9c03ff60 100644 --- a/tex/context/interface/keys-de.xml +++ b/tex/context/interface/keys-de.xml @@ -662,6 +662,7 @@ + diff --git a/tex/context/interface/keys-en.xml b/tex/context/interface/keys-en.xml index c96040b66..69a4ff610 100644 --- a/tex/context/interface/keys-en.xml +++ b/tex/context/interface/keys-en.xml @@ -662,6 +662,7 @@ + diff --git a/tex/context/interface/keys-fr.xml b/tex/context/interface/keys-fr.xml index cabfd3d87..8c986b2c3 100644 --- a/tex/context/interface/keys-fr.xml +++ b/tex/context/interface/keys-fr.xml @@ -662,6 +662,7 @@ + diff --git a/tex/context/interface/keys-it.xml b/tex/context/interface/keys-it.xml index c41046492..7693cce38 100644 --- a/tex/context/interface/keys-it.xml +++ b/tex/context/interface/keys-it.xml @@ -662,6 +662,7 @@ + diff --git a/tex/context/interface/keys-nl.xml b/tex/context/interface/keys-nl.xml index 0ce4d1247..c2dd09597 100644 --- a/tex/context/interface/keys-nl.xml +++ b/tex/context/interface/keys-nl.xml @@ -662,6 +662,7 @@ + diff --git a/tex/context/interface/keys-pe.xml b/tex/context/interface/keys-pe.xml index b38e3607f..1e49026f2 100644 --- a/tex/context/interface/keys-pe.xml +++ b/tex/context/interface/keys-pe.xml @@ -662,6 +662,7 @@ + diff --git a/tex/context/interface/keys-ro.xml b/tex/context/interface/keys-ro.xml index 9e38fbc96..5e1c87f8b 100644 --- a/tex/context/interface/keys-ro.xml +++ b/tex/context/interface/keys-ro.xml @@ -662,6 +662,7 @@ + diff --git a/tex/context/sample/demo-cld.cld b/tex/context/sample/demo-cld.cld deleted file mode 100644 index 7e470da62..000000000 --- a/tex/context/sample/demo-cld.cld +++ /dev/null @@ -1,74 +0,0 @@ --- context.enabletrackers {"tud.trace"} - -context.setuplayout( { - width = "middle", - height = "middle", -}) - -context.showframe() - -context.starttext() - -context.chapter({ "someref" }, "Hello There") - -context.readfile("tufte","","not found") - -context.startitemize({ "packed" }) - for i=1,10 do - context.startitem() - context("this is item %i",i) - context.stopitem() - end -context.stopitemize() - -context.startchapter({ title = "test" }, { more = "oeps" }) - - context["in"]("chapter",{ "someref" }) - - context.startlinecorrection( { "blank" }) - context.bTABLE() - for i=1,10 do - context.bTR() - for i=1,20 do - context.bTD({ align= "middle", style = "type" }) - context("%#2i",math.random(99)) - context.eTD() - end - context.eTR() - end - context.eTABLE() - context.stoplinecorrection() - - context.mathematics("x^{2 \\times 4}") - - context.placefigure("caption", function() - context.externalfigure( { "cow.pdf" } ) - end) - - context.placefigure("caption", function() - context.bTABLE() - context.bTR() - context.bTD() - context.externalfigure( { "cow.pdf" }, { width = "3cm", height = "3cm" } ) - context.eTD() - context.bTD({ align = "{lohi,middle}" } ) - context("and") - context.eTD() - context.bTD() - context.externalfigure( { "cow.pdf" }, { width = "4cm", height = "3cm" } ) - context.eTD() - context.eTR() - context.eTABLE() - end) - -context.stopchapter() - -context.chapter("Speed Test 1") - -for i=1,50 do - context.readfile("tufte","","not found") - context.par() -end - -context.stoptext() - diff --git a/tex/generic/context/luatex-fonts-merged.lua b/tex/generic/context/luatex-fonts-merged.lua index ca51a91c1..55eb2feac 100644 --- a/tex/generic/context/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : c:/data/develop/context/texmf/tex/generic/context/luatex-fonts-merged.lua -- parent file : c:/data/develop/context/texmf/tex/generic/context/luatex-fonts.lua --- merge date : 10/24/09 16:49:06 +-- merge date : 10/26/09 17:28:48 do -- begin closure to overcome local limits and interference @@ -1500,6 +1500,7 @@ function file.collapse_path(str) return str end +--~ print(file.collapse_path("/a")) --~ print(file.collapse_path("a/./b/..")) --~ print(file.collapse_path("a/aa/../b/bb")) --~ print(file.collapse_path("a/../..")) -- cgit v1.2.3