<!-- This file is generated by scripts/link-docs.mjs. Do not edit manually. -->
# Tinymist Typst VS Code Extension

[HTML](https://myriad-dreamin.github.io/tinymist/frontend/vscode.html) | Markdown

A VS Code or VS Codium extension for Typst. You can find the extension on:

- Stable and pre-release versions available at [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=myriad-dreamin.tinymist) and [Open VSX](https://open-vsx.org/extension/myriad-dreamin/tinymist).
- The artifacts built per commits at [GitHub Actions](https://github.com/Myriad-Dreamin/tinymist/actions).
- The artifacts built per release at [GitHub Releases](https://github.com/Myriad-Dreamin/tinymist/releases).

## Features

See [Tinymist Features](https://github.com/Myriad-Dreamin/tinymist#features) for a list of features.

## LLM-Assisted Documentation

The [Software Specification](https://github.com/Myriad-Dreamin/tinymist/tree/main/docs/for-llm/vscode-ui.md) contains user interface provided by this extension, You could find solutions by text search in the docs or ask LLMs with plugging the docs.

## Configuration Reference

[Configuration Reference](https://myriad-dreamin.github.io/tinymist/config/vscode.html).

## Usage Tips

### Initializing with a Template

To initialize a Typst project:

- Use command `Typst init template` (tinymist.initTemplate) to initialize a new Typst project based on a template.
- Use command `Typst show template` (tinymist.showTemplateGallery) to show available Typst templates for picking up a template to initialize.

🎉 If your template contains only a single file, you can also insert the template content in place with command:

- Use command `Typst template in place` (tinymist.initTemplateInPlace) and input a template specifier for initialization.

### Configuring LSP-Enhanced Formatters

1. Open settings.
2. Search for “Tinymist Formatter” and modify the value.
   - Use `"formatterMode": "typstyle"` for [typstyle](https://github.com/Enter-tainer/typstyle).
   - Use `"formatterMode": "typstfmt"` for [typstfmt](https://github.com/astrale-sharp/typstfmt).

Tips: to enable formatting on save, you should add extra settings for typst language:

```json
{
  "[typst]": {
    "editor.formatOnSave": true
  }
}
```

### Configuring Linter

1. Open settings.
2. Search for “Tinymist Lint” and modify the value.
   1. Toggle “Enabled” to enable or disable the linter.
   2. Change “When” to configure when the linter runs.
      - (Default) `onSave` run linting when you save the file.
      - `onType` run linting as you type.

### Configuring/Using Tinymist’s Activity Bar (Sidebar)

If you don’t like the activity bar, you can right-click on the activity bar and uncheck “Tinymist” to hide it.

#### Symbol View

- Search symbols by keywords, descriptions, or handwriting.
- See symbols grouped by categories.
- Click on a symbol, then it will be inserted into the editor.

#### Tool View

- Template Gallery: Show available Typst templates for picking up a template to initialize.
- Document Summary: Show a summary of the current document.
- Symbols: Show symbols in the current document.
- Fonts: Show fonts in the current document.
- Profiling: Profile the current document.

#### Package View

- Create or open some local typst packages.
- Show a list of available typst packages and invoke associated commands.

#### Content View

- Show thumbnail content of the current document, which is useful for creating slides.

#### Label View

- Show labels in the current workspace.

#### Outline View

- Show outline of exported document, viewing typst as a markup language.
  - This is slightly different from the LSP-provided document outline, which shows the syntax structure of the document, viewing typst as a programming language.

### Preview Command

Open command palette (Ctrl+Shift+P), and type `>Typst Preview:`.

You can also use the shortcut (Ctrl+K V).

### Theme-aware template (previewing)

In short, there is a `sys.inputs` item added to the compiler when your document is under the context of _user editing or previewing task_. You can use it to configure your template:

```typ
#let preview-args = json.decode(sys.inputs.at("x-preview", default: "{}"))
// One is previewing the document.
#let is-preview = sys.inputs.has("x-preview")
// `dark` or `light`
#let preview-theme = preview-args.at("theme", default: "light")
```

For details, please check [Preview’s sys.inputs](https://myriad-dreamin.github.io/tinymist/feature/preview.html#label-sys.inputs).

### Configuring path to search fonts

To configure path to search fonts:

1. Open settings.
   - File -\> Preferences -\> Settings (Linux, Windows).
   - Code -\> Preferences -\> Settings (Mac).
2. Search for “Tinymist Font Paths” for providing paths to search fonts order-by-order.
3. Search for “Tinymist System Fonts” for disabling system fonts to be searched, which is useful for reproducible rendering your PDF documents.
4. Reload the window or restart the vscode editor to make the settings take effect.

**Note:** you must provide absolute paths.

**Note:** you can use vscode variables in the settings, see [vscode-variables](https://www.npmjs.com/package/vscode-variables) for more information.

For a reproducible setup, the shared embedded-font inventory, and package-path examples that affect preview and export the same way, see [Compiler Settings](https://myriad-dreamin.github.io/tinymist/feature/compiler-settings.html).

### Configuring path to root directory

To configure the root path resolved for Typst compiler:

1. Open settings.
2. Search for “Tinymist Root Path” and modify the value.
3. Reload the window or restart the vscode editor to make the settings take effect. **Note:** you must provide absolute paths.

If you also need package paths, package cache paths, or certificate settings, refer to [Compiler Settings](https://myriad-dreamin.github.io/tinymist/feature/compiler-settings.html) for examples.

### Managing Local Packages

1. Use `Typst: Create Typst Local Package` command to create a local package.
2. Use `Typst: Open Typst Local Package` command to open a local package.
3. View and manage a list of available local packages in the “PACKAGE” view in the activity bar.

### Compiling PDF

This extension compiles to PDF, but it doesn’t have a PDF viewer yet. To view the output as you work, install a PDF viewer extension, such as `vscode-pdf`.

To find a way to compile PDF:

- Click the code len `Export PDF` at the top of document, or use command `Typst Show PDF ...`, to show the current document to PDF.
- Use command `Typst Export PDF` to export the current document to PDF.
- There are code lens buttons at the start of the document to export your document to PDF or other formats.

To configure when PDFs are compiled:

1. Open settings.
2. Search for “Tinymist Export PDF”.
3. Change the “Export PDF” setting.
   - `onSave` makes a PDF after saving the Typst file.
   - `onType` makes PDF files live, as you type.
   - `never` disables PDF compilation.
   - `onDocumentHasTitle` makes a PDF when the document has a title and, as you save.

To configure where PDFs are saved:

1. Open settings.
2. Search for “Tinymist Output Path”.
3. Change the “Output Path” setting. This is the path pattern to store artifacts, you can use `$root` or `$dir` or `$name` to do magic configuration
   - e.g. `$root/$dir/$name` (default) for `$root/path/to/main.pdf`.
   - e.g. `$root/target/$dir/$name` for `$root/target/path/to/main.pdf`.
   - e.g. `$root/target/foo` for `$root/target/foo.pdf`. This will ensure that the output is always output to `target/foo.pdf`.

**Note:** the output path should be substituted as an absolute path.

### Exporting to Other Formats

You can export your documents to various other formats by lsp as well. Currently, the following formats are supported:

- Official svg, png, and pdf.
- Unofficial html, md (typlite), and txt
- Query Results (into json, yaml, or txt), and pdfpc (by `typst query --selector <pdfpc-file>`, for [Touying](https://touying-typ.github.io/touying/))

See [Docs: Exporting Documents](https://myriad-dreamin.github.io/tinymist/feature/export.html) for more information.

### Working under Power-Saving Mode or with Resource-consumed Projects

When working under power-saving mode or with resource-consumed projects, typst compilations costs too much CPU and memory resources. You can configure the extension to run in syntax only mode, i.e. only performing elementary tasks, like syntax checking, syntax-only code analysis and formatting, by:

1. Open settings.
2. Search for “Tinymist Syntax Only Mode”.
3. Toggle the “Syntax Only Mode” setting to always enable, disable syntax only mode, or enable on power-saving mode.

For more information about power-saving mode, see [Syntax-Only Mode](https://myriad-dreamin.github.io/tinymist/feature/syntax-only-mode.html).

### Working with Multiple-File Projects

You can pin a main file by command.

- Use command `Typst Pin Main` (tinymist.pinMainToCurrent) to set the current file as the main file.
- Use command `Typst Unpin Main` (tinymist.unpinMain) to unset the main file.

> [!NOTE]
> > `tinymist.pinMain` is a stateful command, and tinymist doesn’t remember it between sessions (closing and opening the editor).

### Passing Extra CLI Arguments

There is a **global** configuration `tinymist.typstExtraArgs` to pass extra arguments to tinymist LSP, like what you usually do with `typst-cli` CLI. For example, you can set it to `["--input=awa=1", "--input=abaaba=2", "main.typ"]` to configure `sys.inputs` and entry for compiler, which is equivalent to make LSP run like a `typst-cli` with such arguments:

```
typst watch --input=awa=1 --input=abaaba=2 main.typ
```

For the dedicated settings that override these arguments, reproducible font guidance, and package-path examples shared with preview and export, see [Compiler Settings](https://myriad-dreamin.github.io/tinymist/feature/compiler-settings.html).

## Contributing

You can submit issues or make PRs to [GitHub](https://github.com/Myriad-Dreamin/tinymist).
