### Basic Package Manifest Example Source: https://typst-community.github.io/extra-docs/packages/manifest.html This is a minimal example of a `typst.toml` file, showcasing the required `[package]` section with essential metadata. ```toml [package] name = "example" version = "0.1.0" entrypoint = "lib.typ" authors = ["The Typst Project Developers"] license = "MIT" description = "Calculate elementary arithmetics with functions." ``` -------------------------------- ### Basic Formattable String Source: https://typst-community.github.io/extra-docs/hayagriva/file-format.html A simple formattable string example demonstrating basic case-folding behavior. ```yaml __ publisher: UN World Food Programme ``` -------------------------------- ### Page Range Example Source: https://typst-community.github.io/extra-docs/print.html Demonstrates how to specify a page range using a numeric variable with a prefix and suffix. ```typst __ page-range: S10-15 # Page S10 to 15 ``` -------------------------------- ### Article with Multiple Parents (Conference and Video) Source: https://typst-community.github.io/extra-docs/hayagriva/file-format.html Demonstrates handling media published in multiple ways using a list for the 'parent' field. This example shows an article presented at a conference and also available as a video. ```yaml wwdc-network: type: Article author: ["Mehta, Jiten", "Kinnear, Eric"] title: Boost Performance and Security with Modern Networking date: 2020-06-26 parent: - type: Conference title: World Wide Developer Conference 2020 organization: Apple Inc. location: Mountain View, CA - type: Video runtime: "00:13:42" url: https://developer.apple.com/videos/play/wwdc2020/10111/ ``` -------------------------------- ### Import Package with Full Specification Source: https://typst-community.github.io/extra-docs/print.html Use the full package specification for imports in example files to ensure they are self-contained and compilable as is. This is a requirement for template files. ```typst #import "@preview/my-package:1.0.0": my-function ``` ```typst #import "../lib.typ": my-function ``` -------------------------------- ### Install Hayagriva CLI Source: https://typst-community.github.io/extra-docs/hayagriva/index.html Install the Hayagriva Command Line Interface using Cargo. This command installs the CLI tool for use in your terminal. ```bash cargo install hayagriva --features cli ``` -------------------------------- ### Typst Document Configuration and Scripting Example Source: https://typst-community.github.io/extra-docs/typst/index.html This snippet demonstrates how to configure page settings, heading numbering, and generate dynamic content using Typst's scripting capabilities, including defining variables, functions, and creating tables. ```typst #set page(width: 10cm, height: auto) #set heading(numbering: "1.") = Fibonacci sequence The Fibonacci sequence is defined through the recurrence relation $F_n = F_(n-1) + F_(n-2)$. It can also be expressed in _closed form:_ $ F_n = round(1 / sqrt(5) phi.alt^n), quad phi.alt = (1 + sqrt(5)) / 2 $ #let count = 8 #let nums = range(1, count + 1) #let fib(n) = ( if n <= 2 { 1 } else { fib(n - 1) + fib(n - 2) } ) The first #count numbers of the sequence are: #align(center, table( columns: count, ..nums.map(n => $F_#n$), ..nums.map(n => str(fib(n))), )) ``` -------------------------------- ### Correctly Handling Image Input in Typst Template Source: https://typst-community.github.io/extra-docs/packages/resources.html This example demonstrates the recommended approach for handling image assets in Typst templates. It accepts the image content directly as an argument, allowing for easier customization by the user. ```typst #let cover-page(logo: image("logo.png"), title) = { logo heading(title) } ``` -------------------------------- ### Defining Private and Public Functions in a Package Source: https://typst-community.github.io/extra-docs/packages/typst.html This example shows how to define internal functions and expose only specific ones to the user. The `package.typ` defines both private and public functions, while `lib.typ` imports only the desired public function. ```typst #let private(a, b) = a + b #let public(a, b, c) = private(a, b) * private(b, c) ``` ```typst #import "package.typ": public ``` -------------------------------- ### Typst CLI Help Source: https://typst-community.github.io/extra-docs/print.html Prints a list of available subcommands and options for the Typst CLI. Detailed usage for a specific subcommand can be accessed with `typst help `. ```bash typst help ``` ```bash typst help watch ``` -------------------------------- ### Responsive Image for Light and Dark Themes Source: https://typst-community.github.io/extra-docs/print.html Include this snippet in your README to display images that adapt to the user's preferred color scheme. Ensure 'example-light.png' and 'example-dark.png' are available in your package. ```html Example output ``` -------------------------------- ### Timestamp Range Source: https://typst-community.github.io/extra-docs/hayagriva/file-format.html Represents a range of timestamps, with the first indicating the start and the second the end. Double-quotes are necessary due to colons. ```yaml __ time-range: "03:35:21-03:58:46" ``` -------------------------------- ### Numeric Variable with Page Range Source: https://typst-community.github.io/extra-docs/hayagriva/file-format.html Numeric variables can express a range using hyphens. This example shows a page range from S10 to S15. ```yaml page-range: S10-15 ``` -------------------------------- ### Generate References with Selector Source: https://typst-community.github.io/extra-docs/hayagriva/index.html Use the --select argument with a custom Hayagriva selector to filter entries, for example, to include only those with a URL or DOI. ```bash hayagriva literature.yaml --select "*[url] | *[doi]" reference ``` -------------------------------- ### Typst CLI Help Commands Source: https://typst-community.github.io/extra-docs/typst/index.html Provides access to help information for the Typst CLI, including listing available subcommands and options, or displaying detailed usage for a specific subcommand. ```bash # Prints available subcommands and options. typst help ``` ```bash # Prints detailed usage of a subcommand. typst help watch ``` -------------------------------- ### Article in a Scientific Journal Source: https://typst-community.github.io/extra-docs/hayagriva/file-format.html Example of an article published in a periodical. The 'parent' field specifies the journal details. Fields like 'title' can be used for both the article and its parent. ```yaml kinetics: type: Article title: Kinetics and luminescence of the excitations of a nonequilibrium polariton condensate author: ["Doan, T. D.", "Tran Thoai, D. B.", "Haug, Hartmut"] serial-number: doi: "10.1103/PhysRevB.102.165126" page-range: 165126-165139 date: 2020-10-14 parent: type: Periodical title: Physical Review B volume: 102 issue: 16 publisher: American Physical Society ``` -------------------------------- ### Add Tool Configuration to Manifest Source: https://typst-community.github.io/extra-docs/packages/manifest.html Use the `[tool.]` section to attach Typst-specific configuration for third-party tools to the manifest. ```toml [package] # ... [tool.mytool] foo = "bar" ``` -------------------------------- ### Filter Bibliography Entries with Selector Macro Source: https://typst-community.github.io/extra-docs/print.html Uses the `select!` macro to define and apply a selector to filter bibliography entries. This example filters for 'Article' type entries published in a 'journal' with a 'Periodical' parent. ```rust __ use hayagriva::select; use hayagriva::io::from_yaml_str; let yaml = r#" quantized-vortex: type: Article author: Gross, E. P. title: Structure of a Quantized Vortex in Boson Systems date: 1961-05 page-range: 454-477 doi: 10.1007/BF02731494 parent: issue: 3 volume: 20 title: Il Nuovo Cimento "#; let entries = from_yaml_str(yaml).unwrap(); let journal = select!((Article["date"]) > ("journal":Periodical)); assert!(journal.matches(entries.nth(0).unwrap())); ``` -------------------------------- ### Build Typst CLI Source: https://typst-community.github.io/extra-docs/typst/index.html Clone the Typst repository and build the command-line interface (CLI) using Cargo. The optimized binary will be available in the target/release/ directory. ```bash git clone https://github.com/typst/typst cd typst cargo build --release ``` -------------------------------- ### YAML List Representation for Authors (Compact) Source: https://typst-community.github.io/extra-docs/print.html Demonstrates the compact YAML syntax for representing a list of authors using square brackets and double-quoted names. ```yaml author: ["Omarova, Saule", "Steele, Graham"] ``` -------------------------------- ### Include Images for Light and Dark Themes Source: https://typst-community.github.io/extra-docs/packages/documentation.html Use this HTML snippet in your README.md to include images that adapt to both light and dark themes. Specify separate image sources for each theme using the `` tag with media queries. ```html Example output ``` -------------------------------- ### Incorrectly Handling Image Path in Typst Template Source: https://typst-community.github.io/extra-docs/packages/resources.html This example shows an incorrect way to handle image paths in a Typst template. It uses a string path which can lead to issues when users try to customize the image. ```typst #let cover-page(logo-path: "logo.png", title) = { image(logo-path) heading(title) } ``` -------------------------------- ### Generate Template Thumbnail Source: https://typst-community.github.io/extra-docs/packages/manifest.html Command to compile a Typst document to a PNG thumbnail for template submissions. Adjust PPI and page count as needed. ```bash typst compile -f png --pages 1 --ppi 250 main.typ thumbnail.png ``` -------------------------------- ### Parse and Format Bibliography Entries Source: https://typst-community.github.io/extra-docs/hayagriva/index.html Demonstrates parsing a YAML bibliography string and then formatting entries into citations and a bibliography using CSL styles and locale files. ```rust use hayagriva::io::from_yaml_str; let yaml = r#" crazy-rich: type: Book title: Crazy Rich Asians author: Kwan, Kevin date: 2014 publisher: Anchor Books location: New York, NY, US "#; // Parse a bibliography let bib = from_yaml_str(yaml).unwrap(); assert_eq!(bib.get("crazy-rich").unwrap().date().unwrap().year, 2014); // Format the reference use std::fs; use hayagriva:: BibliographyDriver, BibliographyRequest, BufWriteFormat, CitationItem, CitationRequest, ; use hayagriva::citationberg::{LocaleFile, IndependentStyle}; let en_locale = fs::read_to_string("tests/data/locales-en-US.xml").unwrap(); let locales = [LocaleFile::from_xml(&en_locale).unwrap().into()]; let style = fs::read_to_string("tests/data/art-history.csl").unwrap(); let style = IndependentStyle::from_xml(&style).unwrap(); let mut driver = BibliographyDriver::new(); for entry in bib.iter() { let items = vec![CitationItem::with_entry(entry)]; driver.citation(CitationRequest::from_items(items, &style, &locales)); } let result = driver.finish(BibliographyRequest { style: &style, locale: None, locale_files: &locales, }); for cite in result.citations { println!("{}", cite.citation.to_string()) } ``` -------------------------------- ### Template Package `typst.toml` Configuration Source: https://typst-community.github.io/extra-docs/packages/manifest.html Defines the metadata and template-specific settings for a Typst template package. Ensure `path` points to the template files and `entrypoint` specifies the main template file. ```toml [package] name = "charged-ieee" version = "0.1.0" entrypoint = "lib.typ" authors = ["Typst GmbH "] license = "MIT-0" description = "IEEE-style paper to publish at conferences and journals." [template] path = "template" entrypoint = "main.typ" thumbnail = "thumbnail.png" ``` -------------------------------- ### Using Relative Imports (Not Recommended) Source: https://typst-community.github.io/extra-docs/packages/typst.html Avoid using relative imports like this when referencing your own package, as it can lead to compilation issues if files are moved or copied. ```typst #import "../lib.typ": my-function ``` -------------------------------- ### Clone Typst Packages Repository with Sparse Checkout Source: https://typst-community.github.io/extra-docs/packages/tips.html Clone the Typst packages repository efficiently using sparse checkout to only include specific package directories. This reduces clone time and disk space. Ensure you have forked the repository first. ```bash git clone --depth 1 --no-checkout --filter="tree:0" git@github.com:{your-username}/packages cd packages git sparse-checkout init git sparse-checkout set packages/preview/{your-package-name} git remote add upstream git@github.com:typst/packages git config remote.upstream.partialclonefilter tree:0 git checkout main ``` -------------------------------- ### Select by Entry Type (Macro) Source: https://typst-community.github.io/extra-docs/print.html Use the `select!` macro to match entries with a specific top-level type. Capitalization must match the EntryType struct variants exactly. ```macro Thesis ``` -------------------------------- ### Generate Reference List with APA Style Source: https://typst-community.github.io/extra-docs/hayagriva/index.html Generate a reference list using the American Psychological Association (APA) style by specifying the --style argument. ```bash hayagriva literature.yaml reference --style apa ``` -------------------------------- ### Runtime Source: https://typst-community.github.io/extra-docs/hayagriva/file-format.html Indicates the total runtime of an item, such as a video or audio file. Formatted as a timestamp. ```yaml runtime: 01:42:21,802 ``` -------------------------------- ### Select by Entry Type (String) Source: https://typst-community.github.io/extra-docs/print.html Use a string selector to match entries with a specific top-level type. This selector is case-insensitive. ```string thesis ``` -------------------------------- ### Use Selector Macro for Filtering Entries Source: https://typst-community.github.io/extra-docs/hayagriva/index.html Demonstrates using the `select!` macro to parse and apply a selector to filter bibliography entries, matching articles published in a journal. ```rust use hayagriva::select; use hayagriva::io::from_yaml_str; let yaml = r#" quantized-vortex: type: Article author: Gross, E. P. title: Structure of a Quantized Vortex in Boson Systems date: 1961-05 page-range: 454-477 doi: 10.1007/BF02731494 parent: issue: 3 volume: 20 title: Il Nuovo Cimento "#; let entries = from_yaml_str(yaml).unwrap(); let journal = select!((Article["date"]) > ("journal":Periodical)); assert!(journal.matches(entries.nth(0).unwrap())); ``` -------------------------------- ### Compile Typst Document Source: https://typst-community.github.io/extra-docs/typst/index.html Compiles a Typst source file into a PDF document in the working directory. ```bash # Creates `file.pdf` in working directory. typst compile file.typ ``` ```bash # Creates a PDF file at the desired path. typst compile path/to/source.typ path/to/output.pdf ``` -------------------------------- ### Generate Reference List Source: https://typst-community.github.io/extra-docs/print.html Generates a reference list from a YAML literature file. Defaults to Chicago Manual of Style (17th edition). ```bash hayagriva literature.yaml reference ``` -------------------------------- ### Importing Own Package with Full Specification Source: https://typst-community.github.io/extra-docs/packages/typst.html Use the full package specification for imports when referencing your own package to ensure files can be copied and compiled independently. This avoids issues with relative import paths. ```typst #import "@preview/my-package:1.0.0": my-function ``` -------------------------------- ### Compact YAML Composite Data for URL Source: https://typst-community.github.io/extra-docs/print.html Presents a compact, JSON-like syntax for representing composite data for a URL field. ```yaml url: { value: http://www.techno.org/electronic-music-guide/, date: 2020-11-30 } ``` -------------------------------- ### YAML Composite Data for URL with Date Source: https://typst-community.github.io/extra-docs/print.html Illustrates how to represent composite data for a URL field, including its value and an associated date. ```yaml url: value: http://www.techno.org/electronic-music-guide/ date: 2020-11-30 ``` -------------------------------- ### YAML List Representation for Authors (Verbose) Source: https://typst-community.github.io/extra-docs/print.html Shows the verbose YAML syntax for lists, where each item is on a new indented line preceded by a hyphen. ```yaml author: - Omarova, Saule - Steele, Graham ```