## Author: @natsukagami (https://github.com/natsukagami) ## ## To activate, source the file into kakrc and add: ### require-module latex-kak ## ## NOTE: This overrides , so if you don't like it, remove it. provide-module latex-kak %{ # Create a simple begin block, put the cursors in and remove multi-cursor on exit. define-command -hidden create-begin-block %{ execute-keys "i\begin{b0}\end{b0}" execute-keys "b0" execute-keys -with-hooks "c" hook -once buffer ModeChange .*:normal %{ execute-keys -with-maps "gl" } } # Create a begin block with the given parameter as block name. define-command -params 1 create-begin-block-with %{ execute-keys "i\begin{b0}\end{b0}" execute-keys "b0c%arg{1}" execute-keys "ok" execute-keys -with-maps "gl" } # Create a \param{} block and put the cursor in the middle. define-command -params 2 -hidden create-delims %{ execute-keys "i%arg{1}hZa%arg{2}zli" } define-command -params 1 create-block-with %{ create-delims "\%arg{1}{" "}" } # The font-menu declare-user-mode latex-font ## Semantics map -docstring "Text" global latex-font t ": create-block-with text" map -docstring "Emphasize (emph)" global latex-font e ": create-block-with emph" ## Shape map -docstring "Italics (textit)" global latex-font i ": create-block-with textit" map -docstring "Upright (textup)" global latex-font u ": create-block-with textup" # map -docstring "Slanted (textsl)" global latex-font S ": create-block-with textsl" # map -docstring "Swash font (textsw)" global latex-font W ": create-block-with textsw" # map -docstring "Small caps (textsc)" global latex-font C ": create-block-with textsc" # Weight map -docstring "Bold text (textbf)" global latex-font b ": create-block-with textbf" # map -docstring "Medium bold (textmd)" global latex-font M ": create-block-with textmd" # map -docstring "Normal (textnormal)" global latex-font N ": create-block-with textnormal" ## Family # map -docstring "Serif font (textsf)" global latex-font s ": create-block-with textsf" # map -docstring "Roman text (textrm)" global latex-font r ": create-block-with textrm" map -docstring "Monospace (texttt)" global latex-font m ": create-block-with texttt" ## Math styles map -docstring "Math Calligraphic (mathcal)" global latex-font ": create-block-with mathcal" map -docstring "Math Blackboard (mathbb)" global latex-font ": create-block-with mathbb" # map -docstring "Math Fraktur (mathfr)" global latex-font ": create-block-with mathfr" # map -docstring "Math Roman (mathrm)" global latex-font ": create-block-with mathrm" # map -docstring "Math Italics (mathit)" global latex-font ": create-block-with mathit" # map -docstring "Math Bold (mathbf)" global latex-font ": create-block-with mathbf" # map -docstring "Serif font (mathsf)" global latex-font ": create-block-with mathsf" map -docstring "Math Monospace (mathtt)" global latex-font ": create-block-with mathtt" # "Insert block" menu declare-user-mode latex-insert-block ## Common normal text blocks map -docstring "Unordered list" global latex-insert-block u ": create-begin-block-with itemize" map -docstring "Ordered list" global latex-insert-block o ": create-begin-block-with enumerate" ## Common math blocks map -docstring "Theorem" global latex-insert-block t ": create-begin-block-with theorem" map -docstring "Definition" global latex-insert-block d ": create-begin-block-with definition" map -docstring "Lemma" global latex-insert-block l ": create-begin-block-with lemma" map -docstring "Example" global latex-insert-block e ": create-begin-block-with example" map -docstring "Proof" global latex-insert-block p ": create-begin-block-with proof" ## Common environments map -docstring "align*" global latex-insert-block a ": create-begin-block-with align*" map -docstring "Matrix" global latex-insert-block m ": create-begin-block-with bmatrix" map -docstring "Cases" global latex-insert-block C ": create-begin-block-with cases" map -docstring "Table" global latex-insert-block T ": create-begin-block-with tabular" ## Custom map -docstring "Custom" global latex-insert-block c ": create-begin-block" # Pairs of delimiters declare-user-mode latex-insert-delims map -docstring "Parentheses" global latex-insert-delims p ": create-delims ( )" map -docstring "Large Parentheses" global latex-insert-delims P ": create-delims \left( \right)" map -docstring "Brackets" global latex-insert-delims b ": create-delims \left[ \right]" map -docstring "Sets" global latex-insert-delims s ": create-delims \{ \}" map -docstring "Large Sets" global latex-insert-delims S ": create-delims \left\{ \right\}" hook global WinSetOption filetype=(latex) %{ ## Create inline and display math blocks map buffer normal "i\(\)hhi" map buffer insert "\(\)2h" map buffer normal "i\[\]hhi" map buffer insert "\[\]2h" map buffer normal ": enter-user-mode latex-insert-delims" map buffer insert ": enter-user-mode latex-insert-delims" ## Quickly create begin/end blocks map buffer normal ": create-begin-block" map buffer insert ": create-begin-block" ## Font menu map buffer normal ": enter-user-mode latex-font" map buffer insert ": enter-user-mode latex-font" ## Insert menu map buffer normal ": enter-user-mode latex-insert-block" map buffer insert ": enter-user-mode latex-insert-block" ## Select math equations and environment blocks map buffer object e -docstring "Inline Math equation \( \)" "c\\\\\\(,\\\\\\)" map buffer object E -docstring "Display Math equation \[ \]" "c\\\\\\[,\\\\\\]" map buffer object v -docstring "Simple environment \env{}" "c\\\\\\w+\\{,\\}" map buffer object V -docstring "Full environment \begin{env}\end{env}" "c\\\\begin\\{\\w+\\}(?:\\{[\\w\\s]*\\})*(?:\\[[\\w\\s]*\\])*,\\\\end\\{\\w+\\}" ## Quickly get a new item map buffer normal "o\item " map buffer insert "o\item " } }