11---
2- description : All concepts needed to style your document with Typst.
2+ description : Typst で文書のスタイル設定をするために必要な概念
33---
44
5- # Styling
6- Typst includes a flexible styling system that automatically applies styling of
7- your choice to your document. With _ set rules,_ you can configure basic
8- properties of elements. This way, you create most common styles. However, there
9- might not be a built-in property for everything you wish to do. For this reason,
10- Typst further supports _ show rules_ that can completely redefine the appearance
11- of elements.
12-
13- ## Set rules
14- With set rules, you can customize the appearance of elements. They are written
15- as a [ function call] ( $function ) to an [ element
16- function] ( $function/#element-functions ) preceded by the ` {set} ` keyword (or
17- ` [#set] ` in markup). Only optional parameters of that function can be provided
18- to the set rule. Refer to each function's documentation to see which parameters
19- are optional. In the example below, we use two set rules to change the
20- [ font family] ( $text.font ) and [ heading numbering] ( $heading.numbering ) .
5+ # スタイル設定
6+
7+ Typst には柔軟なスタイル設定機能を持ち、出力される文書に対して自動的に任意のスタイル設定を適用します。
8+ _ setルール_ ではエレメントの基本プロパティを設定できます。
9+ しかし、やりたいことすべてに対応するプロパティがあらかじめ実装されているとは限りません。
10+ このため、Typst はエレメントの外観を完全に再定義できる _ showルール_ もサポートしています。
11+
12+ ## setルール { #set-rules }
13+
14+ set ルールを使うと、エレメントの外観をカスタマイズできます。
15+ これらは、` {set} ` キーワード(マークアップでは ` [#set] ` )を前に置いた [ element 関数] ( $function/#element-functions ) への[ 関数呼び出し] ( $function ) として記述されます。
16+ set ルールに指定できるのは、その関数のオプションのパラメーターだけです。
17+ どのパラメーターがオプションであるかは、各関数のドキュメントを参照してください。
18+ 以下の例では、2 つの set ルールを使って、[ フォント] ( $text.font ) と[ 見出し番号] ( $heading.numbering ) を変更しています。
2119
2220``` example
2321#set heading(numbering: "I.")
@@ -30,11 +28,10 @@ With set rules, you can style
3028your document.
3129```
3230
33- A top level set rule stays in effect until the end of the file. When nested
34- inside of a block, it is only in effect until the end of that block. With a
35- block, you can thus restrict the effect of a rule to a particular segment of
36- your document. Below, we use a content block to scope the list styling to one
37- particular list.
31+ set ルールは、そのまま記述するとファイルの最後まで適用されます。
32+ ブロックの中にネストすると、そのブロックの終わりまで適用されます。
33+ ブロックを使えば、set ルールの効果を指定した部分に限定できます。
34+ 以下では、content ブロックを用いてスコープすることで、特定のリストのスタイルのみを変更しています。
3835
3936``` example
4037This list is affected: #[
@@ -46,8 +43,8 @@ This one is not:
4643- Bullet
4744```
4845
49- Sometimes, you'll want to apply a set rule conditionally. For this, you can use
50- a _ set-if_ rule.
46+ ときには、 set ルールを条件付きで設定したい場合もあるでしょう。
47+ その場合には _ set-if_ ルールを使用します。
5148
5249``` example
5350#let task(body, critical: false) = {
@@ -59,13 +56,13 @@ a _set-if_ rule.
5956#task(critical: false)[Work deadline]
6057```
6158
62- ## Show rules
63- With show rules, you can deeply customize the look of a type of element. The
64- most basic form of show rule is a _ show-set rule. _ Such a rule is written as the
65- ` { show} ` keyword followed by a [ selector ] , a colon and then a set rule. The most
66- basic form of selector is an [ element function ] ( $function/#element-functions ) .
67- This lets the set rule only apply to the selected element. In the example below,
68- headings become dark blue while all other text stays black.
59+ ## showルール { #show- rules }
60+
61+ show ルールを使えば、特定の種類のエレメントの外観を詳細に設定できます。
62+ show ルールの基本的な記述方法は、show- set ルールです。
63+ ` {show} ` キーワードの後に [ セレクター ] ( $selector ) 、コロン、set ルールと続けて記述します。
64+ セレクターの基本的な記述方法は [ element関数 ] ( $function/#element-functions ) を置くことであり、 set ルールは選択されたエレメントにのみ適用されます。
65+ 下の例では、見出しは紺色になり、他のテキストは黒色のままです。
6966
7067``` example
7168#show heading: set text(navy)
@@ -74,15 +71,13 @@ headings become dark blue while all other text stays black.
7471But this stays black.
7572```
7673
77- With show-set rules you can mix and match properties from different functions to
78- achieve many different effects. But they still limit you to what is predefined
79- in Typst. For maximum flexibility, you can instead write a show rule that
80- defines how to format an element from scratch. To write such a show rule,
81- replace the set rule after the colon with an arbitrary [ function] . This function
82- receives the element in question and can return arbitrary content. The available
83- [ fields] ( $scripting/#fields ) on the element passed to the function again match
84- the parameters of the respective element function. Below, we define a show rule
85- that formats headings for a fantasy encyclopedia.
74+ show-set ルールを使えば、さまざまな関数のプロパティを組み合わせることが可能です。
75+ しかし、組み合わせられるプロパティは Typst であらかじめ定義されているものに限定されます。
76+ 最大限の柔軟性を得るには、エレメントをゼロからフォーマットする方法を定義する show ルールを書くことができます。
77+ このような show ルールを書くには、コロンの後の set ルールを任意の[ 関数] ( $function ) に置き換えてください。
78+ この関数は対象のエレメントを受け取り、任意の内容を返すことができます。
79+ 関数に渡されたエレメントで利用可能な[ フィールド] ( $scripting/#fields ) は、それぞれの element 関数のパラメーターと一致します。
80+ 以下は、ファンタジー百科事典の見出しをフォーマットする show ルールを定義する例です。
8681
8782``` example
8883#set heading(numbering: "(I)")
@@ -106,34 +101,29 @@ dragon, the manticore gets
106101extra style points.
107102```
108103
109- Like set rules, show rules are in effect until the end of the current block or
110- file.
104+ set ルールと同様に、show ルールは、現在のブロック内またはファイルの終わりまで有効です。
111105
112- Instead of a function, the right-hand side of a show rule can also take a
113- literal string or content block that should be directly substituted for the
114- element. And apart from a function, the left-hand side of a show rule can also
115- take a number of other _ selectors_ that define what to apply the transformation
116- to:
106+ 関数の代わりに、show ルールのコロン右側は、エレメントに直接置換されるべきリテラル文字列またはコンテンツブロックを取ることもできます。
107+ また show ルールのコロン左側は、以下に示すように、変換を適用する対象を定義する _ セレクター_ を受け取ることができます。
117108
118- - ** Everything:** ` {show: rest => ..} ` \
119- Transform everything after the show rule. This is useful to apply a more
120- complex layout to your whole document without wrapping everything in a giant
121- function call.
109+ - ** すべて:** ` {show: rest => ..} ` \
110+ showルール以降のすべてを変換する。
111+ 個別の関数呼び出しでラップすることなく、複雑なレイアウトを文書全体に適用するのに便利です。
122112
123- - ** Text: ** ` {show "Text": ..} ` \
124- Style, transform or replace text.
113+ - ** 文字列: ** ` {show "Text": ..} ` \
114+ 設定した文字列に対して、スタイル変更や文字の置き換えを行います。
125115
126- - ** Regex: ** ` {show regex("\w+"): ..} ` \
127- Select and transform text with a regular expression for even more flexibility.
128- See the documentation of the [ ` regex ` type ] ( $regex ) for details.
116+ - ** 正規表現: ** ` {show regex("\w+"): ..} ` \
117+ 正規表現にマッチする文字列に対して、スタイル変更や文字の置き換えを行います。
118+ 正規表現については [ regex 関数 ] ( $regex ) を参照してください。
129119
130- - ** Function with fields: ** ` {show heading.where(level: 1): ..} ` \
131- Transform only elements that have the specified fields. For example, you might
132- want to only change the style of level-1 headings.
120+ - ** 関数やフィールド: ** ` {show heading.where(level: 1): ..} ` \
121+ 指定されたフィールドを持つエレメントのみを変換します。
122+ たとえば、レベル 1 の見出しのスタイルだけを変更したい場合などに有効です。
133123
134- - ** Label: ** ` {show <intro>: ..} ` \
135- Select and transform elements that have the specified label. See the
136- documentation of the [ ` label ` type ] ( $label ) for more details.
124+ - ** ラベル: ** ` {show <intro>: ..} ` \
125+ 指定されたラベルを持つエレメントに対して適用する。
126+ ラベルについては [ labelタイプ ] ( $label ) を参照してください。
137127
138128``` example
139129#show "Project": smallcaps
0 commit comments