@@ -21,21 +21,18 @@ use crate::model::{FigureElem, FootnoteElem, HeadingElem, Numbering, NumberingPa
21
21
use crate :: routines:: Routines ;
22
22
use crate :: World ;
23
23
24
- /// Counts through pages, elements, and more.
24
+ /// ページや要素などの数え上げ。
25
25
///
26
- /// With the counter function, you can access and modify counters for pages,
27
- /// headings, figures, and more. Moreover, you can define custom counters for
28
- /// other things you want to count.
26
+ /// counter関数を用いることで、ページや見出し、図表などのカウンターにアクセスしたり、修正を加えたりできます。
27
+ /// さらに、独自のカウンターを定義して、他のものを数えることもできます。
29
28
///
30
- /// Since counters change throughout the course of the document, their current
31
- /// value is _contextual._ It is recommended to read the chapter on [context]
32
- /// before continuing here.
29
+ /// カウンターは文書全体を通して変化するため、現在のその値は _コンテキスト依存_ です。
30
+ /// 先に進む前に[コンテキスト]($context)の章を読むことをおすすめします。
33
31
///
34
- /// # Accessing a counter { #accessing }
35
- /// To access the raw value of a counter, we can use the [`get`]($counter.get)
36
- /// function. This function returns an [array]: Counters can have multiple
37
- /// levels (in the case of headings for sections, subsections, and so on), and
38
- /// each item in the array corresponds to one level.
32
+ /// # カウンターへのアクセス { #accessing }
33
+ /// [`get`]($counter.get)関数を用いると、生のカウンター値にアクセスできます。
34
+ /// この関数は[配列]($array)を返します。
35
+ /// カウンターは(節や小節などの見出しの場合に)複数のレベルを持ち、配列の各アイテムが1つのレベルに対応します。
39
36
///
40
37
/// ```example
41
38
/// #set heading(numbering: "1.")
@@ -45,11 +42,10 @@ use crate::World;
45
42
/// #context counter(heading).get()
46
43
/// ```
47
44
///
48
- /// # Displaying a counter { #displaying }
49
- /// Often, we want to display the value of a counter in a more human-readable
50
- /// way. To do that, we can call the [`display`]($counter.display) function on
51
- /// the counter. This function retrieves the current counter value and formats
52
- /// it either with a provided or with an automatically inferred [numbering].
45
+ /// # カウンターの表示 { #displaying }
46
+ /// しばしば、カウンター値をより人間が読みやすい形で表示したいことがあります。
47
+ /// そうするために、カウンターの[`display`]($counter.display)関数を呼び出します。
48
+ /// この関数は現在のカウンター値を取得し、与えられた形式か自動的に推論された[番号付け]($numbering)で整形します。
53
49
///
54
50
/// ```example
55
51
/// #set heading(numbering: "1.")
@@ -67,21 +63,19 @@ use crate::World;
67
63
/// }
68
64
/// ```
69
65
///
70
- /// # Modifying a counter { #modifying }
71
- /// To modify a counter, you can use the `step` and `update` methods:
66
+ /// # カウンターの変更 { #modifying }
67
+ /// `step`および `update`メソッドを用いてカウンターを変更できます。
72
68
///
73
- /// - The `step` method increases the value of the counter by one. Because
74
- /// counters can have multiple levels , it optionally takes a `level`
75
- /// argument. If given, the counter steps at the given depth.
69
+ /// - `step`メソッドは、カウンター値を1増やします。
70
+ /// カウンターは複数のレベルを持つことがあるため、オプションで `level`引数を取ります。
71
+ /// `level`が指定された場合、指定された深さのカウンター値を増やします。
76
72
///
77
- /// - The `update` method allows you to arbitrarily modify the counter. In its
78
- /// basic form, you give it an integer (or an array for multiple levels). For
79
- /// more flexibility, you can instead also give it a function that receives
80
- /// the current value and returns a new value.
73
+ /// - `update`メソッドを用いるとカウンターを任意に変更できます。
74
+ /// 通常の形式では、整数(あるいは複数レベルに対しては配列を)与えます。
75
+ /// 現在の値を受け取り新しい値を返す関数を代わりに与えると、より柔軟にできます。
81
76
///
82
- /// The heading counter is stepped before the heading is displayed, so
83
- /// `Analysis` gets the number seven even though the counter is at six after the
84
- /// second update.
77
+ /// 見出しのカウンターは見出しが表示される前にインクリメントされます。
78
+ /// そのため、2回目のupdateの後にカウンターが6であったとしても`Analysis`は7になります。
85
79
///
86
80
/// ```example
87
81
/// #set heading(numbering: "1.")
@@ -103,11 +97,11 @@ use crate::World;
103
97
/// }
104
98
/// ```
105
99
///
106
- /// # Page counter
107
- /// The page counter is special. It is automatically stepped at each pagebreak.
108
- /// But like other counters, you can also step it manually. For example, you
109
- /// could have Roman page numbers for your preface, then switch to Arabic page
110
- /// numbers for your main content and reset the page counter to one.
100
+ /// # ページカウンター
101
+ /// ページカウンターは特別です。
102
+ /// 改ページ毎に値がインクリメントされます。
103
+ /// しかし、他のカウンターと同様に手動でインクリメントもできます。
104
+ /// 例えば、前書きではローマ数字のページ番号を使い、メインのコンテンツではアラビア数字のページ番号に変更し、ページカウンターを1にリセットできます。
111
105
///
112
106
/// ```example
113
107
/// >>> #set page(
@@ -130,9 +124,9 @@ use crate::World;
130
124
/// Arabic numbers.
131
125
/// ```
132
126
///
133
- /// # Custom counters
134
- /// To define your own counter, call the `counter` function with a string as a
135
- /// key. This key identifies the counter globally.
127
+ /// # カスタムカウンター
128
+ /// 独自のカウンターを定義するには文字列をキーとして `counter`関数を呼び出します。
129
+ /// このキーはグローバルにカウンターを識別します。
136
130
///
137
131
/// ```example
138
132
/// #let mine = counter("mycounter")
@@ -143,13 +137,10 @@ use crate::World;
143
137
/// #context mine.display()
144
138
/// ```
145
139
///
146
- /// # How to step
147
- /// When you define and use a custom counter, in general, you should first step
148
- /// the counter and then display it. This way, the stepping behaviour of a
149
- /// counter can depend on the element it is stepped for. If you were writing a
150
- /// counter for, let's say, theorems, your theorem's definition would thus first
151
- /// include the counter step and only then display the counter and the theorem's
152
- /// contents.
140
+ /// # インクリメント方法
141
+ /// カスタムカウンターを定義して使用する場合、一般にカウンターを最初にインクリメントしてから表示するべきです。
142
+ /// こうすることで、カウンターのインクリメント動作をインクリメントする要素に依存させることができます。
143
+ /// 例えばtheoremのカウンターを実装する場合、theoremの定義では最初にカウンターのstepを書いてインクリメントを行い、その後に初めてカウンターとtheoremの内容を表示します。
153
144
///
154
145
/// ```example
155
146
/// #let c = counter("theorem")
@@ -163,20 +154,17 @@ use crate::World;
163
154
/// #theorem[$2 < 3$]
164
155
/// ```
165
156
///
166
- /// The rationale behind this is best explained on the example of the heading
167
- /// counter: An update to the heading counter depends on the heading's level. By
168
- /// stepping directly before the heading, we can correctly step from `1` to
169
- /// `1.1` when encountering a level 2 heading. If we were to step after the
170
- /// heading, we wouldn't know what to step to.
157
+ /// この背景にある考え方は、見出しカウンターの例で説明するのが最適です。
158
+ /// 見出しカウンターの更新は、その見出しのレベルに依存します。
159
+ /// 見出しの直前にインクリメントすることで、第2レベルの見出しがあるときに`1`から`1.1`へと正しく更新できます。
160
+ /// もし見出しの後にインクリメントする場合、どれをインクリメントするのかわかりません。
171
161
///
172
- /// Because counters should always be stepped before the elements they count,
173
- /// they always start at zero. This way, they are at one for the first display
174
- /// (which happens after the first step).
162
+ /// カウンターは常に数える要素の前にインクリメントすべきなため、必ず0始まりです。
163
+ /// このようにして、(最初のインクリメントの後に)最初に表示されるときには1になります。
175
164
///
176
- /// # Time travel
177
- /// Counters can travel through time! You can find out the final value of the
178
- /// counter before it is reached and even determine what the value was at any
179
- /// particular location in the document.
165
+ /// # タイムトラベル
166
+ /// カウンターはタイムトラベルができます!
167
+ /// カウンターの最終的な値を実際に到達する前に知ることができますし、文書の任意の特定の場所での値がどうなっていたかさえ決定できます。
180
168
///
181
169
/// ```example
182
170
/// #let mine = counter("mycounter")
@@ -197,10 +185,9 @@ use crate::World;
197
185
/// #mine.step()
198
186
/// ```
199
187
///
200
- /// # Other kinds of state { #other-state }
201
- /// The `counter` type is closely related to [state] type. Read its
202
- /// documentation for more details on state management in Typst and why it
203
- /// doesn't just use normal variables for counters.
188
+ /// # その他の状態 { #other-state }
189
+ /// `counter`型は[state]型と密接に関係しています。
190
+ /// Typstにおける状態管理のより詳しい詳細と、なぜ単に普通の変数をカウンターに用いないのかについてはstateのドキュメントを参照してください。
204
191
#[ ty( scope) ]
205
192
#[ derive( Debug , Clone , PartialEq , Hash ) ]
206
193
pub struct Counter ( CounterKey ) ;
@@ -404,27 +391,26 @@ impl Counter {
404
391
405
392
#[ scope]
406
393
impl Counter {
407
- /// Create a new counter identified by a key.
394
+ /// キーで識別される新しいカウンターの作成。
408
395
#[ func( constructor) ]
409
396
pub fn construct (
410
- /// The key that identifies this counter.
397
+ /// このcounterを識別するキー。
411
398
///
412
- /// - If it is a string, creates a custom counter that is only affected
413
- /// by manual updates,
414
- /// - If it is the [`page`] function, counts through pages,
415
- /// - If it is a [selector], counts through elements that matches with the
416
- /// selector. For example,
417
- /// - provide an element function: counts elements of that type,
418
- /// - provide a [`{<label>}`]($label): counts elements with that label.
399
+ /// - 文字列の場合、手動更新の場合にのみ影響を受けるカスタムカウンターを作成します
400
+ /// - [`page`]関数の場合、改ページに合わせてカウントされます
401
+ /// - [セレクター]($selector)の場合、セレクターにマッチする要素が現れるたびにカウントされます。
402
+ /// 例えば
403
+ /// - 要素関数が与えられた場合、その型を持つ要素がカウントされます
404
+ /// - [`{<label>}`]($label)が与えられた場合、そのラベルを持つ要素がカウントされます
419
405
key : CounterKey ,
420
406
) -> Counter {
421
407
Self :: new ( key)
422
408
}
423
409
424
- /// Retrieves the value of the counter at the current location. Always
425
- /// returns an array of integers, even if the counter has just one number.
410
+ /// 現在の位置でのカウンターの値を取得。
411
+ /// カウンターが1つの数値しか持たない場合でも、常に整数の配列を返します。
426
412
///
427
- /// This is equivalent to `{counter.at(here())}`.
413
+ /// これは `{counter.at(here())}`と等価です。
428
414
#[ func( contextual) ]
429
415
pub fn get (
430
416
& self ,
@@ -436,29 +422,24 @@ impl Counter {
436
422
self . at_loc ( engine, loc)
437
423
}
438
424
439
- /// Displays the current value of the counter with a numbering and returns
440
- /// the formatted output.
425
+ /// 番号付けされたカウンターの現在の値の表示および戻り値としての整形された出力。
441
426
#[ func( contextual) ]
442
427
pub fn display (
443
428
self ,
444
429
engine : & mut Engine ,
445
430
context : Tracked < Context > ,
446
431
span : Span ,
447
- /// A [numbering pattern or a function]($numbering), which specifies how
448
- /// to display the counter. If given a function, that function receives
449
- /// each number of the counter as a separate argument. If the amount of
450
- /// numbers varies, e.g. for the heading argument, you can use an
451
- /// [argument sink]($arguments).
432
+ /// カウンターをどのように表示するか指定する[番号付けのパターンまたは関数]($numbering)。
433
+ /// 関数が与えられた場合、カウンターの各数値が別々の引数として関数に渡されます。
434
+ /// 見出しの番号付けを関数指定するときなどの、引数の数値の数が変化する場合は[引数シンク]($arguments)が使用できます。
452
435
///
453
- /// If this is omitted or set to `{auto}`, displays the counter with the
454
- /// numbering style for the counted element or with the pattern
455
- /// `{"1.1"}` if no such style exists.
436
+ /// 省略されるか`{auto}`に設定された場合、カウントする要素に設定された番号付け形式を用いてカウンターを表示します。
437
+ /// そのようなスタイルが存在しない場合は`{"1.1"}`というパターン指定でカウンターが表示されます。
456
438
#[ default]
457
439
numbering : Smart < Numbering > ,
458
- /// If enabled, displays the current and final top-level count together.
459
- /// Both can be styled through a single numbering pattern. This is used
460
- /// by the page numbering property to display the current and total
461
- /// number of pages when a pattern like `{"1 / 1"}` is given.
440
+ /// 有効化された場合、トップレベルのカウンターの現在値と最終値を一緒に表示します。
441
+ /// 両者のスタイル設定は1つの番号付けパターンで指定できます。
442
+ /// これは、`{"1 / 1"}`のようなパターンが与えられたときに、現在のページ番号と全ページ数を表示するためにページの番号付けプロパティによって使用されます。
462
443
#[ named]
463
444
#[ default( false ) ]
464
445
both : bool ,
@@ -467,27 +448,26 @@ impl Counter {
467
448
self . display_impl ( engine, loc, numbering, both, context. styles ( ) . ok ( ) )
468
449
}
469
450
470
- /// Retrieves the value of the counter at the given location. Always returns
471
- /// an array of integers, even if the counter has just one number.
451
+ /// 指定された位置のカウンター値の取得。
452
+ /// カウンターが1つの数値しか持たない場合でも、常に整数の配列を返します。
472
453
///
473
- /// The `selector` must match exactly one element in the document. The most
474
- /// useful kinds of selectors for this are [labels]($label) and
475
- /// [locations]($location).
454
+ /// `selector`は文書中で厳密に1つだけの要素にマッチしなければなりません。
455
+ /// この目的で最も便利なセレクターは[ラベル]($label)と[位置]($location)です。
476
456
#[ func( contextual) ]
477
457
pub fn at (
478
458
& self ,
479
459
engine : & mut Engine ,
480
460
context : Tracked < Context > ,
481
461
span : Span ,
482
- /// The place at which the counter's value should be retrieved.
462
+ /// カウンター値を取得する場所。
483
463
selector : LocatableSelector ,
484
464
) -> SourceResult < CounterState > {
485
465
let loc = selector. resolve_unique ( engine. introspector , context) . at ( span) ?;
486
466
self . at_loc ( engine, loc)
487
467
}
488
468
489
- /// Retrieves the value of the counter at the end of the document. Always
490
- /// returns an array of integers, even if the counter has just one number.
469
+ /// 文書の終わりでのカウンター値の取得。
470
+ /// カウンターが1つの数値しか持たない場合でも、常に整数の配列を返します。
491
471
#[ func( contextual) ]
492
472
pub fn final_ (
493
473
& self ,
@@ -505,38 +485,34 @@ impl Counter {
505
485
Ok ( state)
506
486
}
507
487
508
- /// Increases the value of the counter by one.
488
+ /// カウンター値を1増加。
509
489
///
510
- /// The update will be in effect at the position where the returned content
511
- /// is inserted into the document. If you don't put the output into the
512
- /// document, nothing happens! This would be the case, for example, if you
513
- /// write `{let _ = counter(page).step()}`. Counter updates are always
514
- /// applied in layout order and in that case, Typst wouldn't know when to
515
- /// step the counter.
490
+ /// updateは、返り値であるコンテンツが文書中に挿入された位置で適用されます。
491
+ /// 文書中に出力がなければ何も起こりません!
492
+ /// 例えば`{let _ = counter(page).step()}`と書いた場合が、この何も起きないときに該当します。
493
+ /// カウンターの更新は常にレイアウト順に適用され、Typstはいつカウンターをインクリメントするのか知りません。
516
494
#[ func]
517
495
pub fn step (
518
496
self ,
519
497
span : Span ,
520
- /// The depth at which to step the counter. Defaults to `{1}`.
498
+ /// カウンターをインクリメントする深さ。
499
+ /// デフォルトは`{1}`です。
521
500
#[ named]
522
501
#[ default( NonZeroUsize :: ONE ) ]
523
502
level : NonZeroUsize ,
524
503
) -> Content {
525
504
self . update ( span, CounterUpdate :: Step ( level) )
526
505
}
527
506
528
- /// Updates the value of the counter.
507
+ /// カウンター値の更新。
529
508
///
530
- /// Just like with `step`, the update only occurs if you put the resulting
531
- /// content into the document.
509
+ /// `step`と同様に、生成されたコンテンツが文書中に配置されたときに限り更新が行われます。
532
510
#[ func]
533
511
pub fn update (
534
512
self ,
535
513
span : Span ,
536
- /// If given an integer or array of integers, sets the counter to that
537
- /// value. If given a function, that function receives the previous
538
- /// counter value (with each number as a separate argument) and has to
539
- /// return the new value (integer or array).
514
+ /// 整数または整数の配列が与えられた場合、カウンターをその値に設定します。
515
+ /// 関数が与えられた場合、その関数は(各数値を別々の引数として)前のカウンターの値を受け取り、新しい値を(整数または配列で)返さなければなりません。
540
516
update : CounterUpdate ,
541
517
) -> Content {
542
518
CounterUpdateElem :: new ( self . 0 , update) . pack ( ) . spanned ( span)
0 commit comments