From 2f66013dbde64a90cee79b897a7a692c2a036983 Mon Sep 17 00:00:00 2001 From: ctbaum Date: Sun, 12 Jul 2026 18:59:26 +0200 Subject: [PATCH] feat(latex, symbols): add missing LaTeX2e/amsmath/amssymb commands The symbol table covers unicode-math names but lacks some common commands that unicode-math spells differently or omits: \ldots, \iff, \implies, \impliedby, \land, \lor, \emptyset, the amsmath \dots* family, several amssymb symbols, and spacing commands (\quad, \qquad, \enspace, \thinspace, \thickspace) mapped to their unicode space characters. Also adds the \mathscr font, identical to \mathcal since unicode has a single script alphabet, and enables it in the font config, docs and test file. Glyph values cross-checked against Julia's REPL latex-to-unicode table (stdlib/REPL/src/latex_symbols.jl, MIT), itself derived from W3C's unicode.xml. Co-Authored-By: Claude Fable 5 --- doc/markview.nvim-latex.txt | 111 +++++++++++++++++----------------- lua/markview/config/latex.lua | 1 + lua/markview/symbols.lua | 35 +++++++++++ test/latex.md | 1 + 4 files changed, 93 insertions(+), 55 deletions(-) diff --git a/doc/markview.nvim-latex.txt b/doc/markview.nvim-latex.txt index 269e4f43..30219691 100644 --- a/doc/markview.nvim-latex.txt +++ b/doc/markview.nvim-latex.txt @@ -82,61 +82,61 @@ Demo {img:2} ---@param cmd_hl? string Highlight group for the command. ---@return markview.config.latex.commands.opts local operator = function (name, text_pos, cmd_conceal, cmd_hl) - return { - condition = function (item) - return #item.args == 1; - end, - - on_command = function (item) - local symbols = require("markview.symbols"); - - return { - end_col = item.range[2] + (cmd_conceal or 1), - conceal = "", - - virt_text_pos = text_pos or "overlay", - virt_text = { - { symbols.tostring("default", name), cmd_hl or "@keyword.function" } - }, - - hl_mode = "combine" - } - end, - - on_args = { - { - on_before = function (item) - return { - end_col = item.range[2] + 1, - - virt_text_pos = "overlay", - virt_text = { - { "(", "@punctuation.bracket" } - }, - - hl_mode = "combine" - } - end, - - after_offset = function (range) - return { range[1], range[2], range[3], range[4] - 1 }; - end, - - on_after = function (item) - return { - end_col = item.range[4], - - virt_text_pos = "overlay", - virt_text = { - { ")", "@punctuation.bracket" } - }, - - hl_mode = "combine" - } - end - } - } - }; + return { + condition = function (item) + return #item.args == 1; + end, + + on_command = function (item) + local symbols = require("markview.symbols"); + + return { + end_col = item.range[2] + (cmd_conceal or 1), + conceal = "", + + virt_text_pos = text_pos or "overlay", + virt_text = { + { symbols.tostring("default", name), cmd_hl or "@keyword.function" } + }, + + hl_mode = "combine" + } + end, + + on_args = { + { + on_before = function (item) + return { + end_col = item.range[2] + 1, + + virt_text_pos = "overlay", + virt_text = { + { "(", "@punctuation.bracket" } + }, + + hl_mode = "combine" + } + end, + + after_offset = function (range) + return { range[1], range[2], range[3], range[4] - 1 }; + end, + + on_after = function (item) + return { + end_col = item.range[4], + + virt_text_pos = "overlay", + virt_text = { + { ")", "@punctuation.bracket" } + }, + + hl_mode = "combine" + } + end + } + } + }; end commands = { @@ -428,6 +428,7 @@ Demo {img:3} mathbf = { enable = true }, mathbfit = { enable = true }, mathcal = { enable = true }, + mathscr = { enable = true }, mathbfscr = { enable = true }, mathfrak = { enable = true }, mathbb = { enable = true }, diff --git a/lua/markview/config/latex.lua b/lua/markview/config/latex.lua index cf16b893..23bc465e 100644 --- a/lua/markview/config/latex.lua +++ b/lua/markview/config/latex.lua @@ -318,6 +318,7 @@ return { mathbf = { enable = true }, mathbfit = { enable = true }, mathcal = { enable = true }, + mathscr = { enable = true }, mathbfscr = { enable = true }, mathfrak = { enable = true }, mathbb = { enable = true }, diff --git a/lua/markview/symbols.lua b/lua/markview/symbols.lua index 8135811e..c8c46271 100644 --- a/lua/markview/symbols.lua +++ b/lua/markview/symbols.lua @@ -4299,6 +4299,37 @@ symbols.entries = { ["ggcurly"] = "⪼", ["Top"] = "⫪", ["Bot"] = "⫫", + + -- LaTeX2e/amsmath/amssymb commands without a unicode-math name. + ["bigcirc"] = "○", + ["circlearrowleft"] = "↺", + ["circlearrowright"] = "↻", + ["circledS"] = "Ⓢ", + ["dotsb"] = "⋯", + ["dotsc"] = "…", + ["dotsi"] = "⋯", + ["dotsm"] = "⋯", + ["dotso"] = "…", + ["emptyset"] = "∅", + ["enspace"] = " ", + ["gvertneqq"] = "≩︀", + ["hbar"] = "ħ", + ["iff"] = "⟺", + ["impliedby"] = "⟸", + ["implies"] = "⟹", + ["land"] = "∧", + ["ldots"] = "…", + ["lor"] = "∨", + ["lvertneqq"] = "≨︀", + ["nleqslant"] = "⩽̸", + ["nsubseteqq"] = "⫅̸", + ["nsupseteqq"] = "⫆̸", + ["qquad"] = " ", + ["quad"] = " ", + ["thickspace"] = " ", + ["thinspace"] = " ", + ["varsubsetneqq"] = "⊊︀", + ["varsupsetneq"] = "⊋︀", }; --- Maps typst symbol names to the symbol. @@ -6325,6 +6356,10 @@ symbols.fonts = { } } +-- Unicode has a single script alphabet; `\mathscr` & `\mathcal` +-- use the same characters. +symbols.fonts.mathscr = symbols.fonts.mathcal; + ---@param font string ---@param text string ---@return string diff --git a/test/latex.md b/test/latex.md index 3d4ac46b..a8a686c0 100644 --- a/test/latex.md +++ b/test/latex.md @@ -31,6 +31,7 @@ Hello LaTeX! \mathbffrak{Hello LaTeX!} \mathbb{Hello LaTeX!} \mathbfscr{Hello LaTeX!} +\mathscr{Hello LaTeX!} \mathrm{Hello LaTeX!} $$