@@ -550,8 +550,8 @@ end
550550
551551This filter converts raw LaTeX tikz environments into images. It
552552works with both PDF and HTML output. The tikz code is compiled
553−to an image using `pdflatex`, and the image is converted (if
554−necessary) from pdf to png format using ImageMagick's `convert`,
553+to an image using `pdflatex`, and the image is converted from pdf
554+to svg format using [`pdf2svg`](https://github.com/dawbarton/pdf2svg),
555555so both of these must be in the system path. Converted images
556556are cached in the working directory and given filenames based on
557557a hash of the source, so that they need not be regenerated each
@@ -563,7 +563,7 @@ local function tikz2image(src, filetype, outfile)
563563 local tmp = os.tmpname()
564564 local tmpdir = string.match(tmp, "^(.*[\\/])") or "."
565565 local f = io.open(tmp .. ".tex", 'w')
566− f:write("\\documentclass{standalone}\n\\usepackage{tikz}\n\\begin{document}\n")
566+ f:write("\\documentclass{standalone}\n\\usepackage{xcolor}\n\\usepackage{tikz}\n\\begin{document}\n\\nopagecolor\n")
567567 f:write(src)
568568 f:write("\n\\end{document}\n")
569569 f:close()
@@ -571,7 +571,7 @@ local function tikz2image(src, filetype, outfile)
571571 if filetype == 'pdf' then
572572 os.rename(tmp .. ".pdf", outfile)
573573 else
574− os.execute("convert " .. tmp .. ".pdf " .. outfile)
574+ os.execute("pdf2svg " .. tmp .. ".pdf " .. outfile)
575575 end
576576 os.remove(tmp .. ".tex")
577577 os.remove(tmp .. ".pdf")
@@ -580,9 +580,9 @@ local function tikz2image(src, filetype, outfile)
580580end
581581
582582extension_for = {
583− html = 'png',
584− html4 = 'png',
585− html5 = 'png',
583+ html = 'svg',
584+ html4 = 'svg',
585+ html5 = 'svg',
586586 latex = 'pdf',
587587 beamer = 'pdf' }
588588
@@ -596,13 +596,22 @@ local function file_exists(name)
596596 end
597597end
598598
599+local function starts_with(start, str)
600+ return str:sub(1, #start) == start
601+end
602+
603+
599604function RawBlock(el)
600− local filetype = extension_for[FORMAT] or "png"
601− local fname = pandoc.sha1(el.text) .. "." .. filetype
602− if not file_exists(fname) then
603− tikz2image(el.text, filetype, fname)
605+ if starts_with("\\begin{tikzpicture}", el.text) then
606+ local filetype = extension_for[FORMAT] or "svg"
607+ local fname = pandoc.sha1(el.text) .. "." .. filetype
608+ if not file_exists(fname) then
609+ tikz2image(el.text, filetype, fname)
610+ end
611+ return pandoc.Para({pandoc.Image({}, fname)})
612+ else
613+ return el
604614 end
605− return pandoc.Para({pandoc.Image({}, fname)})
606615end
607616```
608617