注意 当サイトは、Typst v0.12.0 公式ドキュメントを、日本語コミュニティが非公式に翻訳したものです。誤訳・未訳・古い情報が含まれている可能性があるため、公式ドキュメント との併用を推奨します。このサイトの内容に誤りを発見された方は、GitHubリポジトリまでご報告を頂けましたら幸いです。我々のコミュニティにご興味のある方は、ぜひ非公式Discordサーバー「くみはんクラブ」にご参加ください。
Warning: This site provides an unofficial translation of the Typst v0.12.0 documentation by the Japanese Community. Please note that there may be some inaccuracies, untranslated sections or outdated information. We highly recommend referring to the latest official documentation as well. If you find any errors in the content, please let us know through our GitHub repository. If you are interested in our community, feel free to join our unofficial Discord server, “Kumihan Club.”
Typst ドキュメント日本語版

dictionary

A map from string keys to values.

You can construct a dictionary by enclosing comma-separated key: value pairs in parentheses. The values do not have to be of the same type. Since empty parentheses already yield an empty array, you have to use the special (:) syntax to create an empty dictionary.

A dictionary is conceptually similar to an array, but it is indexed by strings instead of integers. You can access and create dictionary entries with the .at() method. If you know the key statically, you can alternatively use field access notation (.key) to access the value. Dictionaries can be added with the + operator and joined together. To check whether a key is present in the dictionary, use the in keyword.

You can iterate over the pairs in a dictionary using a for loop. This will iterate in the order the pairs were inserted / declared.

Example

#let dict = (
  name: "Typst",
  born: 2019,
)

#dict.name \
#(dict.launch = 20)
#dict.len() \
#dict.keys() \
#dict.values() \
#dict.at("born") \
#dict.insert("city", "Berlin ")
#("name" in dict)
Preview

コンストラクタ
If a type has a constructor, you can call it like a function to create a new value of the type.

Converts a value into a dictionary.

Note that this function is only intended for conversion of a dictionary-like value to a dictionary, not for creation of a dictionary from individual pairs. Use the dictionary syntax (key: value) instead.

dictionary() -> dictionary
#dictionary(sys).at("version")
Preview

value
module
RequiredPositional
Positional parameters are specified in order, without names.

The value that should be converted to a dictionary.

定義
Functions and types and can have associated definitions. These are accessed by specifying the function or type, followed by a period, and then the definition's name.

len

The number of pairs in the dictionary.

self.len(
) -> int

at

Returns the value associated with the specified key in the dictionary. May be used on the left-hand side of an assignment if the key is already present in the dictionary. Returns the default value if the key is not part of the dictionary or fails with an error if no default value was specified.

self.at() -> any

key
str
RequiredPositional
Positional parameters are specified in order, without names.

The key at which to retrieve the item.

default
any

A default value to return if the key is not part of the dictionary.

insert

Inserts a new pair into the dictionary. If the dictionary already contains this key, the value is updated.

self.insert(
str, any,
)

key
str
RequiredPositional
Positional parameters are specified in order, without names.

The key of the pair that should be inserted.

value
any
RequiredPositional
Positional parameters are specified in order, without names.

The value of the pair that should be inserted.

remove

Removes a pair from the dictionary by key and return the value.

self.remove() -> any

key
str
RequiredPositional
Positional parameters are specified in order, without names.

The key of the pair to remove.

default
any

A default value to return if the key does not exist.

keys

Returns the keys of the dictionary as an array in insertion order.

self.keys(
) -> array

values

Returns the values of the dictionary as an array in insertion order.

self.values(
) -> array

pairs

Returns the keys and values of the dictionary as an array of pairs. Each pair is represented as an array of length two.

self.pairs(
) -> array