PNG image files creation from schemas in TeX/LaTex documents



In scientific publications, sophisticated schemas are created in Latex documents using packages (circuitikz for electric circuits, chemfig for chemical molecules…).

To duplicate and insert the schemas in HTML pages, there is an easy way to produce png image files from the PDF Latex documents containing the schemas without using tools like Gimp, Photoshop.

chemfig - Guanine

How to create png image files from schemas in Latex documents using MiKTeX and TexMaker ?

Standalone mode

For one schema, create a Latex document in standalone mode.


Margins may have to be adjusted using the options [margin=…] : in some circumstances, schema may be truncated.


Compile the standalone document to PDF format and then use pdftoppm available in the MiKTeX distribution to generate the png image file from the pdf file :

% cd D:\projects\Tex\pub

% pdftoppm -png guanine.pdf > guanine.png 

A Jpeg format is generated with the option -jpeg.

Multiple schemas in one Latex document, tikz

We may not want to store one schema per file. Still in standalone mode, set the document class to tikz to produce one schema per page in a Latex document. Each page is adjusted to the size of the schema.




	% Page 1 : guanine  	
  	% Page 2 : Benzene

	% Page 3 : Esterification	
	\chemname{\chemfig{R-C(-[:-30]OH)=[:30]O}}{Carboxylic Acid}
	\arrow(.mid east--.mid west)


In the above example :

  • Page 1 : guanine molecule
  • Page 2 : benzene molecule
  • Page 3 : esterification reaction

Use the options -f (first page) and -l (last page) to generate the png file for one schema :

% cd D:\projects\Tex\pub

% pdftoppm -f 2 -l 2 -png chemistry.pdf > benzene.png
% pdftoppm -f 3 -l 3 -png chemistry.pdf > esterification-reaction.png
chemfig - Benzene chemfig - Esterification


The method works for multiple schemas TikzPicture.

% cd D:\projects\Tex\pub
% pdftoppm -f 1 -l 1 -png function.pdf > f-variation.png
% pdftoppm -f 2 -l 2 -png function.pdf > f-graph.png
Math - Function variation Math - Function graph




% Page 1 : Function variation
	{$x$ /1,%
	 $f'(x)=-\dfrac{1}{2x^2}$ /1,%
	 $f(x)=\dfrac{1}{x}$ /2}%	
	{$-\infty$ , $0$ , $+\infty$}%
	\tkzTabLine{ 0, -, d, -, 0}
	\tkzTabVar{+/ $0^-$, -D+/ $-\infty$/ $+\infty$, -/ $0^+$}

% Page 2 : Graph Function
	\begin{axis}[ xlabel={$x$}, ylabel={$y$}
		,axis lines=middle
		,samples=200, grid, thick
		,ymin = -20, ymax = 20
		,xmin = -2.1, xmax = 2.1
		,axis on top=true
	\addplot [domain=-2:-0.001, no marks, blue] {1/x)};
	\addplot [domain=0.001:2,no marks, blue] {1/x)};