Skip to content

Commit fb0e70c

Browse files
feat: support toggling inline and block latex individually
## Details Request: #668 Adds `latex.inline` and `latex.block` which both default to true. Switching one off (or both though that really would not make sense) will result in those latex formulas no longer being rendered by this plugin. Inline is defined as delimitted by `$` and block is delimitted by `$$` (or more dollar signs).
1 parent 7bb5e54 commit fb0e70c

11 files changed

Lines changed: 44 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
- allow rendering when window is in diff mode [#645](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/645)
1313
[629eb95](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/629eb9533ec989d9d5c6cab8f3ad5372422c24e0)
1414
- add snacks.nvim image as conflict if latex is enabled [dcb7751](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/dcb77511efb1665b5073d8396a0033b3e4d680f6)
15+
- improvements to testing setup [#666](https://github.com/MeanderingProgrammer/render-markdown.nvim/pull/666)
16+
[#667](https://github.com/MeanderingProgrammer/render-markdown.nvim/pull/667)
17+
[ae8e75f](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/ae8e75f098ace7447c725bf1f0493d57294ddbe2)
18+
[7bb5e54](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/7bb5e54102cf140e12a7eb0f6ddf2f73c3b43922)
1519

1620
### Bug Fixes
1721

@@ -25,11 +29,14 @@
2529
- conceal padding spaces in multi-backtick code spans per CommonMark spec [#635](https://github.com/MeanderingProgrammer/render-markdown.nvim/pull/635)
2630
- false positive link matching [#650](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/650)
2731
[ff2fcd6](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/ff2fcd6f2c7b69ae2c08ebfb003b644b0d8b9acb)
32+
- handle checkbox rendering in single line nested lists [#659](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/659)
33+
[5adf089](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/5adf0895310c1904e5abfaad40a2baad7fe44a07)
2834

2935
### Collaborator Shoutouts
3036

3137
- @qq3g7bad
3238
- @0x1b2c
39+
- @okuuva
3340

3441
## 8.12.0 (2026-03-08)
3542

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ require('render-markdown').setup({
291291
-- Executable used to convert latex formula to rendered unicode.
292292
-- If a list is provided the commands run in order until the first success.
293293
converter = { 'utftex', 'latex2text' },
294+
-- Render inline latex formulas.
295+
inline = true,
296+
-- Render block latex formulas.
297+
block = true,
294298
-- Highlight for latex blocks.
295299
highlight = 'RenderMarkdownMath',
296300
-- Determines where latex formula is rendered relative to block.

doc/render-markdown.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,10 @@ Default Configuration ~
358358
-- Executable used to convert latex formula to rendered unicode.
359359
-- If a list is provided the commands run in order until the first success.
360360
converter = { 'utftex', 'latex2text' },
361+
-- Render inline latex formulas.
362+
inline = true,
363+
-- Render block latex formulas.
364+
block = true,
361365
-- Highlight for latex blocks.
362366
highlight = 'RenderMarkdownMath',
363367
-- Determines where latex formula is rendered relative to block.

lua/render-markdown/handler/latex.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,22 @@ function Handler:run(root, last)
3535
if not self.config.enabled then
3636
return {}
3737
end
38+
3839
local cmds = env.commands(self.config.converter)
3940
if #cmds == 0 then
4041
log.add('debug', 'ConverterNotFound', self.config.converter)
4142
return {}
4243
end
44+
4345
local node = Node.new(self.context.buf, root)
44-
log.node('latex', node)
45-
self.context.latex:add(node)
46+
local count = str.chars(node.text, '$')
47+
local include = (count <= 1 and self.config.inline)
48+
or (count >= 2 and self.config.block)
49+
if include then
50+
log.node('latex', node)
51+
self.context.latex:add(node)
52+
end
53+
4654
if last then
4755
local nodes = self.context.latex:get()
4856
local inputs = Handler.inputs(nodes)
@@ -58,6 +66,7 @@ function Handler:run(root, last)
5866
self:render(row, row_nodes)
5967
end
6068
end
69+
6170
return self.marks:get()
6271
end
6372

lua/render-markdown/health.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ local state = require('render-markdown.state')
1313
local M = {}
1414

1515
---@private
16-
M.version = '8.12.17'
16+
M.version = '8.12.18'
1717

1818
function M.check()
1919
M.start('versions')

lua/render-markdown/lib/node.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function Node:level(parent)
104104
if not node then
105105
return 0
106106
end
107-
return str.level(vim.treesitter.get_node_text(node, self.buf))
107+
return str.chars(vim.treesitter.get_node_text(node, self.buf), '#')
108108
end
109109

110110
---@param target string

lua/render-markdown/lib/str.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ function M.sub(s, i, j)
2929
return result
3030
end
3131

32-
---number of hashtags at the start of the string
32+
---number of a specific character at the start of the string
3333
---@param s string
34+
---@param ch string
3435
---@return integer
35-
function M.level(s)
36-
local match = s:match('^%s*(#+)')
36+
function M.chars(s, ch)
37+
local match = s:match('^%s*(' .. vim.pesc(ch) .. '+)')
3738
return match and #match or 0
3839
end
3940

lua/render-markdown/render/markdown/heading.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function Render:setup()
4646
if self.node.type == 'atx_heading' and self.config.atx then
4747
atx = true
4848
marker = assert(self.node:child_at(0), 'atx heading missing marker')
49-
level = str.level(marker.text)
49+
level = str.chars(marker.text, '#')
5050
elseif self.node.type == 'setext_heading' and self.config.setext then
5151
atx = false
5252
marker = assert(self.node:child_at(1), 'ext heading missing underline')

lua/render-markdown/render/markdown/section.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ end
8686
---@return boolean
8787
function Render:section(position, by)
8888
local _, line = self.node:line(position, by)
89-
return line and str.level(line) > 0 or false
89+
return line and str.chars(line, '#') > 0 or false
9090
end
9191

9292
return Render

lua/render-markdown/settings.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,8 @@ M.latex = {}
11861186

11871187
---@class (exact) render.md.latex.Config: render.md.base.Config
11881188
---@field converter string|string[]
1189+
---@field inline boolean
1190+
---@field block boolean
11891191
---@field highlight string
11901192
---@field position render.md.latex.Position
11911193
---@field top_pad integer
@@ -1207,6 +1209,10 @@ M.latex.default = {
12071209
-- Executable used to convert latex formula to rendered unicode.
12081210
-- If a list is provided the commands run in order until the first success.
12091211
converter = { 'utftex', 'latex2text' },
1212+
-- Render inline latex formulas.
1213+
inline = true,
1214+
-- Render block latex formulas.
1215+
block = true,
12101216
-- Highlight for latex blocks.
12111217
highlight = 'RenderMarkdownMath',
12121218
-- Determines where latex formula is rendered relative to block.
@@ -1226,6 +1232,8 @@ function M.latex.schema()
12261232
converter = {
12271233
union = { { list = { type = 'string' } }, { type = 'string' } },
12281234
},
1235+
inline = { type = 'boolean' },
1236+
block = { type = 'boolean' },
12291237
highlight = { type = 'string' },
12301238
position = { enum = M.latex.position },
12311239
top_pad = { type = 'number' },

0 commit comments

Comments
 (0)