\documentclass[12pt]{amsart}
\usepackage{amsfonts,a4}
\usepackage[pdftex,pstarrows]{pict2e}
\newcommand{\lfrac}[2]{\mbox{\raisebox{-0.6pt}{{\large$\frac{#1}{#2}$}}}}
\renewcommand{\thefootnote}{\fnsymbol{footnote}}
\setlength{\headsep}{25pt}
\setlength{\oddsidemargin}{10.1mm}
\setlength{\evensidemargin}{9.9mm}
\setlength{\parskip}{1.5ex plus0.5ex minus0.5ex}
\setlength{\parindent}{0em}
\pagestyle{myheadings}

\begin{document}
\markboth{ \;\; \hrulefill \: Herbert M\"oller
\,\hrulefill}
{\hrulefill \; How to Generate \LaTeX\ Picture Environments
Using OpenOffice.org 3 Draw
\,\hrulefill \;\quad }

\vspace*{-15mm}
\begin{center}
\Large{\textbf{How to Generate \LaTeX\ Picture\vspace{2mm} Environments
Using OpenOffice.org 3 Draw}}\\[7mm]
\large{Herbert M\"oller\footnote[1]{\mbox{\rule[0mm]{0mm}{5mm}}\copyright{}
Copyright 2009 by H. M\"oller
(\texttt{mollerh@math.uni-muenster.de}). This documentation may be
distributed and/or modified under the conditions of the \LaTeX\ Project
Public License.}}\\[7mm]
\end{center}

\begin{quote}
	{\small
\textsc{Abstract.} The powerful free drawing software
\texttt{OpenOffice.org 3 Draw} (abbreviated \texttt{OOoDraw} in the
following) and a Perl filter program are used to conveniently create
even complicated figures with the \LaTeX\ \texttt{picture}
environment. Parsing PostScript files exported by \texttt{OOoDraw},
the filter program \texttt{OOopict.pl} generates \LaTeX\ code ready
for use.  Along with other advantages \texttt{OOoDraw} has its own
PostScript translator, which does not depend on the operating systems
supported by \texttt{OpenOffice.org}, namely Linux, Mac OS, Unix, and
Windows. Therefore, \texttt{OOopict.pl} can be applied to PostScript
files of \texttt{OOoDraw} on all these operating systems.  Moreover,
all curves constructed with \texttt{OOoDraw} are represented in the
PostScript files as cubic B\'{e}zier curves which can be directly used
by the package \texttt{pict2e} \cite{GaNi} to produce vector graphics
with \LaTeX.}
\end{quote}

\section{Introduction}

\setlength{\baselineskip}{17pt}
Three years ago a new method for the creation of figures with the \LaTeX\
\texttt{picture} environment was published in the Comprehensive \TeX\
Archive Network (CTAN) \cite{GaP}. It is called ``GaPFilL'' (\emph{Graphics
as PostScript Filtered for \LaTeX}) because it consists of the following
four steps:

\begin{enumerate}
	\item  Generating the figures with a drawing program or	geometry software;

	\item  ``Printing'' or exporting the construction as a PostScript
	file;

	\item  Applying a filter program to the PostScript text;

	\item  Copying the resulting code or parts of it into a \LaTeX\
	document.
\end{enumerate}

Since steps (1) and (2) and the packages used in the \LaTeX\ document
may vary, it is necessary to apply different filter programs. Until now the only
two filter programs \texttt{CABebez.pl} and \texttt{CABpict.pl} in the CTAN have
been developed for the Macintosh version of the geometry software
\texttt{Cabri-g\'{e}om\`{e}tre}$^{\mathrm{TM}}$ \texttt{II}. The first one
requires the macro package \texttt{ebezier} \cite{Ba}, the second additionally uses
the new package \texttt{pict2e} \cite{GaNi}.

The website \emph{Mathkompass} \cite{Mo} contains two filter programs
\texttt{CDTex} and \texttt{CDebez.pl} for use in conjunction with the drawing
software \texttt{ClarisDraw}. They were not published in the CTAN because
\texttt{ClarisDraw} was abandoned when the office program \texttt{AppleWorks}
was released. The first filter is an AppleScript program written in 2002 mainly
for tracing already existing figures with the layer technique of
\texttt{ClarisDraw}. The filter program \texttt{CDebez.pl} is based on
\texttt{CABebez.pl}, but profits from the fact that \texttt{ClarisDraw}
has its own PostScript translator which represents cubic B\'{e}zier curves
directly usable with the package \texttt{ebezier}.

The documentation GaPDoc1.pdf in \cite{GaP} contains the description of the
GaPFilL method by means of the two prototypes \texttt{CABebez.pl} and
\texttt{CABpict.pl}. In the next two sections we will concentrate on those
features of \texttt{OOoDraw} that are useful for the generation of \LaTeX\
figures. Then the application of the perl system with Mac OS and Windows
will be described. The last section contains some explanations of the
characteristics of the filter program \texttt{OOopict.pl} different
from those of \texttt{CABpict.pl}.

\section{The Drawing Program}

\texttt{OOoDraw} is part of the open-source office software suite
\texttt{OpenOffice.org 3} which can be downloaded free of charge
(\texttt{http://www.openoffice.org}, 424 MB). Compared with \texttt{ClarisDraw}
it is even more powerful. Here only some hints are given which are
difficult to find in the online help.

\textbf{Customizing Toolbars}

If \texttt{OOoDraw} is mainly used for generating \LaTeX\ figures,
the entries `Drawing', `Edit Points', `Line and Filling', `Options', `Standard',
and `Color bar'
should be selected in the submenu `Toolbars' of the `View' menu. The
index item `customizing; toolbars' describes how to add or change
buttons in the toolbars. The `Drawing' bar should visibly contain the
buttons `Select', `Line', `Square, Unfilled', `Rectangle, Unfilled',
`Circle, Unfilled', `Ellipse, Unfilled', `Circle Arc', `Arc', `Polygon',
`Dimension Line', `Curve', `Close B\'{e}zier', `Points', and `Position and
Size'. The filter program will not process filled objects or arrows.

\textbf{Drawing Curves}

`Drawing' is the most helpful tool because \texttt{OOoDraw} and the
package \texttt{pict2e} permit to draw arbitrary curves as
vector graphics with \LaTeX. The help entries `curves; drawing' and
`curves; editing' describe how to handle these cubic B\'{e}zier
curves. The filter program \texttt{OOopict.pl} recognises lines
and curves by the respective line endings in the PostScript file.
\textbf{Therefore, it is not possible to continue a curve segment with a line.}

Since the packages \texttt{ebezier} and \texttt{pict2e} don't offer
dotted cubic B\'{e}zier curves, the filter \texttt{OOopict.pl}
approximates these curves by four quadratic B\'{e}zier curves which
can be dotted. \texttt{OOopict.pl} generates quadratic B\'{e}zier curves
from blue or green polygons consisting of two segments. These
curves which represent parabolas are not visible in the slides of
\texttt{OOoDraw}. The fact that each quadratic B\'{e}zier curve is a
special cubic one, may be used to produce visible parabolas
(see \textsc{Figure} 1).\vspace{2mm}

%Figure 1
\begin{figure}[tbh]
  \centering
\setlength{\unitlength}{0.5pt}
\begin{picture}(513,559)(93,-694)
\linethickness{0.8pt}
%Lines, arrows, polygons and quadratic B�zier curves
\put(120.213,-628.379){\line(6553,16382){188.955}}
\put(309.168,-156.006){\line(2943,-9131){167.473}}
\put(246.23,-313.606){\line(12598,-1723){358.448}}
\put(101.605,-613.584){\line(6463,16156){183.89}}
\put(101.605,-613.584){\line(6463,16156){183.89}}
\put(117.567,-627.326){\line(-5,2){23.758}}
\put(306.522,-154.954){\line(-5,2){23.758}}
\put(327.776,-170.802){\line(-1017,-2540){57.873}}
\put(327.776,-170.802){\line(-1017,-2540){57.873}}
\put(311.814,-157.059){\line(167,-67){23.758}}
\put(248.876,-314.289){\line(167,-67){23.758}}
\put(120.213,-628.379){\line(12527,-1660){356.428}}
%Arrows
\linethickness{1.2pt}
\multiput(475.616,-675.611)(2.551,6.236){50}{\line(1,0){2.4}}
\put(604.5,-362.63){\vector(9,22){0}}
\put(99.016,-619.872){\vector(-263,-657){0}}
\put(287.942,-147.641){\vector(113,288){0}}
\put(330.137,-164.542){\vector(200,521){0}}
\put(267.314,-321.573){\vector(-58,-135){0}}
%Cubic B�zier curve
\linethickness{0.8pt}
\cbezier(120.213,-628.379)(246.23,-313.236)(364.992,-330.536)(476.641,-675.611)
%\put(109.515,-648.097){$A$}
\put(109.515,-651){$A$}
\put(244,-340.393){$B$}
\put(344,-351.973){$C$}
\put(470,-696.479){$D$}
\put(311.586,-149.576){$E$}
\put(575,-382){$F$}
\put(171.826,-388.153){$s$}
\put(301,-261){$\lfrac{1}{3}\:\!s$}
\end{picture}
  \caption{Visualization of quadratic B\'{e}zier curves}
  \label{f.1}\vspace{2mm}
\end{figure}

The quadratic B\'{e}zier curve generated by the polygon $AED$ is
exactly the same as the cubic B\'{e}zier curve with the control\vspace{1mm}
points $A,\ B,\ C,$ and $D$, where $|BE|=\lfrac{1}{3}\,|AE|$, and $ADFB$
is a parallelogram. The length\vspace{1mm} of segments can be determined with
the tool `Dimension Line' of \texttt{OOoDraw}.

Some useful drawing aids will be mentioned in the following explanation of how
to close curves or polygons. The direct way is to double-click the
starting point and to observe the number of points shown on the
left-hand side of the `Status Bar' at the bottom of the window. In case it proves 
difficult to snap an object point, you should enlarge the `Snap
range' in the Menu `Grid' of the \texttt{OOoDraw} `Preferences', or 
zoom in with the sliding control on the right-hand side of
the Status Bar. The simplest method is presented by the tool `Close
B\'{e}zier' which closes curves and polygons with a line. As
explained above, in the case of a curve this line must be converted
to a curve segment. This can be done with the tools `Smooth
Transition' or `Symmetric Transition' on the `Edit Points Bar'.

\textbf{Layers and PostScript}

Most drawing programs support layers for the arrangement of elements
on a page. The objects on each layer can be hidden from view, excluded
from printing, or locked. For the GaPFilL method the most important
application is copying pictures by tracing. \texttt{OOoDraw} provides
three predefined layers: Layout, Controls, and Dimension Lines. The
Layout layer is the default workspace. Therefore, when opening a file, 
its contents 
is inserted on this layer. Since \texttt{OOoDraw} accepts the
jpg-format, even photos taken by a digital camera may be traced.

For the traced version you have to add at least one layer by choosing
`Insert - Layer' or by right-clicking the layer tab area at the
bottom. At first, tracing should be done with colours that are
easy to distinguish from the original. Before saving, colours must
be changed according to the information they have to carry described
in the next section.

Since the PostScript translator takes into account the contents of all layers,
even if they are invisible or locked, all but the added
layers must be emptied before exporting to an eps-file via the menu 
`\texttt{File/Export\ldots}'. In the window `\texttt{EPS Export 
Options}' which opens when you click on `\texttt{Save}', you have to 
select No Preview, Level 2, Color, and No Compression.

\section{The Use of Colours}

With the aid of colours additional information is conveyed to the
filter program. \texttt{OOoDraw} offers several colour lists. In
the following we use twelve of the first fourteen colours in the list
`standard.soc'. All colours of the list are shown in the `Color Bar'.
Moving the cursor over any of the coloured squares, the name of the colour appears.
Since most of the names of the same colours in the list `html.soc' are
more customary, they are also used internally in the filter program. These 
names are added in parentheses to the ``standard names'' in the table at the 
end of this section.\vspace{-1mm}

\setlength{\baselineskip}{16pt}
There are three methods to colour a line or curve. A colour may be
preselected by clicking on the corresponding area in the menu `Line
color' of the toolbar `Line and Filling'. The colour of a selected
line or curve can be changed by right-clicking on the area of the new
colour in the `Color Bar'. Finally, dragging a colour of the `Color Bar' to an arbitrary
line or curve changes its colour if it is different.\vspace{-1mm}

In the following an ``object'' may be a line, a polygon, a circle, an
arc of a circle, an ellipse, an arc of an ellipse, or a cubic B\'{e}zier curve.
\vspace{-2mm}

\begin{list}{$\bullet$}{
	\setlength{\labelwidth}{3mm}
	\setlength{\leftmargin}{7mm}
	}
	\item  \emph{Unbroken objects} are drawn with the default colour
	\fbox{black}.\vspace{1mm}
	
	\item  \emph{Dotted objects} are obtained by using the colour \fbox{light
	green}.\vspace{1mm}
	
	\item \emph{Unbroken arrows} must be drawn as a \fbox{turquoise} line.
	A \fbox{blue} line generates an \emph{arrow with a dotted shank}.
	\vspace{1mm}

	\item  \emph{Unbroken quadratic B\'ezier curves} are entered as\vspace{1mm}
	\fbox{light blue} polygons with two segments. A \emph{dotted
	parabola} results from \fbox{green} polygons.\vspace{1mm}

	\item  \emph{Text or formula positions} are defined by using\vspace{1mm}
	lines coloured in \fbox{light cyan}. For the bounding box to be calculated
	correctly, the marking line should approximately be the diagonal of the 
	smallest rectangle
	enclosing the text or formula beginning at the lower left corner. In the \LaTeX\ output a serial
	number will be written at the position of the starting point.\vspace{1mm}

	\item  The remaining five colours are used for \emph{filling,
	hatching} or \emph{dotting} areas bordered by \emph{polygons.} For this purpose
	the filter program splits the polygon area into triangles which have
	the starting point of the polygon as a common corner. To avoid
	overlapping, the given area must be devided into polygons in such a way that 
	for each polygon the triangles arising from connecting the starting
	point with the other corners have no more than one side in common with
	the other triangles (see \cite{GaP}).\vspace{1mm}

  \hspace{-4mm}\fbox{Light red} \emph{polygons} will be \emph{filled} without
	boundary. For \emph{hatching with visible boundary lines} the colour
	\fbox{red} must be chosen for the polygon;\vspace{1mm} \emph{without boundary
	lines} the colour \fbox{brown}. If the polygon is \fbox{magenta}-coloured, 
	its area will be \emph{dotted with visible boundary 
	lines};\vspace{0.5mm}
	using the colour \fbox{light magenta} an area can be \emph{dotted without 
	boundary lines}. The previous assignments of colours are summarized in the
	following table.\vspace{1mm}

	\item  All \emph{drawing elements} coloured in\vspace{0.5mm} \fbox{other
	colours} may serve as \emph{drawing aids} because they are ignored by the
	filter program.

\end{list}
\begin{table}[h]
	\centering
		\begin{tabular}{|c|c|}
			\hline
			\rule[-2mm]{0mm}{6mm} Type & Colour  \\
			\hline
			\rule[0mm]{0mm}{4mm} unbroken object & black (black)  \\
			dotted object & light green (lime)  \\
			unbroken arrow & turquoise (teal)  \\
			dotted arrow & blue (navy)  \\
			unbroken quad. B\'ezier curve & light blue (blue)  \\
			dotted quad. B\'ezier curve & green (green)  \\
			text marker & light cyan (cyan) \\
			filled without border & light red (red) \\
			hatched with border & red (maroon)  \\
			hatched without border & brown (olive) \\
			dotted with border & magenta (purple)  \\
			\rule[-2mm]{0mm}{4mm} dotted without border & light magenta (magenta)  \\
			\hline			
		\end{tabular}
\end{table}\vspace{-3mm}

\section{Application of the Perl system}\vspace{-1mm}

To apply the filter program \texttt{OOopict.pl}, you
need the Perl system and a text editor able to run a
script or a command line while a text file is open in its primary window.

\textbf{Mac OS X}

The operating system provides the native Perl system. As a suitable
source editor \texttt{TextWrangler\ 2.3} is available free of charge
(\texttt{http://www.barebones.com/\linebreak
products/textwrangler}). It is a general purpose text editor developed as
a by-product of the professional HTML and text editor
\texttt{BBEdit}$^{\mathrm{TM}}$ \texttt{9} of Bare Bones Software, Inc.
\texttt{TextWrangler} works directly with the Perl system as a Unix
scripting environment. Therefore, it is accessed via the menu `\verb|#!|'
which gets its ``name'' from the beginning of the first line in each Unix 
script.

\texttt{OOopict.pl} must be placed in the subdirectory `Unix Filters'
which is opened by the command `Open Filters Folder' in the submenu
`Unix Filters' of the menu `\verb|#!|'. With a \texttt{OOoDraw} PostScript 
file open in the primary window, you only have to select
\texttt{OOopict.pl} from the submenu `Unix Filters'. As if by magic,
the PostScript text will then be replaced by the corresponding \LaTeX\
program.

\textbf{Windows and other Operating Systems}

\setlength{\baselineskip}{17pt}
The complete, ready-to-install Perl distribution \texttt{ActivePerl}
for Windows, Linux, Mac OS X, Solaris, AIX and HP-UX is available for free
from ActiveState Software, Inc.
(\texttt{http://www.activestate.com/activeperl}). This company also offers
the free and open source editor \texttt{Komodo Edit 5.1}
(\texttt{http://www.active-\linebreak
state.com/komodo\_edit}) based on the
professional \texttt{Komodo}$^{\mathrm{TM}}$ \texttt{IDE}.

After \texttt{ActivePerl} is installed, \texttt{OOopict.pl} can be saved,
for example, in the directory `\verb|C:\Perl\eg\|'. Having
opened an \texttt{OOoDraw} PostScript file for the first time and
typed `ctrl-A', you can select `Run Command' in the menu `Tools'.
In the command line you will have to enter `\verb|C:\Perl\eg\OOopict.pl|'
(or the path of the directory you have chosen for \texttt{OOopict.pl}).
Before running the command, you must activate the checkbox `Pass
selection as input'. If you also activate the third checkbox, the command
will be stored in the toolbox from where you can run it by double-clicking
its name.

\section{The filter program \texttt{OOopict.pl}}

The Perl filter program \texttt{OOopict.pl} has got 701 lines not including
comment lines beginning with `\#' and the lines containing closing
braces `\}'. The following line numbers don't belong to
the program itself.

\begin{small}
\begin{verbatim}
   1 #!/usr/bin/perl -w
   2 # OOopict.pl
\end{verbatim}
\vspace{-4mm}
\texttt{\mbox{\quad} 3 \# (c) Copyright 2009 H. Moeller
(mollerh@math.uni-muenster.de).\\
\mbox{\quad} 4 \# Version 1.3 for OpenOffice.org 3 Draw with Perl 5.8,\\
\mbox{\hspace{12mm}} and with the LaTeX-package 'pict2e' from 2008\\
\mbox{\hspace{12mm}} or with 'pict2e' (2003) and 'ebezier'.\\[-1mm]
\vspace{-3mm}\mbox{\quad} \ldots}
\begin{verbatim}
  14 # If your package pict2e is from 2008 or later (else $pictnew = 0):
  15 $pictnew = 1;
\end{verbatim}
\end{small}

Since there are two versions of \texttt{pict2e}, the flag
\verb|$pictnew| of line 15 is used to switch from the environment of
\texttt{CABpict.pl} to the new one which doesn't need the package
\texttt{ebezier}, because the 2008 version of \texttt{pict2e} can handle
dotted quadratic B\'{e}zier curves. Furthermore, the absolute
value of the bound of the slope components is increased from 1000 to
16383 which, in \texttt{OOopict.pl}, is also incorporated into the flag
\verb|$pictnew|.

Usually the file \texttt{pict2e.sty} is located in a subdirectory
`\texttt{\ldots/tex/latex/}'. If you don't find it in order to look for the
version date, you can run a test with a \LaTeX\ program containing
\verb|\usepackage[pdftex]{pict2e}| in the preamble and a line
\vspace{-1mm}
\[\verb|\put(0,0){\line(1001,1000){10}}|\]\\[-6mm]
in the document. If you have the old version you will get an error message.

If you know where the file \texttt{pict2e.sty} is located, you can
replace it downloading the directory
\texttt{pict2e} from \cite{GaNi}, running (or opening) the file
\texttt{pict2e.dtx} (or \texttt{pict2e.ins}) with \LaTeX\ , and moving the
resulting \texttt{.sty} file to the desired location.\vspace{-1mm}

\begin{small}
\begin{verbatim}
  46 @lines = <>;
  47 do {
  48   $_ = $lines[$i++];
  49   if ((/ l  /o) or (/ ct /o) or (/ p[cs ][\se]/o)) {
  50     s/\d+ lw \d+ lj //go;
  51     s/ m //go;
  52     if (/ c /o) {
  53       s/(\d\.\d+) (\d\.\d+) (\d\.\d+) c //o;
  54       $c=$1.$2.$3." ";
  55     }
  56     $t="";
  57     $l="";
  58     $tflag=0;
  59     $fflag=0;
  60     while ($_ !~ (/p[cs ][\se]/o)) {
\end{verbatim}
\vspace{-3mm}
\texttt{\vspace{-3mm}\mbox{\quad} \ldots}
\begin{verbatim}
  88     if ($tflag and $fflag) {
  89       $curve[++$#curve] = $c.$t;
  90     }
  91     elsif ($fflag) {
  92       $polygon[++$#polygon] = $c.$l;
  93     }
  94   }
  95 }
  96 until $i == $#lines;
\end{verbatim}		
\end{small}

There are three difficulties in filtering the text lines for \LaTeX.
i) If successive elements (lines, polygons, curves) have the same
colour, only the first one carries the colour data (lines 52 to 54).
ii) Long data lines are broken by the PostScript translator
before getting to the characterizing ending (`\texttt{ps}', `\texttt{pc}'
or `\texttt{ef}'). Therefore, the successive lines have to be
assembled in the strings `\verb|$l|' and `\verb|$t|' according to the
data separators, namely `\texttt{l}' (`\texttt{lineto}') for lines
and `\texttt{ct}' (`\texttt{curveto}') for curves. iii) Whether an
object is to be filled, can only be recognized by the ending
`\texttt{ef}'. Here, the flag `\verb|$fflag|' is
used to decide which strings have to be saved in the arrays
`\verb|@curve|' or `\verb|@polygon|' (lines 88 to 92).

Since \texttt{OOopict.pl} only needs two arrays for collecting the
data strings (instead of five in \texttt{CABpict.pl}), there are at
most 130 lines for calling the appropriate subprocedures (less than
half as many as in \texttt{CABpict.pl}). About 120 lines and the
subprocedure `\texttt{arc}' could be eliminated, because the
PostScript translator of \texttt{OOoDraw} represents all curves as
cubic B\'{e}zier curves.

Some of the remaining eight subprocedures differ from those in
\texttt{CABpict.pl}.
The subprocedure `\texttt{best}' has been corrected, because in the earlier
version the fact that the greatest integer of Perl is
given by $2^{31}-1$ was overlooked. Furthermore, an entry for the upper bound of the
approximating numerator and denominator has been introduced.

In the subprocedure `\texttt{lin}' dotted lines are now generated with
the `\verb|\multiput|' command of \LaTeX. Depending on the flag
\verb|$pictnew| there are two ways to produce dotted quadratic
B\'{e}zier curves with the subprocedure `\texttt{qbez}' and dotted
cubic B\'{e}zier curves with `\texttt{cbez}'. As mentioned above, the
latter is done by approximating cubic B\'{e}zier curves with four quadratic
B\'{e}zier curves, but the result is only satisfying if the cubic
B\'{e}zier curve doesn't contain points of inflection or
self-intersection. This can always be achieved by cutting the cubic
B\'{e}zier curve into suitable segments with \texttt{OOoDraw}.

\begin{thebibliography}{9}

	\setlength{\baselineskip}{18pt}
	\bibitem{Ba}  Bachmaier, Gerhard A.: Using \texttt{ebezier}.
	Package in CTAN:\texttt{/macros/latex/contrib/ebe-} \texttt{zier}, 2002.
	
	\bibitem{GaNi}  G\"a{\ss}lein, Hubert, Niepraschk, Rolf and
	Tkadlec, Josef: The \texttt{pict2e}-package. Package in
	CTAN:\texttt{/macros/latex/contrib/pict2e/pict2e.dtx},
	2008.

	\bibitem{GaP}  M\"oller, Herbert: How to generate \LaTeX\
  \texttt{picture} environments using the GaPFilL method.
  CTAN:\texttt{/graphics/gapfill/GaPDoc1.pdf}, 2006.

	\bibitem{Mo}  M\"oller, Herbert: \emph{Mathkompass}
	(\texttt{http://wwwmath.uni-muenster.de/u/mollerh}).

\end{thebibliography}
\end{document}

.
