1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
--- Personal lua config files for NeoVim.
-- Last Changed: 2019-01-27
-- Author: Federico Igne <git@federicoigne.com>
-- License: This file is placed in the public domain.
local map = require 'dyamon.util.map'
local cp = require 'dyamon.util.checkpoint'
local bopt = vim.bo
local wopt = vim.wo
--- {{{1 Utils
-- @section utils
local function get_TeXroot()
local root
local header = vim.api.nvim_buf_get_lines(0, 0, 5, false)
for _,l in ipairs(header) do
local _, _, r = l:find("^%%%s+!TeX%s+root%s+=%s+(%S+)$")
root = r or root
end
return root or "%"
end
--- {{{1 Options
-- @section options
-- Set default compiler
-- NOTE: this looks for metadata info at the top of the page to set the
-- main entry point of the LaTeX project.
--
-- % !TeX root = <path/to/root.tex>
--
-- Falls back to current file (`%`) if the header is not provided.
vim.b.TeXroot = get_TeXroot()
bopt.makeprg = "latexmk -pdf "..vim.b.TeXroot
-- Set soft wrapping
bopt.textwidth = 0 -- disable hard wrapping
wopt.wrap = true
wopt.linebreak = true -- soft wrapping on 'breakat'
--- {{{1 Custom vim-surround options
-- @section vim-surround
vim.b['surround_'..string.byte('"')] = "``\r''"
vim.b['surround_'..string.byte('>')] = "\\langle \r \\rangle"
vim.b['surround_'..string.byte('p')] = "\\{ \r \\}"
vim.b['surround_'..string.byte('E')] = "\\begin{\1Environment: \1}\n\r\n\\end{\1\1}\n"
vim.b['surround_'..string.byte('e')] = "\\emph{\r}"
vim.b['surround_'..string.byte('i')] = "\\textit{\r}"
vim.b['surround_'..string.byte('b')] = "\\textbf{\r}"
vim.b['surround_'..string.byte('c')] = "\\texttt{\r}"
vim.b['surround_'..string.byte('C')] = "\\cite{\r}"
vim.b['surround_'..string.byte('r')] = "\\ref{\r}"
vim.b['surround_'..string.byte('m')] = "\\mathcal{\r}"
vim.b['surround_'..string.byte('0')] = "\\part{\r}<+\\label{part:<+label+>}+>\n\n"
vim.b['surround_'..string.byte('1')] = "\\chapter{\r}<+\\label{chap:<+label+>}+>\n\n"
vim.b['surround_'..string.byte('2')] = "\\section{\r}<+\\label{sec:<+label+>}+>\n\n"
vim.b['surround_'..string.byte('3')] = "\\subsection{\r}<+\\label{ssec:<+label+>}+>\n\n"
vim.b['surround_'..string.byte('4')] = "\\subsubsection{\r}<+\\label{sssec:<+label+>}+>\n\n"
vim.b['surround_'..string.byte('5')] = "\\paragraph{\r}<+\\label{par:<+label+>}+>\n\n"
--- {{{1 Mappings
-- @section mappings
cp.surround(";be", "E", 0)
cp.surround(";em", "e", 0)
cp.surround(";mc", "m", 0)
cp.surround(";r", "r", 0)
cp.surround(";c", "C", 0)
cp.surround(";pt", "0", 0)
cp.surround(";ch", "1", 0)
cp.surround(";sec", "2", 0)
cp.surround(";ssec", "3", 0)
cp.surround(";sssec", "4", 0)
cp.surround(";pg", "5", 0)
cp.surround(";fi", "i", 0)
cp.surround(";fb", "b", 0)
cp.surround(";fc", "c", 0)
cp.surround("$$", "$", 0)
cp.surround("\\{}", "p", 0)
--- {{{1 Abbreviations
-- @section abbreviations
vim.cmd [[
" Allows imaps that happen to be one the prefix of another (e.g., <- and <--)
function! WrapIAbbr(pat,exp) abort
let c = nr2char(getchar(0))
return ((c =~ '\s') ? a:exp : a:pat) . c
endfunction
" Generic
iabbrev <buffer> \i \item
iabbrev <buffer> .. \dots
" Math
iabbrev <silent> <buffer> \= <c-r>=WrapIAbbr('\=','\models')<cr>
" Arrows
iabbrev <buffer> -> \rightarrow
iabbrev <buffer> --> \longrightarrow
iabbrev <buffer> => \Rightarrow
iabbrev <buffer> ==> \Longleftarrow
iabbrev <silent> <buffer> <- <c-r>=WrapIAbbr('<-','\leftarrow')<cr>
iabbrev <silent> <buffer> <-- <c-r>=WrapIAbbr('<--','\longleftarrow')<cr>
iabbrev <silent> <buffer> <= <c-r>=WrapIAbbr('<=','\Leftarrow')<cr>
iabbrev <silent> <buffer> <== <c-r>=WrapIAbbr('<==','\Longleftarrow')<cr>
iabbrev <buffer> <-> \leftrightarrow
iabbrev <buffer> <--> \longleftrightarrow
iabbrev <buffer> <=> \Leftrightarrow
iabbrev <buffer> <==> \Longleftrightarrow
iabbrev <buffer> \-> \mapsto
iabbrev <buffer> \--> \longmapsto
iabbrev <buffer> \=> \Mapsto
iabbrev <buffer> \==> \Longmapsto
]]
|