We start with a LaTeX document mytext.tex like this:
\documentclass[a4paper,12pt]{article}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{mathptmx}
\usepackage[scaled=.92]{helvet}
\usepackage{courier}
\usepackage{graphicx}
\author{The documentation group}
\title{The documentation}
\begin{document}
\section{Test}
This is a test.
This is a test.
This is a test.
This is a test.
This is a test.
This is a test.
\end{document}
The image doc1.fig to add to the document is drawn in jFig (you can use XFig, WinFig or any other program producing *.fig files):
To do the conversions we run
fig2vect -lmp.tex doc1.fig doc1.mp fig2vect -ltex doc1.fig -i doc1.mps doc1.tex mpost -tex=latex doc1 mv doc1.0 doc1.mps
The LaTeX source mytext.tex is changed, we add a figure environment and include doc1.tex:
\begin{figure}%
{\centering%
\input{doc1.tex}%
\caption{Test image}%
\label{fig:test-image}%
}
\end{figure}
Now we can create mytext.ps by running
latex mytext latex mytext dvips mytext
or mytext.pdf by running
pdflatex mytext pdflatex mytext
In this example we use the same Fig drawing as in the example above.
In the standalone PDF file we want to have the texts in the same fonts as in the example above. So we have to prepare a file preamble.tex containing a preamble only:
\documentclass[a4paper,12pt]{article}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{mathptmx}
\usepackage[scaled=.92]{helvet}
\usepackage{courier}
\usepackage{color}
We have to use all the packages related to font selections, text encoding... The color package is required for text colors.
We use
fig2vect -lmp.tex doc1.fig doc1i.mp mpost -tex=latex doc1i mv doc1i.0 doc1i.mps fig2vect -ltex.full doc1.fig -i doc1i.mps -o preamble.file=preamble.tex doc1.tex pdflatex doc1
to create a standalone PDF file doc1.pdf.
We use
pdftoppm doc1.pdf doc1 pnmtopng doc1-000001.ppm> doc1.png rm doc1-000001.ppm
to convert doc1.pdf to doc1.png.
We use
optipng -q doc1.png
to reduce the size using default settings.
For better compression we attempt
optipng -q -o7 doc1.png
To attempt a maximum number of combinations of compression methods we run
optipng -q -zc1-9 -zmk1-9 -zs0-3 -f0-5 doc1.png
This will take a long time but there is no guarantee for better results
than in the previous command.
The optipng documentation does not recommend this option, so we better use
the simple -o7 option from the command above.
We use the -i option to optipng to create an interlaced image:
optipng -q -i1 -o7 doc1.png
Now we embed the bitmap image testlogo.png into the Fig drawing doc2.fig which originally was a copy of doc1.fig.
In mytext.tex we replace
\begin{figure}%
{\centering%
\input{doc1.tex}%
\caption{Test image}%
\label{fig:test-image}%
}
\end{figure}
by
\begin{figure}%
{\centering%
\input{doc2.tex}%
\caption{Test image}%
\label{fig:test-image}%
}
\end{figure}
to use the new drawing.
We run
fig2vect -lpdf.tex doc2.fig doc2.pdf fig2vect -leps.tex doc2.fig doc2.eps fig2vect -ltex doc2.fig doc2.tex
to produce doc2.pdf, doc2.eps and doc2.tex
Now we can use either
latex mytext latex mytext dvips mytext
or
pdflatex mytext pdflatex mytext
to produce either mytext.ps or mytext.pdf.
We use the same drawing as in the previous example.
To create the partial PDF file doc2i.pdf (containing all graphics elements except texts) we run
fig2vect -lpdf.tex doc2.fig doc2i.pdf
We use the same font preamble file preamble.tex as in example 2.
We use
fig2vect -ltex.full doc2.fig -i doc2i.pdf -o preamble.file=preamble.tex doc2.tex pdflatex doc2
to create a standalone PDF file doc2.pdf.

The example file
doc3.fig
uses fill patterns, contains a thick line with arrowheads and references
two bitmap images:
testlogo.png
and
fbt.png.
The fbt.png image shows a clock standing at five before twelve, the image
uses an alpha channel for transparency effects.
To create doc3i.pdf and doc3.tex we run
fig2vect -lpdf.tex doc3.fig doc3i.pdf fig2vect -ltex doc3.fig doc3.tex -idoc3i.pdf
As at least one embedded bitmap image contains an alpha channel fig2vect reminds us to include a line
\ifpdf\pdfpageattr{/Group <</S /Transparency /I true /CS /DeviceRGB>>}\fi
into the main LaTeX documents preamble.
We also need to use the ``ifpdf'' package providing the \idfpdf instruction.
Instead of doc2.tex we use doc3.tex in the \input instruction in
mytext.tex.
Now we can run
pdflatex mytext pdflatex mytext pdflatex mytext
to produce mytext.pdf.
To produce a standalone PDF file doc3.pdf we run
fig2vect -lpdf.tex doc3.fig doc3i.pdf fig2vect -ltex.full doc3.fig doc3.tex -idoc3i.pdf pdflatex doc3 pdflatex doc3
Looking at the PDFs we find differences to the output of other converters:
In this example we use the Fig drawing
doc1.fig
from the first example again.
When using the SVG output driver the Fig drawing must not
contain special text (text with TeX flag set).
Run
fig2vect -lsvg doc1.fig doc1.svg
to produce doc1.svg.
Run
fig2vect -lsvg.gs doc1.fig doc1.svg
to create doc1.svg.
Run
fig2vect -lsvg.web doc1.fig doc1.svg
to create doc1.svg.
I have prepared a workshop how to use jFig and fig2vect together
with Batik and your favorite text editor to create a
partially transparent PNG file for use as web logo.
This is a little beside from the average use of fig2vect to convert
images for use with LaTeX.
Please note: The text and the embedded images use
approx. 1,77 MB.
Click the link to visit the workshop at
./workshop/workshop.html.