当前位置:   article > 正文

MacOS使用Nvim+LaTeX+Skim配置高效的论文写作环境_latex skim

latex skim

tags: Vim LaTeX Tips Lua

写在前面

折腾一下在Mac上配置neovim写LaTeX的环境, 以及skim阅读器的配置. 这里参考了一位朋友的配置1, 我改成了在mac上使用的配置了.

vimtex配置

function config.vimtex()
    vim.g.tex_flavor='latex' -- Default tex file format
    vim.g.vimtex_view_method = 'skim'
    -- allows forward search after every successful compilation
    vim.g.vimtex_view_skim_sync = 1
    -- allows change focus to skim after command `:VimtexView` is given
    vim.g.vimtex_view_skim_activate = 1

    vim.g.vimtex_indent_bib_enabled = 0
    vim.g.vimtex_indent_enabled = 0

    vim.g.vimtex_complete_enabled = 0
    -- Disable imaps (using Ultisnips)
    vim.g.vimtex_imaps_enabled = 0
    -- Do not open pdfviwer on compile
    vim.g.vimtex_view_automatic = 0
    -- Disable conceal
    vim.g.vimtex_syntax_conceal = {
        accents = 0,
        cites = 0,
        fancy = 0,
        greek = 0,
        math_bounds = 0,
        math_delimiters = 0,
        math_fracs = 0,
        math_super_sub = 0,
        math_symbols = 0,
        sections = 0,
        styles = 0,
    }
    -- Enable quickfix auto open
    -- vim.g.vimtex_quickfix_ignore_mode = 1
    vim.g.vimtex_compiler_progname = 'nvr'
    -- PDF viewer settings
    -- vim.g.vimtex_view_general_viewer = "skim"
    -- auto open quickfix on compile erros
    vim.g.vimtex_quickfix_mode = 1
    -- Latex warnings to ignore
    vim.g.vimtex_quickfix_ignore_filters = {
        "Command terminated with space",
        "LaTeX Font Warning: Font shape",
        "Package caption Warning: The option",
        [[Underfull \\hbox (badness [0-9]*) in]],
        "Package enumitem Warning: Negative labelwidth",
        [[Overfull \\hbox ([0-9]*.[0-9]*pt too wide) in]],
        [[Package caption Warning: Unused \\captionsetup]],
        "Package typearea Warning: Bad type area settings!",
        [[Package fancyhdr Warning: \\headheight is too small]],
        [[Underfull \\hbox (badness [0-9]*) in paragraph at lines]],
        "Package hyperref Warning: Token not allowed in a PDF string",
        [[Overfull \\hbox ([0-9]*.[0-9]*pt too wide) in paragraph at lines]],
    }
    vim.g.vimtex_fold_enabled = 0
    vim.g.vimtex_fold_manual = 0
    vim.g.vimtex_fold_types = {
        cmd_addplot = {
            cmds = { "addplot[+3]?" },
        },
        cmd_multi = {
            cmds = {
                "%(re)?new%(command|environment)",
                "providecommand",
                "presetkeys",
                "Declare%(Multi|Auto)?CiteCommand",
                "Declare%(Index)?%(Field|List|Name)%(Format|Alias)",
            },
        },
        cmd_single = {
            cmds = { "hypersetup", "tikzset", "pgfplotstableread", "lstset" },
        },
        cmd_single_opt = {
            cmds = { "usepackage", "includepdf" },
        },
        comments = {
            enabled = 0,
        },
        env_options = vim.empty_dict(),
        envs = {
            blacklist = {},
            whitelist = { "figure", "frame", "table", "example", "answer" },
        },
        items = {
            enabled = 0,
        },
        markers = vim.empty_dict(),
        preamble = {
            enabled = 0,
        },
        sections = {
            parse_levels = 0,
            parts = { "appendix", "frontmatter", "mainmatter", "backmatter" },
            sections = {
                "%(add)?part",
                "%(chapter|addchap)",
                "%(section|section\\*)",
                "%(subsection|subsection\\*)",
                "%(subsubsection|subsubsection\\*)",
                "paragraph",
            },
        },
    }
end

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103

skim的配置(方法1)

这个方法比较简单,无需配置nvim的服务器实例, 参考2.

同步选项, 选择custom(自定), 命令是nvim, 然后参数为--headless -c "VimtexInverseSearch %line '%file'", 当然前提是要在系统默认的Python环境中安装:

pip3 install neovim-remote
  • 1

这样的话, 就能完成正反向搜索了, skim通过command+shift+左键单击反向跳转到vim, vim通过\lv跳转到skim的文章对应位置.

skim配置(方法2, 弃用)

这个比较麻烦, 需要每次制定一个启动实例, 结果跟上面是一样的, 参考3. 在今年1月份更新vimtex之后, 就不需要通过这样复杂的配置方法进行正反向搜索了.

2022-01-19: With the release of VimTeX v2.8, all the hack here may not be needed anymore.

下面给出lua实现: 思路就是用一个临时文件/tmp/vimtexserver.txt保存:echo v:servername的内容, 然后通过skim读取这份文件的内容.

    vim.api.nvim_create_autocmd("FileType", {
        pattern = "tex",
        callback = function()
            vim.fn.writefile(
                {vim.fn.execute(":echo v:servername", "silent")}, 
                "/tmp/vimtexserver.txt")
        end,
    })
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

在skim中配置如下:

命令自定, nvr, 然后参数为

 --servername `cat /tmp/vimtexserver.txt` +"%line" "%file"
  • 1

ref


  1. jczhang02/nvim_dots (github.com); ↩︎

  2. Setup Skim PDF reader with VimTeX in Mac OS | Deepak Ramani (dr563105.github.io); ↩︎

  3. Set up Inverse Search for LaTeX with VimTeX and Neovim - jdhao’s digital space; ↩︎

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/238319
推荐阅读
相关标签
  

闽ICP备14008679号