pack-ori.mkxl /size: 3171 b    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=pack-ori, % was experimental
3%D        version=2019.07.30,
4%D          title=\CONTEXT\ Packaging Macros,
5%D       subtitle=Anchoring,
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 Packaging Macros / Anchoring}
15
16\registerctxluafile{pack-ori}{autosuffix}
17
18\unprotect
19
20%D Possible options are:
21%D
22%D \starttabulate[|T|T|]
23%D \NC orientation \NC up left down right top bottom
24%D \NC vertical    \NC line top bottom middle
25%D \NC horizontal  \NC middle flushleft flushright left right
26%D \stoptabulate
27
28\installcorenamespace{orientation}
29\installcorenamespace{orientations}
30
31\installcommandhandler \??orientation {orientation} \??orientation
32
33\setuporientation
34  [\c!orientation=\v!normal,
35   \c!horizontal=\v!normal,
36   \c!vertical=\v!normal]
37
38\appendtoks
39    \expandafter\integerdef\csname\??orientations\currentorientation\endcsname\toorientation
40        orientation {\orientationparameter\c!orientation}
41        horizontal  {\orientationparameter\c!horizontal}
42        vertical    {\orientationparameter\c!vertical}
43    \relax\relax
44\to \everydefineorientation
45
46\defineorientation[\v!normal]
47
48\defineorientation[\v!up]    [\c!orientation=\v!up]
49\defineorientation[\v!down]  [\c!orientation=\v!down]
50\defineorientation[\v!left]  [\c!orientation=\v!left]
51\defineorientation[\v!right] [\c!orientation=\v!right]
52\defineorientation[\v!top]   [\c!orientation=\v!top]
53\defineorientation[\v!bottom][\c!orientation=\v!bottom]
54\defineorientation[\v!line]  [\c!orientation=\v!line]
55
56%D There will be some more helpers here.
57
58\permanent\def\theorientation#1%
59  {\numexpr
60     \ifcsname\??orientations#1\endcsname
61       \lastnamedcs
62     \else
63       \zerocount
64     \fi
65  \relax}
66
67\permanent\def\autoorientation#1%
68  {\numexpr
69     \ifcsname\??orientations#1\endcsname
70       \lastnamedcs
71     \else
72       \auto_orientation{#1}%
73     \fi
74   \relax}
75
76%D The \type {\immediateassignment} and \type {\immediateassigned} primitives that
77%D are in \LUATEX\ are obsolete in \LUAMETATEX. Local scanning is, although it is
78%D a bit slower, more general. We didn't really need and use these primitives in
79%D \CONTEXT\ anyway, apart from some playing around with some full expansion, which
80%D made no sense in the end so it was dropped. When things get that hairy it's often
81%D a good reason to look into \LUA\ variants.
82
83\def\auto_orientation#1%
84  {\beginlocalcontrol\global\expandafter\chardef\csname\??orientations#1\endcsname\stringtoorientation{#1}\endlocalcontrol % good enough
85 %{\localcontrolled{\global\expandafter\chardef\csname\??orientations#1\endcsname\stringtoorientation{#1}}%                % a bit slower
86   \csname\??orientations#1\endcsname}
87
88\permanent\protected\def\doifelseorientation#1%
89  {\ifcsname\??orientations#1\endcsname
90     \expandafter\firstoftwoarguments
91   \else
92     \expandafter\secondoftwoarguments
93   \fi}
94
95% \def\iforientationcsname#1{\ifcsname\??orientations}
96
97\protect \endinput
98