typo-stc.mkxl /size: 6229 b    last modification: 2025-02-21 11:03
1%D \module
2%D   [       file=typo-stc,
3%D        version=20240619,
4%D          title=\CONTEXT\ Typesetting Macros,
5%D       subtitle=Stacking,
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% todo: textstyle|color for inline \quotation etc
15
16\writestatus{loading}{ConTeXt Typesetting Macros / Stacking}
17
18\registerctxluafile{typo-stc}{autosuffix}
19
20\unprotect
21
22%D \starttyping
23%D \definestacking[one]
24%D \definestacking[two]
25%D
26%D \startbuffer
27%D This is a test \stacking [one] {and a proof} of \stacking [two] {concept} indeed \stacking [one]
28%D {\blackrule [width=4cm]} is it and the question is how \stacking [two] {\scale [s=2]
29%D {fancy}} we can go
30%D
31%D \startstacking[one]
32%D \startformula
33%D     \sqrt{1+x}
34%D \stopformula
35%D \stopstacking
36%D
37%D and how useful \stacking[two]{\inframed{it}} is.
38%D \stopbuffer
39%D
40%D \startstackingsteps[one,two,{one,two}]
41%D     \getbuffer
42%D \stopstackingsteps
43%D
44%D \startTEXpage[offset=1ts] \setupstacking[criterium={one}]     \getbuffer \stopTEXpage
45%D \startTEXpage[offset=1ts] \setupstacking[criterium={two}]     \getbuffer \stopTEXpage
46%D \startTEXpage[offset=1ts] \setupstacking[criterium={one,two}] \getbuffer \stopTEXpage
47%D \stoptyping
48
49\installcorenamespace {stacking}
50
51\installcommandhandler \??stacking {stacking} \??stacking
52
53\definesystemattribute[stacking][global]
54
55\appendtoks
56    \expandafter\setnewconstant\csname\??stacking:\currentstacking\endcsname
57        \clf_newstacking{\currentstacking}{\stackingparameter\c!number}%
58    \relax
59    \ifcstok{\stackingparameter\c!define}\v!yes
60        \frozen\instance\protected\edefcsname        \currentstacking\endcsname{\typo_stacking{\currentstacking}}%
61        \frozen\instance\protected\edefcsname\e!start\currentstacking\endcsname{\typo_stacking_start{\currentstacking}}%
62        \frozen\instance\protected\edefcsname\e!stop \currentstacking\endcsname{\typo_stacking_stop}%
63    \fi
64\to \everydefinestacking
65
66\def\typo_stacking_set
67  {\c_attr_stacking
68     \ifcsname\??stacking:\currentstacking\endcsname
69       \lastnamedcs
70     \orelse\ifchknum\currentstacking\or
71   % \orelse\ifchknumber\currentstacking\or
72       \currentstacking
73     \else
74       \attributeunsetvalue
75     \fi
76     \relax}
77
78\protected\def\resetstacking
79  {\c_attr_stacking\attributeunsetvalue}
80
81\protected\def\typo_stacking#1#2%
82  {\begingroup
83   \cdef\currentstacking{#1}%
84   \typo_stacking_set
85   #2%
86   \endgroup}
87
88\protected\def\typo_start_stacking#1%
89  {\begingroup
90   \cdef\currentstacking{#1}%
91   \typo_stacking_set}
92
93\protected\def\typo_stop_stacking
94  {\endgroup}
95
96\permanent\protected\def\stacking     [#1]{\typo_stacking{#1}}
97\permanent\protected\def\startstacking[#1]{\typo_start_stacking{#1}}
98\permanent\protected\def\stopstacking     {\typo_stop_stacking}
99
100\appendtoks
101    \clf_setstacking{\namedstackingparameter\empty\c!criterium}%
102\to \everysetupstacking
103
104% \definestacking[stack][define=yes]
105
106\def\typo_stacking_step#1%
107  {\setupstacking[\c!criterium={#1}]%
108   \getbuffer[stackingsteps]%
109   \page}
110
111\permanent\tolerant\protected\def\startstackingsteps[#1]%
112  {\page
113   \begingroup
114   \edef\stackingsteplist{#1}%
115   \begingroup
116   \buff_grab_direct[stackingsteps][stackingsteps][startstackingsteps][stopstackingsteps]}
117
118\permanent\protected\def\stopstackingsteps
119  {%\endgroup
120   \processcommacommand[\stackingsteplist]\typo_stacking_step
121   \endgroup}
122
123%D For Aditya Mahajan: ranges and such.
124%D
125%D \starttyping
126%D \starttext
127%D \startstackingsteps[1,{1:2,201},{1:3,301},{1,2,4},{1-5},{1-6},{1-7}]
128%D     \startTEXpage
129%D         \startstacking[1]   \framed{ONE}    \stopstacking
130%D         \startstacking[2]   \framed{TWO}    \stopstacking
131%D         \startstacking[201] \framed{MORE}   \stopstacking
132%D         \startstacking[3]   \framed{THREE}  \stopstacking
133%D         \startstacking[301] \framed{INDEED} \stopstacking
134%D         \startstacking[4]   \framed{FOUR}   \stopstacking
135%D         \startstacking[5]   \framed{\im {\sqrt {
136%D              \stacking[6] { 1 + x ^ {
137%D              \stacking[7] { 2 } } } } }}
138%D         \stopstacking
139%D     \stopTEXpage
140%D \stopstackingsteps
141%D \stoptext
142%D \stoptyping
143
144\lettonothing\currenthidestacking
145\lettonothing\currentvidestacking
146
147\def\hidestacking[#1]%
148  {\lettonothing\currentvidestacking
149   \cdef\currenthidestacking{#1}}
150
151\def\videstacking[#1]%
152  {\lettonothing\currenthidestacking
153   \cdef\currentvidestacking{#1}}
154
155% slow, we need a doifinrange
156
157\def\typo_stacking_hide#1{\ifnum#1=\scratchcounter     \c_attr_stacking\zerocount\fi}
158\def\typo_stacking_vide#1{\ifnum#1=\scratchcounter\else\c_attr_stacking\zerocount\fi}
159
160\def\typo_stacking_unstack_hide
161  {\clf_enablestacking
162   \dowithrange\currenthidestacking\typo_stacking_hide}
163
164\def\typo_stacking_unstack_vide
165  {\clf_enablestacking
166   \dowithrange\currentvidestacking\typo_stacking_vide}
167
168\protected\def\typo_stacking_unstack
169  {\ifcase\scratchcounter
170     \c_attr_stacking\attributeunsetvalue % or -1
171   \orunless\ifempty\currenthidestacking
172     \typo_stacking_unstack_hide
173   \orunless\ifempty\currentvidestacking
174     \typo_stacking_unstack_vide
175  %\else
176     % nothing
177   \fi}
178
179\permanent\tolerant\protected\def\unstacking[#1]% empty resets
180  {\groupedcommand
181     {\scratchcounter\ifparameter#1\or#1\else\zerocount\fi\typo_stacking_unstack}
182     \donothing}
183
184%D For Mikael Sundqvist: just hiding
185%D
186%D \starttyping
187%D \starttext
188%D \startbuffer
189%D \startformula
190%D   4 \alignhere = 2 \unstacking[1]{+}                2 \breakhere
191%D   4 \alignhere = 2 \unstacking[2]{+\unstacking{!}}  2 \breakhere
192%D   4 \alignhere = 2 \unstacking[2]{+\unstacking{!}+} 2
193%D \stopformula
194%D \stopbuffer
195%D
196%D                    \getbuffer \blank[2*big]
197%D \hidestacking[1]   \getbuffer \blank[2*big]
198%D \hidestacking[2]   \getbuffer \blank[2*big]
199%D \hidestacking[1:2] \getbuffer \page
200%D
201%D                    \getbuffer \blank[2*big]
202%D \videstacking[1]   \getbuffer \blank[2*big]
203%D \videstacking[2]   \getbuffer \blank[2*big]
204%D \videstacking[1:2] \getbuffer \page
205%D \stoptext
206%D \stoptyping
207
208\protect \endinput
209