|
8 | 8 | - `style-dep`: the styling function that will be applied to the dependencies. Optional: Default is `content => text(style: "italic", content)`. |
9 | 9 | - `style-formula`: the styling function that will be applied to the formula. Optional: Default is `content => content`. |
10 | 10 | - `style-rule`: the styling function that will be applied to the rule. Optional: Default is `content => text(style: "bold", content)`. |
| 11 | +- `nested-boxes`: instead of using indentation lines, use nested boxes. Optional: Default is `false`. |
11 | 12 |
|
12 | 13 | */ |
13 | 14 |
|
|
160 | 161 | ) |
161 | 162 | } |
162 | 163 |
|
163 | | -#let ded-nat-alt( |
164 | | - stcolor: black, |
165 | | - arr: array, |
166 | | - style-dep: derive-it-internal-default-style-dep, |
167 | | - style-formula: derive-it-internal-default-style-formula, |
168 | | - style-rule: derive-it-internal-default-style-rule, |
169 | | -) = context { |
170 | | - assert(type(arr) == array, message: "The input must be an array.") |
171 | | - |
172 | | - // validate the input and obtain metrics |
173 | | - let ( |
174 | | - has-dependencies, |
175 | | - line-size, |
176 | | - max-dep-width, |
177 | | - max-indent-level, |
178 | | - max-formula-width, |
179 | | - arr, |
180 | | - ) = derive-it-internal-array-checks(arr, style-dep, style-formula, style-rule) |
181 | | - |
182 | | - let maxWidth = 0pt |
183 | | - let tupArr = () |
184 | | - let i = 0 |
185 | | - while i < arr.len() { |
186 | | - if not has-dependencies { |
187 | | - arr.at(i).insert(0, none) |
188 | | - } |
189 | | - let (dep, indent, formula, rule) = arr.at(i) |
190 | | - |
191 | | - // +1 -> more indented |
192 | | - // -1 -> less indented |
193 | | - // 0 -> equally indented |
194 | | - let prev-indentation-diff = if (i == 0) { -1 } else { |
195 | | - // previous line arrays always have 4 elements (dep=none) |
196 | | - arr.at(i - 1).at(1) - indent |
197 | | - } |
198 | | - let next-indentation-diff = if (arr.len() <= i + 1) { -1 } else { |
199 | | - let ix = if has-dependencies { 1 } else { 0 } |
200 | | - arr.at(i + 1).at(ix) - indent |
201 | | - } |
202 | | - |
203 | | - let bl = formula |
204 | | - |
205 | | - ///////////////////////// FOR ///////////////////////////// |
206 | | - for indent-index in range(0, max-indent-level + 1) { |
207 | | - let stroke = (top: 0pt, right: 0pt, bottom: 0pt, left: 0pt) |
208 | | - let strength = if (indent >= max-indent-level - indent-index) { |
209 | | - 1pt |
210 | | - } else { 0.0pt } // 'else' branch for debugging |
211 | | - // current level of indentation needs box stroke |
212 | | - let stroke-line-config = strength + stcolor |
213 | | - |
214 | | - if (indent == (max-indent-level - indent-index)) { |
215 | | - // we're in the box that corresponds to the indentation of this formula |
216 | | - if prev-indentation-diff <= -1 { |
217 | | - // if the previous formula is in a lower indentation level |
218 | | - stroke.top = stroke-line-config |
219 | | - } |
220 | | - if next-indentation-diff <= -1 { |
221 | | - // if the next formula is in a lower indentation level |
222 | | - stroke.bottom = stroke-line-config |
223 | | - } |
224 | | - } |
225 | | - stroke.left = stroke-line-config |
226 | | - stroke.right = stroke-line-config |
227 | | - |
228 | | - let rect-width = if (indent-index == 0) { |
229 | | - max-formula-width + 10pt // 5pt each for left & right |
230 | | - } else { |
231 | | - auto |
232 | | - } |
233 | | - |
234 | | - let extra-spacing = if (indent-index == max-indent-level) { 0em } else { |
235 | | - 1em |
236 | | - } |
237 | | - |
238 | | - bl = [#box(inset: (x: extra-spacing, y: 0pt))[#rect( |
239 | | - stroke: stroke, |
240 | | - inset: if indent-index == 0 { 5pt } else { 0pt }, |
241 | | - width: rect-width, |
242 | | - )[#bl]]] |
243 | | - } |
244 | | - ///////////////////////// FOR ///////////////////////////// |
245 | | - |
246 | | - let line-index-content = box(width: 1.5em)[#(i + 1).] |
247 | | - |
248 | | - let numInset = (x: 0pt, y: 5pt) |
249 | | - let line = if has-dependencies { |
250 | | - let dependency = box(width: max-dep-width + 1em)[#dep] |
251 | | - let l = box[#box(inset: numInset)[#dependency #line-index-content] #bl] |
252 | | - maxWidth = calc.max(maxWidth, measure(l).width) |
253 | | - l |
254 | | - } else { |
255 | | - let l = box[#box(inset: numInset)[#line-index-content] #bl] |
256 | | - maxWidth = calc.max(maxWidth, measure(l).width) |
257 | | - l |
258 | | - } |
259 | | - |
260 | | - rule = box(baseline: -0.5em, rule) |
261 | | - tupArr.push((line, rule, indent)) |
262 | | - i += 1 |
263 | | - } |
264 | | - tupArr = tupArr.map(a => [#box(width: maxWidth, a.at(0)) #h(1em) #a.at(1)]) |
265 | | - |
266 | | - block( |
267 | | - align( |
268 | | - start, |
269 | | - stack(..tupArr), |
270 | | - ), |
271 | | - ) |
272 | | -} |
273 | | - |
274 | | - |
275 | 164 | #let ded-nat( |
276 | 165 | stcolor: black, |
277 | 166 | arr: array, |
|
366 | 255 | } |
367 | 256 |
|
368 | 257 | let rect-inset = if indent-index == 0 { 5pt } else { 0pt } |
369 | | - bl = box(stroke: 0.1pt+blue, inset: external-box-inset, rect( |
| 258 | + // add stroke for debugging |
| 259 | + bl = box(/* stroke: 0.0pt + blue, */ inset: external-box-inset, rect( |
370 | 260 | stroke: stroke, |
371 | 261 | inset: rect-inset, |
372 | 262 | width: rect-width, |
373 | 263 | bl, |
374 | 264 | )) |
375 | 265 | } |
376 | | - ///////////////////////// FOR ///////////////////////////// |
| 266 | + ///////////////////////// END FOR ///////////////////////////// |
377 | 267 |
|
378 | 268 | let line-index-content = box(width: 1.5em)[#(i + 1).] |
379 | | - let (ins, numInset) = if not nested-boxes and indent == 0 { |
| 269 | + let (line-inset, dep-and-number-inset) = if ( |
| 270 | + not nested-boxes and indent == 0 |
| 271 | + ) { |
380 | 272 | ((y: 0.5em), 0pt) |
381 | 273 | } else { |
382 | 274 | (0pt, (y: 5pt)) |
383 | 275 | } |
| 276 | + |
384 | 277 | let line = if has-dependencies { |
385 | 278 | let dependency = box(width: max-dep-width + 1em)[#dep] |
386 | | - let l = box(inset: ins)[#box( |
387 | | - inset: numInset, |
| 279 | + let l = box(inset: line-inset)[#box( |
| 280 | + inset: dep-and-number-inset, |
388 | 281 | )[#dependency #line-index-content] #bl] |
389 | 282 | maxWidth = calc.max(maxWidth, measure(l).width) |
390 | 283 | l |
391 | 284 | } else { |
392 | | - let l = box(inset: ins)[#box(inset: numInset)[#line-index-content] #bl] |
| 285 | + let l = box(inset: line-inset)[#box( |
| 286 | + inset: dep-and-number-inset, |
| 287 | + line-index-content, |
| 288 | + ) #bl] |
393 | 289 | maxWidth = calc.max(maxWidth, measure(l).width) |
394 | 290 | l |
395 | 291 | } |
|
420 | 316 | - `style-dep`: the styling function that will be applied to the dependencies. Optional: Default is `content => text(style: "italic", content)`. |
421 | 317 | - `style-formula`: the styling function that will be applied to the formula. Optional: Default is `content => content`. |
422 | 318 | - `style-rule`: the styling function that will be applied to the rule. Optional: Default is `content => text(style: "bold", content)`. |
| 319 | +- `nested-boxes`: instead of using indentation lines, use nested boxes. Optional: Default is `false`. |
423 | 320 |
|
424 | 321 | */ |
425 | 322 |
|
|
0 commit comments