anch-loc.mkxl /size: 4102 b    last modification: 2021-10-28 13:50
1%D \module
2%D   [       file=anch-loc,
3%D        version=2021.05.27,
4%D          title=\CONTEXT\ Anchoring Macros,
5%D       subtitle=Local Positioning Support,
6%D         author=Hans Hagen,
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\writestatus{loading}{ConTeXt Anchoring Macros / Local Positioning}
15
16%D This is a typical \LMTX\ feature that could have been provided in \MKIV\ but I
17%D never finished it there. In \LMTX\ we have already a bit better infrastructure
18%D for it.
19%D
20%D When watching the brilliant positive yt videos of Yoyoka Soma (よよか) drum
21%D performances one realizes that a covers can improve the original. Let's see if
22%D this module can improve some of the position related mechanisms. (Btw, quite
23%D often covers impress me more than originals I'd never list too anyway.)
24
25% todo:
26%
27% - make box fit and inject glue
28% - set height / depth or just insert something between
29
30\registerctxluafile{anch-loc}{autosuffix}
31
32\unprotect
33
34\aliased\let\syncanchor \gobblethreearguments
35\aliased\let\alignanchor\gobblefourarguments
36\aliased\let\markanchor \gobblethreearguments
37
38\permanent\protected\def\anch_local_withanchor_s  #1#2#3{\leftboundary\setlocalsyncanchor {#1} #2 #3\rightboundary}
39\permanent\protected\def\anch_local_withanchor_a#1#2#3#4{\leftboundary\setlocalalignanchor{#1} #2 #3{#4}\rightboundary}
40\permanent\protected\def\anch_local_withanchor_n  #1#2#3{\leftboundary\setlocalmarkanchor {#1} #2 #3\rightboundary}
41\permanent\protected\def\anch_local_withanchor_t  #1#2#3{\anch_local_withanchor_n{#1}{#2}{#3}\smash[whd]{\smallinfofont\number#2-\number#3}}
42
43\permanent\protected\def\setlocalanchoring
44  {\enforced\let\syncanchor \anch_local_withanchor_s
45   \enforced\let\alignanchor\anch_local_withanchor_a
46   \enforced\let\markanchor \anch_local_withanchor_m}
47
48\let\anch_local_withanchor_m\anch_local_withanchor_n
49
50\installtextracker{localanchor}
51  {\let\anch_local_withanchor_m\anch_local_withanchor_t}
52  {\let\anch_local_withanchor_m\anch_local_withanchor_n}
53
54\permanent\protected\lettonothing\stopanchoring
55
56\permanent\protected\def\startanchoring#1\stopanchoring % todo: boundary
57  {\begingroup
58   \pushlocalanchors
59   \setlocalanchoring
60   \setbox\scratchbox\vbox{\settrialtypesetting#1}%
61   \analyzelocalanchors\scratchbox
62   \vbox{#1}%
63   \poplocalanchors
64   \endgroup}
65
66\permanent\protected\lettonothing\stopsynchronizing
67
68\permanent\protected\def\startsynchronizing#1\stopsynchronizing % todo: boundary
69  {\begingroup
70   \pushlocalanchors
71   \setlocalanchoring
72   \setbox\scratchbox\vbox{#1}%
73   \synchronizelocalanchors\scratchbox
74   \unvbox\scratchbox
75   \poplocalanchors
76   \endgroup}
77
78% variant on \sync (defined at the lua end)
79
80\permanent\protected\def\autosync#1#2{\leftboundary\sync{#1}{#2}\rightboundary}
81
82% \startsynchronizing
83%     $a            = a            + a        $\par
84%     $a \mathsnc{1}= a            + a        $\par
85%     $  \mordsnc{1}= a            + a + a    $\par
86%     $  \mordsnc{1}= a \mathsnc{2}+ a + a + a$\par
87%     $  \mordsnc{1}    \mordsnc{2}+ a + a + a$
88% \stopsynchronizing
89
90\permanent\protected\def\mathsync#1{\sync{m}{#1}}
91\permanent\protected\def\mordsync#1{\mathord{}\sync{m}{#1}}
92\permanent\protected\def\mrelsync#1{\mathrel{}\sync{m}{#1}}
93\permanent\protected\def\mbinsync#1{\mathbin{}\sync{m}{#1}}
94
95\setlocalanchoring
96
97%D These are defined at the \LUA\ end.
98%D
99%D \starttyping
100%D \pushlocalanchors
101%D \poplocalanchors
102%D \analyzelocalanchors
103%D \synchronizelocalanchors
104%D \setlocalsyncanchor  {name} x y | {name} {x} {y}
105%D \setlocalmarkanchor  {name} x y | {name} {x} {y}
106%D \localanchorx        {name} x y | {name} {x} {y}
107%D \localanchory        {name} x y | {name} {x} {y}
108%D \sync                {name} x   | {name} {x}
109%D \stoptyping
110
111% \permanent\def\anchorxy#1#2#3{(\todimension\localanchorx{#1} #2 #3,\todimension\localanchory{#1} #2 #3)}
112
113\protect \endinput
114
115% Musical timestamp: Nightwish Decades bluray in loop mode.
116