1
Fork 0
satellite/dotfiles/neovim/ftplugin/tex.lua

174 lines
4.7 KiB
Lua
Raw Normal View History

local A = require("my.abbreviations")
2022-12-26 20:07:10 +01:00
local scrap = require("scrap")
2022-09-12 13:50:02 +02:00
require("my.helpers.wrapMovement").setup()
vim.opt.conceallevel = 0
vim.opt.wrap = true
vim.g.vimtex_imaps_enabled = 0
2022-12-14 03:20:59 +01:00
vim.g.vimtex_syntax_conceal_disable = 1
2022-11-14 01:16:10 +01:00
vim.keymap.set("n", "<leader>lg", function()
if not pcall(function()
local a = tonumber(vim.fn.input("A: "))
local b = tonumber(vim.fn.input("B: "))
local g, x, y = require("my.helpers.math.mod").gcd(a, b)
vim.fn.input("Result: " .. g .. " " .. x .. " " .. y)
end) then vim.fn.input("No results exist") end
end, { buffer = true, desc = "Gcd calculator" })
vim.keymap.set("n", "<leader>li", function()
if not pcall(function()
local class = tonumber(vim.fn.input("Mod class: "))
local num = tonumber(vim.fn.input("Number: "))
vim.fn.input("Result: " .. require("my.helpers.math.mod").modinverse(num, class))
end) then vim.fn.input("No results exist") end
end, { buffer = true, desc = "Mod inverse calculator" })
local abbreviations = {
-- Greek chars
{ "eps", "\\epsilon" },
{ "delta", "\\delta" },
{ "Delta", "\\Delta" },
2022-09-18 01:00:32 +02:00
{ "pi", "\\pi" },
2022-09-25 22:03:11 +02:00
{ "psi", "\\psi" },
{ "alpha", "\\alpha" },
{ "beta", "\\beta" },
{ "theta", "\\theta" },
2022-09-25 22:03:11 +02:00
{ "gamma", "\\gamma" },
2022-10-09 03:28:51 +02:00
{ "lam", "\\lambda" },
2022-11-14 01:16:10 +01:00
{ "nuls", "\\varnothing" }, -- Other fancy symvols
2022-12-26 20:07:10 +01:00
{ "tmat", "^T" }, -- Tranpose of a matrix
{ "cmat", "^*" }, -- Conjugate of a matrix
{ "ortco", "^{\\bot}" }, -- Orthogonal complement
2022-12-26 20:07:10 +01:00
{ "sinter", "^{\\circ}" }, -- Interior of a set
-- Basic commands
{ "mangle", "\\measuredangle" },
{ "aangle", "\\angle" },
2022-12-09 02:32:25 +01:00
2022-09-18 01:00:32 +02:00
{ "sdiff", "\\setminus" },
2022-09-12 13:50:02 +02:00
{ "sst", "\\subset" },
{ "sseq", "\\subseteq" },
{ "nin", "\\not\\in" },
{ "iin", "\\in" },
{ "tto", "\\to" },
2022-09-12 13:50:02 +02:00
{ "iip", "\\implies" },
{ "iff", "\\iff" },
{ "land", "\\land" },
{ "lor", "\\lor" },
2022-09-25 22:03:11 +02:00
{ "ssin", "\\sin" },
{ "ccos", "\\cos" },
2022-10-13 01:05:38 +02:00
{ "ttan", "\\ttan" },
{ "ssec", "\\sec" },
2022-09-25 22:03:11 +02:00
{ "lln", "\\ln" },
{ "frl", "\\forall" },
{ "exs", "\\exists" },
2022-09-18 01:00:32 +02:00
{ "iinf", "\\infty" },
{ "ninf", "-\\infty" },
{ "nlnl", "\\pm" }, -- had this as npnp first but it was hard-ish to type
{ "ccup", "\\cup" },
{ "ccap", "\\cap" },
{ "nope", "\\bot" },
{ "yee", "\\top" },
2022-09-25 22:03:11 +02:00
{ "ccan", "\\cancel" },
2022-10-04 23:42:58 +02:00
{ "comp", "\\circ" },
2022-09-18 01:00:32 +02:00
{ "mul", "\\cdot" },
{ "smul", "\\times" },
2022-10-04 23:42:58 +02:00
{ "card", "\\#" },
2022-10-13 01:33:24 +02:00
{ "div", "\\|" },
{ "ndiv", "\\not\\|\\:" },
2022-10-04 23:42:58 +02:00
-- words
2022-11-14 01:16:10 +01:00
{ "rref", "reduced row echalon form" }
}
2022-12-26 20:07:10 +01:00
---@type ExpansionOptions
local no_capitalization = { capitalized = false }
2022-11-14 01:16:10 +01:00
-- Todo: convert exponents and subscripts
-- to use this more concise notation.
2022-12-26 20:07:10 +01:00
---@type ExpansionInput[]
2022-10-09 03:28:51 +02:00
local abolishAbbreviations = {
2022-12-26 20:07:10 +01:00
-- General phrases
{ "thrf", "therefore" },
{ "bcla", "by contradiction let's assume" },
{ "wlg", "without loss of generality" },
-- Calculus
2022-10-14 13:44:47 +02:00
{ "ib{p,s}", "integration by {parts,substitution}" },
2022-12-26 20:07:10 +01:00
-- Linear algebra
{ "eg{va,ve,p}{,s}", "eigen{value,vector,pair}{}" },
2022-11-01 16:48:18 +01:00
{ "mx{,s}", "matri{x,ces}" },
2022-11-14 01:16:10 +01:00
{ "dete{,s}", "determinant{}" },
{ "ort{n,g}", "orto{normal,gonal}" },
2022-12-09 02:32:25 +01:00
{ "l{in,de}", "linearly {independent,dependent}" },
-- My own operator syntax:
-- - Any operator can be prefixed with "a" to
-- align in aligned mode
-- - Any operator can be prefixed with cr to
-- start a new line and align in aligned mode
2022-12-26 20:07:10 +01:00
{
"{cr,a,}{eq,neq,leq,geq,lt,gt}",
"{\\\\\\&,&,}{=,\\neq,\\leq,\\geq,<,>}",
options = no_capitalization
},
-- Exponents and subscripts:
-- {operation}{argument}
-- - operation = e (exponent) | s (subscript)
-- - argument = t{special} | {basic}
-- - basic = 0-9|n|i|t|k
-- - special =
-- - "p" => +
-- - "m" => -
-- - "i" => -1
{
"{e,s}{{0,1,2,3,4,5,6,7,8,9,n,i,t,k},t{i,m,p}}",
"{^,_}{{},{\\{-1\\},-,+}}",
options = no_capitalization
},
-- Set symbols
-- - nats => naturals
-- - ints => integers
-- - rats => rationals
-- - irats => irationals
-- - rrea => reals
-- - comp => complex
-- - ppri => primes
-- - ffie => fields
{
"{nats,ints,rats,irats,rrea,comp,ppri,ffie}",
"\\mathbb\\{{N,Z,Q,I,R,C,P,F}\\}",
options = no_capitalization
},
-- Function calls:
-- {function-name}{modifier?}{argument}
--
-- - function-name = f/g/h/P
-- - modifier:
-- - d => derivative
-- - 2 => squared
-- - 3 => cubed
-- - i => inverse
-- - argument = x/a/t/i/n/k
{ "{f,g,h,P}{d,2,3,i,}{x,a,t,i,n,k}", "{}{',^2,^3,^\\{-1\\},}({})" }
2022-10-09 03:28:51 +02:00
}
2022-12-26 20:07:10 +01:00
local expanded = scrap.expand_many(abolishAbbreviations)
A.manyLocalAbbr(abbreviations)
2022-12-26 20:07:10 +01:00
A.manyLocalAbbr(expanded)
2022-10-14 13:44:47 +02:00
2022-11-14 01:16:10 +01:00
vim.keymap.set("n", "<leader>lc", "<cmd>VimtexCompile<cr>",
{ desc = "Compile current buffer using vimtex", buffer = true })