Giter Site home page Giter Site logo

luasnips-mathtex-snippets's Introduction

Luasnips MathTex Snippets ๐Ÿ˜ฝ

This repo contains mathtex snippets for markdown and latex filetypes.

Forked from iurimateus, add markdown filetype support.

Installation

use {
    "jczhang02/luasnips-mathtex-snippets",
	config = function()
		vim.cmd([[packadd LuaSnip]])
		vim.cmd([[packadd vimtex]])
		vim.cmd([[packadd vim-markdown]])
		require("luasnip-latex-snippets").setup()
		-- or setup({ use_treesitter = true })
	end,
	ft = { "tex", "markdown" },
}
use{
    "preservim/vim-markdown",
	opt = true,
	ft = "markdown",
	config = function()
		vim.cmd([[let g:vim_markdown_math = 1]])
	end,
}

Notice: your luasnips config should set enable_autosnippets = true

Customization

An example file, located in ~/.config/nvim/luasnippets/tex.lua:

--- self Latex snippets

local snips, autosnips = {}, {}

local tex = {}

tex.in_mathzone = function()
	return vim.fn["vimtex#syntax#in_mathzone"]() == 1
end

tex.in_comment = function()
	return vim.fn["vimtex#syntax#in_comment"]() == 1
end

tex.in_text = function()
	return not tex.in_mathzone() and not tex.in_comment()
end

tex.in_align = function()
	return vim.fn["vimtex#env#is_inside"]("align")[1] ~= 0
end

snips = {
	s(
		{ trig = "it", name = "italic", dscr = "Insert italic text." },
		{ t("\\textit{"), i(1), t("}") },
		{ condition = tex.in_text, show_condition = tex.in_text }
	),
	s(
		{ trig = "em", name = "emphasize", dscr = "Insert emphasize text." },
		{ t("\\emph{"), i(1), t("}") },
		{ condition = tex.in_text, show_condition = tex.in_text }
	),
}

autosnips = {
	s({
		trig = "([a-zA-Z])bf",
		name = "math bold",
		wordTrig = false,
		regTrig = true,
	}, {
		f(function(_, snip)
			return "\\mathbf{" .. snip.captures[1] .. "}"
		end, {}),
	}, { condition = tex.in_mathzone }),
	s(
		{ trig = "bf", name = "bold", dscr = "Insert bold text." },
		{ t("\\textbf{"), i(1), t("}") },
		{ condition = tex.in_text, show_condition = tex.in_text }
	),
	s(
		{ trig = "bf", name = "bold", dscr = "Insert bold text." },
		{ t("\\mathbf{"), i(1), t("}") },
		{ condition = tex.in_mathzone, show_condition = tex.in_text }
	),
}

return snips, autosnips

Acknowledgement

iurimateus/luasnip-latex-snippets

luasnips-mathtex-snippets's People

Contributors

jczhang02 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.