summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/anch-box.mkxl
blob: 88809152e05e88be45cfe9db24719291a6bd62c4 (plain)
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
%D \module
%D   [       file=anch-box,
%D        version=2022.03.25,
%D          title=\CONTEXT\ Anchoring Macros,
%D       subtitle=Boxes,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Anchoring Macros / Boxes}

\unprotect

\startMPpositiongraphic{mypos:boxanchor:arrow}{}% from,to,linecolor,text,alternative,leftedge,rightedge,distance}
    anch_box_arrows_draw ;
\stopMPpositiongraphic

\tolerant\permanent\protected\def\connectboxanchors[#1]#*[#2]#*[#3]#*[#4]#*#:#5#6%
  {\begingroup
   \defineboxanchor[#5]%
   \setboxanchor[#5][#1][#3]\hpack{\xypos{\namespacedboxanchor{#5}}}%
   \ifparameter#3\or\setupboxanchorcontent[#1][#3]\fi
   \defineboxanchor[#6]%
   \setboxanchor[#6][#2][#4]\hpack{\xypos{\namespacedboxanchor{#6}}}%
   \ifparameter#4\or\setupboxanchorcontent[#1][#4]\fi
%    \startpositionoverlay{text-1}% will become configurable region
   \startpositionoverlay{text+1}% will become configurable region
     \setMPpositiongraphic
       {\namespacedboxanchor{#5}}%
       {\namedboxanchorcontentparameter{#1}\c!mp}%
       {from=\namespacedboxanchor{#5},%
        to=\namespacedboxanchor{#6},%
        distance={\namedboxanchorcontentparameter{#1}\c!distance},%
        dashtype={\namedboxanchorcontentparameter{#1}\c!dash},%
        alternative={\namedboxanchorcontentparameter{#1}\c!alternative},%
        text={\namedboxanchorcontentparameter{#1}\c!text},%
        rulethickness={\namedboxanchorcontentparameter{#1}\c!rulethickness},%
        linecolor=\namedboxanchorcontentparameter{#1}{\c!rulecolor}}%
   \stoppositionoverlay
   \endgroup}

% dedicated or not

\tolerant\permanent\protected\def\connectmatrixanchors[#1]#*[#2]#*[#3]#*[#4]#*#:#5#6%
  {\begingroup
   \doifelseinset{#5}{\m_anch_matrix_list}\donetrue\donefalse
   \ifdone\else
     \defineboxanchor[#5]%
     \setboxanchor[#5][#1][#3]\hpack{\xypos{\namespacedboxanchor{#5}}}%
     \xdef\m_anch_matrix_list{\m_anch_matrix_list,#5}%
   \fi
   \ifparameter#3\or\setupboxanchorcontent[#1][#3]\fi
   \doifelseinset{#6}{\m_anch_matrix_list}\donetrue\donefalse
   \ifdone\else
     \defineboxanchor[#6]%
     \setboxanchor[#6][#2][#4]\hpack{\xypos{\namespacedboxanchor{#6}}}%
     \xdef\m_anch_matrix_list{\m_anch_matrix_list,#6}%
   \fi
   \ifparameter#4\or\setupboxanchorcontent[#1][#4]\fi
   \startpositionoverlay{text-1}% will become configurable region
     \setMPpositiongraphic
       {\namespacedboxanchor{#5}}%
       {\namedboxanchorcontentparameter{#1}\c!mp}%
       {from=\namespacedboxanchor{#5},%
        to=\namespacedboxanchor{#6},%
        distance={\namedboxanchorcontentparameter{#1}\c!distance},%
        dashtype={\namedboxanchorcontentparameter{#1}\c!dash},%
        alternative={\namedboxanchorcontentparameter{#1}\c!alternative},%
        text={\namedboxanchorcontentparameter{#1}\c!text},%
        rulethickness={\namedboxanchorcontentparameter{#1}\c!rulethickness},%
        linecolor=\namedboxanchorcontentparameter{#1}{\c!rulecolor},%
        % matrix specific:
        leftedge=\namespacedboxanchor\c!leftedge,%
        rightedge=\namespacedboxanchor\c!rightedge}%
   \stoppositionoverlay
   \endgroup}

\let\m_anch_matrix_list\empty

\tolerant\permanent\protected\def\startmatrixanchors
  {\glet\m_anch_matrix_list\empty
   \defineboxanchor[\v!leftedge]%
   \setboxanchor[\v!leftedge][\v!leftedge]\hpack{\xypos{\namespacedboxanchor\v!leftedge}}%
   \defineboxanchor[\v!rightedge]%
   \setboxanchor[\v!rightedge][\v!rightedge]\hpack{\xypos{\namespacedboxanchor\v!rightedge}}%
   \setupmathfence[\c!leftsource=\v!leftedge,\c!rightsource=\v!rightedge]}

\tolerant\permanent\protected\def\stopmatrixanchors
  {\setupmathfence[\c!leftsource=,\c!rightsource=]%
   \glet\m_anch_matrix_list\empty}

\defineboxanchorcontent
  [arrow]
  [\c!mp=mypos:boxanchor:arrow,
   \c!distance=1.5\exheight,
   \c!rulethickness=\linewidth,
   \c!rulecolor=textcolor]

\defineboxanchorcontent
  [\v!top]
  [arrow]
  [\c!corner=\v!height,
   \c!location=\v!depth,
   \c!yoffset=.25\exheight,
   \c!alternative=\v!top]

\defineboxanchorcontent
  [\v!bottom]
  [arrow]
  [\c!corner=\v!depth,
   \c!location=\v!height,
   \c!yoffset=-\namedboxanchorcontentparameter{top}\c!yoffset,
   \c!alternative=\v!bottom]

\defineboxanchorcontent
  [\v!left]
  [arrow]
  [\c!corner={\v!middle,\v!left},
   \c!xoffset=-1.25\emwidth,
   \c!alternative=\v!left]

\defineboxanchorcontent
  [\v!right]
  [arrow]
  [\c!corner={\v!middle,\v!right},
   \c!xoffset=-\namedboxanchorcontentparameter{left}\c!xoffset,
   \c!alternative=\v!right]

\defineboxanchorcontent
  [\v!leftedge]
  [\v!left]
  [\c!xoffset=-.25\exheight]

\defineboxanchorcontent
  [\v!rightedge]
  [\v!right]
  [\c!xoffset=0.25\exheight] % we are centered

\defineboxanchorcontent[\v!middle:\v!bottom][\v!bottom][\c!alternative=\v!middle,\c!yoffset=-.5\exheight]
\defineboxanchorcontent[\v!middle:\v!top   ][\v!top   ][\c!alternative=\v!middle,\c!yoffset=.5\exheight]
\defineboxanchorcontent[\v!middle:\v!left  ][\v!left  ][\c!alternative=\v!middle,\c!xoffset=-.5\exheight]
\defineboxanchorcontent[\v!middle:\v!right ][\v!right ][\c!alternative=\v!middle,\c!xoffset=.5\exheight]

\defineboxanchorcontent
  [\v!left:\v!bottom]
  [\v!bottom]
  [\c!alternative=\v!middle,
   \c!corner={\v!left,\v!depth},
   \c!xoffset=-.25\exheight,
   \c!yoffset=-.25\exheight]

\defineboxanchorcontent
  [\v!right:\v!bottom]
  [\v!bottom]
  [\c!alternative=\v!middle,
   \c!corner={\v!right,\v!depth},
   \c!xoffset=.25\exheight,
   \c!yoffset=-.25\exheight]

\defineboxanchorcontent
  [\v!left:\v!top]
  [\v!top]
  [\c!alternative=\v!middle,
   \c!corner={\v!left,\v!height},
   \c!xoffset=-.25\exheight,
   \c!yoffset=.25\exheight]

\defineboxanchorcontent
  [\v!right:\v!top]
  [\v!top]
  [\c!alternative=\v!middle,
   \c!corner={\v!right,\v!height},
   \c!xoffset=.25\exheight,
   \c!yoffset=.25\exheight]

\protect