mult-dim.mkvi /size: 6203 b    last modification: 2021-10-28 13:50
1%D \module
2%D   [       file=core-gen,
3%D        version=1995.10.10,
4%D          title=\CONTEXT\ Core Macros,
5%D       subtitle=General,
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 Core Macros / General}
15
16% we could write a proper parser now in lua
17
18\unprotect
19
20%D \macros
21%D   {assigndimension,assignalfadimension}
22%D
23%D The following commands are used to process keyword based
24%D dimension setters.
25%D
26%D \starttyping
27%D \assigndimension
28%D   {<value>|small|medium|big|-small|-medium|-big|none}
29%D   {\dimension}
30%D   {value small}
31%D   {value medium}
32%D   {value big}
33%D \stoptyping
34%D
35%D The given keyword determines the result.
36
37\installcorenamespace{dimensionnormal}
38
39\def\assign_dimension_direct#value#dimension#small#medium#big{#dimension=#value\relax}
40
41\setvalue{\??dimensionnormal \v!none  }#value#dimension#small#medium#big{#dimension\zeropoint}
42\setvalue{\??dimensionnormal \empty   }#value#dimension#small#medium#big{#dimension\zeropoint}
43\setvalue{\??dimensionnormal \v!small }#value#dimension#small#medium#big{#dimension=#small\relax}
44\setvalue{\??dimensionnormal \v!medium}#value#dimension#small#medium#big{#dimension=#medium\relax}
45\setvalue{\??dimensionnormal \v!big   }#value#dimension#small#medium#big{#dimension=#big\relax}
46\setvalue{\??dimensionnormal-\v!small }#value#dimension#small#medium#big{#dimension=-#small\relax}
47\setvalue{\??dimensionnormal-\v!medium}#value#dimension#small#medium#big{#dimension=-#medium\relax}
48\setvalue{\??dimensionnormal-\v!big   }#value#dimension#small#medium#big{#dimension=-#big\relax}
49\letvalue{\??dimensionnormal\s!unknown}\assign_dimension_direct
50
51% \protected\def\assigndimension#value%
52%   {\csname\??dimensionnormal\ifcsname\??dimensionnormal#value\endcsname#value\else\s!unknown\fi\endcsname{#value}}
53
54\protected\def\assigndimension#value%
55  {\ifcsname\??dimensionnormal#value\endcsname
56     \expandafter\lastnamedcs
57   \else
58     \expandafter\assign_dimension_direct
59   \fi{#value}}
60
61%D The next variant assigns to a macro instead of a dimension.
62%D
63%D \starttyping
64%D \assignalfadimension
65%D   {<value>|small|medium|big|none}
66%D   {\macro}
67%D   {value small}
68%D   {value medium}
69%D   {value big}
70%D \stoptyping
71%D
72%D This one is used for factors.
73
74\installcorenamespace{dimensionalfa}
75
76\def\assign_alpha_dimension_direct#value#macro#small#medium#big{\edef#macro{#value}}
77
78\setvalue{\??dimensionalfa\v!none   }#value#macro#small#medium#big{\let #macro\!!zerocount}
79\setvalue{\??dimensionalfa\v!small  }#value#macro#small#medium#big{\edef#macro{#small}}
80\setvalue{\??dimensionalfa\v!medium }#value#macro#small#medium#big{\edef#macro{#medium}}
81\setvalue{\??dimensionalfa\v!big    }#value#macro#small#medium#big{\edef#macro{#big}}
82\letvalue{\??dimensionalfa\s!unknown}\assign_alpha_dimension_direct
83
84% \protected\def\assignalfadimension#value%
85%   {\csname\??dimensionalfa\ifcsname\??dimensionalfa#value\endcsname#value\else\s!unknown\fi\endcsname{#value}}
86
87\protected\def\assignalfadimension#value%
88  {\ifcsname\??dimensionalfa#value\endcsname
89     \expandafter\lastnamedcs
90   \else
91     \expandafter\assign_alpha_dimension_direct
92   \fi
93   {#value}}
94
95%D \macros
96%D   {assignvalue}
97%D
98%D A variant that does not assume dimenions ios the following:
99%D
100%D \starttyping
101%D \assignvalue
102%D   {<value>|small|medium|big}
103%D   {\macro}
104%D   {value small}
105%D   {value medium}
106%D   {value big}
107%D \stoptyping
108
109\installcorenamespace{dimensionvalue}
110
111\def\assign_value_direct#value#macro#small#medium#big{\edef#macro{#value}}
112
113\setvalue{\??dimensionvalue\v!small  }#value#macro#small#medium#big{\edef#macro{#small}}
114\setvalue{\??dimensionvalue\v!medium }#value#macro#small#medium#big{\edef#macro{#medium}}
115\setvalue{\??dimensionvalue\v!big    }#value#macro#small#medium#big{\edef#macro{#big}}
116\letvalue{\??dimensionvalue\s!unknown}\assign_value_direct
117
118% \protected\def\assignvalue#value%
119%   {\csname\??dimensionvalue\ifcsname\??dimensionvalue#value\endcsname#value\else\s!unknown\fi\endcsname{#value}}
120
121\protected\def\assignvalue#value%
122  {\ifcsname\??dimensionvalue#value\endcsname
123     \expandafter\lastnamedcs
124   \else
125     \expandafter\assign_value_direct
126  \fi{#value}}
127
128%D \macros
129%D   {assignwidth}
130%D
131%D Een breedte van een opgegeven tekst kan worden berekend en
132%D toegekend aan een \DIMENSION\ met:
133%D
134%D \starttyping
135%D \assignwidth
136%D   {<value>|fit|broad}
137%D   {\dimension}
138%D   {text}
139%D   {extra}
140%D \stoptyping
141
142\installcorenamespace{dimensionwidth}
143
144\newbox\b_assign_width
145
146\def\assign_width_direct#value#dimension#content#extra{#dimension=#value\relax}
147
148% line is like fit but can be used later as signal for ...
149
150\setvalue{\??dimensionwidth          }#value#dimension#content#extra{\setbox\b_assign_width\hbox{#content}#dimension\wd\b_assign_width
151                                                                     \setbox\b_assign_width\emptybox}
152\setvalue{\??dimensionwidth\v!fit    }#value#dimension#content#extra{\setbox\b_assign_width\hbox{#content}#dimension\wd\b_assign_width
153                                                                     \setbox\b_assign_width\emptybox}
154\setvalue{\??dimensionwidth\v!broad  }#value#dimension#content#extra{\setbox\b_assign_width\hbox{#content}#dimension\dimexpr\wd\b_assign_width+#extra\relax
155                                                                     \setbox\b_assign_width\emptybox}
156\setvalue{\??dimensionwidth\v!line   }#value#dimension#content#extra{\setbox\b_assign_width\hbox{#content}#dimension\wd\b_assign_width
157                                                                     \setbox\b_assign_width\emptybox}
158\letvalue{\??dimensionwidth\s!unknown}\assign_width_direct
159
160% \protected\def\assignwidth#value%
161%   {\csname\??dimensionwidth\ifcsname\??dimensionwidth#value\endcsname#value\else\s!unknown\fi\endcsname{#value}}
162
163\protected\def\assignwidth#value%
164  {\ifcsname\??dimensionwidth#value\endcsname
165     \expandafter\lastnamedcs
166   \else
167     \expandafter\assign_width_direct
168   \fi{#value}}
169
170\protect \endinput
171