Typst-Formatting-相关

Formatting 即更高级的排版功能.

Element function

如果一个函数是 Element function, 其就可以被 setshow 关键字处理.

#set 处理的函数似乎对后面所有文本有效.

par 函数

par, 指 “paragraph”, 用于设置文本的 properties 如:

1
2
3
4
5
6
7
8
9
10
11
#par(justify: true)[
= Background
In the case of glaciers, fluid
dynamics principles can be used
to understand how the movement
and behaviour of the ice is
influenced by factors such as
temperature, pressure, and the
presence of other fluids (such as
water).
]

这里为 [] 中的文本开启 justify 属性.

可以结合 set 关键字, 让 par 对其后的多段文本都起作用:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#set par(
first-line-indent: 1em,
justify: true,
)

We proceed by contradiction.
Suppose that there exists a set
of positive integers $a$, $b$, and
$c$ that satisfies the equation
$a^n + b^n = c^n$ for some
integer value of $n > 2$.

Without loss of generality,
let $a$ be the smallest of the
three integers. Then, we ...

align 函数

align 函数用于设置文本的 horizontal 和 vertical 位置, 如水平居中, 靠左对齐等.

如:

1
2
3
4
5
6
#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

常用选项有:

  • start: Aligns at the start of the text direction.
  • end: Aligns at the end of the text direction.
  • 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.

lorem 单词生成的函数

lorem 的第一个参数为要生成单词的个数, 如:

1
2
3
4
5
6
7
8
= Introduction
#lorem(10)

== Background
#lorem(12)

== Methods
#lorem(15)

用于 set up the page 的函数

  • text, 用于设置字体的 family, size, color, 及其他 properties
  • page, 用于设置 page size, margins, headers, enable columns and footers
  • par, 用于 justify paragraphs, set line spacing, and more
  • heading, 用于设置 the appearance of headings and enable numbering
  • document, 设置文档的 metadata, 包括 PDF 输出, title 和 author

如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#set text(
font: "New Computer Modern",
size: 10pt
)
#set page(
paper: "a6",
margin: (x: 1.8cm, y: 1.5cm),
)
#set par(
justify: true,
leading: 0.52em,
)

= Introduction
In this report, we will explore the
various factors that influence fluid
dynamics in glaciers and how they
contribute to the formation and
behaviour of these natural structures.

#align(center + bottom)[
#image("glacier.jpg", width: 70%)

*Glaciers form an important
part of the earth's climate
system.*
]

这里的 (x: 1.8cm, y: 1.5cm) 是 Typst 中的 dictionary.

为 title 添加序号, 可使用 heading 函数:

1
2
3
4
5
6
7
8
9
10
#set heading(numbering: "1.a")

= Introduction
#lorem(10)

== Background
#lorem(12)

== Methods
#lorem(15)

show 关键字

show 关键字用于改变一个 Typst element 的显示方式, 比如改变一个字符串的显示:

1
2
3
4
5
6
7
8
9
10
11
#show "ArtosFlow": name => box[
#box(image(
"logo.svg",
height: 0.7em,
))
#name
]

This report is embedded in the
ArtosFlow project. ArtosFlow is a
project of the Artos Institute.

首先 "ArtosFlow": name 是一个键值对, 后面的 #name 就是引用 "ArtosFlow" 这个字符串文本.

之后的 => 表示调用一个 function, 这里是 box.


Typst-Formatting-相关
http://example.com/2024/04/12/Typst-Formatting-相关/
作者
Jie
发布于
2024年4月12日
许可协议