Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/niuiic/typst-preview.nvim
Neovim plugin to preview typst document.
https://github.com/niuiic/typst-preview.nvim
neovim plugin typst
Last synced: 14 days ago
JSON representation
Neovim plugin to preview typst document.
- Host: GitHub
- URL: https://github.com/niuiic/typst-preview.nvim
- Owner: niuiic
- License: mit
- Created: 2023-09-17T03:42:02.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-11T04:35:00.000Z (6 months ago)
- Last Synced: 2024-07-31T20:42:13.740Z (3 months ago)
- Topics: neovim, plugin, typst
- Language: Lua
- Homepage:
- Size: 11.7 KB
- Stars: 31
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-neovim - niuiic/typst-preview.nvim - Preview typst documents, respond to file changes. (Programming Languages Support / (requires Neovim 0.5))
README
# typst-preview.nvim
Neovim plugin to preview typst document.
[More neovim plugins](https://github.com/niuiic/awesome-neovim-plugins)
## Usage
1. Setup `typst-lsp`. (see example [here](https://github.com/niuiic/modern-neovim-configuration/blob/main/lua/lsp/typst_lsp.lua))
2. Call `require("typst-preview").preview()`.
## How it works
1. Generate pdf files by `typst compile`.
2. Respond to subsequent file changes with `typst-lsp`.
3. Redirect these pdf files to a fixed path when you switch buffer.
4. Preview this pdf by a pdf viewer with the ability to respond to the file changes.## Dependencies
- [typst](https://github.com/typst/typst) (typst compile command)
- [typst-lsp](https://github.com/nvarner/typst-lsp)
- [niuiic/core.nvim](https://github.com/niuiic/core.nvim)
- pdf viewer (recommend okular)## Config
Default configuration here.
```lua
{
-- file opened by pdf viewer
output_file = function()
local core = require("core")
return core.file.root_path() .. "/output.pdf"
end,
-- how to redirect output files
redirect_output = function(original_file, output_file)
vim.cmd(string.format("silent !ln -s %s %s", original_file, output_file))
end,
-- how to preview the pdf file
preview = function(output_file)
local core = require("core")
core.job.spawn("mimeopen", {
output_file,
}, {}, function() end, function() end, function() end)
end,
-- whether to clean all pdf files on VimLeave
clean_temp_pdf = true,
}
```## Notice
Shell commands `ln` and `mimeopen` are used by default. You may need alternatives if they don't exist.
The first time you execute `mimeopen` command, it requires you to set the default application, please run the command manually first, complete the settings before using the plugin.
It is recommended to enable this plugin as soon as reading a typst file, or temp pdf files cannot be cleaned completely.
## Compare to other tools
[typst-live](https://github.com/ItsEthra/typst-live) is awesome. However, severe flickering occurs when the file is updated. This is the limitation of the browser. In addition, it cannot switch files.
[chomosuke/typst-preview.nvim](https://github.com/chomosuke/typst-preview.nvim) supports cross jumping between code and preview, but does not support file switching yet. It should be noted that [typst-preview](https://github.com/Enter-tainer/typst-preview) used by this plugin implements the rendering logic itself instead of using official tools.