init commit
This commit is contained in:
commit
5f5bae8694
20
.gitignore
vendored
Normal file
20
.gitignore
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
# macOS
|
||||
.DS_Store
|
||||
|
||||
# Editor
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
|
||||
# IDE
|
||||
.idea/
|
||||
.vscode/
|
||||
|
||||
# Typst output
|
||||
*.pdf
|
||||
*.png
|
||||
*.svg
|
||||
|
||||
# Temp files
|
||||
*.tmp
|
||||
*.bak
|
||||
201
CLAUDE.md
Normal file
201
CLAUDE.md
Normal file
@ -0,0 +1,201 @@
|
||||
# CLAUDE.md
|
||||
|
||||
This file provides guidance to Claude Code when working with the Calligrapher repository.
|
||||
|
||||
## Repository Purpose
|
||||
|
||||
This repository provides Claude Code skills for working with Typst, a modern typesetting system. The skills enable seamless document compilation, watching, and management directly through Claude Code conversations.
|
||||
|
||||
## Repository Structure
|
||||
|
||||
- **skills/typst/SKILL.md** - Main Claude Code skill definition for Typst
|
||||
- **skills/typst/examples.md** - Usage examples
|
||||
- **README.md** - User-facing documentation
|
||||
- **CLAUDE.md** - This file (Claude Code instructions)
|
||||
|
||||
## Typst Overview
|
||||
|
||||
Typst is a markup-based typesetting system that competes with LaTeX while being more approachable and faster. It supports:
|
||||
|
||||
- **Document Compilation**: Generate PDF, PNG, SVG, or HTML from `.typ` files
|
||||
- **Watch Mode**: Auto-recompile on file changes
|
||||
- **Scripting**: Full programming capabilities for dynamic content
|
||||
- **Styling**: Powerful and flexible document styling
|
||||
- **Math**: LaTeX-like math equation support
|
||||
- **Data Import**: Load JSON, CSV, YAML, TOML, and XML
|
||||
|
||||
## Key Commands
|
||||
|
||||
### Compilation
|
||||
|
||||
```bash
|
||||
# Compile to PDF (default output)
|
||||
typst compile document.typ
|
||||
|
||||
# Compile to specific format
|
||||
typst compile document.typ output.png
|
||||
typst compile document.typ output.svg
|
||||
|
||||
# With explicit output path
|
||||
typst compile document.typ output/document.pdf
|
||||
|
||||
# With custom font path
|
||||
typst compile --font-path ./fonts document.typ
|
||||
```
|
||||
|
||||
### Watch Mode
|
||||
|
||||
```bash
|
||||
# Watch and recompile on changes
|
||||
typst watch document.typ
|
||||
|
||||
# Watch with custom output
|
||||
typst watch document.typ output.pdf
|
||||
```
|
||||
|
||||
### Font Management
|
||||
|
||||
```bash
|
||||
# List available fonts
|
||||
typst fonts
|
||||
|
||||
# Custom font paths
|
||||
typst compile --font-path ./fonts document.typ
|
||||
|
||||
# Or via environment variable
|
||||
export TYPST_FONT_PATHS=/path/to/fonts
|
||||
typst compile document.typ
|
||||
```
|
||||
|
||||
### Help
|
||||
|
||||
```bash
|
||||
typst help
|
||||
typst compile --help
|
||||
typst watch --help
|
||||
typst fonts --help
|
||||
```
|
||||
|
||||
## Important Notes for Claude Code
|
||||
|
||||
### File Extensions
|
||||
|
||||
- Typst source files use the `.typ` extension
|
||||
- Default output is PDF
|
||||
- Output format is inferred from the output filename extension
|
||||
|
||||
### Working Directory
|
||||
|
||||
Typst resolves relative paths from the directory containing the source file. When helping users:
|
||||
|
||||
1. Note the current working directory
|
||||
2. Use absolute paths when needed
|
||||
3. Ensure output directories exist before compilation
|
||||
|
||||
### Common Patterns
|
||||
|
||||
**Basic Document Structure:**
|
||||
```typst
|
||||
#set page(paper: "a4")
|
||||
#set text(font: "New Computer Modern", size: 11pt)
|
||||
|
||||
= Title
|
||||
|
||||
This is a paragraph.
|
||||
|
||||
== Section
|
||||
|
||||
More content here.
|
||||
```
|
||||
|
||||
**Math Equations:**
|
||||
```typst
|
||||
The quadratic formula is $x = (-b plus.minus sqrt(b^2 - 4 a c)) / (2 a)$.
|
||||
|
||||
Display equation:
|
||||
$ sum_(k=0)^n k = (n(n+1)) / 2 $
|
||||
```
|
||||
|
||||
**Code Blocks:**
|
||||
```typst
|
||||
```rust
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
```
|
||||
```
|
||||
|
||||
**Tables:**
|
||||
```typst
|
||||
#table(
|
||||
columns: (auto, auto),
|
||||
[Name], [Age],
|
||||
[Alice], [30],
|
||||
[Bob], [25],
|
||||
)
|
||||
```
|
||||
|
||||
### Error Handling
|
||||
|
||||
Common compilation errors:
|
||||
|
||||
- **File not found**: Check paths are correct and files exist
|
||||
- **Font not found**: Use `typst fonts` to list available fonts, or specify `--font-path`
|
||||
- **Syntax errors**: Typst provides helpful error messages with line/column numbers
|
||||
- **Package errors**: Ensure required packages are available
|
||||
|
||||
### Output Formats
|
||||
|
||||
| Extension | Format | Notes |
|
||||
|-----------|--------|-------|
|
||||
| `.pdf` | PDF | Default, best for documents |
|
||||
| `.png` | PNG | Rasterized, specify page with `{n}` |
|
||||
| `.svg` | SVG | Vector, good for web |
|
||||
|
||||
For multi-page documents to PNG:
|
||||
```bash
|
||||
typst compile document.typ 'output-{n}.png'
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
1. **Verify typst is installed** before running commands: `typst --version`
|
||||
2. **Use watch mode** during development for rapid iteration
|
||||
3. **Specify output paths** to keep source and output organized
|
||||
4. **Check font availability** with `typst fonts` before using custom fonts
|
||||
5. **Use absolute paths** when working directory might be ambiguous
|
||||
|
||||
## Skill Usage
|
||||
|
||||
The `/typst` skill can be invoked explicitly, but Claude Code should also recognize Typst-related requests naturally:
|
||||
|
||||
- "Compile this document"
|
||||
- "Watch my thesis.typ file"
|
||||
- "What fonts are available?"
|
||||
- "Convert to PNG"
|
||||
|
||||
Claude should automatically use the typst skill when appropriate for document operations.
|
||||
|
||||
## Extending the Skills
|
||||
|
||||
When adding new examples or workflows:
|
||||
|
||||
1. Test the commands manually first
|
||||
2. Add to the appropriate section in `skills/typst/SKILL.md`
|
||||
3. Include both basic and advanced examples
|
||||
4. Document any prerequisites or gotchas
|
||||
5. Update this CLAUDE.md if needed
|
||||
|
||||
## Common Pitfalls
|
||||
|
||||
- **Missing output directory**: Typst won't create directories; ensure they exist
|
||||
- **Font path issues**: Use `--font-path` or `TYPST_FONT_PATHS` for custom fonts
|
||||
- **Relative path confusion**: Paths resolve from source file location
|
||||
- **Format inference**: Output format comes from filename extension, not content
|
||||
|
||||
## Resources
|
||||
|
||||
- **Language Reference**: https://typst.app/docs/reference/
|
||||
- **Tutorial**: https://typst.app/docs/tutorial/
|
||||
- **GitHub**: https://github.com/typst/typst
|
||||
- **Packages**: https://typst.app/universe/
|
||||
205
README.md
Normal file
205
README.md
Normal file
@ -0,0 +1,205 @@
|
||||
# Calligrapher
|
||||
|
||||
Claude Code skills for the [Typst](https://typst.app/) programming language and compiler CLI.
|
||||
|
||||
Typst is a markup-based typesetting system designed to be a modern alternative to LaTeX - powerful enough for scientific papers and technical documents, yet easy to learn and fast to compile.
|
||||
|
||||
## What is Typst?
|
||||
|
||||
[Typst](https://github.com/typst/typst) allows you to:
|
||||
|
||||
- Write documents using intuitive markup syntax
|
||||
- Create beautiful PDFs, PNGs, SVGs, and HTML
|
||||
- Use scripting for dynamic content generation
|
||||
- Style documents with a flexible system
|
||||
- Work with math equations, tables, figures, and citations
|
||||
- Import data from JSON, CSV, YAML, TOML, and XML
|
||||
|
||||
## Installation
|
||||
|
||||
### Install Typst CLI
|
||||
|
||||
**macOS (Homebrew):**
|
||||
```bash
|
||||
brew install typst
|
||||
```
|
||||
|
||||
**Windows (Winget):**
|
||||
```powershell
|
||||
winget install --id Typst.Typst
|
||||
```
|
||||
|
||||
**Linux:**
|
||||
```bash
|
||||
# Via Snap
|
||||
snap install typst
|
||||
|
||||
# Or check your distribution's package manager
|
||||
# See: https://repology.org/project/typst/versions
|
||||
```
|
||||
|
||||
**From source (Cargo):**
|
||||
```bash
|
||||
cargo install --locked typst-cli
|
||||
```
|
||||
|
||||
**Pre-built binaries:**
|
||||
|
||||
Download from [GitHub Releases](https://github.com/typst/typst/releases/)
|
||||
|
||||
### Verify Installation
|
||||
|
||||
```bash
|
||||
typst --version
|
||||
```
|
||||
|
||||
## Claude Code Skills
|
||||
|
||||
This repository provides a comprehensive Claude Code skill for the Typst compiler CLI.
|
||||
|
||||
### Installing the Skill
|
||||
|
||||
The skill is located in the `skills/typst/` directory. To use it with Claude Code, you have two options:
|
||||
|
||||
#### Option 1: Symlink (Recommended)
|
||||
|
||||
Create a symbolic link to the skill directory:
|
||||
|
||||
```bash
|
||||
# Create the skills directory if it doesn't exist
|
||||
mkdir -p ~/.claude/skills
|
||||
|
||||
# Symlink the typst skill
|
||||
ln -s /path/to/calligrapher/skills/typst ~/.claude/skills/typst
|
||||
```
|
||||
|
||||
For example:
|
||||
```bash
|
||||
ln -s ~/repos/ajet-industries/calligrapher/skills/typst ~/.claude/skills/typst
|
||||
```
|
||||
|
||||
#### Option 2: Copy Directory
|
||||
|
||||
Copy the skill directory to your Claude Code skills folder:
|
||||
|
||||
```bash
|
||||
# Create the skills directory if it doesn't exist
|
||||
mkdir -p ~/.claude/skills
|
||||
|
||||
# Copy the typst skill
|
||||
cp -r /path/to/calligrapher/skills/typst ~/.claude/skills/typst
|
||||
```
|
||||
|
||||
For example:
|
||||
```bash
|
||||
cp -r ~/repos/ajet-industries/calligrapher/skills/typst ~/.claude/skills/typst
|
||||
```
|
||||
|
||||
### Using the Skill
|
||||
|
||||
Once installed, you can invoke the skill in Claude Code with:
|
||||
|
||||
```
|
||||
/typst
|
||||
```
|
||||
|
||||
Or simply ask Claude to perform Typst operations:
|
||||
|
||||
- "Compile my document to PDF"
|
||||
- "Watch this file for changes"
|
||||
- "List available fonts"
|
||||
- "Create a new Typst document"
|
||||
|
||||
## Common Typst Commands
|
||||
|
||||
### Compilation
|
||||
|
||||
```bash
|
||||
# Compile to PDF (default)
|
||||
typst compile document.typ
|
||||
|
||||
# Compile to PNG
|
||||
typst compile document.typ document.png
|
||||
|
||||
# Compile to SVG
|
||||
typst compile document.typ document.svg
|
||||
|
||||
# Specify output path
|
||||
typst compile document.typ output/document.pdf
|
||||
```
|
||||
|
||||
### Watch Mode
|
||||
|
||||
```bash
|
||||
# Watch for changes and recompile
|
||||
typst watch document.typ
|
||||
|
||||
# Watch with custom output
|
||||
typst watch document.typ output.pdf
|
||||
```
|
||||
|
||||
### Fonts
|
||||
|
||||
```bash
|
||||
# List available fonts
|
||||
typst fonts
|
||||
|
||||
# Use custom font path
|
||||
typst compile --font-path ./fonts document.typ
|
||||
```
|
||||
|
||||
### Help
|
||||
|
||||
```bash
|
||||
# General help
|
||||
typst help
|
||||
|
||||
# Command-specific help
|
||||
typst compile --help
|
||||
typst watch --help
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
- **Typst Reference**: https://typst.app/docs/reference/
|
||||
- **Typst Tutorial**: https://typst.app/docs/tutorial/
|
||||
- **GitHub Repository**: https://github.com/typst/typst
|
||||
- **Skill Documentation**: See `skills/typst/SKILL.md` for Claude Code integration details
|
||||
- **Examples**: See `skills/typst/examples.md` for usage examples
|
||||
|
||||
## Repository Structure
|
||||
|
||||
```
|
||||
calligrapher/
|
||||
├── skills/
|
||||
│ └── typst/
|
||||
│ ├── SKILL.md # Claude Code skill definition
|
||||
│ └── examples.md # Usage examples
|
||||
├── README.md # This file
|
||||
└── CLAUDE.md # Instructions for Claude Code
|
||||
```
|
||||
|
||||
## Why "Calligrapher"?
|
||||
|
||||
Calligraphy is the art of beautiful writing - the careful crafting of letterforms with skill and precision. Just as a calligrapher transforms simple text into visual art, Typst transforms markup into beautifully typeset documents.
|
||||
|
||||
This project aims to help you master the art of document creation with Typst through Claude Code, making the craft of typesetting accessible and efficient.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions welcome! Feel free to:
|
||||
- Add new examples to the skill documentation
|
||||
- Improve existing documentation
|
||||
- Add new workflows
|
||||
- Report issues
|
||||
|
||||
## Links
|
||||
|
||||
- [Typst](https://typst.app/)
|
||||
- [Typst GitHub](https://github.com/typst/typst)
|
||||
- [Typst Documentation](https://typst.app/docs/)
|
||||
- [Claude Code](https://claude.ai/code)
|
||||
353
skills/typst/SKILL.md
Normal file
353
skills/typst/SKILL.md
Normal file
@ -0,0 +1,353 @@
|
||||
---
|
||||
name: typst
|
||||
description: Compile Typst documents to PDF, PNG, SVG, and HTML. Watch files for changes and manage fonts. A modern alternative to LaTeX for typesetting.
|
||||
---
|
||||
|
||||
# Typst CLI
|
||||
|
||||
## When to Use This Skill
|
||||
|
||||
Use this skill when you need to:
|
||||
- **Compile Typst documents** to PDF, PNG, SVG, or HTML
|
||||
- **Watch files** for changes and auto-recompile
|
||||
- **List available fonts** on the system
|
||||
- **Help write Typst markup** for documents, papers, or reports
|
||||
- **Debug compilation errors** in Typst source files
|
||||
- **Set up custom font paths** for document compilation
|
||||
|
||||
## How It Works
|
||||
|
||||
The `typst` CLI compiles `.typ` source files into output documents. It supports incremental compilation for fast rebuilds and watch mode for development workflows.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
**Verify Typst is installed:**
|
||||
```bash
|
||||
typst --version
|
||||
```
|
||||
|
||||
If not installed, see installation options:
|
||||
- macOS: `brew install typst`
|
||||
- Windows: `winget install --id Typst.Typst`
|
||||
- Linux: `snap install typst` or check your package manager
|
||||
- Cargo: `cargo install --locked typst-cli`
|
||||
|
||||
## Common Operations
|
||||
|
||||
### Compile Documents
|
||||
|
||||
**Compile to PDF (default):**
|
||||
```bash
|
||||
typst compile document.typ
|
||||
```
|
||||
|
||||
**Compile to specific format:**
|
||||
```bash
|
||||
typst compile document.typ output.png
|
||||
typst compile document.typ output.svg
|
||||
```
|
||||
|
||||
**Compile to specific output path:**
|
||||
```bash
|
||||
typst compile document.typ output/document.pdf
|
||||
```
|
||||
|
||||
**Compile multi-page document to PNG:**
|
||||
```bash
|
||||
typst compile document.typ 'pages/page-{n}.png'
|
||||
```
|
||||
|
||||
### Watch Mode
|
||||
|
||||
**Watch and recompile on changes:**
|
||||
```bash
|
||||
typst watch document.typ
|
||||
```
|
||||
|
||||
**Watch with custom output:**
|
||||
```bash
|
||||
typst watch document.typ output.pdf
|
||||
```
|
||||
|
||||
**Watch with specific format:**
|
||||
```bash
|
||||
typst watch document.typ output.png
|
||||
```
|
||||
|
||||
### Font Management
|
||||
|
||||
**List available fonts:**
|
||||
```bash
|
||||
typst fonts
|
||||
```
|
||||
|
||||
**Compile with custom font path:**
|
||||
```bash
|
||||
typst compile --font-path ./fonts document.typ
|
||||
```
|
||||
|
||||
**Multiple font paths:**
|
||||
```bash
|
||||
typst compile --font-path ./fonts --font-path ~/.fonts document.typ
|
||||
```
|
||||
|
||||
**Using environment variable:**
|
||||
```bash
|
||||
export TYPST_FONT_PATHS=/path/to/fonts:/another/path
|
||||
typst compile document.typ
|
||||
```
|
||||
|
||||
### Help and Documentation
|
||||
|
||||
**General help:**
|
||||
```bash
|
||||
typst help
|
||||
```
|
||||
|
||||
**Command-specific help:**
|
||||
```bash
|
||||
typst compile --help
|
||||
typst watch --help
|
||||
typst fonts --help
|
||||
```
|
||||
|
||||
## Typst Markup Basics
|
||||
|
||||
### Document Structure
|
||||
|
||||
```typst
|
||||
// Set page and text defaults
|
||||
#set page(paper: "a4", margin: 2cm)
|
||||
#set text(font: "New Computer Modern", size: 11pt)
|
||||
|
||||
// Title
|
||||
#align(center)[
|
||||
#text(size: 20pt, weight: "bold")[Document Title]
|
||||
]
|
||||
|
||||
= Introduction
|
||||
|
||||
This is the first section.
|
||||
|
||||
== Subsection
|
||||
|
||||
Content with *bold* and _italic_ text.
|
||||
|
||||
- Bullet point
|
||||
- Another point
|
||||
- Nested point
|
||||
|
||||
+ Numbered item
|
||||
+ Another numbered item
|
||||
```
|
||||
|
||||
### Math Equations
|
||||
|
||||
**Inline math:**
|
||||
```typst
|
||||
The formula $E = m c^2$ describes mass-energy equivalence.
|
||||
```
|
||||
|
||||
**Display math:**
|
||||
```typst
|
||||
$ integral_0^infinity e^(-x^2) dif x = sqrt(pi) / 2 $
|
||||
```
|
||||
|
||||
**Aligned equations:**
|
||||
```typst
|
||||
$ x &= a + b \
|
||||
y &= c + d $
|
||||
```
|
||||
|
||||
### Tables
|
||||
|
||||
```typst
|
||||
#table(
|
||||
columns: (1fr, 1fr, 1fr),
|
||||
align: center,
|
||||
table.header([Name], [Value], [Unit]),
|
||||
[Mass], [5.0], [kg],
|
||||
[Velocity], [10], [m/s],
|
||||
[Energy], [250], [J],
|
||||
)
|
||||
```
|
||||
|
||||
### Figures and Images
|
||||
|
||||
```typst
|
||||
#figure(
|
||||
image("diagram.png", width: 80%),
|
||||
caption: [System architecture diagram],
|
||||
)
|
||||
```
|
||||
|
||||
### Code Blocks
|
||||
|
||||
````typst
|
||||
```python
|
||||
def hello():
|
||||
print("Hello, world!")
|
||||
```
|
||||
````
|
||||
|
||||
### Bibliography
|
||||
|
||||
```typst
|
||||
// At the end of document
|
||||
#bibliography("refs.bib")
|
||||
```
|
||||
|
||||
## Output Formats
|
||||
|
||||
| Extension | Format | Use Case |
|
||||
|-----------|--------|----------|
|
||||
| `.pdf` | PDF | Documents, papers (default) |
|
||||
| `.png` | PNG | Images, thumbnails |
|
||||
| `.svg` | SVG | Web, scalable graphics |
|
||||
|
||||
### Format-Specific Options
|
||||
|
||||
**PNG resolution:**
|
||||
```bash
|
||||
typst compile --ppi 300 document.typ output.png
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
### Common Errors
|
||||
|
||||
**File not found:**
|
||||
```
|
||||
error: file not found
|
||||
┌─ document.typ:5:1
|
||||
│
|
||||
5 │ #include "missing.typ"
|
||||
│ ^^^^^^^^^^^^^^^^^^^^^^
|
||||
```
|
||||
Solution: Check file paths are correct and files exist.
|
||||
|
||||
**Font not found:**
|
||||
```
|
||||
error: unknown font family
|
||||
```
|
||||
Solution: Use `typst fonts` to list available fonts, or add `--font-path`.
|
||||
|
||||
**Syntax error:**
|
||||
```
|
||||
error: expected expression
|
||||
┌─ document.typ:10:5
|
||||
│
|
||||
10│ #let x =
|
||||
│ ^
|
||||
```
|
||||
Solution: Check Typst syntax at the indicated line/column.
|
||||
|
||||
### Debugging Tips
|
||||
|
||||
1. Read error messages carefully - Typst provides file, line, and column
|
||||
2. Check the Typst reference: https://typst.app/docs/reference/
|
||||
3. Verify all included files exist
|
||||
4. Use `typst fonts` to check font availability
|
||||
|
||||
## Advanced Usage
|
||||
|
||||
### Command-Line Options
|
||||
|
||||
**Specify root directory:**
|
||||
```bash
|
||||
typst compile --root /project document.typ
|
||||
```
|
||||
|
||||
**Add input variables:**
|
||||
```bash
|
||||
typst compile --input version=1.0 document.typ
|
||||
```
|
||||
|
||||
**Diagnostic format:**
|
||||
```bash
|
||||
typst compile --diagnostic-format short document.typ
|
||||
```
|
||||
|
||||
### Environment Variables
|
||||
|
||||
- `TYPST_FONT_PATHS` - Additional font directories (colon-separated)
|
||||
- `TYPST_ROOT` - Root directory for file resolution
|
||||
|
||||
### Scripting Integration
|
||||
|
||||
**Check if compilation succeeds:**
|
||||
```bash
|
||||
if typst compile document.typ; then
|
||||
echo "Compilation successful"
|
||||
else
|
||||
echo "Compilation failed"
|
||||
fi
|
||||
```
|
||||
|
||||
**Batch compilation:**
|
||||
```bash
|
||||
for f in *.typ; do
|
||||
typst compile "$f"
|
||||
done
|
||||
```
|
||||
|
||||
## Typical Workflows
|
||||
|
||||
### Writing a Paper
|
||||
|
||||
1. Create `paper.typ` with document structure
|
||||
2. Start watch mode: `typst watch paper.typ`
|
||||
3. Edit source file - output updates automatically
|
||||
4. Add bibliography: `#bibliography("refs.bib")`
|
||||
5. Final compile: `typst compile paper.typ`
|
||||
|
||||
### Creating Slides
|
||||
|
||||
```typst
|
||||
#import "@preview/polylux:0.3.1": *
|
||||
|
||||
#set page(paper: "presentation-16-9")
|
||||
|
||||
#polylux-slide[
|
||||
= Slide Title
|
||||
|
||||
Content here
|
||||
]
|
||||
```
|
||||
|
||||
### Generating Images
|
||||
|
||||
```bash
|
||||
# Single page to PNG
|
||||
typst compile diagram.typ diagram.png
|
||||
|
||||
# High-resolution
|
||||
typst compile --ppi 600 diagram.typ diagram.png
|
||||
|
||||
# Multiple pages
|
||||
typst compile slides.typ 'slide-{n}.png'
|
||||
```
|
||||
|
||||
## Important Notes
|
||||
|
||||
- **File extension matters**: Output format is inferred from the output filename
|
||||
- **Incremental compilation**: Typst caches intermediate results for speed
|
||||
- **Watch mode**: Ideal for development; use Ctrl+C to stop
|
||||
- **Relative paths**: Resolved from the source file's directory
|
||||
- **Package system**: Import packages with `#import "@preview/package:version"`
|
||||
|
||||
## Getting Help
|
||||
|
||||
```bash
|
||||
typst help # General help
|
||||
typst compile --help # Compile command help
|
||||
typst watch --help # Watch command help
|
||||
typst fonts --help # Fonts command help
|
||||
```
|
||||
|
||||
## Resources
|
||||
|
||||
- **Reference**: https://typst.app/docs/reference/
|
||||
- **Tutorial**: https://typst.app/docs/tutorial/
|
||||
- **Packages**: https://typst.app/universe/
|
||||
- **GitHub**: https://github.com/typst/typst
|
||||
607
skills/typst/examples.md
Normal file
607
skills/typst/examples.md
Normal file
@ -0,0 +1,607 @@
|
||||
# Typst CLI Examples
|
||||
|
||||
Quick reference for common `typst` commands and markup patterns.
|
||||
|
||||
## Installation Verification
|
||||
|
||||
```bash
|
||||
# Check version
|
||||
typst --version
|
||||
|
||||
# Get help
|
||||
typst help
|
||||
```
|
||||
|
||||
## Compilation
|
||||
|
||||
### Basic Compilation
|
||||
|
||||
```bash
|
||||
# Compile to PDF (default)
|
||||
typst compile document.typ
|
||||
|
||||
# Explicit output file
|
||||
typst compile document.typ output.pdf
|
||||
|
||||
# Compile to PNG
|
||||
typst compile document.typ document.png
|
||||
|
||||
# Compile to SVG
|
||||
typst compile document.typ document.svg
|
||||
```
|
||||
|
||||
### Output Options
|
||||
|
||||
```bash
|
||||
# High-resolution PNG (300 PPI)
|
||||
typst compile --ppi 300 document.typ output.png
|
||||
|
||||
# Multi-page to numbered PNGs
|
||||
typst compile document.typ 'output-{n}.png'
|
||||
|
||||
# Custom output directory
|
||||
typst compile document.typ build/output.pdf
|
||||
```
|
||||
|
||||
### Root and Input
|
||||
|
||||
```bash
|
||||
# Set root directory for imports
|
||||
typst compile --root /project/src document.typ
|
||||
|
||||
# Pass input variables
|
||||
typst compile --input version=2.0 document.typ
|
||||
typst compile --input author="John Doe" --input date=2024-01-15 document.typ
|
||||
```
|
||||
|
||||
## Watch Mode
|
||||
|
||||
```bash
|
||||
# Watch and recompile on changes
|
||||
typst watch document.typ
|
||||
|
||||
# Watch with specific output
|
||||
typst watch document.typ output.pdf
|
||||
|
||||
# Watch with PNG output
|
||||
typst watch thesis.typ thesis.png
|
||||
```
|
||||
|
||||
## Font Management
|
||||
|
||||
```bash
|
||||
# List all available fonts
|
||||
typst fonts
|
||||
|
||||
# Filter fonts by name
|
||||
typst fonts | grep -i "computer modern"
|
||||
|
||||
# Compile with custom font path
|
||||
typst compile --font-path ./fonts document.typ
|
||||
|
||||
# Multiple font paths
|
||||
typst compile --font-path ./fonts --font-path ~/Library/Fonts document.typ
|
||||
```
|
||||
|
||||
## Document Templates
|
||||
|
||||
### Basic Document
|
||||
|
||||
```typst
|
||||
// document.typ
|
||||
#set page(paper: "a4", margin: 2.5cm)
|
||||
#set text(font: "New Computer Modern", size: 11pt)
|
||||
#set par(justify: true)
|
||||
|
||||
= Document Title
|
||||
|
||||
#lorem(50)
|
||||
|
||||
== First Section
|
||||
|
||||
#lorem(100)
|
||||
|
||||
=== Subsection
|
||||
|
||||
#lorem(75)
|
||||
```
|
||||
|
||||
### Academic Paper
|
||||
|
||||
```typst
|
||||
// paper.typ
|
||||
#set document(title: "Research Paper", author: "Author Name")
|
||||
#set page(paper: "us-letter", margin: 1in)
|
||||
#set text(font: "Times New Roman", size: 12pt)
|
||||
#set par(justify: true, leading: 2em)
|
||||
#set heading(numbering: "1.1")
|
||||
|
||||
#align(center)[
|
||||
#text(size: 16pt, weight: "bold")[Paper Title]
|
||||
|
||||
#v(1em)
|
||||
|
||||
Author Name \
|
||||
Institution \
|
||||
#link("mailto:email@example.com")
|
||||
|
||||
#v(1em)
|
||||
|
||||
#datetime.today().display("[month repr:long] [day], [year]")
|
||||
]
|
||||
|
||||
#v(2em)
|
||||
|
||||
*Abstract.* #lorem(80)
|
||||
|
||||
#v(1em)
|
||||
|
||||
= Introduction
|
||||
|
||||
#lorem(100)
|
||||
|
||||
= Methods
|
||||
|
||||
#lorem(100)
|
||||
|
||||
= Results
|
||||
|
||||
#lorem(100)
|
||||
|
||||
= Discussion
|
||||
|
||||
#lorem(100)
|
||||
|
||||
#bibliography("references.bib")
|
||||
```
|
||||
|
||||
### Letter
|
||||
|
||||
```typst
|
||||
// letter.typ
|
||||
#set page(paper: "us-letter", margin: 1in)
|
||||
#set text(font: "Georgia", size: 11pt)
|
||||
|
||||
#align(right)[
|
||||
Your Name \
|
||||
123 Main Street \
|
||||
City, State 12345 \
|
||||
#datetime.today().display()
|
||||
]
|
||||
|
||||
#v(2em)
|
||||
|
||||
Recipient Name \
|
||||
456 Other Street \
|
||||
City, State 67890
|
||||
|
||||
#v(1em)
|
||||
|
||||
Dear Recipient,
|
||||
|
||||
#lorem(150)
|
||||
|
||||
Sincerely,
|
||||
|
||||
#v(3em)
|
||||
|
||||
Your Name
|
||||
```
|
||||
|
||||
### Resume/CV
|
||||
|
||||
```typst
|
||||
// resume.typ
|
||||
#set page(paper: "us-letter", margin: 0.5in)
|
||||
#set text(font: "Helvetica", size: 10pt)
|
||||
|
||||
#align(center)[
|
||||
#text(size: 20pt, weight: "bold")[Your Name]
|
||||
|
||||
email\@example.com | (555) 123-4567 | linkedin.com/in/yourname
|
||||
]
|
||||
|
||||
#line(length: 100%)
|
||||
|
||||
== Experience
|
||||
|
||||
*Senior Developer* | Company Name | 2020 - Present
|
||||
- Led team of 5 developers on major product launch
|
||||
- Implemented CI/CD pipeline reducing deployment time by 50%
|
||||
|
||||
*Developer* | Other Company | 2018 - 2020
|
||||
- Built REST APIs serving 1M+ requests daily
|
||||
- Mentored junior developers
|
||||
|
||||
#line(length: 100%)
|
||||
|
||||
== Education
|
||||
|
||||
*Master of Science, Computer Science* | University Name | 2018
|
||||
|
||||
*Bachelor of Science, Computer Science* | University Name | 2016
|
||||
|
||||
#line(length: 100%)
|
||||
|
||||
== Skills
|
||||
|
||||
*Languages:* Python, JavaScript, Rust, Go \
|
||||
*Frameworks:* React, Django, FastAPI \
|
||||
*Tools:* Docker, Kubernetes, AWS
|
||||
```
|
||||
|
||||
## Math Examples
|
||||
|
||||
### Inline Math
|
||||
|
||||
```typst
|
||||
The quadratic formula is $x = (-b plus.minus sqrt(b^2 - 4a c)) / (2a)$.
|
||||
|
||||
Einstein's equation $E = m c^2$ relates mass and energy.
|
||||
|
||||
The sum $sum_(i=1)^n i = (n(n+1))/2$ is well known.
|
||||
```
|
||||
|
||||
### Display Equations
|
||||
|
||||
```typst
|
||||
The Gaussian integral:
|
||||
$ integral_(-infinity)^infinity e^(-x^2) dif x = sqrt(pi) $
|
||||
|
||||
Maxwell's equations:
|
||||
$ nabla dot bold(E) &= rho / epsilon_0 \
|
||||
nabla dot bold(B) &= 0 \
|
||||
nabla times bold(E) &= -pdv(bold(B), t) \
|
||||
nabla times bold(B) &= mu_0 bold(J) + mu_0 epsilon_0 pdv(bold(E), t) $
|
||||
```
|
||||
|
||||
### Matrices
|
||||
|
||||
```typst
|
||||
$ mat(
|
||||
1, 2, 3;
|
||||
4, 5, 6;
|
||||
7, 8, 9;
|
||||
) $
|
||||
|
||||
$ mat(delim: "[",
|
||||
a, b;
|
||||
c, d;
|
||||
) $
|
||||
```
|
||||
|
||||
### Cases
|
||||
|
||||
```typst
|
||||
$ f(x) = cases(
|
||||
x^2 &"if" x >= 0,
|
||||
-x^2 &"if" x < 0,
|
||||
) $
|
||||
```
|
||||
|
||||
## Tables
|
||||
|
||||
### Basic Table
|
||||
|
||||
```typst
|
||||
#table(
|
||||
columns: 3,
|
||||
[Header 1], [Header 2], [Header 3],
|
||||
[Cell 1], [Cell 2], [Cell 3],
|
||||
[Cell 4], [Cell 5], [Cell 6],
|
||||
)
|
||||
```
|
||||
|
||||
### Styled Table
|
||||
|
||||
```typst
|
||||
#table(
|
||||
columns: (1fr, 2fr, 1fr),
|
||||
align: (left, center, right),
|
||||
stroke: 0.5pt,
|
||||
inset: 8pt,
|
||||
table.header(
|
||||
[*Name*], [*Description*], [*Value*],
|
||||
),
|
||||
[Alpha], [First item], [100],
|
||||
[Beta], [Second item], [200],
|
||||
[Gamma], [Third item], [300],
|
||||
)
|
||||
```
|
||||
|
||||
### Data Table
|
||||
|
||||
```typst
|
||||
#let data = csv("data.csv")
|
||||
|
||||
#table(
|
||||
columns: data.first().len(),
|
||||
..data.flatten()
|
||||
)
|
||||
```
|
||||
|
||||
## Figures and Images
|
||||
|
||||
### Basic Image
|
||||
|
||||
```typst
|
||||
#image("photo.jpg", width: 50%)
|
||||
```
|
||||
|
||||
### Figure with Caption
|
||||
|
||||
```typst
|
||||
#figure(
|
||||
image("diagram.png", width: 80%),
|
||||
caption: [System architecture overview],
|
||||
) <fig:architecture>
|
||||
|
||||
As shown in @fig:architecture, the system consists of three layers.
|
||||
```
|
||||
|
||||
### Side-by-Side Figures
|
||||
|
||||
```typst
|
||||
#grid(
|
||||
columns: 2,
|
||||
gutter: 1em,
|
||||
figure(
|
||||
image("before.png"),
|
||||
caption: [Before optimization],
|
||||
),
|
||||
figure(
|
||||
image("after.png"),
|
||||
caption: [After optimization],
|
||||
),
|
||||
)
|
||||
```
|
||||
|
||||
## Code Blocks
|
||||
|
||||
### Inline Code
|
||||
|
||||
```typst
|
||||
Use the `print()` function to output text.
|
||||
```
|
||||
|
||||
### Code Block
|
||||
|
||||
````typst
|
||||
```python
|
||||
def fibonacci(n):
|
||||
if n <= 1:
|
||||
return n
|
||||
return fibonacci(n-1) + fibonacci(n-2)
|
||||
```
|
||||
````
|
||||
|
||||
### Code with Caption
|
||||
|
||||
````typst
|
||||
#figure(
|
||||
```rust
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
```,
|
||||
caption: [A simple Rust program],
|
||||
)
|
||||
````
|
||||
|
||||
## Lists
|
||||
|
||||
### Bullet List
|
||||
|
||||
```typst
|
||||
- First item
|
||||
- Second item
|
||||
- Nested item
|
||||
- Another nested item
|
||||
- Third item
|
||||
```
|
||||
|
||||
### Numbered List
|
||||
|
||||
```typst
|
||||
+ First step
|
||||
+ Second step
|
||||
+ Third step
|
||||
```
|
||||
|
||||
### Definition List
|
||||
|
||||
```typst
|
||||
/ Term: Definition of the term
|
||||
/ Another term: Its definition
|
||||
```
|
||||
|
||||
## Layout
|
||||
|
||||
### Columns
|
||||
|
||||
```typst
|
||||
#columns(2)[
|
||||
#lorem(50)
|
||||
|
||||
#colbreak()
|
||||
|
||||
#lorem(50)
|
||||
]
|
||||
```
|
||||
|
||||
### Grid
|
||||
|
||||
```typst
|
||||
#grid(
|
||||
columns: (1fr, 1fr),
|
||||
rows: (auto, auto),
|
||||
gutter: 1em,
|
||||
[Cell 1], [Cell 2],
|
||||
[Cell 3], [Cell 4],
|
||||
)
|
||||
```
|
||||
|
||||
### Alignment
|
||||
|
||||
```typst
|
||||
#align(center)[Centered text]
|
||||
#align(right)[Right-aligned text]
|
||||
#align(left + bottom)[Bottom-left aligned]
|
||||
```
|
||||
|
||||
### Spacing
|
||||
|
||||
```typst
|
||||
Text before
|
||||
#v(2em) // Vertical space
|
||||
Text after
|
||||
|
||||
Word #h(1cm) spaced #h(1cm) out
|
||||
```
|
||||
|
||||
## References and Citations
|
||||
|
||||
### Labels and References
|
||||
|
||||
```typst
|
||||
= Introduction <intro>
|
||||
|
||||
See @intro for more details.
|
||||
|
||||
#figure(
|
||||
image("fig.png"),
|
||||
caption: [A figure],
|
||||
) <fig:example>
|
||||
|
||||
As shown in @fig:example...
|
||||
```
|
||||
|
||||
### Bibliography
|
||||
|
||||
```typst
|
||||
According to @smith2020, this is important.
|
||||
|
||||
Multiple citations @smith2020 @jones2021.
|
||||
|
||||
#bibliography("refs.bib", style: "ieee")
|
||||
```
|
||||
|
||||
## Data Import
|
||||
|
||||
### JSON
|
||||
|
||||
```typst
|
||||
#let data = json("data.json")
|
||||
#data.name // Access fields
|
||||
```
|
||||
|
||||
### CSV
|
||||
|
||||
```typst
|
||||
#let rows = csv("data.csv")
|
||||
#for row in rows [
|
||||
#row.at(0), #row.at(1)
|
||||
]
|
||||
```
|
||||
|
||||
### YAML
|
||||
|
||||
```typst
|
||||
#let config = yaml("config.yaml")
|
||||
Title: #config.title
|
||||
```
|
||||
|
||||
## Scripting
|
||||
|
||||
### Variables
|
||||
|
||||
```typst
|
||||
#let title = "My Document"
|
||||
#let author = "John Doe"
|
||||
|
||||
#title by #author
|
||||
```
|
||||
|
||||
### Functions
|
||||
|
||||
```typst
|
||||
#let highlight(body) = {
|
||||
box(fill: yellow, inset: 3pt, body)
|
||||
}
|
||||
|
||||
This is #highlight[important] text.
|
||||
```
|
||||
|
||||
### Conditionals
|
||||
|
||||
```typst
|
||||
#let draft = true
|
||||
|
||||
#if draft [
|
||||
*DRAFT - DO NOT DISTRIBUTE*
|
||||
]
|
||||
```
|
||||
|
||||
### Loops
|
||||
|
||||
```typst
|
||||
#for i in range(1, 6) [
|
||||
- Item #i
|
||||
]
|
||||
```
|
||||
|
||||
## Advanced CLI
|
||||
|
||||
### Batch Processing
|
||||
|
||||
```bash
|
||||
# Compile all .typ files in directory
|
||||
for f in *.typ; do
|
||||
typst compile "$f"
|
||||
done
|
||||
|
||||
# Compile with common settings
|
||||
for f in chapters/*.typ; do
|
||||
typst compile --font-path ./fonts "$f" "output/$(basename $f .typ).pdf"
|
||||
done
|
||||
```
|
||||
|
||||
### CI/CD Integration
|
||||
|
||||
```bash
|
||||
# Check compilation succeeds
|
||||
typst compile document.typ && echo "Success" || echo "Failed"
|
||||
|
||||
# Compile and verify output exists
|
||||
typst compile thesis.typ thesis.pdf
|
||||
if [ -f thesis.pdf ]; then
|
||||
echo "PDF generated successfully"
|
||||
fi
|
||||
```
|
||||
|
||||
### Environment Setup
|
||||
|
||||
```bash
|
||||
# Set font paths for session
|
||||
export TYPST_FONT_PATHS="$HOME/fonts:/usr/share/fonts"
|
||||
|
||||
# Compile with custom root
|
||||
export TYPST_ROOT="/project"
|
||||
typst compile src/main.typ
|
||||
```
|
||||
|
||||
## Troubleshooting Commands
|
||||
|
||||
```bash
|
||||
# Verbose output for debugging
|
||||
typst compile document.typ 2>&1 | head -50
|
||||
|
||||
# Check available fonts
|
||||
typst fonts | wc -l # Count fonts
|
||||
|
||||
# Find specific font
|
||||
typst fonts | grep -i "fira"
|
||||
|
||||
# Test minimal document
|
||||
echo '= Test' | typst compile - test.pdf
|
||||
```
|
||||
Loading…
x
Reference in New Issue
Block a user