Skip to content

Commit 5f437a2

Browse files
feat: latex converter can now be a list, prefer utftex converter, fallback to latex2text
## Details The `latex.converter` option can now be a `string[]`, in addition to `string`. When it is a list the first available executable on the system is used. The default value has been updated to: `{ 'utftex', 'latex2text' }`. This means `utftex` will be used if it is available on the system with a fallback to `latex2text`. In this way we should avoid breaking anyone who continues to use `latex2text`. The only edge case is someone with both executables available but who prefers the output of `latex2text`, in which case they will need to set `converter = 'latex2text'` in their config to continue using it. Minor updates to various tests to take this into account as well as added a helper function to provide the first available executable from a list of input, as it's also logic needed in the health check. Updated relevant demo in README as well.
1 parent 5b01324 commit 5f437a2

File tree

14 files changed

+128
-105
lines changed

14 files changed

+128
-105
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
### Bug Fixes
1313

1414
- use display width of concealed ranges [b4885a9](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/b4885a95e5082a6ed164830c581aac257a74f355)
15+
- top & bottom padding for latex [5b01324](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/5b01324a5fce277183098eac0a2cdb9c1b446b73)
1516

1617
## 8.8.0 (2025-09-09)
1718

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Plugin to improve viewing Markdown files in Neovim
1010
| ![Table](https://github.com/user-attachments/assets/7d021918-e89c-4b7d-b33a-869390f9a826) | ![Table](https://github.com/user-attachments/assets/fdbcfbfa-5f9e-49b7-8c19-f7e837979a7a) |
1111
| ![Quote](https://github.com/user-attachments/assets/822ae62c-bc0f-40a7-b8bb-fb3a885a95f9) | ![Quote](https://github.com/user-attachments/assets/aa002ac7-b30f-4079-bba9-505160a4ad78) |
1212
| ![Callout](https://github.com/user-attachments/assets/e468a463-bc8d-420c-bb4c-da1263795092) | ![Callout](https://github.com/user-attachments/assets/d56cc5c7-43cd-4ce7-ad33-6164c2e23875) |
13-
| ![Latex](https://github.com/user-attachments/assets/7b859c0a-1bf6-4398-88b5-7bcde12f2390) | ![Latex](https://github.com/user-attachments/assets/9ef14030-f688-47fd-95ff-befab1253322) |
13+
| ![Latex](https://github.com/user-attachments/assets/68f27ff3-49c8-42b5-bb7a-3b89c1e98401) | ![Latex](https://github.com/user-attachments/assets/41e657a6-bcc2-464d-ab8c-a23bfcb80b0f) |
1414

1515
<!-- panvimdoc-ignore-end -->
1616

@@ -61,6 +61,8 @@ Plugin to improve viewing Markdown files in Neovim
6161
- [mini.icons](https://github.com/nvim-mini/mini.nvim/blob/main/readmes/mini-icons.md)
6262
- [nvim-web-devicons](https://github.com/nvim-tree/nvim-web-devicons)
6363
- System dependencies:
64+
- [libtexprintf](https://github.com/bartp5/libtexprintf) (Optional):
65+
Used to transform `latex` strings to appropriate unicode using `utftex`
6466
- [pylatexenc](https://pypi.org/project/pylatexenc/) (Optional):
6567
Used to transform `latex` strings to appropriate unicode using `latex2text`
6668

@@ -272,7 +274,8 @@ require('render-markdown').setup({
272274
-- Additional modes to render latex.
273275
render_modes = false,
274276
-- Executable used to convert latex formula to rendered unicode.
275-
converter = 'latex2text',
277+
-- If a list is provided the first command available on the system is used.
278+
converter = { 'utftex', 'latex2text' },
276279
-- Highlight for latex blocks.
277280
highlight = 'RenderMarkdownMath',
278281
-- Determines where latex formula is rendered relative to block.

demo/latex.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
$\sqrt{3x-1}+(1+x)^2$
44

55
$$
6-
f(x,y) = x + \sqrt{y}
7-
f(x,y) = \sqrt{y} + \frac{x^2}{4y}
6+
\lim_{n\to\infty} \left(1 + \frac{1}{n}\right)^n
87
$$

demo/minit.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ require('lazy').setup({
2929
},
3030
{
3131
'nvim-lualine/lualine.nvim',
32-
dependencies = { 'nvim-tree/nvim-web-devicons' },
32+
dependencies = { 'nvim-mini/mini.nvim' },
3333
config = function()
3434
require('lualine').setup({
3535
sections = {
@@ -64,7 +64,9 @@ require('lazy').setup({
6464
{
6565
'nvim-mini/mini.nvim',
6666
config = function()
67-
require('mini.icons').setup({})
67+
local icons = require('mini.icons')
68+
icons.setup({})
69+
icons.mock_nvim_web_devicons()
6870
end,
6971
},
7072
{

doc/render-markdown.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For NVIM v0.11.4 Last change: 2025 September 15
1+
*render-markdown.txt* For NVIM v0.11.4 Last change: 2025 September 16
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -87,6 +87,8 @@ Plugin to improve viewing Markdown files in Neovim
8787
- mini.icons <https://github.com/nvim-mini/mini.nvim/blob/main/readmes/mini-icons.md>
8888
- nvim-web-devicons <https://github.com/nvim-tree/nvim-web-devicons>
8989
- System dependencies:
90+
- libtexprintf <https://github.com/bartp5/libtexprintf> (Optional):
91+
Used to transform `latex` strings to appropriate unicode using `utftex`
9092
- pylatexenc <https://pypi.org/project/pylatexenc/> (Optional):
9193
Used to transform `latex` strings to appropriate unicode using `latex2text`
9294

@@ -334,7 +336,8 @@ Default Configuration ~
334336
-- Additional modes to render latex.
335337
render_modes = false,
336338
-- Executable used to convert latex formula to rendered unicode.
337-
converter = 'latex2text',
339+
-- If a list is provided the first command available on the system is used.
340+
converter = { 'utftex', 'latex2text' },
338341
-- Highlight for latex blocks.
339342
highlight = 'RenderMarkdownMath',
340343
-- Determines where latex formula is rendered relative to block.

justfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ health:
3232
log:
3333
cat ~/.local/state/nvim/render-markdown.log
3434

35-
demo: heading table box latex callout
35+
demo: heading table quote callout latex
3636

3737
heading:
3838
python demo/run.py --name "heading_code"
3939

4040
table:
4141
python demo/run.py --name "list_table"
4242

43-
box:
43+
quote:
4444
python demo/run.py --name "box_dash_quote"
4545

46-
latex:
47-
python demo/run.py --name "latex"
48-
4946
callout:
5047
python demo/run.py --name "callout"
48+
49+
latex:
50+
python demo/run.py --name "latex"

lua/render-markdown/config/latex.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---@class (exact) render.md.latex.Config: render.md.base.Config
2-
---@field converter string
2+
---@field converter string|string[]
33
---@field highlight string
44
---@field position render.md.latex.Position
55
---@field top_pad integer
@@ -22,7 +22,8 @@ M.default = {
2222
-- Additional modes to render latex.
2323
render_modes = false,
2424
-- Executable used to convert latex formula to rendered unicode.
25-
converter = 'latex2text',
25+
-- If a list is provided the first command available on the system is used.
26+
converter = { 'utftex', 'latex2text' },
2627
-- Highlight for latex blocks.
2728
highlight = 'RenderMarkdownMath',
2829
-- Determines where latex formula is rendered relative to block.
@@ -39,7 +40,9 @@ M.default = {
3940
---@return render.md.Schema
4041
function M.schema()
4142
return require('render-markdown.config.base').schema({
42-
converter = { type = 'string' },
43+
converter = {
44+
union = { { list = { type = 'string' } }, { type = 'string' } },
45+
},
4346
highlight = { type = 'string' },
4447
position = { enum = Position },
4548
top_pad = { type = 'number' },

lua/render-markdown/handler/latex.lua

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ local Context = require('render-markdown.request.context')
22
local Indent = require('render-markdown.lib.indent')
33
local Marks = require('render-markdown.lib.marks')
44
local Node = require('render-markdown.lib.node')
5+
local env = require('render-markdown.lib.env')
56
local iter = require('render-markdown.lib.iter')
67
local log = require('render-markdown.core.log')
78
local str = require('render-markdown.lib.str')
@@ -34,7 +35,8 @@ function Handler:run(root, last)
3435
if not self.config.enabled then
3536
return {}
3637
end
37-
if vim.fn.executable(self.config.converter) ~= 1 then
38+
local cmd = env.command(self.config.converter)
39+
if not cmd then
3840
log.add('debug', 'ConverterNotFound', self.config.converter)
3941
return {}
4042
end
@@ -43,7 +45,7 @@ function Handler:run(root, last)
4345
self.context.latex:add(node)
4446
if last then
4547
local nodes = self.context.latex:get()
46-
self:convert(nodes)
48+
Handler.convert(cmd, nodes)
4749
local rows = self:rows(nodes)
4850
for row, row_nodes in pairs(rows) do
4951
self:render(row, row_nodes)
@@ -53,9 +55,9 @@ function Handler:run(root, last)
5355
end
5456

5557
---@private
58+
---@param cmd string
5659
---@param nodes render.md.Node[]
57-
function Handler:convert(nodes)
58-
local cmd = self.config.converter
60+
function Handler.convert(cmd, nodes)
5961
local inputs = {} ---@type string[]
6062
for _, node in ipairs(nodes) do
6163
local text = Handler.text(node)
@@ -89,6 +91,14 @@ function Handler:convert(nodes)
8991
end
9092
end
9193

94+
---@private
95+
---@param node render.md.Node
96+
---@return string
97+
function Handler.text(node)
98+
local s = node.text
99+
return vim.trim(s:match('^%$*(.-)%$*$') or s)
100+
end
101+
92102
---@private
93103
---@param nodes render.md.Node[]
94104
---@return table<integer, render.md.Node[]>
@@ -260,14 +270,6 @@ function Handler:indent(node)
260270
end
261271
end
262272

263-
---@private
264-
---@param node render.md.Node
265-
---@return string
266-
function Handler.text(node)
267-
local s = node.text
268-
return vim.trim(s:match('^%$*(.-)%$*$') or s)
269-
end
270-
271273
---@class render.md.handler.Latex: render.md.Handler
272274
local M = {}
273275

lua/render-markdown/health.lua

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
local env = require('render-markdown.lib.env')
12
local icons = require('render-markdown.lib.icons')
23
local state = require('render-markdown.state')
34

45
---@class render.md.Health
56
local M = {}
67

78
---@private
8-
M.version = '8.8.7'
9+
M.version = '8.8.8'
910

1011
function M.check()
1112
M.start('versions')
@@ -17,9 +18,10 @@ function M.check()
1718
local errors = state.validate()
1819
if #errors == 0 then
1920
vim.health.ok('valid')
20-
end
21-
for _, message in ipairs(errors) do
22-
vim.health.error(message)
21+
else
22+
for _, message in ipairs(errors) do
23+
vim.health.error(message)
24+
end
2325
end
2426

2527
local config = state.get(0)
@@ -47,9 +49,15 @@ function M.check()
4749
vim.health.warn('none installed')
4850
end
4951

50-
M.start('executables')
5152
if latex.enabled then
52-
M.executable(latex.converter, M.disable('latex'))
53+
M.start('latex')
54+
local cmd = env.command(latex.converter)
55+
if cmd then
56+
vim.health.ok('using: ' .. cmd)
57+
else
58+
local message = 'none installed: ' .. vim.inspect(latex.converter)
59+
vim.health.warn(message, M.disable('latex'))
60+
end
5361
end
5462

5563
M.start('conflicts')
@@ -145,22 +153,6 @@ function M.ts_info(language, required, active)
145153
end
146154
end
147155

148-
---@private
149-
---@param name string
150-
---@param advice? string[]
151-
function M.executable(name, advice)
152-
if vim.fn.executable(name) == 1 then
153-
vim.health.ok(name .. ': installed')
154-
else
155-
local message = name .. ': not installed'
156-
if advice then
157-
vim.health.warn(message, advice)
158-
else
159-
vim.health.error(message)
160-
end
161-
end
162-
end
163-
164156
---@private
165157
---@param name string
166158
---@param validate? fun(plugin: any): string[]?

lua/render-markdown/lib/env.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ function M.range(buf, win, offset)
6868
return { top, bottom }
6969
end
7070

71+
---@param options string|string[]
72+
---@return string?
73+
function M.command(options)
74+
if type(options) == 'string' then
75+
options = { options }
76+
end
77+
for _, option in ipairs(options) do
78+
if vim.fn.executable(option) == 1 then
79+
return option
80+
end
81+
end
82+
return nil
83+
end
84+
7185
---@class render.md.env.Row
7286
M.row = {}
7387

0 commit comments

Comments
 (0)