Introduction

This guide provides a comprehensive overview for setting up Neovim as an advanced LaTeX editor on Ubuntu. It details the configuration of Neovim, integration with LaTeX tools, and the organization of project directories. The goal is to streamline the process of writing, compiling, and managing LaTeX documents while incorporating essential tools and plugins.

Neovim Configuration for LaTeX

Initial Setup

Neovim serves as the primary text editor for LaTeX document preparation. The configuration file, init.vim, located at ~/.config/nvim/init.vim, contains all the necessary settings to optimize Neovim for LaTeX development. Here’s a detailed breakdown of the configuration:

Editor Settings

  1. Basic Editor Configurations:

    • Line Numbers: Helps in navigation and debugging.

      :set number
      
    • Indentation and Tabs: Ensures consistent code formatting.

      :set autoindent
      :set tabstop=4
      :set shiftwidth=4
      :set smarttab
      :set softtabstop=4
      
    • Mouse Support: Allows mouse interaction for easier text selection and window management.

      :set mouse=a
      
  2. Completion and Color Scheme:

    • Disable Preview in Completion: Minimizes distractions during text completion.

      :set completeopt-=preview
      
    • Color Scheme: Sets the color scheme to Jellybeans with a dark background for better readability.

      :colorscheme jellybeans
      set background=dark
      

Plugin Management

Using vim-plug for plugin management, the init.vim file is configured to include several key plugins:

call plug#begin('~/.config/nvim/plugged')

" Essential Plugins
Plug 'http://github.com/tpope/vim-surround' " For surrounding text (e.g., ysw)
Plug 'https://github.com/preservim/nerdtree' " File explorer (NERDTree)
Plug 'https://github.com/tpope/vim-commentary' " Commenting (gcc & gc)
Plug 'https://github.com/vim-airline/vim-airline' " Status bar
Plug 'https://github.com/ap/vim-css-color' " CSS Color Preview
Plug 'https://github.com/rafi/awesome-vim-colorschemes' " Retro Color Schemes
Plug 'https://github.com/ryanoasis/vim-devicons' " File type icons
Plug 'https://github.com/tc50cal/vim-terminal' " Terminal integration
Plug 'https://github.com/terryma/vim-multiple-cursors' " Multiple cursors (CTRL + N)
Plug 'https://github.com/preservim/tagbar' " Code structure viewer (Tagbar)
Plug 'https://github.com/neoclide/coc.nvim' " Auto-completion and LSP
Plug 'lervag/vimtex' " LaTeX compilation and syntax highlighting
Plug 'sirver/ultisnips' " Snippet management
Plug 'severin-lemaignan/vim-minimap' " Minimap for code overview

call plug#end()

Key Bindings

Custom key bindings streamline operations and enhance productivity:

  • Tagbar: Toggle the Tagbar sidebar to view code structure.

    nmap <F8> :TagbarToggle<CR>
    
  • NERDTree: Manage file navigation with these shortcuts:

    nnoremap <C-f> :NERDTreeFocus<CR>
    nnoremap <C-n> :NERDTree<CR>
    nnoremap <C-t> :NERDTreeToggle<CR>
    
  • Clipboard Operations: Customize copy and paste operations to interact with the system clipboard:

    nnoremap <expr> <C-c> '"*y'
    vnoremap <C-c> "+y
    noremap <C-v> "+p
    

LaTeX-Specific Configurations

  1. Compiler Settings: Configure vimtex to use latexmk for LaTeX compilation.

    let g:vimtex_compiler_latexmk = {
        \ 'executable': 'latexmk',
        \ 'options': [
            \ '-pdf',
            \ '-interaction=nonstopmode',
            \ '-synctex=1',
        \ ],
    \ }
    
  2. Compilation Key Binding: Compile LaTeX documents with F9.

    nmap <F9> :VimtexCompile<CR>
    
  3. PDF Viewer and Spell Checking:

    • PDF Viewer: Use Zathura for viewing PDFs.

      let g:vimtex_view_method='zathura'
      
    • Spell Checking: Enable spell checking with language settings.

      setlocal spell
      set spelllang=it,en_gb
      inoremap <C-l> <c-g>u<Esc>[s1z=`]a<c-g>u
      

Snippet Management

UltiSnips is used for managing LaTeX snippets. The configuration specifies snippet triggers and directories:

let g:UltiSnipsExpandTrigger = '<tab>'
let g:UltiSnipsJumpForwardTrigger = '<tab>'
let g:UltiSnipsJumpBackwardTrigger = '<s-tab>'
let g:UltiSnipsSnippetDirectories=["UltiSnips", "my_snippets"]

Integration with Inkscape

For handling figures in LaTeX documents, Inkscape is integrated into Neovim. This setup allows for creating and editing vector images directly:

  • Commands for Inkscape Integration:
    " Create figures with Inkscape
    inoremap <C-f> <Esc>: silent exec '.!inkscape-figures create "'.getline('.').'" "'.b:vimtex.root.'/figures/"'<CR><CR>:w<CR>
    
    " Edit figures with Inkscape
    nnoremap <C-f> : silent exec '!inkscape-figures edit "'.b:vimtex.root.'/figures/" > /dev/null 2>&1 &'<CR><CR>:redraw!<CR>
    

Directory Organization

A well-structured directory organization is essential for managing LaTeX projects efficiently:

  • Main Folder: /lx serves as the root directory for LaTeX projects.
  • Subject-Specific Folders: Within /lx, sub-folders are organized by subject (e.g., algebra, physics).
  • Figures Directory: Each subject folder contains a /figures sub-folder for storing vector images.

Tools and Inspirations

  • Zathura: A lightweight PDF viewer known for its keyboard-centric navigation, perfect for reviewing LaTeX outputs.
  • Inkscape: Used for creating and managing vector graphics, such as figures and diagrams. Figures are saved in .pdf, .pdf-tex, and .svg formats and are included in LaTeX documents through proper path referencing.
  • Gilles Castel’s Guide: This setup is inspired by Gilles Castel’s guide on LaTeX and Inkscape integration. For more details, refer to Gilles Castel’s guide.

Conclusion

This guide details a robust configuration for Neovim tailored to LaTeX development on Ubuntu. By integrating essential plugins, customizing key bindings, and leveraging tools like Inkscape and Zathura, this setup aims to streamline LaTeX document creation and management. Tailor these configurations further based on individual preferences and project requirements to enhance productivity and workflow.