Hexadecimal Escape Sequences in Typst Templates for Quarto Documents

A Guide to Including Special Characters Like Dollar Signs in Typst Templates

Author

James Balamuta

Published

June 19, 2025

Abstract

Special characters in Typst templates can be surprisingly tricky—try including a dollar sign in your Typst document template for Quarto and you might face cryptic compilation errors that standard escaping won’t fix. This post demonstrates a bulletproof solution using hexadecimal escape sequences like \u{24} for $, walks through Typst’s ASCII table tool for finding hex codes, and provides a practical reference for the most commonly problematic characters in template development.

When working with Typst templates in Quarto, you’ll inevitably encounter special characters that have syntactic meaning in Typst. The dollar sign ($) is a perfect example—essential for monetary values but problematic in templates.

If you’re new to creating Typst templates, the official Typst tutorial provides an excellent introduction, and the Quarto documentation covers how to integrate custom Typst templates with your Quarto workflow.

Special Characters in Typst Templates

While creating Typst templates with $ for monetary values, you might run into issueswhen trying to include the dollar sign directly in your template. Instinctively, you might aim to try:

let price = "$50.00"        // Direct usage
let price = "\$50.00"       // Backslash escape

Both approaches can trigger compilation errors like:

Error compiling template "/var/folders/b0/vt_1hj2d6yd8myx9lwh81pww0000gn/T/quarto-session5507649961f270aa/3d2f7f01b738eb46/6c7df7952a282c34/typst-template.typ" (line 64, column 24):
unexpected "\""
expecting letter or digit or "()"

Escape Sequences with Hexadecimal Values to the Rescue

The reliable workaround is to use hexadecimal escape sequences. For the dollar sign ($), you can use:

\u{24}

This tells Typst to render the Unicode character with hexadecimal code 24, which corresponds to the dollar sign ($). This is one of two types of escape sequences available in Typst. The other type is single-character escapes, which is used for single characters like \n for newline or \t for tab. You can find the reference page for both escape sequence types in the official Typst syntax documentation.

With this in mind, we can define a variable in a Typst template like this:

let price = "\u{24}50.00"   // Hexadecimal escape

Finding Hexadecimal Codes

But, how do you find a hexadecimal code for a character like the dollar sign? Use Typst’s handy ASCII table tool to look up characters and their hexadecimal codes:

https://typst.app/tools/ascii-table/

Let’s walk through how to find the hexadecimal code for the dollar sign ($):

  1. Open a web browser and navigate to Typst’s ASCII table tool linked above
  2. Type into the search bar or scan for your desired character (in our case, $)
  3. Look at the hexadecimal value shown (you’ll see something like 0x24)
  4. Take the part after 0x (so 24 from 0x24)
  5. Use it in the escape sequence: \u{24}

Screenshot of Typst's ASCII table tool showing the full character grid. The dollar sign ($) is highlighted with a blue border in the table, displaying its hex code 0x24 and decimal value 36. The table shows various ASCII characters organized in rows, including control characters (NUL, SOH, STX, etc.) and printable characters (letters, numbers, and symbols like !, ", #, $, %, &).

Alternatively, we can click on the character in the ASCII table, which will open a dialog showing the character’s details, including its Typst escape sequence.

Screenshot of Typst's ASCII table tool showing a popup dialog for the dollar sign character. The popup displays 'Dollar Sign' as the title with the $ symbol prominently shown, along with various encoding formats: Binary (00100100), Unicode Codepoint (U+0024), Typst Escape (\u{24}), HTML Escape ($), JavaScript Escape (\x24), UTF-8 (0x24), and UTF-16 (0x0024). The hex code 0x24 and decimal value 36 are shown below the symbol.

Including the Hexadecimal Codes in Typst

With the hexadecimal escape sequence, you can now safely include the dollar sign in your Typst templates without worrying about compilation errors. Some practical examples of when escape characters come in handy to use in Typst are when defining variables, using them in functions, or including them in text.

For financial content like budgets or prices, you can define variables with the dollar sign like this:

let budget = "Budget: \u{24}1,500 - \u{24}2,000"

For dynamic content like user inputs or calculations, you can use it in functions to format monetary values:

#let currency(amount) = box[\u{24}#amount]
#currency("99.99")  // Renders: $99.99

For everyday usage in text, you can include it directly in your content:

Contact us at info\u{40}company.com for pricing starting at \u{24}50.

Other Useful Escape Sequences

For my own work, I often need to include other special characters in Typst templates. Here are some common characters and their hexadecimal escape sequences that I find useful:

Character Hex Code Escape Sequence
# (hash) 23 \u{23}
$ (dollar) 24 \u{24}
@ (at sign) 40 \u{40}
% (percent) 25 \u{25}
& (ampersand) 26 \u{26}

Fin

Hexadecimal escape sequences (\u{XX}) are your reliable solution when standard escaping fails in Typst templates. They work consistently across different template contexts and eliminate parsing ambiguities. Bookmark Typst’s ASCII table for quick hex code lookups, and your template compilation errors will become a thing of the past.

Reference