Merge pull request #1465 from snoweuph/feat/latex
Some checks are pending
Set up binary cache / cachix (default) (push) Waiting to run
Set up binary cache / cachix (maximal) (push) Waiting to run
Set up binary cache / cachix (nix) (push) Waiting to run
Treewide Checks / Validate flake (push) Waiting to run
Treewide Checks / Check formatting (push) Waiting to run
Treewide Checks / Check source tree for typos (push) Waiting to run
Treewide Checks / Validate documentation builds (push) Waiting to run
Treewide Checks / Validate documentation builds-1 (push) Waiting to run
Treewide Checks / Validate documentation builds-2 (push) Waiting to run
Treewide Checks / Validate documentation builds-3 (push) Waiting to run
Treewide Checks / Validate hyperlinks in documentation sources (push) Waiting to run
Treewide Checks / Validate Editorconfig conformance (push) Waiting to run
Build and deploy documentation / Check latest commit (push) Waiting to run
Build and deploy documentation / publish (push) Blocked by required conditions

languages/latex: add latex support wiht lsp, formatter and highlighting
This commit is contained in:
Snoweuph 2026-03-22 16:54:39 +01:00 committed by GitHub
commit a3ea20fceb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 120 additions and 0 deletions

View file

@ -74,6 +74,7 @@ isMaximal: {
};
toml.enable = isMaximal;
xml.enable = isMaximal;
tex.enable = isMaximal;
# Language modules that are not as common.
arduino.enable = false;

View file

@ -269,6 +269,9 @@
[twig-cs-fixer](https://github.com/VincentLanglet/Twig-CS-Fixer) aren't
packaged for nix.
- Added `languages.tex`. Currently only highlighting, formatting and lsp. No
previewing yet.
- Didn't Add
[`syntax-gaslighting`](https://github.com/NotAShelf/syntax-gaslighting.nvim),
you're crazy.

View file

@ -31,6 +31,7 @@ in {
./json.nix
./lua.nix
./markdown.nix
./tex.nix
./nim.nix
./vala.nix
./nix.nix

View file

@ -0,0 +1,115 @@
{
config,
pkgs,
lib,
...
}: let
inherit (builtins) attrNames;
inherit (lib.meta) getExe;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.options) literalExpression mkEnableOption mkOption;
inherit (lib.types) bool enum listOf;
inherit (lib.nvim.types) mkGrammarOption;
inherit (lib.nvim.attrsets) mapListToAttrs;
cfg = config.vim.languages.tex;
defaultServers = ["texlab"];
servers = {
texlab = {
enable = true;
cmd = [(getExe pkgs.texlab) "run"];
filetypes = ["plaintex" "tex" "bib"];
root_markers = [".git" ".latexmkrc" "latexmkrc" ".texlabroot" "texlabroot" ".texstudio" "Tectonic.toml"];
};
};
defaultFormat = ["tex-fmt"];
formats = {
tex-fmt = {
command = getExe pkgs.tex-fmt;
};
latexindent = {
command = "${pkgs.texlive.withPackages (ps: [ps.latexindent])}/bin/latexindent";
};
};
in {
options.vim.languages.tex = {
enable = mkEnableOption "TeX language support";
treesitter = {
enable = mkOption {
type = bool;
default = config.vim.languages.enableTreesitter;
defaultText = literalExpression "config.vim.languages.enableTreesitter";
description = "Enable TeX treesitter";
};
latexPackage = mkGrammarOption pkgs "latex";
bibtexPackage = mkGrammarOption pkgs "bibtex";
};
lsp = {
enable =
mkEnableOption "TeX LSP support"
// {
default = config.vim.lsp.enable;
defaultText = literalExpression "config.vim.lsp.enable";
};
servers = mkOption {
description = "TeX LSP server to use";
type = listOf (enum (attrNames servers));
default = defaultServers;
};
};
format = {
enable =
mkEnableOption "TeX formatting"
// {
default = config.vim.languages.enableFormat;
defaultText = literalExpression "config.vim.languages.enableFormat";
};
type = mkOption {
type = listOf (enum (attrNames formats));
default = defaultFormat;
description = "TeX formatter to use";
};
};
};
config = mkIf cfg.enable (mkMerge [
(mkIf cfg.treesitter.enable {
vim.treesitter.enable = true;
vim.treesitter.grammars = [
cfg.treesitter.latexPackage
cfg.treesitter.bibtexPackage
];
})
(mkIf cfg.lsp.enable {
vim.lsp.servers =
mapListToAttrs (n: {
name = n;
value = servers.${n};
})
cfg.lsp.servers;
})
(mkIf cfg.format.enable {
vim.formatter.conform-nvim = {
enable = true;
setupOpts = {
formatters_by_ft.tex = cfg.format.type;
formatters_by_ft.plaintex = cfg.format.type;
formatters =
mapListToAttrs (name: {
inherit name;
value = formats.${name};
})
cfg.format.type;
};
};
})
]);
}