d2typ

Crates.iod2typ
lib.rsd2typ
version0.1.3
created_at2025-07-19 19:16:26.090319+00
updated_at2025-07-19 20:17:05.228103+00
descriptionA command-line tool for converting structured data to Typst format
homepagehttps://github.com/acture/d2typ
repositoryhttps://github.com/acture/d2typ
max_upload_size
id1760448
size61,339
acture (Acture)

documentation

https://github.com/acture/d2typ

README

d2typ

A command-line tool for converting structured data to Typst format.

Features

  • Convert data from various formats to Typst syntax
  • Supported input formats:
    • CSV
    • JSON
    • YAML
    • TOML
    • Excel (XLSX)
  • Automatic format detection based on file extension
  • Read from files or standard input
  • Write to files or standard output
  • Customizable options for different input formats

Installation

From crates.io

cargo install d2typ

Using Homebrew

# If formula is submitted to Homebrew
brew install d2typ

From source

git clone https://github.com/yourusername/d2typ.git
cd d2typ
cargo install --path .

Usage

Basic Usage

# Convert a CSV file to Typst format
d2typ input.csv > output.typ

# Convert a JSON file to Typst format
d2typ input.json > output.typ

# Specify output file
d2typ input.yaml -o output.typ

# Read from stdin
cat input.toml | d2typ > output.typ

Command-line Options

Usage: d2typ [OPTIONS] [INPUT]

Arguments:
  [INPUT]  Input file (omit for stdin)

Options:
  -o, --output <OUTPUT>    Output file (omit for stdout)
  -f, --format <FORMAT>    Force input format [default: auto] [possible values: auto, csv, json, yaml, toml, xlsx]
      --no-header          For CSV input: treat as no header
      --sheet <SHEET>      For XLSX input: select sheet
  -h, --help               Print help
  -V, --version            Print version

Examples

CSV to Typst

Input (data.csv):

name,age,city
Alice,30,New York
Bob,25,San Francisco
Charlie,35,Seattle

Command:

d2typ data.csv > data.typ

Output (data.typ):

#let data = [
  { name: Alice, age: 30, city: New York },
  { name: Bob, age: 25, city: San Francisco },
  { name: Charlie, age: 35, city: Seattle }
]

JSON to Typst

Input (data.json):

{
  "users": [
    {"name": "Alice", "age": 30},
    {"name": "Bob", "age": 25}
  ],
  "version": 1.0
}

Command:

d2typ data.json > data.typ

Output (data.typ):

#let data = {
  users: [
    { name: Alice, age: 30 },
    { name: Bob, age: 25 }
  ],
  version: 1.0
}

Integration with Typst

Once you've converted your data to Typst format, you can use it in your Typst documents:

#import "data.typ"

// Access the data
#for user in data.users [
  - #user.name is #user.age years old
]

Building from Source

Prerequisites

  • Rust toolchain (rustc, cargo)
  • Recommended: Rust version 1.75.0 or later

Building the Project

  1. Clone the repository
  2. Build the project:
    cargo build
    
  3. Run the project:
    cargo run -- [arguments]
    

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0-only) - see the LICENSE file for details.

Commit count: 0

cargo fmt