Gabirel / Hack-SpaceVim

🚀 Tell you how to hack SpaceVim. Be useful. Try Discussions!
MIT License
478 stars 68 forks source link

Possible best practice in LaTeX #50

Open Gabirel opened 2 years ago

Gabirel commented 2 years ago

This practice only represents my personal opinion when using SpaceVim.

Mechanism: Latex Support + SpaceVim + CoC + Layer Latex(inside SpaceVim, mainly vimtex) + coc-texlab + Texlab + PDF viewer

Overview

Installation

SpaceVim Settings

In order to enable latex support, we should complete these steps:

Add these configs into your ~/SpaceVim.d/init.vim to make the aforementioned steps to complete:

" Use coc to auto complete
let g:spacevim_autocomplete_method = 'coc'

" Enable layer: latex
call SpaceVim#layers#load('lang#latex')

" CoC Settings
" {{ coc {{
let g:coc_config_home = '~/.SpaceVim.d/'
let g:coc_global_extensions = [
      \ 'coc-dictionary',
      \ 'coc-word',
      \ 'coc-texlab',
      \ ]
" }} coc }}

If you need full init.vim, check dotfiles for more information.

CoC Settings

Add these config into your ~/SpaceVim.d/coc-settings.json

{
  "languageserver": {
    "latex": {
      "command": "/usr/local/bin/texlab",  // put your texlab binary path here
      "filetypes": ["tex", "bib", "plaintex", "context"]
    }
  },
  "texlab.build.onSave": true,
}

Preview

For different PDF viewer, check texlab's previewing documentation for more information.

Personally, I use Skim to forward search on MacOS. So my settings are updated like this:

{
  "languageserver": {
    "latex": {
      "command": "/usr/local/bin/texlab",
      "filetypes": ["tex", "bib", "plaintex", "context"]
    }
  },
  "coc.source.file.ignoreHidden": false,
  "texlab.build.onSave": true,
  "texlab.build.forwardSearchAfter": true,
  "texlab.forwardSearch.executable": "/Applications/Skim.app/Contents/SharedSupport/displayline",
  "texlab.forwardSearch.args": ["-g", "%l", "%p", "%f"]  //"-g" means I want Skim to stay in the background after executing the forward search
}

Conceal

I really don't like the concealing feature, which makes it hard to write latex. So, I disable it completely. FYI, check issue-44 for more details.

TL;DR:

let g:vimtex_syntax_conceal_default = 0

More settings for latex layer

Explanation: Latex layer is mainly about vimtex.

" Disable all syntax conceal let g:vimtex_syntax_conceal_default = 0 " Disable automatic view since I use texlab with skim to preview in background " personally let g:vimtex_view_enabled = 0 let g:vimtex_view_automatic = 0 " }} vimtex }}