Skip to content

LaTeX UltiSnips snippets for use in Vim and Neovim

License

Notifications You must be signed in to change notification settings

ckunte/latex-snippets-vim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LaTeX snippets for Vim and Neovim

Typesetting documents, papers, or letters in LaTeX can be verbose, and error-prone. A bunch of snippets provided in this repository try to reduce this tedium to as low as practicable.

What are snippets and how do they work?

A demo of snippets in action.

latex-snippets-vim.mp4

The concept of a snippet is simple. Think of a block of pre-formatted text (i.e., a template) that one needs to use often. One can of-course type or copy-paste such blocks of text repeatedly the hard way, or one could instead assign such common blocks of text with an abbreviated keyword, which in turn calls the entire block of text. To ensure such blocks do not accidentally appear while typing the actual content of the note, paper, or report, a trigger is required. To illustrate this, see below:

In Vim's insert mode, typing note and hitting tab key on the keyboard inserts the following block, and focuses on the first user input Title in the template. Type the title. To jump to the next placeholder Author, hold ctrl and press j (c-j in Vim parlance). The shortcut to jumping between placeholders can be set in ~/.vimrc file.

%!TeX TS-program = xelatex
%!TeX encoding = utf-8 Unicode
\documentclass[11pt,a4paper]{article}

\title{Title}
\author{Author}

\begin{document}

  \maketitle

\end{document}

This repository contains the following snippets:

Snippets Description
letter + tab Inserts a letter template
note + tab Inserts a note template (for XeLaTeX)
toc + tab Inserts a TOC block
beg + tab Inserts a begin/end block
sum + tab Inserts a summary section block
sec + tab Inserts a section block
sub + tab Inserts a subsection block
subs + tab Inserts a subsubsection block
enum + tab Inserts an enumerate list block
itm + tab Inserts an itemize list block
it + tab Inserts an item line
des + tab Inserts a description list block
par + tab Inserts a paragraph block
fig + tab Inserts a figure/label block
tabl + tab Inserts a table block
ref + tab Inserts a reference block
bi + tab Inserts a bib item block
apdx + tab Inserts an appendix block
pdf + tab Inserts an includepdf line
// + tab Inserts a formatted fraction
bf + tab Inserts bold face tag \textbf{}
em + tab Inserts emphasize tag \emph{}
sr + tab Inserts a formatted square
cb + tab Inserts a formatted cube
compl + tab Inserts a complement

Requirements

To be able to use snippets, the following are required:

  1. Vim or Neovim with python3 support.
  2. UltiSnips
  3. latex-snippets-vim

Installation

  1. Set up vim-plug plug-in manager
  2. Set the required UltiSnips plug-in for latex-snippets-vim by adding the following to .vimrc file (see the author's version of .vimrc for reference):
call plug#begin('~/.vim/plugged')

" UltiSnips for snippets
Plug 'sirver/ultisnips'

" LaTeX snippets for Vim using UltiSnips (downloads only tagged releases)
Plug 'ckunte/latex-snippets-vim', { 'tag': '*' }

call plug#end()

let g:UltiSnipsExpandTrigger = '<tab>'
let g:UltiSnipsJumpForwardTrigger = '<c-j>'
let g:UltiSnipsJumpBackwardTrigger = '<c-k>'

Reload .vimrc and :PlugInstall to install plug-ins.

Manual installation (not recommended)

Place *.snippets files under, say, ~/.vim/UltiSnips/ (and reload ~/.vimrc with source ~/.vimrc if appropriate). This method is not recommended because then one needs to keep track of updates and will have to manually download and place these whenever snippets are updated.