supp-mat.mkiv /size: 9736 b    last modification: 2021-10-28 13:50
1%D \module
2%D   [       file=supp-mat,
3%D        version=1998.09.10,
4%D          title=\CONTEXT\ Support Macros,
5%D       subtitle=Math,
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%D For practical reasons, I decided to move some math things to
15%D a support module. There is nothing spectacular here. It may move
16%D back to math-ini.
17
18\writestatus{loading}{ConTeXt Support Macros / Math}
19
20\unprotect
21
22%D \macros
23%D   {mathematics, math, nomathematics, startmathmode}
24%D
25%D The \type{$} can be both an begin and end math character.
26%D This can lead to confusing and errorprone situations when
27%D macros insert \type{$}. When for instance we have defined:
28%D
29%D \starttyping
30%D \def\MyPlus{$\,+\,$}
31%D \stoptyping
32%D
33%D the sequence \type{$x^2 \MyPlus y^2 = r^2$} will expand to:
34%D
35%D \starttyping
36%D $x^2 $\,+\,$ y^2 = r^2$
37%D \stoptyping
38%D
39%D Here the \type{\,} are given outside math mode and \TEX\ will
40%D definitely complain about this. A more save definition would
41%D have been:
42%D
43%D \starttyping
44%D \def\MyPlus{\mathematics{\,+\,}}
45%D \stoptyping
46%D
47%D Which is implemented (in \type{syst-ini.mkiv}) as:
48
49% \let\normalsuperscript\Usuperscript
50% \let\normalsubscript  \Usubscript
51% \let\normalstartimath \Ustartmath
52% \let\normalstopimath  \Ustopmath
53% \let\normalstartdmath \Ustartdisplaymath
54% \let\normalstopdmath  \Ustopdisplaymath
55
56% \protected\def\Ustartdisplaymath
57%   {\ifinner
58%      \ifhmode
59%        \normalUstartmath
60%        \let\Ustopdisplaymath\normalUstopmath
61%      \else
62%        \normalUstartdisplaymath
63%        \let\Ustopdisplaymath\normalUstopdisplaymath
64%      \fi
65%    \else
66%      \normalUstartdisplaymath
67%      \let\Ustopdisplaymath\normalUstopdisplaymath
68%    \fi}
69
70\protected\def\Ucheckedstartdisplaymath
71  {\ifinner
72     \ifhmode
73       \normalUstartmath
74       \let\Ucheckedstopdisplaymath\normalUstopmath
75     \else
76       \normalUstartdisplaymath
77       \let\Ucheckedstopdisplaymath\normalUstopdisplaymath
78     \fi
79   \else
80     \normalUstartdisplaymath
81     \let\Ucheckedstopdisplaymath\normalUstopdisplaymath
82   \fi}
83
84\let\Ucheckedstopdisplaymath\relax
85
86\def\normalmathaligntab{&} % \let\normalmathaligntab\aligntab does to work well in a let to & (a def works ok)
87
88\let\normalsuper       \Usuperscript       % obsolete
89\let\normalsuber       \Usubscript         % obsolete
90
91\let\startimath        \Ustartmath
92\let\stopimath         \Ustopmath
93\let\startdmath        \Ustartdisplaymath  % \Ucheckedstartdisplaymath
94\let\stopdmath         \Ustopdisplaymath   % \Ucheckedstopdisplaymath
95
96\protected\def\mathematics#1{\relax         \ifmmode#1\else\normalstartimath#1\normalstopimath\fi}
97\protected\def\displaymath#1{\noindent      \ifmmode#1\else\normalstartdmath#1\normalstopdmath\fi}
98\protected\def\inlinemath #1{\dontleavehmode\ifmmode#1\else\normalstartimath#1\normalstopimath\fi}
99\protected\def\textmath   #1{\dontleavehmode\ifmmode#1\else\begingroup\everymath\emptytoks\normalstartimath#1\normalstopimath\endgroup\fi} % \mathsurround\zeropoint
100
101\let\m\mathematics
102
103\let\stopmathmode\relax
104
105\protected\def\startmathmode % nested variant
106  {\relax\ifmmode
107     \begingroup
108     \let\stopmathmode\endgroup
109   \else
110     \normalstartimath
111     \let\stopmathmode\normalstopimath
112   \fi}
113
114\protected\def\nomathematics#1%
115  {\relax\ifmmode\hbox{#1}\else#1\fi}
116
117\let\math\mathematics
118
119%D \macros
120%D   {displaymathematics,inlinemathematics,automathematics}
121%D
122%D An example of usage of the following can be found in the MathML module:
123
124\ifdefined\strc_formulas_start_formula \else
125    \def\strc_formulas_start_formula{\normalstartdmath}
126    \def\strc_formulas_stop_formula {\normalstopdmath }
127\fi
128
129\protected\def\displaymathematics#1{\relax\ifmmode#1\else\strc_formulas_start_formula{}#1\strc_formulas_stop_formula\fi}
130\protected\def\inlinemathematics   {\dontleavehmode\mathematics}
131\protected\def\automathematics     {\relax\ifhmode\expandafter\inlinemathematics\else\expandafter\displaymathematics\fi}
132
133% better, esp when used in bTABLE ... eTABLE
134
135\protected\def\automathematics
136  {\relax
137   \ifhmode
138     \expandafter\inlinemathematics
139   \else\ifintable
140     \doubleexpandafter\inlinemathematics
141   \else
142     \doubleexpandafter\displaymathematics
143   \fi\fi}
144
145%D \macros
146%D   {dimension, nodimension}
147%D
148%D The next few macros are used for typesetting dimensions in
149%D such a way that spacing is acceptable. I won't spend much
150%D words on these macros, because they will be overloaded in
151%D the units module.
152%D
153%D REPLACED (keep commented):
154
155\newsignal\dimensionsignal
156
157\def\dimensiontypeface  {\tf}
158\def\dimensionhalfspace {\,}
159
160\protected\def\dimension#1%
161  {\pushmacro\dodimensionsignal
162   \gdef\dodimensionsignal{\kern\dimensionsignal}%
163   \ifzeropt\lastskip
164     \ifzeropt\lastkern
165       \ifmmode
166         \mathematics{\dimensionhalfspace\dimensionhalfspace\dimensiontypeface#1}%
167       \else
168         \mathematics{\dimensiontypeface#1}%
169       \fi
170     \else\ifdim\lastkern=\dimensionsignal
171       \mathematics{\dimensionhalfspace\dimensiontypeface#1}%
172     \else
173       \unkern\mathematics{\dimensionhalfspace\dimensionhalfspace\dimensiontypeface#1}%
174     \fi\fi
175   \else
176     \unskip\mathematics{\dimensionhalfspace\dimensionhalfspace\dimensiontypeface#1}%
177   \fi
178   \dodimensionsignal
179   \popmacro\dodimensionsignal}
180
181\protected\def\nodimension#1%
182  {\unskip#1\glet\dodimensionsignal\relax}
183
184%D \macros
185%D   {cramped}
186%D
187%D Cramped math:
188%D
189%D \startbuffer
190%D \ruledhbox{$\left\{{x^2\over y^2}\right\}$}
191%D \ruledhbox{$\cramped{\left\{ {x^2\over y^2}\right\}}$}
192%D \stopbuffer
193%D
194%D \typebuffer \getbuffer
195
196\protected\def\cramped
197  {\mathpalette\math_cramped}
198
199%D We force a cramped style by issuing a non||existing radical (box).
200%D After that we make sure the height is correct. (Comment taken from
201%D Morten Høgholm's mathtools package.) Macro suggested by AM and
202%D cleaned up a bit by HH.
203
204% original
205%
206% \def\docramped#1#2%
207%   {\setbox\scratchbox\hbox
208%     {\nulldelimiterspace\zeropoint
209%      $\mathsurround\zeropoint#1\radical\zerocount{#2}$}%
210%    \ifx#1\displaystyle
211%       \scratchdimen\fontdimen8\textfont3
212%       \advance\scratchdimen .25\fontdimen5\textfont2
213%    \else
214%       \scratchdimen1.25\fontdimen8
215%       \ifx#1\textstyle\textfont
216%       \else
217%         \ifx#1\scriptstyle\scriptfont\else\scriptscriptfont\fi
218%       \fi
219%       3
220%     \fi
221%     \advance\scratchdimen-\ht\scratchbox
222%     \ht\scratchbox-\scratchdimen
223%     \box\scratchbox}
224
225% mkii:
226%
227% \def\math_cramped#1#2%
228%   {\begingroup % added HH, made even more cramped
229%    \setbox\scratchbox\hbox
230%      {\nulldelimiterspace\zeropoint
231%       \normalstartimath\mathsurround\zeropoint#1\radical\zerocount{#2}\normalstopimath}%
232%    \ht\scratchbox-\dimexpr
233%      \ifx#1\displaystyle
234%        \fontdimen\pluseight\textfont\plusthree
235%        +.25\fontdimen\plusfive\textfont\plustwo
236%      \else
237%         1.25\fontdimen\pluseight
238%           \ifx#1\textstyle
239%             \textfont
240%           \else\ifx#1\scriptstyle
241%             \scriptfont
242%           \else
243%             \scriptscriptfont
244%           \fi \fi
245%           \plusthree
246%      \fi
247%      -\ht\scratchbox
248%    \relax
249%    \box\scratchbox
250%    \endgroup}
251
252\def\math_cramped#1#2% we have all in one family
253  {\begingroup % added HH, made even more cramped
254   \setbox\scratchbox\hbox
255     {\nulldelimiterspace\zeropoint
256      \normalstartimath\mathsurround\zeropoint#1\radical\zerocount{#2}\normalstopimath}%
257   \ht\scratchbox-\dimexpr
258     \ifx#1\displaystyle
259            \fontdimen\pluseight\textfont\plusone
260       + .25\fontdimen\plusfive \textfont\plusone
261     \else
262        1.25\fontdimen\pluseight
263         \ifx#1\textstyle  \textfont        \else
264         \ifx#1\scriptstyle\scriptfont      \else
265                           \scriptscriptfont\fi\fi \plusone
266     \fi
267     -\ht\scratchbox
268   \relax
269   \box\scratchbox
270   \endgroup}
271
272%D \macros
273%D    {cramedllap, crampedrlap, crampedclap}
274%D
275%D In many cases, one wants to use the \tex {clap} macro in
276%D math mode while using subscripts. Normally, subscripts are
277%D in cramped mode, and these macros allow you to go to
278%D cramped mode. For example:
279%D
280%D \startbuffer
281%D \startformula
282%D   \sum_{a^2 < b^2 < c^2} \quad
283%D   \sum_{\clap{a^2 < b^2 < c^2}} \quad
284%D   \sum_{\crampedclap{a^2 < b^2 < c^2}}
285%D \stopformula
286%D \stopbuffer
287%D
288%D \start
289%D   \typebuffer
290%D   \switchtobodyfont[24pt]
291%D   \getbuffer
292%D \stop
293%D
294%D Notice that \type {\clap{\cramped ... }} would also work,
295%D but it requires \TEX\ to typeset it arguments 16 times.
296
297\protected\def\crampedllap{\mathpalette\math_cramped_llap}
298\protected\def\crampedrlap{\mathpalette\math_cramped_rlap}
299\protected\def\crampedclap{\mathpalette\math_cramped_clap}
300
301\def\math_cramped_llap#1#2{{}\dollap{\math_cramped #1{#2}}}
302\def\math_cramped_rlap#1#2{{}\dorlap{\math_cramped #1{#2}}}
303\def\math_cramped_clap#1#2{{}\doclap{\math_cramped #1{#2}}}
304
305% experiment, not yet to be used
306
307% \protected\def\displaybreak
308%   {\ifhmode
309%      \removeunwantedspaces
310%      \ifcase\raggedstatus\hfill\fi
311%      \strut\penalty-9999 % \break fails on case (3)
312%    \fi}
313%
314% \def\startdisplay{\displaybreak\ignorespaces\startpacked}
315% \def\stopdisplay {\stoppacked\displaybreak\ignorespaces}
316
317\let\superscript  \Usuperscript
318\let\subscript    \Usubscript
319\let\nosuperscript\Unosuperscript
320\let\nosubscript  \Unosubscript
321
322% only in luametatex:
323
324\let\superprescript  \Usuperprescript
325\let\subprescript    \Usubprescript
326\let\nosuperprescript\Unosuperprescript
327\let\nosubsprecript  \Unosubprescript
328
329\protect \endinput
330