Skip to content

Support resvg as alternative to rsvg-convert for SVG rendering #13696

@cderv

Description

@cderv

Installing rsvg-convert on Windows can be challenging for users, requiring either manual binary installation or complex package manager setup. This affects workflows that convert SVG to PDF/LaTeX output, including mermaid diagrams with mermaid-format: svg.

resvg (https://github.com/linebender/resvg) is a modern Rust-based SVG rendering library with better cross-platform support. It provides pre-built binaries for all platforms and is available through Windows package managers (scoop, winget), making installation significantly easier for Windows users.

We could add resvg as an alternative SVG converter alongside rsvg-convert and Inkscape. The conversion pipeline in src/resources/filters/quarto-post/pdf-images.lua already handles rsvg-convert and has infrastructure for tool detection.

local function convert_svg(image)
-- If the src is pointing to a local file that is an svg, process it
local ext = select(2, pandoc.path.split_extension(image.src))
if ext ~= '.svg' then
return nil
end
if not option("use-rsvg-convert", true) then
local stem = pandoc.path.split_extension(image.src)
local output = stem .. '.pdf'
if not _quarto.file.exists(output) then
warn("Skipping SVG conversion for " .. path .. " because use-rsvg-convert is false, but required PDF file does not exist: " .. output)
else
image.src = output
return image
end
end
local converted_path, must_clean = call_rsvg_convert(image.src)
if converted_path == nil then
return nil
end
local contents = _quarto.file.read(converted_path)
assert(contents ~= nil)
local relative_path = pandoc.path.make_relative(converted_path, '.')
-- add to media bag and remove the converted file
pandoc.mediabag.insert(relative_path, 'application/pdf', contents)
if must_clean then
_quarto.file.remove(relative_path)
end
image.src = relative_path
return image
end

We could implement this similar to the existing use-rsvg-convert option, perhaps with a more general svg-converter option that accepts resvg, rsvg-convert, or inkscape, with automatic fallback to whichever tool is available.

This came up while investigating #13661, where better SVG tooling options would help Windows users. Directly addresses the request in #1144 for specifying alternative SVG conversion tools.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestluaIssues related to the lua codebase, filter chain, etc

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions