I need some help!
Isaiah Shavitt
shavitt at chemistry.ohio-state.edu
Tue Sep 7 22:05:44 CEST 1999
-----------------------------------------------------------------------------
This is the PSTricks mailing list, devoted to discussions about computational
graphics in (La)TeX using the PSTricks package from Timothy van Zandt.
For help using this mailing list, see instructions at the end of message.
-----------------------------------------------------------------------------
Thanks to Denis Girou for the prompt response to my request for help.
I did get useful information from the response; I looked in the PS
header file produced by PST and found many definitions that I wanted
to know about.
I have some specific questions which may perhaps be answered easily.
Below I copy a sample macro from my macro collection, on which I can
illustrate some of my problems. This macro draws a line segment
from point (#2,#3) to (#4,#5) and puts an arrow pointing to (#4,#5)
with the CENTER of the arrow (not its tip) #1 of the distance from
(#2,#3) to (#4,#5) (default #1=0.5), preceded by some generic
settings and followed by use examples:
\documentclass[12pt]{book}
\usepackage{pstricks}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{ifthen}
\textwidth 6.5in%
\textheight 9.0in%
\topmargin -0.35in%
\oddsidemargin 0in%
\evensidemargin 0in%
\lineskip=3pt minus 1pt%
\lineskiplimit=2pt%
\parskip 0.2in%
\parindent 0.25in%
\psset{arrowsize=2pt 4,dotsep=2pt}
\newlength{\xl}\newlength{\yl}\newlength{\xc}\newlength{\yc}
\def\ArrowShift{0.15 } % Distance from the center of the arrow to its tip
\SpecialCoor
\newcommand{\dline}[5][0.5]{
\qline(#2,#3)(#4,#5)
\pssetlength{\xl}{#4}\psaddtolength{\xl}{-#2} % x-component of vector
\pssetlength{\yl}{#5}\psaddtolength{\yl}{-#3} % y-component of vector
\pssetlength{\xc}{#2}\psaddtolength{\xc}{#1\xl} % x-coor of arrow center
\pssetlength{\yc}{#3}\psaddtolength{\yc}{#1\yl} % x-coor of arrow center
\psline{->}(\xc,\yc)
(!/Mydict 10 dict def Mydict begin
/Xl #4 #2 sub def /Yl #5 #3 sub def
/Xc #1 #4 mul 1 #1 sub #2 mul add def
/Yc #1 #5 mul 1 #1 sub #3 mul add def
Yl Xl atan dup cos \ArrowShift mul Xc add
exch sin \ArrowShift mul Yc add end)
}
\begin{document}
\begin{center}
\begin{pspicture}(-0.5,0)(1.5,2)
\dline{0}{0}{0}{2}
\dline{1}{2}{1}{0}
\end{pspicture}
\qquad
\begin{pspicture}(-0.5,0)(2.3,2)
\dline{0}{0}{0.8}{2}
\dline{1.8}{2}{1}{0}
\end{pspicture}
\qquad
\begin{pspicture}(-0.5,0)(2.3,2)
\dline{0.8}{0}{0}{2}
\dline{1}{2}{1.8}{0}
\end{pspicture}
\qquad
\begin{pspicture}(-0.5,0)(2.5,2)
\dline{0}{1.5}{2}{1.5}
\dline{2}{0.5}{0}{0.5}
\end{pspicture}
\end{center}
\begin{center}
\begin{pspicture}(-0.5,0)(1.5,2)
\dline[0.7]{0}{0}{0}{2}
\dline[0.3]{1}{2}{1}{0}
\end{pspicture}
\qquad
\begin{pspicture}(-0.5,0)(2.3,2)
\dline[0.7]{0}{0}{0.8}{2}
\dline[0.3]{1.8}{2}{1}{0}
\end{pspicture}
\qquad
\begin{pspicture}(-0.5,0)(2.3,2)
\dline[0.7]{0.8}{0}{0}{2}
\dline[0.3]{1}{2}{1.8}{0}
\end{pspicture}
\qquad
\begin{pspicture}(-0.5,0)(2.5,2)
\dline[0.7]{0}{1.5}{2}{1.5}
\dline[0.3]{2}{0.5}{0}{0.5}
\end{pspicture}
\end{center}
\end{document}
The macro works well, but note the following points:
1. It computes the coordinates of the arrow center twice, first in LaTeX
with the \pssetlength, \psaddtolength commands, giving (\xc,\yc) which
define the starting point in the \psline command, and second in the ps
code to help in the calculation of the arrow tip position. I have not
found a way of using the numerical values of \Xl, \Yl, \Xc, \Yc in the
ps code.
2. I used the LaTeX definition \newcommand{\dline}[5][0.5]{...} instead
of the TeX form \def\dline[#1](#1,#2)(#3,#4){...} because I don't know
how to have an optional argument in the TeX \def. But as a result,
I cannot use the PST convention for specifying coordinate pairs (x,y)
and have to use {x}{y} instead.
Any comments about the above code will be appreciated. I have other
questions, but will leave them to another posting.
--------------------------------------------------------------------------
Isaiah Shavitt
Professor Emeritus
Department of Chemistry Telephone: 614-292-1668
The Ohio State University Fax: 614-292-1685
Columbus, OH 43210-1185 E-mail: shavitt at chemistry.ohio-state.edu
--------------------------------------------------------------------------
-----------------------------------------------------------------------------
The list interface (subscription, information, access to the archives) is on:
http://www.tug.org/cgi-bin/lwgate/pstricks
Otherway to unsubscribe, send mail to pstricks-request at mail.tug.org
with a blank subject and in body the line unsubscribe <email-address>
-----------------------------------------------------------------------------
More information about the PSTricks
mailing list