m-visual.mkiv /size: 23 Kb    last modification: 2021-10-28 13:51
1%D \module
2%D   [       file=m-visual,
3%D        version=2000.01.10,
4%D          title=\CONTEXT\ Extra Modules,
5%D       subtitle=Visualization and Faking,
6%D         author={Hans Hagen \& Ton Otten},
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14\unprotect
15
16%D Much will probably be replaced by \LUA\ based solutions which is
17%D rather trivial and fun doing. A lot here makes no sense any more,
18%D for instance whatsits are not used.
19
20%D This module collect a few more visual debugger features. I
21%D needed them for manuals and styles. The macros are documented
22%D in a my way document.
23
24\definecolor[fakerulecolor]     [black]
25\definecolor[fakebaselinecolor] [green]
26\definecolor[fakeparindentcolor][blue]
27
28\newif    \iffakebaseline \fakebaselinetrue
29\newif    \iffaketrigger  \faketriggerfalse
30\newdimen \fakerulewidth  \fakerulewidth=.2pt
31
32\unexpanded\def\fakerule#1%
33  {\strut
34   \begingroup
35   \ifx\fakerulecolor\relax
36     \directcolored[fr\recurselevel c]%
37   \else
38     \directcolored[fakerulecolor]%
39   \fi
40   \iffakebaseline
41     \vrule\s!height1.25\exheight\s!depth-.05\exheight\s!width#1%
42     \kern-#1%
43     \vrule\s!height-.05\exheight\s!depth .25\exheight\s!width#1%
44   \else
45     \vrule\s!height1.25\exheight\s!depth .25\exheight\s!width#1%
46   \fi
47   \endgroup
48   \allowbreak}
49
50\unexpanded\def\dorandomrecurse#1%
51  {\getrandomcount\scratchcounter{1}{#1}%
52   \dorecurse\scratchcounter}
53
54% can be used in hbox, so %'s are really needed
55
56\unexpanded\def\fakelines#1#2% min max / 3 10
57  {\fakeparindent
58   \scratchdimen\hsize
59   \advance\scratchdimen -\parindent
60   \fakerule\scratchdimen\break
61   \getrandomcount\scratchcounter{\ifcase0#1 3\else#1\fi}{\ifcase0#2 10\else#2\fi}%
62   \dorecurse\scratchcounter{\fakerule\hsize}%
63   \getrandomdimen\scratchdimen{.25\hsize}\hsize
64   \fakerule\scratchdimen
65   \par} % indeed
66
67\unexpanded\def\fakewords
68  {\ifvmode\fakeparindent\fi\onlyfakewords}
69
70\definepalet
71  [fakerule]
72  [fr1c=darkred,
73   fr2c=darkgreen,
74   fr3c=darkblue,
75   fr4c=darkyellow,
76   fr5c=darkgray,
77   fr6c=darkmagenta,
78   fr7c=darkcyan,
79   fr8c=darkorange]
80
81\unexpanded\def\onlyfakewords#1#2% min max / 10 40
82  {\dontleavehmode
83   \ifvmode\noindentation\fi
84   \getrandomcount\scratchcounter{\ifcase0#1 10\else#1\fi}{\ifcase0#2 40\else#2\fi}%
85   \dofakewords\scratchcounter
86   } % no \par
87
88\unexpanded\def\fakenwords#1#2% words seed
89  {\fakeparindent
90   \getrandomseed\fakedwordseed
91   \setrandomseed{\ifcase0#2 #1\else#2\fi}%
92   \dofakewords{#1}%
93   \setrandomseed\fakedwordseed
94   } % no \par
95
96\def\dofakewords#1%
97  {\bgroup
98   \dorecurse{#1}
99     {\iffaketrigger\signalcharacter\fi % so that e.g. line numbering works
100      \getrandomcount\scratchcounter{1}{5}%
101      \dorecurse\scratchcounter
102        {\getrandomdimen\scratchdimen{.5em}{1.25em}%
103         \fakerule\scratchdimen}%
104      \space}%
105   \removeunwantedspaces
106   \egroup}
107
108\def\doshowfakewords#1%
109  {\bgroup
110   \setuppalet[fakerule]%
111   \let\fakerulecolor\relax
112   \dorecurse{#1}
113     {\getrandomcount\scratchcounter{1}{5}%
114      \dorecurse\scratchcounter
115        {\getrandomdimen\scratchdimen{.5em}{1.25em}%
116         \color[fr\recurselevel c]{\fakerule\scratchdimen}}%
117      \space}%
118   \removeunwantedspaces
119   \egroup}
120
121\unexpanded\def\showfakewords
122  {\let\dofakewords\doshowfakewords}
123
124\unexpanded\def\fakeword
125  {\fakewords{1}{1}} % no \plusone
126
127\unexpanded\def\fakeparindent
128  {\noindent
129   \ifzeropt\parindent\else
130     \ifx\dofakedroppedcaps\relax
131       {\fakeparindentcolor
132        \vrule
133          \s!height \strutheight % not longer .5ex
134          \s!depth  \strutdepth  % not longer 0pt
135          \s!width  \parindent}%
136     \else
137       \dofakedroppedcaps \let\dofakedroppedcaps\relax
138     \fi
139%    \else
140%      \dontleavehmode
141   \fi}
142
143\let\dofakedroppedcaps\relax
144
145\unexpanded\def\fakedroppedcaps#1%
146  {\ifnum#1>0
147     \def\dofakedroppedcaps
148       {\setbox\scratchbox\hpack
149          {\setbox\scratchbox\hpack{W}%
150           \scratchdimen\dimexpr#1\lineheight-\lineheight+\dp\strutbox\relax
151           \vrule
152             \s!width#1\wd\scratchbox
153             \s!height\ht\scratchbox
154             \s!depth\scratchdimen}%
155        \ht\scratchbox\ht\strutbox
156        \dp\scratchbox\dp\strutbox
157        \hangindent\dimexpr\wd\scratchbox+.5\emwidth\relax
158        \wd\scratchbox\hangindent
159        \hangafter-#1%
160        \noindent
161        \llap{\fakeparindentcolor\box\scratchbox}}%
162   \fi}
163
164\unexpanded\def\fakefigure
165  {\dodoubleempty\dofakefigure}
166
167\def\dofakefigure[#1][#2]#3#4#5#6% [] [] minwidth maxwidth minheight maxheight
168  {\getvalue{\e!place\v!figure}
169     [#1][#2]%
170     {\freezerandomseed
171      \let\endstrut\relax
172      \let\begstrut\relax
173      \doifelseinset{#1}{\v!left,\v!right}
174        {\fakewords{2}{4}}
175        {\fakewords{4}{10}}}%
176     {\getrandomdimen\scratchdimenone{#3}{#4}%
177      \getrandomdimen\scratchdimentwo{#5}{#6}%
178      \doifinset{#1}{\v!left,\v!right}
179        {\scratchdimenone.75\scratchdimenone
180         \ifdim\scratchdimenone>.6\hsize \scratchdimenone.5\hsize\fi
181         \ifdim\scratchdimenone<.3\hsize \scratchdimenone.3\hsize\fi}%
182      \framed
183        [\c!width=\scratchdimenone,
184         \c!height=\scratchdimentwo,
185         \c!frame=\v!off,
186         \c!background=\v!color,
187         \c!backgroundcolor=fakeparindentcolor]
188        {\bf\white#1}}%
189   \defrostrandomseed}
190
191\unexpanded\def\fakeimage#1#2#3#4%
192  {\getrandomdimen\scratchdimenone{#1}{#3}%
193   \getrandomdimen\scratchdimentwo{#2}{#4}%
194   \framed
195     [\c!width=\scratchdimenone,
196      \c!height=\scratchdimentwo,
197      \c!frame=\v!off,
198      \c!background=\v!color,
199      \c!backgroundcolor=fakeparindentcolor]
200     {}}
201
202\unexpanded\def\fakeformula
203  {\scratchdimenone\zeropoint
204   \getrandomcount\scratchcounter{3}{6}%
205   \dorecurse\scratchcounter
206     {\getrandomdimen\scratchdimentwo{0.5\emwidth}{1.5\emwidth}%
207      \mathord{\red\fakerule\scratchdimentwo}%
208      \ifnum\recurselevel<\scratchcounter+\fi
209      \advance\scratchdimentwo\scratchdimenone}%
210   =\mathinner{\red\fakerule\scratchdimentwo}}
211
212\unexpanded\def\fakespacingformula
213  {\color[fakebaselinecolor]{\ruledbaseline}\fakeformula}
214
215%D test \type{\bodyfontgrid}\space test
216%D test \type{\emexgrid}    \space test
217
218\unexpanded\def\smashedgrid
219  {\dosingleempty\dosmashedgrid}
220
221\def\dosmashedgrid[#1]%
222  {\hsmashed
223     {\setbox\scratchbox=\hpack
224        {\basegrid
225           [\c!nx=10,\c!ny=10,\c!dx=1,\c!dy=1,
226            \c!unit=\bodyfontsize,#1]}%
227      \hpack to \zeropoint
228        {\hss\lower.5\ht\scratchbox\box\scratchbox\hss}%
229      \hpack to \zeropoint
230        {\hss
231         \black\vrule\s!width6\linewidth\s!height3\linewidth\s!depth3\linewidth
232         \hss}}}
233
234\unexpanded\def\bodyfontgrid
235  {\hpack
236     {{\linewidth.1pt\yellow\smashedgrid[\c!nx=30,\c!ny=30,\c!scale=.3333]}%
237      {\linewidth.2pt\green \smashedgrid[\c!nx=20,\c!ny=20,\c!scale=.5]}%
238      {\linewidth.3pt\red   \smashedgrid[\c!nx=10,\c!ny=10,\c!scale=1]}}}
239
240\unexpanded\def\emexgrid
241  {\hpack
242     {{\linewidth.15pt\green\smashedgrid[\c!nx=20,\c!ny=20,\c!unit=ex]}%
243      {\linewidth.15pt\red  \smashedgrid[\c!nx=10,\c!ny=10,\c!unit=em]}}}
244
245%D For Mojca:
246
247\unexpanded\def\simplethesis
248  {\setupsystem[random=1234]
249   \title{\fakewords{3}{4}}
250   \placelist[chapter,section]
251   \dorecurse{6}
252     {\chapter{\fakewords{5}{10}}
253      \dorecurse{5}
254        {\section{\fakewords{2}{5}}
255         \dorecurse{2}
256           {\dorecurse{3}{\fakewords{100}{200}\endgraf}
257            \placefigure{\fakewords{8}{15}}{\fakeimage{5cm}{3cm}{10cm}{5cm}}
258            \dorecurse{2}{\fakewords{100}{200}\endgraf}}}}}
259
260%D Moved code:
261
262%D \module
263%D   [       file=trac-vis, % was core-vis,
264%D        version=1996.06.01,
265%D          title=\CONTEXT\ Tracking Macros,
266%D       subtitle=Visualization,
267%D         author=Hans Hagen,
268%D           date=\currentdate,
269%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
270%C
271%C This module is part of the \CONTEXT\ macro||package and is
272%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
273%C details.
274
275%D This module adds some more visualization cues to the ones
276%D supplied in the support module.
277%D
278%D %\everypar   dual character, \the\everypar and \everypar=
279%D %\hrule      cannot be grabbed in advance, switches mode
280%D %\vrule      cannot be grabbed in advance, switches mode
281%D %
282%D %\indent     only explicit ones
283%D %\noindent   only explicit ones
284%D %\par        only explicit ones
285%D
286%D %\leftskip   only if explicit one
287%D %\rightskip  only if explicit one
288
289\writestatus{loading}{ConTeXt Tracking Macros / Visualization}
290
291\unprotect
292
293%D \macros
294%D   {indent, noindent, par}
295%D
296%D \TeX\ acts upon paragraphs. In mosts documents paragraphs
297%D are separated by empty lines, which internally are handled as
298%D \type{\par}. Paragraphs can be indented or not, depending on
299%D the setting of \type{\parindent}, the first token of a
300%D paragraph and/or user suppressed or forced indentation.
301%D
302%D Because the actual typesetting is based on both explicit
303%D user and implicit system actions, visualization is only
304%D possible for the user supplied \type{\indent},
305%D \type{\noindent}, and \type{\par}. Other
306%D 'clever' tricks will quite certainly lead to more failures
307%D than successes, so we only support these three explicit
308%D primitives and one macro:
309
310\unexpanded\def\showparagraphcue#1#2#3#4#5%
311  {\bgroup
312   \scratchdimen#1\relax
313   \dontinterfere
314   \dontcomplain
315   #3#4\relax
316   \setbox\scratchbox\normalhbox to \scratchdimen
317     {#2{\ruledhbox to \scratchdimen
318           {\vrule #5 20\fakerulewidth \s!width \zeropoint
319            \normalhss}}}%
320   \smashbox\scratchbox
321   \normalpenalty\plustenthousand
322   \box\scratchbox
323   \egroup}
324
325\unexpanded\def\ruledhanging
326  {\ifdim\hangindent>\zeropoint
327     \ifnum\hangafter<\zerocount
328       \normalhbox
329         {\setbox\scratchbox\ruledhbox to \hangindent
330            {\scratchdimen\strutht
331             \advance\scratchdimen \strutdp
332             \vrule
333               \s!width  \zeropoint
334               \s!height \zeropoint
335               \s!depth -\hangafter\scratchdimen}%
336          \normalhskip-\hangindent
337          \smashbox\scratchbox
338          \raise\strutht\box\scratchbox}%
339     \fi
340   \fi}
341
342\unexpanded\def\ruledparagraphcues
343  {\bgroup
344   \dontcomplain
345   \normalhbox to \zeropoint
346     {\ifdim\leftskip>\zeropoint\relax
347        \showparagraphcue\leftskip\llap\relax\relax\!!depth
348        \normalhskip-\leftskip
349      \fi
350      \ruledhanging
351      \normalhskip\hsize
352      \ifdim\rightskip>\zeropoint\relax
353        \normalhskip-\rightskip
354        \showparagraphcue\rightskip\relax\relax\relax\!!depth
355      \fi}%
356   \egroup}
357
358\unexpanded\def\ruledpar
359  {\relax
360   \ifhmode
361     \showparagraphcue{40\fakerulewidth}\relax\rightrulefalse\relax\s!height
362   \fi
363   \normalpar}
364
365\unexpanded\def\rulednoindent
366  {\relax
367   \normalnoindent
368   \ruledparagraphcues
369   \showparagraphcue{40\fakerulewidth}\llap\leftrulefalse\relax\s!height}
370
371\unexpanded\def\ruledindent
372  {\relax
373   \normalnoindent
374   \ruledparagraphcues
375   \ifdim\parindent>\zeropoint
376     \showparagraphcue\parindent\relax\relax\relax\s!height
377   \else
378     \showparagraphcue{40\fakerulewidth}\llap\relax\relax\s!height
379   \fi
380   \normalhskip\parindent}
381
382\unexpanded\def\dontshowimplicits
383  {\let\noindent   \normalnoindent
384   \let\indent     \normalindent
385   \let\par        \normalpar}
386
387\unexpanded\def\showimplicits
388  {\let\noindent \rulednoindent
389   \let\indent   \ruledindent
390   \let\par      \ruledpar}
391
392%D The next few||line examples show the four cues. Keep in
393%D mind that we only see them when we explicitly open or close
394%D a paragraph.
395%D
396%D \bgroup
397%D \def\voorbeeld#1%
398%D   {#1Visualizing some \TeX\ primitives and Plain \TeX\
399%D    macros can be very instructive, at least it is to me.
400%D    Here we see {\tt\string#1} and {\tt\string\ruledpar} in
401%D    action, while {\tt\string\parindent} equals
402%D    {\tt\the\parindent}.\ruledpar}
403%D
404%D \showimplicits
405%D
406%D \voorbeeld \indent
407%D \voorbeeld \noindent
408%D
409%D \parindent=60pt
410%D
411%D \voorbeeld \indent
412%D \voorbeeld \noindent
413%D
414%D \startnarrower
415%D \voorbeeld \indent
416%D \voorbeeld \noindent
417%D \stopnarrower
418%D \egroup
419%D
420%D These examples also demonstrate the visualization of
421%D \type {\leftskip} and \type {\rightskip}. The macro
422%D \type {\nofruledbaselines} determines the number of lines
423%D shown.
424
425\newcounter\ruledbaselines
426
427\def\nofruledbaselines{3}
428
429\unexpanded\def\ruledbaseline
430  {\vrule \s!width \zeropoint
431   \bgroup
432   \dontinterfere
433   \doglobal\increment\ruledbaselines
434   \scratchdimen\nofruledbaselines\baselineskip
435   \setbox\scratchbox\normalvbox to 2\scratchdimen
436     {\leaders
437        \normalhbox
438          {\strut
439           \vrule
440             \s!height \fakerulewidth
441             \s!depth \fakerulewidth
442             \s!width 120\points}
443      \normalvfill}%
444   \smashbox\scratchbox
445   \advance\scratchdimen \strutheightfactor\baselineskip
446   \setbox\scratchbox\normalhbox
447     {\normalhskip -48\points
448      \normalhbox to 24\points
449        {\normalhss
450         {\ttxx\ruledbaselines}%
451         \normalhskip6\points}%
452      \raise\scratchdimen\box\scratchbox}%
453   \smashbox\scratchbox
454   \box\scratchbox
455   \egroup}
456
457\unexpanded\def\showbaselines
458  {\EveryPar{\ruledbaseline}}
459
460%D \macros
461%D   {showpagebuilder}
462%D
463%D The next tracing option probaly is only of use to me and a
464%D few \CONTEXT\ hackers.
465
466\unexpanded\def\showpagebuilder
467  {\EveryPar{\doshowpagebuilder}}
468
469\unexpanded\def\doshowpagebuilder
470  {\strut\llap
471     {\startcolor[blue]\vl
472      \high{\infofont v:\the\vsize    }\vl
473      \high{\infofont g:\the\pagegoal }\vl
474      \high{\infofont t:\the\pagetotal}\vl
475      \stopcolor}}
476
477%D \macros
478%D   {colormarkbox,rastermarkbox}
479%D
480%D This macro is used in the pagebody routine. No other use
481%D is advocated here.
482%D
483%D \starttyping
484%D \colormarkbox0
485%D \stoptyping
486
487\def\colormarkoffset{\cutmarkoffset}
488\def\colormarklength{\cutmarklength}
489
490\def\dodocolorrangeA#1%
491  {\fastcolored[#1]{\hrule\s!width3em\s!height\scratchdimen\s!depth\zeropoint}}
492
493\def\docolorrangeA#1 #2 %
494  {\vpack
495     {\hsize3em % \scratchdimen
496      \ifcase#1\or
497        \dodocolorrangeA{c=#2}\or
498        \dodocolorrangeA{m=#2}\or
499        \dodocolorrangeA{y=#2}\or
500        \dodocolorrangeA{m=#2,y=#2}\or
501        \dodocolorrangeA{c=#2,y=#2}\or
502        \dodocolorrangeA{c=#2,m=#2}\fi
503      \ifdim\scratchdimen>1ex
504        \vskip-\scratchdimen
505        \vpack to \scratchdimen
506          {\vss\hpack to 3em{\hss#2\hss}\vss}%
507      \fi}}
508
509\unexpanded\def\colorrangeA#1%
510  {\vpack
511     {\startcolor[\s!white]%
512      \scratchdimen\dimexpr(-\colormarklength*4+\tractempheight+\tractempdepth)/21\relax
513      \offinterlineskip
514      \docolorrangeA #1 1.00 \docolorrangeA #1 0.95
515      \docolorrangeA #1 0.75
516      \docolorrangeA #1 0.50
517      \docolorrangeA #1 0.25 \docolorrangeA #1 0.05
518      \docolorrangeA #1 0.00
519      \stopcolor}}
520
521\def\docolorrangeB #1 #2 #3 #4 #5 %
522  {\fastcolored
523    [\c!c=#2,\c!m=#3,\c!y=#4,\c!k=#5]
524    {\vrule\s!width\scratchdimen\s!height\colormarklength\s!depth\zeropoint}%
525   \ifdim\scratchdimen>2em
526     \hskip-\scratchdimen
527     \vpack to \colormarklength
528       {\vss\hpack to \scratchdimen{\hss#1\hss}\vss}%
529   \fi}
530
531\unexpanded\def\colorrangeB
532  {\hpack
533     {\startcolor[\s!white]%
534      \scratchdimen\dimexpr(-\colormarklength*\plustwo+\tractempwidth)/11\relax
535      \docolorrangeB .5~C .5  0  0  0
536      \docolorrangeB .5~M  0 .5  0  0
537      \docolorrangeB .5~Y  0  0 .5  0
538      \docolorrangeB .5~K  0  0  0 .5
539      \docolorrangeB    C  1  0  0  0
540      \docolorrangeB    G  1  0  1  0
541      \docolorrangeB    Y  0  0  1  0
542      \docolorrangeB    R  0  1  1  0
543      \docolorrangeB    M  0  1  0  0
544      \docolorrangeB    B  1  1  0  0
545      \docolorrangeB    K  0  0  0  1
546      \stopcolor}}
547
548\def\docolorrangeC#1 %
549  {\fastcolored
550     [\c!s=#1]%
551     {\vrule\s!width\scratchdimen\s!height\colormarklength\s!depth\zeropoint}%
552   \ifdim\scratchdimen>2em
553     \hskip-\scratchdimen
554     \vpack to \colormarklength
555       {\vss\hpack to \scratchdimen{\hss#1\hss}\vss}%
556   \fi}
557
558\unexpanded\def\colorrangeC
559  {\hpack
560     {\startcolor[\s!white]%
561      \scratchdimen\dimexpr(-\colormarklength*2+\tractempwidth)/14\relax
562      \docolorrangeC  1  \docolorrangeC .95
563      \docolorrangeC .9  \docolorrangeC .85
564      \docolorrangeC .8  \docolorrangeC .75
565      \docolorrangeC .7
566      \docolorrangeC .6
567      \docolorrangeC .5
568      \docolorrangeC .4
569      \docolorrangeC .3
570      \docolorrangeC .2
571      \docolorrangeC .1
572      \docolorrangeC  0
573      \stopcolor}}
574
575\def\docolormarkbox#1#2%
576  {\tractempheight\ht#2%
577   \tractempdepth \dp#2%
578   \tractempwidth \wd#2%
579   \setbox#2\hpack
580     {\scratchdimen\dimexpr\colormarklength/2\relax
581      \forgetall
582      \ssxx
583      \setbox\scratchbox\vpack
584        {\offinterlineskip
585         \vskip\dimexpr-\colormarkoffset\scratchdimen-2\scratchdimen\relax
586         \ifcase#1\relax
587           \vskip\dimexpr\colormarklength+\scratchdimen+\tractempheight\relax
588         \else
589           \hpack to \tractempwidth{\hss\hpack{\colorrangeB}\hss}%
590           \vskip\colormarkoffset\scratchdimen
591           \vpack to \tractempheight
592             {\vss
593              \hpack to \tractempwidth
594                {\llap{\colorrangeA1\hskip\colormarkoffset\scratchdimen}\hfill
595                 \rlap{\hskip\colormarkoffset\scratchdimen\colorrangeA4}}%
596              \vss
597              \hpack to \tractempwidth
598                {\llap{\colorrangeA2\hskip\colormarkoffset\scratchdimen}\hfill
599                 \rlap{\hskip\colormarkoffset\scratchdimen\colorrangeA5}}%
600              \vss
601              \hpack to \tractempwidth
602                {\llap{\colorrangeA3\hskip\colormarkoffset\scratchdimen}\hfill
603                 \rlap{\hskip\colormarkoffset\scratchdimen\colorrangeA6}}%
604              \vss}%
605         \fi
606         \vskip\colormarkoffset\scratchdimen
607         \hpack to \tractempwidth
608           {\hss\lower\tractempdepth\hpack{\colorrangeC}\hss}}%
609      \ht\scratchbox\tractempheight
610      \dp\scratchbox\tractempdepth
611      \wd\scratchbox\zeropoint
612      \box\scratchbox
613      \box#2}%
614   \wd#2\tractempwidth
615   \ht#2\tractempheight
616   \dp#2\tractempdepth}
617
618\unexpanded\def\colormarkbox {\docolormarkbox\plusone  } % #1
619\unexpanded\def\rastermarkbox{\docolormarkbox\zerocount} % #1
620
621%D \macros
622%D   {showwhatsits, dontshowwhatsits}
623%D
624%D \TEX\ has three so called whatsits: \type {\mark}, \type
625%D {\write} and \type {\special}. The first one keeps track of
626%D the current state at page boundaries, the last two are used
627%D to communicate to the outside world. Due to fact that
628%D especially \type {\write} is often used in conjunction with
629%D \type {\edef}, we can only savely support that one in \ETEX.
630%D
631%D \bgroup \showwhatsits \setupcolors[state=start]
632%D
633%D Whatsits show up \color[blue]{in color} and are
634%D characterized bij their first character.\footnote [some note]
635%D {So we may encounter \type {w}, \type {m} and \type{s}.}
636%D They are \writestatus{dummy}{demo}\color[yellow]{stacked}.
637%D
638%D \egroup
639
640\newif\ifimmediatewrite
641
642\let\supernormalmark  \normalmark  % mark may already been superseded
643\let\supernormalmarks \normalmarks % mark may already been superseded
644
645\unexpanded\def\showwhatsits
646  {\unexpanded\def\normalmark {\visualwhatsit100+m\supernormalmark }%
647   \unexpanded\def\normalmarks{\visualwhatsit100+m\supernormalmarks}%
648   \unexpanded\def\special    {\visualwhatsit0100s\normalspecial   }%
649   \unexpanded\def\write      {\visualwhatsit001-w\normalwrite     }%
650   \let\immediate\immediatewhatsit
651   \appendtoks\dontshowwhatsits\to\everystoptext}
652
653\unexpanded\def\immediatewhatsit
654  {\bgroup\futurelet\nexttoken\doimmediatewhatsit}
655
656\unexpanded\def\doimmediatewhatsit
657  {\ifx\nexttoken\write
658     \egroup\immediatewritetrue
659   \else
660     \egroup\expandafter\normalimmediate
661   \fi}
662
663\unexpanded\def\dontshowwhatsits
664  {\let\immediate \normalimmediate
665   \let\normalmark\supernormalmark
666   \let\special   \normalspecial
667   \let\write     \normalwrite}
668
669\unexpanded\def\visualwhatsit#1#2#3#4#5%
670  {\bgroup
671   \pushwhatsit
672   \dontinterfere
673   \dontcomplain
674   \dontshowcomposition
675   \dontshowwhatsits
676   \ttx
677   \ifvmode\donetrue\else\donefalse\fi
678   \setbox\scratchbox\hpack
679     {\ifdone
680        \colored[r=#1,g=#2,b=#3]{#5}% temp hack
681      \else
682        \colored[s=0]{#5}% temp hack
683      \fi}%
684   \setbox\scratchbox\hpack
685     {\ifdone
686        \colored[r=#1,g=#2,b=#3]{\vrule\s!width\wd\scratchbox}% temp hack
687      \else
688        \colored[s=0]{\vrule\s!width\wd\scratchbox}% temp hack
689      \fi
690      \hskip-\wd\scratchbox\box\scratchbox}%
691   \scratchdimen1ex
692   \setbox\scratchbox\hpack
693     {\ifdone\hskip\else\raise#4\fi\scratchdimen\box\scratchbox}%
694   \smashbox\scratchbox
695   \ifdone\nointerlineskip\fi
696   \box\scratchbox
697   \ifvmode\nointerlineskip\fi
698   \popwhatsit
699   \egroup
700   \ifimmediatewrite
701     \immediatewritefalse
702     \expandafter\normalimmediate
703   \fi}
704
705\unexpanded\def\pushwhatsit
706  {\ifzeropt\lastskip
707     \ifcase\lastpenalty
708       \ifzeropt\lastkern
709         \ifhmode
710           \let\popwhatsit\relax
711         \else
712           \edef\popwhatsit{\prevdepth\the\prevdepth}%
713         \fi
714       \else
715         \ifhmode
716           \edef\popwhatsit{\kern\the\lastkern}\unkern
717         \else
718           \edef\popwhatsit{\kern\the\lastkern\prevdepth\the\prevdepth}%
719           \kern-\lastkern
720         \fi
721       \fi
722     \else
723       \ifhmode
724         \edef\popwhatsit{\the\lastpenalty}%
725         \unpenalty
726       \else
727         \edef\popwhatsit{\penalty\the\lastpenalty\prevdepth\the\prevdepth}%
728        %\nobreak
729       \fi
730     \fi
731   \else
732     \ifhmode
733       \edef\popwhatsit{\hskip\the\lastskip}\unskip
734     \else
735       \edef\popwhatsit{\vskip\the\lastskip\prevdepth\the\prevdepth}%
736       \vskip-\lastskip
737     \fi
738   \fi}
739
740%D The next macro can be used to keep track of classes of
741%D boxes (handy for development cq.\ tracing).
742
743\def\dodotagbox#1#2#3% can be reimplemented
744  {\def\next##1##2##3##4%
745     {\vpack to \ht#2{##3\hpack to \wd#2{##1#3##2}##4}}%
746   \processaction
747     [#1]
748     [        l=>\next\relax\hfill\vfill\vfill,
749              r=>\next\hfill\relax\vfill\vfill,
750              t=>\next\hfill\hfill\relax\vfill,
751              b=>\next\hfill\hfill\vfill\relax,
752             lt=>\next\relax\hfill\relax\vfill,
753             lb=>\next\relax\hfill\vfill\relax,
754             rt=>\next\hfill\relax\relax\vfill,
755             rb=>\next\hfill\relax\vfill\relax,
756             tl=>\next\relax\hfill\relax\vfill,
757             bl=>\next\relax\hfill\vfill\relax,
758             tr=>\next\hfill\relax\relax\vfill,
759             br=>\next\hfill\relax\vfill\relax,
760     \s!default=>\next\hfill\hfill\vfill\vfill,
761     \s!unknown=>\next\hfill\hfill\vfill\vfill]}
762
763\def\dotagbox[#1]#2%
764  {\bgroup
765   \dowithnextbox
766     {\setbox\scratchbox\flushnextbox
767      \setbox\nextbox\ifhbox\nextbox\hpack\else\vpack\fi
768        \bgroup
769          \startoverlay
770            {\copy\scratchbox}
771            {\dodotagbox{#1}\scratchbox{\framed
772               [\c!background=\v!color,\c!backgroundcolor=\v!gray]{#2}}}
773          \stopoverlay
774        \egroup
775      \nextboxwd\the\wd\scratchbox
776      \nextboxht\the\ht\scratchbox
777      \nextboxdp\the\dp\scratchbox
778      \flushnextbox
779      \egroup}}
780
781\unexpanded\def\tagbox
782  {\dosingleempty\dotagbox}
783
784%D \macros
785%D   {coloredhbox,coloredvbox,coloredvtop,
786%D    coloredstrut}
787%D
788%D The following visualizations are used in some of the manuals:
789
790\definecolor[boxcolor:ht][r=.5,g=.75,b=.5]
791\definecolor[boxcolor:dp][r=.5,g=.5,b=.75]
792\definecolor[boxcolor:wd][r=.75,g=.5,b=.5]
793\definecolor[strutcolor] [r=.5,g=.25,b=.25]
794
795\unexpanded\def\coloredbox#1%
796  {\dowithnextbox{#1{\hpack
797     {\blackrule[\c!width=\nextboxwd,\c!height=\nextboxht,\c!depth=\zeropoint,\c!color=boxcolor:ht]%
798      \hskip-\nextboxwd
799      \blackrule[\c!width=\nextboxwd,\c!height=\zeropoint,\c!depth=\nextboxdp,\c!color=boxcolor:dp]%
800      \hskip-\nextboxwd
801      \box\nextbox}}}#1}
802
803\unexpanded\def\coloredhbox{\coloredbox\hpack}
804\unexpanded\def\coloredvbox{\coloredbox\vpack}
805\unexpanded\def\coloredvtop{\coloredbox\tpack}
806
807\unexpanded\def\coloredstrut
808  {\color[strutcolor]{\def\strutwidth{2\points}\setstrut\strut}}
809
810\protect
811
812\continueifinputfile{m-visual.mkiv}
813
814\starttext
815    \simplethesis
816\stoptext
817