typst-count
A command-line tool to count words and characters in Typst documents.
Features
- Count words and characters from compiled Typst documents
- Counts only rendered text (excludes markup, code, and comments)
- Handles imported and included files automatically
- Multiple output formats: human-readable, JSON, CSV
- Support for multiple input files with totals
- CI-friendly with limit checks and proper exit codes
- Flexible display modes for different use cases
Installation
From crates.io
From source
Usage
Basic Usage
# Count both words and characters
# Count only words
# Count only characters
Output Formats
# Human-readable output (default)
# JSON output for scripting
# CSV output for data analysis
Multiple Files
# Count multiple files with totals
# Output results to a file
Advanced Options
# Exclude imported/included files (count only main file)
# Quiet mode (exit code only, useful in CI)
# Set limits with exit codes (useful for CI/CD)
How It Works
typst-count compiles your Typst document and extracts the rendered text content. This means:
- Counted: All text that appears in the final rendered document
- Counted: Content from imported/included files (by default)
- Counted: Markup syntax (like
*bold*,_italic_) - Not counted: Code blocks and inline code
- Not counted: Comments
- Not counted: Function definitions and calls
Counting Method
- Words: Split by whitespace (same as
wc -w). Note: For languages without spaces (e.g., Chinese, Japanese), each character may be counted as a separate "word" - Characters: Total character count including spaces and punctuation
Examples
Example Output (Human-readable)
File: document.typ
Characters: 1,842
Words: 287
Example Output (JSON)
CI/CD Integration
Check word count limits in your CI pipeline:
# .github/workflows/check-docs.yml
- name: Check documentation word count
run: |
cargo install typst-count
typst-count docs.typ --min-words 1000 --max-words 5000
Exit codes:
0: Success (within limits if specified)1: Below minimum or above maximum limit2: Compilation or other error
Comparison with Other Tools
- vs
wc: Counts only rendered text, not markup/code - vs Typst word count function: Can be used in CI/CD and with multiple files
- vs Tinymist LSP: Standalone tool, doesn't require editor integration
Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development
# Clone the repository
# Run tests
# Run clippy
# Format code
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Built with Typst - A new markup-based typesetting system
- Inspired by classic tools like
wcand modern Typst tooling