Pandoc doesn't know how to handle TikZ environments. However, you can use a Lua filter to teach pandoc.
Specifically, one can use the method outlined in the building images with TikZ example. The example assumes the input to be Markdown mixed with LaTeX, so you'll need to perform a few tweaks for it to work with pure LaTeX input.
First, we want pandoc to keep any LaTeX it can't read as-is instead of doing its best to convert it anyway. Do this by adding --from latex+raw_tex to your command.
Next, we want to run the image generator only on LaTeX snippets which look like a tikzpicture environment, and only if we haven't done this conversion yet.
local function file_exists(name)
local f = io.open(name, 'r')
if f ~= nil then io.close(f); return true
else return false end
end
function RawBlock(el)
-- Don't alter element if it's not a tikzpicture environment
if not el.text:match'^\\begin{tikzpicture}' then
return nil
-- Alternatively, parse the contained LaTeX now:
-- return pandoc.read(el.text, 'latex').blocks
end
local fname = pandoc.sha1(el.text) .. ".png"
if not file_exists(fname) then
tikz2image(el.text, fname)
end
return pandoc.Para({pandoc.Image({}, fname)})
end
Finally, we include the actual image-conversion code
--- Create a standalone LaTeX document which contains only the TikZ picture.
--- Convert to png via Imagemagick.
local function tikz2image(src, outfile)
local tmp = os.tmpname()
local tmpdir = string.match(tmp, "^(.*[\\/])") or "."
local f = io.open(tmp .. ".tex", 'w')
f:write("\\documentclass{standalone}\n")
-- include all packages needed to compile your images
f:write("\\usepackage{tikz}\n\\usepackage{stanli}\n")
f:write("\\begin{document}\n")
f:write(src)
f:write("\n\\end{document}\n")
f:close()
os.execute("pdflatex -output-directory " .. tmpdir .. " " .. tmp)
os.execute("convert " .. tmp .. ".pdf " .. outfile)
os.remove(tmp .. ".tex")
os.remove(tmp .. ".pdf")
os.remove(tmp .. ".log")
os.remove(tmp .. ".aux")
end
Put all of the above code into a file named tikz-to-png.lua and run it by calling pandoc with the --lua-filter=tikz-to-png.lua option.
Note that you'll need ImageMagick's convert program in your path.