diff options
author | Norbert Preining <norbert@preining.info> | 2023-03-07 03:02:56 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2023-03-07 03:02:56 +0000 |
commit | 4f55c9271affed648c1a939790a73083043752f5 (patch) | |
tree | 5de3491421bbf46cdb941a9a70158ca43e748919 /macros/luatex/generic/minim-mp | |
parent | 75cd005305bd2c2a0ec383f30ee5b1749ed15183 (diff) |
CTAN sync 202303070302
Diffstat (limited to 'macros/luatex/generic/minim-mp')
-rw-r--r-- | macros/luatex/generic/minim-mp/README | 7 | ||||
-rw-r--r-- | macros/luatex/generic/minim-mp/minim-mp.doc | 9 | ||||
-rw-r--r-- | macros/luatex/generic/minim-mp/minim-mp.lua | 48 | ||||
-rw-r--r-- | macros/luatex/generic/minim-mp/minim-mp.pdf | bin | 94557 -> 98659 bytes | |||
-rw-r--r-- | macros/luatex/generic/minim-mp/minim.mp | 37 |
5 files changed, 73 insertions, 28 deletions
diff --git a/macros/luatex/generic/minim-mp/README b/macros/luatex/generic/minim-mp/README index 2e04ee1050..b28f8c4267 100644 --- a/macros/luatex/generic/minim-mp/README +++ b/macros/luatex/generic/minim-mp/README @@ -1,4 +1,4 @@ -Version: 2022/1.1 +Version: 2023/1.2 SUMMARY @@ -19,6 +19,11 @@ In order to obtain the typeset manual of this package, simply say: HISTORY +2023/1.2 (3/3/2023) + + * Add a few more metapost macros. + * Various small bug fixes. + 2022/1.1 (3/3/2022) New features: diff --git a/macros/luatex/generic/minim-mp/minim-mp.doc b/macros/luatex/generic/minim-mp/minim-mp.doc index b7fb47f416..af84cd1581 100644 --- a/macros/luatex/generic/minim-mp/minim-mp.doc +++ b/macros/luatex/generic/minim-mp/minim-mp.doc @@ -8,8 +8,8 @@ \else \startmetadata author {Esger Renkema} title {minim-mp} - date {2022-03-03} - version {2022/1.1} + date {2023-03-03} + version {2023/1.2} keywords {LuaTeX; Plain TeX; MetaPost; mplib} stopmetadata \maketitle \fi @@ -291,6 +291,11 @@ cmyk-colours ⟦*cyan⟧, ⟦*magenta⟧, ⟦*yellow⟧ and ⟦*key⟧. The macr ⟦*clockwise⟧, ⟦*xshifted⟧, ⟦*yshifted⟧, ⟦*hflip⟧ and ⟦*vflip⟧, where the flips are defined in such a way that ⟦p & hflip p⟧ gives the expected result. +Version 1.2 brought the following additions: ⟦*save_pair⟧, ⟦*save_path⟧ etc. +etc. that save and declare in one go; the missing trigonometric functions +⟦*tand⟧, ⟦*arcsind⟧, ⟦*arccosd⟧ and ⟦*arctand⟧, and the unit circle segment +drawing function ⟦*arc(⟧$θ_0$⟦*,⟧$θ_ℓ$⟦*)⟧ (taking a starting angle and arc +length, both in degrees). \section Lua interface %1 diff --git a/macros/luatex/generic/minim-mp/minim-mp.lua b/macros/luatex/generic/minim-mp/minim-mp.lua index 366313e60b..a247c49499 100644 --- a/macros/luatex/generic/minim-mp/minim-mp.lua +++ b/macros/luatex/generic/minim-mp/minim-mp.lua @@ -58,12 +58,12 @@ function A.save(append) stroke = st.stroke, fill = st.fill } - append:node(node.new(8, 30)) -- q + append:node(node.new('whatsit', 'pdf_save')) -- q end function A.restore(append) append.state[#append.state] = nil - append:node(node.new(8, 31)) -- Q + append:node(node.new('whatsit', 'pdf_restore')) -- Q end -- The following callback is executed just before the final step of surrounding @@ -138,7 +138,7 @@ function A.printobj(append, obj) if obj.pen then local x = obj.pen.type or 'not elliptical' append:literal('%% pen: see below, form: %s', x) - local x = mplib.pen_info(obj) + 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)) @@ -197,7 +197,7 @@ local function curve_fmt(...) end function A.literal(append, fmt, ...) - local lit = node.new(8,16) -- pdf_literal + local lit = node.new('whatsit', 'pdf_literal') lit.data = fmt:format(...) append:node(lit) end @@ -484,9 +484,9 @@ M.postscripts = postscripts --2 choosing a parser -local function split_specials(specials) - if not specials then return function() return end end - local l = specials:explode('\r') +local function split_specials(thespecials) + if not thespecials then return function() return end end + local l = thespecials:explode('\r') local i, n = 0, #l return function() if i < n then i = i + 1 else return end @@ -627,7 +627,7 @@ end postscripts.pdfcomment = prescripts.pdfcomment prescripts.latelua = function(append, str, object) - local n = node.new(8,7) -- late_lua + local n = node.new('whatsit', 'late_lua') n.data = str append:node(n) end @@ -637,7 +637,7 @@ prescripts.OTYPE = function(append, str, object) append.object_info.otype = append.object_info.otype or str end -specials.BASELINE = function(append, str, object) +specials.BASELINE = function(append, _, object) -- object is a ‘fill’ statement with only a single point in its path (and -- will thus not have to be transformed). append.baseline = object.path[1].y_coord @@ -684,8 +684,8 @@ local function make_pattern_xform(head, bb) return string.format(' /Resources << /XObject << /PTempl %d 0 R >> >>', xform), '/PTempl Do' end -local function definepattern(head, user, bb) - local bb = bbox_fmt(table.unpack(bb)) +local function definepattern(head, user, bbox) + local bb = bbox_fmt(table.unpack(bbox)) local pat, literals, resources = { write = write_pattern_object }, { } -- pattern content for n in node.traverse(head) do @@ -755,9 +755,9 @@ local function make_surrounding_box(nd_id, head) end local function wrap_picture(head, tx, ty) - local horizontal = make_surrounding_box(0, head) - local vertical = make_surrounding_box(1, horizontal) - local outer = make_surrounding_box(0, vertical) + local horizontal = make_surrounding_box('hlist', head) + local vertical = make_surrounding_box('vlist', horizontal) + local outer = make_surrounding_box('hlist', vertical) vertical.shift = tex.sp('-'..ty..'bp') horizontal.shift = tex.sp(''..tx..'bp') return outer @@ -765,7 +765,7 @@ end local function apply_transform(rect, box) local sx, rx, ry, sy, tx, ty = get_transform(rect) - local transform = node.new(8,29) -- pdf_setmatrix + local transform = node.new('whatsit', 'pdf_setmatrix') transform.next, box.prev = box, transform transform.data = string.format('%f %f %f %f', sx, rx, ry, sy) return wrap_picture(transform, tx, ty) @@ -780,14 +780,14 @@ function A.box(append, object, box) append:restore() end -specials.TEXBOX = function(append, box, object) - local box = tex.getbox(tonumber(box)) +specials.TEXBOX = function(append, boxnr, object) + local box = tex.getbox(tonumber(boxnr)) append:box(object, node.copy_list(box)) end specials.CHAR = function(append, data, object) local char, font, xo, yo = table.unpack(data:explode(' ')) - local n = node.new(29) -- glyph + local n = node.new('glyph') n.char, n.font, n.xoffset, n.yoffset = tonumber(char), tonumber(font), tonumber(xo), tonumber(yo) append:box(object, node.hpack(n)) @@ -849,7 +849,7 @@ local function print_log (nr, res, why) -- write out the log log('┌ %smetapost instance %s (%d)', why or '', i.jobname, i.nr) for _,line in ipairs(report) do - log('│ '..line) + log('│ %s', line) end log('└ %s', print_status(res.status)) -- generate error or warning if needed @@ -1198,9 +1198,9 @@ function M.close (nr) local res = i.instance:finish() print_log(nr, res, 'closing ') end - for _, nr in ipairs(i.boxes) do + for _, b in ipairs(i.boxes) do -- remove allocated boxes - tex.box[nr] = nil + tex.box[b] = nil end instances[nr] = false end @@ -1216,6 +1216,7 @@ local function retrieve(nr, name) else image = results.first end + if not image then return end results.count = results.count - 1 if image.prev then if image.next then @@ -1251,7 +1252,7 @@ function M.get_image(nr, name) end function M.shipout(nr) - local ox, oy = pdf.getorigin + local ox, oy = pdf.getorigin() local ho, vo = tex.hoffset, tex.voffset pdf.setorigin() tex.hoffset = 0 @@ -1280,7 +1281,8 @@ alloc.luadef('runmetapost', function() end, 'protected') alloc.luadef('runmetapostimage', function() local i = scan_int() - M.run(i, 'beginfig(0); '..scan_string()..' endfig;') + local code = 'beginfig(0)'..scan_string()..';endfig;' + M.run(i, code) node.write(M.get_image(i)) end, 'protected') diff --git a/macros/luatex/generic/minim-mp/minim-mp.pdf b/macros/luatex/generic/minim-mp/minim-mp.pdf Binary files differindex 1011878d1e..15ada22b36 100644 --- a/macros/luatex/generic/minim-mp/minim-mp.pdf +++ b/macros/luatex/generic/minim-mp/minim-mp.pdf diff --git a/macros/luatex/generic/minim-mp/minim.mp b/macros/luatex/generic/minim-mp/minim.mp index f3f03eb3d0..0bbaa2a27c 100644 --- a/macros/luatex/generic/minim-mp/minim.mp +++ b/macros/luatex/generic/minim-mp/minim.mp @@ -1,14 +1,14 @@ delimiters (); +message "Loading the minim extension macros"; + % redefine some constants to work with the new numerical engines numeric mm, cm, pt, pc, dd, cc; pc = 12 pt; cc = 12 dd; cm = 10 mm; 803 pt = 800; 127 mm = 360; 1157 dd = 1238 pt; eps := 1/2048; infinity := 64*64-epsilon; -message "Loading the minim extension macros"; - % interaction with tex vardef baseline expr o = fill if numeric o : (0,o) else: o fi @@ -114,6 +114,8 @@ def endpattern (expr xstep, ystep) = newinternal tilingtype; tilingtype:=1; _patterns_._last_ := 0; +message "Loading additional definitions"; + % shorthands primarydef p xshifted x = p shifted (x,0) enddef; primarydef p yshifted y = p shifted (0,y) enddef; @@ -141,4 +143,35 @@ key = (0,0,0,1); % constants pi := 355/113; +% shorthands +def save_pair text t = save t; pair t; enddef; +def save_path text t = save t; path t; enddef; +def save_color text t = save t; color t; enddef; +def save_cmykcolor text t = save t; cmykcolor t; enddef; +def save_transform text t = save t; transform t; enddef; +def save_boolean text t = save t; boolean t; enddef; +def save_string text t = save t; string t; enddef; + +% missing trigonometric functions +vardef tand primary x = sind(x)/cosd(x) enddef; +vardef arcsind primary x = angle((1+-+x, x)) enddef; +vardef arccosd primary x = angle((x, 1+-+x)) enddef; +vardef arctand primary x = angle(1, x) enddef; + +% segments of the circle (counterclockwise) +vardef arc (expr thetafrom, thetalen) = + save n, d, l, theta; save_path a; save_pair p, c; + n = ceiling(thetalen / 45); % number of segments (45° is max segment length) + d = thetalen / n; % angle of each segment + l = 4/3 * tand(d/4); % length of control points + theta := thetafrom; + p := (cosd theta, sind theta); + c := l * (-sind theta, cosd theta); + a := p for _ = 1 upto n: + .. controls (p + c) + hide(theta := theta + d; + p := (cosd theta, sind theta); + c := l * (-sind theta, cosd theta);) + and (p - c) .. p + endfor; a enddef; |