diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/anch-pos.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/anch-pos.lua | 109 |
1 files changed, 68 insertions, 41 deletions
diff --git a/Master/texmf-dist/tex/context/base/anch-pos.lua b/Master/texmf-dist/tex/context/base/anch-pos.lua index b16fac05c9c..8066af4ceba 100644 --- a/Master/texmf-dist/tex/context/base/anch-pos.lua +++ b/Master/texmf-dist/tex/context/base/anch-pos.lua @@ -1,6 +1,6 @@ if not modules then modules = { } end modules ['anch-pos'] = { version = 1.001, - comment = "companion to anch-pos.tex", + comment = "companion to anch-pos.mkiv", author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", copyright = "PRAGMA ADE / ConTeXt Development Team", license = "see context related readme files" @@ -12,7 +12,9 @@ can we store much more information in <l n='lua'/> but it's also more efficient.</p> --ldx]]-- -local texprint, concat, format = tex.print, table.concat, string.format +local concat, format = table.concat, string.format +local texprint, ctxcatcodes = tex.print, tex.ctxcatcodes +local lpegmatch = lpeg.match jobpositions = jobpositions or { } jobpositions.collected = jobpositions.collected or { } @@ -50,90 +52,115 @@ function jobpositions.doifelse(name) commands.testcase(jobpositions.collected[name] or ptbs[name]) end -function jobpositions.MPp(id) local jpi = pcol[id] or ptbs[id] texprint((jpi and jpi[1]) or '0' ) end -function jobpositions.MPx(id) local jpi = pcol[id] or ptbs[id] texprint((jpi and jpi[2]) or '0pt') end -function jobpositions.MPy(id) local jpi = pcol[id] or ptbs[id] texprint((jpi and jpi[3]) or '0pt') end -function jobpositions.MPw(id) local jpi = pcol[id] or ptbs[id] texprint((jpi and jpi[4]) or '0pt') end -function jobpositions.MPh(id) local jpi = pcol[id] or ptbs[id] texprint((jpi and jpi[5]) or '0pt') end -function jobpositions.MPd(id) local jpi = pcol[id] or ptbs[id] texprint((jpi and jpi[6]) or '0pt') end - - - function jobpositions.MPx(id) - local jpi = pcol[id] or ptbs[id] - local x = jpi and jpi[2] - if x then - texprint(format('\\the\\dimexpr %s-%s\\relax',x,dx)) - else - texprint('0pt') - end +function jobpositions.MPp(id) local jpi = pcol[id] or ptbs[id] texprint(ctxcatcodes,(jpi and jpi[1]) or '0' ) end +function jobpositions.MPx(id) local jpi = pcol[id] or ptbs[id] texprint(ctxcatcodes,(jpi and jpi[2]) or '0pt') end +function jobpositions.MPy(id) local jpi = pcol[id] or ptbs[id] texprint(ctxcatcodes,(jpi and jpi[3]) or '0pt') end +function jobpositions.MPw(id) local jpi = pcol[id] or ptbs[id] texprint(ctxcatcodes,(jpi and jpi[4]) or '0pt') end +function jobpositions.MPh(id) local jpi = pcol[id] or ptbs[id] texprint(ctxcatcodes,(jpi and jpi[5]) or '0pt') end +function jobpositions.MPd(id) local jpi = pcol[id] or ptbs[id] texprint(ctxcatcodes,(jpi and jpi[6]) or '0pt') end + + +function jobpositions.MPx(id) + local jpi = pcol[id] or ptbs[id] + local x = jpi and jpi[2] + if x then + texprint(ctxcatcodes,format('\\the\\dimexpr%s-%s\\relax',x,dx)) -- no space after dimexpr ! + else + texprint(ctxcatcodes,'0pt') end - function jobpositions.MPy(id) - local jpi = pcol[id] or ptbs[id] - local y = jpi and jpi[3] - if y then - texprint(format('\\the\\dimexpr %s-%s\\relax',y,dy)) - else - texprint('0pt') - end +end + +function jobpositions.MPy(id) + local jpi = pcol[id] or ptbs[id] + local y = jpi and jpi[3] + if y then + texprint(ctxcatcodes,format('\\the\\dimexpr%s-%s\\relax',y,dy)) -- no space after dimexpr ! + else + texprint(ctxcatcodes,'0pt') end +end -- the following are only for MP so there we can leave out the pt --- can be writes +-- can be writes and no format needed any more function jobpositions.MPxy(id) local jpi = pcol[id] or ptbs[id] if jpi then - texprint(format('(%s-%s,%s-%s)',jpi[2],dx,jpi[3],dy)) + texprint(ctxcatcodes,format('(%s-%s,%s-%s)',jpi[2],dx,jpi[3],dy)) +--~ texprint(ctxcatcodes,'(',jpi[2],'-',dx,',',jpi[3],'-',dy,')') else - texprint('(0,0)') + texprint(ctxcatcodes,'(0,0)') end end + function jobpositions.MPll(id) local jpi = pcol[id] or ptbs[id] if jpi then - texprint(format('(%s-%s,%s-%s-%s)',jpi[2],dx,jpi[3],jpi[6],dy)) + texprint(ctxcatcodes,format('(%s-%s,%s-%s-%s)',jpi[2],dx,jpi[3],jpi[6],dy)) +--~ texprint(ctxcatcodes,'(',jpi[2],'-',dx,',',jpi[3],'-',jpi[6],'-',dy,')') else - texprint('(0,0)') + texprint(ctxcatcodes,'(0,0)') end end + function jobpositions.MPlr(id) local jpi = pcol[id] or ptbs[id] if jpi then - texprint(format('(%s+%s-%s,%s-%s-%s)',jpi[2],jpi[4],dx,jpi[3],jpi[6],dy)) + texprint(ctxcatcodes,format('(%s+%s-%s,%s-%s-%s)',jpi[2],jpi[4],dx,jpi[3],jpi[6],dy)) +--~ texprint(ctxcatcodes,'(',jpi[2],'+',jpi[4],'-',dx,',',jpi[3],'-',jpi[6],'-',dy,')') else - texprint('(0,0)') + texprint(ctxcatcodes,'(0,0)') end end + function jobpositions.MPur(id) local jpi = pcol[id] or ptbs[id] if jpi then - texprint(format('(%s+%s-%s,%s+%s-%s)',jpi[2],jpi[4],dx,jpi[3],jpi[5],dy)) + texprint(ctxcatcodes,format('(%s+%s-%s,%s+%s-%s)',jpi[2],jpi[4],dx,jpi[3],jpi[5],dy)) +--~ texprint(ctxcatcodes,'(',jpi[2],'+',jpi[4],'-',dx,',',jpi[3],'+',jpi[5],'-',dy,')') else - texprint('(0,0)') + texprint(ctxcatcodes,'(0,0)') end end + function jobpositions.MPul(id) local jpi = pcol[id] or ptbs[id] if jpi then - texprint(format('(%s-%s,%s+%s-%s)',jpi[2],dx,jpi[3],jpi[5],dy)) + texprint(ctxcatcodes,format('(%s-%s,%s+%s-%s)',jpi[2],dx,jpi[3],jpi[5],dy)) +--~ texprint(ctxcatcodes,'(',jpi[2],'-',dx,',',jpi[3],'+',jpi[5],'-',dy,')') else - texprint('(0,0)') + texprint(ctxcatcodes,'(0,0)') end end + function jobpositions.MPpos(id) local jpi = pcol[id] or ptbs[id] if jpi then - texprint(concat(jpi,',',1,6)) + texprint(ctxcatcodes,concat(jpi,',',1,6)) else - texprint('0,0,0,0,0,0') + texprint(ctxcatcodes,'0,0,0,0,0,0') end end + +local splitter = lpeg.Ct(lpeg.splitat(",")) + function jobpositions.MPplus(id,n,default) local jpi = pcol[id] or ptbs[id] - texprint((jpi and jpi[6+n]) or default) + if not jpi then + texprint(ctxcatcodes,default) + else + local split = jpi[0] + if not split then + split = lpegmatch(splitter,jpi[7]) + jpi[0] = split + end + texprint(ctxcatcodes,split[n] or default) + end end + function jobpositions.MPrest(id,default) local jpi = pcol[id] or ptbs[id] - texprint((jpi and jpi[7] and concat(jpi,",",7,#jpi)) or default) + -- texprint(ctxcatcodes,(jpi and jpi[7] and concat(jpi,",",7,#jpi)) or default) + texprint(ctxcatcodes,(jpi and jpi[7]) or default) end |