From 6930453aea5d3a319e1d774367c8b672bf0d9284 Mon Sep 17 00:00:00 2001 From: "Md. Iftakhar Awal Chowdhury" Date: Mon, 14 Sep 2026 11:44:38 +0600 Subject: [PATCH] fix(latex): set utf-8 python io encoding for windows --- lua/render-markdown/handler/latex.lua | 12 +++++++++++- tests/helpers/system.lua | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lua/render-markdown/handler/latex.lua b/lua/render-markdown/handler/latex.lua index 9bc75a9d..22531075 100644 --- a/lua/render-markdown/handler/latex.lua +++ b/lua/render-markdown/handler/latex.lua @@ -101,7 +101,14 @@ function Handler.convert(cmd, inputs) if vim.system then local tasks = {} ---@type table for _, input in ipairs(inputs) do - tasks[input] = vim.system({ cmd }, { stdin = input, text = true }) + tasks[input] = vim.system({ cmd }, { + stdin = input, + text = true, + -- Python defaults redirected streams to the active code page on + -- Windows. latex2text can emit characters that code page cannot + -- represent, causing the converter to exit with an encoding error. + env = { PYTHONIOENCODING = 'utf-8' }, + }) end for input, task in pairs(tasks) do local output = task:wait() @@ -113,6 +120,8 @@ function Handler.convert(cmd, inputs) end end else + local encoding = vim.env.PYTHONIOENCODING + vim.env.PYTHONIOENCODING = 'utf-8' for _, input in ipairs(inputs) do local result = vim.fn.system(cmd, input) if vim.v.shell_error == 0 and result then @@ -121,6 +130,7 @@ function Handler.convert(cmd, inputs) failed[#failed + 1] = input end end + vim.env.PYTHONIOENCODING = encoding end return failed end diff --git a/tests/helpers/system.lua b/tests/helpers/system.lua index c74bf2b1..0206f134 100644 --- a/tests/helpers/system.lua +++ b/tests/helpers/system.lua @@ -32,6 +32,7 @@ function M.mock(command, outputs) end) stub.new(vim, 'system', function(cmd, opts) assert.same({ command }, cmd) + assert.same({ PYTHONIOENCODING = 'utf-8' }, opts.env) local output = outputs[opts.stdin] assert.not_nil(output, ('missing output: %s'):format(opts.stdin)) return Task.new(table.concat(output, '\n') .. '\n')