Skip to content

feature: inline-only LaTeX rendering #668

@AchmadFathoni

Description

@AchmadFathoni

Is your feature request related to a problem? Please describe.

I want render-markdown.nvim to handle inline math ($...$ and \(...\)) but not display math ($$...$$ and \[...\]). Currently latex.enabled controls both.

I use render-latex.nvim for display math because it renders $$...$$ blocks as high-quality PNG images (matrices, large integrals, etc. need pixel-perfect layout). But I want render-markdown's LaTeX converter for inline math, latex2text/utftex produce great results for $\sqrt{x}$, $\frac{1}{2}$, and other inline expressions that would look ugly as raw LaTeX text.

With latex.enabled = true, both plugins render display math blocks, causing double-rendering artifacts. With enabled = false, inline math stops working too. There's no middle ground.

Describe the solution you'd like

How about a split latex option,:

require("render-markdown").setup({
    latex = {
        enabled = true, -- master control
        inline = false,
        block = false,
    },
})

Describe alternatives you've considered

In my case I want to enable inline latex only so I do

diff --git a/lua/render-markdown/handler/latex.lua b/lua/render-markdown/handler/latex.lua
index 877c39b..befd093 100644
--- a/lua/render-markdown/handler/latex.lua
+++ b/lua/render-markdown/handler/latex.lua
@@ -165,6 +165,11 @@ function Handler:render(row, nodes)
     local lines_below = {} ---@type string[]
     local current = 0
 
+    -- skip display math blocks (handled by render-latex.nvim)
+    if first and first:height() > 1 then
+        return
+    end
+
     for _, node in ipairs(nodes) do
         local output = str.split(Handler.cache[Handler.input(node)], '\n', true)
         if #output > 0 then

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions