Typst Fumadocs

Raw Text / Code

Documentation for the `raw` function.

Raw text with optional syntax highlighting.

Displays the text verbatim and in a monospace font. This is typically used to embed computer code into your document.

Note that text given to this element cannot contain arbitrary formatting, such as *strong* or _emphasis_, as it is displayed verbatim. If you'd like to display any kind of content with a monospace font, instead of using raw, you should change its font to a monospace font using the text function.

Example

Loading compiler...

You can also construct a raw element programmatically from a string (and provide the language tag via the optional lang argument).

Loading compiler...

Syntax

This function also has dedicated syntax. You can enclose text in 1 or 3+ backticks (```) to make it raw. Two backticks produce empty raw text. This works both in markup and code.

When you use three or more backticks, you can additionally specify a language tag for syntax highlighting directly after the opening backticks. Within raw blocks, everything (except for the language tag, if applicable) is rendered as is, in particular, there are no escape sequences.

The language tag ends at the first whitespace or backtick. If your text starts with something that looks like an identifier, but no syntax highlighting is needed, start the text with a single space (which will be trimmed) or use the single backtick syntax. If your text should start or end with a backtick, put a space before or after it (it will be trimmed).

If no syntax highlighting is available by default for your specified language tag (or if you want to override the built-in definition), you may provide a custom syntax specification file to the syntaxes field.

Styling

By default, the raw element uses the DejaVu Sans Mono font (included with Typst), with a smaller font size of 0.8em (that is, 80% of the global font size). This is because monospace fonts tend to be visually larger than non-monospace fonts.

You can customize these properties with show-set rules:

Loading compiler...

In addition, you can customize the syntax highlighting colors by setting a custom theme through the theme field.

For complete customization of the appearance of a raw block, a show rule on raw.line could be helpful, such as to add line numbers.

Note that, in raw text, typesetting features like hyphenation, overhang, CJK-Latin spacing (and justification for raw blocks) will be disabled by default.

#raw(
  text,
  block: bool,
  lang: none | str,
  align: alignment,
  syntaxes: str | bytes | array,
  theme: none | auto | str | bytes,
  tab-size: int
) -> content

Parameters

Prop

Type

Definitions

A highlighted line of raw text.

This is a helper element that is synthesized by raw elements.

It allows you to access various properties of the line, such as the line number, the raw non-highlighted text, the highlighted text, and whether it is the first or last line of the raw block.

#raw.line(
  number,
  count,
  text,
  body
) -> content

Parameters

Prop

Type

On this page