Closed OrangeX4 closed 9 months ago
Lovelace is a unopinionated and flexible pseudocode package and i think it is great.
But I still think there's some points for improvement here, why don't we use a simpler raw text to identify Indent? Something like this:
#import "@preview/lovelace:0.1.0": * #show: setup-lovelace #let _typst2lovelace(typst-code, scope: (:)) = { let indent = 0 let last-indent = 0 let res = () for line in typst-code.text.split("\n") { let whitespaces = line.find(regex("^\\s+")) let current-indent = if (whitespaces != none) { whitespaces.len() } else { 0 } if (indent == 0 and current-indent != 0) { indent = current-indent } if (current-indent > last-indent) { res = res + (ind,) * int((current-indent - last-indent) / indent) } else if (current-indent < last-indent) { res = res + (ded,) * int((last-indent - current-indent) / indent) } last-indent = current-indent let line-code = line.slice(current-indent) let match = line-code.match(regex("^<(.*)>\\s*$")) if (match != none) { res.push(label(match.captures.at(0))) } else { res.push(eval(line-code, mode: "markup", scope: (no-number: no-number, comment: comment) + scope)) } } res } #pseudocode(.._typst2lovelace( ```typ *input:* integers $a$ and $b$ *output:* greatest common divisor of $a$ and $b$ *while* $a != b$ *do* *if* $a > b$ *then* $a <- a - b$ *else* $b <- b - a$ *end* *end* *return* $a$``` ))
I think that might be better :-)
Interesting idea! I'm not sure about the name yet but I'd be happy to review a PR implementing this.
I have opened a pr: https://github.com/andreasKroepelin/lovelace/pull/3
Fixed by #3
Lovelace is a unopinionated and flexible pseudocode package and i think it is great.
But I still think there's some points for improvement here, why don't we use a simpler raw text to identify Indent? Something like this:
I think that might be better :-)