Compare commits

...

6 commits

Author SHA1 Message Date
6f53159d7b
docs(presets): rewrite math rendering section for --katex default 2026-03-06 14:26:21 -05:00
8049730803
refactor(presets): use --katex instead of --embed-resources --mathml
Problem: `--embed-resources` with `--mathml` caused pandoc to inline all
assets at compile time, adding ~15s per save for KaTeX-heavy documents.

Solution: Default to `--katex`, which inserts a CDN `<script>` tag and
defers rendering to the browser. Users can opt into `--embed-resources`
or `--mathml` via `extra_args`.
2026-03-06 14:26:09 -05:00
e513fc57d1
feat(compiler): add compile start/complete notifications
Problem: No user-facing feedback when compilation starts or finishes.
Long-running compilers like pandoc with `--embed-resources` leave the
user staring at nothing for 15+ seconds.

Solution: Notify "compiling..." at compile start and "compilation
complete" on success. The initial `toggle` call uses a combined
"compiling with <name>..." message to avoid stacking two notifications.
2026-03-06 14:25:53 -05:00
047e169c21
docs(presets): improve math rendering section with KaTeX recipes
Problem: the math docs only showed a full `args` override for KaTeX,
without explaining the tradeoffs or offering a simpler alternative.

Solution: add an `extra_args` one-liner recipe (simple but slow due to
`--embed-resources` inlining fonts), keep the `args` override as the
fast option, and explain why `--mathjax` fails entirely.
2026-03-06 14:08:22 -05:00
f5651cc3fc
chore: remove debug files 2026-03-06 13:48:04 -05:00
5f07cdafa6
doc: cleanup 2026-03-06 13:47:53 -05:00
5 changed files with 54 additions and 30 deletions

View file

@ -183,8 +183,8 @@ override individual fields by passing a table instead: >lua
`latex` latexmk -pdf → PDF (with clean support) `latex` latexmk -pdf → PDF (with clean support)
`pdflatex` pdflatex → PDF (single pass, no latexmk) `pdflatex` pdflatex → PDF (single pass, no latexmk)
`tectonic` tectonic → PDF (Rust-based LaTeX engine) `tectonic` tectonic → PDF (Rust-based LaTeX engine)
`markdown` pandoc → HTML (standalone, embedded) `markdown` pandoc → HTML (standalone, KaTeX math)
`github` pandoc → HTML (GitHub-styled, `-f gfm` input) `github` pandoc → HTML (GitHub-styled, `-f gfm`, KaTeX math)
`asciidoctor` asciidoctor → HTML (AsciiDoc with SSE reload) `asciidoctor` asciidoctor → HTML (AsciiDoc with SSE reload)
`plantuml` plantuml → SVG (UML diagrams, `.puml`) `plantuml` plantuml → SVG (UML diagrams, `.puml`)
`mermaid` mmdc → SVG (Mermaid diagrams, `.mmd`) `mermaid` mmdc → SVG (Mermaid diagrams, `.mmd`)
@ -193,27 +193,36 @@ override individual fields by passing a table instead: >lua
Math rendering (pandoc presets): ~ Math rendering (pandoc presets): ~
*preview-math* *preview-math*
The `markdown` and `github` presets use `--mathml` by default, which converts The `markdown` and `github` presets use `--katex` by default, which inserts a
TeX math to native MathML markup rendered by the browser. This is the only `<script>` tag that loads KaTeX from a CDN at view time. The browser fetches
math option compatible with `--embed-resources` (self-contained HTML). the assets once and caches them, so math renders instantly on subsequent loads.
Requires internet on first view.
`--mathjax` and `--katex` insert `<script>` tags that load JavaScript and For offline use, swap in `--mathml` via `extra_args`. MathML is rendered
fonts from a CDN at runtime. Pandoc's `--embed-resources` cannot inline these natively by the browser with no external dependencies: >lua
dynamic dependencies, so math fails to render in the output.
To use KaTeX or MathJax instead, override `args` to drop `--embed-resources`
(the output will require internet access): >lua
vim.g.preview = { vim.g.preview = {
github = { github = { extra_args = { '--mathml' } },
args = function(ctx)
return {
'-f', 'gfm', ctx.file, '-s', '--katex',
'--css', 'https://cdn.jsdelivr.net/gh/pixelbrackets/gfm-stylesheet@master/dist/gfm.css',
'-o', ctx.output,
} }
end, <
},
Note: pandoc's math flags (`--katex`, `--mathml`, `--mathjax`) are mutually
exclusive — last flag wins. Adding `--mathml` via `extra_args` (which is
appended after `args`) overrides `--katex`.
Self-contained output with `--embed-resources`: >lua
vim.g.preview = {
github = { extra_args = { '--embed-resources' } },
}
<
This inlines all external resources into the HTML. With `--katex` this adds
~15s of compile time per save (pandoc fetches KaTeX from the CDN during
compilation). Pair with `--mathml` to avoid the penalty: >lua
vim.g.preview = {
github = { extra_args = { '--embed-resources', '--mathml' } },
} }
< <

View file

