Apr 18, 2026 1.2 KB typst
1= Code
2
3Typst renders code blocks with syntax highlighting.
4
5== Inline code
6
7Use backticks for inline code: `let x = 42` or `SELECT * FROM users`.
8
9== Code blocks
10
11A raw block with language hint for syntax highlighting:
12
13```rust
14fn fibonacci(n: u64) -> u64 {
15 match n {
16 0 => 0,
17 1 => 1,
18 _ => fibonacci(n - 1) + fibonacci(n - 2),
19 }
20}
21```
22
23```python
24def quicksort(arr):
25 if len(arr) <= 1:
26 return arr
27 pivot = arr[len(arr) // 2]
28 left = [x for x in arr if x < pivot]
29 middle = [x for x in arr if x == pivot]
30 right = [x for x in arr if x > pivot]
31 return quicksort(left) + middle + quicksort(right)
32```
33
34```typescript
35async function fetchData<T>(url: string): Promise<T> {
36 const response = await fetch(url);
37 if (!response.ok) {
38 throw new Error(`HTTP ${response.status}`);
39 }
40 return response.json();
41}
42```
43
44```sql
45SELECT users.name, COUNT(orders.id) AS order_count
46FROM users
47LEFT JOIN orders ON users.id = orders.user_id
48WHERE users.created_at > '2024-01-01'
49GROUP BY users.name
50HAVING COUNT(orders.id) > 5
51ORDER BY order_count DESC;
52```
53
54== Plain code blocks
55
56Without a language hint, code renders without highlighting:
57
58```
59this is a plain code block
60no syntax highlighting applied
61just monospace text
62```