TypstDocumentation

rawElement
Question mark

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.

Example

Adding `rbx` to `rcx` gives
the desired result.

```rust
fn main() {
    println!("Hello World!");
}
```
Preview

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. 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 is rendered as is, in particular, there are no escape sequences.

Parameters
Question mark

text
string
RequiredPositional
Question mark

The raw text.

You can also use raw blocks creatively to create custom syntaxes for your automations.

// Parse numbers in raw blocks with the
// `mydsl` tag and sum them up.
#show raw.where(lang: "mydsl"): it => {
  let sum = 0
  for part in it.text.split("+") {
    sum += int(part.trim())
  }
  sum
}

```mydsl
1 + 2 + 3 + 4 + 5
```
Preview

block
boolean
Settable
Question mark

Whether the raw text is displayed as a separate block.

Default: false

// Display inline code in a small box
// that retains the correct baseline.
#show raw.where(block: false): box.with(
  fill: luma(240),
  inset: (x: 3pt, y: 0pt),
  outset: (y: 3pt),
  radius: 2pt,
)

// Display block code in a larger block
// with more padding.
#show raw.where(block: true): block.with(
  fill: luma(240),
  inset: 10pt,
  radius: 4pt,
)

With `rg`, you can search through your files quickly.

```bash
rg "Hello World"
```
Preview

lang
none or string
Settable
Question mark

The language to syntax-highlight in.

Apart from typical language tags known from Markdown, this supports the "typ" and "typc" tags for Typst markup and Typst code, respectively.

Default: none

```typ
This is *Typst!*
```
Preview

align
alignment
Settable
Question mark

The horizontal alignment that each line in a raw block should have. This option is ignored if this is not a raw block (if specified block: false or single backticks were used in markup mode).

By default, this is set to start, meaning that raw text is aligned towards the start of the text direction inside the block by default, regardless of the current context's alignment (allowing you to center the raw block itself without centering the text inside it, for example).

Default: start

#set raw(align: center)

```typc
let f(x) = x
code = "centered"
```
Preview