From 6aa83511b9328dfba3932edc77ffd5eaee9fd390 Mon Sep 17 00:00:00 2001 From: mgt Date: Sun, 26 May 2024 12:44:33 +0800 Subject: [PATCH] feat: allow single item code block be put in a single line --- src/pretty/mod.rs | 2 +- src/util.rs | 26 +- tests/assets/unit/code/short-if.typ | 6 + ...ssets__check_file@cetz-manual.typ-120.snap | 18 +- ...assets__check_file@cetz-manual.typ-40.snap | 4 +- ...assets__check_file@cetz-manual.typ-80.snap | 14 +- .../assets__check_file@cetz-tree.typ-120.snap | 70 +- .../assets__check_file@cetz-tree.typ-40.snap | 8 +- .../assets__check_file@cetz-tree.typ-80.snap | 50 +- ...sets__check_file@simple-paper.typ-120.snap | 4 +- ...ssets__check_file@simple-paper.typ-80.snap | 4 +- .../assets__check_file@tablex.typ-120.snap | 654 ++++-------------- .../assets__check_file@tablex.typ-40.snap | 196 ++---- .../assets__check_file@tablex.typ-80.snap | 417 +++-------- ...38-non-converge-block-comment.typ-120.snap | 6 +- ...138-non-converge-block-comment.typ-40.snap | 6 +- ...138-non-converge-block-comment.typ-80.snap | 6 +- ...check_file@undergraduate-math.typ-120.snap | 8 +- ..._check_file@undergraduate-math.typ-80.snap | 8 +- ...eck_file@unit-code-arg-flavor.typ-120.snap | 8 +- ...heck_file@unit-code-arg-flavor.typ-40.snap | 4 +- ...heck_file@unit-code-arg-flavor.typ-80.snap | 8 +- ...k_file@unit-code-array-flavor.typ-120.snap | 4 +- ...ck_file@unit-code-array-flavor.typ-40.snap | 4 +- ...ck_file@unit-code-array-flavor.typ-80.snap | 4 +- ...ts__check_file@unit-code-cond.typ-120.snap | 10 +- ...ets__check_file@unit-code-cond.typ-40.snap | 10 +- ...ets__check_file@unit-code-cond.typ-80.snap | 10 +- ...unit-code-for-loop-line-break.typ-120.snap | 6 +- ...@unit-code-for-loop-line-break.typ-40.snap | 4 +- ...@unit-code-for-loop-line-break.typ-80.snap | 10 +- ...check_file@unit-code-short-if.typ-120.snap | 11 + ..._check_file@unit-code-short-if.typ-40.snap | 15 + ..._check_file@unit-code-short-if.typ-80.snap | 11 + ...-comment-comment-in-func-call.typ-120.snap | 4 +- ...t-comment-comment-in-func-call.typ-40.snap | 4 +- ...t-comment-comment-in-func-call.typ-80.snap | 4 +- ...t-comment-line-comment-attach.typ-120.snap | 4 +- ...it-comment-line-comment-attach.typ-80.snap | 4 +- ...__check_file@unit-func-spread.typ-120.snap | 4 +- ...s__check_file@unit-func-spread.typ-40.snap | 4 +- ...s__check_file@unit-func-spread.typ-80.snap | 4 +- ...it-markup-code-inside-content.typ-120.snap | 4 +- ...nit-markup-code-inside-content.typ-40.snap | 4 +- ...nit-markup-code-inside-content.typ-80.snap | 4 +- ...ck_file@unit-math-var-in-math.typ-120.snap | 6 +- ...eck_file@unit-math-var-in-math.typ-80.snap | 6 +- ...e@unit-show-code-show-closure.typ-120.snap | 4 +- ...le@unit-show-code-show-closure.typ-80.snap | 4 +- 49 files changed, 448 insertions(+), 1242 deletions(-) create mode 100644 tests/assets/unit/code/short-if.typ create mode 100644 tests/snapshots/assets__check_file@unit-code-short-if.typ-120.snap create mode 100644 tests/snapshots/assets__check_file@unit-code-short-if.typ-40.snap create mode 100644 tests/snapshots/assets__check_file@unit-code-short-if.typ-80.snap diff --git a/src/pretty/mod.rs b/src/pretty/mod.rs index 09b85f35..bf1898f4 100644 --- a/src/pretty/mod.rs +++ b/src/pretty/mod.rs @@ -429,7 +429,7 @@ impl PrettyPrinter { BoxDoc::nil(), (BoxDoc::text("{"), BoxDoc::text("}")), true, - FoldStyle::Never, + FoldStyle::Single, ); doc } diff --git a/src/util.rs b/src/util.rs index 308a1ca9..106efe37 100644 --- a/src/util.rs +++ b/src/util.rs @@ -3,11 +3,15 @@ use pretty::BoxDoc; use crate::attr::Attributes; /// A style for formatting items +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum FoldStyle { /// Fold items if them can fit in a single line Fit, /// Never fold items Never, + /// Fold items if there is only one item + /// Behaves like `Fit` if there is only one item, otherwise `Never` + Single, } impl FoldStyle { @@ -25,13 +29,20 @@ impl FoldStyle { } } -pub fn comma_seprated_items<'a, I>(items: I, fold_style: FoldStyle) -> BoxDoc<'a, ()> +pub fn comma_seprated_items<'a, I>(items: I, mut fold_style: FoldStyle) -> BoxDoc<'a, ()> where I: IntoIterator> + ExactSizeIterator, { if items.len() == 0 { return BoxDoc::text("()"); } + if fold_style == FoldStyle::Single { + fold_style = if items.len() == 1 { + FoldStyle::Fit + } else { + FoldStyle::Never + }; + } let comma_ = BoxDoc::text(",").flat_alt(BoxDoc::nil()); match fold_style { FoldStyle::Fit => { @@ -55,6 +66,9 @@ where .append(BoxDoc::hardline()) .append(")") } + FoldStyle::Single => { + unreachable!(); + } } } @@ -64,7 +78,7 @@ pub fn pretty_items<'a>( multi_line_separator: BoxDoc<'a, ()>, bracket: (BoxDoc<'a, ()>, BoxDoc<'a, ()>), bracket_space: bool, - fold_style: FoldStyle, + mut fold_style: FoldStyle, ) -> BoxDoc<'a, ()> { if items.is_empty() { return bracket.0.append(if bracket_space { @@ -73,6 +87,13 @@ pub fn pretty_items<'a>( bracket.1 }); } + if fold_style == FoldStyle::Single { + fold_style = if items.len() == 1 { + FoldStyle::Fit + } else { + FoldStyle::Never + }; + } pretty_items_impl( items, single_line_separator, @@ -118,6 +139,7 @@ fn pretty_items_impl<'a>( match fold_style { FoldStyle::Fit => auto_items, FoldStyle::Never => multi, + FoldStyle::Single => unreachable!(), } } diff --git a/tests/assets/unit/code/short-if.typ b/tests/assets/unit/code/short-if.typ new file mode 100644 index 00000000..fddfc7df --- /dev/null +++ b/tests/assets/unit/code/short-if.typ @@ -0,0 +1,6 @@ +#table( + fill: (x, y) => if y == 0 { white.darken(15%) } else { none }, + align: (x, y) => if y == 0 { center } else { horizon }, + [Hi], + [there], +) diff --git a/tests/snapshots/assets__check_file@cetz-manual.typ-120.snap b/tests/snapshots/assets__check_file@cetz-manual.typ-120.snap index b54612dd..1a788190 100644 --- a/tests/snapshots/assets__check_file@cetz-manual.typ-120.snap +++ b/tests/snapshots/assets__check_file@cetz-manual.typ-120.snap @@ -23,9 +23,7 @@ input_file: tests/assets/cetz-manual.typ #set terms(indent: 1em) #set par(justify: true) -#set heading(numbering: (..num) => if num.pos().len() < 4 { - numbering("1.1", ..num) -}) +#set heading(numbering: (..num) => if num.pos().len() < 4 { numbering("1.1", ..num) }) #show link: set text(blue) // Outline @@ -58,9 +56,7 @@ Note that draw functions are imported inside the scope of the `canvas` block. Th #show raw.where(block: false): it => if it.text.starts-with("<") and it.text.ends-with(">") { set text(1.2em) doc-style.show-type(it.text.slice(1, -1)) -} else { - it -} +} else { it } == CeTZ Unique Argument Types Many CeTZ functions expect data in certain formats which we will call types. Note that these are actually made up of Typst primitives. @@ -233,11 +229,7 @@ Marks are arrow tips that can be added to the end of path based elements that su let name-to-mnemonic = (:) for (name, item) in cetz.mark-shapes.mnemonics { let list = name-to-mnemonic.at(item.at(0), default: ()) - list += ( - raw(name) + if item.at(1) { - " (reversed)" - }, - ) + list += (raw(name) + if item.at(1) { " (reversed)" },) name-to-mnemonic.insert(item.at(0), list) } ( @@ -1066,9 +1058,7 @@ The palette library provides some predefined palettes. { import cetz.draw: * for i in range(0, p("len")) { - if calc.rem(i, 10) == 0 { - move-to((rel: (0, -.5))) - } + if calc.rem(i, 10) == 0 { move-to((rel: (0, -.5))) } rect((), (rel: (1, .5)), name: "r", ..p(i)) move-to("r.south-east") } diff --git a/tests/snapshots/assets__check_file@cetz-manual.typ-40.snap b/tests/snapshots/assets__check_file@cetz-manual.typ-40.snap index bfffbcdf..6e209ef8 100644 --- a/tests/snapshots/assets__check_file@cetz-manual.typ-40.snap +++ b/tests/snapshots/assets__check_file@cetz-manual.typ-40.snap @@ -68,9 +68,7 @@ Note that draw functions are imported inside the scope of the `canvas` block. Th doc-style.show-type( it.text.slice(1, -1), ) -} else { - it -} +} else { it } == CeTZ Unique Argument Types Many CeTZ functions expect data in certain formats which we will call types. Note that these are actually made up of Typst primitives. diff --git a/tests/snapshots/assets__check_file@cetz-manual.typ-80.snap b/tests/snapshots/assets__check_file@cetz-manual.typ-80.snap index b98871bc..22677e3d 100644 --- a/tests/snapshots/assets__check_file@cetz-manual.typ-80.snap +++ b/tests/snapshots/assets__check_file@cetz-manual.typ-80.snap @@ -58,9 +58,7 @@ Note that draw functions are imported inside the scope of the `canvas` block. Th #show raw.where(block: false): it => if it.text.starts-with("<") and it.text.ends-with(">") { set text(1.2em) doc-style.show-type(it.text.slice(1, -1)) -} else { - it -} +} else { it } == CeTZ Unique Argument Types Many CeTZ functions expect data in certain formats which we will call types. Note that these are actually made up of Typst primitives. @@ -238,11 +236,7 @@ Marks are arrow tips that can be added to the end of path based elements that su let name-to-mnemonic = (:) for (name, item) in cetz.mark-shapes.mnemonics { let list = name-to-mnemonic.at(item.at(0), default: ()) - list += ( - raw(name) + if item.at(1) { - " (reversed)" - }, - ) + list += (raw(name) + if item.at(1) { " (reversed)" },) name-to-mnemonic.insert(item.at(0), list) } ( @@ -1111,9 +1105,7 @@ The palette library provides some predefined palettes. { import cetz.draw: * for i in range(0, p("len")) { - if calc.rem(i, 10) == 0 { - move-to((rel: (0, -.5))) - } + if calc.rem(i, 10) == 0 { move-to((rel: (0, -.5))) } rect((), (rel: (1, .5)), name: "r", ..p(i)) move-to("r.south-east") } diff --git a/tests/snapshots/assets__check_file@cetz-tree.typ-120.snap b/tests/snapshots/assets__check_file@cetz-tree.typ-120.snap index 87157d14..e40c9f5d 100644 --- a/tests/snapshots/assets__check_file@cetz-tree.typ-120.snap +++ b/tests/snapshots/assets__check_file@cetz-tree.typ-120.snap @@ -41,12 +41,8 @@ input_file: tests/assets/cetz-tree.typ assert(grow > 0) assert(spread > 0) - if direction == "down" { - direction = "bottom" - } - if direction == "up" { - direction = "top" - } + if direction == "down" { direction = "bottom" } + if direction == "up" { direction = "top" } let opposite-dir = (left: "right", right: "left", bottom: "top", top: "bottom") @@ -72,16 +68,12 @@ input_file: tests/assets/cetz-tree.typ } */ } - } else if draw-edge == none { - draw-edge = (..) => { } - } + } else if draw-edge == none { draw-edge = (..) => { } } if draw-node == auto or draw-node in ("rect",) { draw-node = (node, parent-name) => { let content = node.content - if type(content) == str { - content = [#content] - } else if type(content) in (float, int) { + if type(content) == str { content = [#content] } else if type(content) in (float, int) { content = $#content$ } else if type(content) == dictionary and "content" in content { content = content.content @@ -89,11 +81,7 @@ input_file: tests/assets/cetz-tree.typ panic("Unsupported content type " + type(content) + "! " + "Provide your own `draw-node` implementation.") } - if content != none { - draw.content((), content, name: "content") - } else { - draw.content((), [?], name: "content") - } + if content != none { draw.content((), content, name: "content") } else { draw.content((), [?], name: "content") } if draw-node == "rect" { draw.rect( (rel: (-.1, .1), to: "content.top-left"), @@ -110,9 +98,7 @@ input_file: tests/assets/cetz-tree.typ if type(tree) == array { children = tree.slice(1).enumerate().map(((n, c)) => build-node(c, depth: depth + 1, sibling: n)) cnt = tree.at(0) - } else { - cnt = tree - } + } else { cnt = tree } return (x: 0, y: depth * grow, n: sibling, depth: depth, children: children, content: cnt) } @@ -147,17 +133,11 @@ input_file: tests/assets/cetz-tree.typ min-x = util.min(min-x, child-min-x) max-x = util.max(max-x, child-max-x) - if child-max-x > right { - shift-x = child-max-x - } + if child-max-x > right { shift-x = child-max-x } shift-x += spread } - if parent-position == "begin" { - node.x = left - } else { - node.x = left + (right - left) / 2 - } + if parent-position == "begin" { node.x = left } else { node.x = left + (right - left) / 2 } node.direct-min-x = left node.direct-max-x = right @@ -174,31 +154,19 @@ input_file: tests/assets/cetz-tree.typ } let node-position(node) = { - if direction == "bottom" { - return (node.x, -node.y) - } else if direction == "top" { + if direction == "bottom" { return (node.x, -node.y) } else if direction == "top" { return (node.x, node.y) - } else if direction == "left" { - return (-node.y, node.x) - } else if direction == "right" { + } else if direction == "left" { return (-node.y, node.x) } else if direction == "right" { return (node.y, node.x) - } else { - panic(message: "Invalid tree direction.") - } + } else { panic(message: "Invalid tree direction.") } } let anchors(node, parent-path) = { - if parent-path != none { - parent-path += "-" - } else { - parent-path = "" - } + if parent-path != none { parent-path += "-" } else { parent-path = "" } let d = (:) d.insert(parent-path + str(node.n), node-position(node)) - for child in node.children { - d += anchors(child, parent-path + str(node.n)) - } + for child in node.children { d += anchors(child, parent-path + str(node.n)) } return d } @@ -215,13 +183,9 @@ input_file: tests/assets/cetz-tree.typ }, ) - if parent-name != none { - cmds += draw-edge(parent-name, name, node) - } + if parent-name != none { cmds += draw-edge(parent-name, name, node) } - for child in node.children { - cmds += render(child, name) - } + for child in node.children { cmds += render(child, name) } return cmds } @@ -244,9 +208,7 @@ input_file: tests/assets/cetz-tree.typ let self = ctx.groups.pop() let nodes = ctx.nodes ctx = self.ctx - if name != none { - ctx.nodes.insert(name, nodes.at(name)) - } + if name != none { ctx.nodes.insert(name, nodes.at(name)) } return ctx }, custom-anchors-ctx: ctx => { diff --git a/tests/snapshots/assets__check_file@cetz-tree.typ-40.snap b/tests/snapshots/assets__check_file@cetz-tree.typ-40.snap index a7ba1f33..28cd8352 100644 --- a/tests/snapshots/assets__check_file@cetz-tree.typ-40.snap +++ b/tests/snapshots/assets__check_file@cetz-tree.typ-40.snap @@ -150,9 +150,7 @@ input_file: tests/assets/cetz-tree.typ sibling: n, )) cnt = tree.at(0) - } else { - cnt = tree - } + } else { cnt = tree } return ( x: 0, @@ -260,9 +258,7 @@ input_file: tests/assets/cetz-tree.typ let anchors(node, parent-path) = { if parent-path != none { parent-path += "-" - } else { - parent-path = "" - } + } else { parent-path = "" } let d = (:) d.insert( diff --git a/tests/snapshots/assets__check_file@cetz-tree.typ-80.snap b/tests/snapshots/assets__check_file@cetz-tree.typ-80.snap index a29c9979..c78c61db 100644 --- a/tests/snapshots/assets__check_file@cetz-tree.typ-80.snap +++ b/tests/snapshots/assets__check_file@cetz-tree.typ-80.snap @@ -41,12 +41,8 @@ input_file: tests/assets/cetz-tree.typ assert(grow > 0) assert(spread > 0) - if direction == "down" { - direction = "bottom" - } - if direction == "up" { - direction = "top" - } + if direction == "down" { direction = "bottom" } + if direction == "up" { direction = "top" } let opposite-dir = ( left: "right", @@ -77,9 +73,7 @@ input_file: tests/assets/cetz-tree.typ } */ } - } else if draw-edge == none { - draw-edge = (..) => { } - } + } else if draw-edge == none { draw-edge = (..) => { } } if draw-node == auto or draw-node in ("rect",) { draw-node = (node, parent-name) => { @@ -94,9 +88,7 @@ input_file: tests/assets/cetz-tree.typ panic("Unsupported content type " + type(content) + "! " + "Provide your own `draw-node` implementation.") } - if content != none { - draw.content((), content, name: "content") - } else { + if content != none { draw.content((), content, name: "content") } else { draw.content((), [?], name: "content") } if draw-node == "rect" { @@ -119,9 +111,7 @@ input_file: tests/assets/cetz-tree.typ sibling: n, )) cnt = tree.at(0) - } else { - cnt = tree - } + } else { cnt = tree } return ( x: 0, @@ -163,15 +153,11 @@ input_file: tests/assets/cetz-tree.typ min-x = util.min(min-x, child-min-x) max-x = util.max(max-x, child-max-x) - if child-max-x > right { - shift-x = child-max-x - } + if child-max-x > right { shift-x = child-max-x } shift-x += spread } - if parent-position == "begin" { - node.x = left - } else { + if parent-position == "begin" { node.x = left } else { node.x = left + (right - left) / 2 } @@ -196,19 +182,13 @@ input_file: tests/assets/cetz-tree.typ return (node.x, node.y) } else if direction == "left" { return (-node.y, node.x) - } else if direction == "right" { - return (node.y, node.x) - } else { + } else if direction == "right" { return (node.y, node.x) } else { panic(message: "Invalid tree direction.") } } let anchors(node, parent-path) = { - if parent-path != none { - parent-path += "-" - } else { - parent-path = "" - } + if parent-path != none { parent-path += "-" } else { parent-path = "" } let d = (:) d.insert(parent-path + str(node.n), node-position(node)) @@ -231,13 +211,9 @@ input_file: tests/assets/cetz-tree.typ }, ) - if parent-name != none { - cmds += draw-edge(parent-name, name, node) - } + if parent-name != none { cmds += draw-edge(parent-name, name, node) } - for child in node.children { - cmds += render(child, name) - } + for child in node.children { cmds += render(child, name) } return cmds } @@ -260,9 +236,7 @@ input_file: tests/assets/cetz-tree.typ let self = ctx.groups.pop() let nodes = ctx.nodes ctx = self.ctx - if name != none { - ctx.nodes.insert(name, nodes.at(name)) - } + if name != none { ctx.nodes.insert(name, nodes.at(name)) } return ctx }, custom-anchors-ctx: ctx => { diff --git a/tests/snapshots/assets__check_file@simple-paper.typ-120.snap b/tests/snapshots/assets__check_file@simple-paper.typ-120.snap index 34e92d83..19b8bd4a 100644 --- a/tests/snapshots/assets__check_file@simple-paper.typ-120.snap +++ b/tests/snapshots/assets__check_file@simple-paper.typ-120.snap @@ -42,9 +42,7 @@ input_file: tests/assets/simple-paper.typ show heading: it => box(width: 100%)[ #v(0.50em) #set text(font: heading-font) - #if it.numbering != none { - counter(heading).display() - } + #if it.numbering != none { counter(heading).display() } #h(0.75em) #it.body ] diff --git a/tests/snapshots/assets__check_file@simple-paper.typ-80.snap b/tests/snapshots/assets__check_file@simple-paper.typ-80.snap index 34e92d83..19b8bd4a 100644 --- a/tests/snapshots/assets__check_file@simple-paper.typ-80.snap +++ b/tests/snapshots/assets__check_file@simple-paper.typ-80.snap @@ -42,9 +42,7 @@ input_file: tests/assets/simple-paper.typ show heading: it => box(width: 100%)[ #v(0.50em) #set text(font: heading-font) - #if it.numbering != none { - counter(heading).display() - } + #if it.numbering != none { counter(heading).display() } #h(0.75em) #it.body ] diff --git a/tests/snapshots/assets__check_file@tablex.typ-120.snap b/tests/snapshots/assets__check_file@tablex.typ-120.snap index 2d13a5dc..6d7073b4 100644 --- a/tests/snapshots/assets__check_file@tablex.typ-120.snap +++ b/tests/snapshots/assets__check_file@tablex.typ-120.snap @@ -49,9 +49,7 @@ input_file: tests/assets/tablex.typ #let typst-calc-rem-supported = using-typst-v030-or-later // Remainder operation. -#let calc-mod = if typst-calc-rem-supported { - calc.rem -} else { +#let calc-mod = if typst-calc-rem-supported { calc.rem } else { (a, b) => calc.floor(a) - calc.floor(b * calc.floor(a / b)) } @@ -65,9 +63,7 @@ input_file: tests/assets/tablex.typ } // Polyfill for array sum (.sum() is Typst 0.3.0+). -#let array-sum(arr, zero: 0) = { - arr.fold(zero, (a, x) => a + x) -} +#let array-sum(arr, zero: 0) = { arr.fold(zero, (a, x) => a + x) } // -- common validators -- @@ -75,14 +71,8 @@ input_file: tests/assets/tablex.typ // Optionally use a default dictionary to fill missing arguments with. // This is in the common section as it is needed by the grid section as well. #let validate-fit-spans(fit-spans, default: (x: false, y: false), error-prefix: none) = { - if type(error-prefix) == _str-type { - error-prefix = " " + error-prefix - } else { - error-prefix = "" - } - if type(fit-spans) == _bool-type { - fit-spans = (x: fit-spans, y: fit-spans) - } + if type(error-prefix) == _str-type { error-prefix = " " + error-prefix } else { error-prefix = "" } + if type(fit-spans) == _bool-type { fit-spans = (x: fit-spans, y: fit-spans) } if type(fit-spans) == _dict-type { assert( fit-spans.len() > 0, @@ -96,11 +86,7 @@ input_file: tests/assets/tablex.typ fit-spans.values().all(v => type(v) == _bool-type), message: "Tablex error:" + error-prefix + " keys 'x' and 'y' in the 'fit-spans' dictionary must be booleans (true/false).", ) - for key in ("x", "y") { - if key in default and key not in fit-spans { - fit-spans.insert(key, default.at(key)) - } - } + for key in ("x", "y") { if key in default and key not in fit-spans { fit-spans.insert(key, default.at(key)) } } } else { panic("Tablex error:" + error-prefix + " Expected 'fit-spans' to be either a boolean or dictionary, found '" + str( type(fit-spans), @@ -207,19 +193,13 @@ input_file: tests/assets/tablex.typ if type(item) == _function-type { // dynamic cell content cellx(item) - } else if keep_empty and item == () { - item - } else if type(item) != _dict-type or "tablex-dict-type" not in item { + } else if keep_empty and item == () { item } else if type(item) != _dict-type or "tablex-dict-type" not in item { cellx[#item] - } else { - item - } + } else { item } } #let rowspanx(length, content, ..cell_options) = { - if is-tablex-cell(content) { - (..content, rowspan: length, ..cell_options.named()) - } else { + if is-tablex-cell(content) { (..content, rowspan: length, ..cell_options.named()) } else { cellx( content, rowspan: length, @@ -229,9 +209,7 @@ input_file: tests/assets/tablex.typ } #let colspanx(length, content, ..cell_options) = { - if is-tablex-cell(content) { - (..content, colspan: length, ..cell_options.named()) - } else { + if is-tablex-cell(content) { (..content, colspan: length, ..cell_options.named()) } else { cellx( content, colspan: length, @@ -249,11 +227,7 @@ input_file: tests/assets/tablex.typ let max_explicit_y = items.filter(c => c.y != auto).fold( 0, (acc, cell) => { - if (is-tablex-cell(cell) and type(cell.y) in (_int-type, _float-type) and cell.y > acc) { - cell.y - } else { - acc - } + if (is-tablex-cell(cell) and type(cell.y) in (_int-type, _float-type) and cell.y > acc) { cell.y } else { acc } }, ) @@ -261,16 +235,12 @@ input_file: tests/assets/tablex.typ if is-tablex-cell(item) and item.x == auto and item.y == auto { // cell occupies (colspan * rowspan) spaces len += item.colspan * item.rowspan - } else if type(item) == _content-type { - len += 1 - } + } else if type(item) == _content-type { len += 1 } } let rows(len) = calc.ceil(len / col_len) - while rows(len) < max_explicit_y { - len += col_len - } + while rows(len) < max_explicit_y { len += col_len } len } @@ -281,9 +251,7 @@ input_file: tests/assets/tablex.typ } // Check if this is a valid color (color, gradient or pattern). -#let is-color(val) = { - type(val) == _color-type or str(type(val)) in ("gradient", "pattern") -} +#let is-color(val) = { type(val) == _color-type or str(type(val)) in ("gradient", "pattern") } #let validate-cols-rows(columns, rows, items: ()) = { if type(columns) == _int-type { @@ -297,23 +265,15 @@ input_file: tests/assets/tablex.typ rows = (auto,) * rows } - if type(columns) != _array-type { - columns = (columns,) - } + if type(columns) != _array-type { columns = (columns,) } - if type(rows) != _array-type { - rows = (rows,) - } + if type(rows) != _array-type { rows = (rows,) } // default empty column to a single auto column - if columns.len() == 0 { - columns = (auto,) - } + if columns.len() == 0 { columns = (auto,) } // default empty row to a single auto row - if rows.len() == 0 { - rows = (auto,) - } + if rows.len() == 0 { rows = (auto,) } let col_row_is_valid(col_row) = ( (not is-infinite-len(col_row)) and ( @@ -359,39 +319,21 @@ input_file: tests/assets/tablex.typ // is greater than 1) #let positions-spanned-by(cell, x: 0, y: 0, x_limit: 0, y_limit: none) = { let result = () - let rowspan = if "rowspan" in cell { - cell.rowspan - } else { - 1 - } - let colspan = if "colspan" in cell { - cell.colspan - } else { - 1 - } + let rowspan = if "rowspan" in cell { cell.rowspan } else { 1 } + let colspan = if "colspan" in cell { cell.colspan } else { 1 } - if rowspan < 1 { - panic("Cell rowspan must be 1 or greater (bad cell: " + repr((x, y)) + ")") - } else if colspan < 1 { + if rowspan < 1 { panic("Cell rowspan must be 1 or greater (bad cell: " + repr((x, y)) + ")") } else if colspan < 1 { panic("Cell colspan must be 1 or greater (bad cell: " + repr((x, y)) + ")") } let max_x = x + colspan let max_y = y + rowspan - if x_limit != none { - max_x = calc.min(x_limit, max_x) - } + if x_limit != none { max_x = calc.min(x_limit, max_x) } - if y_limit != none { - max_y = calc.min(y_limit, max_y) - } + if y_limit != none { max_y = calc.min(y_limit, max_y) } - for x in range(x, max_x) { - for y in range(y, max_y) { - result.push((x, y)) - } - } + for x in range(x, max_x) { for y in range(y, max_y) { result.push((x, y)) } } result } @@ -400,22 +342,14 @@ input_file: tests/assets/tablex.typ #let init-array(amount, element: none, init_function: none) = { let nones = () - if init_function == none { - init_function = () => element - } + if init_function == none { init_function = () => element } range(amount).map(i => init_function()) } // Default 'x' to a certain value if it is equal to the forbidden value // ('none' by default) -#let default-if-not(x, default, if_isnt: none) = { - if x == if_isnt { - default - } else { - x - } -} +#let default-if-not(x, default, if_isnt: none) = { if x == if_isnt { default } else { x } } // Default 'x' to a certain value if it is none #let default-if-none(x, default) = default-if-not(x, default, if_isnt: none) @@ -424,20 +358,10 @@ input_file: tests/assets/tablex.typ #let default-if-auto(x, default) = default-if-not(x, default, if_isnt: auto) // Default 'x' to a certain value if it is auto or none -#let default-if-auto-or-none(x, default) = if x in (auto, none) { - default -} else { - x -} +#let default-if-auto-or-none(x, default) = if x in (auto, none) { default } else { x } // The max between a, b, or the other one if either is 'none'. -#let max-if-not-none(a, b) = if a in (none, auto) { - b -} else if b in (none, auto) { - a -} else { - calc.max(a, b) -} +#let max-if-not-none(a, b) = if a in (none, auto) { b } else if b in (none, auto) { a } else { calc.max(a, b) } // Gets the topmost parent of a line. #let get-top-parent(line) = { @@ -458,9 +382,7 @@ input_file: tests/assets/tablex.typ #let NUMBER-REGEX-STRING = "(?:−|-)?\\d*\\.?\\d+" // Check if the given length has type '_length-type' and no 'em' component. -#let is-purely-pt-len(len) = { - type(len) == _length-type and "em" not in repr(len) -} +#let is-purely-pt-len(len) = { type(len) == _length-type and "em" not in repr(len) } // Measure a length in pt by drawing a line and using the measure() function. // This function will work for negative lengths as well. @@ -488,9 +410,7 @@ input_file: tests/assets/tablex.typ // If the measured length is positive, `len` must have overall been positive. // There's nothing else to be done, so return the measured length. - if measured-pt > 0pt { - return measured-pt - } + if measured-pt > 0pt { return measured-pt } // If we've reached this point, the previously measured length must have been `0pt` // (drawing a line with a negative length will draw nothing, so measuring it will return `0pt`). @@ -513,9 +433,7 @@ input_file: tests/assets/tablex.typ // At this point, we will need to draw a line for measurement, // so we need the styles. - if styles == none { - panic("Cannot convert length to pt ('styles' not specified).") - } + if styles == none { panic("Cannot convert length to pt ('styles' not specified).") } return measure-pt(len, styles) } @@ -529,13 +447,9 @@ input_file: tests/assets/tablex.typ message: "'page-size' should be a purely pt length", ) - if page-size == none { - panic("Cannot convert ratio to pt ('page-size' not specified).") - } + if page-size == none { panic("Cannot convert ratio to pt ('page-size' not specified).") } - if is-infinite-len(page-size) { - return 0pt // page has 'auto' size => % should return 0 - } + if is-infinite-len(page-size) { return 0pt // page has 'auto' size => % should return 0 } ((len / 1%) / 100) * page-size + 0pt // e.g. 100% / 1% = 100; / 100 = 1; 1 * page-size } @@ -550,17 +464,11 @@ input_file: tests/assets/tablex.typ message: "'frac-total' should be a purely pt length", ) - if frac-amount == none { - panic("Cannot convert fraction to pt ('frac-amount' not specified).") - } + if frac-amount == none { panic("Cannot convert fraction to pt ('frac-amount' not specified).") } - if frac-total == none { - panic("Cannot convert fraction to pt ('frac-total' not specified).") - } + if frac-total == none { panic("Cannot convert fraction to pt ('frac-total' not specified).") } - if frac-amount <= 0 or is-infinite-len(frac-total) { - return 0pt - } + if frac-amount <= 0 or is-infinite-len(frac-total) { return 0pt } let len-per-frac = frac-total / frac-amount @@ -580,9 +488,7 @@ input_file: tests/assets/tablex.typ // We will need to draw a line for measurement later, // so we need the styles. - if styles == none { - panic("Cannot convert relative length to pt ('styles' not specified).") - } + if styles == none { panic("Cannot convert relative length to pt ('styles' not specified).") } // Note on precision: the `repr` for em components is precise, unlike // other length components, which are rounded to a precision of 2. @@ -592,9 +498,7 @@ input_file: tests/assets/tablex.typ // Calculate the length minus its em component. // E.g., 1% + 1pt + 1em -> 1% + 1pt - let (em-part, len-minus-em) = if em-part-repr == none { - (0em, len) - } else { + let (em-part, len-minus-em) = if em-part-repr == none { (0em, len) } else { // SAFETY: guaranteed to be a purely em length by regex let em-part = eval(em-part-repr) (em-part, len - em-part) @@ -611,9 +515,7 @@ input_file: tests/assets/tablex.typ let ratio-part-pt = if ratio-part == 0% { // No point doing `convert-ratio-type-to-pt` if there's no ratio component. 0pt - } else { - convert-ratio-type-to-pt(ratio-part, page-size) - } + } else { convert-ratio-type-to-pt(ratio-part, page-size) } // The length part is the pt part + em part. // Note: we cannot use `len - ratio-part` as that returns a `_rel-len-type` value, @@ -638,17 +540,11 @@ input_file: tests/assets/tablex.typ ) = { page-size = 0pt + page-size - if is-infinite-len(len) { - 0pt // avoid the destruction of the universe - } else if type(len) == _length-type { + if is-infinite-len(len) { 0pt // avoid the destruction of the universe } else if type(len) == _length-type { convert-length-type-to-pt(len, styles: styles) - } else if type(len) == _ratio-type { - convert-ratio-type-to-pt(len, page-size) - } else if type(len) == _fraction-type { + } else if type(len) == _ratio-type { convert-ratio-type-to-pt(len, page-size) } else if type(len) == _fraction-type { convert-fraction-type-to-pt(len, frac-amount, frac-total) - } else if type(len) == _rel-len-type { - convert-relative-type-to-pt(len, styles, page-size: page-size) - } else { + } else if type(len) == _rel-len-type { convert-relative-type-to-pt(len, styles, page-size: page-size) } else { panic("Cannot convert '" + type(len) + "' to length.") } } @@ -657,13 +553,10 @@ input_file: tests/assets/tablex.typ #let stroke-len(stroke, stroke-auto: 1pt, styles: none) = { let no-ratio-error = "Tablex error: Stroke cannot be a ratio or relative length (i.e. have a percentage like '53%'). Try using the layout() function (or similar) to convert the percentage to 'pt' instead." let stroke = default-if-auto(stroke, stroke-auto) - if type(stroke) == _length-type { - convert-length-to-pt(stroke, styles: styles) - } else if type(stroke) in (_rel-len-type, _ratio-type) { - panic(no-ratio-error) - } else if is-color(stroke) { - 1pt - } else if type(stroke) == _stroke-type { + if type(stroke) == _length-type { convert-length-to-pt(stroke, styles: styles) } else if type(stroke) in ( + _rel-len-type, + _ratio-type, + ) { panic(no-ratio-error) } else if is-color(stroke) { 1pt } else if type(stroke) == _stroke-type { if typst-fields-supported { // No need for any repr() parsing, just use the thickness field. let thickness = default-if-auto(stroke.thickness, 1pt) @@ -684,35 +577,23 @@ input_file: tests/assets/tablex.typ // note: on typst v0.7.0 or later, can just use 's.thickness' let r = regex("thickness: (" + len-regex + ")") s = repr(stroke).match(r) - if s != none { - s = s.captures.first() // get the first match (the thickness) - } + if s != none { s = s.captures.first() // get the first match (the thickness) } } - if s == none { - 1pt // okay it's probably just a color then - } else { + if s == none { 1pt // okay it's probably just a color then } else { let len = eval(s) - if type(len) == _length-type { - convert-length-to-pt(len, styles: styles) - } else if type(len) in (_rel-len-type, _ratio-type) { - panic(no-ratio-error) - } else { - 1pt // should be unreachable - } + if type(len) == _length-type { convert-length-to-pt(len, styles: styles) } else if type(len) in ( + _rel-len-type, + _ratio-type, + ) { panic(no-ratio-error) } else { 1pt // should be unreachable } } } else if type(stroke) == _dict-type and "thickness" in stroke { let thickness = stroke.thickness - if type(thickness) == _length-type { - convert-length-to-pt(thickness, styles: styles) - } else if type(thickness) in (_rel-len-type, _ratio-type) { - panic(no-ratio-error) - } else { - 1pt - } - } else { - 1pt - } + if type(thickness) == _length-type { convert-length-to-pt(thickness, styles: styles) } else if type(thickness) in ( + _rel-len-type, + _ratio-type, + ) { panic(no-ratio-error) } else { 1pt } + } else { 1pt } } // --- end: utility functions --- @@ -740,11 +621,7 @@ input_file: tests/assets/tablex.typ #let grid-at(grid, x, y) = { let index = grid-index-at(x, y, width: grid.width) - if index < grid.items.len() { - grid.items.at(index) - } else { - none - } + if index < grid.items.len() { grid.items.at(index) } else { none } } // Returns 'true' if the cell at (x, y) @@ -780,9 +657,7 @@ input_file: tests/assets/tablex.typ } // Fetches an entire column of cells (all positions with the given x). -#let grid-get-column(grid, x) = { - range(grid-count-rows(grid)).map(y => grid-at(grid, x, y)) -} +#let grid-get-column(grid, x) = { range(grid-count-rows(grid)).map(y => grid-at(grid, x, y)) } // Expand grid to the given coords (add the missing cells) #let grid-expand-to(grid, x, y, fill_with: grid => none) = { @@ -797,9 +672,7 @@ input_file: tests/assets/tablex.typ let now = grid-index-to-pos(grid, grid.items.len() - 1) // now columns and/or last missing row - while not grid-has-pos(grid, x, y) { - grid.items.push(fill_with(grid)) - } + while not grid-has-pos(grid, x, y) { grid.items.push(fill_with(grid)) } let new = grid-index-to-pos(grid, grid.items.len() - 1) grid @@ -808,13 +681,9 @@ input_file: tests/assets/tablex.typ // if occupied (extension of a cell) => get the cell that generated it. // if a normal cell => return it, untouched. #let get-parent-cell(cell, grid: none) = { - if is-tablex-occupied(cell) { - grid-at(grid, cell.parent_x, cell.parent_y) - } else if is-tablex-cell(cell) { + if is-tablex-occupied(cell) { grid-at(grid, cell.parent_x, cell.parent_y) } else if is-tablex-cell(cell) { cell - } else { - panic("Cannot get parent table cell of a non-cell object: " + repr(cell)) - } + } else { panic("Cannot get parent table cell of a non-cell object: " + repr(cell)) } } // Return the next position available on the grid @@ -903,11 +772,7 @@ input_file: tests/assets/tablex.typ if is-some-tablex-line(item) { // detect lines' x, y if is-tablex-hline(item) { - let this_y = if first_cell_reached { - prev_y + 1 - } else { - prev_y - } + let this_y = if first_cell_reached { prev_y + 1 } else { prev_y } item.y = default-if-auto(item.y, this_y) @@ -926,15 +791,11 @@ input_file: tests/assets/tablex.typ } else if row_wrapped { item.x = x_limit // allow v_line at the last column row_wrapped = false - } else { - item.x = x - } + } else { item.x = x } } vlines.push(item) - } else { - panic("Invalid line received (must be hline or vline).") - } + } else { panic("Invalid line received (must be hline or vline).") } items.at(i) = item // override item with the new x / y coord set continue } @@ -948,9 +809,7 @@ input_file: tests/assets/tablex.typ let this_x = default-if-auto(cell.x, x) let this_y = default-if-auto(cell.y, y) - if cell.x == none or cell.y == none { - panic("Error: Received cell with 'none' as x or y.") - } + if cell.x == none or cell.y == none { panic("Error: Received cell with 'none' as x or y.") } if this_x == none or this_y == none { panic("Internal tablex error: Grid wasn't large enough to fit the given cells. (Previous position: " + repr(( @@ -962,15 +821,11 @@ input_file: tests/assets/tablex.typ cell.x = this_x cell.y = this_y - if type(map-cells) == _function-type { - cell = table-item-convert(map-cells(cell)) - } + if type(map-cells) == _function-type { cell = table-item-convert(map-cells(cell)) } assert(is-tablex-cell(cell), message: "Tablex error: 'map-cells' returned something that isn't a valid cell.") - if row_wrapped { - row_wrapped = false - } + if row_wrapped { row_wrapped = false } let content = cell.content let content = if type(content) == _function-type { @@ -980,12 +835,8 @@ input_file: tests/assets/tablex.typ this_x = cell.x this_y = cell.y [#res.content] - } else { - [#res] - } - } else { - [#content] - } + } else { [#res] } + } else { [#content] } if this_x == none or this_y == none { panic("Error: Cell with function as content returned another cell with 'none' as x or y!") @@ -998,9 +849,7 @@ input_file: tests/assets/tablex.typ cell.content = content // resolve 'fit-spans' option for this cell - if "fit-spans" not in cell { - cell.fit-spans = auto - } else if cell.fit-spans != auto { + if "fit-spans" not in cell { cell.fit-spans = auto } else if cell.fit-spans != auto { cell.fit-spans = validate-fit-spans( cell.fit-spans, default: fit-spans, @@ -1012,9 +861,7 @@ input_file: tests/assets/tablex.typ let max_x = this_x + cell.colspan - 1 let max_y = this_y + cell.rowspan - 1 - if this_x >= x_limit { - panic("Error: Cell at " + repr((this_x, this_y)) + " is placed at an inexistent column.") - } + if this_x >= x_limit { panic("Error: Cell at " + repr((this_x, this_y)) + " is placed at an inexistent column.") } if max_x >= x_limit { panic("Error: Cell at " + repr(( @@ -1081,22 +928,16 @@ input_file: tests/assets/tablex.typ x = next_pos.at(0) y = next_pos.at(1) - if prev_y != y { - row_wrapped = true // we changed rows! - } + if prev_y != y { row_wrapped = true // we changed rows! } } // for missing cell positions: add empty cell for (index, item) in grid.items.enumerate() { - if item == none { - grid.items.at(index) = new_empty_cell(grid, index: index) - } + if item == none { grid.items.at(index) = new_empty_cell(grid, index: index) } } // while there are incomplete rows for some reason, add empty cells - while calc-mod(grid.items.len(), grid.width) != 0 { - grid.items.push(new_empty_cell(grid)) - } + while calc-mod(grid.items.len(), grid.width) != 0 { grid.items.push(new_empty_cell(grid)) } ( grid: grid, @@ -1126,15 +967,11 @@ input_file: tests/assets/tablex.typ fill_default: none, ) = { - let align_default = if type(align_default) == _function-type { - align_default(cell.x, cell.y) // column, row - } else { + let align_default = if type(align_default) == _function-type { align_default(cell.x, cell.y) // column, row } else { align_default } - let fill_default = if type(fill_default) == _function-type { - fill_default(cell.x, cell.y) // row, column - } else { + let fill_default = if type(fill_default) == _function-type { fill_default(cell.x, cell.y) // row, column } else { fill_default } @@ -1198,15 +1035,9 @@ input_file: tests/assets/tablex.typ panic("Tablex error: Invalid alignment specified (must be either a function (column, row) -> alignment, an alignment value - such as 'left' or 'center + top' -, an array of alignment values (one for each column), or 'auto').") } - let aligned_cell_content = if cell_align == auto { - [#content] - } else { - align(cell_align)[#content] - } + let aligned_cell_content = if cell_align == auto { [#content] } else { align(cell_align)[#content] } - if is-infinite-len(inset) { - panic("Tablex error: inset must not be infinite") - } + if is-infinite-len(inset) { panic("Tablex error: inset must not be infinite") } box( width: width, height: height, @@ -1222,13 +1053,7 @@ input_file: tests/assets/tablex.typ #let sum-fixed-size-tracks(tracks) = { tracks.fold( 0pt, - (acc, el) => { - if type(el) == _length-type { - acc + el - } else { - acc - } - }, + (acc, el) => { if type(el) == _length-type { acc + el } else { acc } }, ) } @@ -1239,23 +1064,13 @@ input_file: tests/assets/tablex.typ let amount-frac = frac-tracks.fold(0, (acc, el) => acc + (el.at(1) / 1fr)) - if type(gutter) == _fraction-type { - amount-frac += (gutter / 1fr) * (tracks.len() - 1) - } + if type(gutter) == _fraction-type { amount-frac += (gutter / 1fr) * (tracks.len() - 1) } - let frac-width = if amount-frac > 0 and not is-infinite-len(remaining) { - remaining / amount-frac - } else { - 0pt - } + let frac-width = if amount-frac > 0 and not is-infinite-len(remaining) { remaining / amount-frac } else { 0pt } - if type(gutter) == _fraction-type { - gutter = frac-width * (gutter / 1fr) - } + if type(gutter) == _fraction-type { gutter = frac-width * (gutter / 1fr) } - for (i, size) in frac-tracks { - tracks.at(i) = frac-width * (size / 1fr) - } + for (i, size) in frac-tracks { tracks.at(i) = frac-width * (size / 1fr) } (tracks: tracks, gutter: gutter) } @@ -1267,9 +1082,7 @@ input_file: tests/assets/tablex.typ let last_auto_col = none for (i, col) in columns.enumerate() { - if i in cell-cols and col == auto { - last_auto_col = max-if-not-none(last_auto_col, i) - } + if i in cell-cols and col == auto { last_auto_col = max-if-not-none(last_auto_col, i) } } last_auto_col @@ -1282,9 +1095,7 @@ input_file: tests/assets/tablex.typ let last_auto_row = none for (i, row) in rows.enumerate() { - if i in cell-rows and row == auto { - last_auto_row = max-if-not-none(last_auto_row, i) - } + if i in cell-rows and row == auto { last_auto_row = max-if-not-none(last_auto_row, i) } } last_auto_row @@ -1298,11 +1109,7 @@ input_file: tests/assets/tablex.typ let cell-cols = range(cell.x, cell.x + cell.colspan) let size = 0pt - for (i, col) in columns.enumerate() { - if i in cell-cols and type(col) == _length-type { - size += col - } - } + for (i, col) in columns.enumerate() { if i in cell-cols and type(col) == _length-type { size += col } } size } @@ -1314,11 +1121,7 @@ input_file: tests/assets/tablex.typ let cell-rows = range(cell.y, cell.y + cell.rowspan) let size = 0pt - for (i, row) in rows.enumerate() { - if i in cell-rows and type(row) == _length-type { - size += row - } - } + for (i, row) in rows.enumerate() { if i in cell-rows and type(row) == _length-type { size += row } } size } @@ -1346,16 +1149,12 @@ input_file: tests/assets/tablex.typ let col_size = grid-get-column(grid, i).fold( 0pt, (max, cell) => { - if cell == none { - panic("Not enough cells specified for the given amount of rows and columns.") - } + if cell == none { panic("Not enough cells specified for the given amount of rows and columns.") } let pcell = get-parent-cell(cell, grid: grid) // in case this is a colspan let last-auto-col = get-colspan-last-auto-col(pcell, columns: columns) - let fit-this-span = if "fit-spans" in pcell and pcell.fit-spans != auto { - pcell.fit-spans.x - } else { + let fit-this-span = if "fit-spans" in pcell and pcell.fit-spans != auto { pcell.fit-spans.x } else { fit-spans.x } let this-cell-can-expand-columns = pcell.colspan == 1 or not fit-this-span @@ -1410,9 +1209,7 @@ input_file: tests/assets/tablex.typ let fixed_size = get-colspan-fixed-size-covered(pcell, columns: new_columns) calc.max(max, width - fixed_size, 0pt) - } else { - max - } + } else { max } }, ) @@ -1443,9 +1240,7 @@ input_file: tests/assets/tablex.typ let remaining = available let auto-cols-to-resize = auto-cols.len() - if auto-cols-to-resize <= 0 { - return columns - } + if auto-cols-to-resize <= 0 { return columns } // The fair-share must be the largest possible (to ensure maximum fairness) // such that we can shrink the minimum amount of columns possible and, at the @@ -1490,11 +1285,7 @@ input_file: tests/assets/tablex.typ } // 2. Resize any columns larger than the calculated fair share to the fair share. - for (i, col) in auto-cols { - if col > fair-share { - columns.at(i) = fair-share - } - } + for (i, col) in auto-cols { if col > fair-share { columns.at(i) = fair-share } } columns } @@ -1512,20 +1303,12 @@ input_file: tests/assets/tablex.typ let columns = columns.map(c => { if type(c) in (_length-type, _rel-len-type, _ratio-type) { convert-length-to-pt(c, styles: styles, page-size: page_width) - } else if c == none { - 0pt - } else { - c - } + } else if c == none { 0pt } else { c } }) // what is the fixed size of the gutter? // (calculate it later if it's fractional) - let fixed-size-gutter = if type(col-gutter) == _length-type { - col-gutter - } else { - 0pt - } + let fixed-size-gutter = if type(col-gutter) == _length-type { col-gutter } else { 0pt } let total_fixed_size = sum-fixed-size-tracks(columns) + fixed-size-gutter * (columns.len() - 1) @@ -1567,31 +1350,15 @@ input_file: tests/assets/tablex.typ ) } - columns = columns.map(c => { - if type(c) == _fraction-type { - 0pt // no space left to be divided - } else { - c - } - }) + columns = columns.map(c => { if type(c) == _fraction-type { 0pt // no space left to be divided } else { c } }) } } else { - columns = columns.map(c => { - if c == auto or type(c) == _fraction-type { - 0pt // no space remaining! - } else { - c - } - }) + columns = columns.map(c => { if c == auto or type(c) == _fraction-type { 0pt // no space remaining! } else { c } }) } ( columns: columns, - gutter: if col-gutter == none { - none - } else { - fixed-size-gutter - }, + gutter: if col-gutter == none { none } else { fixed-size-gutter }, ) } @@ -1616,16 +1383,12 @@ input_file: tests/assets/tablex.typ let row_size = grid-get-row(grid, i).fold( 0pt, (max, cell) => { - if cell == none { - panic("Not enough cells specified for the given amount of rows and columns.") - } + if cell == none { panic("Not enough cells specified for the given amount of rows and columns.") } let pcell = get-parent-cell(cell, grid: grid) // in case this is a rowspan let last-auto-row = get-rowspan-last-auto-row(pcell, rows: rows) - let fit-this-span = if "fit-spans" in pcell and pcell.fit-spans != auto { - pcell.fit-spans.y - } else { + let fit-this-span = if "fit-spans" in pcell and pcell.fit-spans != auto { pcell.fit-spans.y } else { fit-spans.y } let this-cell-can-expand-rows = pcell.rowspan == 1 or not fit-this-span @@ -1663,9 +1426,7 @@ input_file: tests/assets/tablex.typ let fixed_size = get-rowspan-fixed-size-covered(pcell, rows: new_rows) calc.max(max, height - fixed_size, 0pt) - } else { - max - } + } else { max } }, ) @@ -1692,9 +1453,7 @@ input_file: tests/assets/tablex.typ let rows = rows.map(r => { if type(r) in (_length-type, _rel-len-type, _ratio-type) { convert-length-to-pt(r, styles: styles, page-size: page_height) - } else { - r - } + } else { r } }) let auto_rows_res = determine-auto-rows( @@ -1712,11 +1471,7 @@ input_file: tests/assets/tablex.typ // what is the fixed size of the gutter? // (calculate it later if it's fractional) - let fixed-size-gutter = if type(row-gutter) == _length-type { - row-gutter - } else { - 0pt - } + let fixed-size-gutter = if type(row-gutter) == _length-type { row-gutter } else { 0pt } let remaining = page_height - sum-fixed-size-tracks(rows) - auto_size - fixed-size-gutter * (rows.len() - 1) @@ -1733,15 +1488,9 @@ input_file: tests/assets/tablex.typ if type(r) == _fraction-type { // no space remaining in this page or box 0pt - } else { - r - } + } else { r } }), - gutter: if row-gutter == none { - none - } else { - fixed-size-gutter - }, + gutter: if row-gutter == none { none } else { fixed-size-gutter }, ) } } @@ -1803,15 +1552,11 @@ input_file: tests/assets/tablex.typ let col_range = range(start, calc.min(columns.len() + 1, end)) let sum = 0pt - for i in col_range { - sum += columns.at(i) + col-gutter - } + for i in col_range { sum += columns.at(i) + col-gutter } // if the end is after all columns, there is // no gutter at the end. - if pre-gutter or end == columns.len() { - sum = calc.max(0pt, sum - col-gutter) // remove extra gutter from last col - } + if pre-gutter or end == columns.len() { sum = calc.max(0pt, sum - col-gutter) // remove extra gutter from last col } sum } @@ -1823,15 +1568,11 @@ input_file: tests/assets/tablex.typ let row_range = range(start, calc.min(rows.len() + 1, end)) let sum = 0pt - for i in row_range { - sum += rows.at(i) + row-gutter - } + for i in row_range { sum += rows.at(i) + row-gutter } // if the end is after all rows, there is // no gutter at the end. - if pre-gutter or end == rows.len() { - sum = calc.max(0pt, sum - row-gutter) // remove extra gutter from last row - } + if pre-gutter or end == rows.len() { sum = calc.max(0pt, sum - row-gutter) // remove extra gutter from last row } sum } @@ -1856,21 +1597,15 @@ input_file: tests/assets/tablex.typ // check the subspan a hline or vline goes through inside a larger span #let get-included-span(l_start, l_end, start: 0, end: 0, limit: 0) = { - if l_start in (none, auto) { - l_start = 0 - } + if l_start in (none, auto) { l_start = 0 } - if l_end in (none, auto) { - l_end = limit - } + if l_end in (none, auto) { l_end = limit } l_start = calc.max(0, l_start) l_end = calc.min(end, limit) // ---- ==== or ==== ---- - if l_end < start or l_start > end { - return none - } + if l_end < start or l_start > end { return none } // --##== ; ==##-- ; #### ; ... : intersection. (calc.max(l_start, start), calc.min(l_end, end)) @@ -1910,9 +1645,7 @@ input_file: tests/assets/tablex.typ if span == none { // no intersection! none - } else { - v-or-hline-with-span(h, start: span.at(0), end: span.at(1)) - } + } else { v-or-hline-with-span(h, start: span.at(0), end: span.at(1)) } }).filter(x => x != none) let vlines = vlines.filter(v => { @@ -1933,9 +1666,7 @@ input_file: tests/assets/tablex.typ if span == none { // no intersection! none - } else { - v-or-hline-with-span(v, start: span.at(0), end: span.at(1)) - } + } else { v-or-hline-with-span(v, start: span.at(0), end: span.at(1)) } }).filter(x => x != none) ( @@ -1967,16 +1698,13 @@ input_file: tests/assets/tablex.typ // -- drawing -- #let parse-stroke(stroke) = { - if is-color(stroke) { - stroke + 1pt - } else if type(stroke) in (_length-type, _rel-len-type, _ratio-type, _stroke-type, _dict-type) or stroke in ( - none, - auto, - ) { - stroke - } else { - panic("Invalid stroke '" + repr(stroke) + "'.") - } + if is-color(stroke) { stroke + 1pt } else if type(stroke) in ( + _length-type, + _rel-len-type, + _ratio-type, + _stroke-type, + _dict-type, + ) or stroke in (none, auto) { stroke } else { panic("Invalid stroke '" + repr(stroke) + "'.") } } // How much should this line expand? @@ -1984,12 +1712,8 @@ input_file: tests/assets/tablex.typ // spanned-tracks-len: row_len (if vline), col_len (if hline) #let get-actual-expansion(line, spanned-tracks-len: 0) = { // TODO: better handle negative expansion - if line.expand in (none, (none, none), auto, (auto, auto)) { - return (none, none) - } - if type(line.expand) != _array-type { - line.expand = (line.expand, line.expand) - } + if line.expand in (none, (none, none), auto, (auto, auto)) { return (none, none) } + if type(line.expand) != _array-type { line.expand = (line.expand, line.expand) } let parent = get-top-parent(line) let parent-start = default-if-auto-or-none(parent.start, 0) @@ -2033,15 +1757,11 @@ input_file: tests/assets/tablex.typ let stroke = default-if-auto(hline.stroke, stroke) let stroke = parse-stroke(stroke) - if default-if-auto-or-none(start, 0) == default-if-auto-or-none(end, columns.len()) { - return - } + if default-if-auto-or-none(start, 0) == default-if-auto-or-none(end, columns.len()) { return } if gutter != none and gutter.row != none and ( (pre-gutter and hline.gutter-restrict == bottom) or (not pre-gutter and hline.gutter-restrict == top) - ) { - return - } + ) { return } let expand = get-actual-expansion(hline, spanned-tracks-len: columns.len()) let left-expand = default-if-auto-or-none(expand.at(0), 0pt) @@ -2073,9 +1793,7 @@ input_file: tests/assets/tablex.typ pre-gutter: hline.stop-pre-gutter == true, ) + right-expand - if end_x - start_x < 0pt { - return // negative length - } + if end_x - start_x < 0pt { return // negative length } if rtl { // invert the line (start from the right instead of from the left) @@ -2092,11 +1810,7 @@ input_file: tests/assets/tablex.typ y, ) - if stroke != auto { - if stroke != none { - line(start: start, end: end, stroke: stroke) - } - } else { + if stroke != auto { if stroke != none { line(start: start, end: end, stroke: stroke) } } else { line(start: start, end: end) } } @@ -2122,15 +1836,11 @@ input_file: tests/assets/tablex.typ let stroke = default-if-auto(vline.stroke, stroke) let stroke = parse-stroke(stroke) - if default-if-auto-or-none(start, 0) == default-if-auto-or-none(end, rows.len()) { - return - } + if default-if-auto-or-none(start, 0) == default-if-auto-or-none(end, rows.len()) { return } if gutter != none and gutter.col != none and ( (pre-gutter and vline.gutter-restrict == right) or (not pre-gutter and vline.gutter-restrict == left) - ) { - return - } + ) { return } let expand = get-actual-expansion(vline, spanned-tracks-len: rows.len()) let top-expand = default-if-auto-or-none(expand.at(0), 0pt) @@ -2156,9 +1866,7 @@ input_file: tests/assets/tablex.typ pre-gutter: stop-before-row-gutter or vline.stop-pre-gutter == true, ) + bottom-expand - if end_y - start_y < 0pt { - return // negative length - } + if end_y - start_y < 0pt { return // negative length } if rtl { // invert the vertical line's x pos (start from the right instead of from the left) @@ -2174,11 +1882,7 @@ input_file: tests/assets/tablex.typ end_y, ) - if stroke != auto { - if stroke != none { - line(start: start, end: end, stroke: stroke) - } - } else { + if stroke != auto { if stroke != none { line(start: start, end: end, stroke: stroke) } } else { line(start: start, end: end) } } @@ -2216,9 +1920,7 @@ input_file: tests/assets/tablex.typ top + left, locate(loc => { page_dim_state.update(s => { - if s.top_left != none { - s - } else { + if s.top_left != none { s } else { let pos = loc.position() let width = s.width - pos.x let height = s.width - pos.y @@ -2232,9 +1934,7 @@ input_file: tests/assets/tablex.typ bottom + right, locate(loc => { page_dim_state.update(s => { - if s.bottom_right != none { - s - } else { + if s.bottom_right != none { s } else { let pos = loc.position() let width = s.width + pos.x let height = s.width + pos.y @@ -2395,11 +2095,7 @@ input_file: tests/assets/tablex.typ let draw-hline = (..args) => place(top + left, dy: added_header_height, draw-hline(..args)) let draw-vline = (..args) => place(top + left, dy: added_header_height, draw-vline(..args)) - let header_last_y = if first-row-group != none { - first-row-group.row_group.y_span.at(1) - } else { - none - } + let header_last_y = if first-row-group != none { first-row-group.row_group.y_span.at(1) } else { none } // if this is the second row, and the header's hlines // do not have priority (thus are not drawn by them, // otherwise they'd repeat on every page), then @@ -2408,19 +2104,13 @@ input_file: tests/assets/tablex.typ let hlines_below_header = first-row-group.row_group.hlines.filter(h => h.y == header_last_y + 1) hlines + hlines_below_header - } else { - hlines - } + } else { hlines } for hline in hlines { // only draw the top hline // if header's wasn't already drawn if hline.y == start-y { - let header_last_y = if first-row-group != none { - first-row-group.row_group.y_span.at(1) - } else { - none - } + let header_last_y = if first-row-group != none { first-row-group.row_group.y_span.at(1) } else { none } // pre-gutter is always false here, as we assume // hlines at the top of this row are handled // at pre-gutter by the preceding row, @@ -2657,16 +2347,10 @@ input_file: tests/assets/tablex.typ let parse-func(line, page-size: none) = { line.stroke-expand = line.stroke-expand == true line.expand = default-if-auto(line.expand, none) - if type(line.expand) != _array-type and line.expand != none { - line.expand = (line.expand, line.expand) - } - line.expand = if line.expand == none { - none - } else { + if type(line.expand) != _array-type and line.expand != none { line.expand = (line.expand, line.expand) } + line.expand = if line.expand == none { none } else { line.expand.slice(0, 2).map(e => { - if e == none { - e - } else { + if e == none { e } else { e = default-if-auto(e, 0pt) if type(e) not in (_length-type, _rel-len-type, _ratio-type) { panic("'expand' argument to lines must be a pair (length, length).") @@ -2759,9 +2443,7 @@ input_file: tests/assets/tablex.typ if type(map-vlines) == _function-type { vlines = vlines.map(vline => { let vline = map-vlines(vline) - if not is-tablex-vline(vline) { - panic("'map-vlines' function returned a non-vline.") - } + if not is-tablex-vline(vline) { panic("'map-vlines' function returned a non-vline.") } vline }) } @@ -2769,9 +2451,7 @@ input_file: tests/assets/tablex.typ if type(map-hlines) == _function-type { hlines = hlines.map(hline => { let hline = map-hlines(hline) - if not is-tablex-hline(hline) { - panic("'map-hlines' function returned a non-hline.") - } + if not is-tablex-hline(hline) { panic("'map-hlines' function returned a non-hline.") } hline }) } @@ -2779,9 +2459,7 @@ input_file: tests/assets/tablex.typ let should-map-rows = type(map-rows) == _function-type let should-map-cols = type(map-cols) == _function-type - if not should-map-rows and not should-map-cols { - return (grid: grid, hlines: hlines, vlines: vlines) - } + if not should-map-rows and not should-map-cols { return (grid: grid, hlines: hlines, vlines: vlines) } let col-len = grid.width let row-len = grid-count-rows(grid) @@ -2793,18 +2471,10 @@ input_file: tests/assets/tablex.typ // occupied cells = none for the outer user let cells = map-rows( row, - original-cells.map(c => { - if is-tablex-occupied(c) { - none - } else { - c - } - }), + original-cells.map(c => { if is-tablex-occupied(c) { none } else { c } }), ) - if type(cells) != _array-type { - panic("Tablex error: 'map-rows' returned something that isn't an array.") - } + if type(cells) != _array-type { panic("Tablex error: 'map-rows' returned something that isn't an array.") } if cells.len() != original-cells.len() { panic("Tablex error: 'map-rows' returned " + str( @@ -2819,9 +2489,7 @@ input_file: tests/assets/tablex.typ continue } - if not is-tablex-cell(cell) { - panic("Tablex error: 'map-rows' returned a non-cell.") - } + if not is-tablex-cell(cell) { panic("Tablex error: 'map-rows' returned a non-cell.") } let x = cell.x let y = cell.y @@ -2851,18 +2519,10 @@ input_file: tests/assets/tablex.typ // occupied cells = none for the outer user let cells = map-cols( column, - original-cells.map(c => { - if is-tablex-occupied(c) { - none - } else { - c - } - }), + original-cells.map(c => { if is-tablex-occupied(c) { none } else { c } }), ) - if type(cells) != _array-type { - panic("Tablex error: 'map-cols' returned something that isn't an array.") - } + if type(cells) != _array-type { panic("Tablex error: 'map-cols' returned something that isn't an array.") } if cells.len() != original-cells.len() { panic("Tablex error: 'map-cols' returned " + str( @@ -2877,9 +2537,7 @@ input_file: tests/assets/tablex.typ continue } - if not is-tablex-cell(cell) { - panic("Tablex error: 'map-cols' returned a non-cell.") - } + if not is-tablex-cell(cell) { panic("Tablex error: 'map-cols' returned a non-cell.") } let x = cell.x let y = cell.y @@ -2914,9 +2572,7 @@ input_file: tests/assets/tablex.typ } #let validate-repeat-header(repeat-header, header-rows: none) = { - if header-rows == none or header-rows < 0 { - return false // cannot repeat an empty header - } + if header-rows == none or header-rows < 0 { return false // cannot repeat an empty header } repeat-header = default-if-auto(default-if-none(repeat-header, false), false) @@ -3146,14 +2802,8 @@ input_file: tests/assets/tablex.typ // When there are more rows than the user specified, we ensure they have // the same size as the last specified row. - let last-row-size = if rows.len() == 0 { - auto - } else { - rows.last() - } - for _ in range(grid_info.new_row_count - row_len) { - rows.push(last-row-size) // add new rows (due to extra cells) - } + let last-row-size = if rows.len() == 0 { auto } else { rows.last() } + for _ in range(grid_info.new_row_count - row_len) { rows.push(last-row-size) // add new rows (due to extra cells) } let col_len = columns.len() let row_len = rows.len() @@ -3239,6 +2889,4 @@ input_file: tests/assets/tablex.typ } // Same as table but defaults to lines off -#let gridx(..options) = { - tablex(auto-lines: false, ..options) -} +#let gridx(..options) = { tablex(auto-lines: false, ..options) } diff --git a/tests/snapshots/assets__check_file@tablex.typ-40.snap b/tests/snapshots/assets__check_file@tablex.typ-40.snap index 450926a2..4ed43e31 100644 --- a/tests/snapshots/assets__check_file@tablex.typ-40.snap +++ b/tests/snapshots/assets__check_file@tablex.typ-40.snap @@ -86,9 +86,7 @@ input_file: tests/assets/tablex.typ ) = { if type(error-prefix) == _str-type { error-prefix = " " + error-prefix - } else { - error-prefix = "" - } + } else { error-prefix = "" } if type(fit-spans) == _bool-type { fit-spans = ( x: fit-spans, @@ -258,9 +256,7 @@ input_file: tests/assets/tablex.typ item } else if type(item) != _dict-type or "tablex-dict-type" not in item { cellx[#item] - } else { - item - } + } else { item } } #let rowspanx( @@ -320,11 +316,7 @@ input_file: tests/assets/tablex.typ _int-type, _float-type, ) and cell.y > acc - ) { - cell.y - } else { - acc - } + ) { cell.y } else { acc } }, ) @@ -401,9 +393,7 @@ input_file: tests/assets/tablex.typ } // default empty row to a single auto row - if rows.len() == 0 { - rows = (auto,) - } + if rows.len() == 0 { rows = (auto,) } let col_row_is_valid(col_row) = ( (not is-infinite-len(col_row)) and ( @@ -466,14 +456,10 @@ input_file: tests/assets/tablex.typ let result = () let rowspan = if "rowspan" in cell { cell.rowspan - } else { - 1 - } + } else { 1 } let colspan = if "colspan" in cell { cell.colspan - } else { - 1 - } + } else { 1 } if rowspan < 1 { panic("Cell rowspan must be 1 or greater (bad cell: " + repr(( @@ -529,11 +515,7 @@ input_file: tests/assets/tablex.typ default, if_isnt: none, ) = { - if x == if_isnt { - default - } else { - x - } + if x == if_isnt { default } else { x } } // Default 'x' to a certain value if it is none @@ -562,21 +544,15 @@ input_file: tests/assets/tablex.typ default, ) = if x in (auto, none) { default -} else { - x -} +} else { x } // The max between a, b, or the other one if either is 'none'. #let max-if-not-none(a, b) = if a in ( none, auto, -) { - b -} else if b in (none, auto) { +) { b } else if b in (none, auto) { a -} else { - calc.max(a, b) -} +} else { calc.max(a, b) } // Gets the topmost parent of a line. #let get-top-parent(line) = { @@ -918,9 +894,7 @@ input_file: tests/assets/tablex.typ } else if type(len) in ( _rel-len-type, _ratio-type, - ) { - panic(no-ratio-error) - } else { + ) { panic(no-ratio-error) } else { 1pt // should be unreachable } } @@ -934,14 +908,10 @@ input_file: tests/assets/tablex.typ } else if type(thickness) in ( _rel-len-type, _ratio-type, - ) { - panic(no-ratio-error) - } else { + ) { panic(no-ratio-error) } else { 1pt } - } else { - 1pt - } + } else { 1pt } } // --- end: utility functions --- @@ -988,9 +958,7 @@ input_file: tests/assets/tablex.typ if index < grid.items.len() { grid.items.at(index) - } else { - none - } + } else { none } } // Returns 'true' if the cell at (x, y) @@ -1218,9 +1186,7 @@ input_file: tests/assets/tablex.typ if is-tablex-hline(item) { let this_y = if first_cell_reached { prev_y + 1 - } else { - prev_y - } + } else { prev_y } item.y = default-if-auto( item.y, @@ -1242,9 +1208,7 @@ input_file: tests/assets/tablex.typ } else if row_wrapped { item.x = x_limit // allow v_line at the last column row_wrapped = false - } else { - item.x = x - } + } else { item.x = x } } vlines.push(item) @@ -1310,12 +1274,8 @@ input_file: tests/assets/tablex.typ this_x = cell.x this_y = cell.y [#res.content] - } else { - [#res] - } - } else { - [#content] - } + } else { [#res] } + } else { [#content] } if this_x == none or this_y == none { panic("Error: Cell with function as content returned another cell with 'none' as x or y!") @@ -1513,18 +1473,14 @@ input_file: tests/assets/tablex.typ cell.x, cell.y, ) // column, row - } else { - align_default - } + } else { align_default } let fill_default = if type(fill_default) == _function-type { fill_default( cell.x, cell.y, ) // row, column - } else { - fill_default - } + } else { fill_default } let content = cell.content @@ -1604,9 +1560,7 @@ input_file: tests/assets/tablex.typ let aligned_cell_content = if cell_align == auto { [#content] - } else { - align(cell_align)[#content] - } + } else { align(cell_align)[#content] } if is-infinite-len(inset) { panic("Tablex error: inset must not be infinite") @@ -1629,9 +1583,7 @@ input_file: tests/assets/tablex.typ (acc, el) => { if type(el) == _length-type { acc + el - } else { - acc - } + } else { acc } }, ) } @@ -1660,9 +1612,7 @@ input_file: tests/assets/tablex.typ let frac-width = if amount-frac > 0 and not is-infinite-len(remaining) { remaining / amount-frac - } else { - 0pt - } + } else { 0pt } if type(gutter) == _fraction-type { gutter = frac-width * (gutter / 1fr) @@ -1814,9 +1764,7 @@ input_file: tests/assets/tablex.typ let fit-this-span = if "fit-spans" in pcell and pcell.fit-spans != auto { pcell.fit-spans.x - } else { - fit-spans.x - } + } else { fit-spans.x } let this-cell-can-expand-columns = pcell.colspan == 1 or not fit-this-span // only expand the last auto column of a colspan, @@ -1882,9 +1830,7 @@ input_file: tests/assets/tablex.typ width - fixed_size, 0pt, ) - } else { - max - } + } else { max } }, ) @@ -2002,9 +1948,7 @@ input_file: tests/assets/tablex.typ styles: styles, page-size: page_width, ) - } else if c == none { - 0pt - } else { + } else if c == none { 0pt } else { c } }) @@ -2013,9 +1957,7 @@ input_file: tests/assets/tablex.typ // (calculate it later if it's fractional) let fixed-size-gutter = if type(col-gutter) == _length-type { col-gutter - } else { - 0pt - } + } else { 0pt } let total_fixed_size = sum-fixed-size-tracks(columns) + fixed-size-gutter * ( columns.len() - 1 @@ -2062,18 +2004,14 @@ input_file: tests/assets/tablex.typ columns = columns.map(c => { if type(c) == _fraction-type { 0pt // no space left to be divided - } else { - c - } + } else { c } }) } } else { columns = columns.map(c => { if c == auto or type(c) == _fraction-type { 0pt // no space remaining! - } else { - c - } + } else { c } }) } @@ -2081,9 +2019,7 @@ input_file: tests/assets/tablex.typ columns: columns, gutter: if col-gutter == none { none - } else { - fixed-size-gutter - }, + } else { fixed-size-gutter }, ) } @@ -2129,9 +2065,7 @@ input_file: tests/assets/tablex.typ let fit-this-span = if "fit-spans" in pcell and pcell.fit-spans != auto { pcell.fit-spans.y - } else { - fit-spans.y - } + } else { fit-spans.y } let this-cell-can-expand-rows = pcell.rowspan == 1 or not fit-this-span // only expand the last auto row of a rowspan, @@ -2183,9 +2117,7 @@ input_file: tests/assets/tablex.typ height - fixed_size, 0pt, ) - } else { - max - } + } else { max } }, ) @@ -2224,9 +2156,7 @@ input_file: tests/assets/tablex.typ styles: styles, page-size: page_height, ) - } else { - r - } + } else { r } }) let auto_rows_res = determine-auto-rows( @@ -2246,9 +2176,7 @@ input_file: tests/assets/tablex.typ // (calculate it later if it's fractional) let fixed-size-gutter = if type(row-gutter) == _length-type { row-gutter - } else { - 0pt - } + } else { 0pt } let remaining = page_height - sum-fixed-size-tracks(rows) - auto_size - fixed-size-gutter * ( rows.len() - 1 @@ -2271,15 +2199,11 @@ input_file: tests/assets/tablex.typ if type(r) == _fraction-type { // no space remaining in this page or box 0pt - } else { - r - } + } else { r } }), gutter: if row-gutter == none { none - } else { - fixed-size-gutter - }, + } else { fixed-size-gutter }, ) } } @@ -2673,9 +2597,7 @@ input_file: tests/assets/tablex.typ (none, none), auto, (auto, auto), - ) { - return (none, none) - } + ) { return (none, none) } if type(line.expand) != _array-type { line.expand = ( line.expand, @@ -2752,9 +2674,7 @@ input_file: tests/assets/tablex.typ ) == default-if-auto-or-none( end, columns.len(), - ) { - return - } + ) { return } if gutter != none and gutter.row != none and ( ( @@ -2762,9 +2682,7 @@ input_file: tests/assets/tablex.typ ) or ( not pre-gutter and hline.gutter-restrict == top ) - ) { - return - } + ) { return } let expand = get-actual-expansion( hline, @@ -2883,9 +2801,7 @@ input_file: tests/assets/tablex.typ ) == default-if-auto-or-none( end, rows.len(), - ) { - return - } + ) { return } if gutter != none and gutter.col != none and ( ( @@ -2893,9 +2809,7 @@ input_file: tests/assets/tablex.typ ) or ( not pre-gutter and vline.gutter-restrict == left ) - ) { - return - } + ) { return } let expand = get-actual-expansion( vline, @@ -3291,9 +3205,7 @@ input_file: tests/assets/tablex.typ let header_last_y = if first-row-group != none { first-row-group.row_group.y_span.at(1) - } else { - none - } + } else { none } // if this is the second row, and the header's hlines // do not have priority (thus are not drawn by them, // otherwise they'd repeat on every page), then @@ -3302,9 +3214,7 @@ input_file: tests/assets/tablex.typ let hlines_below_header = first-row-group.row_group.hlines.filter(h => h.y == header_last_y + 1) hlines + hlines_below_header - } else { - hlines - } + } else { hlines } for hline in hlines { // only draw the top hline @@ -3312,9 +3222,7 @@ input_file: tests/assets/tablex.typ if hline.y == start-y { let header_last_y = if first-row-group != none { first-row-group.row_group.y_span.at(1) - } else { - none - } + } else { none } // pre-gutter is always false here, as we assume // hlines at the top of this row are handled // at pre-gutter by the preceding row, @@ -3655,9 +3563,7 @@ input_file: tests/assets/tablex.typ none } else { line.expand.slice(0, 2).map(e => { - if e == none { - e - } else { + if e == none { e } else { e = default-if-auto(e, 0pt) if type(e) not in ( _length-type, @@ -3852,9 +3758,7 @@ input_file: tests/assets/tablex.typ original-cells.map(c => { if is-tablex-occupied(c) { none - } else { - c - } + } else { c } }), ) @@ -3924,9 +3828,7 @@ input_file: tests/assets/tablex.typ original-cells.map(c => { if is-tablex-occupied(c) { none - } else { - c - } + } else { c } }), ) @@ -4272,9 +4174,7 @@ input_file: tests/assets/tablex.typ // the same size as the last specified row. let last-row-size = if rows.len() == 0 { auto - } else { - rows.last() - } + } else { rows.last() } for _ in range(grid_info.new_row_count - row_len) { rows.push(last-row-size) // add new rows (due to extra cells) } diff --git a/tests/snapshots/assets__check_file@tablex.typ-80.snap b/tests/snapshots/assets__check_file@tablex.typ-80.snap index c2ebd2db..ec70cfc8 100644 --- a/tests/snapshots/assets__check_file@tablex.typ-80.snap +++ b/tests/snapshots/assets__check_file@tablex.typ-80.snap @@ -49,9 +49,7 @@ input_file: tests/assets/tablex.typ #let typst-calc-rem-supported = using-typst-v030-or-later // Remainder operation. -#let calc-mod = if typst-calc-rem-supported { - calc.rem -} else { +#let calc-mod = if typst-calc-rem-supported { calc.rem } else { (a, b) => calc.floor(a) - calc.floor(b * calc.floor(a / b)) } @@ -65,9 +63,7 @@ input_file: tests/assets/tablex.typ } // Polyfill for array sum (.sum() is Typst 0.3.0+). -#let array-sum(arr, zero: 0) = { - arr.fold(zero, (a, x) => a + x) -} +#let array-sum(arr, zero: 0) = { arr.fold(zero, (a, x) => a + x) } // -- common validators -- @@ -81,12 +77,8 @@ input_file: tests/assets/tablex.typ ) = { if type(error-prefix) == _str-type { error-prefix = " " + error-prefix - } else { - error-prefix = "" - } - if type(fit-spans) == _bool-type { - fit-spans = (x: fit-spans, y: fit-spans) - } + } else { error-prefix = "" } + if type(fit-spans) == _bool-type { fit-spans = (x: fit-spans, y: fit-spans) } if type(fit-spans) == _dict-type { assert( fit-spans.len() > 0, @@ -217,9 +209,7 @@ input_file: tests/assets/tablex.typ item } else if type(item) != _dict-type or "tablex-dict-type" not in item { cellx[#item] - } else { - item - } + } else { item } } #let rowspanx(length, content, ..cell_options) = { @@ -260,11 +250,7 @@ input_file: tests/assets/tablex.typ _int-type, _float-type, ) and cell.y > acc - ) { - cell.y - } else { - acc - } + ) { cell.y } else { acc } }, ) @@ -272,16 +258,12 @@ input_file: tests/assets/tablex.typ if is-tablex-cell(item) and item.x == auto and item.y == auto { // cell occupies (colspan * rowspan) spaces len += item.colspan * item.rowspan - } else if type(item) == _content-type { - len += 1 - } + } else if type(item) == _content-type { len += 1 } } let rows(len) = calc.ceil(len / col_len) - while rows(len) < max_explicit_y { - len += col_len - } + while rows(len) < max_explicit_y { len += col_len } len } @@ -316,23 +298,15 @@ input_file: tests/assets/tablex.typ rows = (auto,) * rows } - if type(columns) != _array-type { - columns = (columns,) - } + if type(columns) != _array-type { columns = (columns,) } - if type(rows) != _array-type { - rows = (rows,) - } + if type(rows) != _array-type { rows = (rows,) } // default empty column to a single auto column - if columns.len() == 0 { - columns = (auto,) - } + if columns.len() == 0 { columns = (auto,) } // default empty row to a single auto row - if rows.len() == 0 { - rows = (auto,) - } + if rows.len() == 0 { rows = (auto,) } let col_row_is_valid(col_row) = ( (not is-infinite-len(col_row)) and ( @@ -378,16 +352,8 @@ input_file: tests/assets/tablex.typ // is greater than 1) #let positions-spanned-by(cell, x: 0, y: 0, x_limit: 0, y_limit: none) = { let result = () - let rowspan = if "rowspan" in cell { - cell.rowspan - } else { - 1 - } - let colspan = if "colspan" in cell { - cell.colspan - } else { - 1 - } + let rowspan = if "rowspan" in cell { cell.rowspan } else { 1 } + let colspan = if "colspan" in cell { cell.colspan } else { 1 } if rowspan < 1 { panic("Cell rowspan must be 1 or greater (bad cell: " + repr((x, y)) + ")") @@ -398,19 +364,11 @@ input_file: tests/assets/tablex.typ let max_x = x + colspan let max_y = y + rowspan - if x_limit != none { - max_x = calc.min(x_limit, max_x) - } + if x_limit != none { max_x = calc.min(x_limit, max_x) } - if y_limit != none { - max_y = calc.min(y_limit, max_y) - } + if y_limit != none { max_y = calc.min(y_limit, max_y) } - for x in range(x, max_x) { - for y in range(y, max_y) { - result.push((x, y)) - } - } + for x in range(x, max_x) { for y in range(y, max_y) { result.push((x, y)) } } result } @@ -419,9 +377,7 @@ input_file: tests/assets/tablex.typ #let init-array(amount, element: none, init_function: none) = { let nones = () - if init_function == none { - init_function = () => element - } + if init_function == none { init_function = () => element } range(amount).map(i => init_function()) } @@ -429,11 +385,7 @@ input_file: tests/assets/tablex.typ // Default 'x' to a certain value if it is equal to the forbidden value // ('none' by default) #let default-if-not(x, default, if_isnt: none) = { - if x == if_isnt { - default - } else { - x - } + if x == if_isnt { default } else { x } } // Default 'x' to a certain value if it is none @@ -445,18 +397,13 @@ input_file: tests/assets/tablex.typ // Default 'x' to a certain value if it is auto or none #let default-if-auto-or-none(x, default) = if x in (auto, none) { default -} else { - x -} +} else { x } // The max between a, b, or the other one if either is 'none'. -#let max-if-not-none(a, b) = if a in (none, auto) { - b -} else if b in (none, auto) { - a -} else { - calc.max(a, b) -} +#let max-if-not-none(a, b) = if a in (none, auto) { b } else if b in ( + none, + auto, +) { a } else { calc.max(a, b) } // Gets the topmost parent of a line. #let get-top-parent(line) = { @@ -510,9 +457,7 @@ input_file: tests/assets/tablex.typ // If the measured length is positive, `len` must have overall been positive. // There's nothing else to be done, so return the measured length. - if measured-pt > 0pt { - return measured-pt - } + if measured-pt > 0pt { return measured-pt } // If we've reached this point, the previously measured length must have been `0pt` // (drawing a line with a negative length will draw nothing, so measuring it will return `0pt`). @@ -582,9 +527,7 @@ input_file: tests/assets/tablex.typ panic("Cannot convert fraction to pt ('frac-total' not specified).") } - if frac-amount <= 0 or is-infinite-len(frac-total) { - return 0pt - } + if frac-amount <= 0 or is-infinite-len(frac-total) { return 0pt } let len-per-frac = frac-total / frac-amount @@ -619,9 +562,7 @@ input_file: tests/assets/tablex.typ // Calculate the length minus its em component. // E.g., 1% + 1pt + 1em -> 1% + 1pt - let (em-part, len-minus-em) = if em-part-repr == none { - (0em, len) - } else { + let (em-part, len-minus-em) = if em-part-repr == none { (0em, len) } else { // SAFETY: guaranteed to be a purely em length by regex let em-part = eval(em-part-repr) (em-part, len - em-part) @@ -638,9 +579,7 @@ input_file: tests/assets/tablex.typ let ratio-part-pt = if ratio-part == 0% { // No point doing `convert-ratio-type-to-pt` if there's no ratio component. 0pt - } else { - convert-ratio-type-to-pt(ratio-part, page-size) - } + } else { convert-ratio-type-to-pt(ratio-part, page-size) } // The length part is the pt part + em part. // Note: we cannot use `len - ratio-part` as that returns a `_rel-len-type` value, @@ -678,9 +617,7 @@ input_file: tests/assets/tablex.typ convert-fraction-type-to-pt(len, frac-amount, frac-total) } else if type(len) == _rel-len-type { convert-relative-type-to-pt(len, styles, page-size: page-size) - } else { - panic("Cannot convert '" + type(len) + "' to length.") - } + } else { panic("Cannot convert '" + type(len) + "' to length.") } } // Convert a stroke to its thickness @@ -691,9 +628,7 @@ input_file: tests/assets/tablex.typ convert-length-to-pt(stroke, styles: styles) } else if type(stroke) in (_rel-len-type, _ratio-type) { panic(no-ratio-error) - } else if is-color(stroke) { - 1pt - } else if type(stroke) == _stroke-type { + } else if is-color(stroke) { 1pt } else if type(stroke) == _stroke-type { if typst-fields-supported { // No need for any repr() parsing, just use the thickness field. let thickness = default-if-auto(stroke.thickness, 1pt) @@ -719,17 +654,13 @@ input_file: tests/assets/tablex.typ } } - if s == none { - 1pt // okay it's probably just a color then - } else { + if s == none { 1pt // okay it's probably just a color then } else { let len = eval(s) if type(len) == _length-type { convert-length-to-pt(len, styles: styles) } else if type(len) in (_rel-len-type, _ratio-type) { panic(no-ratio-error) - } else { - 1pt // should be unreachable - } + } else { 1pt // should be unreachable } } } else if type(stroke) == _dict-type and "thickness" in stroke { let thickness = stroke.thickness @@ -737,12 +668,8 @@ input_file: tests/assets/tablex.typ convert-length-to-pt(thickness, styles: styles) } else if type(thickness) in (_rel-len-type, _ratio-type) { panic(no-ratio-error) - } else { - 1pt - } - } else { - 1pt - } + } else { 1pt } + } else { 1pt } } // --- end: utility functions --- @@ -770,11 +697,7 @@ input_file: tests/assets/tablex.typ #let grid-at(grid, x, y) = { let index = grid-index-at(x, y, width: grid.width) - if index < grid.items.len() { - grid.items.at(index) - } else { - none - } + if index < grid.items.len() { grid.items.at(index) } else { none } } // Returns 'true' if the cell at (x, y) @@ -831,9 +754,7 @@ input_file: tests/assets/tablex.typ let now = grid-index-to-pos(grid, grid.items.len() - 1) // now columns and/or last missing row - while not grid-has-pos(grid, x, y) { - grid.items.push(fill_with(grid)) - } + while not grid-has-pos(grid, x, y) { grid.items.push(fill_with(grid)) } let new = grid-index-to-pos(grid, grid.items.len() - 1) grid @@ -844,9 +765,7 @@ input_file: tests/assets/tablex.typ #let get-parent-cell(cell, grid: none) = { if is-tablex-occupied(cell) { grid-at(grid, cell.parent_x, cell.parent_y) - } else if is-tablex-cell(cell) { - cell - } else { + } else if is-tablex-cell(cell) { cell } else { panic("Cannot get parent table cell of a non-cell object: " + repr(cell)) } } @@ -943,11 +862,7 @@ input_file: tests/assets/tablex.typ if is-some-tablex-line(item) { // detect lines' x, y if is-tablex-hline(item) { - let this_y = if first_cell_reached { - prev_y + 1 - } else { - prev_y - } + let this_y = if first_cell_reached { prev_y + 1 } else { prev_y } item.y = default-if-auto(item.y, this_y) @@ -966,15 +881,11 @@ input_file: tests/assets/tablex.typ } else if row_wrapped { item.x = x_limit // allow v_line at the last column row_wrapped = false - } else { - item.x = x - } + } else { item.x = x } } vlines.push(item) - } else { - panic("Invalid line received (must be hline or vline).") - } + } else { panic("Invalid line received (must be hline or vline).") } items.at(i) = item // override item with the new x / y coord set continue } @@ -1014,9 +925,7 @@ input_file: tests/assets/tablex.typ message: "Tablex error: 'map-cells' returned something that isn't a valid cell.", ) - if row_wrapped { - row_wrapped = false - } + if row_wrapped { row_wrapped = false } let content = cell.content let content = if type(content) == _function-type { @@ -1026,12 +935,8 @@ input_file: tests/assets/tablex.typ this_x = cell.x this_y = cell.y [#res.content] - } else { - [#res] - } - } else { - [#content] - } + } else { [#res] } + } else { [#content] } if this_x == none or this_y == none { panic("Error: Cell with function as content returned another cell with 'none' as x or y!") @@ -1148,9 +1053,7 @@ input_file: tests/assets/tablex.typ x = next_pos.at(0) y = next_pos.at(1) - if prev_y != y { - row_wrapped = true // we changed rows! - } + if prev_y != y { row_wrapped = true // we changed rows! } } // for missing cell positions: add empty cell @@ -1195,15 +1098,11 @@ input_file: tests/assets/tablex.typ let align_default = if type(align_default) == _function-type { align_default(cell.x, cell.y) // column, row - } else { - align_default - } + } else { align_default } let fill_default = if type(fill_default) == _function-type { fill_default(cell.x, cell.y) // row, column - } else { - fill_default - } + } else { fill_default } let content = cell.content @@ -1268,9 +1167,7 @@ input_file: tests/assets/tablex.typ panic("Tablex error: Invalid alignment specified (must be either a function (column, row) -> alignment, an alignment value - such as 'left' or 'center + top' -, an array of alignment values (one for each column), or 'auto').") } - let aligned_cell_content = if cell_align == auto { - [#content] - } else { + let aligned_cell_content = if cell_align == auto { [#content] } else { align(cell_align)[#content] } @@ -1292,13 +1189,7 @@ input_file: tests/assets/tablex.typ #let sum-fixed-size-tracks(tracks) = { tracks.fold( 0pt, - (acc, el) => { - if type(el) == _length-type { - acc + el - } else { - acc - } - }, + (acc, el) => { if type(el) == _length-type { acc + el } else { acc } }, ) } @@ -1317,17 +1208,11 @@ input_file: tests/assets/tablex.typ let frac-width = if amount-frac > 0 and not is-infinite-len(remaining) { remaining / amount-frac - } else { - 0pt - } + } else { 0pt } - if type(gutter) == _fraction-type { - gutter = frac-width * (gutter / 1fr) - } + if type(gutter) == _fraction-type { gutter = frac-width * (gutter / 1fr) } - for (i, size) in frac-tracks { - tracks.at(i) = frac-width * (size / 1fr) - } + for (i, size) in frac-tracks { tracks.at(i) = frac-width * (size / 1fr) } (tracks: tracks, gutter: gutter) } @@ -1371,9 +1256,7 @@ input_file: tests/assets/tablex.typ let size = 0pt for (i, col) in columns.enumerate() { - if i in cell-cols and type(col) == _length-type { - size += col - } + if i in cell-cols and type(col) == _length-type { size += col } } size } @@ -1387,9 +1270,7 @@ input_file: tests/assets/tablex.typ let size = 0pt for (i, row) in rows.enumerate() { - if i in cell-rows and type(row) == _length-type { - size += row - } + if i in cell-rows and type(row) == _length-type { size += row } } size } @@ -1430,9 +1311,7 @@ input_file: tests/assets/tablex.typ let fit-this-span = if "fit-spans" in pcell and pcell.fit-spans != auto { pcell.fit-spans.x - } else { - fit-spans.x - } + } else { fit-spans.x } let this-cell-can-expand-columns = pcell.colspan == 1 or not fit-this-span // only expand the last auto column of a colspan, @@ -1491,9 +1370,7 @@ input_file: tests/assets/tablex.typ ) calc.max(max, width - fixed_size, 0pt) - } else { - max - } + } else { max } }, ) @@ -1524,9 +1401,7 @@ input_file: tests/assets/tablex.typ let remaining = available let auto-cols-to-resize = auto-cols.len() - if auto-cols-to-resize <= 0 { - return columns - } + if auto-cols-to-resize <= 0 { return columns } // The fair-share must be the largest possible (to ensure maximum fairness) // such that we can shrink the minimum amount of columns possible and, at the @@ -1572,9 +1447,7 @@ input_file: tests/assets/tablex.typ // 2. Resize any columns larger than the calculated fair share to the fair share. for (i, col) in auto-cols { - if col > fair-share { - columns.at(i) = fair-share - } + if col > fair-share { columns.at(i) = fair-share } } columns @@ -1593,20 +1466,14 @@ input_file: tests/assets/tablex.typ let columns = columns.map(c => { if type(c) in (_length-type, _rel-len-type, _ratio-type) { convert-length-to-pt(c, styles: styles, page-size: page_width) - } else if c == none { - 0pt - } else { - c - } + } else if c == none { 0pt } else { c } }) // what is the fixed size of the gutter? // (calculate it later if it's fractional) let fixed-size-gutter = if type(col-gutter) == _length-type { col-gutter - } else { - 0pt - } + } else { 0pt } let total_fixed_size = sum-fixed-size-tracks(columns) + fixed-size-gutter * ( columns.len() - 1 @@ -1653,28 +1520,20 @@ input_file: tests/assets/tablex.typ columns = columns.map(c => { if type(c) == _fraction-type { 0pt // no space left to be divided - } else { - c - } + } else { c } }) } } else { columns = columns.map(c => { if c == auto or type(c) == _fraction-type { 0pt // no space remaining! - } else { - c - } + } else { c } }) } ( columns: columns, - gutter: if col-gutter == none { - none - } else { - fixed-size-gutter - }, + gutter: if col-gutter == none { none } else { fixed-size-gutter }, ) } @@ -1711,9 +1570,7 @@ input_file: tests/assets/tablex.typ let fit-this-span = if "fit-spans" in pcell and pcell.fit-spans != auto { pcell.fit-spans.y - } else { - fit-spans.y - } + } else { fit-spans.y } let this-cell-can-expand-rows = pcell.rowspan == 1 or not fit-this-span // only expand the last auto row of a rowspan, @@ -1755,9 +1612,7 @@ input_file: tests/assets/tablex.typ ) calc.max(max, height - fixed_size, 0pt) - } else { - max - } + } else { max } }, ) @@ -1784,9 +1639,7 @@ input_file: tests/assets/tablex.typ let rows = rows.map(r => { if type(r) in (_length-type, _rel-len-type, _ratio-type) { convert-length-to-pt(r, styles: styles, page-size: page_height) - } else { - r - } + } else { r } }) let auto_rows_res = determine-auto-rows( @@ -1806,9 +1659,7 @@ input_file: tests/assets/tablex.typ // (calculate it later if it's fractional) let fixed-size-gutter = if type(row-gutter) == _length-type { row-gutter - } else { - 0pt - } + } else { 0pt } let remaining = page_height - sum-fixed-size-tracks(rows) - auto_size - fixed-size-gutter * ( rows.len() - 1 @@ -1831,15 +1682,9 @@ input_file: tests/assets/tablex.typ if type(r) == _fraction-type { // no space remaining in this page or box 0pt - } else { - r - } + } else { r } }), - gutter: if row-gutter == none { - none - } else { - fixed-size-gutter - }, + gutter: if row-gutter == none { none } else { fixed-size-gutter }, ) } } @@ -1907,9 +1752,7 @@ input_file: tests/assets/tablex.typ let col_range = range(start, calc.min(columns.len() + 1, end)) let sum = 0pt - for i in col_range { - sum += columns.at(i) + col-gutter - } + for i in col_range { sum += columns.at(i) + col-gutter } // if the end is after all columns, there is // no gutter at the end. @@ -1933,9 +1776,7 @@ input_file: tests/assets/tablex.typ let row_range = range(start, calc.min(rows.len() + 1, end)) let sum = 0pt - for i in row_range { - sum += rows.at(i) + row-gutter - } + for i in row_range { sum += rows.at(i) + row-gutter } // if the end is after all rows, there is // no gutter at the end. @@ -1978,21 +1819,15 @@ input_file: tests/assets/tablex.typ // check the subspan a hline or vline goes through inside a larger span #let get-included-span(l_start, l_end, start: 0, end: 0, limit: 0) = { - if l_start in (none, auto) { - l_start = 0 - } + if l_start in (none, auto) { l_start = 0 } - if l_end in (none, auto) { - l_end = limit - } + if l_end in (none, auto) { l_end = limit } l_start = calc.max(0, l_start) l_end = calc.min(end, limit) // ---- ==== or ==== ---- - if l_end < start or l_start > end { - return none - } + if l_end < start or l_start > end { return none } // --##== ; ==##-- ; #### ; ... : intersection. (calc.max(l_start, start), calc.min(l_end, end)) @@ -2045,9 +1880,7 @@ input_file: tests/assets/tablex.typ if span == none { // no intersection! none - } else { - v-or-hline-with-span(h, start: span.at(0), end: span.at(1)) - } + } else { v-or-hline-with-span(h, start: span.at(0), end: span.at(1)) } }).filter(x => x != none) let vlines = vlines.filter(v => { @@ -2074,9 +1907,7 @@ input_file: tests/assets/tablex.typ if span == none { // no intersection! none - } else { - v-or-hline-with-span(v, start: span.at(0), end: span.at(1)) - } + } else { v-or-hline-with-span(v, start: span.at(0), end: span.at(1)) } }).filter(x => x != none) ( @@ -2133,17 +1964,13 @@ input_file: tests/assets/tablex.typ // -- drawing -- #let parse-stroke(stroke) = { - if is-color(stroke) { - stroke + 1pt - } else if type(stroke) in ( + if is-color(stroke) { stroke + 1pt } else if type(stroke) in ( _length-type, _rel-len-type, _ratio-type, _stroke-type, _dict-type, - ) or stroke in (none, auto) { - stroke - } else { + ) or stroke in (none, auto) { stroke } else { panic("Invalid stroke '" + repr(stroke) + "'.") } } @@ -2211,17 +2038,13 @@ input_file: tests/assets/tablex.typ if default-if-auto-or-none(start, 0) == default-if-auto-or-none( end, columns.len(), - ) { - return - } + ) { return } if gutter != none and gutter.row != none and ( (pre-gutter and hline.gutter-restrict == bottom) or ( not pre-gutter and hline.gutter-restrict == top ) - ) { - return - } + ) { return } let expand = get-actual-expansion(hline, spanned-tracks-len: columns.len()) let left-expand = default-if-auto-or-none(expand.at(0), 0pt) @@ -2263,9 +2086,7 @@ input_file: tests/assets/tablex.typ pre-gutter: hline.stop-pre-gutter == true, ) + right-expand - if end_x - start_x < 0pt { - return // negative length - } + if end_x - start_x < 0pt { return // negative length } if rtl { // invert the line (start from the right instead of from the left) @@ -2283,12 +2104,8 @@ input_file: tests/assets/tablex.typ ) if stroke != auto { - if stroke != none { - line(start: start, end: end, stroke: stroke) - } - } else { - line(start: start, end: end) - } + if stroke != none { line(start: start, end: end, stroke: stroke) } + } else { line(start: start, end: end) } } #let draw-vline( @@ -2315,17 +2132,13 @@ input_file: tests/assets/tablex.typ if default-if-auto-or-none(start, 0) == default-if-auto-or-none( end, rows.len(), - ) { - return - } + ) { return } if gutter != none and gutter.col != none and ( (pre-gutter and vline.gutter-restrict == right) or ( not pre-gutter and vline.gutter-restrict == left ) - ) { - return - } + ) { return } let expand = get-actual-expansion(vline, spanned-tracks-len: rows.len()) let top-expand = default-if-auto-or-none(expand.at(0), 0pt) @@ -2366,9 +2179,7 @@ input_file: tests/assets/tablex.typ pre-gutter: stop-before-row-gutter or vline.stop-pre-gutter == true, ) + bottom-expand - if end_y - start_y < 0pt { - return // negative length - } + if end_y - start_y < 0pt { return // negative length } if rtl { // invert the vertical line's x pos (start from the right instead of from the left) @@ -2385,12 +2196,8 @@ input_file: tests/assets/tablex.typ ) if stroke != auto { - if stroke != none { - line(start: start, end: end, stroke: stroke) - } - } else { - line(start: start, end: end) - } + if stroke != none { line(start: start, end: end, stroke: stroke) } + } else { line(start: start, end: end) } } // -- end: drawing @@ -2426,9 +2233,7 @@ input_file: tests/assets/tablex.typ top + left, locate(loc => { page_dim_state.update(s => { - if s.top_left != none { - s - } else { + if s.top_left != none { s } else { let pos = loc.position() let width = s.width - pos.x let height = s.width - pos.y @@ -2447,9 +2252,7 @@ input_file: tests/assets/tablex.typ bottom + right, locate(loc => { page_dim_state.update(s => { - if s.bottom_right != none { - s - } else { + if s.bottom_right != none { s } else { let pos = loc.position() let width = s.width + pos.x let height = s.width + pos.y @@ -2642,9 +2445,7 @@ input_file: tests/assets/tablex.typ let header_last_y = if first-row-group != none { first-row-group.row_group.y_span.at(1) - } else { - none - } + } else { none } // if this is the second row, and the header's hlines // do not have priority (thus are not drawn by them, // otherwise they'd repeat on every page), then @@ -2653,9 +2454,7 @@ input_file: tests/assets/tablex.typ let hlines_below_header = first-row-group.row_group.hlines.filter(h => h.y == header_last_y + 1) hlines + hlines_below_header - } else { - hlines - } + } else { hlines } for hline in hlines { // only draw the top hline @@ -2663,9 +2462,7 @@ input_file: tests/assets/tablex.typ if hline.y == start-y { let header_last_y = if first-row-group != none { first-row-group.row_group.y_span.at(1) - } else { - none - } + } else { none } // pre-gutter is always false here, as we assume // hlines at the top of this row are handled // at pre-gutter by the preceding row, @@ -2931,13 +2728,9 @@ input_file: tests/assets/tablex.typ if type(line.expand) != _array-type and line.expand != none { line.expand = (line.expand, line.expand) } - line.expand = if line.expand == none { - none - } else { + line.expand = if line.expand == none { none } else { line.expand.slice(0, 2).map(e => { - if e == none { - e - } else { + if e == none { e } else { e = default-if-auto(e, 0pt) if type(e) not in (_length-type, _rel-len-type, _ratio-type) { panic("'expand' argument to lines must be a pair (length, length).") @@ -3079,11 +2872,7 @@ input_file: tests/assets/tablex.typ let cells = map-rows( row, original-cells.map(c => { - if is-tablex-occupied(c) { - none - } else { - c - } + if is-tablex-occupied(c) { none } else { c } }), ) @@ -3139,11 +2928,7 @@ input_file: tests/assets/tablex.typ let cells = map-cols( column, original-cells.map(c => { - if is-tablex-occupied(c) { - none - } else { - c - } + if is-tablex-occupied(c) { none } else { c } }), ) @@ -3444,11 +3229,7 @@ input_file: tests/assets/tablex.typ // When there are more rows than the user specified, we ensure they have // the same size as the last specified row. - let last-row-size = if rows.len() == 0 { - auto - } else { - rows.last() - } + let last-row-size = if rows.len() == 0 { auto } else { rows.last() } for _ in range(grid_info.new_row_count - row_len) { rows.push(last-row-size) // add new rows (due to extra cells) } @@ -3549,6 +3330,4 @@ input_file: tests/assets/tablex.typ } // Same as table but defaults to lines off -#let gridx(..options) = { - tablex(auto-lines: false, ..options) -} +#let gridx(..options) = { tablex(auto-lines: false, ..options) } diff --git a/tests/snapshots/assets__check_file@typstfmt-138-non-converge-block-comment.typ-120.snap b/tests/snapshots/assets__check_file@typstfmt-138-non-converge-block-comment.typ-120.snap index e66d35af..d6efcf88 100644 --- a/tests/snapshots/assets__check_file@typstfmt-138-non-converge-block-comment.typ-120.snap +++ b/tests/snapshots/assets__check_file@typstfmt-138-non-converge-block-comment.typ-120.snap @@ -3,10 +3,8 @@ source: tests/assets.rs expression: doc_string input_file: tests/assets/typstfmt/138-non-converge-block-comment.typ --- -#let test_func() = { - ( +#let test_func() = { ( /* test */ -) -} +) } diff --git a/tests/snapshots/assets__check_file@typstfmt-138-non-converge-block-comment.typ-40.snap b/tests/snapshots/assets__check_file@typstfmt-138-non-converge-block-comment.typ-40.snap index e66d35af..d6efcf88 100644 --- a/tests/snapshots/assets__check_file@typstfmt-138-non-converge-block-comment.typ-40.snap +++ b/tests/snapshots/assets__check_file@typstfmt-138-non-converge-block-comment.typ-40.snap @@ -3,10 +3,8 @@ source: tests/assets.rs expression: doc_string input_file: tests/assets/typstfmt/138-non-converge-block-comment.typ --- -#let test_func() = { - ( +#let test_func() = { ( /* test */ -) -} +) } diff --git a/tests/snapshots/assets__check_file@typstfmt-138-non-converge-block-comment.typ-80.snap b/tests/snapshots/assets__check_file@typstfmt-138-non-converge-block-comment.typ-80.snap index e66d35af..d6efcf88 100644 --- a/tests/snapshots/assets__check_file@typstfmt-138-non-converge-block-comment.typ-80.snap +++ b/tests/snapshots/assets__check_file@typstfmt-138-non-converge-block-comment.typ-80.snap @@ -3,10 +3,8 @@ source: tests/assets.rs expression: doc_string input_file: tests/assets/typstfmt/138-non-converge-block-comment.typ --- -#let test_func() = { - ( +#let test_func() = { ( /* test */ -) -} +) } diff --git a/tests/snapshots/assets__check_file@undergraduate-math.typ-120.snap b/tests/snapshots/assets__check_file@undergraduate-math.typ-120.snap index 5d84dc3c..bc0a06b9 100644 --- a/tests/snapshots/assets__check_file@undergraduate-math.typ-120.snap +++ b/tests/snapshots/assets__check_file@undergraduate-math.typ-120.snap @@ -52,9 +52,7 @@ input_file: tests/assets/undergraduate-math.typ // No idea #show "?!": box(text(orange, [No idea #emoji.face.unhappy])) // Tricky figure numbering -#set figure(numbering: n => { - ([??], [!!], [?!]).at(n) -}) +#set figure(numbering: n => { ([??], [!!], [?!]).at(n) }) // No prefix #set ref(supplement: "") @@ -73,9 +71,7 @@ input_file: tests/assets/undergraduate-math.typ ) // Black raw code -#show raw.where(block: false): it => { - it.text -} +#show raw.where(block: false): it => { it.text } // Put this here to avoid affecting the title #show link: underline diff --git a/tests/snapshots/assets__check_file@undergraduate-math.typ-80.snap b/tests/snapshots/assets__check_file@undergraduate-math.typ-80.snap index 2b489f4c..6e98d05c 100644 --- a/tests/snapshots/assets__check_file@undergraduate-math.typ-80.snap +++ b/tests/snapshots/assets__check_file@undergraduate-math.typ-80.snap @@ -52,9 +52,7 @@ input_file: tests/assets/undergraduate-math.typ // No idea #show "?!": box(text(orange, [No idea #emoji.face.unhappy])) // Tricky figure numbering -#set figure(numbering: n => { - ([??], [!!], [?!]).at(n) -}) +#set figure(numbering: n => { ([??], [!!], [?!]).at(n) }) // No prefix #set ref(supplement: "") @@ -73,9 +71,7 @@ input_file: tests/assets/undergraduate-math.typ ) // Black raw code -#show raw.where(block: false): it => { - it.text -} +#show raw.where(block: false): it => { it.text } // Put this here to avoid affecting the title #show link: underline diff --git a/tests/snapshots/assets__check_file@unit-code-arg-flavor.typ-120.snap b/tests/snapshots/assets__check_file@unit-code-arg-flavor.typ-120.snap index 382dda54..f4e6f9aa 100644 --- a/tests/snapshots/assets__check_file@unit-code-arg-flavor.typ-120.snap +++ b/tests/snapshots/assets__check_file@unit-code-arg-flavor.typ-120.snap @@ -3,14 +3,10 @@ source: tests/assets.rs expression: doc_string input_file: tests/assets/unit/code/arg-flavor.typ --- -#let my-f(arg1, arg2, args: none) = { - arg1 + arg2 -} +#let my-f(arg1, arg2, args: none) = { arg1 + arg2 } #let my-f( arg1, arg2, args: none, -) = { - arg1 + arg2 -} +) = { arg1 + arg2 } diff --git a/tests/snapshots/assets__check_file@unit-code-arg-flavor.typ-40.snap b/tests/snapshots/assets__check_file@unit-code-arg-flavor.typ-40.snap index 382dda54..7aaaa17e 100644 --- a/tests/snapshots/assets__check_file@unit-code-arg-flavor.typ-40.snap +++ b/tests/snapshots/assets__check_file@unit-code-arg-flavor.typ-40.snap @@ -11,6 +11,4 @@ input_file: tests/assets/unit/code/arg-flavor.typ arg1, arg2, args: none, -) = { - arg1 + arg2 -} +) = { arg1 + arg2 } diff --git a/tests/snapshots/assets__check_file@unit-code-arg-flavor.typ-80.snap b/tests/snapshots/assets__check_file@unit-code-arg-flavor.typ-80.snap index 382dda54..f4e6f9aa 100644 --- a/tests/snapshots/assets__check_file@unit-code-arg-flavor.typ-80.snap +++ b/tests/snapshots/assets__check_file@unit-code-arg-flavor.typ-80.snap @@ -3,14 +3,10 @@ source: tests/assets.rs expression: doc_string input_file: tests/assets/unit/code/arg-flavor.typ --- -#let my-f(arg1, arg2, args: none) = { - arg1 + arg2 -} +#let my-f(arg1, arg2, args: none) = { arg1 + arg2 } #let my-f( arg1, arg2, args: none, -) = { - arg1 + arg2 -} +) = { arg1 + arg2 } diff --git a/tests/snapshots/assets__check_file@unit-code-array-flavor.typ-120.snap b/tests/snapshots/assets__check_file@unit-code-array-flavor.typ-120.snap index e7124ede..6688ce91 100644 --- a/tests/snapshots/assets__check_file@unit-code-array-flavor.typ-120.snap +++ b/tests/snapshots/assets__check_file@unit-code-array-flavor.typ-120.snap @@ -11,6 +11,4 @@ input_file: tests/assets/unit/code/array-flavor.typ ) } -#{ - (11, 22, 33) -} +#{ (11, 22, 33) } diff --git a/tests/snapshots/assets__check_file@unit-code-array-flavor.typ-40.snap b/tests/snapshots/assets__check_file@unit-code-array-flavor.typ-40.snap index e7124ede..6688ce91 100644 --- a/tests/snapshots/assets__check_file@unit-code-array-flavor.typ-40.snap +++ b/tests/snapshots/assets__check_file@unit-code-array-flavor.typ-40.snap @@ -11,6 +11,4 @@ input_file: tests/assets/unit/code/array-flavor.typ ) } -#{ - (11, 22, 33) -} +#{ (11, 22, 33) } diff --git a/tests/snapshots/assets__check_file@unit-code-array-flavor.typ-80.snap b/tests/snapshots/assets__check_file@unit-code-array-flavor.typ-80.snap index e7124ede..6688ce91 100644 --- a/tests/snapshots/assets__check_file@unit-code-array-flavor.typ-80.snap +++ b/tests/snapshots/assets__check_file@unit-code-array-flavor.typ-80.snap @@ -11,6 +11,4 @@ input_file: tests/assets/unit/code/array-flavor.typ ) } -#{ - (11, 22, 33) -} +#{ (11, 22, 33) } diff --git a/tests/snapshots/assets__check_file@unit-code-cond.typ-120.snap b/tests/snapshots/assets__check_file@unit-code-cond.typ-120.snap index 15310919..e655153e 100644 --- a/tests/snapshots/assets__check_file@unit-code-cond.typ-120.snap +++ b/tests/snapshots/assets__check_file@unit-code-cond.typ-120.snap @@ -3,15 +3,9 @@ source: tests/assets.rs expression: doc_string input_file: tests/assets/unit/code/cond.typ --- -#if not true { - // false -} +#if not true { // false } -#if (is-tablex-cell(cell) and type(cell.y) in (_int-type, _float-type) and cell.y > acc) { - cell.y -} else { - acc -} +#if (is-tablex-cell(cell) and type(cell.y) in (_int-type, _float-type) and cell.y > acc) { cell.y } else { acc } #let a = 0 diff --git a/tests/snapshots/assets__check_file@unit-code-cond.typ-40.snap b/tests/snapshots/assets__check_file@unit-code-cond.typ-40.snap index b4c0603c..e04700a4 100644 --- a/tests/snapshots/assets__check_file@unit-code-cond.typ-40.snap +++ b/tests/snapshots/assets__check_file@unit-code-cond.typ-40.snap @@ -3,20 +3,14 @@ source: tests/assets.rs expression: doc_string input_file: tests/assets/unit/code/cond.typ --- -#if not true { - // false -} +#if not true { // false } #if ( is-tablex-cell(cell) and type(cell.y) in ( _int-type, _float-type, ) and cell.y > acc -) { - cell.y -} else { - acc -} +) { cell.y } else { acc } #let a = 0 diff --git a/tests/snapshots/assets__check_file@unit-code-cond.typ-80.snap b/tests/snapshots/assets__check_file@unit-code-cond.typ-80.snap index b4c0603c..e04700a4 100644 --- a/tests/snapshots/assets__check_file@unit-code-cond.typ-80.snap +++ b/tests/snapshots/assets__check_file@unit-code-cond.typ-80.snap @@ -3,20 +3,14 @@ source: tests/assets.rs expression: doc_string input_file: tests/assets/unit/code/cond.typ --- -#if not true { - // false -} +#if not true { // false } #if ( is-tablex-cell(cell) and type(cell.y) in ( _int-type, _float-type, ) and cell.y > acc -) { - cell.y -} else { - acc -} +) { cell.y } else { acc } #let a = 0 diff --git a/tests/snapshots/assets__check_file@unit-code-for-loop-line-break.typ-120.snap b/tests/snapshots/assets__check_file@unit-code-for-loop-line-break.typ-120.snap index beceedb9..ae4cb187 100644 --- a/tests/snapshots/assets__check_file@unit-code-for-loop-line-break.typ-120.snap +++ b/tests/snapshots/assets__check_file@unit-code-for-loop-line-break.typ-120.snap @@ -5,11 +5,7 @@ input_file: tests/assets/unit/code/for-loop-line-break.typ --- #let 六面体 = { import draw: * - let neg(u) = if u == 0 { - 1 - } else { - -1 - } + let neg(u) = if u == 0 { 1 } else { -1 } for (p, c) in ( ((0, 0, 0), black), ((1, 1, 0), red), diff --git a/tests/snapshots/assets__check_file@unit-code-for-loop-line-break.typ-40.snap b/tests/snapshots/assets__check_file@unit-code-for-loop-line-break.typ-40.snap index 6dc39f27..49074575 100644 --- a/tests/snapshots/assets__check_file@unit-code-for-loop-line-break.typ-40.snap +++ b/tests/snapshots/assets__check_file@unit-code-for-loop-line-break.typ-40.snap @@ -5,9 +5,7 @@ input_file: tests/assets/unit/code/for-loop-line-break.typ --- #let 六面体 = { import draw: * - let neg(u) = if u == 0 { - 1 - } else { + let neg(u) = if u == 0 { 1 } else { -1 } for (p, c) in ( diff --git a/tests/snapshots/assets__check_file@unit-code-for-loop-line-break.typ-80.snap b/tests/snapshots/assets__check_file@unit-code-for-loop-line-break.typ-80.snap index feb72061..fdac396c 100644 --- a/tests/snapshots/assets__check_file@unit-code-for-loop-line-break.typ-80.snap +++ b/tests/snapshots/assets__check_file@unit-code-for-loop-line-break.typ-80.snap @@ -5,11 +5,7 @@ input_file: tests/assets/unit/code/for-loop-line-break.typ --- #let 六面体 = { import draw: * - let neg(u) = if u == 0 { - 1 - } else { - -1 - } + let neg(u) = if u == 0 { 1 } else { -1 } for (p, c) in ( ((0, 0, 0), black), ((1, 1, 0), red), @@ -27,9 +23,7 @@ input_file: tests/assets/unit/code/for-loop-line-break.typ pppppppppppppppppppppppppppppppppppppppppp, cccccccccccccccccccccccccccccccc, b, - ) in ((111111, 111111111, 1),) { - "111111111111111111111111111111111" - } + ) in ((111111, 111111111, 1),) { "111111111111111111111111111111111" } } #{ diff --git a/tests/snapshots/assets__check_file@unit-code-short-if.typ-120.snap b/tests/snapshots/assets__check_file@unit-code-short-if.typ-120.snap new file mode 100644 index 00000000..900d6f4e --- /dev/null +++ b/tests/snapshots/assets__check_file@unit-code-short-if.typ-120.snap @@ -0,0 +1,11 @@ +--- +source: tests/assets.rs +expression: doc_string +input_file: tests/assets/unit/code/short-if.typ +--- +#table( + fill: (x, y) => if y == 0 { white.darken(15%) } else { none }, + align: (x, y) => if y == 0 { center } else { horizon }, + [Hi], + [there], +) diff --git a/tests/snapshots/assets__check_file@unit-code-short-if.typ-40.snap b/tests/snapshots/assets__check_file@unit-code-short-if.typ-40.snap new file mode 100644 index 00000000..ab9bdd39 --- /dev/null +++ b/tests/snapshots/assets__check_file@unit-code-short-if.typ-40.snap @@ -0,0 +1,15 @@ +--- +source: tests/assets.rs +expression: doc_string +input_file: tests/assets/unit/code/short-if.typ +--- +#table( + fill: (x, y) => if y == 0 { + white.darken(15%) + } else { none }, + align: (x, y) => if y == 0 { + center + } else { horizon }, + [Hi], + [there], +) diff --git a/tests/snapshots/assets__check_file@unit-code-short-if.typ-80.snap b/tests/snapshots/assets__check_file@unit-code-short-if.typ-80.snap new file mode 100644 index 00000000..900d6f4e --- /dev/null +++ b/tests/snapshots/assets__check_file@unit-code-short-if.typ-80.snap @@ -0,0 +1,11 @@ +--- +source: tests/assets.rs +expression: doc_string +input_file: tests/assets/unit/code/short-if.typ +--- +#table( + fill: (x, y) => if y == 0 { white.darken(15%) } else { none }, + align: (x, y) => if y == 0 { center } else { horizon }, + [Hi], + [there], +) diff --git a/tests/snapshots/assets__check_file@unit-comment-comment-in-func-call.typ-120.snap b/tests/snapshots/assets__check_file@unit-comment-comment-in-func-call.typ-120.snap index 3ecf5021..049fabab 100644 --- a/tests/snapshots/assets__check_file@unit-comment-comment-in-func-call.typ-120.snap +++ b/tests/snapshots/assets__check_file@unit-comment-comment-in-func-call.typ-120.snap @@ -3,9 +3,7 @@ source: tests/assets.rs expression: doc_string input_file: tests/assets/unit/comment/comment-in-func-call.typ --- -#let f(a, b, c: none) = { - [#a] -} +#let f(a, b, c: none) = { [#a] } #f(1, 2, c: 3) diff --git a/tests/snapshots/assets__check_file@unit-comment-comment-in-func-call.typ-40.snap b/tests/snapshots/assets__check_file@unit-comment-comment-in-func-call.typ-40.snap index 3ecf5021..049fabab 100644 --- a/tests/snapshots/assets__check_file@unit-comment-comment-in-func-call.typ-40.snap +++ b/tests/snapshots/assets__check_file@unit-comment-comment-in-func-call.typ-40.snap @@ -3,9 +3,7 @@ source: tests/assets.rs expression: doc_string input_file: tests/assets/unit/comment/comment-in-func-call.typ --- -#let f(a, b, c: none) = { - [#a] -} +#let f(a, b, c: none) = { [#a] } #f(1, 2, c: 3) diff --git a/tests/snapshots/assets__check_file@unit-comment-comment-in-func-call.typ-80.snap b/tests/snapshots/assets__check_file@unit-comment-comment-in-func-call.typ-80.snap index 3ecf5021..049fabab 100644 --- a/tests/snapshots/assets__check_file@unit-comment-comment-in-func-call.typ-80.snap +++ b/tests/snapshots/assets__check_file@unit-comment-comment-in-func-call.typ-80.snap @@ -3,9 +3,7 @@ source: tests/assets.rs expression: doc_string input_file: tests/assets/unit/comment/comment-in-func-call.typ --- -#let f(a, b, c: none) = { - [#a] -} +#let f(a, b, c: none) = { [#a] } #f(1, 2, c: 3) diff --git a/tests/snapshots/assets__check_file@unit-comment-line-comment-attach.typ-120.snap b/tests/snapshots/assets__check_file@unit-comment-line-comment-attach.typ-120.snap index e6b22eb5..4c7a4a17 100644 --- a/tests/snapshots/assets__check_file@unit-comment-line-comment-attach.typ-120.snap +++ b/tests/snapshots/assets__check_file@unit-comment-line-comment-attach.typ-120.snap @@ -5,9 +5,7 @@ input_file: tests/assets/unit/comment/line-comment-attach.typ --- #import "@preview/cheq:0.1.0": checklist -#{ - show: checklist.with(fill: luma(95%), stroke: blue, radius: .2em) // 复选框 -} +#{ show: checklist.with(fill: luma(95%), stroke: blue, radius: .2em) // 复选框 } #{ show: checklist.with(fill: luma(95%), stroke: blue, radius: .2em) // 复选框 diff --git a/tests/snapshots/assets__check_file@unit-comment-line-comment-attach.typ-80.snap b/tests/snapshots/assets__check_file@unit-comment-line-comment-attach.typ-80.snap index e6b22eb5..4c7a4a17 100644 --- a/tests/snapshots/assets__check_file@unit-comment-line-comment-attach.typ-80.snap +++ b/tests/snapshots/assets__check_file@unit-comment-line-comment-attach.typ-80.snap @@ -5,9 +5,7 @@ input_file: tests/assets/unit/comment/line-comment-attach.typ --- #import "@preview/cheq:0.1.0": checklist -#{ - show: checklist.with(fill: luma(95%), stroke: blue, radius: .2em) // 复选框 -} +#{ show: checklist.with(fill: luma(95%), stroke: blue, radius: .2em) // 复选框 } #{ show: checklist.with(fill: luma(95%), stroke: blue, radius: .2em) // 复选框 diff --git a/tests/snapshots/assets__check_file@unit-func-spread.typ-120.snap b/tests/snapshots/assets__check_file@unit-func-spread.typ-120.snap index 667dfe69..565b811a 100644 --- a/tests/snapshots/assets__check_file@unit-func-spread.typ-120.snap +++ b/tests/snapshots/assets__check_file@unit-func-spread.typ-120.snap @@ -13,8 +13,6 @@ input_file: tests/assets/unit/func/spread.typ spread: 1, name: none, ..style, -) = { - -} +) = { } #let f = (..) => 1 diff --git a/tests/snapshots/assets__check_file@unit-func-spread.typ-40.snap b/tests/snapshots/assets__check_file@unit-func-spread.typ-40.snap index 667dfe69..565b811a 100644 --- a/tests/snapshots/assets__check_file@unit-func-spread.typ-40.snap +++ b/tests/snapshots/assets__check_file@unit-func-spread.typ-40.snap @@ -13,8 +13,6 @@ input_file: tests/assets/unit/func/spread.typ spread: 1, name: none, ..style, -) = { - -} +) = { } #let f = (..) => 1 diff --git a/tests/snapshots/assets__check_file@unit-func-spread.typ-80.snap b/tests/snapshots/assets__check_file@unit-func-spread.typ-80.snap index 667dfe69..565b811a 100644 --- a/tests/snapshots/assets__check_file@unit-func-spread.typ-80.snap +++ b/tests/snapshots/assets__check_file@unit-func-spread.typ-80.snap @@ -13,8 +13,6 @@ input_file: tests/assets/unit/func/spread.typ spread: 1, name: none, ..style, -) = { - -} +) = { } #let f = (..) => 1 diff --git a/tests/snapshots/assets__check_file@unit-markup-code-inside-content.typ-120.snap b/tests/snapshots/assets__check_file@unit-markup-code-inside-content.typ-120.snap index 4cfcaa26..07264a55 100644 --- a/tests/snapshots/assets__check_file@unit-markup-code-inside-content.typ-120.snap +++ b/tests/snapshots/assets__check_file@unit-markup-code-inside-content.typ-120.snap @@ -3,6 +3,4 @@ source: tests/assets.rs expression: doc_string input_file: tests/assets/unit/markup/code-inside-content.typ --- -#[#{ - let something = 0 - }\ ] +#[#{ let something = 0 }\ ] diff --git a/tests/snapshots/assets__check_file@unit-markup-code-inside-content.typ-40.snap b/tests/snapshots/assets__check_file@unit-markup-code-inside-content.typ-40.snap index 4cfcaa26..07264a55 100644 --- a/tests/snapshots/assets__check_file@unit-markup-code-inside-content.typ-40.snap +++ b/tests/snapshots/assets__check_file@unit-markup-code-inside-content.typ-40.snap @@ -3,6 +3,4 @@ source: tests/assets.rs expression: doc_string input_file: tests/assets/unit/markup/code-inside-content.typ --- -#[#{ - let something = 0 - }\ ] +#[#{ let something = 0 }\ ] diff --git a/tests/snapshots/assets__check_file@unit-markup-code-inside-content.typ-80.snap b/tests/snapshots/assets__check_file@unit-markup-code-inside-content.typ-80.snap index 4cfcaa26..07264a55 100644 --- a/tests/snapshots/assets__check_file@unit-markup-code-inside-content.typ-80.snap +++ b/tests/snapshots/assets__check_file@unit-markup-code-inside-content.typ-80.snap @@ -3,6 +3,4 @@ source: tests/assets.rs expression: doc_string input_file: tests/assets/unit/markup/code-inside-content.typ --- -#[#{ - let something = 0 - }\ ] +#[#{ let something = 0 }\ ] diff --git a/tests/snapshots/assets__check_file@unit-math-var-in-math.typ-120.snap b/tests/snapshots/assets__check_file@unit-math-var-in-math.typ-120.snap index 385e3163..a9ea0e17 100644 --- a/tests/snapshots/assets__check_file@unit-math-var-in-math.typ-120.snap +++ b/tests/snapshots/assets__check_file@unit-math-var-in-math.typ-120.snap @@ -3,11 +3,7 @@ source: tests/assets.rs expression: doc_string input_file: tests/assets/unit/math/var-in-math.typ --- -#let f(content) = { - if type(content) in (float, int) { - content = $#content$ - } -} +#let f(content) = { if type(content) in (float, int) { content = $#content$ } } $ lr([sum_(k = 0)^n e^(k^2)], size: #50%) $ diff --git a/tests/snapshots/assets__check_file@unit-math-var-in-math.typ-80.snap b/tests/snapshots/assets__check_file@unit-math-var-in-math.typ-80.snap index 385e3163..a9ea0e17 100644 --- a/tests/snapshots/assets__check_file@unit-math-var-in-math.typ-80.snap +++ b/tests/snapshots/assets__check_file@unit-math-var-in-math.typ-80.snap @@ -3,11 +3,7 @@ source: tests/assets.rs expression: doc_string input_file: tests/assets/unit/math/var-in-math.typ --- -#let f(content) = { - if type(content) in (float, int) { - content = $#content$ - } -} +#let f(content) = { if type(content) in (float, int) { content = $#content$ } } $ lr([sum_(k = 0)^n e^(k^2)], size: #50%) $ diff --git a/tests/snapshots/assets__check_file@unit-show-code-show-closure.typ-120.snap b/tests/snapshots/assets__check_file@unit-show-code-show-closure.typ-120.snap index f3e4eecc..5af25555 100644 --- a/tests/snapshots/assets__check_file@unit-show-code-show-closure.typ-120.snap +++ b/tests/snapshots/assets__check_file@unit-show-code-show-closure.typ-120.snap @@ -9,9 +9,7 @@ input_file: tests/assets/unit/show/code-show-closure.typ show heading: it => box(width: 100%)[ #v(0.50em) #set text(font: heading-font) - #if it.numbering != none { - counter(heading).display() - } + #if it.numbering != none { counter(heading).display() } #h(0.75em) #it.body ] diff --git a/tests/snapshots/assets__check_file@unit-show-code-show-closure.typ-80.snap b/tests/snapshots/assets__check_file@unit-show-code-show-closure.typ-80.snap index f3e4eecc..5af25555 100644 --- a/tests/snapshots/assets__check_file@unit-show-code-show-closure.typ-80.snap +++ b/tests/snapshots/assets__check_file@unit-show-code-show-closure.typ-80.snap @@ -9,9 +9,7 @@ input_file: tests/assets/unit/show/code-show-closure.typ show heading: it => box(width: 100%)[ #v(0.50em) #set text(font: heading-font) - #if it.numbering != none { - counter(heading).display() - } + #if it.numbering != none { counter(heading).display() } #h(0.75em) #it.body ]