feat: initial commit
This commit is contained in:
commit
b802ff49ab
454 files changed
+52429
No files matched your search
@@ -0,0 +1,88 @@
|
||||
# Align
|
||||
|
||||
# align
|
||||
|
||||
Aligns content horizontally and vertically.
|
||||
|
||||
## Example
|
||||
|
||||
Let's start with centering our content horizontally:
|
||||
|
||||
```typst
|
||||
#set page(height: 120pt)
|
||||
#set align(center)
|
||||
|
||||
Centered text, a sight to see \
|
||||
In perfect balance, visually \
|
||||
Not left nor right, it stands alone \
|
||||
A work of art, a visual throne
|
||||
```
|
||||
|
||||
To center something vertically, use _horizon_ alignment:
|
||||
|
||||
```typst
|
||||
#set page(height: 120pt)
|
||||
#set align(horizon)
|
||||
|
||||
Vertically centered, \
|
||||
the stage had entered, \
|
||||
a new paragraph.
|
||||
```
|
||||
|
||||
## Combining alignments
|
||||
|
||||
You can combine two alignments with the `+` operator. Let's also only apply this to one piece of content by using the function form instead of a set rule:
|
||||
|
||||
```typst
|
||||
#set page(height: 120pt)
|
||||
Though left in the beginning ...
|
||||
|
||||
#align(right + bottom)[
|
||||
... they were right in the end, \
|
||||
and with addition had gotten, \
|
||||
the paragraph to the bottom!
|
||||
]
|
||||
```
|
||||
|
||||
## Nested alignment
|
||||
|
||||
You can use varying alignments for layout containers and the elements within them. This way, you can create intricate layouts:
|
||||
|
||||
```typst
|
||||
#align(center, block[
|
||||
#set align(left)
|
||||
Though centered together \
|
||||
alone \
|
||||
we \
|
||||
are \
|
||||
left.
|
||||
])
|
||||
```
|
||||
|
||||
## Alignment within the same line
|
||||
|
||||
The `align` function performs block-level alignment and thus always interrupts the current paragraph. To have different alignment for parts of the same line, you should use [fractional spacing](/docs/reference/layout/h/) instead:
|
||||
|
||||
```typst
|
||||
Start #h(1fr) End
|
||||
```
|
||||
|
||||
```typst
|
||||
#align(
|
||||
alignment,
|
||||
body
|
||||
) -> content
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
- alignment:
|
||||
- description: The [alignment](/docs/reference/layout/alignment/) along both axes. ```typst #set page(height: 6cm) #set text(lang: "ar") مثال #align( end + horizon, rect(inset: 12pt)[ركن] ) ```
|
||||
- type: alignment
|
||||
- default: start + top
|
||||
- body:
|
||||
- description: The content to align.
|
||||
- type: content
|
||||
- default: None
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
# Alignment
|
||||
|
||||
Where to align something along an axis.
|
||||
|
||||
Possible values are:
|
||||
|
||||
- `start`: Aligns at the [start](/docs/reference/layout/direction/#definitions-start) of the [text direction](/docs/reference/text/text/#parameters-dir).
|
||||
- `end`: Aligns at the [end](/docs/reference/layout/direction/#definitions-end) of the [text direction](/docs/reference/text/text/#parameters-dir).
|
||||
- `left`: Align at the left.
|
||||
- `center`: Aligns in the middle, horizontally.
|
||||
- `right`: Aligns at the right.
|
||||
- `top`: Aligns at the top.
|
||||
- `horizon`: Aligns in the middle, vertically.
|
||||
- `bottom`: Align at the bottom.
|
||||
|
||||
These values are available globally and also in the alignment type's scope, so you can write either of the following two:
|
||||
|
||||
```typst
|
||||
#align(center)[Hi]
|
||||
#align(alignment.center)[Hi]
|
||||
```
|
||||
|
||||
## 2D alignments
|
||||
|
||||
To align along both axes at the same time, add the two alignments using the `+` operator. For example, `top + right` aligns the content to the top right corner.
|
||||
|
||||
```typst
|
||||
#set page(height: 3cm)
|
||||
#align(center + bottom)[Hi]
|
||||
```
|
||||
|
||||
## Fields
|
||||
|
||||
The `x` and `y` fields hold the alignment's horizontal and vertical components, respectively (as yet another `alignment`). They may be `none`.
|
||||
|
||||
```typst
|
||||
#(top + right).x \
|
||||
#left.x \
|
||||
#left.y (none)
|
||||
```
|
||||
|
||||
|
||||
## Methods
|
||||
|
||||
## alignment.axis
|
||||
|
||||
The axis this alignment belongs to.
|
||||
|
||||
- `"horizontal"` for `start`, `left`, `center`, `right`, and `end`
|
||||
- `"vertical"` for `top`, `horizon`, and `bottom`
|
||||
- `none` for 2-dimensional alignments
|
||||
|
||||
```typst
|
||||
#left.axis() \
|
||||
#bottom.axis()
|
||||
```
|
||||
|
||||
## alignment.inv
|
||||
|
||||
The inverse alignment.
|
||||
|
||||
```typst
|
||||
#top.inv() \
|
||||
#left.inv() \
|
||||
#center.inv() \
|
||||
#(left + bottom).inv()
|
||||
```
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
# Angle
|
||||
|
||||
An angle describing a rotation.
|
||||
|
||||
Typst supports the following angular units:
|
||||
|
||||
- Degrees: `180deg`
|
||||
- Radians: `3.14rad`
|
||||
|
||||
## Example
|
||||
|
||||
```typst
|
||||
#rotate(10deg)[Hello there!]
|
||||
```
|
||||
|
||||
|
||||
## Methods
|
||||
|
||||
## angle.rad
|
||||
|
||||
Converts this angle to radians.
|
||||
|
||||
## angle.deg
|
||||
|
||||
Converts this angle to degrees.
|
||||
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
# Block
|
||||
|
||||
# block
|
||||
|
||||
A block-level container.
|
||||
|
||||
Such a container can be used to separate content, size it, and give it a background or border.
|
||||
|
||||
Blocks are also the primary way to control whether text becomes part of a paragraph or not. See [the paragraph documentation](/docs/reference/model/par/#what-becomes-a-paragraph) for more details.
|
||||
|
||||
## Examples
|
||||
|
||||
With a block, you can give a background to content while still allowing it to break across multiple pages.
|
||||
|
||||
```typst
|
||||
#set page(height: 100pt)
|
||||
#block(
|
||||
fill: luma(230),
|
||||
inset: 8pt,
|
||||
radius: 4pt,
|
||||
lorem(30),
|
||||
)
|
||||
```
|
||||
|
||||
Blocks are also useful to force elements that would otherwise be inline to become block-level, especially when writing show rules.
|
||||
|
||||
```typst
|
||||
#show heading: it => it.body
|
||||
= Blockless
|
||||
More text.
|
||||
|
||||
#show heading: it => block(it.body)
|
||||
= Blocky
|
||||
More text.
|
||||
```
|
||||
|
||||
```typst
|
||||
#block(
|
||||
width: auto | relative,
|
||||
height: auto | relative | fraction,
|
||||
breakable: bool,
|
||||
fill: none | color | gradient | tiling,
|
||||
stroke: none | length | color | gradient | stroke | tiling | dictionary,
|
||||
radius: relative | dictionary,
|
||||
inset: relative | dictionary,
|
||||
outset: relative | dictionary,
|
||||
spacing: relative | fraction,
|
||||
above: auto | relative | fraction,
|
||||
below: auto | relative | fraction,
|
||||
clip: bool,
|
||||
sticky: bool,
|
||||
body
|
||||
) -> content
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
- width:
|
||||
- description: The block\'s width. ```typst #set align(center) #block( width: 60%, inset: 8pt, fill: silver, lorem(10), ) ```
|
||||
- type: auto | relative
|
||||
- default: auto
|
||||
- height:
|
||||
- description: The block\'s height. When the height is larger than the remaining space on a page and [`breakable`](/docs/reference/layout/block/#parameters-breakable) is `true`, the block will continue on the next page with the remaining height. ```typst #set page(height: 80pt) #set align(center) #block( width: 80%, height: 150%, fill: aqua, ) ```
|
||||
- type: auto | relative | fraction
|
||||
- default: auto
|
||||
- breakable:
|
||||
- description: Whether the block can be broken and continue on the next page. ```typst #set page(height: 80pt) The following block will jump to its own page. #block( breakable: false, lorem(15), ) ```
|
||||
- type: bool
|
||||
- default: true
|
||||
- fill:
|
||||
- description: The block\'s background color. See the [rectangle\'s documentation](/docs/reference/visualize/rect/#parameters-fill) for more details.
|
||||
- type: none | color | gradient | tiling
|
||||
- default: none
|
||||
- stroke:
|
||||
- description: The block\'s border color. See the [rectangle\'s documentation](/docs/reference/visualize/rect/#parameters-stroke) for more details.
|
||||
- type: none | length | color | gradient | stroke | tiling | dictionary
|
||||
- default: (:)
|
||||
- radius:
|
||||
- description: How much to round the block\'s corners. See the [rectangle\'s documentation](/docs/reference/visualize/rect/#parameters-radius) for more details.
|
||||
- type: relative | dictionary
|
||||
- default: (:)
|
||||
- inset:
|
||||
- description: How much to pad the block\'s content. See the [box\'s documentation](/docs/reference/layout/box/#parameters-inset) for more details.
|
||||
- type: relative | dictionary
|
||||
- default: (:)
|
||||
- outset:
|
||||
- description: How much to expand the block\'s size without affecting the layout. See the [box\'s documentation](/docs/reference/layout/box/#parameters-outset) for more details.
|
||||
- type: relative | dictionary
|
||||
- default: (:)
|
||||
- spacing:
|
||||
- description: The spacing around the block. When `auto`, inherits the paragraph [`spacing`](/docs/reference/model/par/#parameters-spacing). For two adjacent blocks, the larger of the first block\'s `above` and the second block\'s `below` spacing wins. Moreover, block spacing takes precedence over paragraph [`spacing`](/docs/reference/model/par/#parameters-spacing). Note that this is only a shorthand to set `above` and `below` to the same value. Since the values for `above` and `below` might differ, a [context](/docs/reference/context/) block only provides access to `block.above` and `block.below`, not to `block.spacing` directly. This property can be used in combination with a show rule to adjust the spacing around arbitrary block-level elements. ```typst #set align(center) #show math.equation: set block(above: 8pt, below: 16pt) This sum of $x$ and $y$: $ x + y = z $ A second paragraph. ```
|
||||
- type: relative | fraction
|
||||
- default: 1.2em
|
||||
- above:
|
||||
- description: The spacing between this block and its predecessor.
|
||||
- type: auto | relative | fraction
|
||||
- default: auto
|
||||
- below:
|
||||
- description: The spacing between this block and its successor.
|
||||
- type: auto | relative | fraction
|
||||
- default: auto
|
||||
- clip:
|
||||
- description: Whether to clip the content inside the block. Clipping is useful when the block\'s content is larger than the block itself, as any content that exceeds the block\'s bounds will be hidden. ```typst #block( width: 50pt, height: 50pt, clip: true, image("tiger.jpg", width: 100pt, height: 100pt) ) ```
|
||||
- type: bool
|
||||
- default: false
|
||||
- sticky:
|
||||
- description: Whether this block must stick to the following one, with no break in between. This is, by default, set on heading blocks to prevent orphaned headings at the bottom of the page. ```typst // Disable stickiness of headings. #show heading: set block(sticky: false) #lorem(20) = Chapter #lorem(10) ```
|
||||
- type: bool
|
||||
- default: false
|
||||
- body:
|
||||
- description: The contents of the block.
|
||||
- type: none | content
|
||||
- default: none
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
# Box
|
||||
|
||||
# box
|
||||
|
||||
An inline-level container that sizes content.
|
||||
|
||||
All elements except inline math, text, and boxes are block-level and cannot occur inside of a [paragraph](/docs/reference/model/par/). The box function can be used to integrate such elements into a paragraph. Boxes take the size of their contents by default but can also be sized explicitly.
|
||||
|
||||
## Example
|
||||
|
||||
```typst
|
||||
Refer to the docs
|
||||
#box(
|
||||
height: 9pt,
|
||||
image("docs.svg")
|
||||
)
|
||||
for more information.
|
||||
```
|
||||
|
||||
```typst
|
||||
#box(
|
||||
width: auto | relative | fraction,
|
||||
height: auto | relative,
|
||||
baseline: relative,
|
||||
fill: none | color | gradient | tiling,
|
||||
stroke: none | length | color | gradient | stroke | tiling | dictionary,
|
||||
radius: relative | dictionary,
|
||||
inset: relative | dictionary,
|
||||
outset: relative | dictionary,
|
||||
clip: bool,
|
||||
body
|
||||
) -> content
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
- width:
|
||||
- description: The width of the box. Boxes can have [fractional](/docs/reference/layout/fraction/) widths, as the example below demonstrates. _Note:_ Currently, only boxes and only their widths might be fractionally sized within paragraphs. Support for fractionally sized images, shapes, and more might be added in the future. ```typst Line in #box(width: 1fr, line(length: 100%)) between. ```
|
||||
- type: auto | relative | fraction
|
||||
- default: auto
|
||||
- height:
|
||||
- description: The height of the box.
|
||||
- type: auto | relative
|
||||
- default: auto
|
||||
- baseline:
|
||||
- description: An amount to shift the box\'s baseline by. ```typst Image: #box(baseline: 40%, image("tiger.jpg", width: 2cm)). ```
|
||||
- type: relative
|
||||
- default: 0 % + 0pt
|
||||
- fill:
|
||||
- description: The box\'s background color. See the [rectangle\'s documentation](/docs/reference/visualize/rect/#parameters-fill) for more details.
|
||||
- type: none | color | gradient | tiling
|
||||
- default: none
|
||||
- stroke:
|
||||
- description: The box\'s border color. See the [rectangle\'s documentation](/docs/reference/visualize/rect/#parameters-stroke) for more details.
|
||||
- type: none | length | color | gradient | stroke | tiling | dictionary
|
||||
- default: (:)
|
||||
- radius:
|
||||
- description: How much to round the box\'s corners. See the [rectangle\'s documentation](/docs/reference/visualize/rect/#parameters-radius) for more details.
|
||||
- type: relative | dictionary
|
||||
- default: (:)
|
||||
- inset:
|
||||
- description: How much to pad the box\'s content. This can be a single length for all sides or a dictionary of lengths for individual sides. When passing a dictionary, it can contain the following keys in order of precedence: `top`, `right`, `bottom`, `left` (controlling the respective cell sides), `x`, `y` (controlling vertical and horizontal insets), and `rest` (covers all insets not styled by other dictionary entries). All keys are optional; omitted keys will use their previously set value, or the default value if never set. [Relative lengths](/docs/reference/layout/relative/) for this parameter are relative to the box size excluding [outset](/docs/reference/layout/box/#parameters-outset). Note that relative insets and outsets are different from relative [widths](/docs/reference/layout/box/#parameters-width) and [heights](/docs/reference/layout/box/#parameters-height), which are relative to the container. _Note:_ When the box contains text, its exact size depends on the current [text edges](/docs/reference/text/text/#parameters-top-edge). ```typst #rect(inset: 0pt)[Tight] ```
|
||||
- type: relative | dictionary
|
||||
- default: (:)
|
||||
- outset:
|
||||
- description: How much to expand the box\'s size without affecting the layout. This can be a single length for all sides or a dictionary of lengths for individual sides. [Relative lengths](/docs/reference/layout/relative/) for this parameter are relative to the box size excluding outset. See the documentation for [inset](/docs/reference/layout/box/#parameters-inset) above for further details. This is useful to prevent padding from affecting line layout. For a generalized version of the example below, see the documentation for the [raw text\'s block parameter](/docs/reference/text/raw/#parameters-block). ```typst An inline #box( fill: luma(235), inset: (x: 3pt, y: 0pt), outset: (y: 3pt), radius: 2pt, )[rectangle]. ```
|
||||
- type: relative | dictionary
|
||||
- default: (:)
|
||||
- clip:
|
||||
- description: Whether to clip the content inside the box. Clipping is useful when the box\'s content is larger than the box itself, as any content that exceeds the box\'s bounds will be hidden. ```typst #box( width: 50pt, height: 50pt, clip: true, image("tiger.jpg", width: 100pt, height: 100pt) ) ```
|
||||
- type: bool
|
||||
- default: false
|
||||
- body:
|
||||
- description: The contents of the box.
|
||||
- type: none | content
|
||||
- default: none
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
# Column Break
|
||||
|
||||
# colbreak
|
||||
|
||||
Forces a column break.
|
||||
|
||||
The function will behave like a [page break](/docs/reference/layout/pagebreak/) when used in a single column layout or the last column on a page. Otherwise, content after the column break will be placed in the next column.
|
||||
|
||||
## Example
|
||||
|
||||
```typst
|
||||
#set page(columns: 2)
|
||||
Preliminary findings from our
|
||||
ongoing research project have
|
||||
revealed a hitherto unknown
|
||||
phenomenon of extraordinary
|
||||
significance.
|
||||
|
||||
#colbreak()
|
||||
Through rigorous experimentation
|
||||
and analysis, we have discovered
|
||||
a hitherto uncharacterized process
|
||||
that defies our current
|
||||
understanding of the fundamental
|
||||
laws of nature.
|
||||
```
|
||||
|
||||
```typst
|
||||
#colbreak(
|
||||
weak: bool
|
||||
) -> content
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
- weak:
|
||||
- description: If `true`, the column break is skipped if the current column is already empty.
|
||||
- type: bool
|
||||
- default: false
|
||||
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
# Columns
|
||||
|
||||
# columns
|
||||
|
||||
Separates a region into multiple equally sized columns.
|
||||
|
||||
The `column` function lets you separate the interior of any container into multiple columns. It will currently not balance the height of the columns. Instead, the columns will take up the height of their container or the remaining height on the page. Support for balanced columns is planned for the future.
|
||||
|
||||
When arranging content across multiple columns, use [`colbreak`](/docs/reference/layout/colbreak/) to explicitly continue in the next column.
|
||||
|
||||
## Example
|
||||
|
||||
```typst
|
||||
#columns(2, gutter: 8pt)[
|
||||
This text is in the
|
||||
first column.
|
||||
|
||||
#colbreak()
|
||||
|
||||
This text is in the
|
||||
second column.
|
||||
]
|
||||
```
|
||||
|
||||
## Page-level columns
|
||||
|
||||
If you need to insert columns across your whole document, use the `page` function's [`columns` parameter](/docs/reference/layout/page/#parameters-columns) instead. This will create the columns directly at the page-level rather than wrapping all of your content in a layout container. As a result, things like [pagebreaks](/docs/reference/layout/pagebreak/), [footnotes](/docs/reference/model/footnote/), and [line numbers](/docs/reference/model/par/#definitions-line) will continue to work as expected. For more information, also read the [relevant part of the page setup guide](/docs/guides/page-setup/#columns).
|
||||
|
||||
## Breaking out of columns
|
||||
|
||||
To temporarily break out of columns (e.g. for a paper's title), use parent-scoped floating placement:
|
||||
|
||||
```typst
|
||||
#set page(columns: 2, height: 150pt)
|
||||
|
||||
#place(
|
||||
top + center,
|
||||
scope: "parent",
|
||||
float: true,
|
||||
text(1.4em, weight: "bold")[
|
||||
My document
|
||||
],
|
||||
)
|
||||
|
||||
#lorem(40)
|
||||
```
|
||||
|
||||
```typst
|
||||
#columns(
|
||||
count,
|
||||
gutter: relative,
|
||||
body
|
||||
) -> content
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
- count:
|
||||
- description: The number of columns.
|
||||
- type: int
|
||||
- default: 2
|
||||
- gutter:
|
||||
- description: The size of the gutter space between each column.
|
||||
- type: relative
|
||||
- default: 4 % + 0pt
|
||||
- body:
|
||||
- description: The content that should be layouted into the columns.
|
||||
- type: content
|
||||
- default: None
|
||||
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
# Direction
|
||||
|
||||
The four directions into which content can be laid out.
|
||||
|
||||
Possible values are:
|
||||
|
||||
- `ltr`: Left to right.
|
||||
- `rtl`: Right to left.
|
||||
- `ttb`: Top to bottom.
|
||||
- `btt`: Bottom to top.
|
||||
|
||||
These values are available globally and also in the direction type's scope, so you can write either of the following two:
|
||||
|
||||
```typst
|
||||
#stack(dir: rtl)[A][B][C]
|
||||
#stack(dir: direction.rtl)[A][B][C]
|
||||
```
|
||||
|
||||
|
||||
## Methods
|
||||
|
||||
## direction.from
|
||||
|
||||
Returns a direction from a starting point.
|
||||
|
||||
```typst
|
||||
#direction.from(left) \
|
||||
#direction.from(right) \
|
||||
#direction.from(top) \
|
||||
#direction.from(bottom)
|
||||
```
|
||||
|
||||
```typst
|
||||
#direction.from(
|
||||
side
|
||||
) -> direction
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
- side:
|
||||
- description:
|
||||
- type: alignment
|
||||
- default: None
|
||||
|
||||
## direction.to
|
||||
|
||||
Returns a direction from an end point.
|
||||
|
||||
```typst
|
||||
#direction.to(left) \
|
||||
#direction.to(right) \
|
||||
#direction.to(top) \
|
||||
#direction.to(bottom)
|
||||
```
|
||||
|
||||
```typst
|
||||
#direction.to(
|
||||
side
|
||||
) -> direction
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
- side:
|
||||
- description:
|
||||
- type: alignment
|
||||
- default: None
|
||||
|
||||
## direction.axis
|
||||
|
||||
The axis this direction belongs to, either `"horizontal"` or `"vertical"`.
|
||||
|
||||
```typst
|
||||
#ltr.axis() \
|
||||
#ttb.axis()
|
||||
```
|
||||
|
||||
## direction.sign
|
||||
|
||||
The corresponding sign, for use in calculations.
|
||||
|
||||
```typst
|
||||
#ltr.sign() \
|
||||
#rtl.sign() \
|
||||
#ttb.sign() \
|
||||
#btt.sign()
|
||||
```
|
||||
|
||||
## direction.start
|
||||
|
||||
The start point of this direction, as an alignment.
|
||||
|
||||
```typst
|
||||
#ltr.start() \
|
||||
#rtl.start() \
|
||||
#ttb.start() \
|
||||
#btt.start()
|
||||
```
|
||||
|
||||
## direction.end
|
||||
|
||||
The end point of this direction, as an alignment.
|
||||
|
||||
```typst
|
||||
#ltr.end() \
|
||||
#rtl.end() \
|
||||
#ttb.end() \
|
||||
#btt.end()
|
||||
```
|
||||
|
||||
## direction.inv
|
||||
|
||||
The inverse direction.
|
||||
|
||||
```typst
|
||||
#ltr.inv() \
|
||||
#rtl.inv() \
|
||||
#ttb.inv() \
|
||||
#btt.inv()
|
||||
```
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
# Fraction
|
||||
|
||||
Defines how the remaining space in a layout is distributed.
|
||||
|
||||
Each fractionally sized element gets space based on the ratio of its fraction to the sum of all fractions.
|
||||
|
||||
For more details, also see the [h](/docs/reference/layout/h/) and [v](/docs/reference/layout/v/) functions and the [grid function](/docs/reference/layout/grid/).
|
||||
|
||||
## Example
|
||||
|
||||
```typst
|
||||
Left #h(1fr) Left-ish #h(2fr) Right
|
||||
```
|
||||
|
||||
|
||||
@@ -0,0 +1,399 @@
|
||||
# Grid
|
||||
|
||||
# grid
|
||||
|
||||
Arranges content in a grid.
|
||||
|
||||
The grid element allows you to arrange content in a grid. You can define the number of rows and columns, as well as the size of the gutters between them. There are multiple sizing modes for columns and rows that can be used to create complex layouts.
|
||||
|
||||
While the grid and table elements work very similarly, they are intended for different use cases and carry different semantics. The grid element is intended for presentational and layout purposes, while the [`table`](/docs/reference/model/table/) element is intended for, in broad terms, presenting multiple related data points. Set and show rules on one of these elements do not affect the other. Refer to the [Accessibility Section](/docs/reference/layout/grid/#accessibility) to learn how grids and tables are presented to users of Assistive Technology (AT) like screen readers.
|
||||
|
||||
## Sizing the tracks
|
||||
|
||||
A grid's sizing is determined by the track sizes specified in the arguments. There are multiple sizing parameters: [`columns`](/docs/reference/layout/grid/#parameters-columns), [`rows`](/docs/reference/layout/grid/#parameters-rows) and [`gutter`](/docs/reference/layout/grid/#parameters-gutter). Because each of the sizing parameters accepts the same values, we will explain them just once, here. Each sizing argument accepts an array of individual track sizes. A track size is either:
|
||||
|
||||
- `auto`: The track will be sized to fit its contents. It will be at most as large as the remaining space. If there is more than one `auto` track width, and together they claim more than the available space, the `auto` tracks will fairly distribute the available space among themselves.
|
||||
- A fixed or relative length (e.g. `10pt` or `20% - 1cm`): The track will be exactly of this size.
|
||||
- A fractional length (e.g. `1fr`): Once all other tracks have been sized, the remaining space will be divided among the fractional tracks according to their fractions. For example, if there are two fractional tracks, each with a fraction of `1fr`, they will each take up half of the remaining space.
|
||||
|
||||
To specify a single track, the array can be omitted in favor of a single value. To specify multiple `auto` tracks, enter the number of tracks instead of an array. For example, `columns:` `3` is equivalent to `columns:` `(auto, auto, auto)`.
|
||||
|
||||
## Examples
|
||||
|
||||
The example below demonstrates the different track sizing options. It also shows how you can use [`grid.cell`](/docs/reference/layout/grid/#definitions-cell) to make an individual cell span two grid tracks.
|
||||
|
||||
```typst
|
||||
// We use `rect` to emphasize the
|
||||
// area of cells.
|
||||
#set rect(
|
||||
inset: 8pt,
|
||||
fill: rgb("e4e5ea"),
|
||||
width: 100%,
|
||||
)
|
||||
|
||||
#grid(
|
||||
columns: (60pt, 1fr, 2fr),
|
||||
rows: (auto, 60pt),
|
||||
gutter: 3pt,
|
||||
rect[Fixed width, auto height],
|
||||
rect[1/3 of the remains],
|
||||
rect[2/3 of the remains],
|
||||
rect(height: 100%)[Fixed height],
|
||||
grid.cell(
|
||||
colspan: 2,
|
||||
image("tiger.jpg", width: 100%),
|
||||
),
|
||||
)
|
||||
```
|
||||
|
||||
You can also [spread](/docs/reference/foundations/arguments/#spreading) an array of strings or content into a grid to populate its cells.
|
||||
|
||||
```typst
|
||||
#grid(
|
||||
columns: 5,
|
||||
gutter: 5pt,
|
||||
..range(25).map(str)
|
||||
)
|
||||
```
|
||||
|
||||
## Styling the grid
|
||||
|
||||
The grid and table elements work similarly. For a hands-on explanation, refer to the [Table Guide](/docs/guides/tables/#fills); for a quick overview, continue reading.
|
||||
|
||||
The grid's appearance can be customized through different parameters. These are the most important ones:
|
||||
|
||||
- [`align`](/docs/reference/layout/grid/#parameters-align) to change how cells are aligned
|
||||
- [`inset`](/docs/reference/layout/grid/#parameters-inset) to optionally add internal padding to cells
|
||||
- [`fill`](/docs/reference/layout/grid/#parameters-fill) to give cells a background
|
||||
- [`stroke`](/docs/reference/layout/grid/#parameters-stroke) to optionally enable grid lines with a certain stroke
|
||||
|
||||
To meet different needs, there are various ways to set them.
|
||||
|
||||
If you need to override the above options for individual cells, you can use the [`grid.cell`](/docs/reference/layout/grid/#definitions-cell) element. Likewise, you can override individual grid lines with the [`grid.hline`](/docs/reference/layout/grid/#definitions-hline) and [`grid.vline`](/docs/reference/layout/grid/#definitions-vline) elements.
|
||||
|
||||
To configure an overall style for a grid, you may instead specify the option in any of the following fashions:
|
||||
|
||||
- As a single value that applies to all cells.
|
||||
- As an array of values corresponding to each column. The array will be cycled if there are more columns than the array has items.
|
||||
- As a function in the form of `(x, y) => value`. It receives the cell's column and row indices (both starting from zero) and should return the value to apply to that cell.
|
||||
|
||||
```typst
|
||||
#grid(
|
||||
columns: 5,
|
||||
|
||||
// By a single value
|
||||
align: center,
|
||||
// By a single but more complicated value
|
||||
inset: (x: 2pt, y: 3pt),
|
||||
// By an array of values (cycling)
|
||||
fill: (rgb("#239dad50"), none),
|
||||
// By a function that returns a value
|
||||
stroke: (x, y) => if calc.rem(x + y, 3) == 0 { 0.5pt },
|
||||
|
||||
..range(5 * 3).map(n => numbering("A", n + 1))
|
||||
)
|
||||
```
|
||||
|
||||
On top of that, you may [apply styling rules](/docs/reference/styling/) to [`grid`](/docs/reference/layout/grid/) and [`grid.cell`](/docs/reference/layout/grid/#definitions-cell). Especially, the [`x`](/docs/reference/layout/grid/#definitions-cell-x) and [`y`](/docs/reference/layout/grid/#definitions-cell-y) fields of `grid.cell` can be used in a [`where`](/docs/reference/foundations/function/#definitions-where) selector, making it possible to style cells at specific columns or rows, or individual positions.
|
||||
|
||||
### Stroke styling precedence
|
||||
|
||||
As explained above, there are three ways to set the stroke of a grid cell: through [`grid.cell`'s `stroke` field](/docs/reference/layout/grid/#definitions-cell-stroke), by using [`grid.hline`](/docs/reference/layout/grid/#definitions-hline) and [`grid.vline`](/docs/reference/layout/grid/#definitions-vline), or by setting the [`grid`'s `stroke` field](/docs/reference/layout/grid/#parameters-stroke). When multiple of these settings are present and conflict, the `hline` and `vline` settings take the highest precedence, followed by the `cell` settings, and finally the `grid` settings.
|
||||
|
||||
Furthermore, strokes of a repeated grid header or footer will take precedence over regular cell strokes.
|
||||
|
||||
## Accessibility
|
||||
|
||||
Grids do not carry any special semantics. Assistive Technology (AT) does not offer the ability to navigate two-dimensionally by cell in grids. If you want to present tabular data, use the [`table`](/docs/reference/model/table/) element instead.
|
||||
|
||||
AT will read the grid cells in their semantic order. Usually, this is the order in which you passed them to the grid. However, if you manually positioned them using [`grid.cell`'s `x` and `y` arguments](/docs/reference/layout/grid/#definitions-cell-x), cells will be read row by row, from left to right (in left-to-right documents). A cell will be read when its position is first reached.
|
||||
|
||||
```typst
|
||||
#grid(
|
||||
columns: auto | int | relative | fraction | array,
|
||||
rows: auto | int | relative | fraction | array,
|
||||
gutter: auto | int | relative | fraction | array,
|
||||
column-gutter: auto | int | relative | fraction | array,
|
||||
row-gutter: auto | int | relative | fraction | array,
|
||||
inset: relative | array | dictionary | function,
|
||||
align: auto | array | alignment | function,
|
||||
fill: none | color | gradient | array | tiling | function,
|
||||
stroke: none | length | color | gradient | array | stroke | tiling | dictionary | function,
|
||||
children
|
||||
) -> content
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
- columns:
|
||||
- description: The column sizes. Either specify a track size array or provide an integer to create a grid with that many `auto`-sized columns. Note that opposed to rows and gutters, providing a single track size will only ever create a single column. See the [track size section](#track-size) above for more details.
|
||||
- type: auto | int | relative | fraction | array
|
||||
- default: ()
|
||||
- rows:
|
||||
- description: The row sizes. If there are more cells than fit the defined rows, the last row is repeated until there are no more cells. See the [track size section](#track-size) above for more details.
|
||||
- type: auto | int | relative | fraction | array
|
||||
- default: ()
|
||||
- gutter:
|
||||
- description: The gaps between rows and columns. This is a shorthand to set [`column-gutter`](/docs/reference/layout/grid/#parameters-column-gutter) and [`row-gutter`](/docs/reference/layout/grid/#parameters-row-gutter) to the same value. If there are more gutters than defined sizes, the last gutter is repeated. See the [track size section](#track-size) above for more details.
|
||||
- type: auto | int | relative | fraction | array
|
||||
- default: ()
|
||||
- column-gutter:
|
||||
- description: The gaps between columns.
|
||||
- type: auto | int | relative | fraction | array
|
||||
- default: ()
|
||||
- row-gutter:
|
||||
- description: The gaps between rows.
|
||||
- type: auto | int | relative | fraction | array
|
||||
- default: ()
|
||||
- inset:
|
||||
- description: How much to pad the cells\' content. To specify a uniform inset for all cells, you can use a single length for all sides, or a dictionary of lengths for individual sides. See the [box\'s documentation](/docs/reference/layout/box/#parameters-inset) for more details. To specify varying inset for different cells, you can: - use a single inset for all cells - use an array of insets corresponding to each column - use a function that maps a cell\'s position to its inset See the [styling section](#styling) above for more details. In addition, you can find an example at the [`table.inset`](/docs/reference/model/table/#parameters-inset) parameter.
|
||||
- type: relative | array | dictionary | function
|
||||
- default: (:)
|
||||
- align:
|
||||
- description: How to align the cells\' content. If set to `auto`, the outer alignment is used. You can specify the alignment in any of the following fashions: - use a single alignment for all cells - use an array of alignments corresponding to each column - use a function that maps a cell\'s position to its alignment See the [styling section](#styling) above for details. In addition, you can find an example at the [`table.align`](/docs/reference/model/table/#parameters-align) parameter.
|
||||
- type: auto | array | alignment | function
|
||||
- default: auto
|
||||
- fill:
|
||||
- description: How to fill the cells. This can be: - a single color for all cells - an array of colors corresponding to each column - a function that maps a cell\'s position to its color Most notably, arrays and functions are useful for creating striped grids. See the [styling section](#styling) above for more details. ```typst #grid( fill: (x, y) => if calc.even(x + y) { luma(230) } else { white }, align: center + horizon, columns: 4, inset: 2pt, [X], [O], [X], [O], [O], [X], [O], [X], [X], [O], [X], [O], [O], [X], [O], [X], ) ```
|
||||
- type: none | color | gradient | array | tiling | function
|
||||
- default: none
|
||||
- stroke:
|
||||
- description: How to [stroke](/docs/reference/visualize/stroke/) the cells. Grids have no strokes by default, which can be changed by setting this option to the desired stroke. If it is necessary to place lines which can cross spacing between cells produced by the [`gutter`](/docs/reference/layout/grid/#parameters-gutter) option, or to override the stroke between multiple specific cells, consider specifying one or more of [`grid.hline`](/docs/reference/layout/grid/#definitions-hline) and [`grid.vline`](/docs/reference/layout/grid/#definitions-vline) alongside your grid cells. To specify the same stroke for all cells, you can use a single [stroke](/docs/reference/visualize/stroke/) for all sides, or a dictionary of [strokes](/docs/reference/visualize/stroke/) for individual sides. See the [rectangle\'s documentation](/docs/reference/visualize/rect/#parameters-stroke) for more details. To specify varying strokes for different cells, you can: - use a single stroke for all cells - use an array of strokes corresponding to each column - use a function that maps a cell\'s position to its stroke See the [styling section](#styling) above for more details. ```typst #set page(width: 420pt) #set text(number-type: "old-style") #show grid.cell.where(y: 0): set text(size: 1.3em) #grid( columns: (1fr, 2fr, 2fr), row-gutter: 1.5em, inset: (left: 0.5em), stroke: (x, y) => if x > 0 { (left: 0.5pt + gray) }, align: horizon, [Winter \\ 2007 \\ Season], [Aaron Copland \\ *The Tender Land* \\ January 2007], [Eric Satie \\ *Gymnopedie 1, 2* \\ February 2007], [], [Jan 12 \\ *Middlebury College \\ Center for the Arts* \\ 20:00], [Feb 2 \\ *Johnson State College Dibden Center for the Arts* \\ 19:30], [], [Skip a week \\ #text(0.8em)[_Prepare your exams!_]], [Feb 9 \\ *Castleton State College \\ Fine Arts Center* \\ 19:30], [], [Jan 26, 27 \\ *Lyndon State College Alexander Twilight Theater* \\ 20:00], [ Feb 17 --- #smallcaps[Anniversary] \\ *Middlebury College \\ Center for the Arts* \\ 19:00 #text(0.7em)[(for a special guest)] ], ) ``` ```typst #set page(height: 13em, width: 26em) #let cv(..jobs) = grid( columns: 2, inset: 5pt, stroke: (x, y) => if x == 0 and y > 0 { (right: ( paint: luma(180), thickness: 1.5pt, dash: "dotted", )) }, grid.header(grid.cell(colspan: 2)[ *Professional Experience* #box(width: 1fr, line(length: 100%, stroke: luma(180))) ]), ..{ let last = none for job in jobs.pos() { ( if job.year != last [*#job.year*], [ *#job.company* - #job.role _(#job.timeframe)_ \\ #job.details ] ) last = job.year } } ) #cv( ( year: 2012, company: [Pear Seed & Co.], role: [Lead Engineer], timeframe: [Jul - Dec], details: [ - Raised engineers from 3x to 10x - Did a great job ], ), ( year: 2012, company: [Mega Corp.], role: [VP of Sales], timeframe: [Mar - Jun], details: [- Closed tons of customers], ), ( year: 2013, company: [Tiny Co.], role: [CEO], timeframe: [Jan - Dec], details: [- Delivered 4x more shareholder value], ), ( year: 2014, company: [Glorbocorp Ltd], role: [CTO], timeframe: [Jan - Mar], details: [- Drove containerization forward], ), ) ```
|
||||
- type: none | length | color | gradient | array | stroke | tiling | dictionary | function
|
||||
- default: (:)
|
||||
- children:
|
||||
- description: The contents of the grid cells, plus any extra grid lines specified with the [`grid.hline`](/docs/reference/layout/grid/#definitions-hline) and [`grid.vline`](/docs/reference/layout/grid/#definitions-vline) elements. The cells are populated in row-major order.
|
||||
- type: content
|
||||
- default: None
|
||||
|
||||
|
||||
## Definitions
|
||||
### grid.cell
|
||||
|
||||
A cell in the grid. You can use this function in the argument list of a grid to override grid style properties for an individual cell or manually positioning it within the grid. You can also use this function in show rules to apply certain styles to multiple cells at once.
|
||||
|
||||
For example, you can override the position and stroke for a single cell:
|
||||
|
||||
```typst
|
||||
#set text(15pt, font: "Noto Sans Symbols 2")
|
||||
#show regex("[♚-♟︎]"): set text(fill: rgb("21212A"))
|
||||
#show regex("[♔-♙]"): set text(fill: rgb("111015"))
|
||||
|
||||
#grid(
|
||||
fill: (x, y) => rgb(
|
||||
if calc.odd(x + y) { "7F8396" }
|
||||
else { "EFF0F3" }
|
||||
),
|
||||
columns: (1em,) * 8,
|
||||
rows: 1em,
|
||||
align: center + horizon,
|
||||
|
||||
[♖], [♘], [♗], [♕], [♔], [♗], [♘], [♖],
|
||||
[♙], [♙], [♙], [♙], [], [♙], [♙], [♙],
|
||||
grid.cell(
|
||||
x: 4, y: 3,
|
||||
stroke: blue.transparentize(60%)
|
||||
)[♙],
|
||||
|
||||
..(grid.cell(y: 6)[♟],) * 8,
|
||||
..([♜], [♞], [♝], [♛], [♚], [♝], [♞], [♜])
|
||||
.map(grid.cell.with(y: 7)),
|
||||
)
|
||||
```
|
||||
|
||||
You may also apply a show rule on `grid.cell` to style all cells at once, which allows you, for example, to apply styles based on a cell's position. Refer to the examples of the [`table.cell`](/docs/reference/model/table/#definitions-cell) element to learn more about this.
|
||||
|
||||
```typst
|
||||
#grid.cell(
|
||||
body,
|
||||
x: auto | int,
|
||||
y: auto | int,
|
||||
colspan: int,
|
||||
rowspan: int,
|
||||
inset: auto | relative | dictionary,
|
||||
align: auto | alignment,
|
||||
fill: none | auto | color | gradient | tiling,
|
||||
stroke: none | length | color | gradient | stroke | tiling | dictionary,
|
||||
breakable: auto | bool
|
||||
) -> content
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
- body:
|
||||
- description: The cell\'s body.
|
||||
- type: content
|
||||
- default: None
|
||||
- x:
|
||||
- description: The cell\'s column (zero-indexed). This field may be used in show rules to style a cell depending on its column. You may override this field to pick in which column the cell must be placed. If no row (`y`) is chosen, the cell will be placed in the first row (starting at row 0) with that column available (or a new row if none). If both `x` and `y` are chosen, however, the cell will be placed in that exact position. An error is raised if that position is not available (thus, it is usually wise to specify cells with a custom position before cells with automatic positions). ```typst #let circ(c) = circle( fill: c, width: 5mm ) #grid( columns: 4, rows: 7mm, stroke: .5pt + blue, align: center + horizon, inset: 1mm, grid.cell(x: 2, y: 2, circ(aqua)), circ(yellow), grid.cell(x: 3, circ(green)), circ(black), ) ```
|
||||
- type: auto | int
|
||||
- default: auto
|
||||
- y:
|
||||
- description: The cell\'s row (zero-indexed). This field may be used in show rules to style a cell depending on its row. You may override this field to pick in which row the cell must be placed. If no column (`x`) is chosen, the cell will be placed in the first column (starting at column 0) available in the chosen row. If all columns in the chosen row are already occupied, an error is raised. ```typst #let tri(c) = polygon.regular( fill: c, size: 5mm, vertices: 3, ) #grid( columns: 2, stroke: blue, inset: 1mm, tri(black), grid.cell(y: 1, tri(teal)), grid.cell(y: 1, tri(red)), grid.cell(y: 2, tri(orange)) ) ```
|
||||
- type: auto | int
|
||||
- default: auto
|
||||
- colspan:
|
||||
- description: The amount of columns spanned by this cell.
|
||||
- type: int
|
||||
- default: 1
|
||||
- rowspan:
|
||||
- description: The amount of rows spanned by this cell.
|
||||
- type: int
|
||||
- default: 1
|
||||
- inset:
|
||||
- description: The cell\'s [inset](/docs/reference/layout/grid/#parameters-inset) override.
|
||||
- type: auto | relative | dictionary
|
||||
- default: auto
|
||||
- align:
|
||||
- description: The cell\'s [alignment](/docs/reference/layout/grid/#parameters-align) override.
|
||||
- type: auto | alignment
|
||||
- default: auto
|
||||
- fill:
|
||||
- description: The cell\'s [fill](/docs/reference/layout/grid/#parameters-fill) override.
|
||||
- type: none | auto | color | gradient | tiling
|
||||
- default: auto
|
||||
- stroke:
|
||||
- description: The cell\'s [stroke](/docs/reference/layout/grid/#parameters-stroke) override.
|
||||
- type: none | length | color | gradient | stroke | tiling | dictionary
|
||||
- default: (:)
|
||||
- breakable:
|
||||
- description: Whether rows spanned by this cell can be placed in different pages. When equal to `auto`, a cell spanning only fixed-size rows is unbreakable, while a cell spanning at least one `auto`-sized row is breakable.
|
||||
- type: auto | bool
|
||||
- default: auto
|
||||
|
||||
### grid.hline
|
||||
|
||||
A horizontal line in the grid.
|
||||
|
||||
Overrides any per-cell stroke, including stroke specified through the grid's `stroke` field. Can cross spacing between cells created through the grid's `column-gutter` option.
|
||||
|
||||
An example for this function can be found at the [`table.hline`](/docs/reference/model/table/#definitions-hline) element.
|
||||
|
||||
```typst
|
||||
#grid.hline(
|
||||
y: auto | int,
|
||||
start: int,
|
||||
end: none | int,
|
||||
stroke: none | length | color | gradient | stroke | tiling | dictionary,
|
||||
position: alignment
|
||||
) -> content
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
- y:
|
||||
- description: The row above which the horizontal line is placed (zero-indexed). If the `position` field is set to `bottom`, the line is placed below the row with the given index instead (see [`grid.hline.position`](/docs/reference/layout/grid/#definitions-hline-position) for details). Specifying `auto` causes the line to be placed at the row below the last automatically positioned cell (that is, cell without coordinate overrides) before the line among the grid\'s children. If there is no such cell before the line, it is placed at the top of the grid (row 0). Note that specifying for this option exactly the total amount of rows in the grid causes this horizontal line to override the bottom border of the grid, while a value of 0 overrides the top border.
|
||||
- type: auto | int
|
||||
- default: auto
|
||||
- start:
|
||||
- description: The column at which the horizontal line starts (zero-indexed, inclusive).
|
||||
- type: int
|
||||
- default: 0
|
||||
- end:
|
||||
- description: The column before which the horizontal line ends (zero-indexed, exclusive). Therefore, the horizontal line will be drawn up to and across column `end - 1`. A value equal to `none` or to the amount of columns causes it to extend all the way towards the end of the grid.
|
||||
- type: none | int
|
||||
- default: none
|
||||
- stroke:
|
||||
- description: The line\'s stroke. Specifying `none` removes any lines previously placed across this line\'s range, including hlines or per-cell stroke below it.
|
||||
- type: none | length | color | gradient | stroke | tiling | dictionary
|
||||
- default: 1pt + black
|
||||
- position:
|
||||
- description: The position at which the line is placed, given its row (`y`) - either `top` to draw above it or `bottom` to draw below it. This setting is only relevant when row gutter is enabled (and shouldn\'t be used otherwise - prefer just increasing the `y` field by one instead), since then the position below a row becomes different from the position above the next row due to the spacing between both.
|
||||
- type: alignment
|
||||
- default: top
|
||||
|
||||
### grid.vline
|
||||
|
||||
A vertical line in the grid.
|
||||
|
||||
Overrides any per-cell stroke, including stroke specified through the grid's `stroke` field. Can cross spacing between cells created through the grid's `row-gutter` option.
|
||||
|
||||
```typst
|
||||
#grid.vline(
|
||||
x: auto | int,
|
||||
start: int,
|
||||
end: none | int,
|
||||
stroke: none | length | color | gradient | stroke | tiling | dictionary,
|
||||
position: alignment
|
||||
) -> content
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
- x:
|
||||
- description: The column before which the vertical line is placed (zero-indexed). If the `position` field is set to `end`, the line is placed after the column with the given index instead (see [`grid.vline.position`](/docs/reference/layout/grid/#definitions-vline-position) for details). Specifying `auto` causes the line to be placed at the column after the last automatically positioned cell (that is, cell without coordinate overrides) before the line among the grid\'s children. If there is no such cell before the line, it is placed before the grid\'s first column (column 0). Note that specifying for this option exactly the total amount of columns in the grid causes this vertical line to override the end border of the grid (right in LTR, left in RTL), while a value of 0 overrides the start border (left in LTR, right in RTL).
|
||||
- type: auto | int
|
||||
- default: auto
|
||||
- start:
|
||||
- description: The row at which the vertical line starts (zero-indexed, inclusive).
|
||||
- type: int
|
||||
- default: 0
|
||||
- end:
|
||||
- description: The row on top of which the vertical line ends (zero-indexed, exclusive). Therefore, the vertical line will be drawn up to and across row `end - 1`. A value equal to `none` or to the amount of rows causes it to extend all the way towards the bottom of the grid.
|
||||
- type: none | int
|
||||
- default: none
|
||||
- stroke:
|
||||
- description: The line\'s stroke. Specifying `none` removes any lines previously placed across this line\'s range, including vlines or per-cell stroke below it.
|
||||
- type: none | length | color | gradient | stroke | tiling | dictionary
|
||||
- default: 1pt + black
|
||||
- position:
|
||||
- description: The position at which the line is placed, given its column (`x`) - either `start` to draw before it or `end` to draw after it. The values `left` and `right` are also accepted, but discouraged as they cause your grid to be inconsistent between left-to-right and right-to-left documents. This setting is only relevant when column gutter is enabled (and shouldn\'t be used otherwise - prefer just increasing the `x` field by one instead), since then the position after a column becomes different from the position before the next column due to the spacing between both.
|
||||
- type: alignment
|
||||
- default: start
|
||||
|
||||
### grid.header
|
||||
|
||||
A repeatable grid header.
|
||||
|
||||
If `repeat` is set to `true`, the header will be repeated across pages. For an example, refer to the [`table.header`](/docs/reference/model/table/#definitions-header) element and the [`grid.stroke`](/docs/reference/layout/grid/#parameters-stroke) parameter.
|
||||
|
||||
```typst
|
||||
#grid.header(
|
||||
repeat: bool,
|
||||
level: int,
|
||||
children
|
||||
) -> content
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
- repeat:
|
||||
- description: Whether this header should be repeated across pages.
|
||||
- type: bool
|
||||
- default: true
|
||||
- level:
|
||||
- description: The level of the header. Must not be zero. This allows repeating multiple headers at once. Headers with different levels can repeat together, as long as they have ascending levels. Notably, when a header with a lower level starts repeating, all higher or equal level headers stop repeating (they are "replaced" by the new header).
|
||||
- type: int
|
||||
- default: 1
|
||||
- children:
|
||||
- description: The cells and lines within the header.
|
||||
- type: content
|
||||
- default: None
|
||||
|
||||
### grid.footer
|
||||
|
||||
A repeatable grid footer.
|
||||
|
||||
Just like the [`grid.header`](/docs/reference/layout/grid/#definitions-header) element, the footer can repeat itself on every page of the grid.
|
||||
|
||||
No other grid cells may be placed after the footer.
|
||||
|
||||
```typst
|
||||
#grid.footer(
|
||||
repeat: bool,
|
||||
children
|
||||
) -> content
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
|
||||
- repeat:
|
||||
- description: Whether this footer should be repeated across pages.
|
||||
- type: bool
|
||||
- default: true
|
||||
- children:
|
||||
- description: The cells and lines within the footer.
|
||||
- type: content
|
||||
- default: None
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
# Spacing (H)
|
||||
|
||||
# h
|
||||
|
||||
Inserts horizontal spacing into a paragraph.
|
||||
|
||||
The spacing can be absolute, relative, or fractional. In the last case, the remaining space on the line is distributed among all fractional spacings according to their relative fractions.
|
||||
|
||||
## Example
|
||||
|
||||
```typst
|
||||
First #h(1cm) Second \
|
||||
First #h(30%) Second
|
||||
```
|
||||
|
||||
## Fractional spacing
|
||||
|
||||
With fractional spacing, you can align things within a line without forcing a paragraph break (like [`align`](/docs/reference/layout/align/) would). Each fractionally sized element gets space based on the ratio of its fraction to the sum of all fractions.
|
||||
|
||||
```typst
|
||||
First #h(1fr) Second \
|
||||
First #h(1fr) Second #h(1fr) Third \
|
||||
First #h(2fr) Second #h(1fr) Third
|
||||
```
|
||||
|
||||
## Mathematical Spacing
|
||||
|
||||
In [mathematical formulas](/docs/reference/math/), you can additionally use these constants to add spacing between elements: `thin` (1/6 em), `med` (2/9 em), `thick` (5/18 em), `quad` (1 em), `wide` (2 em).
|
||||
|
||||
```typst
|
||||
#h(
|
||||
amount,
|
||||
weak: bool
|
||||
) -> content
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
- amount:
|
||||
- description: How much spacing to insert.
|
||||
- type: relative | fraction
|
||||
- default: None
|
||||
- weak:
|
||||
- description: If `true`, the spacing collapses at the start or end of a paragraph. Moreover, from multiple adjacent weak spacings all but the largest one collapse. Weak spacing in markup also causes all adjacent markup spaces to be removed, regardless of the amount of spacing inserted. To force a space next to weak spacing, you can explicitly write `#" "` (for a normal space) or `~` (for a non-breaking space). The latter can be useful to create a construct that always attaches to the preceding word with one non-breaking space, independently of whether a markup space existed in front or not. ```typst #h(1cm, weak: true) We identified a group of _weak_ specimens that fail to manifest in most cases. However, when #h(8pt, weak: true) supported #h(8pt, weak: true) on both sides, they do show up. Further #h(0pt, weak: true) more, even the smallest of them swallow adjacent markup spaces. ```
|
||||
- type: bool
|
||||
- default: false
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
# Hide
|
||||
|
||||
# hide
|
||||
|
||||
Hides content without affecting layout.
|
||||
|
||||
The `hide` function allows you to hide content while the layout still "sees" it. This is useful for creating blank space that is exactly as large as some content.
|
||||
|
||||
## Example
|
||||
|
||||
```typst
|
||||
Hello Jane \
|
||||
#hide[Hello] Joe
|
||||
```
|
||||
|
||||
## Redaction
|
||||
|
||||
This function may also be useful for redacting content as its arguments are neither present visually nor accessible to Assistive Technology. That said, there can be _some_ traces of the hidden content (such as a bookmarked heading in the PDF's Document Outline).
|
||||
|
||||
Note that, depending on the circumstances, it may be possible for content to be reverse engineered based on its size in the layout. We thus do not recommend using this function to hide highly sensitive information.
|
||||
|
||||
```typst
|
||||
#hide(
|
||||
body
|
||||
) -> content
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
- body:
|
||||
- description: The content to hide.
|
||||
- type: content
|
||||
- default: None
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
# Layout
|
||||
|
||||
Arranging elements on the page in different ways.
|
||||
|
||||
By combining layout functions, you can create complex and automatic layouts.
|
||||
|
||||
## Definitions
|
||||
|
||||
| Name | Description |
|
||||
| --- | --- |
|
||||
| [`align`](/reference/layout/align/) | Aligns content horizontally and vertically. |
|
||||
| [`alignment`](/reference/layout/alignment/) | Where to align something along an axis. |
|
||||
| [`angle`](/reference/layout/angle/) | An angle describing a rotation. |
|
||||
| [`block`](/reference/layout/block/) | A block-level container. |
|
||||
| [`box`](/reference/layout/box/) | An inline-level container that sizes content. |
|
||||
| [`colbreak`](/reference/layout/colbreak/) | Forces a column break. |
|
||||
| [`columns`](/reference/layout/columns/) | Separates a region into multiple equally sized columns. |
|
||||
| [`direction`](/reference/layout/direction/) | The four directions into which content can be laid out. |
|
||||
| [`fraction`](/reference/layout/fraction/) | Defines how the remaining space in a layout is distributed. |
|
||||
| [`grid`](/reference/layout/grid/) | Arranges content in a grid. |
|
||||
| [`h`](/reference/layout/h/) | Inserts horizontal spacing into a paragraph. |
|
||||
| [`hide`](/reference/layout/hide/) | Hides content without affecting layout. |
|
||||
| [`layout`](/reference/layout/layout/) | Provides access to the current outer container's (or page's, if none) dimensions (width and height). |
|
||||
| [`length`](/reference/layout/length/) | A size or distance, possibly expressed with contextual units. |
|
||||
| [`measure`](/reference/layout/measure/) | Measures the layouted size of content. |
|
||||
| [`move`](/reference/layout/move/) | Moves content without affecting layout. |
|
||||
| [`pad`](/reference/layout/pad/) | Adds spacing around content. |
|
||||
| [`page`](/reference/layout/page/) | Layouts its child onto one or multiple pages. |
|
||||
| [`pagebreak`](/reference/layout/pagebreak/) | A manual page break. |
|
||||
| [`place`](/reference/layout/place/) | Places content relatively to its parent container. |
|
||||
| [`ratio`](/reference/layout/ratio/) | A ratio of a whole. |
|
||||
| [`relative`](/reference/layout/relative/) | A length in relation to some known length. |
|
||||
| [`repeat`](/reference/layout/repeat/) | Repeats content to the available space. |
|
||||
| [`rotate`](/reference/layout/rotate/) | Rotates content without affecting layout. |
|
||||
| [`scale`](/reference/layout/scale/) | Scales content without affecting layout. |
|
||||
| [`skew`](/reference/layout/skew/) | Skews content. |
|
||||
| [`stack`](/reference/layout/stack/) | Arranges content and spacing horizontally or vertically. |
|
||||
| [`v`](/reference/layout/v/) | Inserts vertical spacing into a flow of blocks. |
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
# Layout
|
||||
|
||||
# layout
|
||||
|
||||
Provides access to the current outer container's (or page's, if none) dimensions (width and height).
|
||||
|
||||
Accepts a function that receives a single parameter, which is a dictionary with keys `width` and `height`, both of type [`length`](/docs/reference/layout/length/). The function is provided [context](/docs/reference/context/), meaning you don't need to use it in combination with the `context` keyword. This is why [`measure`](/docs/reference/layout/measure/) can be called in the example below.
|
||||
|
||||
```typst
|
||||
#let text = lorem(30)
|
||||
#layout(size => [
|
||||
#let (height,) = measure(
|
||||
width: size.width,
|
||||
text,
|
||||
)
|
||||
This text is #height high with
|
||||
the current page width: \
|
||||
#text
|
||||
])
|
||||
```
|
||||
|
||||
Note that the `layout` function forces its contents into a [block](/docs/reference/layout/block/)-level container, so placement relative to the page or pagebreaks are not possible within it.
|
||||
|
||||
If the `layout` call is placed inside a box with a width of `800pt` and a height of `400pt`, then the specified function will be given the argument `(width: 800pt, height: 400pt)`. If it is placed directly into the page, it receives the page's dimensions minus its margins. This is mostly useful in combination with [measurement](/docs/reference/layout/measure/).
|
||||
|
||||
To retrieve the _remaining_ height of the page rather than its full size, you can wrap your `layout` call in a `block(height: 1fr)`. This works because the block automatically grows to fill the remaining space (see the [fraction](/docs/reference/layout/fraction/) documentation for more details).
|
||||
|
||||
```typst
|
||||
#set page(height: 150pt)
|
||||
|
||||
#lorem(20)
|
||||
|
||||
#block(height: 1fr, layout(size => [
|
||||
Remaining height: #size.height
|
||||
]))
|
||||
```
|
||||
|
||||
You can also use this function to resolve a [`ratio`](/docs/reference/layout/ratio/) to a fixed length. This might come in handy if you're building your own layout abstractions.
|
||||
|
||||
```typst
|
||||
#layout(size => {
|
||||
let half = 50% * size.width
|
||||
[Half a page is #half wide.]
|
||||
})
|
||||
```
|
||||
|
||||
Note that the width or height provided by `layout` will be infinite if the corresponding page dimension is set to `auto`.
|
||||
|
||||
```typst
|
||||
#layout(
|
||||
func
|
||||
) -> content
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
- func:
|
||||
- description: A function to call with the outer container\'s size. Its return value is displayed in the document. The container\'s size is given as a [dictionary](/docs/reference/foundations/dictionary/) with the keys `width` and `height`, both of type [`length`](/docs/reference/layout/length/). This function is called once for each time the content returned by `layout` appears in the document. This makes it possible to generate content that depends on the dimensions of its container.
|
||||
- type: function
|
||||
- default: None
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
# Length
|
||||
|
||||
A size or distance, possibly expressed with contextual units.
|
||||
|
||||
Typst supports the following length units:
|
||||
|
||||
- Points: `72pt`
|
||||
- Millimeters: `254mm`
|
||||
- Centimeters: `2.54cm`
|
||||
- Inches: `1in`
|
||||
- Relative to font size: `2.5em`
|
||||
|
||||
You can multiply lengths with and divide them by integers and floats.
|
||||
|
||||
## Example
|
||||
|
||||
```typst
|
||||
#rect(width: 20pt)
|
||||
#rect(width: 2em)
|
||||
#rect(width: 1in)
|
||||
|
||||
#(3em + 5pt).em \
|
||||
#(20pt).em \
|
||||
#(40em + 2pt).abs \
|
||||
#(5em).abs
|
||||
```
|
||||
|
||||
## Fields
|
||||
|
||||
- `abs`: A length with just the absolute component of the current length (that is, excluding the `em` component).
|
||||
- `em`: The amount of `em` units in this length, as a [float](/docs/reference/foundations/float/).
|
||||
|
||||
|
||||
## Methods
|
||||
|
||||
## length.pt
|
||||
|
||||
Converts this length to points.
|
||||
|
||||
Fails with an error if this length has non-zero `em` units (such as `5em + 2pt` instead of just `2pt`). Use the `abs` field (such as in `(5em + 2pt).abs.pt()`) to ignore the `em` component of the length (thus converting only its absolute component).
|
||||
|
||||
## length.mm
|
||||
|
||||
Converts this length to millimeters.
|
||||
|
||||
Fails with an error if this length has non-zero `em` units. See the [`pt`](/docs/reference/layout/length/#definitions-pt) method for more details.
|
||||
|
||||
## length.cm
|
||||
|
||||
Converts this length to centimeters.
|
||||
|
||||
Fails with an error if this length has non-zero `em` units. See the [`pt`](/docs/reference/layout/length/#definitions-pt) method for more details.
|
||||
|
||||
## length.inches
|
||||
|
||||
Converts this length to inches.
|
||||
|
||||
Fails with an error if this length has non-zero `em` units. See the [`pt`](/docs/reference/layout/length/#definitions-pt) method for more details.
|
||||
|
||||
## length.to-absolute
|
||||
|
||||
Resolve this length to an absolute length.
|
||||
|
||||
```typst
|
||||
#set text(size: 12pt)
|
||||
#context [
|
||||
#(6pt).to-absolute() \
|
||||
#(6pt + 10em).to-absolute() \
|
||||
#(10em).to-absolute()
|
||||
]
|
||||
|
||||
#set text(size: 6pt)
|
||||
#context [
|
||||
#(6pt).to-absolute() \
|
||||
#(6pt + 10em).to-absolute() \
|
||||
#(10em).to-absolute()
|
||||
]
|
||||
```
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
# Measure
|
||||
|
||||
# measure
|
||||
|
||||
Measures the layouted size of content.
|
||||
|
||||
The `measure` function lets you determine the layouted size of content. By default an infinite space is assumed, so the measured dimensions may not necessarily match the final dimensions of the content. If you want to measure in the current layout dimensions, you can combine `measure` and [`layout`](/docs/reference/layout/layout/).
|
||||
|
||||
## Example
|
||||
|
||||
The same content can have a different size depending on the [context](/docs/reference/context/) that it is placed into. In the example below, the `#content` is of course bigger when we increase the font size.
|
||||
|
||||
```typst
|
||||
#let content = [Hello!]
|
||||
#content
|
||||
#set text(14pt)
|
||||
#content
|
||||
```
|
||||
|
||||
For this reason, you can only measure when context is available.
|
||||
|
||||
```typst
|
||||
#let thing(body) = context {
|
||||
let size = measure(body)
|
||||
[Width of "#body" is #size.width]
|
||||
}
|
||||
|
||||
#thing[Hey] \
|
||||
#thing[Welcome]
|
||||
```
|
||||
|
||||
The measure function returns a dictionary with the entries `width` and `height`, both of type [`length`](/docs/reference/layout/length/).
|
||||
|
||||
```typst
|
||||
#measure(
|
||||
width: auto | length,
|
||||
height: auto | length,
|
||||
content
|
||||
) -> dictionary
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
- width:
|
||||
- description: The width available to layout the content. Setting this to `auto` indicates infinite available width. Note that using the `width` and `height` parameters of this function is different from measuring a sized [`block`](/docs/reference/layout/block/) containing the content. In the following example, the former will get the dimensions of the inner content instead of the dimensions of the block. ```typst #context measure(lorem(100), width: 400pt) #context measure(block(lorem(100), width: 400pt)) ```
|
||||
- type: auto | length
|
||||
- default: auto
|
||||
- height:
|
||||
- description: The height available to layout the content. Setting this to `auto` indicates infinite available height.
|
||||
- type: auto | length
|
||||
- default: auto
|
||||
- content:
|
||||
- description: The content whose size to measure.
|
||||
- type: content
|
||||
- default: None
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
# Move
|
||||
|
||||
# move
|
||||
|
||||
Moves content without affecting layout.
|
||||
|
||||
The `move` function allows you to move content while the layout still 'sees' it at the original positions. Containers will still be sized as if the content was not moved.
|
||||
|
||||
## Example
|
||||
|
||||
```typst
|
||||
#rect(inset: 0pt, fill: gray, move(
|
||||
dx: 4pt, dy: 6pt,
|
||||
rect(
|
||||
inset: 8pt,
|
||||
fill: white,
|
||||
stroke: black,
|
||||
[Abra cadabra]
|
||||
)
|
||||
))
|
||||
```
|
||||
|
||||
## Accessibility
|
||||
|
||||
Moving is transparent to Assistive Technology (AT). Your content will be read in the order it appears in the source, regardless of any visual movement. If you need to hide content from AT altogether in PDF export, consider using [`pdf.artifact`](/docs/reference/pdf/artifact/).
|
||||
|
||||
```typst
|
||||
#move(
|
||||
dx: relative,
|
||||
dy: relative,
|
||||
body
|
||||
) -> content
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
- dx:
|
||||
- description: The horizontal displacement of the content.
|
||||
- type: relative
|
||||
- default: 0 % + 0pt
|
||||
- dy:
|
||||
- description: The vertical displacement of the content.
|
||||
- type: relative
|
||||
- default: 0 % + 0pt
|
||||
- body:
|
||||
- description: The content to move.
|
||||
- type: content
|
||||
- default: None
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
# Padding
|
||||
|
||||
# pad
|
||||
|
||||
Adds spacing around content.
|
||||
|
||||
The spacing can be specified for each side individually, or for all sides at once by specifying a positional argument.
|
||||
|
||||
## Example
|
||||
|
||||
```typst
|
||||
#set align(center)
|
||||
|
||||
#pad(x: 16pt, image("typing.jpg"))
|
||||
_Typing speeds can be
|
||||
measured in words per minute._
|
||||
```
|
||||
|
||||
```typst
|
||||
#pad(
|
||||
left: relative,
|
||||
top: relative,
|
||||
right: relative,
|
||||
bottom: relative,
|
||||
x: relative,
|
||||
y: relative,
|
||||
rest: relative,
|
||||
body
|
||||
) -> content
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
- left:
|
||||
- description: The padding at the left side.
|
||||
- type: relative
|
||||
- default: 0 % + 0pt
|
||||
- top:
|
||||
- description: The padding at the top side.
|
||||
- type: relative
|
||||
- default: 0 % + 0pt
|
||||
- right:
|
||||
- description: The padding at the right side.
|
||||
- type: relative
|
||||
- default: 0 % + 0pt
|
||||
- bottom:
|
||||
- description: The padding at the bottom side.
|
||||
- type: relative
|
||||
- default: 0 % + 0pt
|
||||
- x:
|
||||
- description: A shorthand to set `left` and `right` to the same value.
|
||||
- type: relative
|
||||
- default: 0 % + 0pt
|
||||
- y:
|
||||
- description: A shorthand to set `top` and `bottom` to the same value.
|
||||
- type: relative
|
||||
- default: 0 % + 0pt
|
||||
- rest:
|
||||
- description: A shorthand to set all four sides to the same value.
|
||||
- type: relative
|
||||
- default: 0 % + 0pt
|
||||
- body:
|
||||
- description: The content to pad at the sides.
|
||||
- type: content
|
||||
- default: None
|
||||
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
# Page
|
||||
|
||||
# page
|
||||
|
||||
Layouts its child onto one or multiple pages.
|
||||
|
||||
Although this function is primarily used in set rules to affect page properties, it can also be used to explicitly render its argument onto a set of pages of its own.
|
||||
|
||||
Pages can be set to use `auto` as their width or height. In this case, the pages will grow to fit their content on the respective axis.
|
||||
|
||||
The [Guide for Page Setup](/docs/guides/page-setup/) explains how to use this and related functions to set up a document with many examples.
|
||||
|
||||
## Example
|
||||
|
||||
```typst
|
||||
#set page("us-letter")
|
||||
|
||||
There you go, US friends!
|
||||
```
|
||||
|
||||
## Accessibility
|
||||
|
||||
The contents of the page's header, footer, foreground, and background are invisible to Assistive Technology (AT) like screen readers. Only the body of the page is read by AT. Do not include vital information not included elsewhere in the document in these areas.
|
||||
|
||||
```typst
|
||||
#page(
|
||||
paper: str,
|
||||
width: auto | length,
|
||||
height: auto | length,
|
||||
flipped: bool,
|
||||
margin: auto | relative | dictionary,
|
||||
binding: auto | alignment,
|
||||
columns: int,
|
||||
fill: none | auto | color | gradient | tiling,
|
||||
numbering: none | str | function,
|
||||
supplement: none | auto | content,
|
||||
number-align: alignment,
|
||||
header: none | auto | content,
|
||||
header-ascent: relative,
|
||||
footer: none | auto | content,
|
||||
footer-descent: relative,
|
||||
background: none | content,
|
||||
foreground: none | content,
|
||||
body: content
|
||||
) -> content
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
- paper:
|
||||
- description: A standard paper size to set width and height. This is just a shorthand for setting `width` and `height` and, as such, cannot be retrieved in a context expression.
|
||||
- type: str
|
||||
- default: "a4"
|
||||
- width:
|
||||
- description: The width of the page. ```typst #set page( width: 3cm, margin: (x: 0cm), ) #for i in range(3) { box(square(width: 1cm)) } ```
|
||||
- type: auto | length
|
||||
- default: 595.28pt
|
||||
- height:
|
||||
- description: The height of the page. If this is set to `auto`, page breaks can only be triggered manually by inserting a [page break](/docs/reference/layout/pagebreak/) or by adding another non-empty page set rule. Most examples throughout this documentation use `auto` for the height of the page to dynamically grow and shrink to fit their content.
|
||||
- type: auto | length
|
||||
- default: 841.89pt
|
||||
- flipped:
|
||||
- description: Whether the page is flipped into landscape orientation. ```typst #set page( "us-business-card", flipped: true, fill: rgb("f2e5dd"), ) #set align(bottom + end) #text(14pt)[*Sam H. Richards*] \\ _Procurement Manager_ #set text(10pt) 17 Main Street \\ New York, NY 10001 \\ +1 555 555 5555 ```
|
||||
- type: bool
|
||||
- default: false
|
||||
- margin:
|
||||
- description: The page\'s margins. - `auto`: The margins are set automatically to 2.5/21 times the smaller dimension of the page. This results in 2.5 cm margins for an A4 page. - A single length: The same margin on all sides. - A dictionary: With a dictionary, the margins can be set individually. The dictionary can contain the following keys in order of precedence: - `top`: The top margin. - `right`: The right margin. - `bottom`: The bottom margin. - `left`: The left margin. - `inside`: The margin at the inner side of the page (where the [binding](/docs/reference/layout/page/#parameters-binding) is). - `outside`: The margin at the outer side of the page (opposite to the [binding](/docs/reference/layout/page/#parameters-binding)). - `x`: The horizontal margins. - `y`: The vertical margins. - `rest`: The margins on all sides except those for which the dictionary explicitly sets a size. All keys are optional; omitted keys will use their previously set value, or the default margin if never set. In addition, the values for `left` and `right` are mutually exclusive with the values for `inside` and `outside`. ```typst #set page( width: 3cm, height: 4cm, margin: (x: 8pt, y: 4pt), ) #rect( width: 100%, height: 100%, fill: aqua, ) ```
|
||||
- type: auto | relative | dictionary
|
||||
- default: auto
|
||||
- binding:
|
||||
- description: On which side the pages will be bound. - `auto`: Equivalent to `left` if the [text direction](/docs/reference/text/text/#parameters-dir) is left-to-right and `right` if it is right-to-left. - `left`: Bound on the left side. - `right`: Bound on the right side. This affects the meaning of the `inside` and `outside` options for margins.
|
||||
- type: auto | alignment
|
||||
- default: auto
|
||||
- columns:
|
||||
- description: How many columns the page has. If you need to insert columns into a page or other container, you can also use the [`columns` function](/docs/reference/layout/columns/). ```typst #set page(columns: 2, height: 4.8cm) Climate change is one of the most pressing issues of our time, with the potential to devastate communities, ecosystems, and economies around the world. It\'s clear that we need to take urgent action to reduce our carbon emissions and mitigate the impacts of a rapidly changing climate. ```
|
||||
- type: int
|
||||
- default: 1
|
||||
- fill:
|
||||
- description: The page\'s background fill. Setting this to something non-transparent instructs the printer to color the complete page. If you are considering larger production runs, it may be more environmentally friendly and cost-effective to source pre-dyed pages and not set this property. When set to `none`, the background becomes transparent. Note that PDF pages will still appear with a (usually white) background in viewers, but they are actually transparent. (If you print them, no color is used for the background.) The default of `auto` results in `none` for PDF output, and `white` for PNG and SVG. ```typst #set page(fill: rgb("444352")) #set text(fill: rgb("fdfdfd")) *Dark mode enabled.* ```
|
||||
- type: none | auto | color | gradient | tiling
|
||||
- default: auto
|
||||
- numbering:
|
||||
- description: How to number the pages. You can refer to the Page Setup Guide for [customizing page numbers](/docs/guides/page-setup/#page-numbers). Accepts a [numbering pattern or function](/docs/reference/model/numbering/) taking one or two numbers: 1. The first number is the current page number. 2. The second number is the total number of pages. In a numbering pattern, the second number can be omitted. If a function is passed, it will receive one argument in the context of links or references, and two arguments when producing the visible page numbers. These are logical numbers controlled by the page counter, and may thus not match the physical numbers. Specifically, they are the [current](/docs/reference/introspection/counter/#definitions-get) and the [final](/docs/reference/introspection/counter/#definitions-final) value of `counter(page)`. See the [`counter`](/docs/reference/introspection/counter/#page-counter) documentation for more details. If an explicit [`footer`](/docs/reference/layout/page/#parameters-footer) (or [`header`](/docs/reference/layout/page/#parameters-header) for [top-aligned](/docs/reference/layout/page/#parameters-number-align) numbering) is given, the numbering is ignored. ```typst #set page( height: 100pt, margin: (top: 16pt, bottom: 24pt), numbering: "1 / 1", ) #lorem(48) ```
|
||||
- type: none | str | function
|
||||
- default: none
|
||||
- supplement:
|
||||
- description: A supplement for the pages. For page references, this is added before the page number. ```typst #set page(numbering: "1.", supplement: [p.]) = Introduction <intro> We are on #ref(<intro>, form: "page")! ```
|
||||
- type: none | auto | content
|
||||
- default: auto
|
||||
- number-align:
|
||||
- description: The alignment of the page numbering. If the vertical component is `top`, the numbering is placed into the header and if it is `bottom`, it is placed in the footer. Horizon alignment is forbidden. If an explicit matching `header` or `footer` is given, the numbering is ignored. ```typst #set page( margin: (top: 16pt, bottom: 24pt), numbering: "1", number-align: right, ) #lorem(30) ```
|
||||
- type: alignment
|
||||
- default: center + bottom
|
||||
- header:
|
||||
- description: The page\'s header. Fills the top margin of each page. - Content: Shows the content as the header. - `auto`: Shows the page number if a [`numbering`](/docs/reference/layout/page/#parameters-numbering) is set and [`number-align`](/docs/reference/layout/page/#parameters-number-align) is `top`. - `none`: Suppresses the header. ```typst #set par(justify: true) #set page( margin: (top: 32pt, bottom: 20pt), header: [ #set text(8pt) #smallcaps[Typst Academy] #h(1fr) _Exercise Sheet 3_ ], ) #lorem(19) ```
|
||||
- type: none | auto | content
|
||||
- default: auto
|
||||
- header-ascent:
|
||||
- description: The amount the header is raised into the top margin.
|
||||
- type: relative
|
||||
- default: 30 % + 0pt
|
||||
- footer:
|
||||
- description: The page\'s footer. Fills the bottom margin of each page. - Content: Shows the content as the footer. - `auto`: Shows the page number if a [`numbering`](/docs/reference/layout/page/#parameters-numbering) is set and [`number-align`](/docs/reference/layout/page/#parameters-number-align) is `bottom`. - `none`: Suppresses the footer. For just a page number, the `numbering` property typically suffices. If you want to create a custom footer but still display the page number, you can directly access the [page counter](/docs/reference/introspection/counter/). ```typst #set par(justify: true) #set page( height: 100pt, margin: 20pt, footer: context [ #set align(right) #set text(8pt) #counter(page).display( "1 of I", both: true, ) ] ) #lorem(48) ```
|
||||
- type: none | auto | content
|
||||
- default: auto
|
||||
- footer-descent:
|
||||
- description: The amount the footer is lowered into the bottom margin.
|
||||
- type: relative
|
||||
- default: 30 % + 0pt
|
||||
- background:
|
||||
- description: Content in the page\'s background. This content will be placed behind the page\'s body. It can be used to place a background image or a watermark. ```typst #set page(background: rotate(24deg, text(18pt, fill: rgb("FFCBC4"))[ *CONFIDENTIAL* ] )) = Typst\'s secret plans In the year 2023, we plan to take over the world (of typesetting). ```
|
||||
- type: none | content
|
||||
- default: none
|
||||
- foreground:
|
||||
- description: Content in the page\'s foreground. This content will overlay the page\'s body. ```typst #set page(foreground: text(24pt)[🤓]) Reviewer 2 has marked our paper "Weak Reject" because they did not understand our approach... ```
|
||||
- type: none | content
|
||||
- default: none
|
||||
- body:
|
||||
- description: The contents of the page(s). Multiple pages will be created if the content does not fit on a single page. A new page with the page properties prior to the function invocation will be created after the body has been typeset.
|
||||
- type: content
|
||||
- default: []
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
# Page Break
|
||||
|
||||
# pagebreak
|
||||
|
||||
A manual page break.
|
||||
|
||||
Must not be used inside any containers.
|
||||
|
||||
## Example
|
||||
|
||||
```typst
|
||||
The next page contains
|
||||
more details on compound theory.
|
||||
#pagebreak()
|
||||
|
||||
== Compound Theory
|
||||
In 1984, the first ...
|
||||
```
|
||||
|
||||
Even without manual page breaks, content will be automatically paginated based on the configured page size. You can set [the page height](/docs/reference/layout/page/#parameters-height) to `auto` to let the page grow dynamically until a manual page break occurs.
|
||||
|
||||
Pagination tries to avoid single lines of text at the top or bottom of a page (these are called _widows_ and _orphans_). You can adjust the [`text.costs`](/docs/reference/text/text/#parameters-costs) parameter to disable this behavior.
|
||||
|
||||
```typst
|
||||
#pagebreak(
|
||||
weak: bool,
|
||||
to: none | str
|
||||
) -> content
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
- weak:
|
||||
- description: If `true`, the page break is skipped if the current page is already empty.
|
||||
- type: bool
|
||||
- default: false
|
||||
- to:
|
||||
- description: If given, ensures that the next page will be an even/odd page, with an empty page in between if necessary. ```typst #set page(height: 30pt) First. #pagebreak(to: "odd") Third. ```
|
||||
- type: none | str
|
||||
- default: none
|
||||
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
# Place
|
||||
|
||||
# place
|
||||
|
||||
Places content relatively to its parent container.
|
||||
|
||||
Placed content can be either overlaid (the default) or floating. Overlaid content is aligned with the parent container according to the given [`alignment`](/docs/reference/layout/place/#parameters-alignment), and shown over any other content added so far in the container. Floating content is placed at the top or bottom of the container, displacing other content down or up respectively. In both cases, the content position can be adjusted with [`dx`](/docs/reference/layout/place/#parameters-dx) and [`dy`](/docs/reference/layout/place/#parameters-dy) offsets without affecting the layout.
|
||||
|
||||
The parent can be any container such as a [`block`](/docs/reference/layout/block/), [`box`](/docs/reference/layout/box/), [`rect`](/docs/reference/visualize/rect/), etc. A top level `place` call will place content directly in the text area of the current page. This can be used for absolute positioning on the page: with a `top + left` [`alignment`](/docs/reference/layout/place/#parameters-alignment), the offsets `dx` and `dy` will set the position of the element's top left corner relatively to the top left corner of the text area. For absolute positioning on the full page including margins, you can use `place` in [`page.foreground`](/docs/reference/layout/page/#parameters-foreground) or [`page.background`](/docs/reference/layout/page/#parameters-background).
|
||||
|
||||
## Examples
|
||||
|
||||
```typst
|
||||
#set page(height: 120pt)
|
||||
Hello, world!
|
||||
|
||||
#rect(
|
||||
width: 100%,
|
||||
height: 2cm,
|
||||
place(horizon + right, square()),
|
||||
)
|
||||
|
||||
#place(
|
||||
top + left,
|
||||
dx: -5pt,
|
||||
square(size: 5pt, fill: red),
|
||||
)
|
||||
```
|
||||
|
||||
## Effect on the position of other elements
|
||||
|
||||
Overlaid elements don't take space in the flow of content, but a `place` call inserts an invisible block-level element in the flow. This can affect the layout by breaking the current paragraph. To avoid this, you can wrap the `place` call in a [`box`](/docs/reference/layout/box/) when the call is made in the middle of a paragraph. The alignment and offsets will then be relative to this zero-size box. To make sure it doesn't interfere with spacing, the box should be attached to a word using a word joiner.
|
||||
|
||||
For example, the following defines a function for attaching an annotation to the following word:
|
||||
|
||||
```typst
|
||||
#let annotate(..args) = {
|
||||
box(place(..args))
|
||||
sym.wj
|
||||
h(0pt, weak: true)
|
||||
}
|
||||
|
||||
A placed #annotate(square(), dy: 2pt)
|
||||
square in my text.
|
||||
```
|
||||
|
||||
The zero-width weak spacing serves to discard spaces between the function call and the next word.
|
||||
|
||||
## Accessibility
|
||||
|
||||
Assistive Technology (AT) will always read the placed element at the point where it logically appears in the document, regardless of where this function physically moved it. Put its markup where it would make the most sense in the reading order.
|
||||
|
||||
```typst
|
||||
#place(
|
||||
alignment,
|
||||
scope: str,
|
||||
float: bool,
|
||||
clearance: length,
|
||||
dx: relative,
|
||||
dy: relative,
|
||||
body
|
||||
) -> content
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
- alignment:
|
||||
- description: Relative to which position in the parent container to place the content. - If `float` is `false`, then this can be any alignment other than `auto`. - If `float` is `true`, then this must be `auto`, `top`, or `bottom`. When `float` is `false` and no vertical alignment is specified, the content is placed at the current position on the vertical axis.
|
||||
- type: auto | alignment
|
||||
- default: start
|
||||
- scope:
|
||||
- description: Relative to which containing scope something is placed. The parent scope is primarily used with figures and, for this reason, the figure function has a mirrored [`scope` parameter](/docs/reference/model/figure/#parameters-scope). Nonetheless, it can also be more generally useful to break out of the columns. A typical example would be to [create a single-column title section](/docs/guides/page-setup/#columns) in a two-column document. Note that parent-scoped placement is currently only supported if `float` is `true`. This may change in the future. ```typst #set page(height: 150pt, columns: 2) #place( top + center, scope: "parent", float: true, rect(width: 80%, fill: aqua), ) #lorem(25) ```
|
||||
- type: str
|
||||
- default: "column"
|
||||
- float:
|
||||
- description: Whether the placed element has floating layout. Floating elements are positioned at the top or bottom of the parent container, displacing in-flow content. They are always placed in the in-flow order relative to each other, as well as before any content following a later [`place.flush`](/docs/reference/layout/place/#definitions-flush) element. ```typst #set page(height: 150pt) #let note(where, body) = place( center + where, float: true, clearance: 6pt, rect(body), ) #lorem(10) #note(bottom)[Bottom 1] #note(bottom)[Bottom 2] #lorem(40) #note(top)[Top] #lorem(10) ```
|
||||
- type: bool
|
||||
- default: false
|
||||
- clearance:
|
||||
- description: The spacing between the placed element and other elements in a floating layout. Has no effect if `float` is `false`.
|
||||
- type: length
|
||||
- default: 1.5em
|
||||
- dx:
|
||||
- description: The horizontal displacement of the placed content. ```typst #set page(height: 100pt) #for x in range(-8, 8) { place(center + horizon, dx: x * 8pt, dy: x * 4pt, text( size: calc.root(x + 10, 3) * 6pt, fill: color.mix((green, 8 - x), (blue, 8 + x)), )[T] ) } ``` This does not affect the layout of in-flow content. In other words, the placed content is treated as if it were wrapped in a [`move`](/docs/reference/layout/move/) element.
|
||||
- type: relative
|
||||
- default: 0 % + 0pt
|
||||
- dy:
|
||||
- description: The vertical displacement of the placed content. This does not affect the layout of in-flow content. In other words, the placed content is treated as if it were wrapped in a [`move`](/docs/reference/layout/move/) element.
|
||||
- type: relative
|
||||
- default: 0 % + 0pt
|
||||
- body:
|
||||
- description: The content to place.
|
||||
- type: content
|
||||
- default: None
|
||||
|
||||
|
||||
## Definitions
|
||||
### place.flush
|
||||
|
||||
Asks the layout algorithm to place pending floating elements before continuing with the content.
|
||||
|
||||
This is useful for preventing floating figures from spilling into the next section.
|
||||
|
||||
```typst
|
||||
#lorem(15)
|
||||
|
||||
#figure(
|
||||
rect(width: 100%, height: 50pt),
|
||||
placement: auto,
|
||||
caption: [A rectangle],
|
||||
)
|
||||
|
||||
#place.flush()
|
||||
|
||||
This text appears after the figure.
|
||||
```
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
# Ratio
|
||||
|
||||
A ratio of a whole.
|
||||
|
||||
A ratio is written as a number, followed by a percent sign. Ratios most often appear as part of a [relative length](/docs/reference/layout/relative/), to specify the size of some layout element relative to the page or some container.
|
||||
|
||||
```typst
|
||||
#rect(width: 25%)
|
||||
```
|
||||
|
||||
However, they can also describe any other property that is relative to some base, e.g. an amount of [horizontal scaling](/docs/reference/layout/scale/#parameters-x) or the [height of parentheses](/docs/reference/math/lr/#functions-lr-size) relative to the height of the content they enclose.
|
||||
|
||||
## Scripting
|
||||
|
||||
Within your own code, you can use ratios as you like. You can multiply them with various other types as shown below:
|
||||
|
||||
| Multiply by | Example | Result |
|
||||
| --- | --- | --- |
|
||||
| [`ratio`](/docs/reference/layout/ratio/) | `27% * 10%` | `2.7%` |
|
||||
| [`length`](/docs/reference/layout/length/) | `27% * 100pt` | `27pt` |
|
||||
| [`relative`](/docs/reference/layout/relative/) | `27% * (10% + 100pt)` | `2.7% + 27pt` |
|
||||
| [`angle`](/docs/reference/layout/angle/) | `27% * 100deg` | `27deg` |
|
||||
| [`int`](/docs/reference/foundations/int/) | `27% * 2` | `54%` |
|
||||
| [`float`](/docs/reference/foundations/float/) | `27% * 0.37037` | `10%` |
|
||||
| [`fraction`](/docs/reference/layout/fraction/) | `27% * 3fr` | `0.81fr` |
|
||||
|
||||
When ratios are [displayed](/docs/reference/foundations/repr/) in the document, they are rounded to two significant digits for readability.
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
# Relative Length
|
||||
|
||||
A length in relation to some known length.
|
||||
|
||||
This type is a combination of a [length](/docs/reference/layout/length/) with a [ratio](/docs/reference/layout/ratio/). It results from addition and subtraction of a length and a ratio. Wherever a relative length is expected, you can also use a bare length or ratio.
|
||||
|
||||
## Relative to the page
|
||||
|
||||
A common use case is setting the width or height of a layout element (e.g., [block](/docs/reference/layout/block/), [rect](/docs/reference/visualize/rect/), etc.) as a certain percentage of the width of the page. Here, the rectangle's width is set to `25%`, so it takes up one fourth of the page's _inner_ width (the width minus margins).
|
||||
|
||||
```typst
|
||||
#rect(width: 25%)
|
||||
```
|
||||
|
||||
Bare lengths or ratios are always valid where relative lengths are expected, but the two can also be freely mixed:
|
||||
|
||||
```typst
|
||||
#rect(width: 25% + 1cm)
|
||||
```
|
||||
|
||||
If you're trying to size an element so that it takes up the page's _full_ width, you have a few options (this highly depends on your exact use case):
|
||||
|
||||
1. Set page margins to `0pt` (`#set page(margin: 0pt)`)
|
||||
2. Multiply the ratio by the known full page width (`21cm * 69%`)
|
||||
3. Use padding which will negate the margins (`#pad(x: -2.5cm, ...)`)
|
||||
4. Use the page [background](/docs/reference/layout/page/#parameters-background) or [foreground](/docs/reference/layout/page/#parameters-foreground) field as those don't take margins into account (note that it will render the content outside of the document flow, see [place](/docs/reference/layout/place/) to control the content position)
|
||||
|
||||
## Relative to a container
|
||||
|
||||
When a layout element (e.g. a [rect](/docs/reference/visualize/rect/)) is nested in another layout container (e.g. a [block](/docs/reference/layout/block/)) instead of being a direct descendant of the page, relative widths become relative to the container:
|
||||
|
||||
```typst
|
||||
#block(
|
||||
width: 100pt,
|
||||
fill: aqua,
|
||||
rect(width: 50%),
|
||||
)
|
||||
```
|
||||
|
||||
## Scripting
|
||||
|
||||
You can multiply relative lengths by [ratios](/docs/reference/layout/ratio/), [integers](/docs/reference/foundations/int/), and [floats](/docs/reference/foundations/float/).
|
||||
|
||||
A relative length has the following fields:
|
||||
|
||||
- `length`: Its [length](/docs/reference/layout/length/) component.
|
||||
- `ratio`: Its [ratio](/docs/reference/layout/ratio/) component.
|
||||
|
||||
```typst
|
||||
#(100% - 50pt).length \
|
||||
#(100% - 50pt).ratio
|
||||
```
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
# Repeat
|
||||
|
||||
# repeat
|
||||
|
||||
Repeats content to the available space.
|
||||
|
||||
This can be useful when implementing a custom index, reference, or outline.
|
||||
|
||||
Space may be inserted between the instances of the body parameter, so be sure to adjust the [`justify`](/docs/reference/layout/repeat/#parameters-justify) parameter accordingly.
|
||||
|
||||
Errors if there are no bounds on the available space, as it would create infinite content.
|
||||
|
||||
## Example
|
||||
|
||||
```typst
|
||||
Sign on the dotted line:
|
||||
#box(width: 1fr, repeat[.])
|
||||
|
||||
#set text(10pt)
|
||||
#v(8pt, weak: true)
|
||||
#align(right)[
|
||||
Berlin, the 22nd of December, 2022
|
||||
]
|
||||
```
|
||||
|
||||
## Accessibility
|
||||
|
||||
Repeated content is automatically marked as an [artifact](/docs/reference/pdf/artifact/) and hidden from Assistive Technology (AT). Do not use this function to create content that contributes to the meaning of your document.
|
||||
|
||||
```typst
|
||||
#repeat(
|
||||
body,
|
||||
gap: length,
|
||||
justify: bool
|
||||
) -> content
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
- body:
|
||||
- description: The content to repeat.
|
||||
- type: content
|
||||
- default: None
|
||||
- gap:
|
||||
- description: The gap between each instance of the body.
|
||||
- type: length
|
||||
- default: 0pt
|
||||
- justify:
|
||||
- description: Whether to increase the gap between instances to completely fill the available space.
|
||||
- type: bool
|
||||
- default: true
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
# Rotate
|
||||
|
||||
# rotate
|
||||
|
||||
Rotates content without affecting layout.
|
||||
|
||||
Rotates an element by a given angle. The layout will act as if the element was not rotated unless you specify `reflow: true`.
|
||||
|
||||
## Example
|
||||
|
||||
```typst
|
||||
#stack(
|
||||
dir: ltr,
|
||||
spacing: 1fr,
|
||||
..range(16)
|
||||
.map(i => rotate(24deg * i)[X]),
|
||||
)
|
||||
```
|
||||
|
||||
```typst
|
||||
#rotate(
|
||||
angle,
|
||||
origin: alignment,
|
||||
reflow: bool,
|
||||
body
|
||||
) -> content
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
- angle:
|
||||
- description: The amount of rotation. ```typst #rotate(-1.571rad)[Space!] ```
|
||||
- type: angle
|
||||
- default: 0deg
|
||||
- origin:
|
||||
- description: The origin of the rotation. If, for instance, you wanted the bottom left corner of the rotated element to stay aligned with the baseline, you would set it to `bottom + left` instead. ```typst #set text(spacing: 8pt) #let square = square.with(width: 8pt) #box(square()) #box(rotate(30deg, origin: center, square())) #box(rotate(30deg, origin: top + left, square())) #box(rotate(30deg, origin: bottom + right, square())) ```
|
||||
- type: alignment
|
||||
- default: center + horizon
|
||||
- reflow:
|
||||
- description: Whether the rotation impacts the layout. If set to `false`, the rotated content will retain the bounding box of the original content. If set to `true`, the bounding box will take the rotation of the content into account and adjust the layout accordingly. ```typst Hello #rotate(90deg, reflow: true)[World]! ```
|
||||
- type: bool
|
||||
- default: false
|
||||
- body:
|
||||
- description: The content to rotate.
|
||||
- type: content
|
||||
- default: None
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
# Scale
|
||||
|
||||
# scale
|
||||
|
||||
Scales content without affecting layout.
|
||||
|
||||
Lets you mirror content by specifying a negative scale on a single axis.
|
||||
|
||||
## Example
|
||||
|
||||
```typst
|
||||
#set align(center)
|
||||
#scale(x: -100%)[This is mirrored.]
|
||||
#scale(x: -100%, reflow: true)[This is mirrored.]
|
||||
```
|
||||
|
||||
```typst
|
||||
#scale(
|
||||
factor: auto | length | ratio,
|
||||
x: auto | length | ratio,
|
||||
y: auto | length | ratio,
|
||||
origin: alignment,
|
||||
reflow: bool,
|
||||
body
|
||||
) -> content
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
- factor:
|
||||
- description: The scaling factor for both axes, as a positional argument. This is just an optional shorthand notation for setting `x` and `y` to the same value.
|
||||
- type: auto | length | ratio
|
||||
- default: 100 %
|
||||
- x:
|
||||
- description: The horizontal scaling factor. The body will be mirrored horizontally if the parameter is negative.
|
||||
- type: auto | length | ratio
|
||||
- default: 100 %
|
||||
- y:
|
||||
- description: The vertical scaling factor. The body will be mirrored vertically if the parameter is negative.
|
||||
- type: auto | length | ratio
|
||||
- default: 100 %
|
||||
- origin:
|
||||
- description: The origin of the transformation. ```typst A#box(scale(75%)[A])A \\ B#box(scale(75%, origin: bottom + left)[B])B ```
|
||||
- type: alignment
|
||||
- default: center + horizon
|
||||
- reflow:
|
||||
- description: Whether the scaling impacts the layout. If set to `false`, the scaled content will be allowed to overlap other content. If set to `true`, it will compute the new size of the scaled content and adjust the layout accordingly. ```typst Hello #scale(x: 20%, y: 40%, reflow: true)[World]! ```
|
||||
- type: bool
|
||||
- default: false
|
||||
- body:
|
||||
- description: The content to scale.
|
||||
- type: content
|
||||
- default: None
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
# Skew
|
||||
|
||||
# skew
|
||||
|
||||
Skews content.
|
||||
|
||||
Skews an element in horizontal and/or vertical direction. The layout will act as if the element was not skewed unless you specify `reflow: true`.
|
||||
|
||||
## Example
|
||||
|
||||
```typst
|
||||
#skew(ax: -12deg)[
|
||||
This is some fake italic text.
|
||||
]
|
||||
```
|
||||
|
||||
```typst
|
||||
#skew(
|
||||
ax: angle,
|
||||
ay: angle,
|
||||
origin: alignment,
|
||||
reflow: bool,
|
||||
body
|
||||
) -> content
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
- ax:
|
||||
- description: The horizontal skewing angle. ```typst #skew(ax: 30deg)[Skewed] ```
|
||||
- type: angle
|
||||
- default: 0deg
|
||||
- ay:
|
||||
- description: The vertical skewing angle. ```typst #skew(ay: 30deg)[Skewed] ```
|
||||
- type: angle
|
||||
- default: 0deg
|
||||
- origin:
|
||||
- description: The origin of the skew transformation. The origin will stay fixed during the operation. ```typst X #box(skew(ax: -30deg, origin: center + horizon)[X]) X \\ X #box(skew(ax: -30deg, origin: bottom + left)[X]) X \\ X #box(skew(ax: -30deg, origin: top + right)[X]) X ```
|
||||
- type: alignment
|
||||
- default: center + horizon
|
||||
- reflow:
|
||||
- description: Whether the skew transformation impacts the layout. If set to `false`, the skewed content will retain the bounding box of the original content. If set to `true`, the bounding box will take the transformation of the content into account and adjust the layout accordingly. ```typst Hello #skew(ay: 30deg, reflow: true, "World")! ```
|
||||
- type: bool
|
||||
- default: false
|
||||
- body:
|
||||
- description: The content to skew.
|
||||
- type: content
|
||||
- default: None
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
# Stack
|
||||
|
||||
# stack
|
||||
|
||||
Arranges content and spacing horizontally or vertically.
|
||||
|
||||
The stack places a list of items along an axis, with optional spacing between each item.
|
||||
|
||||
## Example
|
||||
|
||||
```typst
|
||||
#stack(
|
||||
dir: ttb,
|
||||
rect(width: 40pt),
|
||||
rect(width: 120pt),
|
||||
rect(width: 90pt),
|
||||
)
|
||||
```
|
||||
|
||||
## Accessibility
|
||||
|
||||
Stacks do not carry any special semantics. The contents of the stack are read by Assistive Technology (AT) in the order in which they have been passed to this function.
|
||||
|
||||
```typst
|
||||
#stack(
|
||||
dir: direction,
|
||||
spacing: none | relative | fraction,
|
||||
children
|
||||
) -> content
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
- dir:
|
||||
- description: The direction along which the items are stacked. Possible values are: - `ltr`: Left to right. - `rtl`: Right to left. - `ttb`: Top to bottom. - `btt`: Bottom to top. You can use the `start` and `end` methods to obtain the initial and final points (respectively) of a direction, as `alignment`. You can also use the `axis` method to determine whether a direction is `"horizontal"` or `"vertical"`. The `inv` method returns a direction\'s inverse direction. For example, `ttb.start()` is `top`, `ttb.end()` is `bottom`, `ttb.axis()` is `"vertical"` and `ttb.inv()` is equal to `btt`.
|
||||
- type: direction
|
||||
- default: ttb
|
||||
- spacing:
|
||||
- description: Spacing to insert between items where no explicit spacing was provided.
|
||||
- type: none | relative | fraction
|
||||
- default: none
|
||||
- children:
|
||||
- description: The children to stack along the axis.
|
||||
- type: relative | fraction | content
|
||||
- default: None
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
# Spacing (V)
|
||||
|
||||
# v
|
||||
|
||||
Inserts vertical spacing into a flow of blocks.
|
||||
|
||||
The spacing can be absolute, relative, or fractional. In the last case, the remaining space on the page is distributed among all fractional spacings according to their relative fractions.
|
||||
|
||||
## Example
|
||||
|
||||
```typst
|
||||
#grid(
|
||||
rows: 3cm,
|
||||
columns: 6,
|
||||
gutter: 1fr,
|
||||
[A #parbreak() B],
|
||||
[A #v(0pt) B],
|
||||
[A #v(10pt) B],
|
||||
[A #v(0pt, weak: true) B],
|
||||
[A #v(40%, weak: true) B],
|
||||
[A #v(1fr) B],
|
||||
)
|
||||
```
|
||||
|
||||
```typst
|
||||
#v(
|
||||
amount,
|
||||
weak: bool
|
||||
) -> content
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
- amount:
|
||||
- description: How much spacing to insert.
|
||||
- type: relative | fraction
|
||||
- default: None
|
||||
- weak:
|
||||
- description: If `true`, the spacing collapses at the start or end of a flow. Moreover, from multiple adjacent weak spacings all but the largest one collapse. Weak spacings will always collapse adjacent paragraph spacing, even if the paragraph spacing is larger. ```typst The following theorem is foundational to the field: #v(4pt, weak: true) $ x^2 + y^2 = r^2 $ #v(4pt, weak: true) The proof is simple: ```
|
||||
- type: bool
|
||||
- default: false
|
||||
|
||||
|
||||
Reference in new issue
Block a user