情報 / Info
当サイトは、Typst GmbHの許諾を得て、日本語コミュニティ「Typst Japanese Community」がTypst v0.14.0の公式ドキュメントを翻訳したものです。誤訳や古い情報が含まれている可能性があるため、公式ドキュメントとの併用を推奨します。翻訳の改善やサイトの機能向上について、GitHubでのIssueやPull Requestを歓迎します。コミュニティにご興味のある方はDiscordサーバー「くみはんクラブ」にぜひご参加ください。
This site provides a Japanese translation of the Typst v0.14.0 documentation maintained by the "Typst Japanese Community" with permission from Typst GmbH. We recommend using this alongside the official documentation. We welcome contributions through Issues and Pull Requests on our GitHub repository for both translation improvements and website enhancements. Feel free to join our Discord server "Kumihan Club".
部分的に翻訳済み

このページは部分的に翻訳されています。一部原文の内容が含まれています。

スタイル設定

Typstには柔軟なスタイル設定機能を持ち、出力される文書に対して自動的に任意のスタイル設定を適用します。 setルールでは要素の基本プロパティを設定できます。 しかし、やりたいこと全てに対応するプロパティがあらかじめ実装されているとは限りません。 このため、Typstは要素の外観を完全に再定義できるshowルールもサポートしています。

setルール

setルールを使うと、要素の外観をカスタマイズできます。 これらは、setキーワード(マークアップでは#set)を前に置いた要素関数への関数呼び出しとして記述されます。 setルールに指定できるのは、その関数のオプションのパラメーターだけです。 どのパラメーターがオプションであるかは、各関数のドキュメントを参照してください。 以下の例では、2つのsetルールを使って、フォント見出し番号を変更しています。

#set heading(numbering: "I.")
#set text(
  font: "New Computer Modern"
)

= Introduction
With set rules, you can style
your document.
Preview

setルールは、そのまま記述するとファイルの最後まで適用されます。 ブロックの中にネストすると、そのブロックの終わりまで適用されます。 ブロックを使えば、setルールの効果を指定した部分に限定できます。 以下では、contentブロックを用いてスコープすることで、特定のリストのスタイルのみを変更しています。

This list is affected: #[
  #set list(marker: [--])
  - Dash
]

This one is not:
- Bullet
Preview

ときには、setルールを条件付きで設定したい場合もあるでしょう。 その場合にはset-ifルールを使用します。

#let task(body, critical: false) = {
  set text(red) if critical
  [- #body]
}

#task(critical: true)[Food today?]
#task(critical: false)[Work deadline]
Preview

showルール

showルールを使えば、特定の種類の要素の外観を詳細に設定できます。 showルールの基本的な記述方法は、show-setルールです。 show キーワードの後に セレクター、コロン、setルールと続けて記述します。 セレクターの基本的な記述方法は 要素関数を置くことであり、setルールは選択された要素にのみ適用されます。 下の例では、見出しは紺色になり、他のテキストは黒色のままです。

#show heading: set text(navy)

= This is navy-blue
But this stays black.
Preview

With show-set rules you can mix and match properties from different functions to achieve many different effects. But they still limit you to what is predefined in Typst. For maximum flexibility, you can instead write a transformational show rule that defines how to format an element from scratch. To write such a show rule, replace the set rule after the colon with an arbitrary function. This function receives the element in question and can return arbitrary content. The function is often defined inline as it => .. using the unnamed function syntax. The function's parameter is typically named it by convention.

The available fields on the element passed to the function match the parameters of the respective element function. Below, we define a show rule that formats headings for a fantasy encyclopedia.

The show rule itself adds tilde characters around the title (these must be escaped with a backslash because otherwise they would indicate a non-breaking space), emphasizes the title with italics, and then displays the heading counter after the title.

For this example, we also wanted center alignment and a different font. While we could've added these set rules into the existing show rule, we instead added them as separate show-set rules. This is good practice because now these rules can still be overridden by later show-set rules in the document, keeping styling composable. In contrast, set rules within a transformational show rule would not be overridable anymore.

#set heading(numbering: "(I)")
#show heading: set align(center)
#show heading: set text(font: "Inria Serif")
#show heading: it => block[
  \~
  #emph(it.body)
  #counter(heading).display(it.numbering)
  \~
]

= Dragon
With a base health of 15, the dragon is the most
powerful creature.

= Manticore
While less powerful than the dragon, the manticore
gets extra style points.
Preview

setルールと同様に、showルールは、現在のブロック内またはファイルの終わりまで有効です。

関数の代わりに、showルールのコロン右側は、要素に直接置換されるべきリテラル文字列またはコンテンツブロックを取ることもできます。 またshowルールのコロン左側は、以下に示すように、変換を適用する対象を定義するセレクターを受け取ることができます。

  • 全て: show: rest => ..
    showルール以降の全てを変換する。 個別の関数呼び出しでラップすることなく、複雑なレイアウトを文書全体に適用するのに便利です。

  • 文字列: show "Text": ..
    設定した文字列に対して、スタイル変更や文字の置き換えを行います。

  • 正規表現: show regex("\w+"): ..
    正規表現にマッチする文字列に対して、スタイル変更や文字の置き換えを行います。 正規表現についてはregex 関数を参照してください。

  • 関数やフィールド: show heading.where(level: 1): ..
    指定されたフィールドを持つ要素のみを変換します。 例えば、レベル1の見出しのスタイルだけを変更したい場合などに有効です。

  • ラベル: show <intro>: ..
    指定されたラベルを持つ要素に対して適用する。 ラベルについてはlabelタイプを参照してください。

#show "Project": smallcaps
#show "badly": "great"

We started Project in 2019
and are still working on it.
Project is progressing badly.
Preview
原文(英語)を開く

検索