Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

For my latex document, I have image files in tga format that I'd like to include. I want to convert them into pdf so latex can scale them without loose of precision.

By now, I just did this with inkscape, but for many pictures, this can be much work. Is there something to let latex do that automatically? Or is there a way to do it in my command line, without a GUI like inkscape?

Please note: I have linux.

share|improve this question
1  
As I understand it, TGA is a raster format. Since you say you want to be able to scale them without loss of precision, I assume you use Inkscape to trace the raster image and save it as a vector image (as opposed to merely embedding it in a PDF). So your question is concerned with automatically tracing raster images, right? –  Jake Aug 20 '12 at 9:17
    
I use inkscape to print it into a file. This results in a pdf. So I don't think I save it as a vector image, as you say it. –  Johannes Aug 20 '12 at 9:28
1  
In that case, you don't gain anything from converting the TGA to a PDF, because it's still a raster image. Instead of going through the manual process of opening the image in Inkscape and saving it to a PDF, you could just use ImageMagick (apt-get install imagemagick on Ubuntu) to convert the TGA to a format that you can use in LaTeX (JPG for photos, PNG for graphics). You can convert all TGAs in a directory to PNG by using mogrify -format PNG *.TGA –  Jake Aug 20 '12 at 9:33
    
As we were using them, TGA files are good for render outputs and other After Effects goodies often hundreds MB each. Where do you get them? Do you want to make them extremely zoomable(!?) or for large size printing? –  percusse Aug 20 '12 at 9:51
    
@percusse They are not extremely large, but yeah, they shall be zoomable. These are scientific pictures from discrete computations, so I want them to be exact. As written in the answer below, PNG is probably the best solution for that... –  Johannes Aug 20 '12 at 10:02
show 2 more comments

1 Answer

up vote 10 down vote accepted

"Truevision TGA, often referred to as TARGA, is a raster graphics file format [...]"

Remark: The PDF format can contain both raster images and vector images. For example, scan programs often offer PDF as output format, but these PDFs only contain the scanned raster images. It is just a convenience for users that are more familiar with their PDF viewers than with image programs. Also it is easier to put several images as pages to a PDF file.

If you want vector data instead, you need a vectorization and a good program to do it. Example for a freeware tool: potrace for monochrome images. But for good result you usually need to twiddle with the parameters of the vectorization process.

If you just want to include .tga files with pdflatex, then package epstopdf helps:

\usepackage{graphicx}
\usepackage{epstopdf}

\epstopdfDeclareGraphicsRule{.tga}{png}{.png}{%
  convert #1 \OutputFile
}
\AppendGraphicsExtensions{.tga}

Then <file>.tga is automatically converted and included as <file>-tga-converted-to.png. As conversion program convert from ImageMagick is used here.

Edit: Running external programs need some rights. In TeX Live restricted shell escape is enabled by default. But the supported program list does not include convert. Therefore option --shell-escape is needed for pdflatex.

Full example

Assuming the .tga file is called foobar.tga:

\documentclass{article}

\usepackage{graphicx}
\usepackage{epstopdf}

\epstopdfDeclareGraphicsRule{.tga}{png}{.png}{%
  convert #1 \OutputFile
}
\AppendGraphicsExtensions{.tga}

\begin{document}
  \includegraphics{foobar}
\end{document}

And pdflatex needs to be called with option --shell-escape (TeX Live); MiKTeX also uses --enable-write18 as synonym.

P.S. Is there is only one .tga file that should be converted only once, then it is easier to convert it on the command line, e.g.:

convert foobar.tga foobar.png

Also an interactive image program would do that can read TGA files and export PNG files.

share|improve this answer
    
Thanks, but PNG has loss, right (think of sharp edges)? Printing to TGA, as I used to do it, did not result in loss. –  Johannes Aug 20 '12 at 9:40
2  
PNG uses lossless compression, but JPEG uses lossy compression methods. –  Heiko Oberdiek Aug 20 '12 at 9:42
    
I have convert installed, and did exactly what you proposed (the DeclareGraphicsRule thing), but in my includegraphics line, pdflatex complains: "File `images/id_521-tga-converted-to.png' not found". Can you please help? –  Johannes Aug 20 '12 at 9:56
    
Could you please give a real example. Where exactly do I need to put the conversion, i.e., \epstopdfDeclareGraphicsRule{.tga}{png}{.png}{% convert #1 \OutputFile } Do I need to put it before begin{document}? Is there any placeholder in the above snippet (e.g., some name in OutputFile)? I get messages like You can't use macro parameter character # in horizontal mode. etc. I was trying to include a .tga file obtained from VMD. –  iloveX May 10 '13 at 0:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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