Gabirel / Hack-SpaceVim

🚀 Tell you how to hack SpaceVim. Be useful. Try Discussions!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possible best practice in LaTeX

Gabirel opened this issue · comments

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
  • CoC Settings
  • Preview
  • Conceal
  • More settings for latex layer

Installation

SpaceVim Settings

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

  • let SpaceVim install coc for you
  • let coc install coc-texlab
  • enable latex layer

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

  • enable latex support
  • adjust texlab binary path
  • enable texlab to build for us automatically

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 automatically view since I use texlab with Skim
  • use <leader>v to format paragraph for me
" {{ vimtex {{
" Special setting for latex files
" Use `gggqG` to format long lines in Latex
" Use `gq11j` to wrap the line you're on with the 11 below it
" Use `gqip` or `gqap` to wrap the paragraph
" gg(go to first line), gq(format) to G(the last line)
autocmd FileType tex setlocal colorcolumn=80 textwidth=79 tabstop=2 shiftwidth=2 expandtab
nnoremap <leader>v gqip
" See: http://vimdoc.sourceforge.net/htmldoc/syntax.html#g:tex_conceal
" let g:tex_conceal = "abdg"

" 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 }}