### Install typst-preview.nvim with Packer.nvim
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/README.md
Configure Packer.nvim to install the plugin and automatically call the setup function.
```lua
use {
'chomosuke/typst-preview.nvim',
tag = 'v1.*',
config = function()
require 'typst-preview'.setup {}
end,
}
```
--------------------------------
### vim-plug Setup for typst-preview.nvim
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
This example illustrates how to integrate typst-preview.nvim with vim-plug, specifying the plugin and tag, and then calling the setup function in your Neovim configuration.
```vim
-- vim-plug
-- Plug 'chomosuke/typst-preview.nvim', {'tag': 'v1.*'}
-- Then in your init.vim/init.lua: require('typst-preview').setup {}
```
--------------------------------
### Minimal lazy.nvim Setup for typst-preview.nvim
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
This configuration uses lazy.nvim for minimal setup, automatically loading the plugin to provide Typst previews for any .typ file. It implicitly calls the setup function with default options.
```lua
-- lazy.nvim — minimal setup
{
'chomosuke/typst-preview.nvim',
lazy = false, -- load immediately so preview is available for any .typ file
version = '1.*',
opts = {}, -- calls setup({}) implicitly
}
```
--------------------------------
### setup
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Initializes the plugin and performs a binary download/update check. This function should be called once during Neovim configuration.
```APIDOC
## setup(opts)
### Description
Initializes the plugin, merges user options with defaults, and triggers a quiet binary download/update check. This function must be called once.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **opts** (table) - Optional. A table of configuration options. See the plugin's documentation for available keys such as `debug`, `open_cmd`, `port`, `host`, `invert_colors`, `follow_cursor`, `dependencies_bin`, `extra_args`, `get_root`, and `get_main_file`.
### Request Example
```lua
require('typst-preview').setup({
debug = true,
open_cmd = 'firefox %s',
})
```
### Response
None
```
--------------------------------
### Install typst-preview.nvim with vim-plug
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/README.md
Add this line to your vimrc for installation using vim-plug.
```vim
Plug 'chomosuke/typst-preview.nvim', {'tag': 'v1.*'}
```
--------------------------------
### Setup typst-preview.nvim Configuration
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/README.md
Configure the typst-preview.nvim plugin with various options such as debug logging, custom commands, port binding, color inversion, and cursor following. This setup function requires the 'typst-preview' module.
```lua
require 'typst-preview'.setup {
-- Setting this true will enable logging debug information to
-- `vim.fn.stdpath 'data' .. '/typst-preview/log.txt'`
debug = false,
-- Custom format string to open the output link provided with %s
-- Example: open_cmd = 'firefox %s -P typst-preview --class typst-preview'
open_cmd = nil,
-- Custom port to open the preview server. Default is random.
-- Example: port = 8000
port = 0,
-- Custom host to bind the preview server to.
-- Note that '0.0.0.0' is not supported and [won't be](https://github.com/Myriad-Dreamin/tinymist/issues/2105)
-- Example: host = '192.168.0.10'
host = '127.0.0.1',
-- Setting this to 'always' will invert black and white in the preview
-- Setting this to 'auto' will invert depending if the browser has enable
-- dark mode
-- Setting this to '{"rest": "","image": " "}' will apply
-- your choice of color inversion to images and everything else
-- separately.
invert_colors = 'never',
-- Whether the preview will follow the cursor in the source file
follow_cursor = true,
-- Provide the path to binaries for dependencies.
-- Setting this will skip the download of the binary by the plugin.
-- Warning: Be aware that your version might be older than the one
-- required.
dependencies_bin = {
tinymist = nil,
websocat = nil
},
-- A list of extra arguments (or nil) to be passed to previewer.
-- For example, extra_args = { "--input=ver=draft", "--ignore-system-fonts" }
extra_args = nil,
-- This function will be called to determine the root of the typst project
get_root = function(path_of_main_file)
local root = os.getenv 'TYPST_ROOT'
if root then
return root
end
-- Look for a project marker so imports from parent dirs stay inside root
local main_dir = vim.fs.dirname(vim.fn.fnamemodify(path_of_main_file, ':p'))
local found = vim.fs.find({ 'typst.toml', '.git' }, { path = main_dir, upward = true })
if #found > 0 then
return vim.fs.dirname(found[1])
end
return main_dir
end,
-- This function will be called to determine the main file of the typst
-- project.
get_main_file = function(path_of_buffer)
return path_of_buffer
end,
}
```
--------------------------------
### Packer.nvim Setup for typst-preview.nvim
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
This configuration snippet shows how to set up the typst-preview.nvim plugin using Packer.nvim, ensuring it's tagged with a specific version and calling the setup function during configuration.
```lua
-- Packer.nvim
use {
'chomosuke/typst-preview.nvim',
tag = 'v1.*',
config = function()
require('typst-preview').setup {}
end,
}
```
--------------------------------
### Install typst-preview.nvim with lazy.nvim
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/README.md
Use this configuration for lazy.nvim to install the plugin. Ensure lazy is set to false or specify the filetype to 'typst' for automatic loading.
```lua
{
'chomosuke/typst-preview.nvim',
lazy = false, -- or ft = 'typst'
version = '1.*',
opts = {}, -- lazy.nvim will implicitly calls `setup {}`
}
```
--------------------------------
### Start Typst Preview
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/README.md
Starts the Typst preview. You can optionally specify 'document' (default) or 'slide' mode.
```vim
:TypstPreview
```
```vim
:TypstPreview slide
```
--------------------------------
### Start Typst Preview
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/doc/typst-preview.nvim.txt
Starts the Typst document preview. You can optionally specify the preview mode, such as 'document' (default) or 'slide'. If a preview is already running, this will open an additional frontend for that preview.
```APIDOC
## :TypstPreview
### Description
Start the preview. Optionally, the desired preview mode can be specified: `:TypstPreview document` (default) or `:TypstPreview slide` for slide mode.
If a preview is already running, will open another front end for that preview.
```
--------------------------------
### Neovim Keymaps for Typst Preview
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Sets up convenient keybindings for starting the Typst preview in either document or slide mode.
```lua
-- Keymaps for common preview actions
vim.keymap.set('n', 'tp', 'TypstPreview', { desc = 'Typst preview (document)' })
vim.keymap.set('n', 'ts', 'TypstPreview slide', { desc = 'Typst preview (slide)' })
```
--------------------------------
### Start Typst Preview in Neovim
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Starts the live preview for the current Typst buffer. Accepts 'document' (default) or 'slide' mode. Re-opening an existing preview opens an additional browser tab.
```vim
" Start preview in default document mode
:TypstPreview
" Start preview in slide / presentation mode
:TypstPreview slide
" Re-open an existing preview (opens a second browser tab)
:TypstPreview document
```
--------------------------------
### Full Custom Configuration for typst-preview.nvim with lazy.nvim
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
This example demonstrates a comprehensive configuration for typst-preview.nvim using lazy.nvim, allowing customization of debugging, browser commands, server ports, color inversion, cursor following, binary paths, extra arguments, and root/main file detection.
```lua
-- lazy.nvim — full custom configuration
{
'chomosuke/typst-preview.nvim',
lazy = false,
version = '1.*',
opts = {
-- Write debug logs to stdpath('data')/typst-preview/log.txt
debug = false,
-- Custom browser command; %s is substituted with the preview URL
-- open_cmd = 'firefox %s -P typst-preview --class typst-preview',
open_cmd = nil,
-- Static file server port (0 = pick a random free port)
port = 0,
-- Host the preview server binds to ('0.0.0.0' is NOT supported)
host = '127.0.0.1',
-- Color inversion: 'never' | 'always' | 'auto'
-- Fine-grained: '{"rest":"auto","image":"never"}'
invert_colors = 'never',
-- Automatically scroll preview as cursor moves
follow_cursor = true,
-- Point to pre-installed binaries to skip auto-download
dependencies_bin = {
tinymist = nil, -- e.g. 'tinymist' if installed via Mason
websocat = nil,
},
-- Extra CLI flags forwarded to `tinymist preview`
-- Can also be a function(path, mode, port) -> table|string|nil
extra_args = { '--input=ver=draft', '--ignore-system-fonts' },
-- Return the root directory of the Typst project.
-- Defaults to the nearest directory that contains typst.toml or .git,
-- or the file's own directory if no marker is found.
get_root = function(path_of_main_file)
local root = os.getenv 'TYPST_ROOT'
if root then return root end
local main_dir = vim.fs.dirname(vim.fn.fnamemodify(path_of_main_file, ':p'))
local found = vim.fs.find({ 'typst.toml', '.git' }, { path = main_dir, upward = true })
if #found > 0 then return vim.fs.dirname(found[1]) end
return main_dir
end,
-- Return the main .typ file for a given buffer path.
-- Useful for multi-file projects where every file imports a single root.
get_main_file = function(path_of_buffer)
return path_of_buffer
end,
},
}
```
--------------------------------
### Update Typst Preview Binaries
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/README.md
Run this command to download or update the necessary Typst binaries. This is implicitly called by setup {}.
```vim
:TypstPreviewUpdate
```
--------------------------------
### :TypstPreview
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Starts the live preview for the current buffer, opening the browser immediately. Accepts an optional mode argument: `document` (default) or `slide`. If a preview is already running, this opens an additional browser frontend.
```APIDOC
## :TypstPreview [document|slide]
### Description
Starts the live preview for the current buffer. Opens the browser immediately. Accepts an optional mode argument: `document` (default, normal page layout) or `slide` (presentation/slide layout). If a preview is already running for the file, calling the command again opens an additional browser frontend pointing at the same server.
### Usage
```vim
" Start preview in default document mode
:TypstPreview
" Start preview in slide / presentation mode
:TypstPreview slide
" Re-open an existing preview (opens a second browser tab)
:TypstPreview document
```
### Lua Keymaps
```lua
-- Keymaps for common preview actions
vim.keymap.set('n', 'tp', 'TypstPreview', { desc = 'Typst preview (document)' })
vim.keymap.set('n', 'ts', 'TypstPreview slide', { desc = 'Typst preview (slide)' })
```
```
--------------------------------
### Download/Update typst-preview.nvim Binaries
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
This Vim command manually triggers the download or update of the `tinymist` and `websocat` binaries required by the plugin. This is necessary if automatic updates via package manager setup are not performed.
```vim
" Download / update all required binaries
:TypstPreviewUpdate
```
--------------------------------
### Update Typst Binaries
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/doc/typst-preview.nvim.txt
Downloads the necessary Typst binaries to the data directory. This command must be run before any other commands can be executed. Typically, package managers run this automatically during installation.
```APIDOC
## :TypstPreviewUpdate
### Description
Download the necessary binaries to `vim.fn.fnamemodify(vim.fn.stdpath 'data' .. '/typst-preview/', ':p')`.
This must be run before any other commands can be run.
If you followed the installation instructions, your package manager should automatically run this for you.
### Calls
`require 'typst-preview'.update()`
```
--------------------------------
### Configure tinymist Dependency Path
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/README.md
Specify the path to the tinymist binary when it's installed via Mason. This ensures the plugin uses the correct executable.
```lua
dependencies_bin = {
tinymist = 'tinymist'
}
```
```lua
dependencies_bin = {
tinymist = 'tinymist.cmd'
}
```
--------------------------------
### Get Typst Preview Follow Cursor State via Lua
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Returns the current follow-cursor state as a boolean value.
```lua
local following = require('typst-preview').get_follow_cursor()
if following then
print('Preview is tracking cursor')
else
print('Preview is static')
end
```
--------------------------------
### Configure Dependency Binaries (`dependencies_bin`)
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Specify paths to Mason-installed binaries to avoid redundant downloads. Set to `nil` to keep auto-management.
```lua
require('typst-preview').setup {
dependencies_bin = {
-- Use Mason's managed tinymist installation
tinymist = 'tinymist', -- Linux / macOS
-- tinymist = 'tinymist.cmd', -- Windows
websocat = nil, -- still auto-managed
},
}
```
--------------------------------
### Configure Project Root Resolution (`get_root`)
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Override the default project root detection logic. Honors the TYPST_ROOT environment variable first, then walks upward for `typst.toml` or `.git` markers. Falls back to the main file's directory if no markers are found.
```lua
require('typst-preview').setup {
get_root = function(path_of_main_file)
-- Honour an explicit environment variable first
local env = os.getenv 'TYPST_ROOT'
if env then return env end
-- Walk upward to find typst.toml or .git
local main_dir = vim.fs.dirname(vim.fn.fnamemodify(path_of_main_file, ':p'))
local found = vim.fs.find
({
'typst.toml',
'.git',
},
{
path = main_dir,
upward = true,
})
if #found > 0 then
return vim.fs.dirname(found[1])
end
return main_dir
end,
}
```
--------------------------------
### Configure Typst Preview for Multi-file Projects
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Overrides the `get_main_file` function to support Typst projects with multiple source files, ensuring compilation from the project root.
```lua
require('typst-preview').setup {
get_main_file = function(path_of_buffer)
-- Always compile from the project root regardless of which file is open
local root = vim.fs.dirname(
vim.fs.find({ 'typst.toml', '.git' }, { path = path_of_buffer, upward = true })[1]
or path_of_buffer
)
local main = root .. '/main.typ'
if vim.loop.fs_stat(main) then
return main
end
-- Fall back to the current buffer for single-file projects
return path_of_buffer
end,
}
```
--------------------------------
### require('typst-preview').update()
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Programmatic equivalent of `:TypstPreviewUpdate`. Downloads or refreshes the tinymist and websocat binaries. Returns immediately; the download runs asynchronously.
```APIDOC
## require('typst-preview').update()
### Description
Programmatic equivalent of `:TypstPreviewUpdate`. Downloads or refreshes the tinymist and websocat binaries. Returns immediately; the download runs asynchronously.
### Usage
```lua
-- Trigger a binary update from Lua (e.g. inside an autocommand or script)
require('typst-preview').update()
```
```
--------------------------------
### Neovim Keymap for Toggling Typst Preview
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Binds the Typst preview toggle command to a single key for quick access.
```lua
-- Bind to a single key for quick toggling
vim.keymap.set('n', 'tt', 'TypstPreviewToggle', { desc = 'Toggle Typst preview' })
```
--------------------------------
### Programmatically Update Typst Preview Binaries
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Triggers a download or refresh of the tinymist and websocat binaries from Lua. The download runs asynchronously.
```lua
-- Trigger a binary update from Lua (e.g. inside an autocommand or script)
require('typst-preview').update()
```
--------------------------------
### require('typst-preview').sync_with_cursor()
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Scrolls all open preview frontends to the current cursor position. Programmatic equivalent of `:TypstPreviewSyncCursor`.
```APIDOC
## require('typst-preview').sync_with_cursor()
### Description
Scrolls all open preview frontends to the current cursor position. Programmatic equivalent of `:TypstPreviewSyncCursor`.
### Usage
```lua
-- Manually sync preview to cursor from a keymap or autocommand
vim.keymap.set('n', '', function()
require('typst-preview').sync_with_cursor()
end, { desc = 'Sync Typst preview to cursor' })
```
```
--------------------------------
### Typst Preview Lua Configuration and Keymap for Sync Cursor
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Configures Typst preview to disable follow-cursor by default and sets up a keymap to manually sync the preview to the cursor position on demand.
```lua
-- Example: disable follow-cursor by default, use SyncCursor on demand
require('typst-preview').setup {
follow_cursor = false,
}
vim.keymap.set('n', 'tc', 'TypstPreviewSyncCursor',
{ desc = 'Scroll preview to cursor' })
```
--------------------------------
### Programmatically Sync Typst Preview with Cursor via Lua
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Scrolls all open preview frontends to the current cursor position. This is the programmatic equivalent of the `:TypstPreviewSyncCursor` command.
```lua
-- Manually sync preview to cursor from a keymap or autocommand
vim.keymap.set('n', '', function()
require('typst-preview').sync_with_cursor()
end, { desc = 'Sync Typst preview to cursor' })
```
--------------------------------
### require('typst-preview').get_follow_cursor()
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Returns the current follow-cursor state as a boolean.
```APIDOC
## require('typst-preview').get_follow_cursor()
### Description
Returns the current follow-cursor state as a boolean.
### Usage
```lua
local following = require('typst-preview').get_follow_cursor()
if following then
print('Preview is tracking cursor')
else
print('Preview is static')
end
```
```
--------------------------------
### Configuration: get_main_file
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Override this function to support Typst projects where multiple source files all import a single root document. The function receives the path of the currently focused buffer and must return the path of the main `.typ` file that should be compiled.
```APIDOC
## Configuration: get_main_file
### Description
Override this function to support Typst projects where multiple source files all import a single root document. The function receives the path of the currently focused buffer and must return the path of the main `.typ` file that should be compiled.
### Usage
```lua
require('typst-preview').setup {
get_main_file = function(path_of_buffer)
-- Always compile from the project root regardless of which file is open
local root = vim.fs.dirname(
vim.fs.find({ 'typst.toml', '.git' }, { path = path_of_buffer, upward = true })[1]
or path_of_buffer
)
local main = root .. '/main.typ'
if vim.loop.fs_stat(main) then
return main
end
-- Fall back to the current buffer for single-file projects
return path_of_buffer
end,
}
```
```
--------------------------------
### require('typst-preview').set_follow_cursor(enabled)
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Sets whether the preview scrolls as the cursor moves. Equivalent to `:TypstPreviewFollowCursor` / `:TypstPreviewNoFollowCursor`.
```APIDOC
## require('typst-preview').set_follow_cursor(enabled)
### Description
Sets whether the preview scrolls as the cursor moves. Equivalent to `:TypstPreviewFollowCursor` / `:TypstPreviewNoFollowCursor`.
### Parameters
* `enabled` (boolean) - Whether to enable or disable follow cursor.
### Usage
```lua
-- Disable follow-cursor
require('typst-preview').set_follow_cursor(false)
-- Re-enable it
require('typst-preview').set_follow_cursor(true)
-- Toggle based on current state
require('typst-preview').set_follow_cursor(
not require('typst-preview').get_follow_cursor()
)
```
```
--------------------------------
### Enable Cursor Following in Typst Preview
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/README.md
Enables the preview to scroll as the cursor moves in Neovim. This is the default behavior.
```lua
require 'typst-preview'.set_follow_cursor(true)
```
--------------------------------
### Default typst-preview.get_root Function
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/doc/typst-preview.nvim.txt
This Lua function determines the root of a Typst project. It first checks for a TYPST_ROOT environment variable. If not found, it searches for 'typst.toml' or '.git' files upwards from the main file's directory to establish the project root. Otherwise, it defaults to the directory of the main file.
```lua
function(path_of_main_file)
local root = os.getenv 'TYPST_ROOT'
if root then
return root
end
-- Look for project markers so imports from parent dirs stay inside root
local main_dir = vim.fs.dirname(vim.fn.fnamemodify(path_of_main_file, ':p'))
local found = vim.fs.find({ 'typst.toml', '.git' }, { path = main_dir, upward = true })
if #found > 0 then
return vim.fs.dirname(found[1])
end
return main_dir
end
```
--------------------------------
### Configure Color Inversion (`invert_colors`)
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Control how preview colors are inverted for dark mode support. Options include 'always', 'auto' (follows browser setting), or a JSON string for fine-grained control over different elements.
```lua
-- Always invert (light content on dark background)
require('typst-preview').setup { invert_colors = 'always' }
```
```lua
-- Follow browser dark-mode setting
require('typst-preview').setup { invert_colors = 'auto' }
```
```lua
-- Invert everything except images
require('typst-preview').setup {
invert_colors = '{"rest":"auto","image":"never"}',
}
```
--------------------------------
### typst-preview.get_main_file
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/doc/typst-preview.nvim.txt
A function that determines the main Typst file for the project. It receives the current buffer path and should return the path to the main Typst file.
```APIDOC
## typst-preview.get_main_file
This function will be called to determine the main file of the typst project
Parameters: ~
- {path} (string) The path of the current buffer. This is the buffer that
was focused when `:TypstPreview` is called.
Return: ~
(string) The path to the main file of the typst project.
Type: `function`, Default: `function(path) return path end`
```
--------------------------------
### Lua Function: update()
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/doc/typst-preview.nvim.txt
Downloads the necessary Typst binaries to the data directory. This function must be called before any other commands can be run. Package managers typically handle this automatically.
```APIDOC
## typst-preview.update()
### Description
Download the necessary binaries to `vim.fn.fnamemodify(vim.fn.stdpath 'data' .. '/typst-preview/', ':p')`.
This must be run before any other commands can be run.
If you followed the installation instructions, your package manager should automatically run this for you.
```
--------------------------------
### Toggle Typst Preview
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/README.md
Toggles the Typst preview on or off.
```vim
:TypstPreviewToggle
```
--------------------------------
### TypstPreviewUpdate
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Manually downloads or updates the `tinymist` and `websocat` binaries required by the plugin.
```APIDOC
## :TypstPreviewUpdate
### Description
Downloads or updates the `tinymist` and `websocat` binaries to `stdpath('data')/typst-preview/`. This command must be run before any preview functionality is available, though package managers calling `setup {}` often handle this automatically.
### Method
User Command
### Endpoint
N/A
### Parameters
None
### Request Example
```vim
:TypstPreviewUpdate
```
### Response
None
```
--------------------------------
### Set Typst Preview Follow Cursor State via Lua
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Sets whether the preview scrolls as the cursor moves. Accepts a boolean argument.
```lua
-- Disable follow-cursor
require('typst-preview').set_follow_cursor(false)
-- Re-enable it
require('typst-preview').set_follow_cursor(true)
-- Toggle based on current state
require('typst-preview').set_follow_cursor(
not require('typst-preview').get_follow_cursor()
)
```
--------------------------------
### Toggle Cursor Following
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/doc/typst-preview.nvim.txt
Toggles the cursor following feature for the preview. If it's currently enabled, it will be disabled, and vice versa.
```APIDOC
## :TypstPreviewFollowCursorToggle
### Description
Start or stop scrolling preview as cursor moves.
### Calls
`require 'typst-preview'.set_follow_cursor(not require 'typst-preview'.get_follow_cursor())`
```
--------------------------------
### typst-preview.extra_args
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/doc/typst-preview.nvim.txt
A list of extra arguments to be passed to the previewer. This can be used to customize the preview behavior, such as specifying input formats or ignoring system fonts.
```APIDOC
## typst-preview.extra_args
A list of extra arguments (or nil) to be passed to previewer.
For example, `{ "--input=ver=draft", "--ignore-system-fonts" }`
Type: `table`, Default: `nil`
```
--------------------------------
### Sync Cursor Position with Typst Preview
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/README.md
Manually scrolls the preview to the current cursor position. Useful when cursor following is disabled.
```lua
require 'typst-preview'.sync_with_cursor()
```
--------------------------------
### Control Typst Preview Cursor Following in Neovim
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Commands to control whether the preview panel scrolls to track the cursor position. Follow-cursor is enabled by default.
```vim
" Enable cursor tracking (default)
:TypstPreviewFollowCursor
" Disable cursor tracking — preview stays put while you edit
:TypstPreviewNoFollowCursor
" Toggle between the two states
:TypstPreviewFollowCursorToggle
```
--------------------------------
### Sync Typst Preview Cursor Position in Neovim
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Performs a one-shot scroll of the preview to the current cursor position. Most useful when follow-cursor is disabled.
```vim
:TypstPreviewSyncCursor
```
--------------------------------
### :TypstPreviewFollowCursor / :TypstPreviewNoFollowCursor / :TypstPreviewFollowCursorToggle
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Control whether the preview panel scrolls to track the cursor position in the source file. Follow-cursor is enabled by default.
```APIDOC
## :TypstPreviewFollowCursor / :TypstPreviewNoFollowCursor / :TypstPreviewFollowCursorToggle
### Description
Control whether the preview panel scrolls to track the cursor position in the source file. Follow-cursor is enabled by default. These commands are useful when you want to read a different section of the preview without the view jumping as you edit.
### Usage
```vim
" Enable cursor tracking (default)
:TypstPreviewFollowCursor
" Disable cursor tracking — preview stays put while you edit
:TypstPreviewNoFollowCursor
" Toggle between the two states
:TypstPreviewFollowCursorToggle
```
### Lua Example
```lua
-- Example: disable follow-cursor by default, use SyncCursor on demand
require('typst-preview').setup {
follow_cursor = false,
}
vim.keymap.set('n', 'tc', 'TypstPreviewSyncCursor',
{ desc = 'Scroll preview to cursor' })
```
```
--------------------------------
### Pass Extra Arguments to Tinymist (`extra_args`)
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Provide additional CLI flags to `tinymist preview`. Can be a static list or a dynamic function that generates flags based on the current file, mode, and port.
```lua
-- Static list of extra flags
require('typst-preview').setup {
extra_args = { '--input=ver=draft', '--ignore-system-fonts' },
}
```
```lua
-- Dynamic flags based on the file being previewed
require('typst-preview').setup {
extra_args = function(path, mode, port)
if mode == 'slide' then
return { '--input=slide=true' }
end
return {}
end,
}
```
--------------------------------
### typst-preview.get_root
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/doc/typst-preview.nvim.txt
A function that determines the root directory of the Typst project. It receives the path to the main file and should return the project's root path.
```APIDOC
## typst-preview.get_root
This function will be called to determine the root of the typst project
Parameters: ~
- {path} (string) The path to the main file. This is the string returned by
|typst-preview.get_main_file|.
Return: ~
(string) The path to the root of the typst project.
Type: `function`,
Default: >lua
function(path_of_main_file)
local root = os.getenv 'TYPST_ROOT'
if root then
return root
end
-- Look for project markers so imports from parent dirs stay inside root
local main_dir = vim.fs.dirname(vim.fn.fnamemodify(path_of_main_file, ':p'))
local found = vim.fs.find({ 'typst.toml', '.git' }, { path = main_dir, upward = true })
if #found > 0 then
return vim.fs.dirname(found[1])
end
return main_dir
end<
```
--------------------------------
### Lua Function: get_follow_cursor()
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/doc/typst-preview.nvim.txt
Returns a boolean indicating whether the preview is currently set to follow the cursor's movement.
```APIDOC
## typst-preview.get_follow_cursor()
### Description
Returns whether the preview is currently following cursor or not.
### Return
~
(boolean) whether preview is currently following cursor.
```
--------------------------------
### :TypstPreviewStop
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Stops the preview server for the current buffer and closes associated processes.
```APIDOC
## :TypstPreviewStop
### Description
Stops the preview server for the current buffer and closes the associated tinymist and websocat processes.
### Usage
```vim
:TypstPreviewStop
```
```
--------------------------------
### Toggle Cursor Following in Typst Preview
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/README.md
Toggles the cursor following feature on or off.
```lua
require 'typst-preview'.set_follow_cursor(not init.get_follow_cursor())
```
--------------------------------
### Lua Function: sync_with_cursor()
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/doc/typst-preview.nvim.txt
Synchronizes the preview display to the current cursor position in the document. This function is useful for manual synchronization, especially when automatic cursor following is disabled.
```APIDOC
## typst-preview.sync_with_cursor()
### Description
Scroll preview to the current cursor position. This can be used in combination with |:TypstPreviewNoFollowCursor| so that the preview only scroll to the current cursor position when you want it to.
```
--------------------------------
### Enable Cursor Following
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/doc/typst-preview.nvim.txt
Enables the feature where the preview scrolls automatically as the cursor moves within the document. This is the default behavior.
```APIDOC
## :TypstPreviewFollowCursor
### Description
Scroll preview as cursor moves. This is the default.
### Calls
`require 'typst-preview'.set_follow_cursor(true)`
```
--------------------------------
### Toggle Typst Preview
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/doc/typst-preview.nvim.txt
Toggles the Typst document preview. If a preview has been opened previously, it will be reopened with the same mode as the last session.
```APIDOC
## :TypstPreviewToggle
### Description
Toggle the preview.
If the preview has been opened before, will open the preview with the same mode as last time.
```
--------------------------------
### Stop Typst Preview
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/README.md
Stops the Typst preview.
```vim
:TypstPreviewStop
```
--------------------------------
### :TypstPreviewSyncCursor
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Performs a one-shot scroll of the preview to the current cursor position. Most useful when follow-cursor is disabled.
```APIDOC
## :TypstPreviewSyncCursor
### Description
Performs a one-shot scroll of the preview to the current cursor position. Most useful when follow-cursor is disabled — you can read freely then jump the preview to where you are with a single keystroke.
### Usage
```vim
:TypstPreviewSyncCursor
```
```
--------------------------------
### :TypstPreviewToggle
Source: https://context7.com/chomosuke/typst-preview.nvim/llms.txt
Toggles the preview on or off for the current buffer. If a preview was previously opened, it reopens using the same mode (document or slide) that was last used.
```APIDOC
## :TypstPreviewToggle
### Description
Toggles the preview on or off for the current buffer. If a preview was previously opened, it reopens using the same mode (document or slide) that was last used.
### Usage
```vim
:TypstPreviewToggle
" Bind to a single key for quick toggling
vim.keymap.set('n', 'tt', 'TypstPreviewToggle', { desc = 'Toggle Typst preview' })
```
```
--------------------------------
### Lua Function: set_follow_cursor(follow_cursor)
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/doc/typst-preview.nvim.txt
Controls whether the preview scrolls automatically as the cursor moves. Setting `follow_cursor` to `true` enables this behavior, while `false` disables it. The default value is `true`.
```APIDOC
## typst-preview.set_follow_cursor({bool})
### Description
Calling `require 'typst-preview'.set_follow_cursor(true)` will make preview scroll when cursor moves.
Calling `require 'typst-preview'.set_follow_cursor(false)` will stop preview from scrolling when cursor moves
Default: `true`
### Parameters
~
- {follow_cursor} (boolean) whether to scroll preview when cursor moves.
```
--------------------------------
### Disable Cursor Following in Typst Preview
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/README.md
Disables the preview from automatically scrolling as the cursor moves.
```lua
require 'typst-preview'.set_follow_cursor(false)
```
--------------------------------
### Stop Typst Preview
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/doc/typst-preview.nvim.txt
Stops the currently running Typst document preview.
```APIDOC
## :TypstPreviewStop
### Description
Stop the preview.
```
--------------------------------
### Sync Cursor Position
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/doc/typst-preview.nvim.txt
Manually scrolls the preview to synchronize with the current cursor position in the document. This is useful in conjunction with disabling automatic cursor following.
```APIDOC
## :TypstPreviewSyncCursor
### Description
Scroll preview to the current cursor position. This can be used in combination with |:TypstPreviewNoFollowCursor| so that the preview only scroll to the current cursor position when you want it to.
### Calls
`require 'typst-preview.sync_with_cursor()`
```
--------------------------------
### Disable Cursor Following
Source: https://github.com/chomosuke/typst-preview.nvim/blob/master/doc/typst-preview.nvim.txt
Disables the feature where the preview scrolls automatically as the cursor moves within the document.
```APIDOC
## :TypstPreviewNoFollowCursor
### Description
Don't scroll preview as cursor moves.
### Calls
`require 'typst-preview'.set_follow_cursor(false)`
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.