注意 当サイトは、Typst v0.11.1 公式ドキュメントを、日本語コミュニティが非公式に翻訳したものです。誤訳・未訳・古い情報が含まれている可能性があるため、公式ドキュメント との併用を推奨します。このサイトの内容に誤りを発見された方は、GitHubリポジトリまでご報告を頂けましたら幸いです。我々のコミュニティにご興味のある方は、ぜひ非公式Discordサーバー「くみはんクラブ」にご参加ください。
Warning: This site provides an unofficial translation of the Typst v0.11.1 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 ドキュメント日本語版

bytes

A sequence of bytes.

This is conceptually similar to an array of integers between 0 and 255, but represented much more efficiently. You can iterate over it using a for loop.

You can convert

When reading data from a file, you can decide whether to load it as a string or as raw bytes.

#bytes((123, 160, 22, 0)) \
#bytes("Hello 😃")

#let data = read(
  "rhino.png",
  encoding: none,
)

// Magic bytes.
#array(data.slice(0, 4)) \
#str(data.slice(1, 4))
Preview

Constructor
If a type has a constructor, you can call it like a function to create a new value of the type.

Converts a value to bytes.

bytes() -> bytes
#bytes("Hello 😃") \
#bytes((123, 160, 22, 0))
Preview

value
str bytes array
RequiredPositional
Positional parameters are specified in order, without names.

The value that should be converted to bytes.

Definitions
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 length in bytes.

self.len(
) -> int

at

Returns the byte at the specified index. Returns the default value if the index is out of bounds or fails with an error if no default value was specified.

self.at() -> any

index
int
RequiredPositional
Positional parameters are specified in order, without names.

The index at which to retrieve the byte.

default
any

A default value to return if the index is out of bounds.

slice

Extracts a subslice of the bytes. Fails with an error if the start or index is out of bounds.

self.slice() -> bytes

start
int
RequiredPositional
Positional parameters are specified in order, without names.

The start index (inclusive).

end
none int
Positional
Positional parameters are specified in order, without names.

The end index (exclusive). If omitted, the whole slice until the end is extracted.

Default:none

count
int

The number of items to extract. This is equivalent to passing start + count as the end position. Mutually exclusive with end.