I want to use tikz images but include them in my document via PNG with includegraphics. This works nicely both for PDF and HTML, but the original tikz image is displayed, too. The reason why I need this is because I want to use it in conjunction with tex4ht and have the resulting HTML file display the PNG files and not the SVG files.
Currently, the following code just displays three pictures. I want the first one hidden and only be used to export into PNG.
\begin{tikzpicture}
\node[fill=yellow!80,ellipse] (origin) {Origin};
\node[fill=blue!30,ellipse] (destination) at (15em,0) {Destination};
\path (origin) edge[->] node[above,font=\footnotesize] {the journey} (destination);
\end{tikzpicture}
\includegraphics{figures/myfigure.png}
\includegraphics{figures/myfigure-600.png}
To convert and copy the PNG files, I use the following code:
\tikzset{external/force remake}
\tikzset{png export/.style={
external/system call={
pdflatex \tikzexternalcheckshellescape
-halt-on-error -interaction=batchmode -jobname "\image" "\texsource";
convert -units pixelsperinch -density 150 "\image.pdf" "\image.png";
convert -units pixelsperinch -density 600 "\image.pdf" "\image-600.png";
}}}
\tikzset{png export}
\tikzsetexternalprefix{figures/}
\tikzsetnextfilename{myfigure}
Alternatively, I could live with the tikzpicture command directly use the PNG files it generates for the output (instead of relying on the SVG file), so I don't need the includegraphics command (might even be the better solution :) ).
Here is the minimal example: https://www.overleaf.com/17313462rcpxbvktsgvd
Thank you in advance!
main.tex:
\documentclass{scrbook}
\title{TEST TIKZ}
\usepackage{tikz,pgfplots}
\usetikzlibrary{matrix}
\usepgfplotslibrary{external}
\usepackage{siunitx}
\DeclareSIUnit{\sr}{sr}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
%\tikzexternalize % comment out to debug if latex errors: generates the external pdf
\tikzset{external/force remake}
\tikzset{png export/.style={
external/system call={
pdflatex \tikzexternalcheckshellescape
-halt-on-error -interaction=batchmode -jobname "\image" "\texsource";
convert -units pixelsperinch -density 150 "\image.pdf" "\image.png";
convert -units pixelsperinch -density 600 "\image.pdf" "\image-600.png";
}}}
\tikzset{png export}
\tikzsetexternalprefix{figures/}
\tikzsetnextfilename{myfigure}
\usetikzlibrary{calc}
\usetikzlibrary{positioning,shapes.arrows,shapes.symbols,decorations.pathreplacing,}
\usetikzlibrary{patterns,shapes,backgrounds,lindenmayersystems,shadings,intersections}
\begin{document}
\begin{tikzpicture}
\node[fill=yellow!80,ellipse] (origin) {Origin};
\node[fill=blue!30,ellipse] (destination) at (15em,0) {Destination};
\path (origin) edge[->] node[above,font=\footnotesize] {the journey} (destination);
\end{tikzpicture}
\includegraphics{figures/myfigure.png}
\includegraphics{figures/myfigure-600.png}
\end{document}
latexmkrc:
# html generation
$pdflatex = "htlatex %S \"htlatex/htlatex.cfg,MyFonts,NoFonts\" \"\" \"\" -shell-escape > output.txt; pdflatex -shell-escape -synctex=1 %O %S";
$clean_ext .= ' 4ct 4tc idv lg tmp xref';
$clean_full_ext .= ' css html';
htlatex/htlatex.cfg:
\Preamble{xhtml}
\usepackage{graphicx}
\DeclareGraphicsExtensions{.svg,.png,.jpg,.jpeg,.gif,.pdf,.eps}
\Configure{graphics*}
{pdf}
{\Needs{"convert -density 150 \csname Gin@base\endcsname.pdf
\csname Gin@base\endcsname.png"}%
\Picture[pict]{\csname Gin@base\endcsname.png}%
\special{t4ht+@File: \csname Gin@base\endcsname.png}
}
\Configure{graphics*}
{eps}
{\Needs{"convert -density 150 \csname Gin@base\endcsname.eps
\csname Gin@base\endcsname.png"}%
\Picture[pict]{\csname Gin@base\endcsname.png}%
\special{t4ht+@File: \csname Gin@base\endcsname.png}
}
\Configure{VERSION}{}
\Configure{DOCTYPE}{\HCode{<!DOCTYPE html>\Hnewline}}
\Configure{HTML}{\HCode{<html>\Hnewline}}{\HCode{\Hnewline</html>}}
\begin{document}
\EndPreamble
standalone
, if the externalisation library can't do it.