summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Master/texmf-dist/doc/luatex/minim-mp/README52
-rw-r--r--Master/texmf-dist/doc/luatex/minim-mp/minim-mp.doc272
-rw-r--r--Master/texmf-dist/doc/luatex/minim-mp/minim-mp.pdfbin120799 -> 134407 bytes
-rw-r--r--Master/texmf-dist/metapost/minim-mp/minim-mp.mp21
-rw-r--r--Master/texmf-dist/metapost/minim-mp/minim.mp43
-rw-r--r--Master/texmf-dist/tex/luatex/minim-mp/minim-mp.ini2
-rw-r--r--Master/texmf-dist/tex/luatex/minim-mp/minim-mp.lua213
-rw-r--r--Master/texmf-dist/tex/luatex/minim-mp/minim-mp.sty50
-rw-r--r--Master/texmf-dist/tex/luatex/minim-mp/minim-mp.tex82
9 files changed, 498 insertions, 237 deletions
diff --git a/Master/texmf-dist/doc/luatex/minim-mp/README b/Master/texmf-dist/doc/luatex/minim-mp/README
index 372e9626e1a..bf03e5114e4 100644
--- a/Master/texmf-dist/doc/luatex/minim-mp/README
+++ b/Master/texmf-dist/doc/luatex/minim-mp/README
@@ -1,9 +1,9 @@
-Version: 2024/1.5
+Version: 2024/1.6
SUMMARY
-This package offers low-level mplib integration for plain LuaTeX and is
-designed with the purpose of being easy to extend.
+This package offers low-level mplib integration for both plain LuaTeX and
+LuaLaTeX. It is designed with the purpose of being easy to extend.
The use of multiple simultaneous MetaPost instances is supported, as well as
running TeX or lua code from within MetaPost. With the included minim-mp
@@ -17,9 +17,47 @@ In order to obtain the typeset manual of this package, simply say:
luatex minim-mp.doc
+INSTALLATION
+
+In order to use minim-mp as a stand-alone metapost compiler, you will have to
+generate the appropriate format files. For metapost with plain tex, say
+
+ luatex --ini minim-mp.ini
+
+For metapost with latex, say
+
+ luatex --ini minim-lamp.ini
+
+The resulting format (.fmt) files will be found if they are either in the same
+directory as your metapost source file, or in ${TEXMFHOME}/web2c/luatex (the
+latter is of course recommended).
+
+Useful shell aliases are
+
+ alias mpost='luatex --fmt=minim-mp'
+ alias lampost='luatex --fmt=minim-lamp'
+
+
HISTORY
-2025/1.5 (in development)
+2024/1.6 (25/3/2024)
+
+ New features:
+
+ * Add per-instance \everymp token lists
+ * Reduce the number of metapost error messages echoed to the terminal.
+ * The operators infont and glyph of now also accept font names.
+ * Provide \mpdim to latex class.
+
+ Bug fixes:
+
+ * Newlines are now handled by metapost too.
+ * As are all special characters: #$%^&_~
+ * Plain and luatex now use the same catcode regime.
+ * Add the missing tex.skip macro.
+ * Improve debugging messages.
+
+2024/1.5 (25/2/2024)
New features:
@@ -33,9 +71,9 @@ HISTORY
2024/1.4 (5/1/2024)
- * Support the extended graphics state (extgstate)
- * Allow box resource (xform) creation directly from metapost
- * Support transparency and transparency groups
+ * Support the extended graphics state (extgstate).
+ * Allow box resource (xform) creation directly from metapost.
+ * Support transparency and transparency groups.
2023/1.3 (20/10/2023)
diff --git a/Master/texmf-dist/doc/luatex/minim-mp/minim-mp.doc b/Master/texmf-dist/doc/luatex/minim-mp/minim-mp.doc
index 0cd4ff574e0..9b4806807d3 100644
--- a/Master/texmf-dist/doc/luatex/minim-mp/minim-mp.doc
+++ b/Master/texmf-dist/doc/luatex/minim-mp/minim-mp.doc
@@ -8,8 +8,8 @@
\else \startmetadata
author {Esger Renkema}
title {minim-mp}
- date {2024-02-25}
- version {2024/1.5}
+ date {2024-03-25}
+ version {2024/1.6}
keywords {LuaTeX; Plain TeX; MetaPost; mplib}
stopmetadata
\maketitle \fi
@@ -20,18 +20,26 @@ running tex or lua code from within metapost.
In order to use it, simply say ⟦\input minim-mp.tex⟧.
After this, ⟦*\directmetapost [ options ] { mp code }⟧ will result in a series
-of images corresponding to the ⟦beginfig ... endfig⟧ statements in your
+of images corresponding to the ⟦beginfig() ... endfig;⟧ statements in your
⟦mp code⟧. Every image will be in a box of its own.
+The metapost code to-be-run will be read under a special catcode regime in
+which most ‘special’ characters (including {\tt\#} and {\tt\%}) are inert.
+However, any control sequences will be expanded fully, as inside an ⟦\edef⟧.
+Keep this in mind and define any macros you want to use in a ⟦btex ... etex;⟧
+environment as ⟦\protected⟧ (with the latex package, latex’s ‘protected’ macros
+are safe-to-use, too).
+
Every call to ⟦\directmetapost⟧ opens and closes a separate metapost instance.
If you want your second call to remember the first, you will have to define
a persistent metapost instance. This will also give you more control over image
extraction. See below under „Metapost instances”. The ⟦options⟧ will also be
explained there (for simple cases, you will not need them).
-The logs of the metapost run will be included in the regular log file. If an
+The logs of the metapost run will be embedded in the regular log file. If an
error occurs, the log of the last snippet will also be shown on the terminal.
+
\section As a stand-alone Metapost compiler % 1
This package can also be used as a stand-alone metapost compiler. Saying
@@ -47,6 +55,7 @@ With minim-lamp, for specifying the contents of the preamble, you can use
Concluding the preamble with ⟦\begin{document}⟧ is optional, as both ⟦\begin⟧
and ⟦\end{document}⟧ will be inserted automatically if omitted.
+
\section LaTeX compatibility % 1
An experimental latex package is included in ⟦minim-mp.sty⟧. It really is
@@ -61,14 +70,19 @@ commands described in the next section.
As in luamplib, you can use ⟦*\mpcolor {name}⟧ to insert the proper colour
values; this macro is only available inside the above environments.
+A ⟦\mpdim⟧ macro is present too, but quite superfluous: since the contents of
+the metapost environments are fully expanded before metapost sees them, you can
+use ⟦\the⟧ and ⟦\the\dimexpr⟧ like everywhere else. Tex’s registers can also be
+accessed by metapost itself (see below).
When the package is loaded with the option ⟦luamplib⟧, minim-mp will try and
act as a drop-in replacement for luamplib. The effort made is not very great
though, but it will define an ⟦mplibcode⟧ environment, as well as the
⟦\mplibcodeinherit⟧, ⟦\mplibshowlog⟧, ⟦\mplibsetformat⟧ and
-⟦\mplibnumbersystem⟧ switches.
+⟦\mplibnumbersystem⟧ switches;
+also the macros ⟦\everymplib⟧ and ⟦\everyendmplib⟧.
Please do note that this is not the recommended way of using minim-mp, which
-remains the interface documented in the next section.
+remains the interface documented above and further in the next section.
\section Metapost instances % 1
@@ -76,7 +90,8 @@ remains the interface documented in the next section.
For more complicated uses, you can define your own instances by saying
⟦*\newmetapostinstance [ options ] \id⟧.
An instance can be closed with ⟦*\closemetapostinstance \id⟧.
-These are the options you can use:
+The ⟦options⟧ are directly passed to lua, as a table, and can contain the
+following keys:
\smallskip\smallskip\automarktable
\halign{#\quad\hfil&#\quad\hfil&#\hfil\cr
@@ -85,7 +100,7 @@ Option&Default&Description\cr
⟦format⟧&⟦'plain.mp'⟧&Format to initialise the instance with.\cr
⟦mathmode⟧&⟦'scaled'⟧&One of ⟦scaled⟧, ⟦decimal⟧ or ⟦double⟧.\cr
⟦seed⟧&⟦nil⟧&Random seed for this instance.\cr
-⟦catcodes⟧&⟦0⟧&Catcode table for ⟦btex ... etex⟧.\cr
+⟦catcodes⟧&(internal value)&Catcode table for ⟦btex ... etex⟧.\cr
⟦env⟧&copy of ⟦_G⟧&Lua environment; see below.\cr
}\smallskip
@@ -100,7 +115,6 @@ There, the image will be contained in a single box node.
⟦*\getnamedmpimage \id {name}⟧
– Retrieves an image by name
-regardless of its position,
and writes it to the current node list.
⟦*\boxnextmpimage \id box-nr⟧
@@ -110,12 +124,82 @@ tex can parse as a number.
⟦*\boxnamedmpimage \id box-nr {name}⟧
– Puts the image named ⟦name⟧ in box ⟦box-nr⟧.
-Say ⟦*\remainingmpimages \id⟧ for the number of images not yet retrieved.
+Say ⟦*\remainingmpimages \id⟧ for the number of images not yet retrieved
+and ⟦*\getallmpimages \id⟧ to insert all remaining images.
Finally, as a shorthand, ⟦*\runmetapostimage \id { code }⟧ will add
⟦beginfig ... endfig;⟧ to your ⟦code⟧ and write the resulting image immediately
to the current list.
+Associated to every instance are four token registers containing tex and/or
+metapost code to be inserted before or after each executed chunk.
+You can access them with ⟦*\everymp \id {pre|post} {tex|mp}⟧.
+The token lists where ${\tt id}=0$ do not correspond to any instance and will
+apply to every instance instead.
+All four token lists are empty by default if you use minim-mp with plain tex.
+The latex package, on the other hand, uses them for its own purposes, so take
+care in that case to use ⟦\tokspre⟧ and ⟦\toksapp⟧ instead of overwriting their
+contents. As a bonus, when using the latex package, you can use the environment
+name instead of the numerical ⟦\id⟧.
+
+
+\section Lua interface % 1
+
+In what follows, you should assume ⟦M⟧ to be the result of
+\stopformulatagging$$\hbox{⟦M = require('minim-mp')⟧}$$\startformulatagging
+as this package does not claim a table in the global environment for itself.
+
+You can open a new instance with ⟦*nr = M.open {options}⟧.
+This returns an index in the ⟦*M.instances⟧ table.
+Run code with ⟦*M.run (nr, code)⟧ and close the instance with ⟦*M.close (nr)⟧.
+Images can be retrieved only with ⟦*box_node = M.get_image(nr, [name])⟧; omit
+the ⟦name⟧ to select the first image.
+Say ⟦*nr_remaining = M.left(nr)⟧ for the number of remaining images.
+
+Each metapost instance is a table containing the following entries:
+
+\smallskip\smallskip
+\marktableaslist
+\tagattribute List ListNumbering /Description
+\halign{\qquad#\quad\hfil&#\hfil\cr
+⟦jobname⟧&The jobname.\cr
+⟦instance⟧&The primitive metapost instance.\cr
+⟦results⟧&A linked list of unretrieved images.\cr
+⟦status⟧&The last exit status (will never decrease).\cr
+⟦catcodes⟧&Number of the catcode table used with ⟦btex ... etex⟧.\cr
+⟦env⟧&The lua environment for ⟦runscript⟧.\cr}
+
+Default values for the format and number system are available in the
+⟦*M.default_format⟧ and ⟦*M.default_mathmode⟧ variables.
+The full initialisation sequence for new instances (i.e. the first metapost
+chunk, that is executed automatically) is contained in the ⟦*M.init_code⟧
+table.
+
+
+\section Logs and debugging % 1
+
+Metapost log output of every processed chunk of metapost code will be printed
+to the main log file in a quoted form.
+The logs will be duplicated to the terminal if an error occurs or if the
+variable ⟦*M.on_line⟧ is ⟦true⟧ (the default is ⟦false⟧, but set to ⟦true⟧ in
+the stand-alone format files).
+Because a single error message might trigger many others, log output to the
+terminal (but not the log file) will be cut after a certain number of errors:
+this behaviour is governed by the ⟦*M.max_errprint⟧ variable (default ⟦1⟧; set
+to ⟦0⟧ to disable).
+
+You can enable (global) debugging by saying ⟦*debug_pdf⟧ to metapost,
+⟦*\debugmetapost⟧ to tex or ⟦*M.enable_debugging()⟧ to lua. This will write
+out a summary of metapost object information to the pdf file, just above the
+pdf instructions that object was translated into. For this purpose, the pdf
+will be generated uncompressed. Additionally, the metapost code itself will be
+echoed to the log, as well as ⟦runscript⟧ and ⟦maketext⟧ invocations, and
+a small summary of every generated image will be written to log and terminal.
+
+For debugging the results of ⟦maketext⟧ and the like, you can set the
+⟦*debug_tex_bboxes⟧ variable to ⟦true⟧ and have their resulting bounding boxes
+drawn on the pdf.
+
\section Running tex from within metapost % 1
@@ -139,10 +223,12 @@ You can also use metapost’s ⟦*infont⟧ operator, which restricts the text
to-be-typeset to a single font, but returns an ⟦picture⟧ containing a ⟦picture⟧
for each character. The right-hand argument of ⟦infont⟧ should either be
a (numerical) font~id or the (cs)name of a font (without backslash).
+A traditional font name (e.g. ‘cmtt10’) is also accepted; this will silently
+load the font.
One possible use of the ⟦infont⟧ operator is setting text along curves:
-\nobreak
+\goodbreak
⟦beginfig(1)
save t, w, r, a; picture t;
t = "Running TeX from within MetaPost" infont "tenrm";
@@ -157,7 +243,7 @@ endfig;⟧
\vskip-2\parskip plus 2\parskip
\quitvmode\hfil
\startelement alt {The text ‘Running TeX from within MetaPost’ set along a half-circle.} {Figure}%
-\startsinglecontentitem\directmetapost{%
+\startsinglecontentitem\directmetapost [jobname='tex-in-mp'] {%
beginfig(1)
save t, w, r, a; picture t;
t = "Running TeX from within MetaPost" infont "tenrm";
@@ -189,35 +275,7 @@ Be aware that the contours returned by these operators may be disjoint:
a letter ⟦o⟧, for example, will consists of two. This means you cannot recreate
the characters by just filling each contour: this would turn the ⟦o⟧ into
a filled-in circle. Instead, you must use ⟦multifill⟧ on the entire output of
-⟦glyph of⟧ or ⟦contours of⟧ (see the next section).
-
-
-\section Partial paths and the even-odd rule % 1
-
-You can fill or draw two or more disjoint paths in one go by using ⟦*nofill⟧ as
-drawing operator for all paths but the last. This may make it easier to cut
-something out of a shape, since you do not have to worry about stitching the
-paths together.
-
-While metapost fills paths according to the winding number, the pdf format also
-supports filling according to the even-odd rule. This has been made possible
-with the ⟦*eofill⟧ and ⟦*eofilldraw⟧ drawing statements, which can of course
-also be used as the final statement after a series of nofills.
-
-The macros ⟦*multi(draw|fill|filldraw|eofill|eofilldraw)⟧ take a list of paths
-between parentheses and can be followed by the usual drawing options.
-For example,
-⟦multidraw (contours "example" of "tenbf") withpen currentpen scaled 1/10;⟧
-will give the word%
-\markelement{Span}{\setactualtext{example }\startsinglecontentitem\space
-\directmetapost{beginfig(1) multidraw (contours "example" of "tenbf")
-withpen currentpen scaled 1/10; baseline 0; endfig;}\stopsinglecontentitem}
-in a thin outline.
-
-Finally, two handy clipping macros have been added:
-⟦*clipout⟧ and ⟦*clipto⟧, which both receive a list of paths as a ‘text’
-parameter and either clip their ensemble out of the picture, or the picture to
-the ensemble.
+⟦glyph of⟧ or ⟦contours of⟧ (see below under ‘partial paths’).
\section Running lua from within metapost % 1
@@ -228,10 +286,10 @@ you make are local to the instance. (You can of course order the global
environment to be used by giving ⟦env = _G⟧ as option to
⟦\newmetapostinstance⟧.)
Any environment you specify will be supplemented with the contents of the
-⟦*M.mp_functions⟧ table. It currently contains two functions: ⟦quote(s)⟧, which
-escapes all double quotes in the string ⟦s⟧ before surrounding it with the same
-(so that it may be read as a metapost string literal); and ⟦sp_to_pt(nr)⟧,
-which prints dimensions in points (preventing overflows).
+⟦*M.mp_functions⟧ table. Two useful functions pre-supplied are ⟦quote(s)⟧,
+which escapes all double quotes in the string ⟦s⟧ before surrounding it with
+the same (so that it may be read as a metapost string literal); and
+⟦sp_to_pt(nr)⟧, which prints dimensions in points (preventing overflows).
When using ⟦runscript⟧ in this way, you must ensure its argument is a correct
lua program. As an escape hatch, raw strings can be passed to lua with
@@ -289,11 +347,40 @@ For accessing count, dimen, attribute or toks registers, the macros are
setting values.
+\section Partial paths and the even-odd rule % 1
+
+You can fill or draw two or more disjoint paths in one go by using ⟦*nofill⟧ as
+drawing operator for all paths but the last. This may make it easier to cut
+something out of a shape, since you do not have to worry about stitching the
+paths together.
+
+While metapost fills paths according to the winding number, the pdf format also
+supports filling according to the even-odd rule. You can use that method
+with the ⟦*eofill⟧ and ⟦*eofilldraw⟧ drawing statements, which can of course
+also be used as the final statement after a series of nofills.
+
+The macros ⟦*multi(draw|fill|filldraw|eofill|eofilldraw)⟧ take a list of paths
+between parentheses and can be followed by the usual drawing options.
+For example,
+⟦multidraw (contours "example" of "tenbf") withpen currentpen scaled 1/10;⟧
+will give the word%
+\markelement{Span}{\setactualtext{example }\startsinglecontentitem\space
+\directmetapost [jobname='outline']
+{beginfig(1) multidraw (contours "example" of "tenbf")
+withpen currentpen scaled 1/10; baseline 0; endfig;}\stopsinglecontentitem}
+in a thin outline.
+
+Finally, two handy clipping macros have been added:
+⟦*clipout⟧ and ⟦*clipto⟧, which both receive a list of paths as a ‘text’
+parameter and either clip their ensemble out of the picture, or the picture to
+the ensemble.
+
+
\section Tiling patterns % 1
-The condition ⟦*withpattern(<name>)⟧ added to a ⟦fill⟧ statement will fill the path with
-a pattern instead of a solid colour. If the patterns contains no colour
-information of itself, it will have the colour given by ⟦withcolor⟧.
+The specification ⟦*withpattern(<name>)⟧ added to a ⟦fill⟧ statement will fill
+the path with a pattern instead of a solid colour. If the pattern itself does
+not contain any colour statements, it will have the colour given by ⟦withcolor⟧.
Stroking operations (the ⟦draw⟧ part) will not be affected.
Patterns will always look the same, irrespective of any transformations you
apply to the picture.
@@ -315,8 +402,8 @@ information on these parameters.
You can use text inside patterns, as in this example:
\hfill \vbox to 0pt{
\startelement alt{A circle filled with red As in a rectangular pattern.}{Figure}
-\startsinglecontentitem \directmetapost{
-% define the pattern
+\startsinglecontentitem \directmetapost [jobname='pattern']
+{% define the pattern
picture letter; letter = maketext("a");
beginpattern(a)
draw letter rotated 45;
@@ -365,19 +452,19 @@ For applying transparency, ⟦*setalpha(a)⟧ updates the ⟦CA⟧ and ⟦ca⟧
as a stand-alone command and ⟦*withalpha(a)⟧ can be used in a drawing statement
where it will save/restore the graphical state around it. For applying
transparency to an ensemble of drawing statements, ⟦*transparent (a) <picture>⟧
-will create and insert the proper transparency group. The transparency group
-attributes can be set with the string internal ⟦transparency_group_attrs⟧,
-while for all three macros the blend mode can be set with the string internal
-⟦blend_mode⟧ (it will be added whenever set).
+instead of ⟦draw <picture>⟧ will create and insert the proper transparency group.
+The transparency group attributes can be set with the string internal
+⟦*transparency_group_attrs⟧, while for all three macros the blend mode can be
+set with the string internal ⟦*blend_mode⟧ (it will be added whenever set).
A transparency group is a special kind of XForm, and these can be created from
-withing metapost: ⟦<id> =⟧ ⟦*saveboxresource (<attributes>) <picture>⟧ returns
-a number identifying the resource and can be fed attributes in the same way as
-⟦setgstate⟧. XForms defined through metapost are available to other metapost
-instances but not to tex, though the macro painting them, ⟦*boxresource <id>⟧,
-also accepts identifiers of tex-defined box resources. There remains a subtle
-difference, however: metapost-defined box resources are placed at their
-original origin.
+within metapost: ⟦<id> =⟧ ⟦*saveboxresource (<attributes>) <picture>⟧ returns
+a number identifying the resource; the ⟦<attributes>⟧ can be given in the same
+way as the arguments to ⟦setgstate⟧. XForms defined through metapost are
+available to other metapost instances but not to tex, though the macro painting
+them, ⟦*boxresource <id>⟧, also accepts identifiers of tex-defined box
+resources. There remains a subtle difference, however: metapost-defined box
+resources are placed at their original origin.
\section Other metapost extensions % 1
@@ -400,8 +487,16 @@ In that case, they will be added before or after the object they are attached to
Do note that all ⟦special⟧ statements will appear at the beginning of the
image; use pre- and postscripts to drawing statements if the order matters.
-Minim-mp also provides a few elementary macros and constants that are
-conspicuously absent from plain.mp; I hope their addition is uncontroversial.
+
+\section Additions to plain.mp % 1
+
+Minim-mp provides a few elementary macros and constants that are
+conspicuously absent from plain.mp; I hope their addition is uncontroversial.
+All are provided in the file minim.mp; the contents of this file do not depend
+on functions specific to minim-mp and thus it can safely be used with other
+metapost processors. It is included automatically right after the format file
+(i.e. plain.mp).
+
The constants are ⟦*pi⟧ (355/113), ⟦*fullsquare⟧, ⟦*unitcircle⟧ and the
cmyk-colours ⟦*cyan⟧, ⟦*magenta⟧, ⟦*yellow⟧ and ⟦*key⟧. The macros are
⟦*clockwise⟧, ⟦*xshifted⟧, ⟦*yshifted⟧, ⟦*hflip⟧ and ⟦*vflip⟧, where the flips
@@ -413,49 +508,12 @@ etc. that save and declare in one go; the missing trigonometric functions
drawing function ⟦*arc(⟧$θ_0$⟦*,⟧$θ_ℓ$⟦*)⟧ (taking a starting angle and arc
length, both in degrees).
-\section Lua interface % 1
-
-In what follows, you should assume ⟦M⟧ to be the result of
-\stopformulatagging$$\hbox{⟦M = require('minim-mp')⟧}$$\startformulatagging
-as this package does not claim a table in the global environment for itself.
-
-You can open a new instance with ⟦*nr = M.open {options}⟧.
-This returns an index in the ⟦*M.instances⟧ table.
-Run code with ⟦*M.run (nr, code)⟧ and close the instance with ⟦*M.close (nr)⟧.
-Images can be retrieved only with ⟦*box_node = M.get_image(nr, [name])⟧; omit
-the ⟦name⟧ to select the first image.
-Say ⟦*nr_remaining = M.left(nr)⟧ for the number of remaining images.
+Version 1.6 brought ⟦*empty⟧ for testing empty suffixes, ⟦*typeof(v)⟧
+expanding to the type (⟦numeric⟧, ⟦pair⟧ etc.) of variable ⟦v⟧,
+⟦*getbounds⟧ as complement to ⟦setbounds⟧, the (twodimensional) exterior product
+⟦*p extprod q⟧ and the test ⟦*collinear(p,q,r)⟧.
-Each metapost instance is a table containing the following entries:
-
-\smallskip\smallskip
-\marktableaslist
-\tagattribute List ListNumbering /Description
-\halign{\qquad#\quad\hfil&#\hfil\cr
-⟦jobname⟧&The jobname.\cr
-⟦instance⟧&The primitive metapost instance.\cr
-⟦results⟧&A linked list of unretrieved images.\cr
-⟦status⟧&The last exit status (will never decrease).\cr
-⟦catcodes⟧&Number of the catcode table used with ⟦btex ... etex⟧.\cr
-⟦env⟧&The lua environment for ⟦runscript⟧.\cr}
-
-Default values for the format and number system are available in the
-⟦M.default_format⟧ and ⟦M.default_mathmode⟧ variables,
-while ⟦M.on_line⟧ controls whether the logs are always printed to the
-terminal.
-
-
-\section Debugging % 1
-
-You can enable (global) debugging by saying ⟦*debug_pdf⟧ to metapost or
-⟦*M.enable_debugging()⟧ to lua. This will write out a summary of metapost
-object information to the pdf file, just above the pdf instructions that object
-was translated into. For this purpose, the pdf will be generated uncompressed.
-Additionally, a small summary of every generated image will be written to log
-and terminal.
-
-
-\section Extending metapost % 1
+\section Metapost specials % 1
You can extend this package by adding new metapost specials. Specials should
have the form ⟦"identifier: instructions"⟧ and can be added as pre- or
@@ -483,9 +541,5 @@ properly-dimensioned boxes. If a ⟦user.save_fn⟧ function is defined, it will
replace the normal saving of the image to the image list and the image node
list will be flushed.
-The ⟦*M.init_code⟧ table contains the code used for initialing new instances.
-In it, the string ⟦INIT⟧ will be replaced with the value of the ⟦format⟧ option
-(normally ⟦plain.mp⟧).
-
\endmanual %
diff --git a/Master/texmf-dist/doc/luatex/minim-mp/minim-mp.pdf b/Master/texmf-dist/doc/luatex/minim-mp/minim-mp.pdf
index eae0cd360e4..4760106341c 100644
--- a/Master/texmf-dist/doc/luatex/minim-mp/minim-mp.pdf
+++ b/Master/texmf-dist/doc/luatex/minim-mp/minim-mp.pdf
Binary files differ
diff --git a/Master/texmf-dist/metapost/minim-mp/minim-mp.mp b/Master/texmf-dist/metapost/minim-mp/minim-mp.mp
index 2fd2db1074b..30b7d862526 100644
--- a/Master/texmf-dist/metapost/minim-mp/minim-mp.mp
+++ b/Master/texmf-dist/metapost/minim-mp/minim-mp.mp
@@ -7,12 +7,7 @@ delimiters ();
message "Setting up the minim MetaPost extensions";
-def save_picture text t = save t; picture t; enddef;
-def save_boolean text t = save t; boolean t; enddef;
-def save_string text t = save t; string t; enddef;
-def save_path text t = save t; path t; enddef;
-
-% 1 lua scripts, functions and variables
+% 1 lua scripts and functions
def luafunction = gobble inner_luafunction enddef;
vardef inner_luafunction @# (text args) = endgroup
@@ -85,9 +80,6 @@ vardef quote_for_lua tertiary a =
","& (hexadecimal magentapart a) &
","& (hexadecimal yellowpart a) &
","& (hexadecimal blackpart a) & "}"
- elseif pen a:
- hide(errmessage("I cannot pass a pen value to lua");)
- "nil"
elseif transform a:
"{"& (hexadecimal xxpart a) &
","& (hexadecimal xypart a) &
@@ -95,6 +87,9 @@ vardef quote_for_lua tertiary a =
","& (hexadecimal yypart a) &
","& (hexadecimal xpart a) &
","& (hexadecimal ypart a) & "}"
+ elseif pen a:
+ hide(errmessage("I cannot pass a pen value to lua");)
+ "nil"
elseif picture a:
hide(errmessage("I cannot pass a picture value to lua");)
"nil"
@@ -121,7 +116,7 @@ vardef make_lua_keyval @# expr e =
(str @#) & " = " & quote_for_lua e
enddef;
-% tex registers
+% 1 tex registers
string _SUFFIX_HACK_[];
vardef index_or_suffix (suffix s) =
@@ -138,6 +133,8 @@ vardef tex.attribute @# =
runscript ("return tex.attribute" & index_or_suffix(@#)) enddef;
vardef tex.dimen @# =
runscript ("return sp_to_pt(tex.dimen" & index_or_suffix(@#) & ")") enddef;
+vardef tex.skip @# =
+ runscript ("return sp_to_pt(tex.skip" & index_or_suffix(@#) & ".width)") enddef;
vardef tex.toks @# =
runscript ("return quote(tex.toks" & index_or_suffix(@#) & ")") enddef;
@@ -382,8 +379,4 @@ def debug_pdf = luafunction enable_debugging(); enddef;
vardef texmessage text msg = luafunction texmessage (msg) enddef;
-vardef rgb_to_gray expr c =
- luafunction rgb_to_gray (redpart c, greenpart c, bluepart c)
-enddef;
-
% 
diff --git a/Master/texmf-dist/metapost/minim-mp/minim.mp b/Master/texmf-dist/metapost/minim-mp/minim.mp
index b0df361b949..ed152a018b6 100644
--- a/Master/texmf-dist/metapost/minim-mp/minim.mp
+++ b/Master/texmf-dist/metapost/minim-mp/minim.mp
@@ -1,8 +1,7 @@
if known minim.mp:
- message "skipping: already read";
expandafter endinput fi
-minim.mp := 1.3;
+minim.mp := 1.6;
% This file only contains code that is not specific to the minim metapost
% processor. See minim-mp.mp for the wireup of minim-mp’s extensions.
@@ -42,6 +41,9 @@ vardef clipto text t =
vardef clipout text t =
clip currentpicture to
for c = t: c -- cycle -- endfor cycle enddef;
+vardef getbounds primary p = % without bboxmargin
+ llcorner p -- lrcorner p -- urcorner p -- ulcorner p -- cycle
+enddef;
% cmyk colours
cmykcolor cyan, magenta, yellow, key;
@@ -50,12 +52,9 @@ magenta = (0,1,0,0);
yellow = (0,0,1,0);
key = (0,0,0,1);
-% also in minim-mp.mp
-if unknown rgb_to_gray red:
- vardef rgb_to_gray expr c =
- 0.2126*redpart c + 0.7152*greenpart c + 0.0722*bluepart c
- enddef;
-fi
+vardef rgb_to_gray expr c =
+ 0.2126*redpart c + 0.7152*greenpart c + 0.0722*bluepart c
+enddef;
% shorthands
def save_pen text t = save t; pen t; enddef;
@@ -91,3 +90,31 @@ vardef arc (expr thetafrom, thetalen) =
and (p - c) .. p
endfor; a enddef;
+% some linear algebra
+primarydef v extprod w = begingroup
+ xpart v * ypart w - ypart v * xpart w
+endgroup enddef;
+
+vardef collinear(expr p,q,r) =
+ (p <> q) and (q <> r) and (p <> r)
+ and (eps > abs( (p-q) extprod (q-r) ))
+enddef;
+
+% type helpers
+def typeof (expr v) =
+ if numeric v: numeric
+ elseif pair v: pair
+ elseif color v: color
+ elseif cmykcolor v: cmykcolor
+ elseif boolean v: boolean
+ elseif path v: path
+ elseif picture v: picture
+ elseif transform v: transform
+ elseif string v: string
+ elseif pen v: pen
+ fi enddef;
+
+vardef empty suffix s = save_boolean b;
+ b := string _EMPTY_ s; b enddef;
+string _EMPTY_;
+
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
-
-
-