diff options
author | Karl Berry <karl@freefriends.org> | 2024-04-03 21:16:31 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2024-04-03 21:16:31 +0000 |
commit | f07a9a1c37bc288c1d2190f26e5c8d2fb3f4377e (patch) | |
tree | bf8499d580ac3166f9bd163a39c4f5ca4be53cc4 /Master/texmf-dist/tex | |
parent | 148feef62ceba4b97b71ec71cc01b77a35d48c93 (diff) |
minim-mp (3apr24)
git-svn-id: svn://tug.org/texlive/trunk@70847 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/luatex/minim-mp/minim-mp.ini | 2 | ||||
-rw-r--r-- | Master/texmf-dist/tex/luatex/minim-mp/minim-mp.lua | 213 | ||||
-rw-r--r-- | Master/texmf-dist/tex/luatex/minim-mp/minim-mp.sty | 50 | ||||
-rw-r--r-- | Master/texmf-dist/tex/luatex/minim-mp/minim-mp.tex | 82 |
4 files changed, 248 insertions, 99 deletions
diff --git a/Master/texmf-dist/tex/luatex/minim-mp/minim-mp.ini b/Master/texmf-dist/tex/luatex/minim-mp/minim-mp.ini index 11387e00d12..0f628354424 100644 --- a/Master/texmf-dist/tex/luatex/minim-mp/minim-mp.ini +++ b/Master/texmf-dist/tex/luatex/minim-mp/minim-mp.ini @@ -1,7 +1,7 @@ \catcode`\{=1 \catcode`\}=2 \def\fmtname{minim-mp} -\def\fmtversion{2023/1.3} +\def\fmtversion{2024/1.6} \input minim.ini diff --git a/Master/texmf-dist/tex/luatex/minim-mp/minim-mp.lua b/Master/texmf-dist/tex/luatex/minim-mp/minim-mp.lua index fba65732396..885a6941e48 100644 --- a/Master/texmf-dist/tex/luatex/minim-mp/minim-mp.lua +++ b/Master/texmf-dist/tex/luatex/minim-mp/minim-mp.lua @@ -102,6 +102,14 @@ function M.enable_debugging() end E.enable_debugging = M.enable_debugging +alloc.luadef('debugmetapost', M.enable_debugging) + +local function debug(...) + if debugging then + alloc.log(...) + end +end + local function print_prop(append, obj, prop) if obj[prop] then local val = string.gsub(tostring(obj[prop]), '\r', '<CR>') @@ -136,9 +144,8 @@ local function print_knots(append, obj, ptype) end function A.printobj(append, obj) - if not debugging then return end local nc = append.node_count - append:literal('%%Object Type: %s', obj.type) + append:literal('%% Object Type: %s', obj.type) print_prop(append, obj, 'text') print_prop(append, obj, 'font') print_prop(append, obj, 'dsize') @@ -151,16 +158,16 @@ function A.printobj(append, obj) print_knots(append, obj, 'htap') if obj.pen then local x = obj.pen.type or 'not elliptical' - append:literal('%% pen: see below, form: %s', x) + append:literal('%% pen is %s', x) x = mplib.pen_info(obj) - append:literal('%% | width: %s', tostring(x.width)) - append:literal('%% | sx: %s', tostring(x.sx)) - append:literal('%% | sy: %s', tostring(x.sy)) - append:literal('%% | rx: %s', tostring(x.rx)) - append:literal('%% | ry: %s', tostring(x.ry)) - append:literal('%% | tx: %s', tostring(x.tx)) - append:literal('%% | ty: %s', tostring(x.ty)) - print_knots(append, obj, 'pen') + append:literal('%% width: %s', tostring(x.width)) + append:literal('%% sx: %s', tostring(x.sx)) + append:literal('%% sy: %s', tostring(x.sy)) + append:literal('%% rx: %s', tostring(x.rx)) + append:literal('%% ry: %s', tostring(x.ry)) + append:literal('%% tx: %s', tostring(x.tx)) + append:literal('%% ty: %s', tostring(x.ty)) + print_knots(append, obj, 'pen path') end if obj.dash then local d = '' @@ -420,7 +427,9 @@ function A.linestate (append, object) append.dashed = false table.insert(res, '[] 0 d') end - append:literal(table.concat(res, ' ')) + if #res > 0 then + append:literal(table.concat(res, ' ')) + end end --2 path literals @@ -482,7 +491,7 @@ function A.curve(append, path, open, concat) elseif #path == 1 then append_line(path[1], 'l') -- special case: draw a point end - append:literal(table.concat(res, ' ')) + append:literal(table.concat(res, '\n')) end -- And actually draw the path. @@ -556,7 +565,9 @@ end local function parse_object(append, object) append.object_info = { } - append:printobj(object) + if debugging then + append:printobj(object) + end local processor = nil for sp, instr in split_specials(object.prescript) do if not sp then @@ -1018,8 +1029,8 @@ M.instances = instances -- parameters: wd, ht+dp, dp local function make_transform(w, h, d) - return string.format('identity xscaled %fpt yscaled %fpt shifted (0,-%fpt)', - w/65536, (h+d)/65536, d/65536) + return string.format('identity xscaled %fpt yscaled %fpt shifted (0,%fpt)', + w/65536, (h+d)/65536, -d/65536) end local status_names = { [0] = 'good', 'warning', 'error', 'fatal' } @@ -1028,16 +1039,19 @@ local function print_status(st) end M.on_line = false +M.max_errprint = 1 local function print_log (nr, res, why) local i = instances[nr] -- only write to term if on_line or if exit status increases - local log, alog + local log, alog --luacheck:ignore 231 if M.on_line or res.status > i.status then - local nrlines, maxlines = 0, 16 alog = alloc.amsg + local nr_errs = 0 log = function(...) - if M.on_line or nrlines < maxlines then - nrlines = nrlines + 1 + if string.sub(table.pack(...)[2],1,2) == "! " then + nr_errs = nr_errs + 1 + end + if M.max_errprint < 1 or M.max_errprint >= nr_errs then alloc.msg(...) else alloc.log(...) @@ -1050,17 +1064,18 @@ local function print_log (nr, res, why) end -- split log into lines; discard empty lines at the end local report = res.log and res.log:explode('\n') or { } - while report[#report] == '' do - report[#report] = nil - end -- write out the log - log('┌ %smetapost instance %s (%d)', why or '', i.jobname, i.nr) + log('┌ %smetapost instance {%s} (%d)', why or '', i.jobname, i.nr) for _,line in ipairs(report) do - log('│ %s', line) + if line ~= '' and line ~= "(Please type a command or say `end')" then + log('│ %s', line) + end end log('└ %s', print_status(res.status)) -- generate error or warning if needed if res.status > i.status then + local ecl = tex.errorcontextlines -- TODO: why does TeX fill the error context + tex.errorcontextlines = 0 -- with repeated <inserted text> BAD ??? if res.status == 3 then alloc.err('Metapost instance now defunct') elseif res.status == 2 then @@ -1068,6 +1083,7 @@ local function print_log (nr, res, why) elseif res.status == 1 then alloc.msg('Metapost code caused warning') end + tex.errorcontextlines = ecl end -- save the exit status for later comparison i.status = res.status @@ -1107,6 +1123,9 @@ local function process_results(nr, res) local fig = res.fig[i] local name = fig:filename() local append = init_append() + if debugging then + append:literal('%% START OF MP FIGURE %s (instance %d)', name, nr) + end -- parse and append all objects append:save() local objects = fig:objects() @@ -1114,6 +1133,9 @@ local function process_results(nr, res) parse_object (append, objects[j]) end append:restore() + if debugging then + append:literal('%% END OF MP FIGURE %s (instance %d)', name, nr) + end -- bounding box and baseline information local bb = fig:boundingbox() local llx, lly, urx, ury = table.unpack(bb) @@ -1174,12 +1196,19 @@ end -- change in the future.) local function mkluastring(s) - return "'"..(s:gsub('\\', '\\\\'):gsub("'", "\\'"):gsub('\n', '\\n')).."'" + return "'"..(s + :gsub('\\', '\\\\') + :gsub("'", "\\'") + :gsub('\n', '\\n') + :gsub('\013', '\\r') + :gsub('\000', '\\000') + ).."'" end local function runscript(code) + debug('┌ runscript: %s', code) -- (possibly) pass directly to function - local fn, arg = code:match('^%[%[(.+)%]%](.*)') + local fn, arg = code:match('^%[%[(.-)%]%](.*)') if fn then code = 'return '..fn .. mkluastring(arg) end -- execute the script local f, msg = load(code, current_instance.jobname, 't', current_instance.env) @@ -1187,32 +1216,39 @@ local function runscript(code) if f then local result = f() if result == nil then + debug('└ (no return value)') return else local t = type(result) if t == 'number' then - return string.format('%.16f', result) + result = string.format('%.16f', result) elseif t == 'string' then - return result + result = result elseif t == 'table' and result[1] == 'box_size' then - return make_transform(result[2], result[3], result[4]) + result = make_transform(result[2], result[3], result[4]) elseif t == 'table' and #result < 5 then local fmt = #result == 1 and '%.16f' or #result == 2 and '(%.16f, %.16f)' or #result == 3 and '(%.16f, %.16f, %.16f)' or #result == 4 and '(%.16f, %.16f, %.16f, %.16f)' - return fmt:format(table.unpack(result)) + result = fmt:format(table.unpack(result)) elseif t == 'table' and #result == 6 then - return table.concat({ - 'begingroup save t; transform t;', + result = table.concat({ + 'begingroup save t; transform t', 'xxpart t = %.16f', 'xypart t = %.16f', 'yxpart t = %.16f', 'yypart t = %.16f', 'xpart t = %.16f', 'ypart t = %.16f', 't endgroup' }, ';'):format(table.unpack(result)) else - return tostring(result) + result = tostring(result) end + if #result > 120 then + debug('└ %s etc. etc.', result:sub(1,110)) + else + debug('└ %s', result) + end + return result end else local mp_msg = string.gsub(msg, '"', '"&ditto&"') @@ -1257,7 +1293,8 @@ E.catcodes = { numbers = , vrbcatcodes = cct_maketext , prtcatcodes = cct_maketext , ctxcatcodes = cct_maketext , txtcatcodes = cct_maketext } } -E.mp = mp or { } -- all seem nonessential +E.mp = mp or { } --luacheck: ignore 113 +-- all functions below seem nonessential E.mp.mf_path_reset = E.mp.mf_path_reset or function() end E.mp.mf_finish_saving_data = E.mp.mf_finish_saving_data or function() end E.mp.report = E.mp.report or function() end @@ -1283,19 +1320,51 @@ E.mp.report = E.mp.report or function() end local function maketext(text, mode) if mode == 0 then -- btex or maketext local nr = alloc.new_box() + debug('┌ btex: %s', text) table.insert(current_instance.boxes, nr) local assignment = string.format('\\global\\setbox%s=\\hbox{\\the\\everymaketext %s}', nr, text) tex.runtoks(function() tex.print(current_instance.catcodes, assignment:explode('\n')) end) local box = tex.box[nr] + debug('└ etex: box %d', nr) return string.format('_set_maketext_result_(%d, %s)', nr, make_transform(box.width, box.height, box.depth)) elseif mode == 1 then -- verbatimtex + debug('┌ verbatimtex: %s', text) tex.runtoks(function() tex.print(current_instance.catcodes, text:explode('\n')) end) + debug('└ etex') + end +end + +-- a font cache for infont and glyph of +local infont_fonts = { } +local function get_infont_font(fnt) + local csname = 'minim-mp infont '..fnt + local res = infont_fonts[csname] + if res then + debug('├ resolved font "%s" (%d)', fnt, res) + else + tex.runtoks(function() + tex.print(current_instance.catcodes, string.format( + '\\expandafter\\font\\csname %s\\endcsname={%s}\\relax', csname, fnt)) + end) + res = font.id(csname) + infont_fonts[csname] = res + debug('├ loaded font "%s" (%d)', fnt, res) end + return res +end + +local function fontid_from_csname(fnt) + local id = font.id(fnt) + if id < 0 then return end + debug('├ resolved font \\%s (%d)', fnt, id) + return id end local function getfontid(fnt) - return tonumber(fnt) or font.id(fnt) + return tonumber(fnt) + or fontid_from_csname(fnt) + or get_infont_font(fnt) end local typeset_box = alloc.new_box('infont box') @@ -1377,17 +1446,23 @@ function M.make_glyph(glyphname, fnt) end local function get_glyphname(c_id) - return luaotfload.aux.name_of_slot(c_id) + if type(c_id) == 'string' then return c_id end + local res = luaotfload.aux.name_of_slot(c_id) + debug('├ name of glyph %d is %s', c_id, res) + return res end function E.get_glyph(c_id, fnt) - local name = (type(c_id) == 'string') and c_id or get_glyphname(c_id) + debug('┌ glyph %s of %s', c_id, fnt) + local name = get_glyphname(c_id) local contours, size = M.make_glyph(name, fnt) local res = { } for _, c in ipairs(contours) do - table.insert(res, string.format( - '%s scaled %f', c, size/65536/1000)) + local scaled = string.format('%s scaled %f', c, size/65536/1000) + debug('│ %s', scaled) + table.insert(res, scaled) end + debug('└ %d contours returned', #res) return table.concat(res, ', ') end @@ -1419,7 +1494,7 @@ local function apply_default_instance_opts(t) --, script_error = ... , job_name = t.jobname , math_mode = t.mathmode or t.math or M.default_mathmode - , random_seed = t.seed or nil + , random_seed = t.randomseed or t.seed or nil -- , file_line_error_style , make_text = maketext , run_script = runscript @@ -1451,7 +1526,17 @@ function M.run (nr, code) return end current_instance = self + if debugging then + alloc.log('┌ metapost chunk for {%s} (%d)', self.jobname, nr) + for _, line in ipairs(code:explode('\013')) do + alloc.log('│ %s', line) + end + alloc.log('└') + end + local cct = tex.catcodetable + tex.catcodetable = self.catcodes local res = self.instance:execute(code) + tex.catcodetable = cct print_log(nr, res) local picts = process_results(nr, res) save_image_list(self, picts) @@ -1460,17 +1545,19 @@ end M.init_code = { 'let dump=endinput;' , 'boolean mplib; mplib:=true;' , 'input INIT;' - , 'input minim-mp.mp;' - , 'input minim.mp;' } + , 'input minim.mp;' + , 'input minim-mp.mp;' } local maketext_catcodes = alloc.registernumber('minim:mp:catcodes:maketext') function M.open (t) local nr = #instances + 1 - t.jobname = t.jobname or ':metapost:' + tex.count['mp:cur:inst'] = nr -- creating instance options + t.jobname = t.jobname or ':metapost:' local init = string.gsub(table.concat(M.init_code, ''), 'INIT', t.format or M.default_format) local opts = apply_default_instance_opts(t) local instance = mplib.new(opts) + tex.runtoks 'mp:init:env' -- adding the instance instances[nr] = { nr = nr @@ -1484,11 +1571,13 @@ function M.open (t) } current_instance = instances[nr] print_log(nr, instance:execute(init), 'opening ') + tex.count['mp:cur:inst'] = -1 return nr end function M.close (nr) local i = instances[nr] + tex.count['mp:cur:inst'] = nr if i.instance then local res = i.instance:finish() print_log(nr, res, 'closing ') @@ -1498,6 +1587,7 @@ function M.close (nr) tex.box[b] = nil end instances[nr] = false + tex.count['mp:cur:inst'] = -1 end --2 retrieving and using results @@ -1569,25 +1659,30 @@ end local scan_int = token.scan_int local scan_string = token.scan_string +alloc.luadef('closemetapostinstance', function() M.close(scan_int()) end) + local code_catcodes = alloc.registernumber('minim:mp:catcodes:mpcode') -local function scan_codestring() + +alloc.luadef('runmetapost', function() + local id = scan_int() + tex.count['mp:cur:inst'] = id + -- run tex code before + tex.runtoks 'mp:inst:pre:tex' + -- scan the argument with inert catcodes local cct = tex.catcodetable tex.catcodetable = code_catcodes - local res = token.scan_string() + token.scan_keyword '\013' -- ^^M has catcode 12 now + local code = token.scan_string() tex.catcodetable = cct - return res -end - -alloc.luadef('closemetapostinstance', function() M.close(scan_int()) end) - -alloc.luadef('runmetapost', function() - M.run(scan_int(), scan_codestring()) -end, 'protected') -alloc.luadef('runmetapostimage', function() - local i = scan_int() - local code = 'beginfig(0)'..scan_codestring()..';endfig;' - M.run(i, code) - node.write(M.get_image(i)) + -- prepare the argument further + tex.toks['mp:mpcode'] = code + tex.runtoks 'mp:makempcode' + code = tex.toks['mp:mpcode'] + -- run the code + M.run(id, code) + -- run tech code after + tex.runtoks 'mp:inst:post:tex' + tex.count['mp:cur:inst'] = -1 end, 'protected') alloc.luadef('getnextmpimage', function() diff --git a/Master/texmf-dist/tex/luatex/minim-mp/minim-mp.sty b/Master/texmf-dist/tex/luatex/minim-mp/minim-mp.sty index 6240c80b9a4..948c6034b71 100644 --- a/Master/texmf-dist/tex/luatex/minim-mp/minim-mp.sty +++ b/Master/texmf-dist/tex/luatex/minim-mp/minim-mp.sty @@ -11,35 +11,35 @@ \def\mnm@setnormalfont{{\normalfont \xdef\mnm@normalfont{\expandafter\csstring\the\font}}} -% a one-off metapost environment -\newenvironment{metapost}[1][]{% - \begingroup \catcode`\#=12 - \let\mpcolor = \minimpcolor - \csname:metapost:\endcsname[#1]} - {\csname end:metapost:\endcsname \endgroup} -\NewDocumentEnvironment{:metapost:}{O{}+b}{% +% global instance configuration +\everymp0{pre}{mp}{defaultfont:="\mnm@normalfont";} +\everymp0{pre}{tex}{% \mnm@setnormalfont - \let\protect=\noexpand - \directmetapost[#1]{% - defaultfont:="\mnm@normalfont"; #2; }% - \let\protect=\mnm@protect}{} + \let\mpcolor = \minimpcolor + \let\protect = \noexpand} +\everymp0{post}{tex}{% + \let\protect=\mnm@protect} + +% a one-off metapost environment +\newenvironment{metapost}[1][]{\begingroup + \catcodetable\csname minim:mp:catcodes:mpcode\endcsname + \csname:metapost:\endcsname[#1]} + {\csname end:metapost:\endcsname} +\NewDocumentEnvironment{:metapost:}{O{}+b}{\endgroup + \directmetapost[#1]{#2}}{} % separate metapost instances \newcommand\newmetapostenvironment[2][]{% \newmetapostinstance[#1]\mnm@tmp \expandafter\let\csname #2@instance\endcsname\mnm@tmp - \newenvironment{#2}{% - \begingroup \catcode`\#=12 \catcode`\%=12 - \let\mpcolor = \minimpcolor + \everymp\mnm@tmp{post}{tex}{% + \getallmpimages \csname #2@instance\endcsname} + \newenvironment{#2}{\begingroup + \catcodetable\csname minim:mp:catcodes:mpcode\endcsname \csname:#2:\endcsname} - {\csname end:#2:\endcsname \endgroup}% - \NewDocumentEnvironment{:#2:}{+b}{% - \mnm@setnormalfont - \let\protect=\noexpand - \runmetapostimage - \csname #2@instance\endcsname - {defaultfont:="\mnm@normalfont";##1;}% - \let\protect=\mnm@protect}{}} + {\csname end:#2:\endcsname}% + \NewDocumentEnvironment{:#2:}{+b}{\endgroup + \runmetapost \csname #2@instance\endcsname{##1}}{}} % \mpcolor support \def\minimpcolor#1#{\dominimpcolor{#1}} @@ -58,9 +58,9 @@ require 'minim-mp'.on_line = % \ifcsname minimp@switch@#1\endcsname true \else false \fi }} - \newmetapostenvironment[jobname='\jobname']{@mplibcode} \def\mplibcodeinherit#1{% \ifcsname minimp@switch@#1\endcsname + \newmetapostenvironment[jobname='\jobname']{@mplibcode} \let\mplibcode=\@mplibcode \let\endmplibcode=\@mplibcode \else @@ -72,6 +72,10 @@ require 'minim-mp'.default_format = '#1.mp' }} \def\mplibnumbersystem#1{\directlua{ require 'minim-mp'.default_math = '#1' }} + \newcommand\everymplib[2][0]{% + \everymp{#1}{pre}{mp}{defaultfont:="\mnm@normalfont";#2}} + \newcommand\everyendmplib[2][0]{% + \everymp{#1}{post}{mp}{#2}} } \ProcessOptions* \let\minimp@switch@@enable=\relax diff --git a/Master/texmf-dist/tex/luatex/minim-mp/minim-mp.tex b/Master/texmf-dist/tex/luatex/minim-mp/minim-mp.tex index 7b8cef6c6b5..ddc925ab3a6 100644 --- a/Master/texmf-dist/tex/luatex/minim-mp/minim-mp.tex +++ b/Master/texmf-dist/tex/luatex/minim-mp/minim-mp.tex @@ -1,6 +1,6 @@ \ifdefined\minimmploaded - \message{(skipped)} + \wlog{(skipped)} \expandafter\endinput\fi \chardef\minimmploaded = \catcode`\: \catcode`\: = 11 @@ -14,10 +14,11 @@ \savecatcodetable\csname minim:mp:catcodes:maketext\endcsname} % and an empty catcode table for reading metapost code \newcatcodetable \minim:mp:catcodes:mpcode -{\catcodetable\minim:initcatcodes +{\def\\{}\catcodetable\minim:initcatcodes \catcode`\{=1 \catcode`\}=2 \catcode9=10 + \catcode`\$=12 \catcode`\^=12 \catcode`\_=12 \catcode`\&=12 \catcode`\#=12 \catcode`\%=12 \catcode`\~=12 - \savecatcodetable\csname minim:mp:catcodes:mpcode\endcsname} + \catcode"0D=12 \savecatcodetable\csname\\minim:mp:catcodes:mpcode\endcsname} \directlua { require('minim-mp') } @@ -28,24 +29,39 @@ % % \closemetapostinstance \instance % \runmetapost \instance { code } % \protected -% \runmetapostimage \instance { code } % \protected % \getnextmpimage \instance % \getnamedmpimage \instance {name} % \remainingmpimages \instance % \boxnextmpimage \instance box-nr % \boxnamedmpimage \instance box-nr {name} +% \getallmpimages \instance +\newcount\mp:tmpcount +\protected\def\getallmpimages{% + \afterassignment\getallmpimages:do\mp:tmpcount=} +\def\getallmpimages:do{\loop + \ifnum \remainingmpimages\mp:tmpcount>0\relax + \getnextmpimage\mp:tmpcount \repeat} + +% \runmetapostimage \instance { code } +\protected\def\runmetapostimage{\begingroup + \afterassignment\runmetapostimage:do\mp:tmpcount=} +\def\runmetapostimage:do{% + \toksapp\everymp\mp:tmpcount{pre}{mp}{beginfig(0) }% + \tokspre\everymp\mp:tmpcount{post}{mp}{ endfig;}% + \toksapp\everymp\mp:tmpcount{post}{tex}{% + \getallmpimages\mp:tmpcount \endgroup}% + \runmetapost\mp:tmpcount} + % \directmetapost [ options ] { code } \protected\def\directmetapost{% - \begingroup\catcodetable\minim:mp:catcodes:mpcode - \withoptions[]\directmetapost:} -\long\def\directmetapost:[#1]#2{% - \newmetapostinstance[#1]\:mpinst: - \runmetapost\:mpinst:{#2}% - \loop \ifnum\remainingmpimages\:mpinst:>0\relax - \getnextmpimage\:mpinst: \repeat - \closemetapostinstance\:mpinst: - \endgroup} + \withoptions[]\directmetapost:opt} +\long\def\directmetapost:opt[#1]{% + \newmetapostinstance[#1]\:mpinst: + \everymp\:mpinst:{post}{tex}{% + \getallmpimages\:mpinst: + \closemetapostinstance\:mpinst:}% + \runmetapost\:mpinst:} % \newmetapostinstance [ options ] \instance \protected\def\newmetapostinstance{\withoptions[]\newmetapostinstance:} @@ -54,6 +70,41 @@ tex.sprint(require('minim-mp').open{#1}) }\relax} +% tex side of metapost instance initialisation +\newcount \mp:cur:inst +\newtoks \mp:init:env \mp:init:env{% + % four token lists for every instance + \expandafter\newtoks\csname mp:inst:pre:tex:\the\mp:cur:inst\endcsname + \expandafter\newtoks\csname mp:inst:pre:mp:\the\mp:cur:inst\endcsname + \expandafter\newtoks\csname mp:inst:post:mp:\the\mp:cur:inst\endcsname + \expandafter\newtoks\csname mp:inst:post:tex:\the\mp:cur:inst\endcsname} +% the zeroth quarted applies to all +\mp:cur:inst=0 \the\mp:init:env \mp:cur:inst=-1 + +% \everymp \id {pre|post}{mp|tex} % accesses the above token lists +\def\everymp#1#2#3{\csname mp:inst:#2:#3:\the + \ifcsname \string#1@instance\endcsname % for the latex environments + \lastnamedcs\else\numexpr#1\fi + \endcsname} + +% combining the relevant toks registers +\newtoks\mp:inst:pre:tex \mp:inst:pre:tex{% + \the\everymp0{pre}{tex}% + \the\everymp\mp:cur:inst{pre}{tex}} +\newtoks\mp:inst:post:tex \mp:inst:post:tex{% + \the\everymp\mp:cur:inst{post}{tex}% + \the\everymp0{post}{tex}} +\newtoks\mp:mpcode % see lua function scan_mp_chunk() +\newtoks\mp:makempcode \mp:makempcode{% + \edef\minim:mp:tmp{% + \the\everymp0{pre}{mp}% + \the\everymp\mp:cur:inst{pre}{mp}% + \unexpanded{\the\mp:mpcode}% + \the\everymp\mp:cur:inst{post}{mp}% + \the\everymp0{post}{mp}}% + \edef\minim:mp:tmp{\minim:mp:tmp}% + \mp:mpcode=\expandafter{\minim:mp:tmp}} + % colour conversion: 1 grayscale 2 cmyk 3 rgb 4 rgb as spot \newcount \convertmpcolours \convertmpcolours = 0 @@ -62,10 +113,9 @@ \newcount\GtoG \GtoG = 7152 \newcount\BtoG \BtoG = 0722 +% miscellaneous bits and ends \newtoks \everymaketext +\def\mpdim#1{\the\dimexpr#1\relax} \catcode`\: = \minimmploaded - - - |