Possible best practice in LaTeX
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](https://github.com/neoclide/coc.nvim) Settings
- [Preview](https://github.com/latex-lsp/texlab/blob/master/docs/previewing.md)
- [Conceal](https://github.com/Gabirel/Hack-SpaceVim/issues/44)
- More settings for latex layer

## Installation
- LaTeX support
- [Texlab binary](https://github.com/latex-lsp/texlab/releases)
- SpaceVim

## SpaceVim Settings

In order to enable latex support, we should complete these steps:
- let SpaceVim install coc for you
- let coc install [coc-texlab](https://github.com/fannheyward/coc-texlab) 
- enable latex layer

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

```viml
" 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](https://github.com/Gabirel/dotfiles/blob/8efc6fa428a0b1effe86232551f3bfa94c8b16f6/.SpaceVim.d/init.vim) for more information.

## [CoC](https://github.com/neoclide/coc.nvim) 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`
```json
{
  "languageserver": {
    "latex": {
      "command": "/usr/local/bin/texlab",  // put your texlab binary path here
      "filetypes": ["tex", "bib", "plaintex", "context"]
    }
  },
  "texlab.build.onSave": true,
}
```

## [Preview](https://github.com/latex-lsp/texlab/blob/master/docs/previewing.md)
For different PDF viewer, [check texlab's previewing documentation](https://github.com/latex-lsp/texlab/blob/master/docs/previewing.md) for more information.

Personally, I use [Skim](https://skim-app.sourceforge.io/) to forward search on MacOS.
So my settings are updated like this:
```json
{
  "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](https://github.com/Gabirel/Hack-SpaceVim/issues/44) for more details.

**TL;DR:**
```viml
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
```viml
" {{ 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 }}
```