LaTeX/Export To Other Formats

From Wikibooks, the open-content textbooks collection

Jump to: navigation, search

Strictly speaking, LaTeX source can be used to directly generate two formats:

  • DVI using latex, the first one to be supported
  • PDF using pdflatex, more recent

Using other software freely available on Internet, you can easily convert DVI and PDF to other document formats. In particular, you can obtain the PostScript version using software coming within your LaTeX distribution. Some LaTeX IDE will give you the possibility to generate the PostScript version directly (even if it uses internally a DVI mid-step, e.g. LaTeX → DVI → PS). It is also possible to create PDF from DVI and vice versa. It doesn't seem logical to create a file with two steps when you can create it straight away, but some users might need it because, as you remember from the first chapters, the format you can generate depends upon the formats of the images you want to include (EPS for DVI, PNG and JPG for PDF). Here you will find sections about different formats with description about how to get it.

Other formats can be produced, such as RTF (which can be used in Microsoft Word) and HTML. However, these documents are produced from software that parses and interprets the LaTeX files, and do not implement all the features available for the primary DVI and PDF outputs. Nonetheless, they do work, and can be crucial tools for collaboration with colleague that do not edit documents with LaTeX.

Contents

[edit] Convert to PDF

[edit] DVI-> PDF

dvipdfm my_file.dvi

will create my_file.pdf. Another way is to pass through PS generation:

dvi2ps myfile.dvi
ps2pdf myfile.ps

you will get also a file called my_file.ps that you can delete.

[edit] Merging PDF

If you have created different PDF documents and you want to merge them into one single PDF file you can use the following command-line command. You need to have Ghostscript installed:

For Windows:

gswin32 -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=Merged.pdf -dBATCH 1.pdf 2.pdf 3.pdf

For Linux:

gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=Merged.pdf -dBATCH 1.pdf 2.pdf 3.pdf

Another option to check out is pdftk (or PDF toolkit), which is a command-line tool that can manipulate PDFs in many ways. To merge one or more files, use:

pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf

Note: If you are merging external PDF documents into a Latex document which is compiled with pdflatex, a much simpler option is to use the pdfpages package, e.g.:

\usepackage{pdfpages}
...
\includepdf[pages=-]{Document1.pdf}
\includepdf[pages=-]{Document2.pdf}
...

[edit] Convert to PostScript

from PDF
pdf2ps my_file.pdf
from DVI
dvi2ps my_file.dvi

[edit] Convert to RTF

LaTeX can be converted into an RTF file, which in turn can be opened by Microsoft Word and OpenOffice.org Writer. This conversion is done through latex2rtf, which can run on any computer platform. The program operates by reading the LaTeX source, and mimicking the behaviour of the LaTeX program. latex2rtf supports most of the standard implementations of LaTeX, such as standard formatting, some math typesetting, inclusion of EPS, PNG or JPG graphics, and tables. As well, it has some limited support for packages, such as varioref, and natbib. However, many other packages are not supported.

latex2rtf is simple to use. The Windows version has a GUI, which is straightforward to use. The command-line version is offered for all platforms, and can be used on an example mypaper.tex file:

latex mypaper
bibtex mypaper # if you use bibtex
latex2rtf mypaper

Both latex and (if needed) bibtex commands need to be run before latex2rtf, because the .aux and .bbl files are needed to produce the proper output. The result of this conversion will create myfile.rtf, which you may open in many modern word processors. Microsoft Word users can save this file as a myfile.doc to use features included with that program, such as "Track changes".

[edit] Conversion to HTML

There are many converters to HTML. One option is the HEVEA program:

LaTeX
hevea mylatexfile
BibTeX
bibtex2html mybibtexfile

[edit] Conversion to image formats

[edit] PNG

To convert from PDF, open your file with GIMP. It will ask you which page you want to convert, whether you want to use anti-aliasing (choose strong if you want to get something similar to what you see on the screen). Try different resolutions to fit your needs, but 100 dpi should be enough. Once you have the image within GIMP, you can post-process it as you like and save it to any format supported by GIMP, as PNG for example. A method for DVI files is dvipng (usage is the same as dvipdfm). Also, the "convert" command from the ImageMagick suite can convert both DVI and PDF files to PNG.

You can optimize the resulting image using optipng so that it will take up less space.

[edit] SVG

Convert it to PS as described before, then use the bash script ps2svg.sh (it could be possible to write a step-by-step guide for Windows as well; all the software it uses is multiplatform).

One can also use dvisvgm, an open source utility that converts from DVI to SVG.

Previous: General Guidelines Index Next: Internationalization
Personal tools