diff options
Diffstat (limited to 'tex')
35 files changed, 792 insertions, 714 deletions
diff --git a/tex/context/base/mkii/cont-new.mkii b/tex/context/base/mkii/cont-new.mkii index f9b37ed76..54acbd16e 100644 --- a/tex/context/base/mkii/cont-new.mkii +++ b/tex/context/base/mkii/cont-new.mkii @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2017.10.19 13:50} +\newcontextversion{2017.10.24 10:30} %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/mkii/context.mkii b/tex/context/base/mkii/context.mkii index 1f6d45f19..99243fd9d 100644 --- a/tex/context/base/mkii/context.mkii +++ b/tex/context/base/mkii/context.mkii @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2017.10.19 13:50} +\edef\contextversion{2017.10.24 10:30} %D For those who want to use this: diff --git a/tex/context/base/mkii/mult-en.mkii b/tex/context/base/mkii/mult-en.mkii index 8a0ab18a5..ca4675c08 100644 --- a/tex/context/base/mkii/mult-en.mkii +++ b/tex/context/base/mkii/mult-en.mkii @@ -796,6 +796,7 @@ \setinterfaceconstant{fieldoffset}{fieldoffset} \setinterfaceconstant{file}{file} \setinterfaceconstant{filler}{filler} +\setinterfaceconstant{filter}{filter} \setinterfaceconstant{filtercommand}{filtercommand} \setinterfaceconstant{finalnamesep}{finalnamesep} \setinterfaceconstant{finalpagesep}{finalpagesep} @@ -1150,6 +1151,7 @@ \setinterfaceconstant{sidemethod}{sidemethod} \setinterfaceconstant{sidespaceafter}{sidespaceafter} \setinterfaceconstant{sidespacebefore}{sidespacebefore} +\setinterfaceconstant{sidethreshold}{sidethreshold} \setinterfaceconstant{sign}{sign} \setinterfaceconstant{size}{size} \setinterfaceconstant{slantedfeatures}{slantedfeatures} diff --git a/tex/context/base/mkii/mult-nl.mkii b/tex/context/base/mkii/mult-nl.mkii index ddd7db44c..b67d7d7ae 100644 --- a/tex/context/base/mkii/mult-nl.mkii +++ b/tex/context/base/mkii/mult-nl.mkii @@ -796,6 +796,7 @@ \setinterfaceconstant{fieldoffset}{veldoffset} \setinterfaceconstant{file}{file} \setinterfaceconstant{filler}{filler} +\setinterfaceconstant{filter}{filter} \setinterfaceconstant{filtercommand}{filtercommand} \setinterfaceconstant{finalnamesep}{finalnamesep} \setinterfaceconstant{finalpagesep}{finalpagesep} @@ -1150,6 +1151,7 @@ \setinterfaceconstant{sidemethod}{zijmethode} \setinterfaceconstant{sidespaceafter}{zijnawit} \setinterfaceconstant{sidespacebefore}{zijvoorwit} +\setinterfaceconstant{sidethreshold}{sidethreshold} \setinterfaceconstant{sign}{teken} \setinterfaceconstant{size}{formaat} \setinterfaceconstant{slantedfeatures}{slantedfeatures} diff --git a/tex/context/base/mkiv/cldf-ini.lua b/tex/context/base/mkiv/cldf-ini.lua index 391160ebe..a2814877d 100644 --- a/tex/context/base/mkiv/cldf-ini.lua +++ b/tex/context/base/mkiv/cldf-ini.lua @@ -603,6 +603,32 @@ function context.printlines(str,raw) -- todo: see if via file is useable end end +-- function context.printtable(t,separator) -- todo: see if via file is useable +-- if separator == nil or separator == true then +-- separator = "\r" +-- elseif separator == "" then +-- separator = false +-- end +-- for i=1,#t do +-- context(t[i]) -- we need to go through catcode handling +-- if separator then +-- context(separator) +-- end +-- end +-- end + +function context.printtable(t,separator) -- todo: see if via file is useable + if separator == nil or separator == true then + separator = "\r" + elseif separator == "" or separator == false then + separator = "" + end + local s = concat(t,separator) + if s ~= "" then + context(s) + end +end + -- -- -- "{" .. ti .. "}" is somewhat slower in a cld-mkiv run than "{",ti,"}" local containseol = patterns.containseol @@ -905,22 +931,22 @@ local defaultcaller = caller setmetatableindex(context,indexer) setmetatablecall (context,caller) -function context.sprint(...) -- takes catcodes as first argument +function context.sprint(...) -- takes catcodes as first argument flush(...) end -function context.fprint(fmt,first,...) - if type(catcodes) == "number" then - if first then - flush(currentcatcodes,formatters[fmt](first,...)) +function context.fprint(first,second,third,...) + if type(first) == "number" then + if third then + flush(first,formatters[second](third,...)) else - flush(currentcatcodes,fmt) + flush(first,second) end else - if fmt then - flush(formatters[catcodes](fmt,first,...)) + if second then + flush(formatters[first](second,third,...)) else - flush(catcodes) + flush(first) end end end diff --git a/tex/context/base/mkiv/cont-new.mkiv b/tex/context/base/mkiv/cont-new.mkiv index 9b956c756..7127cfc4c 100644 --- a/tex/context/base/mkiv/cont-new.mkiv +++ b/tex/context/base/mkiv/cont-new.mkiv @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2017.10.19 13:50} +\newcontextversion{2017.10.24 10:30} %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/mkiv/context.mkiv b/tex/context/base/mkiv/context.mkiv index 65f779e19..a2cf1f308 100644 --- a/tex/context/base/mkiv/context.mkiv +++ b/tex/context/base/mkiv/context.mkiv @@ -41,7 +41,7 @@ %D up and the dependencies are more consistent. \edef\contextformat {\jobname} -\edef\contextversion{2017.10.19 13:50} +\edef\contextversion{2017.10.24 10:30} \edef\contextkind {beta} %D For those who want to use this: @@ -455,6 +455,7 @@ \loadmarkfile{meta-grd} \loadmarkfile{meta-fnt} \loadmarkfile{meta-nod} +\loadmarkfile{meta-lua} \loadmarkfile{page-mrk} % depends on mp diff --git a/tex/context/base/mkiv/lpdf-fmt.lua b/tex/context/base/mkiv/lpdf-fmt.lua index 241bca182..0830d2d8d 100644 --- a/tex/context/base/mkiv/lpdf-fmt.lua +++ b/tex/context/base/mkiv/lpdf-fmt.lua @@ -355,7 +355,7 @@ local formats = utilities.storage.allocate { pdf_version = 1.7, format_name = "pdf/a-2a", xmp_file = "lpdf-pda.xml", - gts_flag = "GTS_PDFA2", + gts_flag = "GTS_PDFA1", gray_scale = true, cmyk_colors = true, rgb_colors = true, @@ -379,7 +379,7 @@ local formats = utilities.storage.allocate { pdf_version = 1.7, format_name = "pdf/a-3a", xmp_file = "lpdf-pda.xml", - gts_flag = "GTS_PDFA3", + gts_flag = "GTS_PDFA1", gray_scale = true, cmyk_colors = true, rgb_colors = true, diff --git a/tex/context/base/mkiv/lpdf-tag.lua b/tex/context/base/mkiv/lpdf-tag.lua index b9d3e3e64..f4ecfc8a6 100644 --- a/tex/context/base/mkiv/lpdf-tag.lua +++ b/tex/context/base/mkiv/lpdf-tag.lua @@ -149,13 +149,15 @@ local function finishstructure() pdfflushobject(structure_ref,structuretree) addtocatalog("StructTreeRoot",pdfreference(structure_ref)) -- - local markinfo = pdfdictionary { - Marked = lpdf.majorversion == 1 and pdfboolean(true) or nil, - -- UserProperties = pdfboolean(true), -- maybe some day - -- Suspects = lpdf.majorversion == 1 and pdfboolean(true) or nil, - -- AF = #embeddedfilelist > 0 and pdfreference(pdfflushobject(embeddedfilelist)) or nil, - } - addtocatalog("MarkInfo",pdfreference(pdfflushobject(markinfo))) + if lpdf.majorversion() == 1 then + local markinfo = pdfdictionary { + Marked = pdfboolean(true) or nil, + -- UserProperties = pdfboolean(true), -- maybe some day + -- Suspects = pdfboolean(true) or nil, + -- AF = #embeddedfilelist > 0 and pdfreference(pdfflushobject(embeddedfilelist)) or nil, + } + addtocatalog("MarkInfo",pdfreference(pdfflushobject(markinfo))) + end -- for fulltag, element in sortedhash(elements) do -- sorting is easier on comparing pdf pdfflushobject(element.knum,element.kids) diff --git a/tex/context/base/mkiv/math-noa.lua b/tex/context/base/mkiv/math-noa.lua index 6e0324256..1d7c6eb05 100644 --- a/tex/context/base/mkiv/math-noa.lua +++ b/tex/context/base/mkiv/math-noa.lua @@ -97,6 +97,7 @@ local setlist = nuts.setlist local setnext = nuts.setnext local setprev = nuts.setprev local setchar = nuts.setchar +local setfam = nuts.setfam local setsubtype = nuts.setsubtype local setattr = nuts.setattr @@ -108,6 +109,7 @@ local getid = nuts.getid local getsubtype = nuts.getsubtype local getchar = nuts.getchar local getfont = nuts.getfont +local getfam = nuts.getfam local getattr = nuts.getattr local getlist = nuts.getlist @@ -226,7 +228,7 @@ local function process(start,what,n,parent) elseif id == math_char then local char = getchar(start) local font = getfont(start) - local fam = getfield(start,"fam") + local fam = getfam(start) report_processing("%w%S, family %a, font %a, char %a, shape %c",n*2,nutstring(start),fam,font,char,char) else report_processing("%w%S",n*2,nutstring(start)) @@ -454,7 +456,7 @@ do } families[math_char] = function(pointer) - if getfield(pointer,"fam") == 0 then + if getfam(pointer) == 0 then local a = getattr(pointer,a_mathfamily) if a and a > 0 then setattr(pointer,a_mathfamily,0) @@ -466,13 +468,13 @@ do if trace_families then report_families("no bold replacement for %C, family %s with remap %s becomes %s with remap %s",char,a,familymap[a],newa,familymap[newa]) end - setfield(pointer,"fam",newa) + setfam(pointer,newa) elseif not fontcharacters[font_of_family(newa)][bold] then if trace_families then report_families("no bold character for %C, family %s with remap %s becomes %s with remap %s",char,a,familymap[a],newa,familymap[newa]) end if newa > 3 then - setfield(pointer,"fam",newa-3) + setfam(pointer,newa-3) end else setattr(pointer,a_exportstatus,char) @@ -480,7 +482,7 @@ do if trace_families then report_families("replacing %C by bold %C, family %s with remap %s becomes %s with remap %s",char,bold,a,familymap[a],newa,familymap[newa]) end - setfield(pointer,"fam",newa) + setfam(pointer,newa) end else local char = getchar(pointer) @@ -492,7 +494,7 @@ do if trace_families then report_families("family of %C becomes %s with remap %s",char,a,familymap[a]) end - setfield(pointer,"fam",a) + setfam(pointer,a) end end end @@ -529,6 +531,30 @@ do end end + -- will become: + + -- families[math_delim] = function(pointer) + -- if getfam(pointer) == 0 then + -- local a = getattr(pointer,a_mathfamily) + -- if a and a > 0 then + -- setattr(pointer,a_mathfamily,0) + -- if a > 5 then + -- -- no bold delimiters in unicode + -- a = a - 3 + -- end + -- local char = getchar(pointer) + -- local okay = fontcharacters[font_of_family(a)][char] + -- if okay then + -- setfam(pointer,a) + -- elseif a > 2 then + -- setfam(pointer,a-3) + -- end + -- else + -- setfam(pointer,0) + -- end + -- end + -- end + families[math_textchar] = families[math_char] function handlers.families(head,style,penalties) @@ -732,6 +758,28 @@ do end end + -- will become: + + -- resize[math_fence] = function(pointer) + -- local subtype = getsubtype(pointer) + -- if subtype == left_fence_code or subtype == right_fence_code then + -- local a = getattr(pointer,a_mathsize) + -- if a and a > 0 then + -- local method, size = div(a,100), a % 100 + -- setattr(pointer,a_mathsize,0) + -- local delimiter = getfield(pointer,"delim") + -- local chr = getchar(delimiter) + -- if chr > 0 then + -- local fam = getfam(delimiter) + -- local id = font_of_family(fam) + -- if id > 0 then + -- setchar(delimiter,mathematics.big(fontdata[id],chr,size,method)) + -- end + -- end + -- end + -- end + -- end + function handlers.resize(head,style,penalties) processnoads(head,resize,"resize") return true @@ -753,12 +801,12 @@ do if char then local sym = getnucleus(char) local chr = getchar(sym) - local fam = getfield(sym,"fam") + local fam = getfam(sym) if chr == dummyfencechar then chr = 0 end setfield(d,"small_char",chr) - setfield(d,"small_fam", fam) + setfield(d,"small_fam",fam) flush_node(sym) end setsubtype(f,what) @@ -767,6 +815,28 @@ do return f end + -- will become + + -- local function makefence(what,char) + -- local d = new_delimiter() + -- local f = new_fence() + -- if char then + -- local sym = getnucleus(char) + -- local chr = getchar(sym) + -- local fam = getfam(sym) + -- if chr == dummyfencechar then + -- chr = 0 + -- end + -- setchar(d,chr) + -- setfam(d,fam) + -- flush_node(sym) + -- end + -- setsubtype(f,what) + -- setfield(f,"delim",d) + -- setfield(f,"class",-1) -- tex itself does this, so not fenceclasses[what] + -- return f + -- end + local function makelist(noad,f_o,o_next,c_prev,f_c,middle) local list = new_submlist() setlist(list,f_o) diff --git a/tex/context/base/mkiv/meta-grd.mkiv b/tex/context/base/mkiv/meta-grd.mkiv index da410ba68..8b1a934d6 100644 --- a/tex/context/base/mkiv/meta-grd.mkiv +++ b/tex/context/base/mkiv/meta-grd.mkiv @@ -84,9 +84,9 @@ \def\typo_grid_base[#1]% {\hbox\bgroup \getdummyparameters - [\c!nx=10,\c!ny=10,\c!dx=.5,\c!dy=.5,\c!xstep=0,\c!ystep=0, - \c!unit=\s!cm,\c!scale=1,\c!factor=1, - \c!offset=.25ex,\c!xoffset=\directdummyparameter\c!offset,\c!yoffset=\directdummyparameter\c!offset, + [\c!nx=10,\c!ny=10,\c!dx=.5,\c!dy=.5,\c!xstep=0,\c!ystep=0,% + \c!unit=\s!cm,\c!scale=1,\c!factor=1,% + \c!offset=.25ex,\c!xoffset=\directdummyparameter\c!offset,\c!yoffset=\directdummyparameter\c!offset,% \c!align=, #1]% \usedummystyleandcolor\c!style\c!color diff --git a/tex/context/base/mkiv/meta-imp-txt.mkiv b/tex/context/base/mkiv/meta-imp-txt.mkiv index b2a6d6d1d..56da9229d 100644 --- a/tex/context/base/mkiv/meta-imp-txt.mkiv +++ b/tex/context/base/mkiv/meta-imp-txt.mkiv @@ -11,15 +11,12 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -%D In this library some handy text manipulations are -%D defined. Some can and will be improved as soon as the -%D \TEX||\METAPOST\ interface is stable. Some of the -%D solutions may look weird, which is entirely my fault, -%D since I implemented them in the process of getting grip -%D on this kind of manipulations. Undoubtly better -%D \METAPOST\ code is possible, but my way of learning -%D this kind of trickery happens to be by \quote {trial -%D and error} and \quote {look and feel} (as well as +%D In this library some handy text manipulations are defined. Some can and will be +%D improved as soon as the \TEX||\METAPOST\ interface is stable. Some of the +%D solutions may look weird, which is entirely my fault, since I implemented them in +%D the process of getting grip on this kind of manipulations. Undoubtly better +%D \METAPOST\ code is possible, but my way of learning this kind of trickery happens +%D to be by \quote {trial and error} and \quote {look and feel} (as well as %D identifying tricks in Hobby's code). % textext ipv btex ... etex @@ -30,112 +27,102 @@ \definesystemvariable {sh} % ShapedText .. todo: commandhandler +\unexpanded\def\setupshapetexts + {\dodoubleempty\getparameters[\??sh]} + +\setupshapetexts + [\c!bodyfont=] + \startMPextensions loadmodule "text" ; \stopMPextensions -%%%%%%% - -% \def\newchar#1{\chardef#1=0 } - -\ifdefined\MPtoks \else \newtoks\MPtoks \fi -\ifdefined\MPbox \else \newbox \MPbox \fi - -\ifdefined\parwidth \else \newdimen\parwidth \fi -\ifdefined\parheight \else \newdimen\parheight \fi -\ifdefined\parvoffset \else \newdimen\parvoffset \fi -\ifdefined\parhoffset \else \newdimen\parhoffset \fi -\ifdefined\parlines \else \newcount\parlines \fi -\ifdefined\partoks \else \newtoks \partoks \fi -\ifdefined\shapetextbox \else \newbox \shapetextbox \fi - \newif \ifparseries -\ifdefined\parfirst \else \chardef \parfirst=0 \fi +\ifdefined\parwidth \else + \newdimen\parwidth + \newdimen\parheight + \newdimen\parvoffset + \newdimen\parhoffset + \newcount\parlines + \newtoks \partoks + \newbox \shapetextbox + \newcount\parfirst +\fi \unexpanded\def\startshapetext[#1]% {\global\newcounter\currentshapetext \global\setbox\shapetextbox\vbox\bgroup - \expanded{\switchtobodyfont[\@@shbodyfont]}% + \switchtobodyfont[\@@shbodyfont]% \dontcomplain \hsize\parwidth \setuptolerance[\v!verytolerant,\v!stretch]% - \!!counta\zerocount - \!!toksa\emptytoks + \scratchcounter\zerocount + \scratchtoks\emptytoks \def\docommand##1% {\setbox\scratchbox\hbox{\useMPgraphic{##1}}% - \global\chardef\parfirst\zerocount - \getMPdata % \readlocfile{\MPdatafile}{}{}% + \global\parfirst\zerocount + \getMPdata \setshapecharacteristics - \advance\!!counta by \parlines - \expandafter\appendtoks\the\partoks\to\!!toksa}% + \advance\scratchcounter by \parlines + \expandafter\appendtoks\the\partoks\to\scratchtoks}% \processcommalist[#1]\docommand - \global\parseriestrue - \xdef\totalparlines{\the\!!counta}% - \global\partoks\!!toksa - %\ifx\partoks\emptytoks\else % safeguard - \expanded{\parshape \the\!!counta \the\!!toksa}% - %\fi + \xdef\totalparlines{\the\scratchcounter}% + \global\partoks\scratchtoks + \parshape \the\scratchcounter \the\scratchtoks\relax \setshapecharacteristics % extra dummy - \ifparseries\def\par{\endgraf\adaptparshape}\fi - \EveryPar{\begstrut}} + \def\par{\endgraf\adaptparshape}% + \everypar{\begstrut}} \unexpanded\def\stopshapetext {\endstrut - %\removebottomthings \egroup \global\newcounter\currentshapetext \getshapecharacteristics} \unexpanded\def\adaptparshape {\def\docommand##1% - {\ifcase\!!counta - \expandafter\appendtoks\space##1 \to\!!toksa + {\ifcase\scratchcounter + \expandafter\appendtoks\space##1 \to\scratchtoks \else - \advance\!!counta \minusone + \advance\scratchcounter\minusone \fi}% - \!!counta\prevgraf - \doglobal\decrement(\totalparlines,\!!counta)% - \multiply\!!counta \plustwo - \!!toksa\emptytoks + \scratchcounter\prevgraf + \doglobal\decrement(\totalparlines,\scratchcounter)% + \multiply\scratchcounter\plustwo + \scratchtoks\emptytoks \expanded{\processseparatedlist[\the\partoks][\space]}\docommand - \global\partoks\!!toksa - %\ifx\partoks\emptytoks\else % safeguard - \expanded{\parshape\totalparlines\the\partoks}% - }%\fi} + \global\partoks\scratchtoks + \parshape\totalparlines\the\partoks\relax} \unexpanded\def\getshapecharacteristics {\doglobal\increment\currentshapetext \doifelsedefined{parlines:\currentshapetext} - {\global\parlines \getvalue{parlines:\currentshapetext}% - \global\chardef\parfirst \getvalue{parfirst:\currentshapetext}% - \global\parvoffset \getvalue{parvoffset:\currentshapetext}% - \global\parhoffset \getvalue{parhoffset:\currentshapetext}% - \global\parwidth \getvalue{parwidth:\currentshapetext}% - \global\parheight \getvalue{parheight:\currentshapetext}} - {\global\parlines \plusone - \global\chardef\parfirst \zerocount - \global\parvoffset \zeropoint - \global\parhoffset \zeropoint - \global\parwidth \hsize - \global\parheight \vsize}} + {\getvalue{parlines:\currentshapetext}} + {\global\parlines \plusone + \global\parfirst \zerocount + \global\parvoffset\zeropoint + \global\parhoffset\zeropoint + \global\parwidth \hsize + \global\parheight \vsize}} \unexpanded\def\setshapecharacteristics {\doglobal\increment\currentshapetext - \setxvalue{parlines:\currentshapetext }{\the\parlines}% - \setxvalue{parfirst:\currentshapetext }{\the\parfirst}% - \setxvalue{parvoffset:\currentshapetext}{\the\parvoffset}% - \setxvalue{parhoffset:\currentshapetext}{\the\parhoffset}% - \setxvalue{parwidth:\currentshapetext }{\the\parwidth}% - \setxvalue{parheight:\currentshapetext }{\the\parheight}} + \setxvalue{parlines:\currentshapetext}% + {\global\parlines \the\parlines + \global\parfirst \the\parfirst + \global\parvoffset\the\parvoffset + \global\parhoffset\the\parhoffset + \global\parwidth \the\parwidth + \global\parheight \the\parheight}} \unexpanded\def\getshapetext % option: unvbox {\vbox\bgroup \forgetall \dontcomplain \setbox\scratchbox\vbox to \parheight - {\expanded{\switchtobodyfont[\@@shbodyfont]}% evt strutheight en - \splittopskip\strutheight % lineheight opslaan - \vskip\parvoffset % scheelt switch en - \ifcase\parfirst\or\vskip\lineheight\fi % is ook veiliger + {\switchtobodyfont[\@@shbodyfont]% + \splittopskip\strutheight + \vskip\parvoffset + \ifcase\parfirst\else\vskip\lineheight\fi \hskip\parhoffset \hbox{\vsplit\shapetextbox to \parlines\lineheight}}% \wd\scratchbox\parwidth @@ -145,89 +132,8 @@ \getshapecharacteristics \egroup} -\unexpanded\def\setupshapetexts - {\dodoubleempty\getparameters[\??sh]} - -\setupshapetexts - [\c!bodyfont=] - \doifundefined{RotFont}{\definefont[RotFont][RegularBold*default]} -% \startuseMPgraphic{followtokens} -% % we default to nothing -% \stopuseMPgraphic - -% \unexpanded\def\processfollowingtoken#1% strut toegevoegd -% {\appendtoks#1\to\MPtoks -% \setbox\MPbox=\hbox{\RotFont\setstrut\strut\the\MPtoks}% -% \startMPdrawing -% n := n + 1 ; len[n] := \the\wd\MPbox ; -% \stopMPdrawing -% \startMPdrawing[-] -% % pic[n] := textext{\RotFont\setstrut\strut#1} ; % btex \RotFont\setstrut\strut#1 etex ; -% pic[n] := btex \RotFont\setstrut\strut#1 etex ; -% pic[n] := pic[n] shifted - llcorner pic[n] ; -% \stopMPdrawing} -% -% \unexpanded\def\dofollowtokens#1#2% -% {\vbox\bgroup -% \forgetall -% \dontcomplain -% \doifundefined{RotFont}{\definefont[RotFont][RegularBold*default]}% -% \MPtoks\emptytoks -% \resetMPdrawing -% \startMPdrawing -% \includeMPgraphic{followtokens} ; -% picture pic[] ; numeric len[], n ; n := 0 ; -% \stopMPdrawing -% \handletokens#2\with\processfollowingtoken -% \startMPdrawing -% if unknown RotPath : path RotPath ; RotPath := origin ; fi ; -% if unknown RotColor : color RotColor ; RotColor := black ; fi ; -% if unknown TraceRot : boolean TraceRot ; TraceRot := false ; fi ; -% if unknown ExtraRot : numeric ExtraRot ; ExtraRot := 0 ; fi ; -% numeric al, at, pl, pc, wid, pos ; pair ap, ad ; -% al := arclength RotPath ; -% if al=0 : -% al := len[n] + ExtraRot ; -% RotPath := origin -- (al,0) ; -% fi ; -% if al<len[n]: -% RotPath := RotPath scaled ((len[n]+ExtraRot)/al) ; -% al := arclength RotPath ; -% fi ; -% if \number#1 = 1 : -% pl := (al-len[n])/(if n>1 : (n-1) else : 1 fi) ; -% pc := 0 ; -% else : % centered / MP -% pl := 0 ; -% pc := arclength RotPath/2 - len[n]/2 ; -% fi ; -% if TraceRot : -% draw RotPath withpen pencircle scaled 1pt withcolor blue ; -% fi ; -% for i=1 upto n : -% wid := abs(xpart urcorner pic[i] - xpart llcorner pic[i]) ; -% pos := len[i]-wid/2 + (i-1)*pl + pc ; -% at := arctime pos of RotPath ; -% ap := point at of RotPath ; -% ad := direction at of RotPath ; -% draw pic[i] shifted (-wid/2,0) rotated(angle(ad)) shifted ap -% withcolor RotColor ; -% if TraceRot : -% draw boundingbox -% pic[i] shifted (-wid/2,0) rotated(angle(ad)) shifted ap -% withpen pencircle scaled .25pt withcolor red ; -% draw ap -% withpen pencircle scaled .50pt withcolor green ; -% fi ; -% endfor ; -% \stopMPdrawing -% \MPdrawingdonetrue -% \getMPdrawing -% \resetMPdrawing -% \egroup} - \unexpanded\def\getfollowtoken#1% {\hbox\bgroup \strut @@ -479,8 +385,7 @@ \setlocalhsize \noindent \reuseMPgraphic{EnglishRule} \stoplinecorrection} -%D The following macro returns a tight bound character -%D sequence. +%D The following macro returns a tight bound character sequence. %D %D \useMPlibrary[txt] %D diff --git a/tex/context/base/mkiv/meta-ini.lua b/tex/context/base/mkiv/meta-ini.lua index 114553c7a..4ba0cec2d 100644 --- a/tex/context/base/mkiv/meta-ini.lua +++ b/tex/context/base/mkiv/meta-ini.lua @@ -8,6 +8,7 @@ if not modules then modules = { } end modules ['meta-ini'] = { local tonumber = tonumber local format = string.format +local concat = table.concat local lpegmatch, lpegpatterns = lpeg.match, lpeg.patterns local P, Cs, R, S, C, Cc = lpeg.P, lpeg.Cs, lpeg.R, lpeg.S, lpeg.C, lpeg.Cc @@ -15,131 +16,133 @@ metapost = metapost or { } local metapost = metapost local context = context --- experimental - local colorhash = attributes.list[attributes.private('color')] - local textype = tex.type local MPcolor = context.MPcolor --- local validdimen = lpegpatterns.validdimen * P(-1) --- --- function commands.prepareMPvariable(v) -- slow but ok --- if v == "" then --- MPcolor("black") --- else --- local typ, var = match(v,"(.):(.*)") --- if not typ then --- -- parse --- if colorhash[v] then --- MPcolor(v) --- elseif tonumber(v) then --- context(v) --- elseif lpegmatch(validdimen,v) then --- return context("\\the\\dimexpr %s",v) --- else --- for s in gmatch(v,"\\([a-zA-Z]+)") do -- can have trailing space --- local t = textype(s) --- if t == "dimen" then --- return context("\\the\\dimexpr %s",v) --- elseif t == "count" then --- return context("\\the\\numexpr %s",v) --- end --- end --- context("\\number %s",v) -- 0.4 ... --- end --- elseif typ == "d" then -- to be documented --- -- dimension --- context("\\the\\dimexpr %s",var) --- elseif typ == "n" then -- to be documented --- -- number --- context("\\the\\numexpr %s",var) --- elseif typ == "s" then -- to be documented --- -- string --- context(var) --- elseif typ == "c" then -- to be documented --- -- color --- MPcolor(var) --- else --- context(var) --- end --- end --- end - --- we can actually get the dimen/count values here - -local dimenorname = - lpegpatterns.validdimen / function(s) - context("\\the\\dimexpr %s",s) - end - + (C(lpegpatterns.float) + Cc(1)) * lpegpatterns.space^0 * P("\\") * C(lpegpatterns.letter^1) / function(f,s) - local t = textype(s) - if t == "dimen" then - context("\\the\\dimexpr %s\\%s\\relax",f,s) - elseif t == "count" then - context("\\the\\numexpr \\%s * %s\\relax",s,f) -- <n>\scratchcounter is not permitted +do + + local dimenorname = + lpegpatterns.validdimen / function(s) + context("\\the\\dimexpr %s",s) end - end + + (C(lpegpatterns.float) + Cc(1)) * lpegpatterns.space^0 * P("\\") * C(lpegpatterns.letter^1) / function(f,s) + local t = textype(s) + if t == "dimen" then + context("\\the\\dimexpr %s\\%s\\relax",f,s) + elseif t == "count" then + context("\\the\\numexpr \\%s * %s\\relax",s,f) -- <n>\scratchcounter is not permitted + end + end + + local splitter = lpeg.splitat("::",true) -local splitter = lpeg.splitat("::",true) - -interfaces.implement { - name = "prepareMPvariable", - arguments = "string", - actions = function(v) - if v == "" then - -- MPcolor("black") - context("black") - else - local typ, var = lpegmatch(splitter,v) - if not var then - -- parse - if colorhash[v] then - -- MPcolor(v) + interfaces.implement { + name = "prepareMPvariable", + arguments = "string", + actions = function(v) + if v == "" then + -- MPcolor("black") + context("black") + else + local typ, var = lpegmatch(splitter,v) + if not var then + -- parse + if colorhash[v] then + -- MPcolor(v) + context("%q",var) + elseif tonumber(v) then + context(v) + elseif not lpegmatch(dimenorname,v) then + context("\\number %s",v) -- 0.4 ... + end + elseif typ == "d" then -- to be documented + -- dimension + context("\\the\\dimexpr %s\\relax",var) + elseif typ == "n" then -- to be documented + -- number + context("\\the\\numexpr %s\\relax",var) + elseif typ == "s" then -- to be documented + -- string + -- context(var) + context("%q",var) + elseif typ == "c" then -- to be documented + -- color + -- MPcolor(var) context("%q",var) - elseif tonumber(v) then - context(v) - elseif not lpegmatch(dimenorname,v) then - context("\\number %s",v) -- 0.4 ... + else + context(var) end - elseif typ == "d" then -- to be documented - -- dimension - context("\\the\\dimexpr %s\\relax",var) - elseif typ == "n" then -- to be documented - -- number - context("\\the\\numexpr %s\\relax",var) - elseif typ == "s" then -- to be documented - -- string - -- context(var) - context("%q",var) - elseif typ == "c" then -- to be documented - -- color - -- MPcolor(var) - context("%q",var) - else - context(var) end end + } + +end + +do + + local ctx_mathematics = context.mathematics + + -- function metapost.formatnumber(f,n) -- just lua format + -- f = gsub(f,"@(%d)","%%.%1") + -- f = gsub(f,"@","%%") + -- f = format(f,tonumber(n) or 0) + -- f = gsub(f,"e([%+%-%d]+)",function(s) + -- return format("\\times10^{%s}",tonumber(s) or s) -- strips leading zeros + -- end) + -- context.mathematics(f) + -- end + + -- formatters["\\times10^{%N}"](s) -- strips leading zeros too + + local one = Cs((P("@")/"%%." * (R("09")^1) + P("@")/"%%" + 1)^0) + local two = Cs((P("e")/"" * ((S("+-")^0 * R("09")^1) / function(s) return format("\\times10^{%s}",tonumber(s) or s) end) + 1)^1) + + -- local two = Cs((P("e")/"" * ((S("+-")^0 * R("09")^1) / formatters["\\times10^{%N}"]) + 1)^1) + + function metapost.formatnumber(fmt,n) -- just lua format + ctx_mathematics(lpegmatch(two,format(lpegmatch(one,fmt),n))) + end + +end + +do + + -- this is an old pass-data-to-tex mechanism + + local ctx_printtable = context.printtable + + local data = false + + function mp.start_saving_data(n) + data = { } end -} --- function metapost.formatnumber(f,n) -- just lua format --- f = gsub(f,"@(%d)","%%.%1") --- f = gsub(f,"@","%%") --- f = format(f,tonumber(n) or 0) --- f = gsub(f,"e([%+%-%d]+)",function(s) --- return format("\\times10^{%s}",tonumber(s) or s) -- strips leading zeros --- end) --- context.mathematics(f) --- end + function mp.stop_saving_data() + if data then + -- nothing + end + end --- formatters["\\times10^{%N}"](s) -- strips leading zeros too + function mp.finish_saving_data() + if data then + -- nothing + end + end -local one = Cs((P("@")/"%%." * (R("09")^1) + P("@")/"%%" + 1)^0) -local two = Cs((P("e")/"" * ((S("+-")^0 * R("09")^1) / function(s) return format("\\times10^{%s}",tonumber(s) or s) end) + 1)^1) + function mp.save_data(str) + if data then + data[#data+1] = str + end + end --- local two = Cs((P("e")/"" * ((S("+-")^0 * R("09")^1) / formatters["\\times10^{%N}"]) + 1)^1) + interfaces.implement { + name = "getMPdata", + actions = function() + if data then + ctx_printtable(data,"\r") + end + end + } -function metapost.formatnumber(fmt,n) -- just lua format - context.mathematics(lpegmatch(two,format(lpegmatch(one,fmt),n))) end diff --git a/tex/context/base/mkiv/meta-ini.mkiv b/tex/context/base/mkiv/meta-ini.mkiv index 1d0fa11e0..03d800958 100644 --- a/tex/context/base/mkiv/meta-ini.mkiv +++ b/tex/context/base/mkiv/meta-ini.mkiv @@ -84,9 +84,9 @@ \def \t_meta_inclusions {\csname\??mpinclusions \currentMPinstance\endcsname} % token register \def \t_meta_definitions {\csname\??mpdefinitions\currentMPinstance\endcsname} % token register -% The next command is, of course, dedicated to Mojca, who -% needs it for gnuplot. Anyway, the whole multiple engine -% mechanism is to keep her gnuplot from interfering. +%D The next command is, of course, dedicated to Mojca, who needs it for gnuplot. +%D Anyway, the whole multiple engine mechanism is to keep her gnuplot from +%D interfering. \unexpanded\def\startMPdefinitions {\dosinglegroupempty\meta_start_definitions} @@ -155,13 +155,6 @@ \global\t_meta_inclusions\expandafter{\the\t_meta_inclusions#2}% \let\currentMPinstance\m_meta_saved_instance} -% \def\meta_preset_definitions -% {\edef\overlaywidth {\overlaywidth \space}% -% \edef\overlayheight {\overlayheight \space}% -% \edef\overlaylinewidth{\overlaylinewidth\space}} - -\let\meta_preset_definitions\relax - \installcommandhandler \??mpinstance {MPinstance} \??mpinstance \setupMPinstance @@ -261,7 +254,6 @@ {\begingroup \meta_enable_include \the\everyMPgraphic - \meta_preset_definitions %\setMPrandomseed % this has to change \edef\p_initializations{\MPinstanceparameter\s!initializations}% \ifx\p_initializations\v!yes @@ -365,12 +357,11 @@ % % \useMPgraphic{x} % -% so we cannot overload unless we let back to the original meanings -% each graphic ... a better solution is: +% so we cannot overload unless we let back to the original meanings each graphic +% ... a better solution is: \def\includeMPgraphic#1% gets expanded ! {\ifcsname\??mpgraphic#1\endcsname - %\doubleexpandafter\fourthoffourarguments\csname\??mpgraphic#1\endcsname ; % ; is safeguard \doubleexpandafter\fourthoffourarguments\lastnamedcs ; % ; is safeguard \fi} @@ -408,7 +399,6 @@ {\relax \bgroup \meta_enable_include - \meta_preset_definitions % in case #2 has measures \doifelse{#1}{-}{\convertargument#2\to\asciia}{\def\asciia{#2}}% \xdef\MPdrawingdata{\MPdrawingdata\asciia}% \egroup} @@ -419,7 +409,6 @@ {\relax \bgroup \meta_enable_include - \meta_preset_definitions \xdef\MPdrawingdata{\MPdrawingdata#1}% \egroup} @@ -458,8 +447,8 @@ \relax}% \meta_stop_current_graphic} -%D Since we want lables to follow the document settings, we -%D also set the font related variables. +%D Since we want lables to follow the document settings, we also set the font +%D related variables. \unexpanded\def\MPfontsizehskip#1% {\dontleavehmode @@ -476,12 +465,6 @@ % defaultscale:=1; \stopMPinitializations -% watch out, this is a type1 font because mp can only handle 8 bit fonts - -% \startMPinitializations % scale is not yet ok -% defaultfont:="rm-lmtt10"; -% \stopMPinitializations - %D A signal that we're in combined \CONTEXT||\METAFUN mode: \startMPextensions @@ -496,12 +479,11 @@ %D \macros %D {setupMPvariables} %D -%D When we build collections of \METAPOST\ graphics, like -%D background and buttons, the need for passing settings -%D arises. By (mis|)|using the local prefix that belongs to -%D \type {\framed}, we get a rather natural interface to -%D backgrounds. To prevent conflicts, we will use the \type -%D {-} in \METAPOST\ specific variables, like: +%D When we build collections of \METAPOST\ graphics, like background and buttons, +%D the need for passing settings arises. By (mis|)|using the local prefix that +%D belongs to \type {\framed}, we get a rather natural interface to backgrounds. To +%D prevent conflicts, we will use the \type {-} in \METAPOST\ specific variables, +%D like: %D %D \starttyping %D \setupMPvariables[meta:button][size=20pt] @@ -510,9 +492,9 @@ % \lineheight 2pt 2 \scratchcounter red 0.4 .5\bodyfontsize % % see cont-loc for test code -% -% currently the inheritance of backgrounds does not work and -% we might drop it anyway (too messy) + +%D Currently the inheritance of backgrounds does not work and we might drop it +%D anyway (too messy) \newbox\b_meta_variable_box @@ -623,9 +605,9 @@ %D \macros %D {startuniqueMPgraphic, uniqueMPgraphic} %D -%D This macros is probably of most use to myself, since I like -%D to use graphics that adapt themselves. The next \METAPOST\ -%D kind of graphic is both unique and reused when possible. +%D This macros is probably of most use to myself, since I like to use graphics that +%D adapt themselves. The next \METAPOST\ kind of graphic is both unique and reused +%D when possible. %D %D \starttyping %D \defineoverlay[example][\uniqueMPgraphic{test}] @@ -644,19 +626,17 @@ \MPcolor\overlaycolor :% % todo, expand once \m_overlaycolor \MPcolor\overlaylinecolor} % todo, expand once \m_overlaylinecolor -%D A better approach is to let additional variables play a role -%D in determining the uniqueness. In the next macro, the -%D second, optional, argument is used to guarantee the -%D uniqueness, as well as prepare variables for passing them to +%D A better approach is to let additional variables play a role in determining the +%D uniqueness. In the next macro, the second, optional, argument is used to +%D guarantee the uniqueness, as well as prepare variables for passing them to %D \METAPOST. %D %D \starttyping %D \startuniqueMPgraphic{meta:hash}{gap,angle,...} %D \stoptyping %D -%D The calling macro also accepts a second argument. For -%D convenient use in overlay definitions, we use \type {{}} -%D instead of \type {[]}. +%D The calling macro also accepts a second argument. For convenient use in overlay +%D definitions, we use \type {{}} instead of \type {[]}. %D %D \starttyping %D \uniqueMPgraphic{meta:hash}{gap=10pt,angle=30} @@ -699,9 +679,6 @@ {\MPllx#2\MPlly#3\MPurx#4\MPury#5% \hpack{\forcecolorhack\getobject{MP}{#1}}} % else no proper color intent -% \unexpanded\def\meta_use_box -% {\setobject{MP}} - \unexpanded\def\meta_use_box {\setunreferencedobject{MP}} @@ -723,9 +700,6 @@ \unexpanded\def\startuniqueMPgraphic {\dodoublegroupempty\meta_start_unique_graphic} -% \def\meta_start_unique_graphic#1#2#3\stopuniqueMPgraphic -% {\setgvalue{\??mpgraphic#1}{\meta_handle_unique_graphic{#1}{#2}{#3}}} - \def\meta_start_unique_graphic#1% {\normalexpanded{\meta_start_unique_graphic_indeed{#1}}} @@ -888,12 +862,9 @@ %D {\edef\overlaystamp{\overlaystamp:\MPvariable{##1}}}% %D \processcommalist[#1]\docommand} %D \stoptyping - -%D Since we need to feed \METAPOST\ with expanded dimensions, -%D we introduce a dedicated expansion engine. - -%D We redefine \type {\extendMPoverlaystamp} to preprocess -%D variables using \type {\meta_prepare_variable}. +%D +%D Since we need to feed \METAPOST\ with expanded dimensions, we introduce a +%D dedicated expansion engine. We redefine \type {\extendMPoverlaystamp} to \unexpanded\def\extendMPoverlaystamp#1% {\processcommalist[#1]\meta_extend_overlay_stamp} @@ -909,40 +880,22 @@ % This will change ... -\def\MPdataMPDfile{\jobname-mpgraph.mpd} % this one will become obsolete -\def\MPdataMPOfile{\jobname-mpgraph.mpo} \def\MPdataMPYfile{\jobname-mpgraph.mpy} -% makempy.registerfile(filename) - -% % hm. extensions get expanded so the wrong names then end up in format -% -% \startMPinitializations -% boolean collapse_data; collapse_data:=true ; % will be obsolete -% def data_mpd_file = "\MPdataMPDfile" enddef ; % will go via lua -% def data_mpo_file = "\MPdataMPOfile" enddef ; -% def data_mpy_file = "\MPdataMPYfile" enddef ; -% \stopMPinitializations - \startMPextensions - boolean collapse_data; collapse_data:=true ; % will be obsolete - def data_mpd_file = "\noexpand\MPdataMPDfile" enddef ; % will go via lua - def data_mpo_file = "\noexpand\MPdataMPOfile" enddef ; def data_mpy_file = "\noexpand\MPdataMPYfile" enddef ; \stopMPextensions -\unexpanded\def\getMPdata - {\let\MPdata\secondoftwoarguments - \startreadingfile - % \startnointerference % no, else we need to do all data global - \readlocfile\MPdataMPDfile\donothing\donothing - % \stopnointerference - \stopreadingfile} +\unexpanded\def\getMPdata {\clf_getMPdata} + \let\rawMPdata \clf_getMPdata -% We need this trick because we need to make sure that the tex scanner -% sees newlines and does not quit. Also, we do need to flush the buffer -% under a normal catcode regime in order to expand embedded tex macros. -% As usual with buffers, \type {#1} can be a list. +\unexpanded\def\getMPstored{\clf_getMPstored} + \let\rawMPstored \clf_getMPstored + +%D We need this trick because we need to make sure that the tex scanner sees +%D newlines and does not quit. Also, we do need to flush the buffer under a normal +%D catcode regime in order to expand embedded tex macros. As usual with buffers, +%D \type {#1} can be a list. \unexpanded\def\processMPbuffer {\dosingleempty\meta_process_buffer} @@ -961,22 +914,8 @@ %D \macros %D {startMPenvironment, resetMPenvironment} %D -%D In order to synchronize the main \TEX\ run and the runs -%D local to \METAPOST, environments can be passed. - -% \unexpanded\def\startMPenvironment % second arg gobbles spaces, so that reset gives \emptytoks -% {\dodoubleempty\dostartMPenvironment} - -% \def\dostartMPenvironment[#1][#2]#3\stopMPenvironment -% {\edef\m_meta_option{#1} -% \ifx\m_meta_option\s!reset -% \resetMPenvironment % reset mp toks -% \else\ifx\m_meta_option\v!global -% #3% % use in main doc too -% \else\ifx\m_meta_option\!!plustoken -% #3% % use in main doc too -% \fi\fi\fi -% \ctxlua{metapost.tex.set(\!!bs\detokenize{#3}\!!es)}} +%D In order to synchronize the main \TEX\ run and the runs local to \METAPOST, +%D environments can be passed. \unexpanded\def\startMPenvironment {\begingroup @@ -1003,8 +942,7 @@ \unexpanded\def\useMPenvironmentbuffer[#1]% {\clf_mptexsetfrombuffer{#1}} -%D This command takes \type {[reset]} as optional -%D argument. +%D This command takes \type {[reset]} as optional argument. %D %D \starttyping %D \startMPenvironment @@ -1148,8 +1086,8 @@ \def\MPstring#1{"\begincsname\??mptext#1\endcsname\empty"} \def\MPbetex #1{btex \begincsname\??mptext#1\endcsname\space etex} -%D In order to communicate conveniently with the \TEX\ -%D engine, we introduce some typesetting variables. +%D In order to communicate conveniently with the \TEX\ engine, we introduce some +%D typesetting variables. % \setupcolors[state=stop,conversion=never] % quite tricky ... type mismatch @@ -1169,8 +1107,8 @@ % OverlayOffset:=\overlayoffset; % \stopMPinitializations -% A dirty trick, ** in colo-ini.lua (mpcolor). We cannot use a vardef, because -% that fails with spot colors. +%D A dirty trick, ** in colo-ini.lua (mpcolor). We cannot use a vardef, because +%D that fails with spot colors. \startMPinitializations def OverlayLineColor=\ifx\overlaylinecolor\empty black \else\MPcolor{\overlaylinecolor} \fi enddef; @@ -1241,21 +1179,11 @@ %D \macros %D {PDFMPformoffset} %D -%D In \PDF, forms are clipped and therefore we have to take -%D precautions to get this right. Since this is related to -%D objects, we use the same offset as used there. +%D In \PDF, forms are clipped and therefore we have to take precautions to get this +%D right. Since this is related to objects, we use the same offset as used there. \def\PDFMPformoffset{\objectoffset} -% %D \macros -% %D {insertMPfile} -% %D -% %D Bypassing the special driver and figure mechanism is not -% %D that nice but saves upto 5\% time in embedding \METAPOST\ -% %D graphics by using the low level \PDF\ converter directly, -% %D given of course that we use \PDFTEX. As a result we need to -% %D fool around with the object trigger. - \newtoks\everyinsertMPfile \startMPextensions @@ -1295,19 +1223,17 @@ % if unknown context_bare : input mp-bare.mpiv ; fi ; % \stopMPdefinitions -%D And some more. These are not really needed since we -%D don't use the normal figure inclusion macros any longer. +%D And some more. These are not really needed since we don't use the normal figure +%D inclusion macros any longer. \appendtoks \externalfigurepostprocessors\emptytoks % safeguard \to \everyinsertMPfile -%D We also take care of disabling fancy figure features, that -%D can terribly interfere when dealing with symbols, -%D background graphics and running (postponed) graphics. -%D You won't believe me if I tell you what funny side effects -%D can occur. One took me over a day to uncover when -%D processing the screen version of the \METAFUN\ manual. +%D We also take care of disabling fancy figure features, that can terribly interfere +%D when dealing with symbols, background graphics and running (postponed) graphics. +%D You won't believe me if I tell you what funny side effects can occur. One took me +%D over a day to uncover when processing the screen version of the \METAFUN\ manual. \def\doifelseMPgraphic#1% {\ifcsname\??mpgraphic #1\endcsname \expandafter \firstoftwoarguments \else @@ -1372,8 +1298,8 @@ %D \macros %D {startstaticMPfigure,useMPstaticfigure} %D -%D Static figures are processed only when there has been -%D something changed. Here is Aditya Mahajan's testcase: +%D Static figures are processed only when there has been something changed. Here is +%D Aditya Mahajan's testcase: %D %D \startbuffer %D \startstaticMPfigure{circle} @@ -1415,19 +1341,17 @@ \def\MPdivten[#1]{\withoutpt\the\dimexpr#1pt/10\relax} -%D There is no way to distinguish the black color that you get when -%D you issue a \type {draw} without color specification from a color -%D that has an explicit black specification unless you set the -%D variable \type {defaultcolormodel} to 1. Hoewever, in that case -%D you cannot distinguish that draw from one with a \type -%D {withoutcolor} specification. This means that we have to provide -%D multiple variants of inheritance. +%D There is no way to distinguish the black color that you get when you issue a +%D \type {draw} without color specification from a color that has an explicit black +%D specification unless you set the variable \type {defaultcolormodel} to 1. +%D Hoewever, in that case you cannot distinguish that draw from one with a \type +%D {withoutcolor} specification. This means that we have to provide multiple +%D variants of inheritance. %D -%D In any case we need to tell the converter what the inherited color -%D is to start with. Case~3 is kind of unpredictable as it closely -%D relates to the order in which paths are flushed. If you want to -%D inherit automatically from the surrounding, you can best stick to -%D variant 1. Variant 0 (an isolated graphic) is the default. +%D In any case we need to tell the converter what the inherited color is to start +%D with. Case~3 is kind of unpredictable as it closely relates to the order in which +%D paths are flushed. If you want to inherit automatically from the surrounding, you +%D can best stick to variant 1. Variant 0 (an isolated graphic) is the default. %D %D \startbuffer %D \startuseMPgraphic{test} @@ -1541,10 +1465,9 @@ \installsetuponlycommandhandler \??MPgraphics {MPgraphics} -%D Here we hook in the outer color. When \type {color} is set to \type -%D {global} we get the outer color automatically. If you change this -%D setting, you should do it grouped in order not to make other graphics -%D behave in unexpected ways. +%D Here we hook in the outer color. When \type {color} is set to \type {global} we +%D get the outer color automatically. If you change this setting, you should do it +%D grouped in order not to make other graphics behave in unexpected ways. \appendtoks \doifelse{\directMPgraphicsparameter\c!color}\v!global{\MPcolormethod\plusone}{\MPcolormethod\zerocount}% diff --git a/tex/context/base/mkiv/meta-lua.lua b/tex/context/base/mkiv/meta-lua.lua new file mode 100644 index 000000000..42d036630 --- /dev/null +++ b/tex/context/base/mkiv/meta-lua.lua @@ -0,0 +1,96 @@ +if not modules then modules = { } end modules ['meta-lua'] = { + version = 1.001, + comment = "companion to meta-lua.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files", +} + +-- Don't use this code yet. I use it in some experimental rendering of graphics +-- based on output from database queries. It's not that pretty but will be +-- considered when the (similar) lmx code is redone. Also, dropping the print +-- variant makes it nicer. This experiment is part of playing with several template +-- mechanisms. (Also see trac-lmx.) + +local P, V, Cs, lpegmatch = lpeg.P, lpeg.V, lpeg.Cs, lpeg.match +local formatters = string.formatters +local concat = table.concat +local load, pcall = load, pcall + +local errorformatter = formatters[ [[draw textext("\tttf error in template '%s'") ;]] ] +local concatformatter = formatters[ [[local _t = { } local _n = 0 local p = function(s) _n = _n + 1 _t[_n] = s end %s return table.concat(_t," ")]] ] +local appendformatter = formatters[ [[_n=_n+1 _t[_n]=%q]] ] + +local blua = P("blua ") / " " +local elua = P(" elua") / " " +local bluacode = P("<?lua ") / " " +local eluacode = P(" ?>") / " " + +local plua = (blua * (1 - elua)^1 * elua) +local pluacode = (bluacode * (1 - eluacode)^1 * eluacode) + +-- local methods = { +-- both = Cs { "start", +-- start = (V("bluacode") + V("blua") + V("rest"))^0, +-- blua = plua, +-- bluacode = pluacode, +-- rest = (1 - V("blua") - V("bluacode"))^1 / appendformatter, +-- }, +-- xml = Cs { "start", +-- start = (V("bluacode") + V("rest"))^0, +-- bluacode = pluacode, +-- rest = (1 - V("bluacode"))^1 / appendformatter, +-- }, +-- xml = Cs ((pluacode + (1 - pluacode)^1 / appendformatter)^0), +-- metapost = Cs { "start", +-- start = (V("blua") + V("rest"))^0, +-- blua = plua, +-- rest = (1 - V("blua"))^1 / appendformatter, +-- }, +-- } + +local methods = { + both = Cs ((pluacode + plua + (1 - plua - pluacode)^1 / appendformatter)^0), + xml = Cs ((pluacode + (1 - pluacode)^1 / appendformatter)^0), + metapost = Cs (( plua + (1 - plua )^1 / appendformatter)^0), +} + +methods.mp = methods.metapost + +-- Unfortunately mp adds a suffix ... also weird is that successive loading +-- of the same file gives issues. Maybe some weird buffering goes on (smells +-- similar to older write / read issues). + +mplib.finders.mpstemplate = function(specification,name,mode,ftype) + local authority = specification.authority + local queries = specification.queries + local nameonly = file.nameonly(queries.name or "") + local method = file.nameonly(queries.method or "") + local pattern = methods[method] or methods.both + local data = nil + if nameonly == "" then + data = errorformatter("no name") + elseif authority == "file" then + local foundname = resolvers.findfile(nameonly) + if foundname ~= "" then + data = io.loaddata(foundname) + end + elseif authority == "buffer" then + data = buffers.getcontent(nameonly) + end + data = data and lpegmatch(pattern,data) + data = data and concatformatter(data) + data = data and load(data) + if data then + local okay + okay, data = pcall(data) + end + if not data or data == "" then + data = errorformatter(nameonly) + end + local name = luatex.registertempfile(nameonly,true) + local data = metapost.checktexts(data) + io.savedata(name,data) + return name +end + diff --git a/tex/context/base/mkiv/meta-lua.mkiv b/tex/context/base/mkiv/meta-lua.mkiv new file mode 100644 index 000000000..1d550ea47 --- /dev/null +++ b/tex/context/base/mkiv/meta-lua.mkiv @@ -0,0 +1,95 @@ +%D \module +%D [ file=meta-lua, +%D version=2012.07.23, +%D title=\METAPOST\ Integrated Graphics, +%D subtitle=Templates, +%D author=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 Don't use this code yet. I use it in some experimental rendering of graphics +%D based on output from database queries. It's not that pretty but will be +%D considered when the (similar) lmx code is redone. Also, dropping the print +%D variant makes it nicer. This experiment is part of playing with several template +%D mechanisms. (Also see trac-lmx.) +%D +%D Note for myself: see if the (bar)chart code use in q2p can use this kind of +%D magic. Basically we then need a channel to data. + +\writestatus{loading}{MetaPost Library Graphics / Templates} + +\registerctxluafile{meta-lua}{1.001} + +\continueifinputfile{meta-lua.mkiv} + +\starttext + +% conforming btex ... etex + +\startbuffer[test-a] + blua for i=1,100,5 do elua + draw fullcircle scaled (blua p(i) elua * cm) withcolor green withpen pencircle scaled 4 ; + blua end elua + + blua for i=1,100,10 do elua + draw fullcircle scaled (blua p(i) elua * cm) withcolor red withpen pencircle scaled 2 ; + blua end elua +\stopbuffer + +\startMPpage[offset=10pt] + input "mpstemplate://buffer?name=test-a" ; +\stopMPpage + +% conforming lmx + +\startbuffer[test-b] + <?lua for i=1,100,5 do ?> + draw fullcircle scaled (<?lua p(i) ?> * cm) withcolor green withpen pencircle scaled 4 ; + <?lua end ?> + + <?lua for i=1,100,10 do ?> + draw fullcircle scaled (<?lua p(i) ?> * cm) withcolor red withpen pencircle scaled 2 ; + <?lua end ?> +\stopbuffer + +\startMPpage[offset=10pt] + input "mpstemplate://buffer?name=test-b" ; +\stopMPpage + +\startMPpage[offset=10pt] + picture p[] ; % we can't input nested + input "mpstemplate://buffer?name=test-a&method=metapost" ; + p[1] := currentpicture ; currentpicture := nullpicture ; + input "mpstemplate://buffer?name=test-b&method=xml" ; + p[2] := currentpicture ; currentpicture := nullpicture ; + draw p[1] ysized 3cm ; + draw p[2] ysized 4cm shifted (4cm,0) ; +\stopMPpage + +% a mixture (using a wrapped input) + +\startMPpage[offset=10pt] + draw image (loadfile("mpstemplate://buffer?name=test-a&method=metapost")) ysized 3cm shifted (4cm,0cm) ; + draw image (loadfile("mpstemplate://buffer?name=test-b&method=xml")) ysized 3cm shifted (0cm,4cm) ; + draw loadimage ("mpstemplate://buffer?name=test-a&method=metapost") ysized 4cm shifted (4cm,4cm) ; + draw loadimage ("mpstemplate://buffer?name=test-b&method=xml") ysized 4cm shifted (0cm,0cm) ; +\stopMPpage + +% conforming myself + +\startluacode + context.startMPpage { offset = "10pt" } + for i=1,100,5 do + context("draw fullcircle scaled (%s * cm) withcolor green withpen pencircle scaled 4 ;",i) + end + for i=1,100,10 do + context("draw fullcircle scaled (%s * cm) withcolor red withpen pencircle scaled 2 ;",i) + end + context.stopMPpage() +\stopluacode + +\stoptext diff --git a/tex/context/base/mkiv/meta-tex.lua b/tex/context/base/mkiv/meta-tex.lua index 0c5fedf30..3c31e3e1e 100644 --- a/tex/context/base/mkiv/meta-tex.lua +++ b/tex/context/base/mkiv/meta-tex.lua @@ -7,263 +7,160 @@ if not modules then modules = { } end modules ['meta-tex'] = { } local tostring, tonumber = tostring, tonumber -local format, gsub, find, match = string.format, string.gsub, string.find, string.match +local format = string.format local formatters = string.formatters local P, S, R, C, Cs, lpegmatch = lpeg.P, lpeg.S, lpeg.R, lpeg.C, lpeg.Cs, lpeg.match -metapost = metapost or { } -local metapost = metapost -local context = context +metapost = metapost or { } +local metapost = metapost +local context = context local implement = interfaces.implement --- local left = P("[") --- local right = P("]") --- local space = P(" ") --- local argument = left * C((1-right)^1) * right --- local pattern = (argument + space)^0 +do --- function metapost.sometxt(optional,str) --- if optional == "" then --- context.sometxta(str) --- else --- local one, two = lpegmatch(pattern,optional) --- if two then --- context.sometxtc(one,two,str) --- elseif one then --- context.sometxtb(one,str) --- else --- context.sometxta(str) --- end --- end --- end + local pattern = Cs((P([[\"]]) + P([["]])/"\\quotedbl{}" + P(1))^0) -- or \char -local pattern = Cs((P([[\"]]) + P([["]])/"\\quotedbl{}" + P(1))^0) -- or \char - -function metapost.escaped(str) - context(lpegmatch(pattern,str)) -end - -implement { - name = "metapostescaped", - actions = metapost.escaped, - arguments = "string" -} - -local simplify = true - --- local function strip(n,e) --- -- get rid of e(0) --- -- get rid of e(+*) --- e = gsub(e,"^+","") --- -- remove leading zeros --- e = gsub(e,"^([+-]*)0+(%d)","%1%2") --- if not simplify then --- -- take it as it is --- elseif n == "1" then --- return format("10^{%s}",e) --- end --- return format("%s\\times10^{%s}",n,e) --- end --- --- function metapost.format_n(fmt,...) --- fmt = gsub(fmt,"@","%%") --- local initial, hasformat, final = match(fmt,"^(.-)(%%.-[%a])(.-)$") --- if hasformat then --- str = format(fmt,...) --- str = gsub(str,"(.-)e(.-)$",strip) --- str = format("%s\\mathematics{%s}%s",initial,str,final) --- elseif not find(fmt,"%%") then --- str = format("%"..fmt,...) --- str = gsub(str,"(.-)e(.-)$",strip) --- str = format("\\mathematics{%s}",str) --- end --- context(str) --- end - --- todo: proper lpeg - --- local function strip(n,e) --- -- get rid of e(0) --- -- get rid of e(+*) --- e = gsub(e,"^+","") --- -- remove leading zeros --- e = gsub(e,"^([+-]*)0+(%d)","%1%2") --- if not simplify then --- -- take it as it is --- elseif n == "1" then --- return format("\\mathematics{10^{%s}}",e) --- end --- return format("\\mathematics{%s\\times10^{%s}}",n,e) --- end --- --- function metapost.format_n(fmt,...) --- fmt = gsub(fmt,"@","%%") --- if find(fmt,"%%") then --- str = format(fmt,...) --- else -- yes or no --- str = format("%"..fmt,...) --- end --- str = gsub(str,"([%-%+]-[%.%d]+)e([%-%+]-[%.%d]+)",strip) --- context(str) --- end --- --- function metapost.format_v(fmt,str) --- metapost.format_n(fmt,metapost.untagvariable(str,false)) --- end + function metapost.escaped(str) + context(lpegmatch(pattern,str)) + end --- -- -- + implement { + name = "metapostescaped", + actions = metapost.escaped, + arguments = "string" + } -local number = C((S("+-")^0 * R("09","..")^1)) -local enumber = number * S("eE") * number +end -local cleaner = Cs((P("@@")/"@" + P("@")/"%%" + P(1))^0) +do -context = context or { exponent = function(...) print(...) end } + local simplify = true + local number = C((S("+-")^0 * R("09","..")^1)) + local enumber = number * S("eE") * number + local cleaner = Cs((P("@@")/"@" + P("@")/"%%" + P(1))^0) -function metapost.format_string(fmt,...) - context(lpegmatch(cleaner,fmt),...) -end - -function metapost.format_number(fmt,num) - if not num then - num = fmt - fmt = "%e" + local function format_string(fmt,...) + context(lpegmatch(cleaner,fmt),...) end - local number = tonumber(num) - if number then - local base, exponent = lpegmatch(enumber,formatters[lpegmatch(cleaner,fmt)](number)) - if base and exponent then - context.MPexponent(base,exponent) + + local function format_number(fmt,num) + if not num then + num = fmt + fmt = "%e" + end + local number = tonumber(num) + if number then + local base, exponent = lpegmatch(enumber,formatters[lpegmatch(cleaner,fmt)](number)) + if base and exponent then + context.MPexponent(base,exponent) + else + context(number) + end else - context(number) + context(tostring(num)) end - else - context(tostring(num)) end -end - --- This is experimental and will change! - -function metapost.svformat(fmt,str) - metapost.format_string(fmt,metapost.untagvariable(str,false)) -end -function metapost.nvformat(fmt,str) - metapost.format_number(fmt,metapost.untagvariable(str,false)) -end - -implement { name = "metapostformatted", actions = metapost.svformat, arguments = { "string", "string" } } -implement { name = "metapostgraphformat", actions = metapost.nvformat, arguments = { "string", "string" } } + -- This is experimental and will change! --- kind of new + metapost.format_string = format_string + metapost.format_number = format_number -local f_exponent = formatters["\\MPexponent{%s}{%s}"] + function metapost.svformat(fmt,str) + format_string(fmt,metapost.untagvariable(str,false)) + end -local mpformatters = table.setmetatableindex(function(t,k) - local v = formatters[lpegmatch(cleaner,k)] - t[k] = v - return v -end) + function metapost.nvformat(fmt,str) + format_number(fmt,metapost.untagvariable(str,false)) + end -function metapost.texexp(num,bfmt,efmt) - local number = tonumber(num) - if number then - local base, exponent = lpegmatch(enumber,format("%e",number)) - if base and exponent then - if bfmt then - -- base = formatters[lpegmatch(cleaner,bfmt)](base) - base = mpformatters[bfmt](base) - else - base = format("%f",base) - end - if efmt then - -- exponent = formatters[lpegmatch(cleaner,efmt)](exponent) - exponent = mpformatters[efmt](exponent) + local f_exponent = formatters["\\MPexponent{%s}{%s}"] + + -- can be a weak one: mpformatters + + local mpformatters = table.setmetatableindex(function(t,k) + local v = formatters[lpegmatch(cleaner,k)] + t[k] = v + return v + end) + + function metapost.texexp(num,bfmt,efmt) + local number = tonumber(num) + if number then + local base, exponent = lpegmatch(enumber,format("%e",number)) + if base and exponent then + if bfmt then + -- base = formatters[lpegmatch(cleaner,bfmt)](base) + base = mpformatters[bfmt](base) + else + base = format("%f",base) + end + if efmt then + -- exponent = formatters[lpegmatch(cleaner,efmt)](exponent) + exponent = mpformatters[efmt](exponent) + else + exponent = format("%i",exponent) + end + return f_exponent(base,exponent) + elseif bfmt then + -- return formatters[lpegmatch(cleaner,bfmt)](number) + return mpformatters[bfmt](number) else - exponent = format("%i",exponent) + return number end - return f_exponent(base,exponent) - elseif bfmt then - -- return formatters[lpegmatch(cleaner,bfmt)](number) - return mpformatters[bfmt](number) else - return number + return num end - else - return num end -end - --- not in context a namespace - -if _LUAVERSION < 5.2 then - utilities.strings.formatters.add(formatters,"texexp", [[texexp(...)]], "local texexp = metapost.texexp") -else - utilities.strings.formatters.add(formatters,"texexp", [[texexp(...)]], { texexp = metapost.texexp }) -end --- print(string.formatters["%!3.3!texexp!"](10.4345E30)) --- print(string.formatters["%3!texexp!"](10.4345E30,"%2.3f","%2i")) --- print(string.formatters["%2!texexp!"](10.4345E30,"%2.3f")) --- print(string.formatters["%1!texexp!"](10.4345E30)) --- print(string.formatters["%!texexp!"](10.4345E30)) + implement { + name = "metapostformatted", + actions = metapost.svformat, + arguments = { "string", "string" } + } --- local function test(fmt,n) --- logs.report("mp format test","fmt: %s, n: %s, result: %s, \\exponent{%s}{%s}",fmt,n, --- formatters[lpegmatch(cleaner,fmt)](n), --- lpegmatch(enumber,formatters[lpegmatch(cleaner,fmt)](n)) --- ) --- end --- --- test("@j","1e-8") --- test("@j",1e-8) --- test("@j","1e+8") --- test("@j","1e-10") --- test("@j",1e-10) --- test("@j","1e+10") --- test("@j","1e-12") --- test("@j","1e+12") --- test("@j","1e-0") --- test("@j","1e+0") --- test("@j","1") --- test("@j test","1") --- test("@j","-1") --- test("@j","1e-102") --- test("@1.4j","1e+102") --- test("@j","1.2e+102") --- test("@j","1.23e+102") --- test("@j","1.234e+102") + implement { + name = "metapostgraphformat", + actions = metapost.nvformat, + arguments = { "string", "string" } + } -local f_textext = formatters[ [[textext("%s")]] ] -local f_mthtext = formatters[ [[textext("\mathematics{%s}")]] ] -local f_exptext = formatters[ [[textext("\mathematics{%s\times10^{%s}}")]] ] + if _LUAVERSION < 5.2 then + utilities.strings.formatters.add(formatters,"texexp", [[texexp(...)]], "local texexp = metapost.texexp") + else + utilities.strings.formatters.add(formatters,"texexp", [[texexp(...)]], { texexp = metapost.texexp }) + end --- local cleaner = Cs((P("\\")/"\\\\" + P("@@")/"@" + P("@")/"%%" + P(1))^0) + local f_textext = formatters[ [[textext("%s")]] ] + local f_mthtext = formatters[ [[textext("\mathematics{%s}")]] ] + local f_exptext = formatters[ [[textext("\mathematics{%s\times10^{%s}}")]] ] -local mpprint = mp.print + local mpprint = mp.print -function mp.format(fmt,str) -- bah, this overloads mp.format in mlib-lua.lua - fmt = lpegmatch(cleaner,fmt) - mpprint(f_textext(formatters[fmt](metapost.untagvariable(str,false)))) -end + function mp.format(fmt,str) -- bah, this overloads mp.format in mlib-lua.lua + fmt = lpegmatch(cleaner,fmt) + mpprint(f_textext(formatters[fmt](metapost.untagvariable(str,false)))) + end -function mp.formatted(fmt,...) -- svformat - fmt = lpegmatch(cleaner,fmt) - mpprint(f_textext(formatters[fmt](...))) -end + function mp.formatted(fmt,...) -- svformat + fmt = lpegmatch(cleaner,fmt) + mpprint(f_textext(formatters[fmt](...))) + end -function mp.graphformat(fmt,num) -- nvformat - fmt = lpegmatch(cleaner,fmt) - local number = tonumber(num) - if number then - local base, exponent = lpegmatch(enumber,number) - if base and exponent then - mpprint(f_exptext(base,exponent)) + function mp.graphformat(fmt,num) -- nvformat + fmt = lpegmatch(cleaner,fmt) + local number = tonumber(num) + if number then + local base, exponent = lpegmatch(enumber,number) + if base and exponent then + mpprint(f_exptext(base,exponent)) + else + mpprint(f_mthtext(num)) + end else - mpprint(f_mthtext(num)) + mpprint(f_textext(tostring(num))) end - else - mpprint(f_textext(tostring(num))) end + end diff --git a/tex/context/base/mkiv/mlib-ctx.lua b/tex/context/base/mkiv/mlib-ctx.lua index baa08384f..0ff28c1c4 100644 --- a/tex/context/base/mkiv/mlib-ctx.lua +++ b/tex/context/base/mkiv/mlib-ctx.lua @@ -6,9 +6,6 @@ if not modules then modules = { } end modules ['mlib-ctx'] = { license = "see context related readme files", } --- for the moment we have the scanners here but they migh tbe moved to --- the other modules - local type, tostring = type, tostring local format, concat = string.format, table.concat local settings_to_hash = utilities.parsers.settings_to_hash @@ -87,10 +84,6 @@ function metapost.getextensions(instance,state) end end --- function commands.getmpextensions(instance,state) --- context(metapost.getextensions(instance,state)) --- end - implement { name = "setmpextensions", actions = metapost.setextensions, @@ -139,7 +132,7 @@ implement { end } --- metapost.variables = { } -- to be stacked +-- metapost.variables = { } -- to be stacked implement { name = "mprunvar", diff --git a/tex/context/base/mkiv/mlib-int.lua b/tex/context/base/mkiv/mlib-int.lua index 108002929..8db8055f9 100644 --- a/tex/context/base/mkiv/mlib-int.lua +++ b/tex/context/base/mkiv/mlib-int.lua @@ -17,6 +17,8 @@ local mpcolor = attributes.colors.mpcolor local emwidths = fonts.hashes.emwidths local exheights = fonts.hashes.exheights +local mpgetdimen = mp.getdimen + function mp.PaperHeight () mpprint(getdimen("paperheight") *factor) end function mp.PaperWidth () mpprint(getdimen("paperwidth") *factor) end function mp.PrintPaperHeight () mpprint(getdimen("printpaperheight") *factor) end diff --git a/tex/context/base/mkiv/mlib-lua.lua b/tex/context/base/mkiv/mlib-lua.lua index 3406d05db..83c1e49ee 100644 --- a/tex/context/base/mkiv/mlib-lua.lua +++ b/tex/context/base/mkiv/mlib-lua.lua @@ -18,7 +18,7 @@ local concat = table.concat local lpegmatch = lpeg.match local lpegpatterns = lpeg.patterns -local P, S, Ct = lpeg.P, lpeg.S, lpeg.Ct +local P, S, Ct, Cs, Cc, C = lpeg.P, lpeg.S, lpeg.Ct, lpeg.Cs, lpeg.Cc, lpeg.C local report_luarun = logs.reporter("metapost","lua") local report_message = logs.reporter("metapost") @@ -87,7 +87,44 @@ local function mpprint(...) end end -mp.print = mpprint +local r = P('%') / "percent" + + P('"') / "dquote" + + P('\n') / "crlf" + -- + P(' ') / "space" +local a = Cc("&") +local q = Cc('"') +local p = Cs(q * (r * a)^-1 * (a * r * (P(-1) + a) + P(1))^0 * q) + +local function mpvprint(...) -- variable print + for i=1,select("#",...) do + local value = select(i,...) + if value ~= nil then + n = n + 1 + local t = type(value) + if t == "number" then + buffer[n] = f_numeric(value) + elseif t == "string" then + buffer[n] = lpegmatch(p,value) + elseif t == "table" then + local m = #t + if m == 2 then + buffer[n] = f_pair(unpack(t)) + elseif m == 3 then + buffer[n] = f_triplet(unpack(t)) + elseif m == 4 then + buffer[n] = f_quadruple(unpack(t)) + else -- error + buffer[n] = "" + end + else -- boolean or whatever + buffer[n] = tostring(value) + end + end + end +end + +mp.print = mpprint +mp.vprint = mpvprint -- We had this: -- @@ -217,9 +254,11 @@ local function mpquoted(fmt,s,...) if not find(fmt,"%%") then fmt = lpegmatch(replacer,fmt) end - buffer[n] = '"' .. formatters[fmt](s,...) .. '"' + -- buffer[n] = '"' .. formatters[fmt](s,...) .. '"' + buffer[n] = lpegmatch(p,formatters[fmt](s,...)) elseif fmt then - buffer[n] = '"' .. fmt .. '"' + -- buffer[n] = '"' .. fmt .. '"' + buffer[n] = '"' .. lpegmatch(p,fmt) .. '"' else -- something is wrong end @@ -275,24 +314,6 @@ end -- endfor ; -- \stopMPpage --- function metapost.runscript(code) --- local f = loadstring(f_code(code)) --- if f then --- local result = f() --- if result then --- local t = type(result) --- if t == "number" then --- return f_numeric(result) --- elseif t == "string" then --- return result --- else --- return tostring(result) --- end --- end --- end --- return "" --- end - local cache, n = { }, 0 -- todo: when > n then reset cache or make weak function metapost.runscript(code) @@ -340,7 +361,7 @@ function metapost.runscript(code) report_luarun("no result") end else - report_luarun("no result, invalid code") + report_luarun("no result, invalid code: %s",code) end return "" end @@ -650,3 +671,32 @@ do end end + +do +local stores = { } + + function mp.newstore(name) + stores[name] = { } + end + + function mp.disposestore(name) + stores[name] = nil + end + + function mp.tostore(name,key,value) + stores[name][key] = value + end + + function mp.fromstore(name,key) + mp.vprint(stores[name][key]) -- type specific + end + + interfaces.implement { + name = "getMPstored", + arguments = { "string", "string" }, + actions = function(name,key) + context(stores[name][key]) + end + } + +end diff --git a/tex/context/base/mkiv/mlib-pdf.mkiv b/tex/context/base/mkiv/mlib-pdf.mkiv index 5875c7635..2f283ff1a 100644 --- a/tex/context/base/mkiv/mlib-pdf.mkiv +++ b/tex/context/base/mkiv/mlib-pdf.mkiv @@ -31,7 +31,7 @@ \ifdefined\MPbox \else \newbox \MPbox \fi -\def\setMPboundingbox#1#2#3#4% at some point we might pass them as base or scaled points +\unexpanded\def\setMPboundingbox#1#2#3#4% at some point we might pass them as base or scaled points {\global\MPllx #1\onebasepoint \global\MPlly #2\onebasepoint \global\MPurx #3\onebasepoint @@ -39,7 +39,7 @@ \global\MPwidth \dimexpr\MPurx-\MPllx\relax \global\MPheight\dimexpr\MPury-\MPlly\relax} -\def\resetMPboundingbox +\unexpanded\def\resetMPboundingbox {\global\MPwidth \zeropoint \global\MPheight\zeropoint \global\MPllx \zeropoint @@ -47,14 +47,14 @@ \global\MPurx \zeropoint \global\MPury \zeropoint} -\def\repositionMPboxindeed +\unexpanded\def\repositionMPboxindeed {\setbox\MPbox\hpack\bgroup \kern-\MPllx \raise-\MPlly \box\MPbox \egroup} -\def\repositionMPbox +\unexpanded\def\repositionMPbox {\ifzeropt\MPllx \ifzeropt\MPlly % okay @@ -65,7 +65,7 @@ \repositionMPboxindeed \fi} -\def\finalizeMPbox +\unexpanded\def\finalizeMPbox {\repositionMPbox \setbox\MPbox\vpack to \MPheight\bgroup \vfill @@ -76,7 +76,7 @@ \wd\MPbox\MPwidth \ht\MPbox\MPheight} -\def\MPtextext#1#2#3#4#5% beware: we use a different method now (see mlib-pps) +\unexpanded\def\MPtextext#1#2#3#4#5% beware: we use a different method now (see mlib-pps) {\begingroup \setbox\MPbox\hbox{\font\temp=#1\space at #2\onebasepoint \let\c\char \temp #3}% text \MPllx-#4\onebasepoint @@ -88,9 +88,9 @@ % MPLIB specific: -\def\MPLIBtoPDF{\clf_mpflushliteral} +\def\MPLIBtoPDF{\clf_mpflushliteral} % expanded -\def\startMPLIBtoPDF#1#2#3#4% +\unexpanded\def\startMPLIBtoPDF#1#2#3#4% {\meta_process_graphic_figure_start \dostarttagged\t!mpgraphic\empty \naturalhpack attr \imageattribute \plusone \bgroup @@ -100,7 +100,7 @@ % \forgetall % already done elsewhere \noindent} % forces the proper cm in the backend -\def\stopMPLIBtoPDF +\unexpanded\def\stopMPLIBtoPDF {\egroup \finalizeMPbox \box\MPbox @@ -128,8 +128,8 @@ \let\normalstartMPLIBtoPDF\startMPLIBtoPDF \let\normalstopMPLIBtoPDF \stopMPLIBtoPDF -\def\directstartMPLIBtoPDF{\startTEXpage\normalstartMPLIBtoPDF} -\def\directstopMPLIBtoPDF {\normalstopMPLIBtoPDF\stopTEXpage} +\unexpanded\def\directstartMPLIBtoPDF{\startTEXpage\normalstartMPLIBtoPDF} +\unexpanded\def\directstopMPLIBtoPDF {\normalstopMPLIBtoPDF\stopTEXpage} \unexpanded\def\directMPgraphic {\dodoublegroupempty\mlib_direct_graphic} diff --git a/tex/context/base/mkiv/mult-fun.lua b/tex/context/base/mkiv/mult-fun.lua index df127eb5c..dc0a0366a 100644 --- a/tex/context/base/mkiv/mult-fun.lua +++ b/tex/context/base/mkiv/mult-fun.lua @@ -19,7 +19,8 @@ return { "crossingscale", "crossingoption", }, commands = { - "loadmodule", "dispose", "nothing", "transparency", "tolist", "topath", "tocycle", + "loadfile", "loadimage", "loadmodule", + "dispose", "nothing", "transparency", "tolist", "topath", "tocycle", -- "sqr", "log", "ln", "exp", "inv", "pow", "pi", "radian", "tand", "cotd", "sin", "cos", "tan", "cot", "atan", "asin", "acos", diff --git a/tex/context/base/mkiv/node-aux.lua b/tex/context/base/mkiv/node-aux.lua index 7643e5e15..84567068b 100644 --- a/tex/context/base/mkiv/node-aux.lua +++ b/tex/context/base/mkiv/node-aux.lua @@ -35,7 +35,6 @@ local getlist = nuts.getlist local getfont = nuts.getfont local getchar = nuts.getchar local getattr = nuts.getattr -local getfield = nuts.getfield local getboth = nuts.getboth local getcomponents = nuts.getcomponents local getwidth = nuts.getwidth diff --git a/tex/context/base/mkiv/node-nut.lua b/tex/context/base/mkiv/node-nut.lua index cbfd43f14..b0730526b 100644 --- a/tex/context/base/mkiv/node-nut.lua +++ b/tex/context/base/mkiv/node-nut.lua @@ -224,6 +224,14 @@ nodes.tonut = tonut -- helpers +if not direct.getfam then + local getfield = direct.getfield + local setfield = direct.setfield + + direct.getfam = function(n,f) getfield(n,"small_fam",f) end + direct.setfam = function(n,f) setfield(n,"small_fam",f) end +end + nuts.tostring = direct.tostring nuts.copy = direct.copy nuts.copy_node = direct.copy @@ -336,6 +344,8 @@ nuts.getchar = direct.getchar nuts.setchar = direct.setchar nuts.getfont = direct.getfont nuts.setfont = direct.setfont +nuts.getfam = direct.getfam +nuts.setfam = direct.setfam nuts.getboth = direct.getboth nuts.setboth = direct.setboth diff --git a/tex/context/base/mkiv/node-res.lua b/tex/context/base/mkiv/node-res.lua index d6f988e0b..375719eb7 100644 --- a/tex/context/base/mkiv/node-res.lua +++ b/tex/context/base/mkiv/node-res.lua @@ -69,7 +69,6 @@ local tonut = nuts.tonut local tonode = nuts.tonode local getbox = nuts.getbox -local getfield = nuts.getfield local getid = nuts.getid local getlist = nuts.getlist local getglue = nuts.getglue diff --git a/tex/context/base/mkiv/publ-imp-apa.mkvi b/tex/context/base/mkiv/publ-imp-apa.mkvi index 0a166576d..6cf79fe49 100644 --- a/tex/context/base/mkiv/publ-imp-apa.mkvi +++ b/tex/context/base/mkiv/publ-imp-apa.mkvi @@ -673,7 +673,7 @@ % used in publ-imp-page.mkvi -\startsetups [btx:apa:list:page-or-pages] +\startsetups btx:apa:list:page-or-pages \ifx\currentbtxlastpage\empty \btxlabeltext{p} \else diff --git a/tex/context/base/mkiv/spac-ver.lua b/tex/context/base/mkiv/spac-ver.lua index cafab12ad..0146b1178 100644 --- a/tex/context/base/mkiv/spac-ver.lua +++ b/tex/context/base/mkiv/spac-ver.lua @@ -118,7 +118,6 @@ local nuts = nodes.nuts local tonode = nuts.tonode local tonut = nuts.tonut -local getfield = nuts.getfield local getnext = nuts.getnext local setlink = nuts.setlink local getprev = nuts.getprev diff --git a/tex/context/base/mkiv/status-files.pdf b/tex/context/base/mkiv/status-files.pdf Binary files differindex 6927d71f2..92cff15e3 100644 --- a/tex/context/base/mkiv/status-files.pdf +++ b/tex/context/base/mkiv/status-files.pdf diff --git a/tex/context/base/mkiv/status-lua.pdf b/tex/context/base/mkiv/status-lua.pdf Binary files differindex 8e423d993..9d368f7b8 100644 --- a/tex/context/base/mkiv/status-lua.pdf +++ b/tex/context/base/mkiv/status-lua.pdf diff --git a/tex/context/base/mkiv/tabl-xtb.lua b/tex/context/base/mkiv/tabl-xtb.lua index 1f4ba4a14..0835576c7 100644 --- a/tex/context/base/mkiv/tabl-xtb.lua +++ b/tex/context/base/mkiv/tabl-xtb.lua @@ -66,7 +66,6 @@ local getnext = nuts.getnext local getprev = nuts.getprev local getlist = nuts.getlist local getwidth = nuts.getwidth -local getfield = nuts.getfield local getbox = nuts.getbox local getwhd = nuts.getwhd @@ -909,7 +908,7 @@ function xtables.construct() texsetdimen("global","d_tabl_x_final_width",0) else texsetcount("global","c_tabl_x_state",1) - texsetdimen("global","d_tabl_x_final_width",getfield(body[1][1],"width")) -- why not: getfield(body[1][1]) + texsetdimen("global","d_tabl_x_final_width",getwidth(body[1][1])) end end diff --git a/tex/context/interface/mkii/keys-en.xml b/tex/context/interface/mkii/keys-en.xml index 3add761bc..3ac165945 100644 --- a/tex/context/interface/mkii/keys-en.xml +++ b/tex/context/interface/mkii/keys-en.xml @@ -802,6 +802,7 @@ <cd:constant name='fieldoffset' value='fieldoffset'/> <cd:constant name='file' value='file'/> <cd:constant name='filler' value='filler'/> + <cd:constant name='filter' value='filter'/> <cd:constant name='filtercommand' value='filtercommand'/> <cd:constant name='finalnamesep' value='finalnamesep'/> <cd:constant name='finalpagesep' value='finalpagesep'/> @@ -1156,6 +1157,7 @@ <cd:constant name='sidemethod' value='sidemethod'/> <cd:constant name='sidespaceafter' value='sidespaceafter'/> <cd:constant name='sidespacebefore' value='sidespacebefore'/> + <cd:constant name='sidethreshold' value='sidethreshold'/> <cd:constant name='sign' value='sign'/> <cd:constant name='size' value='size'/> <cd:constant name='slantedfeatures' value='slantedfeatures'/> diff --git a/tex/context/interface/mkii/keys-nl.xml b/tex/context/interface/mkii/keys-nl.xml index 22b32e372..8cef8ca55 100644 --- a/tex/context/interface/mkii/keys-nl.xml +++ b/tex/context/interface/mkii/keys-nl.xml @@ -802,6 +802,7 @@ <cd:constant name='fieldoffset' value='veldoffset'/> <cd:constant name='file' value='file'/> <cd:constant name='filler' value='filler'/> + <cd:constant name='filter' value='filter'/> <cd:constant name='filtercommand' value='filtercommand'/> <cd:constant name='finalnamesep' value='finalnamesep'/> <cd:constant name='finalpagesep' value='finalpagesep'/> @@ -1156,6 +1157,7 @@ <cd:constant name='sidemethod' value='zijmethode'/> <cd:constant name='sidespaceafter' value='zijnawit'/> <cd:constant name='sidespacebefore' value='zijvoorwit'/> + <cd:constant name='sidethreshold' value='sidethreshold'/> <cd:constant name='sign' value='teken'/> <cd:constant name='size' value='formaat'/> <cd:constant name='slantedfeatures' value='slantedfeatures'/> diff --git a/tex/context/interface/mkiv/i-context.pdf b/tex/context/interface/mkiv/i-context.pdf Binary files differindex b9522e0b8..10eb9ef10 100644 --- a/tex/context/interface/mkiv/i-context.pdf +++ b/tex/context/interface/mkiv/i-context.pdf diff --git a/tex/context/interface/mkiv/i-readme.pdf b/tex/context/interface/mkiv/i-readme.pdf Binary files differindex ee51a22b9..8550ad0ae 100644 --- a/tex/context/interface/mkiv/i-readme.pdf +++ b/tex/context/interface/mkiv/i-readme.pdf diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index b23b4ef0a..8137842b5 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 : c:/data/develop/context/sources/luatex-fonts-merged.lua -- parent file : c:/data/develop/context/sources/luatex-fonts.lua --- merge date : 10/19/17 13:50:13 +-- merge date : 10/24/17 10:30:41 do -- begin closure to overcome local limits and interference |