|
86 | 86 | sorted-elems += whitespaces
|
87 | 87 | sorted-elems
|
88 | 88 | }
|
89 |
| - |
| 89 | + |
90 | 90 | // concatenate consecutive non-whitespace elements
|
91 | 91 | // i.e. just combine everything that definitely aren't
|
92 | 92 | // on separate lines
|
|
98 | 98 | if (
|
99 | 99 | child == [ ]
|
100 | 100 | or child == linebreak()
|
101 |
| - or child == parbreak() |
| 101 | + or child == parbreak() |
102 | 102 | ){
|
103 | 103 | if temp != [] {
|
104 | 104 | joined-children.push(temp)
|
105 | 105 | temp = []
|
106 | 106 | }
|
107 |
| - |
| 107 | + |
108 | 108 | joined-children.push(child)
|
109 | 109 | } else {
|
110 | 110 | temp += child
|
|
145 | 145 | let joined-lines = ()
|
146 | 146 | let line-parts = []
|
147 | 147 | let num-linebreaks = 0
|
148 |
| - |
149 |
| - for i, line in lines-and-breaks { |
| 148 | + |
| 149 | + for (i, line) in lines-and-breaks.enumerate() { |
150 | 150 | if line == linebreak() {
|
151 | 151 | if line-parts != [] {
|
152 | 152 | joined-lines.push(line-parts)
|
153 | 153 | line-parts = []
|
154 | 154 | }
|
155 |
| - |
| 155 | + |
156 | 156 | num-linebreaks += 1
|
157 |
| - |
| 157 | + |
158 | 158 | if num-linebreaks > 1 {
|
159 | 159 | joined-lines.push([])
|
160 | 160 | }
|
|
163 | 163 | num-linebreaks = 0
|
164 | 164 | }
|
165 | 165 | }
|
166 |
| - |
| 166 | + |
167 | 167 | if line-parts != [] {
|
168 | 168 | joined-lines.push(line-parts)
|
169 | 169 | }
|
170 | 170 |
|
171 | 171 | joined-lines
|
172 | 172 | }
|
173 | 173 | )
|
174 |
| - |
| 174 | + |
175 | 175 | let rows = ()
|
176 | 176 |
|
177 | 177 | // build table input (with line numbers if specified)
|
178 |
| - for i, line in display-lines { |
| 178 | + for (i, line) in display-lines.enumerate() { |
179 | 179 | let formatted-line = {
|
180 | 180 | counter("_algo-indent").display(n =>
|
181 | 181 | pad(
|
|
184 | 184 | )
|
185 | 185 | )
|
186 | 186 | }
|
187 |
| - |
| 187 | + |
188 | 188 | if line-numbers {
|
189 | 189 | let line-number = i + 1
|
190 | 190 | rows.push([#line-number])
|
191 | 191 | }
|
192 | 192 |
|
193 | 193 | rows.push(formatted-line)
|
194 | 194 | }
|
195 |
| - |
| 195 | + |
196 | 196 | align(center, block(
|
197 | 197 | width: auto,
|
198 | 198 | height: auto,
|
|
204 | 204 | )[
|
205 | 205 | #let algo-header = {
|
206 | 206 | set align(left)
|
207 |
| - |
| 207 | + |
208 | 208 | if title != none {
|
209 | 209 | set text(1.1em)
|
210 |
| - |
| 210 | + |
211 | 211 | if type(title) == "string" {
|
212 | 212 | underline(smallcaps(title))
|
213 | 213 | } else {
|
214 | 214 | title
|
215 | 215 | }
|
216 |
| - |
| 216 | + |
217 | 217 | if parameters.len() == 0 {
|
218 | 218 | $()$
|
219 | 219 | }
|
220 | 220 | }
|
221 |
| - |
| 221 | + |
222 | 222 | if parameters != () {
|
223 | 223 | set text(1.1em)
|
224 |
| - |
| 224 | + |
225 | 225 | $($
|
226 |
| - |
227 |
| - for i, param in parameters { |
| 226 | + |
| 227 | + for (i, param) in parameters.enumerate() { |
228 | 228 | if type(param) == "string" {
|
229 | 229 | math.italic(param)
|
230 | 230 | } else {
|
231 | 231 | param
|
232 | 232 | }
|
233 |
| - |
| 233 | + |
234 | 234 | if i < parameters.len() - 1 {
|
235 | 235 | [, ]
|
236 | 236 | }
|
237 | 237 | }
|
238 |
| - |
| 238 | + |
239 | 239 | $)$
|
240 | 240 | }
|
241 | 241 |
|
|
246 | 246 |
|
247 | 247 | #algo-header
|
248 | 248 | #v(weak: true, row-gutter)
|
249 |
| - |
| 249 | + |
250 | 250 | #align(left, table(
|
251 | 251 | columns: if line-numbers {2} else {1},
|
252 | 252 | column-gutter: column-gutter,
|
|
289 | 289 | set par(justify: false)
|
290 | 290 | let content = ()
|
291 | 291 | let i = 1
|
292 |
| - |
| 292 | + |
293 | 293 | for item in body.children {
|
294 | 294 | if item.func() == raw {
|
295 | 295 | for line in item.text.split("\n") {
|
296 | 296 | if line-numbers {
|
297 | 297 | content.push(str(i))
|
298 | 298 | }
|
299 |
| - |
| 299 | + |
300 | 300 | content.push(raw(line, lang: item.lang))
|
301 | 301 | i += 1
|
302 | 302 | }
|
303 | 303 | }
|
304 | 304 | }
|
305 |
| - |
| 305 | + |
306 | 306 | align(center, block(
|
307 | 307 | stroke: stroke,
|
308 | 308 | inset: inset,
|
|
0 commit comments