diff --git a/src/library/mod.rs b/src/library/mod.rs index b33ec7116..7e9689941 100644 --- a/src/library/mod.rs +++ b/src/library/mod.rs @@ -44,13 +44,13 @@ pub fn new() -> Scope { // Functions. set!(func: "align", align); - set!(func: "box", box_); set!(func: "font", font); set!(func: "h", h); set!(func: "image", image); set!(func: "pad", pad); set!(func: "page", page); set!(func: "pagebreak", pagebreak); + set!(func: "rect", rect); set!(func: "repr", repr); set!(func: "rgb", rgb); set!(func: "type", type_); diff --git a/src/library/shapes.rs b/src/library/shapes.rs index 254a22852..41be3b2b2 100644 --- a/src/library/shapes.rs +++ b/src/library/shapes.rs @@ -1,16 +1,16 @@ use super::*; -/// `box`: Create a rectangular box. +/// `rect`: Create a rectangular box. /// /// # Positional arguments /// - Body: optional, of type `template`. /// /// # Named arguments -/// - Width of the box: `width`, of type `linear` relative to parent width. -/// - Height of the box: `height`, of type `linear` relative to parent height. -/// - Main layouting direction: `main-dir`, of type `direction`. -/// - Cross layouting direction: `cross-dir`, of type `direction`. -/// - Background color of the box: `color`, of type `color`. +/// - Width of the box: `width`, of type `linear` relative to parent width. +/// - Height of the box: `height`, of type `linear` relative to parent height. +/// - Main layouting direction: `main-dir`, of type `direction`. +/// - Cross layouting direction: `cross-dir`, of type `direction`. +/// - Fill color of the box: `fill`, of type `color`. /// /// # Relevant types and constants /// - Type `direction` @@ -18,12 +18,12 @@ use super::*; /// - `rtl` (right to left) /// - `ttb` (top to bottom) /// - `btt` (bottom to top) -pub fn box_(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value { +pub fn rect(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value { let width = args.get(ctx, "width"); let height = args.get(ctx, "height"); let main = args.get(ctx, "main-dir"); let cross = args.get(ctx, "cross-dir"); - let color = args.get(ctx, "color"); + let fill = args.get(ctx, "fill"); let body = args.find::(ctx).unwrap_or_default(); Value::template("box", move |ctx| { @@ -33,7 +33,7 @@ pub fn box_(ctx: &mut EvalContext, args: &mut ValueArgs) -> Value { let child = ctx.exec(&body).into(); let fixed = NodeFixed { width, height, child }; - if let Some(color) = color { + if let Some(color) = fill { ctx.push(NodeBackground { fill: Fill::Color(color), child: fixed.into(), diff --git a/tests/ref/repr.png b/tests/ref/repr.png index 21d7af278..2f5697fd5 100644 Binary files a/tests/ref/repr.png and b/tests/ref/repr.png differ diff --git a/tests/typ/control/let.typ b/tests/typ/control/let.typ index 7752ec901..dd971ee5e 100644 --- a/tests/typ/control/let.typ +++ b/tests/typ/control/let.typ @@ -18,8 +18,8 @@ --- // Syntax sugar for function definitions. #let background = #239dad -#let box(body) = box(width: 2cm, height: 1cm, color: background, body) -#box[Hi!] +#let rect(body) = rect(width: 2cm, height: 1cm, fill: background, body) +#rect[Hi!] // Error: 13 expected body #let func(x) diff --git a/tests/typ/expand.typ b/tests/typ/expand.typ index 3b2429289..230447443 100644 --- a/tests/typ/expand.typ +++ b/tests/typ/expand.typ @@ -6,9 +6,9 @@ // Top-level paragraph fills page, boxed paragraph only when width is fixed. L #right[R] \ -#box(width: 50pt)[L #right[R]] \ -#box[L #right[R]] \ +#rect(width: 50pt)[L #right[R]] \ +#rect[L #right[R]] \ // Pad inherits expansion behaviour. #pad[PL #right[PR]] \ -#box(pad[PL #right[PR]]) +#rect(pad[PL #right[PR]]) diff --git a/tests/typ/expr/ops-invalid.typ b/tests/typ/expr/ops-invalid.typ index f760ae312..12d2a2c30 100644 --- a/tests/typ/expr/ops-invalid.typ +++ b/tests/typ/expr/ops-invalid.typ @@ -50,10 +50,10 @@ // Error: 3-4 unknown variable { z = 1 } -// Error: 3-6 cannot assign to a constant -{ box = "hi" } +// Error: 3-7 cannot assign to a constant +{ rect = "hi" } -// Works if we define box beforehand +// Works if we define rect beforehand // (since then it doesn't resolve to the standard library version anymore). -#let box = "" -{ box = "hi" } +#let rect = "" +{ rect = "hi" } diff --git a/tests/typ/full/coma.typ b/tests/typ/full/coma.typ index d324627f3..243c667f9 100644 --- a/tests/typ/full/coma.typ +++ b/tests/typ/full/coma.typ @@ -10,10 +10,10 @@ #let university = [*Technische Universität {city}*] #let faculty = [*Fakultät II, Institut for Mathematik*] -// The `box` function just places content into a rectangular container. When +// The `rect` function just places content into a rectangular container. When // the only argument to a function is a template, the parentheses can be omitted // (i.e. `f[a]` is the same as `f([a])`). -#box[ +#rect[ // Backslash adds a forced line break. #university \ #faculty \ @@ -21,7 +21,7 @@ Dr. Max Mustermann \ Ola Nordmann, John Doe ] -#align(right, box[*WiSe 2019/2020* \ Woche 3]) +#align(right, rect[*WiSe 2019/2020* \ Woche 3]) // Adds vertical spacing. #v(6mm) diff --git a/tests/typ/library/base.typ b/tests/typ/library/base.typ index 000a80ea3..29c976c2a 100644 --- a/tests/typ/library/base.typ +++ b/tests/typ/library/base.typ @@ -3,7 +3,7 @@ --- #test(type("hi"), "string") -#test(repr([Hi #box[there]]), "[Hi []]") +#test(repr([Hi #rect[there]]), "[Hi []]") --- // Check the output. diff --git a/tests/typ/library/pad.typ b/tests/typ/library/pad.typ index c8bfe907b..c3d3786ba 100644 --- a/tests/typ/library/pad.typ +++ b/tests/typ/library/pad.typ @@ -5,9 +5,9 @@ #pad(left: 10pt, [Indented!]) // All sides together. -#box(color: #9feb52, +#rect(fill: #9feb52, pad(10pt, right: 20pt, - box(color: #eb5278, width: 20pt, height: 20pt))) + rect(width: 20pt, height: 20pt, fill: #eb5278))) -// Error: 13-23 missing argument: body -Hi #box(pad(left: 10pt)) there +// Error: 14-24 missing argument: body +Hi #rect(pad(left: 10pt)) there diff --git a/tests/typ/library/shapes.typ b/tests/typ/library/shapes.typ index efb68edfd..c5a8abf95 100644 --- a/tests/typ/library/shapes.typ +++ b/tests/typ/library/shapes.typ @@ -1,31 +1,33 @@ // Test shapes. --- +// Test `rect` function. + #page("a8", flip: true) -// Box with fixed width, should have text height. -#box(width: 2cm, color: #9650D6)[Legal] +// Fixed width, should have text height. +#rect(width: 2cm, fill: #9650D6)[Legal] Sometimes there is no box. -// Box with fixed height, should span line. -#box(height: 1cm, width: 100%, color: #734CED)[B] +// Fixed height, should span line. +#rect(height: 1cm, width: 100%, fill: #734CED)[B] -// Empty box with fixed width and height. -#box(width: 6cm, height: 12pt, color: #CB4CED) +// Empty with fixed width and height. +#rect(width: 6cm, height: 12pt, fill: #CB4CED) // Not visible, but creates a gap between the boxes above and below. -#box(width: 2in, color: #ff0000) +#rect(width: 2in, fill: #ff0000) // These are in a row! -#box(width: 0.5in, height: 10pt, color: #D6CD67) -#box(width: 0.5in, height: 10pt, color: #EDD466) -#box(width: 0.5in, height: 10pt, color: #E3BE62) +#rect(width: 0.5in, height: 10pt, fill: #D6CD67) +#rect(width: 0.5in, height: 10pt, fill: #EDD466) +#rect(width: 0.5in, height: 10pt, fill: #E3BE62) --- -// Make sure that you can't do page related stuff in a box. +// Make sure that you can't do page related stuff in a shape. A -#box[ +#rect[ B // Error: 16 cannot modify page from here #pagebreak() diff --git a/tests/typ/markup/emph.typ b/tests/typ/markup/emph.typ index 772e15abf..500381c12 100644 --- a/tests/typ/markup/emph.typ +++ b/tests/typ/markup/emph.typ @@ -8,7 +8,7 @@ _Emphasized!_ Partly em_phas_ized. // Scoped to body. -#box[_Scoped] to body. +#rect[_Scoped] to body. // Unterminated is fine. _The End diff --git a/tests/typ/markup/heading.typ b/tests/typ/markup/heading.typ index 8497ec8f7..15c391d1b 100644 --- a/tests/typ/markup/heading.typ +++ b/tests/typ/markup/heading.typ @@ -21,7 +21,7 @@ } // Function call continues heading. -= #box[ += #rect[ A ] B @@ -35,7 +35,7 @@ B // Parsed as headings if at start of the context. /**/ = Ok {[== Ok]} -#box[=== Ok] +#rect[=== Ok] // Not at the start of the context. No = heading diff --git a/tests/typ/markup/strong.typ b/tests/typ/markup/strong.typ index b02a55a5c..a56e0e1cf 100644 --- a/tests/typ/markup/strong.typ +++ b/tests/typ/markup/strong.typ @@ -8,7 +8,7 @@ Partly str*ength*ened. // Scoped to body. -#box[*Scoped] to body. +#rect[*Scoped] to body. // Unterminated is fine. *The End diff --git a/tests/typ/repr.typ b/tests/typ/repr.typ index 96eb710ef..cf137745c 100644 --- a/tests/typ/repr.typ +++ b/tests/typ/repr.typ @@ -52,6 +52,6 @@ // Functions #let f(x) = x -{box} \ +{rect} \ {f} \ {() => none} \