MetaFun - Pragma ADE
MetaFun - Pragma ADE MetaFun - Pragma ADE
144 paragraph is typeset, but in the former case a second pass is needed. Because such graphics are not bound to one paragraph, the multi--pass option suits better because it gives us more control: the more we know about he final state, the better we can act upon it. Think of graphics on the first page that depend on the content of the last page or, as in this paragraph, backgrounds that depend on the typeset text. It may be clear now that we need some positional information in order to provide features like the ones shown here. The fact that we will act upon in a second pass simplifies the task, although it forces us to store the positional information between runs in some place. This may look uncomfortable at first sight, but it also enables us to store some additional information. Now why is that needed? A position has no dimensions, it's just a place somewhere on the page. In order to do tricks like those shown here, we also need to know the height and depth of lines at a specific point as well as the width of the box(es) we're dealing with. In the encircled examples, the dimensions of the box following the positional node are stored along with the position. In the background example, we store the current height and depth of the strut (an imaginary character with maximum height and depth but no width) along with the current text width. In order to process the graphics, we tag each point with a name, so that we can attach actions to those points. In fact they become trigger points. As we will demonstrate, we also need to store the current page number. This brings the data stored with a point to: The page number is needed in order to let the graphics engine determine boundary conditions. Backgrounds like those shown here can span multiple pages. In order to calculate the right backgrounds, some additional information must be available, like the top and bottom of the current text area. In fact, these are just normal points that can be saved while processing the split off page. So, apart from positioning anchors in the text we need anchors on crucial points of the layout. This means that this kind of support cannot be fully integrated into the TEX kernel, unless we also add extensive support for layout definitions, and that is probably not what we want. As soon as something like (x,y) shows up, a logical question is where (0,0) is located. Although this is a valid question, the answer is less important than you may expect. Even if we know that (0,0) is ‘officially' located in the bottom left corner of the page, the simple fact that in CONTEXT we are dealing with a mixed page concept, like paper size and print paper size, or left and right pages, forces us to think in relative positions instead of absolute ones. Therefore, graphics, even those that involve multiple positions, are anchored to a position on the layer on which they are located. The \MPanchor macro takes care of this. Users who simply want to use these features may wonder why we go into so much detail. The main reason is that in the end many users will want to go beyond the simple cases, and when dealing with these issues, you must be aware not only of height, depth and width, but also of the crossing of a page boundary, and the height and depth of lines. In some cases your graphics may have to respond to layout characteristics, like differences between odd and even pages. Given that unique identifiers are used for anchor points, in CONTEXT you can have access to all the information needed. Positional graphics The concept
5.2 Anchors and layers In a previous section we saw that some words were circled and connected by an arrow. As with most things in CONTEXT, marking these words is separated from declaring what to do with those words. This paragraph is keyed in as: In a previous section we saw that some \hpos {X-1} {words} were \hpos {X-2} {circled} and connected by an \hpos {X-3} {arrow}. As with most things in \CONTEXT, marking these words is separated from declaring what to do with those words. This paragraph is keyed in as: We see three position anchors, each marked by an identifier: X-1, X-2 and X-3. Each of these anchors can be associated with a (series) of graphic operations. Here we defined: \setMPpositiongraphic{X-1}{mypos:arrow}{to=X-2} \setMPpositiongraphic{X-2}{mypos:arrow}{to=X-3} These examples clearly demonstrate that we cannot control to what extent graphics will cover text and vice versa. A solution to this problem is using position overlays. We can define such an overlay as follows: \startpositionoverlay{backgraphics} \setMPpositiongraphic{G-1}{mypos:circle} \setMPpositiongraphic{G-2}{mypos:circle} \setMPpositiongraphic{G-3}{mypos:circle} \setMPpositiongraphic{G-4}{mypos:circle} \stoppositionoverlay \startpositionoverlay{foregraphics} \setMPpositiongraphic{G-1}{mypos:line}{to=G-2} \setMPpositiongraphic{G-2}{mypos:line}{to=G-3} \setMPpositiongraphic{G-3}{mypos:line}{to=G-4} \stoppositionoverlay First we have defined an overlay. This overlay can be attached to some overlay layer, like, in our case, the page. We define four small circles. These are drawn as soon as the page overlay is typeset. Because they are located in the background, they don't cover the text, while the lines do. The previous paragraph was typeset by saying: First we have defined an \hpos {G-1} {overlay}. This overlay can be attached to some overlay layer, like, in our case, the \hpos {G-2} {page}. We define four small \hpos {G-3} {circles}. These are drawn as soon as the page overlay is typeset. Because they are located in the background, they don't cover the \hpos {G-4} {text}, while the lines do. The previous paragraph was typeset by saying: As said, the circles are on the background layer, but the lines are not! They are positioned on top of the text. This is a direct result of the definition of the page background: Anchors and layers Positional graphics 145
- Page 97 and 98: currentpicture := currentpicture sl
- Page 99 and 100: We can achieve this by defining poi
- Page 101 and 102: We're still not there. Like in a pr
- Page 103 and 104: Due to the thicker line width used
- Page 105 and 106: left up down right The previous def
- Page 107 and 108: Here the & glues strings together,
- Page 109 and 110: picture p ; p := "MetaFun" normalin
- Page 111 and 112: pickup pencircle scaled 2pt ; draw
- Page 113 and 114: Because the z--variables are used f
- Page 115 and 116: 3 Embedded graphics In addition to
- Page 117 and 118: \startMPcode fill fullcircle scaled
- Page 119 and 120: \startuniqueMPgraphic{right or wron
- Page 121 and 122: {\externalfigure[mprun:extrafun::my
- Page 123 and 124: \startlinecorrection[blank] \proces
- Page 125 and 126: In order to prevent problems, we ad
- Page 127 and 128: There are a few more low level swit
- Page 129 and 130: When we convert color to gray, we u
- Page 131 and 132: 4 Enhancing the layout One of the m
- Page 133 and 134: 4.2 Overlay variables [offset=3pt,f
- Page 135 and 136: This background demonstrates that a
- Page 137 and 138: As you may know, TEX's ambassador i
- Page 139 and 140: This works as expected: \RotatedTex
- Page 141 and 142: We will now apply this knowledge of
- Page 143 and 144: p := p shifted (2o,OverlayHeight-yp
- Page 145 and 146: We demonstrated that when defining
- Page 147: 5 Positional graphics In this chapt
- Page 151 and 152: pab := pab cutafter (pab intersecti
- Page 153 and 154: fill p withcolor \MPcolor{lightgray
- Page 155 and 156: The previous example also demonstra
- Page 157 and 158: \setMPlayer [test] [somepos-1] [loc
- Page 159 and 160: 6 Page backgrounds Especially in in
- Page 161 and 162: As soon as you want to make an elec
- Page 163 and 164: do_it (1,4,false) ; do_it (5,4,fals
- Page 165 and 166: gigigi Watch how the bounding boxes
- Page 167 and 168: You can test this concept yourself
- Page 169 and 170: StartPage ; fill Area[Text][Text] s
- Page 171 and 172: fi ; Main := Main enlarged 6pt ; pi
- Page 173 and 174: ulcorner Field[Text] [Text] -urcorn
- Page 175 and 176: The left picture demonstrates what
- Page 177 and 178: There are two more operators: inner
- Page 179 and 180: 7 Shapes, symbols and buttons One c
- Page 181 and 182: Table 7.1 demonstrates how scratch
- Page 183 and 184: for i := 1 upto \MPvar{n} : xpos :=
- Page 185 and 186: This table is defined as: \bTABLE[f
- Page 187 and 188: Since we have collected some nice b
- Page 189 and 190: 8 Special effects Sometimes we want
- Page 191 and 192: Because of this implementation, sha
- Page 193 and 194: test_shade(origin shifted (.25cm,0)
- Page 195 and 196: fill p shifted (3cm,0) withcolor .5
- Page 197 and 198: \definecolor [tred] [r=1,t=.5,a=exc
144<br />
paragraph is typeset, but in the former case a second pass is needed. Because such graphics are<br />
not bound to one paragraph, the multi--pass option suits better because it gives us more control:<br />
the more we know about he final state, the better we can act upon it. Think of graphics on the<br />
first page that depend on the content of the last page or, as in this paragraph, backgrounds that<br />
depend on the typeset text.<br />
It may be clear now that we need some positional information in order to provide features like the<br />
ones shown here. The fact that we will act upon in a second pass simplifies the task, although it<br />
forces us to store the positional information between runs in some place. This may look uncomfortable<br />
at first sight, but it also enables us to store some additional information. Now why is that<br />
needed?<br />
A position has no dimensions, it's just a place somewhere on the page. In order to do tricks like<br />
those shown here, we also need to know the height and depth of lines at a specific point as well<br />
as the width of the box(es) we're dealing with. In the encircled examples, the dimensions of the<br />
box following the positional node are stored along with the position. In the background example,<br />
we store the current height and depth of the strut (an imaginary character with maximum height<br />
and depth but no width) along with the current text width.<br />
In order to process the graphics, we tag each point with a name, so that we can attach actions to<br />
those points. In fact they become trigger points. As we will demonstrate, we also need to store the<br />
current page number. This brings the data stored with a point to:<br />
<br />
The page number is needed in order to let the graphics engine determine boundary conditions.<br />
Backgrounds like those shown here can span multiple pages. In order to calculate the right backgrounds,<br />
some additional information must be available, like the top and bottom of the current<br />
text area. In fact, these are just normal points that can be saved while processing the split off page.<br />
So, apart from positioning anchors in the text we need anchors on crucial points of the layout. This<br />
means that this kind of support cannot be fully integrated into the TEX kernel, unless we also add<br />
extensive support for layout definitions, and that is probably not what we want.<br />
As soon as something like (x,y) shows up, a logical question is where (0,0) is located. Although<br />
this is a valid question, the answer is less important than you may expect. Even if we know that<br />
(0,0) is ‘officially' located in the bottom left corner of the page, the simple fact that in CONTEXT we<br />
are dealing with a mixed page concept, like paper size and print paper size, or left and right pages,<br />
forces us to think in relative positions instead of absolute ones. Therefore, graphics, even those<br />
that involve multiple positions, are anchored to a position on the layer on which they are located.<br />
The \MPanchor macro takes care of this.<br />
Users who simply want to use these features may wonder why we go into so much detail. The<br />
main reason is that in the end many users will want to go beyond the simple cases, and when<br />
dealing with these issues, you must be aware not only of height, depth and width, but also of the<br />
crossing of a page boundary, and the height and depth of lines. In some cases your graphics may<br />
have to respond to layout characteristics, like differences between odd and even pages. Given that<br />
unique identifiers are used for anchor points, in CONTEXT you can have access to all the information<br />
needed.<br />
Positional graphics The concept