I would need to convert my .tex file into an editable format such as odt. After various vicissitudes, I managed to find the right way. The equations are exported almost correctly (the command (\sin
is transcribed as s
), but there is no trace of the images created with tikz.The problem is that the script does not recognize the pdf2svg
command, since it is not installed. I followed the instructions, but being in a Windows environment, commands like ./configure --prefix=/usr/local
and make
are not recognized despite having Chocolately and MSYS2 installed.
Here is all the material for the MWE:
.tex code:
\documentclass[tikz,convert=pdf2svg]{standalone}\usepackage{amsmath}\usepackage{mathtools}\usepackage{blindtext}\usepackage{tikz}\usepackage{pgfplots}\pgfplotsset{compat=newest}\usepackage{siunitx}\DeclareSIUnit\angstrom{\text {A}}\usepackage{graphicx}\title{Sections and Chapters}\author{Overleaf}\date{\today}\begin{document}\maketitle\section{Introduction}This is the first section.\begin{equation}\label{eq:1} E = mc^2\end{equation}Lorem ipsum dolor sit amet, consectetuer adipiscing elit.Etiam lobortis this in inline equation:\[ \cos(\theta + \phi) = \cos \theta \cos \phi - \sin \theta \sin \phi \]facilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales commodo, lectus velit ultricesaugue, a dignissim nibh lectus placerat pede.Vivamus nunc nunc, molestieut, ultricies vel, semper in, velit.Ut porttitor.Praesent in sapien.Loremipsum dolor sit amet, consectetuer adipiscing elit. Duis fringilla tristique neque.Sed interdum libero ut metus.Pellentesque placerat.Nam rutrum augue aleo. Morbi sed elit sit amet ante lobortis sollicitudin. Praesent blandit blanditmauris.Praesent lectus tellus, aliquet aliquam, luctus a, egestas a, turpis.Mauris lacinia lorem sit amet ipsum. Nunc quis urna dictum turpis accumsansemper.\section{Second Section}This is the second section\begin{center}\begin{figure} \begin{tikzpicture} \begin{axis}[ colorbar, colorbar style={ title=$V$, ylabel=\unit{\kilo\cal} \unit{\mol^{-1}}, ytick={0,50,100,150,200,250}, xshift=1cm }, xtick={1,2,3,4},xmin=1,xmax=4.5, ytick={1,2,3,4},ymin=1,ymax=4.5, ztick={0,50,100,150,200,250},zmin=0,zmax=250, xlabel={$r_{\mathrm{AB}}\hspace{3px}\left(\unit{\angstrom}\right)$}, ylabel={$r_{\mathrm{BC}}\hspace{3px}\left(\unit{\angstrom}\right)$}, zlabel={$V \hspace{3px} \left(\unit{\kilo\cal} \hspace{3px} \unit{\mol^{-1}}\right)$}, % tick align=outside, zticklabel style={yshift=5pt}, xticklabel style={xshift=5pt}, x label style={yshift=0.25cm}, y label style={yshift=0.5cm}, ] \addplot3 [surf,shader=flat,draw=black,domain=1:4.5,y domain=1:4.5] {(128*(1-exp(-(x-1.3)))^2)+(128*(1-exp(-(y-1.3)))^2)}; \end{axis} \end{tikzpicture}\caption{Sezione dell'ipersuperficie dell'energia potenziale per una generica molecola ABC}\end{figure}\end{center}\blindtext\end{document}
Lua code:
local system = require 'pandoc.system'local tikz_doc_template = [[\documentclass{book}\usepackage{mathtools}\usepackage{blindtext}\usepackage{tikz}\usepackage{pgfplots}\pgfplotsset{compat=newest}\usepackage{siunitx}\DeclareSIUnit\angstrom{\text {A}}\usepackage[T1]{fontenc}\usepackage{lmodern}\usepackage{amsmath}\usepackage[arrow]{hhtensor}\usepackage{graphicx}\begin{document}\nopagecolor%s\end{document}]]local function tikz2image(src, filetype, outfile) system.with_temporary_directory('tikz2image', function (tmpdir) system.with_working_directory(tmpdir, function() local f = io.open('tikz.tex', 'w') f:write(tikz_doc_template:format(src)) f:close() os.execute('pdflatex tikz.tex') if filetype == 'pdf' then os.rename('tikz.pdf', outfile) elseif filetype == 'png' then os.execute("pdftoppm -png tikz.pdf > " .. outfile) else os.execute('pdf2svg -o' .. outfile .. 'tikz.pdf') end end) end)endextension_for = { docx = 'png', 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 endendlocal function starts_with(start, str) return str:sub(1, #start) == startendfunction RawBlock(el) if starts_with('\\begin{tikzpicture}', el.text) then local filetype = extension_for[FORMAT] or 'svg' local fname = system.get_working_directory() .. '/' .. pandoc.sha1(el.text) .. '.' .. filetype if not file_exists(fname) then tikz2image(el.text, filetype, fname) end return pandoc.Para({pandoc.Image({}, fname)}) else return el endend
Prompt command: pandoc --from latex+raw_tex --lua-filter=tikz-to-png.lua -s test.tex -o test.odt