Debian Codegraph @

texmf-dist/doc/luatex/luamplib/test-luamplib-plain.tex

raw
1 \input luaotfload.sty
2 \ifnum\outputmode>0
3 \font\myfont={file:lmroman10-bold.otf} at 10pt
4 \else
5 \let\myfont=\bf
6 \fi
7 \input miniltx
8 \input color
9 \definecolor{orange}{rgb}{1,.5,0}
10 \input luamplib.sty
11 \mpliblegacybehavior{true}%
12 \everymplib{ beginfig(0); }\everyendmplib{ endfig; }
13 \tracingcommands1
14 A%
15 \mplibcode
16 %% test all printable ascii chars in comments
17 %% ( 2 < F P Z d n x
18 %% ) 3 = G Q [ e o y
19 %% * 4 > H R \ f p z
20 %% ! + 5 ? I S ] g q {
21 %% " , 6 @ J T ^ h r |
22 %% # - 7 A K U _ i s }
23 %% $ . 8 B L V ` j t ~
24 %% % / 9 C M W a k u DEL
25 %% & 0 : D N X b l v
26 %% ยด 1 ; E O Y c m w
27 fill fullcircle scaled 20;
28 \endmplibcode
29 B\par
30 \everymplib{}\everyendmplib{}% reset toks
31 A%
32 \mplibcode
33 verbatimtex \lower.2em etex
34 beginfig(0);
35 draw origin--(1cm,0) withcolor red;
36 draw btex g etex withcolor blue;
37 draw btex\tracingcommands0 multi
38 line
39 tex code
40 100 \% color
41 etex shifted (20,0);
42 draw textext "\tracingcommands0 textext 50\% color" shifted (10,-10) withcolor .5white;
43 draw bbox currentpicture;
44 endfig;
45
46 verbatimtex B\endgraf A etex;
47 beginfig(18);
48 numeric u;
49 u = 1cm;
50 draw (0,2u)--(0,0)--(4u,0);
51 pickup pencircle scaled 1pt;
52 draw (0,0){up}
53 for i=1 upto 8: ..(i/2,sqrt(i/2))*u endfor;
54 label.lrt(btex $\sqrt x$ etex, (3,sqrt 3)*u);
55 label.bot(btex $x$ etex, (2u,0));
56 label.lft(btex $y$ etex, (0,u));
57 endfig;
58 \endmplibcode
59 B\par
60 A%
61 \mplibcode
62 beginfig(2);
63 numeric u; u=1cm;
64 z1=-z2=(-u,0);
65 for i = 1 upto 3:
66 draw z1..(0, i*u)..z2;
67 label.top(TEX("$e_{" & decimal(i) & "}$"), (0, i*u)) withcolor \mpcolor{orange};
68 endfor;
69 endfig;
70 \endmplibcode
71 B\par\mplibforcehmode
72 \mplibcodeinherit{enable}%
73 \mplibglobaltextext{enable}%
74 \everymplib{ beginfig(0);}\everyendmplib{ endfig;}%
75 \mplibcode
76 label(btex $\sqrt{2}$ etex, origin);
77 draw fullcircle scaled 20;
78 picture pic; pic := currentpicture;
79 \endmplibcode
80 \mplibcode
81 currentpicture := pic scaled 2;
82 \endmplibcode
83 \mplibnoforcehmode
84 \everymplib{}\everyendmplib{}%
85 \mplibcodeinherit{disable}%
86 \mplibglobaltextext{disable}\par
87 \mplibsetformat{metafun}%
88 \mplibcode
89 message "Hello World!";
90 verbatimtex \moveright 0.4\hsize etex
91 beginfig(0);
92 path p; p:= fullcircle scaled 2cm yshifted .5cm;
93 fill p withcolor transparent("normal", 0.5, red);
94 fill p rotated 120 withcolor transparent("normal", 0.5, green);
95 fill p rotated 240 withcolor transparent("normal", 0.5, blue);
96 endfig;
97 verbatimtex \leavevmode etex
98 picture p; p := btex MetaPost etex scaled 2;
99 beginfig(1);
100 linear_shade(bbox p,0,blue,.7white);
101 draw p withcolor white;
102 endfig;
103 verbatimtex \kern10pt etex
104 beginfig(2);
105 circular_shade(bbox p,0,blue,.7white);
106 draw p withcolor white;
107 endfig;
108 \endmplibcode
109
110 \newbox\mympbox
111 \def\prependtomplibbox{\global\setbox\mympbox}%
112 \mplibcode
113 %verbatimtex \global\setbox\mympbox etex
114 beginfig(0);
115 breadth=.667\mpdim\hsize;
116 height=2pt;
117 x1=0; x2=x6=.333x4; x5=x3=.667x4;
118 x4=breadth;
119 y1=y4=height/2; y2=y3=height; y5=y6=0;
120 fill z1--z2--z3--z4--z5--z6--cycle;
121 endfig;
122 \endmplibcode
123 \copy\mympbox
124 \copy\mympbox
125 \copy\mympbox
126 \copy\mympbox
127
128 \mplibnoforcehmode
129 \mplibnumbersystem{double}%
130 \mplibcode
131 beginfig(0);
132 u := 10**5*(10**-4);
133 draw unitsquare scaled u;
134 endfig;
135 \endmplibcode
136 \mplibsetformat{plain}%
137 \mplibcode
138 input graph;
139 beginfig(0);
140 draw begingraph(100,100);
141 gdraw (10,10)--(30,35)--(50,25)--(70,80)--(90,90);
142 autogrid(otick.bot,);
143 for y=20,40,60,80:
144 grid.lft(format("%e",1000y), y) withcolor .85white;
145 endfor
146 endgraph;
147 endfig;
148 \endmplibcode
149 \mplibtextextlabel{enable}%
150 \mplibcode
151 beginfig(0);
152 dotlabel.rt("$\sqrt2$",origin);
153 endfig;
154 \endmplibcode
155 \leavevmode
156 \mplibcode
157 D := sqrt(2)**7;
158 beginfig(0);
159 draw fullcircle scaled D;
160 VerbatimTeX("\gdef\Dia{" & decimal D & "}");
161 endfig;
162 \endmplibcode
163 diameter:\Dia bp.%
164 \mplibcode
165 vardef rotatedlabel@#(expr str, loc, angl) =
166 draw thelabel@#(str, loc) rotatedaround(loc, angl)
167 enddef;
168
169 beginfig(1);
170 rotatedlabel.top(textext "Rotated!", origin, 45);
171 endfig;
172 \endmplibcode
173
174 \vfill
175 \penalty-9999
176
177 \mplibcode
178 beginfig(1) % in dvi mode, not work for type1 font
179 draw mplibgraphictext "\bf Funny$\sqrt{2}$"
180 fakebold 2 % fontspec option
181 drawcolor blue fillcolor .5[red,white]
182 scaled 3 rotated 30 ;
183 draw mplibgraphictext "\it xyz"
184 fillcolor .7white
185 scaled 3 shifted (40,0);
186 endfig;
187 \endmplibcode
188 \par
189 %\mplibsetformat{metafun}%
190 \mplibcode
191 beginfig(1)
192 fill unitsquare xscaled \mpdim\hsize yscaled 1cm
193 withshadingmethod "linear"
194 withshadingvector (0,1)
195 withshadingstep (
196 withshadingfraction .5
197 withshadingcolors (red,blue)
198 )
199 withshadingstep (
200 withshadingfraction 1
201 withshadingcolors (blue,green)
202 )
203 ;
204 endfig;
205 \endmplibcode
206 \leavevmode
207 \mpfig
208 color yellow; yellow = (1,1,0);
209 picture Q, u, e;
210 Q := mplibglyph "Q" of "texgyrepagella-bolditalic.otf" scaled .1;
211 u := mplibglyph "u" of "texgyrepagella-bolditalic.otf" scaled .1 shifted lrcorner Q;
212 e := mplibglyph "e" of "texgyrepagella-bolditalic.otf" scaled .1 shifted lrcorner u;
213 i:=0;
214 totallen := length Q + length u + length e;
215 for pic=Q, u, e:
216 for item within pic:
217 i:=i+1;
218 fill pathpart item
219 if i < totallen: withpostscript "collect"; fi
220 endfor
221 endfor
222 withshadingmethod "linear"
223 withshadingdirection (0.5,2.5)
224 withshadingcolors (.7red,.7yellow)
225 withshadingstroke "yes"
226 withpen pencircle scaled 2 withcolor 2/3red
227 ;
228 \endmpfig
229 \everymplib[@mpfig]{ drawoptions(withcolor mplibrgbtexcolor"orange"); }%
230 \mpfig* input boxes \endmpfig
231 \mpfig circleit.a(btex\tracingcommands0 Box 1 etex); drawboxed(a); \endmpfig
232 \def\mpfiginstancename{mympfig}%
233 \mpfig
234 draw mpliboutlinetext.b ("$\overbrace{x+\cdots+x}^k$")
235 (withcolor .6[red,white])
236 (withpen pencircle scaled .2 withcolor red)
237 scaled 3 ;
238 \endmpfig
239 \par
240 \mpfig
241 draw mpliboutlinetext.r
242 ("Question")
243 ( withpen pencircle scaled .3 )
244 (
245 withshadingmethod "linear"
246 withshadingdirection (2.5, 0.5)
247 withshadingcolors(red, blue)
248 )
249 scaled 4;
250 \endmpfig
251 \par\leavevmode
252 \mppattern{mypatt}
253 \mpfig
254 picture q;
255 q := btex Q etex;
256 fill bbox q withcolor .8[red,white];
257 draw q withcolor .8red;
258 \endmpfig
259 \endmppattern
260 \mpfig
261 fill fullcircle scaled 100 withpostscript "collect";
262 fill unitsquare shifted - center unitsquare scaled 45
263 withmppattern "mypatt"
264 withpostscript "evenodd"
265 ;
266 \endmpfig
267 \mppattern{pattuncolored}
268 [
269 colored = false,
270 matrix = "slanted .3 rotated 30",
271 ]
272 \fiverm\TeX
273 \endmppattern
274 \mpfig
275 picture tex;
276 tex = mpliboutlinetext.p ("\bf \TeX");
277 draw image(
278 for i=1 upto mpliboutlinenum:
279 j:=0;
280 for item within mpliboutlinepic[i]:
281 j:=j+1;
282 filldraw pathpart item scaled 10
283 if j < length mpliboutlinepic[i]:
284 withpostscript "collect"
285 else:
286 withmppattern "pattuncolored"
287 withpen pencircle scaled 1/2
288 withcolor (i/4)[red,blue]
289 fi;
290 endfor
291 endfor
292 )
293 withfademethod "linear"
294 ;
295 \endmpfig
296 \par\leavevmode
297 \mpfig
298 fill fullcircle scaled 125 withcolor 2/3[blue,white];
299 fill fullcircle scaled 80 withcolor 2/3[red,white];
300 draw image(
301 draw (left--right) rotated 45 scaled 50
302 withpen pencircle scaled 20
303 ;
304 draw (left--right) rotated -45 scaled 50
305 withpen pencircle scaled 20
306 ;
307 )
308 asgroup ""
309 withgroupname "testTRgroup"
310 withtransparency (1, .3)
311 ;
312 \endmpfig
313 \mpfig
314 fill fullcircle scaled 125 withcolor 2/3[red,white];
315 fill fullcircle scaled 80 withcolor 2/3[blue,white];
316 usemplibgroup "testTRgroup"
317 withfademethod "circular"
318 withfaderadius (0,60)
319 ;
320 \endmpfig
321 \mplibgroup{mytex}[matrix="rotated 15"] \TeX \endmplibgroup
322 \hbox to0pt{\hss\vrule width.5pt height5pt depth5pt\hss}%
323 \hbox to0pt{\hss\vrule width10pt height.25pt depth.25pt\hss}%
324 \usemplibgroup{mytex}%
325 \mpfig usemplibgroup "mytex"; draw (left--right) scaled 5; draw (up--down) scaled 5; \endmpfig
326 \par
327 \leavevmode
328 \mpfig
329 draw mplibgraphictext "\myfont MPLIB"
330 fakebold 1 fillcolor .7[white,blue] drawcolor .7blue scaled 7
331 withmppattern "pattuncolored" ;
332 \endmpfig
333 \mpfig
334 draw btex \myfont\TeX etex rotated 30 scaled 3
335 withshadingmethod "linear"
336 withshadingcolors (red,blue)
337 withshadingvector (0,1)
338 ;
339 \endmpfig
340
341 \leavevmode
342 \mppattern{p1}
343 \mpfig
344 fill fullcircle scaled 3
345 withcolor .7red
346 ;
347 \endmpfig
348 \endmppattern
349 \mppattern{p2}
350 \mpfig
351 fill fullcircle scaled 12
352 withmppattern "p1"
353 ;
354 \endmpfig
355 \endmppattern
356 \mpfig
357 fill fullcircle scaled 60
358 withmppattern "p2"
359 ;
360 \endmpfig
361 \mpfig
362 picture pic;
363 pic = mplibglyph "R" of "texgyrepagella-regular.otf" scaled 1/10;
364 mplibfillandstrokeglyph pic
365 slanted 0.25
366 withpen pencircle scaled 1
367 withmplibcolors ("orange", 2/3red)
368 ;
369 \endmpfig
370 \mpfig*
371 picture pic;
372 pic = image(fill fullcircle scaled 80; fill fullcircle scaled 80 shifted 40right);
373 \endmpfig
374 \mplibgroup{mymask}[asgroup="masking"]
375 \mpfig
376 label(btex \font\t=cmssbx10 at 20bp \t Meta etex scaled 2, center pic) withcolor 1;
377 \endmpfig
378 \endmplibgroup
379 \mpfig
380 fill bbox pic
381 withshadingmethod "linear"
382 withshadingcolors(3/4red,3/4blue)
383 ;
384 draw pic
385 withmaskinggroup "mymask"
386 withmaskingbgcolor 0.2
387 withcolor (red+blue)
388 ;
389 \endmpfig
390 \mpfig
391 mplibdrawglyph mplibglyph "R" of "cmr10.pfb" scaled 1/12 withcolor 2/3red;
392 mplibdrawglyph mplibglyph "R" of "cmss10.pfb" scaled 1/12 shifted 60right withcolor 2/3red;
393 \endmpfig
394 \tracingcommands0
395
396 \vskip 2\baselineskip
397 \mplibcodeinherit{disable}
398 \everymplib[instanceOne]{beginfig(1);}
399 \everyendmplib[instanceOne]{endfig;}
400
401 \mplibcode[instanceOne]
402 picture TeX;
403 TeX := btex \TeX etex;
404 a := 1cm;
405 draw fullcircle scaled a;
406 draw btex a circle with $d=a$ etex shifted (a,0);
407 draw TeX;
408 \endmplibcode
409 Current instance name is: \currentmpinstancename \vskip 2\baselineskip
410
411 \mplibcode[instanceTwo]
412 beginfig(1);
413 if not known a:
414 draw btex code is not inherited from an instance with a different name etex;
415 else:
416 errmessage("Variable was inherited from a different instance");
417 fi;
418 endfig;
419 \endmplibcode
420 Current instance name is: \currentmpinstancename \vskip 2\baselineskip
421
422 \mplibcode
423 beginfig(1);
424 if not known a:
425 draw btex code is not inherited if instance name is not listed etex;
426 else:
427 errmessage("Variable was inherited from a different instance");
428 fi;
429 a := 1cm;
430 endfig;
431 \endmplibcode
432 Current instance name is: \currentmpinstancename (should be empty) \vskip 2\baselineskip
433
434 \mplibcode
435 beginfig(1);
436 if not known a:
437 draw btex code is not inherited if mplibcodeinherit is disabled and instance name is not explicitly set etex;
438 else:
439 errmessage("Variable was inherited when code inheritance is turned off and instance name is not set");
440 fi;
441 endfig;
442 \endmplibcode
443 Current instance name is: \currentmpinstancename (should be empty) \vskip 2\baselineskip
444
445 \mplibcode[instanceOne]
446 draw unitsquare scaled a;
447 draw btex a square with side $=a$, inherited from the same instance etex shifted (3/2a, 1/2a);
448 draw TeX;
449 \endmplibcode
450 Current instance name is: \currentmpinstancename
451
452 \medskip
453 \centerline{*\qquad *\qquad * }
454 \medskip
455
456 \mpfig*
457 def myshading =
458 withshadingmethod "linear"
459 withshadingvector (2, 1)
460 withshadingcolors (red, blue)
461 enddef;
462 picture pic[];
463 pic1 = image(
464 fill fullcircle scaled 60 shifted 30right withoutcolor;
465 fill fullcircle scaled 60 withoutcolor;
466 ) ;
467 pic2 := image( draw pic1 myshading ) ;
468 \endmpfig
469
470 \setbox0\hbox{\def\mplibgroupname{mygrshpic}\mpfig draw pic2; \endmpfig}
471 \directlua{ luamplib.registergroup(0, "mygrshpic", { asgroup="" }) }
472 \leavevmode
473 \mpfig
474 usemplibgroup "mygrshpic"
475 withtransparency (1, 2/3) ;
476 \endmpfig
477 \mplibgroup{mygrshpic}[asgroup=""]
478 \mpfig
479 draw pic2 ;
480 \endmpfig
481 \endmplibgroup
482 \usemplibgroup{mygrshpic}
483
484 \leavevmode
485 \mpfig
486 usemplibgroup "mygrshpic"
487 withtransparency (1, 2/3) ;
488 \endmpfig
489 \mpfig % shading outside picture group
490 draw pic1
491 asgroup "off"
492 myshading
493 withtransparency (1, 2/3) ;
494 \endmpfig
495
496 \leavevmode
497 \mpfig % shading outside picture group
498 draw btex \bf\TeX etex scaled 5
499 asgroup "off"
500 myshading
501 withoutcolor
502 withtransparency (1, 2/3) ;
503 \endmpfig
504 \mpfig % shading outside picture non-group
505 draw btex \bf\TeX etex scaled 5
506 myshading
507 withtransparency (1, 2/3) ;
508 \endmpfig
509
510 this is the best:
511 \mplibgroup{myshading}
512 \mpfig
513 draw pic2
514 myshading ;
515 draw btex \bf\TeX etex scaled 5 shifted lrcorner pic2
516 myshading ;
517 \endmpfig
518 \endmplibgroup
519 \mpfig
520 usemplibgroup "myshading" asgroup "" withtransparency(1, 2/3) ;
521 \endmpfig
522 \bye