1
0
Fork
You've already forked trype
0
A utility for generating Typst templates from TOML 'stylesheet' configuration files
  • Makefile 88%
  • Rust 8.3%
  • Typst 3.4%
  • D 0.2%
2024年11月21日 18:11:30 +00:00
src first commit 2024年11月21日 18:08:52 +00:00
target first commit 2024年11月21日 18:08:52 +00:00
Cargo.lock first commit 2024年11月21日 18:08:52 +00:00
Cargo.toml first commit 2024年11月21日 18:08:52 +00:00
demo.typ first commit 2024年11月21日 18:08:52 +00:00
formats.toml first commit 2024年11月21日 18:08:52 +00:00
LICENSE Initial commit 2024年11月21日 18:05:48 +00:00
README.md Updated README.md 2024年11月21日 18:11:30 +00:00
template.typ first commit 2024年11月21日 18:08:52 +00:00
test.typ first commit 2024年11月21日 18:08:52 +00:00

Trype

A utility for generating Typst templates from TOML configuration files.

Overview

Trype converts a TOML-based configuration file into a Typst template that defines consistent styling for your documents. The configuration file supports a wide range of formatting parameters including fonts, sizes, spacing, and colors.

Trype is very much at a pre-alpha stage, so please feel free to kick the tires, see what does and doesn't work, and let me know.

Installation

cargo install --path .

Usage

Command-line Options

trype [OPTIONS]
Options:
 -c, --config <FILE> Path to the input TOML configuration file [default: formats.toml]
 -o, --output <FILE> Path to the output Typst template file [default: template.typ]
 -t, --test Generate a test document showing all styled elements
 --test-output <FILE> Path to the test document output file [default: test.typ]
 -h, --help Print help
 -V, --version Print version

Basic Usage

  1. Create or edit a formats.toml file to define your desired styles (all fields are optional)
  2. Run the utility:
    trype # Use default filenames
    # or
    trype -c my-config.toml -o my-template.typ # Specify custom filenames
    # or
    trype --test # Generate both template and test document
    # or
    trype --test --test-output demo.typ # Generate test document with custom name
    
  3. Import the template in your Typst documents:
    #import"template.typ":styles#setpage(styles.page)#settext(styles.text)#setheading(styles.heading)= Your Document TitleThisisaparagraphwiththedefaulttextstyle.

Test Document

Run trype --test to generate a comprehensive test document that shows how your styles look. This will create:

  1. Your template file (default: template.typ)
  2. A test document (default: test.typ)

The test document is useful for:

  • Previewing your styles
  • Verifying style changes
  • Creating documentation
  • Learning how to use the template

Configuration Format

All fields in the formats.toml file are optional and have sensible defaults. You only need to specify the values you want to customize.

Configuration Sections

  • defaults: Common values used across styles (fonts, weights, colors)
  • page: Page size, margins, background, numbering
  • text: Default text properties (font, size, weight, alignment)
  • heading: Styles for heading levels 1-3
  • paragraph: Text block formatting and spacing
  • block-quote: Quote styling and indentation
  • list: Bullet points, numbering, spacing
  • code-block: Code snippet formatting
  • table: Table borders, spacing, alignment
  • caption: Figure and table caption styling

Default Values

The program uses these defaults if values are not specified:

  • Fonts:
    • Text and headings: "Linux Libertine"
    • Code blocks: "New Computer Modern Mono"
  • Sizes:
    • Body text: 11pt
    • Captions and code: 10pt
    • Headings: 14pt
  • Colors:
    • Text: black
    • Background: white
    • Accent: blue
    • Code/quote background: light gray (rgb(245, 245, 245))
  • Page:
    • Size: A4 (210mm ×ばつ 297mm)
    • Margins: 25mm on all sides
  • Spacing:
    • Paragraph/block spacing: 1em
    • List item spacing: 0.5em
    • Indentation: 1-2em depending on element
  • Text properties:
    • Weight: regular (bold for headings)
    • Style: normal (italic for captions and quotes)
    • Alignment: left (center for page numbers)
    • Language: English

Value Formats

When specifying values, use these formats:

  • Absolute units: pt, mm, cm, in
  • Relative units: em, fr (fraction)
  • Percentages: "120%"
  • Colors:
    • Hex: "#ff0000"
    • RGB: { r = 255, g = 0, b = 0 }
    • Named: "red", "blue", etc.
  • Font weights:
    • "thin", "extralight", "light", "regular", "medium"
    • "semibold", "bold", "extrabold", "black"
  • Text alignment:
    • "left", "center", "right", "justify"

Examples

Minimal Configuration

A simple configuration that changes just a few settings:

[text]
font = "Arial"
size = "12pt"
[heading]
level1.size = "16pt"
level1.color = "blue"
[paragraph]
text-align = "justify"

Academic Paper Style

A configuration suitable for academic papers:

[page]
width = "6.5in"
height = "9in"
margin.top = "1in"
margin.bottom = "1in"
margin.left = "1in"
margin.right = "1in"
numbering = "1"
[text]
font = "New Computer Modern"
size = "11pt"
text-align = "justify"
[heading]
level1.size = "14pt"
level1.style = "normal"
level1.numbering = "1."
level2.size = "12pt"
level2.style = "normal"
level2.numbering = "1.1."
[paragraph]
first-line-indent = "0.5in"
space-above = "0em"
space-below = "0em"
leading = "1.5em"

Modern Web Documentation

A style suitable for web-based documentation:

[page]
width = "auto"
margin.left = "2em"
margin.right = "2em"
background = "#ffffff"
[text]
font = "Source Sans Pro"
size = "14pt"
text-align = "left"
[heading]
level1.font = "Source Sans Pro"
level1.size = "24pt"
level1.weight = "bold"
level1.color = "#2a4b8d"
level1.numbering = "none"
[code-block]
font = "Fira Code"
size = "13pt"
background = "#f5f5f5"
line-numbers = true
[block-quote]
background = "#f9f9f9"
indent = "1em"
font-style = "italic"
[list]
marker = "•"
indent = "1.5em"
item-spacing = "0.5em"

Book Chapter

A configuration for book chapters:

[page]
width = "6in"
height = "9in"
margin.top = "0.75in"
margin.bottom = "0.75in"
margin.left = "0.75in"
margin.right = "0.75in"
numbering = "I"
[text]
font = "Palatino"
size = "11pt"
text-align = "justify"
[heading]
level1.font = "Palatino"
level1.size = "18pt"
level1.weight = "bold"
level1.space-above = "2em"
level1.space-below = "1em"
level1.numbering = "none"
[paragraph]
first-line-indent = "1em"
leading = "1.4em"
[caption]
font = "Palatino"
size = "10pt"
style = "italic"
space-above = "0.5em"
space-below = "1em"

Dependencies

  • toml = "0.7.6"
  • serde = { version = "1.0", features = ["derive"] }
  • anyhow = "1.0"
  • clap = { version = "4.4", features = ["derive"] }

License

MIT