I want to export chemical lewis structures as transparent PNG-files in order to use them in Word documents.

So I want to achieve whats described in this post. I just can't get it to work because my understanding of LaTeX is very limited.

This is my code:

\newcommand{\pol}[2][red]{$\color{#1} \delta^{#2}$}




This is what it looks like:

enter image description here

When I use \documentclass{standalone} it crops the document too close:

enter image description here

In the post mentioned above the OP wrote:

There is a border class option which sets the border around the content (the default is 0.5bp). This option excepts either one (border for all sides), two (left/right, top/bottom) or four values (left, bottom, right, top).

I have no clue how to implement the border though.

Regarding the PNG Output another user wrote this Shell-Script but I don't know how to use it. Where do I need to save the script and where do I place the code to call it in the LaTeX document?

  • 2
    \documentclass[border=1mm]{standalone} adds 1mm to each side. – Torbjørn T. May 15 at 11:38

You can try to use dvisvgm to convert your document into an .svg file, and then if you need into a .png.

You have to download this then you can create a .bat file (converter.bat for example) in the same folder as your .tex file, then put the following code :

@echo off
path=C:\Program Files\MiKTeX 2.9\miktex\bin\x64;%path%;
dvisvgm --pdf --no-fonts myfile.pdf myflie.svg
@echo on

Then you can run it after create your pdf file, and then you go.

  • Thanks this works perfectly. And it's even better since SVG is supported in MS Office applications. Do you by any chance know how to increase the border when I use "\documentclass{standalone}"? – user363808 May 15 at 13:45
  • I found it here: tex.stackexchange.com/questions/123880/… – user363808 May 15 at 13:56

You must use an external tool, like convert, as is mentioned in the post that you cite. The border option is very easy if you want then same margin at the four borders:


Latex can call automatically that external tool. For example, taking the example in this other question:

\documentclass[convert={density=300,size=1080x800,outext=.png}, border=15mm]{standalone}

Note that you must have installed convert program, and that you have to call latex with -shell-escape option.

A different approach is to use the tikz and its external library.


  external/system call/.add=
  {; convert -density 300 -transparent white "\image.pdf" "\image.png"},
  /pgf/images/external info,


A figure to export
% Optional: you can set the filename of the following picture:
   \node[text width=\linewidth]
      Your latex code here: \[x=1\]

Another figure

   \node[text width=\linewidth]
      Other latex code here: \[x^2=1\]

In this example the the directory dir must exist. Then pdflatex --shell-escape generete two png files:


The filename of each picture can be set with \tikzsetnextfilename{filename}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.