Typst and Touying Agent Skills

repository·main·Indexed 41 days ago

https://github.com/apcamargo/typst-skills

A collection of agent skills for AI assistants to improve performance when working with Typst and the Touying presentation package. Includes the `typst-author` skill with a mirror of official Typst documentation and the `touying-author` skill featuring guides on building custom themes, configuring colors via `config-colors()`, and implementing advanced slide layouts and animations for Touying 0.6.1.

Tokens
78.4K
Snippets
313
Records
448
Agent score
54%

What's inside Typst Skills

  1. Introduction to Touying

    main

    Touying is a slide and presentation package for Typst. It is designed as a modern alternative to LaTeX Beamer, offering faster rendering speeds and a more concise syntax.

    Terminology:

    • slides: Refers to the entire slideshow.
    • slide: Refers to a single slide.
    • subslide: Refers to a sub-slide within a slide.

    Key Advantages:

    • Content/Style Separation: Unlike PowerPoint, Touying allows you to separate content from styling, making it ideal for research writing involving code blocks, math, and theorems.
    • Typesetting Control: Provides more powerful control over headers, footers, and layouts compared to Markdown-based slide tools.
    • Dynamic Capabilities: Supports #pause and #meanwhile markers for dynamic slide transitions.
    • Performance: Offers millisecond-level compilation speeds, significantly faster than LaTeX Beamer.
  2. Overview of available Typst skills

    main

    This repository provides specialized skills to help AI agents write, edit, and debug Typst documents without hallucinating syntax. It works by providing the agent with local copies of documentation and examples to search through before generating code.

    Available skills:

    • typst-author: A general-purpose skill for writing Typst documents. It contains a complete mirror of the official Typst documentation, including references, tutorials, and guides.
    • touying-author: A specialized skill for creating presentation slides using the Touying package. It includes local Touying documentation and examples for slide decks, animations, and custom themes.
  3. Use the typst-author skill

    main

    The typst-author skill is designed for agents to generate, edit, and troubleshoot Typst (.typ) documents. It is used for document creation, debugging, compilation, formatting, template work, and answering syntax questions.

    Key Workflows:

    • New Projects: Start with a minimal document example and follow the tutorial sequence.
    • Editing: Locate target text, apply changes, and verify syntax against the local reference.
    • Formatting: Use typstyle for post-edit checks to ensure consistency.
    • Consistency: Always reuse existing fonts, colors, and typographic hierarchies for new layouts, figures, or tables.
    #set document(title: "My Document", author: "Author Name")
    #set page(numbering: "1")
    #set text(lang: "en")
    
    #set par(
      justify: true,
      justification-limits: (
        tracking: (min: -0.012em, max: 0.012em),
        spacing: (min: 75%, max: 120%),
      )
    )
    
    #title[My Document]
    
    = Heading 1
    
    This is a paragraph in Typst.
    
    == Heading 2
    
    #lorem(50)
  4. Use advanced Table features

    main

    Tables in Typst support complex structures:

    • Multiple Headers: You can define multiple header rows or subheaders within a table.
    • Rowbreaks: Table headers now automatically force a rowbreak, ensuring that an incomplete row before a header is not filled with cells after the header appears.
    • Augment Lines: An augment line can now be placed at the very start or very end of a matrix/table, in addition to being used between columns and rows.
  5. Use Figures and Labels for Referencing

    main

    To create a captioned figure, use the #figure function. This function takes the content (like an image) as a positional argument and an optional caption as a named argument.

    • Content Blocks: Use square brackets [...] to pass markup to arguments like caption.
    • Labels: Attach a label to a figure (or heading/equation) by adding <name> immediately after the element.
    • Referencing: Reference a labeled element using the [@name] syntax.
    Glaciers as the one shown in @glaciers will cease to exist...
    
    #figure(
      image("glacier.jpg", width: 70%),
      caption: [
        _Glaciers_ form an important part of the earth's climate system.
      ],
    ) <glaciers>
  6. Align table content using the align argument

    main

    You can control the alignment of table content using the align argument in the table function. There are three ways to specify alignment:

    1. Single alignment: Applies the same alignment to all cells (e.g., right, center + horizon).
    2. Array of alignments: Typst cycles through the array for each column. This is useful for setting different alignments per column.
    3. Function: A function that receives the horizontal x and vertical y coordinates of a cell and returns an alignment. This allows for complex, conditional alignment logic (e.g., different alignment for headers vs. body).

    To combine horizontal and vertical alignments, use the + operator (e.g., left + top).

    Note: You can also override alignment for a single cell using the align argument within the table.cell function.

    #table(
      columns: 4,
      // Using an array to cycle alignment per column
      align: (right, left, left, left),
      // Using a function for conditional alignment
      // x == 0 is the first column, y == 0 is the first row
      align: (x, y) =>
        if x == 0 { right } else { left } +
        if y == 0 { bottom } else { top },
      table.header[Day][Location][Hotel][Activities],
      [1], [Paris], [Hôtel], [Arrival],
    )
  7. Understand Typst's three syntactical modes

    main

    Typst operates in three distinct modes: Markup, Math, and Code. The document starts in Markup mode by default. You can switch between modes using specific syntax:

    • Code mode: Prefix with # (e.g., #let x = 1). Once in code mode, you don't need further hashes unless you switch back to markup or math.
    • Math mode: Surround with $ (e.g., $x^2$).
    • Markup mode: Surround with [[..]] (e.g., [[let name = [*Typst!*]]] - used primarily within code/math to return to markup).
    New modeSyntaxExample
    CodePrefix with #[Number: #(1 + 2)]
    MathSurround with [$..$][$-x$ is the opposite of $x$]
    MarkupSurround with [[..]]{let name = [*Typst!*]}
    // Switching modes example
    Markup text here. 
    #let x = 1 // Enter code mode
    $x^2$ // Enter math mode
    [[Back to markup]] // Return to markup via content block
  8. Manage reading order for Assistive Technology

    main

    Logical reading order can differ from visual layout order (e.g., when using floating figures). To ensure screen readers announce content in a sensible sequence, place your function calls in the markup where you want them to appear in the logical flow, even if the visual placement is different.

    Best Practices:

    • Typst markup implies a single reading order based on the order of elements in the source code.
    • When using place or move, position the function call in the markup at the point where a screen reader should naturally encounter that content.
  9. Display math inline or as blocks

    main

    In Typst, math formulas are enclosed in dollar signs ($).

    • Inline math: Use single dollar signs without surrounding spaces (e.g., $x^2$).
    • Block math: Ensure the formula starts and ends with at least one space inside the dollar signs (e.g., $ x^2 $). This will force the formula into its own separate block.
    $ A = pi r^2 $
    $ "area" = pi dot "radius"^2 $
  10. Create Lists in Typst

    main

    Lists in Typst do not use environments. They are created using lightweight prefix syntax:

    • Unordered (Bullet) Lists: Prefix each line with a hyphen -.
    • Ordered (Numbered) Lists: Prefix each line with a plus sign +.
    • Term Lists (Description): Use the syntax [/ Term: Description].

    Nesting: Nesting is achieved through indentation. Adding a blank line between items results in increased vertical spacing.

    - Fast
    - Flexible
    - Intuitive
    
    + First item
    + Second item
    
    [/ Term: A description of the term]
  11. Use the new file `path` type

    main

    Typst 0.15 introduces a dedicated path type. This type is now accepted in all locations where paths were previously represented as strings.

    Key behaviors:

    • Paths constructed in one file are resolved relative to their original file when used in another file.
    • Paths can be passed across package boundaries.
    • This allows for more robust project-relative path handling.