@vetala/vetala 0.1.0-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @vetala/vetala might be problematic. Click here for more details.
- package/CONTRIBUTING.md +77 -0
- package/LICENSE +184 -0
- package/README.md +136 -0
- package/THIRD_PARTY_LICENSES.md +17 -0
- package/dist/src/agent.d.ts +30 -0
- package/dist/src/agent.js +216 -0
- package/dist/src/agent.js.map +1 -0
- package/dist/src/approvals.d.ts +18 -0
- package/dist/src/approvals.js +81 -0
- package/dist/src/approvals.js.map +1 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +87 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/config.d.ts +12 -0
- package/dist/src/config.js +183 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/context-memory.d.ts +7 -0
- package/dist/src/context-memory.js +96 -0
- package/dist/src/context-memory.js.map +1 -0
- package/dist/src/ink/command-suggestions.d.ts +7 -0
- package/dist/src/ink/command-suggestions.js +179 -0
- package/dist/src/ink/command-suggestions.js.map +1 -0
- package/dist/src/ink/ink-terminal-ui.d.ts +36 -0
- package/dist/src/ink/ink-terminal-ui.js +79 -0
- package/dist/src/ink/ink-terminal-ui.js.map +1 -0
- package/dist/src/ink/repl-app.d.ts +9 -0
- package/dist/src/ink/repl-app.js +789 -0
- package/dist/src/ink/repl-app.js.map +1 -0
- package/dist/src/ink/transcript-cards.d.ts +6 -0
- package/dist/src/ink/transcript-cards.js +24 -0
- package/dist/src/ink/transcript-cards.js.map +1 -0
- package/dist/src/path-policy.d.ts +11 -0
- package/dist/src/path-policy.js +67 -0
- package/dist/src/path-policy.js.map +1 -0
- package/dist/src/process-utils.d.ts +13 -0
- package/dist/src/process-utils.js +52 -0
- package/dist/src/process-utils.js.map +1 -0
- package/dist/src/repl.d.ts +9 -0
- package/dist/src/repl.js +13 -0
- package/dist/src/repl.js.map +1 -0
- package/dist/src/sarvam/client.d.ts +15 -0
- package/dist/src/sarvam/client.js +208 -0
- package/dist/src/sarvam/client.js.map +1 -0
- package/dist/src/sarvam/models.d.ts +2 -0
- package/dist/src/sarvam/models.js +7 -0
- package/dist/src/sarvam/models.js.map +1 -0
- package/dist/src/search-provider.d.ts +6 -0
- package/dist/src/search-provider.js +8 -0
- package/dist/src/search-provider.js.map +1 -0
- package/dist/src/session-store.d.ts +19 -0
- package/dist/src/session-store.js +318 -0
- package/dist/src/session-store.js.map +1 -0
- package/dist/src/skills/runtime.d.ts +26 -0
- package/dist/src/skills/runtime.js +317 -0
- package/dist/src/skills/runtime.js.map +1 -0
- package/dist/src/skills/types.d.ts +25 -0
- package/dist/src/skills/types.js +2 -0
- package/dist/src/skills/types.js.map +1 -0
- package/dist/src/terminal-ui.d.ts +29 -0
- package/dist/src/terminal-ui.js +236 -0
- package/dist/src/terminal-ui.js.map +1 -0
- package/dist/src/tools/filesystem.d.ts +2 -0
- package/dist/src/tools/filesystem.js +622 -0
- package/dist/src/tools/filesystem.js.map +1 -0
- package/dist/src/tools/git.d.ts +2 -0
- package/dist/src/tools/git.js +326 -0
- package/dist/src/tools/git.js.map +1 -0
- package/dist/src/tools/index.d.ts +6 -0
- package/dist/src/tools/index.js +21 -0
- package/dist/src/tools/index.js.map +1 -0
- package/dist/src/tools/registry.d.ts +15 -0
- package/dist/src/tools/registry.js +59 -0
- package/dist/src/tools/registry.js.map +1 -0
- package/dist/src/tools/shell.d.ts +2 -0
- package/dist/src/tools/shell.js +97 -0
- package/dist/src/tools/shell.js.map +1 -0
- package/dist/src/tools/skill.d.ts +3 -0
- package/dist/src/tools/skill.js +130 -0
- package/dist/src/tools/skill.js.map +1 -0
- package/dist/src/tools/web.d.ts +3 -0
- package/dist/src/tools/web.js +144 -0
- package/dist/src/tools/web.js.map +1 -0
- package/dist/src/types.d.ts +236 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/workspace-trust.d.ts +3 -0
- package/dist/src/workspace-trust.js +31 -0
- package/dist/src/workspace-trust.js.map +1 -0
- package/dist/src/xdg.d.ts +9 -0
- package/dist/src/xdg.js +77 -0
- package/dist/src/xdg.js.map +1 -0
- package/package.json +57 -0
- package/skill/agents-md-generator/SKILL.md +75 -0
- package/skill/agents-md-generator/references/agents_md_template.md +160 -0
- package/skill/agents-md-generator/references/loc_measurement.md +67 -0
- package/skill/agents-md-generator/references/monorepo_detection.md +78 -0
- package/skill/agents-md-generator/references/monorepo_strategy.md +60 -0
- package/skill/agents-md-generator/references/read_only_commands.md +151 -0
- package/skill/agents-md-generator/references/update_strategy.md +160 -0
- package/skill/agents-md-generator/references/working_agreements.md +53 -0
- package/skill/biz-opportunity-scout/SKILL.md +53 -0
- package/skill/biz-opportunity-scout/references/competitive_analysis.md +84 -0
- package/skill/biz-opportunity-scout/references/market_sizing.md +68 -0
- package/skill/biz-opportunity-scout/references/pmf_indicators.md +94 -0
- package/skill/biz-opportunity-scout/references/report_template.md +243 -0
- package/skill/biz-opportunity-scout/references/unit_economics.md +97 -0
- package/skill/code-review/SKILL.md +86 -0
- package/skill/code-review/references/change_analysis.md +116 -0
- package/skill/code-review/references/git_operations.md +115 -0
- package/skill/code-review/references/impact_detection.md +149 -0
- package/skill/code-review/references/output_format.md +137 -0
- package/skill/code-review/references/severity_criteria.md +100 -0
- package/skill/code-security-audit/SKILL.md +123 -0
- package/skill/code-security-audit/references/audit_process.md +277 -0
- package/skill/code-security-audit/references/remediation_patterns.md +599 -0
- package/skill/code-security-audit/references/report_format.md +391 -0
- package/skill/code-security-audit/references/security_domains.md +830 -0
- package/skill/code-security-audit/references/vulnerability_patterns.md +813 -0
- package/skill/composition-patterns/SKILL.md +83 -0
- package/skill/composition-patterns/rules/architecture-avoid-boolean-props.md +100 -0
- package/skill/composition-patterns/rules/architecture-compound-components.md +112 -0
- package/skill/composition-patterns/rules/patterns-children-over-render-props.md +87 -0
- package/skill/composition-patterns/rules/patterns-explicit-variants.md +100 -0
- package/skill/composition-patterns/rules/react19-no-forwardref.md +42 -0
- package/skill/composition-patterns/rules/state-context-interface.md +191 -0
- package/skill/composition-patterns/rules/state-decouple-implementation.md +113 -0
- package/skill/composition-patterns/rules/state-lift-state.md +125 -0
- package/skill/deploy-to-vercel/SKILL.md +293 -0
- package/skill/deploy-to-vercel/resources/deploy-sandbox.sh +301 -0
- package/skill/deploy-to-vercel/resources/deploy.sh +301 -0
- package/skill/doc/SKILL_GUIDELINES.md +138 -0
- package/skill/git-workflow/SKILL.md +94 -0
- package/skill/git-workflow/references/advanced-git.md +632 -0
- package/skill/git-workflow/references/branching-strategies.md +344 -0
- package/skill/git-workflow/references/ci-cd-integration.md +683 -0
- package/skill/git-workflow/references/code-quality-tools.md +351 -0
- package/skill/git-workflow/references/commit-conventions.md +439 -0
- package/skill/git-workflow/references/github-releases.md +288 -0
- package/skill/git-workflow/references/pull-request-workflow.md +773 -0
- package/skill/git-workflow/scripts/verify-git-workflow.sh +263 -0
- package/skill/jetbrains-vmoptions/SKILL.md +51 -0
- package/skill/jetbrains-vmoptions/references/common-options.md +357 -0
- package/skill/jetbrains-vmoptions/references/gc-options.md +350 -0
- package/skill/jetbrains-vmoptions/references/memory-options.md +339 -0
- package/skill/jetbrains-vmoptions/references/prerequisite-check.md +65 -0
- package/skill/kysely-converter/SKILL.md +62 -0
- package/skill/kysely-converter/references/delete.md +323 -0
- package/skill/kysely-converter/references/insert.md +386 -0
- package/skill/kysely-converter/references/operators.md +331 -0
- package/skill/kysely-converter/references/select.md +1000 -0
- package/skill/kysely-converter/references/update.md +349 -0
- package/skill/kysely-converter/references/window_function.md +537 -0
- package/skill/react-best-practices/SKILL.md +131 -0
- package/skill/react-best-practices/rules/advanced-event-handler-refs.md +55 -0
- package/skill/react-best-practices/rules/advanced-init-once.md +42 -0
- package/skill/react-best-practices/rules/advanced-use-latest.md +39 -0
- package/skill/react-best-practices/rules/async-api-routes.md +38 -0
- package/skill/react-best-practices/rules/async-defer-await.md +80 -0
- package/skill/react-best-practices/rules/async-dependencies.md +51 -0
- package/skill/react-best-practices/rules/async-parallel.md +28 -0
- package/skill/react-best-practices/rules/async-suspense-boundaries.md +99 -0
- package/skill/react-best-practices/rules/bundle-barrel-imports.md +59 -0
- package/skill/react-best-practices/rules/bundle-conditional.md +31 -0
- package/skill/react-best-practices/rules/bundle-defer-third-party.md +49 -0
- package/skill/react-best-practices/rules/bundle-dynamic-imports.md +35 -0
- package/skill/react-best-practices/rules/bundle-preload.md +50 -0
- package/skill/react-best-practices/rules/client-event-listeners.md +74 -0
- package/skill/react-best-practices/rules/client-localstorage-schema.md +71 -0
- package/skill/react-best-practices/rules/client-passive-event-listeners.md +48 -0
- package/skill/react-best-practices/rules/client-swr-dedup.md +56 -0
- package/skill/react-best-practices/rules/js-batch-dom-css.md +107 -0
- package/skill/react-best-practices/rules/js-cache-function-results.md +80 -0
- package/skill/react-best-practices/rules/js-cache-property-access.md +28 -0
- package/skill/react-best-practices/rules/js-cache-storage.md +70 -0
- package/skill/react-best-practices/rules/js-combine-iterations.md +32 -0
- package/skill/react-best-practices/rules/js-early-exit.md +50 -0
- package/skill/react-best-practices/rules/js-hoist-regexp.md +45 -0
- package/skill/react-best-practices/rules/js-index-maps.md +37 -0
- package/skill/react-best-practices/rules/js-length-check-first.md +49 -0
- package/skill/react-best-practices/rules/js-min-max-loop.md +82 -0
- package/skill/react-best-practices/rules/js-set-map-lookups.md +24 -0
- package/skill/react-best-practices/rules/js-tosorted-immutable.md +57 -0
- package/skill/react-best-practices/rules/rendering-activity.md +26 -0
- package/skill/react-best-practices/rules/rendering-animate-svg-wrapper.md +47 -0
- package/skill/react-best-practices/rules/rendering-conditional-render.md +40 -0
- package/skill/react-best-practices/rules/rendering-content-visibility.md +38 -0
- package/skill/react-best-practices/rules/rendering-hoist-jsx.md +46 -0
- package/skill/react-best-practices/rules/rendering-hydration-no-flicker.md +82 -0
- package/skill/react-best-practices/rules/rendering-hydration-suppress-warning.md +30 -0
- package/skill/react-best-practices/rules/rendering-svg-precision.md +28 -0
- package/skill/react-best-practices/rules/rendering-usetransition-loading.md +75 -0
- package/skill/react-best-practices/rules/rerender-defer-reads.md +39 -0
- package/skill/react-best-practices/rules/rerender-dependencies.md +45 -0
- package/skill/react-best-practices/rules/rerender-derived-state-no-effect.md +40 -0
- package/skill/react-best-practices/rules/rerender-derived-state.md +29 -0
- package/skill/react-best-practices/rules/rerender-functional-setstate.md +74 -0
- package/skill/react-best-practices/rules/rerender-lazy-state-init.md +58 -0
- package/skill/react-best-practices/rules/rerender-memo-with-default-value.md +38 -0
- package/skill/react-best-practices/rules/rerender-memo.md +44 -0
- package/skill/react-best-practices/rules/rerender-move-effect-to-event.md +45 -0
- package/skill/react-best-practices/rules/rerender-simple-expression-in-memo.md +35 -0
- package/skill/react-best-practices/rules/rerender-transitions.md +40 -0
- package/skill/react-best-practices/rules/rerender-use-ref-transient-values.md +73 -0
- package/skill/react-best-practices/rules/server-after-nonblocking.md +73 -0
- package/skill/react-best-practices/rules/server-auth-actions.md +96 -0
- package/skill/react-best-practices/rules/server-cache-lru.md +41 -0
- package/skill/react-best-practices/rules/server-cache-react.md +76 -0
- package/skill/react-best-practices/rules/server-dedup-props.md +65 -0
- package/skill/react-best-practices/rules/server-hoist-static-io.md +142 -0
- package/skill/react-best-practices/rules/server-parallel-fetching.md +83 -0
- package/skill/react-best-practices/rules/server-serialization.md +38 -0
- package/skill/react-native-skills/SKILL.md +115 -0
- package/skill/react-native-skills/rules/animation-derived-value.md +53 -0
- package/skill/react-native-skills/rules/animation-gesture-detector-press.md +95 -0
- package/skill/react-native-skills/rules/animation-gpu-properties.md +65 -0
- package/skill/react-native-skills/rules/design-system-compound-components.md +66 -0
- package/skill/react-native-skills/rules/fonts-config-plugin.md +71 -0
- package/skill/react-native-skills/rules/imports-design-system-folder.md +68 -0
- package/skill/react-native-skills/rules/js-hoist-intl.md +61 -0
- package/skill/react-native-skills/rules/list-performance-callbacks.md +44 -0
- package/skill/react-native-skills/rules/list-performance-function-references.md +132 -0
- package/skill/react-native-skills/rules/list-performance-images.md +53 -0
- package/skill/react-native-skills/rules/list-performance-inline-objects.md +97 -0
- package/skill/react-native-skills/rules/list-performance-item-expensive.md +94 -0
- package/skill/react-native-skills/rules/list-performance-item-memo.md +82 -0
- package/skill/react-native-skills/rules/list-performance-item-types.md +104 -0
- package/skill/react-native-skills/rules/list-performance-virtualize.md +67 -0
- package/skill/react-native-skills/rules/monorepo-native-deps-in-app.md +46 -0
- package/skill/react-native-skills/rules/monorepo-single-dependency-versions.md +63 -0
- package/skill/react-native-skills/rules/navigation-native-navigators.md +188 -0
- package/skill/react-native-skills/rules/react-compiler-destructure-functions.md +50 -0
- package/skill/react-native-skills/rules/react-compiler-reanimated-shared-values.md +48 -0
- package/skill/react-native-skills/rules/react-state-dispatcher.md +91 -0
- package/skill/react-native-skills/rules/react-state-fallback.md +56 -0
- package/skill/react-native-skills/rules/react-state-minimize.md +65 -0
- package/skill/react-native-skills/rules/rendering-no-falsy-and.md +74 -0
- package/skill/react-native-skills/rules/rendering-text-in-text-component.md +36 -0
- package/skill/react-native-skills/rules/scroll-position-no-state.md +82 -0
- package/skill/react-native-skills/rules/state-ground-truth.md +80 -0
- package/skill/react-native-skills/rules/ui-expo-image.md +66 -0
- package/skill/react-native-skills/rules/ui-image-gallery.md +104 -0
- package/skill/react-native-skills/rules/ui-measure-views.md +78 -0
- package/skill/react-native-skills/rules/ui-menus.md +174 -0
- package/skill/react-native-skills/rules/ui-native-modals.md +77 -0
- package/skill/react-native-skills/rules/ui-pressable.md +61 -0
- package/skill/react-native-skills/rules/ui-safe-area-scroll.md +65 -0
- package/skill/react-native-skills/rules/ui-scrollview-content-inset.md +45 -0
- package/skill/react-native-skills/rules/ui-styling.md +87 -0
- package/skill/react-vite-guide/SKILL.md +101 -0
- package/skill/react-vite-guide/references/composition-patterns.md +709 -0
- package/skill/react-vite-guide/references/performance-optimization.md +1222 -0
- package/skill/react-vite-guide/references/vite-specific.md +385 -0
- package/skill/react-vite-guide/references/web-interface.md +146 -0
- package/skill/skill-maker/SKILL.md +52 -0
- package/skill/skill-maker/references/content_spec.md +67 -0
- package/skill/skill-maker/references/frontmatter_spec.md +96 -0
- package/skill/skill-maker/references/input_validation.md +90 -0
- package/skill/skill-maker/references/skill_structure.md +74 -0
- package/skill/system-prompt-creator/SKILL.md +50 -0
- package/skill/system-prompt-creator/references/data_format_selection.md +135 -0
- package/skill/system-prompt-creator/references/multi_prompt_architecture.md +386 -0
- package/skill/system-prompt-creator/references/prompt_structure.md +140 -0
- package/skill/system-prompt-creator/references/quality_criteria.md +83 -0
- package/skill/typst-creator/SKILL.md +51 -0
- package/skill/typst-creator/references/layout.md +401 -0
- package/skill/typst-creator/references/math.md +297 -0
- package/skill/typst-creator/references/scripting.md +237 -0
- package/skill/typst-creator/references/styling.md +217 -0
- package/skill/typst-creator/references/syntax.md +234 -0
- package/skill/web-design-guidelines/SKILL.md +35 -0
- package/terminal.png +0 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
# Typst Scripting Reference
|
|
2
|
+
|
|
3
|
+
Typst includes a built-in scripting language for logic and data manipulation.
|
|
4
|
+
|
|
5
|
+
## Variables
|
|
6
|
+
|
|
7
|
+
Variables store values for reuse throughout your document. All bindings are immutable by default but can be reassigned with `=`.
|
|
8
|
+
|
|
9
|
+
### Let Bindings
|
|
10
|
+
|
|
11
|
+
Use `let` to create named bindings. Variable names can contain letters, numbers, and hyphens but must start with a letter.
|
|
12
|
+
|
|
13
|
+
```typst
|
|
14
|
+
#let name = "Alice"
|
|
15
|
+
#let count = 42
|
|
16
|
+
#let ratio = 3.14
|
|
17
|
+
#let active = true
|
|
18
|
+
#let items = (1, 2, 3)
|
|
19
|
+
#let person = (name: "Bob", age: 30)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Destructuring
|
|
23
|
+
|
|
24
|
+
Extract multiple values from arrays or dictionaries in a single statement. Pattern matching makes it easy to work with structured data.
|
|
25
|
+
|
|
26
|
+
```typst
|
|
27
|
+
#let (a, b) = (1, 2)
|
|
28
|
+
#let (name: n, age: a) = (name: "Alice", age: 25)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Data Types
|
|
32
|
+
|
|
33
|
+
Typst is dynamically typed with these built-in types. Type checking happens at runtime.
|
|
34
|
+
|
|
35
|
+
| Type | Example |
|
|
36
|
+
|------|---------|
|
|
37
|
+
| Integer | `42`, `-10` |
|
|
38
|
+
| Float | `3.14`, `1e-5` |
|
|
39
|
+
| String | `"hello"` |
|
|
40
|
+
| Boolean | `true`, `false` |
|
|
41
|
+
| Array | `(1, 2, 3)` |
|
|
42
|
+
| Dictionary | `(key: "value")` |
|
|
43
|
+
| Content | `[*bold*]` |
|
|
44
|
+
| None | `none` |
|
|
45
|
+
| Auto | `auto` |
|
|
46
|
+
|
|
47
|
+
## Arrays
|
|
48
|
+
|
|
49
|
+
Ordered collections of values. Arrays support functional methods like `map`, `filter`, and `fold` for data transformation.
|
|
50
|
+
|
|
51
|
+
```typst
|
|
52
|
+
#let arr = (1, 2, 3, 4, 5)
|
|
53
|
+
|
|
54
|
+
arr.len() // 5
|
|
55
|
+
arr.first() // 1
|
|
56
|
+
arr.last() // 5
|
|
57
|
+
arr.at(2) // 3
|
|
58
|
+
arr.slice(1, 3) // (2, 3)
|
|
59
|
+
arr.contains(3) // true
|
|
60
|
+
arr.map(x => x * 2) // (2, 4, 6, 8, 10)
|
|
61
|
+
arr.filter(x => x > 2) // (3, 4, 5)
|
|
62
|
+
arr.fold(0, (a, b) => a + b) // 15
|
|
63
|
+
arr.join(", ") // "1, 2, 3, 4, 5"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Dictionaries
|
|
67
|
+
|
|
68
|
+
Key-value pairs for structured data. Access values using dot notation or the `at()` method. Keys are always strings.
|
|
69
|
+
|
|
70
|
+
```typst
|
|
71
|
+
#let dict = (name: "Alice", age: 25)
|
|
72
|
+
|
|
73
|
+
dict.name // "Alice"
|
|
74
|
+
dict.at("age") // 25
|
|
75
|
+
dict.keys() // ("name", "age")
|
|
76
|
+
dict.values() // ("Alice", 25)
|
|
77
|
+
dict.pairs() // (("name", "Alice"), ("age", 25))
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Functions
|
|
81
|
+
|
|
82
|
+
Functions encapsulate reusable logic and can return both values and content. Define them with `let` and call them with parentheses.
|
|
83
|
+
|
|
84
|
+
### Function Definition
|
|
85
|
+
|
|
86
|
+
Basic functions use the arrow syntax. The expression after `=` becomes the return value.
|
|
87
|
+
|
|
88
|
+
```typst
|
|
89
|
+
#let greet(name) = [Hello, #name!]
|
|
90
|
+
#let add(a, b) = a + b
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Default Parameters
|
|
94
|
+
|
|
95
|
+
Provide fallback values with `:` syntax. Parameters with defaults become optional when calling the function.
|
|
96
|
+
|
|
97
|
+
```typst
|
|
98
|
+
#let greet(name, greeting: "Hello") = [#greeting, #name!]
|
|
99
|
+
#greet("Alice") // Hello, Alice!
|
|
100
|
+
#greet("Bob", greeting: "Hi") // Hi, Bob!
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Named Parameters
|
|
104
|
+
|
|
105
|
+
Use named arguments for clarity when calling functions with many parameters. Order doesn't matter for named arguments.
|
|
106
|
+
|
|
107
|
+
```typst
|
|
108
|
+
#let rect-area(width: 10, height: 5) = width * height
|
|
109
|
+
#rect-area() // 50
|
|
110
|
+
#rect-area(width: 20) // 100
|
|
111
|
+
#rect-area(height: 10) // 100
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Content Functions
|
|
115
|
+
|
|
116
|
+
Functions that return styled content are the foundation of Typst templates. Use set rules inside to affect only the function's scope.
|
|
117
|
+
|
|
118
|
+
```typst
|
|
119
|
+
#let highlight(body) = {
|
|
120
|
+
set text(fill: red)
|
|
121
|
+
body
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
#highlight[Important text]
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Control Flow
|
|
128
|
+
|
|
129
|
+
Control the execution flow with conditionals and loops. All control structures are expressions that return values.
|
|
130
|
+
|
|
131
|
+
### Conditionals
|
|
132
|
+
|
|
133
|
+
`if` expressions evaluate to their branch's value. Use for conditional content or computation.
|
|
134
|
+
|
|
135
|
+
```typst
|
|
136
|
+
#let x = 5
|
|
137
|
+
|
|
138
|
+
#if x > 0 {
|
|
139
|
+
[Positive]
|
|
140
|
+
} else if x < 0 {
|
|
141
|
+
[Negative]
|
|
142
|
+
} else {
|
|
143
|
+
[Zero]
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### For Loops
|
|
148
|
+
|
|
149
|
+
Iterate over arrays, ranges, or dictionary pairs. The loop body is evaluated for each element and results are joined.
|
|
150
|
+
|
|
151
|
+
```typst
|
|
152
|
+
#for i in range(5) {
|
|
153
|
+
[Item #i ]
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
#for (key, value) in (a: 1, b: 2) {
|
|
157
|
+
[#key: #value ]
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
#for item in ("apple", "banana", "cherry") {
|
|
161
|
+
list.item(item)
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### While Loops
|
|
166
|
+
|
|
167
|
+
Repeat while a condition is true. Be careful to ensure the condition eventually becomes false to avoid infinite loops.
|
|
168
|
+
|
|
169
|
+
```typst
|
|
170
|
+
#let i = 0
|
|
171
|
+
#while i < 3 {
|
|
172
|
+
[#i ]
|
|
173
|
+
i = i + 1
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Operators
|
|
178
|
+
|
|
179
|
+
Standard operators for arithmetic, comparison, and logical operations. Note that Typst uses `and`, `or`, `not` instead of symbols for logical operators.
|
|
180
|
+
|
|
181
|
+
| Operator | Description |
|
|
182
|
+
|----------|-------------|
|
|
183
|
+
| `+`, `-`, `*`, `/` | Arithmetic |
|
|
184
|
+
| `==`, `!=` | Equality |
|
|
185
|
+
| `<`, `>`, `<=`, `>=` | Comparison |
|
|
186
|
+
| `and`, `or`, `not` | Logical |
|
|
187
|
+
| `in`, `not in` | Membership |
|
|
188
|
+
| `+=` | Addition assignment |
|
|
189
|
+
|
|
190
|
+
## String Operations
|
|
191
|
+
|
|
192
|
+
Strings are immutable sequences of characters. Methods return new strings rather than modifying in place.
|
|
193
|
+
|
|
194
|
+
```typst
|
|
195
|
+
#let s = "Hello, World!"
|
|
196
|
+
|
|
197
|
+
s.len() // 13
|
|
198
|
+
s.contains("World") // true
|
|
199
|
+
s.starts-with("He") // true
|
|
200
|
+
s.ends-with("!") // true
|
|
201
|
+
s.replace("World", "Typst") // "Hello, Typst!"
|
|
202
|
+
s.split(", ") // ("Hello", "World!")
|
|
203
|
+
s.trim() // removes whitespace
|
|
204
|
+
upper(s) // "HELLO, WORLD!"
|
|
205
|
+
lower(s) // "hello, world!"
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Import and Modules
|
|
209
|
+
|
|
210
|
+
Organize code across files using imports. Import specific items or use `*` to import everything from a module.
|
|
211
|
+
|
|
212
|
+
```typst
|
|
213
|
+
// Import from file
|
|
214
|
+
#import "template.typ": conf, title
|
|
215
|
+
|
|
216
|
+
// Import all
|
|
217
|
+
#import "utils.typ": *
|
|
218
|
+
|
|
219
|
+
// Import with alias
|
|
220
|
+
#import "math.typ": formula as f
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Context
|
|
224
|
+
|
|
225
|
+
The `context` keyword provides access to document state that depends on location, such as page numbers, counters, and current styles. Required for introspection queries.
|
|
226
|
+
|
|
227
|
+
```typst
|
|
228
|
+
// Access current location/state
|
|
229
|
+
#context {
|
|
230
|
+
let current-page = counter(page).get()
|
|
231
|
+
[Page: #current-page.first()]
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Access set rule values
|
|
235
|
+
#set text(lang: "ko")
|
|
236
|
+
#context text.lang // "ko"
|
|
237
|
+
```
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# Typst Styling Reference
|
|
2
|
+
|
|
3
|
+
Typst uses set rules and show rules for styling documents.
|
|
4
|
+
|
|
5
|
+
## Function Parameters
|
|
6
|
+
|
|
7
|
+
These tables document the key styling functions. Use them with set rules to configure defaults or directly for inline styling.
|
|
8
|
+
|
|
9
|
+
### `text` Function
|
|
10
|
+
|
|
11
|
+
Controls typography including font family, size, color, and language settings. This is the most fundamental styling function for text appearance.
|
|
12
|
+
|
|
13
|
+
| Parameter | Type | Default | Description |
|
|
14
|
+
|-----------|------|---------|-------------|
|
|
15
|
+
| `font` | str \| array | `"libertinus serif"` | Font family or priority list |
|
|
16
|
+
| `size` | length | `11pt` | Font size |
|
|
17
|
+
| `fill` | color | `black` | Text color |
|
|
18
|
+
| `weight` | int \| str | `"regular"` | `"thin"`, `"light"`, `"regular"`, `"medium"`, `"bold"`, or 100-900 |
|
|
19
|
+
| `style` | str | `"normal"` | `"normal"`, `"italic"`, `"oblique"` |
|
|
20
|
+
| `lang` | str | `"en"` | Language code (e.g., `"ko"`, `"ja"`, `"zh"`) |
|
|
21
|
+
| `region` | str \| none | `none` | Region code (e.g., `"KR"`, `"US"`) |
|
|
22
|
+
| `hyphenate` | auto \| bool | `auto` | Enable hyphenation |
|
|
23
|
+
| `tracking` | length | `0pt` | Letter spacing |
|
|
24
|
+
| `spacing` | relative | `100%` | Word spacing |
|
|
25
|
+
| `baseline` | length | `0pt` | Baseline shift |
|
|
26
|
+
| `body` | content | required | Text content |
|
|
27
|
+
|
|
28
|
+
### `par` Function
|
|
29
|
+
|
|
30
|
+
Controls paragraph-level formatting including line spacing, justification, and indentation. Essential for achieving professional document layouts.
|
|
31
|
+
|
|
32
|
+
| Parameter | Type | Default | Description |
|
|
33
|
+
|-----------|------|---------|-------------|
|
|
34
|
+
| `leading` | length | `0.65em` | Line spacing (between lines) |
|
|
35
|
+
| `spacing` | length | `1.2em` | Paragraph spacing (between paragraphs) |
|
|
36
|
+
| `justify` | bool | `false` | Justify text |
|
|
37
|
+
| `linebreaks` | auto \| str | `auto` | `"simple"`, `"optimized"` |
|
|
38
|
+
| `first-line-indent` | length | `0pt` | First line indentation |
|
|
39
|
+
| `hanging-indent` | length | `0pt` | Hanging indent for subsequent lines |
|
|
40
|
+
| `body` | content | required | Paragraph content |
|
|
41
|
+
|
|
42
|
+
### `block` Function
|
|
43
|
+
|
|
44
|
+
Creates block-level containers with visual styling options like backgrounds, borders, and padding. Use for callout boxes, code blocks, or any content that needs visual separation.
|
|
45
|
+
|
|
46
|
+
| Parameter | Type | Default | Description |
|
|
47
|
+
|-----------|------|---------|-------------|
|
|
48
|
+
| `width` | auto \| relative | `auto` | Block width |
|
|
49
|
+
| `height` | auto \| relative | `auto` | Block height |
|
|
50
|
+
| `fill` | none \| color | `none` | Background color |
|
|
51
|
+
| `stroke` | none \| stroke | `none` | Border stroke |
|
|
52
|
+
| `radius` | relative \| dict | `(:)` | Corner radius |
|
|
53
|
+
| `inset` | relative \| dict | `(:)` | Inner padding |
|
|
54
|
+
| `outset` | relative \| dict | `(:)` | Outer expansion |
|
|
55
|
+
| `spacing` | relative | `1.2em` | Spacing around block (sets above & below) |
|
|
56
|
+
| `above` | auto \| relative | `auto` | Spacing above |
|
|
57
|
+
| `below` | auto \| relative | `auto` | Spacing below |
|
|
58
|
+
| `breakable` | bool | `true` | Allow page breaks |
|
|
59
|
+
| `clip` | bool | `false` | Clip overflow content |
|
|
60
|
+
| `sticky` | bool | `false` | Stick to next block |
|
|
61
|
+
| `body` | content | `none` | Block content |
|
|
62
|
+
|
|
63
|
+
## Set Rules
|
|
64
|
+
|
|
65
|
+
Set rules apply default property values to all instances of an element within a scope. They cascade like CSS and are the primary mechanism for consistent document styling.
|
|
66
|
+
|
|
67
|
+
### Syntax
|
|
68
|
+
|
|
69
|
+
```typst
|
|
70
|
+
#set element(property: value)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Common Set Rules
|
|
74
|
+
|
|
75
|
+
These examples show the most frequently used set rules for document configuration. Set rules can be placed at the document start for global effect or within content blocks for local scope.
|
|
76
|
+
|
|
77
|
+
```typst
|
|
78
|
+
// Text styling
|
|
79
|
+
#set text(font: "New Computer Modern", size: 11pt)
|
|
80
|
+
#set text(lang: "ko") // Korean language
|
|
81
|
+
|
|
82
|
+
// Paragraph styling
|
|
83
|
+
#set par(justify: true, leading: 0.65em, first-line-indent: 1em)
|
|
84
|
+
|
|
85
|
+
// Page setup
|
|
86
|
+
#set page(paper: "a4", margin: 2cm)
|
|
87
|
+
#set page(numbering: "1")
|
|
88
|
+
|
|
89
|
+
// Heading numbering
|
|
90
|
+
#set heading(numbering: "1.1")
|
|
91
|
+
|
|
92
|
+
// List styling
|
|
93
|
+
#set list(marker: [•])
|
|
94
|
+
#set enum(numbering: "1.a)")
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Scoped Set Rules
|
|
98
|
+
|
|
99
|
+
Wrap content in `#[...]` to create a scope where set rules only apply locally. This is useful for applying temporary styles without affecting the rest of the document.
|
|
100
|
+
|
|
101
|
+
```typst
|
|
102
|
+
// Apply only within block
|
|
103
|
+
#[
|
|
104
|
+
#set text(fill: blue)
|
|
105
|
+
This text is blue.
|
|
106
|
+
]
|
|
107
|
+
This text is default color.
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Show Rules
|
|
111
|
+
|
|
112
|
+
Show rules transform how elements are displayed. Unlike set rules which configure properties, show rules can completely redefine an element's appearance using custom logic.
|
|
113
|
+
|
|
114
|
+
### Basic Show Rule
|
|
115
|
+
|
|
116
|
+
The basic form takes an element type and a transformation function. The `it` parameter receives the matched element.
|
|
117
|
+
|
|
118
|
+
```typst
|
|
119
|
+
// Transform all headings
|
|
120
|
+
#show heading: it => {
|
|
121
|
+
set text(fill: blue)
|
|
122
|
+
it
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Transform specific element
|
|
126
|
+
#show "typst": [*Typst*]
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Show-Set Rule
|
|
130
|
+
|
|
131
|
+
A shorthand syntax that combines show rules with set rules. Use when you want to apply set rules only to specific elements without custom transformation logic.
|
|
132
|
+
|
|
133
|
+
```typst
|
|
134
|
+
// Apply set rule to specific element
|
|
135
|
+
#show heading: set text(fill: navy)
|
|
136
|
+
#show raw: set text(font: "Fira Code")
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Show with Function
|
|
140
|
+
|
|
141
|
+
For complex transformations, define a function that receives the element and returns modified content. Access element properties through the `it` parameter.
|
|
142
|
+
|
|
143
|
+
```typst
|
|
144
|
+
#show heading.where(level: 1): it => {
|
|
145
|
+
pagebreak(weak: true)
|
|
146
|
+
set text(size: 18pt)
|
|
147
|
+
block(it.body)
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Selector Types
|
|
152
|
+
|
|
153
|
+
Selectors determine which elements a show rule matches. Use `.where()` to filter by specific property values.
|
|
154
|
+
|
|
155
|
+
| Selector | Example |
|
|
156
|
+
|----------|---------|
|
|
157
|
+
| Element | `#show heading: ...` |
|
|
158
|
+
| Text | `#show "word": ...` |
|
|
159
|
+
| Regex | `#show regex("\d+"): ...` |
|
|
160
|
+
| Label | `#show <label>: ...` |
|
|
161
|
+
| Where | `#show heading.where(level: 1): ...` |
|
|
162
|
+
|
|
163
|
+
## Document Setup Pattern
|
|
164
|
+
|
|
165
|
+
A typical document preamble combines set rules and show rules to establish consistent styling. Place these at the document start before any content.
|
|
166
|
+
|
|
167
|
+
```typst
|
|
168
|
+
// Typical document setup
|
|
169
|
+
#set document(
|
|
170
|
+
title: "Document Title",
|
|
171
|
+
author: "Author Name",
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
#set page(
|
|
175
|
+
paper: "a4",
|
|
176
|
+
margin: (x: 2.5cm, y: 3cm),
|
|
177
|
+
header: [
|
|
178
|
+
#set text(8pt)
|
|
179
|
+
Document Title
|
|
180
|
+
#h(1fr)
|
|
181
|
+
#context counter(page).display()
|
|
182
|
+
],
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
#set text(
|
|
186
|
+
font: "Noto Sans KR",
|
|
187
|
+
size: 10pt,
|
|
188
|
+
lang: "ko",
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
#set par(
|
|
192
|
+
justify: true,
|
|
193
|
+
leading: 0.8em,
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
#set heading(numbering: "1.1")
|
|
197
|
+
#show heading.where(level: 1): set text(size: 16pt)
|
|
198
|
+
#show heading.where(level: 2): set text(size: 14pt)
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## LaTeX-like Styling
|
|
202
|
+
|
|
203
|
+
To achieve a classic academic paper appearance similar to LaTeX defaults, use these settings with Computer Modern fonts. Adjust margins and spacing to match your target style.
|
|
204
|
+
|
|
205
|
+
```typst
|
|
206
|
+
// Achieve LaTeX look
|
|
207
|
+
#set page(margin: 1.75in)
|
|
208
|
+
#set par(
|
|
209
|
+
leading: 0.55em,
|
|
210
|
+
spacing: 0.55em,
|
|
211
|
+
first-line-indent: 1.8em,
|
|
212
|
+
justify: true,
|
|
213
|
+
)
|
|
214
|
+
#set text(font: "New Computer Modern")
|
|
215
|
+
#show raw: set text(font: "New Computer Modern Mono")
|
|
216
|
+
#show heading: set block(above: 1.4em, below: 1em)
|
|
217
|
+
```
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
# Typst Syntax Reference
|
|
2
|
+
|
|
3
|
+
Typst has three syntactical modes: Markup, Math, and Code.
|
|
4
|
+
|
|
5
|
+
## Function Parameters
|
|
6
|
+
|
|
7
|
+
These tables provide quick reference for the most commonly used markup functions and their configurable options.
|
|
8
|
+
|
|
9
|
+
### `heading` Function
|
|
10
|
+
|
|
11
|
+
Defines document structure with hierarchical sections. The number of `=` signs determines the heading level.
|
|
12
|
+
|
|
13
|
+
| Parameter | Type | Default | Description |
|
|
14
|
+
|-----------|------|---------|-------------|
|
|
15
|
+
| `level` | auto \| int | `auto` | Heading level (1-6), auto-detected from `=` count |
|
|
16
|
+
| `depth` | int | - | (read-only) Nesting depth relative to `offset` |
|
|
17
|
+
| `offset` | int | `0` | Starting level offset for numbering |
|
|
18
|
+
| `numbering` | none \| str \| func | `none` | Number format: `"1."`, `"1.1"`, `"I.a"` |
|
|
19
|
+
| `supplement` | auto \| none \| content | `auto` | Reference prefix (e.g., "Section") |
|
|
20
|
+
| `outlined` | bool | `true` | Include in outline |
|
|
21
|
+
| `bookmarked` | auto \| bool | `auto` | Include in PDF bookmarks |
|
|
22
|
+
| `hanging-indent` | auto \| length | `auto` | Indent for wrapped lines |
|
|
23
|
+
| `body` | content | required | Heading text |
|
|
24
|
+
|
|
25
|
+
### `list` Function (Bullet List)
|
|
26
|
+
|
|
27
|
+
Creates unordered lists with customizable bullet markers. Use `-` in markup mode for quick list creation.
|
|
28
|
+
|
|
29
|
+
| Parameter | Type | Default | Description |
|
|
30
|
+
|-----------|------|---------|-------------|
|
|
31
|
+
| `tight` | bool | `true` | Reduce spacing between items |
|
|
32
|
+
| `marker` | content \| array \| func | `[•]` | Bullet marker(s) per level |
|
|
33
|
+
| `indent` | length | `0pt` | Indent from left |
|
|
34
|
+
| `body-indent` | length | `0.5em` | Gap between marker and text |
|
|
35
|
+
| `spacing` | auto \| relative | `auto` | Space between items |
|
|
36
|
+
| `children` | content | required | List items |
|
|
37
|
+
|
|
38
|
+
### `enum` Function (Numbered List)
|
|
39
|
+
|
|
40
|
+
Creates ordered lists with automatic numbering. Use `+` in markup mode. Supports various numbering formats including letters and roman numerals.
|
|
41
|
+
|
|
42
|
+
| Parameter | Type | Default | Description |
|
|
43
|
+
|-----------|------|---------|-------------|
|
|
44
|
+
| `tight` | bool | `true` | Reduce spacing between items |
|
|
45
|
+
| `numbering` | str \| func | `"1."` | Number format: `"1."`, `"a)"`, `"(i)"` |
|
|
46
|
+
| `start` | int | `1` | Starting number |
|
|
47
|
+
| `full` | bool | `false` | Show full numbering (e.g., "1.1.1") |
|
|
48
|
+
| `indent` | length | `0pt` | Indent from left |
|
|
49
|
+
| `body-indent` | length | `0.5em` | Gap between number and text |
|
|
50
|
+
| `spacing` | auto \| relative | `auto` | Space between items |
|
|
51
|
+
| `children` | content | required | List items |
|
|
52
|
+
|
|
53
|
+
### `raw` Function (Code Block)
|
|
54
|
+
|
|
55
|
+
Displays text exactly as written without interpretation. Use backticks in markup mode for inline code or triple backticks for code blocks with syntax highlighting.
|
|
56
|
+
|
|
57
|
+
| Parameter | Type | Default | Description |
|
|
58
|
+
|-----------|------|---------|-------------|
|
|
59
|
+
| `text` | str | required | Raw text content |
|
|
60
|
+
| `block` | bool | `false` | Display as block (true for fenced blocks) |
|
|
61
|
+
| `lang` | none \| str | `none` | Language for syntax highlighting |
|
|
62
|
+
| `align` | alignment | `start` | Text alignment |
|
|
63
|
+
| `syntaxes` | str \| array | `()` | Additional syntax definition files |
|
|
64
|
+
| `theme` | auto \| str \| none | `auto` | Syntax highlighting theme |
|
|
65
|
+
| `tab-size` | int | `2` | Tab width in spaces |
|
|
66
|
+
|
|
67
|
+
### `link` Function
|
|
68
|
+
|
|
69
|
+
Creates clickable hyperlinks to URLs, labels, or document locations. URLs are automatically detected in markup mode.
|
|
70
|
+
|
|
71
|
+
| Parameter | Type | Default | Description |
|
|
72
|
+
|-----------|------|---------|-------------|
|
|
73
|
+
| `dest` | str \| label \| location \| dict | required | URL, label, or location |
|
|
74
|
+
| `body` | auto \| content | `auto` | Link text (auto shows URL) |
|
|
75
|
+
|
|
76
|
+
### `ref` Function
|
|
77
|
+
|
|
78
|
+
Creates cross-references to labeled elements like headings, figures, or equations. Use `@label` syntax in markup mode.
|
|
79
|
+
|
|
80
|
+
| Parameter | Type | Default | Description |
|
|
81
|
+
|-----------|------|---------|-------------|
|
|
82
|
+
| `target` | label | required | Target label |
|
|
83
|
+
| `supplement` | auto \| none \| content | `auto` | Reference prefix |
|
|
84
|
+
|
|
85
|
+
## Mode Switching
|
|
86
|
+
|
|
87
|
+
Typst has three syntactical modes that you can switch between at any point. Understanding mode transitions is essential for combining text, math, and logic.
|
|
88
|
+
|
|
89
|
+
| New Mode | Syntax | Example |
|
|
90
|
+
|----------|--------|---------|
|
|
91
|
+
| Code | Prefix with `#` | `Number: #(1 + 2)` |
|
|
92
|
+
| Math | Surround with `$...$` | `$-x$ is the opposite of $x$` |
|
|
93
|
+
| Markup | Surround with `[..]` | `let name = [*Typst!*]` |
|
|
94
|
+
|
|
95
|
+
## Markup Mode Syntax
|
|
96
|
+
|
|
97
|
+
Markup mode is the default in a Typst document. It provides lightweight syntax for common document elements, with each shorthand corresponding to a function.
|
|
98
|
+
|
|
99
|
+
| Element | Syntax | Function |
|
|
100
|
+
|---------|--------|----------|
|
|
101
|
+
| Paragraph break | Blank line | `parbreak` |
|
|
102
|
+
| Strong emphasis | `*strong*` | `strong` |
|
|
103
|
+
| Emphasis | `_emphasis_` | `emph` |
|
|
104
|
+
| Raw text | `` `code` `` | `raw` |
|
|
105
|
+
| Link | `https://typst.app/` | `link` |
|
|
106
|
+
| Label | `<intro>` | `label` |
|
|
107
|
+
| Reference | `@intro` | `ref` |
|
|
108
|
+
| Heading | `= Heading` | `heading` |
|
|
109
|
+
| Bullet list | `- item` | `list` |
|
|
110
|
+
| Numbered list | `+ item` | `enum` |
|
|
111
|
+
| Term list | `/ Term: description` | `terms` |
|
|
112
|
+
| Line break | `\` | `linebreak` |
|
|
113
|
+
| Smart quote | `'single'` or `"double"` | `smartquote` |
|
|
114
|
+
| Comment | `/* block */` or `// line` | - |
|
|
115
|
+
|
|
116
|
+
### Heading Levels
|
|
117
|
+
|
|
118
|
+
The number of `=` signs determines the heading depth. Add more `=` for deeper nesting levels.
|
|
119
|
+
|
|
120
|
+
```typst
|
|
121
|
+
= Level 1 Heading
|
|
122
|
+
== Level 2 Heading
|
|
123
|
+
=== Level 3 Heading
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Lists
|
|
127
|
+
|
|
128
|
+
Typst supports bullet lists (`-`), numbered lists (`+`), and term/definition lists (`/`). Indent with spaces for nested items.
|
|
129
|
+
|
|
130
|
+
```typst
|
|
131
|
+
- Bullet item 1
|
|
132
|
+
- Bullet item 2
|
|
133
|
+
- Nested item
|
|
134
|
+
|
|
135
|
+
+ Numbered item 1
|
|
136
|
+
+ Numbered item 2
|
|
137
|
+
|
|
138
|
+
/ Term: Definition of the term
|
|
139
|
+
/ Another: Its definition
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Math Mode Syntax
|
|
143
|
+
|
|
144
|
+
Math mode is entered by wrapping equations in `$` characters. The equation becomes a block if it has spaces after `$` and before the closing `$`; otherwise it renders inline.
|
|
145
|
+
|
|
146
|
+
| Element | Syntax | Example |
|
|
147
|
+
|---------|--------|---------|
|
|
148
|
+
| Inline math | `$...$` (no spaces) | `$x^2$` |
|
|
149
|
+
| Block math | `$ ... $` (with spaces) | `$ x^2 $` |
|
|
150
|
+
| Subscript | `_` | `$x_1$` |
|
|
151
|
+
| Superscript | `^` | `$x^2$` |
|
|
152
|
+
| Fraction | `/` | `$(a+b)/5$` |
|
|
153
|
+
| Alignment | `&` | `$x &= 2 \ &= 3$` |
|
|
154
|
+
| Line break | `\` | `$x \ y$` |
|
|
155
|
+
|
|
156
|
+
### Math Examples
|
|
157
|
+
|
|
158
|
+
These examples demonstrate common mathematical notation patterns including inline equations, block equations, matrices, and aligned multi-line equations.
|
|
159
|
+
|
|
160
|
+
```typst
|
|
161
|
+
// Inline equation
|
|
162
|
+
The formula $a^2 + b^2 = c^2$ is famous.
|
|
163
|
+
|
|
164
|
+
// Block equation
|
|
165
|
+
$ sum_(i=1)^n i = (n(n+1))/2 $
|
|
166
|
+
|
|
167
|
+
// Matrix
|
|
168
|
+
$ mat(1, 2; 3, 4) $
|
|
169
|
+
|
|
170
|
+
// Aligned equations
|
|
171
|
+
$ x &= 2 + 3 \
|
|
172
|
+
&= 5 $
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Code Mode Syntax
|
|
176
|
+
|
|
177
|
+
Code mode lets you use Typst's scripting features. Prefix with `#` to enter code mode from markup. Once in code mode, you don't need additional hashes until switching back.
|
|
178
|
+
|
|
179
|
+
| Element | Syntax |
|
|
180
|
+
|---------|--------|
|
|
181
|
+
| Variable binding | `#let x = 1` |
|
|
182
|
+
| Function call | `#func(arg)` |
|
|
183
|
+
| Code block | `#{ ... }` |
|
|
184
|
+
| Content block | `#[ ... ]` |
|
|
185
|
+
| Conditional | `#if cond { } else { }` |
|
|
186
|
+
| Loop | `#for x in items { }` |
|
|
187
|
+
|
|
188
|
+
### Code Examples
|
|
189
|
+
|
|
190
|
+
These examples show variable definitions, loops, and conditionals. Content blocks `[...]` are used to return markup from code.
|
|
191
|
+
|
|
192
|
+
```typst
|
|
193
|
+
#let title = "My Document"
|
|
194
|
+
#let items = (1, 2, 3)
|
|
195
|
+
|
|
196
|
+
#for item in items {
|
|
197
|
+
[Item: #item]
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
#if items.len() > 0 {
|
|
201
|
+
[Has items]
|
|
202
|
+
} else {
|
|
203
|
+
[Empty]
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Escape Sequences
|
|
208
|
+
|
|
209
|
+
Use backslash to escape special characters that would otherwise be interpreted as markup syntax.
|
|
210
|
+
|
|
211
|
+
| Character | Escape |
|
|
212
|
+
|-----------|--------|
|
|
213
|
+
| `\` | `\\` |
|
|
214
|
+
| `#` | `\#` |
|
|
215
|
+
| `*` | `\*` |
|
|
216
|
+
| `_` | `\_` |
|
|
217
|
+
| `$` | `\$` |
|
|
218
|
+
| `<` | `\<` |
|
|
219
|
+
| `>` | `\>` |
|
|
220
|
+
| `@` | `\@` |
|
|
221
|
+
|
|
222
|
+
## Symbol Shorthands
|
|
223
|
+
|
|
224
|
+
Typst provides convenient shortcuts for commonly used typographic symbols. These work in both markup and math modes.
|
|
225
|
+
|
|
226
|
+
| Symbol | Shorthand |
|
|
227
|
+
|--------|-----------|
|
|
228
|
+
| Non-breaking space | `~` |
|
|
229
|
+
| Em dash | `---` |
|
|
230
|
+
| En dash | `--` |
|
|
231
|
+
| Ellipsis | `...` |
|
|
232
|
+
| Arrow right | `->` |
|
|
233
|
+
| Arrow left | `<-` |
|
|
234
|
+
| Double arrow | `<->` |
|