@ -329,6 +329,9 @@ function M.compile(bufnr, name, provider, ctx, opts)
s.provider = name s.provider = name
s.is_reload = true s.is_reload = true
if not opts.silent then
vim.notify('[preview.nvim]: compiling...', vim.log.levels.INFO)
end
vim.api.nvim_exec_autocmds('User', { vim.api.nvim_exec_autocmds('User', {
pattern = 'PreviewCompileStarted', pattern = 'PreviewCompileStarted',
data = { bufnr = bufnr, provider = name }, data = { bufnr = bufnr, provider = name },
@ -360,6 +363,7 @@ function M.compile(bufnr, name, provider, ctx, opts)
end end
if result.code == 0 then if result.code == 0 then
log.dbg('compilation succeeded for buffer %d', bufnr) log.dbg('compilation succeeded for buffer %d', bufnr)
vim.notify('[preview.nvim]: compilation complete', vim.log.levels.INFO)
clear_errors(bufnr, provider) clear_errors(bufnr, provider)
vim.api.nvim_exec_autocmds('User', { vim.api.nvim_exec_autocmds('User', {
pattern = 'PreviewCompileSuccess', pattern = 'PreviewCompileSuccess',
@ -403,6 +407,9 @@ function M.compile(bufnr, name, provider, ctx, opts)
s.provider = name s.provider = name
s.is_reload = false s.is_reload = false
if not opts.silent then
vim.notify('[preview.nvim]: compiling...', vim.log.levels.INFO)
end
vim.api.nvim_exec_autocmds('User', { vim.api.nvim_exec_autocmds('User', {
pattern = 'PreviewCompileStarted', pattern = 'PreviewCompileStarted',
data = { bufnr = bufnr, provider = name }, data = { bufnr = bufnr, provider = name },
@ -512,8 +519,8 @@ function M.toggle(bufnr, name, provider, ctx_builder)
log.dbg('watching buffer %d with provider "%s"', bufnr, name) log.dbg('watching buffer %d with provider "%s"', bufnr, name)
end end
vim.notify('[preview.nvim]: watching with "' .. name .. '"', vim.log.levels.INFO) vim.notify('[preview.nvim]: compiling with "' .. name .. '"...', vim.log.levels.INFO)
M.compile(bufnr, name, provider, ctx_builder(bufnr)) M.compile(bufnr, name, provider, ctx_builder(bufnr), { silent = true })
end end
---@param bufnr integer ---@param bufnr integer

View file

@ -224,7 +224,7 @@ M.markdown = {
ft = 'markdown', ft = 'markdown',
cmd = { 'pandoc' }, cmd = { 'pandoc' },
args = function(ctx) args = function(ctx)
return { ctx.file, '-s', '--embed-resources', '--mathml', '-o', ctx.output } return { ctx.file, '-s', '--katex', '-o', ctx.output }
end, end,
output = function(ctx) output = function(ctx)
return (ctx.file:gsub('%.md$', '.html')) return (ctx.file:gsub('%.md$', '.html'))
@ -249,8 +249,7 @@ M.github = {
'gfm', 'gfm',
ctx.file, ctx.file,
'-s', '-s',
'--embed-resources', '--katex',
'--mathml',
'--css', '--css',
'https://cdn.jsdelivr.net/gh/pixelbrackets/gfm-stylesheet@master/dist/gfm.css', 'https://cdn.jsdelivr.net/gh/pixelbrackets/gfm-stylesheet@master/dist/gfm.css',
'-o', '-o',

View file

@ -55,6 +55,14 @@ describe('compiler', function()
end, end,
}) })
local notified = false
local orig = vim.notify
vim.notify = function(msg)
if msg:find('compiling') then
notified = true
end
end
local provider = { cmd = { 'echo', 'ok' } } local provider = { cmd = { 'echo', 'ok' } }
local ctx = { local ctx = {
bufnr = bufnr, bufnr = bufnr,
@ -64,7 +72,9 @@ describe('compiler', function()
} }
compiler.compile(bufnr, 'echo', provider, ctx) compiler.compile(bufnr, 'echo', provider, ctx)
vim.notify = orig
assert.is_true(fired) assert.is_true(fired)
assert.is_true(notified)
vim.wait(2000, function() vim.wait(2000, function()
return process_done(bufnr) return process_done(bufnr)

View file

@ -294,11 +294,11 @@ describe('presets', function()
assert.are.same({ 'pandoc' }, presets.markdown.cmd) assert.are.same({ 'pandoc' }, presets.markdown.cmd)
end) end)
it('returns args with standalone, embed-resources, and mathml flags', function() it('returns args with standalone and katex flags', function()
local args = presets.markdown.args(md_ctx) local args = presets.markdown.args(md_ctx)
assert.is_table(args) assert.is_table(args)
assert.are.same( assert.are.same(
{ '/tmp/document.md', '-s', '--embed-resources', '--mathml', '-o', '/tmp/document.html' }, { '/tmp/document.md', '-s', '--katex', '-o', '/tmp/document.html' },
args args
) )
end) end)
@ -382,7 +382,7 @@ describe('presets', function()
assert.are.same({ 'pandoc' }, presets.github.cmd) assert.are.same({ 'pandoc' }, presets.github.cmd)
end) end)
it('returns args with standalone, embed-resources, mathml, and css flags', function() it('returns args with standalone, katex, and css flags', function()
local args = presets.github.args(md_ctx) local args = presets.github.args(md_ctx)
assert.is_table(args) assert.is_table(args)
assert.are.same({ assert.are.same({
@ -390,8 +390,7 @@ describe('presets', function()
'gfm', 'gfm',
'/tmp/document.md', '/tmp/document.md',
'-s', '-s',
'--embed-resources', '--katex',
'--mathml',
'--css', '--css',
'https://cdn.jsdelivr.net/gh/pixelbrackets/gfm-stylesheet@master/dist/gfm.css', 'https://cdn.jsdelivr.net/gh/pixelbrackets/gfm-stylesheet@master/dist/gfm.css',
'-o', '-o',