1
2
3
4\setupbodyfont
5 [plex,4pt]
6
7\setuppapersize
8 [A3,landscape]
9
10\setuplayout
11 [width=middle,
12 height=middle,
13 header=0pt,
14 footer=0pt,
15 backspace=5mm,
16 topspace=5mm]
17
18\definelayer
19 [page]
20 [width=\textwidth,
21 height=\textheight]
22
23\setupbackgrounds
24 [page]
25 [background=color,
26 backgroundcolor=middlegray]
27
28\setuptyping
29 [before=,after=]
30
31\usemodule
32 [abbreviationslogos]
33
34\startbuffer[style]
35 \setupbodyfont
36 [plex]
37 \setuplayout
38 [width=middle,
39 height=middle,
40 margin=1cm]
41 \setupcolors
42 [textcolor=white]
43 \usemodule
44 [abbreviationslogos]
45 \setupwhitespace
46 [big]
47 \setuphead
48 [chapter]
49 [style=\bfc]
50\stopbuffer
51
52\startbuffer[intro]
53
54 \starttitle[title={Using \CONTEXT}]
55
56 The \CONTEXT\ macro package is more than just a \TEX\ processor,
57 various input is possible, some we show here. An example of a
58 method not shown here is fetching data from a database. The
59 various input methods can be combined, so depending on what you
60 need you can mix \TEX\ (for typesetting text), \METAPOST\ (for
61 producing graphics) or \LUA\ (as language for manipulating
62 data.
63
64 All these methods are quite efficient and always have access to
65 the full power of the typesetting engine.
66
67 When you use \CONTEXT\ with \LUAMETATEX, you get a reasonable
68 small self contained component that can be used in workflows
69 that need quality rendering. The ecosystem is rather future
70 proof too.
71
72 The \CONTEXT\ macro package has been around for decades and
73 evolved from \MKII, to \MKIV\ and now \LMTX. The development
74 team has always been involved in the development of engines
75 like \PDFTEX, \LUATEX\ and \LUAMETATEX. There is an active
76 mailing list and there are \CONTEXT\ meetings.
77
78 \stoptitle
79
80\stopbuffer
81
82\startbuffer[tex]
83\starttext
84
85 \starttitle[title={Some \TEX}]
86
87 Just an example.
88
89 \starttabulate[cc]
90 \NC first 1 \NC last 1 \NC \NR
91 \NC first 2 \NC last 2 \NC \NR
92 \stoptabulate
93
94 \stoptitle
95
96\stoptext
97\stopbuffer
98
99\startbuffer[xml]
100\startbuffer[demo]
101<?xml version="1.0"?>
102<document>
103 <title>Some XML<title>
104 <p>Just an example.<p>
105 <table>
106 <r> <c>first 1<c> <c>last 1<c> <r>
107 <r> <c>first 2<c> <c>last 2<c> <r>
108 <table>
109<document>
110\stopbuffer
111
112\startxmlsetups xml:basics
113 \xmlsetsetup{#1}{titleptable}{xml:*}
114\stopxmlsetups
115\startxmlsetups xml:title
116 \title{\xmltext{#1}{.}}
117\stopxmlsetups
118\startxmlsetups xml:p
119 \xmlflush{#1}\par
120\stopxmlsetups
121\startxmlsetups xml:table
122 \starttabulate[cc]
123 \xmlfilter{#1}{rcommand(xml:r)}
124 \stoptabulate
125\stopxmlsetups
126\startxmlsetups xml:r
127 \NC \xmlfilter{#1}{ccommand(xml:c)} \NR
128\stopxmlsetups
129\startxmlsetups xml:c
130 \xmlflush{#1} \NC
131\stopxmlsetups
132
133\xmlregistersetup{xml:basics}
134
135\starttext
136 \xmlprocessbuffer{demo}{demo}{}
137\stoptext
138\stopbuffer
139
140\startbuffer[lua]
141\startluacode
142 local tmp = {
143 { a = "first 1", b = "last 1" },
144 { b = "last 2", a = "first 2" },
145 }
146
147
148
149 context.starttext()
150
151 context.starttitle { title = "Some Lua" }
152
153 context("Just an example.") context.par()
154
155 context.starttabulate { "|c|c|" }
156 for i=1,#tmp do
157 local t = tmp[i]
158 context.NC()
159 context(t.a) context.NC()
160 context(t.b) context.NC()
161 context.NR()
162 end
163 context.stoptabulate()
164
165 context.stoptitle()
166
167 context.stoptext()
168\stopluacode
169\stopbuffer
170
171\startbuffer[mp]
172\startMPpage
173 draw textext("\bf Some \MetaPost")
174 xsized 4cm
175 rotated(45)
176 withcolor "white" ;
177
178 draw textext("\bs\strut in \ConTeXt")
179 xsized 5cm
180 shifted (0,-40mm)
181 withcolor "white" ;
182
183 draw fullcircle
184 scaled 6cm
185 dashed evenly
186 withcolor "gray" ;
187\stopMPpage
188\stopbuffer
189
190\startbuffer[csv]
191\startluacode
192 local tmp = [[
193 first,second
194 first 1,last 1
195 first 2,last 2
196 ]]
197
198
199
200 local mycsvsplitter = utilities.parsers.rfc4180splitter()
201 local list, names = mycsvsplitter(tmp,true)
202
203 context.starttext()
204
205 context.starttitle { title = "Some CSV" }
206
207 context("Just an example.") context.par()
208
209 context.starttabulate { "|c|c|" }
210 for i=1,#list do
211 local l = list[i]
212 context.NC()
213 context(l[1]) context.NC()
214 context(l[2]) context.NC()
215 context.NR()
216 end
217 context.stoptabulate()
218
219 context.stoptitle()
220
221 context.stoptext()
222\stopluacode
223\stopbuffer
224
225\startbuffer[json]
226\startluacode
227 require("util-jsn")
228
229
230
231 local str = [[ {
232 "title": "Some JSON",
233 "text" : "Just an example.",
234 "data" : [
235 { "a" : "first 1", "b" : "last 1" },
236 { "b" : "last 2", "a" : "first 2" }
237 ]
238 } ]]
239
240 local tmp = utilities.json.tolua(str)
241
242 context.starttext()
243
244 context.starttitle { title = tmp.title }
245
246 context(tmp.text) context.par()
247
248 context.starttabulate { "|c|c|" }
249 for i=1,#tmp.data do
250 local d = tmp.data[i]
251 context.NC()
252 context(d.a) context.NC()
253 context(d.b) context.NC()
254 context.NR()
255 end
256 context.stoptabulate()
257
258 context.stoptitle()
259
260 context.stoptext()
261\stopluacode
262\stopbuffer
263
264\startbuffer[mkxi]
265
266
267\startbuffer[demo]
268\starttext
269 \starttitle[title={Some template}]
270
271 Just an example. \blank
272
273 \startlinecorrection
274 \bTABLE
275 <?lua for i=1,20 do ?>
276 \bTR
277 <?lua for j=1,5 do ?>
278 \bTD
279 cell (<?lua inject(i) ?>,<?lua inject(j) ?>)
280 is <?lua inject(variables.text or "unset") ?>
281 \eTD
282 <?lua end ?>
283 \eTR
284 <?lua end ?>
285 \eTABLE
286 \stoplinecorrection
287
288 \stoptitle
289\stoptext
290
291\stopbuffer
292
293\savebuffer[file=demo.mkxi,prefix=no,list=demo]
294
295
296
297\startluacode
298 document.variables.text = "set"
299\stopluacode
300
301\input{demo.mkxi}
302\stopbuffer
303
304\definemeasure[blobwidth] [\textwidth43mm]
305\definemeasure[blobscale] [\textwidth43mm4mm]
306\definemeasure[blobheight][\textheight22mm]
307
308\startbuffer[everything]
309
310\setlayerframed
311 [page]
312 [preset=lefttop]
313 [align=normal,
314 offset=2mm,
315 strut=no,
316 frame=off,
317 height=\measure{blobheight},
318 width=\measure{blobwidth},
319 background=color,
320 backgroundcolor=darkgray,
321 foregroundcolor=white]
322 {\doifelsemode{verbose}{\typebuffer[intro]}{\typesetbuffer[style,intro][frame=on,width=\measure{blobscale}]}}
323
324\setlayerframed
325 [page]
326 [preset=lefttop,
327 hoffset=4mm,
328 x=\measure{blobwidth}]
329 [align=normal,
330 offset=2mm,
331 strut=no,
332 frame=off,
333 height=\measure{blobheight},
334 width=\measure{blobwidth},
335 background=color,
336 backgroundcolor=darkred,
337 foregroundcolor=white]
338 {\doifelsemode{verbose}{\typebuffer[tex]}{\typesetbuffer[style,tex][frame=on,width=\measure{blobscale}]}}
339
340\setlayerframed
341 [page]
342 [preset=righttop,
343 hoffset=4mm,
344 x=\measure{blobwidth}]
345 [align=normal,
346 offset=2mm,
347 strut=no,
348 frame=off,
349 height=\measure{blobheight},
350 width=\measure{blobwidth},
351 background=color,
352 backgroundcolor=darkblue,
353 foregroundcolor=white]
354 {\doifelsemode{verbose}{\typebuffer[xml]}{\typesetbuffer[style,xml][frame=on,width=\measure{blobscale}]}}
355
356\setlayerframed
357 [page]
358 [preset=righttop]
359 [align=normal,
360 offset=2mm,
361 strut=no,
362 frame=off,
363 height=\measure{blobheight},
364 width=\measure{blobwidth},
365 background=color,
366 backgroundcolor=darkgreen,
367 foregroundcolor=white]
368 {\doifelsemode{verbose}{\typebuffer[lua]}{\typesetbuffer[style,lua][frame=on,width=\measure{blobscale}]}}
369
370\setlayerframed
371 [page]
372 [preset=lefttop,
373 voffset=4mm,
374 y=\measure{blobheight}]
375 [align=normal,
376 offset=2mm,
377 strut=no,
378 frame=off,
379 height=\measure{blobheight},
380 width=\measure{blobwidth},
381 background=color,
382 backgroundcolor=darkcyan,
383 foregroundcolor=white]
384 {\doifelsemode{verbose}{\typebuffer[mp]}{\typesetbuffer[style,mp][frame=on,width=\measure{blobscale}]}}
385
386\setlayerframed
387 [page]
388 [preset=lefttop,
389 hoffset=4mm,
390 x=\measure{blobwidth},
391 voffset=4mm,
392 y=\measure{blobheight}]
393 [align=normal,
394 offset=2mm,
395 strut=no,
396 frame=off,
397 height=\measure{blobheight},
398 width=\measure{blobwidth},
399 background=color,
400 backgroundcolor=darkmagenta,
401 foregroundcolor=white]
402 {\doifelsemode{verbose}{\typebuffer[csv]}{\typesetbuffer[style,csv][frame=on,width=\measure{blobscale}]}}
403
404\setlayerframed
405 [page]
406 [preset=righttop,
407 hoffset=4mm,
408 x=\measure{blobwidth},
409 voffset=4mm,
410 y=\measure{blobheight}]
411 [align=normal,
412 offset=2mm,
413 strut=no,
414 frame=off,
415 height=\measure{blobheight},
416 width=\measure{blobwidth},
417 background=color,
418 backgroundcolor=darkyellow,
419 foregroundcolor=white]
420 {\doifelsemode{verbose}{\typebuffer[json]}{\typesetbuffer[style,json][frame=on,width=\measure{blobscale}]}}
421
422\setlayerframed
423 [page]
424 [preset=righttop,
425 voffset=4mm,
426 y=\measure{blobheight}]
427 [align=normal,
428 offset=2mm,
429 strut=no,
430 frame=off,
431 height=\measure{blobheight},
432 width=\measure{blobwidth},
433 background=color,
434 backgroundcolor=darkorange,
435 foregroundcolor=white]
436 {\doifelsemode{verbose}{\typebuffer[mkxi]}{\typesetbuffer[style,mkxi][frame=on,width=\measure{blobscale}]}}
437
438\startstandardmakeup
439 \tightlayer[page]
440\stopstandardmakeup
441
442\stopbuffer
443
444\starttext
445
446{\enablemode[verbose] \getbuffer[everything]}
447 \getbuffer[everything]
448
449\stoptext
450
451 |