# [pstricks] Defining and using Postscript procedures with pstricks?

Denis Girou Denis.Girou at idris.fr
Tue Apr 2 22:05:03 CEST 2002

>>>>> "Remi.Coulom" == Remi Coulom <Remi.Coulom at free.fr> writes:

Remi.Coulom> In a very big automatically generated pstricks figure I made, I have thousands
Remi.Coulom> of pslines that all have the same pstricks options and the same structure:
Remi.Coulom> \psline(x0,y0)(x1,y1)
Remi.Coulom> \psline(x1,y1)(x2,y2)

Remi.Coulom> My problem is that it generates a huge postscript file. What I would like to do
Remi.Coulom> is replace the long code generated by pstricks by more compact postscript. For
Remi.Coulom> instance, it would be nice to have some code like
Remi.Coulom> x0 y0 x1 y1 x2 y2 /MyMacro
Remi.Coulom> in the ps file. I believe it would make my file about 10 times smaller, which
Remi.Coulom> would be very nice.

You are right: using thousands of \psline commands will create very huge
and specially not optimized files.

The alternative is simple: you have rather to use the \lineto macro,
fixing at the beginning the first point with the \moveto macro.
They must be used both inside a \pscustom macro. See pages 32, 36 and 39
of the manual and the following basic example.

On this test, we have a ratio of 8.6.

If you really need to still decrease the resulting file, you can easily
suppress some characters for each point: rather than the PostScript operator
"lineto", use the "L" alias that PSTricks define. You will replace six
characters by only one, which give you 5 x N characters less. On my test,
we got this time your expected ratio of 10...

\documentclass[a4paper]{article}

\usepackage{multido}
\usepackage{pstricks}

\pagestyle{empty}

\begin{document}

% Resulting file: 1300 KB
% \multido{\i=1+1}{5000}{\psline(1,1)(2,2)}

% Resulting file:  150 KB
%\pscustom{%
%  \moveto(1,1)
%  \multido{\i=1+1}{5000}{\lineto(2,2)}}

% Resulting file:  130 KB

% D.G. modification begin - Apr.  2, 2002
% \def\lineto{\pst at onecoor{lineto}}%
% D.G. modification end

\makeatletter
\pscustom{%
\def\lineto{\pst at onecoor{L}}%
\moveto(1,1)
\multido{\i=1+1}{5000}{\lineto(2,2)}}
\makeatother

\end{document}

D.G.



More information about the PSTricks mailing list