Take the 2-minute tour ×

I need to generate PNG images of Latin characters and AMS symbols with transparent background. Each image should be exactly in dimensions of its box. I know It's possible with LaTeX because I see online LaTeX formula editors can generate such pictures. Currently I can generate only dvi and pdf files in known paper sizes (a4,letter ...). size of output must be bounded to its content and output must be in png format with transparent background.

I wish do this using a program. because there are thousands of characters and symbols that I need their LaTeX-produced images. Please tell me if there are CLI solutions or not. Also some of characters can only produced by XeTeX and XeLaTeX (characters of non-latin scripts)

share|improve this question
A related question: tex.stackexchange.com/questions/11866/…. –  John Palmieri Mar 26 '11 at 0:16
add comment

3 Answers

up vote 7 down vote accepted

How about using dvipng.

        \advance\n by 1

Then run latex l; dvipng l; mv l256.png l0.png

Obviously, this only solves part of the problem, but it should demonstrate how to handle the ones that can be done with dvi output.

share|improve this answer
Thank you. It works for me :-) –  sorush-r Mar 26 '11 at 13:13
add comment

To generate PDF pages which are only as big as the printed content you can use the preview package or the standalone class which is using it. For your purpose I recommend using preview directly in a loop and then use Image Magick's convert to convert the PDFs in multiple PNGs:

% chars.tex
\foreach \n in {0,...,255} {%


pdflatex chars.tex
convert -density 600 chars.pdf -quality 90 chars.png

However you should be aware that characters can swap over their official bounding box, so the images might cut of some material. You might try to add some \PreviewBorder to it and use pdfcrop before the conversion to PNG.

share|improve this answer
add comment

Not a LaTeX-solution, but if you have the characters you want to generate available as a TrueType or OTF font, you can use ImageMagick directly, in this case to generate images for codepoints 00C0 through 00C7 for Latin Modern Roman 10pt:

for (( i=192; i<200; i++ )); do
    codepoint=`printf %04x $i`
    env LC_CTYPE=en_US.utf8 printf "\u$codepoint" \
         | convert -background transparent -fill black -pointsize 10 \
         -font /usr/share/texmf/fonts/opentype/public/lm/lmroman10-regular.otf \
         label:@- $codepoint.png
share|improve this answer
add comment

Your Answer


