1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
|
%\DocumentMetadata{ uncompress }
\ifnum\outputmode > 0
\documentclass{article}
\else
\documentclass[dvipdfmx]{article}
\fi
\usepackage{fontspec}
\setmainfont{latin modern roman}
\usepackage{luamplib}
\usepackage{graphicx,xcolor}
\everymplib{ beginfig(0); }
\everyendmplib{ endfig; }
\mpliblegacybehavior{true}%
\begin{document}
\tracingcommands1
A%
\begin{mplibcode}
%% test all printable ascii chars in comments
%% ( 2 < F P Z d n x
%% ) 3 = G Q [ e o y
%% * 4 > H R \ f p z
%% ! + 5 ? I S ] g q {
%% " , 6 @ J T ^ h r |
%% # - 7 A K U _ i s }
%% $ . 8 B L V ` j t ~
%% % / 9 C M W a k u DEL
%% & 0 : D N X b l v
%% ´ 1 ; E O Y c m w
fill fullcircle scaled 20; %% actual <tab> to make sure it works
\end{mplibcode}%
B\par
\everymplib{}\everyendmplib{}% reset toks
A%
\begin{mplibcode}
verbatimtex \lower.2em etex
beginfig(0);
draw origin--(1cm,0) withcolor \mpcolor{teal};
draw btex g etex withcolor \mpcolor{orange};
draw btex\tracingcommands0
multi%
\begin{huge}line\end{huge}
texcode
with \%
etex shifted (10,0);
draw bbox currentpicture;
endfig;
beginfig(18);
numeric u;
u = 1cm;
draw (0,2u)--(0,0)--(4u,0);
pickup pencircle scaled 1pt;
draw (0,0){up}
for i=1 upto 8: ..(i/2,sqrt(i/2))*u endfor;
label.lrt(btex $\sqrt x$ etex, (3,sqrt 3)*u);
label.bot(btex $x$ etex, (2u,0));
label.lft(btex $y$ etex, (0,u));
endfig;
\end{mplibcode}%
B\par
A%
\begin{mplibcode}
beginfig(2);
numeric u; u=1cm;
z1=-z2=(-u,0);
for i = 1 upto 3:
draw z1..(0, i*u)..z2;
label.top(TEX("$e_{" & decimal(i) & "}$"), (0, i*u))
withcolor \mpcolor{red!70!blue};
endfor;
endfig;
\end{mplibcode}%
B\par\mplibforcehmode
\mplibcodeinherit{enable}%
\mplibglobaltextext{enable}%
\everymplib{ beginfig(0);}\everyendmplib{ endfig;}%
\begin{mplibcode}
label(btex $\sqrt{2}$ etex, origin);
draw fullcircle scaled 20;
picture pic; pic := currentpicture;
\end{mplibcode}%
\begin{mplibcode}
currentpicture := pic scaled 2;
\end{mplibcode}%
\mplibnoforcehmode
\everymplib{}\everyendmplib{}%
\mplibcodeinherit{disable}%
\mplibglobaltextext{disable}\par
\mplibsetformat{metafun}%
\begin{mplibcode}
message "Hello World!";
verbatimtex \moveright 0.4\hsize etex
beginfig(0);
path p; p:= fullcircle scaled 2cm yshifted .5cm;
fill p withcolor transparent("normal", 0.5, red);
fill p rotated 120 withcolor transparent("normal", 0.5, green);
fill p rotated 240 withcolor transparent("normal", 0.5, blue);
endfig;
verbatimtex \leavevmode etex
picture p; p := btex MetaPost etex scaled 2;
beginfig(1);
linear_shade(bbox p,0,blue,.7white);
draw p withcolor white;
endfig;
verbatimtex \kern10pt etex
beginfig(2);
circular_shade(bbox p,0,blue,.7white);
draw p withcolor white;
endfig;
\end{mplibcode}%
\newbox\mympbox
\def\prependtomplibbox{\global\setbox\mympbox}%
\begin{mplibcode}
%verbatimtex \global\setbox\mympbox etex
beginfig(0);
breadth=.667\mpdim\linewidth;
height=2pt;
x1=0; x2=x6=.333x4; x5=x3=.667x4;
x4=breadth;
y1=y4=height/2; y2=y3=height; y5=y6=0;
fill z1--z2--z3--z4--z5--z6--cycle;
endfig;
\end{mplibcode}%
\copy\mympbox
\copy\mympbox
\copy\mympbox
\copy\mympbox
\mplibnoforcehmode
\mplibnumbersystem{double}%
\begin{mplibcode}
beginfig(0);
u := 10**5*(10**-4);
draw unitsquare scaled u;
endfig;
\end{mplibcode}%
\mplibsetformat{plain}%
\begin{mplibcode}
input graph;
beginfig(0);
draw begingraph(100,100);
gdraw (10,10)--(30,35)--(50,25)--(70,80)--(90,90);
autogrid(otick.bot,);
for y=20,40,60,80:
grid.lft(format("%e",1000y), y) withcolor .85white;
endfor
endgraph;
endfig;
\end{mplibcode}%
\mplibtextextlabel{enable}%
\begin{mplibcode}
beginfig(0);
dotlabel.rt("$\sqrt2$",origin);
endfig;
\end{mplibcode}%
\leavevmode
\begin{mplibcode}
D := sqrt(2)**7;
beginfig(0);
draw fullcircle scaled D;
VerbatimTeX("\gdef\Dia{" & decimal D & "}");
endfig;
\end{mplibcode}%
diameter:\Dia bp.%
\begin{mplibcode}
vardef rotatedlabel@#(expr str, loc, angl) =
draw thelabel@#(str, loc) rotatedaround(loc, angl)
enddef;
beginfig(1);
rotatedlabel.top(textext("Rotated!"), origin, 45);
endfig;
\end{mplibcode}%
\par
\begin{mplibcode}
beginfig(1)
draw mplibgraphictext "\bfseries Funny$\sqrt{2}$"
fakebold 2 % fontspec option
drawcolor blue fillcolor "red!50" % l3color expression
scaled 3 rotated 30 ;
picture p;
p:=mplibgraphictext "\bfseries\itshape xyz";
draw p scaled 3 shifted (40,0);
endfig;
\end{mplibcode}%
\par
\mplibsetformat{metafun}%
\begin{mplibcode}
beginfig(1)
fill unitsquare xyscaled (\mpdim\textwidth,1cm)
withshademethod "linear"
withshadevector (0,1)
withshadestep (
withshadefraction .5
withshadecolors (red,"blue!50")
)
withshadestep (
withshadefraction 1
withshadecolors ("blue!50",green)
)
;
endfig;
\end{mplibcode}%
\leavevmode
\mpfig
picture Q, u, e;
Q := mplibglyph "Q" of "texgyrepagella-bolditalic.otf" scaled .1;
u := mplibglyph "u" of "texgyrepagella-bolditalic.otf" scaled .1 shifted lrcorner Q;
e := mplibglyph "e" of "texgyrepagella-bolditalic.otf" scaled .1 shifted lrcorner u;
i:=0;
totallen := length Q + length u + length e;
for pic=Q, u, e:
for item within pic:
i:=i+1;
fill pathpart item
if i < totallen: withpostscript "collect"; fi
endfor
endfor
withshademethod "linear"
withshadedirection (0.5,2.5)
withshadecolors (.7red,.7yellow)
;
\endmpfig
\everymplib[@mpfig]{ drawoptions(withcolor mplibrgbtexcolor "olive"); }%
\mpfig* input boxes \endmpfig
\mpfig circleit.a(btex\tracingcommands0 Box 1 etex); drawboxed(a); \endmpfig
\def\mpfiginstancename{mympfig}%
\mpfig
draw mpliboutlinetext.b ("$\displaystyle\frac{1}{1-x^2}$")
(withcolor .6[red,white])
(withpen pencircle scaled .2 withcolor red)
scaled 4 ;
\endmpfig
\par
\mpfig
draw mpliboutlinetext.r
("Question")
( withpen pencircle scaled .3 )
(
withshademethod "linear"
withshadedirection (2.5, 0.5)
withshadecolors(red, blue)
)
scaled 4;
\endmpfig
\par\leavevmode
\mppattern{mypatt}
\mpfig
picture q;
q := btex Q etex;
fill bbox q withcolor .8[red,white];
draw q withcolor .8red;
\endmpfig
\endmppattern
\mpfig
fill fullcircle scaled 100 withpostscript "collect";
draw unitsquare shifted - center unitsquare scaled 45
withpattern "mypatt"
withpostscript "evenodd"
;
\endmpfig
\begin{mppattern}{pattuncolored}
[
colored = false,
matrix = "slanted .3 rotated 30",
]
\tiny\TeX
\end{mppattern}\relax
\mpfig
picture tex;
tex = mpliboutlinetext.p ("\bfseries \TeX");
for i=1 upto mpliboutlinenum:
j:=0;
for item within mpliboutlinepic[i]:
j:=j+1;
draw pathpart item scaled 10
if j < length mpliboutlinepic[i]:
withpostscript "collect"
else:
withpattern "pattuncolored"
withfademethod "linear"
withfadebbox (10 llcorner mpliboutlinepic[i], 10 urcorner mpliboutlinepic[i])
withpen pencircle scaled 1/2
withcolor (i/4)[red,blue]
fi;
endfor
endfor
\endmpfig
\par\leavevmode
\mpfig
picture mill; mill = btex \includegraphics[width=100bp]{mill} etex;
draw mill;
mill := mill shifted 125right;
draw mill
withfademethod "circular"
withfadecenter (center mill, center mill)
withfaderadius (20, abs(lrcorner mill - llcorner mill)/2)
withfadeopacity (1, 0)
;
\endmpfig
\par
\def\test#1{%
\mpfig
fill unitsquare shifted -center unitsquare scaled 200
withshademethod "linear"
withshadecolors (.3[red,white], .3[blue,white])
;
label( btex MetaPost etex scaled 3, origin) ;
draw image(
fill fullcircle scaled 100 shifted 25left
withcolor .8white
withtransparency (2,1)
;
fill fullcircle scaled 100 shifted 25right
withcolor .8white
withtransparency (2,1)
;
)
asgroup "#1"
withtransparency (1,.5)
;
currentpicture := currentpicture scaled 3/4;
\endmpfig
}%
\hbox{\test{isolated,knockout}\,\test{isolated}\vbox to\MPheight{\vss\hbox{~isolated}\vss}}%
\hbox{\test{knockout}\,\test{}}%
\hbox to\MPwidth{\hss knockout\hss}%
\tracingcommands0
\vskip 2\baselineskip
\mplibcodeinherit{disable}%
\everymplib[instanceOne]{beginfig(1);}
\everyendmplib[instanceOne]{endfig;}
\begin{mplibcode}[instanceOne]
picture TeX;
TeX := btex \TeX etex;
a := 1cm;
draw fullcircle scaled a;
draw btex a circle with $d=a$ etex shifted (a,0);
draw TeX;
\end{mplibcode}%
Current instance name is: \currentmpinstancename \vskip 2\baselineskip
\begin{mplibcode}[instanceTwo]
beginfig(1);
if not known a:
draw btex code is not inherited from an instance with a different name etex;
else:
errmessage("Variable was inherited from a different instance");
fi;
endfig;
\end{mplibcode}%
Current instance name is: \currentmpinstancename \vskip 2\baselineskip
\begin{mplibcode}
beginfig(1);
if not known a:
draw btex code is not inherited if instance name is not listed etex;
else:
errmessage("Variable was inherited from a different instance");
fi;
a := 1cm;
endfig;
\end{mplibcode}%
Current instance name is: \currentmpinstancename (should be empty) \vskip 2\baselineskip
\begin{mplibcode}
beginfig(1);
if not known a:
draw btex code is not inherited if mplibcodeinherit is disabled and instance name is not explicitly set etex;
else:
errmessage("Variable was inherited when code inheritance is turned off and instance name is not set");
fi;
endfig;
\end{mplibcode}%
Current instance name is: \currentmpinstancename (should be empty) \vskip 2\baselineskip
\begin{mplibcode}[instanceOne]
draw unitsquare scaled a;
draw btex a square with side $=a$, inherited from the same instance etex shifted (3/2a, 1/2a);
draw TeX;
\end{mplibcode}%
Current instance name is: \currentmpinstancename \vskip 2\baselineskip
\end{document}
|