The Neovim plugin for Myriad-Dreamin/tinymist.
https://github.com/chomosuke/typst-preview.nvim/assets/38484873/9f8ecf0f-aa1c-4edb-85a9-96a8005e8f25
Lazy.nvim:
{
'chomosuke/typst-preview.nvim',
lazy = false, -- or ft = 'typst'
version = '1.*',
opts = {}, -- lazy.nvim will implicitly calls `setup {}`
}
Packer.nvim:
use {
'chomosuke/typst-preview.nvim',
tag = 'v1.*',
config = function()
require 'typst-preview'.setup {}
end,
}
vim-plug:
Plug 'chomosuke/typst-preview.nvim', {'tag': 'v1.*'}
Note: You can pin typst's minor version by pinning the minor version of this
plugin, i.e., v1.1.*
instead of v1.*
.
:TypstPreviewUpdate
or require 'typst-preview'.update()
:vim.fn.fnamemodify(vim.fn.stdpath 'data' .. '/typst-preview/', ':p')
.setup {}
.:TypstPreview
::TypstPreview document
(default) or :TypstPreview slide
for slide mode.:TypstPreviewStop
::TypstPreviewToggle
::TypstPreviewFollowCursor
or require 'typst-preview'.set_follow_cursor(true)
::TypstPreviewNoFollowCursor
or require 'typst-preview'.set_follow_cursor(false)
::TypstPreviewFollowCursorToggle
or
require 'typst-preview'.set_follow_cursor(not init.get_follow_cursor())
.:TypstPreviewSyncCursor
or require 'typst-preview'.sync_with_cursor()
::TypstPreviewNoFollowCursor
so that the preview only scroll to the current cursor position
when you want it to.This plugin should work out of the box with no configuration. However, calling
setup()
is required to ensure that the binaries that the plugin depends on are
downloaded and up to date.
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,
-- 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": "<option>","image": "<option>"}' 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
return vim.fn.fnamemodify(path_of_main_file, ':p:h')
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,
}
Set dependencies_bin
option to
dependencies_bin = { ['tinymist'] = 'tinymist' }
should point towards the
Mason installation of tinymist.
The author of Enter-tainer/typst-preview wrote a good comparison here.
All PRs are welcome.
This plugin wouldn't be possible without the work of Enter-tainer/typst-preview and Myriad-Dreamin/tinymist. If you like this plugin enough to star it, please consider starring Enter-tainer/typst-preview and Myriad-Dreamin/tinymist as well.