diff --git a/flake.nix b/flake.nix index 539840f..bb71950 100644 --- a/flake.nix +++ b/flake.nix @@ -34,6 +34,16 @@ pkgs.selene pkgs.lua-language-server ]; + okular-wrapped = pkgs.symlinkJoin { + name = "okular"; + paths = [ pkgs.kdePackages.okular ]; + nativeBuildInputs = [ pkgs.makeWrapper ]; + postBuild = '' + wrapProgram $out/bin/okular \ + --prefix XDG_DATA_DIRS : "${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}" \ + --prefix XDG_DATA_DIRS : "${pkgs.gtk3}/share/gsettings-schemas/${pkgs.gtk3.name}" + ''; + }; in { default = pkgs.mkShell { @@ -51,6 +61,7 @@ pkgs.mermaid-cli pkgs.zathura pkgs.sioyek + okular-wrapped ]; }; } diff --git a/spec/synctex_okular.lua b/spec/synctex_okular.lua new file mode 100644 index 0000000..982a45c --- /dev/null +++ b/spec/synctex_okular.lua @@ -0,0 +1,38 @@ +vim.cmd([[set runtimepath=$VIMRUNTIME]]) +vim.opt.runtimepath:append('.') +vim.opt.packpath = {} +vim.opt.loadplugins = false + +require('preview.commands').setup() + +vim.fn.serverstart('/tmp/nvim-preview.sock') + +local synctex_pdf = {} +vim.api.nvim_create_autocmd('User', { + pattern = 'PreviewCompileSuccess', + callback = function(args) + synctex_pdf[args.data.bufnr] = args.data.output + end, +}) + +vim.g.preview = { + latex = { + open = { 'okular', '--unique' }, + output = function(ctx) + return vim.fn.fnamemodify(ctx.file, ':h') + .. '/build/' + .. vim.fn.fnamemodify(ctx.file, ':t:r') + .. '.pdf' + end, + }, +} + +vim.keymap.set('n', 's', function() + local pdf = synctex_pdf[vim.api.nvim_get_current_buf()] + if pdf then + vim.fn.jobstart({ + 'okular', '--unique', + ('%s#src:%d:%s'):format(pdf, vim.fn.line('.'), vim.fn.expand('%:p')), + }) + end +end) diff --git a/spec/synctex_sioyek.lua b/spec/synctex_sioyek.lua new file mode 100644 index 0000000..a666409 --- /dev/null +++ b/spec/synctex_sioyek.lua @@ -0,0 +1,42 @@ +vim.cmd([[set runtimepath=$VIMRUNTIME]]) +vim.opt.runtimepath:append('.') +vim.opt.packpath = {} +vim.opt.loadplugins = false + +require('preview.commands').setup() + +vim.fn.serverstart('/tmp/nvim-preview.sock') + +local synctex_pdf = {} +vim.api.nvim_create_autocmd('User', { + pattern = 'PreviewCompileSuccess', + callback = function(args) + synctex_pdf[args.data.bufnr] = args.data.output + end, +}) + +vim.g.preview = { + latex = { + open = { 'sioyek', '--instance-name', 'preview' }, + output = function(ctx) + return vim.fn.fnamemodify(ctx.file, ':h') + .. '/build/' + .. vim.fn.fnamemodify(ctx.file, ':t:r') + .. '.pdf' + end, + }, +} + +vim.keymap.set('n', 's', function() + local pdf = synctex_pdf[vim.api.nvim_get_current_buf()] + if pdf then + vim.fn.jobstart({ + 'sioyek', + '--instance-name', 'preview', + '--reuse-window', + '--forward-search-file', vim.fn.expand('%:p'), + '--forward-search-line', tostring(vim.fn.line('.')), + pdf, + }) + end +end) diff --git a/spec/synctex_zathura.lua b/spec/synctex_zathura.lua index 16c7e76..75ae1fb 100644 --- a/spec/synctex_zathura.lua +++ b/spec/synctex_zathura.lua @@ -23,6 +23,12 @@ vim.g.preview = { 'nvim --server /tmp/nvim-preview.sock' .. [[ --remote-expr "execute('b +%{line} %{input}')"]], }, + output = function(ctx) + return vim.fn.fnamemodify(ctx.file, ':h') + .. '/build/' + .. vim.fn.fnamemodify(ctx.file, ':t:r') + .. '.pdf' + end, }, }