diff --git a/crates/typst-library/src/model/par.rs b/crates/typst-library/src/model/par.rs index cf31b5195..7897c6cce 100644 --- a/crates/typst-library/src/model/par.rs +++ b/crates/typst-library/src/model/par.rs @@ -10,71 +10,71 @@ use crate::introspection::{Count, CounterUpdate, Locatable}; use crate::layout::{Em, HAlignment, Length, OuterHAlignment}; use crate::model::Numbering; -/// A logical subdivison of textual content. -/// -/// Typst automatically collects _inline-level_ elements into paragraphs. -/// Inline-level elements include [text], [horizontal spacing]($h), -/// [boxes]($box), and [inline equations]($math.equation). -/// -/// To separate paragraphs, use a blank line (or an explicit [`parbreak`]). -/// Paragraphs are also automatically interrupted by any block-level element -/// (like [`block`], [`place`], or anything that shows itself as one of these). -/// -/// The `par` element is primarily used in set rules to affect paragraph -/// properties, but it can also be used to explicitly display its argument as a -/// paragraph of its own. Then, the paragraph's body may not contain any -/// block-level content. -/// -/// # Boxes and blocks -/// As explained above, usually paragraphs only contain inline-level content. -/// However, you can integrate any kind of block-level content into a paragraph -/// by wrapping it in a [`box`]. -/// -/// Conversely, you can separate inline-level content from a paragraph by -/// wrapping it in a [`block`]. In this case, it will not become part of any -/// paragraph at all. Read the following section for an explanation of why that -/// matters and how it differs from just adding paragraph breaks around the -/// content. -/// -/// # What becomes a paragraph? -/// When you add inline-level content to your document, Typst will automatically -/// wrap it in paragraphs. However, a typical document also contains some text -/// that is not semantically part of a paragraph, for example in a heading or -/// caption. -/// -/// The rules for when Typst wraps inline-level content in a paragraph are as -/// follows: -/// -/// - All text at the root of a document is wrapped in paragraphs. -/// -/// - Text in a container (like a `block`) is only wrapped in a paragraph if the -/// container holds any block-level content. If all of the contents are -/// inline-level, no paragraph is created. -/// -/// In the laid-out document, it's not immediately visible whether text became -/// part of a paragraph. However, it is still important for various reasons: -/// -/// - Certain paragraph styling like `first-line-indent` will only apply to -/// proper paragraphs, not any text. Similarly, `par` show rules of course -/// only trigger on paragraphs. -/// -/// - A proper distinction between paragraphs and other text helps people who -/// rely on assistive technologies (such as screen readers) navigate and -/// understand the document properly. Currently, this only applies to HTML -/// export since Typst does not yet output accessible PDFs, but support for -/// this is planned for the near future. -/// -/// - HTML export will generate a `
` tag only for paragraphs. -/// -/// When creating custom reusable components, you can and should take charge -/// over whether Typst creates paragraphs. By wrapping text in a [`block`] -/// instead of just adding paragraph breaks around it, you can force the absence -/// of a paragraph. Conversely, by adding a [`parbreak`] after some content in a -/// container, you can force it to become a paragraph even if it's just one -/// word. This is, for example, what [non-`tight`]($list.tight) lists do to -/// force their items to become paragraphs. -/// -/// # Example +/// テキストコンテンツの論理的な区分。 +/// +/// Typstは _インラインレベル_ の要素を自動的に段落にまとめます。 +/// インラインレベルの要素には、[テキスト]($text)、 [水平方向の空白]($h)、 +/// [ボックス]($box)、[インライン数式]($math.equation)が含まれます。 +/// +/// 段落を区切るには、空行(または明示的な[`parbreak`])を使用します。 +/// 段落は、任意のブロックレベルの要素 +/// ([`block`]、[`place`]、またはこれらのいずれかとして表示されるもの)によっても自動的に中断されます。 +/// +/// `par`要素は主にsetルールにおいて段落のプロパティに影響を与えるために使用されますが、 +/// その引数を明示的に独立した段落として表示するためにも使用できます。 +/// その場合、 +/// その段落の本文にはブロックレベルのコンテンツを含めることはできません。 +/// +/// # ボックスとブロック +/// 上記の通り、通常、段落はインラインレベルのコンテンツのみを含みます。 +/// しかし、[`box`]でラップすることで、 +/// あらゆる種類のブロックレベルのコンテンツを段落に組み込むことができます。 +/// +/// 逆に、インラインレベルのコンテンツを[`block`]でラップすることにより、 +/// コンテンツを段落から分離できます。 +/// この場合、そのコンテンツはどの段落にも属さなくなります。 +/// なぜこれが重要なのか、また単にコンテンツの前後に段落区切りを追加することとどう異なるのかについては、 +/// 次のセクションをお読みください。 +/// +/// # 何が段落になるのか? +/// インラインレベルのコンテンツをドキュメントに追加すると、 +/// Typstは自動的にそれを段落でラップします。 +/// しかし、一般的なドキュメントには、見出しやキャプションなど、 +/// 意味的に段落の一部ではないテキストも含まれます。 +/// +/// Typstがインラインレベルのコンテンツを +/// 段落でラップするルールは次の通りです。 +/// +/// - ドキュメントのルート(最上位)にある全てのテキストは段落でラップされます。 +/// +/// - コンテナ(`block`など)内のテキストは、 +/// そのコンテナにブロックレベルのコンテンツが含まれている場合にのみ段落でラップされます。 +/// コンテンツが全てインラインレベルである場合は、段落は作成されません。 +/// +/// 組版された文書では、テキストが段落の一部になったかどうかはすぐにはわかりません。 +/// しかし、いくつかの理由からこれは依然として重要です。 +/// +/// - `first-line-indent`などの特定の段落スタイルは正式な段落に対してのみ適用され、 +/// 任意のテキストには適用されません。 +/// 同様に、`par`に対するshowルールももちろん段落に対してのみ適用されます。 +/// +/// - 段落とその他のテキストを適切に区別することは、 +/// スクリーンリーダーなどの支援技術を利用する人々が文書を正しく読み進め、理解するのに役立ちます。 +/// 現在はTypstがアクセシブルなPDFをまだ出力しないため、 +/// この仕組みはHTMLエクスポートにのみ適用されますが、 +/// 近い将来PDFへのサポートも計画されています。 +/// +/// - HTMLエクスポートでは、段落に対してのみ`
`タグが生成されます。
+///
+/// 独自の再利用可能なコンポーネントを作成する際には、
+/// Typstが段落を作成するかどうかを自分で制御できますし、制御すべきです。
+/// テキストを単に段落区切りで囲むのではなく、
+/// `block`で囲むことで段落を作成させないようにできます。
+/// 逆に、コンテナ内のコンテンツの後に`parbreak`を追加することで、
+/// たとえ1つの単語であっても段落にすることができます。
+/// これは、[非タイト]($list.tight)リストがその項目を強制的に段落にさせるために行う手法の例です。
+///
+/// # 例
/// ```example
/// #set par(
/// first-line-indent: 1em,
@@ -95,55 +95,55 @@ use crate::model::Numbering;
/// ```
#[elem(scope, title = "Paragraph")]
pub struct ParElem {
- /// The spacing between lines.
- ///
- /// Leading defines the spacing between the [bottom edge]($text.bottom-edge)
- /// of one line and the [top edge]($text.top-edge) of the following line. By
- /// default, these two properties are up to the font, but they can also be
- /// configured manually with a text set rule.
- ///
- /// By setting top edge, bottom edge, and leading, you can also configure a
- /// consistent baseline-to-baseline distance. You could, for instance, set
- /// the leading to `{1em}`, the top-edge to `{0.8em}`, and the bottom-edge
- /// to `{-0.2em}` to get a baseline gap of exactly `{2em}`. The exact
- /// distribution of the top- and bottom-edge values affects the bounds of
- /// the first and last line.
+ /// 行間。
+ ///
+ /// leadingは、
+ /// ある行の[下端]($text.bottom-edge)と次の行の[上端]($text.top-edge)との間隔を定義します。
+ /// デフォルトでは、これら2つのプロパティはフォントによって決まりますが、
+ /// テキストのsetルールを使用して手動で設定することもできます。
+ ///
+ /// top-edge、bottom-edge、およびleadingを設定することで、
+ /// ベースライン間の距離を一定に揃えることも可能です。
+ /// 例えば、leadingを `{1em}`、top-edgeを`{0.8em}`、
+ /// bottom-edgeを `{-0.2em}` に設定すると、
+ /// ちょうど`{2em}`のベースライン間隔になります。
+ /// top-edgeとbottom-edgeの値の正確な配分が最初の行と最後の行の境界に影響を与えます。
#[resolve]
#[default(Em::new(0.65).into())]
pub leading: Length,
- /// The spacing between paragraphs.
+ /// 段落間の間隔。
///
- /// Just like leading, this defines the spacing between the bottom edge of a
- /// paragraph's last line and the top edge of the next paragraph's first
- /// line.
+ /// leadingと同様に、
+ /// このプロパティはある段落の最終行の下端と、
+ /// 次の段落の最初の行の上端との間隔を定義します。
///
- /// When a paragraph is adjacent to a [`block`] that is not a paragraph,
- /// that block's [`above`]($block.above) or [`below`]($block.below) property
- /// takes precedence over the paragraph spacing. Headings, for instance,
- /// reduce the spacing below them by default for a better look.
+ /// 段落が、段落ではない[`block`]に隣接している場合、
+ /// そのブロックの[`above`]($block.above)または[`below`]($block.below)プロパティが段落間の間隔よりも優先されます。
+ /// 例えば、
+ /// 見出しはより良い外観のためにデフォルトで下側の間隔を狭くしています。
#[resolve]
#[default(Em::new(1.2).into())]
pub spacing: Length,
- /// Whether to justify text in its line.
+ /// 行内でテキストを両端揃えするかどうか。
///
- /// Hyphenation will be enabled for justified paragraphs if the
- /// [text function's `hyphenate` property]($text.hyphenate) is set to
- /// `{auto}` and the current language is known.
+ /// [text関数の`hyphenate`プロパティ]($text.hyphenate)が`{auto}`に設定され、
+ /// かつ現在の言語が認識されている場合、
+ /// 両端揃えが行われた段落ではハイフネーションが有効になります。
///
- /// Note that the current [alignment]($align.alignment) still has an effect
- /// on the placement of the last line except if it ends with a
- /// [justified line break]($linebreak.justify).
+ /// 最後の行が[両端揃えされた改行]($linebreak.justify)で終わらない限り、
+ /// 現在の[alignment]($align.alignment)は依然として
+ /// 最終行の配置に影響を与えることに注意してください。
#[default(false)]
pub justify: bool,
- /// How to determine line breaks.
+ /// 改行位置の決定方法
///
- /// When this property is set to `{auto}`, its default value, optimized line
- /// breaks will be used for justified paragraphs. Enabling optimized line
- /// breaks for ragged paragraphs may also be worthwhile to improve the
- /// appearance of the text.
+ /// このプロパティがデフォルトの`{auto}`に設定されている場合、
+ /// 両端揃えされた段落に対して最適化された改行が行われます。
+ /// また、段落が不揃いであっても最適化された改行を有効にすることで、
+ /// テキストの見栄えが向上することがあります。
///
/// ```example
/// #set page(width: 207pt)
@@ -161,24 +161,24 @@ pub struct ParElem {
/// ```
pub linebreaks: Smart