-
I need to convert a Latex document containing Tikz pictures to HTML. The following is an example document
which has the following PDF output. In order to convert to HTML, I am using the following command:
where Unfortunately, the HTML output I get is the following where the picture is missing.
Which is the same output I get when I don't use the filter in the Could you please help me achieve my goal? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Here's what I do in a book I'm working on. I use a Lua filter tex2image.lua: local system = require 'pandoc.system'
local doc_template = [[
\documentclass{standalone}
\usepackage{bookgraphics} % Local package with my own macro definitions used in tikz diagrams
\begin{document}
%s
\end{document}
]]
local function tex2image(src, filetype, outfile)
local f = io.open('tex-temp.tex', 'w')
f:write(doc_template:format(src))
f:close()
local _, _, status = os.execute('lualatex -pdflua -auxdir=textmp -interaction=nonstopmode -halt-on-error -shell-escape tex-temp.tex')
if status ~= 0 then
os.exit(1)
end
if filetype == 'pdf' then
os.rename('tex-temp.pdf', outfile)
else
os.execute('pdf2svg tex-temp.pdf ' .. outfile)
end
end
extension_for = {
html = 'svg',
html4 = 'svg',
html5 = 'svg',
latex = 'pdf',
beamer = 'pdf' }
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)
if el.format == 'latex' and
(el.text:match("^\\begin%{tikz") or el.text:match("^%$")) then
local filetype = extension_for[FORMAT] or 'svg'
local fbasename = pandoc.sha1(el.text) .. '.' .. filetype
if not pandoc.mediabag.lookup(fbasename) then
local outname = "tex-temp." .. filetype
tex2image(el.text, filetype, outname)
local mt, contents = pandoc.mediabag.fetch(outname)
pandoc.mediabag.insert(fbasename, mt, contents)
end
return pandoc.Para({pandoc.Image({}, fbasename)})
else
return el
end
end This uses lualatex and pdf2svg to generate svg versions of the tikz environments, which it then puts in the "mediabag." My source format is markdown, but I think it would work for you if you use diagram.lua is, if I recall, designed to translate certain markdown code blocks into tikz diagrams, so it's not going to work for going directly from latex. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
There is another Lua filter you could try: https://dialoa.github.io/imagify/ -- it uses a different SVG converter (https://dvisvgm.de rather than PDF2SVG) IINM. You could also edit John's filter to use |
Beta Was this translation helpful? Give feedback.
Here's what I do in a book I'm working on. I use a Lua filter tex2image.lua: