Local Package Architecture Feature

Overview

This document outlines the requirements and architecture for creating a local Typst package library for typstwriter.nvim. The goal is to centralize styling, layout, and visual formatting logic into a reusable local package while keeping templates focused on content and metadata.

Motivation

Currently, templates like meeting.typ, note.typ contain duplicated styling code for:

This leads to:

Goals

Primary Goals

  1. Centralized Styling: Create a single source of truth for all visual formatting
  2. Template Simplification: Reduce templates to pure content + metadata
  3. Advanced Layouts: Enable sophisticated styling like colored tags, enhanced lists, rich headers
  4. Maintainability: Changes propagate automatically to all templates
  5. Consistency: Uniform visual appearance across all document types

Secondary Goals

  1. Extensibility: Easy to add new styling functions and components
  2. Performance: Efficient import and compilation
  3. Modularity: Import only needed styling functions
  4. Customization: Allow per-document styling overrides

Architecture Design

Package Structure

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
packages/
└── typstwriter/
    ├── typst.toml           # Package manifest
    ├── lib.typ              # Main library entry point
    ├── core/
    │   ├── layout.typ       # Page layout and typography
    │   ├── metadata.typ     # Metadata display functions
    │   └── typography.typ   # Font and text styling
    ├── components/
    │   ├── tags.typ         # Colored tag styling
    │   ├── headers.typ      # Enhanced header styles
    │   ├── lists.typ        # List formatting and indentation
    │   └── links.typ        # Link styling and formatting
    └── themes/
        ├── default.typ      # Default color scheme
        ├── corporate.typ    # Corporate theme
        └── academic.typ     # Academic paper theme

Package Manifest (typst.toml)

1
2
3
4
5
6
7
8
9
[package]
name = "typstwriter"
version = "0.1.0" 
description = "Local styling library for typstwriter.nvim templates"
authors = ["typstwriter contributors"]
compiler = "0.11"

[dependencies]
# No external dependencies initially

Core Library Functions

Layout Functions

Metadata Display

Advanced Styling Components

Template Integration

Templates become minimal and focused:

#import "../packages/typstwriter/lib.typ": *

#metadata((
  type: "meeting",
  title: "Project Review Meeting",
  date: "2025-01-16",
  status: "draft",
  tags: ("project", "review", "urgent"),
  participants: ("Alice", "Bob", "Charlie"),
))

// Apply template with styling options
#show: meeting-template.with(
  theme: "corporate",
  colored-tags: true,
  enhanced-headers: true
)

// Pure content - no styling concerns
== Agenda
- Review Q4 progress
- Discuss budget allocation

== Discussion Points
// Content here...

== Action Items
// Content here...

Implementation Phases

Phase 1: Core Infrastructure

Phase 2: Template Refactoring

Phase 3: Advanced Styling Components

Phase 4: Theme System

Phase 5: Plugin Integration

Benefits

For Template Authors

For Plugin Development

For Future PKS Evolution

Technical Considerations

Import Performance

Compatibility

Testing Strategy

Success Metrics

Future Enhancements

Advanced Components

Interactive Elements

Collaboration Features

Conclusion

This local package architecture will transform typstwriter.nvim from a template system into a comprehensive document styling platform, laying the groundwork for the future Personal Knowledge System while maintaining the metadata-driven philosophy that makes the plugin unique.