Initial commit

This commit is contained in:
Zhongwei Li
2025-11-30 09:08:16 +08:00
commit fc569e5620
38 changed files with 4997 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
# Basic Setup
```typst
// In your document, cite with @label
Some text with a citation @smith2023.
Multiple citations @jones2024 @doe2025.
// At the end of your document
#bibliography("references.bib", title: "References", style: "ieee")
```
# Citation Styles
- `"ieee"` - IEEE numeric style [1], [2], [3]
- `"apa"` - APA author-year style (Smith, 2023)
- `"chicago-author-date"` - Chicago author-date style
- `"chicago-notes"` - Chicago notes and bibliography style
- `"mla"` - MLA style
# BibTeX Format (.bib files)
```bibtex
@article{smith2023,
title = {Title of the Article},
author = {Smith, John and Doe, Jane},
journal = {Journal Name},
year = {2023},
volume = {10},
pages = {123--145},
}
@online{webresource,
title = {Web Page Title},
author = {Author Name},
year = {2024},
url = {https://example.com},
urldate = {2024-11-19},
}
@book{doe2025,
title = {Book Title},
author = {Doe, Jane},
publisher = {Publisher Name},
year = {2025},
}
```
# Bibliography Function Parameters
```typst
#bibliography(
"file.bib", // Path to bibliography file
title: "References", // Section title (or none for no title)
style: "ieee", // Citation style
full: false, // Show all entries or only cited ones
)
```

View File

@@ -0,0 +1,154 @@
# Typst Syntax Reference
## Critical Syntax Distinctions
### Data Structures
- **Arrays**: Use `()` parentheses
```typst
#let colors = (red, blue, green)
#let mixed = (1, "text", true)
```
- **Dictionaries**: Use `()` with key-value pairs
```typst
#let config = (name: "value", count: 5)
#let palette = (primary: red, secondary: blue)
```
- **Content blocks**: Use `[]` square brackets
```typst
#let heading = [== My Title]
#let paragraph = [This is some *bold* text]
```
**IMPORTANT**: Typst does NOT have tuples. Only arrays (with parentheses).
### Function Definitions
```typst
// Basic function
#let greet(name) = [Hello, #name!]
// With default parameters
#let box-style(fill: none, stroke: 1pt) = { ... }
// With variadic arguments
#let items(..args) = {
for item in args.pos() { ... }
}
```
### Conditionals and Loops
```typst
// If-else
#if condition {
[true branch]
} else {
[false branch]
}
// For loop
#for item in array {
[Processing #item]
}
```
### String Interpolation
```typst
#let name = "World"
[Hello #name] // Content context
#("Hello " + name) // String concatenation
```
## Common Patterns
### Custom Styling Functions
```typst
#let highlight(color, body) = {
box(fill: color.lighten(80%), inset: 3pt, body)
}
#highlight(red)[Important text]
```
### State Management
```typst
#let counter = state("my-counter", 0)
#counter.update(x => x + 1)
#context counter.get()
```
### Layout Helpers
```typst
// Stack (vertical by default)
#stack(
spacing: 1em,
[First item],
[Second item]
)
// Grid
#grid(
columns: (1fr, 2fr),
rows: auto,
gutter: 10pt,
[Cell 1], [Cell 2]
)
// Box with styling
#box(
fill: gray.lighten(90%),
stroke: 1pt,
inset: 8pt,
radius: 4pt,
[Content]
)
```
### Color Manipulation
```typst
#let base = rgb("#3366ff")
#let lighter = base.lighten(40%)
#let darker = base.darken(20%)
#let transparent = base.transparentize(50%)
#let mixed = red.mix(blue, 30%)
```
## Common Gotchas
1. **Array access**: Use `.at()` method, not `[]`
```typst
#let arr = (1, 2, 3)
#arr.at(0) // Correct
// arr[0] // WRONG - [] is for content
```
2. **Method chaining on arrays**:
```typst
#items.map(x => x * 2).filter(x => x > 5).join(", ")
```
3. **Context blocks**: Required for accessing state
```typst
#context {
let val = my-state.get()
[The value is #val]
}
```
4. **Assignment in code blocks**: Use `let`, not `=` alone
```typst
#{
let x = 5 // Correct
// x = 5 // WRONG
}
```