⌨️
Astro NvimのCommunity pluginのvimtexだとskimが起動しなかった話
Q. Skill issue では?
A. はい。
はじめに
Astro NvimにはAstro communityという、有志が欲しいパッケージを纏めてくれるありがたいものがある。しかし、ここで入れたvimtexだとどうもskimの起動がうまくいかなかったので、結局自分でpluginを書いた、という話。
環境
- MacBook Air(M1) Sequoia
- nvim: v0.10.2
- AstroNvim: v4.26.5
- lazy.nvim: v11.14.1
- skim:v1.7.4
なぜskim?
Mac標準のプレビューが微妙に使いにくい+PDFの更新を感知する自動更新が便利
(どうもPDF更新を自動で感知するよりlatexmk
のときにskimに更新を渡すように設定したほうがいいらしいが、今のところ不都合はないのでまた今度で……)
.latexmkrcの編集
まずはlatexの設定ファイルを編集してあげる。lualatexを使用しているので以下のようになる。
.latexmkrc
#! /usr/bin/env perl
$lualatex = 'lualatex -synctex=1';
$pdflualatex = $lualatex;
$biber = 'biber %O --bblencoding=utf8 -u -U --output_safechars %B';
$bibtex = 'bibtex %O %B';
$makeindex = 'mendex %O -o %D %S';
$max_repeat = 5;
$pdf_mode = 4;
$pvc_view_file_via_temporary = 0;
#preview
$pdf_previewer = "open -ga /Applications/Skim.app";
正直設定ファイルの半分も意味をわかっていないがとりあえずpdf_previewer
をSkimに設定してあげる。
これでうまくいく、という記事も多いがどうもうまくいかない。vimtecのinfoを見てみても(AstroNvimなら,li
で見える)viewerの情報がGlobal
のままである。どうもある記事によればvimtexにも設定を渡す必要があったらしい。
vimtex.luaを作る
community.lua
を編集すると見栄えが悪いので結局plugin/以下にvimtex.luaを作ることにした。基本のキーマップは拝借して、以下のようになった。
vimtex.lua
return {
"lervag/vimtex",
lazy = false,
-- ここからskimの設定
config = function()
vim.g.tex_flavor = "latex"
vim.g.vimtex_view_method = "skim"
vim.g.vimtex_view_general_viewer = "skim"
vim.g.vimtex_view_skim_sync = 1
vim.g.vimtex_view_skim_activate = 1
end,
-- ここまで
dependencies = {
"AstroNvim/astrocore",
opts = {
autocmds = {
vimtex_mapping_descriptions = {
{
event = "FileType",
desc = "Set up VimTex Which-Key descriptions",
pattern = "tex",
callback = function(event)
local wk_avail, wk = pcall(require, "which-key")
if not wk_avail then return end
wk.add {
buffer = event.buf,
{
mode = "n",
{ "<localleader>l", group = "VimTeX" },
{ "<localleader>la", desc = "Show Context Menu" },
{ "<localleader>lC", desc = "Full Clean" },
{ "<localleader>lc", desc = "Clean" },
{ "<localleader>le", desc = "Show Errors" },
{ "<localleader>lG", desc = "Show Status for All" },
{ "<localleader>lg", desc = "Show Status" },
{ "<localleader>li", desc = "Show Info" },
{ "<localleader>lI", desc = "Show Full Info" },
{ "<localleader>lk", desc = "Stop VimTeX" },
{ "<localleader>lK", desc = "Stop All VimTeX" },
{ "<localleader>lL", desc = "Compile Selection" },
{ "<localleader>ll", desc = "Compile" },
{ "<localleader>lm", desc = "Show Imaps" },
{ "<localleader>lo", desc = "Show Compiler Output" },
{ "<localleader>lq", desc = "Show VimTeX Log" },
{ "<localleader>ls", desc = "Toggle Main" },
{ "<localleader>lt", desc = "Open Table of Contents" },
{ "<localleader>lT", desc = "Toggle Table of Contents" },
{ "<localleader>lv", desc = "View Compiled Document" },
{ "<localleader>lX", desc = "Reload VimTeX State" },
{ "<localleader>lx", desc = "Reload VimTeX" },
{ "ts", group = "VimTeX Toggles & Cycles" },
{ "ts$", desc = "Cycle inline, display & numbered equation" },
{ "tsc", desc = "Toggle star of command" },
{ "tsd", desc = "Cycle (), \\left(\\right) [,...]" },
{ "tsD", desc = "Reverse Cycle (), \\left(\\right) [, ...]" },
{ "tse", desc = "Toggle star of environment" },
{ "tsf", desc = "Toggle a/b vs \\frac{a}{b}" },
{ "[/", desc = "Previous start of a LaTeX comment" },
{ "[*", desc = "Previous end of a LaTeX comment" },
{ "[[", desc = "Previous beginning of a section" },
{ "[]", desc = "Previous end of a section" },
{ "[m", desc = "Previous \\begin" },
{ "[M", desc = "Previous \\end" },
{ "[n", desc = "Previous start of a math zone" },
{ "[N", desc = "Previous end of a math zone" },
{ "[r", desc = "Previous \\begin{frame}" },
{ "[R", desc = "Previous \\end{frame}" },
{ "]/", desc = "Next start of a LaTeX comment %" },
{ "]*", desc = "Next end of a LaTeX comment %" },
{ "][", desc = "Next beginning of a section" },
{ "]]", desc = "Next end of a section" },
{ "]m", desc = "Next \\begin" },
{ "]M", desc = "Next \\end" },
{ "]n", desc = "Next start of a math zone" },
{ "]N", desc = "Next end of a math zone" },
{ "]r", desc = "Next \\begin{frame}" },
{ "]R", desc = "Next \\end{frame}" },
{ "csc", desc = "Change surrounding command" },
{ "cse", desc = "Change surrounding environment" },
{ "cs$", desc = "Change surrounding math zone" },
{ "csd", desc = "Change surrounding delimiter" },
{ "dsc", desc = "Delete surrounding command" },
{ "dse", desc = "Delete surrounding environment" },
{ "ds$", desc = "Delete surrounding math zone" },
{ "dsd", desc = "Delete surrounding delimiter" },
},
{
mode = "o",
{ "ic", desc = "LaTeX Command" },
{ "ac", desc = "LaTeX Command" },
{ "id", desc = "LaTeX Math Delimiter" },
{ "ad", desc = "LaTeX Math Delimiter" },
{ "ie", desc = "LaTeX Environment" },
{ "ae", desc = "LaTeX Environment" },
{ "i$", desc = "LaTeX Math Zone" },
{ "a$", desc = "LaTeX Math Zone" },
{ "iP", desc = "LaTeX Section, Paragraph, ..." },
{ "aP", desc = "LaTeX Section, Paragraph, ..." },
{ "im", desc = "LaTeX Item" },
{ "am", desc = "LaTeX Item" },
},
}
end,
},
},
},
},
},
}
これでうまくいった。 以上!
Discussion