[pstricks] ps code redundancy

Denis Girou Denis.Girou at idris.fr
Wed Jun 18 20:41:14 CEST 2003


>>>>> "Matteo.Gattanini" == Matteo Gattanini <matteo.gattanini at libero.it> writes:

    Matteo.Gattanini> I have written a stupid macro (based on pstricks and
    Matteo.Gattanini> pst-node) that draws a closed line that embraces three nodes (I used it
    Matteo.Gattanini> in a recent work to emphasize in the mathematical formulas the terms
    Matteo.Gattanini> that must be simplified). The line is composed by two beziers and three
    Matteo.Gattanini> arcs.

  I have not studied your code, but just looking at the problem I do not
think that this is simple and that this is possible without major efforts to
have a general solution. So, if your code does what you want in the cases you
must manage, rather keep it like it...

  Nevertheless, this is one case (unfrequent!) where I guess that a
lower-level approach is both simplest and more powerful. If you need to manage
not only three nodes but four or more, I can suppose that this is not possible
to extend your code without huge efforts.

  A simple approach is to define nodes at the four corners of the entries that
you must manage (and sometimes other ones), then to draw explicitely the curve
addressing the nodes in the right order. This is of course more painful to
code that in your solution, but rather easy to do, with the advantages to give
you a great control of the result to improve the straightforward behavior, and
to be extensible to more than three nodes.


  P.S. Please, avoid to send HTML coded messages on mailing lists. It will
cause problems to some people (like me, with a mail reader unable to decode
your mail that I must edit and rebuild by hand).

D.G.

\documentclass[a4paper]{article}

\usepackage{pst-node}

\def\DefineNodes#1#2{%
\rnode[tl]{#1_tl}{%
\rnode[tr]{#1_tr}{%
\rnode[bl]{#1_bl}{%
\rnode[br]{#1_br}{#2}}}}}

\SpecialCoor

\pagestyle{empty}

\begin{document}

\Huge

\[ \frac{A_1+\DefineNodes{B}{B_1}+C_1}
        {\DefineNodes{D}{D_1}+E_1+\DefineNodes{F}{F_1}} \]
\psccurve(D_tl)(D_tr)(B_bl)(B_tl)(B_tr)(B_br)
         (F_tl)(F_tr)(F_br)(F_bl)(B_br)(B_bl)(D_br)(D_bl)

\vspace{5mm}
\[ \frac{A_1+\DefineNodes{B}{B_1}+C_1}
        {\DefineNodes{D}{D_1}+E_1+\DefineNodes{F}{F_1}} \]
\psccurve(D_tl)(D_tr)(B_tl)(B_tr)
         (F_tl)(F_tr)(F_br)(F_bl)(B_br)(B_bl)(D_br)(D_bl)

\vspace{5mm}
\[ \frac{A_1+\DefineNodes{B}{B_1}+C_1}
        {\DefineNodes{D}{D_1}+E_1+\DefineNodes{F}{F_1}} \]
\psccurve(D_tl)([angle=90,nodesep=0.2]D_tr)
         ([angle=180,nodesep=0.2]B_bl)(B_tl)(B_tr)([nodesep=0.2]B_br)
         ([angle=90,nodesep=0.2]F_tl)(F_tr)(F_br)(F_bl)
         ([angle=-90,nodesep=0.3]B_br)([angle=-90,nodesep=0.3]B_bl)
         (D_br)(D_bl)

\vspace{5mm}
\[ \frac{\DefineNodes{A}{A_1}+B_1+\DefineNodes{C}{C_1}}
        {D_1+\DefineNodes{E}{E_1}+F_1} \]
\psccurve(A_bl)(A_tl)(A_tr)(A_br)(E_tl)(E_tr)
         (C_bl)(C_tl)(C_tr)(C_br)(E_br)(E_bl)

\vspace{5mm}
\[ \frac{\DefineNodes{A}{A_1}+\DefineNodes{B}{B_1}+C_1}
        {\DefineNodes{D}{D_1}+\DefineNodes{E}{E_1}+\DefineNodes{F}{F_1}} \]
\psccurve[linecolor=red,linestyle=dashed,fillstyle=hlines,hatchcolor=yellow]
         (D_bl)(A_tl)(A_tr)
         ([angle=-90,nodesep=0.1]B_bl)([angle=-90,nodesep=0.1]B_br)
         (F_tr)(F_br)(F_bl)
         ([angle=90,nodesep=0.1]E_tr)([angle=90,nodesep=0.1]E_tl)
         (D_br)(D_bl)

\vspace{5mm}
\[ \frac{\DefineNodes{A}{A_1}+B_1+\DefineNodes{C}{C_1}+D_1}
        {E_1+\DefineNodes{F}{F_1}+G_1+\DefineNodes{H}{H_1}} \]
\psccurve[fillstyle=hlines,hatchcolor=yellow]
  (A_bl)(A_tl)(A_tr)(A_br)
  ([angle=135,nodesep=0.2]F_tl)([angle=45,nodesep=0.2]F_tr)
  (C_bl)(C_tl)(C_tr)(C_br)
  ([angle=135,nodesep=0.2]H_tl)(H_tr)(H_br)(H_bl)
  ([angle=-90,nodesep=0.3]C_br)([angle=-90,nodesep=0.3]C_bl)
  (F_br)(F_bl)([angle=-45,nodesep=0.4]A_br)

\end{document}



More information about the PSTricks mailing list