diff options
Diffstat (limited to 'Master/texmf-dist/tex/luatex')
-rw-r--r-- | Master/texmf-dist/tex/luatex/luamplib/luamplib.lua | 124 | ||||
-rw-r--r-- | Master/texmf-dist/tex/luatex/luamplib/luamplib.sty | 2 |
2 files changed, 83 insertions, 43 deletions
diff --git a/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua b/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua index 06286a01214..afc21674267 100644 --- a/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua +++ b/Master/texmf-dist/tex/luatex/luamplib/luamplib.lua @@ -11,8 +11,8 @@ luatexbase.provides_module { name = "luamplib", - version = "2.26.4", - date = "2024/03/10", + version = "2.27.0", + date = "2024/03/23", description = "Lua package to typeset Metapost with LuaTeX's MPLib.", } @@ -345,8 +345,9 @@ end luamplib.codeinherit = false local mplibinstances = {} +local instancename -local function process (data, instancename) +local function process (data) local defaultinstancename = currentformat .. (luamplib.numbersystem or "scaled") .. tostring(luamplib.textextlabel) .. tostring(luamplib.legacy_verbatimtex) local currfmt = instancename or defaultinstancename @@ -376,7 +377,10 @@ local function run_tex_code (str, cat) texruntoks(function() texsprint(cat, str) end) end -local tex_box_id = 2047 +local texboxes = { + locals = {}, localid = 4096, + globals = {}, globalid = 0, +} local factor = 65536*(7227/7200) local textext_fmt = [[image(addto currentpicture doublepath unitsquare ]].. @@ -385,10 +389,32 @@ local textext_fmt = [[image(addto currentpicture doublepath unitsquare ]].. local function process_tex_text (str) if str then - tex_box_id = tex_box_id + 1 - local global = luamplib.globaltextext and "\\global" or "" - run_tex_code(format("%s\\setbox%i\\hbox{%s}", global, tex_box_id, str)) - local box = texgetbox(tex_box_id) + local boxtable, global + if instancename and instancename ~= "" then + texboxes[instancename] = texboxes[instancename] or {} + boxtable, global = texboxes[instancename], "\\global" + elseif luamplib.globaltextext or luamplib.codeinherit then + boxtable, global = texboxes.globals, "\\global" + else + boxtable, global = texboxes.locals, "" + end + local tex_box_id = boxtable[str] + local box = tex_box_id and texgetbox(tex_box_id) + if not box then + if global == "" then + tex_box_id = texboxes.localid + 1 + texboxes.localid = tex_box_id + else + local boxid = texboxes.globalid + 1 + texboxes.globalid = boxid + run_tex_code(format( + [[\expandafter\newbox\csname luamplib.box.%s\endcsname]], boxid)) + tex_box_id = tex.getcount'allocationnumber' + end + boxtable[str] = tex_box_id + run_tex_code(format("%s\\setbox%i\\hbox{%s}", global, tex_box_id, str)) + box = texgetbox(tex_box_id) + end local wd = box.width / factor local ht = box.height / factor local dp = box.depth / factor @@ -692,7 +718,10 @@ end luamplib.everymplib = { [""] = "" } luamplib.everyendmplib = { [""] = "" } -local function process_mplibcode (data, instancename) +local function process_mplibcode (data, instance) + instancename = instance + texboxes.localid = 4096 + legacy_mplibcode_reset() local everymplib = luamplib.everymplib[instancename] or @@ -736,7 +765,7 @@ local function process_mplibcode (data, instancename) end) end - process(data, instancename) + process(data) end luamplib.process_mplibcode = process_mplibcode @@ -920,7 +949,7 @@ local pdfmanagement = is_defined'pdfmanagement_add:nnn' local pdf_objs = {} local getpageres, setpageres -local pgf = { bye = "pgfutil@everybye", extgs = "pgf@sys@addpdfresource@extgs@plain" } +local pgf = { extgs = "pgf@sys@addpdfresource@extgs@plain" } if pdfmode then getpageres = pdf.getpageresources or function() return pdf.pageresources end @@ -939,6 +968,7 @@ local function update_pdfobjs (os) on = pdf.immediateobj(os) else on = pdf_objs.cnt or 0 + texsprint(format("\\special{pdf:obj @mplibpdfobj%s %s}",on,os)) pdf_objs.cnt = on + 1 end pdf_objs[os] = on @@ -960,20 +990,36 @@ local function update_tr_res(res,mode,opaq) if pdfmode then if pdfmanagement then texsprint(ccexplat,format( - [[\pdfmanagement_add:nnn{Page/Resources/ExtGState}{MPlibTr%s}{%s 0 R}]], - on,on)) + [[\pdfmanagement_add:nnn{Page/Resources/ExtGState}{MPlibTr%s}{%s 0 R}]], on,on)) else - res = format("%s/MPlibTr%i %i 0 R",res,on,on) + local tr = format("/MPlibTr%s %s 0 R",on,on) + if pgf.loaded then + texsprint(format("\\csname %s\\endcsname{%s}", pgf.extgs,tr)) + elseif is_defined"TRP@list" then + texsprint(catat11,{ + [[\if@filesw\immediate\write\@auxout{]], + [[\string\g@addto@macro\string\TRP@list{]], + tr, + [[}}\fi]], + }) + if not token.get_macro"TRP@list":find(tr) then + texsprint(catat11,[[\global\TRP@reruntrue]]) + end + else + res = res..tr + end end else if pdfmanagement then texsprint(ccexplat,format( - [[\pdfmanagement_add:nnn{Page/Resources/ExtGState}{MPlibTr%s}{%s}]], - on,os)) - elseif pgf.loaded then - texsprint(format("\\csname %s\\endcsname{/MPlibTr%i%s}", pgf.extgs, on, os)) + [[\pdfmanagement_add:nnn{Page/Resources/ExtGState}{MPlibTr%s}{@mplibpdfobj%s}]], on,on)) else - texsprint(format("\\special{pdf:put @MPlibTr<</MPlibTr%i%s>>}",on,os)) + local tr = format("/MPlibTr%s @mplibpdfobj%s",on,on) + if pgf.loaded then + texsprint(format("\\csname %s\\endcsname{%s}", pgf.extgs,tr)) + else + texsprint(format("\\special{pdf:put @MPlibTr<<%s>>}",tr)) + end end end end @@ -981,31 +1027,26 @@ local function update_tr_res(res,mode,opaq) end local function tr_pdf_pageresources(mode,opaq) - if not pgf.loaded and pgf.bye then - pgf.loaded = is_defined(pgf.bye) - pgf.bye = pgf.loaded and pgf.bye + if pgf.loaded == nil then + pgf.loaded = is_defined(pgf.extgs) end local res, on_on, off_on = "", nil, nil res, off_on = update_tr_res(res, "Normal", 1) res, on_on = update_tr_res(res, mode, opaq) - if pdfmanagement then return on_on, off_on end + if pdfmanagement or pgf.loaded or is_defined"TRP@list" then + return on_on, off_on + end if pdfmode then if res ~= "" then - if pgf.loaded then - texsprint(format("\\csname %s\\endcsname{%s}", pgf.extgs, res)) - else - local tpr, n = getpageres() or "", 0 - tpr, n = tpr:gsub("/ExtGState<<", "%1"..res) - if n == 0 then - tpr = format("%s/ExtGState<<%s>>", tpr, res) - end - setpageres(tpr) + local tpr, n = getpageres() or "", 0 + tpr, n = tpr:gsub("/ExtGState<<", "%1"..res) + if n == 0 then + tpr = format("%s/ExtGState<<%s>>", tpr, res) end + setpageres(tpr) end else - if not pgf.loaded then - texsprint(format("\\special{pdf:put @resources<</ExtGState @MPlibTr>>}")) - end + texsprint(format("\\special{pdf:put @resources<</ExtGState @MPlibTr>>}")) end return on_on, off_on end @@ -1028,7 +1069,8 @@ local function sh_pdfpageresources(shtype,domain,colorspace,colora,colorb,coordi if not pdfmanagement and not shading_res then shading_initialize() end local os = format("<</FunctionType 2/Domain [ %s ]/C0 [ %s ]/C1 [ %s ]/N 1>>", domain, colora, colorb) - local funcobj = pdfmode and format("%i 0 R",update_pdfobjs(os)) or os + local funcobj = pdfmode and format("%s 0 R",update_pdfobjs(os)) + or format("@mplibpdfobj%s",update_pdfobjs(os)) os = format("<</ShadingType %i/ColorSpace /%s/Function %s/Coords [ %s ]/Extend [ true true ]/AntiAlias true>>", shtype, colorspace, funcobj, coordinates) local on, new = update_pdfobjs(os) @@ -1036,10 +1078,9 @@ local function sh_pdfpageresources(shtype,domain,colorspace,colora,colorb,coordi if new then if pdfmanagement then texsprint(ccexplat,format( - [[\pdfmanagement_add:nnn{Page/Resources/Shading}{MPlibSh%s}{%s 0 R}]], - on,on)) + [[\pdfmanagement_add:nnn{Page/Resources/Shading}{MPlibSh%s}{%s 0 R}]], on,on)) else - local res = format("/MPlibSh%i %i 0 R", on, on) + local res = format("/MPlibSh%s %s 0 R", on, on) if pdf_objs.finishpdf then shading_res[#shading_res+1] = res else @@ -1056,12 +1097,11 @@ local function sh_pdfpageresources(shtype,domain,colorspace,colora,colorb,coordi if pdfmanagement then if new then texsprint(ccexplat,format( - [[\pdfmanagement_add:nnn{Page/Resources/Shading}{MPlibSh%s}{%s}]], - on,os)) + [[\pdfmanagement_add:nnn{Page/Resources/Shading}{MPlibSh%s}{@mplibpdfobj%s}]], on,on)) end else if new then - texsprint(format("\\special{pdf:put @MPlibSh<</MPlibSh%i%s>>}",on,os)) + texsprint(format("\\special{pdf:put @MPlibSh<</MPlibSh%s @mplibpdfobj%s>>}",on,on)) end texsprint(format("\\special{pdf:put @resources<</Shading @MPlibSh>>}")) end diff --git a/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty b/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty index 4f53ce04170..7bb410bf6a9 100644 --- a/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty +++ b/Master/texmf-dist/tex/luatex/luamplib/luamplib.sty @@ -14,7 +14,7 @@ \else \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{luamplib} - [2024/03/10 v2.26.4 mplib package for LuaTeX] + [2024/03/23 v2.27.0 mplib package for LuaTeX] \ifx\newluafunction\@undefined \input ltluatex \fi |