Debian Codegraph @

texmf-dist/tex/luatex/minim-mp/minim-mp.sty

raw
1
2 \ProvidesPackage{minim-mp}[2025/02/12 Run MetaPost code from LaTeX]
3
4 \input minim-mp
5
6 % work around latex’s \protect mechanism
7 \let\mnm@protect=\protect
8 \everymaketext{\let\protect=\mnm@protect}
9 \everyverbatimtex{\let\protect=\mnm@protect}
10
11 % the defaultfont is the current \normalfont
12 \def\mnm@setnormalfont{{\normalfont
13 \xdef\mnm@normalfont{\expandafter\csstring\the\font}}}
14
15 % global instance configuration
16 \everymp0{pre}{mp}{defaultfont:="\mnm@normalfont";}
17 \everymp0{pre}{tex}{%
18 \mnm@setnormalfont
19 \let\mpcolor = \minimpcolor
20 \let\protect = \noexpand}
21 \everymp0{post}{tex}{%
22 \let\protect=\mnm@protect}
23
24 % a one-off metapost environment
25 \newenvironment{metapost}[1][]{\begingroup
26 \catcodetable\csname minim:mp:catcodes:mpcode\endcsname
27 \csname:metapost:\endcsname[#1]}
28 {\csname end:metapost:\endcsname}
29 \NewDocumentEnvironment{:metapost:}{O{}+b}{\endgroup
30 \directmetapost[#1]{#2}}{}
31
32 % separate metapost instances
33 \newcommand\newmetapostenvironment[2][]{%
34 \newmetapostinstance[#1]\mnm@tmp
35 \expandafter\let\csname #2@instance\endcsname\mnm@tmp
36 \everymp\mnm@tmp{post}{tex}{%
37 \getallmpimages \csname #2@instance\endcsname}
38 \newenvironment{#2}{\begingroup
39 \catcodetable\csname minim:mp:catcodes:mpcode\endcsname
40 \csname:#2:\endcsname}
41 {\csname end:#2:\endcsname}%
42 \NewDocumentEnvironment{:#2:}{+b}{\endgroup
43 \runmetapost \csname #2@instance\endcsname{##1}}{}}
44
45 % \mpcolor support
46 \def\minimpcolor#1#{\dominimpcolor{#1}}
47 \def\dominimpcolor#1#2{%
48 \directlua{ tex.scantoks('mpcolorspectoks', 0, '#1{#2}')
49 tex.runtoks 'mpcolorruntoks' }
50 (\the\mpcolorvaltoks)}
51 \newtoks\mpcolorspectoks \newtoks\mpcolorruntoks \newtoks\mpcolorvaltoks
52 \mpcolorruntoks{\expandafter\extractcolorspec\the\mpcolorspectoks\mptmpcolor
53 \expandafter\mpcolorvaltoks\expandafter\@gobble\mptmpcolor}
54
55 % as a rather fragile drop-in replacement for luamplib
56 \DeclareOption{luamplib}{%
57 \def\mplibtextextlabel#1{} % always enabled
58 \def\mplibshowlog#1{\directlua{
59 require 'minim-mp'.on_line = %
60 \ifcsname minimp@switch@#1\endcsname
61 true \else false \fi }}
62 \def\mplibcodeinherit#1{%
63 \ifcsname minimp@switch@#1\endcsname
64 \newmetapostenvironment[jobname='\jobname']{@mplibcode}
65 \let\mplibcode=\@mplibcode
66 \let\endmplibcode=\@mplibcode
67 \else
68 \let\mplibcode=\metapost
69 \let\endmplibcode=\endmetapost
70 \fi}
71 \mplibcodeinherit{disable}
72 \def\mplibsetformat#1{\directlua{
73 require 'minim-mp'.default_format = '#1.mp' }}
74 \def\mplibnumbersystem#1{\directlua{
75 require 'minim-mp'.default_math = '#1' }}
76 \newcommand\everymplib[2][0]{%
77 \everymp{#1}{pre}{mp}{defaultfont:="\mnm@normalfont";#2}}
78 \newcommand\everyendmplib[2][0]{%
79 \everymp{#1}{post}{mp}{#2}}
80 } \ProcessOptions*
81
82 \let\minimp@switch@@enable=\relax
83 \let\minimp@switch@@enabled=\relax
84 \let\minimp@switch@@true=\relax
85 \let\minimp@switch@@yes=\relax
86
87