summaryrefslogtreecommitdiff
path: root/graphics/mathspic
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /graphics/mathspic
Initial commit
Diffstat (limited to 'graphics/mathspic')
-rw-r--r--graphics/mathspic/dos/mpicm01.m24
-rw-r--r--graphics/mathspic/dos/mpicm01.pic44
-rw-r--r--graphics/mathspic/dos/mpicm02a.m14
-rw-r--r--graphics/mathspic/dos/mpicm02a.pic28
-rw-r--r--graphics/mathspic/dos/mpicm02b.m14
-rw-r--r--graphics/mathspic/dos/mpicm02b.pic28
-rw-r--r--graphics/mathspic/dos/mpicm03.m30
-rw-r--r--graphics/mathspic/dos/mpicm03.pic54
-rw-r--r--graphics/mathspic/dos/mpicm04.m32
-rw-r--r--graphics/mathspic/dos/mpicm04.pic59
-rw-r--r--graphics/mathspic/dos/mpicm05.m39
-rw-r--r--graphics/mathspic/dos/mpicm05.pic77
-rw-r--r--graphics/mathspic/dos/mpicm06.m72
-rw-r--r--graphics/mathspic/dos/mpicm06.pic113
-rw-r--r--graphics/mathspic/dos/mpicm07.m23
-rw-r--r--graphics/mathspic/dos/mpicm07.pic47
-rw-r--r--graphics/mathspic/dos/mpicm08a.m25
-rw-r--r--graphics/mathspic/dos/mpicm08a.pic44
-rw-r--r--graphics/mathspic/dos/mpicm08b.m30
-rw-r--r--graphics/mathspic/dos/mpicm08b.pic53
-rw-r--r--graphics/mathspic/dos/mpicm09.m28
-rw-r--r--graphics/mathspic/dos/mpicm09.pic52
-rw-r--r--graphics/mathspic/dos/mpicm10.m33
-rw-r--r--graphics/mathspic/dos/mpicm10.pic58
-rw-r--r--graphics/mathspic/dos/mpicm11.m65
-rw-r--r--graphics/mathspic/dos/mpicm11.pic119
-rw-r--r--graphics/mathspic/dos/mpicm12.m52
-rw-r--r--graphics/mathspic/dos/mpicm12.pic96
-rw-r--r--graphics/mathspic/dos/mpicm13.dat16
-rw-r--r--graphics/mathspic/dos/mpicm13.m22
-rw-r--r--graphics/mathspic/dos/mpicm13.pic756
-rw-r--r--graphics/mathspic/dos/mpicm14.dat30
-rw-r--r--graphics/mathspic/dos/mpicm14.m27
-rw-r--r--graphics/mathspic/dos/mpicm14.pic79
-rw-r--r--graphics/mathspic/dos/mpicm15.m35
-rw-r--r--graphics/mathspic/dos/mpicm15.pic68
-rw-r--r--graphics/mathspic/dos/mpicm16.m84
-rw-r--r--graphics/mathspic/dos/mpicm16.pic176
-rw-r--r--graphics/mathspic/dos/mpicm21.dvibin0 -> 539712 bytes
-rw-r--r--graphics/mathspic/dos/mpicm21.pdfbin0 -> 603558 bytes
-rw-r--r--graphics/mathspic/dos/mpicm21.tex4373
-rw-r--r--graphics/mathspic/dos/readme21.txt121
-rw-r--r--graphics/mathspic/dos/show.combin0 -> 1485 bytes
-rw-r--r--graphics/mathspic/perl/HELP.txt598
-rw-r--r--graphics/mathspic/perl/MATHSPIC.BAT2
-rw-r--r--graphics/mathspic/perl/README.txt115
-rw-r--r--graphics/mathspic/perl/grabtexdata.tex44
-rw-r--r--graphics/mathspic/perl/mathsPICmanual.pdfbin0 -> 686541 bytes
-rw-r--r--graphics/mathspic/perl/mathspic.1576
-rw-r--r--graphics/mathspic/perl/mathspic.lib13
-rw-r--r--graphics/mathspic/perl/mathspic.sh14
-rw-r--r--graphics/mathspic/perl/mathspic.sty41
-rw-r--r--graphics/mathspic/perl/mathspic113.pl3336
-rw-r--r--graphics/mathspic/perl/sourcecode113.html5128
-rw-r--r--graphics/mathspic/perl/sourcecode113.nw5021
-rw-r--r--graphics/mathspic/perl/sourcecode113.pdfbin0 -> 2864043 bytes
56 files changed, 22028 insertions, 0 deletions
diff --git a/graphics/mathspic/dos/mpicm01.m b/graphics/mathspic/dos/mpicm01.m
new file mode 100644
index 0000000000..5cc6990e10
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm01.m
@@ -0,0 +1,24 @@
+%% mPICm01.m (figure 1)
+%% mathsPIC (smallTriangle with incircle)
+%%-------------------
+\documentclass[a4paper]{article}
+\usepackage{pictexwd}
+\begin{document}
+%%---------------------
+pictex{\beginpicture}
+paper{units(cm) xrange(0,5), yrange(0,2.5)}
+point(A){0,0}
+point(B){A, polar(5, 10 deg)}
+point(C){A, polar(3, 50 deg)}
+drawpoint(ABC)
+drawTriangle(ABC)
+drawIncircle(ABC)
+variable(d){0.5}
+text($A$){A, shift(-d,0)}
+text($B$){B, shift(d,0)}
+text($C$){C, shift(-d,0)}
+pictex{\endpicture}
+%%-----------------
+\end{document}
+
+
diff --git a/graphics/mathspic/dos/mpicm01.pic b/graphics/mathspic/dos/mpicm01.pic
new file mode 100644
index 0000000000..d1a0274207
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm01.pic
@@ -0,0 +1,44 @@
+%* -------------------------------------------
+%* mathsPIC 2.1
+%* Copyright (c) RWD Nickalls 1999-2000
+%* Email: dicknickalls@compuserve.com
+%* Date (m/d/y) : 11-05-2000 20:46:50
+%* Command Line: /b/s MPICM01.M
+%* Input Filename: MPICM01.M
+%* Output Filename: MPICM01.MT
+%* -------------------------------------------
+%% mPICm01.m (figure 1)
+%% mathsPIC (smallTriangle with incircle)
+%%-------------------
+%\documentclass[a4paper]{article}
+%\usepackage{pictexwd}
+%\begin{document}
+%%---------------------
+\beginpicture
+%% paper{units(cm)xrange(0,5),yrange(0,2.5)}
+\setcoordinatesystem units < 1cm, 1cm>
+\setplotarea x from 0 to 5, y from 0 to 2.5
+%% point(A){0,0} ( 0 , 0 )
+%% point(B){A,polar(5,10deg)} ( 4.924039 , .8682409 )
+%% point(C){A,polar(3,50deg)} ( 1.928363 , 2.298133 )
+%% drawpoint(ABC)
+\put {$\bullet$} at 0 0 %% A
+\put {$\bullet$} at 4.924039 .8682409 %% B
+\put {$\bullet$} at 1.928363 2.298133 %% C
+%% drawTriangle(ABC)
+\plot 0 0 4.924039 .8682409 / %% AB
+\plot 4.924039 .8682409 1.928363 2.298133 / %% BC
+\plot 1.928363 2.298133 0 0 / %% CA
+%% drawIncircle(ABC)
+%% Incircle centre = 2.156815 , 1.245238 ; TrueRadius = .8517928 [ .8517928 ]
+\circulararc 360 degrees from 3.008607 1.245238 center at 2.156815 1.245238
+%% variable(d){0.5} ( .5 )
+%% text($A$){A,shift(-d,0)}
+\put {$A$} at -.5 0
+%% text($B$){B,shift(d,0)}
+\put {$B$} at 5.424039 .8682409
+%% text($C$){C,shift(-d,0)}
+\put {$C$} at 1.428363 2.298133
+\endpicture
+%%-----------------
+%\end{document}
diff --git a/graphics/mathspic/dos/mpicm02a.m b/graphics/mathspic/dos/mpicm02a.m
new file mode 100644
index 0000000000..729ad3a132
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm02a.m
@@ -0,0 +1,14 @@
+%% mPICm02a.m (figure 2a)
+%% mathsPIC axes
+%%-------------
+\documentclass[a4paper]{article}
+\usepackage{pictexwd}
+\begin{document}
+%%---------------
+\beginpicture
+%% setup the plot area
+paper{units(mm),xrange(0,50),yrange(0,50),axes(LRTB),ticks(10,10)}
+\endpicture
+%%-------------------
+\end{document}
+
diff --git a/graphics/mathspic/dos/mpicm02a.pic b/graphics/mathspic/dos/mpicm02a.pic
new file mode 100644
index 0000000000..7214fd2539
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm02a.pic
@@ -0,0 +1,28 @@
+%* -------------------------------------------
+%* mathsPIC 2.1
+%* Copyright (c) RWD Nickalls 1999-2000
+%* Email: dicknickalls@compuserve.com
+%* Date (m/d/y) : 11-05-2000 20:51:54
+%* Command Line: /b/s MPICM02A.M
+%* Input Filename: MPICM02A.M
+%* Output Filename: MPICM02A.MT
+%* -------------------------------------------
+%% mPICm02a.m (figure 2a)
+%% mathsPIC axes
+%%-------------
+%\documentclass[a4paper]{article}
+%\usepackage{pictexwd}
+%\begin{document}
+%%---------------
+\beginpicture
+%% setup the plot area
+%% paper{units(mm),xrange(0,50),yrange(0,50),axes(LRTB),ticks(10,10)}
+\setcoordinatesystem units < 1mm, 1mm>
+\setplotarea x from 0 to 50, y from 0 to 50
+\axis left ticks numbered from 0 to 50 by 10 /
+\axis right ticks numbered from 0 to 50 by 10 /
+\axis top ticks numbered from 0 to 50 by 10 /
+\axis bottom ticks numbered from 0 to 50 by 10 /
+\endpicture
+%%-------------------
+%\end{document}
diff --git a/graphics/mathspic/dos/mpicm02b.m b/graphics/mathspic/dos/mpicm02b.m
new file mode 100644
index 0000000000..40fad4cbb8
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm02b.m
@@ -0,0 +1,14 @@
+%% mPICm02b.m (figure 2b)
+%% mathsPIC axes
+%%-------------
+\documentclass[a4paper]{article}
+\usepackage{pictexwd}
+\begin{document}
+%%---------------
+\beginpicture
+%% setup the plot area
+paper{units(cm),xrange(-2,3),yrange(-2,3),axes(XY),ticks(1,1)}
+\endpicture
+%%-------------------
+\end{document}
+
diff --git a/graphics/mathspic/dos/mpicm02b.pic b/graphics/mathspic/dos/mpicm02b.pic
new file mode 100644
index 0000000000..32cc1fd366
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm02b.pic
@@ -0,0 +1,28 @@
+%* -------------------------------------------
+%* mathsPIC 2.1
+%* Copyright (c) RWD Nickalls 1999-2000
+%* Email: dicknickalls@compuserve.com
+%* Date (m/d/y) : 11-05-2000 20:53:48
+%* Command Line: /b/s MPICM02B.M
+%* Input Filename: MPICM02B.M
+%* Output Filename: MPICM02B.MT
+%* -------------------------------------------
+%% mPICm02b.m (figure 2b)
+%% mathsPIC axes
+%%-------------
+%\documentclass[a4paper]{article}
+%\usepackage{pictexwd}
+%\begin{document}
+%%---------------
+\beginpicture
+%% setup the plot area
+%% paper{units(cm),xrange(-2,3),yrange(-2,3),axes(XY),ticks(1,1)}
+\setcoordinatesystem units < 1cm, 1cm>
+\setplotarea x from -2 to 3, y from -2 to 3
+\axis left shiftedto x=0 ticks numbered from -2 to -1 by 1
+ from 1 to 3 by 1 /
+\axis bottom shiftedto y=0 ticks numbered from -2 to -1 by 1
+ from 1 to 3 by 1 /
+\endpicture
+%%-------------------
+%\end{document}
diff --git a/graphics/mathspic/dos/mpicm03.m b/graphics/mathspic/dos/mpicm03.m
new file mode 100644
index 0000000000..846d2506b2
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm03.m
@@ -0,0 +1,30 @@
+%% mpicm03.m (Figure 3)
+\documentclass[a4paper]{article}
+\usepackage{pictexwd}
+\begin{document}
+%%-----------
+\beginpicture
+paper{units(cm),xrange(0,6),yrange(0,3),axes(LBT*R*),ticks(1,1)}
+point(P){4,2}[$\odot$]
+point(B){2,0.5}
+point(S){1,2}
+drawPoints(PBS)
+\setdashes
+\inboundscheckon %% restrict circles to drawing area
+drawcircle(P,1)
+drawcircle(P,2)
+\setsolid
+point*(P){P}[,1] %% set line-free radius of P to 1cm
+drawArrow(BP) %% draw arrow from B (below)
+point*(P){P}[,2] %% change line-free radius of P to 2cm
+drawArrow(SP) %% draw arrow from S (side)
+text($S$){S, shift(-0.4,0)}
+text($B$){B, shift(-0.4,0)}
+text(\textsc{p}){P, shift(0.3,0)}
+\newcommand{\textbox}{\fbox{text\hspace{17mm}box}}%
+text(\textbox){P}
+\endpicture
+%%--------
+\end{document}
+
+
diff --git a/graphics/mathspic/dos/mpicm03.pic b/graphics/mathspic/dos/mpicm03.pic
new file mode 100644
index 0000000000..bd7a056a8e
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm03.pic
@@ -0,0 +1,54 @@
+%* -------------------------------------------
+%* mathsPIC 2.1
+%* Copyright (c) RWD Nickalls 1999-2000
+%* Email: dicknickalls@compuserve.com
+%* Date (m/d/y) : 11-05-2000 20:55:19
+%* Command Line: /b/s MPICM03.M
+%* Input Filename: MPICM03.M
+%* Output Filename: MPICM03.MT
+%* -------------------------------------------
+%% mpicm03.m (Figure 3)
+%\documentclass[a4paper]{article}
+%\usepackage{pictexwd}
+%\begin{document}
+%%-----------
+\beginpicture
+%% paper{units(cm),xrange(0,6),yrange(0,3),axes(LBT*R*),ticks(1,1)}
+\setcoordinatesystem units < 1cm, 1cm>
+\setplotarea x from 0 to 6, y from 0 to 3
+\axis left ticks numbered from 0 to 3 by 1 /
+\axis right /
+\axis top /
+\axis bottom ticks numbered from 0 to 6 by 1 /
+%% point(P){4,2}[$\odot$] ( 4 , 2 )
+%% point(B){2,0.5} ( 2 , .5 )
+%% point(S){1,2} ( 1 , 2 )
+%% drawPoints(PBS)
+\put {$\odot$} at 4 2 %% P
+\put {$\bullet$} at 2 .5 %% B
+\put {$\bullet$} at 1 2 %% S
+\setdashes
+\inboundscheckon %% restrict circles to drawing area
+%% drawcircle(P,1)
+\circulararc 360 degrees from 5 2 center at 4 2
+%% drawcircle(P,2)
+\circulararc 360 degrees from 6 2 center at 4 2
+\setsolid
+%% point*(P){P}[,1] ( 4 , 2 ) %% set line-free radius of P to 1cm
+%% drawArrow(BP) %% draw arrow from B (below)
+\arrow < 2mm> [ .2679492, .7279404] from 2 .5 to 3.2 1.4
+%% point*(P){P}[,2] ( 4 , 2 ) %% change line-free radius of P to 2cm
+%% drawArrow(SP) %% draw arrow from S (side)
+\arrow < 2mm> [ .2679492, .7279404] from 1 2 to 2 2
+%% text($S$){S,shift(-0.4,0)}
+\put {$S$} at .6 2
+%% text($B$){B,shift(-0.4,0)}
+\put {$B$} at 1.6 .5
+%% text(\textsc{p}){P,shift(0.3,0)}
+\put {\textsc{p}} at 4.3 2
+\newcommand{\textbox}{\fbox{text\hspace{17mm}box}}%
+%% text(\textbox){P}
+\put {\textbox} at 4 2
+\endpicture
+%%--------
+%\end{document}
diff --git a/graphics/mathspic/dos/mpicm04.m b/graphics/mathspic/dos/mpicm04.m
new file mode 100644
index 0000000000..f9454611fb
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm04.m
@@ -0,0 +1,32 @@
+%% mPICm04.m (figure 4)
+%% mathsPIC triangle
+\documentclass[a4paper]{article}
+\usepackage{pictexwd}
+\begin{document}
+%%-------------------
+\beginpicture
+\setdashes
+paper{units(mm),xrange(0,70),yrange(0,50),axes(LRTB),ticks(10,10)}
+\setsolid
+point(A){10,10}[$\odot$,1.2] %% anchor point
+point(B){A, polar(40, 50 deg)}[$\odot$,1.2]
+point(C){A, polar(50, 10 deg)}[$\odot$,1.2]
+point(D){perpendicular(B,AC)}
+drawPoints(ABCD)
+drawLine(ABCA)
+\setdashes
+drawLine(BD)
+\setsolid
+drawRightangle(BDC,2.5)
+text($B$){B, shift(-1,4)}
+text($A$){A, shift(-4,-2)}
+text($C$){C, shift(4,-1)}
+text($D$){D, shift(1,-4)}
+showLength(BD)
+showLength(AC)
+showArea(ABC)
+\endpicture
+%%------------------
+\end{document}
+
+
diff --git a/graphics/mathspic/dos/mpicm04.pic b/graphics/mathspic/dos/mpicm04.pic
new file mode 100644
index 0000000000..dade5ea84b
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm04.pic
@@ -0,0 +1,59 @@
+%* -------------------------------------------
+%* mathsPIC 2.1
+%* Copyright (c) RWD Nickalls 1999-2000
+%* Email: dicknickalls@compuserve.com
+%* Date (m/d/y) : 11-05-2000 20:56:58
+%* Command Line: /b/s MPICM04.M
+%* Input Filename: MPICM04.M
+%* Output Filename: MPICM04.MT
+%* -------------------------------------------
+%% mPICm04.m (figure 4)
+%% mathsPIC triangle
+%\documentclass[a4paper]{article}
+%\usepackage{pictexwd}
+%\begin{document}
+%%-------------------
+\beginpicture
+\setdashes
+%% paper{units(mm),xrange(0,70),yrange(0,50),axes(LRTB),ticks(10,10)}
+\setcoordinatesystem units < 1mm, 1mm>
+\setplotarea x from 0 to 70, y from 0 to 50
+\axis left ticks numbered from 0 to 50 by 10 /
+\axis right ticks numbered from 0 to 50 by 10 /
+\axis top ticks numbered from 0 to 70 by 10 /
+\axis bottom ticks numbered from 0 to 70 by 10 /
+\setsolid
+%% point(A){10,10}[$\odot$,1.2] ( 10 , 10 ) %% anchor point
+%% point(B){A,polar(40,50deg)}[$\odot$,1.2] ( 35.7115 , 40.64178 )
+%% point(C){A,polar(50,10deg)}[$\odot$,1.2] ( 59.24039 , 18.68241 )
+%% point(D){perpendicular(B,AC)} ( 40.17626 , 15.32089 )
+%% drawPoints(ABCD)
+\put {$\odot$} at 10 10 %% A
+\put {$\odot$} at 35.7115 40.64178 %% B
+\put {$\odot$} at 59.24039 18.68241 %% C
+\put {$\bullet$} at 40.17626 15.32089 %% D
+%% drawLine(ABCA)
+\plot 10.77135 10.91925 34.94016 39.72252 / %% AB
+\plot 36.58879 39.82301 58.3631 19.50117 / %% BC
+\plot 58.05862 18.47403 11.18177 10.20838 / %% CA
+\setdashes
+%% drawLine(BD)
+\plot 35.91988 39.46001 40.17626 15.32089 / %% BD
+\setsolid
+%% drawRightangle(BDC,2.5)
+\plot 42.63828 15.75501 42.20416 18.21703 /
+\plot 39.74214 17.78291 42.20416 18.21703 /
+%% text($B$){B,shift(-1,4)}
+\put {$B$} at 34.7115 44.64178
+%% text($A$){A,shift(-4,-2)}
+\put {$A$} at 6 8
+%% text($C$){C,shift(4,-1)}
+\put {$C$} at 63.24039 17.68241
+%% text($D$){D,shift(1,-4)}
+\put {$D$} at 41.17626 11.32089
+%% showLength(BD) 25.7115
+%% showLength(AC) 50
+%% showArea(ABC) 642.7875
+\endpicture
+%%------------------
+%\end{document}
diff --git a/graphics/mathspic/dos/mpicm05.m b/graphics/mathspic/dos/mpicm05.m
new file mode 100644
index 0000000000..ae3c9278cb
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm05.m
@@ -0,0 +1,39 @@
+%% mPICm05.m (figure 5)
+%% mathsPIC rectangular box
+\documentclass[a4paper]{article}
+\usepackage{pictexwd}
+\begin{document}
+%%----------------------
+\beginpicture
+paper{units(mm), xrange(0,50), yrange(0,62)}
+variable(s){20} % Sides front & back
+variable(L){34} % Length
+variable(a2){56.6} % Angle degrees
+\def\fancydashes{\setdashpattern <6pt, 2pt, 1pt, 2pt>}
+point(A){5,7}
+point(B){A, polar(s,90)}
+point(C){B, polar(s,0)}
+point(D){A, polar(s,0 )}
+point(H){A, polar(L,a2 deg)}
+point(G){B, polar(L,a2 deg)}
+point(F){C, polar(L,a2 deg)}
+point(E){D, polar(L,a2 deg)}
+drawpoints(ABCDEFGH)
+\linethickness=2pt \setsolid
+drawlines(ABCDA)
+\setdashes
+drawlines(HGFEH)
+\linethickness=0.4pt \fancydashes
+drawlines(AH, BG, CF, DE)
+text($A$){A, shift(-2,-4)}
+text($B$){B, shift(-4,1)}
+text($C$){C, shift(4,0)}
+text($D$){D, shift(1,-4)}
+text($E$){E, shift(4,0)}
+text($F$){F, shift(2,4)}
+text($G$){G, shift(-1,4)}
+text($H$){H, shift(-4,1)}
+\endpicture
+%%-------------------
+\end{document}
+
diff --git a/graphics/mathspic/dos/mpicm05.pic b/graphics/mathspic/dos/mpicm05.pic
new file mode 100644
index 0000000000..f703fc38b9
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm05.pic
@@ -0,0 +1,77 @@
+%* -------------------------------------------
+%* mathsPIC 2.1
+%* Copyright (c) RWD Nickalls 1999-2000
+%* Email: dicknickalls@compuserve.com
+%* Date (m/d/y) : 11-05-2000 20:58:13
+%* Command Line: /b/s MPICM05.M
+%* Input Filename: MPICM05.M
+%* Output Filename: MPICM05.MT
+%* -------------------------------------------
+%% mPICm05.m (figure 5)
+%% mathsPIC rectangular box
+%\documentclass[a4paper]{article}
+%\usepackage{pictexwd}
+%\begin{document}
+%%----------------------
+\beginpicture
+%% paper{units(mm),xrange(0,50),yrange(0,62)}
+\setcoordinatesystem units < 1mm, 1mm>
+\setplotarea x from 0 to 50, y from 0 to 62
+%% variable(s){20} ( 20 ) % Sides front & back
+%% variable(L){34} ( 34 ) % Length
+%% variable(a2){56.6} ( 56.6 ) % Angle degrees
+\def\fancydashes{\setdashpattern <6pt, 2pt, 1pt, 2pt>}
+%% point(A){5,7} ( 5 , 7 )
+%% point(B){A,polar(s,90)} ( 5 , 27 )
+%% point(C){B,polar(s,0)} ( 25 , 27 )
+%% point(D){A,polar(s,0)} ( 25 , 7 )
+%% point(H){A,polar(L,a2deg)} ( 23.71635 , 35.38483 )
+%% point(G){B,polar(L,a2deg)} ( 23.71635 , 55.38483 )
+%% point(F){C,polar(L,a2deg)} ( 43.71635 , 55.38483 )
+%% point(E){D,polar(L,a2deg)} ( 43.71635 , 35.38483 )
+%% drawpoints(ABCDEFGH)
+\put {$\bullet$} at 5 7 %% A
+\put {$\bullet$} at 5 27 %% B
+\put {$\bullet$} at 25 27 %% C
+\put {$\bullet$} at 25 7 %% D
+\put {$\bullet$} at 43.71635 35.38483 %% E
+\put {$\bullet$} at 43.71635 55.38483 %% F
+\put {$\bullet$} at 23.71635 55.38483 %% G
+\put {$\bullet$} at 23.71635 35.38483 %% H
+\linethickness=2pt \setsolid
+%% drawlines(ABCDA)
+\putrule from 5 7 to 5 27 %% AB
+\putrule from 5 27 to 25 27 %% BC
+\putrule from 25 27 to 25 7 %% CD
+\putrule from 25 7 to 5 7 %% DA
+\setdashes
+%% drawlines(HGFEH)
+\putrule from 23.71635 35.38483 to 23.71635 55.38483 %% HG
+\putrule from 23.71635 55.38483 to 43.71635 55.38483 %% GF
+\putrule from 43.71635 55.38483 to 43.71635 35.38483 %% FE
+\putrule from 43.71635 35.38483 to 23.71635 35.38483 %% EH
+\linethickness=0.4pt \fancydashes
+%% drawlines(AH,BG,CF,DE)
+\plot 5 7 23.71635 35.38483 / %% AH
+\plot 5 27 23.71635 55.38483 / %% BG
+\plot 25 27 43.71635 55.38483 / %% CF
+\plot 25 7 43.71635 35.38483 / %% DE
+%% text($A$){A,shift(-2,-4)}
+\put {$A$} at 3 3
+%% text($B$){B,shift(-4,1)}
+\put {$B$} at 1 28
+%% text($C$){C,shift(4,0)}
+\put {$C$} at 29 27
+%% text($D$){D,shift(1,-4)}
+\put {$D$} at 26 3
+%% text($E$){E,shift(4,0)}
+\put {$E$} at 47.71635 35.38483
+%% text($F$){F,shift(2,4)}
+\put {$F$} at 45.71635 59.38483
+%% text($G$){G,shift(-1,4)}
+\put {$G$} at 22.71635 59.38483
+%% text($H$){H,shift(-4,1)}
+\put {$H$} at 19.71635 36.38483
+\endpicture
+%%-------------------
+%\end{document}
diff --git a/graphics/mathspic/dos/mpicm06.m b/graphics/mathspic/dos/mpicm06.m
new file mode 100644
index 0000000000..9aea827384
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm06.m
@@ -0,0 +1,72 @@
+%% mPICm06.m (figure 6)
+%% mathsPIC boxed setArrowShape diagram
+\documentclass[a4paper]{article}
+\usepackage{pictexwd}
+\begin{document}
+%%-------------------
+\beginpicture
+paper{units(mm), xrange(0,100), yrange(0,70), axes(LBTR)}%, ticks(10,10)}
+%% first do all the small arrows (from top down)
+point(J11){5,30}
+ point(J12){20,30}
+point(J9){5,25}
+ point(J10){20,25}
+point(J7){5,20}
+ point(J8){20,20}
+point(J5){5,15}
+ point(J6){20,15}
+point(J3){5,10}
+ point(J4){20,10}
+point(J1){5,5}
+ point(J2){20,5}
+%%
+arrowshape(6,30,60)
+ drawArrows(J11J12)
+arrowshape(4,30,60)
+ drawArrows(J9J10)
+arrowshape(2,30,60)
+ drawArrows(J7J8)
+arrowshape(6,30,40)
+ drawArrows(J5J6)
+arrowshape(4,30,40)
+ drawArrows(J3J4)
+arrowshape(2,30,40)
+ drawArrows(J1J2)
+%%
+text(\texttt{Arrowshape(2,30,40)}){J2,shift(5,0)}[l]
+text(\texttt{Arrowshape(4,30,40)}){J4,shift(5,0)}[l]
+text(\texttt{Arrowshape(6,30,40)}){J6,shift(5,0)}[l]
+text(\texttt{Arrowshape(2,30,60)}){J8,shift(5,0)}[l]
+text(\texttt{Arrowshape(4,30,60)}){J10,shift(5,0)}[l]
+text(\texttt{Arrowshape(6,30,60)}){J12,shift(5,0)}[l]
+%%
+%% now draw big arrow
+point(D){30,40}
+point(A){D,shift(62,0)}
+arrowshape(20,50,75)
+drawArrow(DA)
+point(B1){82,44.75}
+point(B2){82,35.25}
+point(C1){72,55}
+point(C2){72,25}
+drawpoints(DAB1B2C1C2)
+text($A$){A, shift(4,0)}
+text($B_1$){B1, shift(3,3)}
+text($B_2$){B2, shift(3,-3)}
+text($C_1$){C1, shift(-4,3)}
+text($C_2$){C2, shift(0,-4)}
+text($D$){D, shift(-4,0)}
+%%
+point(T1){10,63}
+point(T2){10,57}
+point(T3){10,51}
+text(\texttt{Arrowshape($L$,$B$,$C$)}){T1}[l]
+text($B$ = \mbox{angle $B_1AB_2$ degrees}){T2}[l]
+text($C$ = \mbox{angle $C_1AC_2$ degrees}){T3}[l]
+%%
+\betweenarrows {$L$} from 74 55 to 92 55
+\endpicture
+%%-------------------
+\end{document}
+
+
diff --git a/graphics/mathspic/dos/mpicm06.pic b/graphics/mathspic/dos/mpicm06.pic
new file mode 100644
index 0000000000..4794e7d6ed
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm06.pic
@@ -0,0 +1,113 @@
+%* -------------------------------------------
+%* mathsPIC 2.1
+%* Copyright (c) RWD Nickalls 1999-2000
+%* Email: dicknickalls@compuserve.com
+%* Date (m/d/y) : 11-05-2000 20:59:41
+%* Command Line: /b/s MPICM06.M
+%* Input Filename: MPICM06.M
+%* Output Filename: MPICM06.MT
+%* -------------------------------------------
+%% mPICm06.m (figure 6)
+%% mathsPIC boxed setArrowShape diagram
+%\documentclass[a4paper]{article}
+%\usepackage{pictexwd}
+%\begin{document}
+%%-------------------
+\beginpicture
+%% paper{units(mm),xrange(0,100),yrange(0,70),axes(LBTR)} %, ticks(10,10)}
+\setcoordinatesystem units < 1mm, 1mm>
+\setplotarea x from 0 to 100, y from 0 to 70
+\axis left /
+\axis right /
+\axis top /
+\axis bottom /
+%% first do all the small arrows (from top down)
+%% point(J11){5,30} ( 5 , 30 )
+%% point(J12){20,30} ( 20 , 30 )
+%% point(J9){5,25} ( 5 , 25 )
+%% point(J10){20,25} ( 20 , 25 )
+%% point(J7){5,20} ( 5 , 20 )
+%% point(J8){20,20} ( 20 , 20 )
+%% point(J5){5,15} ( 5 , 15 )
+%% point(J6){20,15} ( 20 , 15 )
+%% point(J3){5,10} ( 5 , 10 )
+%% point(J4){20,10} ( 20 , 10 )
+%% point(J1){5,5} ( 5 , 5 )
+%% point(J2){20,5} ( 20 , 5 )
+%%
+%% arrowshape(6,30,60)
+%% drawArrows(J11J12)
+\arrow < 6mm> [ .2679492, 1.154701] from 5 30 to 20 30
+%% arrowshape(4,30,60)
+%% drawArrows(J9J10)
+\arrow < 4mm> [ .2679492, 1.154701] from 5 25 to 20 25
+%% arrowshape(2,30,60)
+%% drawArrows(J7J8)
+\arrow < 2mm> [ .2679492, 1.154701] from 5 20 to 20 20
+%% arrowshape(6,30,40)
+%% drawArrows(J5J6)
+\arrow < 6mm> [ .2679492, .7279404] from 5 15 to 20 15
+%% arrowshape(4,30,40)
+%% drawArrows(J3J4)
+\arrow < 4mm> [ .2679492, .7279404] from 5 10 to 20 10
+%% arrowshape(2,30,40)
+%% drawArrows(J1J2)
+\arrow < 2mm> [ .2679492, .7279404] from 5 5 to 20 5
+%%
+%% text(\texttt{Arrowshape(2,30,40)}){J2,shift(5,0)}[l]
+\put {\texttt{Arrowshape(2,30,40)}} [l] at 25 5
+%% text(\texttt{Arrowshape(4,30,40)}){J4,shift(5,0)}[l]
+\put {\texttt{Arrowshape(4,30,40)}} [l] at 25 10
+%% text(\texttt{Arrowshape(6,30,40)}){J6,shift(5,0)}[l]
+\put {\texttt{Arrowshape(6,30,40)}} [l] at 25 15
+%% text(\texttt{Arrowshape(2,30,60)}){J8,shift(5,0)}[l]
+\put {\texttt{Arrowshape(2,30,60)}} [l] at 25 20
+%% text(\texttt{Arrowshape(4,30,60)}){J10,shift(5,0)}[l]
+\put {\texttt{Arrowshape(4,30,60)}} [l] at 25 25
+%% text(\texttt{Arrowshape(6,30,60)}){J12,shift(5,0)}[l]
+\put {\texttt{Arrowshape(6,30,60)}} [l] at 25 30
+%%
+%% now draw big arrow
+%% point(D){30,40} ( 30 , 40 )
+%% point(A){D,shift(62,0)} ( 92 , 40 )
+%% arrowshape(20,50,75)
+%% drawArrow(DA)
+\arrow < 20mm> [ .4663076, 1.534654] from 30 40 to 92 40
+%% point(B1){82,44.75} ( 82 , 44.75 )
+%% point(B2){82,35.25} ( 82 , 35.25 )
+%% point(C1){72,55} ( 72 , 55 )
+%% point(C2){72,25} ( 72 , 25 )
+%% drawpoints(DAB1B2C1C2)
+\put {$\bullet$} at 30 40 %% D
+\put {$\bullet$} at 92 40 %% A
+\put {$\bullet$} at 82 44.75 %% B1
+\put {$\bullet$} at 82 35.25 %% B2
+\put {$\bullet$} at 72 55 %% C1
+\put {$\bullet$} at 72 25 %% C2
+%% text($A$){A,shift(4,0)}
+\put {$A$} at 96 40
+%% text($B_1$){B1,shift(3,3)}
+\put {$B_1$} at 85 47.75
+%% text($B_2$){B2,shift(3,-3)}
+\put {$B_2$} at 85 32.25
+%% text($C_1$){C1,shift(-4,3)}
+\put {$C_1$} at 68 58
+%% text($C_2$){C2,shift(0,-4)}
+\put {$C_2$} at 72 21
+%% text($D$){D,shift(-4,0)}
+\put {$D$} at 26 40
+%%
+%% point(T1){10,63} ( 10 , 63 )
+%% point(T2){10,57} ( 10 , 57 )
+%% point(T3){10,51} ( 10 , 51 )
+%% text(\texttt{Arrowshape($L$,$B$,$C$)}){T1}[l]
+\put {\texttt{Arrowshape($L$,$B$,$C$)}} [l] at 10 63
+%% text($B$ = \mbox{angle $B_1AB_2$ degrees}){T2}[l]
+\put {$B$ = \mbox{angle $B_1AB_2$ degrees}} [l] at 10 57
+%% text($C$ = \mbox{angle $C_1AC_2$ degrees}){T3}[l]
+\put {$C$ = \mbox{angle $C_1AC_2$ degrees}} [l] at 10 51
+%%
+\betweenarrows {$L$} from 74 55 to 92 55
+\endpicture
+%%-------------------
+%\end{document}
diff --git a/graphics/mathspic/dos/mpicm07.m b/graphics/mathspic/dos/mpicm07.m
new file mode 100644
index 0000000000..5788b8034d
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm07.m
@@ -0,0 +1,23 @@
+%% mPICm07.m (Figure 7)
+%% mathsPIC arrow in triangle
+\documentclass[a4paper]{article}
+\usepackage{pictexwd}
+\begin{document}
+%%-------------------
+\beginpicture
+paper{units(mm),xrange(5,45),yrange(5,45)}
+point(A){30,30}
+point(P){10,10}
+point(B){30,10}
+drawPoints(APB)
+drawLine(APBA)
+text($A$){A,shift(1,5)}
+text($B$){B,shift(5,0)}
+text($P$){P,shift(-5,0)}
+drawAngleArrow{angle(BPA),radius(11),anticlockwise,internal}
+text($\psi$){P,polar(7,22.5 deg)}
+drawRightangle(ABP,2.5)
+\endpicture
+%%------------------
+latex{\end{document}}
+
diff --git a/graphics/mathspic/dos/mpicm07.pic b/graphics/mathspic/dos/mpicm07.pic
new file mode 100644
index 0000000000..a88ecc086e
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm07.pic
@@ -0,0 +1,47 @@
+%* -------------------------------------------
+%* mathsPIC 2.1
+%* Copyright (c) RWD Nickalls 1999-2000
+%* Email: dicknickalls@compuserve.com
+%* Date (m/d/y) : 11-05-2000 21:01:05
+%* Command Line: /b/s MPICM07.M
+%* Input Filename: MPICM07.M
+%* Output Filename: MPICM07.MT
+%* -------------------------------------------
+%% mPICm07.m (Figure 7)
+%% mathsPIC arrow in triangle
+%\documentclass[a4paper]{article}
+%\usepackage{pictexwd}
+%\begin{document}
+%%-------------------
+\beginpicture
+%% paper{units(mm),xrange(5,45),yrange(5,45)}
+\setcoordinatesystem units < 1mm, 1mm>
+\setplotarea x from 5 to 45, y from 5 to 45
+%% point(A){30,30} ( 30 , 30 )
+%% point(P){10,10} ( 10 , 10 )
+%% point(B){30,10} ( 30 , 10 )
+%% drawPoints(APB)
+\put {$\bullet$} at 30 30 %% A
+\put {$\bullet$} at 10 10 %% P
+\put {$\bullet$} at 30 10 %% B
+%% drawLine(APBA)
+\plot 30 30 10 10 / %% AP
+\putrule from 10 10 to 30 10 %% PB
+\putrule from 30 10 to 30 30 %% BA
+%% text($A$){A,shift(1,5)}
+\put {$A$} at 31 35
+%% text($B$){B,shift(5,0)}
+\put {$B$} at 35 10
+%% text($P$){P,shift(-5,0)}
+\put {$P$} at 5 10
+%% drawAngleArrow{angle(BPA),radius(11),anticlockwise,internal}
+\circulararc 45.00001 degrees from 21 10 center at 10 10
+\arrow <1.5mm> [0.5, 1] from 18.45241 17.03966 to 17.77818 17.77818
+%% text($\psi$){P,polar(7,22.5deg)}
+\put {$\psi$} at 16.46716 12.67878
+%% drawRightangle(ABP,2.5)
+\plot 27.5 10 27.5 12.5 /
+\plot 30 12.5 27.5 12.5 /
+\endpicture
+%%------------------
+%\end{document}
diff --git a/graphics/mathspic/dos/mpicm08a.m b/graphics/mathspic/dos/mpicm08a.m
new file mode 100644
index 0000000000..5812fdf89d
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm08a.m
@@ -0,0 +1,25 @@
+%% mPICm08a.m (figure 8a)
+\documentclass[a4paper]{article}
+\usepackage{pictexwd}
+\begin{document}
+%\framebox{\vbox{
+%%-------------------
+\beginpicture
+paper{units(mm),xrange(10,40),yrange(0,45)}%, axes(LB), ticks(10,10)}
+point(N){15,20}
+point(S){N,shift(20,0)}
+text(\framebox{$N$}){N,shift(0,-2.5)}
+text(\framebox{$S$}){S,shift(0,-2.5)}
+point(Z){midpoint(NS)}
+drawAngleArrow{angle(NZS),radius(NZ),clockwise,internal}
+point(N1){N,shift(2,1)}
+point(S1){S,shift(-2,1)}
+point(Z1){Z,shift(0,-3)}
+drawAngleArrow{angle(N1Z1S1),radius(N1Z1),clockwise,internal}
+point(N2){N1,shift(2,-0.5)}
+point(S2){S1,shift(-2,-0.5)}
+point(Z2){Z,shift(0,-10)}
+drawAngleArrow{angle(N2Z2S2),radius(N2Z2),clockwise,internal}
+\endpicture
+%\ }}
+\end{document}
diff --git a/graphics/mathspic/dos/mpicm08a.pic b/graphics/mathspic/dos/mpicm08a.pic
new file mode 100644
index 0000000000..885fb80839
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm08a.pic
@@ -0,0 +1,44 @@
+%* -------------------------------------------
+%* mathsPIC 2.1
+%* Copyright (c) RWD Nickalls 1999-2000
+%* Email: dicknickalls@compuserve.com
+%* Date (m/d/y) : 11-05-2000 21:02:19
+%* Command Line: /b/s MPICM08A.M
+%* Input Filename: MPICM08A.M
+%* Output Filename: MPICM08A.MT
+%* -------------------------------------------
+%% mPICm08a.m (figure 8a)
+%\documentclass[a4paper]{article}
+%\usepackage{pictexwd}
+%\begin{document}
+%\framebox{\vbox{
+%%-------------------
+\beginpicture
+%% paper{units(mm),xrange(10,40),yrange(0,45)} %, axes(LB), ticks(10,10)}
+\setcoordinatesystem units < 1mm, 1mm>
+\setplotarea x from 10 to 40, y from 0 to 45
+%% point(N){15,20} ( 15 , 20 )
+%% point(S){N,shift(20,0)} ( 35 , 20 )
+%% text(\framebox{$N$}){N,shift(0,-2.5)}
+\put {\framebox{$N$}} at 15 17.5
+%% text(\framebox{$S$}){S,shift(0,-2.5)}
+\put {\framebox{$S$}} at 35 17.5
+%% point(Z){midpoint(NS)} ( 25 , 20 )
+%% drawAngleArrow{angle(NZS),radius(NZ),clockwise,internal}
+\circulararc -180 degrees from 15 20 center at 25 20
+\arrow <1.5mm> [0.5, 1] from 34.95 20.99875 to 35 20
+%% point(N1){N,shift(2,1)} ( 17 , 21 )
+%% point(S1){S,shift(-2,1)} ( 33 , 21 )
+%% point(Z1){Z,shift(0,-3)} ( 25 , 17 )
+%% drawAngleArrow{angle(N1Z1S1),radius(N1Z1),clockwise,internal}
+\circulararc -126.8699 degrees from 17 21 center at 25 17
+\arrow <1.5mm> [0.5, 1] from 32.50349 21.86803 to 33 21
+%% point(N2){N1,shift(2,-0.5)} ( 19 , 20.5 )
+%% point(S2){S1,shift(-2,-0.5)} ( 31 , 20.5 )
+%% point(Z2){Z,shift(0,-10)} ( 25 , 10 )
+%% drawAngleArrow{angle(N2Z2S2),radius(N2Z2),clockwise,internal}
+\circulararc -59.48976 degrees from 19 20.5 center at 25 10
+\arrow <1.5mm> [0.5, 1] from 30.11199 20.95982 to 31 20.5
+\endpicture
+%\ }}
+%\end{document}
diff --git a/graphics/mathspic/dos/mpicm08b.m b/graphics/mathspic/dos/mpicm08b.m
new file mode 100644
index 0000000000..e3f586ed52
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm08b.m
@@ -0,0 +1,30 @@
+%% mPICm08b.m (figure 8b)
+\documentclass[a4paper]{article}
+\usepackage{pictexwd}
+\begin{document}
+%%-------------------
+\beginpicture
+paper{units(mm),xrange(0,45),yrange(0,45)}%, axes(LB), ticks(10,10)}
+point(P){5,10}[$P$,5]
+point(Q){P,polar(30,90 deg)}[$Q$,5]
+point(R){Q,polar(40,0 deg)}[$R$,5]
+point(T){P,polar(30,0 deg)}[$T$,5]
+drawPoints(PQRT)
+drawArrows(PQ,QR,PT,TR,PR)
+point(P1){midpoint(PQ)}
+text($p_1$){P1,shift(3,0)}
+point(P2){midpoint(PT)}
+text($p_2$){P2,shift(0,-3)}
+point(P3){midpoint(PR)}
+text($p_3$){P3,shift(2,-2)}
+point(T1){midpoint(TR)}
+text($t$){T1,shift(3,0)}
+point(Q1){midpoint(QR)}
+%% use a macro for the label
+\newcommand{\q}{$q \star q \star q \star q \star q$}
+text(\q){Q1,shift(-1,3)}
+\endpicture
+%%------------------
+\end{document}
+
+
diff --git a/graphics/mathspic/dos/mpicm08b.pic b/graphics/mathspic/dos/mpicm08b.pic
new file mode 100644
index 0000000000..083d21fb3b
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm08b.pic
@@ -0,0 +1,53 @@
+%* -------------------------------------------
+%* mathsPIC 2.1
+%* Copyright (c) RWD Nickalls 1999-2000
+%* Email: dicknickalls@compuserve.com
+%* Date (m/d/y) : 11-05-2000 21:04:01
+%* Command Line: /b/s MPICM08B.M
+%* Input Filename: MPICM08B.M
+%* Output Filename: MPICM08B.MT
+%* -------------------------------------------
+%% mPICm08b.m (figure 8b)
+%\documentclass[a4paper]{article}
+%\usepackage{pictexwd}
+%\begin{document}
+%%-------------------
+\beginpicture
+%% paper{units(mm),xrange(0,45),yrange(0,45)} %, axes(LB), ticks(10,10)}
+\setcoordinatesystem units < 1mm, 1mm>
+\setplotarea x from 0 to 45, y from 0 to 45
+%% point(P){5,10}[$P$,5] ( 5 , 10 )
+%% point(Q){P,polar(30,90deg)}[$Q$,5] ( 5 , 40 )
+%% point(R){Q,polar(40,0deg)}[$R$,5] ( 45 , 40 )
+%% point(T){P,polar(30,0deg)}[$T$,5] ( 35 , 10 )
+%% drawPoints(PQRT)
+\put {$P$} at 5 10 %% P
+\put {$Q$} at 5 40 %% Q
+\put {$R$} at 45 40 %% R
+\put {$T$} at 35 10 %% T
+%% drawArrows(PQ,QR,PT,TR,PR)
+\arrow < 2mm> [ .2679492, .7279404] from 5 15 to 5 35
+\arrow < 2mm> [ .2679492, .7279404] from 10 40 to 40 40
+\arrow < 2mm> [ .2679492, .7279404] from 10 10 to 30 10
+\arrow < 2mm> [ .2679492, .7279404] from 36.58114 14.74342 to 43.41886 35.25658
+\arrow < 2mm> [ .2679492, .7279404] from 9 13 to 41 37
+%% point(P1){midpoint(PQ)} ( 5 , 25 )
+%% text($p_1$){P1,shift(3,0)}
+\put {$p_1$} at 8 25
+%% point(P2){midpoint(PT)} ( 20 , 10 )
+%% text($p_2$){P2,shift(0,-3)}
+\put {$p_2$} at 20 7
+%% point(P3){midpoint(PR)} ( 25 , 25 )
+%% text($p_3$){P3,shift(2,-2)}
+\put {$p_3$} at 27 23
+%% point(T1){midpoint(TR)} ( 40 , 25 )
+%% text($t$){T1,shift(3,0)}
+\put {$t$} at 43 25
+%% point(Q1){midpoint(QR)} ( 25 , 40 )
+%% use a macro for the label
+\newcommand{\q}{$q \star q \star q \star q \star q$}
+%% text(\q){Q1,shift(-1,3)}
+\put {\q} at 24 43
+\endpicture
+%%------------------
+%\end{document}
diff --git a/graphics/mathspic/dos/mpicm09.m b/graphics/mathspic/dos/mpicm09.m
new file mode 100644
index 0000000000..bd2020e114
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm09.m
@@ -0,0 +1,28 @@
+%% mPICm09.m (figure 9)
+%% mathsPIC (4 circles figure)
+\documentclass[a4paper]{article}
+\usepackage{pictexwd}
+\begin{document}
+%%-------------------
+\beginpicture
+paper{units(mm),xrange(0,70),yrange(0,60)}%
+point(A){30,11}[circle,8]
+point(B){A,shift(-10,30)}[circle,15] %% big circle
+point(C){A,polar(30,20 deg)}[circle,5]
+point(D){A,polar(45,50 deg)}[circle,7]
+drawPoints(ABCD)
+drawLines(AB,AC,BC,BD,CD)
+\setdashes
+drawLine(AD)
+text($A$){A}
+%% use a macro for the formula
+\newcommand{\formula}{%
+\ $\displaystyle \sum_{p\ge0} \Delta_{jp} z^{(p+1)}$%
+\ }%
+text(\formula){B}
+text($C$){C}
+text($D$){D}
+\endpicture
+%%------------------
+\end{document}
+
diff --git a/graphics/mathspic/dos/mpicm09.pic b/graphics/mathspic/dos/mpicm09.pic
new file mode 100644
index 0000000000..ada9201c75
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm09.pic
@@ -0,0 +1,52 @@
+%* -------------------------------------------
+%* mathsPIC 2.1
+%* Copyright (c) RWD Nickalls 1999-2000
+%* Email: dicknickalls@compuserve.com
+%* Date (m/d/y) : 11-05-2000 21:05:21
+%* Command Line: /b/s MPICM09.M
+%* Input Filename: MPICM09.M
+%* Output Filename: MPICM09.MT
+%* -------------------------------------------
+%% mPICm09.m (figure 9)
+%% mathsPIC (4 circles figure)
+%\documentclass[a4paper]{article}
+%\usepackage{pictexwd}
+%\begin{document}
+%%-------------------
+\beginpicture
+%% paper{units(mm),xrange(0,70),yrange(0,60)} %
+\setcoordinatesystem units < 1mm, 1mm>
+\setplotarea x from 0 to 70, y from 0 to 60
+%% point(A){30,11}[circle,8] ( 30 , 11 )
+%% point(B){A,shift(-10,30)}[circle,15] ( 20 , 41 ) %% big circle
+%% point(C){A,polar(30,20deg)}[circle,5] ( 58.19078 , 21.2606 )
+%% point(D){A,polar(45,50deg)}[circle,7] ( 58.92544 , 45.472 )
+%% drawPoints(ABCD)
+\circulararc 360 degrees from 38 11 center at 30 11
+\circulararc 360 degrees from 35 41 center at 20 41
+\circulararc 360 degrees from 63.19078 21.2606 center at 58.19078 21.2606
+\circulararc 360 degrees from 65.92545 45.472 center at 58.92544 45.472
+%% drawLines(AB,AC,BC,BD,CD)
+\plot 27.47018 18.58947 24.74342 26.76975 / %% AB
+\plot 37.51754 13.73616 53.49232 19.5505 / %% AC
+\plot 33.32532 34.11264 53.74901 23.55639 / %% BC
+\plot 34.90198 42.71203 51.97118 44.67305 / %% BD
+\plot 58.34243 26.2583 58.71313 38.47522 / %% CD
+\setdashes
+%% drawLine(AD)
+\plot 35.1423 17.12836 54.42593 40.10969 / %% AD
+%% text($A$){A}
+\put {$A$} at 30 11
+%% use a macro for the formula
+\newcommand{\formula}{%
+ $\displaystyle \sum_{p\ge0} \Delta_{jp} z^{(p+1)}$%
+ }%
+%% text(\formula){B}
+\put {\formula} at 20 41
+%% text($C$){C}
+\put {$C$} at 58.19078 21.2606
+%% text($D$){D}
+\put {$D$} at 58.92544 45.472
+\endpicture
+%%------------------
+%\end{document}
diff --git a/graphics/mathspic/dos/mpicm10.m b/graphics/mathspic/dos/mpicm10.m
new file mode 100644
index 0000000000..7b41aab5cf
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm10.m
@@ -0,0 +1,33 @@
+%% mPICm10.m (figure 10)
+%% mathsPIC circle with arrows
+%%-------------------
+\documentclass[a4paper]{article}
+\usepackage{pictexwd}
+\begin{document}
+%%---------------------
+\beginpicture
+paper{units(mm), xrange(5,55), yrange(5,55)}
+point(C){30,30}[$\odot$,1.2] %% center
+variable(r){20} %% radius
+drawcircle(C,r)
+point(P){C, polar(r,250 deg)}
+point(Q){C, polar(r,120 deg)}
+point(S){C, polar(r,-30 deg)}
+drawpoints(CPQS)
+drawlines(PCSQP)
+text($P$){P, polar(5,250 deg)}
+text($Q$){Q, polar(5,120 deg)}
+text($S$){S, polar(5,-30 deg)}
+drawAngleArrow{angle(PCS), radius(8) anticlockwise internal}
+text($\beta$){C, polar(5,285 deg)}
+drawAngleArrow{angle(PQS), radius(12) anticlockwise internal}
+text($\alpha$){Q, polar(8,-65 deg)}
+show angle(PQS) % alpha
+show angle(PCS) % beta
+\endpicture
+%%-------------------
+\end{document}
+
+
+
+
diff --git a/graphics/mathspic/dos/mpicm10.pic b/graphics/mathspic/dos/mpicm10.pic
new file mode 100644
index 0000000000..e41f05f7e4
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm10.pic
@@ -0,0 +1,58 @@
+%* -------------------------------------------
+%* mathsPIC 2.1
+%* Copyright (c) RWD Nickalls 1999-2000
+%* Email: dicknickalls@compuserve.com
+%* Date (m/d/y) : 11-05-2000 21:06:54
+%* Command Line: /b/s MPICM10.M
+%* Input Filename: MPICM10.M
+%* Output Filename: MPICM10.MT
+%* -------------------------------------------
+%% mPICm10.m (figure 10)
+%% mathsPIC circle with arrows
+%%-------------------
+%\documentclass[a4paper]{article}
+%\usepackage{pictexwd}
+%\begin{document}
+%%---------------------
+\beginpicture
+%% paper{units(mm),xrange(5,55),yrange(5,55)}
+\setcoordinatesystem units < 1mm, 1mm>
+\setplotarea x from 5 to 55, y from 5 to 55
+%% point(C){30,30}[$\odot$,1.2] ( 30 , 30 ) %% center
+%% variable(r){20} ( 20 ) %% radius
+%% drawcircle(C,r)
+\circulararc 360 degrees from 50 30 center at 30 30
+%% point(P){C,polar(r,250deg)} ( 23.1596 , 11.20615 )
+%% point(Q){C,polar(r,120deg)} ( 20 , 47.32051 )
+%% point(S){C,polar(r,-30deg)} ( 47.32051 , 20 )
+%% drawpoints(CPQS)
+\put {$\odot$} at 30 30 %% C
+\put {$\bullet$} at 23.1596 11.20615 %% P
+\put {$\bullet$} at 20 47.32051 %% Q
+\put {$\bullet$} at 47.32051 20 %% S
+%% drawlines(PCSQP)
+\plot 23.1596 11.20615 29.58958 28.87237 / %% PC
+\plot 31.03923 29.4 47.32051 20 / %% CS
+\plot 47.32051 20 20 47.32051 / %% SQ
+\plot 20 47.32051 23.1596 11.20615 / %% QP
+%% text($P$){P,polar(5,250deg)}
+\put {$P$} at 21.4495 6.507683
+%% text($Q$){Q,polar(5,120deg)}
+\put {$Q$} at 17.5 51.65063
+%% text($S$){S,polar(5,-30deg)}
+\put {$S$} at 51.65063 17.5
+%% drawAngleArrow{angle(PCS),radius(8)anticlockwiseinternal}
+\circulararc 79.99999 degrees from 27.26384 22.48246 center at 30 30
+\arrow <1.5mm> [0.5, 1] from 36.37505 25.16692 to 36.9282 26
+%% text($\beta$){C,polar(5,285deg)}
+\put {$\beta$} at 31.29409 25.17037
+%% drawAngleArrow{angle(PQS),radius(12)anticlockwiseinternal}
+\circulararc 40 degrees from 21.04587 35.36617 center at 20 47.32051
+\arrow <1.5mm> [0.5, 1] from 27.74932 38.1582 to 28.48528 38.83522
+%% text($\alpha$){Q,polar(8,-65deg)}
+\put {$\alpha$} at 23.38095 40.07005
+%% showangle(PQS) % alpha 40 degrees / radians .6981316
+%% showangle(PCS) % beta 79.99999 degrees / radians 1.396263
+\endpicture
+%%-------------------
+%\end{document}
diff --git a/graphics/mathspic/dos/mpicm11.m b/graphics/mathspic/dos/mpicm11.m
new file mode 100644
index 0000000000..edbede9f2b
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm11.m
@@ -0,0 +1,65 @@
+%% rn-fig2.m (= tug2000.m)
+%% used in TUG-2000 article with Apostolos.
+%% mathsPIC
+\documentclass[a4paper]{article}
+\usepackage{pictexwd}
+\begin{document}
+\beginpicture
+\setdashes
+paper{units(mm),xrange(0,70),yrange(0,60),axes(LBT*R*),ticks(10,10)}
+\setsolid
+point(A){10,10} %% anchor point
+point(B){A, polar(50,50 deg)}
+point(C){A,polar(50,0 deg)}
+point(J){pointonline(AB,30)}
+point(K){perpendicular(J,AC)}
+drawRightangle(JKC,3)
+drawLines(AB,AC,JK)
+drawIncircle(AJK)
+drawExcircle(AJK,JK)
+\setplotsymbol({\large .})
+\setdots
+drawCircumcircle(AJK)
+point(I){IncircleCenter(AJK)}[$\odot$]
+point(E){ExcircleCenter(AJK,JK)}[$\odot$,1.2]
+point(P1){perpendicular(E,AC)}
+variable(r){EP1} %% radius of excircle
+variable(d){72} %% angle of pentagon (deg)
+variable(a1){-90}
+variable(a2){a1, advance(d)}
+variable(a3){a2, advance(d)}
+variable(a4){a3, advance(d)}
+variable(a5){a4, advance(d)}
+point(P2){E, polar(r,a2)}
+point(P3){E, polar(r,a3)}
+point(P4){E, polar(r,a4)}
+point(P5){E, polar(r,a5)}
+drawPoints(ABCJKIEP1P2P3P4P5)
+\setplotsymbol({\tiny .})
+\setdashes
+drawline(P1P2P3P4P5P1,EP1,EP2)
+\setsolid
+drawAnglearc{angle(P2EP1),radius(9),internal,clockwise}
+\newcommand{\figtitle}{%
+ \fbox{%
+ \begin{minipage}{30mm}%
+ \ Triangle, pentagon and three circles%
+ \end{minipage}%
+ \ }}%
+text(\figtitle){20,52}
+variable(s){5}
+text($A$){A,polar(s,230 deg)}
+text($B$){B,polar(s,50 deg)}
+text($C$){C,polar(s,0 deg)}
+text($J$){J,polar(s,90 deg)}
+text($K$){K,polar(s,270 deg)}
+text($E$){E,polar(s,a3 deg)}
+text($72$){E,polar(5.5,-54 deg)}
+text($I$){I,shift(3, 0)}
+text($P_1$){P1,polar(s,a1)}
+text($P_2$){P2,polar(s, a2)}
+text($P_3$){P3,polar(s, a3)}
+\endpicture
+\end{document}
+
+
diff --git a/graphics/mathspic/dos/mpicm11.pic b/graphics/mathspic/dos/mpicm11.pic
new file mode 100644
index 0000000000..43698069c3
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm11.pic
@@ -0,0 +1,119 @@
+%* -------------------------------------------
+%* mathsPIC 2.1
+%* Copyright (c) RWD Nickalls 1999-2000
+%* Email: dicknickalls@compuserve.com
+%* Date (m/d/y) : 11-05-2000 21:08:12
+%* Command Line: /b/s MPICM11.M
+%* Input Filename: MPICM11.M
+%* Output Filename: MPICM11.MT
+%* -------------------------------------------
+%% mpicm11.m (Figure 11)
+%\documentclass[a4paper]{article}
+%\usepackage{pictexwd}
+%\begin{document}
+\beginpicture
+\setdashes
+%% paper{units(mm),xrange(0,70),yrange(0,60),axes(LBT*R*),ticks(10,10)}
+\setcoordinatesystem units < 1mm, 1mm>
+\setplotarea x from 0 to 70, y from 0 to 60
+\axis left ticks numbered from 0 to 60 by 10 /
+\axis right /
+\axis top /
+\axis bottom ticks numbered from 0 to 70 by 10 /
+\setsolid
+%% point(A){10,10} ( 10 , 10 ) %% anchor point
+%% point(B){A,polar(50,50deg)} ( 42.13938 , 48.30222 )
+%% point(C){A,polar(50,0deg)} ( 60 , 10 )
+%% point(J){pointonline(AB,30)} ( 29.28363 , 32.98133 )
+%% point(K){perpendicular(J,AC)} ( 29.28363 , 10 )
+%% drawRightangle(JKC,3)
+\plot 32.28363 10 32.28363 13 /
+\plot 29.28363 13 32.28363 13 /
+%% drawLines(AB,AC,JK)
+\plot 10 10 42.13938 48.30222 / %% AB
+\putrule from 10 10 to 60 10 %% AC
+\putrule from 29.28363 32.98133 to 29.28363 10 %% JK
+%% drawIncircle(AJK)
+%% Incircle centre = 23.15115 , 16.13248 ; TrueRadius = 6.132483 [ 6.132483 ]
+\circulararc 360 degrees from 29.28363 16.13248 center at 23.15115 16.13248
+%% drawExcircle(AJK,JK)
+%% Excircle centre = 46.13249 , 26.84886 ; TrueRadius = 16.84886 [ 16.84886 ]
+\circulararc 360 degrees from 62.98135 26.84886 center at 46.13249 26.84886
+\setplotsymbol({\large .})
+\setdots
+%% drawCircumcircle(AJK)
+%% circumcircle centre = 19.64182 , 21.49067 ; Radius = 15
+\circulararc 360 degrees from 34.64181 21.49067 center at 19.64182 21.49067
+%% point(I){IncircleCenter(AJK)}[$\odot$] ( 23.15115 , 16.13248 )
+%% point(E){ExcircleCenter(AJK,JK)}[$\odot$,1.2] ( 46.13249 , 26.84886 )
+%% point(P1){perpendicular(E,AC)} ( 46.13249 , 10 )
+%% variable(r){EP1} ( 16.84886 ) %% radius of excircle
+%% variable(d){72} ( 72 ) %% angle of pentagon (deg)
+%% variable(a1){-90} (-90 )
+%% variable(a2){a1,advance(d)} (-18 )
+%% variable(a3){a2,advance(d)} ( 54 )
+%% variable(a4){a3,advance(d)} ( 126 )
+%% variable(a5){a4,advance(d)} ( 198 )
+%% point(P2){E,polar(r,a2)} ( 62.1567 , 21.64227 )
+%% point(P3){E,polar(r,a3)} ( 56.036 , 40.47987 )
+%% point(P4){E,polar(r,a4)} ( 36.22898 , 40.47987 )
+%% point(P5){E,polar(r,a5)} ( 30.10827 , 21.64227 )
+%% drawPoints(ABCJKIEP1P2P3P4P5)
+\put {$\bullet$} at 10 10 %% A
+\put {$\bullet$} at 42.13938 48.30222 %% B
+\put {$\bullet$} at 60 10 %% C
+\put {$\bullet$} at 29.28363 32.98133 %% J
+\put {$\bullet$} at 29.28363 10 %% K
+\put {$\odot$} at 23.15115 16.13248 %% I
+\put {$\odot$} at 46.13249 26.84886 %% E
+\put {$\bullet$} at 46.13249 10 %% P1
+\put {$\bullet$} at 62.1567 21.64227 %% P2
+\put {$\bullet$} at 56.036 40.47987 %% P3
+\put {$\bullet$} at 36.22898 40.47987 %% P4
+\put {$\bullet$} at 30.10827 21.64227 %% P5
+\setplotsymbol({\tiny .})
+\setdashes
+%% drawline(P1P2P3P4P5P1,EP1,EP2)
+\plot 46.13249 10 62.1567 21.64227 / %% P1P2
+\plot 62.1567 21.64227 56.036 40.47987 / %% P2P3
+\putrule from 56.036 40.47987 to 36.22898 40.47987 %% P3P4
+\plot 36.22898 40.47987 30.10827 21.64227 / %% P4P5
+\plot 30.10827 21.64227 46.13249 10 / %% P5P1
+\putrule from 46.13249 25.64886 to 46.13249 10 %% EP1
+\plot 47.27376 26.47803 62.1567 21.64227 / %% EP2
+\setsolid
+%% drawAnglearc{angle(P2EP1),radius(9),internal,clockwise}
+\circulararc -71.99998 degrees from 54.692 24.0677 center at 46.13249 26.84886
+\newcommand{\figtitle}{%
+ \fbox{%
+ \begin{minipage}{30mm}%
+ Triangle, pentagon and three circles%
+ \end{minipage}%
+ }}%
+%% text(\figtitle){20,52}
+\put {\figtitle} at 20 52
+%% variable(s){5} ( 5 )
+%% text($A$){A,polar(s,230deg)}
+\put {$A$} at 6.786062 6.169777
+%% text($B$){B,polar(s,50deg)}
+\put {$B$} at 45.35332 52.13245
+%% text($C$){C,polar(s,0deg)}
+\put {$C$} at 65 10
+%% text($J$){J,polar(s,90deg)}
+\put {$J$} at 29.28363 37.98133
+%% text($K$){K,polar(s,270deg)}
+\put {$K$} at 29.28363 5
+%% text($E$){E,polar(s,a3deg)}
+\put {$E$} at 49.07141 30.89394
+%% text($72$){E,polar(5.5,-54deg)}
+\put {$72$} at 49.36531 22.39926
+%% text($I$){I,shift(3,0)}
+\put {$I$} at 26.15115 16.13248
+%% text($P_1$){P1,polar(s,a1)}
+\put {$P_1$} at 46.13249 5
+%% text($P_2$){P2,polar(s,a2)}
+\put {$P_2$} at 66.91198 20.09719
+%% text($P_3$){P3,polar(s,a3)}
+\put {$P_3$} at 58.97492 44.52495
+\endpicture
+%\end{document}
diff --git a/graphics/mathspic/dos/mpicm12.m b/graphics/mathspic/dos/mpicm12.m
new file mode 100644
index 0000000000..b517363a6f
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm12.m
@@ -0,0 +1,52 @@
+%% mPICm12.m (figure 12)
+%% mathsPIC dynamic figure
+%%-------------------
+\documentclass[a4paper]{article}
+\usepackage{pictexwd}
+\begin{document}
+%%---------------------
+\beginpicture
+paper{units(mm), xrange(5,110), yrange(0,45)}
+point(A){15,5}[$\odot$,1.2]
+point(P){A, shift(10,30)}[$\odot$,1.2]
+point(B){A, polar(45,60 deg)}
+point(Q){perpendicular(P,AB)}
+drawRightangle(PQA,2)
+drawpoints(ABPQ)
+drawline(ABPQ)
+drawincircle(PQB)
+text($A$){A,shift(-5, 0)}
+text($B$){B,shift(5, 0)}
+text($P$){P,shift(-5, 0)}
+point(S){pointOnLine(QP,-5)}
+text($Q$){S}
+point(N){A,shift(0,10)}
+\setdashes
+drawline(AN)
+\setsolid
+drawAngleArrow{angle(NAB),radius(5.7),clockwise,internal}
+
+%%--------- second figure
+
+point*(A){60,5}[$\odot$,1.2]
+point*(P){A, shift(10,30)}[$\odot$,1.2]
+point*(B){A, polar(45,5 deg)} %%5 60 deg
+point*(Q){perpendicular(P,AB)}
+drawRightangle(PQA,2)
+drawpoints(ABPQ)
+drawline(ABPQ)
+drawincircle(PQB)
+text($A$){A,shift(-5, 0)}
+text($B$){B,shift(5, 0)}
+text($P$){P,shift(-5, 0)}
+point*(S){pointOnLine(QP,-5)}
+text($Q$){S}
+point*(N){A,shift(0,10)}
+\setdashes
+drawline(AN)
+\setsolid
+drawAngleArrow{angle(NAB),radius(5.7),clockwise,internal}
+
+%%------
+\endpicture
+\end{document}
diff --git a/graphics/mathspic/dos/mpicm12.pic b/graphics/mathspic/dos/mpicm12.pic
new file mode 100644
index 0000000000..e2ab0a06f1
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm12.pic
@@ -0,0 +1,96 @@
+%* -------------------------------------------
+%* mathsPIC 2.1
+%* Copyright (c) RWD Nickalls 1999-2000
+%* Email: dicknickalls@compuserve.com
+%* Date (m/d/y) : 11-05-2000 21:10:47
+%* Command Line: /b/s MPICM12.M
+%* Input Filename: MPICM12.M
+%* Output Filename: MPICM12.MT
+%* -------------------------------------------
+%% mPICm12.m (figure 12)
+%% mathsPIC dynamic figure
+%%-------------------
+%\documentclass[a4paper]{article}
+%\usepackage{pictexwd}
+%\begin{document}
+%%---------------------
+\beginpicture
+%% paper{units(mm),xrange(5,110),yrange(0,45)}
+\setcoordinatesystem units < 1mm, 1mm>
+\setplotarea x from 5 to 110, y from 0 to 45
+%% point(A){15,5}[$\odot$,1.2] ( 15 , 5 )
+%% point(P){A,shift(10,30)}[$\odot$,1.2] ( 25 , 35 )
+%% point(B){A,polar(45,60deg)} ( 37.5 , 43.97115 )
+%% point(Q){perpendicular(P,AB)} ( 30.49038 , 31.83013 )
+%% drawRightangle(PQA,2)
+\plot 29.49038 30.09808 27.75833 31.09808 /
+\plot 28.75833 32.83013 27.75833 31.09808 /
+%% drawpoints(ABPQ)
+\put {$\odot$} at 15 5 %% A
+\put {$\bullet$} at 37.5 43.97115 %% B
+\put {$\odot$} at 25 35 %% P
+\put {$\bullet$} at 30.49038 31.83013 %% Q
+%% drawline(ABPQ)
+\plot 15.6 6.03923 37.5 43.97115 / %% AB
+\plot 37.5 43.97115 25.97491 35.69968 / %% BP
+\plot 26.03923 34.4 30.49038 31.83013 / %% PQ
+%% drawincircle(PQB)
+%% Incircle centre = 29.58027 , 35.22668 ; TrueRadius = 2.486452 [ 2.486452 ]
+\circulararc 360 degrees from 32.06673 35.22668 center at 29.58027 35.22668
+%% text($A$){A,shift(-5,0)}
+\put {$A$} at 10 5
+%% text($B$){B,shift(5,0)}
+\put {$B$} at 42.5 43.97115
+%% text($P$){P,shift(-5,0)}
+\put {$P$} at 20 35
+%% point(S){pointOnLine(QP,-5)} ( 34.82051 , 29.33013 )
+%% text($Q$){S}
+\put {$Q$} at 34.82051 29.33013
+%% point(N){A,shift(0,10)} ( 15 , 15 )
+\setdashes
+%% drawline(AN)
+\putrule from 15 6.2 to 15 15 %% AN
+\setsolid
+%% drawAngleArrow{angle(NAB),radius(5.7),clockwise,internal}
+\circulararc -30.00002 degrees from 15 10.7 center at 15 5
+\arrow <1.5mm> [0.5, 1] from 16.94345 10.35845 to 17.85 9.936344
+%%--------- second figure
+%% point*(A){60,5}[$\odot$,1.2] ( 60 , 5 )
+%% point*(P){A,shift(10,30)}[$\odot$,1.2] ( 70 , 35 )
+%% point*(B){A,polar(45,5deg)} ( 104.8288 , 8.922009 ) %%5 60 deg
+%% point*(Q){perpendicular(P,AB)} ( 72.52876 , 6.096125 )
+%% drawRightangle(PQA,2)
+\plot 70.53638 5.921813 70.36206 7.914203 /
+\plot 72.35445 8.088514 70.36206 7.914203 /
+%% drawpoints(ABPQ)
+\put {$\odot$} at 60 5 %% A
+\put {$\bullet$} at 104.8288 8.922009 %% B
+\put {$\odot$} at 70 35 %% P
+\put {$\bullet$} at 72.52876 6.096125 %% Q
+%% drawline(ABPQ)
+\plot 61.19543 5.104587 104.8288 8.922009 / %% AB
+\plot 104.8288 8.922009 70.96058 34.28077 / %% BP
+\plot 70.10458 33.80457 72.52876 6.096125 / %% PQ
+%% drawincircle(PQB)
+%% Incircle centre = 80.67732 , 15.80719 ; TrueRadius = 8.963924 [ 8.963924 ]
+\circulararc 360 degrees from 89.64125 15.80719 center at 80.67732 15.80719
+%% text($A$){A,shift(-5,0)}
+\put {$A$} at 55 5
+%% text($B$){B,shift(5,0)}
+\put {$B$} at 109.8288 8.922009
+%% text($P$){P,shift(-5,0)}
+\put {$P$} at 65 35
+%% point*(S){pointOnLine(QP,-5)} ( 72.96454 , 1.115151 )
+%% text($Q$){S}
+\put {$Q$} at 72.96454 1.115151
+%% point*(N){A,shift(0,10)} ( 60 , 15 )
+\setdashes
+%% drawline(AN)
+\putrule from 60 6.2 to 60 15 %% AN
+\setsolid
+%% drawAngleArrow{angle(NAB),radius(5.7),clockwise,internal}
+\circulararc -85.00002 degrees from 60 10.7 center at 60 5
+\arrow <1.5mm> [0.5, 1] from 65.5041 6.481498 to 65.67831 5.496788
+%%------
+\endpicture
+%\end{document}
diff --git a/graphics/mathspic/dos/mpicm13.dat b/graphics/mathspic/dos/mpicm13.dat
new file mode 100644
index 0000000000..6fe9cf7c17
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm13.dat
@@ -0,0 +1,16 @@
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+variable*(r){r, advance(-0.5)} %% r=r-0.5
+variable*(a){a, advance(15)} %% a=a+15
+point*(P){C,polar(r,a deg )}
+drawpoint(P)
+drawline(TP)
+point*(T){P} %% t=p
+%% make a square on P (s is defined in mPICm-12.m)
+point*(Q1){P,polar(s,0)}
+point*(Q2){P,polar(s,90)}
+point*(Q3){P,polar(s,180)}
+point*(Q4){P,polar(s,270)}
+drawline(Q1Q2Q3Q4Q1)
+
diff --git a/graphics/mathspic/dos/mpicm13.m b/graphics/mathspic/dos/mpicm13.m
new file mode 100644
index 0000000000..de3924681d
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm13.m
@@ -0,0 +1,22 @@
+%% mPICm13.m (figure 13)
+%% mathsPIC small spiral by recursion
+%% (requires file mPICm13.dat)
+\documentclass[a4paper]{article}
+\usepackage{pictexwd}
+\begin{document}
+%%---------------
+\beginpicture
+paper{units(mm), xrange(0,60), yrange(0,60)}% axes(LB), ticks(10,10)}
+point(C){30,30} % circle center
+drawcircle(c,25)
+variable(a){315} % angle
+variable(r){20} % radius
+variable(s){5} % square semi-diagonal
+point(t){c,polar(r,330 deg)}
+inputfile(mpicm13.dat)[30]
+\endpicture
+%%----------------
+\end{document}
+
+
+
diff --git a/graphics/mathspic/dos/mpicm13.pic b/graphics/mathspic/dos/mpicm13.pic
new file mode 100644
index 0000000000..58a0e63efb
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm13.pic
@@ -0,0 +1,756 @@
+%* -------------------------------------------
+%* mathsPIC 2.1
+%* Copyright (c) RWD Nickalls 1999-2000
+%* Email: dicknickalls@compuserve.com
+%* Date (m/d/y) : 11-05-2000 21:12:02
+%* Command Line: /b/s MPICM13.M
+%* Input Filename: MPICM13.M
+%* Output Filename: MPICM13.MT
+%* -------------------------------------------
+%% mPICm13.m (figure 13)
+%% mathsPIC small spiral by recursion
+%% (requires file mPICm13.dat)
+%\documentclass[a4paper]{article}
+%\usepackage{pictexwd}
+%\begin{document}
+%%---------------
+\beginpicture
+%% paper{units(mm),xrange(0,60),yrange(0,60)} % axes(LB), ticks(10,10)}
+\setcoordinatesystem units < 1mm, 1mm>
+\setplotarea x from 0 to 60, y from 0 to 60
+%% point(C){30,30} ( 30 , 30 ) % circle center
+%% drawcircle(c,25)
+\circulararc 360 degrees from 55 30 center at 30 30
+%% variable(a){315} ( 315 ) % angle
+%% variable(r){20} ( 20 ) % radius
+%% variable(s){5} ( 5 ) % square semi-diagonal
+%% point(t){c,polar(r,330deg)} ( 47.32051 , 20 )
+%% inputfile(mpicm13.dat)[30]
+%% ... start of file <mpicm13.dat> loop(1)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 19.5 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 330 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 46.88749 , 20.25 )
+%% ... Note: pointname (P) not used before--suggest using point() here
+%% drawpoint(P)
+\put {$\bullet$} at 46.88749 20.25 %% P
+%% drawline(TP)
+\plot 47.32051 20 46.88749 20.25 / %% TP
+%% point*(T){P} ( 46.88749 , 20.25 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 51.88749 , 20.25 )
+%% ... Note: pointname (Q1) not used before--suggest using point() here
+%% point*(Q2){P,polar(s,90)} ( 46.88749 , 25.25 )
+%% ... Note: pointname (Q2) not used before--suggest using point() here
+%% point*(Q3){P,polar(s,180)} ( 41.88749 , 20.25 )
+%% ... Note: pointname (Q3) not used before--suggest using point() here
+%% point*(Q4){P,polar(s,270)} ( 46.88749 , 15.25 )
+%% ... Note: pointname (Q4) not used before--suggest using point() here
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 51.88749 20.25 46.88749 25.25 / %% Q1Q2
+\plot 46.88749 25.25 41.88749 20.25 / %% Q2Q3
+\plot 41.88749 20.25 46.88749 15.25 / %% Q3Q4
+\plot 46.88749 15.25 51.88749 20.25 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(1)
+%% ... start of file <mpicm13.dat> loop(2)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 19 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 345 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 48.35259 , 25.08243 )
+%% drawpoint(P)
+\put {$\bullet$} at 48.35259 25.08243 %% P
+%% drawline(TP)
+\plot 46.88749 20.25 48.35259 25.08243 / %% TP
+%% point*(T){P} ( 48.35259 , 25.08243 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 53.35259 , 25.08243 )
+%% point*(Q2){P,polar(s,90)} ( 48.35259 , 30.08243 )
+%% point*(Q3){P,polar(s,180)} ( 43.35259 , 25.08243 )
+%% point*(Q4){P,polar(s,270)} ( 48.35259 , 20.08243 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 53.35259 25.08243 48.35259 30.08243 / %% Q1Q2
+\plot 48.35259 30.08243 43.35259 25.08243 / %% Q2Q3
+\plot 43.35259 25.08243 48.35259 20.08243 / %% Q3Q4
+\plot 48.35259 20.08243 53.35259 25.08243 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(2)
+%% ... start of file <mpicm13.dat> loop(3)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 18.5 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 360 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 48.5 , 30 )
+%% drawpoint(P)
+\put {$\bullet$} at 48.5 30 %% P
+%% drawline(TP)
+\plot 48.35259 25.08243 48.5 30 / %% TP
+%% point*(T){P} ( 48.5 , 30 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 53.5 , 30 )
+%% point*(Q2){P,polar(s,90)} ( 48.5 , 35 )
+%% point*(Q3){P,polar(s,180)} ( 43.5 , 30 )
+%% point*(Q4){P,polar(s,270)} ( 48.5 , 25 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 53.5 30 48.5 35 / %% Q1Q2
+\plot 48.5 35 43.5 30 / %% Q2Q3
+\plot 43.5 30 48.5 25 / %% Q3Q4
+\plot 48.5 25 53.5 30 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(3)
+%% ... start of file <mpicm13.dat> loop(4)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 18 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 375 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 47.38667 , 34.65874 )
+%% drawpoint(P)
+\put {$\bullet$} at 47.38667 34.65874 %% P
+%% drawline(TP)
+\plot 48.5 30 47.38667 34.65874 / %% TP
+%% point*(T){P} ( 47.38667 , 34.65874 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 52.38667 , 34.65874 )
+%% point*(Q2){P,polar(s,90)} ( 47.38667 , 39.65874 )
+%% point*(Q3){P,polar(s,180)} ( 42.38667 , 34.65874 )
+%% point*(Q4){P,polar(s,270)} ( 47.38667 , 29.65874 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 52.38667 34.65874 47.38667 39.65874 / %% Q1Q2
+\plot 47.38667 39.65874 42.38667 34.65874 / %% Q2Q3
+\plot 42.38667 34.65874 47.38667 29.65874 / %% Q3Q4
+\plot 47.38667 29.65874 52.38667 34.65874 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(4)
+%% ... start of file <mpicm13.dat> loop(5)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 17.5 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 390 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 45.15545 , 38.75 )
+%% drawpoint(P)
+\put {$\bullet$} at 45.15545 38.75 %% P
+%% drawline(TP)
+\plot 47.38667 34.65874 45.15545 38.75 / %% TP
+%% point*(T){P} ( 45.15545 , 38.75 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 50.15545 , 38.75 )
+%% point*(Q2){P,polar(s,90)} ( 45.15545 , 43.75 )
+%% point*(Q3){P,polar(s,180)} ( 40.15545 , 38.75 )
+%% point*(Q4){P,polar(s,270)} ( 45.15545 , 33.75 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 50.15545 38.75 45.15545 43.75 / %% Q1Q2
+\plot 45.15545 43.75 40.15545 38.75 / %% Q2Q3
+\plot 40.15545 38.75 45.15545 33.75 / %% Q3Q4
+\plot 45.15545 33.75 50.15545 38.75 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(5)
+%% ... start of file <mpicm13.dat> loop(6)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 17 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 405 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 42.02081 , 42.02082 )
+%% drawpoint(P)
+\put {$\bullet$} at 42.02081 42.02082 %% P
+%% drawline(TP)
+\plot 45.15545 38.75 42.02081 42.02082 / %% TP
+%% point*(T){P} ( 42.02081 , 42.02082 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 47.02081 , 42.02082 )
+%% point*(Q2){P,polar(s,90)} ( 42.02081 , 47.02082 )
+%% point*(Q3){P,polar(s,180)} ( 37.02081 , 42.02082 )
+%% point*(Q4){P,polar(s,270)} ( 42.02081 , 37.02082 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 47.02081 42.02082 42.02081 47.02082 / %% Q1Q2
+\plot 42.02081 47.02082 37.02081 42.02082 / %% Q2Q3
+\plot 37.02081 42.02082 42.02081 37.02082 / %% Q3Q4
+\plot 42.02081 37.02082 47.02081 42.02082 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(6)
+%% ... start of file <mpicm13.dat> loop(7)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 16.5 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 420 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 38.25 , 44.28942 )
+%% drawpoint(P)
+\put {$\bullet$} at 38.25 44.28942 %% P
+%% drawline(TP)
+\plot 42.02081 42.02082 38.25 44.28942 / %% TP
+%% point*(T){P} ( 38.25 , 44.28942 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 43.25 , 44.28942 )
+%% point*(Q2){P,polar(s,90)} ( 38.25 , 49.28942 )
+%% point*(Q3){P,polar(s,180)} ( 33.25 , 44.28942 )
+%% point*(Q4){P,polar(s,270)} ( 38.25 , 39.28942 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 43.25 44.28942 38.25 49.28942 / %% Q1Q2
+\plot 38.25 49.28942 33.25 44.28942 / %% Q2Q3
+\plot 33.25 44.28942 38.25 39.28942 / %% Q3Q4
+\plot 38.25 39.28942 43.25 44.28942 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(7)
+%% ... start of file <mpicm13.dat> loop(8)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 16 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 435 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 34.14111 , 45.45481 )
+%% drawpoint(P)
+\put {$\bullet$} at 34.14111 45.45481 %% P
+%% drawline(TP)
+\plot 38.25 44.28942 34.14111 45.45481 / %% TP
+%% point*(T){P} ( 34.14111 , 45.45481 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 39.14111 , 45.45481 )
+%% point*(Q2){P,polar(s,90)} ( 34.14111 , 50.45481 )
+%% point*(Q3){P,polar(s,180)} ( 29.14111 , 45.45481 )
+%% point*(Q4){P,polar(s,270)} ( 34.14111 , 40.45481 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 39.14111 45.45481 34.14111 50.45481 / %% Q1Q2
+\plot 34.14111 50.45481 29.14111 45.45481 / %% Q2Q3
+\plot 29.14111 45.45481 34.14111 40.45481 / %% Q3Q4
+\plot 34.14111 40.45481 39.14111 45.45481 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(8)
+%% ... start of file <mpicm13.dat> loop(9)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 15.5 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 450 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 30 , 45.5 )
+%% drawpoint(P)
+\put {$\bullet$} at 30 45.5 %% P
+%% drawline(TP)
+\plot 34.14111 45.45481 30 45.5 / %% TP
+%% point*(T){P} ( 30 , 45.5 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 35 , 45.5 )
+%% point*(Q2){P,polar(s,90)} ( 30 , 50.5 )
+%% point*(Q3){P,polar(s,180)} ( 25 , 45.5 )
+%% point*(Q4){P,polar(s,270)} ( 30 , 40.5 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 35 45.5 30 50.5 / %% Q1Q2
+\plot 30 50.5 25 45.5 / %% Q2Q3
+\plot 25 45.5 30 40.5 / %% Q3Q4
+\plot 30 40.5 35 45.5 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(9)
+%% ... start of file <mpicm13.dat> loop(10)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 15 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 465 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 26.11771 , 44.48889 )
+%% drawpoint(P)
+\put {$\bullet$} at 26.11771 44.48889 %% P
+%% drawline(TP)
+\plot 30 45.5 26.11771 44.48889 / %% TP
+%% point*(T){P} ( 26.11771 , 44.48889 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 31.11771 , 44.48889 )
+%% point*(Q2){P,polar(s,90)} ( 26.11771 , 49.48889 )
+%% point*(Q3){P,polar(s,180)} ( 21.11771 , 44.48889 )
+%% point*(Q4){P,polar(s,270)} ( 26.11771 , 39.48889 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 31.11771 44.48889 26.11771 49.48889 / %% Q1Q2
+\plot 26.11771 49.48889 21.11771 44.48889 / %% Q2Q3
+\plot 21.11771 44.48889 26.11771 39.48889 / %% Q3Q4
+\plot 26.11771 39.48889 31.11771 44.48889 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(10)
+%% ... start of file <mpicm13.dat> loop(11)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 14.5 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 480 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 22.75 , 42.55737 )
+%% drawpoint(P)
+\put {$\bullet$} at 22.75 42.55737 %% P
+%% drawline(TP)
+\plot 26.11771 44.48889 22.75 42.55737 / %% TP
+%% point*(T){P} ( 22.75 , 42.55737 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 27.75 , 42.55737 )
+%% point*(Q2){P,polar(s,90)} ( 22.75 , 47.55737 )
+%% point*(Q3){P,polar(s,180)} ( 17.75 , 42.55737 )
+%% point*(Q4){P,polar(s,270)} ( 22.75 , 37.55737 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 27.75 42.55737 22.75 47.55737 / %% Q1Q2
+\plot 22.75 47.55737 17.75 42.55737 / %% Q2Q3
+\plot 17.75 42.55737 22.75 37.55737 / %% Q3Q4
+\plot 22.75 37.55737 27.75 42.55737 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(11)
+%% ... start of file <mpicm13.dat> loop(12)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 14 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 495 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 20.10051 , 39.89949 )
+%% drawpoint(P)
+\put {$\bullet$} at 20.10051 39.89949 %% P
+%% drawline(TP)
+\plot 22.75 42.55737 20.10051 39.89949 / %% TP
+%% point*(T){P} ( 20.10051 , 39.89949 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 25.10051 , 39.89949 )
+%% point*(Q2){P,polar(s,90)} ( 20.10051 , 44.89949 )
+%% point*(Q3){P,polar(s,180)} ( 15.10051 , 39.89949 )
+%% point*(Q4){P,polar(s,270)} ( 20.10051 , 34.89949 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 25.10051 39.89949 20.10051 44.89949 / %% Q1Q2
+\plot 20.10051 44.89949 15.10051 39.89949 / %% Q2Q3
+\plot 15.10051 39.89949 20.10051 34.89949 / %% Q3Q4
+\plot 20.10051 34.89949 25.10051 39.89949 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(12)
+%% ... start of file <mpicm13.dat> loop(13)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 13.5 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 510 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 18.30866 , 36.75 )
+%% drawpoint(P)
+\put {$\bullet$} at 18.30866 36.75 %% P
+%% drawline(TP)
+\plot 20.10051 39.89949 18.30866 36.75 / %% TP
+%% point*(T){P} ( 18.30866 , 36.75 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 23.30866 , 36.75 )
+%% point*(Q2){P,polar(s,90)} ( 18.30866 , 41.75 )
+%% point*(Q3){P,polar(s,180)} ( 13.30866 , 36.75 )
+%% point*(Q4){P,polar(s,270)} ( 18.30866 , 31.75 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 23.30866 36.75 18.30866 41.75 / %% Q1Q2
+\plot 18.30866 41.75 13.30866 36.75 / %% Q2Q3
+\plot 13.30866 36.75 18.30866 31.75 / %% Q3Q4
+\plot 18.30866 31.75 23.30866 36.75 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(13)
+%% ... start of file <mpicm13.dat> loop(14)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 13 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 525 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 17.44296 , 33.36465 )
+%% drawpoint(P)
+\put {$\bullet$} at 17.44296 33.36465 %% P
+%% drawline(TP)
+\plot 18.30866 36.75 17.44296 33.36465 / %% TP
+%% point*(T){P} ( 17.44296 , 33.36465 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 22.44296 , 33.36465 )
+%% point*(Q2){P,polar(s,90)} ( 17.44296 , 38.36465 )
+%% point*(Q3){P,polar(s,180)} ( 12.44296 , 33.36465 )
+%% point*(Q4){P,polar(s,270)} ( 17.44296 , 28.36465 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 22.44296 33.36465 17.44296 38.36465 / %% Q1Q2
+\plot 17.44296 38.36465 12.44296 33.36465 / %% Q2Q3
+\plot 12.44296 33.36465 17.44296 28.36465 / %% Q3Q4
+\plot 17.44296 28.36465 22.44296 33.36465 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(14)
+%% ... start of file <mpicm13.dat> loop(15)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 12.5 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 540 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 17.5 , 30 )
+%% drawpoint(P)
+\put {$\bullet$} at 17.5 30 %% P
+%% drawline(TP)
+\plot 17.44296 33.36465 17.5 30 / %% TP
+%% point*(T){P} ( 17.5 , 30 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 22.5 , 30 )
+%% point*(Q2){P,polar(s,90)} ( 17.5 , 35 )
+%% point*(Q3){P,polar(s,180)} ( 12.5 , 30 )
+%% point*(Q4){P,polar(s,270)} ( 17.5 , 25 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 22.5 30 17.5 35 / %% Q1Q2
+\plot 17.5 35 12.5 30 / %% Q2Q3
+\plot 12.5 30 17.5 25 / %% Q3Q4
+\plot 17.5 25 22.5 30 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(15)
+%% ... start of file <mpicm13.dat> loop(16)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 12 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 555 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 18.40889 , 26.89417 )
+%% drawpoint(P)
+\put {$\bullet$} at 18.40889 26.89417 %% P
+%% drawline(TP)
+\plot 17.5 30 18.40889 26.89417 / %% TP
+%% point*(T){P} ( 18.40889 , 26.89417 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 23.40889 , 26.89417 )
+%% point*(Q2){P,polar(s,90)} ( 18.40889 , 31.89417 )
+%% point*(Q3){P,polar(s,180)} ( 13.40889 , 26.89417 )
+%% point*(Q4){P,polar(s,270)} ( 18.40889 , 21.89417 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 23.40889 26.89417 18.40889 31.89417 / %% Q1Q2
+\plot 18.40889 31.89417 13.40889 26.89417 / %% Q2Q3
+\plot 13.40889 26.89417 18.40889 21.89417 / %% Q3Q4
+\plot 18.40889 21.89417 23.40889 26.89417 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(16)
+%% ... start of file <mpicm13.dat> loop(17)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 11.5 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 570 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 20.04071 , 24.25 )
+%% drawpoint(P)
+\put {$\bullet$} at 20.04071 24.25 %% P
+%% drawline(TP)
+\plot 18.40889 26.89417 20.04071 24.25 / %% TP
+%% point*(T){P} ( 20.04071 , 24.25 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 25.04071 , 24.25 )
+%% point*(Q2){P,polar(s,90)} ( 20.04071 , 29.25 )
+%% point*(Q3){P,polar(s,180)} ( 15.04071 , 24.25 )
+%% point*(Q4){P,polar(s,270)} ( 20.04071 , 19.25 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 25.04071 24.25 20.04071 29.25 / %% Q1Q2
+\plot 20.04071 29.25 15.04071 24.25 / %% Q2Q3
+\plot 15.04071 24.25 20.04071 19.25 / %% Q3Q4
+\plot 20.04071 19.25 25.04071 24.25 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(17)
+%% ... start of file <mpicm13.dat> loop(18)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 11 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 585 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 22.22182 , 22.22183 )
+%% drawpoint(P)
+\put {$\bullet$} at 22.22182 22.22183 %% P
+%% drawline(TP)
+\plot 20.04071 24.25 22.22182 22.22183 / %% TP
+%% point*(T){P} ( 22.22182 , 22.22183 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 27.22182 , 22.22183 )
+%% point*(Q2){P,polar(s,90)} ( 22.22182 , 27.22183 )
+%% point*(Q3){P,polar(s,180)} ( 17.22182 , 22.22183 )
+%% point*(Q4){P,polar(s,270)} ( 22.22182 , 17.22183 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 27.22182 22.22183 22.22182 27.22183 / %% Q1Q2
+\plot 22.22182 27.22183 17.22182 22.22183 / %% Q2Q3
+\plot 17.22182 22.22183 22.22182 17.22183 / %% Q3Q4
+\plot 22.22182 17.22183 27.22182 22.22183 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(18)
+%% ... start of file <mpicm13.dat> loop(19)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 10.5 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 600 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 24.75 , 20.90673 )
+%% drawpoint(P)
+\put {$\bullet$} at 24.75 20.90673 %% P
+%% drawline(TP)
+\plot 22.22182 22.22183 24.75 20.90673 / %% TP
+%% point*(T){P} ( 24.75 , 20.90673 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 29.75 , 20.90673 )
+%% point*(Q2){P,polar(s,90)} ( 24.75 , 25.90673 )
+%% point*(Q3){P,polar(s,180)} ( 19.75 , 20.90673 )
+%% point*(Q4){P,polar(s,270)} ( 24.75 , 15.90673 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 29.75 20.90673 24.75 25.90673 / %% Q1Q2
+\plot 24.75 25.90673 19.75 20.90673 / %% Q2Q3
+\plot 19.75 20.90673 24.75 15.90673 / %% Q3Q4
+\plot 24.75 15.90673 29.75 20.90673 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(19)
+%% ... start of file <mpicm13.dat> loop(20)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 10 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 615 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 27.41181 , 20.34074 )
+%% drawpoint(P)
+\put {$\bullet$} at 27.41181 20.34074 %% P
+%% drawline(TP)
+\plot 24.75 20.90673 27.41181 20.34074 / %% TP
+%% point*(T){P} ( 27.41181 , 20.34074 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 32.41181 , 20.34074 )
+%% point*(Q2){P,polar(s,90)} ( 27.41181 , 25.34074 )
+%% point*(Q3){P,polar(s,180)} ( 22.41181 , 20.34074 )
+%% point*(Q4){P,polar(s,270)} ( 27.41181 , 15.34074 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 32.41181 20.34074 27.41181 25.34074 / %% Q1Q2
+\plot 27.41181 25.34074 22.41181 20.34074 / %% Q2Q3
+\plot 22.41181 20.34074 27.41181 15.34074 / %% Q3Q4
+\plot 27.41181 15.34074 32.41181 20.34074 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(20)
+%% ... start of file <mpicm13.dat> loop(21)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 9.5 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 630 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 30 , 20.5 )
+%% drawpoint(P)
+\put {$\bullet$} at 30 20.5 %% P
+%% drawline(TP)
+\plot 27.41181 20.34074 30 20.5 / %% TP
+%% point*(T){P} ( 30 , 20.5 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 35 , 20.5 )
+%% point*(Q2){P,polar(s,90)} ( 30 , 25.5 )
+%% point*(Q3){P,polar(s,180)} ( 25 , 20.5 )
+%% point*(Q4){P,polar(s,270)} ( 30 , 15.5 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 35 20.5 30 25.5 / %% Q1Q2
+\plot 30 25.5 25 20.5 / %% Q2Q3
+\plot 25 20.5 30 15.5 / %% Q3Q4
+\plot 30 15.5 35 20.5 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(21)
+%% ... start of file <mpicm13.dat> loop(22)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 9 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 645 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 32.32937 , 21.30667 )
+%% drawpoint(P)
+\put {$\bullet$} at 32.32937 21.30667 %% P
+%% drawline(TP)
+\plot 30 20.5 32.32937 21.30667 / %% TP
+%% point*(T){P} ( 32.32937 , 21.30667 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 37.32937 , 21.30667 )
+%% point*(Q2){P,polar(s,90)} ( 32.32937 , 26.30667 )
+%% point*(Q3){P,polar(s,180)} ( 27.32937 , 21.30667 )
+%% point*(Q4){P,polar(s,270)} ( 32.32937 , 16.30667 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 37.32937 21.30667 32.32937 26.30667 / %% Q1Q2
+\plot 32.32937 26.30667 27.32937 21.30667 / %% Q2Q3
+\plot 27.32937 21.30667 32.32937 16.30667 / %% Q3Q4
+\plot 32.32937 16.30667 37.32937 21.30667 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(22)
+%% ... start of file <mpicm13.dat> loop(23)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 8.5 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 660 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 34.25 , 22.63878 )
+%% drawpoint(P)
+\put {$\bullet$} at 34.25 22.63878 %% P
+%% drawline(TP)
+\plot 32.32937 21.30667 34.25 22.63878 / %% TP
+%% point*(T){P} ( 34.25 , 22.63878 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 39.25 , 22.63878 )
+%% point*(Q2){P,polar(s,90)} ( 34.25 , 27.63878 )
+%% point*(Q3){P,polar(s,180)} ( 29.25 , 22.63878 )
+%% point*(Q4){P,polar(s,270)} ( 34.25 , 17.63878 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 39.25 22.63878 34.25 27.63878 / %% Q1Q2
+\plot 34.25 27.63878 29.25 22.63878 / %% Q2Q3
+\plot 29.25 22.63878 34.25 17.63878 / %% Q3Q4
+\plot 34.25 17.63878 39.25 22.63878 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(23)
+%% ... start of file <mpicm13.dat> loop(24)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 8 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 675 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 35.65685 , 24.34315 )
+%% drawpoint(P)
+\put {$\bullet$} at 35.65685 24.34315 %% P
+%% drawline(TP)
+\plot 34.25 22.63878 35.65685 24.34315 / %% TP
+%% point*(T){P} ( 35.65685 , 24.34315 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 40.65685 , 24.34315 )
+%% point*(Q2){P,polar(s,90)} ( 35.65685 , 29.34315 )
+%% point*(Q3){P,polar(s,180)} ( 30.65685 , 24.34315 )
+%% point*(Q4){P,polar(s,270)} ( 35.65685 , 19.34315 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 40.65685 24.34315 35.65685 29.34315 / %% Q1Q2
+\plot 35.65685 29.34315 30.65685 24.34315 / %% Q2Q3
+\plot 30.65685 24.34315 35.65685 19.34315 / %% Q3Q4
+\plot 35.65685 19.34315 40.65685 24.34315 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(24)
+%% ... start of file <mpicm13.dat> loop(25)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 7.5 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 690 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 36.49519 , 26.25 )
+%% drawpoint(P)
+\put {$\bullet$} at 36.49519 26.25 %% P
+%% drawline(TP)
+\plot 35.65685 24.34315 36.49519 26.25 / %% TP
+%% point*(T){P} ( 36.49519 , 26.25 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 41.49519 , 26.25 )
+%% point*(Q2){P,polar(s,90)} ( 36.49519 , 31.25 )
+%% point*(Q3){P,polar(s,180)} ( 31.49519 , 26.25 )
+%% point*(Q4){P,polar(s,270)} ( 36.49519 , 21.25 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 41.49519 26.25 36.49519 31.25 / %% Q1Q2
+\plot 36.49519 31.25 31.49519 26.25 / %% Q2Q3
+\plot 31.49519 26.25 36.49519 21.25 / %% Q3Q4
+\plot 36.49519 21.25 41.49519 26.25 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(25)
+%% ... start of file <mpicm13.dat> loop(26)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 7 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 705 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 36.76148 , 28.18826 )
+%% drawpoint(P)
+\put {$\bullet$} at 36.76148 28.18826 %% P
+%% drawline(TP)
+\plot 36.49519 26.25 36.76148 28.18826 / %% TP
+%% point*(T){P} ( 36.76148 , 28.18826 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 41.76148 , 28.18826 )
+%% point*(Q2){P,polar(s,90)} ( 36.76148 , 33.18826 )
+%% point*(Q3){P,polar(s,180)} ( 31.76148 , 28.18826 )
+%% point*(Q4){P,polar(s,270)} ( 36.76148 , 23.18826 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 41.76148 28.18826 36.76148 33.18826 / %% Q1Q2
+\plot 36.76148 33.18826 31.76148 28.18826 / %% Q2Q3
+\plot 31.76148 28.18826 36.76148 23.18826 / %% Q3Q4
+\plot 36.76148 23.18826 41.76148 28.18826 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(26)
+%% ... start of file <mpicm13.dat> loop(27)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 6.5 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 720 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 36.5 , 30 )
+%% drawpoint(P)
+\put {$\bullet$} at 36.5 30 %% P
+%% drawline(TP)
+\plot 36.76148 28.18826 36.5 30 / %% TP
+%% point*(T){P} ( 36.5 , 30 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 41.5 , 30 )
+%% point*(Q2){P,polar(s,90)} ( 36.5 , 35 )
+%% point*(Q3){P,polar(s,180)} ( 31.5 , 30 )
+%% point*(Q4){P,polar(s,270)} ( 36.5 , 25 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 41.5 30 36.5 35 / %% Q1Q2
+\plot 36.5 35 31.5 30 / %% Q2Q3
+\plot 31.5 30 36.5 25 / %% Q3Q4
+\plot 36.5 25 41.5 30 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(27)
+%% ... start of file <mpicm13.dat> loop(28)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 6 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 735 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 35.79556 , 31.55291 )
+%% drawpoint(P)
+\put {$\bullet$} at 35.79556 31.55291 %% P
+%% drawline(TP)
+\plot 36.5 30 35.79556 31.55291 / %% TP
+%% point*(T){P} ( 35.79556 , 31.55291 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 40.79556 , 31.55291 )
+%% point*(Q2){P,polar(s,90)} ( 35.79556 , 36.55291 )
+%% point*(Q3){P,polar(s,180)} ( 30.79556 , 31.55291 )
+%% point*(Q4){P,polar(s,270)} ( 35.79556 , 26.55291 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 40.79556 31.55291 35.79556 36.55291 / %% Q1Q2
+\plot 35.79556 36.55291 30.79556 31.55291 / %% Q2Q3
+\plot 30.79556 31.55291 35.79556 26.55291 / %% Q3Q4
+\plot 35.79556 26.55291 40.79556 31.55291 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(28)
+%% ... start of file <mpicm13.dat> loop(29)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 5.5 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 750 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 34.76314 , 32.75 )
+%% drawpoint(P)
+\put {$\bullet$} at 34.76314 32.75 %% P
+%% drawline(TP)
+\plot 35.79556 31.55291 34.76314 32.75 / %% TP
+%% point*(T){P} ( 34.76314 , 32.75 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 39.76314 , 32.75 )
+%% point*(Q2){P,polar(s,90)} ( 34.76314 , 37.75 )
+%% point*(Q3){P,polar(s,180)} ( 29.76314 , 32.75 )
+%% point*(Q4){P,polar(s,270)} ( 34.76314 , 27.75 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 39.76314 32.75 34.76314 37.75 / %% Q1Q2
+\plot 34.76314 37.75 29.76314 32.75 / %% Q2Q3
+\plot 29.76314 32.75 34.76314 27.75 / %% Q3Q4
+\plot 34.76314 27.75 39.76314 32.75 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(29)
+%% ... start of file <mpicm13.dat> loop(30)
+%% mPICm13.dat
+%% mathsPIC (spiral data) input by file mPICm13.m
+\typeout{...}%
+%% variable*(r){r,advance(-0.5)} ( 5 ) %% r=r-0.5
+%% variable*(a){a,advance(15)} ( 765 ) %% a=a+15
+%% point*(P){C,polar(r,adeg)} ( 33.53553 , 33.53553 )
+%% drawpoint(P)
+\put {$\bullet$} at 33.53553 33.53553 %% P
+%% drawline(TP)
+\plot 34.76314 32.75 33.53553 33.53553 / %% TP
+%% point*(T){P} ( 33.53553 , 33.53553 ) %% t=p
+%% ... points T & t are the same
+%% make a square on P (s is defined in mPICm-12.m)
+%% point*(Q1){P,polar(s,0)} ( 38.53553 , 33.53553 )
+%% point*(Q2){P,polar(s,90)} ( 33.53553 , 38.53553 )
+%% point*(Q3){P,polar(s,180)} ( 28.53553 , 33.53553 )
+%% point*(Q4){P,polar(s,270)} ( 33.53553 , 28.53553 )
+%% drawline(Q1Q2Q3Q4Q1)
+\plot 38.53553 33.53553 33.53553 38.53553 / %% Q1Q2
+\plot 33.53553 38.53553 28.53553 33.53553 / %% Q2Q3
+\plot 28.53553 33.53553 33.53553 28.53553 / %% Q3Q4
+\plot 33.53553 28.53553 38.53553 33.53553 / %% Q4Q1
+%% ... end of file <mpicm13.dat> loop(30)
+\endpicture
+%%----------------
+%\end{document}
diff --git a/graphics/mathspic/dos/mpicm14.dat b/graphics/mathspic/dos/mpicm14.dat
new file mode 100644
index 0000000000..cca7e1a7b3
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm14.dat
@@ -0,0 +1,30 @@
+%% mpicm14.dat
+%% quartic curve
+%% Q.dat
+\setquadratic
+\plot
+-0.6 3.50
+-0.5 2.37
+-0.4 1.66
+-0.35 1.43
+-0.3 1.26
+-0.25 1.14
+-0.2 1.07
+-0.15 1.03
+-0.1 1.00
+-0.05 1.00
+ 0 1
+ 0.05 0.99
+ 0.15 0.97
+ 0.35 0.74
+ 0.55 0.21
+ 0.75 -0.47
+ 0.80 -0.63
+ 0.85 -0.78
+ 0.95 -0.97
+ 1.0 -1.0
+ 1.05 -0.96
+ 1.15 -0.67
+ 1.25 0.02
+ 1.35 1.24
+ 1.45 3.13 /
diff --git a/graphics/mathspic/dos/mpicm14.m b/graphics/mathspic/dos/mpicm14.m
new file mode 100644
index 0000000000..d6040044b2
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm14.m
@@ -0,0 +1,27 @@
+%% mPICm14.m
+%% quartic curve for mathsPIC manual
+\documentclass[a4paper]{article}
+\usepackage{pictexwd}
+\begin{document}
+%-----------------
+\beginpicture
+\linethickness=1pt %% make a thick line for the axes
+paper{units(3cm,cm),xrange(-1,2),yrange(-2,4),axes(XY),ticks(1,1)}
+\linethickness=0.4pt %% reset to default value
+\headingtoplotskip=8mm
+\plotheading{\fbox{\Large A quartic equation}}
+inputfile*(mpicm14.dat) % inputting file containing data points for curve
+variable(r){0.3} % define a line-free radius r=0.3 for points
+point(E1){1,3.5}[,r]
+text($f(x)=6x^4 - 8x^3 + 1$){E1} % center the equation at E1
+point(E2){1.4,2}[,r]
+drawarrow(E1E2)
+point(J1){0.55,2}[,r]
+text(inflection points){J1} % center inflection text at J1
+point(J2){0,1}[,r]
+point(J3){0.6,0}[,r]
+drawarrows(J1J2,J1J3)
+\endpicture
+%-----------------
+\end{document}
+
diff --git a/graphics/mathspic/dos/mpicm14.pic b/graphics/mathspic/dos/mpicm14.pic
new file mode 100644
index 0000000000..13c29b634d
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm14.pic
@@ -0,0 +1,79 @@
+%* -------------------------------------------
+%* mathsPIC 2.1
+%* Copyright (c) RWD Nickalls 1999-2000
+%* Email: dicknickalls@compuserve.com
+%* Date (m/d/y) : 11-05-2000 21:13:42
+%* Command Line: /b/s MPICM14.M
+%* Input Filename: MPICM14.M
+%* Output Filename: MPICM14.MT
+%* -------------------------------------------
+%% mPICm14.m
+%% quartic curve for mathsPIC manual
+%\documentclass[a4paper]{article}
+%\usepackage{pictexwd}
+%\begin{document}
+%-----------------
+\beginpicture
+\linethickness=1pt %% make a thick line for the axes
+%% paper{units(3cm,cm),xrange(-1,2),yrange(-2,4),axes(XY),ticks(1,1)}
+\setcoordinatesystem units < 3cm, 1cm>
+%% ... note: xunits & yunits are different
+\setplotarea x from -1 to 2, y from -2 to 4
+\axis left shiftedto x=0 ticks numbered from -2 to -1 by 1
+ from 1 to 4 by 1 /
+\axis bottom shiftedto y=0 ticks numbered from -1 to -1 by 1
+ from 1 to 2 by 1 /
+\linethickness=0.4pt %% reset to default value
+\headingtoplotskip=8mm
+\plotheading{\fbox{\Large A quartic equation}}
+%% inputfile*(mpicm14.dat) % inputting file containing data points for curve
+%% ... start of file <mpicm14.dat>
+%% mpicm14.dat
+%% quartic curve
+%% Q.dat
+\setquadratic
+\plot
+-0.6 3.50
+-0.5 2.37
+-0.4 1.66
+-0.35 1.43
+-0.3 1.26
+-0.25 1.14
+-0.2 1.07
+-0.15 1.03
+-0.1 1.00
+-0.05 1.00
+ 0 1
+ 0.05 0.99
+ 0.15 0.97
+ 0.35 0.74
+ 0.55 0.21
+ 0.75 -0.47
+ 0.80 -0.63
+ 0.85 -0.78
+ 0.95 -0.97
+ 1.0 -1.0
+ 1.05 -0.96
+ 1.15 -0.67
+ 1.25 0.02
+ 1.35 1.24
+ 1.45 3.13 /
+%% ... end of file <mpicm14.dat>
+%% variable(r){0.3} ( .3 ) % define a line-free radius r=0.3 for points
+%% point(E1){1,3.5}[,r] ( 1 , 3.5 )
+%% text($f(x)=6x^4 - 8x^3 + 1$){E1} % center the equation at E1
+\put {$f(x)=6x^4 - 8x^3 + 1$} at 1 3.5
+%% point(E2){1.4,2}[,r] ( 1.4 , 2 )
+%% drawarrow(E1E2)
+\arrow < 2mm> [ .2679492, .7279404] from 1.077299 3.210129 to 1.322701 2.289871
+%% point(J1){0.55,2}[,r] ( .55 , 2 )
+%% text(inflection points){J1} % center inflection text at J1
+\put {inflection points} at .55 2
+%% point(J2){0,1}[,r] ( 0 , 1 )
+%% point(J3){0.6,0}[,r] ( .6 , 0 )
+%% drawarrows(J1J2,J1J3)
+\arrow < 2mm> [ .2679492, .7279404] from .4054244 1.737135 to .1445756 1.262865
+\arrow < 2mm> [ .2679492, .7279404] from .5574977 1.700094 to .5925024 .2999063
+\endpicture
+%-----------------
+%\end{document}
diff --git a/graphics/mathspic/dos/mpicm15.m b/graphics/mathspic/dos/mpicm15.m
new file mode 100644
index 0000000000..bb6896e9a1
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm15.m
@@ -0,0 +1,35 @@
+%% mpicm15.m
+%% mathsPIC
+\documentclass[a4paper]{article}
+\usepackage{pictexwd,amssymb}
+\begin{document}
+\beginpicture
+%----------------
+paper{units(cm),xrange(0,6),yrange(73,77),axes(LBT*R*),ticks(1,1)}
+variable(r){0.2} %% linefree radius
+pointsymbol($\odot$)
+point(d1){1, 76.2}[,r]
+point(d2){2, 76.2}[,r]
+point(d3){3, 75.5}[,r]
+point(d4){4, 75.7}[,r]
+point(d5){5, 74.6}[,r]
+drawpoints(d1d2d3d4d5)
+drawline(d1d2d3d4d5)
+%
+pointsymbol($\boxdot$)
+point(k1){1, 75.2}[,r]
+point(k2){2, 75.4}[,r]
+point(k3){3, 74.8}[,r]
+point(k4){4, 74.1}[,r]
+point(k5){5, 74.0}[,r]
+drawpoints(k1k2k3k4k5)
+\setdashpattern <2pt, 2pt>
+drawline(k1k2k3k4k5)
+%
+\plotheading{\textsf{\Large Weight change with diet}}
+text(\shortstack{\textsf{\large Weight}\\($kg$)}){-1.5,75.3}
+text(\textsf{\large Days}){3,72}
+\endpicture
+\end{document}
+
+
diff --git a/graphics/mathspic/dos/mpicm15.pic b/graphics/mathspic/dos/mpicm15.pic
new file mode 100644
index 0000000000..19bac0dbf3
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm15.pic
@@ -0,0 +1,68 @@
+%* -------------------------------------------
+%* mathsPIC 2.1
+%* Copyright (c) RWD Nickalls 1999-2000
+%* Email: dicknickalls@compuserve.com
+%* Date (m/d/y) : 11-05-2000 21:14:59
+%* Command Line: /b/s MPICM15.M
+%* Input Filename: MPICM15.M
+%* Output Filename: MPICM15.MT
+%* -------------------------------------------
+%% mpicm15.m
+%% mathsPIC
+%\documentclass[a4paper]{article}
+%\usepackage{pictexwd,amssymb}
+%\begin{document}
+\beginpicture
+%----------------
+%% paper{units(cm),xrange(0,6),yrange(73,77),axes(LBT*R*),ticks(1,1)}
+\setcoordinatesystem units < 1cm, 1cm>
+\setplotarea x from 0 to 6, y from 73 to 77
+\axis left ticks numbered from 73 to 77 by 1 /
+\axis right /
+\axis top /
+\axis bottom ticks numbered from 0 to 6 by 1 /
+%% variable(r){0.2} ( .2 ) %% linefree radius
+%% pointsymbol($\odot$)
+%% point(d1){1,76.2}[,r] ( 1 , 76.2 )
+%% point(d2){2,76.2}[,r] ( 2 , 76.2 )
+%% point(d3){3,75.5}[,r] ( 3 , 75.5 )
+%% point(d4){4,75.7}[,r] ( 4 , 75.7 )
+%% point(d5){5,74.6}[,r] ( 5 , 74.6 )
+%% drawpoints(d1d2d3d4d5)
+\put {$\odot$} at 1 76.2 %% d1
+\put {$\odot$} at 2 76.2 %% d2
+\put {$\odot$} at 3 75.5 %% d3
+\put {$\odot$} at 4 75.7 %% d4
+\put {$\odot$} at 5 74.6 %% d5
+%% drawline(d1d2d3d4d5)
+\putrule from 1.2 76.2 to 1.8 76.2 %% d1d2
+\plot 2.163847 76.0853 2.836153 75.61469 / %% d2d3
+\plot 3.196116 75.53922 3.803884 75.66077 / %% d3d4
+\plot 4.134535 75.55201 4.865465 74.74799 / %% d4d5
+%
+%% pointsymbol($\boxdot$)
+%% point(k1){1,75.2}[,r] ( 1 , 75.2 )
+%% point(k2){2,75.4}[,r] ( 2 , 75.4 )
+%% point(k3){3,74.8}[,r] ( 3 , 74.8 )
+%% point(k4){4,74.1}[,r] ( 4 , 74.1 )
+%% point(k5){5,74.0}[,r] ( 5 , 74 )
+%% drawpoints(k1k2k3k4k5)
+\put {$\boxdot$} at 1 75.2 %% k1
+\put {$\boxdot$} at 2 75.4 %% k2
+\put {$\boxdot$} at 3 74.8 %% k3
+\put {$\boxdot$} at 4 74.1 %% k4
+\put {$\boxdot$} at 5 74 %% k5
+\setdashpattern <2pt, 2pt>
+%% drawline(k1k2k3k4k5)
+\plot 1.196116 75.23922 1.803884 75.36078 / %% k1k2
+\plot 2.171499 75.2971 2.828501 74.9029 / %% k2k3
+\plot 3.163846 74.68531 3.836154 74.21469 / %% k3k4
+\plot 4.199008 74.0801 4.800992 74.0199 / %% k4k5
+%
+\plotheading{\textsf{\Large Weight change with diet}}
+%% text(\shortstack{\textsf{\large Weight}\\($kg$)}){-1.5,75.3}
+\put {\shortstack{\textsf{\large Weight}\\($kg$)}} at -1.5 75.3
+%% text(\textsf{\large Days}){3,72}
+\put {\textsf{\large Days}} at 3 72
+\endpicture
+%\end{document}
diff --git a/graphics/mathspic/dos/mpicm16.m b/graphics/mathspic/dos/mpicm16.m
new file mode 100644
index 0000000000..a100ce62c5
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm16.m
@@ -0,0 +1,84 @@
+\documentclass[a4paper]{article}
+\usepackage{pictexwd}
+\begin{document}
+% new mpicm16.m (figure 16)
+%
+% Changed lines are marked with "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
+% on the right
+%
+\beginpicture
+variable(U){12} %% units = 12 mm
+paper{units(Umm),xRange(0.5,8.5),yRange(-0.5,5.5)}
+variable(r){0.7} %% line-free radius of \circ (0.7mm)
+variable*(r){r, divide(U)} %% line free radius scaled for U mm
+pointsymbol($\circ$,r)
+Point(A){1,1}
+Point(B){2,4}
+Point(C){5,3}
+Point(D){6,0}
+Point(E){8,2}
+Point(F){8,5}
+Point(G){3,0}
+pointsymbol(default) %% restore $\bullet$
+%
+Point(A1){midpoint(AB)}
+Point(B1){midpoint(BC)}
+Point(C1){midpoint(CD)}
+Point(D1){midpoint(DE)}
+Point(E1){midpoint(EF)}
+Point(F1){midpoint(FG)}
+Point(G1){midpoint(GA)}
+%
+Point(A2){midpoint(G1A1)}
+Point*(A2){midpoint(AA2)}
+Point(B2){midpoint(A1B1)}
+Point*(B2){midpoint(BB2)}
+Point(C2){midpoint(B1C1)}
+Point*(C2){midpoint(CC2)}
+Point(D2){midpoint(C1D1)}
+Point*(D2){midpoint(DD2)}
+Point(E2){midpoint(D1E1)}
+Point*(E2){midpoint(EE2)}
+Point(F2){midpoint(E1F1)}
+Point*(F2){midpoint(FF2)}
+Point(G2){midpoint(F1G1)}
+Point*(G2){midpoint(GG2)}
+%
+DrawPoints(ABCDEFG)
+DrawPoints(A1B1C1D1E1F1G1)
+DrawPoints(A2B2C2D2E2F2G2)
+%
+DrawLine(ABCDEFGA)
+\setplotsymbol ({\Large.})
+DrawCurve(A1B2B1)
+DrawCurve(B1C2C1)
+DrawCurve(C1D2D1)
+DrawCurve(D1E2E1)
+DrawCurve(E1F2F1)
+DrawCurve(F1G2G1)
+DrawCurve(G1A2A1)
+%
+Text($A$){A,shift(-.2,0)}
+Text($B$){B,shift(-.2,.1)}
+Text($C$){C,shift(0,.25)}
+Text($D$){D,shift(0,-.25)}
+Text($E$){E,shift(.2,0)}
+Text($F$){F,shift(0,.25)}
+Text($G$){G,shift(0,-.25)}
+\scriptsize
+Text($A_1$){A1,shift(.25,0)}
+Text($B_1$){B1,shift(0,-.2)}
+Text($C_1$){C1,shift(.25,0)}
+Text($D_1$){D1,shift(-.2,.15)} % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+Text($E_1$){E1,shift(-.2,0)}
+Text($F_1$){F1,shift(.15,-.15)}
+Text($G_1$){G1,shift(.1,.2)}
+Text($A_2$){A2,shift(.25,0)}
+Text($B_2$){B2,shift(.1,-.2)}
+Text($C_2$){C2,shift(-.1,-.15)}
+Text($D_2$){D2,shift(.1,.2)}
+Text($E_2$){E2,shift(-.25,.05)} % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+Text($F_2$){F2,shift(.05,-.2)} % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+Text($G_2$){G2,shift(0,.25)} % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\endpicture
+\end{document}
diff --git a/graphics/mathspic/dos/mpicm16.pic b/graphics/mathspic/dos/mpicm16.pic
new file mode 100644
index 0000000000..d018456a7a
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm16.pic
@@ -0,0 +1,176 @@
+%* -------------------------------------------
+%* mathsPIC 2.1
+%* Copyright (c) RWD Nickalls 1999-2000
+%* Email: dicknickalls@compuserve.com
+%* Date (m/d/y) : 11-05-2000 21:16:17
+%* Command Line: /b/s MPICM16.M
+%* Input Filename: MPICM16.M
+%* Output Filename: MPICM16.MT
+%* -------------------------------------------
+%% mpicm16.m (figure 16)
+%\documentclass[a4paper]{article}
+%\usepackage{pictexwd}
+%\begin{document}
+%
+\beginpicture
+%% variable(U){12} ( 12 ) %% units = 12 mm
+%% paper{units(Umm),xRange(0.5,8.5),yRange(-0.5,5.5)}
+\setcoordinatesystem units < 12mm, 12mm>
+\setplotarea x from .5 to 8.5, y from -.5 to 5.5
+%% variable(r){0.7} ( .7 ) %% line-free radius of \circ (0.7mm)
+%% variable*(r){r,divide(U)} ( 5.833333E-2 ) %% line free radius scaled for U mm
+%% pointsymbol($\circ$,r)
+%% Point(A){1,1} ( 1 , 1 )
+%% Point(B){2,4} ( 2 , 4 )
+%% Point(C){5,3} ( 5 , 3 )
+%% Point(D){6,0} ( 6 , 0 )
+%% Point(E){8,2} ( 8 , 2 )
+%% Point(F){8,5} ( 8 , 5 )
+%% Point(G){3,0} ( 3 , 0 )
+%% pointsymbol(default) %% restore $\bullet$
+%
+%% Point(A1){midpoint(AB)} ( 1.5 , 2.5 )
+%% Point(B1){midpoint(BC)} ( 3.5 , 3.5 )
+%% Point(C1){midpoint(CD)} ( 5.5 , 1.5 )
+%% Point(D1){midpoint(DE)} ( 7 , 1 )
+%% Point(E1){midpoint(EF)} ( 8 , 3.5 )
+%% Point(F1){midpoint(FG)} ( 5.5 , 2.5 )
+%% Point(G1){midpoint(GA)} ( 2 , .5 )
+%
+%% Point(A2){midpoint(G1A1)} ( 1.75 , 1.5 )
+%% Point*(A2){midpoint(AA2)} ( 1.375 , 1.25 )
+%% Point(B2){midpoint(A1B1)} ( 2.5 , 3 )
+%% Point*(B2){midpoint(BB2)} ( 2.25 , 3.5 )
+%% Point(C2){midpoint(B1C1)} ( 4.5 , 2.5 )
+%% Point*(C2){midpoint(CC2)} ( 4.75 , 2.75 )
+%% Point(D2){midpoint(C1D1)} ( 6.25 , 1.25 )
+%% Point*(D2){midpoint(DD2)} ( 6.125 , .625 )
+%% Point(E2){midpoint(D1E1)} ( 7.5 , 2.25 )
+%% Point*(E2){midpoint(EE2)} ( 7.75 , 2.125 )
+%% Point(F2){midpoint(E1F1)} ( 6.75 , 3 )
+%% Point*(F2){midpoint(FF2)} ( 7.375 , 4 )
+%% Point(G2){midpoint(F1G1)} ( 3.75 , 1.5 )
+%% Point*(G2){midpoint(GG2)} ( 3.375 , .75 )
+%
+%% DrawPoints(ABCDEFG)
+\put {$\circ$} at 1 1 %% A
+\put {$\circ$} at 2 4 %% B
+\put {$\circ$} at 5 3 %% C
+\put {$\circ$} at 6 0 %% D
+\put {$\circ$} at 8 2 %% E
+\put {$\circ$} at 8 5 %% F
+\put {$\circ$} at 3 0 %% G
+%% DrawPoints(A1B1C1D1E1F1G1)
+\put {$\bullet$} at 1.5 2.5 %% A1
+\put {$\bullet$} at 3.5 3.5 %% B1
+\put {$\bullet$} at 5.5 1.5 %% C1
+\put {$\bullet$} at 7 1 %% D1
+\put {$\bullet$} at 8 3.5 %% E1
+\put {$\bullet$} at 5.5 2.5 %% F1
+\put {$\bullet$} at 2 .5 %% G1
+%% DrawPoints(A2B2C2D2E2F2G2)
+\put {$\bullet$} at 1.375 1.25 %% A2
+\put {$\bullet$} at 2.25 3.5 %% B2
+\put {$\bullet$} at 4.75 2.75 %% C2
+\put {$\bullet$} at 6.125 .625 %% D2
+\put {$\bullet$} at 7.75 2.125 %% E2
+\put {$\bullet$} at 7.375 4 %% F2
+\put {$\bullet$} at 3.375 .75 %% G2
+%
+%% DrawLine(ABCDEFGA)
+\plot 1.018447 1.05534 1.981553 3.94466 / %% AB
+\plot 2.05534 3.981553 4.94466 3.018447 / %% BC
+\plot 5.018446 2.94466 5.981554 +0.05533986 / %% CD
+\plot 6.041248 .0412479 7.958752 1.958752 / %% DE
+\putrule from 8 2.058333 to 8 4.941667 %% EF
+\plot 7.958752 4.958752 3.041248 .0412479 / %% FG
+\plot 2.947825 +0.02608746 1.052175 .9739125 / %% GA
+\setplotsymbol ({\Large.})
+%% DrawCurve(A1B2B1)
+\setquadratic
+\plot 1.5 2.5 %% A1
+ 2.25 3.5 %% B2
+ 3.5 3.5 / %% B1
+\setlinear
+%% DrawCurve(B1C2C1)
+\setquadratic
+\plot 3.5 3.5 %% B1
+ 4.75 2.75 %% C2
+ 5.5 1.5 / %% C1
+\setlinear
+%% DrawCurve(C1D2D1)
+\setquadratic
+\plot 5.5 1.5 %% C1
+ 6.125 .625 %% D2
+ 7 1 / %% D1
+\setlinear
+%% DrawCurve(D1E2E1)
+\setquadratic
+\plot 7 1 %% D1
+ 7.75 2.125 %% E2
+ 8 3.5 / %% E1
+\setlinear
+%% DrawCurve(E1F2F1)
+\setquadratic
+\plot 8 3.5 %% E1
+ 7.375 4 %% F2
+ 5.5 2.5 / %% F1
+\setlinear
+%% DrawCurve(F1G2G1)
+\setquadratic
+\plot 5.5 2.5 %% F1
+ 3.375 .75 %% G2
+ 2 .5 / %% G1
+\setlinear
+%% DrawCurve(G1A2A1)
+\setquadratic
+\plot 2 .5 %% G1
+ 1.375 1.25 %% A2
+ 1.5 2.5 / %% A1
+\setlinear
+%
+%% text($A$){A,shift(-.2,0)}
+\put {$A$} at .8 1
+%% text($B$){B,shift(-.2,.1)}
+\put {$B$} at 1.8 4.1
+%% text($C$){C,shift(0,.25)}
+\put {$C$} at 5 3.25
+%% text($D$){D,shift(0,-.25)}
+\put {$D$} at 6 -.25
+%% text($E$){E,shift(.2,0)}
+\put {$E$} at 8.2 2
+%% text($F$){F,shift(0,.25)}
+\put {$F$} at 8 5.25
+%% text($G$){G,shift(0,-.25)}
+\put {$G$} at 3 -.25
+\scriptsize
+%% text($A_1$){A1,shift(.25,0)}
+\put {$A_1$} at 1.75 2.5
+%% text($B_1$){B1,shift(0,-.2)}
+\put {$B_1$} at 3.5 3.3
+%% text($C_1$){C1,shift(.25,0)}
+\put {$C_1$} at 5.75 1.5
+%% text($D_1$){D1,shift(-.2,.15)} %
+\put {$D_1$} at 6.8 1.15
+%% text($E_1$){E1,shift(-.2,0)}
+\put {$E_1$} at 7.8 3.5
+%% text($F_1$){F1,shift(.15,-.15)}
+\put {$F_1$} at 5.65 2.35
+%% text($G_1$){G1,shift(.1,.2)}
+\put {$G_1$} at 2.1 .7
+%% text($A_2$){A2,shift(.25,0)}
+\put {$A_2$} at 1.625 1.25
+%% text($B_2$){B2,shift(.1,-.2)}
+\put {$B_2$} at 2.35 3.3
+%% text($C_2$){C2,shift(-.1,-.15)}
+\put {$C_2$} at 4.65 2.6
+%% text($D_2$){D2,shift(.1,.2)}
+\put {$D_2$} at 6.225 .825
+%% text($E_2$){E2,shift(-.25,.05)} %
+\put {$E_2$} at 7.5 2.175
+%% text($F_2$){F2,shift(.05,-.2)} %
+\put {$F_2$} at 7.425 3.8
+%% text($G_2$){G2,shift(0,.25)} %
+\put {$G_2$} at 3.375 1
+\endpicture
+%\end{document}
diff --git a/graphics/mathspic/dos/mpicm21.dvi b/graphics/mathspic/dos/mpicm21.dvi
new file mode 100644
index 0000000000..78ca23000c
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm21.dvi
Binary files differ
diff --git a/graphics/mathspic/dos/mpicm21.pdf b/graphics/mathspic/dos/mpicm21.pdf
new file mode 100644
index 0000000000..3a2771f300
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm21.pdf
Binary files differ
diff --git a/graphics/mathspic/dos/mpicm21.tex b/graphics/mathspic/dos/mpicm21.tex
new file mode 100644
index 0000000000..4ece3dfe02
--- /dev/null
+++ b/graphics/mathspic/dos/mpicm21.tex
@@ -0,0 +1,4373 @@
+
+%%-----------------------------
+%% File name = mPICm21.tex
+%% manual for mathsPIC 2.1 (PowerBASIC/DOS version)
+%%
+%% Copyright (c) RWD Nickalls November 5th, 2000
+%% RWD Nickalls,
+%% Department of Anaesthesia,
+%% City Hospital, Nottingham, UK.
+%% email: dicknickalls@compuserve.com
+%%
+%% The mathsPIC program is released under the terms of the
+%% General Public License as published by
+%% the Free Software Foundation; either version 2
+%% of the license or later.
+%%
+%% MathsPIC is distributed without any warranty or
+%% implied warranty of merchantability or fitness for a
+%% particular purpose. See the General Public License
+%% for more details.
+%%
+%%----------------------------------------------
+\documentclass[a4paper]{article}
+\usepackage{geometry} \geometry{hscale=0.75,vscale=0.85}
+\usepackage{pictexwd} % new pictex style option by Andreas Schrell (1994)
+\usepackage{amssymb} % for symbols in Table 1
+\usepackage{fancyhdr}
+%% pictexwd is available from CTAN\tex-archive\graphics\pictex\addon
+
+%%------ mathsPIC and PiCTeX macros -----------
+\newcommand{\mathsPIC}{\textsf{mathsPIC}}
+\newcommand{\MathsPIC}{\textsf{MathsPIC}}
+\newcommand{\bs}{$\backslash$}
+\newcommand{\gap}{\protect\texttt{\char'40}\protect} %% the <space> symbol
+
+%%---------some table macros-------------
+\newcommand{\tstrut}{\rule{0pt}{12pt}} % for top line
+\newcommand{\mstrut}{\rule{0pt}{12pt}} % middle lines
+\newcommand{\bstrut}{\rule{0pt}{12pt}} % bottom lines
+%%-------------------- start of document -------------------
+
+\begin{document}
+\thispagestyle{empty}
+
+\vspace*{1cm}
+\bigskip\bigskip\bigskip
+\hrule \medskip
+\begin{flushleft}
+ \hspace*{3cm}{\huge \mathsPIC\Large\ 2.1} \\
+ \end{flushleft}
+
+\medskip
+\hrule
+
+\vspace{3cm}
+
+\begin{flushright}
+\large
+ Richard W.\ D.\ Nickalls,\\
+ Department of Anaesthesia,\\
+ City Hospital, Nottingham, UK. \\
+ \textit{dicknickalls@compuserve.com}\\
+ Tel: +44-(0)115-9691169\\
+ Fax: +44-(0)115-9627713\\
+
+ {\ } \\
+ November 5th, 2000
+ \end{flushright}
+%%--------------------------
+ \vspace{4cm}
+
+
+\newpage %{\ }\cleardoublepage
+\vspace*{7cm}
+
+
+\begin{center}
+ Copyright {\copyright} RWD Nickalls 1999--2000
+\end{center}
+
+\begin{center}
+\begin{minipage}{10cm}
+ {\mathsPIC} is released under the terms of the
+ General Public License as published by
+ the Free Software Foundation; either version~2
+ of the license or later.
+ {\MathsPIC} is distributed without any warranty or
+ implied warranty of merchantability or fitness for a
+ particular purpose. See the General Public License
+ for more details.
+\end{minipage}
+\end{center}
+
+\newpage
+
+%---------------------------
+\tableofcontents
+
+\cleardoublepage
+
+%%------------------------------------
+\pagestyle{fancy}
+\fancyfoot{}
+\fancyhead{}
+\fancyhead[L]{\Large\mathsPIC\large\ 2.1}
+\fancyhead[R]{\thepage}
+%%-----------------------------------
+
+\section{Introduction}
+
+{\MathsPIC}\footnote{{\mathsPIC}
+(\texttt{CTAN:/tex-archive/graphics/pictex/mathspic/})
+was first presented at the
+Euro{\TeX}'99 conference in Heidelberg, Germany. It is a free MS-DOS
+program (150 KB) compatible with MS-Windows 9x, 2000, NT.}
+ is a small filter program for use with the excellent free
+{\PiCTeX} drawing
+engine\footnote{\texttt{CTAN:/tex-archive/graphics/pictex/addon/}.
+The files input using \texttt{pictexwd.sty} total only 138 KB.
+See Section~9 for details.}
+(Nickalls, 1999a, 1999b; Syropoulos and Nickalls, 2000).
+ {\MathsPIC} parses a plain text input-file (the {\mathsPIC} file),
+ and generates a plain text output-file
+ containing {\PiCTeX} and \TeX\ commands
+ which can then be {\TeX}ed (or {\LaTeX}ed) in the usual way.
+ Spaces and the comment \texttt{\%} symbol are used in the same way as
+ \TeX, although unlike \TeX, {\mathsPIC} commands
+are \textit{not} case-sensitive. {\PiCTeX}, \TeX\ and \LaTeX\
+commands can all be freely used in the {mathsPIC} file.
+ {\MathsPIC} also returns various parameter values in
+ the output-file, e.g.\ angles, distances between points,
+center and radius of inscribed and
+exscribed circles, areas of triangles etc., since such values can be
+useful when making adjustments to a diagram.
+
+
+The motivation for {\mathsPIC} stems from the fact that, while
+{\PiCTeX} is an extremely versatile system for drawing
+figures, and offers the convenience and advantages of
+having the graphics code within the \TeX\
+ document itself (e.g.\ printer-independence),
+it does require you to specify the coordinates
+of most points. This can make {\PiCTeX} quite
+awkward to use with complicated diagrams, particularly
+if several coordinates have to be
+re-calculated manually each time the diagram is adjusted.
+ For example, suppose it is necessary to draw
+a triangle $ABC$ with $AB$ 5 cm, $AC$ 3 cm, and included
+angle $BAC$ 40 degrees, together with its incircle.
+One such triangle is shown in Figure~1, and the
+{\PiCTeX} commands for drawing it are as follows
+(the units are in cm).
+
+
+%%------------Figure 1-----------------
+%% triangle with incircle
+\begin{figure}[hbt]
+\begin{center}
+ %% small triangle with incircle
+ \strut\input{mPICm01.pic}
+ \vspace{-4mm} %% raise position of caption %%
+ \caption{\ }
+\end{center}
+\end{figure}
+%-----------------------
+
+\vspace{-5mm}
+
+\begin{verbatim}
+\put {$\bullet$} at 0 0 % draw point A
+\put {$\bullet$} at 4.924039 0.8682409 % draw point B
+\put {$\bullet$} at 1.928363 2.298133 % draw point C
+\plot 0 0 4.924039 0.8682409 1.928363 2.298133 0 0/ % draw triangle
+\circulararc 360 degrees from 3.008607 1.245238 center at 2.156815 1.245238
+\put {$A$} at -0.5 0
+\put {$B$} at 5.424039 .8682409
+\put {$C$} at 1.428363 2.298133
+\end{verbatim}
+
+
+Although point $A$ can be placed at the origin for
+convenience it is then necessary to resort to geometry
+and a calculator to determine points $B$ and $C$,
+since $AB$, $AC$, and the included angle are defined (see above).
+ It is then necessary to recall the coordinates of all the points
+in order to write the \verb!\plot! command.
+Finally, the \verb!\circulararc! command requires
+even more geometry and calculation to figure out the radius of
+the incircle, the coordinates of its center, and the
+coordinates of the starting point of the arc-drawing routine.
+ Furthermore, if the initial diagram is not a suitable shape
+or size, the calculator has to be used again for any adjustments.
+ In practice, therefore, {\PiCTeX} requires a certain
+amount of planning and calculation for all but the
+simplest of diagrams.
+
+
+{\MathsPIC} overcomes all these difficulties by
+providing an environment for manipulating named points and
+scalar variables,
+which has the effect of making even complicated
+ mathematical diagrams very easy to create.
+ For example, the equivalent {\mathsPIC}
+commands for drawing Figure~1 are as follows (the units are in
+cm as before).
+
+
+\begin{verbatim}
+point(A){0,0} % point A at origin
+point(B){A,polar(5,10 deg)} % point B 5 cm from A; AB slope 10 deg
+point(C){A,polar(3,50 deg)} % point C 3 cm from A; BAC = 40 deg
+drawPoint(ABC) % put $\bullet$ at points A B C
+drawTriangle(ABC)
+drawIncircle(ABC)
+variable(d){0.5} % d = 0.5 cm
+text($A$){A, shift(-d,0)} % label for A
+text($B$){B, shift(d,0)} % label for B
+text($C$){C, shift(-d,0)} % label for C
+\end{verbatim}
+
+
+{\MathsPIC} facilitates the drawing of
+{\PiCTeX} diagrams because not only does it allow points
+to be defined in terms of other points (relative addressing),
+but it also allows the use of scalar variables which can be
+manipulated mathematically (see Section~4.5).
+Consequently, diagrams can be constructed in an intuitive
+way, much as one might with a compass and ruler; for example,
+constructing a point at a certain position in order to allow
+some other point to be constructed, perhaps to draw a line to.
+In other words, {\mathsPIC} offers the freedom to create
+`hidden' points having a sort of scaffolding function.
+ In particular, this facility allows diagrams to be
+constructed in such a way that they remain functionally
+connected even when points are moved (see Section~7.5).
+Files can also be input recursively (see Section~7.6).
+A significant feature of {\mathsPIC} is that it
+allows TeX macros to be easily used within the {\mathsPIC} file.
+
+Note that {\mathsPIC} can also be viewed as a handy tool
+for exploring elementary geometry since its \texttt{show} commands
+return the values of various parameters;
+for example, angles, the distance between points,
+coordinates of derived points, areas of triangles etc.
+
+
+A PERL version of {\mathsPIC} is currently being developed
+(Syropoulos and Nickalls, 2000), and should be available in 2001
+(see Section~11).
+
+
+
+%%---------------------------
+\section{Installing {\mathsPIC}}
+
+\texttt{CTAN:/tex-archive/graphics/pictex/mathspic/}
+
+{\mathsPIC} can be downloaded from the above directory at CTAN
+(Comprehensive \TeX\ Archive Network).
+See the file \texttt{readme.txt}.
+ When installing \PiCTeX\ (see Section~9) I would recommend using
+the new \PiCTeX\ files by Andreas Schrell (1994), namely
+\verb!pictexwd.sty! (for \LaTeX\ users) and \verb!pictexwd.tex!
+(for plain \TeX\ users).
+
+%-----
+\subsection{The program}
+
+\begin{verbatim}
+mpic21.exe (rename to mathspic.exe)
+\end{verbatim}
+
+The executable program \verb!mpic21.exe! was compiled
+on an MS-DOS 6.2 platform. It is compatible with
+WINDOWS 9x, 2000, NT.
+For the purposes of this manual it is suggested that
+\verb!mpic21.exe! be renamed to
+\verb!mathspic.exe!. The executable program
+must be either in the same directory as the {\mathsPIC} input-file,
+or in the directory path.
+
+
+
+%------
+\subsection{Optional utilities}
+
+\begin{verbatim}
+show.com (a DOS textviewer)
+clean.exe (a DOS tool for deleting comment lines)
+\end{verbatim}
+
+
+ These two files should be placed in the same directory as
+ \verb!mathspic.exe!.
+\verb!clean.exe! is a program for removing all the
+commented lines from the output-file (see
+Section~3.2 for details). \verb!show.com! is a simple
+textviewer which can be invoked using the /s switch (see
+Section~3.1.2 for details).
+
+%-------
+\subsection{The manual}
+
+\begin{verbatim}
+mpicm21.tex
+mpicm21.dvi
+mpicm21.ps
+mpicm21.pdf
+mpicm01.pic - mpicm16.pic
+\end{verbatim}
+
+The 16 figure files \texttt{mpicm01.pic}---\texttt{mpicm16.pic}
+are input by \verb!mpicm21.tex!.
+Note that all the {\mathsPIC} files for these figures
+(\texttt{mpicm01.m}---\texttt{mpicm16.m})
+are also included in the package---users are free to experiment
+with them as they wish.
+
+
+
+%---------
+\subsection{Examples}
+
+The file \texttt{examples} is a collection of
+example figures and corresponding {\mathsPIC} code.
+
+
+%%----------------------------
+\section{Running {\mathsPIC}}
+\subsection{Command-line syntax}
+
+Assuming the \verb!.exe! file has been renamed
+to \verb!mathspic.exe!, then
+the minimum command-line instruction requires only the name of
+an input-file as follows.
+
+\begin{verbatim}
+mathspic inputfile
+\end{verbatim}
+
+This will result in \verb!mathspic! generating an output-file (in
+the same directory) with
+the same filename but with a \verb!.mt! filename extension (see
+below for options), and a log-file (\verb!.mlg!).
+
+While {\mathsPIC} is running, its progress is documented on the
+screen by a series of dots (one dot per program line). If an
+error is encounted then this is shown as an E instead of a
+dot, as follows.
+
+\begin{verbatim}
+.................E....EE..........
+\end{verbatim}
+
+
+\subsubsection{Files}
+{\MathsPIC} actions only the first two filenames (any additional
+filenames are ignored).
+ Each filename must be isolated by at
+least one space. The order is important; the first filename is
+actioned as the \verb!inputfile! (the {\mathsPIC} file);
+the second filename (if present) is actioned as the \verb!outputfile!.
+
+
+\begin{verbatim}
+mathspic inputfile outputfile
+\end{verbatim}
+
+
+If the \texttt{outputfile} is not specified then {\mathsPIC} will
+create an output-file having the same filename as the
+\verb!inputfile! but with the filename extension \verb!.mt!.
+For example, if you want an input-file called
+\verb!myinfile.abc! to generate an output-file called
+\verb!myoutfile.xyz! then use the following command.
+
+\begin{verbatim}
+mathspic myinfile.abc myoutfile.xyz
+\end{verbatim}
+
+ In practice, I find it convenient to use the filename
+extension \verb!.m! for {\mathsPIC} files (input-files),
+since I can then easily
+distinguish between the various files. Thus \verb!.m!\ files
+are {\mathsPIC} files (input-files), while
+\verb!.mt!\ files are output {\TeX} files containing {\PiCTeX}
+commands ready for {\TeX}ing, and \verb!.mlg! files are
+{\mathsPIC} log-files.
+
+
+\subsubsection{Switches}
+
+Five switches are currently used (\verb!/? /h /help /b /s!).
+Switches are \emph{not} case-sensitive;
+they can be run together without intervening spaces; and they can be
+positioned anywhere, provided that they are separated by at
+least one space from any filenames.
+The switches are as follows.
+
+\smallskip
+
+\hspace{1cm}\verb!/?!\hspace{1cm}Help---shows all commands
+(also \verb!/h /help!).
+
+\smallskip
+
+\hspace{1cm}\verb!/b!\hspace{1cm}Error-beep. A beep is sounded if
+{\mathsPIC} detects an error.
+
+\smallskip
+
+\hspace{1cm}\verb!/s!\hspace{1cm}Screen view.
+Automatically shows the output-file using the free
+text-viewer \texttt{show.com}.
+
+\medskip
+
+For example, the following command invokes both the error-beep
+and automatic viewing of the output-file by the default file-viewer
+ \texttt{show.com}.
+\begin{verbatim}
+mathspic /b /s inputfile outputfile
+\end{verbatim}
+
+%---------
+\subsection{Removing comment lines from the output-file}
+
+Once a diagram has been finalised, it is sometimes convenient to
+remove all the various commented lines from the final
+output-file, particularly if the file is a large one.
+
+This can be easily done using the included \textsc{clean.exe}
+utility, which will strip out all lines starting with the
+double comment symbol \verb!%%!. The /s switch can also be used
+with \textsc{clean.exe}.
+ Examples of the syntax are as follows.
+
+\begin{verbatim}
+clean.exe /?
+clean.exe inputfilename
+clean.exe /s inputfilename
+clean.exe /s inputfilename outputfilename
+\end{verbatim}
+
+If no output filename is supplied, then \textsc{clean.exe} will
+use the same filename but add the filename extension
+\verb!.mtc!.
+For example, the following command will clean the
+output-file \verb!myfile.mt!, generating the file \verb!myfile.mtc!
+as the cleaned file, and then view the `cleaned' output-file
+using \verb!show.com!.
+
+\begin{verbatim}
+clean.exe /s myfile.mt
+\end{verbatim}
+
+%---------
+\subsection{Batch processing}
+
+In addition to running the program from the command-line,
+{\mathsPIC} can also be run from a batch-file (some familiarity
+with the MS-DOS batch-file language is assumed; note that the
+batch-files need to be tailored to the particular command-line
+sequence.)
+ For example, the following command line with five parameters
+ (two switches and three filenames)
+
+\begin{verbatim}
+mathspic /b /s testpic.m testpic.mt testpic.dvi
+\end{verbatim}
+
+
+{\noindent}will be executed by the following MS-DOS batch-file (written
+for the {Em\TeX}\footnote{The Em\TeX\ screen viewer
+is \texttt{dviscrs.exe} and is usually called via
+the batch-file \texttt{vs.bat}.}
+implementation of \LaTeX\ for PCs using MS-DOS),
+which first runs {\mathsPIC} on the input-file
+\verb!testpic.m!; then calls \LaTeXe\ to process the output-file;
+and finally calls the Em\TeX\ screen viewer \texttt{dviscrs.exe}
+(via \verb!vs.bat!) to view
+the file \verb!testpic.dvi! (\verb!%5!).
+
+
+
+\begin{verbatim}
+REM mathsPIC.bat (MS-DOS 6.0 and greater)
+@ECHO OFF
+mathspic.exe %1 %2 %3 %4 %5
+CALL latex2e %4
+CALL vs.bat /s3 %5
+\end{verbatim}
+
+
+
+Note that care needs to be taken to make sure that the
+parameters used in the batch-file
+correspond to the command-line parameters.
+ For example, if the two switches are
+run together without a space (e.g.\ \verb!/b/s!)
+ they will be perceived by MS-DOS as a single entity, in which case
+the \verb!.dvi! file would be represented by \verb!%4! in the
+batch-file instead of \verb!%5!.
+For example, the following four-parameter command-line
+
+\begin{verbatim}
+mathspic /b/s testpic.m testpic.mt testpic.dvi
+\end{verbatim}
+
+
+{\noindent}would require the following MS-DOS batch-file.
+
+
+\begin{verbatim}
+@ECHO OFF
+mathspic.exe %1 %2 %3 %4
+CALL latex2e.bat %3
+CALL vs.bat /s3 %4
+\end{verbatim}
+
+
+As a final example (again based on the {Em\TeX} implementation),
+suppose you wish to use your own text-viewer (say,
+\verb!myTextViewer.exe!) to view the output-file,
+with the \verb!/b! switch (enables error-beep), and have
+conditional branching---i.e.\ have the option to either (a) quit
+(select the `\verb!N!' option) and return to the text-editor
+after viewing the output-file, or (b) proceed (select the `\verb!Y!' option)
+and process the output-file \verb!testpic.mt! (\verb!%3!) and
+then view the \verb!.dvi! file (\verb!%4!).
+In this example, the following four-parameter command-line
+
+
+\begin{verbatim}
+mathspic /b testpic.m testpic.mt testpic.dvi
+\end{verbatim}
+
+{\noindent}could be run using the following batch-file.
+
+
+\begin{verbatim}
+REM mPIC.bat (MS-DOS 6.0 and greater)
+@ECHO OFF
+mathspic.exe %1 %2 %3 %4
+CALL myTextViewer.exe %3
+CHOICE /C:YN View figure?:
+IF ERRORLEVEL 1 IF NOT ERRORLEVEL 2 GOTO yes
+GOTO no
+:yes
+CALL latex2e %3
+CALL vs.bat /s3 %4
+:no
+\end{verbatim}
+
+
+%%--------------------------------
+\section{The {\mathsPIC} file and script}
+
+The idea underlying the {\mathsPIC} file (input-file) is that it
+should be able to contain
+everything required to generate the proposed
+figure (i.e.\ all {\mathsPIC} commands, comments,
+{\TeX} and {\LaTeX} commands including headers and footers,
+{\PiCTeX} commands, as well as lines to be copied verbatim)
+so that the output-file can be
+immediately {\TeX}ed to generate the graphic.
+Some general points relating to the {\mathsPIC} file are
+as follows.
+
+\begin{itemize}
+
+\item
+ {\mathsPIC} commands are \textit{not} prefixed by backslashes. They
+ are therefore easily distinguished from
+ \TeX\ and {\PiCTeX} commands.
+
+\item
+Each {\mathsPIC} command must be on a separate line.
+This is because \hbox{\mathsPIC} frequently adds data to
+the end of a line in the output-file (see below).
+
+\item
+As with \TeX, spaces can be used to enhance readability.
+This is particularly useful when writing lists of points.
+For example the command \texttt{drawpoint(a1a22a34a4)}
+can be made easier to read by writing it as
+ \texttt{drawpoint(a1 a22 a34 a4)}.
+
+
+
+\item
+{\mathsPIC} commands and point-names are \textit{not}
+case sensitive. This allows the user
+to customise the commands to enhance readability. Thus the command
+\texttt{drawpoint} can be written as \texttt{drawPoint} or
+\texttt{DrawPoint} etc.
+
+
+\item
+Delimiters have a hierarchical structure as follows:
+{\newline}Curved brackets contain the primary
+ argument; e.g.\ \verb!showPoint(A)!
+\newline
+ Braces contain required supporting arguments;
+ e.g.\ \verb!point(A){5,6}!
+\newline
+ Square brackets contain optional arguments;
+ e.g.\ \verb!point(p3){a,shift(1,2)}[circle,5]!
+
+
+\item
+Logically distinct groups within brackets must be separated
+by commas.
+{\newline}e.g.\ \verb!point(B2){A,polar(3,40deg)}[circle,5]!
+
+
+\item
+Comments are prefixed by the {\%} symbol in the usual way.
+Lines having a leading {\%} symbol are copied verbatim through
+to the output-file.
+
+\item
+Lines having a leading backslash command (i.e.\
+where there is \textit{no} inter-word space immediately
+following the backslash, e.g.\ \verb!\setdashes!
+or \verb!\begin{document}!)
+are copied verbatim through to the output-file.
+Consequently, all {\TeX}, {\LaTeX} and {\PiCTeX} commands
+can be used in the normal way providing
+the command is restricted to a single line.
+However, if such commands do run on to the subsequent
+lines, these lines will need to be
+prevented from being processed as {\mathsPIC} commands,
+by prefixing them with
+ \texttt{$\backslash$\gap} (see below)---unless of course
+they also start with a backslash command (see Sections~4.1 and 4.2).
+
+
+
+\item
+Lines having a leading \texttt{$\backslash$\gap}
+(i.e.\ where the \texttt{$\backslash$} is followed immediately by
+one or more inter-word spaces {\gap} \hbox{e.g.\ \verb!\ 25.3 16.8!)}
+are copied verbatim through to the output-file \textit{without}
+the leading backslash.
+
+
+
+\item
+Data-files containing {\mathsPIC} commands can be input using the
+\verb!inputfile! command.
+Files can also be input \textit{verbatim} using the
+\verb!inputfile*! command (useful for inputting files containing
+only {\PiCTeX} commands and/or coordinate data;
+ for example, a list of data points as part
+of a {\PiCTeX} \verb!\plot! command)---see example in
+Section~7.6.1
+
+\end{itemize}
+
+
+%-------------------------------
+\subsection{\PiCTeX\ commands}
+
+Note that \PiCTeX\ commands can \textit{only} be used within the
+\verb!\beginpicture! ... \verb!\endpicture! environment,
+ as described in the \PiCTeX\ Manual\footnote{See Section~9.5 for
+ information regarding the {\PiCTeX} manual.} (Wichura, 1992).
+
+
+
+Most \PiCTeX\ commands are short one-line commands starting
+with a leading backslash.
+ Such commands can be used in the normal way
+ as {\mathsPIC} will automatically
+copy lines starting with a backslash command unchanged through into
+the output-file (\verb!.mt! file).
+For example, drawing with dashed lines is enabled using
+the {\PiCTeX} \verb!\setdashes! command, and this would be
+expressed in the {\mathsPIC} file as follows.
+
+\begin{verbatim}
+\setdashes
+\end{verbatim}
+
+However, some {\PiCTeX} commands are very long.
+It is therefore sometimes necessary to have the initial part of a
+{\PiCTeX} command on one line, with the rest of the command
+continuing onto the next line, such that the second
+ and subsequent lines may well not have a leading backslash command.
+In order to protect such subsequent lines
+ from being processed as {\mathsPIC}
+commands, they must be protected by a leading
+backslash \textit{followed by one or more spaces}
+(e.g.\ \verb!\!{\gap\ldots}) as this instruction tells {\mathsPIC} to
+copy the rest of the line unchanged (\textit{without} the leading
+backslash) through into the output-file.
+For example, the {\PiCTeX} code for plotting data-points for a
+curve could be spread across several lines in the {\mathsPIC}
+file as follows.
+
+\begin{verbatim}
+\setquadratic
+\plot 1.15 -0.67
+\ 1.25 0.02
+\ 1.35 1.24
+\ 1.45 3.13 /
+\setlinear
+\end{verbatim}
+
+When these commands are processed by {\mathsPIC}, they will
+appear in the output {\TeX} file (\verb!.mt! file) as follows.
+
+\begin{verbatim}
+\setquadratic
+\plot 1.15 -0.67
+ 1.25 0.02
+ 1.35 1.24
+ 1.45 3.13 /
+\setlinear
+\end{verbatim}
+
+
+%%------------------------------------
+\subsection{\TeX\ and \LaTeX\ commands}
+
+\subsubsection{Headers and footers}
+
+It is particularly useful to include in the
+{\mathsPIC} file any \TeX\ or \LaTeX\ headers and footers
+which would otherwise have to be
+added manually to the output-file before {\LaTeX}ing the file.
+For example, when using \LaTeX\ a typical
+format for a {\mathsPIC} file might be as follows (note that
+in this example Andreas Schrell's style option \verb!pictexwd.sty! is
+used---see Section~9.2).
+
+
+\begin{verbatim}
+\documentclass[a4paper]{article}
+\usepackage{pictexwd}
+\begin{document}
+\beginpicture
+...
+...
+\endpicture
+\end{document}
+\end{verbatim}
+
+
+For users of plain \TeX\ a typical format might be as
+follows (see Section~9).
+
+\begin{verbatim}
+\input latexpic.tex
+\input pictexwd.tex
+\font\tiny=cmr5 %% used for drawing lines
+\font\large=cmr12 %% used for drawing thicklines
+\beginpicture
+...
+...
+\endpicture
+\bye
+\end{verbatim}
+
+
+If it is necessary (or just simply convenient) to extend a
+{\TeX} or {\LaTeX} command across several lines, then each
+additional line must be protected within the {\mathsPIC} file
+using a leading \verb!\!\gap\ldots\ sequence (see Section~4.1)
+unless a line actually starts with a \TeX\ command.
+A typical example is the following macro (used in Figure~9)
+which defines a `display' maths formula.
+The macro is split across several lines, as follows.
+
+\begin{verbatim}
+\newcommand{\formula}{%
+\ $\displaystyle \sum_{p\ge0} \Delta_{jp} z^{(p+1)}$%
+\ }%
+text(\formula){B1}
+\end{verbatim}
+
+Note that when using {\TeX} or {\LaTeX} commands \textit{within}
+the {\PiCTeX} picture environment, it is very important
+to include the comment \verb!%! symbol at the end of such lines,
+to prevent {\PiCTeX} accumulating additional space characters from
+the ends of non-{\PiCTeX} commands,
+since otherwise {\PiCTeX} incorporates such space characters
+into the horizontal distance used for representing
+ $x$-coordinates, with the effect that all subsequent picture elements
+may be displaced slightly to the right.
+
+
+
+%%---------------------------
+\subsubsection{Other \TeX\ commands}
+
+A very useful command is the \verb!\typeout{}! command,
+which will make \TeX\ print comments to the screen while the
+output-file is being processed.
+For example, the following commands in the {\mathsPIC} file
+will print a message to the
+screen just before processing a data-file for a curve.
+
+\begin{verbatim}
+\typeout{processing the data-file now}%
+inputfile*(curve.dat)
+\end{verbatim}
+
+This command is also useful is when a file is
+\verb!input! several times in a loop using the
+{\mathsPIC} \verb!inputFile{..}[]!
+command. In such cases it is quite useful to include
+the line \verb!\typeout{...}%! at the beginning of the file
+being input, as this results in \TeX\ printing \verb!...!
+to the screen each time the file is input.
+
+Note the importance of including the comment \verb!%! symbol
+at the end of the line when the \verb!\typeout{}%! command
+is used within the {\PiCTeX} picture environment.
+
+%%--------------------------------
+\subsection{The plotting area}
+
+\subsubsection{Axes}
+
+When drawing a new figure it is often useful to have a graduated ruled frame
+to guide placement of picture elements.
+This task is greatly simplified by using {\mathsPIC}'s one-line
+\verb!paper! command, which has
+optional \verb!axes! and \verb!ticks! parameters\footnote{Since
+{\PiCTeX} uses the name `axis', \textsf{mathsPIC} recognises
+both spellings (`axis' and `axes').}.
+The axes-codes used in the \texttt{axes()} option are
+\texttt{L}~(Left), \texttt{R}~(Right), \texttt{T}~(Top),
+\texttt{B}~(Bottom), \texttt{X}~(X-axis), \texttt{Y}~(Y-axis).
+ For example, the following \texttt{paper} command
+generates a drawing area 5 cm x 5 cm with a ruled frame on
+four sides as shown in Figure~2a.
+
+\begin{verbatim}
+paper{units(mm),xrange(0,50),yrange(0,50),axes(LRTB),ticks(10,10)}
+\end{verbatim}
+
+This particular \verb!paper! command is
+converted by {\mathsPIC} into the following {\PiCTeX} code
+in the output-file (\verb!.mt! file).
+
+
+\begin{verbatim}
+\setcoordinatesystem units <1mm,1mm>
+\setplotarea x from 0 to 50 , y from 0 to 50
+\axis left ticks numbered from 0 to 50 by 10 /
+\axis right ticks numbered from 0 to 50 by 10 /
+\axis top ticks numbered from 0 to 50 by 10 /
+\axis bottom ticks numbered from 0 to 50 by 10 /
+\end{verbatim}
+
+
+
+%%------------Figure 2-----------------
+%% the plotting area
+\begin{figure}[hbt]
+\begin{center}
+\noindent
+%\framebox{
+ % box picture
+\begin{minipage}{6cm}
+ %\vspace{2cm} %% controls space above picture
+ \input{mPICm02a.pic}
+ \vspace{5mm} %% controls space between pict and caption
+ \begin{center}
+ a. Using \texttt{...axes(LRTB)}
+ \end{center}
+\end{minipage}
+%} % end of framebox
+%-----------------------
+\hspace{1cm} %% controls space between figs
+%% use this when making A5 booklet to put vertically
+%% and use with \clearpage to flush the floats
+%%\bigskip\bigskip %% use this to place vertically
+%%----------------------
+%\framebox{
+\begin{minipage}{5cm}
+ \vspace{3mm} %% controls space between pict and caption
+ \input{mPICm02b.pic}
+ \vspace{10mm} %% controls space between pict and caption
+ \begin{center}
+ b. Using \texttt{...axes(XY)}
+ \end{center}
+\end{minipage}
+%} % end of framebox
+\end{center}
+\caption{\ }
+\end{figure}
+%-----------------------
+
+For graphs it is more usual for the axes to be centered on the
+origin $(0,0)$, and this is provided for by the
+\texttt{XY} options. For example, Figure~2b was generated
+using the following \verb!paper! command,
+
+
+
+\begin{verbatim}
+paper{units(cm),xrange(-2,3),yrange(-2,3),axes(XY),ticks(1,1)}
+\end{verbatim}
+
+{\noindent}which is converted by {\mathsPIC} into the following {\PiCTeX}
+code in the output-file.
+
+\begin{verbatim}
+\setcoordinatesystem units <1cm, 1cm>
+\setplotarea x from -2 to 3, y from -2 to 3
+\axis left shiftedto x=0 ticks numbered from -2 to -1 by 1
+ from 1 to 3 by 1 /
+\axis bottom shiftedto y=0 ticks numbered from -2 to -1 by 1
+ from 1 to 3 by 1 /
+\end{verbatim}
+
+
+The tick-marks associated with an axis can be prevented by using a *
+after the axes-code (e.g.\ \verb!axis(LBT*R*)! gives four axes but
+generates tick-marks only on the Left and Bottom axes).
+Note that any combination of axes-codes can be used. For example,
+the options ...\texttt{axes(LRTBX*Y*), ticks(10,10)} will generate
+a rectangular axes frame (with ticks) containing the
+$XY$ axes (without ticks).
+
+%%\clearpage %% need to flush the floats.
+
+The line-thickness of axes and tick-marks is controlled by
+the {\PiCTeX}\verb! \linethickness! command (see Section~4.6.1,
+and also Figure~14).
+
+Once the figure is finished, then the frame or axes can be
+easily adjusted or even removed. The figure can also
+be scaled in size simply by altering the \texttt{units}
+parameters. For example, the option \verb!units(3cm,1cm)! will
+generate an $X$-axis having three times the scale as the $Y$-axis
+(see Figure~14).
+If complicated or more demanding axis configurations are
+required, then the {\PiCTeX} Manual (see Section~9.5)
+will need to be consulted.
+See also Section~8 for details on positioning figures within
+\LaTeX\ documents.
+
+
+\subsubsection{Units}
+
+In addition to the usual units \verb!mm!, \verb!cm!, and
+\verb!pt!, {\PiCTeX} accomodates the other six units used by
+{\TeX}\footnote{These are described in Chapter~10 of the
+\textit{The {\TeX}book} by D.\ Knuth.},
+and also uses the same two-letter codes,
+ namely \verb!pc! (pica), \verb!in! (inch), \verb!bp! (big
+point), \verb!dd! (didot), \verb!cc! (cicero), \verb!sp! (scaled
+point). The available units thus enbrace the Metric system (mm,
+cm), the Didot system (didot, cicero), and the UK system
+(point, big point, pica, inch).
+
+Note that if only \textit{one} unit is indicated in the
+\verb!units! option, then {\mathsPIC} uses the \textit{same} unit
+for both the $x$ and $y$ axes.
+Thus the option \verb!units(mm)! in the
+\texttt{paper} command is translated by {\mathsPIC} into
+the following {\PiCTeX} command in the output-file.
+
+\begin{verbatim}
+\setcoordinatesystem units <1mm,1mm>
+\end{verbatim}
+
+Note that variables can also be used to control the $x$ and $y$
+units, as shown in the following example, where the radius
+(\verb!r!)
+and the distance (\verb!s!) between the label $A$ and its
+point-location
+are fixed irrespective of scaling (i.e.\ with
+changes in the value of \verb!u!) by dividing the relevant variables
+by the scaling value \verb!u!.
+
+\begin{verbatim}
+variable(u){1.5}
+paper{units(u mm), xrange(0,100), yrange(0,100)}
+...
+variable(r){2}
+variable*(r){r, divide(u)}
+point(A){30,20}[circle,r]
+variable(s){4}
+variable*(s){s, divide(u)
+text($A$){A, shift(-s,s)}
+\end{verbatim}
+
+
+
+If different scales are required (most commonly when drawing
+curves and equations---see Figure~14)
+then both need to be specified
+in the {\mathsPIC} \verb!units! option. For example, if
+units of 1 cm and 2 mm are required for the $x$ and $y$ axes
+respectively, then this will be implemented by the {mathsPIC}
+command \verb!units(1cm,2mm)!.
+However, when the $x$ and $y$ scales \textit{are} different
+strange effects can occasionally occur, particularly if
+drawing ellipses or circular arcs.
+In view of this {\mathsPIC} writes a warning note to the output-file
+and log-file when different units are being used.
+The drawing of complete circles will only be affected if the $x$-units
+is changed, since the {\mathsPIC} starts the arc at a location
+having the same $y$-coordinate as that of the center.
+In general users are therefore recommended to avoid using
+different $x$ and $y$ units in the \verb!paper! command
+if at all possible.
+
+
+
+\subsubsection{Tick-marks}
+
+It is recommended that integers are used with the \verb!ticks!
+option, since {\PiCTeX} sometimes gives unpredictable results
+if decimals are used with the \verb!xrange! and
+\verb!yrange! options in conjunction with the \verb!ticks!
+option.
+In general {\PiCTeX} gives more pleasing axes if integers are
+used throughout the \verb!paper! command.
+
+
+
+ %------------------
+\subsection{Points}
+
+ Each point is associated with a point-name which is defined
+ using the \verb!point! command. For example, the following command
+ allocates the point-name $A$ to the coordinates (5,7).
+
+\begin{verbatim}
+point(A){5,7}
+\end{verbatim}
+
+ Once defined, points can be referred to by name.
+ Consequently, points can be defined in relation to other points
+ or lines simply by using point-names, as shown by the
+ following commands.
+
+\begin{verbatim}
+point(C){midpoint(AB)}
+point(E){intersection(AB,CD)}
+point(J){Q, rotate(P, 25 deg)} %% J = Q rotated about P by 25 deg
+\end{verbatim}
+
+Points are interpreted according to their grouping and context.
+Thus two points represent either a line or its Pythagorean length.
+ For example, the command \verb!drawCircle(P,AB)! means
+ draw a circle, center $P$ with radius the length of line $AB$.
+A group of three points represents either a triangle, an angle,
+or a line, depending on the circumstances.
+
+%-----
+\subsubsection{Point-name}
+
+
+A point-name \textit{must} begin
+with a \textit{single} letter,
+and may have up to a \textit{maximum} of two following
+digits. The following are valid point-names: {$A, B, C3, d45$}.
+Since {\mathsPIC} is not case sensitive the points {$d45$}
+and {$D45$} are regarded as being the same point.
+Point-names can be either separated by spaces, or simply run
+together.
+
+
+Sometimes it is necessary to re-allocate new coordinates
+to an existing point-name, in which case the \verb!point*!
+command is used. This is often used during recursive operations
+whereby the {\mathsPIC} file inputs another file (using
+the \verb!inputfile! command) containing commands which
+alter the value of pre-existing points. For example,
+the following command increments the $x$-coordinate of
+point~$A$ by 5 units.
+
+\medskip
+
+\noindent\verb!point*(A){A, shift(5,0)}!
+
+
+%%---------------
+\subsubsection{Point-symbol}
+
+The default point-symbol is $\bullet$ (\verb!$\bullet$!).
+However, {\mathsPIC} allows the optional use of any \TeX\
+character or string of characters to represent a particular point,
+by including it in a following square bracket.
+For example, the point~$A$(5,10) can be
+represented by the $\triangle$ symbol by defining it as follows.
+
+\medskip
+
+\noindent\verb!point(A){5,10}[$\triangle$]!
+
+\medskip
+
+ The default point-symbol can also be changed to any \TeX\ character
+or string of characters by using the
+{\mathsPIC} \verb!PointSymbol! command, and putting this
+command \textit{before} any relevant \verb!point! commands,
+since the \verb!PointSymbol! command only influences
+subsequent \verb!point! commands.
+For example, the
+character $\odot$ (\verb!$\odot$!) can be made the new global
+point-symbol by using the command \verb!PointSymbol($\odot$)!.
+The original default point-symbol ($\bullet$) can be
+reinstituted (reset) using the command \verb!PointSymbol(default)!.
+ The point-symbol is drawn at the point-location
+using the \texttt{drawPoint} command; for example,
+\texttt{drawPoint(A)}, or \texttt{drawPoint(ABCD)}.
+
+
+Since most \TeX\ characters and symbols are typeset
+asymmetrically in relation to the baseline,
+they will not be positioned symmetrically over a point-location.
+Most characters are therefore not ideal for use as point-symbols,
+as they generally require some slight adjustment in order to
+position them symmetrically.
+In view of this, Table~1 lists those \TeX\ characters
+which \textit{are} particularly suitable, since they are automatically
+positioned by \TeX\ symmetrically with respect to a point-location
+(for example the $\odot$ character \verb!$\odot$!), and are
+therefore ideal for use with \PiCTeX.
+
+%%---------------------------
+\subsubsection{Line-free zone}
+
+When lines are drawn to a point, the line will (unless
+otherwise instructed) extend to the point-location. However,
+this can be prevented by allocating an optional
+circular line-free zone to a point by specifying the line-free radius
+in a following square bracket.
+ For example, lines to a $\triangle$ symbol at point~$A$
+can be prevented from being drawn through the triangle to its center
+by allocating a 5 unit line-free zone to the point, as follows.
+
+\begin{verbatim}
+point(A){3,10}[$\triangle$,5]
+\end{verbatim}
+
+If only the line-free radius is to be specified
+ then a preceding comma must be used (e.g.\ \verb![,10]!).
+For example the following {\mathsPIC} command would change the line-free
+radius associated with point $A$ to 10 units.
+
+\begin{verbatim}
+point*(A){A}[,10]
+\end{verbatim}
+
+
+%----table~1 of line free zones-----------------------------------
+\newcommand{\ttstrut}{\rule{0pt}{14pt}} % for top line
+\newcommand{\mmstrut}{\rule[-2pt]{0pt}{14pt}} % middle lines
+\newcommand{\bbstrut}{\rule[-6pt]{0pt}{17pt}} % bottom lines
+
+% small table for line-free radius
+\begin{table}[hbt]
+\begin{center}
+\caption{Useful point-symbols and their radii for 10--12pt fonts.}
+{\ } \\ %% line between caption and table
+\begin{tabular}{|l|c|c|c|}
+\hline
+\multicolumn{2}{|c|}{\raisebox{-3mm}{symbol}} &
+ \multicolumn{1}{|c|}{\ttstrut\ radius mm} &
+ \multicolumn{1}{|c|}{\raisebox{-3mm}{symbol package}} \\
+\cline{3-3}
+\multicolumn{2}{|c|}{{\mmstrut}\ } &
+ \multicolumn{1}{|c|}{10pt / 11pt / 12pt} &
+ \multicolumn{1}{|c|}{\ } \\
+\cline{1-2}\cline{3-4}
+\verb!$\circ$! & $\circ$ & 0.70 / 0.75 / 0.80 & standard {\ttstrut} \\
+\verb!$\odot$! & $\odot$ & 1.20 / 1.35 / 1.50 & standard {\mmstrut} \\
+\verb!$\oplus$! & $\oplus$ & 1.20 / 1.35 / 1.50 & standard {\mmstrut} \\
+\verb!$\ominus$! & $\ominus$ & 1.20 / 1.35 / 1.50 & standard {\mmstrut} \\
+\verb!$\oslash$! & $\oslash$ & 1.20 / 1.35 / 1.50 & standard {\mmstrut}\\
+\verb!$\otimes$! & $\otimes$ & 1.20 / 1.35 / 1.50 & standard {\mmstrut} \\
+\verb!$\bigcirc$! & $\bigcirc$ & 1.70 / 1.85 / 2.05 & standard {\mmstrut} \\
+\verb!$\bigodot$! & $\bigodot$ & 1.70 / 1.85 / 2.05 & standard {\mmstrut} \\
+\verb!$\bigoplus$! & $\bigoplus$ & 1.70 / 1.85 / 2.05 & standard {\mmstrut} \\
+\verb!$\bigotimes$! & $\bigotimes$ & 1.70 / 1.85 / 2.05 & standard {\mmstrut} \\
+\verb!$\star$! & $\star$ & --- & standard {\mmstrut} \\
+\verb!$\triangle$! & $\triangle$ & --- & standard {\mmstrut} \\
+\verb!$\square$! & $\square$ & --- & amssymb.sty {\mmstrut} \\
+\verb!$\blacksquare$! & $\blacksquare$ & --- & amssymb.sty {\mmstrut} \\
+\verb!$\lozenge$! & $\lozenge$ & --- & amssymb.sty {\mmstrut} \\
+\verb!$\blacklozenge$! & $\blacklozenge$ & --- & amssymb.sty {\mmstrut} \\
+\verb!$\bigstar$! & $\bigstar$ & --- & amssymb.sty {\mmstrut} \\
+\verb!$\boxdot$! & $\boxdot$ & --- & amssymb.sty {\mmstrut} \\
+\verb!$\boxtimes$! & $\boxtimes$ & --- & amssymb.sty {\mmstrut} \\
+\verb!$\boxminus$! & $\boxminus$ & --- & amssymb.sty {\mmstrut} \\
+\verb!$\boxplus$! & $\boxplus$ & --- & amssymb.sty {\mmstrut} \\
+\verb!$\divideontimes$! & $\divideontimes$ & --- & amssymb.sty {\bbstrut} \\
+\hline
+\end{tabular}
+\end{center}
+\end{table}
+%%----------------------------------------------------------
+
+
+
+Table~1 gives a list of useful point-symbols which \TeX\
+places symmetrically over a point-location
+(note that \verb!$\Box$! and \verb!$\Diamond$! are not placed
+symmetrically over a point location, but \verb!$\square$!
+and \verb!$\lozenge$! are).
+Other useful symbols are available from the
+\verb!textcomp! fonts\footnote{See Harald Harders' useful
+file (\texttt{textcomp.tex}) which shows the characters
+of the \texttt{textcomp} font together with their names.
+It can be found at \texttt{CTAN:/tex-archive/info/texcomp-info/}.}.
+ For example, the following commands will draw lines between
+points ABC, such that the lines just touch the edge of the
+$\odot$ point-symbol (line-free radius 1.2 mm; 10pt font).
+
+\begin{verbatim}
+point(A){1,1}[$\odot$,1.2]
+point(B){2,2}[$\odot$,1.2]
+point(C){1,3}[$\odot$,1.2]
+drawline(ABC)
+\end{verbatim}
+
+ It is often useful to adjust the line-free radius
+associated with a particular point before drawing
+lines or arrows to it, in order to optimise the distance
+between an object centered at the point and the line or arrow.
+For example, one can use the \verb!point*! command
+to set a line-free radius of 2 units for a pre-existing
+point ($P$), as follows.
+
+
+\begin{verbatim}
+point*(P){P}[,2]
+\end{verbatim}
+
+
+By way of illustration, this command is used in
+drawing Figure~3
+where arrows are being drawn from various
+directions ($B$, $S$) to a text box centered on point $P$
+$\odot$ (the code is shown below as \texttt{mpicm03a.m}).
+By setting the line-free radius (dashed circles)
+associated with point $P$ before drawing each particular arrow,
+one can easily adjust and optimise the distance between the
+arrowhead and the text box.
+
+
+%%------------Figure 3-----------------
+%% rectangular text box
+\begin{figure}[hbt]
+\begin{center}
+ %% rectangular text box
+ \strut\input{mPICm03.pic}
+ \caption{\ }
+\end{center}
+\end{figure}
+%-----------------------
+
+\begin{verbatim}
+%% mpicm03a.m (Figure 3)
+\beginpicture
+paper{units(cm),xrange(0,6),yrange(0,3),axes(LBT*R*),ticks(1,1)}
+point(P){4,2}[$\odot$]
+point(B){2,0.5}
+point(S){1,2}
+drawPoint(PBS)
+\setdashes
+\inboundscheckon %% restrict circles to drawing area
+drawcircle(P,1)
+drawcircle(P,2)
+\setsolid
+point*(P){P}[,1] %% set line-free radius of P to 1 cm
+drawArrow(BP) %% draw arrow from B (below)
+point*(P){P}[,2] %% change line-free radius of P to 2 cm
+drawArrow(SP) %% draw arrow from S (side)
+text($S$){S, shift(-0.4,0)}
+text($B$){B, shift(-0.4,0)}
+text(\textsc{p}){P, shift(0.3,0)}
+\newcommand{\textbox}{\fbox{text\hspace{17mm}box}}%
+text(\textbox){P}
+\endpicture
+\end{verbatim}
+
+
+Of course, sometimes it is convenient just to draw
+the arrows a certain length from one point towards another point.
+For example, in Figure~3, the two \verb!point*! commands and the
+two \verb!drawArrow! commands could all be replaced by the
+following two commands using the \hbox{[\ ]} option to indicate the
+length of the arrow.
+
+\begin{verbatim}
+drawArrow(SP)[1] %% draw arrow 1 unit from point A towards P
+drawArrow(BP)[1.5] %% draw arrow 1.5 units from point B towards P
+\end{verbatim}
+
+
+%%----
+\subsubsection{Order of points}
+
+The order of points in {\mathsPIC} commands is sometimes significant.
+For example, the command
+\newline\verb!point(D){PointOnLine(AB,23)}!
+defines the point $D$ as being 23 units
+\textit{from $A$ in the direction of $B$}.
+
+
+%%---
+\subsubsection{Number of points}
+
+The maximum combined number of named points and variables
+which can be used
+is currently set by default at 50. The total array space for
+points and variables can be increased
+by using the {\mathsPIC} \verb!PointNumber()!
+command. For example, array space for a total of 75
+points/variables would be allocated by the command
+\verb!PointNumber(75)!.
+
+
+If the combined point/variable allocation is exceeded, then a so-called
+`fatal error' arises and the program terminates.
+The following example (from an output-file) documents a fatal error
+which occured while the program was trying to define a new point $Z_3$.
+
+\begin{verbatim}
+%% *** point(Z3){P,shift(2,5)}
+%% ... FATAL ERROR: points used exceed allocation
+%% ... use the PointNumber() command to increase allocation
+\end{verbatim}
+
+%%----
+\subsection{Scalar variables}
+
+Numeric scalar variables are defined using the
+\verb!variable(!\textit{name}\verb!){!\textit{value}\verb!}! command.
+The \textit{value} in the braces can be either a numeric (e.g.\
+4.32; 2.6E-2), a variable name (e.g.\ r3), or two points (e.g.\
+AB---meaning the Pythagorean distance between the two points
+$A,B$).
+Thus the command
+\verb!variable(r3){20}! allocates 20 to the variable
+\texttt{r3}, which could then be used, for example, as the
+radius in the circle command \verb!drawcircle(C3,r3)!.
+New values can be re-allocated to existing variable-names
+using the \verb!variable*! command.
+
+However, one must be careful not to mistake
+variables for points, and vice versa, since they both
+have the same name structure. When both are necessary,
+ using upper case for points and
+lower case for variables is a convenient strategy.
+If you inadvertently use a point instead of a variable
+{\mathsPIC} will generate an appropriate error message
+(see the last example in Section~5.1).
+
+
+\subsubsection{Arithmetic}
+
+Variables can be manipulated using the commands
+\verb!advance!, \verb!multiply!, \verb!divide! and \verb!mod!.
+The format is similar to that of the \verb!point! commands.
+Thus the command \verb!variable(a1){a,advance(-r3)}! makes
+the variable \verb!a1! assume the value \verb!a-r3! (i.e.\
+$a_1 = a - r_3$).
+Note that although {\mathsPIC} allows the use of the negative
+sign with variables (e.g.\ \verb!-5.34!, \verb!-r3!),
+the positive sign is \textit{not} allowed.
+Examples of valid \verb!variable! commands are given in Section~6.
+
+
+\subsubsection{Scientific notation}
+
+When numbers are either very small or very big they are
+generally written using the usual computer `E' format of
+ so-called `scientific notation', for example, 1.243E--9 etc.
+{\mathsPIC} allows the use of scientific notation in commands
+wherever decimals are normally allowed, as follows.
+
+
+\begin{verbatim}
+variable(p2){3.78E3}
+point(Z3){J,shift(1.3E-1,6)}
+\end{verbatim}
+
+
+Unfortunately, \TeX\ does not process numeric values in scientific notation,
+and will generate an error message whenever it finds the letter \verb!E!
+as part of a number.
+ Consequently {\mathsPIC} converts all numbers which appear
+within \PiCTeX\ commands in the output-file into conventional
+decimal format (place-value notation).
+If the value is less than 1.0E--7 (0.0000001) then {\mathsPIC}
+simply converts the value to zero.
+
+However, since this convertion requires additional checking,
+{\mathsPIC} does not bother to do this when it outputs data to the
+end of a commented line.
+For example, in the following extract from an output-file
+the variables $s_4$ and $s_5$ appear in scientific
+notation when in commented lines, but in decimal notation
+in the \PiCTeX\ \verb!\put...! commands (see the line for
+point $J_{45}$).
+Note also that in this example the $y$-coordinate of $J_{45}$
+appears as zero
+in the \verb!\put...! command (since \verb!s5! is less than
+0.0000001), but as \verb!2.3E-8! in the
+\verb!%%variable(s5){...! line.
+
+\begin{verbatim}
+%% variable(r){23} ( 23 )
+%% variable(s1){r,divide(100000)} ( .00023 )
+%% variable(s2){r,divide(1000000)} ( .000023 )
+%% variable(s3){r,divide(10000000)} ( .0000023 )
+%% variable(s4){r,divide(100000000)} ( 2.3E-7 )
+%% variable(s5){r,divide(1000000000)} ( 2.3E-8 )
+%% point(J12){s1,s2}
+%% point(J23){s2,s3}
+%% point(J34){s3,s4}
+%% point(J45){s4,s5}
+%% drawpoint(J12 J23 J34 J45)
+\put {$\bullet$} at .00023 .000023 %% J12
+\put {$\bullet$} at .000023 .0000023 %% J23
+\put {$\bullet$} at .0000023 .00000023 %% J34
+\put {$\bullet$} at .00000023 0 %% J45
+\end{verbatim}
+
+
+%-----------------
+\subsection{Lines}
+
+{\mathsPIC} draws lines using
+its \texttt{drawLine} and \verb!drawThickline! commands.
+For example, a line from ${P_1}$ to ${P_2}$ is drawn with the
+command \texttt{drawLine(P1P2)}.
+ If a line is to be drawn through several points
+(say, $J_1, J_2, J_3, J_4, J_5$)
+and can be drawn without `lifting the pen', then this can
+be achieved using the single {\mathsPIC}
+command \texttt{drawLine(J1J2J3J4J5)}.
+ Several unconnected lines can also be drawn using one command
+by separating each line segment with a comma; for example,
+\texttt{drawLine(J1J2,J3J4J5,J1J3)}.
+
+A line can also be drawn a specified distance from one point
+towards (or away from) another point, using the square-bracket option.
+For example, the following command draws a line a distance $d$
+units from point $A$ \textit{towards} point $B$.
+
+\begin{verbatim}
+drawline(AB)[d]
+\end{verbatim}
+
+Note that in this particular command
+the order of the points $AB$ and the sign of the
+distance \verb![d]! are important. For example, the following
+command will draw a line a distance $d$
+units from point $B$ \textit{away from} point $A$.
+
+
+\begin{verbatim}
+drawline(BA)[-d]
+\end{verbatim}
+
+
+
+Since the {\PiCTeX} \verb!\putrule! command for drawing horizontal or
+vertical lines is much more memory efficient than the
+\verb!\plot! command, {\mathsPIC} automatically invokes the
+\verb!\putrule! command for horizontal and vertical lines
+(see also \texttt{Pictex2.sty} in Section~9.3).
+
+However, there are some occasions when it is necessary to draw using
+the \verb!\plot! command even for horizontal and vertical
+lines (eg.\ when using \verb!\setdots! with larger than usual
+dots), in which case the \verb!drawline*! command (disables the
+use of \verb!\putrule!) should be used.
+
+
+%-------------
+\subsubsection{Line thickness}
+
+{\PiCTeX} draws lines using two different methods depending
+on whether the lines are (a) horizontal or vertical, (b) any
+other orientation. These two groups use different
+commands for controlling line-thickness, as follows.
+
+
+\subsubsection*{Horizontal and vertical lines (rules)}
+
+Horizontal and vertical lines are drawn using the {\PiCTeX}
+\verb!\putrule!
+command\footnote{Note that the {\PiCTeX} \texttt{$\backslash$putrule}
+ command employs the {\TeX} and {\LaTeX} \texttt{$\backslash$rule}
+ command, and so is only used for horizontal and vertical lines.}
+and consequently the thickness of such lines is controlled
+by the {\PiCTeX} \verb!\linethickness!
+command (the default line-thickness is 0.4pt).
+ For example, the following {\PiCTeX} command changes the
+ thickness to 1pt.
+
+\begin{verbatim}
+\linethickness=1pt
+\end{verbatim}
+
+The \verb!\linethickness! command is also useful
+for adjusting the thickness of graph axes, tick marks.
+For example, the following commands are used in the code for
+Figure~14 to draw thick axes.
+
+\begin{verbatim}
+\linethickness=2pt
+paper{units(mm),xrange(0,50),yrange(0,50),axes(XY)}
+\linethickness=0.4pt %% reset to default
+\end{verbatim}
+
+Note also that the {\PiCTeX} \verb!\linethickness! command can also
+be reset to its default value ($0.4$pt) by the {\PiCTeX}
+\verb!\normalgraphs! command, which resets all
+{\PiCTeX} graph-drawing parameters to their default values
+including \verb!\linethickness! (see Section~6.3).
+
+
+\subsubsection*{Other lines and curves}
+
+All other lines (non-horizontal non-vertical) and curves
+are drawn using the {\PiCTeX} \verb!\plot! command which draws a
+continuous line of dots. Consequently
+the thickness of these lines is controlled by
+the size of the dot, which is defined using the
+{\PiCTeX} \verb!\setplotsymbol! command,
+the default size of dot being \verb!{\tiny .}!.
+Larger dots therefore generate thicker lines.
+ For example, the following {\PiCTeX} command sets the dot to a
+ larger size.
+
+
+\begin{verbatim}
+\setplotsymbol({\Large .})
+\end{verbatim}
+
+The {\mathsPIC} \verb!drawLine! command uses the current dot
+size. However, the {\mathsPIC}
+\verb!drawThickline! command uses the \verb!\large! dot size,
+but then resets the dot size to \verb!\tiny!.
+For example, the commands
+
+\begin{verbatim}
+point(A){5,5}
+point(B){10,10}
+drawThickline(AB)
+\end{verbatim}
+
+
+{\noindent}will result in the following code in the output-file.
+
+\begin{verbatim}
+%% point(A){5,5} (5,5)
+%% point(B){10,10} (10, 10)
+%% drawThickline(AB)
+\setplotsymbol({\large .})
+\plot 5 5 10 10 / %% AB
+\setplotsymbol({\tiny .})
+\end{verbatim}
+
+\subsubsection*{Recommendations}
+
+Since {\PiCTeX} uses two groups of commands for controlling
+the thickness of lines (i.e.\ \verb!\linethickness! and
+\verb!\setplotsymbol!)
+it is important to use pairs of equivalent commands for
+`rules' (horizontal and vertical lines) and dots (all other
+lines) when changing line-thickness.
+These are shown in Table~2
+for a 10-point font (note that the default sizes are 0.4-point and
+\verb!\tiny!).
+
+
+%----table~2 line thickness commands-----------------------------------
+%\newcommand{\tstrut}{\rule{0pt}{12pt}} % for top line
+%\newcommand{\mstrut}{\rule{0pt}{12pt}} % middle lines
+%\newcommand{\bstrut}{\rule{0pt}{12pt}} % bottom lines
+
+% small table for line-free radius
+\begin{table}[hbt]
+\begin{center}
+\caption{Equivalent {\PiCTeX} commands for a 10-point font}
+{\ } \\ %% line between caption and table
+\begin{tabular}{|l|l|}
+\hline
+\multicolumn{1}{|c|}{{\tstrut}rules (horizontal/vertical)}
+ & \multicolumn{1}{|c|}{all other lines}\\
+\hline
+\verb!\linethickness=1.35pt! & \verb!\setplotsymbol({\Large .})! {\mstrut} \\
+\verb!\linethickness=1.1pt! & \verb!\setplotsymbol({\large .})! {\mstrut} \\
+\verb!\linethickness=0.9pt! & \verb!\setplotsymbol({\normalsize .})! {\mstrut} \\
+\verb!\linethickness=0.4pt! & \verb!\setplotsymbol({\tiny .})! {\mstrut} \\
+\hline
+\end{tabular}
+\end{center}
+\end{table}
+%%----------------------------------------------------------
+
+The author's experience is that although {\mathsPIC}
+does have commands for drawing thick lines and thick arrows, it
+is generally better to control the line-thickness separately
+using the two {\PiCTeX} commands shown in Table~2, and to
+make separate macros where necessary.
+For example, the following code draws a medium-thick
+line $AB$ by invoking the command \verb!\mediumthickline!.
+
+\begin{verbatim}
+\newcommand{\mediumthickline}{\linethickness=1.1pt\setplotsymbol({\large .})}%
+...
+\mediumthickline%
+drawline(AB)
+\end{verbatim}
+
+
+%---------------
+\subsection{Text}
+
+Text is typeset using the \texttt{text} command and, by default, is
+centered both horizontally and vertically at a defined point.
+ For example, the triangle symbol $\triangle$ would be placed at the
+point $Z$ using the command \verb!text($\triangle$){Z}!.
+
+Text can be located relative to a point-location using the
+\texttt{shift($dx$,$dy$)} or \texttt{polar($r$,$\theta$)}
+commands. For example, points ${P_1}{P_2}{P_3}$ could have
+their labels located 4 units from each point as follows.
+
+
+\begin{verbatim}
+variable(d){4}
+text($P_1$){P1,shift(-d,0)}
+text($P_2$){P2,polar(d,10 deg)}
+text($P_3$){P3,polar(d,0.29088 rad)}
+\end{verbatim}
+
+
+ Optionally, text can be positioned relative to a
+given point using appropriate combinations of the
+\textit{case sensitive} {\PiCTeX} options \verb! l t r B b! to
+align the \textbf{l}eft edge, \textbf{r}ight edge, \textbf{t}op edge,
+\textbf{B}aseline, \textbf{b}ottom edge
+ of the text respectively, as
+described in the {\PiCTeX} manual (see Section~9.5).
+ For example in the diagram below,
+ the text box \framebox{\texttt{a nice box}}
+ is aligned such that the right edge of the text box
+ is centered vertically at the point $P$ using the
+ \verb![r]! option as follows.
+
+
+\begin{verbatim}
+point(P){25,5}
+text(\fbox{a nice box}){P}[r]
+\end{verbatim}
+
+
+%----------------small diagram--------
+%% A2test.m
+%% mathsPIC 2.0k
+\begin{center}
+\framebox{\vbox{
+\beginpicture
+%% paper{units(mm),xrange(0,28),yrange(0,10)}
+\setcoordinatesystem units < 1mm, 1mm>
+\setplotarea x from 0 to 28, y from 0 to 10
+%% point(P){25,5}[$\bullet$,2] ( 25 , 5 )
+%% text(\fbox{a nice box}){P}[r]
+\put {\fbox{a nice box}} [r] at 25 5
+%% drawpoint(P)
+\put {$\bullet$} at 25 5 %% P
+%% point(J){P,polar(15,-20deg)}[,2] ( 39.09539 ,-.130302 )
+%% text(this is point P){J}[l]
+\put {this is point P} [l] at 39.09539 -.130302
+%% drawarrow(JP)
+\arrow < 2mm> [ .2679492, .7279404] from 37.216 .5537382 to 26.87938 4.31596
+\endpicture
+}}
+\end{center}
+%%------------------------------
+
+Text can also be placed at a point-location (using a
+\verb!DrawPoint! command), if the
+text is defined as the optional point-symbol (in square brackets)
+associated with a \verb!point! command. Although this is useful
+in certain circumstances, this method is somewhat less flexible
+than the \verb!text! command, since the \verb!drawPoint! command
+centers the point-symbol vertically and horizontally over the
+point-location.
+
+
+\section{Error-messages}
+A certain amount of syntax checking is performed by {\mathsPIC}.
+Error-messages appear in the output-file (\verb!.mt! file)
+and also in the log-file (\verb!.mlg! file).
+
+
+\subsection{Output-file}
+
+ A line containing an error is prefixed by \texttt{***};
+the associated error-message appears on the next line and is
+prefixed by dots (\texttt{...}).
+If the \texttt{/b} switch is used then a beep is sounded if
+an error occurs during processing.
+
+
+Runtime errors most commonly arise when an argument has been
+omitted, or division by zero has been attempted.
+ Syntax errors are
+where the {\mathsPIC} commands are written incorrectly (e.g.\
+missing bracket).
+ A typical example might be in a \texttt{draw} command if
+a point has not been previously defined
+resulting in a `point-name' error as follows.
+
+
+\begin{verbatim}
+%% *** drawTriangle(T1T6T3)
+%% ... ?syntax error: point T6 is not defined
+\end{verbatim}
+
+
+If the maximum point/variable allocation (default is 50)
+is exceeded, then a so-called
+`fatal error' arises and the program terminates.
+In the following example, a fatal error occured while
+the program was trying to define a new point $Z_3$.
+
+\begin{verbatim}
+%% *** point(Z3){P,shift(2,5)}
+%% ... FATAL ERROR: points used exceed allocation
+%% ... use the PointNumber() command to increase allocation
+\end{verbatim}
+
+
+Some other examples of error-messages are as follows.
+
+
+\begin{verbatim}
+%% *** point(a2{5,6}
+%% ... syntax error: extra or missing ()
+%%
+%% *** point(B2){A,shift(,6)}
+%% ... syntax error: missing X coordinate in shift()
+%%
+%% *** point(z2){}
+%% ... runtime error: ?syntax error
+%%
+%% *** pointt(z4){2,3}
+%% ... ?syntax error: statement not recognised
+%%
+%% *** drawLine(AB)
+%% ... ?syntax error: points A and B are the same
+%%
+%% *** variable(d){j, advance(4)}
+%% ... ?syntax error: j is a Point not a Variable
+
+\end{verbatim}
+
+
+\subsection{Log-file}
+{\mathsPIC} outputs a log-file (\verb!.mlg! file)
+which contains details of all errors, relevant line numbers
+and file names (e.g.\ $<$myfile.m$>$).
+The format was designed to match that of a standard \TeX\ log-file
+in order to be compatible with commonly used
+error-checking utilities.
+Part of a typical log-file is as follows.
+
+\begin{verbatim}
+mathsPIC log-file = myfile.mlg
+mathsPIC input-file = myfile.m
+mathsPIC output-file = myfile.mt
+
+! syntax error: extra or missing () bracket
+l.9 point(A{10,5}
+<myfile.m>
+
+! ?syntax error: point A is not defined
+l.13 drawpoint(ABC)
+<myfile.m>
+
+! syntax error: point A is not defined
+l.22 point(P){A,shift(5,0)}
+<myfile.m>
+
+! start of inputfile <newfile.dat>
+
+! syntax error: point X is not defined
+l.7 point(Q){X,shift(5,0)}
+<newfile.dat>
+...
+...
+\end{verbatim}
+
+
+%%-----------------------
+\section{Commands}
+
+\subsection{\MathsPIC\ commands}
+Although {\mathsPIC} commands are \textit{not} case sensitive,
+it is recommended (to avoid confusion) that
+points are represented using upper case
+letters, and variables are represented using lower case
+letters.
+
+The parameters of {\mathsPIC} commands are either strings
+(any legitimate {\TeX} or {\LaTeX} commands or characters which
+are suitable for an \verb!\hbox! are allowed),
+point-names (e.g.\ A,B,C), or scalar quantities.
+Where appropriate, {\MathsPIC} allows scalar quantities in
+commands to be represented by either a
+numeric value (e.g.\ 0.432, or 4.32E-1 ),
+a variable name (e.g.\ r2), or the Pythagorean distance between
+two points (e.g.\ $AB$).
+ For example, the structure of a
+ \texttt{DrawCircle(\textit{center,radius})} command is
+ quite flexible, as follows.
+
+\begin{verbatim}
+drawCircle(C,4.32)
+drawCircle(C,3.6E-1)
+drawCircle(C,r2)
+drawcircle(C,AB)
+\end{verbatim}
+
+The various parameters which control the thickness of lines,
+arrows and curves drawn by {\PiCTeX} are described in
+Section~4.6.1.
+
+
+%-----------------------------
+\begin{itemize}
+%-----------------------------
+\item \framebox{\texttt{$\backslash$...}\ } \hspace{5mm}
+ \framebox{\texttt{$\backslash$\gap...}\ }
+
+A line having a \textit{leading} backslash is processed (copied
+verbatim) slightly differently depending on whether the character
+following the backslash is a space or not.
+
+A leading backslash \textit{followed by a non-space character}
+tells {\mathsPIC} to copy the
+whole line verbatim (\textit{including} the backslash) through to the
+output-file (thus a line leading with the {\LaTeX} command
+\verb!\begin{document}! will be copied unchanged).
+
+However, a leading backslash \textit{followed by one
+or more spaces}, (e.g.\ \texttt{$\backslash$\gap\ldots})
+ tells {\mathsPIC} to copy the rest of the line
+verbatim through to the output-file, but \textit{without} the
+leading backslash.
+
+
+%-------------------------
+\item \framebox{\tt Arrowshape(\textit{L, B, C})}
+
+This command defines the shape of an arrowhead, and allows
+different arrowheads to be customised (see Section~7.3 for details).
+The default arrow shape is equivalent to the
+command \verb!Arrowshape(2,30,40)!.
+This default arrowhead shape can be reset using
+\verb!default! as the argument, as shown in the following example.
+
+
+\begin{verbatim}
+Arrowshape(4,30,60)
+drawArrow(AB)
+ArrowShape(default)
+\end{verbatim}
+
+
+
+
+%-----------------------------
+\item \framebox{\tt DrawAngleArc{\{}angle(), radius(), internal, clockwise{\}}}
+
+This command draws an arc in the specified angle, a distance
+\textit{radius} from the angle. The angle is either
+\textit{internal} ($\leq 180^{\circ}$) or
+\textit{external} ($\geq 180^{\circ}$).
+The direction of the arc is
+either \textit{clockwise} or \textit{anticlockwise}, and this
+direction must correspond with the letter sequence specified
+for the angle.
+Strange and unexpected results will be produced if
+the four parameters are not internally consistent.
+
+
+For example, the following command draws a clockwise arc,
+radius 3 units, in the external angle $ABC$, from line $AB$
+to line $BC$.
+
+
+
+\begin{verbatim}
+DrawAngleArc{angle(ABC), radius(3), external, clockwise}
+\end{verbatim}
+
+%----------
+\item \framebox{\tt DrawAngleArrow{\{}angle(), radius(), internal, clockwise{\}}}
+
+This command draws an arrow in the specified angle, a distance
+\textit{radius} from the angle. The angle is either
+\textit{internal} ($\leq 180^{\circ}$) or
+\textit{external} ($\geq 180^{\circ}$).
+The direction of the arrow is
+either \textit{clockwise} or \textit{anticlockwise}, and this
+direction must correspond with the letter sequence specified
+for the angle.
+Strange and unexpected results will be produced if
+the four parameters are not internally consistent.
+The arrow shape for the angleArrow is currently fixed,
+and cannot be changed using the \verb!ArrowShape! command for
+straight arrows (the author is happy to make this more flexible
+if necessary).
+
+
+For example, the following command draws a clockwise arrow,
+radius 3 units, in the internal angle $ABC$ from line $AB$
+to line $BC$.
+
+
+
+\begin{verbatim}
+drawAngleArrow{angle(ABC), radius(3), internal, clockwise}
+\end{verbatim}
+
+
+
+%-------------------------
+\item \framebox{\tt drawArrow(\textit{AB})} \hspace{5mm}
+ \framebox{\tt drawArrow(\textit{AB})[d]} \hspace{5mm}
+ \framebox{\tt drawThickarrow(\textit{AB,CD,FG, ...})}
+
+These commands draw arrows (or thick arrows) joining
+two points.
+The direction of the arrow is in the point order specified.
+The shape of the arrowhead is controlled by the
+\verb!ArrowShape! command (see Section~7.3).
+Parameters which control line-thickness
+are described in Section~4.6.1
+
+
+\begin{verbatim}
+drawArrow(AB)
+drawArrow(FG, HJ)
+drawThickarrow(BC)
+drawThickarrow(PQ, RS)
+\end{verbatim}
+
+
+An arrow can also be drawn a specified distance from one point
+towards another point, using a square-bracket option. For
+example, the following command draws an arrow a distance $d$
+units from point $A$ towards point $B$.
+
+
+\begin{verbatim}
+drawArrow(AB)[d]
+\end{verbatim}
+
+
+%-----------------------------
+\item \framebox{\tt DrawCircle(\textit{center, radius})}
+
+This command draws a circle defined by its radius and the
+point-name of its centre. The radius argument can be either a
+decimal, a variable, or the Pythagorean length of a line (e.g.\ AB).
+The following example draws a circle centre $C_2$, and radius 5
+units.
+
+
+\begin{verbatim}
+drawCircle(C2,5)
+\end{verbatim}
+
+
+In the following example, the radius argument
+is the variable \verb!r2!.
+
+
+\begin{verbatim}
+drawCircle(C2,r2)
+\end{verbatim}
+
+
+
+In the following example, the radius argument
+is the Pythagorean length of the line $AB$.
+
+
+\begin{verbatim}
+drawCircle(C2,AB)
+\end{verbatim}
+
+
+Note that \PiCTeX\ draws circles with the
+\verb!\circulararc! command, using a radius
+equivalent to the distance from the center to the point at
+which it starts drawing the arc.
+Consequently, if the units of the $x$ and $y$ axes are
+different, circles may be drawn strangely. {\MathsPIC}
+therefore generates a message to this effect in the output-file
+ if different units are selected for the two axes in the
+\verb!units! command (see Section~4.3.2).
+
+
+%-----------------------------
+\item \framebox{\tt DrawCircumcircle($ABC$)}
+
+This command draws the circumcircle of the triangle defined
+by the points A, B, C.
+
+
+%-----------------------------
+\item \framebox{\tt DrawCurve(\textit{ABC})}
+
+This command draws a smooth quadratic curve through three points
+$A,B,C$ in the point order specified.
+At present it uses the {\PiCTeX} \verb!\plot! command, and
+so it is only recommended for three points (for more than
+three points the resulting curve is unlikely to be `smooth').
+This command will be upgraded in the next version to give a smooth
+curve for more than three points.
+
+
+Note that curves drawn using this command
+ do \textit{not} break to
+avoid line-free zones associated with
+ the points (the \verb!drawLine! command for straight lines
+\textit{does} acknowledge line-free zones).
+
+%-----------------------------
+\item \framebox{\tt DrawExcircle($ABC$, $AB$)[${\delta}r$]}
+
+
+This command draws the excircle touching side $AB$ of the
+triangle $ABC$.
+The optional argument [${\delta}r$] is a fine adjustment
+to the radius of the excircle circle to facilitate drawing
+the figure in certain circumstances.
+
+
+In the following two examples, the first draws the true
+excircle, while the second draws the excircle with its
+radius reduced by 0.2 units.
+
+
+\begin{verbatim}
+drawExcircle(T1T2T3, T1T2)
+drawExcircle(T1T2T3, T1T2)[-0.2]
+\end{verbatim}
+
+
+%-----------------------------
+\item \framebox{\tt DrawIncircle($ABC$)[${\delta}r$]}
+
+This command draws the incircle of a triangle.
+The optional argument [${\delta}r$] is a fine adjustment
+to the radius of the incircle circle to facilitate drawing the figure.
+
+In the following two examples, the first draws the true
+incircle, while the second draws the incircle with its
+radius reduced by 0.2 units.
+
+\begin{verbatim}
+drawIncircle(T1T2T3)
+drawIncircle(T1T2T3)[-0.2]
+\end{verbatim}
+
+
+
+%-------------------------
+\item \framebox{\tt drawline(\textit{ABCD...})} \hspace{5mm}
+ \framebox{\tt drawline(\textit{AB})[6]} \hspace{5mm}
+ \framebox{\tt drawline(\textit{AB,CD,EFG, ...})}
+
+
+\framebox{\tt drawline*(\textit{ABCD...})}
+
+This command draws a line joining
+two or more points.
+Lines are drawn in the order specified.
+Lines are not drawn within line-free zones of points.
+
+Parameters which control line-thickness
+are described in Section~4.6.1.
+
+\begin{verbatim}
+drawline(AB)
+drawline(BCDE)
+drawline(FG, HJK, PQRST)
+\end{verbatim}
+
+
+A line can also be drawn a specified distance from one point
+towards another point, using a square-bracket option. For
+example, the following command draws a line a distance $d$
+units from point $A$ towards point $B$.
+
+
+\begin{verbatim}
+drawline(AB)[d]
+\end{verbatim}
+
+Note that some restrictions are associated with the square
+bracket option: (a) it can only be used when
+drawing a \textit{single} line; (b) a line-free zone associated with the
+second point will be ignored, (c) the order of the points $AB$ is
+important---the line is drawn from the first point
+\textit{towards} the second point (see Figure~11).
+
+Note that the \verb!drawline! command uses the {\PiCTeX}
+\verb!\putrule!
+command for horizontal and vertical lines, and the \verb!\plot!
+command for all other lines.
+However, the use of the \verb!\putrule! command is disabled
+when using the {\mathsPIC} \verb!drawline*! command, which uses only
+the \verb!\plot! command for all lines.
+Since the \verb!\plot! command should be used when using
+larger than normal dots (\verb!\setdots!) for horizontal or
+vertical lines, then this is achieved with the \verb!drawline*!
+command.
+
+
+
+%-----------------------------
+\item \framebox{\tt DrawPerpendicular(\textit{point,line})[foot]}
+
+
+This command draws the perpendicular from \textit{point} to
+the \textit{line}.
+ If the option [foot] is specified,
+then this command also draws the current \verb!pointsymbol()!
+character (default point-symbol is \verb!$\bullet$!)
+ at the point where the perpendicular joins the line.
+The following example draws the perpendicular from the
+ point $P$ to the line $AB$.
+
+
+
+\begin{verbatim}
+drawPerpendicular(P,AB)
+\end{verbatim}
+
+
+
+%--------------------------
+\item \framebox{\tt drawpoint(\textit{name})} \hspace{5mm}
+ \framebox{\tt drawpoint(\textit{name1 name2 ... })}
+
+
+This command draws the point-symbol at the point-location.
+Commas must not be used to separate points.
+ The default point-symbol is \verb!$\bullet$!, unless
+an optional point-symbol (or string of characters) was
+specified in the associated
+\verb!point! command. If the \verb![circle]! option was used
+with the \verb!point! command \textit{without} a radius parameter,
+then the \verb!$\circ$! symbol will be used (see
+the \verb!point! command).
+
+
+\begin{verbatim}
+drawpoint(T4)
+drawpoint(ABCDEF)
+drawpoint(P1 P2 P3 P4)
+\end{verbatim}
+
+
+%-----------------------------
+\item \framebox{\tt DrawRightangle(\textit{angle,symbolsize})}
+
+
+This command draws the standard right-angle symbol in the
+internal angle specified.
+ The following example draws a right-angle symbol (side
+3 units) in the internal angle ABC.
+
+
+\begin{verbatim}
+drawRightangle(ABC,3)
+\end{verbatim}
+
+%-------------------------
+\item \framebox{\tt drawThickline(\textit{ABCD...})} \hspace{5mm}
+ \framebox{\tt drawThickline(\textit{AB})[d]} \hspace{5mm}
+ \framebox{\tt drawThickline(\textit{AB,CD,EFG, ...})}
+
+This command draws a thick line joining
+two or more points in the point-order specified.
+Lines are not draw within line-free zones associated with points.
+
+Parameters which control line-thickness
+are described in Section~4.6.1.
+
+\begin{verbatim}
+drawThickline(AB)
+drawThickline(BCDE)
+drawThickline(FG, HIJ)
+\end{verbatim}
+
+
+An arrow can also be drawn a specified distance from one point
+towards another point, using a square-bracket option. For
+example, the following command draws an arrow a distance $d$
+units from point $A$ towards point$B$.
+
+
+\begin{verbatim}
+drawThickArrow(AB)[d]
+\end{verbatim}
+
+
+ %-----------------------------
+\item \framebox{\tt DrawTriangle($ABC$)}
+
+This command draws the triangle defined by the points $A, B, C$.
+Note that \verb!drawTriangle(ABC)! is equivalent to \verb!drawLine(ABCA)!.
+The \verb!drawTriangle! command checks
+that the area is not zero, and generates an error-message if it
+is (note that this area check
+is \textit{not} made when using the equivalent
+\verb!drawLine(ABCA)! command to draw a triangle).
+
+
+%-----------------------------
+\item \framebox{\tt inputFile($mathspic.doc$)[$loop$]} {\hspace{5mm}}
+ \framebox{\tt inputFile*($pictex.doc$)}
+
+The \verb!inputFile! command inputs a plain text file
+containing {\mathsPIC} commands. Optionally, the file can be input
+[\textit{loop}] times, in which case this command functions like a
+DO--LOOP.
+For example, the following command inputs the file
+\verb!newfile.dat! 4 times in succession.
+
+\begin{verbatim}
+inputFile(newfile.dat)[4]
+\end{verbatim}
+
+The \verb!inputfile*! command is used to input a file in
+\textit{verbatim},
+i.e.\ a file with \textit{no} {\mathsPIC} commands. For example, a file
+containing only \PiCTeX\ commands or data-points
+for plotting etc. A typical example might be the following file
+(curve-A.dat) which would be input verbatim
+using the command \verb!inputfile*(curve-A.dat)!.
+
+\begin{verbatim}
+%% curve-A.dat
+\setquadratic
+\plot 0 0
+ 3.56 4.87
+ 8.45 9.45
+ 5 7
+ 2.34 3.23 /
+\setlinear
+\end{verbatim}
+
+Note that the \verb!inputfile*! command has no
+[$loop$] option.
+
+%--------------------------
+\item
+\framebox{\tt paper{\{}units(\ ),xrange(\ ),yrange(\ ),axes(\ ),ticks(\ ){\}}}
+
+\smallskip
+
+\texttt{units({\it unit})}\ \ or\ \ \texttt{units({\it xunit,yunit})}
+
+\texttt{xrange({\it xlow,xhigh})}
+
+\texttt{yrange({\it ylow,yhigh})}
+
+\texttt{axes({\it XYLRTB})}
+
+\texttt{ticks({\it x,y})}
+
+
+The \verb!paper{..}! command defines a plot area with
+optional axes and tick-marks (see Section~4.3.1).
+
+For example, the following statement sets up a rectangular drawing area
+50mm x 50mm with axes on the \verb!L!eft (y-axis) and \verb!B!ottom
+(x-axis), and tick marks at 10mm intervals.
+
+
+\begin{verbatim}
+paper{units(mm),xrange(0,50),yrange(0,50),axes(LB),ticks(10,10)}
+\end{verbatim}
+
+
+All combinations of the axis-codes (XYLRTB) are allowed, and a *
+following an axis-code (e.g.\ L*) stops ticks being drawn on
+the specified axis.
+
+If it is necessary to have \emph{different} unit scales
+for the $x$ and $y$
+axes, say 1 cm and 2 mm respectively, then this is implemented
+by \verb!units(1cm,2mm)!, or \verb!units(cm,2mm)!. If there is
+no digit associated with a unit (e.g.\ mm), then {\mathsPIC}
+actions the command as \verb!1mm!.
+If only a single unit is specified (e.g.\ \verb!units(cm)!)
+then {\mathsPIC} automatically makes this the unit scale for
+\textit{both} axes.
+If the \verb!unit! option is omitted {\PiCTeX} will use
+the last defined units (within the same picture environment),
+the default units being \textit{xunit}=1pt and \textit{yunit}=1pt
+(see the {\PiCTeX} Manual, page~3; Wichura, 1992).
+
+
+
+%-----------------------
+\item \framebox{\tt
+point(\textit{name}){\{}...{\}}[\textit{symbol, linefree radius}]}
+
+
+\framebox{\tt
+point*(\textit{name}){\{}...{\}}[\textit{symbol, linefree radius}]}
+
+
+The \verb!point! command is used to define points.
+ Note that a point-name \textit{must} begin
+with a \textit{single} letter (either upper or lower case),
+and may have up to a \textit{maximum} of two following digits.
+
+The default point-symbol is the \verb!$\bullet$!.
+An optional alternative point-symbol (or string of characters)
+can be specified within square
+brackets e.g.\ \verb![$\triangle$]! (see Section~4.4).
+
+By default lines are drawn to the point location. However, the
+radius of an optional line-free zone can be specified within an
+optional square bracket e.g.\ \verb![$\triangle$,4]!
+(see Section~4.4).
+If a line-free radius is specified without a point-symbol, then
+the preceding comma must still be included; for example
+\verb![,5]!.
+
+An optional `{\verb!circle!}' can also be used
+as the \textit{symbol}. If a radius value is also
+included, e.g.\ \verb![circle, 5]! then
+a circle will be drawn having the specified radius (the radius
+value will also be assumed to be the line-free radius).
+If no radius value is specified,
+e.g.\ \verb![circle]!, then the
+small circle symbol (\verb!$\circ$!) is used instead (and
+line-free radius set to zero).
+
+
+Points can also be defined relative to \emph{previously defined}
+points. For example, as the intersection
+of two existing lines, or as a $+$ve or $-$ve extension (in the
+direction indicated by the letters) between two previously
+defined points, etc.
+
+The \verb!point*! command re-allocates new parameters (e.g.\
+coordinates, point-symbol, or line-free radius)
+to a previously defined point-name.
+
+Some examples of valid point commands are as follows.
+
+
+\begin{verbatim}
+point(A){5,5}
+point(B2){22,46}[circle]
+point(B2){22,46}[circle,5]
+point(C32){3,8}[$\Box$]
+point(D1){20,2}[$\Box$,4]
+point(D10){20,5}[,4]
+point(D2){B2, shift(5,5)}
+point(D3){D2, polar(6,32 deg)}
+point(D4){D2, polar(6,1.2 rad)}
+point(D2){intersection(AB,CD)}
+point(F){PointOnLine(AB,5.3)}
+point(G){perpendicular(P,AB)}
+point(G2){Q, rotate(P, 23 deg)}
+point(H){circumcircleCenter(ABC)}
+point(J){incircleCenter(ABC)}
+point(K){excircleCenter(ABC,BC)}
+point*(A){6,3}
+point*(B){B, shift(5,0)}
+point*(C){C}[,6]
+\end{verbatim}
+
+
+%--------------------------
+\item \framebox{\tt PointNumber(n)}
+
+This command allows the array space
+used for holding the total number of points and variables
+(combined) to be increased (or decreased).
+ This statement must therefore be placed before
+any \verb!point! statements, and so is best used right at
+the beginning of the {\mathsPIC} file.
+The default number is set at 50 points.
+
+
+\begin{verbatim}
+PointNumber(55)
+\end{verbatim}
+
+
+If the total number of points and variables combined exceeds
+the allocated number then
+a `fatal error' is triggered, and the program terminates (see
+Section~4.4.5).
+
+
+
+%--------------------------
+\item \framebox{\tt PointSymbol(\textit{symbol, linefree radius})}
+
+This command allows the default point-symbol (\verb!$\bullet$!,
+line-free radius zero) to be changed.
+The syntax of this command mirrors exactly that of the
+square-bracket option associated with the \texttt{point} command.
+The PointSymbol command is particularly useful where a set of
+points uses the same point-symbol (Figure~16), and also
+when drawing graphs (Figure~15).
+
+
+For example, the following command changes the
+point-symbol to $\odot$ (\verb!$\odot$!)
+having a line-free radius of 0.7 units.
+
+\begin{verbatim}
+PointSymbol($\odot$, 0.7)
+\end{verbatim}
+
+Note that the \verb!PointSymbol! command only influences
+subsequent \verb!point! commands.
+For example, the following commands will make points $A$ and $B$
+be drawn as circles having radius of 5 units.
+
+\begin{verbatim}
+variable(r){5}
+PointSymbol(circle,r)
+point(A){5,5}
+point(B){10,12}
+\end{verbatim}
+
+Note that the optional square bracket of the \verb!point! command
+overrides the PointSymbol command.
+The point-symbol can be reset to the default $\bullet$
+(\verb!$\bullet$!) using the command \verb!PointSymbol(default)!.
+
+
+%%--------
+\item \framebox{\tt show ...}
+
+This command forces {\mathsPIC} to
+ return the value of a calculation or specified parameter; for
+ example, the value of a particular angle, or the length of a line.
+The result is shown in the output-file as a commented line.
+ This allows {\mathsPIC} commands to be
+ adjusted in the light of calculations.
+
+\begin{verbatim}
+show(B) %% for both Points and Variables
+show(r) %% for both Points and Variables
+showLength(AB)
+showIntersection(AB,CD)
+showAngle(ABC)
+showArea(ABC)
+\end{verbatim}
+
+When the above examples are processed, the results appear
+as commented lines in the output-file as follows.
+
+\begin{verbatim}
+%% show(B) Point (22.12432, 18.96723)
+%% show(r) Variable (8.25367)
+%% showLength(AB) 25.35746
+%% showIntersection(AB,CD) (15.13245, 22.74723)
+%% showAngle(ABC) 39.35746 degrees (0.68691 radians)
+%% showArea(ABC) 54.54267
+\end{verbatim}
+
+
+%--------------------------
+\item \framebox{\tt text({\it string}){\{}{\it x,y}{\}}[{\it position}]}
+
+\framebox{\tt text({\it string}){\{}{\it pointname,
+ adjustment}{\}}[{\it position}]}
+
+\smallskip
+where the \textit{adjustment} option is either {\tt shift($dx$,$dy$)}
+or {\tt polar($r$,$\theta$)}.
+
+This command puts the given text-string either at the named
+point, or with a displacement specified by the
+optional \texttt{shift($dx$,$dy$)} or
+\texttt{polar($r$,$\theta$)} parameters.
+By default the text is centered vertically and
+horizontally at the specified point.
+
+ Optionally, text can be placed relative to a
+point using appropriate combinations of the
+ {\PiCTeX} \textit{position} options \verb! l t r B b! to
+align the \textbf{l}eft edge, \textbf{r}ight edge, \textbf{t}op edge,
+\textbf{B}aseline, \textbf{b}ottom edge
+respectively of the text box with the point-location
+(see the {\PiCTeX} Manual, page~5; Wichura, 1992).
+ For example, the text box \framebox{\texttt{This is point P}}
+ would be aligned such that the right edge of the text box would be
+centered vertically at the point $P$,
+using \verb!text(This is point P){P}[r]!.
+
+The \verb!text! command can be used to label points, or to simply
+position text in a diagram, as shown in the following examples.
+
+\begin{verbatim}
+text(A){5,6}
+text($A_1$){A1, shift(2, 2)}
+text($Z2$){Z2, shift(5, -5)}[tr]
+text($Z3$){Z2, polar(5, 20 deg)}[Br]
+text($Z4$){Z2, polar(5, 1.34 rad)}
+text(\framebox{$Z5$}){Z3}
+\end{verbatim}
+
+
+%-----------------------
+\item
+\framebox{\tt variable(\textit{name}){\{}\textit{value}{\}}}
+
+\framebox{\tt variable*(\textit{name}){\{}\textit{value}{\}}}
+
+
+The \verb!variable! command is used to define scalar variables
+(see Section~4.5).
+ Note that a variable-name \textit{must} begin
+with a \textit{single} letter (either upper or lower case),
+and may have up to a \textit{maximum} of two following digits.
+Variables and points have the same name structure, and a
+variable cannot have the same name as a point.
+The scalar argument in the braces can be either a numeric value,
+ another variable, or two points (implying the distance
+between the two points).
+
+New values can be re-allocated to existing variable-names using
+the equivalent \verb!variable*! command; thus the variable
+\verb!r3! can be re-allocated the value 15 using the command
+\verb!variable*(r3){15}! (if the variable-name has not been used
+before then {\mathsPIC} will generate an error message).
+
+Variables can be manipulated using the commands
+\verb!advance!, \verb!multiply!, \verb!divide! and \verb!mod!.
+
+
+The following are examples of valid \verb!variable! commands.
+
+\begin{verbatim}
+variable(r3){20}
+variable(z3){3.46E-2}
+variable(r4){r1}
+variable(r5){AB}
+variable*(r5){6}
+variable(x1){w, advance(-6)}
+variable(x2){w2, divide(-p)}
+variable(x3){AB, multiply(2)}
+variable*(x1){x1, mod(3)}
+variable(g){angle(ABC)}
+variable(g2){area(ABC)}
+variable(x3){Xpoint(P3)} % gets the x-coordinate of a point
+variable(y3){Ypoint(P3)} % gets the y-coordinate of a point
+variable(p1){3.14159} % use p1 to represent Pi
+variable(e){2.71828}
+\end{verbatim}
+
+
+\end{itemize}
+%-----------------------------
+
+
+\subsection{Summary of \mathsPIC\ commands}
+
+The following list shows the format and typical usage
+of all {\mathsPIC} commands.
+Although {\mathsPIC} commands are \textit{not} case sensitive,
+in this summary of commands points are represented using upper case
+letters, and variables are represented using lower case
+letters. Note that a leading
+\texttt{$\backslash$\gap} is used for copying \TeX\ or \PiCTeX\
+lines verbatim, for example with macros or coordinates of data
+points etc.
+
+\begin{verbatim}
+\ 4.5 6.3
+\setdashes
+\typeout{drawing circle C2 now}%
+arrowShape(4,30,40)
+arrowShape(default)
+drawAngleArc{angle(ABC), radius(3), internal, clockwise}
+drawAngleArrow{angle(ABC), radius(3), internal, clockwise}
+drawArrow(AB)
+drawArrow(AB)[d] %% draw arrow distance d from A towards B
+drawArrow(AB,CD)
+drawCircle(J,12)
+drawCircle(C,r2)
+drawCircle(C,AB) %% the radius is length of line AB
+drawCircumcircle(ABC)
+drawCurve(ABC) %% best for only three points
+drawExcircle(ABC)[-0.2]
+drawIncircle(ABC)[-0.3]
+drawLine(AB)
+drawline*(AB, CDEF) %% the * option disables use of \putrule
+drawLine(AB)[d] %% draw line distance d from A towards B
+drawLine(ABCDE)
+drawPerpendicular(P,AB)
+drawPerpendicular(P,AB)[foot] %% draws pointSymbol at the foot
+drawPoint(B)
+drawPoint(ABP1P2)
+drawRightAngle(ABC, 4)
+drawThickArrow(AB)
+drawThickArrow(AB)[d] %% draw thickarrow distance d from A towards B
+drawThickArrow(AB,CD)
+drawThickLine(PQ)
+drawThickLine(RS,TU)
+drawTriangle(ABC)
+inputFile(mathspic.dat)
+inputFile(mathspic.dat)[4]
+inputfile*(fig2.dat) %% disables mathsPIC processing of file
+paper{units(1mm,3mm),xrange(-5,50),yrange(-5,50),axes(LR)}
+paper{units(cm),xrange(0,5),yrange(0,9),axes(X*Y),ticks(1,1)}
+point(D1){20,2}
+point(D4){6.3,8.9534E-1}
+point(P){x1,y1}
+point(P){AB,PQ}
+point(D2){20,2}[circle]
+point(D3){20,3}[circle,5]
+point(D4){20,4}[$\Box$,4]
+point(D5){20,7}[,4] %% set the line-free radius
+point(E1){D1, shift(5,6)}[$\Box$]
+point(E5){D1, shift(r2,6)}
+point(E2){D2, polar(8,45)} %% deg is the default
+point(E2){D2, polar(8,45 deg)}
+point(E6){D2, polar(r4,45 deg)}
+point(E5){D2, polar(AB,45 deg)}[,5]
+point(D32){midpoint(AB)}
+point(D2){intersection(AB,CD)}
+point(F){PointOnLine(AB,5.3)}
+point(G){perpendicular(P,AB)}
+point(G){perpendicular(P,AB)}
+point(G2){Q, rotate(P, 23 deg)} %% rotate Q about P by 23 deg
+point(H){circumcircleCenter(ABC)}
+point(J){incircleCenter(ABC)}
+point(K){excircleCenter(ABC,BC)}
+point*(D1){20,3}
+point*(E1){D1, shift(3,0)}
+point*(E1){E1}[,6] %% change the line-free radius
+pointNumber(67) %% default is 50 points
+pointSymbol($\odot$)
+pointSymbol($\odot$,3)
+pointSymbol(,4)
+pointSymbol(default)
+show(P3)
+show(m)
+showAngle(ABC)
+showArea(ABC)
+showIntersection(AB,CD)
+showLength(AB)
+text(P){5,7}
+text($A$){A}
+text($K$){K}[r]
+text($B$){B, shift(5,5)}
+text(\framebox{$C$}){C, polar(5,62 deg)}[Br]
+variable(r1){15}
+variable(z3){4.875E-2}
+variable(d){AB}
+variable(d2){d1}
+variable(x1){w, advance(6)}
+variable(x1){w, advance(-23.55)}
+variable(x2){w2, divide(-p)}
+variable(x3){AB, multiply(2)}
+variable(g){angle(ABC)}
+variable(g2){area(ABC)}
+variable(x3{Xpoint(P3)} % gets the x-coordinate of a point
+variable(y3){Ypoint(P3)} % gets the y-coordinate of a point
+variable(p1){3.14159} % use p1 to represent Pi
+variable(e){2.71828}
+variable*(r1){20}
+variable*(x1){x1, mod(3)}
+\end{verbatim}
+
+
+Note that the old \verb!latex{...}! \verb!pictex{...}! and
+\verb!tex{...}! `wrapper' commands (for copying their argument
+unchanged into the output file) have been superseded by the
+more convenient
+\texttt{$\backslash$} and \texttt{$\backslash$\gap} commands,
+but are still available to allow downwards
+compatibility with earlier versions of {\mathsPIC}.
+
+
+\subsection{Useful \PiCTeX\ commands}
+
+ The following is a list of {\PiCTeX} commands which are
+particularly useful for including in the {\mathsPIC} file, mainly for
+ controlling the thickness of lines and axes, customising dash
+ patterns and symbol spacing, and for plotting and rotation.
+ Note that there is a section on {\PiCTeX} in Alan
+Hoenig's recent book \textsl{\TeX\ Unbound}\footnote{Hoenig A
+(1998). \textsl{\TeX\ Unbound: \LaTeX\ and \TeX\ strategies for fonts,
+graphics, \& more.} (Oxford University Press, UK) pp 580.
+\textsc{isbn}: 0-19-509685-1 (hardback), 0-19-509686-X
+(paperback); see pages 377--389.}
+ which also includes a brief list of commands.
+ Note that where small angle brackets are shown (e.g.\ \verb!<!) then
+ these must be used exactly as shown.
+
+
+\begin{verbatim}
+\grid {cols} {rows} %% eg \grid {5} {10}
+\setdashpattern <4pt, 2pt>
+\setdashes <7pt> %% equivalent to \setdashpattern <7pt, 7pt>
+\setdashes %% default is \setdashes <5pt>
+\setdots <4pt>
+\setdots %% default is \setdots <5pt>
+\setsolid %% sets solid-line mode (ie not dashes/dots)
+\setlinear %% sets straight-line plotting mode (ie not quadratic)
+\setquadratic %% sets curved plotting for graphs etc
+\setplotsymbol({\large .})
+\setplotsymbol({\tiny .}) %% default size for curves (used by \plot)
+\plotsymbolspacing=2pt %% sets spacing between plot symbols (used by \plot)
+\plotheading{..} %% eg \plotheading{This is a quadratic curve}
+\headingtoplotskip=1cm %% separation between plotheading and graph
+\linethickness=2pt %% for horiz & vert lines: default 0.4pt
+\frame <sep> {text} %% eg \frame <5pt> Hello
+\rectangle <width> <height> %% eg \rectangle <2cm> <1cm>
+\putrectangle corners at 5 10 30 5 %% corners at Top-left Bottom-right
+\inboundscheckon %% restricts plotting to plotting area
+\inboundscheckoff %%
+\normalgraphs %% restores default values for graph parameters
+\circulararc 30 degrees from 3.5 4.5 center at 5 5
+\ellipticalarc axes ratio 2:1 360 degrees from 3 3 center at 5 5
+(axes ratio is major-axis:minor-axis, ie a:b)
+\end{verbatim}
+
+Note that {\PiCTeX} also has an excellent rotation facility.
+{\PiCTeX} will rotate about a given point, by a given angle, all
+picture elements (but not text) which
+are detailed between its \verb!\startrotation...! and
+\verb!\stoprotation! commands. However the decimal value of
+the Sine and Cosine angle must be supplied (see below).
+If the point is not specified then
+rotation is performed about the origin. The format is as follows.
+
+\begin{verbatim}
+\startrotation by cos(t) sin(t) [about x y]
+...
+\stoprotation
+\end{verbatim}
+
+This command is particularly useful for rotating curves.
+For example, to rotate an ellipse by 30 degrees about the
+point (5,5) one would write
+
+\begin{verbatim}
+\startrotation by 0.86602 0.5 about 5 5
+\ellipticalarc.....
+\stoprotation
+\end{verbatim}
+
+A {\PiCTeX} error-bar facility is also available by loading
+the file \verb!errorbar.tex! (see Section~9.4).
+Note that {\PiCTeX} does allow more sophisticated graph axes and
+tick-marks to be setup, as well as shading of enclosed areas.
+However, these are complicated and require access
+to the {\PiCTeX} Manual (see Section~9.5), and are
+currently outside the scope of {\mathsPIC}.
+
+%%---------------------------
+\section{Examples}
+
+This section describes some practical examples of figures drawn
+using {\mathsPIC}, together with the associated code.
+A collection of more complicated examples
+can be found in the the companion document \verb!examples.tex!
+which is included in the {\mathsPIC} package.
+
+When drawing a new figure or diagram, the author finds it best
+to start with a graduated coordinate frame (see Figure~1) using
+the \verb!axes! and \verb!ticks! options of the \verb!paper!
+command.
+The next step is to define an \textit{anchor point} from which other
+points can be derived---this has the advantage that the whole
+figure can then be moved
+by simply changing the coordinates of the anchor point.
+If necessary, different parts of a complicated figure can be made
+having their own separate anchor points, allowing the various parts
+to be easily adjusted relative to each other.
+Finally (if the frame is not required), the frame should
+be moved close to the edge of the figure
+by adjusting the \verb!xrange! and \verb!yrange! parameters, in
+order to remove unnecessary surrounding white space, after which the
+the \verb!axes! and \verb!ticks! options of the
+\verb!paper! command can be removed, ready for inserting into
+the document. The code can then be either pasted into the
+document directly, or kept as a separate file and then
+\verb!\input! as required.
+
+As regards scales and units, the author finds it most
+convenient to use the mm units and to keep the $x$ and $y$ scales
+the same whenever possible (i.e.\ use \verb!paper{units(mm)...}!),
+since this allows easy scaling up and down after the figure has
+been finished (see Section~4.3.2 for details regarding the use of
+variables to control the units).
+
+The appropriate \LaTeX\ commands to \verb!\input! the file and
+position the graphic on the page are described in Section~8.
+
+
+
+%-----
+\subsection{Input- and output-files}
+
+The following example {\mathsPIC} file (input-file)
+illustrates how some of these commands are used
+to draw Figure~4. Note that the dashed line $AD$ is drawn after
+the {\PiCTeX} \verb!\setdashes! command is invoked; following
+this \verb!\setsolid! is used before drawing the right-angle
+symbol.
+Also, the points $A,B,C$ are defined using the \TeX\
+\verb!\odot! symbol $\odot$, in conjunction with a line-free
+zone of 1.2 mm in order to make the lines go to the edge of the
+symbol---the value of the radius of such \TeX\ symbols
+has to be determined by trial and error---see Table~1
+(Section~4.4.3).
+
+\bigskip
+
+%%------------Figure 4-----------------
+%% the triangle
+%% testing importing a small fig (works OK)
+ \begin{figure}[hbt]
+ \begin{center}
+ %\framebox{
+ \strut\vbox{
+ %% triangle
+ \input{mPICm04.pic}
+ }
+ % }
+ \caption{\ }
+ \end{center}
+\end{figure}
+%-----------------------
+
+\begin{verbatim}
+% mPICm04.m (Figure 4)
+\documentclass[a4paper]{article}
+\usepackage{pictexwd}
+\begin{document}
+%-------------------
+\beginpicture
+\setdashes
+paper{units(mm),xrange(0,70),yrange(0,50),axes(LRTB),ticks(10,10)}
+\setsolid
+point(A){10,10}[$\odot$,1.2] %% anchor point
+point(B){A, polar(40, 50 deg)}[$\odot$,1.2]
+point(C){A, polar(50, 10 deg)}[$\odot$,1.2]
+point(D){perpendicular(B,AC)}
+drawPoint(ABCD)
+drawLine(ABCA)
+\setdashes
+drawLine(BD)
+\setsolid
+drawRightangle(BDC,2.5)
+text($B$){B, shift(-1,4)}
+text($A$){A, shift(-4,-2)}
+text($C$){C, shift(4,-1)}
+text($D$){D, shift(1,-4)}
+showLength(BD)
+showLength(AC)
+showArea(ABC)
+\endpicture
+%------------------
+\end{document}
+\end{verbatim}
+
+
+When the above file is processed by {\mathsPIC} the
+output-file (\verb!.mt! file) is as follows. Note how the
+{\PiCTeX} commands are preceded by their
+{\mathsPIC} commands (commented out), some of which
+have additional information added (e.g.\ the
+coordinates of a derived point---see the
+line \verb!%% point(D)...!\ ).
+Being able to compare the {\mathsPIC} and resulting {\PiCTeX}
+commands in the output-file is particularly useful when
+debugging.
+Note also how the \texttt{show} commands
+return the lengths AD, BC, and the area ABC.
+
+\begin{verbatim}
+% mPICm04.m (Figure 4)
+\documentclass[a4paper]{article}
+\usepackage{pictexwd}
+\begin{document}
+%-------------------
+\beginpicture
+%% paper{units(mm),xrange(0,70),yrange(0,50),axes(LB),ticks(10,10)}
+\setcoordinatesystem units <1mm, 1mm>
+\setplotarea x from 0 to 70, y from 0 to 50
+\axis left ticks numbered from 0 to 50 by 10 /
+\axis bottom ticks numbered from 0 to 70 by 10 /
+%% point(A){10,10}[$\odot$,1.2] ( 10 , 10 ) %% anchor point
+%% point(B){A,polar(40,50deg)}[$\odot$,1.2] ( 35.7115 , 40.64178 )
+%% point(C){A,polar(50,10deg)}[$\odot$,1.2] ( 59.24039 , 18.68241 )
+%% point(D){perpendicular(B,AC)} ( 40.17626 , 15.32089 )
+%% drawPoint(ABCD)
+\put {$\odot$} at 10 10 %% A
+\put {$\odot$} at 35.7115 40.64178 %% B
+\put {$\odot$} at 59.24039 18.68241 %% C
+\put {$\bullet$} at 40.17626 15.32089 %% D
+%% drawLine(ABCA)
+\plot 10.77135 10.91925 34.94016 39.72252 / %% AB
+\plot 36.58879 39.82301 58.3631 19.50117 / %% BC
+\plot 58.05862 18.47403 11.18177 10.20838 / %% CA
+\setdashes
+%% drawLine(BD)
+\plot 35.91988 39.46001 40.17626 15.32089 / %% BD
+\setsolid
+%% drawRightangle(BDC,2.5)
+\plot 42.63828 15.75501 42.20416 18.21703 /
+\plot 39.74214 17.78291 42.20416 18.21703 /
+%% text($B$){B,shift(-1,4)}
+\put {$B$} at 34.7115 44.64178
+%% text($A$){A,shift(-4,-2)}
+\put {$A$} at 6 8
+%% text($C$){C,shift(4,-1)}
+\put {$C$} at 63.24039 17.68241
+%% text($D$){D,shift(1,-4)}
+\put {$D$} at 41.17626 11.32089
+%% showLength(BD) 25.7115
+%% showLength(AC) 50
+%% showArea(ABC) 642.7875
+\endpicture
+%------------------
+\end{document}
+\end{verbatim}
+
+
+If the above output-file (\verb!.mt! file) is to be included or
+\verb!\input! into a document (say, into a
+\verb!figure! environment), it is sometimes useful
+to reduce the size of the file by removing
+all the \verb!%%! comment lines (using the
+\textsc{clean.exe} utility---see Section~3.2), as well as
+some of the header and footer lines which are not now required,
+as follows.
+
+\begin{verbatim}
+% mPICm04.pic (Figure 4)
+%------------
+\beginpicture
+\setcoordinatesystem units < 1mm, 1mm>
+\setplotarea x from 0 to 70, y from 0 to 50
+\axis left ticks numbered from 0 to 50 by 10 /
+\axis bottom ticks numbered from 0 to 70 by 10 /
+\put {$\odot$} at 10 10 %% A
+\put {$\odot$} at 35.7115 40.64178 %% B
+\put {$\odot$} at 59.24039 18.68241 %% C
+\put {$\bullet$} at 40.17626 15.32089 %% D
+\plot 10.77135 10.91925 34.94016 39.72252 / %% AB
+\plot 36.58879 39.82301 58.3631 19.50117 / %% BC
+\plot 58.05862 18.47403 11.18177 10.20838 / %% CA
+\setdashes
+\plot 35.91988 39.46001 40.17626 15.32089 / %% BD
+\setsolid
+\plot 42.63828 15.75501 42.20416 18.21703 /
+\plot 39.74214 17.78291 42.20416 18.21703 /
+\put {$B$} at 34.7115 44.64178
+\put {$A$} at 6 8
+\put {$C$} at 63.24039 17.68241
+\put {$D$} at 41.17626 11.32089
+\endpicture
+%----------
+\end{verbatim}
+
+
+Note that the remaining comments at the end of the
+\verb!\plot! and \verb!\put! lines are generally sufficient to
+understand what each line relates to.
+Note also that the \textsc{clean.exe} utility only removes lines
+having a leading \verb!%%! pair of characters, so comment lines
+prefixed with only a single \verb!%! character will remain.
+
+
+%---------------------
+\subsection{Line modes}
+
+When drawing figures with both solid and dashed lines
+it is necessary to switch between the {\PiCTeX} commands
+\verb!\setdashes! and \verb!\setsolid! (see Section~6.3),
+as in the following code for drawing the rectangular box
+shown in Figure~5.
+
+The default \verb!\setdashes! gives alternating lines and
+spaces, each of width 5pt.
+More fancy dash-patterns (see Figure~5) can be easily generated using
+the {\PiCTeX} \verb!\setdashpattern! command which defines
+the pattern cycle, and hence takes an even number of
+parameters. If a particular
+dash-pattern is to be used several times in a figure,
+then a defining macro may be useful, as follows.
+
+\begin{verbatim}
+\def\fancydashes{\setdashpattern <6pt, 2pt, 1pt, 2pt>}
+...
+\fancydashes
+\end{verbatim}
+
+
+Note that in Figure~5 all the points are defined, directly or
+indirectly, relative to point $A$, with the effect that
+the position of the whole figure
+can be adjusted simply by altering the coordinates of
+point $A$. This can be useful when drawing diagrams
+having several components since the relative position
+of each component can then be easily adjusted.
+
+
+
+
+
+%-----figure 5-----------------
+\begin{figure}[hbt]
+%% the rectangular box
+\begin{center}
+ \strut\input{mPICm05.pic}
+ \caption{\ }
+\end{center}
+\end{figure}
+%%----------------------
+
+\begin{verbatim}
+%% mPICm05.m (Figure 5)
+\beginpicture
+paper{units(mm), xrange(0,50), yrange(0,62)}
+variable(s){20} % Sides front & back
+variable(L){34} % Length
+variable(a2){56.6} % Angle degrees
+\def\fancydashes{\setdashpattern <6pt, 2pt, 1pt, 2pt>}
+point(A){5,7}
+point(B){A, polar(s,90)}
+point(C){B, polar(s,0)}
+point(D){A, polar(s,0 )}
+point(H){A, polar(L,a2 deg)}
+point(G){B, polar(L,a2 deg)}
+point(F){C, polar(L,a2 deg)}
+point(E){D, polar(L,a2 deg)}
+drawpoint(ABCDEFGH)
+\linethickness=2pt \setsolid
+drawline(ABCDA)
+\setdashes
+drawline(HGFEH)
+\linethickness=0.4pt \fancydashes
+drawline(AH, BG, CF, DE)
+text($A$){A, shift(-2,-4)}
+text($B$){B, shift(-4,1)}
+text($C$){C, shift(4,0)}
+text($D$){D, shift(1,-4)}
+text($E$){E, shift(4,0)}
+text($F$){F, shift(2,4)}
+text($G$){G, shift(-1,4)}
+text($H$){H, shift(-4,1)}
+\endpicture
+\end{verbatim}
+
+%------------------
+\subsection{Arrows}
+
+Arrows can be drawn in all possible orientations,
+will \textit{stretch} between points, and arrow-heads
+are readily customised using the
+{\mathsPIC} \texttt{Arrowshape} command (see also Salomon,
+1992).
+
+Although arrow shape can of course be controlled using
+standard {\PiCTeX} commands,
+the {\mathsPIC} \texttt{Arrowshape} command makes this
+easier by allowing you to define the angle
+parameters ($B$ and $C$) of the arrow-head directly (see box).
+ The default arrowshape is equivalent to the following command
+
+\begin{verbatim}
+Arrowshape(2,30,40)
+\end{verbatim}
+
+
+%%--------BOX with arrow diagram----Figure 6----
+
+\begin{figure}[hbt]
+\begin{center}
+ \strut\input{mPICm06.pic}
+ \caption{\ }
+\end{center}
+\end{figure}
+%%---------------------------------------
+
+
+If the arrowshape has been altered, it can be reset using the
+command \verb!ArrowShape(default)!.
+ Curved arrows (circular arcs) are drawn using the \verb!drawAngleArrow!
+command, which takes parameters for the angle, radius of arc,
+direction, and whether the angle is internal or external
+(see Figures~7 and~8).
+
+
+%% ? keep this next triangle fig & code together
+
+\begin{figure}[hbt]
+\noindent
+\begin{minipage}{4cm}
+%-----------------
+\begin{verbatim}
+% mPICm07.m (Figure 7)
+\beginpicture
+paper{units(mm),xrange(5,45),yrange(5,45)}
+point(A){30,30}
+point(P){10,10}
+point(B){30,10}
+drawPoint(APB)
+drawLine(APBA)
+text($A$){A,shift(1,5)}
+text($B$){B,shift(5,0)}
+text($P$){P,shift(-5,0)}
+drawAngleArrow{angle(BPA),radius(11),anticlockwise,internal}
+text($\psi$){P,polar(7,22.5 deg)}
+drawRightangle(ABP,2.5)
+\endpicture
+\end{verbatim}
+\end{minipage}
+%%-----------
+ \hspace{3cm}
+%%-----------
+\begin{minipage}{4cm}
+%% arrow1
+ \vspace{.1mm}
+ %% small triangle with angle arrow (arrow1)
+ \strut\input{mPICm07.pic}
+ \vspace{-12mm} %%to adjust the position of the caption%%
+ \caption{\ }
+ \vspace{2.5cm}
+\end{minipage}
+%----------
+\hfill
+\end{figure}
+
+
+Arrows can also be used to link elements in a diagram,
+ as shown in Figure~8. The right-hand diagram uses the
+ \texttt{drawArrow} command; the small gap between the
+arrows and the letters $P,Q,R,T$ being due to the 5 unit
+line-free radius associated with these points
+(see \texttt{mpicm08b.m}). The arrows
+are easily `stretched' to accommodate their labels
+ simply by adjusting the separation of the nodes using the
+ \texttt{polar($r$,$\theta$)} commands (cf.\ Feruglio, 1994).
+
+
+\bigskip
+
+%%------------Figure 8-----------------
+%% the plotting area
+\begin{figure}[hbt]
+\begin{center}
+\noindent
+%\framebox{
+\begin{minipage}{3cm}
+ \begin{center}
+ %\vspace{2cm} %% controls top space
+ \input{mPICm08a.pic}
+ %\vspace{5mm} %% controls space between pict and caption
+ a. Circular arrows
+ \end{center}
+\end{minipage}
+%} % end of framebox
+%-----------------------
+\hspace{12mm} %% controls space between figs
+%%\bigskip\bigskip %% use this to place vertically
+%% use this when making A5 booklet to put vertically
+%% and use with \clearpage to flush the floats
+%%----------------------
+%\framebox{
+\begin{minipage}{5cm}
+ \begin{center}
+ %\vspace{3mm} %% controls top space
+ \input{mPICm08b.pic}
+ %\vspace{5mm} %% controls space between pict and caption
+ b. Straight arrows
+ \end{center}
+\end{minipage}
+%} % end of framebox
+\caption{\hspace{7mm} }
+\end{center}
+\end{figure}
+%-----------------------
+
+
+\begin{verbatim}
+%% mpicm08a.m (Figure 8a)
+\beginpicture
+paper{units(mm),xrange(10,40),yrange(0,45)}
+point(N){15,20}
+point(S){N,shift(20,0)}
+text(\framebox{$N$}){N,shift(0,-2.5)}
+text(\framebox{$S$}){S,shift(0,-2.5)}
+point(Z){midpoint(NS)}
+drawAngleArrow{angle(NZS),radius(NZ),clockwise,internal}
+point(N1){N,shift(2,1)}
+point(S1){S,shift(-2,1)}
+point(Z1){Z,shift(0,-3)}
+drawAngleArrow{angle(N1Z1S1),radius(N1Z1),clockwise,internal}
+point(N2){N1,shift(2,-0.5)}
+point(S2){S1,shift(-2,-0.5)}
+point(Z2){Z,shift(0,-10)}
+drawAngleArrow{angle(N2Z2S2),radius(N2Z2),clockwise,internal}
+\endpicture
+\end{verbatim}
+
+\bigskip
+
+\begin{verbatim}
+%% mpicm08b.m (Figure 8b)
+\beginpicture
+paper{units(mm),xrange(0,45),yrange(0,45)}
+point(P){5,10}[$P$,5]
+point(Q){P,polar(30,90 deg)}[$Q$,5]
+point(R){Q,polar(40,0 deg)}[$R$,5]
+point(T){P,polar(30,0 deg)}[$T$,5]
+drawPoint(PQRT)
+drawArrow(PQ,QR,PT,TR,PR)
+point(P1){midpoint(PQ)}
+text($p_1$){P1,shift(3,0)}
+point(P2){midpoint(PT)}
+text($p_2$){P2,shift(0,-3)}
+point(P3){midpoint(PR)}
+text($p_3$){P3,shift(2,-2)}
+point(T1){midpoint(TR)}
+text($t$){T1,shift(3,0)}
+point(Q1){midpoint(QR)}
+%% use a macro for the label
+\newcommand{\q}{$q \star q \star q \star q \star q$}
+text(\q){Q1,shift(-1,3)}
+\endpicture
+\end{verbatim}
+
+
+%%-------------------
+\subsection{Circles}
+
+{\MathsPIC} allows the point-symbol to be designated as a
+circle using the \verb![circle,r]! option to the
+\texttt{point} command, which not only gives
+the circles an internal line-free zone, but
+also arranges that they are drawn by the
+\texttt{drawPoint} command, as shown in Figure~9.
+This construction greatly simplifies the drawing of directed
+graphs, trees and equivalent structures.
+
+\bigskip
+
+%-------------figure 9----------
+\begin{figure}[hbt]
+\begin{center}
+ %% 4 circles
+ \strut\input{mPICm09.pic}
+ \caption{\ }
+\end{center}
+\end{figure}
+%-----------------------
+
+
+\begin{verbatim}
+%% mPICm09.m (Figure 9)
+\beginpicture
+paper{units(mm),xrange(0,70),yrange(0,60)}
+point(A){30,11}[circle,8]
+point(B){A,shift(-10,30)}[circle,15] %% big circle
+point(C){A,polar(30,20 deg)}[circle,5]
+point(D){A,polar(45,50 deg)}[circle,7]
+drawPoint(ABCD)
+drawLine(AB,AC,BC,BD,CD)
+\setdashes
+drawLine(AD)
+text($A$){A}
+%% use a macro for the formula
+\newcommand{\formula}{%
+\ $\displaystyle \sum_{p\ge0} \Delta_{jp} z^{(p+1)}$%
+\ }%
+text(\formula){B}
+text($C$){C}
+text($D$){D}
+\endpicture
+\end{verbatim}
+
+Note that in this particular case it is necessary to define the
+maths formula using \verb!\displaystyle!, in order to
+avoid the embedded \verb!\textwidth! white space associated with
+using \verb!\vbox{\formula}! in the \verb!\text()! command,
+ and hence allow centering of the figure.
+Note also how the {\mathsPIC} \texttt{$\backslash$\gap...}
+commands make it easy to include multi-line macros
+in the {\mathsPIC} file.
+
+
+%%---------------
+
+Points on circles (and their labels) are most easily defined
+and positioned using the \texttt{polar($r$,$\theta$)} option,
+as shown in the {\mathsPIC} file for Figure~10.
+Notice the use of the variable \verb!r! for the radius of the
+circle (allocated using the command \verb!variable(r){20}!),
+which then allows the use of \verb!r! to define the radius in
+the \verb!polar! commands for the points $P,Q,S$.
+
+%%---------Figure 10 circles---------------------
+\begin{figure}[hbt]
+\begin{center}
+ %% circle and chord with two angles
+ \strut\input{mPICm10.pic}
+ \caption{\ }
+ \end{center}
+\end{figure}
+%%--------------------------
+
+\begin{verbatim}
+%% mPICm10.m (Figure 10)
+\beginpicture
+paper{units(mm), xrange(5,55), yrange(5,55)}
+point(C){30,30}[$\odot$,1.2] %% center
+variable(r){20} %% radius
+drawcircle(C,r)
+point(P){C, polar(r,250 deg)}
+point(Q){C, polar(r,120 deg)}
+point(S){C, polar(r,-30 deg)}
+drawpoint(CPQS)
+drawline(PCSQP)
+text($P$){P, polar(5,250 deg)}
+text($Q$){Q, polar(5,120 deg)}
+text($S$){S, polar(5,-30 deg)}
+drawAngleArrow{angle(PCS), radius(8) anticlockwise internal}
+text($\beta$){C, polar(5,285 deg)}
+drawAngleArrow{angle(PQS), radius(12) anticlockwise internal}
+text($\alpha$){Q, polar(8,-65 deg)}
+show angle(PQS) % alpha
+show angle(PCS) % beta
+\endpicture
+\end{verbatim}
+
+
+
+Note that the returned values in the output-file
+from the \texttt{showAngle} commands (see below)
+for Figure~10 indicate that $\beta$ is twice $\alpha$,
+as one would expect.
+
+
+\begin{verbatim}
+%% showAngle(PQS) 40 degrees / radians 0.6981316 % alpha
+%% showAngle(PCS) 79.99999 degrees / radians 1.396263 % beta
+\end{verbatim}
+
+%---------
+
+
+{\MathsPIC} offers a range of other circle commands
+(\texttt{drawIncircle},
+\texttt{drawExcircle},
+\texttt{drawCircumcircle}),
+ specifically for geometry diagrams
+ (cf.\ Cameron, 1992), as shown in Figure~11.
+
+\bigskip
+
+%%---------------------------
+\begin{figure}[hbt]
+\begin{center}
+%% the incircles
+ \strut\input{mPICm11.pic}
+ \caption{\ }
+ \end{center}
+\end{figure}
+%%-----------------------------
+
+
+\begin{verbatim}
+%% mpicm11.m (Figure 11)
+\beginpicture
+\setdashes
+paper{units(mm),xrange(0,70),yrange(0,60),axes(LBT*R*),ticks(10,10)}
+\setsolid
+point(A){10,10} %% anchor point
+point(B){A, polar(50,50 deg)}
+point(C){A,polar(50,0 deg)}
+point(J){pointonline(AB,30)}
+point(K){perpendicular(J,AC)}
+drawRightangle(JKC,3)
+drawLine(AB,AC,JK)
+drawIncircle(AJK)
+drawExcircle(AJK,JK)
+\setplotsymbol({\large .})
+\setdots
+drawCircumcircle(AJK)
+point(I){IncircleCenter(AJK)}[$\odot$]
+point(E){ExcircleCenter(AJK,JK)}[$\odot$,1.2]
+point(P1){perpendicular(E,AC)}
+variable(r){EP1} %% radius of excircle
+variable(d){72} %% angle of pentagon (deg)
+variable(a1){-90}
+variable(a2){a1, advance(d)}
+variable(a3){a2, advance(d)}
+variable(a4){a3, advance(d)}
+variable(a5){a4, advance(d)}
+point(P2){E, polar(r,a2)}
+point(P3){E, polar(r,a3)}
+point(P4){E, polar(r,a4)}
+point(P5){E, polar(r,a5)}
+drawPoint(ABCJKIEP1P2P3P4P5)
+\setplotsymbol({\tiny .})
+\setdashes
+drawline(P1P2P3P4P5P1,EP1,EP2)
+\setsolid
+drawAnglearc{angle(P2EP1),radius(9),internal,clockwise}
+\newcommand{\figtitle}{%
+ \fbox{%
+ \begin{minipage}{30mm}%
+ \ Triangle, pentagon and three circles%
+ \end{minipage}%
+ \ }}%
+text(\figtitle){20,52}
+variable(s){5}
+text($A$){A,polar(s,230 deg)}
+text($B$){B,polar(s,50 deg)}
+text($C$){C,polar(s,0 deg)}
+text($J$){J,polar(s,90 deg)}
+text($K$){K,polar(s,270 deg)}
+text($E$){E,polar(s,a3 deg)}
+text($72$){E,polar(5.5,-54 deg)}
+text($I$){I,shift(3, 0)}
+text($P_1$){P1,polar(s,a1)}
+text($P_2$){P2,polar(s, a2)}
+text($P_3$){P3,polar(s, a3)}
+\endpicture
+\end{verbatim}
+
+
+%----------------------------------------
+\subsection{Functionally connected diagrams}
+
+When constructing diagrams it is often useful to write the
+{\mathsPIC} file in such a way that the position of each new point
+is related to that of earlier points, since then the structure
+of the diagram is maintained even when points are moved.
+This is demonstrated in Figure~12, where the {\mathsPIC} code
+for the two diagrams differs \emph{only} in the angle of the
+line $AB$ (left diagram, 60 degrees; right diagram, 5 degrees)
+as defined in the \verb!point(B){...}! command as follows.
+
+
+\begin{itemize}
+ \item Left-hand diagram: \verb!point(B){A,polar(45,60 deg)}!
+ \item Right-hand diagram: \verb!point(B){A,polar(45,5 deg)}!
+\end{itemize}
+
+
+\bigskip
+
+%%--------figure 12-----------------
+%% dynamic.m
+ \begin{figure}[hbt]
+ \begin{center}
+ %% dynamic figure
+ \strut \input{mPICm12.pic}
+ \caption{The {\mathsPIC} code for the two diagrams differs
+ \emph{only} in the angle of the line $AB$ as defined
+ in the \texttt{point(B)\char`\{...\char`\}} command
+ (see \texttt{mPICm12.m}).}
+ \end{center}
+\end{figure}
+%-----------------------
+
+\begin{verbatim}
+%% mPICm12.m (Figure 12)
+\beginpicture
+paper{units(mm),xrange(5,120),yrange(0,45)}
+point(A){15,5}[$\odots$,1.2]
+point(P){A,shift(10,30)}[$\odots$,1.2]
+point(B){A,polar(45,60 deg)}
+point(Q){perpendicular(P,AB)} % from P to line AB
+drawRightangle(PQA,2)
+drawPoint(ABPQ)
+drawLine(ABPQ)
+drawIncircle(PQB)
+text($A$){A,shift(-5, 0)}
+text($B$){B,shift(5, 0)}
+text($P$){P,shift(-5, 0)}
+point(S){pointOnLine(QP,-5)}
+text($Q$){S}
+%% now draw vertical line and angle
+point(N){A,shift(0,12)}
+\setdashes
+drawLine(AN)
+\setsolid
+drawAngleArrow{angle(NAB),radius(7),clockwise,internal}
+\endpicture
+\end{verbatim}
+
+Note that in Figure~12 the location of the label `Q' is made to
+lie outside the figure by placing the label at
+point~S, which is defined as being 5 mm to the right of line AB
+in-line with the points PQ, using the command
+\verb!point(S){pointOnLine(QP,-5)}!.
+
+%%-------------------------------------------
+\subsection{Inputting files and recursion}
+
+{\mathsPIC} allows the recursive input of blocks of {\mathsPIC}
+commands as files, using the \verb!inputfile! command.
+In practice, this functions as a `DO--LOOP' in a
+program.
+For example, the file \texttt{myfile.dat} would be input six
+times sequentially using the command
+\verb!inputfile(myfile.dat)[6]!.
+
+\bigskip
+
+%%---------figure 13-----------
+\begin{figure}[hbt]
+\begin{center}
+ %% spiral
+ \strut\input{mPICm13.pic}
+ \caption{\ }
+\end{center}
+\end{figure}
+%-----------------------
+
+ Figure~13 was produced by the following
+code which inputs a small file of {\mathsPIC}
+code (\verb!mpicm13.dat!) recursively 30 times using the
+command \verb!inputfile(mpicm13.dat)[30]!.
+Note the use of the \verb!variable*! and \verb!point*! commands
+and the \verb!advance! operator in order to
+re-allocate variables and points recursively.
+
+
+\begin{verbatim}
+%% mpicm13.m (Figure 13)
+%% spiral
+\beginpicture
+paper{units(mm), xrange(0,60), yrange(0,60)}% axes(LB), ticks(10,10)}
+point(C){30,30} % circle center
+drawcircle(C,25)
+variable(a){315} % angle deg
+variable(r){20} % radius of spiral
+variable(s){5} % square, semi-diagonal
+point(T){C,polar(r,330 deg)}
+inputfile(mpicm13.dat)[30]
+\endpicture
+
+ %% mpicm13.dat (Figure 13)
+ %% spiral routine
+ variable*(r){r,advance(-0.5)} % let r = r - 0.5
+ variable*(a){a,advance(15)} % let a = a + 15 deg
+ point*(P){C,polar(r,a deg)}
+ drawpoint(P)
+ drawline(TP)
+ point*(T){P} % let T = P
+ %% make a square centered on P
+ point*(Q1){P,polar(s,0)}
+ point*(Q2){P,polar(s,90)}
+ point*(Q3){P,polar(s,180)}
+ point*(Q4){P,polar(s,270)}
+ drawline(Q1Q2Q3Q4Q1)
+\end{verbatim}
+
+
+\subsubsection{Plotting graphs}
+
+Data-files which do \textit{not} contain {\mathsPIC} commands can be input
+using the \verb!inputfile*! command. This command inputs files
+\textit{verbatim}, and so can be used for inputting files
+containing, for example, only \PiCTeX\ commands and/or
+points for plotting curves (see Section~6).
+For example, the following {\mathsPIC} code (\texttt{mpicm14.m})
+draws the quartic curve shown in Figure~14, by inputting
+in \textit{verbatim} a datafile (\texttt{mpicm14.dat}) containing some
+{\PiCTeX} commands and a set of data points for plotting.
+Note that in this example the $x$-axis is stretched by using
+\verb!units(3cm,cm)! in the \verb!paper{}! command.
+
+
+\bigskip
+
+%%---------figure 14-----------
+\begin{figure}[hbt]
+\begin{center}
+ %% quartic equation
+ \strut\input{mPICm14.pic}
+ \caption{\ }
+\end{center}
+\end{figure}
+%-----------------------
+
+\begin{verbatim}
+%% mpicm14.m (Figure 14)
+\beginpicture
+\linethickness=1pt %% use a thick line for the axes
+paper{units(3cm,cm),xrange(-1,2),yrange(-2,4),axes(XY),ticks(1,1)}
+\linethickness=0.4pt %% reset to default value
+\headingtoplotskip=8mm
+\plotheading{\fbox{\Large A quartic equation}}
+inputfile*(mpicm14.dat) %% input file containing data points for curve
+variable(r){0.3} %% define a line-free radius r = 0.3
+point(E1){1,3.5}[,r]
+text($f(x)=6x^4 - 8x^3 + 1$){E1} % center the equation at E1
+point(E2){1.4,2}[,r]
+drawArrow(E1E2)
+point(J1){0.55,2}[,r]
+text(inflection points){J1} %% center inflection text at J1
+point(J2){0,1}[,r]
+point(J3){0.6,0}[,r]
+drawArrow(J1J2,J1J3)
+\endpicture
+\end{verbatim}
+
+
+The datafile for the curve is as follows.
+Note that {\PiCTeX} requires an \textit{odd} number of pairs of
+data points to satisfy its curve-drawing algorithm.\footnote{See
+the \PiCTeX\ manual (Wichura, 1992).}
+
+
+\begin{verbatim}
+%% mpicm14.dat (Figure 14)
+%% quartic curve data (use an odd number of data points)
+\setquadratic
+\plot
+-0.6 3.50
+-0.5 2.37
+-0.4 1.66
+-0.35 1.43
+...
+...
+ 1.15 -0.67
+ 1.25 0.02
+ 1.35 1.24
+ 1.45 3.13 /
+\setlinear
+ \end{verbatim}
+
+
+However, when there are only a few data points, it is somtimes
+more convenient just to plot the points separately and then
+draw connecting lines, as shown in Figure~15.
+
+
+\bigskip
+
+%%---------figure 15-----------
+\begin{figure}[hbt]
+\begin{center}
+ %% diet graph
+ \strut\input{mPICm15.pic}
+ \caption{\ }
+\end{center}
+\end{figure}
+%-----------------------
+
+\begin{verbatim}
+%% mpicm15.m (Figure 15)
+\beginpicture
+paper{units(cm),xrange(0,6),yrange(73,77),axes(LBT*R*),ticks(1,1)}
+variable(r){0.2} %% line-free radius
+pointsymbol($\odot$,r)
+point(d1){1, 76.2}
+point(d2){2, 76.2}
+point(d3){3, 75.5}
+point(d4){4, 75.7}
+point(d5){5, 74.6}
+drawpoint(d1d2d3d4d5)
+drawline(d1d2d3d4d5)
+%
+pointsymbol($\boxdot$,r)
+point(k1){1, 75.2}
+point(k2){2, 75.4}
+point(k3){3, 74.8}
+point(k4){4, 74.1}
+point(k5){5, 74.0}
+drawpoint(k1k2k3k4k5)
+\setdashpattern <2pt, 2pt>
+drawline(k1k2k3k4k5)
+%
+\plotheading{\textsf{\Large Weight change with diet}}
+text(\shortstack{\textsf{\large Weight}\\($kg$)}){-1.5,75.3}
+text(\textsf{\large Days}){3,72}
+\endpicture
+\end{verbatim}
+
+
+The \verb!drawcurve! command can also be used for drawing smooth
+curves linking a number of points or touching lines.
+For example, Figure~16 shows a smooth curve touching
+a piecewise linear closed
+line\footnote{Figure~16 was constructed and drawn by Frantisek Chvala.},
+ some of the points being constructed using a Bezier
+technique\footnote{see \textit{The Metafont book} by DE Knuth,
+chapter~3 for details regarding Bezier curves.}.
+The smooth curve is drawn using the \verb!drawcurve! command for
+successive three-point sequences.
+
+
+
+%%---------figure 16-----------
+\begin{figure}[hbt]
+\begin{center}
+ %% smooth curve from Frantisek
+ \strut\input{mPICm16.pic}
+ \caption{A smooth curve inscribed in the intersecting
+ closed line $ABCDEFGA$}
+\end{center}
+\end{figure}
+%-----------------------
+
+
+
+\begin{verbatim}
+%% mpicm16.m (Figure 16)
+\beginpicture
+variable(u){12} %% units = 12 mm
+paper{units(u mm),xRange(0,9),yRange(-1,6)}
+variable(r){0.7} %% line-free radius of \circ = 0.7mm
+variable*(r){r, divide(u)} %% scale line-free radius for u mm
+pointsymbol($\circ$,r)
+Point(A){1,1}
+Point(B){2,4}
+Point(C){5,3}
+Point(D){6,0}
+Point(E){8,2}
+Point(F){8,5}
+Point(G){3,0}
+pointsymbol(default) %% restore $\bullet$ symbol for points
+%
+Point(A1){midpoint(AB)}
+Point(B1){midpoint(BC)}
+Point(C1){midpoint(CD)}
+Point(D1){midpoint(DE)}
+Point(E1){midpoint(EF)}
+Point(F1){midpoint(FG)}
+Point(G1){midpoint(GA)}
+%
+Point(A2){midpoint(G1A1)}
+Point*(A2){midpoint(AA2)}
+Point(B2){midpoint(A1B1)}
+Point*(B2){midpoint(BB2)}
+Point(C2){midpoint(B1C1)}
+Point*(C2){midpoint(CC2)}
+Point(D2){midpoint(C1D1)}
+Point*(D2){midpoint(DD2)}
+Point(E2){midpoint(D1E1)}
+Point*(E2){midpoint(EE2)}
+Point(F2){midpoint(E1F1)}
+Point*(F2){midpoint(FF2)}
+Point(G2){midpoint(F1G1)}
+Point*(G2){midpoint(GG2)}
+%
+DrawPoints(ABCDEFG)
+DrawPoints(A1B1C1D1E1F1G1)
+DrawPoints(A2B2C2D2E2F2G2)
+%
+DrawLine(ABCDEFGA)
+\setplotsymbol ({\Large.})
+DrawCurve(A1B2B1)
+DrawCurve(B1C2C1)
+DrawCurve(C1D2D1)
+DrawCurve(D1E2E1)
+DrawCurve(E1F2F1)
+DrawCurve(F1G2G1)
+DrawCurve(G1A2A1)
+%
+Text($A$){A,shift(-.2,0)}
+Text($B$){B,shift(-.2,.1)}
+Text($C$){C,shift(0,.25)}
+Text($D$){D,shift(0,-.25)}
+Text($E$){E,shift(.2,0)}
+Text($F$){F,shift(0,.25)}
+Text($G$){G,shift(0,-.25)}
+\scriptsize
+Text($A_1$){A1,shift(.25,0)}
+Text($B_1$){B1,shift(0,-.2)}
+Text($C_1$){C1,shift(.25,0)}
+Text($D_1$){D1,shift(-.2,.15)}
+Text($E_1$){E1,shift(-.2,0)}
+Text($F_1$){F1,shift(.15,-.15)}
+Text($G_1$){G1,shift(.1,.2)}
+Text($A_2$){A2,shift(.25,0)}
+Text($B_2$){B2,shift(.1,-.2)}
+Text($C_2$){C2,shift(-.1,-.15)}
+Text($D_2$){D2,shift(.1,.2)}
+Text($E_2$){E2,shift(-.25,.05)}
+Text($F_2$){F2,shift(.05,-.2)}
+Text($G_2$){G2,shift(0,.25)}
+\endpicture
+\end{verbatim}
+
+
+
+Note the technique used in the code for Figure~16, for making
+the \textit{physical} line-free radius (r) invariant with respect to
+the scaling value (u) (i.e.\ does not change when the figure is
+enlarged or reduced by varying the value of the variable u),
+as follows (see also Section~4.3.2).
+
+\begin{verbatim}
+variable(u){12} %% units = 12 mm
+paper{units(u mm),xRange(0,9),yRange(-1,6)}
+variable(r){0.7} %% line-free radius of \circ = 0.7mm
+variable*(r){r, divide(u)} %% scaled linefree radius for u mm
+pointsymbol($\circ$, r)
+point(A){1,1}
+\end{verbatim}
+
+This technique can be very useful if it will be necessary to
+scale the figure markedly after having designed the figure, in
+order, say, to make it fit into a particular space in a document.
+
+
+
+%%-------------------------------------------
+\section{Positioning figures in a document}
+
+Once a diagram or figure has been finished it can be easily
+placed in a document either by including the {\PiCTeX} code
+directly in
+the main document within the \verb!\begin{figure}...\end{figure}!
+environment, or by \verb!\input!ting the code as a separate
+file.
+For example, if the {\mathsPIC} file was called \verb!myPIC.m!
+and this generated the output-file \verb!myPIC.mt!, then one would
+comment-out the \LaTeX\ headers and footers from the \verb!.mt!
+file, keeping just the part of the file within the
+\verb!\beginpicture!\ldots\verb!\endpicture! environment (renaming
+it, say, \verb!myPIC.pic!) as follows.
+
+
+\begin{verbatim}
+%% this is file myPIC.pic
+\beginpicture
+...
+...
+\endpicture
+\end{verbatim}
+
+The \verb!myPIC.pic! file can then be \verb!\input! into
+a document as a centered Figure as follows.
+
+
+\begin{verbatim}
+\begin{figure}[hbt]
+\begin{center}
+ \strut\input{myPIC.pic}
+ \caption{...}
+ \label{...}
+\end{center}
+\end{figure}
+\end{verbatim}
+
+It is often useful when adjusting
+its position on the page,
+to initially place the Figure inside a frame
+in order to see the exact extent of the Figure, in which case replace the
+\verb!\input! line above with the following:
+
+
+\begin{verbatim}
+\strut\framebox{\input{myPIC.pic}}
+\end{verbatim}
+
+
+Sometimes more flexibility is needed regarding positioning
+the \verb!\caption!, in which case a \verb!\parbox! is useful,
+as follows:
+
+\begin{verbatim}
+\begin{figure}[hbt]
+\begin{center}
+ \strut\input{myPIC.pic}
+ \parbox{10cm}{
+ \vspace{5mm}
+ \caption{...}
+ \label{...}
+ }
+\end{center}
+\end{figure}
+\end{verbatim}
+
+
+When typesetting text and a figure side-by-side the following
+format for using two adjacent minipages works well---this was the
+construction used for displaying the program code
+and the associated Figure~7.
+
+\begin{verbatim}
+\begin{figure}[hbt]
+\noindent
+\begin{minipage}{4cm}
+%% put some text or a figure here
+...
+...
+\end{minipage}
+%%-----------
+\hspace{3cm} %% controls the horizontal space between Figures
+%%-----------
+\begin{minipage}{4cm}
+ \vspace{3mm}
+ \strut\hspace*{...}\input{circle.pic}
+ \vspace{...} % adjusts vertical position of caption
+ \caption{...}
+ \label{...}
+\end{minipage}
+%-----
+\hfill
+\end{figure}
+\end{verbatim}
+
+
+Finally, it is often necessary to have two figures side-by-side,
+each with separate sub-captions, in which case the following
+rather similar format is useful---this was the
+construction used for displaying the two figures of Figure~8.
+Note the commented-out \verb!\framebox{}! commands; these are
+very useful for revealing the full extent of any white-space
+surrounding the separate figures, since such unwanted white-space is
+probably the most common cause of difficulty when trying to
+position and center figures in a document.
+
+
+\begin{verbatim}
+\begin{figure}[hbt]
+\begin{center}
+ %-------
+ \noindent %\framebox{
+ \begin{minipage}{3cm}
+ \begin{center}
+ %\vspace{...} %% controls space above picture
+ \input{mPICm08a.pic}
+ %\vspace{...} %% controls space between pict and caption
+ a. Circular arrows
+ \end{center}
+ \end{minipage}
+ %} %end of framebox
+ %-----------------------
+ \hspace{12mm} %% controls horiz space between figs
+ % \bigskip\bigskip %% use this to place figs vertically
+ %----------------------
+ %\framebox{
+ \begin{minipage}{5cm}
+ \begin{center}
+ %\vspace{...} %% controls space between pict and caption
+ \input{mPICm08b.pic}
+ %\vspace{...} %% controls space between pict and caption
+ b. Straight arrows
+ \end{center}
+ \end{minipage}
+ %} %end of framebox
+ %---------
+ \caption{.....\hspace{7mm}} % add \hspace{} to adjust horiz possn
+\end{center}
+\end{figure}
+\end{verbatim}
+
+
+%%-----------------------------------------
+\section{Downloading and installing \PiCTeX}
+
+{\PiCTeX} is an excellent small graphics package, freely available
+from CTAN and the usual \TeX\ CD-ROM
+discs\footnote{Available from \TeX\ user groups.
+Note that a particularly good 3-disk CTAN archive is published
+annually by the German \TeX\ users group DANTE
+(\textit{dante@dante.de}, \texttt{http://www.dante.de}).}.
+ Download all the files in the following two
+directories, and place them where your \TeX\ system can
+find them\footnote{For EmTeX, this would be the directory
+\texttt{c:{\bs}emtex{\bs}texinput{\bs}pictex{\bs}}}.
+\begin{itemize}
+ \item \verb!CTAN/tex-archive/graphics/pictex/!
+ \item \verb!CTAN/tex-archive/graphics/pictex/addon/!
+\end{itemize}
+If you are a \LaTeX\ user, then use \verb!\usepackage{pictexwd}!.
+If you are a plain \TeX\ user, then use \verb!\input pictexwd.tex!
+(see Section~4.2.1 and Section~9.2 for details).
+
+
+ Unfortunately, the {\PiCTeX} documentation is not available
+from CTAN---the {\PiCTeX}
+manual has to be purchased separately (see Section~9.5).
+However, {\mathsPIC} users will mostly find this
+unnecessary, since those \PiCTeX\ commands
+which are particularly useful in conjunction with {\mathsPIC}
+are described in the {\mathsPIC} manual (Section~6.3), together
+with examples in the code for the various Figures.
+
+
+
+%%%--------------------
+\subsection{The original files (1986)}
+
+\noindent\texttt{CTAN/tex-archive/graphics/pictex/}
+
+\medskip
+
+The original {\PiCTeX} package by Michael Wichura (21/09/1987)
+originally consisted of the 4 files listed below.
+On the left is the MS-DOS name (truncated to 8 characters), and
+on the right is the full UNIX name).
+
+The file \texttt{latexpic.tex} gives Plain \TeX\ users the
+option of using the \LaTeX\ Picture macros \verb!\line!, \verb!\vector!,
+\verb!\circle!, \verb!\oval!, \verb!\thicklines! and
+\verb!\thinlines! (for syntax and use with \PiCTeX\ see
+Wichura, 1992).
+
+Note that only two of the files are required for
+using with plain {\TeX}, while three files are
+ required when running \LaTeX.
+
+\begin{verbatim}
+latexpic.tex 11243 bytes (latexpicobjs.tex --for plain TeX only)
+prepicte.tex 1293 bytes (prepictex.tex --for LaTeX)
+pictex.tex 133388 bytes (pictex.tex --for LaTeX and plain TeX)
+postpict.tex 1614 bytes (postpictex.tex --for LaTeX)
+\end{verbatim}
+
+
+The three files required for use with \LaTeX\
+need to be loaded (input) \textit{in the order
+shown above}.
+ Note that when using {\PiCTeX} with \LaTeXe\
+it is necessary to redefine the \LaTeX\ 2.09 command \verb!\fiverm!
+(because {\PiCTeX} was originally written for \LaTeX\ 2.09).
+This is most easily done as follows.
+
+\begin{verbatim}
+\newcommand{\fiverm}{\rmfamily\tiny}
+\end{verbatim}
+
+Alternatively you can use the more robust method (i.e.\ for
+\textit{wizards}) suggested
+by Michael J Downes as follows (I believe
+Michael Downes suggested this originally on the
+\textsl{comp.text.tex} usenet group---see also
+the file \texttt{fntguide.tex} among the \LaTeXe\ documents).
+
+\begin{verbatim}
+\declarefixedfont{\fiverm}{\encodingdefault}{\rmdefault}{m}{n}{5}
+\end{verbatim}
+
+A significant problem with the original \PiCTeX\ package was
+that it was very memory hungry. However, in 1994
+this problem was overcome by a significant rewrite by Andreas
+Schrell (see Section~9.2).
+
+%%--------------------
+\subsection{The new updated files (1994)}
+
+\begin{verbatim}
+CTAN/tex-archive/graphics/pictex/addon/
+\end{verbatim}
+
+In 1994 Andreas Schrell uploaded a set of updated \PiCTeX\ files into the
+\verb!CTAN: .../pictex/addon/! directory. One of these additional files
+(\verb!pictexwd.tex!) is a replacement for the original
+(\verb!pictex.tex!), and is extremely
+economic in its use of {\TeX}'s dimension registers,
+ allowing significantly better memory usage
+ with exactly the same functionality.
+The other files correct some errors (\verb!piccorr.sty!),
+and add new functionality (\verb!picmore.tex!).
+
+\begin{verbatim}
+pictexwd.sty 416 bytes
+pictexwd.tex 133232 bytes
+picmore.tex 2952 bytes
+piccorr.sty 4608 bytes
+pictex.sty 311 bytes
+\end{verbatim}
+
+
+%--------
+\begin{itemize}
+
+ \item \verb!pictexwd.sty!
+
+For \LaTeX\ users. This replaces \verb!pictex.sty!. It inputs
+\verb!prepictex.tex!, \verb!pictexwd.tex!, and
+\verb!postpictex.tex!, as well as inputting \verb!piccorr.sty!
+and \verb!picmore.tex! if these are available.
+
+ \item \verb!pictexwd.tex!
+
+For \TeX\ users.
+
+ \item \verb!picmore.tex!
+
+An extension for drawing impulse diagrams.
+
+ \item \verb!piccorr.sty!
+
+A correction for the
+original \PiCTeX\ \verb!\betweenarrows! command.
+
+\item \verb!pictex.sty!
+
+The \LaTeX\ style-option for loading the \textit{original}
+\PiCTeX\ files. Note that it also inputs \verb!piccorr.sty!
+and \verb!picmore.tex! if these are available.
+
+
+ \end{itemize}
+%------
+
+
+ All the necessary files required for
+running \PiCTeX\ are automatically input in
+the correct order by \verb!pictexwd.sty! (\LaTeX\ users), or by
+\verb!pictexwd.tex! (\TeX\ users).
+Users of {\LaTeXe} should include the following command in the
+preamble.
+
+\begin{verbatim}
+\usepackage{pictexwd}
+\end{verbatim}
+
+Users of plain {\TeX} need to include the following.
+
+\begin{verbatim}
+\input latexpic.tex
+\input pictexwd.tex
+\end{verbatim}
+
+Note that it is still necessary to download all the original
+\PiCTeX\ files even when using Andreas Schrell's new files, as
+some of the original files are still required.
+
+
+%%----------------------
+\subsection{Pictex2.sty}
+
+
+\begin{verbatim}
+CTAN/tex-archive/macros/latex/contrib/supported/pictex2.sty
+16418 bytes 09/05/1999
+\end{verbatim}
+
+
+William Park\footnote{\texttt{parkw@better.net}}
+has written a style option (\texttt{pictex2.sty})
+which adds two useful commands to standard {\PiCTeX},
+which force the use of the \verb!\putrule! command where lines are
+either horizontal or vertical, thus saving on memory (note that
+{\mathsPIC} automatically implements the use of \verb!\putrule!
+in these circumstances---see Section~4.6).
+These two commands are as follows.
+
+\begin{itemize}
+\item \texttt{$\backslash$putanyline} command
+
+This command invokes the {\PiCTeX} \verb!\putrule! command
+(instead of \verb!\plot!) in cases where lines are either
+vertical or horizontal.
+
+
+\item \texttt{$\backslash$setanyline} command
+
+This is a line-drawing mode (similar to \verb!\setlinear!) which
+forces subsequent \verb!\plot! commands to invoke \verb!\putrule!
+whenever the line is either horizontal or vertical.
+
+\end{itemize}
+
+
+%%----------------------
+\subsection{Errorbar.tex}
+
+
+\begin{verbatim}
+CTAN/tex-archive/graphics/pictex/errorbar.tex
+3041 bytes 20/04/1988
+\end{verbatim}
+
+In 1988 Dirk Grunwald implemented the following errorbar command
+for \PiCTeX\ which draws error bars using
+a modified \verb!\plot! command as follows.
+
+
+\begin{itemize}
+\item \texttt{$\backslash$plotWithErrorBars} command
+
+This command, which is case sensitive, has the format
+
+\begin{verbatim}
+\plotWithErrorBars mark M at
+ x1 y1 e1
+ ...
+ xn yn en /
+\end{verbatim}
+
+where \verb!M! is a \TeX\ character (e.g.\ \verb!$\bullet$!),
+and \verb!e! is the size of vertical error bars which are
+plotted above and below the point. The default cross-bar length
+is 5pt, but can be changed, say to 7pt, using the command
+\verb!\crossbarlength=7pt!.
+
+To use this command, input the file \verb!errorbar.tex! after
+all the \PiCTeX\ files.
+
+\end{itemize}
+
+
+
+%%------------------------------------------
+\subsection{The \PiCTeX\ Manual}
+
+You may wish to purchase \textsl{The {\PiCTeX} Manual}
+by Michael J.\ Wichura (The University of Chicago, Chicago,
+Illinois, USA; \textit{wichur@galton.uchicago.edu}).
+This excellent booklet (version 1.1, third printing, March 1992; 85 pages)
+used to be available from TUG as Publication No.\ 6 in
+the TUG {\TeX}niques series.
+Unfortunately, TUG (\texttt{http://www.tug.org/})
+has now stopped publishing the manual, and
+\textsl{The {\PiCTeX} Manual}
+is currently only available from \textsl{Personal \TeX\
+Inc.} (\textit{texsales@pctex.com}\ \texttt{http://www.pctex.com/})
+at approximately {\$}59 plus postage.
+
+When you buy a copy of the manual you also receive a floppy disk
+containing {\PiCTeX} files. Unfortunately these are only
+the original 1986 files, and do not as yet include any of Andreas Schrell's
+1994 files.
+
+%%-------------------
+
+\section{Bug reports}
+The author would be grateful for any bug reports,
+constructive comments, and any ideas for improving this program.
+The author is grateful to Apostolos Syropoulos, Bob Schumacher,
+Frantisek Chvala, Orlando Rodriguez, Boris Kuselj, and others
+for testing this program, and for their many ideas and
+suggestions.
+
+\section{Perl version of {\mathsPIC}}
+A Perl version of {\mathsPIC} is currently in progress
+(Syropoulos and Nickalls, 2000). It will have a number
+of enhanced features, particularly with regard to handling of
+variables. The authors expect it to be first released in the Autumn of
+2001.
+
+%%----------------
+\section{History}
+
+\begin{itemize}
+
+\item 2.1 (November, 2000):
+
+Revised the documentation; fixed numerous bugs; introduced the
+\texttt{$\backslash$} and \texttt{$\backslash$\gap...} commands
+to facilitate the use of \TeX\ and \LaTeX\ commands and for
+copying lines verbatim. The following
+commands have also been added/extended.
+
+\begin{verbatim}
+drawCurve(ABC)
+drawline(AB)[d] %% added the [] option
+drawline*(AB) %% disables use of \putrule
+point(S){Q, rotate(P, 23 deg)} %% added the rotate() option
+pointsymbol(char,lineFreeRadius) %% added the line-free radius option
+\end{verbatim}
+
+
+\item 1.9b (May 2000):
+
+Fixed a bug associated with the
+\verb!drawAngleArc! and \verb!drawAngleArrow! commands.
+
+
+\item 1.9a (January 2000):
+
+Added the options X and Y to the \texttt{axes} option in the
+\texttt{paper} command, which allows X and Y axes to be drawn.
+Also added
+the option of following any of the \texttt{axes} options by a * which
+prevents ticks being drawn on that particular axis.
+
+\item 1.8f (October 1999):
+
+Fixed problem with scientific
+notation; added current loop number indicator; added the
+following new commands:
+
+\begin{verbatim}
+variable(){area()}
+variable(){angle()}
+variable(){Xpoint()}
+variable(){Ypoint()}
+inputfile*()
+PointSymbol(default)
+\end{verbatim}
+
+
+\item 1.7u (September 1999): First release.
+
+\end{itemize}
+
+%%-------------------
+\section{References}
+
+\begin{itemize}
+
+\item Cameron P.\ J.\ (1992). Geometric diagrams in \LaTeX.
+\textit{TUGboat} \textbf{13} (No.~2), 215--216.
+
+\item Feruglio G.\ V.\ (1994). Typesetting commutative diagrams.
+\textit{TUGboat} \textbf{15} (No.~4), 466--484.
+
+\item Nickalls RWD (1999a).
+{\MathsPIC}: a filter program for use with {\PiCTeX}.
+{\newline}\textit{Euro{\TeX}'99 Proceedings}; 197--210.
+(Heidelberg, Germany; August 1999).
+
+\item Nickalls RWD (1999b).
+{\MathsPIC}: a filter program for use with {\PiCTeX}.
+{\newline}\textit{Eutupon}\footnote{The editor is Apostolos
+Syropoulos (email: \textit{apostolo@obelix.ee.duth.gr}).}
+[the Greek \TeX\ Friends' journal];
+No.~3 (October, 1999), 33--49 (English).
+{\newline} [This is an updated version of Nickalls (1999a)].
+
+
+\item Salomon D.\ (1992). Arrows for technical drawing.
+\textit{TUGboat} \textbf{13} (No.~2), 146--149.
+
+\item Syropoulos A.\ and Nickalls R.\ W.\ D.\ (2000).
+A PERL porting of the {\mathsPIC} graphics package.
+{\newline}\textit{TUG2000 Conference} (Oxford, UK); August
+13--16, 2000.
+
+\item Wichura M.\ J.\ (1992). The {\PiCTeX} manual.
+Pub: Personal \TeX\ Inc., 12~Madrona Avenue, Mill Valley, CA
+94941, USA. \textit{texsales@pctex.com}\ \
+\texttt{http://www.pctex.com}.
+
+\end{itemize}
+
+
+\begin{center}
+------------
+\end{center}
+
+\end{document}
diff --git a/graphics/mathspic/dos/readme21.txt b/graphics/mathspic/dos/readme21.txt
new file mode 100644
index 0000000000..edaa127ffb
--- /dev/null
+++ b/graphics/mathspic/dos/readme21.txt
@@ -0,0 +1,121 @@
+README21.TXT
+
+-------------------------------------
+ mathsPIC 2.1
+ A filter program for use with PiCTeX
+-------------------------------------
+
+Copyright (c) RWD Nickalls
+November 5, 2000.
+
+RWD Nickalls
+Department of Anaesthesia,
+City Hospital,
+Nottingham, UK.
+dicknickalls@compuserve.com
+TeL: +44-(0)115-9856663
+FAX: +44-(0)115-9627713
+
+----------------------------------------------
+SUMMARY
+
+mathsPIC is a DOS filter program for use with the small
+graphics engine PiCTeX (CTAN: tex-archive/graphics/pictex/ ).
+mathsPIC converts an input text-file (the mathsPIC file)
+containing mathsPIC/PiCTeX/TeX/LaTeX drawing commands,
+into an output TeX-file containing PiCTeX and TeX/LaTeX commands,
+which can then be run through TeX/LaTeX to produce
+the graphic in the normal way.
+Put simply, mathsPIC takes the pain out of PiCTeX!
+mathsPIC is designed for maths figures/diagrams/graphs/trees.
+The manual (55 pages, A4 size) is in .tex/.dvi/.ps/.pdf formats,
+and includes 16 example Figures with documented code.
+
+MathsPIC 2.1 will run under Windows 9x, NT4 and 2000
+---------------------------------------------
+
+Read the manual (mpicm21.tex/dvi/ps/pdf)
+to find info on command-line syntax.
+Please read Section 9 in the manual regarding
+the location of PiCTeX files on CTAN.
+---------------------------------------------
+
+The mathsPIC package consists of the following files.
+
+
+(A) The mathsPIC program
+------------------------
+ mpic21.exe (the mathsPIC program (MS-DOS)
+
+Rename this file to mathsPIC.exe
+Keep this file either in the PATH, or in the same directory
+as the input file.
+
+
+(B) Optional utilities -- see manual (mpicm21.*)
+------------------------------------------------
+ show.com (a MS-DOS screen text viewer enabled by /s switch)
+ clean.exe (a MS-DOS utility for removing commented lines)
+
+Keep these two files either in the PATH, or in the same
+directory as the mathsPIC program (mpic21.exe)
+
+
+(C) mathsPIC manual/documentation
+----------------------------------
+readme21.txt this file
+mpicm21.tex the manual (LaTeX2e)--inputs all the .pic files below
+mpicm21.dvi the manual (DVI)
+mpicm21.ps the manual (PostScript; 600 dpi/A4 size)
+mpicm21.pdf the manual (PDF; A4 size)
+
+
+The following .pic files (figures) are input by mpicm21.tex
+(the manual).
+
+mpicm01.pic
+mpicm02a.pic
+mpicm02b.pic
+mpicm03.pic
+mpicm04.pic
+mpicm05.pic
+mpicm06.pic
+mpicm07.pic
+mpicm08.pic
+mpicm09.pic
+mpicm10.pic
+mpicm11.pic
+mpicm12.pic
+mpicm13.pic
+mpicm14.pic
+mpicm15.pic
+mpicm16.pic
+
+
+(D) mathsPIC input files (.m and .dat) for figures in the manual.
+----------------------------------------------------------------
+These are included for experimentation purposes. Runnimg
+mathsPIC on the .m files will generate output (.mt) files
+which will show the figure/diagram when LaTeXed.
+
+mpicm01.m
+mpicm02a.m
+mpicm02b.m
+mpicm03.m
+mpicm04.m
+mpicm05.m
+mpicm06.m
+mpicm07.m
+mpicm08.m
+mpicm09.m
+mpicm10.m
+mpicm11.m
+mpicm12.m
+mpicm12.dat (required by mpicm12.m)
+mpicm13.m
+mpicm13.dat (required by mpicm13.m)
+mpicm14.m
+mpicm14.dat (required by mpicm14.m)
+mpicm15.m
+mpicm16.m
+------------------end------------------------
diff --git a/graphics/mathspic/dos/show.com b/graphics/mathspic/dos/show.com
new file mode 100644
index 0000000000..759b8d87fd
--- /dev/null
+++ b/graphics/mathspic/dos/show.com
Binary files differ
diff --git a/graphics/mathspic/perl/HELP.txt b/graphics/mathspic/perl/HELP.txt
new file mode 100644
index 0000000000..2ecc754700
--- /dev/null
+++ b/graphics/mathspic/perl/HELP.txt
@@ -0,0 +1,598 @@
+
+
+HELP.txt
+
+A .txt version of the Linux manpage (for use with MS-Windows)
+
+copyright (c) 2010 A Syropoulos and RWD Nickalls
+mathsPIC 1.13 April 26, 2010 mathsPIC perl version
+
+NAME: mathsPIC
+
+AUTHORS: A. Syropoulos and R.W.D. Nickalls (April 26, 2010)
+
+ asyropoulos[at]<yahoo><com>
+ dick[at]<nickalls><org>
+
+DESCRIPTION
+-----------
+mathsPIC is a Perl filter program for PiCTeX. mathsPIC has its own macro and macro library capability, and allows use of mathsPIC, PiCTeX, TeX and LaTeX commands. A significant feature of mathsPIC is that it allows access to the command-line, and so allows the user to extend mathsPIC commands by calling Perl and other programs written to perform particular drawing actions. See the package manual for full details and examples. The latest version can be downloaded from
+
+ CTAN: tex-archive/graphics/pictex/mathspic/perl
+
+Commands which can be used in the mathsPIC script file fall into four main groups (a)-mathsPIC macro commands (prefixed with %def), (b)-regular mathsPIC commands (do not have a backslash), (c)-regular PiCTeX commands (all have a backslash), and (d)-regular TeX and LaTeX commands (all have a backslash).
+
+
+The following mathematics functions can used (note that decimal fractions having an absolute value less than 1 must have a leading zero). Note also that all the trignometric functions require their argument in radians.
+
+Trigonometric: sin(), cos(), tan(), asin(), acos(), atan()
+Remainder: rem(); eg var r=12 rem(5)
+Integer: int(); eg var r= int(3.87) --> 3
+Sign (returns -1, 0, +1): sgn(); eg var s=sgn(-3.27) --> -1
+Square root: sqrt(); eg var s = sqrt(14)
+Exponentiation: **; eg var j = r**2
+Pi constant (3.14159...): _Pi_ and _pi_
+e constant (2.71828...): _E_ and _e_
+Linethickness: _linethickness_ ; eg var t = _linethickness_
+
+COMMAND-LINE USE
+-----------------
+
+perl mathspic.pl [-b] [-c] [-h] [-o <outfile>] <infile>
+ -b enables beep if mathsPIC detects an error
+ -c disables the writing of comments to output file
+ -h displays the help file
+ -o defines the output file name
+
+
+MACRO COMMANDS
+--------------
+macro definition commands are prefixed with %def and can take either 0, 1, or more parameters. Macros will generally be used as part of a var command as shown below. Macros are deleted using the %undef command.
+
+ -----syntax:
+ %def MACRONAME(parameters)<macrodefinition>
+ %undef MACRONAME(parameters)
+
+ -----notes:
+ Notes: (a) the () must be used in the definition even if no parameters are used, (b) the name can be any combination of upper and lower case characters and numbers, (c) when the macro is used in a command it is prefixed by a & symbol, (d) it is a good idea to always place a % symbol at the end of the definition, (e) comments (prefixed by a % symbol) can be placed after the macro definition just as in TeX or LaTeX.
+
+ -----examples:
+ %def d2r()_pi_/180% % degrees2radians
+ %def AreaOfRectangle(x,y)x*y% % width x, length y
+ %undef d2r() % delete the macro
+
+ -----use:
+ var j2= 6*(&d2r(45) + 23)
+ var a3 = 3*&AreaOfRectangle(5,7)
+
+GENERAL COMMANDS
+----------------
+
+ NUMERICAL EXPRESSIONS
+ When dealing with commands we will refer frequently to the term `numerical expression' by which is meant either (a) a number (integer or decimal), (b) a numeric variable or constant (defined using the var or const command), (c) any mathsPIC function, macro, or mathematical expression which evaluates to a number, or (d) a pair of point names (e.g. AB) representing the Pythagorean distance between the two points. A leading zero must be used with decimal fractions less than one.
+
+ In general, if a command's argument accepts a number then it will also accept a `numerical expression' (<expr>) as defined above. Sometimes a following <unit> is associated with the number or numerical expression, in which case the number or numerical expression can be delimited by a round bracket (or separated from the unit by a <space>), as shown in the following examples.
+
+ -----examples:
+ ArrowShape(3mm, 20,40)
+ var h=4
+ ArrowShape(h mm, 20, 40)
+ ArrowShape((2*h)mm,20,40)
+
+=============================
+
+ BACKSLASH \
+
+ A leading backslash without a following space indicates that it is part of a PiCTeX, TeX or LaTeX command, in which case mathsPIC simply copies the whole line verbatim into the output file. A leading backslash followed by one or more spaces makes mathsPIC copy the whole line verbatim into the output file but without the backslash.
+
+=============================
+
+ USING THE COLOR PACKAGE
+
+ The standard COLOR package can be used with mathsPIC, but note that it is important to load the COLOR package after the mathsPIC package.
+
+ It is best to place a comment symbol % at the end of LaTeX and TeX commands to limit white space at the end.
+
+ In the event of any colour-spill from a diagram into any following text (this used to be a problem in early TeX implementations) consider using the \normalcolor command as a delimiter within the \beginpicture...\endpicture environment.
+
+==============================
+
+ ARROWSHAPE
+
+ This command defines the shape of an arrowhead, and allows
+different arrowheads to be customised.
+
+The default arrow shape is equivalent to the Arrowshape(2mm,30,40) command.
+This default arrowhead shape can be reset using the Arrowshape(default) command, as shown in the following example.
+
+ -----syntax:
+ arrowshape(<length>[units], <angledeg>, <angledeg>)
+
+ -----examples:
+ Arrowshape(4mm,30,60)
+ drawArrow(AB)
+ Arrowshape(default)
+
+==============================
+
+ beginLOOP...endLOOP
+
+ This is an environment which cycles a block of code a specified number of times.
+
+ -----syntax:
+ beginLoop <expr>
+ ...
+ endLoop
+
+ -----notes:
+ The block of code which lies within the environment is input <expr> times.
+
+ -----example:
+ beginLoop 5
+ ...
+ endLoop
+
+
+==============================
+
+ beginSKIP...endSKIP
+
+ This is an `environment' within which commands are not actioned. It is useful in development for testing isolated commands and excluding other commands.
+
+==============================
+
+ CONST
+
+ The const command is used to define scalar constants. Note that a constant-name must begin with a single letter (either upper or lower case), and may have up to a maximum of three following digits. Note that constants, variables and points have the same name structure, and a constant could have the same name as a point (and so we suggest points have uppercase letters and variables and constants have lowercase letters). The scalar argument can be any numeric expression. New values cannot be re-allocated to existing constant-names. If this occurs mathsPIC will issue an error message.
+
+ -----syntax:
+ const name = <expr>
+
+ -----examples:
+ const r = 20, r4 = r3*tan(0.3)
+
+==============================
+
+ DashArray
+
+ The dasharray command takes an arbitrary number of paired arguments that are used to specify a dash pattern.
+
+ -----syntax
+ dasharray(d1 , g1 , d2 , g2 , ... )
+
+ -----notes
+ The ds denotes the length of a dash and the gs denotes the length of the gap between two consecutive dashes. There must be an even number of arguments. If a variable or expression is used then it should be separated from the unit either by a <space> or with round brackets ( ) as shown below.
+
+ -----example
+ dasharray(6pt, 2pt, 1pt, 2pt)
+ var d=2
+ dasharray(6pt, 2pt, 1pt, d pt)
+ dasharray(6pt, 2pt, 1pt, (d)pt)
+ dasharray(6pt, 2pt, 1pt, (3*d)pt)
+
+==============================
+
+ DrawAngleArc
+
+ This command draws an arc in the specified angle, a distance <radius> from the angle. The angle is either <internal> (less than 180 deg) or <external> (greater than 180 deg). The direction of the arc is either <clockwise> or <anticlockwise>, and this direction must correspond with the letter sequence specified for the angle.
+Strange and unexpected results will be produced if the four parameters are not internally consistent. The option order angle/radius/internal or external/clockwise or anticlockwise is important. The <radius> parameter can be any numerical expression.
+
+ -----syntax:
+ DrawAngleArc{angle(), radius(), external, clockwise}
+
+ -----example:
+ DrawAngleArc{angle(ABC), radius(3), external, clockwise}
+ var r=3
+ DrawAngleArc{angle(ABC), radius(r), external, clockwise}
+
+==============================
+
+ DrawAngleArrow
+
+ This command draws a curved arrow in the specified angle, a distance <radius> from the angle. The angle is either <internal> (less than 180 deg) or <external> (greater than 180 deg). The direction of the arrow is either <clockwise> or <anticlockwise>, and this direction must correspond with the letter sequence specified for the angle.
+Strange and unexpected results will be produced if the four parameters are not internally consistent. The option order angle/radius/internal/clockwise is important. The <radius> parameter can be any numerical expression.
+
+ -----syntax:
+ DrawAngleArrow{angle(), radius(), external, clockwise}
+
+ -----example:
+ DrawAngleArrow{angle(ABC), radius(3), external, clockwise}
+ var r=3
+ DrawAngleArrow{angle(ABC), radius(r), external, clockwise}
+
+==============================
+
+ DrawArrow
+
+ This command draws an arrow(s) joining two points. The direction of the arrow is in the point order specified.
+
+ -----syntax:
+ drawArrow(<line> [,<line>] ... )
+
+ -----notes:
+ The length option can only refer to one arrow
+
+ -----example:
+ drawArrow(AB)
+ drawArrow(FG, HJ)
+
+==============================
+
+ DrawCircle
+
+ This command draws a circle defined by its radius and the point-name of its centre. The <radius> can be any numerical expression. If the units of the X and Y axes are different, circles may be drawn strangely, and mathsPIC therefore generates a warning message to this effect.
+
+ -----syntax:
+ DrawCircle(<center>, <radius>)
+
+ -----examples:
+ drawCircle(C2,5)
+ drawCircle(C2,r2)
+ drawCircle(C2,r2/tan(1.3))
+ drawCircle(C2,AB)
+
+==============================
+
+ DrawCircumcircle
+
+ This command draws the circumcircle of a triangle.
+
+ -----syntax:
+ DrawCircumcircle(<triangle>)
+
+ -----example:
+ drawCircumcircle(ABC)
+
+==============================
+
+ DrawCurve
+
+ This command draws a smooth quadratic curve through three points in the point order specified. Note that curves drawn using this command do not break to avoid line-free zones associated with the points.
+
+ -----syntax:
+ DrawCurve(<point><point><point>)
+
+ -----example:
+ drawCurve(ABC)
+
+==============================
+
+ DrawExcircle
+
+ This command draws the excircle touching one side of a triangle.
+
+ -----syntax:
+ DrawExcircle(<triangle>, <side>)
+
+ -----example:
+ drawExcircle(ABC, BC)
+
+==============================
+
+ DrawIncircle
+
+ This command draws the incircle of a triangle.
+
+ -----syntax:
+ DrawIncircle(<triangle>)
+
+ -----example:
+ drawIncircle(ABC)
+
+==============================
+
+ DrawLine
+
+ This command draws a line joining two or more points. Use the Linethickness command to vary thickness. This command uses the PiCTeX \putrule command for horizontal and vertical lines, and the \plot command for all other orientations.
+
+ -----syntax:
+ DrawLine( <points> [, <points>] )
+
+ -----notes:
+ <points> is any sequence of two or more point names.
+ <expr> is any numerical expression.
+ Lines are drawn in the order specified.
+ Lines are separated by a comma.
+
+ -----examples:
+ drawline(AB)
+ drawline(BCDE)
+ drawline(FG, HJK, PQRST)
+
+==============================
+
+ DrawPerpendicular
+
+ This command draws the perpendicular from a point to a line.
+
+ -----syntax:
+ DrawPerpendicular(<point>, <line)
+
+ -----example:
+ drawPerpendicular(P,AB)
+
+==============================
+
+ DrawPoint
+
+ This command draws the point-symbol at the point-location. Commas must not be used to separate point names. The default point-symbol is \$\bullet\$, unless an optional point-symbol (or string of characters) is specified in the associated point command.
+
+ -----syntax:
+ DrawPoint(<point> [<point> ..])
+
+ -----examples:
+ drawpoint(T4)
+ drawpoint(ABCDEF)
+ drawpoint(P1 P2 P3 P4)
+
+==============================
+
+ DrawRightangle
+
+ This command draws the standard right-angle symbol in the internal angle specified at the size specified by <expr>.
+
+ -----syntax:
+ DrawRightangle(<angle>, <expr>)
+
+ -----notes:
+ The <expr> can be any numerical expression.
+
+ -----example:
+ drawRightangle(ABC,3)
+ drawRightangle(ABC,PQ)
+ var d=5
+ drawRightangle(ABC,d)
+
+==============================
+
+ DrawSquare
+
+ This command draws a square defined by its side and the point-name of its centre. The <sidelength> can be any numerical expression.
+
+ -----syntax:
+ DrawSquare(<centerpoint>, <sidelength>)
+
+ -----examples:
+ drawSquare(P,5)
+ var s2=3, j=2
+ drawSquare(P,s2)
+ drawSquare(P, s2*4/(3*j))
+ drawSquare(P,AB)
+
+==============================
+
+ DrawThickArrow
+
+ This command draws a thick arrow(s) joining two points. The direction of the arrow is in the point order specified. The shape of the arrowhead is controlled by the ArrowShape command.
+
+ -----syntax:
+ drawThickArrow(<line> [,<line>,...])
+
+ -----examples:
+ drawThickarrow(BC)
+ drawThickarrow(PQ, RS)
+
+==============================
+
+ DrawThickLine
+
+ This command draws a thick line(s) joining two points. The direction of the line is in the point order specified. Use the Linethickness command to vary thickness of a line.
+
+ -----syntax:
+ drawThickLine(<line> [,<line>,...])
+
+ -----examples:
+ drawThickline(BC)
+ drawThickline(PQ, RS)
+
+==============================
+
+ InputFile
+
+ This command inputs a plain text file containing mathsPIC commands. Optionally, the file can be input several times, in which case this command functions like a DO--LOOP. The <loopnumber> can be any numerical expression. If the <loopnumber> is not an integer then mathsPIC will round the value down to the nearest integer. See also the beginLOOP ... endLOOP commands.
+
+ -----syntax:
+ inputFile[*](<filename>)[<loopnumber>]
+
+ -----notes:
+ The inputfile* command is used to input a file in verbatim, i.e. a file with no mathsPIC commands, for example, a file containing only PiCTeX commands or data-points for plotting etc. Note that the inputfile* command has no <loopnumber> option. Note also that PiCTeX requires a ODD number of points.
+
+ -----examples:
+ inputFile(myfile.dat)[4]
+ inputFile*(mycurvedata.dat)
+
+==============================
+
+ LineThickness
+
+ This command sets a particular linethickness. The command linethickness(default) restores the working linethickness to the default value of 0.4pt.
+The current value of the linethickness (in current units) can be accessed using the var command (this can be useful when drawing figures using thick lines) .
+
+ -----syntax:
+ LineThickness(<expr><units>)
+ LineThickness(default)
+ var t = _linethickness_
+
+ -----notes:
+ This command also sets the font to cmr and plotsymbol to \CM . and also sets the rule thickness for drawing horizontal and vertical lines. It is important to include a leading zero with decimal fractions less than one.
+
+ -----examples:
+ linethickness(2pt)
+ var t=3
+ linethickness((t)pt)
+ lineThickness((2*t)pt)
+ linethickness(default)
+ var t = _linethickness_
+
+ -----caution:
+ Note that there is a similar PiCTeX command with the same name (but with a different syntax).
+
+==============================
+
+ PAPER
+
+ Defines the plotting area in terms of the options units(), xrange(), yrange(), axes(), and ticks(). The units() argument must contain a numeric value and a valid TeX length unit mm, cm, pt, pc(pica), in(inch), bp(big point), dd(didot), cc(cicero), sp(scaled point). The X and Y axes can have different units (see second example below). The axes() arguments XYTBLR refer to the X and Y axes, and the Top, Bottom, Left and Right axes. A * following one of the axes disables ticks on that axis. The X and Y axes pass through the zeros.
+
+ -----examples:
+ paper{units(1cm),xrange(0,10),yrange(0,10)}
+ paper{units(2cm,1cm),xrange(0,10),yrange(0,10),axes(LB)}
+ paper{units(1mm),xrange(0,100),yrange(0,100),axes(XY)}
+ paper{units(1cm),xrange(-5,5),yrange(-5,5),axes(LRTBXY),ticks(1,1)}
+ paper{units(1cm),xrange(-5,5),yrange(-5,5),axes(LRT*B*)}
+
+==============================
+
+ POINT
+
+ Defines a new point by allocating coordinates to a new point name. The * option re-allocates coordinates to an existing point name.
+
+ -----syntax:
+ POINT[*](<name>){<point>}[symbol=<chars>, radius=<expr>]
+ POINT[*](<name>){<location>}[symbol=<chars>, radius=<expr>]
+
+ -----notes:
+ <name> one leading letter plus maximum of four trailing digits
+ <chars> any TeX string allowed in an \hbox{}
+ <expr> any numerical expression
+ The polar(r,theta) option defaults to radians for the angle theta. To work in degrees then must append <deg> eg: polar(r,theta deg). Can use <direction()> and <directiondeg()> to replace theta. Note that the term vector(AB) means use same (r, theta) as AB.
+
+ -----examples:
+ point(A){5,5}
+ point(B2){22,46}[symbol=$\odot$]
+ point(B2){22,46}[symbol=circle(2),radius=5]
+ var r=3
+ point(B2){22,46}[symbol=square(3),radius=r]
+ point(B123){22,46}[radius=5]
+ point(D2){B2, shift(5,5)}
+ var s = 3
+ point(D2){B2, shift(2*s,4*s)}
+ point(D3){D2, polar(6,32 deg)}
+ point(D4){D2, polar(6,1.2 rad)}
+ point(D4){D2, polar(6, direction(AB))} %% radians by default
+ point(D4){D2, polar(6, directiondeg(AB) deg)}
+ point(G2){Q, rotate(P, 23 deg)}
+ point(G2){Q, vector(AB)}
+ point(D2){intersection(AB,CD)}
+ point(F){PointOnLine(AB,5.3)}
+ point(G){perpendicular(P,AB)}
+ point(H){circumcircleCenter(ABC)}
+ point(J){incircleCenter(ABC)}
+ point(K){excircleCenter(ABC,BC)}
+ point*(A){6,3}
+ point*(P){Q}
+ point*(B){B, shift(5,0)}
+ point*(P){xcoord(J),ycoord(K)}
+
+==============================
+
+ PointSymbol
+
+ This command allows the default point-symbol \bullet (with zero line-free radius) to be changed. The PointSymbol command is particularly useful where a set of points uses the same point-symbol, for example, when drawing graphs. The point-symbol can be reset to the default \bullet using the command PointSymbol(default).
+
+ -----syntax:
+ PointSymbol(<symbol>, <line-free-radius>)
+ PointSymbol(default)
+
+ -----notes:
+ The PointSymbol command only influences subsequent point commands.
+ The optional square bracket of the point command overrides the PointSymbol command.
+
+ -----examples:
+ PointSymbol($\odot$, 0.7)
+ PointSymbol(default)
+
+==============================
+
+ SYSTEM
+
+ This command allows the user to access the command line and execute standard Linux commands. A important use for this command is to run a Perl program.
+
+ -----syntax:
+ System("<command>")
+
+ -----notes:
+ The <command> string must be in inverted commas.
+
+ -----example:
+ system("dir > mydir-listing.txt")
+ system("perl myperlprogram.pl")
+
+==============================
+
+ SHOW....
+
+ This command makes mathsPIC return the value of a calculation or specified parameter; for example, the value of a particular angle, or the length of a line. The result is shown in the output-file as a commented line. This allows mathsPIC commands to be adjusted in the light of calculations. There are currently five such commands as follows.
+
+ -----syntax:
+ showLength(AB)
+ showAngle(ABC) % returns angle in radians
+ showAngledeg(ABC) % returns angle in degrees
+ showArea(ABC)
+ showPoints
+ showVariables
+
+==============================
+
+ TEXT
+
+ This command places a text-string at a specific location. By default the text is centered vertically and horizontally at the specified point. Optionally, text can be placed relative to a point using appropriate combinations of the PiCTeX `position' options l t r B b to align the (l)eft edge, (r)ight edge, (t)op edge, (B)aseline, (b)ottom edge respectively of the text box with the point-location.
+
+ Remember that the default units for the angle argument of the polar() expression is radians; hence you MUST append `deg' if you want to work in degrees
+
+ -----syntax:
+ text(<string>){<location>}[<position options>]
+ text(<string>){<pointname>, shift(<x>,<y>)}[]
+ text(<string>){<pointname>, polar(<r>,<angle>[rad])}[]
+
+ -----examples:
+ text(A){5,6}
+ text($A_1$){A1, shift(2, 2)}
+ text(Z2){Z2, shift(5, -5)}[tr]
+ text(Z3){Z2, polar(5, 20 deg)}[Br]
+ text(Z4){Z2, polar(5, 1.34 rad)}
+ text(\framebox{Z5}){Z5}
+
+==============================
+
+ VAR
+
+ The var command is used to define scalar variables. It can be any numerical expression. A variable-name must begin with a single letter (either upper or lower case), and may have up to a maximum of four following digits. If a more detailed variable name is required, then a simple alternative is to use a mathsPIC macro---as any string can be allocated via macros (see the beginning of this chapter for details on macros).
+
+ Note that variables, constants and points have the same name structure, and a variable can have the same name as a point (and so we suggest points have uppercase letters and variables and constants have lowercase letters). New values can be re-allocated to existing variable-names; however, when this occurs then mathsPIC does not issue a warning message to hightlight this fact.
+
+ If it is important to be warned if a potential variable is accidentally reallocated then one should consider using the const command instead (since mathsPIC does generate an error message if a constant is reallocated).
+
+ -----syntax:
+ var <name> = <expr>
+
+ -----notes:
+ In addition to the mathematical functions mathsPIC functions which can be used with the var command are:
+
+ angle(<three-points>) % returns angle in radians
+ angledeg(<three-points>) % returns angle in degrees
+ area(<three-points>)
+ xcoord(<point>)
+ ycoord(<point>)
+ direction(<two-points>) % returns angular direction in radians
+ directiondeg(<two-points>) % returns angular direction in degrees
+
+ -----examples:
+ var r = 20, r4 = r3*tan(0.3), j = (r*2e3)**2, r5 = AB
+ var e = _e_, p1 = _Pi_
+ var t = _linethickness_ % returns linethickness in current units
+ var g137 = angle(ABC) %(default: returns in radians)
+ var g = angledeg(ABC) % angle in degrees
+ var h = area(ABC)
+ var x2 = xcoord(A), y2 = ycoord(A)
+ var m5 = 12 rem 3 % remainder after dividing by 3
+ var r1 = direction(PQ) % in radians
+ var d1 = directiondeg(PQ)
+
+==============================
+ SEE ALSO
+The mathsPIC package manual and examples
+
+ BUGS
+Please report bugs to Dick Nickalls (dick [AT] nickalls [dot] org) or to Apostolos Syropoulos
+
+================END================= \ No newline at end of file
diff --git a/graphics/mathspic/perl/MATHSPIC.BAT b/graphics/mathspic/perl/MATHSPIC.BAT
new file mode 100644
index 0000000000..6ffcadce68
--- /dev/null
+++ b/graphics/mathspic/perl/MATHSPIC.BAT
@@ -0,0 +1,2 @@
+perl mathspic113.pl %1 %2 %3 %4 %5
+
diff --git a/graphics/mathspic/perl/README.txt b/graphics/mathspic/perl/README.txt
new file mode 100644
index 0000000000..4ef106013a
--- /dev/null
+++ b/graphics/mathspic/perl/README.txt
@@ -0,0 +1,115 @@
+%% readme.txt
+%% for mathsPIC (version 1.13)
+
+Name:- mathsPIC (Perl version)
+Authors:- A. Syropoulos (asyropoulos@yahoo.com)
+ and R.W.D. Nickalls (dick@nickalls.org)
+Date:- April 26, 2010
+
+(1) INTRODUCTION
+-----------------
+MathsPIC is an open-source `filter' program for the PiCTeX graphics package, which enables complicated drawings/diagrams to be constructed very easily (allows the flexible use of LaTeX commands, relative addressing, macros, libraries, and perl programs).
+
+MathsPIC is a Perl program which processes an input script file (containing mathsPIC, TeX, LaTeX, and PiCTeX commands) into a .tex file which can be processed in the usual way (by TeX or LaTeX) to generate the final graphic. Please read the comprehensive manual for details of commands, usage, examples, installation etc.
+
+MathsPIC will run on any platform having a working Perl and TeX/LaTeX installation. However, there may of course be minor differences regarding installation and usage between platforms.
+
+MathsPIC has been well tested using a Solaris x86 box and GNU/Linux which the authors are familiar with. Feedback regarding installation and usage on other platforms will be greatly appreciated, and included in future manuals.
+
+For details see the manual (mp1manual*.pdf).
+
+(2) HISTORY
+-----------
+MathsPIC was originally an MS-DOS program (September 1999). mathsPIC was implemented in Perl in order to (a) greatly improve its utility, and (b) to make it available to the wide range of platforms which run Perl. An early version of the Perl mathsPIC was presented at the TUG2000 conference (Oxford, UK).
+
+(3) REQUIRED SYSTEMS
+--------------------
+-perl (an interpreter for the perl language, see http://www.perl.com)
+
+
+(4) PACKAGE FILES
+------------------
+The following files are included in the mathsPIC package.
+
+
+grabtexdata.pl % Perl program used in Chapter 8 (Accessing TeX parameters)
+HELP.TXT % text version of the Unix manpage
+mathspic113.pl % mathsPIC program version 1.13 (perl)
+mathspic.sty % style option
+mathspic.1 % unix/Linux manpage file
+mathspic.sh % example BASH file for running the program
+MATHSPIC.BAT % example batch file (MS-Windows)
+mathsPICmanual.pdf % manual
+mathsPICmanual.zip % manual--all the LaTeX and figure files
+mathsPICfigures.zip % all the .m and .pl files described in the manual
+mathspic.lib % example library file of macros
+README.txt % this file
+sourcecode.pdf % source code
+sourcecode.html % source code
+sourcecode.nw % source code (noweb)
+
+
+
+(5) INSTALLATION (Unix/Linux)
+-----------------------------
+Four files need to be placed in specific locations as follows
+(see also USAGE regarding the BASH script file)
+
+(a) mathsPIC program (mathspic113.pl)
+This needs to be placed where your shell can find it
+(typically: /usr/local/bin)
+
+(b) mathsPIC BASH script (mathspic.sh)
+This needs to be placed where your shell can find it
+(typically: /usr/local/bin)
+
+(c) LaTeX package (mathspic.sty)
+This needs to be placed with the other style options
+(typically: /usr/share/texmf/tex/latex/base/).
+
+(d) manpage (mathspic.1)
+place this file in the /man1/ directory
+(typically: /usr/share/man/man1/)
+
+An alternative to using the shell script (BASH file) is simply to make the
+perl script file (mathspic.pl) `executable', as follows:
+Just copy the file mathspic.pl to a directory where the shell
+can find it (typically /usr/local/bin) and then
+ (1) rename the file --> mathspic.
+ (2) make the file `executable' (e.g., by issuing the command <chmod 755 mathspic> ).
+
+
+(6) USAGE (see manual for full details)
+----------------------------------------
+In Unix/Linux one way of running mathsPIC is to type the following at the command-line (options are shown in square brackets). Note this requires both the perl program (mathspic.pl) and the input file to be in the same directory.
+
+Syntax:
+ perl mathspic113.pl [-b] [-c] [-h] infile [-o outfile]
+
+Options:
+ -b enables bell/sound if errors are detected
+ -c disables writing of comments to output file
+ -o to be followed by the <outfile>
+ -h displays help info
+
+However, it is generally much more convenient to run mathsPIC via a batch file, since we can then run mathsPIC from any directory.
+
+For example (Unix/Linux) rename the example BASH file <mathspic.sh> to <mathspic>. Now change the user permissions to make it a read/write/executable file ($ chmod 755 mathspic). Finally, copy the file to a place where your shell will find it, typically the directory /usr/local/bin/. Now you will be able to run mathsPIC from the command-line in any directory using the command:-
+
+mathspic [-b] [-c] [-h] infile [-o outfile]
+
+MS-Windows users can use the example MATHSPIC.BAT file similarly.
+
+(7) LICENSE (LPPL):
+-------------
+ This program is free software; you can redistribute it and/or modify it under the terms of the LaTeX Project Public License.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+-----------------
+End of README.txt
+-----------------
+
+
+
+=========================
+
diff --git a/graphics/mathspic/perl/grabtexdata.tex b/graphics/mathspic/perl/grabtexdata.tex
new file mode 100644
index 0000000000..64b8e40bbe
--- /dev/null
+++ b/graphics/mathspic/perl/grabtexdata.tex
@@ -0,0 +1,44 @@
+%% grabtexdata.tex
+%% part of the mathsPIC package
+%% example file used in Chapter 8 of the mathsPICmanual
+%% (accessing TeX parameter values)
+%% RWD Nickalls (c) April 2010
+%% dick@nickalls.org
+%%========================================================
+%% for extracting TeX-file data into mathspic var commands
+%%========================================================
+\scrollmode % prevent LaTeX stopping if there are errors
+%---------------------
+% make a print command macro
+\newcommand{\print}[1]{\immediate\write\outfile{#1}}
+%---------------------
+% make a comment % command macro
+% first need to define percentchar for the write statement
+% (From "TeX for the Impatient" (1990), p 292)
+{\catcode`\%=12 \global\def\percentchar{%}}%
+\newcommand{\comment}{\percentchar\space}
+%
+% make a \macro command --> %def<space>
+\newcommand{\mydef}{def}
+\newcommand{\macro}{\percentchar\mydef\space}
+%----------------------
+% create and open a new file with filename = textfiledata.dat
+\newwrite\outfile
+\immediate\openout\outfile=texfiledata.dat
+%----------------------
+%% write file header & general info
+\print{\percentchar\percentchar\space file: texdata.dat}
+\print{\percentchar\percentchar\space accessing TeX parameter values}
+%---------------------
+%% now get \textwidth and \textheight values from the tex file
+\print{\comment ============}
+\print{var w555 = \number\textwidth\comment\textwidth=scaled points}
+\print{var w556 = \number\textwidth\comment\textwidth=\the\textwidth}
+\print{var w557 = \number\textwidth/1864679.8\comment (\textwidth in cms)}
+\print{\macro textwidthcms()\number\textwidth/1864679.8\comment}
+\print{\macro textheightcms()\number\textheight/1864679.8\comment}
+\print{\comment ============}
+%--------------------
+% close the file
+\immediate\closeout\outfile
+%%=========end=========================
diff --git a/graphics/mathspic/perl/mathsPICmanual.pdf b/graphics/mathspic/perl/mathsPICmanual.pdf
new file mode 100644
index 0000000000..b2ee735a10
--- /dev/null
+++ b/graphics/mathspic/perl/mathsPICmanual.pdf
Binary files differ
diff --git a/graphics/mathspic/perl/mathspic.1 b/graphics/mathspic/perl/mathspic.1
new file mode 100644
index 0000000000..9ffa4b6c6c
--- /dev/null
+++ b/graphics/mathspic/perl/mathspic.1
@@ -0,0 +1,576 @@
+.\" copyright (c) 2010 A Syropoulos and RWD Nickalls
+.\" mathspic.1
+.\" place this file in: /usr/share/man/man1/
+..
+.TH mathsPIC 1 "April 26, 2010" "mathsPIC perl version"
+.SH NAME
+.B mathsPIC
+.SH AUTHORS
+A. Syropoulos and R.W.D. Nickalls (April 26, 2010)
+
+ asyropoulos[at]<yahoo><com>
+ dick[at]<nickalls><org>
+
+.SH DESCRIPTION
+.B mathsPIC
+is a Perl filter program for PiCTeX. mathsPIC has its own macro and macro library capability, and allows use of mathsPIC, PiCTeX, TeX and LaTeX commands. A significant feature of mathsPIC is that it allows access to the command-line, and so allows the user to extend mathsPIC commands by calling Perl and other programs written to perform particular drawing actions. See the package manual for full details and examples. The latest version can be downloaded from
+.PP
+CTAN: tex-archive/graphics/pictex/mathspic/perl
+.PP
+Commands which can be used in the mathsPIC script file fall into four main groups (a) mathsPIC macro commands (prefixed with %def), (b) regular mathsPIC commands (do not have a backslash), (c) regular PiCTeX commands (all have a backslash), and (d) regular TeX and LaTeX commands (all have a backslash).
+.PP
+The following mathematics functions can used (note that decimal fractions having an absolute value less than 1 must have a leading zero). Note also that all the trignometric functions require their argument in radians.
+
+Trigonometric: sin(), cos(), tan(), asin(), acos(), atan()
+
+Remainder: rem(); eg var r=12 rem(5)
+
+Integer: int(); eg var r= int(3.87) --> 3
+
+Sign (returns -1, 0, +1): sgn(); eg var s=sgn(-3.27) --> -1
+
+Square root: sqrt(); eg var s = sqrt(14)
+
+Exponentiation: **; eg var j = r**2
+
+Pi constant (3.14159...): _Pi_ and _pi_
+
+e constant (2.71828...): _E_ and _e_
+
+Linethickness: _linethickness_ ; eg var t = _linethickness_
+
+.SH COMMAND-LINE USE
+perl mathspic.pl [-b] [-c] [-h] [-o <outfile>] <infile>
+
+.B -b
+enables beep if mathsPIC detects an error
+
+.B -c
+disables the writing of comments to output file
+
+.B -h
+displays the help file
+
+.B -o
+defines the output file name
+.SH MACRO COMMANDS
+macro definition commands are prefixed with %def and can take either 0, 1, or more parameters. Macros will generally be used as part of a
+.B var
+command as shown below. Macros are deleted using the
+.B %undef
+command.
+
+ -----syntax:
+ %def MACRONAME(parameters)<macrodefinition>
+ %undef MACRONAME(parameters)
+
+ -----notes:
+ Notes: (a) the () must be used in the definition even if no parameters are used, (b) the name can be any combination of upper and lower case characters and numbers, (c) when the macro is used in a command it is prefixed by a & symbol, (d) it is a good idea to always place a % symbol at the end of the definition, (e) comments (prefixed by a % symbol) can be placed after the macro definition just as in TeX or LaTeX.
+
+ -----examples:
+ %def d2r()_pi_/180% % degrees2radians
+ %def AreaOfRectangle(x,y)x*y% % width x, length y
+ %undef d2r() % delete the macro
+
+ -----use:
+ var j2= 6*(&d2r(45) + 23)
+ var a3 = 3*&AreaOfRectangle(5,7)
+.SH GENERAL COMMANDS
+
+.P
+.B NUMERICAL EXPRESSIONS
+ When dealing with commands we will refer frequently to the term `numerical expression' by which is meant either (a) a number (integer or decimal), (b) a numeric variable or constant (defined using the var or const command), (c) any mathsPIC function, macro, or mathematical expression which evaluates to a number, or (d) a pair of point names (e.g. AB) representing the Pythagorean distance between the two points. A leading zero must be used with decimal fractions less than one.
+
+ In general, if a command's argument accepts a number then it will also accept a `numerical expression' (<expr>) as defined above. Sometimes a following <unit> is associated with the number or numerical expression, in which case the number or numerical expression can be delimited by a round bracket (or separated from the unit by a <space>), as shown in the following examples.
+
+ -----examples:
+ ArrowShape(3mm, 20,40)
+ var h=4
+ ArrowShape(h mm, 20, 40)
+ ArrowShape((2*h)mm,20,40)
+
+.P
+.B BACKSLASH
+\\
+ A leading backslash without a following space indicates that it is part of a PiCTeX, TeX or LaTeX command, in which case mathsPIC simply copies the whole line verbatim into the output file. A leading backslash followed by one or more spaces makes mathsPIC copy the whole line verbatim into the output file but without the backslash.
+
+.P
+.B USING THE COLOR PACKAGE
+ The standard COLOR package can be used with mathsPIC, but note that it is important to load the COLOR package after the mathsPIC package.
+
+ It is best to place a comment symbol % at the end of LaTeX and TeX commands to limit white space at the end.
+
+ In the event of any colour-spill from a diagram into any following text (this used to be a problem in early TeX implementations) consider using the \\normalcolor command as a delimiter within the \\beginpicture...\\endpicture environment.
+
+==============================
+
+.B ARROWSHAPE
+ This command defines the shape of an arrowhead, and allows
+different arrowheads to be customised.
+
+The default arrow shape is equivalent to the Arrowshape(2mm,30,40) command.
+This default arrowhead shape can be reset using the Arrowshape(default) command, as shown in the following example.
+
+ -----syntax:
+ arrowshape(<length>[units], <angledeg>, <angledeg>)
+
+ -----examples:
+ Arrowshape(4mm,30,60)
+ drawArrow(AB)
+ Arrowshape(default)
+
+==============================
+
+.B beginLOOP...endLOOP
+ This is an environment which cycles a block of code a specified number of times.
+
+ -----syntax:
+ beginLoop <expr>
+ ...
+ endLoop
+
+ -----notes:
+ The block of code which lies within the environment is input <expr> times.
+
+ -----example:
+ beginLoop 5
+ ...
+ endLoop
+
+
+==============================
+
+.B beginSKIP...endSKIP
+ This is an `environment' within which commands are not actioned. It is useful in development for testing isolated commands and excluding other commands.
+
+==============================
+
+.B CONST
+ The const command is used to define scalar constants. Note that a constant-name must begin with a single letter (either upper or lower case), and may have up to a maximum of three following digits. Note that constants, variables and points have the same name structure, and a constant could have the same name as a point (and so we suggest points have uppercase letters and variables and constants have lowercase letters). The scalar argument can be any numeric expression. New values cannot be re-allocated to existing constant-names. If this occurs mathsPIC will issue an error message.
+
+ -----syntax:
+ const name = <expr>
+
+ -----examples:
+ const r = 20, r4 = r3*tan(0.3)
+
+==============================
+
+.B DashArray
+ The dasharray command takes an arbitrary number of paired arguments that are used to specify a dash pattern.
+
+ -----syntax
+ dasharray(d1 , g1 , d2 , g2 , ... )
+
+ -----notes
+ The ds denotes the length of a dash and the gs denotes the length of the gap between two consecutive dashes. There must be an even number of arguments. If a variable or expression is used then it should be separated from the unit either by a <space> or with round brackets ( ) as shown below.
+
+ -----example
+ dasharray(6pt, 2pt, 1pt, 2pt)
+ var d=2
+ dasharray(6pt, 2pt, 1pt, d pt)
+ dasharray(6pt, 2pt, 1pt, (d)pt)
+ dasharray(6pt, 2pt, 1pt, (3*d)pt)
+
+==============================
+
+.B DrawAngleArc
+ This command draws an arc in the specified angle, a distance <radius> from the angle. The angle is either <internal> (less than 180 deg) or <external> (greater than 180 deg). The direction of the arc is either <clockwise> or <anticlockwise>, and this direction must correspond with the letter sequence specified for the angle.
+Strange and unexpected results will be produced if the four parameters are not internally consistent. The option order angle/radius/internal or external/clockwise or anticlockwise is important. The <radius> parameter can be any numerical expression.
+
+ -----syntax:
+ DrawAngleArc{angle(), radius(), external, clockwise}
+
+ -----example:
+ DrawAngleArc{angle(ABC), radius(3), external, clockwise}
+ var r=3
+ DrawAngleArc{angle(ABC), radius(r), external, clockwise}
+
+==============================
+
+.B DrawAngleArrow
+ This command draws a curved arrow in the specified angle, a distance <radius> from the angle. The angle is either <internal> (less than 180 deg) or <external> (greater than 180 deg). The direction of the arrow is either <clockwise> or <anticlockwise>, and this direction must correspond with the letter sequence specified for the angle.
+Strange and unexpected results will be produced if the four parameters are not internally consistent. The option order angle/radius/internal/clockwise is important. The <radius> parameter can be any numerical expression.
+
+ -----syntax:
+ DrawAngleArrow{angle(), radius(), external, clockwise}
+
+ -----example:
+ DrawAngleArrow{angle(ABC), radius(3), external, clockwise}
+ var r=3
+ DrawAngleArrow{angle(ABC), radius(r), external, clockwise}
+
+==============================
+
+.B DrawArrow
+ This command draws an arrow(s) joining two points. The direction of the arrow is in the point order specified.
+
+ -----syntax:
+ drawArrow(<line> [,<line>] ... )
+
+ -----notes:
+ The length option can only refer to one arrow
+
+ -----example:
+ drawArrow(AB)
+ drawArrow(FG, HJ)
+
+==============================
+
+.B DrawCircle
+ This command draws a circle defined by its radius and the point-name of its centre. The <radius> can be any numerical expression. If the units of the X and Y axes are different, circles may be drawn strangely, and mathsPIC therefore generates a warning message to this effect.
+
+ -----syntax:
+ DrawCircle(<center>, <radius>)
+
+ -----examples:
+ drawCircle(C2,5)
+ drawCircle(C2,r2)
+ drawCircle(C2,r2/tan(1.3))
+ drawCircle(C2,AB)
+
+==============================
+
+.B DrawCircumcircle
+ This command draws the circumcircle of a triangle.
+
+ -----syntax:
+ DrawCircumcircle(<triangle>)
+
+ -----example:
+ drawCircumcircle(ABC)
+
+==============================
+
+.B DrawCurve
+ This command draws a smooth quadratic curve through three points in the point order specified. Note that curves drawn using this command do not break to avoid line-free zones associated with the points.
+
+ -----syntax:
+ DrawCurve(<point><point><point>)
+
+ -----example:
+ drawCurve(ABC)
+
+==============================
+
+.B DrawExcircle
+ This command draws the excircle touching one side of a triangle.
+
+ -----syntax:
+ DrawExcircle(<triangle>, <side>)
+
+ -----example:
+ drawExcircle(ABC, BC)
+
+==============================
+
+.B DrawIncircle
+ This command draws the incircle of a triangle.
+
+ -----syntax:
+ DrawIncircle(<triangle>)
+
+ -----example:
+ drawIncircle(ABC)
+
+==============================
+
+.B DrawLine
+ This command draws a line joining two or more points. Use the Linethickness command to vary thickness. This command uses the PiCTeX \\putrule command for horizontal and vertical lines, and the \\plot command for all other orientations.
+
+ -----syntax:
+ DrawLine( <points> [, <points>] )
+
+ -----notes:
+ <points> is any sequence of two or more point names.
+ <expr> is any numerical expression.
+ Lines are drawn in the order specified.
+ Lines are separated by a comma.
+
+ -----examples:
+ drawline(AB)
+ drawline(BCDE)
+ drawline(FG, HJK, PQRST)
+
+==============================
+
+.B DrawPerpendicular
+ This command draws the perpendicular from a point to a line.
+
+ -----syntax:
+ DrawPerpendicular(<point>, <line)
+
+ -----example:
+ drawPerpendicular(P,AB)
+
+==============================
+
+.B DrawPoint
+ This command draws the point-symbol at the point-location. Commas must not be used to separate point names. The default point-symbol is \$\\bullet\$, unless an optional point-symbol (or string of characters) is specified in the associated point command.
+
+ -----syntax:
+ DrawPoint(<point> [<point> ..])
+
+ -----examples:
+ drawpoint(T4)
+ drawpoint(ABCDEF)
+ drawpoint(P1 P2 P3 P4)
+
+==============================
+
+.B DrawRightangle
+ This command draws the standard right-angle symbol in the internal angle specified at the size specified by <expr>.
+
+ -----syntax:
+ DrawRightangle(<angle>, <expr>)
+
+ -----notes:
+ The <expr> can be any numerical expression.
+
+ -----example:
+ drawRightangle(ABC,3)
+ drawRightangle(ABC,PQ)
+ var d=5
+ drawRightangle(ABC,d)
+
+==============================
+
+.B DrawSquare
+ This command draws a square defined by its side and the point-name of its centre. The <sidelength> can be any numerical expression.
+
+ -----syntax:
+ DrawSquare(<centerpoint>, <sidelength>)
+
+ -----examples:
+ drawSquare(P,5)
+ var s2=3, j=2
+ drawSquare(P,s2)
+ drawSquare(P, s2*4/(3*j))
+ drawSquare(P,AB)
+
+==============================
+
+.B DrawThickArrow
+ This command draws a thick arrow(s) joining two points. The direction of the arrow is in the point order specified. The shape of the arrowhead is controlled by the ArrowShape command.
+
+ -----syntax:
+ drawThickArrow(<line> [,<line>,...])
+
+ -----examples:
+ drawThickarrow(BC)
+ drawThickarrow(PQ, RS)
+
+==============================
+
+.B DrawThickLine
+ This command draws a thick line(s) joining two points. The direction of the line is in the point order specified. Use the Linethickness command to vary thickness of a line.
+
+ -----syntax:
+ drawThickLine(<line> [,<line>,...])
+
+ -----examples:
+ drawThickline(BC)
+ drawThickline(PQ, RS)
+
+==============================
+
+.B InputFile
+ This command inputs a plain text file containing mathsPIC commands. Optionally, the file can be input several times, in which case this command functions like a DO--LOOP.
+The <loopnumber> can be any numerical expression. If the <loopnumber> is not an integer then mathsPIC will round the value down to the nearest integer. See also the beginLOOP ... endLOOP commands.
+
+ -----syntax:
+ inputFile[*](<filename>)[<loopnumber>]
+
+ -----notes:
+ The inputfile* command is used to input a file in verbatim, i.e. a file with no mathsPIC commands, for example, a file containing only PiCTeX commands or data-points
+for plotting etc. Note that the inputfile* command has no <loopnumber> option. Note also that PiCTeX requires a ODD number of points.
+
+ -----examples:
+ inputFile(myfile.dat)[4]
+ inputFile*(mycurvedata.dat)
+
+==============================
+
+.B LineThickness
+ This command sets a particular linethickness. The command linethickness(default) restores the working linethickness to the default value of 0.4pt.
+The current value of the linethickness (in current units) can be accessed using the var command (this can be useful when drawing figures using thick lines) .
+
+ -----syntax:
+ LineThickness(<expr><units>)
+ LineThickness(default)
+ var t = _linethickness_
+
+ -----notes:
+ This command also sets the font to cmr and plotsymbol to \\CM . and also sets the rule thickness for drawing horizontal and vertical lines. It is important to include a leading zero with decimal fractions less than one.
+
+ -----examples:
+ linethickness(2pt)
+ var t=3
+ linethickness((t)pt)
+ lineThickness((2*t)pt)
+ linethickness(default)
+ var t = _linethickness_
+
+ -----caution:
+ Note that there is a similar PiCTeX command with the same name (but with a different syntax).
+
+==============================
+
+.B PAPER
+ Defines the plotting area in terms of the options units(), xrange(), yrange(), axes(), and ticks(). The units() argument must contain a numeric value and a valid TeX length unit mm, cm, pt, pc(pica), in(inch), bp(big point), dd(didot), cc(cicero), sp(scaled point). The X and Y axes can have different units (see second example below). The axes() arguments XYTBLR refer to the X and Y axes, and the Top, Bottom, Left and Right axes. A * following one of the axes disables ticks on that axis. The X and Y axes pass through the zeros.
+
+ -----examples:
+ paper{units(1cm),xrange(0,10),yrange(0,10)}
+ paper{units(2cm,1cm),xrange(0,10),yrange(0,10),axes(LB)}
+ paper{units(1mm),xrange(0,100),yrange(0,100),axes(XY)}
+ paper{units(1cm),xrange(-5,5),yrange(-5,5),axes(LRTBXY),ticks(1,1)}
+ paper{units(1cm),xrange(-5,5),yrange(-5,5),axes(LRT*B*)}
+
+==============================
+
+.B POINT
+ Defines a new point by allocating coordinates to a new point name. The * option re-allocates coordinates to an existing point name.
+
+ -----syntax:
+ POINT[*](<name>){<point>}[symbol=<chars>, radius=<expr>]
+ POINT[*](<name>){<location>}[symbol=<chars>, radius=<expr>]
+
+ -----notes:
+ <name> one leading letter plus maximum of three trailing digits
+ <chars> any TeX string allowed in an \\hbox{}
+ <expr> any numerical expression
+ The polar(r,theta) option defaults to radians for the angle theta. To work in degrees then must append <deg> eg: polar(r,theta deg). Can use <direction()> and <directiondeg()> to replace theta. Note that the term vector(AB) means use same (r, theta) as AB.
+
+ -----examples:
+ point(A){5,5}
+ point(B2){22,46}[symbol=$\\odot$]
+ point(B2){22,46}[symbol=circle(2),radius=5]
+ var r=3
+ point(B2){22,46}[symbol=square(3),radius=r]
+ point(B123){22,46}[radius=5]
+ point(D2){B2, shift(5,5)}
+ var s = 3
+ point(D2){B2, shift(2*s,4*s)}
+ point(D3){D2, polar(6,32 deg)}
+ point(D4){D2, polar(6,1.2 rad)}
+ point(D4){D2, polar(6, direction(AB))} %% radians by default
+ point(D4){D2, polar(6, directiondeg(AB) deg)}
+ point(G2){Q, rotate(P, 23 deg)}
+ point(G2){Q, vector(AB)}
+ point(D2){intersection(AB,CD)}
+ point(F){PointOnLine(AB,5.3)}
+ point(G){perpendicular(P,AB)}
+ point(H){circumcircleCenter(ABC)}
+ point(J){incircleCenter(ABC)}
+ point(K){excircleCenter(ABC,BC)}
+ point*(A){6,3}
+ point*(P){Q}
+ point*(B){B, shift(5,0)}
+ point*(P){xcoord(J),ycoord(K)}
+
+==============================
+
+.B PointSymbol
+ This command allows the default point-symbol \\bullet (with zero line-free radius) to be changed. The PointSymbol command is particularly useful where a set of points uses the same point-symbol, for example, when drawing graphs. The point-symbol can be reset to the default \\bullet using the command PointSymbol(default).
+
+ -----syntax:
+ PointSymbol(<symbol>, <line-free-radius>)
+ PointSymbol(default)
+
+ -----notes:
+ The PointSymbol command only influences subsequent point commands.
+ The optional square bracket of the point command overrides the PointSymbol command.
+
+ -----examples:
+ PointSymbol($\\odot$, 0.7)
+ PointSymbol(default)
+
+==============================
+
+.B SYSTEM
+ This command allows the user to access the command line and execute standard Linux commands. A important use for this command is to run a Perl program.
+
+ -----syntax:
+ System("<command>")
+
+ -----notes:
+ The <command> string must be in inverted commas.
+
+ -----example:
+ system("dir > mydir-listing.txt")
+ system("perl myperlprogram.pl")
+
+==============================
+
+.B SHOW....
+ This command makes mathsPIC return the value of a calculation or specified parameter; for example, the value of a particular angle, or the length of a line. The result is shown in the output-file as a commented line. This allows mathsPIC commands to be adjusted in the light of calculations. There are currently five such commands as follows.
+
+ -----syntax:
+ showLength(AB)
+ showAngle(ABC) % returns angle in radians
+ showAngledeg(ABC) % returns angle in degrees
+ showArea(ABC)
+ showPoints
+ showVariables
+
+==============================
+
+.B TEXT
+ This command places a text-string at a specific location. By default the text is centered vertically and horizontally at the specified point. Optionally, text can be placed relative to a point using appropriate combinations of the PiCTeX `position' options l t r B b to align the (l)eft edge, (r)ight edge, (t)op edge, (B)aseline, (b)ottom edge respectively of the text box with the point-location.
+
+ Remember that the default units for the angle argument of the polar() expression is radians; hence you MUST append `deg' if you want to work in degrees
+
+ -----syntax:
+ text(<string>){<location>}[<position options>]
+ text(<string>){<pointname>, shift(<x>,<y>)}[]
+ text(<string>){<pointname>, polar(<r>,<angle>[rad])}[]
+
+ -----examples:
+ text(A){5,6}
+ text($A_1$){A1, shift(2, 2)}
+ text(Z2){Z2, shift(5, -5)}[tr]
+ text(Z3){Z2, polar(5, 20 deg)}[Br]
+ text(Z4){Z2, polar(5, 1.34 rad)}
+ text(\\framebox{Z5}){Z5}
+
+==============================
+
+.B VAR
+ The var command is used to define scalar variables. It can be any numerical expression. A variable-name must begin with a single letter (either upper or lower case), and may have up to a maximum of four following digits. If a more detailed variable name is required, then a simple alternative is to use a mathsPIC macro---as any string can be allocated via macros (see the beginning of this chapter for details on macros).
+
+ Note that variables, constants and points have the same name structure, and a variable can have the same name as a point (and so we suggest points have uppercase letters and variables and constants have lowercase letters). New values can be re-allocated to existing variable-names; however, when this occurs then mathsPIC does not issue a warning message to hightlight this fact.
+
+ If it is important to be warned if a potential variable is accidentally reallocated then one should consider using the const command instead (since mathsPIC does generate an error message if a constant is reallocated).
+
+ -----syntax:
+ var <name> = <expr>
+
+ -----notes:
+ In addition to the mathematical functions mathsPIC functions which can be used with the var command are:
+
+ angle(<three-points>) % returns angle in radians
+ angledeg(<three-points>) % returns angle in degrees
+ area(<three-points>)
+ xcoord(<point>)
+ ycoord(<point>)
+ direction(<two-points>) % returns angular direction in radians
+ directiondeg(<two-points>) % returns angular direction in degrees
+
+ -----examples:
+ var r = 20, r4 = r3*tan(0.3), j = (r*2e3)**2, r5 = AB
+ var e = _e_, p1 = _Pi_
+ var t = _linethickness_ % returns linethickness in current units
+ var g137 = angle(ABC) %(default: returns in radians)
+ var g = angledeg(ABC) % angle in degrees
+ var h = area(ABC)
+ var x2 = xcoord(A), y2 = ycoord(A)
+ var m5 = 12 rem 3 % remainder after dividing by 3
+ var r1 = direction(PQ) % in radians
+ var d1 = directiondeg(PQ)
+
+==============================
+.SH SEE ALSO
+The mathsPIC package manual and examples
+.SH BUGS
+Please report bugs to Dick Nickalls (dick [AT] nickalls [dot] org) or to Apostolos Syropoulos
+
diff --git a/graphics/mathspic/perl/mathspic.lib b/graphics/mathspic/perl/mathspic.lib
new file mode 100644
index 0000000000..97c26f3f18
--- /dev/null
+++ b/graphics/mathspic/perl/mathspic.lib
@@ -0,0 +1,13 @@
+%%--- mathspic.lib---
+%% RWD Nickalls & A Syropoulos
+%% April 2010
+%%----------------------
+%% example mathsPIC macros
+%def bigdots()\setplotsymbol({\large .})\setdots%
+%def normaldots()\setplotsymbol({\tiny .})\setdots%
+%def log10(a)log(a)/log(10)%
+%def loge(a)log(a)%
+%def mod(a)rem(a)%
+%def d2r() _pi_/180%
+%def r2d() 180/_pi_%
+%%---end of library---
diff --git a/graphics/mathspic/perl/mathspic.sh b/graphics/mathspic/perl/mathspic.sh
new file mode 100644
index 0000000000..f0d0d76fc1
--- /dev/null
+++ b/graphics/mathspic/perl/mathspic.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+## April 26, 2010
+## RWD Nickalls & A Syropoulos
+## mathspic.sh # mathspic script
+## put this file in /usr/local/bin
+## rename it: mathspic.sh --> mathspic
+## and make it executable (chmod 755 mathspic)
+#################
+## format is:
+## bash mathspic.sh <options> filename
+## mathspic [-b] [-c] [-h] [-o outfile] infile
+#################
+
+perl /usr/local/bin/mathspic113.pl $1 $2 $3 $4 $5
diff --git a/graphics/mathspic/perl/mathspic.sty b/graphics/mathspic/perl/mathspic.sty
new file mode 100644
index 0000000000..4ba85b3376
--- /dev/null
+++ b/graphics/mathspic/perl/mathspic.sty
@@ -0,0 +1,41 @@
+%%
+%% This is file `mathspic.sty',
+%% April 26, 2010
+%%
+%% (c) copyright 2004-2010 A Syropoulos & RWD Nickalls
+%% This program can be redistributed and/or modified under the terms
+%% of the LaTeX Project Public License Distributed from CTAN
+%% archives in directory macros/latex/base/lppl.txt; either
+%% version 1 of the License, or any later version.
+%%
+%% Please report errors or suggestions for improvement to
+%%
+%% Apostolos Syropoulos Dick Nickalls
+%% apostolo@yahoo.com dick@nickalls.org
+%%
+\wlog{Package `mathspic' A Syropoulos & RWD Nickalls (April 2010)}%
+\typeout{Loading mathsPIC package (c) RWD Nickalls & A Syropoulos April 2010}%
+\ProvidesFile{mathspic.sty}%
+ [2010/04/26 v1.13 Package `mathspic.sty']%
+\def\fileversion{1.13}
+\def\filedate{2010/04/26}
+\ifx\fiverm\undefined
+ \newfont\fiverm{cmr5}
+\fi
+\let\Linethickness\linethickness%
+%%----------mathsPIC logos---------------------
+\newcommand{\mathsPIC}{\textsf{mathsPIC}}
+\newcommand{\MathsPIC}{\textsf{MathsPIC}}
+\newcommand{\mathsPICp}{\textsf{mathsPIC}\kern-0.08em\raisebox{-0.15em}{\textit{\tiny P}}}
+\newcommand{\MathsPICp}{\textsf{MathsPIC}\kern-0.08em\raisebox{-0.15em}{\textit{\tiny P}}}
+\newcommand{\mathsPICperl}{\textsf{mathsPIC}\kern-0.08em\raisebox{-0.15em}{\textit{\tiny Perl}}}
+\newcommand{\MathsPICperl}{\textsf{MathsPIC}\kern-0.08em\raisebox{-0.15em}{\textit{\tiny Perl}}}
+%%-----------PICTEX stuff-----------------------------
+\input prepictex
+\input pictexwd
+\input postpictex
+%%-------------------------------------
+\thispagestyle{empty}% stop page numbers
+\endinput
+%%
+%% End of file `mathspic.sty'.
diff --git a/graphics/mathspic/perl/mathspic113.pl b/graphics/mathspic/perl/mathspic113.pl
new file mode 100644
index 0000000000..5c3ed4ec1f
--- /dev/null
+++ b/graphics/mathspic/perl/mathspic113.pl
@@ -0,0 +1,3336 @@
+#!/usr/bin/perl
+#
+#(c) Copyright 2005-2010 VERSION 1.13 April 26, 2010
+# Apostolos Syropoulos & R.W.D. Nickalls
+# asyropoulos@yahoo.com dick@nickalls.org
+#
+# This program can be redistributed and/or modified under the terms
+# of the LaTeX Project Public License Distributed from CTAN
+# archives in directory macros/latex/base/lppl.txt; either
+# version 1 of the License, or any later version.
+#
+package DummyFH;
+my $index = 0;
+sub TIEHANDLE {
+ my $class = shift;
+ my $self= shift;
+ bless $self, $class;
+}
+sub READLINE {
+ my $self = shift;
+ #shift @$self;
+ if ($index > $#$self) {
+ $index = 0;
+ return undef;
+ }
+ else {
+ return $self->[$index++];
+ }
+}
+
+package main;
+use Math::Trig;
+our $version_number = "1.13 Apr 26, 2010";
+our $commandLineArgs = join(" ", @ARGV);
+our $command = "";
+our $curr_in_file = "";
+our %PointTable = ();
+our %VarTable = ();
+our %ConstTable = ();
+our $no_errors = 0;
+our $xunits = "1pt";
+our $yunits = "1pt";
+our $units = "pt|pc|in|bp|cm|mm|dd|cc|sp";
+our $defaultsymbol = "\$\\bullet\$";
+our $defaultLFradius = 0;
+use constant PI => atan2(1,1)*4;
+use constant R2D => 180 / PI;
+use constant D2R => PI / 180;
+our $arrowLength = 2;
+our $arrowLengthUnits = "mm";
+our $arrowAngleB = 30;
+our $arrowAngleC = 40;
+our %DimOfPoint = ();
+our $GlobalDimOfPoints = 0;
+our @Macros = ();
+our $LineThickness = 0.4;
+
+ sub mpp {
+ my $in_line;
+ chomp($in_line = shift);
+ my $LC = shift;
+ my $out_line = $in_line;
+ my $macro_name = "";
+ my @macro_param = ();
+ my $macro_code = "";
+ if ($in_line =~ s/^%def\s*//) {
+ if ($in_line =~ s/^(\w+)\s*//){
+ $macro_name = $1;
+ }
+ else {
+ PrintErrorMessage("No macro name has been found",$LC);
+ return ""
+ }
+ if ($in_line =~ s/^\(\s*//) {
+ # do nothing
+ }
+ else {
+ PrintErrorMessage("No left parenthesis after macro name has been found",$LC);
+ return "";
+ }
+ if ($in_line =~ s/^\)//) {
+ # Macro has no parameters!
+ }
+ else {
+ MACROS: while (1) {
+ if ($in_line =~ s/^(\w+)\s*//) {
+ push (@macro_param, $1);
+ }
+ else {
+ PrintErrorMessage("No macro parameter name has been found",$LC);
+ return "";
+ }
+ if ($in_line =~ s/^,\s*//) {
+ next MACROS;
+ }
+ else {
+ last MACROS;
+ }
+ }
+ if ($in_line =~ s/^\)//) {
+ # do nothing!
+ }
+ else {
+ PrintErrorMessage("No closing parenthesis after macro parameters",$LC);
+ return "";
+ }
+ }
+ $in_line =~ s/([^%]+)(%.*)/$1/;
+ $macro_code = $in_line;
+ push ( @Macros , { 'macro_name' => $macro_name,
+ 'macro_code' => $macro_code,
+ 'macro_param' => \@macro_param });
+ return $out_line;
+ }
+ elsif ($in_line =~ s/^%undef\s*//) {
+ if ($in_line =~ s/^(\w+)//) {
+ my $undef_macro = $1;
+ for(my $i = $#Macros; $i >= 0; $i--) {
+ if ($Macros[$i]->{'macro_name'} eq $undef_macro) {
+ splice(@Macros,$i,1);
+ }
+ }
+ }
+ return $out_line;
+ }
+ elsif ($in_line =~ s/^\s*%//) {
+ return $out_line;
+ }
+ else {
+ my $comment = $2 if $in_line =~ s/([^%]+)(%.+)/$1/;
+ EXPANSIONLOOP: while () {
+ my $org_in_line = $in_line;
+ for(my $i = $#Macros; $i >= 0; $i--) {
+ my $macro_name = $Macros[$i]->{'macro_name'};
+ if ($in_line =~ /&$macro_name\b/) { ############################
+ my $num_of_macro_args = @{$Macros[$i]->{'macro_param'}};
+ if ( $num_of_macro_args > 0 ) {
+ # Macro with parameters
+ my $pattern = "&$macro_name\\(";
+ foreach my $p ( 1..$num_of_macro_args ) {
+ my $comma = ($p == $num_of_macro_args) ? "\\s*" : "\\s*,\\s*";
+ $pattern .= "\\s*[^\\s\\)]+$comma";
+ }
+ $pattern .= "\\)";
+ while($in_line =~ /&$macro_name\b/) {
+ if ($in_line =~ /$pattern/) {
+ my $before = $`;
+ my $after = $';
+ my $match = $&;
+ my $new_code = $Macros[$i]->{'macro_code'};
+ $match =~ s/^&$macro_name\(\s*//;
+ $match =~ s/\)$//;
+ foreach my $arg ( 0..($num_of_macro_args - 1) ) {
+ my $old = $Macros[$i]->{'macro_param'}->[$arg];
+ my $comma = ($arg == ($num_of_macro_args - 1)) ? "" : ",";
+ $match =~ s/^\s*([^\s,]+)\s*$comma//;
+ my $new = $1;
+ # 'g': Parameter may occur several times
+ # in $new_code.
+ # '\b': Substitute only whole words
+ # not x in xA
+ $new_code =~ s/\b$old\b/$new/g;
+ }
+ $in_line = "$before$new_code$after";
+ }
+ else {
+ PrintErrorMessage("Usage of macro &$macro_name does not " .
+ "match its definition", $LC);
+ return "";
+ }
+ }
+ }
+ else {
+ # Macro without parameters
+ my $replacement = $Macros[$i]->{'macro_code'};
+ # '\b': Substitute only whole words
+ # not x in xA
+ $in_line =~ s/&$macro_name\b/$replacement/g;
+ }
+ }
+ }
+ last EXPANSIONLOOP if ( $org_in_line eq $in_line );
+ }
+ return "$in_line$comment";
+ }
+ }
+
+ sub PrintErrorMessage {
+ my $errormessage = shift;
+ my $error_line = shift;
+ my ($l,$A);
+ $l = 1+length($command)-length;
+ $A = substr($command,0,$l);
+ $l += 7 +length($error_line);
+
+ for my $fh (STDOUT, LOG) {
+ print $fh "$curr_in_file", "Line $error_line: $A\n";
+ print $fh " " x $l ,$_,"***Error: $errormessage\n";
+ }
+ if ($comments_on) { #print to output file file
+ print OUT "%% *** $curr_in_file", "Line $error_line: $A\n";
+ print OUT "%% *** "," " x $l ,$_,"%% ... Error: $errormessage\n";
+ }
+ $no_errors++;
+ }
+
+ sub PrintWarningMessage {
+ my $warningMessage = shift;
+ my $warning_line = shift;
+ my ($l,$A);
+ $l = 1+length($command)-length;
+ $A = substr($command,0,$l);
+ $l += 7 +length($warning_line);
+
+ for my $fh (STDOUT, LOG) {
+ print $fh "$curr_in_file", "Line $warning_line: $A\n";
+ print $fh " " x $l ,$_,"***Warning: $warningMessage\n";
+ }
+ if ($comments_on) { #print to output file file
+ print OUT "%% *** $curr_in_file", "Line $warning_line: $A\n";
+ print OUT "%% *** "," " x $l ,$_,"%% ... Warning: $warningMessage\n";
+ }
+ }
+
+ sub PrintFatalError {
+ my $FatalMessage = shift;
+ my $fatal_line = shift;
+ my ($l,$A);
+ $l = 1+length($command)-length;
+ $A = substr($command,0,$l);
+ $l += 7 +length($fatal_line);
+
+ die "$curr_in_file", "Line $fatal_line: $A\n" .
+ (" " x $l) . $_ . "***Fatal Error: $FatalMessage\n";
+ }
+
+ sub chk_lparen {
+ my $token = $_[0];
+ my $lc = $_[1];
+ s/\s*//;
+ if (/^[^\(]/) {
+ PrintErrorMessage("Missing ( after $token",$lc);
+ }
+ else {
+ s/^\(\s*//;
+ }
+ }
+
+ sub chk_rparen {
+ my $token = $_[0];
+ my $lc = $_[1];
+ s/\s*//;
+ if (s/^\)//) {
+ s/\s*//;
+ }
+ else {
+ PrintErrorMessage("Missing ) after $token",$lc);
+ }
+ }
+
+
+ sub chk_lcb {
+ my $token = $_[0];
+ my $lc = $_[1];
+ s/\s*//;
+ if ($_ !~ /^\{/) {
+ PrintErrorMessage("Missing { after $token",$lc);
+ }
+ else {
+ s/^{\s*//;
+ }
+ }
+
+ sub chk_rcb {
+ my $token = $_[0];
+ my $lc = $_[1];
+ if ($_ !~ /^\s*\}/) {
+ PrintErrorMessage("Missing } after $token",$lc);
+ }
+ else {
+ s/^\s*}\s*//;
+ }
+ }
+
+ sub chk_lsb {
+ my $token = $_[0];
+ my $lc = $_[1];
+
+ s/\s*//;
+ if ($_ !~ /^\[/) {
+ PrintErrorMessage("Missing [ after $token",$lc);
+ }
+ else {
+ s/^\[\s*//;
+ }
+ }
+
+ sub chk_rsb {
+ my $token = $_[0];
+ my $lc = $_[1];
+
+ s/\s*//;
+ if ($_ !~ /^\]/) {
+ PrintErrorMessage("Missing ] after $token",$lc);
+ }
+ else {
+ s/^\]\s*//;
+ }
+ }
+
+ sub chk_comma {
+ my $lc = $_[0];
+
+ s/\s*//;
+ if (/^[^,]/) {
+ PrintErrorMessage("Did not find expected comma",$lc);
+ }
+ else {
+ s/^,\s*//;
+ }
+ }
+
+ sub chk_comment {
+ my $lc = $_[0];
+
+ s/\s*//;
+ if (/^%/) {
+ # do nothing!
+ }
+ elsif (/^[^%]/) {
+ PrintWarningMessage("Trailing text is ignored",$lc);
+ }
+ }
+
+ sub print_headers
+ {
+ my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
+ $year+=1900;
+ $mon+=1;
+ $now_string = "$year/" . ($mon>9 ? "$mon/" : "0$mon/") .
+ ($mday>9 ? "$mday " : "0$mday ") .
+ ($hour>9 ? "$hour:" : "0$hour:") .
+ ($min>9 ? "$min:" : "0$min:") .
+ ($sec>9 ? "$sec" : "0$sec");
+ print OUT "%* -----------------------------------------------\n";
+ print OUT "%* mathspic (Perl version $version_number)\n";
+ print OUT "%* A filter program for use with PiCTeX\n";
+ print OUT "%* Copyright (c) 2005-2010 A Syropoulos & RWD Nickalls \n";
+ print OUT "%* Command line: $0 $commandLineArgs\n";
+ print OUT "%* Input filename : $source_file\n";
+ print OUT "%* Output filename: $out_file\n";
+ print OUT "%* Date & time: $now_string\n";
+ print OUT "%* -----------------------------------------------\n";
+ #
+ print LOG "----\n";
+ print LOG "$now_string\n";
+ print LOG "mathspic (Perl version $version_number)\n";
+ print LOG "Copyright (c) 2005-2010 A Syropoulos & RWD Nickalls \n";
+ print LOG "Input file = $source_file\n";
+ print LOG "Output file = $out_file\n";
+ print LOG "Log file = $log_file\n";
+ print LOG "----\n";
+ }
+
+ sub get_point {
+
+ my ($lc) = $_[0];
+ my ($PointName);
+
+ if (s/^([^\W\d_]\d{0,4})\s*//i) { #point name
+ $PointName = $1;
+ if (!exists($PointTable{lc($PointName)})) {
+ PrintErrorMessage("Undefined point $PointName",$lc);
+ return "_undef_";
+ }
+ else {
+ return lc($PointName);
+ }
+ }
+ else {
+ PrintErrorMessage("Point name expected",$lc);
+ return "_undef_";
+ }
+ }
+
+ sub perpendicular {
+ my ($xP, $yP, $xA, $yA, $xB, $yB) = @_;
+ my ($xF, $yF, $deltax, $deltay, $m1, $m2, $c1, $c2, $factor);
+
+ $deltax = $xA - $xB;
+ return ($xA, $yP) if abs($deltax) < 0.0000001;
+ $deltay = $yA - $yB;
+ return ($xP, $yA) if abs($deltay) < 0.0000001;
+ $m1 = $deltay / $deltax;
+ eval { $m2 = (-1) / $m1;};
+ PrintFatalError("Division by zero",$lc) if $@;
+ $c1 = $yA - $m1 * $xA;
+ $c2 = $yP - $m2 * $xP;
+ eval { $factor = 1 / ($m1 - $m2)};
+ PrintFatalError("Division by zero",$lc) if $@;
+ return (($c2 - $c1) * $factor, ($m1 * $c2 - $m2 * $c1) * $factor);
+ }
+
+ sub Length {
+ my ($xA, $yA, $xB, $yB)=@_;
+ return sqrt(($xB - $xA)**2 + ($yB - $yA)**2);
+ }
+
+ sub triangleArea {
+ my ($xA, $yA, $xB, $yB, $xC, $yC)=@_;
+ my ($lenAB, $lenBC, $lenCA, $s);
+
+ $lenAB = Length($xA,$yA,$xB,$yB);
+ $lenBC = Length($xB,$yB,$xC,$yC);
+ $lenCA = Length($xC,$yC,$xA,$yA);
+ $s = ($lenAB + $lenBC + $lenCA) / 2;
+ return sqrt($s * ($s - $lenAB)*($s - $lenBC)*($s - $lenCA));
+ }
+
+ sub pointOnLine {
+ my ($xA, $yA, $xB, $yB, $dist)=@_;
+ my ($deltax, $deltay, $xPol, $yPol);
+
+ $deltax = $xB - $xA;
+ $deltay = $yB - $yA;
+ $xPol = $xA + ($dist * $deltax / &Length($xA,$yA,$xB,$yB));
+ $yPol = $yA + ($dist * $deltay / &Length($xA,$yA,$xB,$yB));
+ return ($xPol, $yPol);
+ }
+
+
+
+ sub circumCircleCenter {
+ my ($xA, $yA, $xB, $yB, $xC, $yC, $lc)=@_;
+ my ($deltay12, $deltax12, $xs12, $ys12);
+ my ($deltay23, $deltax23, $xs23, $ys23);
+ my ($xcc, $ycc);
+ my ($m23, $mr23, $c23, $m12, $mr12, $c12);
+ my ($sideA, $sideB, $sideC, $a, $radius);
+
+ if (abs(triangleArea($xA, $yA, $xB, $yB, $xC, $yC)) < 0.0000001)
+ {
+ PrintErrorMessage("Area of triangle is zero!",$lc);
+ return (0,0,0);
+ }
+ $deltay12 = $yB - $yA;
+ $deltax12 = $xB - $xA;
+ $xs12 = $xA + $deltax12 / 2;
+ $ys12 = $yA + $deltay12 / 2;
+ #
+ $deltay23 = $yC - $yB;
+ $deltax23 = $xC - $xB;
+ $xs23 = $xB + $deltax23 / 2;
+ $ys23 = $yB + $deltay23 / 2;
+ #
+ CCXYLINE:{
+ if (abs($deltay12) < 0.0000001)
+ {
+ $xcc = $xs12;
+ if (abs($deltax23) < 0.0000001)
+ {
+ $ycc = $ys23;
+ last CCXYLINE;
+ }
+ else
+ {
+ $m23 = $deltay23 / $deltax23;
+ $mr23 = -1 / $m23;
+ $c23 = $ys23 - $mr23 * $xs23;
+ $ycc = $mr23 * $xs12 + $c23;
+ last CCXYLINE;
+ }
+ }
+ if (abs($deltax12) < 0.0000001)
+ {
+ $ycc = $ys12;
+ if (abs($deltay23) < 0.0000001)
+ {
+ $xcc = $xs23;
+ last CCXYLINE;
+ }
+ else
+ {
+ $m23 = $deltay23 / $deltax23;
+ $mr23 = -1 / $m23;
+ $c23 = $ys23 - $mr23 * $xs23;
+ $xcc = ($ys12 - $c23) / $mr23;
+ last CCXYLINE;
+ }
+ }
+ if (abs($deltay23) < 0.0000001)
+ {
+ $xcc = $xs23;
+ if (abs($deltax12) < 0.0000001)
+ {
+ $ycc = $ys12;
+ last CCXYLINE;
+ }
+ else
+ {
+ $m12 = $deltay12 / $deltax12;
+ $mr12 = -1 / $m12;
+ $c12 = $ys12 - $mr12 * $xs12;
+ $ycc = $mr12 * $xcc + $c12;
+ last CCXYLINE;
+ }
+ }
+ if (abs($deltax23) < 0.0000001)
+ {
+ $ycc = $ys23;
+ if (abs($deltay12) < 0.0000001)
+ {
+ $xcc = $xs12;
+ last CCXYLINE;
+ }
+ else
+ {
+ $m12 = $deltay12 / $deltax12;
+ $mr12 = -1 / $m12;
+ $c12 = $ys12 - $mr12 * $xs12;
+ $xcc = ($ycc - $c12) / $mr12;
+ last CCXYLINE;
+ }
+ }
+ $m12 = $deltay12 / $deltax12;
+ $mr12 = -1 / $m12;
+ $c12 = $ys12 - $mr12 * $xs12;
+ #-----
+ $m23 = $deltay23 / $deltax23;
+ $mr23 = -1 / $m23;
+ $c23 = $ys23 - $mr23 * $xs23;
+ $xcc = ($c23 - $c12) / ($mr12 - $mr23);
+ $ycc = ($c23 * $mr12 - $c12 * $mr23) / ($mr12 - $mr23);
+ }
+ #
+ $sideA = &Length($xA,$yA,$xB,$yB);
+ $sideB = &Length($xB,$yB,$xC,$yC);
+ $sideC = &Length($xC,$yC,$xA,$yA);
+ $a = triangleArea($xA, $yA, $xB, $yB, $xC, $yC);
+ $radius = ($sideA * $sideB * $sideC) / (4 * $a);
+ #
+ return ($xcc, $ycc, $radius);
+ }
+
+ sub ComputeDist {
+ my ($lc) = $_[0];
+ my ($v1, $v2);
+
+ if (s/^((\+|-)?\d+(\.\d+)?([eE](\+|-)?\d+)?)//) #is it a number?
+ {
+ return ($1, 1);
+ }
+ elsif (/^[^\W\d_]\d{0,4}[^\W\d_]\d{0,4}/) #it is a pair of IDs?
+ {
+ s/^([^\W\d_]\d{0,4})//i;
+ $v1 = $1;
+ if (!exists($PointTable{lc($v1)})) {
+ if (exists($VarTable{lc($v1)})) {
+ return ($VarTable{lc($v1)}, 1);
+ }
+ PrintErrorMessage("Point $v1 has not been defined", $lc);
+ s/^\s*[^\W\d_]\d{0,4}//i;
+ return (0,0);
+ }
+ $v1 = lc($v1);
+ s/^\s*([^\W\d_]\d{0,4})//i;
+ $v2 = $1;
+ if (!exists($PointTable{lc($v2)}))
+ {
+ PrintErrorMessage("Point $v2 has not been defined", $lc);
+ return (0,0);
+ }
+ $v2 = lc($v2);
+ my ($x1,$y1,$pSV1,$pS1) = unpack("d3A*",$PointTable{$v1});
+ my ($x2,$y2,$pSV2,$pS2) = unpack("d3A*",$PointTable{$v2});
+ return (Length($x1,$y1,$x2,$y2), 1);
+ }
+ elsif (s/^([^\W\d_]\d{0,4})//i) # it is a single id
+ {
+ $v1 = $1;
+ if (!exists($VarTable{lc($v1)})) #it isn't a variable
+ {
+ PrintErrorMessage("Variable $v1 has not been defined", $lc);
+ return (0,0);
+ }
+ return ($VarTable{lc($v1)}, 1);
+ }
+ else
+ {
+ PrintErrorMessage("Unexpected token", $lc);
+ return (0,0);
+ }
+ }
+
+ sub intersection4points {
+ my ($x1, $y1, $x2, $y2, $x3, $y3, $x4, $y4) = @_;
+ my ($deltay12, $deltax12, $deltay34, $deltax34);
+ my ($xcc, $ycc, $m34, $c34, $m12, $c12);
+
+ $deltay12 = $y2 - $y1;
+ $deltax12 = $x2 - $x1;
+ #
+ $deltay34 = $y4 - $y3;
+ $deltax34 = $x4 - $x3;
+ I4PXYLINE:{
+ if (abs($deltay12) < 0.0000001)
+ {
+ $ycc = $y1;
+ if (abs($deltax34) < 0.0000001)
+ {
+ $xcc = $x3;
+ last I4PXYLINE;
+ }
+ else
+ {
+ $m34 = $deltay34 / $deltax34;
+ $c34 = $y3 - $m34 * $x3;
+ $xcc = ($ycc - $c34) / $m34;
+ last I4PXYLINE;
+ }
+ }
+ if (abs($deltax12) < 0.0000001)
+ {
+ $xcc = $x1;
+ if (abs($deltay34) < 0.0000001)
+ {
+ $ycc = $y3;
+ last I4PXYLINE;
+ }
+ else
+ {
+ $m34 = $deltay34 / $deltax34;
+ $c34 = $y3 - $m34 * $x3;
+ $ycc = $m34 * $xcc + $c34;
+ last I4PXYLINE;
+ }
+ }
+ if (abs($deltay34) < 0.0000001)
+ {
+ $ycc = $y3;
+ if (abs($deltax12) < 0.0000001)
+ {
+ $xcc = $x1;
+ last I4PXYLINE;
+ }
+ else
+ {
+ $m12 = $deltay12 / $deltax12;
+ $c12 = $y1 - $m12 * $x1;
+ $xcc = ($ycc - $c12) / $m12;
+ last I4PXYLINE;
+ }
+ }
+ if (abs($deltax34) < 0.0000001)
+ {
+ $xcc = $x3;
+ if (abs($deltay12) < 0.0000001)
+ {
+ $ycc = $y1;
+ last I4PXYLINE;
+ }
+ else
+ {
+ $m12 = $deltay12 / $deltax12;
+ $c12 = $y1 - $m12 * $x1;
+ $ycc = $m12 * $xcc + $c12;
+ last I4PXYLINE;
+ }
+ }
+ $m12 = $deltay12 / $deltax12;
+ $c12 = $y1 - $m12 * $x1;
+ $m34 = $deltay34 / $deltax34;
+ $c34 = $y3 - $m34 * $x3;
+ $xcc = ($c34 - $c12) / ($m12 - $m34);
+ $ycc = ($c34 * $m12 - $c12 * $m34) / ($m12 - $m34);
+ }
+ return ($xcc, $ycc);
+ }
+
+ sub IncircleCenter {
+ my ($Ax, $Ay, $Bx, $By, $Cx, $Cy) = @_;
+ my ($sideA, $sideB, $sideC);
+ my ($ba1, $xA1, $yA1, $cb1, $ac1, $xB1, $yB1, $xC1, $yC1, $a, $s, $r);
+
+ #determine the lengths of the sides
+ $sideA = Length($Bx, $By, $Cx, $Cy);
+ $sideB = Length($Cx, $Cy, $Ax, $Ay);
+ $sideC = Length($Ax, $Ay, $Bx, $By);
+ #
+ $ba1 = ($sideC * $sideA) / ($sideB + $sideC);
+ ($xA1, $yA1) = pointOnLine($Bx, $By, $Cx, $Cy, $ba1);
+ $cb1 = ($sideA * $sideB) / ($sideC + $sideA);
+ ($xB1, $yB1) = pointOnLine($Cx, $Cy, $Ax, $Ay, $cb1);
+ $ac1 = ($sideB * $sideC) / ($sideA + $sideB);
+ ($xC1, $yC1) = pointOnLine($Ax, $Ay, $Bx, $By, $ac1);
+ ($xcenter, $ycenter) = &intersection4points($Ax, $Ay, $xA1, $yA1,
+ $Bx, $By, $xB1, $yB1);
+ # get radius
+ $a = &triangleArea($Ax, $Ay, $Bx, $By, $Cx, $Cy);
+ $s = ($sideA + $sideB +$sideC) / 2;
+ $r = $a / $s;
+ return ($xcenter, $ycenter, $r);
+ }
+
+ sub Angle {
+ my ($Ax, $Ay, $Bx, $By, $Cx, $Cy) = @_;
+ my ($RAx, $RAy, $RBx, $RBy, $RCx, $RCy, $deltax, $deltay);
+ my ($lineBA, $lineBC, $lineAC, $k, $kk, $angle);
+ my ($T, $cosT, $sinT) = (0.3, cos(0.3), sin(0.3));
+
+ $RAx = $Ax * $cosT + $Ay * $sinT;
+ $RAy = -$Ax * $sinT + $Ay * $cosT;
+ $RBx = $Bx * $cosT + $By * $sinT;
+ $RBy = -$Bx * $sinT + $By * $cosT;
+ $RCx = $Cx * $cosT + $Cy * $sinT;
+ $RCy = -$Cx * $sinT + $Cy * $cosT;
+ $deltax = $RBx - $RAx;
+ $deltay = $RBy - $RAy;
+ $lineBA = sqrt($deltax*$deltax + $deltay*$deltay);
+ if ($lineBA < 0.0000001)
+ {
+ return -500;
+ }
+ $deltax = $RBx - $RCx;
+ $deltay = $RBy - $RCy;
+ $lineBC = sqrt($deltax*$deltax + $deltay*$deltay);
+ if ($lineBC < 0.0000001)
+ {
+ return -500;
+ }
+ $deltax = $RAx - $RCx;
+ $deltay = $RAy - $RCy;
+ $lineAC = sqrt($deltax*$deltax + $deltay*$deltay);
+ if ($lineAC < 0.0000001)
+ {
+ return -500;
+ }
+ $k = ($lineBA*$lineBA + $lineBC*$lineBC - $lineAC*$lineAC ) /
+ (2 * $lineBA * $lineBC);
+ $k = -1 if $k < -0.99999;
+ $k = 1 if $k > 0.99999;
+ $kk = $k * $k;
+ if (($kk * $kk) == 1)
+ {
+ $angle = PI if $k == -1;
+ $angle = 0 if $k == 1;
+ }
+ else
+ {
+ $angle = (PI / 2) - atan2($k / sqrt(1 - $kk),1);
+ }
+ return $angle * 180 / PI;
+ }
+
+ sub excircle {
+ my ($A, $B, $C, $D, $E) = @_;
+ my ($Ax,$Ay,$Bx,$By,$Dx,$Dy,$Ex,$Ey,$ASVA,$ASA);
+ ($Ax,$Ay,$ASVA,$ASA)=unpack("d3A*",$PointTable{$A});
+ ($Bx,$By,$ASVA,$ASA)=unpack("d3A*",$PointTable{$B});
+ ($Cx,$Cy,$ASVA,$ASA)=unpack("d3A*",$PointTable{$C});
+ ($Dx,$Dy,$ASVA,$ASA)=unpack("d3A*",$PointTable{$D});
+ ($Ex,$Ey,$ASVA,$ASA)=unpack("d3A*",$PointTable{$E});
+ my ($sideA, $sideB, $sideC, $s, $R, $theAdeg, $d);
+ my ($Xmypoint, $Ymypoint, $deltax, $deltay, $mylength, $xc, $yc);
+
+ $sideA = &Length($Bx, $By, $Cx, $Cy);
+ $sideB = &Length($Cx, $Cy, $Ax, $Ay);
+ $sideC = &Length($Ax, $Ay, $Bx, $By);
+ $s = ($sideA + $sideB + $sideC) / 2;
+ $R = triangleArea($Ax, $Ay, $Bx, $By, $Cx, $Cy) /
+ ($s - &Length($Dx, $Dy, $Ex, $Ey));
+ if (($D eq $A && $E eq $B) || ($D eq $B && $E eq $A))
+ {
+ $theAdeg = &Angle($Bx, $By, $Cx, $Cy, $Ax, $Ay);
+ $Xmypoint = $Cx;
+ $Ymypoint = $Cy;
+ }
+ elsif (($D eq $B && $E eq $C) || ($D eq $C && $E eq $B))
+ {
+ $theAdeg = &Angle($Cx, $Cy, $Ax, $Ay, $Bx, $By);
+ $Xmypoint = $Ax;
+ $Ymypoint = $Ay;
+ }
+ elsif (($D eq $C && $E eq $A) || ($D eq $A && $E eq $C))
+ {
+ $theAdeg = &Angle($Ax, $Ay, $Bx, $By, $Cx, $Cy);
+ $Xmypoint = $Bx;
+ $Ymypoint = $By;
+ }
+ else
+ {
+ return (0,0,0);
+ }
+ $d = $R / sin($theAdeg * PI / 180 / 2);
+ my ($xIn, $yIn, $rin) = &IncircleCenter($Ax, $Ay, $Bx, $By, $Cx, $Cy);
+ $deltax = $xIn - $Xmypoint;
+ $deltay = $yIn - $Ymypoint;
+ $mylength = sqrt($deltax*$deltax + $deltay*$deltay);
+ $xc = $Xmypoint + $d * $deltax / $mylength;
+ $yc = $Ymypoint + $d * $deltay / $mylength;
+ return ($xc, $yc, $R);
+ }
+
+ sub DrawLineOrArrow {
+ my $draw_Line = shift;
+ my $lc = shift;
+ my $lineLength = -1;
+ my $stacklen = 0;
+ my @PP = ();
+ # if ($draw_Line != 2) {
+ # s/\s*//;
+ # if (s/^\[\s*//) { # optional length specifier
+ # $lineLength = expr($lc);
+ # if ($lineLength <= 0) {
+ # PrintErrorMessage("length must greater than zero",$lc);
+ # $lineLength = -1;
+ # }
+ # chk_rsb("optional part",$lc);
+ # }
+ # }
+ chk_lparen("$cmd",$lc);
+ DRAWLINES:while(1) {
+ @PP = () ;
+ while(1) {
+ if (s/^([^\W\d_]\d{0,4})\s*//i) { #point name
+ $P = $1;
+ if (!exists($PointTable{lc($P)})) {
+ PrintErrorMessage("Undefined point $P",$lc);
+ }
+ else {
+ push (@PP,$P);
+ }
+ }
+ else {
+ $stacklen = @PP;
+ if ($draw_Line != 2) {
+ if ($stacklen <= 1) {
+ PrintErrorMessage("Wrong number of points",$lc);
+ }
+ else {
+ push(@PP,$lc);
+ if ($draw_Line == 0) {
+ drawarrows(@PP);
+ }
+ elsif ($draw_Line == 1) {
+ drawlines(@PP);
+ }
+ }
+ }
+ if (s/^,\s*// and $draw_Line != 2) {
+ next DRAWLINES;
+ }
+ else {
+ last DRAWLINES;
+ }
+ }
+ }
+ }
+ if ($draw_Line == 2) {
+ $stacklen = @PP;
+ if ($stacklen < 2) {
+ PrintErrorMessage("Wrong number of points",$lc);
+ }
+ elsif ($stacklen % 2 == 0) {
+ PrintErrorMessage("Number of points must be odd",$lc);
+ }
+ else {
+ drawCurve(@PP);
+ }
+ }
+ chk_rparen("arguments of $cmd",$lc);
+ chk_comment($lc);
+ }
+
+ sub drawarrows {
+ my ($NoArgs);
+ $NoArgs = @_;
+ my ($lc) = $_[$NoArgs-1]; #line number is the last argument
+ my ($NumberOfPoints, $p, $q, $r12, $d12);
+ my ($px,$py,$pSV,$pS, $qx,$qy,$qSV,$qS);
+
+ $NumberOfPoints = $NoArgs - 1;
+ LOOP: for(my $i=0; $i < $NumberOfPoints - 1; $i++)
+ {
+ $p = $_[$i];
+ $q = $_[$i+1];
+ ($px,$py,$pSV,$pS) = unpack("d3A*",$PointTable{lc($p)});
+ ($qx,$qy,$qSV,$qS) = unpack("d3A*",$PointTable{lc($q)});
+ $pSV = $defaultLFradius if $pSV == 0;
+ $qSV = $defaultLFradius if $qSV == 0;
+ $r12 = $pSV + $qSV;
+ $d12 = Length($px,$py,$qx,$qy);
+ if ($d12 <= $r12)
+ {
+ if($d12 == 0)
+ {
+ PrintErrorMessage("points $p and $q are the same", $lc);
+ next LOOP;
+ }
+ PrintWarningMessage("arrow $p$q not drawn: points too close or ".
+ "radii too big", $lc);
+ next LOOP;
+ }
+ ($px, $py) = pointOnLine($px, $py, $qx, $qy, $pSV) if $pSV > 0;
+ ($qx, $qy) = pointOnLine($qx, $qy, $px, $py, $qSV) if $qSV > 0;
+ my ($beta, $gamma);
+ $beta = tan($arrowAngleB * D2R / 2);
+ $gamma = 2 * tan($arrowAngleC * D2R / 2);
+ printf OUT "\\arrow <%.5f%s> [%.5f,%.5f] from %.5f %.5f to %.5f %.5f\n",
+ $arrowLength, $arrowLengthUnits, $beta, $gamma, $px, $py, $qx, $qy;
+ }
+ }
+
+ sub drawlines {
+ my ($NoArgs);
+ $NoArgs = @_;
+ my ($lc) = $_[$NoArgs-1]; #line number is the last argument
+ my ($NumberOfPoints, $p, $q, $r12, $d12);
+ my ($px,$py,$pSV,$pS, $qx,$qy,$qSV,$qS);
+
+ $NumberOfPoints = $NoArgs - 1;
+ LOOP: for(my $i=0; $i < $NumberOfPoints - 1; $i++)
+ {
+ $p = $_[$i];
+ $q = $_[$i+1];
+ ($px,$py,$pSV,$pS) = unpack("d3A*",$PointTable{lc($p)});
+ ($qx,$qy,$qSV,$qS) = unpack("d3A*",$PointTable{lc($q)});
+ $pSV = $defaultLFradius if $pSV == 0;
+ $qSV = $defaultLFradius if $qSV == 0;
+ $r12 = $pSV + $qSV;
+ $d12 = Length($px,$py,$qx,$qy);
+ if ($d12 <= $r12)
+ {
+ if($d12 == 0)
+ {
+ PrintErrorMessage("points $p and $q are the same", $lc);
+ next LOOP;
+ }
+ PrintWarningMessage("line $p$q not drawn: points too close or ".
+ "radii too big", $lc);
+ next LOOP;
+ }
+ ($px, $py) = pointOnLine($px, $py, $qx, $qy, $pSV) if $pSV > 0;
+ ($qx, $qy) = pointOnLine($qx, $qy, $px, $py, $qSV) if $qSV > 0;
+ if ($px == $qx || $py == $qy)
+ {
+ printf OUT "\\putrule from %.5f %.5f to %.5f %.5f %%%% %s%s\n",
+ $px,$py,$qx,$qy,$p,$q;
+ }
+ else
+ {
+ printf OUT "\\plot %.5f %.5f\t%.5f %.5f / %%%% %s%s\n",
+ $px, $py,$qx,$qy,$p,$q;
+ }
+ }
+ }
+
+ sub drawCurve {
+ my ($NoArgs);
+ $NoArgs = @_;
+ my ($lc) = $_[$NoArgs-1]; #line number is the last argument
+ my ($NumberOfPoints, $p);
+
+ $NumberOfPoints = $NoArgs - 1;
+ print OUT "\\setquadratic\n\\plot\n";
+ for(my $i=0; $i <= $NumberOfPoints; $i++)
+ {
+ $p = $_[$i];
+ my ($px,$py,$pSV,$pS) = unpack("d3A*",$PointTable{lc($p)});
+ printf OUT "\t%0.5f %0.5f", $px, $py;
+ print OUT (($i == $NumberOfPoints) ? " / %$p\n" : " %$p\n");
+ }
+ print OUT "\\setlinear\n";
+ }
+
+ sub drawpoints {
+ my ($NumberOfPoints,$p);
+ $NumberOfPoints = @_;
+ my ($px,$py,$pSV,$pS);
+
+ for($i=0; $i < $NumberOfPoints; $i++)
+ {
+ $p = $_[$i];
+ ($px,$py,$pSV,$pS) = unpack("d3A*",$PointTable{lc($p)});
+ if ($pS eq "" and $defaultsymbol =~ /circle|square/) {
+ $pS = $defaultsymbol;
+ }
+ POINTSWITCH: {
+ if ($pS eq "") # no plot symbol specified
+ {
+ printf OUT "\\put {%s} at %.5f %.5f %%%% %s\n",
+ $defaultsymbol, $px, $py, $p;
+ last POINTSWITCH;
+ }
+ if ($pS eq "circle") # plot symbol is a circle
+ {
+ my $radius = (defined($DimOfPoint{lc($p)})) ? $DimOfPoint{lc($p)} :
+ $GlobalDimOfPoints;
+ if ($radius > 0) # draw a circle using the current units
+ {
+ if ($radius == 1.5) # use \bigcirc
+ {
+ printf OUT "\\put {\$\\bigcirc\$} at %.5f %.5f %%%% %s\n",
+ $px, $py, $p;
+ }
+ else
+ {
+ printf OUT "\\circulararc 360 degrees from %.5f %.5f center at %.5f %.5f %%%% %s\n",
+ $px+$radius, $py, $px, $py, $p;
+ }
+ }
+ else #use \circ symbol
+ {
+ printf OUT "\\put {\$\\circ\$} at %.5f %.5f %%%% %s\n",
+ $px,$py,$p;
+ }
+ last POINTSWITCH;
+ }
+ if ($pS eq "square")
+ {
+ my $side = (defined($DimOfPoint{lc($p)})) ? $DimOfPoint{lc($p)} :
+ $GlobalDimOfPoints;
+ printf OUT "\\put {%s} at %.5f %.5f %%%% %s\n",
+ drawsquare($side), $px, $py, $p;
+ last POINTSWITCH;
+ }
+ printf OUT "\\put {%s} at %.5f %.5f %%%% %s\n", $pS,$px,$py,$p;
+ }
+ }
+ }
+
+ sub drawAngleArc {
+ my ($P1, $P2, $P3, $radius, $inout, $direction) = @_;
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$P1});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$P2});
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$P3});
+
+ my $internalAngle = Angle($x1, $y1, $x2, $y2, $x3, $y3);
+ my $externalAngle = 360 - $internalAngle;
+ my ($x, $y) = pointOnLine($x2, $y2, $x1, $y1, $radius);
+ my $code = "";
+ if ($inout eq "internal" and $direction eq "clockwise" ) {
+ $code = sprintf "\\circulararc %.5f degrees from %.5f %.5f center at %.5f %.5f\n",
+ -1 * $internalAngle, $x, $y, $x2, $y2;
+ }
+ elsif ($inout eq "internal" and $direction eq "anticlockwise" ) {
+ $code = sprintf "\\circulararc %.5f degrees from %.5f %.5f center at %.5f %.5f\n",
+ $internalAngle, $x, $y, $x2, $y2;
+ }
+ elsif ($inout eq "external" and $direction eq "clockwise" ) {
+ $code = sprintf "\\circulararc %.5f degrees from %.5f %.5f center at %.5f %.5f\n",
+ -1 * $externalAngle, $x, $y, $x2, $y2;
+ }
+ elsif ($inout eq "external" and $direction eq "anticlockwise" ) {
+ $code = sprintf "\\circulararc %.5f degrees from %.5f %.5f center at %.5f %.5f\n",
+ $externalAngle, $x, $y, $x2, $y2;
+ }
+ return $code;
+ }
+
+ sub drawAngleArrow {
+ my ($P1, $P2, $P3, $radius, $inout, $direction) = @_;
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$P1});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$P2});
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$P3});
+
+ my $code = drawAngleArc($P1, $P2, $P3, $radius, $inout, $direction);
+
+ my ($xqp, $yqp) = pointOnLine($x2, $y2, $x1, $y1, $radius);
+ my ($deltax, $deltay) = ($x1 - $x2, $y1 - $y2);
+ my $AL;
+
+ if ($xunits =~ /mm/) {
+ $AL = 1;
+ }
+ elsif ($xunits =~ /cm/) {
+ $AL = 0.1;
+ }
+ elsif ($xunits =~ /pt/) {
+ $AL = 2.845;
+ }
+ elsif ($xunits =~ /bp/) {
+ $AL = 2.835;
+ }
+ elsif ($xunits =~ /pc/) {
+ $AL = 0.2371;
+ }
+ elsif ($xunits =~ /in/) {
+ $AL = 0.03937;
+ }
+ elsif ($xunits =~ /dd/) {
+ $AL = 2.659;
+ }
+ elsif ($xunits =~ /cc/) {
+ $AL = 0.2216;
+ }
+ elsif ($xunits =~ /sp/) {
+ $AL = 186467.98;
+ }
+ my $halfAL = $AL / 2;
+ my $d = sqrt($radius * $radius - $halfAL * $halfAL);
+ my $alpha = atan2($d / $halfAL, 1) * R2D;
+ my $beta = 2 * (90 - $alpha);
+ my $thetaqr;
+ if (abs($deltay) < 0.00001) {
+ if ($deltax > 0 ) {$thetaqr = 0 }
+ elsif ($deltax < 0) {$thetaqr = -180}
+ }
+ else {
+ if (abs($deltax) < 0.00001) {
+ $thetaqr = 90;
+ }
+ else {
+ $thetaqr = atan2($deltay / $deltax, 1) * R2D;
+ }
+ }
+ my ($xqr, $yqr) = pointOnLine($x2, $y2, $x3, $y3, $radius);
+ $deltax = $x3 - $x2;
+ $deltay = $y3 - $y2;
+ $alpha = atan2(sqrt($radius * $radius - $halfAL * $halfAL) / $halfAL, 1) /
+ D2R;
+ $beta = 2 * (90 - $alpha);
+ LINE2 : {
+ if (abs($deltax) < 0.00001) {
+ if ($deltay > 0) { $thetaqr = 90 }
+ elsif ($deltay < 0) { $thetaqr = - 90 }
+ last LINE2;
+ }
+ else {
+ $thetaqr = atan2($deltay / $deltax, 1) * R2D;
+ }
+ if (abs($deltay) < 0.00001) {
+ if ($deltax > 0) { $thetaqr = 0 }
+ elsif ($deltax < 0) { $thetaqr = -180 }
+ last LINE2;
+ }
+ else {
+ $thetaqr = atan2($deltay / $deltax, 1) * R2D;
+ }
+ if ($deltax < 0 and $deltay > 0) { $thetaqr += 180 }
+ elsif ($deltax < 0 and $deltay < 0) { $thetaqr += 180 }
+ elsif ($deltax > 0 and $deltay < 0) { $thetaqr += 360 }
+ }
+ my $xqrleft = $x2 + $radius * cos(($thetaqr + $beta) * D2R);
+ my $yqrleft = $y2 + $radius * sin(($thetaqr + $beta) * D2R);
+ my $xqrright = $x2 + $radius * cos(($thetaqr - $beta) * D2R);
+ my $yqrright = $y2 + $radius * sin(($thetaqr - $beta) * D2R);
+ if ($inout eq "internal" and $direction eq "clockwise") {
+ $code .= sprintf "\\arrow <1.5mm> [0.5, 1] from %.5f %.5f to %.5f %.5f\n",
+ $xqrleft, $yqrleft, $xqr, $yqr;
+ }
+ elsif ($inout eq "internal" and $direction eq "anticlockwise") {
+ $code .= sprintf "\\arrow <1.5mm> [0.5, 1] from %.5f %.5f to %.5f %.5f\n",
+ $xqrright, $yqrright, $xqr, $yqr;
+ }
+ elsif ($inout eq "external" and $direction eq "clockwise") {
+ $code .= sprintf "\\arrow <1.5mm> [0.5, 1] from %.5f %.5f to %.5f %.5f\n",
+ $xqrleft, $yqrleft, $xqr, $yqr;
+ }
+ elsif ($inout eq "external" and $direction eq "anticlockwise") {
+ $code .= sprintf "\\arrow <1.5mm> [0.5, 1] from %.5f %.5f to %.5f %.5f\n",
+ $xqrright, $yqrright, $xqr, $yqr;
+ }
+ return $code;
+ }
+
+ sub expr {
+ my $lc = $_[0];
+ my($left,$op,$right);
+
+ $left = term($lc);
+ while ($op = addop()) {
+ $right = term($lc);
+ if ($op eq '+')
+ { $left += $right }
+ else
+ { $left -= $right }
+ }
+ return $left;
+ }
+
+ sub addop {
+ s/^([+-])// && $1;
+ }
+
+ sub term {
+ my $lc = $_[0];
+ my ($left, $op, $right);
+ $left = factor($lc);
+ while ($op = mulop()) {
+ $right = factor($lc);
+ if ($op eq '*')
+ { $left *= $right }
+ elsif ($op =~ /rem/i) {
+ eval {$left %= $right};
+ PrintFatalError("Division by zero", $lc) if $@;
+ }
+ else {
+ eval {$left /= $right};
+ PrintFatalError("Division by zero", $lc) if $@;
+ }
+ }
+ return $left;
+ }
+
+ sub mulop {
+ (s#^([*/])## || s/^(rem)//i) && lc($1);
+ }
+
+ sub factor {
+ my $lc = $_[0];
+ my ($left);
+
+ $left = primitive($lc);
+ if (s/^\*\*//) {
+ $left **= factor($lc);
+ }
+ return $left;
+ }
+
+ sub primitive {
+ my $lc = $_[0];
+ my $val;
+ s/\s*//;
+ if (s/^\(//) { #is it an expr in parentheses
+ $val = expr($lc);
+ s/^\)// || PrintErrorMessage("Missing right parenthesis", $lc);
+ }
+ elsif (s/^-//) { # is it a negated primitive
+ $val = - primitive();
+ }
+ elsif (s/^\+//) { # is it a positive primitive
+ $val = primitive();
+ }
+ elsif (s/^angledeg//i) {
+ chk_lparen("angledeg",$lc);
+ my $point_1 = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_1});
+ my $point_2 = get_point($lc);
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point_2});
+ my $point_3 = get_point($lc);
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point_3});
+ my $d12 = Length($x1, $y1, $x2, $y2);
+ my $d23 = Length($x2, $y2, $x3, $y3);
+ my $d31 = Length($x3, $y3, $x1, $y1);
+ if ( $d12 == 0 ) {
+ PrintErrorMessage("points `$point_1' and `$point_2' are the same", $lc);
+ $val = 0;
+ }
+ elsif ( $d23 == 0 ) {
+ PrintErrorMessage("points `$point_2' and `$point_3' are the same", $lc);
+ $val = 0;
+ }
+ elsif ( $d31 == 0 ) {
+ PrintErrorMessage("points `$point_1' and `$point_3' are the same", $lc);
+ $val = 0;
+ }
+ else {
+ $val = Angle($x1, $y1, $x2, $y2, $x3, $y3);
+ $val = 0 if $val == -500;
+ }
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^angle//i) {
+ chk_lparen("angle",$lc);
+ my $point_1 = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_1});
+ my $point_2 = get_point($lc);
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point_2});
+ my $point_3 = get_point($lc);
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point_3});
+ my $d12 = Length($x1, $y1, $x2, $y2);
+ my $d23 = Length($x2, $y2, $x3, $y3);
+ my $d31 = Length($x3, $y3, $x1, $y1);
+ if ( $d12 == 0 ) {
+ PrintErrorMessage("points `$point_1' and `$point_2' are the same", $lc);
+ $val = 0;
+ }
+ elsif ( $d23 == 0 ) {
+ PrintErrorMessage("points `$point_2' and `$point_3' are the same", $lc);
+ $val = 0;
+ }
+ elsif ( $d31 == 0 ) {
+ PrintErrorMessage("points `$point_1' and `$point_3' are the same", $lc);
+ $val = 0;
+ }
+ else {
+ $val = Angle($x1, $y1, $x2, $y2, $x3, $y3);
+ if ($val == -500) {
+ $val = 0;
+ }
+ else {
+ $val = D2R * $val;
+ }
+ }
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^area//i) {
+ chk_lparen("angledeg",$lc);
+ my $point_1 = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_1});
+ my $point_2 = get_point($lc);
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point_2});
+ my $point_3 = get_point($lc);
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point_3});
+ $val = triangleArea($x1, $y1, $x2, $y2, $x3, $y3);
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^asin//i) {
+ chk_lparen("asin");
+ $val = expr();
+ PrintFatalError("Can't take asin of $val", $lc) if $val < -1 || $val > 1;
+ $val = asin($val);
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^acos//i) {
+ chk_lparen("acos");
+ $val = expr();
+ PrintFatalError("Can't take acos of $val", $lc) if $val < -1 || $val > 1 ;
+ $val = acos($val);
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^atan//i) {
+ chk_lparen("atan");
+ $val = expr();
+ $val = atan($val);
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^cos//i) {
+ chk_lparen("cos");
+ $val = expr();
+ $val = cos($val);
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^directiondeg//i) {
+ chk_lparen("directiondeg",$lc);
+ my $point_1 = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_1});
+ my $point_2 = get_point($lc);
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point_2});
+ my $x3 = $x1+1;
+ if ( ($y2 - $y1) >= 0) {
+ $val = Angle($x3, $y1, $x1, $y1, $x2, $y2);
+ $val = 0 if $val == -500;
+ }
+ else {
+ $val = 360 - Angle($x3, $y1, $x1, $y1, $x2, $y2);
+ $val = 0 if $val == -500;
+ }
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^direction//i) {
+ chk_lparen("direction",$lc);
+ my $point_1 = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_1});
+ my $point_2 = get_point($lc);
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point_2});
+ my $x3 = $x1+1;
+ if ( ($y2 - $y1) >= 0) {
+ $val = Angle($x3, $y1, $x1, $y1, $x2, $y2);
+ $val = 0 if $val == -500;
+ $val = D2R * $val;
+ }
+ else {
+ $val = 360 - Angle($x3, $y1, $x1, $y1, $x2, $y2);
+ $val = 0 if $val == -500;
+ $val = D2R * $val;
+ }
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^exp//i) {
+ chk_lparen("exp");
+ $val = expr();
+ $val = exp($val);
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^int//i) {
+ chk_lparen("int");
+ $val = expr();
+ $val = int($val);
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^log//i) {
+ chk_lparen("log");
+ $val = expr();
+ PrintFatalError("Can't take log of $val", $lc) if $val <= 0;
+ $val = log($val);
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^sin//i) {
+ chk_lparen("sin");
+ $val = expr();
+ $val = sin($val);
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^sgn//i) {
+ chk_lparen("sgn");
+ $val = expr();
+ if ($val > 0) {
+ $val = 1;
+ }
+ elsif ($val == 0) {
+ $val = 0;
+ }
+ else {
+ $val = -1;
+ }
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^sqrt//i) {
+ chk_lparen("sqrt");
+ $val = expr();
+ $val = sqrt($val);
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^tan//i) {
+ chk_lparen("tan");
+ $val = expr();
+ $val = sin($val)/cos($val);
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^xcoord//i) {
+ chk_lparen("xcoord");
+ my $point_name = get_point;
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_name});
+ $val = $x1;
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^ycoord//i) {
+ chk_lparen("ycoord");
+ my $point_name = get_point;
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_name});
+ $val = $y1;
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^_pi_//i) {
+ $val = PI;
+ }
+ elsif (s/^_e_//i) {
+ $val = 2.71828182845905;
+ }
+ elsif (s/^_linethickness_//i) {
+ $val = $LineThickness / $xunits;
+ }
+ else {
+ my $err_code;
+ ($val,$err_code) = ComputeDist($lc);
+ }
+ s/\s*//;
+ return $val;
+ }
+
+ sub memberOf {
+ my $elem = shift(@_);
+
+ my $found = 0;
+ foreach $item (@_){
+ if ($item eq $elem){
+ $found = 1;
+ last;
+ }
+ }
+ return $found;
+ }
+
+ sub midpoint {
+ my ($x1, $y1, $x2, $y2)=@_;
+ return ($x1 + ($x2 - $x1)/2,
+ $y1 + ($y2 - $y1)/2);
+ }
+
+
+ sub tand {
+ my $d = $_[0];
+ $d = $d * PI / 180;
+ return sin($d)/cos($d);
+ }
+
+ sub get_string {
+ my $string = shift;
+ my $lc = shift;
+
+ $string =~ s/^\s+//;
+ if ($string !~ s/^\"//) {
+ PrintErrorMessage("No starting \" found",$lc);
+ return (1,$string,$string);
+ }
+ my @ch = split //,$string;
+ my @cmd;
+ while (@ch and $ch[0] ne "\"") {
+ if ($ch[0] eq "\\" and (defined $ch[1]) and $ch[1] eq "\"") {
+ shift @ch;
+ push @cmd, $ch[0];
+ shift @ch;
+ }
+ else {
+ push @cmd, $ch[0];
+ shift @ch;
+ }
+ }
+ if (! defined $ch[0]) {
+ PrintErrorMessage("No closing \" found",$lc);
+ return (1,join("",@cmd), join("",@ch))
+ }
+ else {
+ shift @ch;
+ return (0, join("",@cmd), join("",@ch))
+ }
+ }
+
+ sub is_tainted {
+ my $arg = shift;
+ my $nada = substr($arg,0,0);
+ local $@;
+ eval { eval "# $nada"};
+ return length($@) != 0;
+ }
+
+ sub noOfDigits {
+ my $num = $_[0];
+
+ if ($num =~ /^[\+-]?\d+(?!\.)/) {
+ return 0;
+ }
+ elsif ($num =~ /^[\+-]\d+\.(\d+)?/) {
+ return length($1);
+ }
+ }
+
+ sub drawsquare {
+ my $s = $_[0];
+ #$s *= sqrt(2);
+ $s = sprintf "%.5f", $s;
+ my $code = "\\setlength{\\unitlength}{$xunits}%\n";
+ $code .= "\\begin{picture}($s,$s)\\put(0,0)" .
+ "{\\framebox($s,$s){}}\\end{picture}";
+ return $code;
+ }
+
+ sub X2sp {
+ my $LT = shift;
+ my $units = shift;
+
+ if ($units eq "pc") {
+ return $LT * 786432;
+ }
+ elsif ($units eq "pt") {
+ return $LT * 65536;
+ }
+ elsif ($units eq "in") {
+ return $LT * 4736286.72;
+ }
+ elsif ($units eq "bp") {
+ return $LT * 65781.76;
+ }
+ elsif ($units eq "cm") {
+ return $LT * 1864679.811023622;
+ }
+ elsif ($units eq "mm") {
+ return $LT * 186467.981102362;
+ }
+ elsif ($units eq "dd") {
+ return $LT * 70124.086430424;
+ }
+ elsif ($units eq "cc") {
+ return $LT * 841489.037165082;
+ }
+ elsif ($units eq "sp") {
+ return $LT;
+ }
+ }
+
+
+ sub sp2X {
+ my $LT = shift;
+ my $units = shift;
+
+ if ($units eq "pc") {
+ return $LT / 786432;
+ }
+ elsif ($units eq "pt") {
+ return $LT / 65536;
+ }
+ elsif ($units eq "in") {
+ return $LT / 4736286.72;
+ }
+ elsif ($units eq "bp") {
+ return $LT / 65781.76;
+ }
+ elsif ($units eq "cm") {
+ return $LT / 1864679.811023622;
+ }
+ elsif ($units eq "mm") {
+ return $LT / 186467.981102362;
+ }
+ elsif ($units eq "dd") {
+ return $LT / 70124.086430424;
+ }
+ elsif ($units eq "cc") {
+ return $LT / 841489.037165082;
+ }
+ elsif ($units eq "sp") {
+ return $LT;
+ }
+ }
+
+ sub setLineThickness {
+ my $Xunits = shift;
+ my $LT = shift;
+ $Xunits =~ s/^((\+|-)?\d+(\.\d+)?([eE](\+|-)?\d+)?)//;
+ my $xlength = "$1";
+ $Xunits =~ s/^\s*($units)//;
+ my $x_in_units = $1;
+ $LT =~ s/^((\+|-)?\d+(\.\d+)?([eE](\+|-)?\d+)?)//;
+ my $LTlength = "$1";
+ $LT =~ s/^\s*($units)//;
+ my $LT_in_units = $1;
+ $LTlength = X2sp($LTlength,$LT_in_units);
+ $LTlength = sp2X($LTlength,$x_in_units);
+ return $LTlength;
+ }
+
+ sub process_input {
+ my ($INFILE,$currInFile) = @_;
+ my $lc = 0;
+ my $no_output = 0;
+ $curr_in_file = $currInFile;
+ LINE: while(<$INFILE>) {
+ $lc++;
+ chomp($command = $_);
+ s/^\s+//;
+ if (/^beginSkip\s*/i) {
+ $no_output = 1;
+ print OUT "%%$_" if $comments_on;
+ next LINE;
+ }
+ elsif (/^endSkip\s*/i) {
+ if ($no_output == 0) {
+ PrintErrorMessage("endSkip without beginSkip",$lc);
+ }
+ else {
+ $no_output = 0;
+ }
+ print OUT "%%$_" if $comments_on and !$no_output;
+ next LINE;
+ }
+ elsif ($no_output == 1) {
+ next LINE;
+ }
+ else {
+ if (/^[^\\]/) {
+ my $out_line = mpp($command,$lc) unless /^\\/; #call macro pre-processor
+ $_ = "$out_line\n";
+ }
+
+ if (/^\s*%/)
+ {
+ print OUT "$_" if $comments_on;
+ }
+ elsif (s/^\s*(beginloop(?=\W))//i) {
+ s/\s+//;
+ my $times = expr($lc);
+ print OUT "%% BEGINLOOP $times\n" if $comments_on;
+ my @C = ();
+ REPEATCOMMS: while (<$INFILE>) {
+ if (/^\s*endloop/i) {
+ last REPEATCOMMS;
+ }
+ else {
+ push @C, $_;
+ }
+ }
+ if (! /^\s*endloop/i) {
+ PrintFatalError("unexpected end of file",$lc);
+ }
+ else {
+ s/^\s*endloop//i;
+ for(my $i=1; $i<=$times; $i++) {
+ tie *DUMMY, 'DummyFH', \@C;
+ process_input(DUMMY, $currInFile);
+ untie *DUMMY;
+ }
+ print OUT "%% ENDLOOP\n" if $comments_on;
+ }
+ }
+ elsif (s/^\s*(ArrowShape(?=\W))//i)
+ {
+ my $cmd = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+
+ chk_lparen("$cmd",$lc);
+ if (s/^default//i) {
+ $arrowLength = 2;
+ $arrowLengthUnits = "mm";
+ $arrowAngleB = 30;
+ $arrowAngleC = 40;
+ }
+ else {
+ my ($LocalArrowLength, $LocalArrowAngleB ,$LocalArrowAngleC) = (0,0,0);
+ $LocalArrowLength = expr($lc);
+ if (s/^\s*($units)//i) {
+ $arrowLengthUnits = "$1";
+ }
+ else {
+ $xunits =~ /(\d+(\.\d+)?)\s*($units)/;
+ $LocalArrowLength *= $1;
+ $arrowLengthUnits = "$3";
+ }
+ chk_comma($lc);
+ $LocalArrowAngleB = expr($lc);
+ chk_comma($lc);
+ $LocalArrowAngleC = expr($lc);
+ $arrowLength = ($LocalArrowLength == 0 ? 2 : $LocalArrowLength);
+ $arrowLengthUnits = ($LocalArrowLength == 0 ? "mm" : $arrowLengthUnits);
+ $arrowAngleB = ($LocalArrowAngleB == 0 ? 30 : $LocalArrowAngleB);
+ $arrowAngleC = ($LocalArrowAngleC == 0 ? 40 : $LocalArrowAngleC);
+ }
+ chk_rparen("after $cmd arguments",$lc);
+ chk_comment("after $cmd command",$lc);
+ print OUT "%% arrowLength = $arrowLength$arrowLengthUnits, ",
+ "arrowAngleB = $arrowAngleB ",
+ "and arrowAngleC = $arrowAngleC\n" if $comments_on;
+
+ }
+ elsif (s/^\s*(const(?=\W))//i)
+ {
+ print OUT "%% $1$_" if $comments_on;
+ do{
+ s/\s*//;
+ PrintErrorMessage("no identifier found after token const",$lc)
+ if $_ !~ s/^([^\W\d_]\d{0,4})//i;
+ my $Constname = $1;
+ my $constname = lc($Constname);
+ if (exists $ConstTable{$constname}) {
+ PrintErrorMessage("Redefinition of constant $constname",$lc);
+ }
+ s/\s*//; #remove leading white space
+ PrintErrorMessage("did not find expected = sign",$lc)
+ if $_ !~ s/^[=]//i;
+ my $val = expr($lc);
+ $VarTable{$constname} = $val;
+ $ConstTable{$constname} = 1;
+ print OUT "%% $Constname = $val\n" if $comments_on;
+ }while (s/^,//);
+ chk_comment($lc);
+ s/\s*//;
+ if (/^[^%]/) {
+ PrintWarningMessage("Trailing text is ignored",$lc);
+ }
+
+ }
+ elsif (s/^\s*(dasharray(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ chk_lparen($cmd,$lc);
+ my @DashArray = ();
+ my $dash = "";
+ my $dashpattern = "";
+ PATTERN: while (1) {
+ $dash = sprintf("%.5f", expr($lc));
+ if (s/^\s*($units)//i) {
+ push (@DashArray, "$dash$1");
+ }
+ else {
+ PrintErrorMessage("Did not found unit after expression", $lc);
+ }
+ s/\s*//;
+ if (/^[^,]/) {
+ last PATTERN;
+ }
+ else {
+ s/^,\s*//;
+ }
+ }
+ print OUT "\\setdashpattern <";
+ while (@DashArray) {
+ $dashpattern .= shift @DashArray;
+ $dashpattern .= ",";
+ }
+ $dashpattern =~ s/,$//;
+ print OUT $dashpattern, ">\n";
+ chk_rparen("arguments of $cmd",$lc);
+ chk_comment($lc);
+
+ }
+ elsif (s/^\s*(drawAngleArc(?=\W))//i or s/^\s*(drawAngleArrow(?=\W))//i )
+ {
+ my $cmd = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+
+ chk_lcb($cmd,$lc);
+ my ($P1, $P2, $P3);
+ if (s/^angle(?=\W)//i) {
+ chk_lparen("token angle of command $cmd",$lc);
+ $P1 = get_point($lc);
+ next LINE if $P1 eq "_undef_";
+ $P2 = get_point($lc);
+ next LINE if $P2 eq "_undef_";
+ $P3 = get_point($lc);
+ next LINE if $P3 eq "_undef_";
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$P1});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$P2});
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$P3});
+ my $Angle = Angle($x1, $y1, $x2, $y2, $x3, $y3);
+ if ($Angle <= 0) {
+ if ($Angle == 0) {
+ PrintErrorMessage("Angle is equal to zero",$lc);
+ next LINE;
+ }
+ elsif ($Angle < -400) {
+ PrintErrorMessage("Something is wrong with the points",$lc);
+ next LINE;
+ }
+ }
+ chk_rparen("angle part of command $cmd",$lc);
+ }
+ else {
+ PrintErrorMessage("Did not find expected angle part",$lc);
+ next LINE;
+ }
+
+ s/^,\s*// or s/\s*//; #parse optional comma
+
+ my $radius;
+ if (s/^radius(?=\W)//i) {
+ chk_lparen("token radius of command $cmd",$lc);
+ $radius = expr($lc);
+ chk_rparen("radius part of command $cmd",$lc);
+ }
+ else {
+ PrintErrorMessage("Did not found expected angle part",$lc);
+ next LINE;
+ }
+
+ s/^,\s*// or s/\s*//; #parse optional comma
+ my $inout = "";
+ if (s/^(internal(?=\W))//i or s/^(external(?=\W))//i) {
+ $inout = $1;
+ }
+ else {
+ PrintErrorMessage("Did not find expected 'internal' specifier", $lc);
+ next LINE;
+ }
+ s/^,\s*// or s/\s*//; #parse optional comma
+ my $direction = "";
+ if (s/^(clockwise(?=\W))//i or s/^(anticlockwise(?=\W))//i) {
+ $direction = $1;
+ }
+ else {
+ PrintErrorMessage("Did not find expected 'direction' specifier", $lc);
+ next LINE;
+ }
+ chk_rcb("arguments of $cmd",$lc);
+ chk_comment($lc);
+ my $code;
+ if (lc($cmd) eq "drawanglearc") {
+ $code = drawAngleArc($P1, $P2, $P3, $radius, $inout, $direction);
+ }
+ else {
+ $code = drawAngleArrow($P1, $P2, $P3, $radius, $inout, $direction);
+ }
+ print OUT $code if $code ne "";
+
+ }
+ elsif (s/^\s*(drawArrow(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ DrawLineOrArrow(0,$lc);
+ }
+ elsif (s/^\s*(drawcircle(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ chk_lparen("drawcircle",$lc);
+ my $Point = get_point($lc);
+ next LINE if $Point eq "_undef_";
+ chk_comma($lc);
+ my $R = expr($lc);
+ if ($R <= 0) {
+ PrintErrorMessage("Radius must be greater than zero",$lc);
+ next LINE;
+ }
+ my ($x,$y,$pSV,$pS)=unpack("d3A*",$PointTable{lc($Point)});
+ printf OUT "\\circulararc 360 degrees from %.5f %.5f center at %.5f %.5f\n",
+ $x+$R, $y, $x, $y;
+ chk_rparen("arguments of $cmd",$lc);
+ chk_comment($lc);
+
+ }
+ elsif (s/^\s*(drawcurve(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ DrawLineOrArrow(2,$lc);
+ }
+ elsif (s/^\s*(drawcircumcircle(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ chk_lparen("drawcircumcircle",$lc);
+ my $point1 = get_point($lc);
+ next LINE if $point1 eq "_undef_";
+ my $point2 = get_point($lc);
+ next LINE if $point2 eq "_undef_";
+ my $point3 = get_point($lc);
+ next LINE if $point3 eq "_undef_";
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point1});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point2});
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point3});
+ my ($xc, $yc,$r) = circumCircleCenter($x1,$y1,$x2,$y2,$x3,$y3,$lc);
+ next LINE if $xc == 0 and $yc == 0 and $r == 0;
+ print OUT "%% circumcircle center = ($xc,$yc), radius = $r\n" if $comments_on;
+ printf OUT "\\circulararc 360 degrees from %.5f %.5f center at %.5f %.5f\n",
+ $xc+$r, $yc, $xc, $yc;
+ chk_rparen("arguments of $cmd",$lc);
+ chk_comment($lc);
+
+ }
+ elsif (s/^\s*(drawexcircle(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ chk_lparen("drawexcircle",$lc);
+ my $point1 = get_point($lc);
+ next LINE if $point1 eq "_undef_";
+ my $point2 = get_point($lc);
+ next LINE if $point2 eq "_undef_";
+ my $point3 = get_point($lc);
+ next LINE if $point3 eq "_undef_";
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point1});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point2});
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point3});
+ if (triangleArea($x1, $y1, $x2, $y2, $x3, $y3) < 0.0001) {
+ PrintErrorMessage("Area of triangle is zero!",$lc);
+ next LINE;
+ }
+ chk_comma($lc);
+ my $point4 = get_point($lc);
+ if (!memberOf($point4, $point1, $point2, $point3)) {
+ PrintErrorMessage("Current point isn't a side point",$lc);
+ next LINE;
+ }
+ next LINE if $point4 eq "_undef_";
+ my $point5 = get_point($lc);
+ next LINE if $point5 eq "_undef_";
+ if (!memberOf($point5, $point1, $point2, $point3)) {
+ PrintErrorMessage("Current point isn't a side point",$lc);
+ next LINE;
+ }
+ if ($point4 eq $point5) {
+ PrintErrorMessage("Side points are identical",$lc);
+ next LINE;
+ }
+ chk_rparen("arguments of $cmd",$lc);
+ my ($xc, $yc, $r) = excircle($point1, $point2, $point3,
+ $point4, $point5);
+ my $R=$r;
+ if (s/^\s*\[\s*//) {
+ $R += expr($lc);
+ if ($R < 0.0001) {
+ PrintErrorMessage("Radius has become equal to zero!",$lc);
+ next LINE;
+ }
+ chk_rsb($lc);
+ }
+ if ($R > (500 / 2.845)) {
+ PrintErrorMessage("Radius is greater than 175mm!",$lc);
+ next LINE;
+ }
+ print OUT "%% excircle center = ($xc,$yc) radius = $R\n" if $comments_on;
+ printf OUT "\\circulararc 360 degrees from %.5f %.5f center at %.5f %.5f\n",
+ $xc+$R, $yc, $xc, $yc;
+ chk_comment($lc);
+
+ }
+ elsif (s/^\s*(drawincircle(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ chk_lparen("drawincircle",$lc);
+ my $point1 = get_point($lc);
+ next LINE if $point1 eq "_undef_";
+ my $point2 = get_point($lc);
+ next LINE if $point2 eq "_undef_";
+ my $point3 = get_point($lc);
+ next LINE if $point3 eq "_undef_";
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point1});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point2});
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point3});
+ if (triangleArea($x1, $y1, $x2, $y2, $x3, $y3) < 0.0001) {
+ PrintErrorMessage("Area of triangle is zero!",$lc);
+ next LINE;
+ }
+ my ($xc, $yc, $r) = IncircleCenter($x1,$y1,$x2,$y2,$x3,$y3);
+ my $R=$r;
+ if (s/^\s*\[\s*//) {
+ $R += expr($lc);
+ if ($R < 0.0001) {
+ PrintErrorMessage("Radius has become equal to zero!",$lc);
+ next LINE;
+ }
+ chk_rsb($lc);
+ }
+ if ($R > (500 / 2.845)) {
+ PrintErrorMessage("Radius is greater than 175mm!",$lc);
+ next LINE;
+ }
+ print OUT "%% incircle center = ($xc,$yc) radius = $R\n" if $comments_on;
+ printf OUT "\\circulararc 360 degrees from %.5f %.5f center at %.5f %.5f\n",
+ $xc+$R, $yc, $xc, $yc;
+ chk_rparen("arguments of $cmd",$lc);
+ chk_comment($lc);
+
+ }
+ elsif (s/^\s*(drawline(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ DrawLineOrArrow(1,$lc);
+ }
+ elsif (s/^\s*(drawthickarrow(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ print OUT "\\setplotsymbol ({\\usefont{OT1}{cmr}{m}{n}\\large .})%\n";
+ print OUT "{\\setbox1=\\hbox{\\usefont{OT1}{cmr}{m}{n}\\large .}%\n";
+ print OUT " \\global\\linethickness=0.31\\wd1}%\n";
+ DrawLineOrArrow(0,$lc);
+ print OUT "\\setlength{\\linethickness}{0.4pt}%\n";
+ print OUT "\\setplotsymbol ({\\usefont{OT1}{cmr}{m}{n}\\tiny .})%\n";
+ }
+ elsif (s/^\s*(drawthickline(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ print OUT "\\setplotsymbol ({\\usefont{OT1}{cmr}{m}{n}\\large .})%\n";
+ print OUT "{\\setbox1=\\hbox{\\usefont{OT1}{cmr}{m}{n}\\large .}%\n";
+ print OUT " \\global\\linethickness=0.31\\wd1}%\n";
+ DrawLineOrArrow(1,$lc);
+ print OUT "\\setlength{\\linethickness}{0.4pt}%\n";
+ print OUT "\\setplotsymbol ({\\usefont{OT1}{cmr}{m}{n}\\tiny .})%\n";
+ }
+ elsif (s/^\s*(drawperpendicular(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+
+ chk_lparen($cmd,$lc);
+ my $A = get_point($lc);
+ next LINE if $A eq "_undef_";
+ chk_comma($lc);
+ my $B = get_point($lc);
+ next LINE if $A eq "_undef_";
+ s/\s*//; #ignore white space
+ my $C = get_point($lc);
+ next LINE if $A eq "_undef_";
+ chk_rparen("arguments of $cmd",$lc);
+ chk_comment($lc);
+ #
+ #start actual computation
+ #
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$A});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$B});
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$C});
+ my ($xF, $yF) = perpendicular($x1, $y1, $x2, $y2, $x3, $y3);
+ printf OUT "\\plot %.5f %.5f %.5f %.5f /\n",
+ $x1, $y1, $xF, $yF;
+
+ }
+ elsif (s/^\s*(drawpoint(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ my ($stacklen);
+ chk_lparen("$cmd",$lc);
+ if (/^\)/) {
+ PrintErrorMessage("There are no point to draw",$lc);
+ next LINE;
+ }
+ my(@PP);
+ DRAWPOINTS:while(1) {
+ if (s/^([^\W\d_]\d{0,4})//i) { #point name
+ $P = $1;
+ if (!exists($PointTable{lc($P)})) {
+ PrintErrorMessage("Undefined point $P",$lc);
+ next DRAWPOINTS;
+ }
+ else {
+ push (@PP,$P);
+ s/\s*//;
+ }
+ }
+ else {
+ last DRAWPOINTS;
+ }
+ }
+ drawpoints(@PP);
+ chk_rparen("arguments of $cmd",$lc);
+ chk_comment($lc);
+
+ }
+ elsif (s/^\s*(drawRightAngle(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+
+ chk_lparen("drawRightAngle",$lc);
+ my $point1 = get_point($lc);
+ next LINE if $point1 eq "_undef_";
+ my $point2 = get_point($lc);
+ next LINE if $point2 eq "_undef_";
+ my $point3 = get_point($lc);
+ next LINE if $point3 eq "_undef_";
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point1});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point2});
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point3});
+ chk_comma($lc);
+ my $dist = expr($lc);
+ chk_rparen("arguments of $cmd",$lc);
+ chk_comment($lc);
+ #
+ #actual computation
+ #
+ my ($Px, $Py) = pointOnLine($x2, $y2, $x1, $y1, $dist);
+ my ($Qx, $Qy) = pointOnLine($x2, $y2, $x3, $y3, $dist);
+ my ($Tx, $Ty) = midpoint($Px, $Py, $Qx, $Qy);
+ my ($Ux, $Uy) = pointOnLine($x2, $y2, $Tx, $Ty, 2*Length($x2, $y2, $Tx, $Ty));
+ if ($Px == $Ux || $Py == $Uy) {
+ printf OUT "\\putrule from %.5f %.5f to %.5f %.5f \n", $Px,$Py,$Ux,$Uy;
+ }
+ else {
+ printf OUT "\\plot %.5f %.5f\t%.5f %.5f / \n", $Px, $Py,$Ux,$Uy;
+ }
+ if ($Ux == $Qx || $Uy == $Qy) {
+ printf OUT "\\putrule from %.5f %.5f to %.5f %.5f \n", $Ux,$Uy,$Qx,$Qy;
+ }
+ else {
+ printf OUT "\\plot %.5f %.5f\t%.5f %.5f / \n", $Ux, $Uy,$Qx,$Qy;
+ }
+
+
+ }
+ elsif (s/^\s*(drawsquare(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ chk_lparen("drawSquare",$lc);
+ my $p = get_point($lc);
+ chk_comma($lc);
+ my $side = expr($lc);
+ $side = $side - (1.1 * $LineThickness/$xunits); #Suggested by RWDN
+ my ($x,$y,$pSV,$pS) = unpack("d3A*",$PointTable{$p});
+ printf OUT "\\put {%s} at %.5f %.5f %%drawsquare\n", drawsquare($side), $x, $y;
+ chk_rparen("arguments of $cmd",$lc);
+ chk_comment($lc);
+
+ }
+ elsif (s/^\s*inputfile\*//i)
+ {
+ chk_lparen("inputfile*",$lc);
+ my $row_in = "";
+ if (s/^((\w|-|\.)+)//) {
+ $row_in = $1;
+ }
+ else {
+ PrintErrorMessage("No input file name found",$lc);
+ next LINE;
+ }
+ if (!(-e $row_in)) {
+ PrintErrorMessage("File $row_in does not exist",$lc);
+ next LINE;
+ }
+ open(ROW, "$row_in")|| die "Can't open file $row_in\n";
+ while (defined($in_line=<ROW>)) { print OUT $in_line; }
+ print OUT "%% ... end of input file <$row_in>\n";
+ close ROW;
+ chk_rparen("input file name",$lc);
+ chk_comment($lc);
+
+
+ }
+ elsif (s/^\s*(inputfile(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+
+ chk_lparen("inputfile",$lc);
+ my $comm_in = "";
+ if (s/^((\w|-|\.)+)//) {
+ $comm_in = $1;
+ }
+ else {
+ PrintErrorMessage("No input file name found",$lc);
+ next LINE;
+ }
+ if (!(-e $comm_in)) {
+ PrintErrorMessage("File $comm_in does not exist",$lc);
+ next LINE;
+ }
+ chk_rparen("input file name",$lc);
+ my $input_times = 1; #default value
+ if (s/^\[//) {
+ $input_times = expr($lc);
+ chk_rsb("optional argument",$lc);
+ }
+ print OUT "%% ... start of file <$comm_in> loop [$input_times]\n";
+ for (my $i=0; $i<int($input_times); $i++) {
+ open(COMM,"$comm_in") or die "Can't open file $comm_in\n";
+ print OUT "%%% Iteration number: ",$i+1,"\n";
+ my $old_file_name = $curr_in_file;
+ process_input(COMM,"File $comm_in, ");
+ $curr_in_file = $old_file_name;
+ close COMM;
+ }
+ print OUT "%% ... end of file <$comm_in> loop [$input_times]\n";
+ chk_comment($lc);
+
+ }
+ elsif (s/^\s*(linethickness(?=\W))//i)
+ {
+ my $cmd = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ chk_lparen("linethickness", $lc);
+ if (s/^default//i) {
+ print OUT "\\linethickness=0.4pt\\Linethickness{0.4pt}%%\n";
+ print OUT "\\setplotsymbol ({\\usefont{OT1}{cmr}{m}{n}\\tiny .})%\n";
+ $LineThickness = setLineThickness($xunits,"0.4pt");
+ }
+ else {
+ my $length = expr($lc);
+ if (s/^\s*($units)//i) {
+ my $units = $1;
+ printf OUT "\\linethickness=%.5f%s\\Linethickness{%.5f%s}%%\n",
+ $length, $units, $length, $units;
+ $LineThickness = setLineThickness($xunits,"$length$units");
+ my $mag;
+ if ($units eq "pc") {
+ $mag = $length * 12;
+ }
+ elsif ($units eq "in") {
+ $mag = $length * 72.27;
+ }
+ elsif ($units eq "bp") {
+ $mag = $length * 1.00375;
+ }
+ elsif ($units eq "cm") {
+ $mag = $length * 28.45275;
+ }
+ elsif ($units eq "mm") {
+ $mag = $length * 2.845275;
+ }
+ elsif ($units eq "dd") {
+ $mag = $length * 1.07001;
+ }
+ elsif ($units eq "cc") {
+ $mag = $length * 0.08917;
+ }
+ elsif ($units eq "sp") {
+ $mag = $length * 0.000015259;
+ }
+ elsif ($units eq "pt") {
+ $mag = $length;
+ }
+ $mag = 10 * $mag / 1.00278219;
+ printf OUT "\\font\\CM=cmr10 at %.5fpt%%\n", $mag;
+ print OUT "\\setplotsymbol ({\\CM .})%\n";
+ }
+ else {
+ PrintErrorMessage("Did not found expect units part",$lc);
+ }
+ }
+ chk_rparen("linethickness", $lc);
+ chk_comment($lc);
+
+
+ }
+ elsif (s/^\s*(paper(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ chk_lcb("paper", $lc);
+ if (s/^units(?=\W)//i)
+ {
+
+ chk_lparen("units",$lc);
+ if(s/^\)//)
+ {
+ PrintWarningMessage("Missing value in \"units\"--default is 1pt",
+ $lc);
+ $xunits = "1pt";
+ }
+ else {
+ $xunits = expr($lc);
+ s/\s*//;
+ if (s/^($units)//i) {
+ $xunits .= "$1";
+ $LineThickness = setLineThickness($xunits,"0.4pt");
+ }
+ elsif(s/^(\w)+//i) {
+ PrintErrorMessage("$1 is not a valid mathspic unit",$lc);
+ $xunits = "1pt";
+ }
+ else {
+ PrintErrorMessage("No x-units found",$lc);
+ $xunits = "1pt";
+ }
+ s/\s*//; #ignore white space
+ if (s/^,//) { # there is a comma so expect an y-units
+ s/\s*//; #ignore white space
+ $yunits = expr($lc);
+ s/\s*//; #ignore white space
+ if (s/^($units)//i) {
+ $yunits .= "$1";
+ }
+ elsif(s/^(\w)+//i) {
+ PrintErrorMessage("$1 is not a valid mathspic unit",$lc);
+ $yunits = "1pt";
+ }
+ else {
+ PrintErrorMessage("No y-units found",$lc);
+ $yunits = $xunits;
+ }
+ }
+ else {
+ $yunits = $xunits;
+ }
+ chk_rparen("units",$lc);
+ }
+
+ $nounits = 0;
+ }
+ else
+ {
+ $nounits = 1;
+ }
+ s/^,\s*// or s/\s*//;
+ if (s/^xrange//i)
+ {
+
+ chk_lparen("xrange",$lc);
+ my $ec;
+ ($xlow,$ec) = ComputeDist($lc);
+ next LINE if $ec == 0;
+ chk_comma($lc);
+ ($xhigh,$ec) = ComputeDist($lc);
+ next LINE if $ec == 0;
+ if ($xlow >= $xhigh)
+ {
+ PrintErrorMessage("xlow >= xhigh in xrange",$lc);
+ next LINE;
+ }
+ chk_rparen("$xhigh",$lc);
+
+ $noxrange = 0;
+ }
+ else
+ {
+ $noxrange = 1;
+ }
+ s/^,\s*// or s/\s*//;
+ if (s/^yrange//i)
+ {
+
+ chk_lparen("yrange",$lc);
+ my $ec;
+ ($ylow,$ec) = ComputeDist($lc);
+ next LINE if $ec == 0;
+ chk_comma($lc);
+ ($yhigh,$ec) = ComputeDist($lc);
+ next LINE if $ec == 0;
+ if ($ylow >= $yhigh)
+ {
+ PrintErrorMessage("ylow >= yhigh in yrange",$lc);
+ next LINE;
+ }
+ chk_rparen("$yhigh",$lc);
+
+ $noyrange = 0;
+ }
+ else
+ {
+ $noyrange = 1;
+ }
+
+ if (!$nounits)
+ {
+ printf OUT "\\setcoordinatesystem units <%s,%s>\n",
+ $xunits,$yunits;
+ }
+ if(!$noxrange && !$noyrange)
+ {
+ printf OUT "\\setplotarea x from %.5f to %.5f, y from %.5f to %.5f\n",
+ $xlow, $xhigh, $ylow, $yhigh;
+
+ }
+
+ s/^,\s*// or s/\s*//;
+ $axis = "";
+ if (s/^ax[ei]s(?=\W)//i)
+ {
+
+ chk_lparen("axis",$lc);
+ while(/^[^\)]/)
+ {
+ if (s/^([lrtbxy]{1}\*?)//i)
+ {
+ $axis .= $1;
+ }
+ elsif (s/^([^lrtbxy])//i)
+ {
+ PrintErrorMessage("Non-valid character \"$1\" in axis()",$lc);
+ }
+ s/\s*//;
+ }
+ chk_rparen("axis(arguments",$lc);
+
+ }
+ $axis = uc($axis);
+ s/^,\s*// or s/\s*//;
+ if (s/^ticks(?=\W)//i)
+ {
+ chk_lparen("ticks",$lc);
+ my $ec;
+ ($xticks,$ec) = ComputeDist($lc);
+ next LINE if $ec == 0;
+ chk_comma($lc);
+ ($yticks,$ec) = ComputeDist($lc);
+ next LINE if $ec == 0;
+ chk_rparen("ticks(arguments",$lc);
+
+ }
+ else
+ {
+ $xticks = $yticks = 0;
+ }
+ chk_rcb("paper", $lc);
+ YBRANCH: {
+ if (index($axis, "Y")>-1)
+ {
+ if (index($axis, "Y*")>-1)
+ {
+ print OUT "\\axis left shiftedto x=0 / \n";
+ last YBRANCH;
+ }
+ if ($yticks > 0)
+ {
+ if (index($axis, "T")>-1 && index($axis, "B")==-1)
+ {
+ print OUT "\\axis left shiftedto x=0 ticks numbered from ";
+ print OUT "$ylow to -$yticks by $yticks\n from $yticks to ";
+ print OUT $yhigh-$yticks," by $yticks /\n";
+ }
+ elsif (index($axis, "T")==-1 && index($axis, "B")>-1)
+ {
+ print OUT "\\axis left shiftedto x=0 ticks numbered from ";
+ print OUT $ylow+$yticks," to -$yticks by $yticks\n from ";
+ print OUT "$yticks to $yhigh by $yticks /\n";
+ }
+ elsif (index($axis, "T")>-1 && index($axis, "B")>-1)
+ {
+ print OUT "\\axis left shiftedto x=0 ticks numbered from ";
+ print OUT $ylow+$yticks," to -$yticks by $yticks\n from ";
+ print OUT "$yticks to ",$yhigh-$yticks," by $yticks /\n";
+ }
+ else
+ {
+ print OUT "\\axis left shiftedto x=0 ticks numbered from ";
+ print OUT "$ylow to -$yticks by $yticks\n from ";
+ print OUT "$yticks to $yhigh by $yticks /\n";
+ }
+ }
+ else
+ {
+ print OUT "\\axis left shiftedto x=0 /\n";
+ }
+ }
+ }
+ XBRANCH: { if (index($axis, "X")>-1)
+ {
+ if (index($axis, "X*")>-1)
+ {
+ print OUT "\\axis bottom shiftedto y=0 /\n";
+ last XBRANCH;
+ }
+ if ($xticks > 0)
+ {
+ if (index($axis, "L")>-1 && index($axis, "R")==1)
+ {
+ print OUT "\\axis bottom shiftedto y=0 ticks numbered from ";
+ print OUT $xlow + $xticks," to -$xticks by $xticks\n from";
+ print OUT " $xticks to $xhigh by $xticks /\n";
+ }
+ elsif (index($axis, "L")==-1 && index($axis, "R")>-1)
+ {
+ print OUT "\\axis bottom shiftedto y=0 ticks numbered from ";
+ print OUT "$xlow to -$xticks by $xticks\n from ";
+ print OUT "$xticks to ",$xhigh-$xticks," by $xticks /\n";
+ }
+ elsif (index($axis, "L")>-1 && index($axis, "R")>-1)
+ {
+ print OUT "\\axis bottom shiftedto y=0 ticks numbered from ";
+ print OUT $xlow + $xticks," to -$xticks by $xticks\n from ";
+ print OUT "$xticks to ",$xhigh - $xticks," by $xticks /\n";
+ }
+ else
+ {
+ print OUT "\\axis bottom shiftedto y=0 ticks numbered from ";
+ print OUT "$xlow to -$xticks by $xticks\n from ";
+ print OUT "$xticks to $xhigh by $xticks /\n";
+ }
+ }
+ else
+ {
+ print OUT "\\axis bottom shiftedto y=0 /\n";
+ }
+ } }
+ LBRANCH: {if (index($axis, "L")>-1)
+ {
+ if (index($axis, "L")>-1)
+ {
+ if (index($axis, "L*")>-1)
+ {
+ print OUT "\\axis left /\n";
+ last LBRANCH;
+ }
+ if ($yticks > 0)
+ {
+ print OUT "\\axis left ticks numbered from ";
+ print OUT "$ylow to $yhigh by $yticks /\n";
+ }
+ else
+ {
+ print OUT "\\axis left /\n";
+ }
+ }
+ } }
+ RBRANCH: { if (index($axis, "R")>-1)
+ {
+ if (index($axis, "R*")>-1)
+ {
+ print OUT "\\axis right /\n";
+ last RBRANCH;
+ }
+ if ($yticks > 0)
+ {
+ print OUT "\\axis right ticks numbered from $ylow to $yhigh by ";
+ print OUT "$yticks /\n";
+ }
+ else
+ {
+ print OUT "\\axis right /\n";
+ }
+ } }
+ TBRANCH: { if (index($axis, "T")>-1)
+ {
+ if (index($axis, "T*")>-1)
+ {
+ print OUT "\\axis top /\n";
+ last TBRANCH;
+ }
+ if ($xticks > 0)
+ {
+ print OUT "\\axis top ticks numbered from $xlow to $xhigh by ";
+ print OUT "$xticks /\n";
+ }
+ else
+ {
+ print OUT "\\axis top /\n";
+ }
+ } }
+ BBRANCH: { if (index($axis, "B")>-1)
+ {
+ if (index($axis, "B*")>-1)
+ {
+ print OUT "\\axis bottom /\n";
+ last BBRANCH;
+ }
+ if ($xticks > 0)
+ {
+ print OUT "\\axis bottom ticks numbered from $xlow to $xhigh by ";
+ print OUT "$xticks /\n";
+ }
+ else
+ {
+ print OUT "\\axis bottom /\n";
+ }
+ } }
+
+
+ chk_comment($lc);
+
+ }
+ elsif (s/^\s*(PointSymbol(?=\W))//i)
+ {
+ my $cmd = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+
+ chk_lparen("$cmd",$lc);
+ if (s/^default//i) #default point symbol
+ {
+ $defaultsymbol = "\$\\bullet\$";
+ }
+ elsif (s/^(circle|square)//i) {
+ $defaultsymbol = $1;
+ chk_lparen($defaultsymbol, $lc);
+ $GlobalDimOfPoints = expr($lc);
+ chk_rparen("expression", $lc);
+ }
+ elsif (s/^(((\\,){1}|(\\\)){1}|(\\\s){1}|[^\),\s])+)//) #arbitrary LaTeX point
+ {
+ $defaultsymbol = $1;
+ $defaultsymbol=~ s/\\\)/\)/g;
+ $defaultsymbol=~ s/\\,/,/g;
+ $defaultsymbol=~ s/\\ / /g;
+ }
+ else
+ {
+ PrintErrorMessage("unrecognized point symbol",$lc);
+ }
+ if (s/\s*,\s*//) {
+ $defaultLFradius = expr($lc);
+ }
+ chk_rparen("after $cmd arguments",$lc);
+ chk_comment("after $cmd command",$lc);
+
+ }
+ elsif (s/^\s*point(?=\W)//i)
+ {
+ my ($Point_Line);
+ chomp($Point_Line=$_);
+ my ($pointStar, $PointName, $origPN);
+ $pointStar = 0; # default value: he have a point command
+ $pointStar = 1 if s/^\*//;
+ chk_lparen("point" . (($pointStar)?"*":""),$lc);
+ if (s/^([^\W\d_](?![^\W\d_])\d{0,4})//i) {
+ #
+ # Note: the regular expression (foo)(?!bar) means that we are
+ # looking a foo not followed by a bar. Moreover, the regular
+ # expression [^\W\d_] means that we are looking for letter.
+ #
+ $origPN = $1;
+ $PointName = lc($1);
+ }
+ else {
+ PrintErrorMessage("Invalid point name",$lc);
+ next LINE;
+ }
+ #if ($pointStar and !exists($PointTable{$PointName})) {
+ # PrintWarningMessage("Point $origPN has not been defined",$lc);
+ #}
+ if (!$pointStar and exists($PointTable{$PointName})) {
+ PrintWarningMessage("Point $origPN has been used already",$lc);
+ }
+ chk_rparen("point" . (($pointStar)?"*":""). "($origPN",$lc);
+ chk_lcb("point" . (($pointStar)?"*":""). "($origPN)",$lc);
+ my ($Px, $Py);
+ if (s/^perpendicular(?=\W)//i) {
+ chk_lparen("perpendicular",$lc);
+ my $FirstPoint = &get_point($lc);
+ next LINE if $FirstPoint eq "_undef_";
+ chk_comma($lc);
+ my $SecondPoint = &get_point($lc);
+ next LINE if $SecondPoint eq "_undef_";
+ my $ThirdPoint = &get_point($lc);
+ next LINE if $ThirdPoint eq "_undef_";
+ chk_rparen("No closing parenthesis found",$lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$FirstPoint});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$SecondPoint});
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$ThirdPoint});
+ ($Px, $Py) = perpendicular($x1,$y1,$x2,$y2,$x3,$y3);
+
+ }
+ elsif (s/^intersection(?=\W)//i) {
+ chk_lparen("intersection",$lc);
+ my $FirstPoint = get_point($lc);
+ next LINE if $FirstPoint eq "_undef_";
+ my $SecondPoint = get_point($lc);
+ next LINE if $SecondPoint eq "_undef_";
+ chk_comma($lc);
+ my $ThirdPoint = get_point($lc);
+ next LINE if $ThirdPoint eq "_undef_";
+ my $ForthPoint = get_point($lc);
+ next LINE if $ForthPoint eq "_undef_";
+ chk_rparen("No closing parenthesis found",$lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$FirstPoint});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$SecondPoint});
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$ThirdPoint});
+ my ($x4,$y4,$pSV4,$pS4)=unpack("d3A*",$PointTable{$ForthPoint});
+ ($Px, $Py) = intersection4points($x1,$y1,$x2,$y2,$x3,$y3,$x4,$y4);
+
+
+ }
+ elsif (s/^midpoint(?=\W)//i) {
+ chk_lparen("midpoint",$lc);
+ my $FirstPoint = &get_point($lc);
+ next LINE if $FirstPoint eq "_undef_";
+ my $SecondPoint = &get_point($lc);
+ next LINE if $SecondPoint eq "_undef_";
+ chk_rparen("No closing parenthesis found",$lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$FirstPoint});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$SecondPoint});
+ ($Px, $Py) = midpoint($x1, $y1, $x2, $y2);
+
+ }
+ elsif (s/^pointonline(?=\W)//i) {
+ chk_lparen("pointonline",$lc);
+ my $FirstPoint = &get_point($lc);
+ next LINE if $FirstPoint eq "_undef_";
+ my $SecondPoint = &get_point($lc);
+ next LINE if $SecondPoint eq "_undef_";
+ chk_comma($lc);
+ # now get the distance
+ my $distance = expr($lc);
+ chk_rparen("No closing parenthesis found",$lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$FirstPoint});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$SecondPoint});
+ ($Px, $Py) = pointOnLine($x1,$y1,$x2,$y2,$distance);
+
+ }
+ elsif (s/^circumcircleCenter(?=\W)//i) {
+ chk_lparen("circumCircleCenter",$lc);
+ my $FirstPoint = &get_point($lc);
+ next LINE if $FirstPoint eq "_undef_";
+ my $SecondPoint = &get_point($lc);
+ next LINE if $SecondPoint eq "_undef_";
+ my $ThirdPoint = &get_point($lc);
+ next LINE if $ThirdPoint eq "_undef_";
+ chk_rparen("No closing parenthesis found",$lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$FirstPoint});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$SecondPoint});
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$ThirdPoint});
+ ($Px, $Py,$r) = &circumCircleCenter($x1,$y1,$x2,$y2,$x3,$y3,$lc);
+ next LINE if $Px == 0 and $Py == 0 and $r == 0;
+
+ }
+ elsif (s/^IncircleCenter(?=\W)//i) {
+ chk_lparen("IncircleCenter",$lc);
+ my $FirstPoint = &get_point($lc);
+ next LINE if $FirstPoint eq "_undef_";
+ my $SecondPoint = &get_point($lc);
+ next LINE if $SecondPoint eq "_undef_";
+ my $ThirdPoint = &get_point($lc);
+ next LINE if $ThirdPoint eq "_undef_";
+ chk_rparen("No closing parenthesis found",$lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$FirstPoint});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$SecondPoint});
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$ThirdPoint});
+ ($Px, $Py, $r) = IncircleCenter($x1,$y1,$x2,$y2,$x3,$y3);
+
+ }
+ elsif (s/^ExcircleCenter(?=\W)//i) {
+ chk_lparen("ExcircleCenter",$lc);
+ my $PointA = get_point($lc);
+ next LINE if $PointA eq "_undef_";
+ my $PointB = get_point($lc);
+ next LINE if $PointB eq "_undef_";
+ my $PointC = get_point($lc);
+ next LINE if $PointC eq "_undef_";
+ chk_comma($lc);
+ my $PointD = &get_point($lc);
+ next LINE if $PointD eq "_undef_";
+ if (!memberOf($PointD, $PointA, $PointB, $PointC)) {
+ PrintErrorMessage("Current point isn't a side point",$lc);
+ next LINE;
+ }
+ my $PointE = get_point($lc);
+ next LINE if $PointE eq "_undef_";
+ if (!memberOf($PointE, $PointA, $PointB, $PointC)) {
+ PrintErrorMessage("Current point isn't a side point",$lc);
+ next LINE;
+ }
+ if ($PointD eq $PointE) {
+ PrintErrorMessage("Side points are identical",$lc);
+ next LINE;
+ }
+ ($Px, $Py, $r) = excircle($PointA, $PointB, $PointC,
+ $PointD, $PointE);
+ chk_rparen("after coordinates part",$lc);
+
+ }
+ elsif (/^[^\W\d_]\d{0,4}\s*[^,\w]/) {
+ m/^([^\W\d_]\d{0,4})\s*/i;
+ if (exists($PointTable{lc($1)})) {
+ my $Tcoord = get_point($lc);
+ my ($x,$y,$pSV,$pS)=unpack("d3A*",$PointTable{$Tcoord});
+ $Px = $x;
+ $Py = $y;
+ }
+ else {
+ $Px = expr();
+ chk_comma($lc);
+ $Py = expr();
+ }
+ }
+ elsif (/[^\W\d_]\d{0,4}\s*,\s*shift|polar|rotate|vector/i) { #a point?
+ s/^([^\W\d_]\d{0,4})//i;
+ my $PointA = $1;
+ if (exists($PointTable{lc($PointA)})) {
+ s/\s*//;
+ if (s/^,//) {
+ s/\s*//;
+ if (s/^shift(?=\W)//i) {
+
+ chk_lparen("shift",$lc);
+ my $dist1 = expr($lc);
+ chk_comma($lc);
+ my $dist2 = expr($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{lc($PointA)});
+ $Px = $x1 + $dist1;
+ $Py = $y1 + $dist2;
+ chk_rparen("shift part",$lc);
+
+ }
+ elsif (s/^polar(?=\W)//i) {
+ chk_lparen("polar",$lc);
+ my ($R1, $Theta1);
+ $R1 = expr($lc);
+ chk_comma($lc);
+ $Theta1 = expr($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{lc($PointA)});
+ s/\s*//;
+ if (s/^rad(?=\W)//i) {
+ # do nothing!
+ }
+ elsif (s/^deg(?=\W)//i) {
+ $Theta1 = $Theta1 * PI / 180;
+ }
+ else {
+ #$Theta1 = $Theta1 * PI / 180;
+ }
+ $Px = $x1 + $R1 * cos($Theta1);
+ $Py = $y1 + $R1 * sin($Theta1);
+ chk_rparen("after polar part",$lc);
+
+ }
+ elsif (s/^rotate(?=\W)//i) {
+ chk_lparen("rotate",$lc);
+ my $Q = lc($PointA);
+ my $P = get_point($lc);
+ next LINE if $P eq "_undef_";
+ chk_comma($lc);
+ my $Theta1 = expr($lc);
+ my ($xP,$yP,$pSV1,$pS1)=unpack("d3A*",$PointTable{$P});
+ my ($xQ,$yQ,$pSV2,$pS2)=unpack("d3A*",$PointTable{$Q});
+ s/\s*//;
+ if (s/^rad(?=\W)//i)
+ {
+ # do nothing!
+ }
+ elsif (s/^deg(?=\W)//i)
+ {
+ $Theta1 = $Theta1 * PI / 180;
+ }
+ else
+ {
+ $Theta1 = $Theta1 * PI / 180;
+ }
+ # shift origin to P
+ $xQ -= $xP;
+ $yQ -= $yP;
+ # do the rotation
+ $Px = $xQ * cos($Theta1) - $yQ * sin($Theta1);
+ $Py = $xQ * sin($Theta1) + $yQ * cos($Theta1);
+ # return origin back to original origin
+ $Px += $xP;
+ $Py += $yP;
+ chk_rparen("after rotate part",$lc);
+
+ }
+ elsif (s/^vector(?=\W)//i) {
+ chk_lparen("vector",$lc);
+ my ($x0,$y0,$pSV0,$pS0) = unpack("d3A*",$PointTable{lc($PointA)});
+ my $P = get_point($lc);
+ my $Q = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1) = unpack("d3A*",$PointTable{$P});
+ my ($x2,$y2,$pSV2,$pS2) = unpack("d3A*",$PointTable{$Q});
+ $Px = $x0 + $x2 - $x1;
+ $Py = $y0 + $y2 - $y1;
+ chk_rparen("vector part",$lc);
+
+
+ }
+ else {
+ PrintErrorMessage("unexpected token",$lc);
+ next LINE;
+ }
+ }
+ else {
+ my ($xA,$yA,$pSVA,$pSA)=unpack("d3A*",$PointTable{lc($PointA)});
+ $Px = $xA;
+ $Py = $yA;
+ }
+ }
+ else {
+ PrintErrorMessage("Undefined point $PointA",$lc);
+ next LINE;
+ }
+ }
+ else {
+ $Px = expr();
+ chk_comma($lc);
+ $Py = expr();
+ }
+
+ chk_rcb("coordinates part",$lc);
+ my $sv = $defaultsymbol;
+ my $sh = $defaultLFradius;
+ my $side_or_radius = undef;
+ if (s/^\[\s*//) { # the user has opted to specify the optional part
+ if (/^(symbol|radius|side)\s*/i) {
+ my @previous_options = ();
+ my $number_of_options = 1;
+ my $symbol_set = 0;
+ while (s/^(symbol|radius)\s*//i and $number_of_options <= 2) {
+ my $option = lc($1);
+ if (s/^=\s*//) {
+ if (memberOf($option,@previous_options)) {
+ PrintErrorMessage("Option \"$option\" has been already defined", $lc);
+ my $dummy = expr($lc);
+ }
+ elsif ($option eq "radius") {
+ $sh = expr($lc);
+ $sv = $defaultsymbol if ! $symbol_set;
+ }
+ elsif ($option eq "symbol") {
+ if (s/^circle\s*//i) {
+ $sv = "circle";
+ chk_lparen("after token circle",$lc);
+ $side_or_radius = expr($lc);
+ chk_rparen("expression",$lc);
+ }
+ elsif (s/^square\s*//i) {
+ $sv = "square";
+ chk_lparen("after token square",$lc);
+ $side_or_radius = expr($lc);
+ chk_rparen("expression",$lc);
+ }
+ elsif (s/^(((\\\]){1}|(\\,){1}|(\\\s){1}|[^\],\s])+)//) {
+ $sv = $1;
+ $sv =~ s/\\\]/\]/g;
+ $sv =~ s/\\,/,/g;
+ $sv =~ s/\\ / /g;
+ s/\s*//;
+ }
+ $symbol_set = 1;
+ }
+ }
+ else {
+ PrintErrorMessage("unexpected token", $lc);
+ next LINE;
+ }
+ $number_of_options++;
+ push (@previous_options, $option);
+ s/^,\s*//;
+ }
+ }
+ else {
+ PrintErrorMessage("unexpected token", $lc);
+ next LINE;
+ }
+
+ chk_rsb("optional part",$lc);
+ }
+ # to avoid truncation problems introduced by the pack function, we
+ # round each number up to five decimal digits
+ $Px = sprintf("%.5f", $Px);
+ $Py = sprintf("%.5f", $Py);
+ print OUT "%% point$Point_Line \t$origPN = ($Px, $Py)\n" if $comments_on;
+ chk_comment($lc);
+ $PointTable{$PointName} = pack("d3A*",$Px,$Py,$sh,$sv);
+ if (defined($side_or_radius)) {
+ $DimOfPoint{$PointName} = $side_or_radius;
+ }
+
+ }
+ elsif (/^\s*setPointNumber(?=\W)/i)
+ {
+ PrintWarningMessage("Command setPointNumber is ignored",$lc);
+ next LINE;
+ }
+ elsif (s/^\s*(showAngle(?=\W))//i)
+ {
+ chk_lparen("showangle",$lc);
+ my $point_1 = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_1});
+ my $point_2 = get_point($lc);
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point_2});
+ my $point_3 = get_point($lc);
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point_3});
+ my $angle = Angle($x1, $y1, $x2, $y2, $x3, $y3);
+ $angle = 0 if $angle == -500;
+ printf OUT "%%%% angle(%s%s%s) = %.5f deg ( %.5f rad)\n", $point_1,
+ $point_2, $point_3, $angle, $angle*D2R;
+ chk_rparen("Missing right parenthesis", $lc);
+
+ }
+ elsif (s/^\s*(showArea(?=\W))//i)
+ {
+ chk_lparen("showarea",$lc);
+ my $point_1 = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_1});
+ my $point_2 = get_point($lc);
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point_2});
+ my $point_3 = get_point($lc);
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point_3});
+ print OUT "%% area($point_1$point_2$point_3) = ",
+ triangleArea($x1, $y1, $x2, $y2, $x3, $y3), "\n";
+ chk_rparen("Missing right parenthesis", $lc);
+
+ }
+ elsif (s/^\s*(showLength(?=\W))//i)
+ {
+ chk_lparen("showlength",$lc);
+ my $point_1 = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_1});
+ my $point_2 = get_point($lc);
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point_2});
+ print OUT "%% length($point_1$point_2) = ",
+ Length($x1, $y1, $x2, $y2), "\n";
+ chk_rparen("Missing right parenthesis", $lc);
+
+
+ }
+ elsif (/^\s*showPoints(?=\W)/i)
+ {
+ print OUT "%%-------------------------------------------------\n";
+ print OUT "%% L I S T O F P O I N T S \n";
+ print OUT "%%-------------------------------------------------\n";
+ foreach my $p (keys(%PointTable)) {
+ my ($x, $y, $pSV, $pS) = unpack("d3A*",$PointTable{$p});
+ printf OUT "%%%%\t%s\t= ( %.5f, %.5f ), LF-radius = %.5f, symbol = %s\n",
+ $p, $x, $y, $pSV, $pS;
+ }
+ print OUT "%%-------------------------------------------------\n";
+ print OUT "%% E N D O F L I S T O F P O I N T S \n";
+ print OUT "%%-------------------------------------------------\n";
+ next LINE;
+ }
+ elsif (/^\s*showVariables(?=\W)/i)
+ {
+ print OUT "%%-------------------------------------------------\n";
+ print OUT "%% L I S T O F V A R I A B L E S \n";
+ print OUT "%%-------------------------------------------------\n";
+ foreach my $var (keys(%VarTable)) {
+ print OUT "%%\t", $var, "\t=\t", $VarTable{$var}, "\n";
+ }
+ print OUT "%%-------------------------------------------------\n";
+ print OUT "%% E N D O F L I S T O F V A R I A B L E S \n";
+ print OUT "%%-------------------------------------------------\n";
+ next LINE;
+ }
+ elsif (s/^\s*(system(?=\W))//i)
+ {
+ print OUT "%% $1$_" if $comments_on;
+
+ chk_lparen("$cmd",$lc);
+ my ($error, $command, $rest) = get_string($_);
+ next LINE if $error == 1;
+ $_ = $rest;
+ if (! is_tainted($command)) {
+ system($command);
+ }
+ else {
+ PrintErrorMessage("String \"$command\" has tainted data", $lc);
+ next LINE;
+ }
+ chk_rparen("after $cmd arguments",$lc);
+ chk_comment("after $cmd command",$lc);
+
+ }
+ elsif (s/^\s*(text(?=\W))//i)
+ {
+ print OUT "%% $1$_" if $comments_on;
+
+ chk_lparen("text",$lc);
+ my ($level,$text)=(1,"");
+ TEXTLOOP: while (1)
+ {
+ $level++ if /^\(/;
+ $level-- if /^\)/;
+ s/^(.)//;
+ last TEXTLOOP if $level==0;
+ $text .= $1;
+ }
+ chk_lcb("text part",$lc);
+ my ($Px, $Py,$dummy,$pos);
+ $pos="";
+ s/\s*//;
+
+ if (/^[^\W\d_]\d{0,4}\s*[^,\w]/) {
+ my $Tcoord = get_point($lc);
+ my ($x,$y,$pSV,$pS)=unpack("d3A*",$PointTable{$Tcoord});
+ $Px = $x;
+ $Py = $y;
+ }
+ elsif (/[^\W\d_]\d{0,4}\s*,\s*shift|polar/i) {
+ s/^([^\W\d_]\d{0,4})//i;
+ my $PointA = $1;
+ if (exists($PointTable{lc($PointA)})) {
+ s/\s*//;
+ if (s/^,//) {
+ s/\s*//;
+ if (s/^shift(?=\W)//i) {
+
+ chk_lparen("shift",$lc);
+ my $dist1 = expr($lc);
+ chk_comma($lc);
+ my $dist2 = expr($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{lc($PointA)});
+ $Px = $x1 + $dist1;
+ $Py = $y1 + $dist2;
+ chk_rparen("shift part",$lc);
+
+ }
+ elsif (s/^polar(?=\W)//i) {
+ chk_lparen("polar",$lc);
+ my ($R1, $Theta1);
+ $R1 = expr($lc);
+ chk_comma($lc);
+ $Theta1 = expr($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{lc($PointA)});
+ s/\s*//;
+ if (s/^rad(?=\W)//i) {
+ # do nothing!
+ }
+ elsif (s/^deg(?=\W)//i) {
+ $Theta1 = $Theta1 * PI / 180;
+ }
+ else {
+ #$Theta1 = $Theta1 * PI / 180;
+ }
+ $Px = $x1 + $R1 * cos($Theta1);
+ $Py = $y1 + $R1 * sin($Theta1);
+ chk_rparen("after polar part",$lc);
+
+ }
+ }
+ }
+ else {
+ PrintErrorMessage("undefined point/var",$lc);
+ next LINE;
+ }
+ }
+ else {
+ $Px = expr();
+ chk_comma($lc);
+ $Py = expr();
+ }
+
+ chk_rcb("coordinates part of text command",$lc);
+ if (s/^\[//)
+ {
+ s/\s*//;
+
+ if (s/^(\w{1})\s*//) {
+ $pos .= $1;
+ if (memberOf($pos, "l", "r")) {
+ if (s/^(\w{1})\s*//) {
+ my $np = $1;
+ if (memberOf($np, "t", "b", "B")) {
+ $pos .= $np;
+ }
+ else {
+ if (memberOf($np, "l", "r")) {
+ PrintErrorMessage("$np can't follow 'l' or 'r'", $lc);
+ }
+ else {
+ PrintErrorMessage("$np is not a valid positioning option", $lc);
+ }
+ next LINE;
+ }
+ }
+ }
+ elsif (memberOf($pos, "t", "b", "B")) {
+ if (s/^(\w{1})\s*//) {
+ my $np = $1;
+ if (memberOf($np, "l", "r")) {
+ $pos .= $np;
+ }
+ else {
+ if (memberOf($np, "t", "b", "B")) {
+ PrintErrorMessage("$np can't follow 't', 'b', or 'B'", $lc);
+ }
+ else {
+ PrintErrorMessage("$np is not a valid positioning option", $lc);
+ }
+ next LINE;
+ }
+ }
+ }
+ else {
+ PrintErrorMessage("$pos is not a valid positioning option", $lc);
+ next LINE;
+ }
+ }
+ else {
+ PrintErrorMessage("illegal token in optional part of text command",$lc);
+ next LINE;
+ }
+
+ s/\s*//;
+ chk_rsb("optional part of text command",$lc);
+ }
+ chk_comment($lc);
+ if ($pos eq "")
+ {
+ printf OUT "\\put {%s} at %f %f\n", $text, $Px, $Py;
+ }
+ else
+ {
+ printf OUT "\\put {%s} [%s] at %f %f\n", $text, $pos, $Px, $Py;
+ }
+
+ }
+ elsif (s/^\s*(var(?=\W))//i)
+ {
+ print OUT "%% $1$_" if $comments_on;
+ do{
+ s/\s*//;
+ PrintErrorMessage("no identifier found after token var",$lc)
+ if $_ !~ s/^([^\W\d_]\d{0,4})//i;
+ my $Varname = $1;
+ my $varname = lc($Varname);
+ if (exists $ConstTable{$varname}) {
+ PrintErrorMessage("Redefinition of constant $varname",$lc);
+ }
+ s/\s*//; #remove leading white space
+ PrintErrorMessage("did not find expected = sign",$lc)
+ if $_ !~ s/^[=]//i;
+ my $val = expr($lc);
+ $VarTable{$varname} = $val;
+ print OUT "%% $Varname = $val\n" if $comments_on;
+ }while (s/^,//);
+ chk_comment($lc);
+ s/\s*//;
+ if (/^[^%]/) {
+ PrintWarningMessage("Trailing text is ignored",$lc);
+ }
+ }
+ elsif (/^\s*\\(.+)/)
+ {
+ my $line = $1;
+ if ($line =~ /^\s+(.+)/)
+ {
+ print OUT " $line\n";
+ }
+ else
+ {
+ print OUT "\\$line\n";
+ }
+ next LINE;
+ }
+ elsif (0==length) #empty line
+ {
+ next LINE;
+ }
+ else {
+ PrintErrorMessage("command not recognized",$lc);
+ next LINE;
+ }
+
+ }
+ }
+ }
+
+
+our $alarm="";
+our $comments_on=1;
+our $out_file="default";
+our $argc=@ARGV;
+if ($argc == 0 || $argc > 5 ){ # no command line arguments or more than 4
+ # arguments
+ die "\nmathspic version $version_number\n" .
+ "Usage: mathspic [-h] [-b] [-c] [-o <out file>] <in file>\n\n";
+}
+else {
+ our $file = "";
+ SWITCHES:
+ while($_ = $ARGV[0]) {
+ shift;
+ if (/^-h$/) {
+ die "\nThis is mathspic version $version_number\n" .
+ "Type \"man mathspic\" for detailed help\n".
+ "Usage:\tmathspic [-h] [-b] [-c] [-o <out file>] <in file>\n" .
+ "\twhere,\n" .
+ "\t[-b]\tenables bell sound if error exists\n" .
+ "\t[-c]\tdisables comments in output file\n" .
+ "\t[-h]\tgives this help listing\n" .
+ "\t[-o]\tcreates specified output file\n\n";
+ }
+ elsif (/^-b$/) {
+ $alarm = chr(7);
+ }
+ elsif (/^-c$/) {
+ $comments_on = 0;
+ }
+ elsif (/^-o$/) {
+ die "No output file specified!\n" if !@ARGV;
+ $out_file = $ARGV[0];
+ shift;
+ }
+ elsif (/^-\w+/) {
+ die "$_: Illegal command line switch!\n";
+ }
+ else {
+ $file = $_;
+ }
+ }my ($xA, $yA, $xB, $yB, $dist)=@_;
+ die "No input file specified!\n" if $file eq "";
+
+ print "This is mathspic version $version_number\n";
+}
+ our ($source_file, $log_file);
+ if (! -e $file) {
+ die "$file: no such file!\n" if (! (-e "$file.m"));
+ $source_file = "$file.m";
+ }
+ else {
+ $source_file = $file;
+ $file = $1 if $file =~ /(\w[\w-\.]+)\.\w+/;
+ }
+ $out_file= "$file.mt" if $out_file eq "default";
+ $log_file= "$file.mlg";
+
+
+ open(IN,"$source_file")||die "Can't open source file: $source_file\n";
+ open(OUT,">$out_file")||die "Can't open output file: $out_file\n";
+ open(LOG,">$log_file")||die "Can't open log file: $log_file\n";
+ print_headers;
+ process_input(IN,"");
+
+print $alarm if $no_errors > 0;
+__END__
+
diff --git a/graphics/mathspic/perl/sourcecode113.html b/graphics/mathspic/perl/sourcecode113.html
new file mode 100644
index 0000000000..b611771f41
--- /dev/null
+++ b/graphics/mathspic/perl/sourcecode113.html
@@ -0,0 +1,5128 @@
+<!-- this file was generated automatically by noweave; better not edit it-->
+<html><head><title>mathsPIC.nw</title></head><body><center><h1> <tt>mathspic</tt> in Perl </h1></center>
+<center><h2>
+<table>
+<tr><td><address>
+<b>Apostolos Syropoulos</b><br>
+366, 28th October Str.<br>
+GR-671 00 Xanthi<br>
+Greece<br>
+email: <tt>asyropoulos@yahoo.com</tt>
+</address></td>
+<td><address>
+<b>R.W.D. Nickalls</b><br/>
+Consultant in Anaesthesia & Intensive Care (retired)<br/>
+c/o Department of Anaesthesia<br/>
+Nottingham University Hospitals<br/>
+<a name="NWDCUvTi-1">City Hospital Campus</a><br/>
+Hucknall Road<br/>
+Nottingham NG5 1PB, UK<br/>
+email:<tt>dick@nickalls.org</tt>
+</address></td>
+</table></h2>
+version 1.13 Apr 26, 2010
+</center>
+
+<h3><b>Introduction</b></h3><p>
+<tt>mathspic</tt> is a graphics program which implements a simple
+programming notation, <i>mathspic</i>, suitable for the
+creation of diagrams or mathematical figures.
+<tt>mathspic</tt>'s input is a LaTeX file containing
+<tt>mathspic</tt> plotting commands.
+<tt>mathspic</tt>'s output is the equivalent LaTeX file
+containing PiCTeX plotting commands.
+Technically, therefore, <tt>mathspic</tt>
+is a preprocessor or `filter' for use with the PiCTeX drawing engine.
+<tt>mathspic</tt> was originally written in PowerBASIC 3.5, a
+DOS-based programming language. Since, many
+potential users are working in rather different programming environments,
+the authors thought of porting <tt>mathspic</tt> into another programming
+cross-platform language which would be widely available.
+The authors decided to rewrite <tt>mathspic</tt> in Perl
+since not only is Perl pretty stable, but it has
+extensive mathematical support.<p>
+
+<h3><b>Program Structure</b></h3><p>
+<a name="NWDCUvTi-2">Initially, we define a little package that is used to implement the </a><code>loop</code>
+command. Then, we must do is to check the possible command line arguments.
+Next, we process the input file.
+If the user has used the <code>-b</code> (see below), the program will `beep'
+if any errors are found during processing.
+We need some auxiliary subroutines in order to properly parse the input
+file and of course to handle the various commands. We also need a
+few global variables.
+
+<pre><a name="NWCUvTi-1p0Y9w-1" href="#NWDCUvTi-2"><dfn>&lt;*&gt;=</dfn></a>
+#!/usr/bin/perl
+#
+#(c) Copyright 2005-2010
+# Apostolos Syropoulos &amp; R.W.D. Nickalls
+# asyropoulos@yahoo.com dick@nickalls.org
+#
+# This program can be redistributed and/or modified under the terms
+# of the LaTeX Project Public License Distributed from CTAN
+# archives in directory macros/latex/base/lppl.txt; either
+# version 1 of the License, or any later version.
+#
+<a name="NWCUvTi-1p0Y9w-1-u1" href="#NWDCUvTi-3"><i>&lt;package <tt>DummyFH</tt> &gt;</i></a>
+package main;
+use Math::Trig;
+<a name="NWCUvTi-1p0Y9w-1-u2" href="#NWDCUvTi-8"><i>&lt;Define global variables&gt;</i></a>
+<a name="NWCUvTi-1p0Y9w-1-u3" href="#NWDCUvTi-9"><i>&lt;subroutine definitions&gt;</i></a>
+<a name="NWCUvTi-1p0Y9w-1-u4" href="#NWDCUvTi-4"><i>&lt;Check for command line arguments&gt;</i></a>
+<a name="NWCUvTi-1p0Y9w-1-u5" href="#NWDCUvTi-7"><i>&lt;process file&gt;</i></a>
+print $alarm if $no_errors &gt; 0;
+__END__
+
+</pre><p><a name="NWDCUvTi-3">The package </a><code>DummyFH</code> is used in the implementation of the <code>loop</code> command.
+It creates a dummy filehandle that is associated with an array of strings. Since
+we only read data from this dummy filehandle, we implement the <code>READLINE</code> subroutine.
+When we read a line from this dummy filehandle, we actually requesting the next entry
+of the array (if any). That is why we use the package variable <code>$index</code>. When there
+are no more entries in the array, subroutine <code>READLINE</code> returns the value <code>undef</code>
+so to falsify loop that controls the consumption of input from this dummy filehandle.
+
+<pre><a name="NWCUvTi-2YwRNH-1" href="#NWDCUvTi-3"><dfn>&lt;package <tt>DummyFH</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-2">&lt;-U</a>)</b>
+package DummyFH;
+my $index = 0;
+sub TIEHANDLE {
+ my $class = shift;
+ my $self= shift;
+ bless $self, $class;
+}
+sub READLINE {
+ my $self = shift;
+ #shift @$self;
+ if ($index &gt; $#$self) {
+ $index = 0;
+ return undef;
+ }
+ else {
+ return $self-&gt;[$index++];
+ }
+}
+
+</pre><p><tt>mathspic</tt> accepts at most four command-line switches, namely
+<tt>-b</tt> for enabling the beep, <tt>-s</tt> for automatic
+screen viewing of the output-file,
+<tt>-c</tt> for cleaning out all comment-lines,
+and <tt>-o</tt> with a following file-name
+for specifying the output file-name.
+<tt><a name="NWDCUvTi-4">mathspic</a></tt> requires the name of an existing input-file
+(the so-called <tt>mathspic</tt>-file) containing
+<tt>mathspic</tt>commands.
+If no command-line arguments are supplied, we print a
+suitable usage message indicating the syntax.
+For each command-line argument we set a global
+variable. The default behavior is that the `bell' does not beep
+and comment-lines are not removed from the output-file.
+
+<pre><a name="NWCUvTi-122Dzz-1" href="#NWDCUvTi-4"><dfn>&lt;Check for command line arguments&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-2">&lt;-U</a>)</b>
+our $alarm=&quot;&quot;;
+our $comments_on=1;
+our $out_file=&quot;default&quot;;
+our $argc=@ARGV;
+if ($argc == 0 || $argc &gt; 5 ){ # no command line arguments or more than 4
+ # arguments
+ die &quot;\nmathspic version $version_number\n&quot; .
+ &quot;Usage: mathspic [-h] [-b] [-c] [-o &lt;out file&gt;] &lt;in file&gt;\n\n&quot;;
+}
+else {
+ <a name="NWCUvTi-122Dzz-1-u1" href="#NWDCUvTi-5"><i>&lt;Process command line arguments&gt;</i></a>
+ print &quot;This is mathspic version $version_number\n&quot;;
+}
+<a name="NWCUvTi-122Dzz-1-u2" href="#NWDCUvTi-6"><i>&lt;Check if .m file exists&gt;</i></a>
+
+</pre><p><a name="NWDCUvTi-5">In order to get the various command-line arguments we use a simple</a>
+<code>while</code> loop that checks each element of the array <code>@ARGV</code>. We check
+for all the switches, and we get the name of the input-file.
+
+<pre><a name="NWCUvTi-LnOV9-1" href="#NWDCUvTi-5"><dfn>&lt;Process command line arguments&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-4">&lt;-U</a>)</b>
+ our $file = &quot;&quot;;
+ SWITCHES:
+ while($_ = $ARGV[0]) {
+ shift;
+ if (/^-h$/) {
+ die &quot;\nThis is mathspic version $version_number\n&quot; .
+ &quot;Type \&quot;man mathspic\&quot; for detailed help\n&quot;.
+ &quot;Usage:\tmathspic [-h] [-b] [-c] [-o &lt;out file&gt;] &lt;in file&gt;\n&quot; .
+ &quot;\twhere,\n&quot; .
+ &quot;\t[-b]\tenables bell sound if error exists\n&quot; .
+ &quot;\t[-c]\tdisables comments in ouput file\n&quot; .
+ &quot;\t[-h]\tgives this help listing\n&quot; .
+ &quot;\t[-o]\tcreates specified output file\n\n&quot;;
+ }
+ elsif (/^-b$/) {
+ $alarm = chr(7);
+ }
+ elsif (/^-c$/) {
+ $comments_on = 0;
+ }
+ elsif (/^-o$/) {
+ die &quot;No output file specified!\n&quot; if !@ARGV;
+ $out_file = $ARGV[0];
+ shift;
+ }
+ elsif (/^-\w+/) {
+ die &quot;$_: Illegal command line switch!\n&quot;;
+ }
+ else {
+ $file = $_;
+ }
+ }my ($xA, $yA, $xB, $yB, $dist)=@_;
+ die &quot;No input file specified!\n&quot; if $file eq &quot;&quot;;
+
+</pre><p><a name="NWDCUvTi-6">In order to check whether the input-file exists, we simply use the</a>
+<code>-e</code> operator. First we check to see if <code>$file</code> exits.
+If the input-file does exist then the variable <code>$file</code> contains
+the file name. In case the user has not specified an output
+file, the default output file name is the name of the input file with
+extension <code>.mt</code>. Finally, the program outputs all error messages to
+the screen and to a log file. The name of the log file consists of
+the contents of the variable <code>$file</code> and the extension <code>.mlg</code>.
+
+<pre><a name="NWCUvTi-2K3CIm-1" href="#NWDCUvTi-6"><dfn>&lt;Check if .m file exists&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-4">&lt;-U</a>)</b>
+ our ($source_file, $log_file);
+ if (! -e $file) {
+ die &quot;$file: no such file!\n&quot; if (! (-e &quot;$file.m&quot;));
+ $source_file = &quot;$file.m&quot;;
+ }
+ else {
+ $source_file = $file;
+ $file = $1 if $file =~ /(\w[\w-\.]+)\.\w+/;
+ }
+ $out_file= &quot;$file.mt&quot; if $out_file eq &quot;default&quot;;
+ $log_file= &quot;$file.mlg&quot;;
+
+</pre><p><a name="NWDCUvTi-7">Now that we have all the command line arguments, we can start processing</a>
+the input file. This is done by calling the subroutine <code>process_input</code>.
+Before that we must open all necessary files. Next,
+we print some `header' information to the output file and to the log file.
+
+<pre><a name="NWCUvTi-EP1QE-1" href="#NWDCUvTi-7"><dfn>&lt;process file&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-2">&lt;-U</a>)</b>
+ open(IN,&quot;$source_file&quot;)||die &quot;Can't open source file: $source_file\n&quot;;
+ open(OUT,&quot;&gt;$out_file&quot;)||die &quot;Can't open output file: $out_file\n&quot;;
+ open(LOG,&quot;&gt;$log_file&quot;)||die &quot;Can't open log file: $log_file\n&quot;;
+ print_headers;
+ process_input(IN,&quot;&quot;);
+
+</pre><p>In this section we define a few global variables. More specifically:
+the variable <code>$version_number</code> contains the current version number of the
+program, the variable <code>$commandLineArgs</code> contains the command line arguments.
+These two variables are used in the <code>print_headers</code> subroutine.
+The variable <code>$command</code> will contain the whole current input line.
+Hash <code>%PointTable</code> is used to store point names and related
+information. Hash <code>%VarTable</code> is used to store mathspic variable names
+and related information, while the associative array <code>%ConstTable</code> contains the
+names of constants. Note that the values of both constants and variables are
+kept in <code>%VarTable</code>.
+The variable <code>$no_errors</code> is incremented whenever the
+program encounters an error in the input file. The variables <code>$xunits</code>,
+<code>$yunits</code> and <code>$units</code> are related to the <code>paper</code> command.
+In particular, the variable <code>$units</code> is used to parse the unit part of the
+<code>unit</code> part of the <code>paper</code> command. The variable <code>$defaultsymbol</code> is used to
+set the point shape. The constant <code>PI</code> holds the value of the mathematical
+ constant pi.
+The constant <code>R2D</code> holds the transformation factor to transform radians to
+degrees. The constant <code>D2R</code> holds the transformation factor
+to transform degrees to radians, i.e., the value <code>1/R2D</code>. The global variables
+<code>$arrowLength</code>, <code>$arrowAngleB</code> and <code>$arrowAngleC</code> are actually parameters that
+<a name="NWDCUvTi-8">are used by the subroutines that draw arrows. Since </a><code>$arrowLength</code> is actually
+a length, variable <code>$arrowLenghtUnits</code> holds the units of measure in which
+this length is expressed. The hash table <code>%DimOfPoint</code> contains the side or the
+radius of a point whose plot-symbol is a square or a circle, respectively. In case the
+default point symbol is a circle or a square, variable <code>$GlobalDimOfPoints</code> is used
+to store the length of the radius or the length of the side of default point symbol,
+respectively. Variable <code>$LineThickness</code> holds the current line thickness (the
+default value is 0.4&nbsp;pt).
+
+<pre><a name="NWCUvTi-xIn58-1" href="#NWDCUvTi-8"><dfn>&lt;Define global variables&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-2">&lt;-U</a>)</b>
+our $version_number = &quot;1.13 Apr 26, 2010&quot;;
+our $commandLineArgs = join(&quot; &quot;, @ARGV);
+our $command = &quot;&quot;;
+our $curr_in_file = &quot;&quot;;
+our %PointTable = ();
+our %VarTable = ();
+our %ConstTable = ();
+our $no_errors = 0;
+our $xunits = &quot;1pt&quot;;
+our $yunits = &quot;1pt&quot;;
+our $units = &quot;pt|pc|in|bp|cm|mm|dd|cc|sp&quot;;
+our $defaultsymbol = &quot;\$\\bullet\$&quot;;
+our $defaultLFradius = 0;
+use constant PI =&gt; atan2(1,1)*4;
+use constant R2D =&gt; 180 / PI;
+use constant D2R =&gt; PI / 180;
+our $arrowLength = 2;
+our $arrowLengthUnits = &quot;mm&quot;;
+our $arrowAngleB = 30;
+our $arrowAngleC = 40;
+our %DimOfPoint = ();
+our $GlobalDimOfPoints = 0;
+our @Macros = ();
+our $LineThickness = 0.4;
+
+</pre><p>In this section we define the various subroutines that are needed in order
+to process the input file.
+
+<p> Subroutine <tt>mpp</tt> is a mathspic preprocessor that allows the definition
+and use of macros with or without arguments. For the moment it is an experimental
+feature and it should be used with care.
+
+<p> Subroutine <tt>PrintErrorMessage</tt> is used to print error messages
+to the screen, to the output file and to the log file.
+
+<p> Subroutine <tt>PrintWarningMessage</tt> is used to print warning messages
+to the screen, to the output file and to the log file.
+
+<p> Subroutine <tt>PrintFatalError</tt> is used to print an error message
+to the screen and to abort execution, where the error is considered fatal
+and not recoverable.
+
+<p>Subroutine <tt>chk_lparen</tt> checks whether the next input
+character is a left parenthesis. Subroutine <tt>chk_rparen</tt>
+checks whether the next input character is a right parenthesis. Subroutine
+<tt>chk_comment</tt> checks whether a given command is followed by a trailing
+comment. In the same spirit, we define the subroutines <tt>chk_lcb</tt>,
+<tt>chk_rcb</tt>, <tt>chk_lsb</tt>, and <tt>chk_rsb</tt> which check for
+opening and closing curly and square brackets respectively.
+The subroutine <code>chk_comma</code> checks whether the next token is a comma.
+
+<p> Subroutine <code>print_headers</code> is used to print a header to the output file,
+so a user knows that the file has been generated by <tt>mathspic</tt>.
+
+<p> Subroutine <code>get_point</code> is used to parse a point name and to
+check whether the point exists (i.e whether the point has been defined).
+
+<p> Subroutine <code>perpendicular</code> is used to compute the coordinates of the
+foot of perpendicular line from some point P to a line AB.
+
+<p> Subroutine <code>Length</code> is used to compute the distance between two
+points A and B.
+
+<p> Subroutine <code>triangleArea</code> computes the area of a triangle defined
+by three points.
+
+<p> Subroutine <code>PointOnLine</code> is used to compute the coordinates of
+a point on a line segment AB and a distance d units from A towards B.
+
+<p> Subroutine <code>circumCircleCenter</code> takes six arguments that are the
+coordinates of three points and computes the center of the circle that
+passes through the three points which define the triangle.
+
+<p> Subroutine <code>ComputeDist</code> is used to compute a numeric value that is
+specified by either a variable name, a pair of points, or just a number.
+
+<p> Subroutine <code>intersection4points</code> is used to compute the coordinates
+of the point of intersection of two lines specified by the four arguments
+(i.e. two arguments for each point).
+
+<p> Subroutine <code>IncircleCenter</code> is used to compute the center and
+the radius of a circle that touches internally the sides of a triangle,
+the coordinates of the three points which define the triangle
+being the arguments of the subroutine.
+
+<p> Subroutine <code>Angle</code> determines the opening in degrees of an angle
+defined by three points which are the arguments of this subroutine.
+
+<p> Subroutine <code>excircle</code> computes the center and the radius of
+a circle that externally touches a given side (4th and 5th arguments) of
+triangle (determined by the 1st, the 2nd and the 3rd argument).
+
+<p> Subroutine <code>DrawLineOrArrow</code> is used to parse the arguments of the commands
+ <code>drawline</code>, <code>drawthickline</code>, <code>drawarrow</code>, <code>drawthickarrow</code> and
+ <code>drawCurve</code>.
+
+<p> Subroutine <code>drawarrows</code> is used to draw one or more arrows between points.
+
+<p> Subroutine <code>drawlines</code> is used to draw one or more lines between points.
+
+<p> Subroutine <code>drawCurve</code> is used to draw a curve between an odd number of points.
+
+<p> Subroutine <code>drawpoints</code> is used to draw the point symbol of one or more points.
+
+<p> Subroutine <code>drawAngleArc</code> is used to draw an arc line within an angle.
+
+<p> Subroutine <code>drawAngleArrow</code> is used to draw an arc line with an arrow on the end,
+within an angle.
+
+<p> Subroutine <code>expr</code> and subroutines <code>term</code>, <code>factor</code> and
+<code>primitive</code> are used to parse an expression that follows a variable
+declaration.
+
+<p> Subroutine <code>memberOf</code> is used to determine whether a string is a
+member of a list of strings.
+
+<p> Subroutine <code>midpoint</code> computes the midpoint of two points.
+
+<p> Subroutine <code>tand</code> computes the tangent of an angle, where the
+angle is expressed in degrees.
+
+<p> Subroutine <code>get_string</code> scans a string in order to extract a
+valid mathspic string.
+
+<p> Subroutine <code>is_tainted</code> checks whether a string contains data that
+may be proved harmful if used as arguments to a shell escape.
+
+<p> Subroutine <code>noOfDigits</code> has one argument which is a number and
+returns the number of decimal digits it has.
+
+<p> Subroutine <code>drawsquare</code> has one argument which is the radius of point
+and yields LaTeX code that draws a square.
+
+<p> Subroutine <code>X2sp</code> can be used to transform a length to sp units.
+
+<p> <a name="NWDCUvTi-9">Subroutine </a><code>sp2X</code> can be used to transform a length expressed in sp units
+ to any other acceptable unit.
+
+<p> Subroutine <code>setLineThickness</code> is used to determine the length of the
+ linethickness in the current paper units.
+
+<p> Subroutine <code>process_input</code> parses the input file and any other file
+ being included in the main file, and generates output.
+
+<pre><a name="NWCUvTi-2AA3uL-1" href="#NWDCUvTi-9"><dfn>&lt;subroutine definitions&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-2">&lt;-U</a>)</b>
+ <a name="NWCUvTi-2AA3uL-1-u1" href="#NWDCUvTi-A"><i>&lt;subroutine <tt>mpp</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u2" href="#NWDCUvTi-B"><i>&lt;subroutine <tt>PrintErrorMessage</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u3" href="#NWDCUvTi-C"><i>&lt;subroutine <tt>PrintWarningMessage</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u4" href="#NWDCUvTi-D"><i>&lt;subroutine <tt>PrintFatalError</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u5" href="#NWDCUvTi-E"><i>&lt;subroutine <tt>chk_lparen</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u6" href="#NWDCUvTi-F"><i>&lt;subroutine <tt>chk_rparen</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u7" href="#NWDCUvTi-G"><i>&lt;subroutine <tt>chk_lcb</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u8" href="#NWDCUvTi-H"><i>&lt;subroutine <tt>chk_rcb</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u9" href="#NWDCUvTi-I"><i>&lt;subroutine <tt>chk_lsb</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u10" href="#NWDCUvTi-J"><i>&lt;subroutine <tt>chk_rsb</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u11" href="#NWDCUvTi-K"><i>&lt;subroutine <tt>chk_comma</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u12" href="#NWDCUvTi-L"><i>&lt;subroutine <tt>chk_comment</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u13" href="#NWDCUvTi-M"><i>&lt;subroutine <tt>print_headers</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u14" href="#NWDCUvTi-N"><i>&lt;subroutine <tt>get_point</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u15" href="#NWDCUvTi-O"><i>&lt;subroutine <tt>perpendicular</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u16" href="#NWDCUvTi-P"><i>&lt;subroutine <tt>Length</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u17" href="#NWDCUvTi-Q"><i>&lt;subroutine <tt>triangleArea</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u18" href="#NWDCUvTi-R"><i>&lt;subroutine <tt>pointOnLine</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u19" href="#NWDCUvTi-S"><i>&lt;subroutine <tt>circumCircleCenter</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u20" href="#NWDCUvTi-T"><i>&lt;subroutine <tt>ComputeDist</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u21" href="#NWDCUvTi-U"><i>&lt;subroutine <tt>intersection4points</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u22" href="#NWDCUvTi-V"><i>&lt;subroutine <tt>IncircleCenter</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u23" href="#NWDCUvTi-W"><i>&lt;subroutine <tt>Angle</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u24" href="#NWDCUvTi-X"><i>&lt;subroutine <tt>excircle</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u25" href="#NWDCUvTi-Y"><i>&lt;subroutine <tt>DrawLineOrArrow</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u26" href="#NWDCUvTi-Z"><i>&lt;subroutine <tt>drawarrows</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u27" href="#NWDCUvTi-a"><i>&lt;subroutine <tt>drawlines</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u28" href="#NWDCUvTi-b"><i>&lt;subroutine <tt>drawCurve</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u29" href="#NWDCUvTi-c"><i>&lt;subroutine <tt>drawpoints</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u30" href="#NWDCUvTi-d"><i>&lt;subroutine <tt>drawAngleArc</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u31" href="#NWDCUvTi-e"><i>&lt;subroutine <tt>drawAngleArrow</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u32" href="#NWDCUvTi-f"><i>&lt;subroutine <tt>expr</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u33" href="#NWDCUvTi-g"><i>&lt;subroutine <tt>memberOf</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u34" href="#NWDCUvTi-h"><i>&lt;subroutine <tt>midpoint</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u35" href="#NWDCUvTi-i"><i>&lt;subroutine <tt>tand</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u36" href="#NWDCUvTi-j"><i>&lt;subroutine <tt>get_string</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u37" href="#NWDCUvTi-k"><i>&lt;subroutine <tt>is_tainted</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u38" href="#NWDCUvTi-l"><i>&lt;subroutine <tt>noOfDigits</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u39" href="#NWDCUvTi-m"><i>&lt;subroutine <tt>drawsquare</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u40" href="#NWDCUvTi-n"><i>&lt;subroutine <tt>X2sp</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u41" href="#NWDCUvTi-o"><i>&lt;subroutine <tt>sp2X</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u42" href="#NWDCUvTi-p"><i>&lt;subroutine <tt>setLineThickness</tt> &gt;</i></a>
+ <a name="NWCUvTi-2AA3uL-1-u43" href="#NWDCUvTi-q"><i>&lt;subroutine <tt>process_input</tt> &gt;</i></a>
+
+</pre><p>Subroutine <tt>mpp</tt> is an implementation of a mathspic preprocessor that allows
+the definition of one-line macros with or without arguments. Macro definition has the
+following syntax:
+<center>
+ <tt>"%def" macro_name "(" [ parameters ] ")" macro_code
+</center>
+where parameters is a list of comma separated strings (e.g., x,y,z). Once a macro is
+defined it can be used or it can be undefined. To undefine a macro one has to use
+the following command:
+<center>
+ <tt>"%undef" [ macro_name ]
+</center
+This means that an undef command without an accompanying macro name has no effect
+at all. In order to use a macro we simply type its name and its arguments in
+parentheses. Note that macro arguments should not contain spaces. If a macro has no
+argument, there is no need to type any parentheses. We will now describe briefly how
+the macro processor operates.
+<p> If the current input line starts with <tt>%def</tt>, then we assume that we have
+a macro definition. We parse each component of the macro definition and finally we
+store the macro name, the macro code and the macro parameters (if any) in an anonymous
+hash that eventually becomes part of an array. If we encounter any error, we simply
+<a name="NWDCUvTi-A">skip to the next line after printing a suitable error message. Now, if the first tokens</a>
+of an input line are <tt>%undef</tt>, we assume the user wants to delete a macro.
+In case these tokens are not followed by a macro name or the macro name has not been
+defined we simply go on. Otherwise, we delete the corresponding macro data from the
+global array <code>@Macros</code> that contains all the macro information. Macro expansion is
+more difficult and it will be described in detail in a separate document. At this point
+we would like to thank Joachim Schneider <joachim at hal dot rhein-necker dot de>
+for a suggestion on improving macro expansion.
+
+<pre><a name="NWCUvTi-2rq75n-1" href="#NWDCUvTi-A"><dfn>&lt;subroutine <tt>mpp</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+sub mpp {
+ my $in_line;
+ chomp($in_line = shift);
+ my $LC = shift;
+ my $out_line = $in_line;
+ my $macro_name = &quot;&quot;;
+ my @macro_param = ();
+ my $macro_code = &quot;&quot;;
+ if ($in_line =~ s/^%def\s*//) {
+ if ($in_line =~ s/^(\w+)\s*//){
+ $macro_name = $1;
+ }
+ else {
+ PrintErrorMessage(&quot;No macro name has been found&quot;,$LC);
+ return &quot;&quot;
+ }
+ if ($in_line =~ s/^\(\s*//) {
+ # do nothing
+ }
+ else {
+ PrintErrorMessage(&quot;No left parenthesis after macro name has been found&quot;,$LC);
+ return &quot;&quot;;
+ }
+ if ($in_line =~ s/^\)//) {
+ # Macro has no parameters!
+ }
+ else {
+ MACROS: while (1) {
+ if ($in_line =~ s/^(\w+)\s*//) {
+ push (@macro_param, $1);
+ }
+ else {
+ PrintErrorMessage(&quot;No macro parameter name has been found&quot;,$LC);
+ return &quot;&quot;;
+ }
+ if ($in_line =~ s/^,\s*//) {
+ next MACROS;
+ }
+ else {
+ last MACROS;
+ }
+ }
+ if ($in_line =~ s/^\)//) {
+ # do nothing!
+ }
+ else {
+ PrintErrorMessage(&quot;No closing parenthesis after macro parameters&quot;,$LC);
+ return &quot;&quot;;
+ }
+ }
+ $in_line =~ s/([^%]+)(%.*)/$1/;
+ $macro_code = $in_line;
+ push ( @Macros , { 'macro_name' =&gt; $macro_name,
+ 'macro_code' =&gt; $macro_code,
+ 'macro_param' =&gt; \@macro_param });
+ return $out_line;
+ }
+ elsif ($in_line =~ s/^%undef\s*//) {
+ if ($in_line =~ s/^(\w+)//) {
+ my $undef_macro = $1;
+ for(my $i = $#Macros; $i &gt;= 0; $i--) {
+ if ($Macros[$i]-&gt;{'macro_name'} eq $undef_macro) {
+ splice(@Macros,$i,1);
+ }
+ }
+ }
+ return $out_line;
+ }
+ elsif ($in_line =~ s/^\s*%//) {
+ return $out_line;
+ }
+ else {
+ my $comment = $2 if $in_line =~ s/([^%]+)(%.+)/$1/;
+ EXPANSIONLOOP: while () {
+ my $org_in_line = $in_line;
+ for(my $i = $#Macros; $i &gt;= 0; $i--) {
+ my $macro_name = $Macros[$i]-&gt;{'macro_name'};
+ if ($in_line =~ /&amp;$macro_name\b/) { ############################
+ my $num_of_macro_args = @{$Macros[$i]-&gt;{'macro_param'}};
+ if ( $num_of_macro_args &gt; 0 ) {
+ # Macro with parameters
+ my $pattern = &quot;&amp;$macro_name\\(&quot;;
+ foreach my $p ( 1..$num_of_macro_args ) {
+ my $comma = ($p == $num_of_macro_args) ? &quot;\\s*&quot; : &quot;\\s*,\\s*&quot;;
+ $pattern .= &quot;\\s*[^\\s\\)]+$comma&quot;;
+ }
+ $pattern .= &quot;\\)&quot;;
+ while($in_line =~ /&amp;$macro_name\b/) {
+ if ($in_line =~ /$pattern/) {
+ my $before = $`;
+ my $after = $';
+ my $match = $&amp;;
+ my $new_code = $Macros[$i]-&gt;{'macro_code'};
+ $match =~ s/^&amp;$macro_name\(\s*//;
+ $match =~ s/\)$//;
+ foreach my $arg ( 0..($num_of_macro_args - 1) ) {
+ my $old = $Macros[$i]-&gt;{'macro_param'}-&gt;[$arg];
+ my $comma = ($arg == ($num_of_macro_args - 1)) ? &quot;&quot; : &quot;,&quot;;
+ $match =~ s/^\s*([^\s,]+)\s*$comma//;
+ my $new = $1;
+ # 'g': Parameter may occur several times
+ # in $new_code.
+ # '\b': Substitute only whole words
+ # not x in xA
+ $new_code =~ s/\b$old\b/$new/g;
+ }
+ $in_line = &quot;$before$new_code$after&quot;;
+ }
+ else {
+ PrintErrorMessage(&quot;Usage of macro &amp;$macro_name does not &quot; .
+ &quot;match its definition&quot;, $LC);
+ return &quot;&quot;;
+ }
+ }
+ }
+ else {
+ # Macro without parameters
+ my $replacement = $Macros[$i]-&gt;{'macro_code'};
+ # '\b': Substitute only whole words
+ # not x in xA
+ $in_line =~ s/&amp;$macro_name\b/$replacement/g;
+ }
+ }
+ }
+ last EXPANSIONLOOP if ( $org_in_line eq $in_line );
+ }
+ return &quot;$in_line$comment&quot;;
+ }
+}
+
+</pre><p>Subroutine <tt>PrintErrorMessage</tt> has two parameters: the
+error message that will be printed on the screen, the log file and
+the output file, and the line number of the line containing the
+error was detected.
+The general form of the error message is the following:
+<pre>
+line X: paper{units(
+ ,mm)xrange(0,20)yrange(0,30)axes(B)ticks(10,10)}
+
+***Error: Error_Message
+</pre>
+where <code>X</code> denotes the line number and <code>Error_Message</code> is the
+actual error message. Note, that we print the tokens processed so far
+and on the text line the unprocessed tokens, so that the user knows
+<a name="NWDCUvTi-B">exactly where the error is. In the variable </a><code>$A</code> we store the processed
+tokens, while the variable <code>$l</code> holds the length of <code>$A</code> plus the
+length of the <code>$error_line</code> (that is the number of the input line where
+the error occurred) plus 7, i.e., 4 (the length of the word
+<code>line</code>) plus 2 (the two blank spaces) plus 1 (the symbol <code>:</code>).
+Finally, we increment the error counter (variable <code>$no_errors</code>). Note, that
+in case the user has specified the <code>-c</code> command line switch, we will not
+print any messages to the output file.
+
+<pre><a name="NWCUvTi-1m1522-1" href="#NWDCUvTi-B"><dfn>&lt;subroutine <tt>PrintErrorMessage</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+ sub PrintErrorMessage {
+ my $errormessage = shift;
+ my $error_line = shift;
+ my ($l,$A);
+ $l = 1+length($command)-length;
+ $A = substr($command,0,$l);
+ $l += 7 +length($error_line);
+
+ for my $fh (STDOUT, LOG) {
+ print $fh &quot;$curr_in_file&quot;, &quot;Line $error_line: $A\n&quot;;
+ print $fh &quot; &quot; x $l ,$_,&quot;***Error: $errormessage\n&quot;;
+ }
+ if ($comments_on) { #print to output file file
+ print OUT &quot;%% *** $curr_in_file&quot;, &quot;Line $error_line: $A\n&quot;;
+ print OUT &quot;%% *** &quot;,&quot; &quot; x $l ,$_,&quot;%% ... Error: $errormessage\n&quot;;
+ }
+ $no_errors++;
+ }
+
+</pre><p><a name="NWDCUvTi-C">Subroutine </a><tt>PrintWarningMessage</tt> behaves exactly like the subroutine
+<tt>PrintErrorMessage</tt>. The only difference is that the second
+subroutine prints only a warning message. A warning is issued when
+the system detects parameters that do nothing.
+
+<pre><a name="NWCUvTi-3Lpu7M-1" href="#NWDCUvTi-C"><dfn>&lt;subroutine <tt>PrintWarningMessage</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+ sub PrintWarningMessage {
+ my $warningMessage = shift;
+ my $warning_line = shift;
+ my ($l,$A);
+ $l = 1+length($command)-length;
+ $A = substr($command,0,$l);
+ $l += 7 +length($warning_line);
+
+ for my $fh (STDOUT, LOG) {
+ print $fh &quot;$curr_in_file&quot;, &quot;Line $warning_line: $A\n&quot;;
+ print $fh &quot; &quot; x $l ,$_,&quot;***Warning: $warningMessage\n&quot;;
+ }
+ if ($comments_on) { #print to output file file
+ print OUT &quot;%% *** $curr_in_file&quot;, &quot;Line $warning_line: $A\n&quot;;
+ print OUT &quot;%% *** &quot;,&quot; &quot; x $l ,$_,&quot;%% ... Warning: $warningMessage\n&quot;;
+ }
+ }
+
+</pre><p><a name="NWDCUvTi-D">The subroutine </a><tt>PrintFatalError</tt> behaves similarly to the subroutine
+<tt>PrintErrorMessage</tt>. It prints an error message to the
+screen and aborts execution.
+
+<pre><a name="NWCUvTi-4RPeBe-1" href="#NWDCUvTi-D"><dfn>&lt;subroutine <tt>PrintFatalError</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+ sub PrintFatalError {
+ my $FatalMessage = shift;
+ my $fatal_line = shift;
+ my ($l,$A);
+ $l = 1+length($command)-length;
+ $A = substr($command,0,$l);
+ $l += 7 +length($fatal_line);
+
+ die &quot;$curr_in_file&quot;, &quot;Line $fatal_line: $A\n&quot; .
+ (&quot; &quot; x $l) . $_ . &quot;***Fatal Error: $FatalMessage\n&quot;;
+ }
+
+</pre><p><a name="NWDCUvTi-E">The subroutine </a><tt>chk_lparen</tt> accepts two arguments: the name
+of the token that should be immediately before the left parenthesis (variable
+<code>$token</code>), and the current line number (variable <code>$lc</code>). First we
+skip any leading white space and then check whether the next
+input character is a left parenthesis, then the subroutine skips any
+trailing white space; otherwise it prints an error message.
+
+<pre><a name="NWCUvTi-4Y5BUt-1" href="#NWDCUvTi-E"><dfn>&lt;subroutine <tt>chk_lparen</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+sub chk_lparen {
+ my $token = $_[0];
+ my $lc = $_[1];
+ s/\s*//;
+ if (/^[^\(]/) {
+ PrintErrorMessage(&quot;Missing ( after $token&quot;,$lc);
+ }
+ else {
+ s/^\(\s*//;
+ }
+}
+
+</pre><p><a name="NWDCUvTi-F">The subroutine </a><tt>chk_rparen</tt> accepts two parameters: the name
+of the token that should be immediately after a right parenthesis (variable
+<code>$token</code>), and the current line number (variable <code>$lc</code>). Initially, we
+skip any leading white space and then we check whether the next input
+token is a right parenthesis. If it is not we issue a error message and
+return, otherwise we skip the parenthesis and any trailing white space.
+
+<pre><a name="NWCUvTi-3fTYkz-1" href="#NWDCUvTi-F"><dfn>&lt;subroutine <tt>chk_rparen</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+sub chk_rparen {
+ my $token = $_[0];
+ my $lc = $_[1];
+ s/\s*//;
+ if (s/^\)//) {
+ s/\s*//;
+ }
+ else {
+ PrintErrorMessage(&quot;Missing ) after $token&quot;,$lc);
+ }
+}
+
+
+</pre><p><a name="NWDCUvTi-G">The subroutine </a><tt>chk_lcb</tt> behaves in a similar way to the subroutine
+<tt>chk_lparen</tt>.
+
+<pre><a name="NWCUvTi-2vMx6j-1" href="#NWDCUvTi-G"><dfn>&lt;subroutine <tt>chk_lcb</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+sub chk_lcb {
+ my $token = $_[0];
+ my $lc = $_[1];
+ s/\s*//;
+ if ($_ !~ /^\{/) {
+ PrintErrorMessage(&quot;Missing { after $token&quot;,$lc);
+ }
+ else {
+ s/^{\s*//;
+ }
+}
+
+</pre><p><a name="NWDCUvTi-H">Subroutine </a><tt>chk_rcb</tt> behaves in a similar way to the subroutine
+<tt>chk_rparen</tt>.
+
+<pre><a name="NWCUvTi-FE9Ax-1" href="#NWDCUvTi-H"><dfn>&lt;subroutine <tt>chk_rcb</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+sub chk_rcb {
+ my $token = $_[0];
+ my $lc = $_[1];
+ if ($_ !~ /^\s*\}/) {
+ PrintErrorMessage(&quot;Missing } after $token&quot;,$lc);
+ }
+ else {
+ s/^\s*}\s*//;
+ }
+}
+
+</pre><p><a name="NWDCUvTi-I">Subroutine </a><tt>chk_lsb</tt> behaves in a similar way to the subroutine
+<tt>chk_lparen</tt>.
+
+<pre><a name="NWCUvTi-3N30ZF-1" href="#NWDCUvTi-I"><dfn>&lt;subroutine <tt>chk_lsb</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+sub chk_lsb {
+ my $token = $_[0];
+ my $lc = $_[1];
+
+ s/\s*//;
+ if ($_ !~ /^\[/) {
+ PrintErrorMessage(&quot;Missing [ after $token&quot;,$lc);
+ }
+ else {
+ s/^\[\s*//;
+ }
+}
+
+</pre><p><a name="NWDCUvTi-J">Subroutine </a><tt>chk_rsb</tt> behaves in a similar way to the subroutine
+<tt>chk_rparen</tt>.
+
+<pre><a name="NWCUvTi-ma6zf-1" href="#NWDCUvTi-J"><dfn>&lt;subroutine <tt>chk_rsb</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+sub chk_rsb {
+ my $token = $_[0];
+ my $lc = $_[1];
+
+ s/\s*//;
+ if ($_ !~ /^\]/) {
+ PrintErrorMessage(&quot;Missing ] after $token&quot;,$lc);
+ }
+ else {
+ s/^\]\s*//;
+ }
+}
+
+</pre><p><a name="NWDCUvTi-K">The subroutine </a><code>chk_comma</code> checks whether the next token is a comma.
+If it is not then it prints an error message, otherwise it consumes the
+comma and any white space that follows the comma.
+
+<pre><a name="NWCUvTi-UyyUp-1" href="#NWDCUvTi-K"><dfn>&lt;subroutine <tt>chk_comma</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+sub chk_comma {
+ my $lc = $_[0];
+
+ s/\s*//;
+ if (/^[^,]/) {
+ PrintErrorMessage(&quot;Did not find expected comma&quot;,$lc);
+ }
+ else {
+ s/^,\s*//;
+ }
+}
+
+</pre><p><a name="NWDCUvTi-L">The subroutine </a><code>chk_comment</code> has only one parameter which is the current
+line number. It checks whether the next input character is a comment
+character and in this case it does nothing!. Otherwise, if there is some trailing text
+it simply prints a warning to the screen.
+
+<pre><a name="NWCUvTi-wLKY1-1" href="#NWDCUvTi-L"><dfn>&lt;subroutine <tt>chk_comment</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+sub chk_comment {
+ my $lc = $_[0];
+
+ s/\s*//;
+ if (/^%/) {
+ # do nothing!
+ }
+ elsif (/^[^%]/) {
+ PrintWarningMessage(&quot;Trailing text is ignored&quot;,$lc);
+ }
+}
+
+</pre><p><a name="NWDCUvTi-M">The subroutine </a><code>print_headers</code> prints a header to the output file, as
+well as a header to the LOG file.
+The header contains information regarding the version of the
+program, a copyright notice, the command line, date and time information,
+and the names of the various files processed/generated.
+
+<pre><a name="NWCUvTi-3iVliS-1" href="#NWDCUvTi-M"><dfn>&lt;subroutine <tt>print_headers</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+ sub print_headers
+ {
+ my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
+ $year+=1900;
+ $mon+=1;
+ $now_string = &quot;$year/&quot; . ($mon&gt;9 ? &quot;$mon/&quot; : &quot;0$mon/&quot;) .
+ ($mday&gt;9 ? &quot;$mday &quot; : &quot;0$mday &quot;) .
+ ($hour&gt;9 ? &quot;$hour:&quot; : &quot;0$hour:&quot;) .
+ ($min&gt;9 ? &quot;$min:&quot; : &quot;0$min:&quot;) .
+ ($sec&gt;9 ? &quot;$sec&quot; : &quot;0$sec&quot;);
+ print OUT &quot;%* -----------------------------------------------\n&quot;;
+ print OUT &quot;%* mathspic (Perl version $version_number)\n&quot;;
+ print OUT &quot;%* A filter program for use with PiCTeX\n&quot;;
+ print OUT &quot;%* Copyright (c) 2005-2010 A Syropoulos &amp; RWD Nickalls \n&quot;;
+ print OUT &quot;%* Command line: $0 $commandLineArgs\n&quot;;
+ print OUT &quot;%* Input filename : $source_file\n&quot;;
+ print OUT &quot;%* Output filename: $out_file\n&quot;;
+ print OUT &quot;%* Date &amp; time: $now_string\n&quot;;
+ print OUT &quot;%* -----------------------------------------------\n&quot;;
+ #
+ print LOG &quot;----\n&quot;;
+ print LOG &quot;$now_string\n&quot;;
+ print LOG &quot;mathspic (Perl version $version_number)\n&quot;;
+ print LOG &quot;Copyright (c) 2005-2010 A Syropoulos &amp; RWD Nickalls \n&quot;;
+ print LOG &quot;Input file = $source_file\n&quot;;
+ print LOG &quot;Output file = $out_file\n&quot;;
+ print LOG &quot;Log file = $log_file\n&quot;;
+ print LOG &quot;----\n&quot;;
+ }
+
+</pre><p><a name="NWDCUvTi-N">The subroutine </a><code>get_point</code> parses an individual point name.
+If the next token is also a point name then it returns the point name
+ (but only if the only if
+the point name exists in the PointTable). In all other cases it returns
+the string <code>_undef_</code> to indicate that something is wrong.
+
+<pre><a name="NWCUvTi-1h5ef9-1" href="#NWDCUvTi-N"><dfn>&lt;subroutine <tt>get_point</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+ sub get_point {
+
+ my ($lc) = $_[0];
+ my ($PointName);
+
+ if (s/^([^\W\d_]\d{0,4})\s*//i) { #point name
+ $PointName = $1;
+ if (!exists($PointTable{lc($PointName)})) {
+ PrintErrorMessage(&quot;Undefined point $PointName&quot;,$lc);
+ return &quot;_undef_&quot;;
+ }
+ else {
+ return lc($PointName);
+ }
+ }
+ else {
+ PrintErrorMessage(&quot;Point name expected&quot;,$lc);
+ return &quot;_undef_&quot;;
+ }
+ }
+
+</pre><p>The subroutine <code>perpendicular</code> has 6 parameters that correspond to the
+coordinates of some point P and to the coordinates of two points A and
+B that define a line. The subroutine returns
+a pair of numbers that correspond to the coordinates of a point that lies
+at the foot of the perpendicular to the line AB that passes through point P.
+The slope of line AB is m<sub>1</sub> and so its equation is
+y=m<sub>1</sub>x+c<sub>1</sub>. Similarly, the slope of the line PF is
+m<sub>2</sub>=-1/m<sub>1</sub> and its equation is
+y=m<sub>2</sub>x+c<sub>2</sub>. Since the line AB passes through A, then
+c<sub>1</sub>=y<sub>A</sub>-m<sub>1</sub>x<sub>A</sub>. Similarly, as P is
+on line PF, then c<sub>2</sub>=y<sub>P</sub>-m<sub>2</sub>x<sub>P</sub>.
+Now point F is on both lines, therefore
+<a name="NWDCUvTi-O">y</a><sub>F</sub>=m<sub>2</sub>x<sub>F</sub>+c<sub>2</sub> and
+y<sub>F</sub>=m<sub>1</sub>x<sub>F</sub>+c<sub>1</sub>. Solving these
+equations for x<sub>F</sub> and y<sub>F</sub> gives:
+<center>
+x<sub>F</sub>=(c<sub>2</sub>-c<sub>1</sub>)/(m<sub>1</sub>-m<sub>2</sub>)<br>
+y<sub>F</sub>=(m<sub>1</sub>c<sub>2</sub>-m<sub>2</sub>c<sub>1</sub>)/
+(m<sub>1</sub>-m<sub>2</sub>)
+</center>
+
+<pre><a name="NWCUvTi-1GxwYt-1" href="#NWDCUvTi-O"><dfn>&lt;subroutine <tt>perpendicular</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+ sub perpendicular {
+ my ($xP, $yP, $xA, $yA, $xB, $yB) = @_;
+ my ($xF, $yF, $deltax, $deltay, $m1, $m2, $c1, $c2, $factor);
+
+ $deltax = $xA - $xB;
+ return ($xA, $yP) if abs($deltax) &lt; 0.0000001;
+ $deltay = $yA - $yB;
+ return ($xP, $yA) if abs($deltay) &lt; 0.0000001;
+ $m1 = $deltay / $deltax;
+ eval { $m2 = (-1) / $m1;};
+ PrintFatalError(&quot;Division by zero&quot;,$lc) if $@;
+ $c1 = $yA - $m1 * $xA;
+ $c2 = $yP - $m2 * $xP;
+ eval { $factor = 1 / ($m1 - $m2)};
+ PrintFatalError(&quot;Division by zero&quot;,$lc) if $@;
+ return (($c2 - $c1) * $factor, ($m1 * $c2 - $m2 * $c1) * $factor);
+ }
+
+</pre><p> <a name="NWDCUvTi-P">The subroutine </a><code>Length</code> computes the distance between two points A and B.
+Notice, that the name of the subroutine starts with a capital L, just
+to avoid conflict with the predefined Perl function. The subroutine
+requires four parameters which are the coordinates of the two points.
+
+<pre><a name="NWCUvTi-4XEuZg-1" href="#NWDCUvTi-P"><dfn>&lt;subroutine <tt>Length</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+ sub Length {
+ my ($xA, $yA, $xB, $yB)=@_;
+ return sqrt(($xB - $xA)**2 + ($yB - $yA)**2);
+ }
+
+</pre><p><a name="NWDCUvTi-Q">The subroutine </a><code>triangleArea</code> computes the area of a triangle by using
+Heron's formula, i.e., given a triangle ABC, we first compute
+s=(AB+BC+CA)/2 and then the area of the triangle is equal to the
+square root of s times (s-AB) times (s-BC) times (s-BA), where AB, BC, and CA
+are the lengths of the three sides of the triangle. The subroutine accepts 6
+parameters, which correspond to the coordinates of three points that define
+the triangle.
+
+<pre><a name="NWCUvTi-4DwBs6-1" href="#NWDCUvTi-Q"><dfn>&lt;subroutine <tt>triangleArea</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+ sub triangleArea {
+ my ($xA, $yA, $xB, $yB, $xC, $yC)=@_;
+ my ($lenAB, $lenBC, $lenCA, $s);
+
+ $lenAB = Length($xA,$yA,$xB,$yB);
+ $lenBC = Length($xB,$yB,$xC,$yC);
+ $lenCA = Length($xC,$yC,$xA,$yA);
+ $s = ($lenAB + $lenBC + $lenCA) / 2;
+ return sqrt($s * ($s - $lenAB)*($s - $lenBC)*($s - $lenCA));
+ }
+
+</pre><p><a name="NWDCUvTi-R">The subroutine </a><code>poinOnLine</code> accepts five arguments: the coordinates of two
+points and the decimal number which corresponds to the distance from the
+first point towards the second one. The way we compute the coordinates of
+the point is fairly simple.
+
+<pre><a name="NWCUvTi-VFnEE-1" href="#NWDCUvTi-R"><dfn>&lt;subroutine <tt>pointOnLine</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+ sub pointOnLine {
+ my ($xA, $yA, $xB, $yB, $dist)=@_;
+ my ($deltax, $deltay, $xPol, $yPol);
+
+ $deltax = $xB - $xA;
+ $deltay = $yB - $yA;
+ $xPol = $xA + ($dist * $deltax / &amp;Length($xA,$yA,$xB,$yB));
+ $yPol = $yA + ($dist * $deltay / &amp;Length($xA,$yA,$xB,$yB));
+ return ($xPol, $yPol);
+ }
+
+
+</pre><p>As we have mentioned above the subroutine <code>circumCircleCenter</code> takes six
+arguments that correspond to the coordinates of three points that
+define a triangle. The subroutine computes the coordinates of
+the center of a circle that passes through these three points, and the radius of
+the circle. We now describe how the subroutine computes the center
+of the circle and its radius. Let the triangle points be <code>t1</code>, <code>t2</code>
+and <code>t3</code>. We use the two pairs of points to define two sides,
+i.e., <code>t1t2</code> and <code>t2t3</code>. For each
+<a name="NWDCUvTi-S">side we locate the midpoints and get the their coordinates. We check</a>
+whether either of these two lines is either vertical or horizontal. If this
+is true, we know that one of the coordinates of the center of the circumcircle
+is the same as that of the midpoints of the horizontal or vertical line.
+Next, we determine the slopes of the lines <code>t1t2</code> and <code>t2t3</code>.
+We now determine the slope of lines at right-angles to these lines. We solve the
+resulting equations and obtain the center of the circumcircle. Now we get the
+radius, and then we are done.
+
+<pre><a name="NWCUvTi-lKNKf-1" href="#NWDCUvTi-S"><dfn>&lt;subroutine <tt>circumCircleCenter</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+
+ sub circumCircleCenter {
+ my ($xA, $yA, $xB, $yB, $xC, $yC, $lc)=@_;
+ my ($deltay12, $deltax12, $xs12, $ys12);
+ my ($deltay23, $deltax23, $xs23, $ys23);
+ my ($xcc, $ycc);
+ my ($m23, $mr23, $c23, $m12, $mr12, $c12);
+ my ($sideA, $sideB, $sideC, $a, $radius);
+
+ if (abs(triangleArea($xA, $yA, $xB, $yB, $xC, $yC)) &lt; 0.0000001)
+ {
+ PrintErrorMessage(&quot;Area of triangle is zero!&quot;,$lc);
+ return (0,0,0);
+ }
+ $deltay12 = $yB - $yA;
+ $deltax12 = $xB - $xA;
+ $xs12 = $xA + $deltax12 / 2;
+ $ys12 = $yA + $deltay12 / 2;
+ #
+ $deltay23 = $yC - $yB;
+ $deltax23 = $xC - $xB;
+ $xs23 = $xB + $deltax23 / 2;
+ $ys23 = $yB + $deltay23 / 2;
+ #
+ CCXYLINE:{
+ if (abs($deltay12) &lt; 0.0000001)
+ {
+ $xcc = $xs12;
+ if (abs($deltax23) &lt; 0.0000001)
+ {
+ $ycc = $ys23;
+ last CCXYLINE;
+ }
+ else
+ {
+ $m23 = $deltay23 / $deltax23;
+ $mr23 = -1 / $m23;
+ $c23 = $ys23 - $mr23 * $xs23;
+ $ycc = $mr23 * $xs12 + $c23;
+ last CCXYLINE;
+ }
+ }
+ if (abs($deltax12) &lt; 0.0000001)
+ {
+ $ycc = $ys12;
+ if (abs($deltay23) &lt; 0.0000001)
+ {
+ $xcc = $xs23;
+ last CCXYLINE;
+ }
+ else
+ {
+ $m23 = $deltay23 / $deltax23;
+ $mr23 = -1 / $m23;
+ $c23 = $ys23 - $mr23 * $xs23;
+ $xcc = ($ys12 - $c23) / $mr23;
+ last CCXYLINE;
+ }
+ }
+ if (abs($deltay23) &lt; 0.0000001)
+ {
+ $xcc = $xs23;
+ if (abs($deltax12) &lt; 0.0000001)
+ {
+ $ycc = $ys12;
+ last CCXYLINE;
+ }
+ else
+ {
+ $m12 = $deltay12 / $deltax12;
+ $mr12 = -1 / $m12;
+ $c12 = $ys12 - $mr12 * $xs12;
+ $ycc = $mr12 * $xcc + $c12;
+ last CCXYLINE;
+ }
+ }
+ if (abs($deltax23) &lt; 0.0000001)
+ {
+ $ycc = $ys23;
+ if (abs($deltay12) &lt; 0.0000001)
+ {
+ $xcc = $xs12;
+ last CCXYLINE;
+ }
+ else
+ {
+ $m12 = $deltay12 / $deltax12;
+ $mr12 = -1 / $m12;
+ $c12 = $ys12 - $mr12 * $xs12;
+ $xcc = ($ycc - $c12) / $mr12;
+ last CCXYLINE;
+ }
+ }
+ $m12 = $deltay12 / $deltax12;
+ $mr12 = -1 / $m12;
+ $c12 = $ys12 - $mr12 * $xs12;
+ #-----
+ $m23 = $deltay23 / $deltax23;
+ $mr23 = -1 / $m23;
+ $c23 = $ys23 - $mr23 * $xs23;
+ $xcc = ($c23 - $c12) / ($mr12 - $mr23);
+ $ycc = ($c23 * $mr12 - $c12 * $mr23) / ($mr12 - $mr23);
+ }
+ #
+ $sideA = &amp;Length($xA,$yA,$xB,$yB);
+ $sideB = &amp;Length($xB,$yB,$xC,$yC);
+ $sideC = &amp;Length($xC,$yC,$xA,$yA);
+ $a = triangleArea($xA, $yA, $xB, $yB, $xC, $yC);
+ $radius = ($sideA * $sideB * $sideC) / (4 * $a);
+ #
+ return ($xcc, $ycc, $radius);
+ }
+
+</pre><p>The subroutine <code>ComputeDist</code> is used to compute a distance that is
+specified by either a float number, a pair of points, or a variable
+name. In case we have a pair of identifiers, we check whether the first
+one is a point. If it isn't a point we assume we have a variable followed
+by a keyword. Otherwise, i.e., if it is a point name, we check whether
+the second identifier is also a point name. If it is, we simply return
+the distance between them, otherwise we issue an error message.
+<a name="NWDCUvTi-T">If we have only a single identifier, we check whether it is a</a>
+variable that has already been defined, and if so we return its value.
+ Since, this
+subroutine is heavily used, it actually returns a pair of numbers:
+the first one being the computed distance and the second one being an
+error indicator. If the value of this indicator is 0, then there is no
+error. If its value is 1, then there is an error. Moreover, in case there
+is an error the distance is assumed to be equal to zero.
+
+<pre><a name="NWCUvTi-3GSnCT-1" href="#NWDCUvTi-T"><dfn>&lt;subroutine <tt>ComputeDist</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+ sub ComputeDist {
+ my ($lc) = $_[0];
+ my ($v1, $v2);
+
+ if (s/^((\+|-)?\d+(\.\d+)?([eE](\+|-)?\d+)?)//) #is it a number?
+ {
+ return ($1, 1);
+ }
+ elsif (/^[^\W\d_]\d{0,4}[^\W\d_]\d{0,4}/) #it is a pair of IDs?
+ {
+ s/^([^\W\d_]\d{0,4})//i;
+ $v1 = $1;
+ if (!exists($PointTable{lc($v1)})) {
+ if (exists($VarTable{lc($v1)})) {
+ return ($VarTable{lc($v1)}, 1);
+ }
+ PrintErrorMessage(&quot;Point $v1 has not been defined&quot;, $lc);
+ s/^\s*[^\W\d_]\d{0,4}//i;
+ return (0,0);
+ }
+ $v1 = lc($v1);
+ s/^\s*([^\W\d_]\d{0,4})//i;
+ $v2 = $1;
+ if (!exists($PointTable{lc($v2)}))
+ {
+ PrintErrorMessage(&quot;Point $v2 has not been defined&quot;, $lc);
+ return (0,0);
+ }
+ $v2 = lc($v2);
+ my ($x1,$y1,$pSV1,$pS1) = unpack(&quot;d3A*&quot;,$PointTable{$v1});
+ my ($x2,$y2,$pSV2,$pS2) = unpack(&quot;d3A*&quot;,$PointTable{$v2});
+ return (Length($x1,$y1,$x2,$y2), 1);
+ }
+ elsif (s/^([^\W\d_]\d{0,4})//i) # it is a single id
+ {
+ $v1 = $1;
+ if (!exists($VarTable{lc($v1)})) #it isn't a variable
+ {
+ PrintErrorMessage(&quot;Variable $v1 has not been defined&quot;, $lc);
+ return (0,0);
+ }
+ return ($VarTable{lc($v1)}, 1);
+ }
+ else
+ {
+ PrintErrorMessage(&quot;Unexpected token&quot;, $lc);
+ return (0,0);
+ }
+ }
+
+</pre><p><a name="NWDCUvTi-U">The subroutine </a><code>intersection4points</code> has 8 parameters that correspond to the
+coordinates of four points that uniquely determine two lines, and computes the
+the point of intersection of these two lines.
+
+<pre><a name="NWCUvTi-106ivL-1" href="#NWDCUvTi-U"><dfn>&lt;subroutine <tt>intersection4points</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+ sub intersection4points {
+ my ($x1, $y1, $x2, $y2, $x3, $y3, $x4, $y4) = @_;
+ my ($deltay12, $deltax12, $deltay34, $deltax34);
+ my ($xcc, $ycc, $m34, $c34, $m12, $c12);
+
+ $deltay12 = $y2 - $y1;
+ $deltax12 = $x2 - $x1;
+ #
+ $deltay34 = $y4 - $y3;
+ $deltax34 = $x4 - $x3;
+ I4PXYLINE:{
+ if (abs($deltay12) &lt; 0.0000001)
+ {
+ $ycc = $y1;
+ if (abs($deltax34) &lt; 0.0000001)
+ {
+ $xcc = $x3;
+ last I4PXYLINE;
+ }
+ else
+ {
+ $m34 = $deltay34 / $deltax34;
+ $c34 = $y3 - $m34 * $x3;
+ $xcc = ($ycc - $c34) / $m34;
+ last I4PXYLINE;
+ }
+ }
+ if (abs($deltax12) &lt; 0.0000001)
+ {
+ $xcc = $x1;
+ if (abs($deltay34) &lt; 0.0000001)
+ {
+ $ycc = $y3;
+ last I4PXYLINE;
+ }
+ else
+ {
+ $m34 = $deltay34 / $deltax34;
+ $c34 = $y3 - $m34 * $x3;
+ $ycc = $m34 * $xcc + $c34;
+ last I4PXYLINE;
+ }
+ }
+ if (abs($deltay34) &lt; 0.0000001)
+ {
+ $ycc = $y3;
+ if (abs($deltax12) &lt; 0.0000001)
+ {
+ $xcc = $x1;
+ last I4PXYLINE;
+ }
+ else
+ {
+ $m12 = $deltay12 / $deltax12;
+ $c12 = $y1 - $m12 * $x1;
+ $xcc = ($ycc - $c12) / $m12;
+ last I4PXYLINE;
+ }
+ }
+ if (abs($deltax34) &lt; 0.0000001)
+ {
+ $xcc = $x3;
+ if (abs($deltay12) &lt; 0.0000001)
+ {
+ $ycc = $y1;
+ last I4PXYLINE;
+ }
+ else
+ {
+ $m12 = $deltay12 / $deltax12;
+ $c12 = $y1 - $m12 * $x1;
+ $ycc = $m12 * $xcc + $c12;
+ last I4PXYLINE;
+ }
+ }
+ $m12 = $deltay12 / $deltax12;
+ $c12 = $y1 - $m12 * $x1;
+ $m34 = $deltay34 / $deltax34;
+ $c34 = $y3 - $m34 * $x3;
+ $xcc = ($c34 - $c12) / ($m12 - $m34);
+ $ycc = ($c34 * $m12 - $c12 * $m34) / ($m12 - $m34);
+ }
+ return ($xcc, $ycc);
+ }
+
+</pre><p>The subroutine <code>IncircleCenter</code> computes the center and the
+radius of the circle that is inside a triangle and touches the sides of
+the triangle. The subroutine has six arguments that correspond to the
+coordinates of three points that uniquely determine the triangle. Here are
+the details:
+<ul>
+<li> Let the triangle points be A, B, C and sides a, b, c, where side B
+is opposite angle B, etc. </li>
+<li> Use angles A and B only.</li>
+<li> Let the bisector of angle A meet side a in point A1, and let the
+distance of A1 from B be designated BA1</li>
+<li> Using the sine rule, one gets: BA1/c = a/(b+c), that is
+BA1 = c * a/(b+c).</li>
+<li> Now do the same for side b, and determine equivalent point B1.
+<a name="NWDCUvTi-V">CB1/a = b/(b+c), that is CB1 = a * b/(b+c).</a></li>
+<li> We can now find the intersection of the line from point A to point A1,
+and the line from point B to point B1. We have four points, so we use the
+mathspic internal <code>intersection4points</code> subroutine to return the
+coordinates of the intersection X<sub>i</sub>, Y<sub>i</sub>.</li>
+<li> Now get the radius: R=(area of triangle)/(a+b+c)/2</li>
+<li>Finally, return the radius and the coordinates of the center.
+</ul>
+
+<pre><a name="NWCUvTi-Kxdzt-1" href="#NWDCUvTi-V"><dfn>&lt;subroutine <tt>IncircleCenter</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+ sub IncircleCenter {
+ my ($Ax, $Ay, $Bx, $By, $Cx, $Cy) = @_;
+ my ($sideA, $sideB, $sideC);
+ my ($ba1, $xA1, $yA1, $cb1, $ac1, $xB1, $yB1, $xC1, $yC1, $a, $s, $r);
+
+ #determine the lengths of the sides
+ $sideA = Length($Bx, $By, $Cx, $Cy);
+ $sideB = Length($Cx, $Cy, $Ax, $Ay);
+ $sideC = Length($Ax, $Ay, $Bx, $By);
+ #
+ $ba1 = ($sideC * $sideA) / ($sideB + $sideC);
+ ($xA1, $yA1) = pointOnLine($Bx, $By, $Cx, $Cy, $ba1);
+ $cb1 = ($sideA * $sideB) / ($sideC + $sideA);
+ ($xB1, $yB1) = pointOnLine($Cx, $Cy, $Ax, $Ay, $cb1);
+ $ac1 = ($sideB * $sideC) / ($sideA + $sideB);
+ ($xC1, $yC1) = pointOnLine($Ax, $Ay, $Bx, $By, $ac1);
+ ($xcenter, $ycenter) = &amp;intersection4points($Ax, $Ay, $xA1, $yA1,
+ $Bx, $By, $xB1, $yB1);
+ # get radius
+ $a = &amp;triangleArea($Ax, $Ay, $Bx, $By, $Cx, $Cy);
+ $s = ($sideA + $sideB +$sideC) / 2;
+ $r = $a / $s;
+ return ($xcenter, $ycenter, $r);
+ }
+
+</pre><p><a name="NWDCUvTi-W">The subroutine </a><code>Angle</code> takes six arguments which correspond to the
+coordinates of three points that define an angle. The subroutine computes
+the opening of the angle in degrees. In case there is an error it returns
+the number -500. ****EXPLAIN THE ALGORITHM****
+
+<pre><a name="NWCUvTi-3xteda-1" href="#NWDCUvTi-W"><dfn>&lt;subroutine <tt>Angle</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+ sub Angle {
+ my ($Ax, $Ay, $Bx, $By, $Cx, $Cy) = @_;
+ my ($RAx, $RAy, $RBx, $RBy, $RCx, $RCy, $deltax, $deltay);
+ my ($lineBA, $lineBC, $lineAC, $k, $kk, $angle);
+ my ($T, $cosT, $sinT) = (0.3, cos(0.3), sin(0.3));
+
+ $RAx = $Ax * $cosT + $Ay * $sinT;
+ $RAy = -$Ax * $sinT + $Ay * $cosT;
+ $RBx = $Bx * $cosT + $By * $sinT;
+ $RBy = -$Bx * $sinT + $By * $cosT;
+ $RCx = $Cx * $cosT + $Cy * $sinT;
+ $RCy = -$Cx * $sinT + $Cy * $cosT;
+ $deltax = $RBx - $RAx;
+ $deltay = $RBy - $RAy;
+ $lineBA = sqrt($deltax*$deltax + $deltay*$deltay);
+ if ($lineBA &lt; 0.0000001)
+ {
+ return -500;
+ }
+ $deltax = $RBx - $RCx;
+ $deltay = $RBy - $RCy;
+ $lineBC = sqrt($deltax*$deltax + $deltay*$deltay);
+ if ($lineBC &lt; 0.0000001)
+ {
+ return -500;
+ }
+ $deltax = $RAx - $RCx;
+ $deltay = $RAy - $RCy;
+ $lineAC = sqrt($deltax*$deltax + $deltay*$deltay);
+ if ($lineAC &lt; 0.0000001)
+ {
+ return -500;
+ }
+ $k = ($lineBA*$lineBA + $lineBC*$lineBC - $lineAC*$lineAC ) /
+ (2 * $lineBA * $lineBC);
+ $k = -1 if $k &lt; -0.99999;
+ $k = 1 if $k &gt; 0.99999;
+ $kk = $k * $k;
+ if (($kk * $kk) == 1)
+ {
+ $angle = PI if $k == -1;
+ $angle = 0 if $k == 1;
+ }
+ else
+ {
+ $angle = (PI / 2) - atan2($k / sqrt(1 - $kk),1);
+ }
+ return $angle * 180 / PI;
+ }
+
+</pre><p>The subroutine <code>excircle</code> computes the center and the radius of a circle that
+externally touches a given side (4th and 5th arguments) of triangle (determined
+by the 1rst, the 2nd and 3rd argument). Here are the details:
+<ul>
+<li> Let the triangle points be A, B, C, and the given side be BC.</li>
+<li> Now calculate the radius of Excircle = (triangle area)/(s - side length),
+where s = (a+b+c)/2</li>
+<li><a name="NWDCUvTi-X">Calculate the distance from the angle (A) (opposite the given side BC)</a>
+ to the excircle center = radius/sin(A/2)</li>
+<li> Now determine the the Excircle center by locating it on the angle bisector
+(i.e., same line that the IncircleCenter is on), but at distance d further
+away from angle A. So, we now have the Incircle center (I),
+ determine deltaX and deltaY from I to A, calculate the distance AI,
+ and then extend the line from I by distance d to Excenter Xc, Yc.</li>
+</ul>
+
+<pre><a name="NWCUvTi-cchrT-1" href="#NWDCUvTi-X"><dfn>&lt;subroutine <tt>excircle</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+ sub excircle {
+ my ($A, $B, $C, $D, $E) = @_;
+ my ($Ax,$Ay,$Bx,$By,$Dx,$Dy,$Ex,$Ey,$ASVA,$ASA);
+ ($Ax,$Ay,$ASVA,$ASA)=unpack(&quot;d3A*&quot;,$PointTable{$A});
+ ($Bx,$By,$ASVA,$ASA)=unpack(&quot;d3A*&quot;,$PointTable{$B});
+ ($Cx,$Cy,$ASVA,$ASA)=unpack(&quot;d3A*&quot;,$PointTable{$C});
+ ($Dx,$Dy,$ASVA,$ASA)=unpack(&quot;d3A*&quot;,$PointTable{$D});
+ ($Ex,$Ey,$ASVA,$ASA)=unpack(&quot;d3A*&quot;,$PointTable{$E});
+ my ($sideA, $sideB, $sideC, $s, $R, $theAdeg, $d);
+ my ($Xmypoint, $Ymypoint, $deltax, $deltay, $mylength, $xc, $yc);
+
+ $sideA = &amp;Length($Bx, $By, $Cx, $Cy);
+ $sideB = &amp;Length($Cx, $Cy, $Ax, $Ay);
+ $sideC = &amp;Length($Ax, $Ay, $Bx, $By);
+ $s = ($sideA + $sideB + $sideC) / 2;
+ $R = triangleArea($Ax, $Ay, $Bx, $By, $Cx, $Cy) /
+ ($s - &amp;Length($Dx, $Dy, $Ex, $Ey));
+ if (($D eq $A &amp;&amp; $E eq $B) || ($D eq $B &amp;&amp; $E eq $A))
+ {
+ $theAdeg = &amp;Angle($Bx, $By, $Cx, $Cy, $Ax, $Ay);
+ $Xmypoint = $Cx;
+ $Ymypoint = $Cy;
+ }
+ elsif (($D eq $B &amp;&amp; $E eq $C) || ($D eq $C &amp;&amp; $E eq $B))
+ {
+ $theAdeg = &amp;Angle($Cx, $Cy, $Ax, $Ay, $Bx, $By);
+ $Xmypoint = $Ax;
+ $Ymypoint = $Ay;
+ }
+ elsif (($D eq $C &amp;&amp; $E eq $A) || ($D eq $A &amp;&amp; $E eq $C))
+ {
+ $theAdeg = &amp;Angle($Ax, $Ay, $Bx, $By, $Cx, $Cy);
+ $Xmypoint = $Bx;
+ $Ymypoint = $By;
+ }
+ else
+ {
+ return (0,0,0);
+ }
+ $d = $R / sin($theAdeg * PI / 180 / 2);
+ my ($xIn, $yIn, $rin) = &amp;IncircleCenter($Ax, $Ay, $Bx, $By, $Cx, $Cy);
+ $deltax = $xIn - $Xmypoint;
+ $deltay = $yIn - $Ymypoint;
+ $mylength = sqrt($deltax*$deltax + $deltay*$deltay);
+ $xc = $Xmypoint + $d * $deltax / $mylength;
+ $yc = $Ymypoint + $d * $deltay / $mylength;
+ return ($xc, $yc, $R);
+ }
+
+</pre><p>The <code>DrawLineOrArrow</code> subroutine is used to parse the arguments of the commands
+<code>drawline</code>, <code>drawthickline</code>, <code>drawarrow</code>, <code>drawthickarrow</code> and
+<code>drawCurve</code>. In general, these commands have as arguments a list of points separated by
+commas that are used to draw a set of lines. The list of points is
+enclosed in parentheses. Here we give only the syntax of the <code>drawline</code>
+comma, as the syntax of the other commands is identical:
+<pre>
+ drawline ::= "drawline" "(" Points { "," Points } ")"
+ Points ::= Point { separator Point}
+ separator ::= blank | empty
+</pre>
+<a name="NWDCUvTi-Y">In the following code we</a>
+scan a list of points (possibly separated by blanks) and we stop when
+we encounter either a comma or some other character. In case we have found
+a comma, we check whether we have a <code>drawline</code> command and if this is
+the case we plot the list of points. We continue with the next list of points,
+until there are no more points. The inner while-loop is used to control the
+consumption of point tokens and the external to reset the array <code>PP</code> which
+holds the point names.
+
+<pre><a name="NWCUvTi-cviH2-1" href="#NWDCUvTi-Y"><dfn>&lt;subroutine <tt>DrawLineOrArrow</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+ sub DrawLineOrArrow {
+ my $draw_Line = shift;
+ my $lc = shift;
+ my $lineLength = -1;
+ my $stacklen = 0;
+ my @PP = ();
+# if ($draw_Line != 2) {
+# s/\s*//;
+# if (s/^\[\s*//) { # optional length specifier
+# $lineLength = expr($lc);
+# if ($lineLength &lt;= 0) {
+# PrintErrorMessage(&quot;length must greater than zero&quot;,$lc);
+# $lineLength = -1;
+# }
+# chk_rsb(&quot;optional part&quot;,$lc);
+# }
+# }
+ chk_lparen(&quot;$cmd&quot;,$lc);
+ DRAWLINES:while(1) {
+ @PP = () ;
+ while(1) {
+ if (s/^([^\W\d_]\d{0,4})\s*//i) { #point name
+ $P = $1;
+ if (!exists($PointTable{lc($P)})) {
+ PrintErrorMessage(&quot;Undefined point $P&quot;,$lc);
+ }
+ else {
+ push (@PP,$P);
+ }
+ }
+ else {
+ $stacklen = @PP;
+ if ($draw_Line != 2) {
+ if ($stacklen &lt;= 1) {
+ PrintErrorMessage(&quot;Wrong number of points&quot;,$lc);
+ }
+ else {
+ push(@PP,$lc);
+ if ($draw_Line == 0) {
+ drawarrows(@PP);
+ }
+ elsif ($draw_Line == 1) {
+ drawlines(@PP);
+ }
+ }
+ }
+ if (s/^,\s*// and $draw_Line != 2) {
+ next DRAWLINES;
+ }
+ else {
+ last DRAWLINES;
+ }
+ }
+ }
+ }
+ if ($draw_Line == 2) {
+ $stacklen = @PP;
+ if ($stacklen &lt; 2) {
+ PrintErrorMessage(&quot;Wrong number of points&quot;,$lc);
+ }
+ elsif ($stacklen % 2 == 0) {
+ PrintErrorMessage(&quot;Number of points must be odd&quot;,$lc);
+ }
+ else {
+ drawCurve(@PP);
+ }
+ }
+ chk_rparen(&quot;arguments of $cmd&quot;,$lc);
+ chk_comment($lc);
+ }
+
+</pre><p>The subroutine <code>drawarrows</code> is used to draw one or more lines. The subroutine
+accepts as argument an array which contains the names of the points which
+<a name="NWDCUvTi-Z">define the lines, plus the current program line number. Each arrow is printed</a>
+using the following code:
+<center>
+<tt>\arrow < </tt>ArrowLength <tt> mm> [</tt> beta <tt>,</tt> gamma <tt>] from
+x1 y1 to x2 y2 </tt>
+</center>
+where beta is equal to tan(<code>$arrowAngleB</code> * <code>d2r</code> /2) and gamma is equal to
+2*tan(<code>$arrowAngleC</code> * <code>d2r</code> / 2).
+
+<pre><a name="NWCUvTi-4STZZz-1" href="#NWDCUvTi-Z"><dfn>&lt;subroutine <tt>drawarrows</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+ sub drawarrows {
+ my ($NoArgs);
+ $NoArgs = @_;
+ my ($lc) = $_[$NoArgs-1]; #line number is the last argument
+ my ($NumberOfPoints, $p, $q, $r12, $d12);
+ my ($px,$py,$pSV,$pS, $qx,$qy,$qSV,$qS);
+
+ $NumberOfPoints = $NoArgs - 1;
+ LOOP: for(my $i=0; $i &lt; $NumberOfPoints - 1; $i++)
+ {
+ $p = $_[$i];
+ $q = $_[$i+1];
+ ($px,$py,$pSV,$pS) = unpack(&quot;d3A*&quot;,$PointTable{lc($p)});
+ ($qx,$qy,$qSV,$qS) = unpack(&quot;d3A*&quot;,$PointTable{lc($q)});
+ $pSV = $defaultLFradius if $pSV == 0;
+ $qSV = $defaultLFradius if $qSV == 0;
+ $r12 = $pSV + $qSV;
+ $d12 = Length($px,$py,$qx,$qy);
+ if ($d12 &lt;= $r12)
+ {
+ if($d12 == 0)
+ {
+ PrintErrorMessage(&quot;points $p and $q are the same&quot;, $lc);
+ next LOOP;
+ }
+ PrintWarningMessage(&quot;arrow $p$q not drawn: points too close or &quot;.
+ &quot;radii too big&quot;, $lc);
+ next LOOP;
+ }
+ ($px, $py) = pointOnLine($px, $py, $qx, $qy, $pSV) if $pSV &gt; 0;
+ ($qx, $qy) = pointOnLine($qx, $qy, $px, $py, $qSV) if $qSV &gt; 0;
+ my ($beta, $gamma);
+ $beta = tan($arrowAngleB * D2R / 2);
+ $gamma = 2 * tan($arrowAngleC * D2R / 2);
+ printf OUT &quot;\\arrow &lt;%.5f%s&gt; [%.5f,%.5f] from %.5f %.5f to %.5f %.5f\n&quot;,
+ $arrowLength, $arrowLengthUnits, $beta, $gamma, $px, $py, $qx, $qy;
+ }
+ }
+
+</pre><p>The subroutine <code>drawlines</code> is used to draw one or more lines. The subroutine
+accepts as argument an array which contains the names of the points which
+define the lines, plus the current program line number. If there are only
+two points (i.e., only one line), then we output the following PiCTeX code:
+<center>
+<tt> \plot x1 y1 x2 y2 / %% pointname1 pointname2</tt>
+</center>
+If there are more than two points, then we need to write the PiCTeX code in
+pairs with two points on each line (just to keep things simple) as follows:
+<center>
+<tt> \plot x1 y1 x2 y2 / %% pointname1 pointname2</tt>
+<tt> \plot x2 y2 x3 y3 / %% pointname2 pointname3</tt>
+<tt> \plot x3 y3 x4 y4 / %% pointname3 pointname4</tt>
+</center>
+<a name="NWDCUvTi-a">An important part of the subroutine is devoted to checking whether either</a>
+or both of the pairs of points are associated with a line-free zone, and if
+so, then we must take care not to draw the line inside the line-free zone. If
+a point does have a line-free zone, then we use the <code>pointOnLine</code>
+subroutine to determine the point on the line which is just on the line-free
+boundary, and draw the line to the that point instead of to the exact
+point-location.
+
+<pre><a name="NWCUvTi-3KtTfB-1" href="#NWDCUvTi-a"><dfn>&lt;subroutine <tt>drawlines</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+ sub drawlines {
+ my ($NoArgs);
+ $NoArgs = @_;
+ my ($lc) = $_[$NoArgs-1]; #line number is the last argument
+ my ($NumberOfPoints, $p, $q, $r12, $d12);
+ my ($px,$py,$pSV,$pS, $qx,$qy,$qSV,$qS);
+
+ $NumberOfPoints = $NoArgs - 1;
+ LOOP: for(my $i=0; $i &lt; $NumberOfPoints - 1; $i++)
+ {
+ $p = $_[$i];
+ $q = $_[$i+1];
+ ($px,$py,$pSV,$pS) = unpack(&quot;d3A*&quot;,$PointTable{lc($p)});
+ ($qx,$qy,$qSV,$qS) = unpack(&quot;d3A*&quot;,$PointTable{lc($q)});
+ $pSV = $defaultLFradius if $pSV == 0;
+ $qSV = $defaultLFradius if $qSV == 0;
+ $r12 = $pSV + $qSV;
+ $d12 = Length($px,$py,$qx,$qy);
+ if ($d12 &lt;= $r12)
+ {
+ if($d12 == 0)
+ {
+ PrintErrorMessage(&quot;points $p and $q are the same&quot;, $lc);
+ next LOOP;
+ }
+ PrintWarningMessage(&quot;line $p$q not drawn: points too close or &quot;.
+ &quot;radii too big&quot;, $lc);
+ next LOOP;
+ }
+ ($px, $py) = pointOnLine($px, $py, $qx, $qy, $pSV) if $pSV &gt; 0;
+ ($qx, $qy) = pointOnLine($qx, $qy, $px, $py, $qSV) if $qSV &gt; 0;
+ if ($px == $qx || $py == $qy)
+ {
+ printf OUT &quot;\\putrule from %.5f %.5f to %.5f %.5f %%%% %s%s\n&quot;,
+ $px,$py,$qx,$qy,$p,$q;
+ }
+ else
+ {
+ printf OUT &quot;\\plot %.5f %.5f\t%.5f %.5f / %%%% %s%s\n&quot;,
+ $px, $py,$qx,$qy,$p,$q;
+ }
+ }
+ }
+
+</pre><p>The subroutine <code>drawCurve</code> is used to draw a curve that passes through an odd
+number of points. The subroutine has as argument an array which contains the names of the
+points which define the lines plus the current program line number. The subroutine
+emits code that has the following general form:
+<pre>
+ <a name="NWDCUvTi-b">\setquadratic</a>
+ \plot
+ X1 Y1
+ X2 Y2
+ X3 Y3
+ \setlinear
+</pre>
+
+
+<pre><a name="NWCUvTi-3c2Tgd-1" href="#NWDCUvTi-b"><dfn>&lt;subroutine <tt>drawCurve</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+ sub drawCurve {
+ my ($NoArgs);
+ $NoArgs = @_;
+ my ($lc) = $_[$NoArgs-1]; #line number is the last argument
+ my ($NumberOfPoints, $p);
+
+ $NumberOfPoints = $NoArgs - 1;
+ print OUT &quot;\\setquadratic\n\\plot\n&quot;;
+ for(my $i=0; $i &lt;= $NumberOfPoints; $i++)
+ {
+ $p = $_[$i];
+ my ($px,$py,$pSV,$pS) = unpack(&quot;d3A*&quot;,$PointTable{lc($p)});
+ printf OUT &quot;\t%0.5f %0.5f&quot;, $px, $py;
+ print OUT (($i == $NumberOfPoints) ? &quot; / %$p\n&quot; : &quot; %$p\n&quot;);
+ }
+ print OUT &quot;\\setlinear\n&quot;;
+ }
+
+</pre><p>The subroutine <code>drawpoints</code> is used to draw one or more points. The subroutine
+<a name="NWDCUvTi-c">has as arguments a list of points. For each point we produce code that has</a>
+the following general form:
+<center>
+<tt> \put {SYMBOL} at Px PY</tt>
+</center>
+where <code>SYMBOL</code> is either the default plot symbol, i.e., <code>$\bullet$</code>,
+whatever the user has set with the <code>PointSymbol</code> command, or the plot
+symbol specified in the definition of the point.
+
+<pre><a name="NWCUvTi-1NgToL-1" href="#NWDCUvTi-c"><dfn>&lt;subroutine <tt>drawpoints</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+ sub drawpoints {
+ my ($NumberOfPoints,$p);
+ $NumberOfPoints = @_;
+ my ($px,$py,$pSV,$pS);
+
+ for($i=0; $i &lt; $NumberOfPoints; $i++)
+ {
+ $p = $_[$i];
+ ($px,$py,$pSV,$pS) = unpack(&quot;d3A*&quot;,$PointTable{lc($p)});
+ if ($pS eq &quot;&quot; and $defaultsymbol =~ /circle|square/) {
+ $pS = $defaultsymbol;
+ }
+ POINTSWITCH: {
+ if ($pS eq &quot;&quot;) # no plot symbol specified
+ {
+ printf OUT &quot;\\put {%s} at %.5f %.5f %%%% %s\n&quot;,
+ $defaultsymbol, $px, $py, $p;
+ last POINTSWITCH;
+ }
+ if ($pS eq &quot;circle&quot;) # plot symbol is a circle
+ {
+ my $radius = (defined($DimOfPoint{lc($p)})) ? $DimOfPoint{lc($p)} :
+ $GlobalDimOfPoints;
+ if ($radius &gt; 0) # draw a circle using the current units
+ {
+ if ($radius == 1.5) # use \bigcirc
+ {
+ printf OUT &quot;\\put {\$\\bigcirc\$} at %.5f %.5f %%%% %s\n&quot;,
+ $px, $py, $p;
+ }
+ else
+ {
+ printf OUT &quot;\\circulararc 360 degrees from %.5f %.5f center at %.5f %.5f %%%% %s\n&quot;,
+ $px+$radius, $py, $px, $py, $p;
+ }
+ }
+ else #use \circ symbol
+ {
+ printf OUT &quot;\\put {\$\\circ\$} at %.5f %.5f %%%% %s\n&quot;,
+ $px,$py,$p;
+ }
+ last POINTSWITCH;
+ }
+ if ($pS eq &quot;square&quot;)
+ {
+ my $side = (defined($DimOfPoint{lc($p)})) ? $DimOfPoint{lc($p)} :
+ $GlobalDimOfPoints;
+ printf OUT &quot;\\put {%s} at %.5f %.5f %%%% %s\n&quot;,
+ drawsquare($side), $px, $py, $p;
+ last POINTSWITCH;
+ }
+ printf OUT &quot;\\put {%s} at %.5f %.5f %%%% %s\n&quot;, $pS,$px,$py,$p;
+ }
+ }
+ }
+
+</pre><p>The subroutine <code>drawAngleArc</code> gets six arguments which correspond to
+three points defining an angle (variables <code>$P1</code>, <code>$P2</code> and <code>$P3</code>),
+the radius, the internal/external specification and the direction
+specification (clockwise or anticlockwise).
+Depending on the values of these arguments, the subroutine
+returns the corresponding PiCTeX code, the general format of
+which is <pre>
+ \circulararc Angle degrees from x y center at x2 y2
+</pre>
+<a name="NWDCUvTi-d">where </a><code>Angle</code> is the angle that the three points P1 P2 P3 define
+(computed by subroutine <code>Angle</code>),
+and <code>x</code> and <code>y</code> are the coordinates of a point
+residing on line P2P1 at distance equal to a <code>$radius</code> from
+point <code>$P2</code>; and <code>x2</code>, <code>y2</code> are the coordinates of the
+center of the circle about which the arc is drawn,
+i.e., point <code>$P2</code>.
+
+<pre><a name="NWCUvTi-497AQD-1" href="#NWDCUvTi-d"><dfn>&lt;subroutine <tt>drawAngleArc</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+sub drawAngleArc {
+ my ($P1, $P2, $P3, $radius, $inout, $direction) = @_;
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$P1});
+ my ($x2,$y2,$pSV2,$pS2)=unpack(&quot;d3A*&quot;,$PointTable{$P2});
+ my ($x3,$y3,$pSV3,$pS3)=unpack(&quot;d3A*&quot;,$PointTable{$P3});
+
+ my $internalAngle = Angle($x1, $y1, $x2, $y2, $x3, $y3);
+ my $externalAngle = 360 - $internalAngle;
+ my ($x, $y) = pointOnLine($x2, $y2, $x1, $y1, $radius);
+ my $code = &quot;&quot;;
+ if ($inout eq &quot;internal&quot; and $direction eq &quot;clockwise&quot; ) {
+ $code = sprintf &quot;\\circulararc %.5f degrees from %.5f %.5f center at %.5f %.5f\n&quot;,
+ -1 * $internalAngle, $x, $y, $x2, $y2;
+ }
+ elsif ($inout eq &quot;internal&quot; and $direction eq &quot;anticlockwise&quot; ) {
+ $code = sprintf &quot;\\circulararc %.5f degrees from %.5f %.5f center at %.5f %.5f\n&quot;,
+ $internalAngle, $x, $y, $x2, $y2;
+ }
+ elsif ($inout eq &quot;external&quot; and $direction eq &quot;clockwise&quot; ) {
+ $code = sprintf &quot;\\circulararc %.5f degrees from %.5f %.5f center at %.5f %.5f\n&quot;,
+ -1 * $externalAngle, $x, $y, $x2, $y2;
+ }
+ elsif ($inout eq &quot;external&quot; and $direction eq &quot;anticlockwise&quot; ) {
+ $code = sprintf &quot;\\circulararc %.5f degrees from %.5f %.5f center at %.5f %.5f\n&quot;,
+ $externalAngle, $x, $y, $x2, $y2;
+ }
+ return $code;
+}
+
+</pre><p><a name="NWDCUvTi-e">The subroutine </a><code>drawAngleArrow</code> gets six arguments which correspond to
+three points defining an angle (variables <code>$P1</code>, <code>$P2</code> and <code>$P3</code>),
+the radius, the internal/external specification and the direction
+specification. The subroutine mainly draws the arrowhead, and
+calls the subroutine <code>drawAngleArc</code> to draw the
+arc part of the arrow.
+
+<pre><a name="NWCUvTi-4UPwva-1" href="#NWDCUvTi-e"><dfn>&lt;subroutine <tt>drawAngleArrow</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+sub drawAngleArrow {
+ my ($P1, $P2, $P3, $radius, $inout, $direction) = @_;
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$P1});
+ my ($x2,$y2,$pSV2,$pS2)=unpack(&quot;d3A*&quot;,$PointTable{$P2});
+ my ($x3,$y3,$pSV3,$pS3)=unpack(&quot;d3A*&quot;,$PointTable{$P3});
+
+ my $code = drawAngleArc($P1, $P2, $P3, $radius, $inout, $direction);
+
+ my ($xqp, $yqp) = pointOnLine($x2, $y2, $x1, $y1, $radius);
+ my ($deltax, $deltay) = ($x1 - $x2, $y1 - $y2);
+ my $AL;
+
+ if ($xunits =~ /mm/) {
+ $AL = 1;
+ }
+ elsif ($xunits =~ /cm/) {
+ $AL = 0.1;
+ }
+ elsif ($xunits =~ /pt/) {
+ $AL = 2.845;
+ }
+ elsif ($xunits =~ /bp/) {
+ $AL = 2.835;
+ }
+ elsif ($xunits =~ /pc/) {
+ $AL = 0.2371;
+ }
+ elsif ($xunits =~ /in/) {
+ $AL = 0.03937;
+ }
+ elsif ($xunits =~ /dd/) {
+ $AL = 2.659;
+ }
+ elsif ($xunits =~ /cc/) {
+ $AL = 0.2216;
+ }
+ elsif ($xunits =~ /sp/) {
+ $AL = 186467.98;
+ }
+ my $halfAL = $AL / 2;
+ my $d = sqrt($radius * $radius - $halfAL * $halfAL);
+ my $alpha = atan2($d / $halfAL, 1) * R2D;
+ my $beta = 2 * (90 - $alpha);
+ my $thetaqr;
+ if (abs($deltay) &lt; 0.00001) {
+ if ($deltax &gt; 0 ) {$thetaqr = 0 }
+ elsif ($deltax &lt; 0) {$thetaqr = -180}
+ }
+ else {
+ if (abs($deltax) &lt; 0.00001) {
+ $thetaqr = 90;
+ }
+ else {
+ $thetaqr = atan2($deltay / $deltax, 1) * R2D;
+ }
+ }
+ my ($xqr, $yqr) = pointOnLine($x2, $y2, $x3, $y3, $radius);
+ $deltax = $x3 - $x2;
+ $deltay = $y3 - $y2;
+ $alpha = atan2(sqrt($radius * $radius - $halfAL * $halfAL) / $halfAL, 1) /
+ D2R;
+ $beta = 2 * (90 - $alpha);
+ LINE2 : {
+ if (abs($deltax) &lt; 0.00001) {
+ if ($deltay &gt; 0) { $thetaqr = 90 }
+ elsif ($deltay &lt; 0) { $thetaqr = - 90 }
+ last LINE2;
+ }
+ else {
+ $thetaqr = atan2($deltay / $deltax, 1) * R2D;
+ }
+ if (abs($deltay) &lt; 0.00001) {
+ if ($deltax &gt; 0) { $thetaqr = 0 }
+ elsif ($deltax &lt; 0) { $thetaqr = -180 }
+ last LINE2;
+ }
+ else {
+ $thetaqr = atan2($deltay / $deltax, 1) * R2D;
+ }
+ if ($deltax &lt; 0 and $deltay &gt; 0) { $thetaqr += 180 }
+ elsif ($deltax &lt; 0 and $deltay &lt; 0) { $thetaqr += 180 }
+ elsif ($deltax &gt; 0 and $deltay &lt; 0) { $thetaqr += 360 }
+ }
+ my $xqrleft = $x2 + $radius * cos(($thetaqr + $beta) * D2R);
+ my $yqrleft = $y2 + $radius * sin(($thetaqr + $beta) * D2R);
+ my $xqrright = $x2 + $radius * cos(($thetaqr - $beta) * D2R);
+ my $yqrright = $y2 + $radius * sin(($thetaqr - $beta) * D2R);
+ if ($inout eq &quot;internal&quot; and $direction eq &quot;clockwise&quot;) {
+ $code .= sprintf &quot;\\arrow &lt;1.5mm&gt; [0.5, 1] from %.5f %.5f to %.5f %.5f\n&quot;,
+ $xqrleft, $yqrleft, $xqr, $yqr;
+ }
+ elsif ($inout eq &quot;internal&quot; and $direction eq &quot;anticlockwise&quot;) {
+ $code .= sprintf &quot;\\arrow &lt;1.5mm&gt; [0.5, 1] from %.5f %.5f to %.5f %.5f\n&quot;,
+ $xqrright, $yqrright, $xqr, $yqr;
+ }
+ elsif ($inout eq &quot;external&quot; and $direction eq &quot;clockwise&quot;) {
+ $code .= sprintf &quot;\\arrow &lt;1.5mm&gt; [0.5, 1] from %.5f %.5f to %.5f %.5f\n&quot;,
+ $xqrleft, $yqrleft, $xqr, $yqr;
+ }
+ elsif ($inout eq &quot;external&quot; and $direction eq &quot;anticlockwise&quot;) {
+ $code .= sprintf &quot;\\arrow &lt;1.5mm&gt; [0.5, 1] from %.5f %.5f to %.5f %.5f\n&quot;,
+ $xqrright, $yqrright, $xqr, $yqr;
+ }
+ return $code;
+}
+
+</pre><p>The subroutine <code>expr</code> is used to parse an expression. We are using a
+recursive descent parser to parse and evaluate an expression. The
+general syntax of an expression is as follows:
+<pre>
+expr ::= term { addop term }
+addop ::= "+" | "-"
+term ::= factor { mulop factor }
+mulop ::= "*" | "/" | "rem"
+factor ::= primitive [ ** factor ]
+primitive ::= [ "+" | "-"] primitive | number | variable |
+ pair-of-points | "(" expr ")" |
+ "sin (" expr ")" | "cos (" expr ")" | "area (" ThreePoints ")" |
+ "tan (" expr ")" | "exp (" expr ")" | "int" "(" expr ")" |
+ "log (" expr ")" | "atan (" expr ")" | "sgn" "(" expr ")" |
+ <a name="NWDCUvTi-f">"sqrt (" expr ")" | "acos (" expr ")" | "asin (" expr ")" |</a>
+ "atan (" expr ")" | "_pi_" | "_e_" |
+ "xcoord (" point ")" | "ycoord (" point ")" | "angle "(" ThreePoints ")"|
+ "angledeg" "(" ThreePoints ")" | "direction" "(" TwoPoints ")" |
+ "directiondeg" "(" TwoPoints ")" | "_linethickness_"
+</pre>
+Note that <code>_pi_</code> and <code>_e_</code> can be used to access the value of the constants
+Pi and e.
+
+<pre><a name="NWCUvTi-1aVxdI-1" href="#NWDCUvTi-f"><dfn>&lt;subroutine <tt>expr</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+sub expr {
+ my $lc = $_[0];
+ my($left,$op,$right);
+
+ $left = term($lc);
+ while ($op = addop()) {
+ $right = term($lc);
+ if ($op eq '+')
+ { $left += $right }
+ else
+ { $left -= $right }
+ }
+ return $left;
+}
+
+sub addop {
+ s/^([+-])// &amp;&amp; $1;
+}
+
+sub term {
+ my $lc = $_[0];
+ my ($left, $op, $right);
+ $left = factor($lc);
+ while ($op = mulop()) {
+ $right = factor($lc);
+ if ($op eq '*')
+ { $left *= $right }
+ elsif ($op =~ /rem/i) {
+ eval {$left %= $right};
+ PrintFatalError(&quot;Division by zero&quot;, $lc) if $@;
+ }
+ else {
+ eval {$left /= $right};
+ PrintFatalError(&quot;Division by zero&quot;, $lc) if $@;
+ }
+ }
+ return $left;
+}
+
+sub mulop {
+ (s#^([*/])## || s/^(rem)//i) &amp;&amp; lc($1);
+}
+
+sub factor {
+ my $lc = $_[0];
+ my ($left);
+
+ $left = primitive($lc);
+ if (s/^\*\*//) {
+ $left **= factor($lc);
+ }
+ return $left;
+}
+
+sub primitive {
+ my $lc = $_[0];
+ my $val;
+ s/\s*//;
+ if (s/^\(//) { #is it an expr in parentheses
+ $val = expr($lc);
+ s/^\)// || PrintErrorMessage(&quot;Missing right parenthesis&quot;, $lc);
+ }
+ elsif (s/^-//) { # is it a negated primitive
+ $val = - primitive();
+ }
+ elsif (s/^\+//) { # is it a positive primitive
+ $val = primitive();
+ }
+ elsif (s/^angledeg//i) {
+ chk_lparen(&quot;angledeg&quot;,$lc);
+ my $point_1 = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$point_1});
+ my $point_2 = get_point($lc);
+ my ($x2,$y2,$pSV2,$pS2)=unpack(&quot;d3A*&quot;,$PointTable{$point_2});
+ my $point_3 = get_point($lc);
+ my ($x3,$y3,$pSV3,$pS3)=unpack(&quot;d3A*&quot;,$PointTable{$point_3});
+ my $d12 = Length($x1, $y1, $x2, $y2);
+ my $d23 = Length($x2, $y2, $x3, $y3);
+ my $d31 = Length($x3, $y3, $x1, $y1);
+ if ( $d12 == 0 ) {
+ PrintErrorMessage(&quot;points `$point_1' and `$point_2' are the same&quot;, $lc);
+ $val = 0;
+ }
+ elsif ( $d23 == 0 ) {
+ PrintErrorMessage(&quot;points `$point_2' and `$point_3' are the same&quot;, $lc);
+ $val = 0;
+ }
+ elsif ( $d31 == 0 ) {
+ PrintErrorMessage(&quot;points `$point_1' and `$point_3' are the same&quot;, $lc);
+ $val = 0;
+ }
+ else {
+ $val = Angle($x1, $y1, $x2, $y2, $x3, $y3);
+ $val = 0 if $val == -500;
+ }
+ chk_rparen(&quot;Missing right parenthesis&quot;, $lc);
+ }
+ elsif (s/^angle//i) {
+ chk_lparen(&quot;angle&quot;,$lc);
+ my $point_1 = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$point_1});
+ my $point_2 = get_point($lc);
+ my ($x2,$y2,$pSV2,$pS2)=unpack(&quot;d3A*&quot;,$PointTable{$point_2});
+ my $point_3 = get_point($lc);
+ my ($x3,$y3,$pSV3,$pS3)=unpack(&quot;d3A*&quot;,$PointTable{$point_3});
+ my $d12 = Length($x1, $y1, $x2, $y2);
+ my $d23 = Length($x2, $y2, $x3, $y3);
+ my $d31 = Length($x3, $y3, $x1, $y1);
+ if ( $d12 == 0 ) {
+ PrintErrorMessage(&quot;points `$point_1' and `$point_2' are the same&quot;, $lc);
+ $val = 0;
+ }
+ elsif ( $d23 == 0 ) {
+ PrintErrorMessage(&quot;points `$point_2' and `$point_3' are the same&quot;, $lc);
+ $val = 0;
+ }
+ elsif ( $d31 == 0 ) {
+ PrintErrorMessage(&quot;points `$point_1' and `$point_3' are the same&quot;, $lc);
+ $val = 0;
+ }
+ else {
+ $val = Angle($x1, $y1, $x2, $y2, $x3, $y3);
+ if ($val == -500) {
+ $val = 0;
+ }
+ else {
+ $val = D2R * $val;
+ }
+ }
+ chk_rparen(&quot;Missing right parenthesis&quot;, $lc);
+ }
+ elsif (s/^area//i) {
+ chk_lparen(&quot;angledeg&quot;,$lc);
+ my $point_1 = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$point_1});
+ my $point_2 = get_point($lc);
+ my ($x2,$y2,$pSV2,$pS2)=unpack(&quot;d3A*&quot;,$PointTable{$point_2});
+ my $point_3 = get_point($lc);
+ my ($x3,$y3,$pSV3,$pS3)=unpack(&quot;d3A*&quot;,$PointTable{$point_3});
+ $val = triangleArea($x1, $y1, $x2, $y2, $x3, $y3);
+ chk_rparen(&quot;Missing right parenthesis&quot;, $lc);
+ }
+ elsif (s/^asin//i) {
+ chk_lparen(&quot;asin&quot;);
+ $val = expr();
+ PrintFatalError(&quot;Can't take asin of $val&quot;, $lc) if $val &lt; -1 || $val &gt; 1;
+ $val = asin($val);
+ chk_rparen(&quot;Missing right parenthesis&quot;, $lc);
+ }
+ elsif (s/^acos//i) {
+ chk_lparen(&quot;acos&quot;);
+ $val = expr();
+ PrintFatalError(&quot;Can't take acos of $val&quot;, $lc) if $val &lt; -1 || $val &gt; 1 ;
+ $val = acos($val);
+ chk_rparen(&quot;Missing right parenthesis&quot;, $lc);
+ }
+ elsif (s/^atan//i) {
+ chk_lparen(&quot;atan&quot;);
+ $val = expr();
+ $val = atan($val);
+ chk_rparen(&quot;Missing right parenthesis&quot;, $lc);
+ }
+ elsif (s/^cos//i) {
+ chk_lparen(&quot;cos&quot;);
+ $val = expr();
+ $val = cos($val);
+ chk_rparen(&quot;Missing right parenthesis&quot;, $lc);
+ }
+ elsif (s/^directiondeg//i) {
+ chk_lparen(&quot;directiondeg&quot;,$lc);
+ my $point_1 = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$point_1});
+ my $point_2 = get_point($lc);
+ my ($x2,$y2,$pSV2,$pS2)=unpack(&quot;d3A*&quot;,$PointTable{$point_2});
+ my $x3 = $x1+1;
+ if ( ($y2 - $y1) &gt;= 0) {
+ $val = Angle($x3, $y1, $x1, $y1, $x2, $y2);
+ $val = 0 if $val == -500;
+ }
+ else {
+ $val = 360 - Angle($x3, $y1, $x1, $y1, $x2, $y2);
+ $val = 0 if $val == -500;
+ }
+ chk_rparen(&quot;Missing right parenthesis&quot;, $lc);
+ }
+ elsif (s/^direction//i) {
+ chk_lparen(&quot;direction&quot;,$lc);
+ my $point_1 = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$point_1});
+ my $point_2 = get_point($lc);
+ my ($x2,$y2,$pSV2,$pS2)=unpack(&quot;d3A*&quot;,$PointTable{$point_2});
+ my $x3 = $x1+1;
+ if ( ($y2 - $y1) &gt;= 0) {
+ $val = Angle($x3, $y1, $x1, $y1, $x2, $y2);
+ $val = 0 if $val == -500;
+ $val = D2R * $val;
+ }
+ else {
+ $val = 360 - Angle($x3, $y1, $x1, $y1, $x2, $y2);
+ $val = 0 if $val == -500;
+ $val = D2R * $val;
+ }
+ chk_rparen(&quot;Missing right parenthesis&quot;, $lc);
+ }
+ elsif (s/^exp//i) {
+ chk_lparen(&quot;exp&quot;);
+ $val = expr();
+ $val = exp($val);
+ chk_rparen(&quot;Missing right parenthesis&quot;, $lc);
+ }
+ elsif (s/^int//i) {
+ chk_lparen(&quot;int&quot;);
+ $val = expr();
+ $val = int($val);
+ chk_rparen(&quot;Missing right parenthesis&quot;, $lc);
+ }
+ elsif (s/^log//i) {
+ chk_lparen(&quot;log&quot;);
+ $val = expr();
+ PrintFatalError(&quot;Can't take log of $val&quot;, $lc) if $val &lt;= 0;
+ $val = log($val);
+ chk_rparen(&quot;Missing right parenthesis&quot;, $lc);
+ }
+ elsif (s/^sin//i) {
+ chk_lparen(&quot;sin&quot;);
+ $val = expr();
+ $val = sin($val);
+ chk_rparen(&quot;Missing right parenthesis&quot;, $lc);
+ }
+ elsif (s/^sgn//i) {
+ chk_lparen(&quot;sgn&quot;);
+ $val = expr();
+ if ($val &gt; 0) {
+ $val = 1;
+ }
+ elsif ($val == 0) {
+ $val = 0;
+ }
+ else {
+ $val = -1;
+ }
+ chk_rparen(&quot;Missing right parenthesis&quot;, $lc);
+ }
+ elsif (s/^sqrt//i) {
+ chk_lparen(&quot;sqrt&quot;);
+ $val = expr();
+ $val = sqrt($val);
+ chk_rparen(&quot;Missing right parenthesis&quot;, $lc);
+ }
+ elsif (s/^tan//i) {
+ chk_lparen(&quot;tan&quot;);
+ $val = expr();
+ $val = sin($val)/cos($val);
+ chk_rparen(&quot;Missing right parenthesis&quot;, $lc);
+ }
+ elsif (s/^xcoord//i) {
+ chk_lparen(&quot;xcoord&quot;);
+ my $point_name = get_point;
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$point_name});
+ $val = $x1;
+ chk_rparen(&quot;Missing right parenthesis&quot;, $lc);
+ }
+ elsif (s/^ycoord//i) {
+ chk_lparen(&quot;ycoord&quot;);
+ my $point_name = get_point;
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$point_name});
+ $val = $y1;
+ chk_rparen(&quot;Missing right parenthesis&quot;, $lc);
+ }
+ elsif (s/^_pi_//i) {
+ $val = PI;
+ }
+ elsif (s/^_e_//i) {
+ $val = 2.71828182845905;
+ }
+ elsif (s/^_linethickness_//i) {
+ $val = $LineThickness / $xunits;
+ }
+ else {
+ my $err_code;
+ ($val,$err_code) = ComputeDist($lc);
+ }
+ s/\s*//;
+ return $val;
+}
+
+</pre><p><a name="NWDCUvTi-g">The subroutine </a><code>memberOf</code> is used to check whether a string is part of
+a list of strings. We assume that the first argument is the string in
+question. We compare each list element against the string in question and
+if we find it we stop and return the value <code>1</code> (denoting truth). Otherwise,
+we simply return the value <code>0</code> (denoting false).
+
+<pre><a name="NWCUvTi-2tc9Fr-1" href="#NWDCUvTi-g"><dfn>&lt;subroutine <tt>memberOf</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+sub memberOf {
+ my $elem = shift(@_);
+
+ my $found = 0;
+ foreach $item (@_){
+ if ($item eq $elem){
+ $found = 1;
+ last;
+ }
+ }
+ return $found;
+}
+
+</pre><p><a name="NWDCUvTi-h">The subroutine </a><code>midpoint</code> computes the coordinates of the midpoint of two points
+by means of the simple formula:
+<center>
+m<sub>x</sub>=x<sub>1</sub>+(y<sub>2</sub> - y<sub>1</sub>)/2 <br>
+m<sub>y</sub>=y<sub>1</sub>+(x<sub>2</sub> - x<sub>1</sub>)/2
+</center>
+
+<pre><a name="NWCUvTi-2wh1NN-1" href="#NWDCUvTi-h"><dfn>&lt;subroutine <tt>midpoint</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+sub midpoint {
+ my ($x1, $y1, $x2, $y2)=@_;
+ return ($x1 + ($x2 - $x1)/2,
+ $y1 + ($y2 - $y1)/2);
+}
+
+
+</pre><p><a name="NWDCUvTi-i">The subroutine </a><code>tand</code> computes the tangent of an angle. The angle is
+supposed to be in degrees. We simply transform it into radians and then
+compute the actual result.
+
+<pre><a name="NWCUvTi-22jtMr-1" href="#NWDCUvTi-i"><dfn>&lt;subroutine <tt>tand</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+sub tand {
+ my $d = $_[0];
+ $d = $d * PI / 180;
+ return sin($d)/cos($d);
+}
+
+</pre><p>The subroutine <code>get_string</code> is used to extract a leading valid mathspic string
+from the input line. A string must start with a quotation mark, i.e., <code>&quot;</code>,
+and must end with the same symbol. A string may contain quotation marks which
+must be escaped with a backslash, i.e., <code>\</code>. Initially, we remove all
+leading white space. If the next character of the string is not a quotation
+mark we print an error message and stop. Otherwise, we split the string into
+an array of characters and store the characters up to the next quotation
+mark to the array <code>@cmd</code>. In case the next character is a backslash and
+we aren't at the end of the input string and the next character is a
+quotation mark, we have an escape sequence. This means that we store these
+two characters in the <code>@cmd</code> array and skip to characters after the quotation
+mark. Otherwise, we simply store the character in the <code>@cmd</code> array and
+<a name="NWDCUvTi-j">skip to the next character. This process is repeated until either we consume</a>
+all the characters of the string or until we find a sole quotation mark.
+Since we are not sure what has forced the loop to exit, we check whether
+there are still characters in the input string and we check whether this
+is a quotation mark. If these tests fail we have a string without a
+closing quotation mark. In all cases we return a triplet consisting of
+a number denoting success (1) or failure (0) and what we have consumed
+from the input string, and what is left from the input string.
+
+<pre><a name="NWCUvTi-ufkvF-1" href="#NWDCUvTi-j"><dfn>&lt;subroutine <tt>get_string</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+sub get_string {
+ my $string = shift;
+ my $lc = shift;
+
+ $string =~ s/^\s+//;
+ if ($string !~ s/^\&quot;//) {
+ PrintErrorMessage(&quot;No starting \&quot; found&quot;,$lc);
+ return (1,$string,$string);
+ }
+ my @ch = split //,$string;
+ my @cmd;
+ while (@ch and $ch[0] ne &quot;\&quot;&quot;) {
+ if ($ch[0] eq &quot;\\&quot; and (defined $ch[1]) and $ch[1] eq &quot;\&quot;&quot;) {
+ shift @ch;
+ push @cmd, $ch[0];
+ shift @ch;
+ }
+ else {
+ push @cmd, $ch[0];
+ shift @ch;
+ }
+ }
+ if (! defined $ch[0]) {
+ PrintErrorMessage(&quot;No closing \&quot; found&quot;,$lc);
+ return (1,join(&quot;&quot;,@cmd), join(&quot;&quot;,@ch))
+ }
+ else {
+ shift @ch;
+ return (0, join(&quot;&quot;,@cmd), join(&quot;&quot;,@ch))
+ }
+}
+
+</pre><p><a name="NWDCUvTi-k">The definition as well as an explanation of the functionality of the</a>
+following subroutine can be found in "Programming Perl", 3rd edition.
+
+<pre><a name="NWCUvTi-1MGdDt-1" href="#NWDCUvTi-k"><dfn>&lt;subroutine <tt>is_tainted</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+sub is_tainted {
+ my $arg = shift;
+ my $nada = substr($arg,0,0);
+ local $@;
+ eval { eval &quot;# $nada&quot;};
+ return length($@) != 0;
+}
+
+</pre><p><a name="NWDCUvTi-l">The subroutine </a><code>noOfDigits</code> has one argument which is a number and returns
+the number of decimal digits it has. If the number matches the regular
+expression <code>^\d+(?!\.)</code> (a series of digits <i>not</i> followed by a
+period), then the number of decimal digits is zero. If the
+number matches the
+regular expression <code>^\d+\.(\d+)?</code>, then number of decimal digits equals
+<code>length($1)</code>. Naturally, it maybe zero!
+
+<pre><a name="NWCUvTi-3mBo7s-1" href="#NWDCUvTi-l"><dfn>&lt;subroutine <tt>noOfDigits</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+sub noOfDigits {
+ my $num = $_[0];
+
+ if ($num =~ /^[\+-]?\d+(?!\.)/) {
+ return 0;
+ }
+ elsif ($num =~ /^[\+-]\d+\.(\d+)?/) {
+ return length($1);
+ }
+}
+
+</pre><p><a name="NWDCUvTi-m">Subroutine </a><code>drawsquare</code> is use by the <code>drawpoints</code> routine to plot a
+point whose point symbol is a square. The subroutine has one argument, which is
+equal to the radius of the point. From this argument it computes the side of
+the square.
+
+<pre><a name="NWCUvTi-3ywJ89-1" href="#NWDCUvTi-m"><dfn>&lt;subroutine <tt>drawsquare</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+sub drawsquare {
+ my $s = $_[0];
+ #$s *= sqrt(2);
+ $s = sprintf &quot;%.5f&quot;, $s;
+ my $code = &quot;\\setlength{\\unitlength}{$xunits}%\n&quot;;
+ $code .= &quot;\\begin{picture}($s,$s)\\put(0,0)&quot; .
+ &quot;{\\framebox($s,$s){}}\\end{picture}&quot;;
+ return $code;
+}
+
+</pre><p><a name="NWDCUvTi-n">Subroutine </a><code>X2sp</code> has two arguments: a number and a length unit. It returns
+the length expresssed in sp units.
+
+<pre><a name="NWCUvTi-39f7o8-1" href="#NWDCUvTi-n"><dfn>&lt;subroutine <tt>X2sp</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+sub X2sp {
+ my $LT = shift;
+ my $units = shift;
+
+ if ($units eq &quot;pc&quot;) {
+ return $LT * 786432;
+ }
+ elsif ($units eq &quot;pt&quot;) {
+ return $LT * 65536;
+ }
+ elsif ($units eq &quot;in&quot;) {
+ return $LT * 4736286.72;
+ }
+ elsif ($units eq &quot;bp&quot;) {
+ return $LT * 65781.76;
+ }
+ elsif ($units eq &quot;cm&quot;) {
+ return $LT * 1864679.811023622;
+ }
+ elsif ($units eq &quot;mm&quot;) {
+ return $LT * 186467.981102362;
+ }
+ elsif ($units eq &quot;dd&quot;) {
+ return $LT * 70124.086430424;
+ }
+ elsif ($units eq &quot;cc&quot;) {
+ return $LT * 841489.037165082;
+ }
+ elsif ($units eq &quot;sp&quot;) {
+ return $LT;
+ }
+}
+
+
+</pre><p><a name="NWDCUvTi-o">Subroutine </a><code>sp2X</code> has two arguments: a number that denotes a length in sp units
+ and a length unit. It returns the length expresssed in units that are specified by
+ the second argument.
+
+<pre><a name="NWCUvTi-3wV39i-1" href="#NWDCUvTi-o"><dfn>&lt;subroutine <tt>sp2X</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+sub sp2X {
+ my $LT = shift;
+ my $units = shift;
+
+ if ($units eq &quot;pc&quot;) {
+ return $LT / 786432;
+ }
+ elsif ($units eq &quot;pt&quot;) {
+ return $LT / 65536;
+ }
+ elsif ($units eq &quot;in&quot;) {
+ return $LT / 4736286.72;
+ }
+ elsif ($units eq &quot;bp&quot;) {
+ return $LT / 65781.76;
+ }
+ elsif ($units eq &quot;cm&quot;) {
+ return $LT / 1864679.811023622;
+ }
+ elsif ($units eq &quot;mm&quot;) {
+ return $LT / 186467.981102362;
+ }
+ elsif ($units eq &quot;dd&quot;) {
+ return $LT / 70124.086430424;
+ }
+ elsif ($units eq &quot;cc&quot;) {
+ return $LT / 841489.037165082;
+ }
+ elsif ($units eq &quot;sp&quot;) {
+ return $LT;
+ }
+}
+
+</pre><p><a name="NWDCUvTi-p">Subroutine </a><code>setLineThickness</code> takes two arguments: the value of the variable
+ <code>$xunits</code> and a string denoting the linethickness. It returns the linthickness
+ expressed in the units of the <code>$xunits</code>.
+
+<pre><a name="NWCUvTi-4XWBBY-1" href="#NWDCUvTi-p"><dfn>&lt;subroutine <tt>setLineThickness</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+sub setLineThickness {
+ my $Xunits = shift;
+ my $LT = shift;
+ $Xunits =~ s/^((\+|-)?\d+(\.\d+)?([eE](\+|-)?\d+)?)//;
+ my $xlength = &quot;$1&quot;;
+ $Xunits =~ s/^\s*($units)//;
+ my $x_in_units = $1;
+ $LT =~ s/^((\+|-)?\d+(\.\d+)?([eE](\+|-)?\d+)?)//;
+ my $LTlength = &quot;$1&quot;;
+ $LT =~ s/^\s*($units)//;
+ my $LT_in_units = $1;
+ $LTlength = X2sp($LTlength,$LT_in_units);
+ $LTlength = sp2X($LTlength,$x_in_units);
+ return $LTlength;
+}
+
+</pre><p>The subroutine <code>process_input</code> accepts one argument which is a file handle
+that corresponds to the file that the subroutine is supposed to process.
+The processing cycle is fairly simple: we input one line at the time, remove
+any leading space characters and the trailing new line character, and then
+start the actual processing. The variable <code>$INFILE</code> contains the name of
+the input file and the variable <code>$lc</code> is the local line counter. The
+commands <code>beginSkip</code> and <code>endSkip</code> can be used to ignore blocks
+of code and so we need to process them here. The variable <code>$no_output</code>
+is used as a switch to toggle from process mode to no-precess mode.
+<a name="NWDCUvTi-q">If the first token is </a><code>beginSkip</code>, we set the variable <code>$no_output</code> to 1,
+print a comment to the output file and continue with the next input line.
+If the first token is <code>endSkip</code>, we check whether we are in a no-process
+mode. If this is the case, we revert to process mode; otherwise we print
+an error message. Finally, depending on whether we are in process or no-process
+mode we process the input text or simply printed commented out to the output
+file. Note, that we don't allow nested comment blocks, as this makes really
+no sense!
+
+<pre><a name="NWCUvTi-1RrLPF-1" href="#NWDCUvTi-q"><dfn>&lt;subroutine <tt>process_input</tt> &gt;=</dfn></a> <b>(<a href="#NWDCUvTi-9">&lt;-U</a>)</b>
+ sub process_input {
+ my ($INFILE,$currInFile) = @_;
+ my $lc = 0;
+ my $no_output = 0;
+ $curr_in_file = $currInFile;
+ LINE: while(&lt;$INFILE&gt;) {
+ $lc++;
+ chomp($command = $_);
+ s/^\s+//;
+ if (/^beginSkip\s*/i) {
+ $no_output = 1;
+ print OUT &quot;%%$_&quot; if $comments_on;
+ next LINE;
+ }
+ elsif (/^endSkip\s*/i) {
+ if ($no_output == 0) {
+ PrintErrorMessage(&quot;endSkip without beginSkip&quot;,$lc);
+ }
+ else {
+ $no_output = 0;
+ }
+ print OUT &quot;%%$_&quot; if $comments_on and !$no_output;
+ next LINE;
+ }
+ elsif ($no_output == 1) {
+ next LINE;
+ }
+ else {
+ if (/^[^\\]/) {
+ my $out_line = mpp($command,$lc) unless /^\\/; #call macro pre-processor
+ $_ = &quot;$out_line\n&quot;;
+ }
+ <a name="NWCUvTi-1RrLPF-1-u1" href="#NWDCUvTi-r"><i>&lt;process input line&gt;</i></a>
+ }
+ }
+ }
+
+</pre><p>Each command line starts with a particular <i>token</i> and depending on
+which one we have we perform different actions. If the first character
+is <code>%</code> we have a comment line, and depending on the value of the variable
+<code>$comments_on</code> we either output the comment on the output file (default
+action) or just ignore it and continue with the next input line. In case the
+first token is the name of a valid command we process the command and
+output the corresponding code. Otherwise, we print an error message to
+the screen and to the log file and continue with the next input line.
+Note that the input language is case-insensitive and so one is free to write a
+command name using any combination of upper and lower case
+letters, e.g., the tokens <code>lAtEx</code>,
+<code>LaTeX</code>, and <code>latex</code> are considered exactly the same.
+The valid <i>MathsPIC</i> commands are the following (don't pay attention
+to the case!):
+<ul>
+<li>
+Commands <code>drawAngleArc</code> and <code>drawAngleArrow</code> are used to draw an arc and an
+arrow, respectively. Since, their user interface is identical, we process
+them as if they were identical commands.
+</li>
+<li>
+Command <code>drawcircle</code> is used to draw a circle with a specified radius.
+</li>
+<li>
+Command <code>drawCircumCircle</code> is used to draw the circumcircle of triangle
+specified by three points.
+</li>
+<li>
+Command <code>drawexcircle</code> is used to draw the excircle of triangle
+relative to a given side of the triangle.
+</li>
+<li>
+Command <code>drawincircle</code> is used to draw the incircle of triangle.
+</li>
+<li>
+Command <code>drawincurve</code> is used to draw a curve that passes through a number of points.
+</li>
+<li> Command <code>drawline</code> is used to draw either
+a line (not necessarily a straight one) or a number of lines from a list
+or lists of points. The lines are specified as pairs of points that can
+be separated by blank spaces.
+<li> Command <code>drawthickline</code> is used to draw either
+a thick line (not necessarily a straight one) or a number of lines from a list
+or lists of points. The lines are specified as pairs of points that can
+be separated by blank spaces.
+</li>
+<li>
+Command <code>drawPerpendicular</code> draws a perpendicular line from point A to
+line BC.
+</li>
+<li> Command <code>drawpoint</code> is used to draw one, two or more points.
+The point names can be separated by blanks.
+</li>
+<li>
+Command <code>drawRightAngle</code> draws an angle, specified by three points,
+of a size specified by a side length.
+</li>
+<li>
+Command <code>drawsquare</code> draws a square, centered at the coordinates of the
+first arguments, which is assumed to be a point, with side equal to the
+second argument.
+</li>
+<li>
+Command <code>inputfile*</code> is used to verbatim include a file into the output
+file.
+</li>
+<li>
+Command <code>inputfile</code> is used to include a <i>MathsPIC</i> program file
+into the main file.
+</li>
+<li>
+Command <code>linethickness</code> should be used to set the thickness of lines.
+</li>
+<li>
+The <code>paper</code> command sets the paper scale, size, axes, etc. The most
+general format of the command follows:
+<center>
+<tt>paper{units(mm), xrange(0,120), yrange(0,100),axes(LRTB)}</tt>
+</center>
+Note, that one may opt not to write the commas between the different
+parts of command.
+</li>
+<li>
+Command <code>point*</code> allocates <i>new</i> co-ordinates and optionally
+a T<sub>E</sub>X point-name, to an existing point-name.
+Command <code>point</code> allocates co-ordinates and, optionally a T<sub>E</sub>X
+point character, to a <i>new</i> point-name. Since, both commands have
+identical syntax, we handle them together.
+</li>
+<li> Command <code>PointSymbol</code> is used to set or reset the default
+point symbol, i.e., when one plots a point this is the symbol that will
+appear on the final DVI/PostScript file.
+</li>
+<li>
+In the original DOS version of <tt>mathspic</tt> the command
+<code>setPointNumber</code> was used to set the length of the arrays that keep the
+various point related information. Since, in Perl arrays are dynamic objects
+and one can push as many objects as he/she wants, the command is implemented
+as an no-op. For reasons of compatibility, we only check the syntax of the
+command.
+</li>
+<li>
+Commands <code>showAngle</code> and <code>showArea</code> can be used to get
+the angle or the area determined by three points. In addition, the command
+<code>showLenght</code> can be used to get the length between two points. These three
+commands produce a comment to the output file.
+</li>
+<li> The <code>system</code> command provides a shell escape.
+</li>
+<li>
+The <code>text</code> command is used to put a symbol/text at a
+particular point location.
+</li>
+<li>
+Command <code>var</code> is used to store a numeric value into a comma separated
+list of variables.
+</li>
+<li>
+Command <code>const</code> is used to store a numeric value into a comma separated
+list of variables, whose value cannot be altered.
+</li>
+<li>
+<a name="NWDCUvTi-r">If a line starts with a backslash, </a><code>\</code>, then we copy verbatim this
+line to the output file. In case the second character is a space character,
+then we simply output a copy of the line without the leading backslash.
+</li>
+</ul>
+Empty lines are always ignored.
+
+<pre><a name="NWCUvTi-RKDir-1" href="#NWDCUvTi-r"><dfn>&lt;process input line&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-q">&lt;-U</a>)</b>
+
+ if (/^\s*%/)
+ {
+ print OUT &quot;$_&quot; if $comments_on;
+ }
+ elsif (s/^\s*(beginloop(?=\W))//i) {
+ s/\s+//;
+ my $times = expr($lc);
+ print OUT &quot;%% BEGINLOOP $times\n&quot; if $comments_on;
+ my @C = ();
+ REPEATCOMMS: while (&lt;$INFILE&gt;) {
+ if (/^\s*endloop/i) {
+ last REPEATCOMMS;
+ }
+ else {
+ push @C, $_;
+ }
+ }
+ if (! /^\s*endloop/i) {
+ PrintFatalError(&quot;unexpected end of file&quot;,$lc);
+ }
+ else {
+ s/^\s*endloop//i;
+ for(my $i=1; $i&lt;=$times; $i++) {
+ tie *DUMMY, 'DummyFH', \@C;
+ process_input(DUMMY, $currInFile);
+ untie *DUMMY;
+ }
+ print OUT &quot;%% ENDLOOP\n&quot; if $comments_on;
+ }
+ }
+ elsif (s/^\s*(ArrowShape(?=\W))//i)
+ {
+ my $cmd = $1;
+ print OUT &quot;%% $cmd$_&quot; if $comments_on;
+ <a name="NWCUvTi-RKDir-1-u1" href="#NWDCUvTi-1W"><i>&lt;process <tt>ArrowShape</tt> command&gt;</i></a>
+ }
+ elsif (s/^\s*(const(?=\W))//i)
+ {
+ print OUT &quot;%% $1$_&quot; if $comments_on;
+ <a name="NWCUvTi-RKDir-1-u2" href="#NWDCUvTi-1c"><i>&lt;process <tt>const</tt> command&gt;</i></a>
+ }
+ elsif (s/^\s*(dasharray(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT &quot;%% $cmd$_&quot; if $comments_on;
+ <a name="NWCUvTi-RKDir-1-u3" href="#NWDCUvTi-s"><i>&lt;process <tt>dasharray</tt> command&gt;</i></a>
+ }
+ elsif (s/^\s*(drawAngleArc(?=\W))//i or s/^\s*(drawAngleArrow(?=\W))//i )
+ {
+ my $cmd = $1;
+ print OUT &quot;%% $cmd$_&quot; if $comments_on;
+ <a name="NWCUvTi-RKDir-1-u4" href="#NWDCUvTi-t"><i>&lt;process <tt>drawAngleArcOrArrow</tt> command&gt;</i></a>
+ }
+ elsif (s/^\s*(drawArrow(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT &quot;%% $cmd$_&quot; if $comments_on;
+ DrawLineOrArrow(0,$lc);
+ }
+ elsif (s/^\s*(drawcircle(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT &quot;%% $cmd$_&quot; if $comments_on;
+ <a name="NWCUvTi-RKDir-1-u5" href="#NWDCUvTi-w"><i>&lt;process <tt>drawcircle</tt> command&gt;</i></a>
+ }
+ elsif (s/^\s*(drawcurve(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT &quot;%% $cmd$_&quot; if $comments_on;
+ DrawLineOrArrow(2,$lc);
+ }
+ elsif (s/^\s*(drawcircumcircle(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT &quot;%% $cmd$_&quot; if $comments_on;
+ <a name="NWCUvTi-RKDir-1-u6" href="#NWDCUvTi-x"><i>&lt;process <tt>drawcircumcircle</tt> command&gt;</i></a>
+ }
+ elsif (s/^\s*(drawexcircle(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT &quot;%% $cmd$_&quot; if $comments_on;
+ <a name="NWCUvTi-RKDir-1-u7" href="#NWDCUvTi-y"><i>&lt;process <tt>drawexcircle</tt> command&gt;</i></a>
+ }
+ elsif (s/^\s*(drawincircle(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT &quot;%% $cmd$_&quot; if $comments_on;
+ <a name="NWCUvTi-RKDir-1-u8" href="#NWDCUvTi-z"><i>&lt;process <tt>drawincircle</tt> command&gt;</i></a>
+ }
+ elsif (s/^\s*(drawline(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT &quot;%% $cmd$_&quot; if $comments_on;
+ DrawLineOrArrow(1,$lc);
+ }
+ elsif (s/^\s*(drawthickarrow(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT &quot;%% $cmd$_&quot; if $comments_on;
+ print OUT &quot;\\setplotsymbol ({\\usefont{OT1}{cmr}{m}{n}\\large .})%\n&quot;;
+ print OUT &quot;{\\setbox1=\\hbox{\\usefont{OT1}{cmr}{m}{n}\\large .}%\n&quot;;
+ print OUT &quot; \\global\\linethickness=0.31\\wd1}%\n&quot;;
+ DrawLineOrArrow(0,$lc);
+ print OUT &quot;\\setlength{\\linethickness}{0.4pt}%\n&quot;;
+ print OUT &quot;\\setplotsymbol ({\\usefont{OT1}{cmr}{m}{n}\\tiny .})%\n&quot;;
+ }
+ elsif (s/^\s*(drawthickline(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT &quot;%% $cmd$_&quot; if $comments_on;
+ print OUT &quot;\\setplotsymbol ({\\usefont{OT1}{cmr}{m}{n}\\large .})%\n&quot;;
+ print OUT &quot;{\\setbox1=\\hbox{\\usefont{OT1}{cmr}{m}{n}\\large .}%\n&quot;;
+ print OUT &quot; \\global\\linethickness=0.31\\wd1}%\n&quot;;
+ DrawLineOrArrow(1,$lc);
+ print OUT &quot;\\setlength{\\linethickness}{0.4pt}%\n&quot;;
+ print OUT &quot;\\setplotsymbol ({\\usefont{OT1}{cmr}{m}{n}\\tiny .})%\n&quot;;
+ }
+ elsif (s/^\s*(drawperpendicular(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT &quot;%% $cmd$_&quot; if $comments_on;
+ <a name="NWCUvTi-RKDir-1-u9" href="#NWDCUvTi-10"><i>&lt;process <tt>drawPerpendicular</tt> command&gt;</i></a>
+ }
+ elsif (s/^\s*(drawpoint(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT &quot;%% $cmd$_&quot; if $comments_on;
+ <a name="NWCUvTi-RKDir-1-u10" href="#NWDCUvTi-11"><i>&lt;process <tt>drawpoint</tt> command&gt;</i></a>
+ }
+ elsif (s/^\s*(drawRightAngle(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT &quot;%% $cmd$_&quot; if $comments_on;
+ <a name="NWCUvTi-RKDir-1-u11" href="#NWDCUvTi-12"><i>&lt;process <tt>drawRightAngle</tt> command&gt;</i></a>
+ }
+ elsif (s/^\s*(drawsquare(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT &quot;%% $cmd$_&quot; if $comments_on;
+ <a name="NWCUvTi-RKDir-1-u12" href="#NWDCUvTi-13"><i>&lt;process <tt>drawsquare</tt> command&gt;</i></a>
+ }
+ elsif (s/^\s*inputfile\*//i)
+ {
+ <a name="NWCUvTi-RKDir-1-u13" href="#NWDCUvTi-14"><i>&lt;process <tt>inputfile*</tt> command&gt;</i></a>
+ }
+ elsif (s/^\s*(inputfile(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT &quot;%% $cmd$_&quot; if $comments_on;
+ <a name="NWCUvTi-RKDir-1-u14" href="#NWDCUvTi-15"><i>&lt;process <tt>inputfile</tt> command&gt;</i></a>
+ }
+ elsif (s/^\s*(linethickness(?=\W))//i)
+ {
+ my $cmd = $1;
+ print OUT &quot;%% $cmd$_&quot; if $comments_on;
+ <a name="NWCUvTi-RKDir-1-u15" href="#NWDCUvTi-16"><i>&lt;process <tt>linethickness</tt> command&gt;</i></a>
+ }
+ elsif (s/^\s*(paper(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT &quot;%% $cmd$_&quot; if $comments_on;
+ <a name="NWCUvTi-RKDir-1-u16" href="#NWDCUvTi-17"><i>&lt;process <tt>paper</tt> command&gt;</i></a>
+ }
+ elsif (s/^\s*(PointSymbol(?=\W))//i)
+ {
+ my $cmd = $1;
+ print OUT &quot;%% $cmd$_&quot; if $comments_on;
+ <a name="NWCUvTi-RKDir-1-u17" href="#NWDCUvTi-1X"><i>&lt;process <tt>PointSymbol</tt> command&gt;</i></a>
+ }
+ elsif (s/^\s*point(?=\W)//i)
+ {
+ my ($Point_Line);
+ chomp($Point_Line=$_);
+ <a name="NWCUvTi-RKDir-1-u18" href="#NWDCUvTi-1I"><i>&lt;process <tt>point/point*</tt> commands&gt;</i></a>
+ }
+ elsif (/^\s*setPointNumber(?=\W)/i)
+ {
+ PrintWarningMessage(&quot;Command setPointNumber is ignored&quot;,$lc);
+ next LINE;
+ }
+ elsif (s/^\s*(showAngle(?=\W))//i)
+ {
+ <a name="NWCUvTi-RKDir-1-u19" href="#NWDCUvTi-1B"><i>&lt;process <tt>showAngle</tt> command&gt;</i></a>
+ }
+ elsif (s/^\s*(showArea(?=\W))//i)
+ {
+ <a name="NWCUvTi-RKDir-1-u20" href="#NWDCUvTi-1C"><i>&lt;process <tt>showArea</tt> command&gt;</i></a>
+ }
+ elsif (s/^\s*(showLength(?=\W))//i)
+ {
+ <a name="NWCUvTi-RKDir-1-u21" href="#NWDCUvTi-1D"><i>&lt;process <tt>showLength</tt> command&gt;</i></a>
+ }
+ elsif (/^\s*showPoints(?=\W)/i)
+ {
+ print OUT &quot;%%-------------------------------------------------\n&quot;;
+ print OUT &quot;%% L I S T O F P O I N T S \n&quot;;
+ print OUT &quot;%%-------------------------------------------------\n&quot;;
+ foreach my $p (keys(%PointTable)) {
+ my ($x, $y, $pSV, $pS) = unpack(&quot;d3A*&quot;,$PointTable{$p});
+ printf OUT &quot;%%%%\t%s\t= ( %.5f, %.5f ), LF-radius = %.5f, symbol = %s\n&quot;,
+ $p, $x, $y, $pSV, $pS;
+ }
+ print OUT &quot;%%-------------------------------------------------\n&quot;;
+ print OUT &quot;%% E N D O F L I S T O F P O I N T S \n&quot;;
+ print OUT &quot;%%-------------------------------------------------\n&quot;;
+ next LINE;
+ }
+ elsif (/^\s*showVariables(?=\W)/i)
+ {
+ print OUT &quot;%%-------------------------------------------------\n&quot;;
+ print OUT &quot;%% L I S T O F V A R I A B L E S \n&quot;;
+ print OUT &quot;%%-------------------------------------------------\n&quot;;
+ foreach my $var (keys(%VarTable)) {
+ print OUT &quot;%%\t&quot;, $var, &quot;\t=\t&quot;, $VarTable{$var}, &quot;\n&quot;;
+ }
+ print OUT &quot;%%-------------------------------------------------\n&quot;;
+ print OUT &quot;%% E N D O F L I S T O F V A R I A B L E S \n&quot;;
+ print OUT &quot;%%-------------------------------------------------\n&quot;;
+ next LINE;
+ }
+ elsif (s/^\s*(system(?=\W))//i)
+ {
+ print OUT &quot;%% $1$_&quot; if $comments_on;
+ <a name="NWCUvTi-RKDir-1-u22" href="#NWDCUvTi-1Y"><i>&lt;process <tt>system</tt> command&gt;</i></a>
+ }
+ elsif (s/^\s*(text(?=\W))//i)
+ {
+ print OUT &quot;%% $1$_&quot; if $comments_on;
+ <a name="NWCUvTi-RKDir-1-u23" href="#NWDCUvTi-1Z"><i>&lt;process <tt>text</tt> command&gt;</i></a>
+ }
+ elsif (s/^\s*(var(?=\W))//i)
+ {
+ print OUT &quot;%% $1$_&quot; if $comments_on;
+ <a name="NWCUvTi-RKDir-1-u24" href="#NWDCUvTi-1d"><i>&lt;process <tt>var</tt> command&gt;</i></a>
+ }
+ elsif (/^\s*\\(.+)/)
+ {
+ my $line = $1;
+ if ($line =~ /^\s+(.+)/)
+ {
+ print OUT &quot; $line\n&quot;;
+ }
+ else
+ {
+ print OUT &quot;\\$line\n&quot;;
+ }
+ next LINE;
+ }
+ elsif (0==length) #empty line
+ {
+ next LINE;
+ }
+ else {
+ PrintErrorMessage(&quot;command not recognized&quot;,$lc);
+ next LINE;
+ }
+
+</pre><p>Command <code>dasharray</code> takes an arbitrary number of arguments that are used to
+specify a dash pattern. Its general syntax follows:
+<center>
+ <tt> "dasharray" "(" d<sub>1</sub> "," g<sub>1</sub> "," d<sub>2</sub> ","
+ g<sub>2</sub> "," ... ")"</tt>
+</center>
+where <tt>d<sub>i</sub></tt> denotes the length of a dash and <tt>g<sub>i</sub></tt>
+<a name="NWDCUvTi-s">denotes the length of gap between two consecutive dashes. Each </a><tt>d<sub>i</sub></tt>
+and <tt>g<sub>i</sub></tt> is a length (i.e., a number accompanied by a length of unit).
+Since we do not a priori know the number of arguments, we push them onto a stack and
+then we produce a command of the form
+<center>
+ <tt> \setdashpattern &lt; d<sub>1</sub>, g<sub>1</sub>, d<sub>2</sub>,
+ g<sub>2</sub>, ...&gt;</tt>
+</center>
+
+<pre><a name="NWCUvTi-19jqyn-1" href="#NWDCUvTi-s"><dfn>&lt;process <tt>dasharray</tt> command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-r">&lt;-U</a>)</b>
+ chk_lparen($cmd,$lc);
+ my @DashArray = ();
+ my $dash = &quot;&quot;;
+ my $dashpattern = &quot;&quot;;
+ PATTERN: while (1) {
+ $dash = sprintf(&quot;%.5f&quot;, expr($lc));
+ if (s/^\s*($units)//i) {
+ push (@DashArray, &quot;$dash$1&quot;);
+ }
+ else {
+ PrintErrorMessage(&quot;Did not found unit after expression&quot;, $lc);
+ }
+ s/\s*//;
+ if (/^[^,]/) {
+ last PATTERN;
+ }
+ else {
+ s/^,\s*//;
+ }
+ }
+ print OUT &quot;\\setdashpattern &lt;&quot;;
+ while (@DashArray) {
+ $dashpattern .= shift @DashArray;
+ $dashpattern .= &quot;,&quot;;
+ }
+ $dashpattern =~ s/,$//;
+ print OUT $dashpattern, &quot;&gt;\n&quot;;
+ chk_rparen(&quot;arguments of $cmd&quot;,$lc);
+ chk_comment($lc);
+
+</pre><p>The command <code>drawAngleArc</code> draws an arc in the specified angle, a
+distance <i>radius</i> from the angle. The angle is either <i>internal</i>
+(<= 180 degrees) or <i>external</i> (>180 degrees). The direction of the
+arc is either <i>clockwise</i> or <i>anticlockwise</i>. The command
+<code>drawAngleArrow</code> draws an arrow just like the command <code>drawAngleArc</code>
+draws an arc. The syntax of these commands is as follows:
+<pre>
+ cmds ::= ( "drawAngleArc" | "drawAngleArrow" ) args
+ args ::= "{" angle comma radius comma internal comma clockwise "}"
+ angle ::= "angle" "(" three-points ")"
+ radius ::= "radius" "(" distance ")"
+ distance ::= expression
+ internal ::= "internal" | "external"
+ clockwise ::= "clockwise" | "anticlockwise"
+ comma ::= "," | empty
+</pre>
+We first collect all relevant information by parsing the <code>args</code> and then
+call the either the subroutine <code>drawAngleArc</code> or the subroutine
+<code>drawAngleArrow</code> to produce the actual code
+which is then printed into the output file. In order to be able to distinguish
+which command we are dealing with we simply use the variable <code>$cmd</code>.
+<a name="NWDCUvTi-t">We now start parsing the input line. We first check whether there is a</a>
+left curly bracket. Next, we parse the <code>angle</code>, the <code>distance</code>, the
+<code>internal</code> and the <code>clockwise</code> parts of the command. Finally, we check
+for right curly bracket and a trailing comment. Depending on
+the value of
+the variable <code>$cmd</code> we call either the subroutine <code>drawAngleArc</code> or the
+subroutine <code>drawAngleArrow</code>. These subroutines return the code that will be
+finally output to the output file.
+
+<pre><a name="NWCUvTi-12lwO-1" href="#NWDCUvTi-t"><dfn>&lt;process <tt>drawAngleArcOrArrow</tt> command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-r">&lt;-U</a>)</b>
+
+ chk_lcb($cmd,$lc);
+ <a name="NWCUvTi-12lwO-1-u1" href="#NWDCUvTi-u"><i>&lt;process <tt>angle</tt> part of command&gt;</i></a>
+ s/^,\s*// or s/\s*//; #parse optional comma
+ <a name="NWCUvTi-12lwO-1-u2" href="#NWDCUvTi-v"><i>&lt;process <tt>radius</tt> part of command&gt;</i></a>
+ s/^,\s*// or s/\s*//; #parse optional comma
+ my $inout = &quot;&quot;;
+ if (s/^(internal(?=\W))//i or s/^(external(?=\W))//i) {
+ $inout = $1;
+ }
+ else {
+ PrintErrorMessage(&quot;Did not find expected 'internal' specifier&quot;, $lc);
+ next LINE;
+ }
+ s/^,\s*// or s/\s*//; #parse optional comma
+ my $direction = &quot;&quot;;
+ if (s/^(clockwise(?=\W))//i or s/^(anticlockwise(?=\W))//i) {
+ $direction = $1;
+ }
+ else {
+ PrintErrorMessage(&quot;Did not find expected 'direction' specifier&quot;, $lc);
+ next LINE;
+ }
+ chk_rcb(&quot;arguments of $cmd&quot;,$lc);
+ chk_comment($lc);
+ my $code;
+ if (lc($cmd) eq &quot;drawanglearc&quot;) {
+ $code = drawAngleArc($P1, $P2, $P3, $radius, $inout, $direction);
+ }
+ else {
+ $code = drawAngleArrow($P1, $P2, $P3, $radius, $inout, $direction);
+ }
+ print OUT $code if $code ne &quot;&quot;;
+
+</pre><p><a name="NWDCUvTi-u">We first check whether the first token is the word </a><code>angle</code>. In case it
+isn't, this yields an unrecoverable error. In case the expected word is
+there, we check for a left parenthesis. Next, we parse the three points that
+must follow. For this purpose we use the user-defined subroutine
+<code>get_point</code>. Now we check that the angle has a reasonable value, i.e., if
+it is less than -400 or equal to zero, the value yields an unrecoverable error.
+We finish by checking whether there is a right parenthesis.
+
+<pre><a name="NWCUvTi-4X9wPg-1" href="#NWDCUvTi-u"><dfn>&lt;process <tt>angle</tt> part of command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-t">&lt;-U</a>)</b>
+ my ($P1, $P2, $P3);
+ if (s/^angle(?=\W)//i) {
+ chk_lparen(&quot;token angle of command $cmd&quot;,$lc);
+ $P1 = get_point($lc);
+ next LINE if $P1 eq &quot;_undef_&quot;;
+ $P2 = get_point($lc);
+ next LINE if $P2 eq &quot;_undef_&quot;;
+ $P3 = get_point($lc);
+ next LINE if $P3 eq &quot;_undef_&quot;;
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$P1});
+ my ($x2,$y2,$pSV2,$pS2)=unpack(&quot;d3A*&quot;,$PointTable{$P2});
+ my ($x3,$y3,$pSV3,$pS3)=unpack(&quot;d3A*&quot;,$PointTable{$P3});
+ my $Angle = Angle($x1, $y1, $x2, $y2, $x3, $y3);
+ if ($Angle &lt;= 0) {
+ if ($Angle == 0) {
+ PrintErrorMessage(&quot;Angle is equal to zero&quot;,$lc);
+ next LINE;
+ }
+ elsif ($Angle &lt; -400) {
+ PrintErrorMessage(&quot;Something is wrong with the points&quot;,$lc);
+ next LINE;
+ }
+ }
+ chk_rparen(&quot;angle part of command $cmd&quot;,$lc);
+ }
+ else {
+ PrintErrorMessage(&quot;Did not find expected angle part&quot;,$lc);
+ next LINE;
+ }
+
+</pre><p><a name="NWDCUvTi-v">In this section we parse the </a><code>radius</code> part of the <code>drawAngleArc</code> or the
+<code>drawAngleArrow</code> command. We first check whether the next token is the word
+<code>radius</code>. If it is not, then we continue with the next line.
+
+<pre><a name="NWCUvTi-2mAaDL-1" href="#NWDCUvTi-v"><dfn>&lt;process <tt>radius</tt> part of command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-t">&lt;-U</a>)</b>
+
+ my $radius;
+ if (s/^radius(?=\W)//i) {
+ chk_lparen(&quot;token radius of command $cmd&quot;,$lc);
+ $radius = expr($lc);
+ chk_rparen(&quot;radius part of command $cmd&quot;,$lc);
+ }
+ else {
+ PrintErrorMessage(&quot;Did not found expected angle part&quot;,$lc);
+ next LINE;
+ }
+
+</pre><p>Command <code>drawcircle</code> accepts two arguments--a point name that is
+used to specify the center of the circle and the radius of the circle.
+The radius is simply an expression, whose value must be greater than zero.
+Otherwise, we print an error message and continue with the next input line.
+The general syntax of the command is as follows:
+<pre>
+ "drawcircle" "(" point-name "," rad ")"
+</pre>
+The code we emit for a point with coordinates <code>x</code> and <code>y</code> and for radius
+equal to <code>R</code> is:
+<pre>
+ \circulararc 360 degrees from X y center at x y
+</pre>
+where <code>X = x+R</code>.<p>
+<a name="NWDCUvTi-w">Initially, we check whether there is an opening left parenthesis. Next,</a>
+we get the point name by using the subroutine <code>get_point</code> which
+issues an error message if the point hasn't been defined. In this
+case we stop processing the command, as there is absolutely no reason to
+do otherwise. Next, we parse the comma and then the radius by using
+the subroutine <code>ComputeDist</code>. If there is no problem, we emit the code
+and finally we check for a closing right parenthesis and for
+possible garbage that may follow the command.
+
+<pre><a name="NWCUvTi-EIAAh-1" href="#NWDCUvTi-w"><dfn>&lt;process <tt>drawcircle</tt> command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-r">&lt;-U</a>)</b>
+ chk_lparen(&quot;drawcircle&quot;,$lc);
+ my $Point = get_point($lc);
+ next LINE if $Point eq &quot;_undef_&quot;;
+ chk_comma($lc);
+ my $R = expr($lc);
+ if ($R &lt;= 0) {
+ PrintErrorMessage(&quot;Radius must be greater than zero&quot;,$lc);
+ next LINE;
+ }
+ my ($x,$y,$pSV,$pS)=unpack(&quot;d3A*&quot;,$PointTable{lc($Point)});
+ printf OUT &quot;\\circulararc 360 degrees from %.5f %.5f center at %.5f %.5f\n&quot;,
+ $x+$R, $y, $x, $y;
+ chk_rparen(&quot;arguments of $cmd&quot;,$lc);
+ chk_comment($lc);
+
+</pre><p>Command <code>drawcircumcircle</code> is used to draw the circumcircle of triangle
+specified by three points which are the arguments of the command. We start
+by parsing the opening left parenthesis. Next, we get the three points
+that define the triangle. We are now able to compute the center and
+the radius of the circumcircle by calling the subroutine <code>circumCircleCenter</code>.
+If the triangle area is equal to zero, then this subroutine will return
+the array <code>(0,0,0)</code> to indicate this fact.
+We now have all necessary information to draw the circumcircle. We use the
+<a name="NWDCUvTi-x">following code to do the job:</a>
+<pre>
+ \circulararc 360 degrees from X y center x y
+</pre>
+where <code>x</code> and <code>y</code> are the coordinates of the center, <code>R</code> its
+radius and <code>X=x+R</code>. What is left is to check whether there is a
+closing right parenthesis and any trailing garbage.
+
+
+<pre><a name="NWCUvTi-1HqG4z-1" href="#NWDCUvTi-x"><dfn>&lt;process <tt>drawcircumcircle</tt> command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-r">&lt;-U</a>)</b>
+ chk_lparen(&quot;drawcircumcircle&quot;,$lc);
+ my $point1 = get_point($lc);
+ next LINE if $point1 eq &quot;_undef_&quot;;
+ my $point2 = get_point($lc);
+ next LINE if $point2 eq &quot;_undef_&quot;;
+ my $point3 = get_point($lc);
+ next LINE if $point3 eq &quot;_undef_&quot;;
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$point1});
+ my ($x2,$y2,$pSV2,$pS2)=unpack(&quot;d3A*&quot;,$PointTable{$point2});
+ my ($x3,$y3,$pSV3,$pS3)=unpack(&quot;d3A*&quot;,$PointTable{$point3});
+ my ($xc, $yc,$r) = circumCircleCenter($x1,$y1,$x2,$y2,$x3,$y3,$lc);
+ next LINE if $xc == 0 and $yc == 0 and $r == 0;
+ print OUT &quot;%% circumcircle center = ($xc,$yc), radius = $r\n&quot; if $comments_on;
+ printf OUT &quot;\\circulararc 360 degrees from %.5f %.5f center at %.5f %.5f\n&quot;,
+ $xc+$r, $yc, $xc, $yc;
+ chk_rparen(&quot;arguments of $cmd&quot;,$lc);
+ chk_comment($lc);
+
+</pre><p>The syntax of the <code>drawexcircle</code> command is as follows:
+<pre>
+ drawexcircle ::= "drawexcircle" "(" ThreePoints "," TwoPoints ")"
+ [ modifier ]
+ modifier ::= "[" expr "]"
+
+</pre>
+The <code>modifier</code> is an expression that is used to modify the radius of the
+excicle. We start by checking whether there is a left parenthesis. Then we
+get names of the three points. In case any of the points is not defined
+we issue an error message and continue with the next input line. Next, we
+check whether there is a comma that separates the three points defining the
+triangle from the two points defining a side of the triangle (variables
+<code>$point1</code>, <code>$point2</code>, and <code>$point3</code>). Moreover, we must ensure that
+the area of the area defined by these points is not equal to
+zero. If it is we issue an error message and we continue with the next
+input line. Now, we are ready to get the two
+point names that define the side of the triangle (variables <code>$point3</code> and
+<code>$point5</code>). At this point we must make sure that these points are different
+points and that they are members of the list of points that define the triangle.
+We make this check by calling the subroutine <code>memberOf</code>. Next, we check
+whether there is a closing right parenthesis. We now compute the center
+and the radius of the excircle by calling the subroutine <code>excircle</code>. The
+coordinates of the center are stored in the variables <code>$xc</code> and <code>$yc</code>,
+while the radius is stored in the variable <code>$r</code>. If the next
+non-blank input character is a left square bracket, then we know the user has
+specified the optional part. We use the subroutine <code>expr</code> to get the value of
+the optional part. The value of the optional part is stored in the variable <code>$R</code>.
+At this point we check whether the sum of the radius
+plus the optional part is equal to zero and if it is we continue with the
+next input line. Next, we check for a closing right square bracket. We are
+<a name="NWDCUvTi-y">now ready to emit the source code. The first thing we must check is that</a>
+the radius is not too big for PiCTeX, i.e., not greater than 500/2.845.
+Then we print some informative text to the output file and of course the
+actual code. We use the following code to do the job:
+<pre>
+ \circulararc 360 degrees from (xc+R) yc center xc yc
+</pre>
+The last thing we check is whether there is some trailing garbage.
+
+<pre><a name="NWCUvTi-Wbuba-1" href="#NWDCUvTi-y"><dfn>&lt;process <tt>drawexcircle</tt> command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-r">&lt;-U</a>)</b>
+ chk_lparen(&quot;drawexcircle&quot;,$lc);
+ my $point1 = get_point($lc);
+ next LINE if $point1 eq &quot;_undef_&quot;;
+ my $point2 = get_point($lc);
+ next LINE if $point2 eq &quot;_undef_&quot;;
+ my $point3 = get_point($lc);
+ next LINE if $point3 eq &quot;_undef_&quot;;
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$point1});
+ my ($x2,$y2,$pSV2,$pS2)=unpack(&quot;d3A*&quot;,$PointTable{$point2});
+ my ($x3,$y3,$pSV3,$pS3)=unpack(&quot;d3A*&quot;,$PointTable{$point3});
+ if (triangleArea($x1, $y1, $x2, $y2, $x3, $y3) &lt; 0.0001) {
+ PrintErrorMessage(&quot;Area of triangle is zero!&quot;,$lc);
+ next LINE;
+ }
+ chk_comma($lc);
+ my $point4 = get_point($lc);
+ if (!memberOf($point4, $point1, $point2, $point3)) {
+ PrintErrorMessage(&quot;Current point isn't a side point&quot;,$lc);
+ next LINE;
+ }
+ next LINE if $point4 eq &quot;_undef_&quot;;
+ my $point5 = get_point($lc);
+ next LINE if $point5 eq &quot;_undef_&quot;;
+ if (!memberOf($point5, $point1, $point2, $point3)) {
+ PrintErrorMessage(&quot;Current point isn't a side point&quot;,$lc);
+ next LINE;
+ }
+ if ($point4 eq $point5) {
+ PrintErrorMessage(&quot;Side points are identical&quot;,$lc);
+ next LINE;
+ }
+ chk_rparen(&quot;arguments of $cmd&quot;,$lc);
+ my ($xc, $yc, $r) = excircle($point1, $point2, $point3,
+ $point4, $point5);
+ my $R=$r;
+ if (s/^\s*\[\s*//) {
+ $R += expr($lc);
+ if ($R &lt; 0.0001) {
+ PrintErrorMessage(&quot;Radius has become equal to zero!&quot;,$lc);
+ next LINE;
+ }
+ chk_rsb($lc);
+ }
+ if ($R &gt; (500 / 2.845)) {
+ PrintErrorMessage(&quot;Radius is greater than 175mm!&quot;,$lc);
+ next LINE;
+ }
+ print OUT &quot;%% excircle center = ($xc,$yc) radius = $R\n&quot; if $comments_on;
+ printf OUT &quot;\\circulararc 360 degrees from %.5f %.5f center at %.5f %.5f\n&quot;,
+ $xc+$R, $yc, $xc, $yc;
+ chk_comment($lc);
+
+</pre><p>The syntax of the <code>drawincircle</code> command is as follows:
+<pre>
+ drawincircle ::= "drawincircle" "(" ThreePoints ")" [ modifier]
+ modifier ::= "[" expr "]"
+</pre>
+where <code>ThreePoints</code> correspond to the points defining the triangle and
+<code>modifier</code> is an optional modification factor.
+The first thing we do is to check whether
+there is an opening left parenthesis. Then we get the names of the three
+points that define the triangle (variables <code>$point1</code>, <code>$point2</code>,
+and <code>$point3</code>). Next, we make sure that the area of the
+triangle defined by these three points is not equal to zero. If it is, then
+we issue an error message and continue with the next input line. Now, we
+compute the center and the radius of the incircle (variables <code>$xc</code>, <code>$yc</code>,
+and <code>$r</code>). If the next non-blank input character is a left square bracket,
+then we now the user has specified the optional part. We use subroutine
+<code>expr</code> to get the value of the optional part. The value of
+the optional part
+is stored in the variable <code>$R</code>. At this point we check whether the sum of the
+radius plus the optional part is equal to zero and if it is we continue with
+the next input line. Next, we check for a closing right square bracket.
+<a name="NWDCUvTi-z">We are now ready to emit the source code. The first thing we must check is</a>
+that the radius is not too big for PiCTeX, i.e., not greater than 500/2.845.
+Then we print some informative text to the output file and of course the
+actual code. We use the following code to do the job:
+<pre>
+ \circulararc 360 degrees from (xc+R) yc center xc yc
+</pre>
+The last thing we check is whether there is some trailing garbage.
+
+<pre><a name="NWCUvTi-3GJ2p7-1" href="#NWDCUvTi-z"><dfn>&lt;process <tt>drawincircle</tt> command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-r">&lt;-U</a>)</b>
+ chk_lparen(&quot;drawincircle&quot;,$lc);
+ my $point1 = get_point($lc);
+ next LINE if $point1 eq &quot;_undef_&quot;;
+ my $point2 = get_point($lc);
+ next LINE if $point2 eq &quot;_undef_&quot;;
+ my $point3 = get_point($lc);
+ next LINE if $point3 eq &quot;_undef_&quot;;
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$point1});
+ my ($x2,$y2,$pSV2,$pS2)=unpack(&quot;d3A*&quot;,$PointTable{$point2});
+ my ($x3,$y3,$pSV3,$pS3)=unpack(&quot;d3A*&quot;,$PointTable{$point3});
+ if (triangleArea($x1, $y1, $x2, $y2, $x3, $y3) &lt; 0.0001) {
+ PrintErrorMessage(&quot;Area of triangle is zero!&quot;,$lc);
+ next LINE;
+ }
+ my ($xc, $yc, $r) = IncircleCenter($x1,$y1,$x2,$y2,$x3,$y3);
+ my $R=$r;
+ if (s/^\s*\[\s*//) {
+ $R += expr($lc);
+ if ($R &lt; 0.0001) {
+ PrintErrorMessage(&quot;Radius has become equal to zero!&quot;,$lc);
+ next LINE;
+ }
+ chk_rsb($lc);
+ }
+ if ($R &gt; (500 / 2.845)) {
+ PrintErrorMessage(&quot;Radius is greater than 175mm!&quot;,$lc);
+ next LINE;
+ }
+ print OUT &quot;%% incircle center = ($xc,$yc) radius = $R\n&quot; if $comments_on;
+ printf OUT &quot;\\circulararc 360 degrees from %.5f %.5f center at %.5f %.5f\n&quot;,
+ $xc+$R, $yc, $xc, $yc;
+ chk_rparen(&quot;arguments of $cmd&quot;,$lc);
+ chk_comment($lc);
+
+</pre><p>The command <code>drawPerpendicular</code> command draws a line from point A to line
+BC, such that it is perpendicular to line BC. The general syntax of the
+command is as follows:
+<pre>
+ drawPenpedicular ::= "drawPenpedicular" "(" Point "," TwoPoints ")"
+</pre>
+The first thing we do is to parse the left parenthesis. Then we parse
+the name of the first point, namely <code>$A$</code>. If this point is undefined
+we print an error message and continue with the next line. Next, we parse
+the expected leading comma and the names of the other two points. Certainly,
+in case either of these two points has not been defined, we simply print an
+error message and continue with the next input line. Finally, we check for
+a closing right parenthesis and a possible trailing comment. Now we are
+ready to compute the coordinates of the foot of the
+perpendicular line. We do so my calling subroutine
+<code><a name="NWDCUvTi-10">perpendicular</a></code>. Certainly, before we do this we have to get the
+coordinates of the points that we have parsed. Finally, we output the
+PiCTeX code:
+<pre>
+ \plot x1 y1 xF xY /
+</pre>
+where <code>x1</code> and <code>y1</code> are coordinates of the point A and <code>xF</code> and <code>yF</code>
+the coordinates of the foot.
+
+<pre><a name="NWCUvTi-4OiWfi-1" href="#NWDCUvTi-10"><dfn>&lt;process <tt>drawPerpendicular</tt> command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-r">&lt;-U</a>)</b>
+
+ chk_lparen($cmd,$lc);
+ my $A = get_point($lc);
+ next LINE if $A eq &quot;_undef_&quot;;
+ chk_comma($lc);
+ my $B = get_point($lc);
+ next LINE if $A eq &quot;_undef_&quot;;
+ s/\s*//; #ignore white space
+ my $C = get_point($lc);
+ next LINE if $A eq &quot;_undef_&quot;;
+ chk_rparen(&quot;arguments of $cmd&quot;,$lc);
+ chk_comment($lc);
+ #
+ #start actual computation
+ #
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$A});
+ my ($x2,$y2,$pSV2,$pS2)=unpack(&quot;d3A*&quot;,$PointTable{$B});
+ my ($x3,$y3,$pSV3,$pS3)=unpack(&quot;d3A*&quot;,$PointTable{$C});
+ my ($xF, $yF) = perpendicular($x1, $y1, $x2, $y2, $x3, $y3);
+ printf OUT &quot;\\plot %.5f %.5f %.5f %.5f /\n&quot;,
+ $x1, $y1, $xF, $yF;
+
+</pre><p>The <code>drawpoint</code> command has a number of points as arguments and produces
+PiCTeX code that draws a plot symbol at the coordinates of each point. The
+syntax of the command is as follows:
+<pre>
+ drawpoint ::= "drawpoint" "(" Point { separator Point } ")"
+</pre>
+The <code>while</code> loop is used to consume all points that are
+<a name="NWDCUvTi-11">between an opening left parenthesis and a closing right parenthesis. All</a>
+points are pushed on the local array <code>PP</code>. When we have parsed the lists
+of points, we call the subroutine <code>drawpoints</code> to emit the actual PiCTeX code.
+Finally, we check whether there is a closing parenthesis
+parenthesis, and whether
+there is some trailing text that makes no sense. In case there are no points
+between the parentheses, then we issue an appropriate error message and
+we continue with the next input line.
+
+<pre><a name="NWCUvTi-2EC5Ei-1" href="#NWDCUvTi-11"><dfn>&lt;process <tt>drawpoint</tt> command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-r">&lt;-U</a>)</b>
+ my ($stacklen);
+ chk_lparen(&quot;$cmd&quot;,$lc);
+ if (/^\)/) {
+ PrintErrorMessage(&quot;There are no point to draw&quot;,$lc);
+ next LINE;
+ }
+ my(@PP);
+ DRAWPOINTS:while(1) {
+ if (s/^([^\W\d_]\d{0,4})//i) { #point name
+ $P = $1;
+ if (!exists($PointTable{lc($P)})) {
+ PrintErrorMessage(&quot;Undefined point $P&quot;,$lc);
+ next DRAWPOINTS;
+ }
+ else {
+ push (@PP,$P);
+ s/\s*//;
+ }
+ }
+ else {
+ last DRAWPOINTS;
+ }
+ }
+ drawpoints(@PP);
+ chk_rparen(&quot;arguments of $cmd&quot;,$lc);
+ chk_comment($lc);
+
+</pre><p>The syntax of the <code>drawRightAngle</code> command is as follows:
+<pre>
+ drawRightAngle "(" ThreePoints "," dist ")"
+ dist ::= expr | TwoPoints
+</pre>
+Before we proceed with the actual computation we parse the left parenthesis,
+the three points, the comma, the <code>dist</code>, and the right parenthesis. In case
+we have neither three points nor a <code>dist</code> we print an error message and
+continue with the next input line, i.e., these errors are irrecoverable.
+The names of the three points are stored in variables <code>$point1</code>,
+<code>$point2</code>, and <code>$point3</code>. The value of the distance is stored
+in the variable <code>$dist</code>.
+Let's now explain the semantics of this command.<p>
+
+Our aim is to draw lines S<sub>1</sub>-S, S<sub>2</sub>-S (S<sub>1</sub>
+and S<sub>2</sub> are at distance d from B). All the relevant points are
+depicted in the following figure:
+<center>
+<img src="fig1.jpg">
+</center>
+Some notes are in order:
+<ol>
+<li> BS bisects angle ABC, and meets AC in Q, so start by determining point
+Q, then determine S, and then S<sub>1</sub> and S<sub>2</sub>, and then
+draw S<sub>1</sub>-S and S<sub>2</sub>-S.</li>
+<li> Distance AQ is given by AC/(1+tan(BCA))</li>
+<li> The coordinates of Q are computed using the subroutine <code>pointOnLine</code>.</li>
+<li> Now we compute the coordinates of S on line BQ.</li>
+<li> We compute the coordinates of S<sub>1</sub> and S<sub>2</sub> by using
+The subroutine <code>pointOnLine</code>.</li>
+</ol>
+<a name="NWDCUvTi-12">In order to implement the above steps we first compute the length of the line</a>
+AB. Note that A is <code>$point1</code>, etc. Next we compute the angle BAC. Now
+we compute the distance AQ (variable <code>$line1</code>). The coordinates of point
+Q are stored in variables <code>$xQ</code> and <code>$yQ</code>. The coordinates of point
+S are stored in variables <code>$xS</code> and <code>$yS</code>. Now we have to determine the
+coordinates of points S<sub>1</sub> and S<sub>2</sub>. These coordinates
+are stored in variables <code>$xS1</code>, <code>$yS1</code> and <code>$xS2</code>, <code>$yS2</code>,
+respectively. Finally, we emit the PiCTeX target code.
+
+<pre><a name="NWCUvTi-2KJKP6-1" href="#NWDCUvTi-12"><dfn>&lt;process <tt>drawRightAngle</tt> command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-r">&lt;-U</a>)</b>
+
+ chk_lparen(&quot;drawRightAngle&quot;,$lc);
+ my $point1 = get_point($lc);
+ next LINE if $point1 eq &quot;_undef_&quot;;
+ my $point2 = get_point($lc);
+ next LINE if $point2 eq &quot;_undef_&quot;;
+ my $point3 = get_point($lc);
+ next LINE if $point3 eq &quot;_undef_&quot;;
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$point1});
+ my ($x2,$y2,$pSV2,$pS2)=unpack(&quot;d3A*&quot;,$PointTable{$point2});
+ my ($x3,$y3,$pSV3,$pS3)=unpack(&quot;d3A*&quot;,$PointTable{$point3});
+ chk_comma($lc);
+ my $dist = expr($lc);
+ chk_rparen(&quot;arguments of $cmd&quot;,$lc);
+ chk_comment($lc);
+ #
+ #actual computation
+ #
+ my ($Px, $Py) = pointOnLine($x2, $y2, $x1, $y1, $dist);
+ my ($Qx, $Qy) = pointOnLine($x2, $y2, $x3, $y3, $dist);
+ my ($Tx, $Ty) = midpoint($Px, $Py, $Qx, $Qy);
+ my ($Ux, $Uy) = pointOnLine($x2, $y2, $Tx, $Ty, 2*Length($x2, $y2, $Tx, $Ty));
+ if ($Px == $Ux || $Py == $Uy) {
+ printf OUT &quot;\\putrule from %.5f %.5f to %.5f %.5f \n&quot;, $Px,$Py,$Ux,$Uy;
+ }
+ else {
+ printf OUT &quot;\\plot %.5f %.5f\t%.5f %.5f / \n&quot;, $Px, $Py,$Ux,$Uy;
+ }
+ if ($Ux == $Qx || $Uy == $Qy) {
+ printf OUT &quot;\\putrule from %.5f %.5f to %.5f %.5f \n&quot;, $Ux,$Uy,$Qx,$Qy;
+ }
+ else {
+ printf OUT &quot;\\plot %.5f %.5f\t%.5f %.5f / \n&quot;, $Ux, $Uy,$Qx,$Qy;
+ }
+
+
+</pre><p><a name="NWDCUvTi-13">The command </a><code>drawsquare</code> has two arguments: a point, which specifies the
+coordinates of the point where the square will be placed, and a number, which
+specifies the length of the side of the square. The syntax of the command is as follows:
+<center>
+ <tt> "drawSquare" "(" Point "," expression ")" </tt>
+</center>
+Note that RWDN has suggested to alter the value of the <code>$side</code> variable (see the
+line with <code>RWDN</code> comment).
+
+<pre><a name="NWCUvTi-2lxjRF-1" href="#NWDCUvTi-13"><dfn>&lt;process <tt>drawsquare</tt> command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-r">&lt;-U</a>)</b>
+ chk_lparen(&quot;drawSquare&quot;,$lc);
+ my $p = get_point($lc);
+ chk_comma($lc);
+ my $side = expr($lc);
+ $side = $side - (1.1 * $LineThickness/$xunits); #Suggested by RWDN
+ my ($x,$y,$pSV,$pS) = unpack(&quot;d3A*&quot;,$PointTable{$p});
+ printf OUT &quot;\\put {%s} at %.5f %.5f %%drawsquare\n&quot;, drawsquare($side), $x, $y;
+ chk_rparen(&quot;arguments of $cmd&quot;,$lc);
+ chk_comment($lc);
+
+</pre><p>The argument of the <code>inputfile*</code> command is a file name that is always
+enclosed in parentheses:
+<pre>
+ starred-input-file ::= "inputfile*" "(" file-name ")"
+ file-name ::= (alpha | period) { alpha | period }
+ alpha ::= letter | digit | "_" | "-"
+</pre>
+<a name="NWDCUvTi-14">Note, that the input file is assumed to contain TeX code.</a>
+We first check to see if there is a left parenthesis. Then we consume
+the file name. We check if the file exists and then we copy verbatim the
+input file to the output file. Next, we check for the closing parenthesis.
+Now, if there is a trailing comment we copy it to the output file depending
+on the value of the variable <code>$comments_on</code>, else if there is some other
+text we simply ignore it and issue a warning message.
+
+<pre><a name="NWCUvTi-fJuCf-1" href="#NWDCUvTi-14"><dfn>&lt;process <tt>inputfile*</tt> command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-r">&lt;-U</a>)</b>
+ chk_lparen(&quot;inputfile*&quot;,$lc);
+ my $row_in = &quot;&quot;;
+ if (s/^((\w|-|\.)+)//) {
+ $row_in = $1;
+ }
+ else {
+ PrintErrorMessage(&quot;No input file name found&quot;,$lc);
+ next LINE;
+ }
+ if (!(-e $row_in)) {
+ PrintErrorMessage(&quot;File $row_in does not exist&quot;,$lc);
+ next LINE;
+ }
+ open(ROW, &quot;$row_in&quot;)|| die &quot;Can't open file $row_in\n&quot;;
+ while (defined($in_line=&lt;ROW&gt;)) { print OUT $in_line; }
+ print OUT &quot;%% ... end of input file &lt;$row_in&gt;\n&quot;;
+ close ROW;
+ chk_rparen(&quot;input file name&quot;,$lc);
+ chk_comment($lc);
+
+
+</pre><p>The <code>inputfile</code> command has at most two arguments, second being
+optional: a file name enclosed in curly brackets and the number of
+times this file should be included in square brackets:
+<pre>
+ inputfile ::= "inputfile" "(" file-name ")" [ Times ]
+ <a name="NWDCUvTi-15">Times ::= "[" expr "]"</a>
+</pre>
+Note that the input file is assumed to contain mathspic commands. In addition, if
+the expression is equal to a decimal number, it is truncated.
+As in the case of the <code>inputfile*</code> command we parse the left parenthesis,
+the file name, the right parenthesis and the optional argument if it exists.
+In order to process the commands contained in the input file, we call
+The subroutine <code>process_input</code>.
+
+<pre><a name="NWCUvTi-2EQO3c-1" href="#NWDCUvTi-15"><dfn>&lt;process <tt>inputfile</tt> command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-r">&lt;-U</a>)</b>
+
+ chk_lparen(&quot;inputfile&quot;,$lc);
+ my $comm_in = &quot;&quot;;
+ if (s/^((\w|-|\.)+)//) {
+ $comm_in = $1;
+ }
+ else {
+ PrintErrorMessage(&quot;No input file name found&quot;,$lc);
+ next LINE;
+ }
+ if (!(-e $comm_in)) {
+ PrintErrorMessage(&quot;File $comm_in does not exist&quot;,$lc);
+ next LINE;
+ }
+ chk_rparen(&quot;input file name&quot;,$lc);
+ my $input_times = 1; #default value
+ if (s/^\[//) {
+ $input_times = expr($lc);
+ chk_rsb(&quot;optional argument&quot;,$lc);
+ }
+ print OUT &quot;%% ... start of file &lt;$comm_in&gt; loop [$input_times]\n&quot;;
+ for (my $i=0; $i&lt;int($input_times); $i++) {
+ open(COMM,&quot;$comm_in&quot;) or die &quot;Can't open file $comm_in\n&quot;;
+ print OUT &quot;%%% Iteration number: &quot;,$i+1,&quot;\n&quot;;
+ my $old_file_name = $curr_in_file;
+ process_input(COMM,&quot;File $comm_in, &quot;);
+ $curr_in_file = $old_file_name;
+ close COMM;
+ }
+ print OUT &quot;%% ... end of file &lt;$comm_in&gt; loop [$input_times]\n&quot;;
+ chk_comment($lc);
+
+</pre><p><a name="NWDCUvTi-16">The </a><code>linethickness</code> command should be used to set the thickness of lines.
+The command has one argument, which is a length or the word <code>default</code>.
+The default line thickness is 0.4 pt.
+
+<pre><a name="NWCUvTi-1t58ZF-1" href="#NWDCUvTi-16"><dfn>&lt;process <tt>linethickness</tt> command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-r">&lt;-U</a>)</b>
+ chk_lparen(&quot;linethickness&quot;, $lc);
+ if (s/^default//i) {
+ print OUT &quot;\\linethickness=0.4pt\\Linethickness{0.4pt}%%\n&quot;;
+ print OUT &quot;\\setplotsymbol ({\\usefont{OT1}{cmr}{m}{n}\\tiny .})%\n&quot;;
+ $LineThickness = setLineThickness($xunits,&quot;0.4pt&quot;);
+ }
+ else {
+ my $length = expr($lc);
+ if (s/^\s*($units)//i) {
+ my $units = $1;
+ printf OUT &quot;\\linethickness=%.5f%s\\Linethickness{%.5f%s}%%\n&quot;,
+ $length, $units, $length, $units;
+ $LineThickness = setLineThickness($xunits,&quot;$length$units&quot;);
+ my $mag;
+ if ($units eq &quot;pc&quot;) {
+ $mag = $length * 12;
+ }
+ elsif ($units eq &quot;in&quot;) {
+ $mag = $length * 72.27;
+ }
+ elsif ($units eq &quot;bp&quot;) {
+ $mag = $length * 1.00375;
+ }
+ elsif ($units eq &quot;cm&quot;) {
+ $mag = $length * 28.45275;
+ }
+ elsif ($units eq &quot;mm&quot;) {
+ $mag = $length * 2.845275;
+ }
+ elsif ($units eq &quot;dd&quot;) {
+ $mag = $length * 1.07001;
+ }
+ elsif ($units eq &quot;cc&quot;) {
+ $mag = $length * 0.08917;
+ }
+ elsif ($units eq &quot;sp&quot;) {
+ $mag = $length * 0.000015259;
+ }
+ elsif ($units eq &quot;pt&quot;) {
+ $mag = $length;
+ }
+ $mag = 10 * $mag / 1.00278219;
+ printf OUT &quot;\\font\\CM=cmr10 at %.5fpt%%\n&quot;, $mag;
+ print OUT &quot;\\setplotsymbol ({\\CM .})%\n&quot;;
+ }
+ else {
+ PrintErrorMessage(&quot;Did not found expect units part&quot;,$lc);
+ }
+ }
+ chk_rparen(&quot;linethickness&quot;, $lc);
+ chk_comment($lc);
+
+
+</pre><p>We first output the input line as a comment into the output file. Now,
+after the <code>paper</code> token we look for an opening brace. Then we process
+the <code>units</code> part of the command, if the token <code>units</code> is present. Note
+that the <code>units</code> part is optional. Next we process the <code>xrange</code> and the
+<code>yrange</code> part of the command, which are also optional parts of the command.
+We are now ready to process the <code>axis</code> part. Note, that the user is allowed
+to alternatively specify this part with the word <code>axes</code>.
+<a name="NWDCUvTi-17">The variable </a><code>$axis</code>
+is supposed to hold the various data relate to the <code>axis</code> part. The last
+thing we check is the <code>ticks</code> part. In case the user has not specified
+this part we assume that both ticks are equal to zero. If everything is
+according to the language syntax, we expect a closing right curly bracket.
+Now, that we have all relevant information we can output the rest of the code,
+as some parts of it have already been output during parsing. The last thing we
+do is to check whether there is any trailing comment.
+
+<pre><a name="NWCUvTi-1Pby5X-1" href="#NWDCUvTi-17"><dfn>&lt;process <tt>paper</tt> command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-r">&lt;-U</a>)</b>
+ chk_lcb(&quot;paper&quot;, $lc);
+ if (s/^units(?=\W)//i)
+ {
+ <a name="NWCUvTi-1Pby5X-1-u1" href="#NWDCUvTi-18"><i>&lt;process <tt>unit</tt> part&gt;</i></a>
+ $nounits = 0;
+ }
+ else
+ {
+ $nounits = 1;
+ }
+ s/^,\s*// or s/\s*//;
+ if (s/^xrange//i)
+ {
+ <a name="NWCUvTi-1Pby5X-1-u2" href="#NWDCUvTi-19"><i>&lt;process <tt>xrange</tt> part&gt;</i></a>
+ $noxrange = 0;
+ }
+ else
+ {
+ $noxrange = 1;
+ }
+ s/^,\s*// or s/\s*//;
+ if (s/^yrange//i)
+ {
+ <a name="NWCUvTi-1Pby5X-1-u3" href="#NWDCUvTi-1A"><i>&lt;process <tt>yrange</tt> part&gt;</i></a>
+ $noyrange = 0;
+ }
+ else
+ {
+ $noyrange = 1;
+ }
+ <a name="NWCUvTi-1Pby5X-1-u4" href="#NWDCUvTi-1E"><i>&lt;generate plot area related commands&gt;</i></a>
+ s/^,\s*// or s/\s*//;
+ $axis = &quot;&quot;;
+ if (s/^ax[ei]s(?=\W)//i)
+ {
+ <a name="NWCUvTi-1Pby5X-1-u5" href="#NWDCUvTi-1F"><i>&lt;process <tt>axis</tt> part&gt;</i></a>
+ }
+ $axis = uc($axis);
+ s/^,\s*// or s/\s*//;
+ if (s/^ticks(?=\W)//i)
+ {
+ <a name="NWCUvTi-1Pby5X-1-u6" href="#NWDCUvTi-1G"><i>&lt;process <tt>ticks</tt> part&gt;</i></a>
+ }
+ else
+ {
+ $xticks = $yticks = 0;
+ }
+ chk_rcb(&quot;paper&quot;, $lc);
+ <a name="NWCUvTi-1Pby5X-1-u7" href="#NWDCUvTi-1H"><i>&lt;generate the rest of the code for the <tt>paper</tt> command&gt;</i></a>
+ chk_comment($lc);
+
+</pre><p><a name="NWDCUvTi-18">We first check whether there is a left parenthesis. Next, we check</a>
+whether there is decimal number or a variable name. In case there isn't one we assume it
+is the number 1. Now, we get the units. If there is no valid unit, we issue
+an error and the x-unit is set to its default value. In case, there is
+a trailing comma, we assume the user wants also to specify the y-unit and
+we process this part just like we did with the x-unit part. Finally, we
+output the corresponding PiCTeX command. In case there is no y-unit
+we assume it is equal to the x-unit.
+
+<pre><a name="NWCUvTi-15UlOC-1" href="#NWDCUvTi-18"><dfn>&lt;process <tt>unit</tt> part&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-17">&lt;-U</a>)</b>
+
+ chk_lparen(&quot;units&quot;,$lc);
+ if(s/^\)//)
+ {
+ PrintWarningMessage(&quot;Missing value in \&quot;units\&quot;--default is 1pt&quot;,
+ $lc);
+ $xunits = &quot;1pt&quot;;
+ }
+ else {
+ $xunits = expr($lc);
+ s/\s*//;
+ if (s/^($units)//i) {
+ $xunits .= &quot;$1&quot;;
+ $LineThickness = setLineThickness($xunits,&quot;0.4pt&quot;);
+ }
+ elsif(s/^(\w)+//i) {
+ PrintErrorMessage(&quot;$1 is not a valid mathspic unit&quot;,$lc);
+ $xunits = &quot;1pt&quot;;
+ }
+ else {
+ PrintErrorMessage(&quot;No x-units found&quot;,$lc);
+ $xunits = &quot;1pt&quot;;
+ }
+ s/\s*//; #ignore white space
+ if (s/^,//) { # there is a comma so expect an y-units
+ s/\s*//; #ignore white space
+ $yunits = expr($lc);
+ s/\s*//; #ignore white space
+ if (s/^($units)//i) {
+ $yunits .= &quot;$1&quot;;
+ }
+ elsif(s/^(\w)+//i) {
+ PrintErrorMessage(&quot;$1 is not a valid mathspic unit&quot;,$lc);
+ $yunits = &quot;1pt&quot;;
+ }
+ else {
+ PrintErrorMessage(&quot;No y-units found&quot;,$lc);
+ $yunits = $xunits;
+ }
+ }
+ else {
+ $yunits = $xunits;
+ }
+ chk_rparen(&quot;units&quot;,$lc);
+ }
+
+</pre><p><a name="NWDCUvTi-19">The </a><code>xrange</code> token must be followed by a left parenthesis, so we
+check whether the next token is a left parenthesis. We store in the variables
+<code>$xlow</code> and <code>$xhigh</code> the values of the range. The range is specified
+as pair of decimal numbers/variable/pair of points, separated by a
+comma. We use the subroutine <code>ComputeDist</code> to get the value of the lower
+end and the upper end of the range. The last thing we check is whether
+the lower end is less than the upper end. If this isn't the case we
+issue an error message and we skip into the next input line.
+
+<pre><a name="NWCUvTi-39noUt-1" href="#NWDCUvTi-19"><dfn>&lt;process <tt>xrange</tt> part&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-17">&lt;-U</a>)</b>
+
+ chk_lparen(&quot;xrange&quot;,$lc);
+ my $ec;
+ ($xlow,$ec) = ComputeDist($lc);
+ next LINE if $ec == 0;
+ chk_comma($lc);
+ ($xhigh,$ec) = ComputeDist($lc);
+ next LINE if $ec == 0;
+ if ($xlow &gt;= $xhigh)
+ {
+ PrintErrorMessage(&quot;xlow &gt;= xhigh in xrange&quot;,$lc);
+ next LINE;
+ }
+ chk_rparen(&quot;$xhigh&quot;,$lc);
+
+</pre><p><a name="NWDCUvTi-1A">The </a><code>yrange</code> token must be followed by a left parenthesis, so we
+check whether the next token is a left parenthesis. We store in the variables
+<code>$ylow</code> and <code>$yhigh</code> the values of the range. The range is specified
+as pair of decimal numbers/variable/pair of points, separated by a
+comma. We use the subroutine <code>ComputeDist</code> to get the value of the lower
+end and the upper end of the range. The last thing we check is whether
+the lower end is less than the upper end. If this isn't the case we
+issue an error message and we skip into the next input line.
+
+<pre><a name="NWCUvTi-3SApmu-1" href="#NWDCUvTi-1A"><dfn>&lt;process <tt>yrange</tt> part&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-17">&lt;-U</a>)</b>
+
+ chk_lparen(&quot;yrange&quot;,$lc);
+ my $ec;
+ ($ylow,$ec) = ComputeDist($lc);
+ next LINE if $ec == 0;
+ chk_comma($lc);
+ ($yhigh,$ec) = ComputeDist($lc);
+ next LINE if $ec == 0;
+ if ($ylow &gt;= $yhigh)
+ {
+ PrintErrorMessage(&quot;ylow &gt;= yhigh in yrange&quot;,$lc);
+ next LINE;
+ }
+ chk_rparen(&quot;$yhigh&quot;,$lc);
+
+</pre><p><a name="NWDCUvTi-1B">The </a><code>showAngle</code> command has three arguments that correspond to three distinct
+points and emits a comment of the form:
+<center>
+<tt>%% angle(ABC) = 45</tt>
+</center>
+Note that the computed angle is expressed in degrees.
+
+<pre><a name="NWCUvTi-2ObcXb-1" href="#NWDCUvTi-1B"><dfn>&lt;process <tt>showAngle</tt> command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-r">&lt;-U</a>)</b>
+ chk_lparen(&quot;showangle&quot;,$lc);
+ my $point_1 = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$point_1});
+ my $point_2 = get_point($lc);
+ my ($x2,$y2,$pSV2,$pS2)=unpack(&quot;d3A*&quot;,$PointTable{$point_2});
+ my $point_3 = get_point($lc);
+ my ($x3,$y3,$pSV3,$pS3)=unpack(&quot;d3A*&quot;,$PointTable{$point_3});
+ my $angle = Angle($x1, $y1, $x2, $y2, $x3, $y3);
+ $angle = 0 if $angle == -500;
+ printf OUT &quot;%%%% angle(%s%s%s) = %.5f deg ( %.5f rad)\n&quot;, $point_1,
+ $point_2, $point_3, $angle, $angle*D2R;
+ chk_rparen(&quot;Missing right parenthesis&quot;, $lc);
+
+</pre><p><a name="NWDCUvTi-1C">The </a><code>showArea</code> command has three arguments that correspond to three distinct
+points and emits a comment of the form:
+<center>
+<tt>%% area(ABC) = 45</tt>
+</center>
+Note that the computed angle is expressed in degrees.
+
+<pre><a name="NWCUvTi-2THNRJ-1" href="#NWDCUvTi-1C"><dfn>&lt;process <tt>showArea</tt> command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-r">&lt;-U</a>)</b>
+ chk_lparen(&quot;showarea&quot;,$lc);
+ my $point_1 = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$point_1});
+ my $point_2 = get_point($lc);
+ my ($x2,$y2,$pSV2,$pS2)=unpack(&quot;d3A*&quot;,$PointTable{$point_2});
+ my $point_3 = get_point($lc);
+ my ($x3,$y3,$pSV3,$pS3)=unpack(&quot;d3A*&quot;,$PointTable{$point_3});
+ print OUT &quot;%% area($point_1$point_2$point_3) = &quot;,
+ triangleArea($x1, $y1, $x2, $y2, $x3, $y3), &quot;\n&quot;;
+ chk_rparen(&quot;Missing right parenthesis&quot;, $lc);
+
+</pre><p><a name="NWDCUvTi-1D">The </a><code>showLength</code> command has two arguments that correspond to two distinct
+points and emits a comment of the form:
+<center>
+<tt>%% length(AB) = 45</tt>
+</center>
+Note that the computed angle is expressed in degrees.
+
+<pre><a name="NWCUvTi-Ofe1b-1" href="#NWDCUvTi-1D"><dfn>&lt;process <tt>showLength</tt> command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-r">&lt;-U</a>)</b>
+ chk_lparen(&quot;showlength&quot;,$lc);
+ my $point_1 = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$point_1});
+ my $point_2 = get_point($lc);
+ my ($x2,$y2,$pSV2,$pS2)=unpack(&quot;d3A*&quot;,$PointTable{$point_2});
+ print OUT &quot;%% length($point_1$point_2) = &quot;,
+ Length($x1, $y1, $x2, $y2), &quot;\n&quot;;
+ chk_rparen(&quot;Missing right parenthesis&quot;, $lc);
+
+
+</pre><p><a name="NWDCUvTi-1E">If the user hasn't specified units then we use the previous values to</a>
+set the coordinate system. If the user hasn't specified either the
+<code>xunits</code> part or the <code>yunits</code>, then we don't emit code. In case he/she
+has specified both parts we generate the command that sets the plot area.
+
+<pre><a name="NWCUvTi-2SitZA-1" href="#NWDCUvTi-1E"><dfn>&lt;generate plot area related commands&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-17">&lt;-U</a>)</b>
+
+ if (!$nounits)
+ {
+ printf OUT &quot;\\setcoordinatesystem units &lt;%s,%s&gt;\n&quot;,
+ $xunits,$yunits;
+ }
+ if(!$noxrange &amp;&amp; !$noyrange)
+ {
+ printf OUT &quot;\\setplotarea x from %.5f to %.5f, y from %.5f to %.5f\n&quot;,
+ $xlow, $xhigh, $ylow, $yhigh;
+
+ }
+
+</pre><p>We first check to see whether there is an opening left parenthesis. Next
+<a name="NWDCUvTi-1F">we get the various options the user may have entered. The valid options</a>
+are the letters L, R, T, B, X, and Y. These letters may be followed by
+an optional star <code>*</code> with space characters between the letter and the star.
+We use a loop, that stops when a right parenthesis is found, to
+go through all
+possible arguments and append each argument in the string <code>$axis</code>. Note
+one can have blank space between different arguments. The last thing we do is
+to check for the closing right parenthesis.
+
+<pre><a name="NWCUvTi-19Hy2D-1" href="#NWDCUvTi-1F"><dfn>&lt;process <tt>axis</tt> part&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-17">&lt;-U</a>)</b>
+
+ chk_lparen(&quot;axis&quot;,$lc);
+ while(/^[^\)]/)
+ {
+ if (s/^([lrtbxy]{1}\*?)//i)
+ {
+ $axis .= $1;
+ }
+ elsif (s/^([^lrtbxy])//i)
+ {
+ PrintErrorMessage(&quot;Non-valid character \&quot;$1\&quot; in axis()&quot;,$lc);
+ }
+ s/\s*//;
+ }
+ chk_rparen(&quot;axis(arguments&quot;,$lc);
+
+</pre><p>As usual we start by skipping white space. Next we check whether there is
+<a name="NWDCUvTi-1G">an opening left parenthesis. Now, we expect two numbers/variables/pair of</a>
+point representing the <code>ticks</code> increment value. These <code>ticks</code> increment
+values must be separated by a comma (and possibly some white space around
+them). We use the subroutine <code>ComputeDist</code> to get the value of the <code>ticks</code>
+increment value and we assign to the variables <code>$xticks</code> and <code>$yticks</code>
+the value of x-ticks and y-ticks increment value. In case there is a
+problem we issue an error message and continue with the next line. The last
+thing we check is whether there is a closing right parenthesis.
+
+<pre><a name="NWCUvTi-1isLLJ-1" href="#NWDCUvTi-1G"><dfn>&lt;process <tt>ticks</tt> part&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-17">&lt;-U</a>)</b>
+ chk_lparen(&quot;ticks&quot;,$lc);
+ my $ec;
+ ($xticks,$ec) = ComputeDist($lc);
+ next LINE if $ec == 0;
+ chk_comma($lc);
+ ($yticks,$ec) = ComputeDist($lc);
+ next LINE if $ec == 0;
+ chk_rparen(&quot;ticks(arguments&quot;,$lc);
+
+</pre><p><a name="NWDCUvTi-1H">We actually emit code if the user has specified either the </a><code>X</code> or
+<code>Y</code> option in the <code>axis</code> part. If the user has specified the
+<code>Y*</code> or the <code>X*</code> option in the axis part, we just emit the commands
+<code>\axis left shiftedto x=0</code> or <code>\axis bottom shiftedto y=0</code> respectively
+and exit. If the use has specified ticks, then, depending on the options
+he had supplied with the <code>axis</code> part, we emit code that
+implements the user's wishes.
+**** HERE WE MUST EXPLAIN THE MEANING OF THE CODE EMITTED!!! *****
+
+<pre><a name="NWCUvTi-2gFm3I-1" href="#NWDCUvTi-1H"><dfn>&lt;generate the rest of the code for the <tt>paper</tt> command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-17">&lt;-U</a>)</b>
+YBRANCH: {
+ if (index($axis, &quot;Y&quot;)&gt;-1)
+ {
+ if (index($axis, &quot;Y*&quot;)&gt;-1)
+ {
+ print OUT &quot;\\axis left shiftedto x=0 / \n&quot;;
+ last YBRANCH;
+ }
+ if ($yticks &gt; 0)
+ {
+ if (index($axis, &quot;T&quot;)&gt;-1 &amp;&amp; index($axis, &quot;B&quot;)==-1)
+ {
+ print OUT &quot;\\axis left shiftedto x=0 ticks numbered from &quot;;
+ print OUT &quot;$ylow to -$yticks by $yticks\n from $yticks to &quot;;
+ print OUT $yhigh-$yticks,&quot; by $yticks /\n&quot;;
+ }
+ elsif (index($axis, &quot;T&quot;)==-1 &amp;&amp; index($axis, &quot;B&quot;)&gt;-1)
+ {
+ print OUT &quot;\\axis left shiftedto x=0 ticks numbered from &quot;;
+ print OUT $ylow+$yticks,&quot; to -$yticks by $yticks\n from &quot;;
+ print OUT &quot;$yticks to $yhigh by $yticks /\n&quot;;
+ }
+ elsif (index($axis, &quot;T&quot;)&gt;-1 &amp;&amp; index($axis, &quot;B&quot;)&gt;-1)
+ {
+ print OUT &quot;\\axis left shiftedto x=0 ticks numbered from &quot;;
+ print OUT $ylow+$yticks,&quot; to -$yticks by $yticks\n from &quot;;
+ print OUT &quot;$yticks to &quot;,$yhigh-$yticks,&quot; by $yticks /\n&quot;;
+ }
+ else
+ {
+ print OUT &quot;\\axis left shiftedto x=0 ticks numbered from &quot;;
+ print OUT &quot;$ylow to -$yticks by $yticks\n from &quot;;
+ print OUT &quot;$yticks to $yhigh by $yticks /\n&quot;;
+ }
+ }
+ else
+ {
+ print OUT &quot;\\axis left shiftedto x=0 /\n&quot;;
+ }
+ }
+ }
+ XBRANCH: { if (index($axis, &quot;X&quot;)&gt;-1)
+ {
+ if (index($axis, &quot;X*&quot;)&gt;-1)
+ {
+ print OUT &quot;\\axis bottom shiftedto y=0 /\n&quot;;
+ last XBRANCH;
+ }
+ if ($xticks &gt; 0)
+ {
+ if (index($axis, &quot;L&quot;)&gt;-1 &amp;&amp; index($axis, &quot;R&quot;)==1)
+ {
+ print OUT &quot;\\axis bottom shiftedto y=0 ticks numbered from &quot;;
+ print OUT $xlow + $xticks,&quot; to -$xticks by $xticks\n from&quot;;
+ print OUT &quot; $xticks to $xhigh by $xticks /\n&quot;;
+ }
+ elsif (index($axis, &quot;L&quot;)==-1 &amp;&amp; index($axis, &quot;R&quot;)&gt;-1)
+ {
+ print OUT &quot;\\axis bottom shiftedto y=0 ticks numbered from &quot;;
+ print OUT &quot;$xlow to -$xticks by $xticks\n from &quot;;
+ print OUT &quot;$xticks to &quot;,$xhigh-$xticks,&quot; by $xticks /\n&quot;;
+ }
+ elsif (index($axis, &quot;L&quot;)&gt;-1 &amp;&amp; index($axis, &quot;R&quot;)&gt;-1)
+ {
+ print OUT &quot;\\axis bottom shiftedto y=0 ticks numbered from &quot;;
+ print OUT $xlow + $xticks,&quot; to -$xticks by $xticks\n from &quot;;
+ print OUT &quot;$xticks to &quot;,$xhigh - $xticks,&quot; by $xticks /\n&quot;;
+ }
+ else
+ {
+ print OUT &quot;\\axis bottom shiftedto y=0 ticks numbered from &quot;;
+ print OUT &quot;$xlow to -$xticks by $xticks\n from &quot;;
+ print OUT &quot;$xticks to $xhigh by $xticks /\n&quot;;
+ }
+ }
+ else
+ {
+ print OUT &quot;\\axis bottom shiftedto y=0 /\n&quot;;
+ }
+ } }
+ LBRANCH: {if (index($axis, &quot;L&quot;)&gt;-1)
+ {
+ if (index($axis, &quot;L&quot;)&gt;-1)
+ {
+ if (index($axis, &quot;L*&quot;)&gt;-1)
+ {
+ print OUT &quot;\\axis left /\n&quot;;
+ last LBRANCH;
+ }
+ if ($yticks &gt; 0)
+ {
+ print OUT &quot;\\axis left ticks numbered from &quot;;
+ print OUT &quot;$ylow to $yhigh by $yticks /\n&quot;;
+ }
+ else
+ {
+ print OUT &quot;\\axis left /\n&quot;;
+ }
+ }
+ } }
+ RBRANCH: { if (index($axis, &quot;R&quot;)&gt;-1)
+ {
+ if (index($axis, &quot;R*&quot;)&gt;-1)
+ {
+ print OUT &quot;\\axis right /\n&quot;;
+ last RBRANCH;
+ }
+ if ($yticks &gt; 0)
+ {
+ print OUT &quot;\\axis right ticks numbered from $ylow to $yhigh by &quot;;
+ print OUT &quot;$yticks /\n&quot;;
+ }
+ else
+ {
+ print OUT &quot;\\axis right /\n&quot;;
+ }
+ } }
+ TBRANCH: { if (index($axis, &quot;T&quot;)&gt;-1)
+ {
+ if (index($axis, &quot;T*&quot;)&gt;-1)
+ {
+ print OUT &quot;\\axis top /\n&quot;;
+ last TBRANCH;
+ }
+ if ($xticks &gt; 0)
+ {
+ print OUT &quot;\\axis top ticks numbered from $xlow to $xhigh by &quot;;
+ print OUT &quot;$xticks /\n&quot;;
+ }
+ else
+ {
+ print OUT &quot;\\axis top /\n&quot;;
+ }
+ } }
+ BBRANCH: { if (index($axis, &quot;B&quot;)&gt;-1)
+ {
+ if (index($axis, &quot;B*&quot;)&gt;-1)
+ {
+ print OUT &quot;\\axis bottom /\n&quot;;
+ last BBRANCH;
+ }
+ if ($xticks &gt; 0)
+ {
+ print OUT &quot;\\axis bottom ticks numbered from $xlow to $xhigh by &quot;;
+ print OUT &quot;$xticks /\n&quot;;
+ }
+ else
+ {
+ print OUT &quot;\\axis bottom /\n&quot;;
+ }
+ } }
+
+
+</pre><p>The syntax of the <code>point</code> commands follows:
+<pre>
+point[*](PointName){Coordinates}[PointSymbol]
+</pre>
+where <code>PointName</code> is valid point name, <code>Coordinates</code> is either a
+pair of numbers denoting the coordinates of the point or an expression
+by means of which the system computes the coordinates of the point, and
+the <code>PointSymbol</code> is a valid T<sub><font size=+1>E</font></sub>X
+command denoting a point symbol. A valid point name consists of a
+letter and at most two trailing digits. That is, the names <code>a11</code>,
+<code>b2</code> and <code>c</code> are valid names while <code>qw</code> and <code>s123</code> are not.
+The first thing we do is to set the point shape to the default symbol
+(this has been initialized in the main program). Next, we check whether
+we have a <code>point</code>command or a <code>point*</code> simply by inspecting the very
+next token. Note that there must be no blank spaces between the token
+<code>point</code> and the star symbol. Next, we get the point name: remember that
+<a name="NWDCUvTi-1I">the point name is surrounded by parentheses. In case we don't find a valid</a>
+point name we issue an error message and continue with the next line of
+input. Suppose the point name was a valid one. If we have a <code>point*</code>
+command we must ensure that the this particular point name has been defined.
+If we have a <code>point</code> command we must ensure that this particular point
+name has not been defined. Point names are stored in the hash <code>%PointTable</code>.
+We are now ready to process the coordinates part and the optional
+plot symbol part.
+
+<pre><a name="NWCUvTi-2bvYBY-1" href="#NWDCUvTi-1I"><dfn>&lt;process <tt>point/point*</tt> commands&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-r">&lt;-U</a>)</b>
+ my ($pointStar, $PointName, $origPN);
+ $pointStar = 0; # default value: he have a point command
+ $pointStar = 1 if s/^\*//;
+ chk_lparen(&quot;point&quot; . (($pointStar)?&quot;*&quot;:&quot;&quot;),$lc);
+ if (s/^([^\W\d_](?![^\W\d_])\d{0,4})//i) {
+ #
+ # Note: the regular expression (foo)(?!bar) means that we are
+ # looking a foo not followed by a bar. Moreover, the regular
+ # expression [^\W\d_] means that we are looking for letter.
+ #
+ $origPN = $1;
+ $PointName = lc($1);
+ }
+ else {
+ PrintErrorMessage(&quot;Invalid point name&quot;,$lc);
+ next LINE;
+ }
+ #if ($pointStar and !exists($PointTable{$PointName})) {
+ # PrintWarningMessage(&quot;Point $origPN has not been defined&quot;,$lc);
+ #}
+ if (!$pointStar and exists($PointTable{$PointName})) {
+ PrintWarningMessage(&quot;Point $origPN has been used already&quot;,$lc);
+ }
+ chk_rparen(&quot;point&quot; . (($pointStar)?&quot;*&quot;:&quot;&quot;). &quot;($origPN&quot;,$lc);
+ chk_lcb(&quot;point&quot; . (($pointStar)?&quot;*&quot;:&quot;&quot;). &quot;($origPN)&quot;,$lc);
+ my ($Px, $Py);
+ <a name="NWCUvTi-2bvYBY-1-u1" href="#NWDCUvTi-1J"><i>&lt;process coordinates&gt;</i></a>
+ chk_rcb(&quot;coordinates part&quot;,$lc);
+ my $sv = $defaultsymbol;
+ my $sh = $defaultLFradius;
+ my $side_or_radius = undef;
+ if (s/^\[\s*//) { # the user has opted to specify the optional part
+ <a name="NWCUvTi-2bvYBY-1-u2" href="#NWDCUvTi-1V"><i>&lt;process optional point shape part&gt;</i></a>
+ chk_rsb(&quot;optional part&quot;,$lc);
+ }
+ # to avoid truncation problems introduced by the pack function, we
+ # round each number up to five decimal digits
+ $Px = sprintf(&quot;%.5f&quot;, $Px);
+ $Py = sprintf(&quot;%.5f&quot;, $Py);
+ print OUT &quot;%% point$Point_Line \t$origPN = ($Px, $Py)\n&quot; if $comments_on;
+ chk_comment($lc);
+ $PointTable{$PointName} = pack(&quot;d3A*&quot;,$Px,$Py,$sh,$sv);
+ if (defined($side_or_radius)) {
+ $DimOfPoint{$PointName} = $side_or_radius;
+ }
+
+</pre><p>In this section we parse the <code>Coordinates</code> part of the <code>point</code> command.
+The complete syntax of the <code>Coordinates</code> part follows:
+<pre>
+Coordinates ::= Variable |
+ Distance "," Distance |
+ "midpoint" "(" Point-Name Point-Name ")" |
+ "pointOnLine" "(" Two-Points "," Distance ")" |
+ "intersection" "(" Two-Points "," Two-Points ")" |
+ "perpendicular" "(" Point-Name "," Two-Points ")" |
+ "circumCircleCenter" "(" Three-Points ") |
+ "incircleCenter" "(" Three-Points ")" |
+ "excircleCenter" "(" Three-Points "," Two-Points ")" |
+ Point-Name [ "," Modifier ]
+
+Modifier ::= "shift" "(" Distance "," Distance ")" |
+ "polar" "(" Distance, Distance [ "deg" | "rad" ] ")" |
+ "rotate" "(" Point-Name, Distance [ "deg" | "rad" ] ")" |
+ "vector" "(" Two-Points ")"
+
+Distance ::= expression
+
+Two-Points ::= Point-Name Point-Name
+
+Three-Points ::= Point-Name Two-Points
+</pre>
+We now briefly explain the functionality of each option:
+<ul>
+<li>midpoint(AB): the midpoint between points A and B</li>
+<li>pointOnLine(AB,d): point at distance d from A towards B</li>
+<li>intersection(AB,CD): intersection of lines defined by AB and CD</li>
+<li>perpendicular(A,BC): point of the foot of the perpendicular from A to line BC</li>
+<li>circumCircleCenter(ABC): center of circumcircle of triangle ABC</li>
+<li>incircleCenter(ABC):center of incircle of triangle ABC</li>
+<li>excircleCenter(ABC,BC): center of excircle of triangle ABC, touching
+side BC</li>
+<li>A, shift(x,y): Point displaced from A by x and y along the X and Y
+axes</li>
+<li>A, polar(r,d): Point displaced from A by distance r in direction d</li>
+<li>A, rotate(B,d): Rotate A about B by d</li>
+</ul>
+We now explain how the following piece of code operates. In case the first
+token is a number, we assume that the coordinates are specified by a
+number and another number, a variable or a pair of points. So, we check
+whether there is a comma and use the subroutine <code>ComputeDist</code> to get the
+second coordinate. In case the next token is one of the words
+<code>perpendicular</code>, <code>intersection</code>, <code>midpoint</code>, <code>pointonline</code>,
+<code>circumcircleCenter</code>, <code>IncircleCenter</code>, or <code>ExcircleCenter</code>
+we consume the corresponding token and process the corresponding case.
+In case the first two tokens are two identifiers, then we assume that we
+have a pair of numbers. We compute their distance, check whether there is
+a leading comma and compute the y-coordinate by calling subroutine
+<code>ComputeDist</code>. In case the next token is a single identifier, we store
+its name in the variable <code>$PointA</code>. If this identifier is a defined point name,
+we check whether the next token is a comma. In case it is, we check whether
+he token after the comma is either the token <code>shift</code>, <code>polar</code>, or
+<code>rotate</code> and process each case accordingly. If it is
+<a name="NWDCUvTi-1J">none of these tokens we issue an error message and continue with the next</a>
+input line. Now, if the token after the identifier isn't a comma, we assume
+that the coordinates of the point will be identical to those of the point
+whose name has been stored in the variable <code>$PointA</code>. If the identifier is a
+variable name, we assume that the x-coordinate is the value of this variable.
+We check whether the next token is a comma, and compute the y-coordinate by
+calling the subroutine <code>ComputeDist</code>. The x-coordinate is stored in the variable
+<code>$Px</code> and the y-coordinate in the variable <code>$Py</code>.
+
+<pre><a name="NWCUvTi-3bnmlP-1" href="#NWDCUvTi-1J"><dfn>&lt;process coordinates&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-1I">&lt;-U</a>)</b>
+ if (s/^perpendicular(?=\W)//i) {
+ <a name="NWCUvTi-3bnmlP-1-u1" href="#NWDCUvTi-1K"><i>&lt;process <tt>perpendicular</tt> case&gt;</i></a>
+ }
+ elsif (s/^intersection(?=\W)//i) {
+ <a name="NWCUvTi-3bnmlP-1-u2" href="#NWDCUvTi-1L"><i>&lt;process <tt>intersection</tt> case&gt;</i></a>
+ }
+ elsif (s/^midpoint(?=\W)//i) {
+ <a name="NWCUvTi-3bnmlP-1-u3" href="#NWDCUvTi-1M"><i>&lt;process <tt>midpoint</tt> case&gt;</i></a>
+ }
+ elsif (s/^pointonline(?=\W)//i) {
+ <a name="NWCUvTi-3bnmlP-1-u4" href="#NWDCUvTi-1N"><i>&lt;process <tt>pointonline</tt> case&gt;</i></a>
+ }
+ elsif (s/^circumcircleCenter(?=\W)//i) {
+ <a name="NWCUvTi-3bnmlP-1-u5" href="#NWDCUvTi-1O"><i>&lt;process <tt>circumcircleCenter</tt> case&gt;</i></a>
+ }
+ elsif (s/^IncircleCenter(?=\W)//i) {
+ <a name="NWCUvTi-3bnmlP-1-u6" href="#NWDCUvTi-1P"><i>&lt;process <tt>IncircleCenter</tt> case&gt;</i></a>
+ }
+ elsif (s/^ExcircleCenter(?=\W)//i) {
+ <a name="NWCUvTi-3bnmlP-1-u7" href="#NWDCUvTi-1Q"><i>&lt;process <tt>ExcircleCenter</tt> case&gt;</i></a>
+ }
+ elsif (/^[^\W\d_]\d{0,4}\s*[^,\w]/) {
+ m/^([^\W\d_]\d{0,4})\s*/i;
+ if (exists($PointTable{lc($1)})) {
+ my $Tcoord = get_point($lc);
+ my ($x,$y,$pSV,$pS)=unpack(&quot;d3A*&quot;,$PointTable{$Tcoord});
+ $Px = $x;
+ $Py = $y;
+ }
+ else {
+ $Px = expr();
+ chk_comma($lc);
+ $Py = expr();
+ }
+ }
+ elsif (/[^\W\d_]\d{0,4}\s*,\s*shift|polar|rotate|vector/i) { #a point?
+ s/^([^\W\d_]\d{0,4})//i;
+ my $PointA = $1;
+ if (exists($PointTable{lc($PointA)})) {
+ s/\s*//;
+ if (s/^,//) {
+ s/\s*//;
+ if (s/^shift(?=\W)//i) {
+ <a name="NWCUvTi-3bnmlP-1-u8" href="#NWDCUvTi-1R"><i>&lt;process <tt>shift</tt> case&gt;</i></a>
+ }
+ elsif (s/^polar(?=\W)//i) {
+ <a name="NWCUvTi-3bnmlP-1-u9" href="#NWDCUvTi-1S"><i>&lt;process <tt>polar</tt> case&gt;</i></a>
+ }
+ elsif (s/^rotate(?=\W)//i) {
+ <a name="NWCUvTi-3bnmlP-1-u10" href="#NWDCUvTi-1T"><i>&lt;process <tt>rotate</tt> case&gt;</i></a>
+ }
+ elsif (s/^vector(?=\W)//i) {
+ <a name="NWCUvTi-3bnmlP-1-u11" href="#NWDCUvTi-1U"><i>&lt;process <tt>vector</tt> case&gt;</i></a>
+ }
+ else {
+ PrintErrorMessage(&quot;unexpected token&quot;,$lc);
+ next LINE;
+ }
+ }
+ else {
+ my ($xA,$yA,$pSVA,$pSA)=unpack(&quot;d3A*&quot;,$PointTable{lc($PointA)});
+ $Px = $xA;
+ $Py = $yA;
+ }
+ }
+ else {
+ PrintErrorMessage(&quot;Undefined point $PointA&quot;,$lc);
+ next LINE;
+ }
+ }
+ else {
+ $Px = expr();
+ chk_comma($lc);
+ $Py = expr();
+ }
+
+</pre><p>In the following piece of code we process the <code>perpendicular</code>
+case of the <code>point</code> specification. We first check whether there is an
+<a name="NWDCUvTi-1K">opening left parenthesis. Next, we get the first point name. In case</a>
+there is no point name, we simply abandon the processing of this
+line and continue with the next one. Then we see whether there is
+a trailing comma. Omitting this token yields a non-fatal error.
+Then we get two more points. As before, if we can't find any of these
+points this yields a fatal-error. Note, that each time we check that the
+point names correspond to existing point names. Then, we call subroutine
+<code>perpendicular</code> to calculate the coordinates of the point.
+
+<pre><a name="NWCUvTi-s2gHc-1" href="#NWDCUvTi-1K"><dfn>&lt;process <tt>perpendicular</tt> case&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-1J">&lt;-U</a>)</b>
+ chk_lparen(&quot;perpendicular&quot;,$lc);
+ my $FirstPoint = &amp;get_point($lc);
+ next LINE if $FirstPoint eq &quot;_undef_&quot;;
+ chk_comma($lc);
+ my $SecondPoint = &amp;get_point($lc);
+ next LINE if $SecondPoint eq &quot;_undef_&quot;;
+ my $ThirdPoint = &amp;get_point($lc);
+ next LINE if $ThirdPoint eq &quot;_undef_&quot;;
+ chk_rparen(&quot;No closing parenthesis found&quot;,$lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$FirstPoint});
+ my ($x2,$y2,$pSV2,$pS2)=unpack(&quot;d3A*&quot;,$PointTable{$SecondPoint});
+ my ($x3,$y3,$pSV3,$pS3)=unpack(&quot;d3A*&quot;,$PointTable{$ThirdPoint});
+ ($Px, $Py) = perpendicular($x1,$y1,$x2,$y2,$x3,$y3);
+
+</pre><p><a name="NWDCUvTi-1L">In the following piece of code we process the </a><code>intersection</code> case of the
+<code>point</code> specification. We get the four point names and if there is
+no error we compute the intersection point by calling subroutine
+<code>intersection</code>.
+
+<pre><a name="NWCUvTi-1uJA3A-1" href="#NWDCUvTi-1L"><dfn>&lt;process <tt>intersection</tt> case&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-1J">&lt;-U</a>)</b>
+ chk_lparen(&quot;intersection&quot;,$lc);
+ my $FirstPoint = get_point($lc);
+ next LINE if $FirstPoint eq &quot;_undef_&quot;;
+ my $SecondPoint = get_point($lc);
+ next LINE if $SecondPoint eq &quot;_undef_&quot;;
+ chk_comma($lc);
+ my $ThirdPoint = get_point($lc);
+ next LINE if $ThirdPoint eq &quot;_undef_&quot;;
+ my $ForthPoint = get_point($lc);
+ next LINE if $ForthPoint eq &quot;_undef_&quot;;
+ chk_rparen(&quot;No closing parenthesis found&quot;,$lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$FirstPoint});
+ my ($x2,$y2,$pSV2,$pS2)=unpack(&quot;d3A*&quot;,$PointTable{$SecondPoint});
+ my ($x3,$y3,$pSV3,$pS3)=unpack(&quot;d3A*&quot;,$PointTable{$ThirdPoint});
+ my ($x4,$y4,$pSV4,$pS4)=unpack(&quot;d3A*&quot;,$PointTable{$ForthPoint});
+ ($Px, $Py) = intersection4points($x1,$y1,$x2,$y2,$x3,$y3,$x4,$y4);
+
+
+</pre><p><a name="NWDCUvTi-1M">Given two points A and B, the midpoint option computes the coordinates</a>
+of a third point that lies on the middle of the line segment defined by
+these two points. We get the the two points, and then we compute the
+coordinates of the midpoint with function <code>midpoint</code>.
+
+<pre><a name="NWCUvTi-3udkns-1" href="#NWDCUvTi-1M"><dfn>&lt;process <tt>midpoint</tt> case&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-1J">&lt;-U</a>)</b>
+ chk_lparen(&quot;midpoint&quot;,$lc);
+ my $FirstPoint = &amp;get_point($lc);
+ next LINE if $FirstPoint eq &quot;_undef_&quot;;
+ my $SecondPoint = &amp;get_point($lc);
+ next LINE if $SecondPoint eq &quot;_undef_&quot;;
+ chk_rparen(&quot;No closing parenthesis found&quot;,$lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$FirstPoint});
+ my ($x2,$y2,$pSV2,$pS2)=unpack(&quot;d3A*&quot;,$PointTable{$SecondPoint});
+ ($Px, $Py) = midpoint($x1, $y1, $x2, $y2);
+
+</pre><p><a name="NWDCUvTi-1N">Given two points A and B and length d, the </a><code>PointOnLine</code> option
+computes the coordinates of a point that lies d units in the direction from
+A towards B. We first get the coordinates of the two points that define
+the line and then we get the distance, which can be a number, a variable,
+or a pair of points.
+
+<pre><a name="NWCUvTi-2ahy6i-1" href="#NWDCUvTi-1N"><dfn>&lt;process <tt>pointonline</tt> case&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-1J">&lt;-U</a>)</b>
+ chk_lparen(&quot;pointonline&quot;,$lc);
+ my $FirstPoint = &amp;get_point($lc);
+ next LINE if $FirstPoint eq &quot;_undef_&quot;;
+ my $SecondPoint = &amp;get_point($lc);
+ next LINE if $SecondPoint eq &quot;_undef_&quot;;
+ chk_comma($lc);
+ # now get the distance
+ my $distance = expr($lc);
+ chk_rparen(&quot;No closing parenthesis found&quot;,$lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$FirstPoint});
+ my ($x2,$y2,$pSV2,$pS2)=unpack(&quot;d3A*&quot;,$PointTable{$SecondPoint});
+ ($Px, $Py) = pointOnLine($x1,$y1,$x2,$y2,$distance);
+
+</pre><p><a name="NWDCUvTi-1O">The </a><code>circumcircleCenter</code> is used when one wants to compute the coordinates
+of the center of circle that passes through the three points
+of a triangle defined
+by the three arguments of the option. All we do is get the coordinates
+of the three points and then we call the subroutine <code>circumCircleCenter</code>
+to compute the center.
+
+<pre><a name="NWCUvTi-2TpCLC-1" href="#NWDCUvTi-1O"><dfn>&lt;process <tt>circumcircleCenter</tt> case&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-1J">&lt;-U</a>)</b>
+ chk_lparen(&quot;circumCircleCenter&quot;,$lc);
+ my $FirstPoint = &amp;get_point($lc);
+ next LINE if $FirstPoint eq &quot;_undef_&quot;;
+ my $SecondPoint = &amp;get_point($lc);
+ next LINE if $SecondPoint eq &quot;_undef_&quot;;
+ my $ThirdPoint = &amp;get_point($lc);
+ next LINE if $ThirdPoint eq &quot;_undef_&quot;;
+ chk_rparen(&quot;No closing parenthesis found&quot;,$lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$FirstPoint});
+ my ($x2,$y2,$pSV2,$pS2)=unpack(&quot;d3A*&quot;,$PointTable{$SecondPoint});
+ my ($x3,$y3,$pSV3,$pS3)=unpack(&quot;d3A*&quot;,$PointTable{$ThirdPoint});
+ ($Px, $Py,$r) = &amp;circumCircleCenter($x1,$y1,$x2,$y2,$x3,$y3,$lc);
+ next LINE if $Px == 0 and $Py == 0 and $r == 0;
+
+</pre><p><a name="NWDCUvTi-1P">The </a><code>IncircleCenter</code> option is to determine the coordinates of a point
+that is the center of circle that internally touches the sides
+of a triangle defined by three given points.
+The coordinates are computed by the subroutine <code>IncircleCenter</code>.
+
+<pre><a name="NWCUvTi-4fhWIW-1" href="#NWDCUvTi-1P"><dfn>&lt;process <tt>IncircleCenter</tt> case&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-1J">&lt;-U</a>)</b>
+ chk_lparen(&quot;IncircleCenter&quot;,$lc);
+ my $FirstPoint = &amp;get_point($lc);
+ next LINE if $FirstPoint eq &quot;_undef_&quot;;
+ my $SecondPoint = &amp;get_point($lc);
+ next LINE if $SecondPoint eq &quot;_undef_&quot;;
+ my $ThirdPoint = &amp;get_point($lc);
+ next LINE if $ThirdPoint eq &quot;_undef_&quot;;
+ chk_rparen(&quot;No closing parenthesis found&quot;,$lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$FirstPoint});
+ my ($x2,$y2,$pSV2,$pS2)=unpack(&quot;d3A*&quot;,$PointTable{$SecondPoint});
+ my ($x3,$y3,$pSV3,$pS3)=unpack(&quot;d3A*&quot;,$PointTable{$ThirdPoint});
+ ($Px, $Py, $r) = IncircleCenter($x1,$y1,$x2,$y2,$x3,$y3);
+
+</pre><p>The <code>ExcircleCenter</code> option is used to define the coordinates of point
+that is the center of an excircle of a triangle. We first check
+whether there is an opening left parenthesis. Next, we get the names of the
+<a name="NWDCUvTi-1Q">three points that define the triangle. Then, we</a>
+check whether there is a comma. Now we get the names of the two points that
+define one side of the triangle. We check whether the two points we
+get are of the set of the triangle points. If not we issue
+an error message and continue with the next input line. Then we make sure
+that these two points are not identical. We compute the actual
+coordinates by calling the subroutine <code>excircle</code>. Finally, we
+make sure there is a closing right parenthesis.
+
+<pre><a name="NWCUvTi-13KcO0-1" href="#NWDCUvTi-1Q"><dfn>&lt;process <tt>ExcircleCenter</tt> case&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-1J">&lt;-U</a>)</b>
+ chk_lparen(&quot;ExcircleCenter&quot;,$lc);
+ my $PointA = get_point($lc);
+ next LINE if $PointA eq &quot;_undef_&quot;;
+ my $PointB = get_point($lc);
+ next LINE if $PointB eq &quot;_undef_&quot;;
+ my $PointC = get_point($lc);
+ next LINE if $PointC eq &quot;_undef_&quot;;
+ chk_comma($lc);
+ my $PointD = &amp;get_point($lc);
+ next LINE if $PointD eq &quot;_undef_&quot;;
+ if (!memberOf($PointD, $PointA, $PointB, $PointC)) {
+ PrintErrorMessage(&quot;Current point isn't a side point&quot;,$lc);
+ next LINE;
+ }
+ my $PointE = get_point($lc);
+ next LINE if $PointE eq &quot;_undef_&quot;;
+ if (!memberOf($PointE, $PointA, $PointB, $PointC)) {
+ PrintErrorMessage(&quot;Current point isn't a side point&quot;,$lc);
+ next LINE;
+ }
+ if ($PointD eq $PointE) {
+ PrintErrorMessage(&quot;Side points are identical&quot;,$lc);
+ next LINE;
+ }
+ ($Px, $Py, $r) = excircle($PointA, $PointB, $PointC,
+ $PointD, $PointE);
+ chk_rparen(&quot;after coordinates part&quot;,$lc);
+
+</pre><p> <a name="NWDCUvTi-1R">The </a><code>shift</code> option allows us to define a point's coordinates relative
+to the coordinates of an existing point by using two shift parameters. Each
+parameter can be either a float, a variable name, or a pair of points.
+
+<pre><a name="NWCUvTi-aOKf8-1" href="#NWDCUvTi-1R"><dfn>&lt;process <tt>shift</tt> case&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-1J">&lt;-U</a> <a href="#NWDCUvTi-1a">U-&gt;</a>)</b>
+
+ chk_lparen(&quot;shift&quot;,$lc);
+ my $dist1 = expr($lc);
+ chk_comma($lc);
+ my $dist2 = expr($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{lc($PointA)});
+ $Px = $x1 + $dist1;
+ $Py = $y1 + $dist2;
+ chk_rparen(&quot;shift part&quot;,$lc);
+
+</pre><p><a name="NWDCUvTi-1S">The </a><code>polar</code> option allows us to define a point's coordinates relative
+to the coordinates of an existing point using the polar coordinates of some
+other point. We first check whether there is a left parenthesis,
+Then we parse the various parts of the <code>polar</code> option.
+In case the user has specified the angle in degrees, we have
+to transform it into radians, as all trigonometric function expect their
+arguments to be radians. Next, we compute the coordinates of the point.
+We conclude by checking whether there is a closing parenthesis.
+
+<pre><a name="NWCUvTi-2GUwzc-1" href="#NWDCUvTi-1S"><dfn>&lt;process <tt>polar</tt> case&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-1J">&lt;-U</a> <a href="#NWDCUvTi-1a">U-&gt;</a>)</b>
+ chk_lparen(&quot;polar&quot;,$lc);
+ my ($R1, $Theta1);
+ $R1 = expr($lc);
+ chk_comma($lc);
+ $Theta1 = expr($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{lc($PointA)});
+ s/\s*//;
+ if (s/^rad(?=\W)//i) {
+ # do nothing!
+ }
+ elsif (s/^deg(?=\W)//i) {
+ $Theta1 = $Theta1 * PI / 180;
+ }
+ else {
+ #$Theta1 = $Theta1 * PI / 180;
+ }
+ $Px = $x1 + $R1 * cos($Theta1);
+ $Py = $y1 + $R1 * sin($Theta1);
+ chk_rparen(&quot;after polar part&quot;,$lc);
+
+</pre><p>The <code>rotate</code> option allows us to define a point's coordinates by
+rotating an existing point, Q, about a third point, P, by a
+specified angle.
+The method to achieve this is to first get the coordinates of points
+P and Q and then
+<ol>
+<li> <a name="NWDCUvTi-1T">translate origin to P</a></li>
+<li> rotate about P</li>
+<li> translate from P back to origin, etc</li>
+</ol>
+As in the case of the <code>polar</code> option, we check for an opening parenthesis.
+Next, we parse the point name and the angle. At this point we are able to
+compute the coordinates of the rotated point. We conclude by checking
+whether there is a closing parenthesis.
+
+<pre><a name="NWCUvTi-42YuKP-1" href="#NWDCUvTi-1T"><dfn>&lt;process <tt>rotate</tt> case&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-1J">&lt;-U</a>)</b>
+ chk_lparen(&quot;rotate&quot;,$lc);
+ my $Q = lc($PointA);
+ my $P = get_point($lc);
+ next LINE if $P eq &quot;_undef_&quot;;
+ chk_comma($lc);
+ my $Theta1 = expr($lc);
+ my ($xP,$yP,$pSV1,$pS1)=unpack(&quot;d3A*&quot;,$PointTable{$P});
+ my ($xQ,$yQ,$pSV2,$pS2)=unpack(&quot;d3A*&quot;,$PointTable{$Q});
+ s/\s*//;
+ if (s/^rad(?=\W)//i)
+ {
+ # do nothing!
+ }
+ elsif (s/^deg(?=\W)//i)
+ {
+ $Theta1 = $Theta1 * PI / 180;
+ }
+ else
+ {
+ $Theta1 = $Theta1 * PI / 180;
+ }
+ # shift origin to P
+ $xQ -= $xP;
+ $yQ -= $yP;
+ # do the rotation
+ $Px = $xQ * cos($Theta1) - $yQ * sin($Theta1);
+ $Py = $xQ * sin($Theta1) + $yQ * cos($Theta1);
+ # return origin back to original origin
+ $Px += $xP;
+ $Py += $yP;
+ chk_rparen(&quot;after rotate part&quot;,$lc);
+
+</pre><p> <code><a name="NWDCUvTi-1U">vector(PQ)</a></code> is actually is a shorthand of <code>shift(xQ-xP,yQ-yP)</code>. Thus, it
+is implemented by borrowing code from the <code>shift</code> modifier.
+
+<pre><a name="NWCUvTi-3FiNXu-1" href="#NWDCUvTi-1U"><dfn>&lt;process <tt>vector</tt> case&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-1J">&lt;-U</a>)</b>
+ chk_lparen(&quot;vector&quot;,$lc);
+ my ($x0,$y0,$pSV0,$pS0) = unpack(&quot;d3A*&quot;,$PointTable{lc($PointA)});
+ my $P = get_point($lc);
+ my $Q = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1) = unpack(&quot;d3A*&quot;,$PointTable{$P});
+ my ($x2,$y2,$pSV2,$pS2) = unpack(&quot;d3A*&quot;,$PointTable{$Q});
+ $Px = $x0 + $x2 - $x1;
+ $Py = $y0 + $y2 - $y1;
+ chk_rparen(&quot;vector part&quot;,$lc);
+
+
+</pre><p> When lines are drawn to a point, the line will (unless otherwise
+specified) extend to the point location. However, this can be prevented by
+allocating an optional circular line-free zone to a point by specifying the
+radius (in square brackets) of the optional point shape part. Currently, in this part
+we are allowed to describe the point shape and the radius value. If only the
+radius is specified, e.g., <tt>[radius=5]</tt>, then the line-free zone will be
+applied to the default point character, i.e., <tt>$\bullet$</tt> or whatever it
+has been set to. Here is the syntax we employ:
+<pre>
+Optional_point_shape_part ::= "[" [ symbol_part ] [","] [ radius_part ]"
+<a name="NWDCUvTi-1V">symbol_part ::= "symbol" "=" symbol</a>
+symbol ::= "circle" "(" expression ")" |
+ "square" "(" expression ")" |
+ LaTeX_Code
+radius_part ::= "radius" "=" expression
+</pre>
+Note that it is possible to have right square bracket in the <tt>LaTeX_Code</tt> but it
+has to be escaped (i.e., <tt>\]</tt>).
+
+<pre><a name="NWCUvTi-48J1W6-1" href="#NWDCUvTi-1V"><dfn>&lt;process optional point shape part&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-1I">&lt;-U</a>)</b>
+ if (/^(symbol|radius|side)\s*/i) {
+ my @previous_options = ();
+ my $number_of_options = 1;
+ my $symbol_set = 0;
+ while (s/^(symbol|radius)\s*//i and $number_of_options &lt;= 2) {
+ my $option = lc($1);
+ if (s/^=\s*//) {
+ if (memberOf($option,@previous_options)) {
+ PrintErrorMessage(&quot;Option \&quot;$option\&quot; has been already defined&quot;, $lc);
+ my $dummy = expr($lc);
+ }
+ elsif ($option eq &quot;radius&quot;) {
+ $sh = expr($lc);
+ $sv = $defaultsymbol if ! $symbol_set;
+ }
+ elsif ($option eq &quot;symbol&quot;) {
+ if (s/^circle\s*//i) {
+ $sv = &quot;circle&quot;;
+ chk_lparen(&quot;after token circle&quot;,$lc);
+ $side_or_radius = expr($lc);
+ chk_rparen(&quot;expression&quot;,$lc);
+ }
+ elsif (s/^square\s*//i) {
+ $sv = &quot;square&quot;;
+ chk_lparen(&quot;after token square&quot;,$lc);
+ $side_or_radius = expr($lc);
+ chk_rparen(&quot;expression&quot;,$lc);
+ }
+ elsif (s/^(((\\\]){1}|(\\,){1}|(\\\s){1}|[^\],\s])+)//) {
+ $sv = $1;
+ $sv =~ s/\\\]/\]/g;
+ $sv =~ s/\\,/,/g;
+ $sv =~ s/\\ / /g;
+ s/\s*//;
+ }
+ $symbol_set = 1;
+ }
+ }
+ else {
+ PrintErrorMessage(&quot;unexpected token&quot;, $lc);
+ next LINE;
+ }
+ $number_of_options++;
+ push (@previous_options, $option);
+ s/^,\s*//;
+ }
+ }
+ else {
+ PrintErrorMessage(&quot;unexpected token&quot;, $lc);
+ next LINE;
+ }
+
+</pre><p>The <code>ArrowShape</code> command has either one or three arguments. If the only argument of
+the command is the token <code>default</code>, then the parameters associated with the
+arrow shape resume their default values. Now, if there are three arguments, these are
+used to specify the shape of an arrow. The command actually sets the three global variables
+<code>$arrowLength</code>, <code>$arrowAngleB</code> and <code>$arrowAngleC</code>. Arguments whose value is equal
+to zero, do not affect the value of the corresponding global variables. To reset the
+values of the global variables one should use the commane with <code>default</code> as it
+only argument. The syntax of the command is as follows:
+<center>
+<tt><a name="NWDCUvTi-1W">"ArrowShape" "(" expr [ units ] "," expr "," expr ")"</a></tt> or<br>
+<tt>"ArrowShape" "(" "default" ")" </tt>
+</center>>
+Here <code>units</code> is any valid TeX unit (e.g., "mm", "cm", etc.). Note that if
+any of the three expressions is equal to zero, the default value is taken
+instead. As direct consequence, if the value of the first expression is zero,
+the units part is actually ignored.
+
+<pre><a name="NWCUvTi-4T61Ms-1" href="#NWDCUvTi-1W"><dfn>&lt;process <tt>ArrowShape</tt> command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-r">&lt;-U</a>)</b>
+
+ chk_lparen(&quot;$cmd&quot;,$lc);
+ if (s/^default//i) {
+ $arrowLength = 2;
+ $arrowLengthUnits = &quot;mm&quot;;
+ $arrowAngleB = 30;
+ $arrowAngleC = 40;
+ }
+ else {
+ my ($LocalArrowLength, $LocalArrowAngleB ,$LocalArrowAngleC) = (0,0,0);
+ $LocalArrowLength = expr($lc);
+ if (s/^\s*($units)//i) {
+ $arrowLengthUnits = &quot;$1&quot;;
+ }
+ else {
+ $xunits =~ /(\d+(\.\d+)?)\s*($units)/;
+ $LocalArrowLength *= $1;
+ $arrowLengthUnits = &quot;$3&quot;;
+ }
+ chk_comma($lc);
+ $LocalArrowAngleB = expr($lc);
+ chk_comma($lc);
+ $LocalArrowAngleC = expr($lc);
+ $arrowLength = ($LocalArrowLength == 0 ? 2 : $LocalArrowLength);
+ $arrowLengthUnits = ($LocalArrowLength == 0 ? &quot;mm&quot; : $arrowLengthUnits);
+ $arrowAngleB = ($LocalArrowAngleB == 0 ? 30 : $LocalArrowAngleB);
+ $arrowAngleC = ($LocalArrowAngleC == 0 ? 40 : $LocalArrowAngleC);
+ }
+ chk_rparen(&quot;after $cmd arguments&quot;,$lc);
+ chk_comment(&quot;after $cmd command&quot;,$lc);
+ print OUT &quot;%% arrowLength = $arrowLength$arrowLengthUnits, &quot;,
+ &quot;arrowAngleB = $arrowAngleB &quot;,
+ &quot;and arrowAngleC = $arrowAngleC\n&quot; if $comments_on;
+
+</pre><p>The <code>PointSymbol</code> command is used to set the point symbol and possibly its
+line-free radius. The point symbol can be either a LaTeX symbol or the word <code>default</code>
+which corresponds to the default point symbol, i.e., <tt>$\bullet$</tt>. The line-free
+radius can be an expression. Here is the complete syntax:
+<pre>
+ <a name="NWDCUvTi-1X">pointsymbol ::= "pointsymbol" ( symbol [ "," radius])</a>
+ symbol ::= "default" | circle | square | LaTeX_Code
+ circle ::= "circle" "(" expression ")"
+ square ::= "square" "(" expression ")"
+ radius ::= expression
+</pre>
+Note that the <tt>LaTeX_Code</tt> can contain the symbols <tt>\,</tt> and
+<tt>\)</tt> which are escape sequences for a comma and right parenthesis, respectively.
+
+<pre><a name="NWCUvTi-iKtUD-1" href="#NWDCUvTi-1X"><dfn>&lt;process <tt>PointSymbol</tt> command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-r">&lt;-U</a>)</b>
+
+ chk_lparen(&quot;$cmd&quot;,$lc);
+ if (s/^default//i) #default point symbol
+ {
+ $defaultsymbol = &quot;\$\\bullet\$&quot;;
+ }
+ elsif (s/^(circle|square)//i) {
+ $defaultsymbol = $1;
+ chk_lparen($defaultsymbol, $lc);
+ $GlobalDimOfPoints = expr($lc);
+ chk_rparen(&quot;expression&quot;, $lc);
+ }
+ elsif (s/^(((\\,){1}|(\\\)){1}|(\\\s){1}|[^\),\s])+)//) #arbitrary LaTeX point
+ {
+ $defaultsymbol = $1;
+ $defaultsymbol=~ s/\\\)/\)/g;
+ $defaultsymbol=~ s/\\,/,/g;
+ $defaultsymbol=~ s/\\ / /g;
+ }
+ else
+ {
+ PrintErrorMessage(&quot;unrecognized point symbol&quot;,$lc);
+ }
+ if (s/\s*,\s*//) {
+ $defaultLFradius = expr($lc);
+ }
+ chk_rparen(&quot;after $cmd arguments&quot;,$lc);
+ chk_comment(&quot;after $cmd command&quot;,$lc);
+
+</pre><p>The <code>system</code> command provides a shell escape. However, we use a subroutine
+to check whether the argument of the command contains tainted data. If this
+is the case, then we simply ignore this command. The syntax of the command
+is as follows:
+<pre>
+ system-cmd ::= "system" "(" string ")"
+</pre>
+<a name="NWDCUvTi-1Y">where string is just a sequence of characters enclosed in quotation marks.</a>
+We start by parsing a left parenthesis and then we get the command by
+calling the subroutine <code>get_string</code>. If there is an error we skip this
+command. Otherwise, we assign to the variable <code>$_</code> what is left. Now we check
+if the variable <code>$command</code> contains any tainted data. If it doesn't, we
+execute the command, otherwise we print an error message and skip to the
+next input line. Next, we check for closing right parenthesis and a possible
+trailing comment.
+
+<pre><a name="NWCUvTi-4C0pFV-1" href="#NWDCUvTi-1Y"><dfn>&lt;process <tt>system</tt> command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-r">&lt;-U</a>)</b>
+
+ chk_lparen(&quot;$cmd&quot;,$lc);
+ my ($error, $command, $rest) = get_string($_);
+ next LINE if $error == 1;
+ $_ = $rest;
+ if (! is_tainted($command)) {
+ system($command);
+ }
+ else {
+ PrintErrorMessage(&quot;String \&quot;$command\&quot; has tainted data&quot;, $lc);
+ next LINE;
+ }
+ chk_rparen(&quot;after $cmd arguments&quot;,$lc);
+ chk_comment(&quot;after $cmd command&quot;,$lc);
+
+</pre><p>The <code>text</code> command is used to put a piece of text or a symbol on
+a particular point of the resulting graph. The syntax of the command is
+as follows:
+<pre>
+ text-comm ::= "text" "(" text ")" "{"coords"} "[" pos-code "]"
+ text ::= ascii string
+ coords ::= Coord "," Coord |
+ Point-Name "," "shift" "(" Coord "," Coord ")" |
+ Point-Name "," "polar" "(" Coord "," Coord [angle-unit] ")"
+ Coord ::= decimal number | variable | pair-of-Point-Names
+ pair-of-Point-Names ::= Point-Name Point-Name
+ angle-unit ::= "deg" | "rad"
+ pos-code ::= lr-code [tb-code] | tb-code [lr-code]
+ lr-code ::= "l" | "r"
+ tb-code ::= "t" | "b" | "B"
+</pre>
+Initially, we parse the <code>text</code>. Since the text may contain parentheses
+we assume that the user enters pairs of matching parentheses. Note, that
+this is a flaw in the original design of the language, which may be remedied
+in future releases of the software. Then, we check the <code>coords</code> part. Next,
+<a name="NWDCUvTi-1Z">if there is a left square bracket, we assume the user has specified the</a>
+<code>pos-code</code>. We conclude by checking a possible trailing comment.
+The next thing we do is to generate the PiCTeX code. The two possible
+forms follow:
+<center>
+<tt>\put {TEXT} [POS] at Px Py</tt><br>
+<tt>\put {TEXT} at Px Py</tt><br>
+</center>
+
+<pre><a name="NWCUvTi-z25eX-1" href="#NWDCUvTi-1Z"><dfn>&lt;process <tt>text</tt> command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-r">&lt;-U</a>)</b>
+
+ chk_lparen(&quot;text&quot;,$lc);
+ my ($level,$text)=(1,&quot;&quot;);
+ TEXTLOOP: while (1)
+ {
+ $level++ if /^\(/;
+ $level-- if /^\)/;
+ s/^(.)//;
+ last TEXTLOOP if $level==0;
+ $text .= $1;
+ }
+ chk_lcb(&quot;text part&quot;,$lc);
+ my ($Px, $Py,$dummy,$pos);
+ $pos=&quot;&quot;;
+ s/\s*//;
+ <a name="NWCUvTi-z25eX-1-u1" href="#NWDCUvTi-1a"><i>&lt;process coordinates part of text command&gt;</i></a>
+ chk_rcb(&quot;coordinates part of text command&quot;,$lc);
+ if (s/^\[//)
+ {
+ s/\s*//;
+ <a name="NWCUvTi-z25eX-1-u2" href="#NWDCUvTi-1b"><i>&lt;process optional part of text command&gt;</i></a>
+ s/\s*//;
+ chk_rsb(&quot;optional part of text command&quot;,$lc);
+ }
+ chk_comment($lc);
+ if ($pos eq &quot;&quot;)
+ {
+ printf OUT &quot;\\put {%s} at %f %f\n&quot;, $text, $Px, $Py;
+ }
+ else
+ {
+ printf OUT &quot;\\put {%s} [%s] at %f %f\n&quot;, $text, $pos, $Px, $Py;
+ }
+
+</pre><p> In this section we define the code that handles the coordinates part
+<a name="NWDCUvTi-1a">of the </a><code>text</code> command. The code just implements the grammar given above.
+If the first token is a number, we assume this is the x-coordinate. If
+it is a variable, we assume its value is the x-coordinate. However, if
+it is a point name, we check whether the next token is another point name.
+In this case we compute the distance between the two points. In case we
+have a single point followed by a comma, we expect to have either a polar
+or a shift part, which we process the same we processed them in the point
+command.
+
+<pre><a name="NWCUvTi-Ee8Ug-1" href="#NWDCUvTi-1a"><dfn>&lt;process coordinates part of text command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-1Z">&lt;-U</a>)</b>
+
+ if (/^[^\W\d_]\d{0,4}\s*[^,\w]/) {
+ my $Tcoord = get_point($lc);
+ my ($x,$y,$pSV,$pS)=unpack(&quot;d3A*&quot;,$PointTable{$Tcoord});
+ $Px = $x;
+ $Py = $y;
+ }
+ elsif (/[^\W\d_]\d{0,4}\s*,\s*shift|polar/i) {
+ s/^([^\W\d_]\d{0,4})//i;
+ my $PointA = $1;
+ if (exists($PointTable{lc($PointA)})) {
+ s/\s*//;
+ if (s/^,//) {
+ s/\s*//;
+ if (s/^shift(?=\W)//i) {
+ <a name="NWCUvTi-Ee8Ug-1-u1" href="#NWDCUvTi-1R"><i>&lt;process <tt>shift</tt> case&gt;</i></a>
+ }
+ elsif (s/^polar(?=\W)//i) {
+ <a name="NWCUvTi-Ee8Ug-1-u2" href="#NWDCUvTi-1S"><i>&lt;process <tt>polar</tt> case&gt;</i></a>
+ }
+ }
+ }
+ else {
+ PrintErrorMessage(&quot;undefined point/var&quot;,$lc);
+ next LINE;
+ }
+ }
+ else {
+ $Px = expr();
+ chk_comma($lc);
+ $Py = expr();
+ }
+
+</pre><p>In this section we process the optional part of the <code>text</code> command.
+The general rule is that we are allowed to have up to two options one
+from the characters <code>l</code> and <code>r</code> and one from the the characters
+<code>B</code>, <code>b</code>, and <code>t</code>. We first check whether the next character is
+letter, if it isn't we issue an error message and continue with the next
+input line. If it is a letter we check whether it belongs to one of the
+two groups and if it doesn't we issue an error message and continue with the
+next input line. If the next character belongs to first group, i.e., it is
+either <code>l</code> or <code>r</code>, we store this character into the variable <code>$pos</code>. Next,
+<a name="NWDCUvTi-1b">we check whether there is another letter. If it is a letter, we store it</a>
+in the variable <code>$np</code>. Now we make sure that this character belongs to the
+other group, i.e., it is either <code>b</code>, <code>B</code>, or <code>t</code>. In case it belongs
+to the other group, we append the value of <code>$np</code> to the string stored in
+the variable <code>$pos</code>. Otherwise we issue an error message and continue with the
+next input line. We work similarly for the other case. In order to check
+whether a character belongs to some group of characters, we use the user
+defined function <code>memberOf</code>.
+
+<pre><a name="NWCUvTi-RSg70-1" href="#NWDCUvTi-1b"><dfn>&lt;process optional part of text command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-1Z">&lt;-U</a>)</b>
+
+ if (s/^(\w{1})\s*//) {
+ $pos .= $1;
+ if (memberOf($pos, &quot;l&quot;, &quot;r&quot;)) {
+ if (s/^(\w{1})\s*//) {
+ my $np = $1;
+ if (memberOf($np, &quot;t&quot;, &quot;b&quot;, &quot;B&quot;)) {
+ $pos .= $np;
+ }
+ else {
+ if (memberOf($np, &quot;l&quot;, &quot;r&quot;)) {
+ PrintErrorMessage(&quot;$np can't follow 'l' or 'r'&quot;, $lc);
+ }
+ else {
+ PrintErrorMessage(&quot;$np is not a valid positioning option&quot;, $lc);
+ }
+ next LINE;
+ }
+ }
+ }
+ elsif (memberOf($pos, &quot;t&quot;, &quot;b&quot;, &quot;B&quot;)) {
+ if (s/^(\w{1})\s*//) {
+ my $np = $1;
+ if (memberOf($np, &quot;l&quot;, &quot;r&quot;)) {
+ $pos .= $np;
+ }
+ else {
+ if (memberOf($np, &quot;t&quot;, &quot;b&quot;, &quot;B&quot;)) {
+ PrintErrorMessage(&quot;$np can't follow 't', 'b', or 'B'&quot;, $lc);
+ }
+ else {
+ PrintErrorMessage(&quot;$np is not a valid positioning option&quot;, $lc);
+ }
+ next LINE;
+ }
+ }
+ }
+ else {
+ PrintErrorMessage(&quot;$pos is not a valid positioning option&quot;, $lc);
+ next LINE;
+ }
+ }
+ else {
+ PrintErrorMessage(&quot;illegal token in optional part of text command&quot;,$lc);
+ next LINE;
+ }
+
+</pre><p>The <code>const</code> command is used to store values into a comma separated
+list of named constants. Constant names have the same format as point names,
+i.e., they start with a letter and are followed by up to two digits. The
+<a name="NWDCUvTi-1c">whole operation is performed by a </a><code>do-while</code> construct that checks that
+there is a valid constant name, a <code>=</code> sign, and an expression. The
+<code>do-while</code> construct terminates if the next token isn't a comma. Variable
+<code>$Constname</code> is used to store the initial variable name, while we store
+in variable <code>$varname</code> the lowercase version of the variable name. In addition,
+we make sure a constant is not redefined (or else it wouldn't be a constant:-).
+The last thing we do is to check whether there is a trailing comment.
+In case there, we simply ignore itl; otherwise we print a warning message.
+
+<pre><a name="NWCUvTi-4F0xHm-1" href="#NWDCUvTi-1c"><dfn>&lt;process <tt>const</tt> command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-r">&lt;-U</a>)</b>
+ do{
+ s/\s*//;
+ PrintErrorMessage(&quot;no identifier found after token const&quot;,$lc)
+ if $_ !~ s/^([^\W\d_]\d{0,4})//i;
+ my $Constname = $1;
+ my $constname = lc($Constname);
+ if (exists $ConstTable{$constname}) {
+ PrintErrorMessage(&quot;Redefinition of constant $constname&quot;,$lc);
+ }
+ s/\s*//; #remove leading white space
+ PrintErrorMessage(&quot;did not find expected = sign&quot;,$lc)
+ if $_ !~ s/^[=]//i;
+ my $val = expr($lc);
+ $VarTable{$constname} = $val;
+ $ConstTable{$constname} = 1;
+ print OUT &quot;%% $Constname = $val\n&quot; if $comments_on;
+ }while (s/^,//);
+ chk_comment($lc);
+ s/\s*//;
+ if (/^[^%]/) {
+ PrintWarningMessage(&quot;Trailing text is ignored&quot;,$lc);
+ }
+
+</pre><p>The <code>var</code> command is used to store values into a comma separated
+list of named variables. Variable names have the same format as point names,
+<a name="NWDCUvTi-1d">i.e., they start with a letter and are followed by up to two digits. The</a>
+whole operation is performed by a <code>do-while</code> construct that checks that
+there is a valid variable name, a <code>=</code> sign, and an expression. The
+<code>do-while</code> construct terminates if the next token isn't a comma. The variable
+<code>$Varname</code> is used to store the initial variable name, while we store
+in the variable <code>$varname</code> the lowercase version of the variable name.
+The last thing we do is to check whether there is a trailing comment.
+In case there, we simply ignore itl; otherwise we print a warning message.
+
+<pre><a name="NWCUvTi-2NFa6I-1" href="#NWDCUvTi-1d"><dfn>&lt;process <tt>var</tt> command&gt;=</dfn></a> <b>(<a href="#NWDCUvTi-r">&lt;-U</a>)</b>
+ do{
+ s/\s*//;
+ PrintErrorMessage(&quot;no identifier found after token var&quot;,$lc)
+ if $_ !~ s/^([^\W\d_]\d{0,4})//i;
+ my $Varname = $1;
+ my $varname = lc($Varname);
+ if (exists $ConstTable{$varname}) {
+ PrintErrorMessage(&quot;Redefinition of constant $varname&quot;,$lc);
+ }
+ s/\s*//; #remove leading white space
+ PrintErrorMessage(&quot;did not find expected = sign&quot;,$lc)
+ if $_ !~ s/^[=]//i;
+ my $val = expr($lc);
+ $VarTable{$varname} = $val;
+ print OUT &quot;%% $Varname = $val\n&quot; if $comments_on;
+ }while (s/^,//);
+ chk_comment($lc);
+ s/\s*//;
+ if (/^[^%]/) {
+ PrintWarningMessage(&quot;Trailing text is ignored&quot;,$lc);
+ }
+</pre>
+
+<ul>
+<li><a href="#NWDCUvTi-2"><i>&lt;*&gt;</i></a>: <a href="#NWDCUvTi-2">D1</a>
+<li><a href="#NWDCUvTi-4"><i>&lt;Check for command line arguments&gt;</i></a>: <a href="#NWDCUvTi-2">U1</a>, <a href="#NWDCUvTi-4">D2</a>
+<li><a href="#NWDCUvTi-6"><i>&lt;Check if .m file exists&gt;</i></a>: <a href="#NWDCUvTi-4">U1</a>, <a href="#NWDCUvTi-6">D2</a>
+<li><a href="#NWDCUvTi-8"><i>&lt;Define global variables&gt;</i></a>: <a href="#NWDCUvTi-2">U1</a>, <a href="#NWDCUvTi-8">D2</a>
+<li><a href="#NWDCUvTi-1E"><i>&lt;generate plot area related commands&gt;</i></a>: <a href="#NWDCUvTi-17">U1</a>, <a href="#NWDCUvTi-1E">D2</a>
+<li><a href="#NWDCUvTi-1H"><i>&lt;generate the rest of the code for the <tt>paper</tt> command&gt;</i></a>: <a href="#NWDCUvTi-17">U1</a>, <a href="#NWDCUvTi-1H">D2</a>
+<li><a href="#NWDCUvTi-3"><i>&lt;package <tt>DummyFH</tt> &gt;</i></a>: <a href="#NWDCUvTi-2">U1</a>, <a href="#NWDCUvTi-3">D2</a>
+<li><a href="#NWDCUvTi-u"><i>&lt;process <tt>angle</tt> part of command&gt;</i></a>: <a href="#NWDCUvTi-t">U1</a>, <a href="#NWDCUvTi-u">D2</a>
+<li><a href="#NWDCUvTi-1W"><i>&lt;process <tt>ArrowShape</tt> command&gt;</i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-1W">D2</a>
+<li><a href="#NWDCUvTi-1F"><i>&lt;process <tt>axis</tt> part&gt;</i></a>: <a href="#NWDCUvTi-17">U1</a>, <a href="#NWDCUvTi-1F">D2</a>
+<li><a href="#NWDCUvTi-1O"><i>&lt;process <tt>circumcircleCenter</tt> case&gt;</i></a>: <a href="#NWDCUvTi-1J">U1</a>, <a href="#NWDCUvTi-1O">D2</a>
+<li><a href="#NWDCUvTi-1c"><i>&lt;process <tt>const</tt> command&gt;</i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-1c">D2</a>
+<li><a href="#NWDCUvTi-s"><i>&lt;process <tt>dasharray</tt> command&gt;</i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-s">D2</a>
+<li><a href="#NWDCUvTi-t"><i>&lt;process <tt>drawAngleArcOrArrow</tt> command&gt;</i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-t">D2</a>
+<li><a href="#NWDCUvTi-w"><i>&lt;process <tt>drawcircle</tt> command&gt;</i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-w">D2</a>
+<li><a href="#NWDCUvTi-x"><i>&lt;process <tt>drawcircumcircle</tt> command&gt;</i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-x">D2</a>
+<li><a href="#NWDCUvTi-y"><i>&lt;process <tt>drawexcircle</tt> command&gt;</i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-y">D2</a>
+<li><a href="#NWDCUvTi-z"><i>&lt;process <tt>drawincircle</tt> command&gt;</i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-z">D2</a>
+<li><a href="#NWDCUvTi-10"><i>&lt;process <tt>drawPerpendicular</tt> command&gt;</i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-10">D2</a>
+<li><a href="#NWDCUvTi-11"><i>&lt;process <tt>drawpoint</tt> command&gt;</i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-11">D2</a>
+<li><a href="#NWDCUvTi-12"><i>&lt;process <tt>drawRightAngle</tt> command&gt;</i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-12">D2</a>
+<li><a href="#NWDCUvTi-13"><i>&lt;process <tt>drawsquare</tt> command&gt;</i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-13">D2</a>
+<li><a href="#NWDCUvTi-1Q"><i>&lt;process <tt>ExcircleCenter</tt> case&gt;</i></a>: <a href="#NWDCUvTi-1J">U1</a>, <a href="#NWDCUvTi-1Q">D2</a>
+<li><a href="#NWDCUvTi-1P"><i>&lt;process <tt>IncircleCenter</tt> case&gt;</i></a>: <a href="#NWDCUvTi-1J">U1</a>, <a href="#NWDCUvTi-1P">D2</a>
+<li><a href="#NWDCUvTi-14"><i>&lt;process <tt>inputfile*</tt> command&gt;</i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-14">D2</a>
+<li><a href="#NWDCUvTi-15"><i>&lt;process <tt>inputfile</tt> command&gt;</i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-15">D2</a>
+<li><a href="#NWDCUvTi-1L"><i>&lt;process <tt>intersection</tt> case&gt;</i></a>: <a href="#NWDCUvTi-1J">U1</a>, <a href="#NWDCUvTi-1L">D2</a>
+<li><a href="#NWDCUvTi-16"><i>&lt;process <tt>linethickness</tt> command&gt;</i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-16">D2</a>
+<li><a href="#NWDCUvTi-1M"><i>&lt;process <tt>midpoint</tt> case&gt;</i></a>: <a href="#NWDCUvTi-1J">U1</a>, <a href="#NWDCUvTi-1M">D2</a>
+<li><a href="#NWDCUvTi-17"><i>&lt;process <tt>paper</tt> command&gt;</i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-17">D2</a>
+<li><a href="#NWDCUvTi-1K"><i>&lt;process <tt>perpendicular</tt> case&gt;</i></a>: <a href="#NWDCUvTi-1J">U1</a>, <a href="#NWDCUvTi-1K">D2</a>
+<li><a href="#NWDCUvTi-1I"><i>&lt;process <tt>point/point*</tt> commands&gt;</i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-1I">D2</a>
+<li><a href="#NWDCUvTi-1N"><i>&lt;process <tt>pointonline</tt> case&gt;</i></a>: <a href="#NWDCUvTi-1J">U1</a>, <a href="#NWDCUvTi-1N">D2</a>
+<li><a href="#NWDCUvTi-1X"><i>&lt;process <tt>PointSymbol</tt> command&gt;</i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-1X">D2</a>
+<li><a href="#NWDCUvTi-1S"><i>&lt;process <tt>polar</tt> case&gt;</i></a>: <a href="#NWDCUvTi-1J">U1</a>, <a href="#NWDCUvTi-1S">D2</a>, <a href="#NWDCUvTi-1a">U3</a>
+<li><a href="#NWDCUvTi-v"><i>&lt;process <tt>radius</tt> part of command&gt;</i></a>: <a href="#NWDCUvTi-t">U1</a>, <a href="#NWDCUvTi-v">D2</a>
+<li><a href="#NWDCUvTi-1T"><i>&lt;process <tt>rotate</tt> case&gt;</i></a>: <a href="#NWDCUvTi-1J">U1</a>, <a href="#NWDCUvTi-1T">D2</a>
+<li><a href="#NWDCUvTi-1R"><i>&lt;process <tt>shift</tt> case&gt;</i></a>: <a href="#NWDCUvTi-1J">U1</a>, <a href="#NWDCUvTi-1R">D2</a>, <a href="#NWDCUvTi-1a">U3</a>
+<li><a href="#NWDCUvTi-1B"><i>&lt;process <tt>showAngle</tt> command&gt;</i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-1B">D2</a>
+<li><a href="#NWDCUvTi-1C"><i>&lt;process <tt>showArea</tt> command&gt;</i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-1C">D2</a>
+<li><a href="#NWDCUvTi-1D"><i>&lt;process <tt>showLength</tt> command&gt;</i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-1D">D2</a>
+<li><a href="#NWDCUvTi-1Y"><i>&lt;process <tt>system</tt> command&gt;</i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-1Y">D2</a>
+<li><a href="#NWDCUvTi-1Z"><i>&lt;process <tt>text</tt> command&gt;</i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-1Z">D2</a>
+<li><a href="#NWDCUvTi-1G"><i>&lt;process <tt>ticks</tt> part&gt;</i></a>: <a href="#NWDCUvTi-17">U1</a>, <a href="#NWDCUvTi-1G">D2</a>
+<li><a href="#NWDCUvTi-18"><i>&lt;process <tt>unit</tt> part&gt;</i></a>: <a href="#NWDCUvTi-17">U1</a>, <a href="#NWDCUvTi-18">D2</a>
+<li><a href="#NWDCUvTi-1d"><i>&lt;process <tt>var</tt> command&gt;</i></a>: <a href="#NWDCUvTi-r">U1</a>, <a href="#NWDCUvTi-1d">D2</a>
+<li><a href="#NWDCUvTi-1U"><i>&lt;process <tt>vector</tt> case&gt;</i></a>: <a href="#NWDCUvTi-1J">U1</a>, <a href="#NWDCUvTi-1U">D2</a>
+<li><a href="#NWDCUvTi-19"><i>&lt;process <tt>xrange</tt> part&gt;</i></a>: <a href="#NWDCUvTi-17">U1</a>, <a href="#NWDCUvTi-19">D2</a>
+<li><a href="#NWDCUvTi-1A"><i>&lt;process <tt>yrange</tt> part&gt;</i></a>: <a href="#NWDCUvTi-17">U1</a>, <a href="#NWDCUvTi-1A">D2</a>
+<li><a href="#NWDCUvTi-5"><i>&lt;Process command line arguments&gt;</i></a>: <a href="#NWDCUvTi-4">U1</a>, <a href="#NWDCUvTi-5">D2</a>
+<li><a href="#NWDCUvTi-1J"><i>&lt;process coordinates&gt;</i></a>: <a href="#NWDCUvTi-1I">U1</a>, <a href="#NWDCUvTi-1J">D2</a>
+<li><a href="#NWDCUvTi-1a"><i>&lt;process coordinates part of text command&gt;</i></a>: <a href="#NWDCUvTi-1Z">U1</a>, <a href="#NWDCUvTi-1a">D2</a>
+<li><a href="#NWDCUvTi-7"><i>&lt;process file&gt;</i></a>: <a href="#NWDCUvTi-2">U1</a>, <a href="#NWDCUvTi-7">D2</a>
+<li><a href="#NWDCUvTi-r"><i>&lt;process input line&gt;</i></a>: <a href="#NWDCUvTi-q">U1</a>, <a href="#NWDCUvTi-r">D2</a>
+<li><a href="#NWDCUvTi-1b"><i>&lt;process optional part of text command&gt;</i></a>: <a href="#NWDCUvTi-1Z">U1</a>, <a href="#NWDCUvTi-1b">D2</a>
+<li><a href="#NWDCUvTi-1V"><i>&lt;process optional point shape part&gt;</i></a>: <a href="#NWDCUvTi-1I">U1</a>, <a href="#NWDCUvTi-1V">D2</a>
+<li><a href="#NWDCUvTi-W"><i>&lt;subroutine <tt>Angle</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-W">D2</a>
+<li><a href="#NWDCUvTi-K"><i>&lt;subroutine <tt>chk_comma</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-K">D2</a>
+<li><a href="#NWDCUvTi-L"><i>&lt;subroutine <tt>chk_comment</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-L">D2</a>
+<li><a href="#NWDCUvTi-G"><i>&lt;subroutine <tt>chk_lcb</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-G">D2</a>
+<li><a href="#NWDCUvTi-E"><i>&lt;subroutine <tt>chk_lparen</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-E">D2</a>
+<li><a href="#NWDCUvTi-I"><i>&lt;subroutine <tt>chk_lsb</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-I">D2</a>
+<li><a href="#NWDCUvTi-H"><i>&lt;subroutine <tt>chk_rcb</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-H">D2</a>
+<li><a href="#NWDCUvTi-F"><i>&lt;subroutine <tt>chk_rparen</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-F">D2</a>
+<li><a href="#NWDCUvTi-J"><i>&lt;subroutine <tt>chk_rsb</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-J">D2</a>
+<li><a href="#NWDCUvTi-S"><i>&lt;subroutine <tt>circumCircleCenter</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-S">D2</a>
+<li><a href="#NWDCUvTi-T"><i>&lt;subroutine <tt>ComputeDist</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-T">D2</a>
+<li><a href="#NWDCUvTi-d"><i>&lt;subroutine <tt>drawAngleArc</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-d">D2</a>
+<li><a href="#NWDCUvTi-e"><i>&lt;subroutine <tt>drawAngleArrow</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-e">D2</a>
+<li><a href="#NWDCUvTi-Z"><i>&lt;subroutine <tt>drawarrows</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-Z">D2</a>
+<li><a href="#NWDCUvTi-b"><i>&lt;subroutine <tt>drawCurve</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-b">D2</a>
+<li><a href="#NWDCUvTi-Y"><i>&lt;subroutine <tt>DrawLineOrArrow</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-Y">D2</a>
+<li><a href="#NWDCUvTi-a"><i>&lt;subroutine <tt>drawlines</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-a">D2</a>
+<li><a href="#NWDCUvTi-c"><i>&lt;subroutine <tt>drawpoints</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-c">D2</a>
+<li><a href="#NWDCUvTi-m"><i>&lt;subroutine <tt>drawsquare</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-m">D2</a>
+<li><a href="#NWDCUvTi-X"><i>&lt;subroutine <tt>excircle</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-X">D2</a>
+<li><a href="#NWDCUvTi-f"><i>&lt;subroutine <tt>expr</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-f">D2</a>
+<li><a href="#NWDCUvTi-N"><i>&lt;subroutine <tt>get_point</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-N">D2</a>
+<li><a href="#NWDCUvTi-j"><i>&lt;subroutine <tt>get_string</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-j">D2</a>
+<li><a href="#NWDCUvTi-V"><i>&lt;subroutine <tt>IncircleCenter</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-V">D2</a>
+<li><a href="#NWDCUvTi-U"><i>&lt;subroutine <tt>intersection4points</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-U">D2</a>
+<li><a href="#NWDCUvTi-k"><i>&lt;subroutine <tt>is_tainted</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-k">D2</a>
+<li><a href="#NWDCUvTi-P"><i>&lt;subroutine <tt>Length</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-P">D2</a>
+<li><a href="#NWDCUvTi-g"><i>&lt;subroutine <tt>memberOf</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-g">D2</a>
+<li><a href="#NWDCUvTi-h"><i>&lt;subroutine <tt>midpoint</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-h">D2</a>
+<li><a href="#NWDCUvTi-A"><i>&lt;subroutine <tt>mpp</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-A">D2</a>
+<li><a href="#NWDCUvTi-l"><i>&lt;subroutine <tt>noOfDigits</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-l">D2</a>
+<li><a href="#NWDCUvTi-O"><i>&lt;subroutine <tt>perpendicular</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-O">D2</a>
+<li><a href="#NWDCUvTi-R"><i>&lt;subroutine <tt>pointOnLine</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-R">D2</a>
+<li><a href="#NWDCUvTi-M"><i>&lt;subroutine <tt>print_headers</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-M">D2</a>
+<li><a href="#NWDCUvTi-B"><i>&lt;subroutine <tt>PrintErrorMessage</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-B">D2</a>
+<li><a href="#NWDCUvTi-D"><i>&lt;subroutine <tt>PrintFatalError</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-D">D2</a>
+<li><a href="#NWDCUvTi-C"><i>&lt;subroutine <tt>PrintWarningMessage</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-C">D2</a>
+<li><a href="#NWDCUvTi-q"><i>&lt;subroutine <tt>process_input</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-q">D2</a>
+<li><a href="#NWDCUvTi-p"><i>&lt;subroutine <tt>setLineThickness</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-p">D2</a>
+<li><a href="#NWDCUvTi-o"><i>&lt;subroutine <tt>sp2X</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-o">D2</a>
+<li><a href="#NWDCUvTi-i"><i>&lt;subroutine <tt>tand</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-i">D2</a>
+<li><a href="#NWDCUvTi-Q"><i>&lt;subroutine <tt>triangleArea</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-Q">D2</a>
+<li><a href="#NWDCUvTi-n"><i>&lt;subroutine <tt>X2sp</tt> &gt;</i></a>: <a href="#NWDCUvTi-9">U1</a>, <a href="#NWDCUvTi-n">D2</a>
+<li><a href="#NWDCUvTi-9"><i>&lt;subroutine definitions&gt;</i></a>: <a href="#NWDCUvTi-2">U1</a>, <a href="#NWDCUvTi-9">D2</a>
+</ul>
+</body></html>
+
diff --git a/graphics/mathspic/perl/sourcecode113.nw b/graphics/mathspic/perl/sourcecode113.nw
new file mode 100644
index 0000000000..00d7ae8e14
--- /dev/null
+++ b/graphics/mathspic/perl/sourcecode113.nw
@@ -0,0 +1,5021 @@
+<center><h1> <tt>mathspic</tt> in Perl </h1></center>
+<center><h2>
+<table>
+<tr><td><address>
+<b>Apostolos Syropoulos</b><br>
+366, 28th October Str.<br>
+GR-671 00 Xanthi<br>
+Greece<br>
+email: <tt>asyropoulos@yahoo.com</tt>
+</address></td>
+<td><address>
+<b>R.W.D. Nickalls</b><br/>
+Consultant in Anaesthesia & Intensive Care (retired)<br/>
+c/o Department of Anaesthesia<br/>
+Nottingham University Hospitals<br/>
+City Hospital Campus<br/>
+Hucknall Road<br/>
+Nottingham NG5 1PB, UK<br/>
+email:<tt>dick@nickalls.org</tt>
+</address></td>
+</table></h2>
+version 1.13 Apr 26, 2010
+</center>
+
+@ <h3><b>Introduction</b></h3><p>
+<tt>mathspic</tt> is a graphics program which implements a simple
+programming notation, <i>mathspic</i>, suitable for the
+creation of diagrams or mathematical figures.
+<tt>mathspic</tt>'s input is a LaTeX file containing
+<tt>mathspic</tt> plotting commands.
+<tt>mathspic</tt>'s output is the equivalent LaTeX file
+containing PiCTeX plotting commands.
+Technically, therefore, <tt>mathspic</tt>
+is a preprocessor or `filter' for use with the PiCTeX drawing engine.
+<tt>mathspic</tt> was originally written in PowerBASIC 3.5, a
+DOS-based programming language. Since, many
+potential users are working in rather different programming environments,
+the authors thought of porting <tt>mathspic</tt> into another programming
+cross-platform language which would be widely available.
+The authors decided to rewrite <tt>mathspic</tt> in Perl
+since not only is Perl pretty stable, but it has
+extensive mathematical support.<p>
+
+<h3><b>Program Structure</b></h3><p>
+Initially, we define a little package that is used to implement the [[loop]]
+command. Then, we must do is to check the possible command line arguments.
+Next, we process the input file.
+If the user has used the [[-b]] (see below), the program will `beep'
+if any errors are found during processing.
+We need some auxiliary subroutines in order to properly parse the input
+file and of course to handle the various commands. We also need a
+few global variables.
+
+<<*>>=
+#!/usr/bin/perl
+#
+#(c) Copyright 2005-2010
+# Apostolos Syropoulos & R.W.D. Nickalls
+# asyropoulos@yahoo.com dick@nickalls.org
+#
+# This program can be redistributed and/or modified under the terms
+# of the LaTeX Project Public License Distributed from CTAN
+# archives in directory macros/latex/base/lppl.txt; either
+# version 1 of the License, or any later version.
+#
+<<package <tt>DummyFH</tt> >>
+package main;
+use Math::Trig;
+<<Define global variables>>
+<<subroutine definitions>>
+<<Check for command line arguments>>
+<<process file>>
+print $alarm if $no_errors > 0;
+__END__
+
+@ The package [[DummyFH]] is used in the implementation of the [[loop]] command.
+It creates a dummy filehandle that is associated with an array of strings. Since
+we only read data from this dummy filehandle, we implement the [[READLINE]] subroutine.
+When we read a line from this dummy filehandle, we actually requesting the next entry
+of the array (if any). That is why we use the package variable [[$index]]. When there
+are no more entries in the array, subroutine [[READLINE]] returns the value [[undef]]
+so to falsify loop that controls the consumption of input from this dummy filehandle.
+
+<<package <tt>DummyFH</tt> >>=
+package DummyFH;
+my $index = 0;
+sub TIEHANDLE {
+ my $class = shift;
+ my $self= shift;
+ bless $self, $class;
+}
+sub READLINE {
+ my $self = shift;
+ #shift @$self;
+ if ($index > $#$self) {
+ $index = 0;
+ return undef;
+ }
+ else {
+ return $self->[$index++];
+ }
+}
+
+@ <tt>mathspic</tt> accepts at most four command-line switches, namely
+<tt>-b</tt> for enabling the beep, <tt>-s</tt> for automatic
+screen viewing of the output-file,
+<tt>-c</tt> for cleaning out all comment-lines,
+and <tt>-o</tt> with a following file-name
+for specifying the output file-name.
+<tt>mathspic</tt> requires the name of an existing input-file
+(the so-called <tt>mathspic</tt>-file) containing
+<tt>mathspic</tt>commands.
+If no command-line arguments are supplied, we print a
+suitable usage message indicating the syntax.
+For each command-line argument we set a global
+variable. The default behavior is that the `bell' does not beep
+and comment-lines are not removed from the output-file.
+
+<<Check for command line arguments>>=
+our $alarm="";
+our $comments_on=1;
+our $out_file="default";
+our $argc=@ARGV;
+if ($argc == 0 || $argc > 5 ){ # no command line arguments or more than 4
+ # arguments
+ die "\nmathspic version $version_number\n" .
+ "Usage: mathspic [-h] [-b] [-c] [-o <out file>] <in file>\n\n";
+}
+else {
+ <<Process command line arguments>>
+ print "This is mathspic version $version_number\n";
+}
+<<Check if .m file exists>>
+
+@ In order to get the various command-line arguments we use a simple
+[[while]] loop that checks each element of the array [[@ARGV]]. We check
+for all the switches, and we get the name of the input-file.
+
+<<Process command line arguments>>=
+ our $file = "";
+ SWITCHES:
+ while($_ = $ARGV[0]) {
+ shift;
+ if (/^-h$/) {
+ die "\nThis is mathspic version $version_number\n" .
+ "Type \"man mathspic\" for detailed help\n".
+ "Usage:\tmathspic [-h] [-b] [-c] [-o <out file>] <in file>\n" .
+ "\twhere,\n" .
+ "\t[-b]\tenables bell sound if error exists\n" .
+ "\t[-c]\tdisables comments in ouput file\n" .
+ "\t[-h]\tgives this help listing\n" .
+ "\t[-o]\tcreates specified output file\n\n";
+ }
+ elsif (/^-b$/) {
+ $alarm = chr(7);
+ }
+ elsif (/^-c$/) {
+ $comments_on = 0;
+ }
+ elsif (/^-o$/) {
+ die "No output file specified!\n" if !@ARGV;
+ $out_file = $ARGV[0];
+ shift;
+ }
+ elsif (/^-\w+/) {
+ die "$_: Illegal command line switch!\n";
+ }
+ else {
+ $file = $_;
+ }
+ }my ($xA, $yA, $xB, $yB, $dist)=@_;
+ die "No input file specified!\n" if $file eq "";
+
+@ In order to check whether the input-file exists, we simply use the
+[[-e]] operator. First we check to see if [[$file]] exits.
+If the input-file does exist then the variable [[$file]] contains
+the file name. In case the user has not specified an output
+file, the default output file name is the name of the input file with
+extension [[.mt]]. Finally, the program outputs all error messages to
+the screen and to a log file. The name of the log file consists of
+the contents of the variable [[$file]] and the extension [[.mlg]].
+
+<<Check if .m file exists>>=
+ our ($source_file, $log_file);
+ if (! -e $file) {
+ die "$file: no such file!\n" if (! (-e "$file.m"));
+ $source_file = "$file.m";
+ }
+ else {
+ $source_file = $file;
+ $file = $1 if $file =~ /(\w[\w-\.]+)\.\w+/;
+ }
+ $out_file= "$file.mt" if $out_file eq "default";
+ $log_file= "$file.mlg";
+
+@ Now that we have all the command line arguments, we can start processing
+the input file. This is done by calling the subroutine [[process_input]].
+Before that we must open all necessary files. Next,
+we print some `header' information to the output file and to the log file.
+
+<<process file>>=
+ open(IN,"$source_file")||die "Can't open source file: $source_file\n";
+ open(OUT,">$out_file")||die "Can't open output file: $out_file\n";
+ open(LOG,">$log_file")||die "Can't open log file: $log_file\n";
+ print_headers;
+ process_input(IN,"");
+
+@ In this section we define a few global variables. More specifically:
+the variable [[$version_number]] contains the current version number of the
+program, the variable [[$commandLineArgs]] contains the command line arguments.
+These two variables are used in the [[print_headers]] subroutine.
+The variable [[$command]] will contain the whole current input line.
+Hash [[%PointTable]] is used to store point names and related
+information. Hash [[%VarTable]] is used to store mathspic variable names
+and related information, while the associative array [[%ConstTable]] contains the
+names of constants. Note that the values of both constants and variables are
+kept in [[%VarTable]].
+The variable [[$no_errors]] is incremented whenever the
+program encounters an error in the input file. The variables [[$xunits]],
+[[$yunits]] and [[$units]] are related to the [[paper]] command.
+In particular, the variable [[$units]] is used to parse the unit part of the
+[[unit]] part of the [[paper]] command. The variable [[$defaultsymbol]] is used to
+set the point shape. The constant [[PI]] holds the value of the mathematical
+ constant pi.
+The constant [[R2D]] holds the transformation factor to transform radians to
+degrees. The constant [[D2R]] holds the transformation factor
+to transform degrees to radians, i.e., the value [[1/R2D]]. The global variables
+[[$arrowLength]], [[$arrowAngleB]] and [[$arrowAngleC]] are actually parameters that
+are used by the subroutines that draw arrows. Since [[$arrowLength]] is actually
+a length, variable [[$arrowLenghtUnits]] holds the units of measure in which
+this length is expressed. The hash table [[%DimOfPoint]] contains the side or the
+radius of a point whose plot-symbol is a square or a circle, respectively. In case the
+default point symbol is a circle or a square, variable [[$GlobalDimOfPoints]] is used
+to store the length of the radius or the length of the side of default point symbol,
+respectively. Variable [[$LineThickness]] holds the current line thickness (the
+default value is 0.4&nbsp;pt).
+
+<<Define global variables>>=
+our $version_number = "1.13 Apr 26, 2010";
+our $commandLineArgs = join(" ", @ARGV);
+our $command = "";
+our $curr_in_file = "";
+our %PointTable = ();
+our %VarTable = ();
+our %ConstTable = ();
+our $no_errors = 0;
+our $xunits = "1pt";
+our $yunits = "1pt";
+our $units = "pt|pc|in|bp|cm|mm|dd|cc|sp";
+our $defaultsymbol = "\$\\bullet\$";
+our $defaultLFradius = 0;
+use constant PI => atan2(1,1)*4;
+use constant R2D => 180 / PI;
+use constant D2R => PI / 180;
+our $arrowLength = 2;
+our $arrowLengthUnits = "mm";
+our $arrowAngleB = 30;
+our $arrowAngleC = 40;
+our %DimOfPoint = ();
+our $GlobalDimOfPoints = 0;
+our @Macros = ();
+our $LineThickness = 0.4;
+
+@ In this section we define the various subroutines that are needed in order
+to process the input file.
+
+<p> Subroutine <tt>mpp</tt> is a mathspic preprocessor that allows the definition
+and use of macros with or without arguments. For the moment it is an experimental
+feature and it should be used with care.
+
+<p> Subroutine <tt>PrintErrorMessage</tt> is used to print error messages
+to the screen, to the output file and to the log file.
+
+<p> Subroutine <tt>PrintWarningMessage</tt> is used to print warning messages
+to the screen, to the output file and to the log file.
+
+<p> Subroutine <tt>PrintFatalError</tt> is used to print an error message
+to the screen and to abort execution, where the error is considered fatal
+and not recoverable.
+
+<p>Subroutine <tt>chk_lparen</tt> checks whether the next input
+character is a left parenthesis. Subroutine <tt>chk_rparen</tt>
+checks whether the next input character is a right parenthesis. Subroutine
+<tt>chk_comment</tt> checks whether a given command is followed by a trailing
+comment. In the same spirit, we define the subroutines <tt>chk_lcb</tt>,
+<tt>chk_rcb</tt>, <tt>chk_lsb</tt>, and <tt>chk_rsb</tt> which check for
+opening and closing curly and square brackets respectively.
+The subroutine [[chk_comma]] checks whether the next token is a comma.
+
+<p> Subroutine [[print_headers]] is used to print a header to the output file,
+so a user knows that the file has been generated by <tt>mathspic</tt>.
+
+<p> Subroutine [[get_point]] is used to parse a point name and to
+check whether the point exists (i.e whether the point has been defined).
+
+<p> Subroutine [[perpendicular]] is used to compute the coordinates of the
+foot of perpendicular line from some point P to a line AB.
+
+<p> Subroutine [[Length]] is used to compute the distance between two
+points A and B.
+
+<p> Subroutine [[triangleArea]] computes the area of a triangle defined
+by three points.
+
+<p> Subroutine [[PointOnLine]] is used to compute the coordinates of
+a point on a line segment AB and a distance d units from A towards B.
+
+<p> Subroutine [[circumCircleCenter]] takes six arguments that are the
+coordinates of three points and computes the center of the circle that
+passes through the three points which define the triangle.
+
+<p> Subroutine [[ComputeDist]] is used to compute a numeric value that is
+specified by either a variable name, a pair of points, or just a number.
+
+<p> Subroutine [[intersection4points]] is used to compute the coordinates
+of the point of intersection of two lines specified by the four arguments
+(i.e. two arguments for each point).
+
+<p> Subroutine [[IncircleCenter]] is used to compute the center and
+the radius of a circle that touches internally the sides of a triangle,
+the coordinates of the three points which define the triangle
+being the arguments of the subroutine.
+
+<p> Subroutine [[Angle]] determines the opening in degrees of an angle
+defined by three points which are the arguments of this subroutine.
+
+<p> Subroutine [[excircle]] computes the center and the radius of
+a circle that externally touches a given side (4th and 5th arguments) of
+triangle (determined by the 1st, the 2nd and the 3rd argument).
+
+<p> Subroutine [[DrawLineOrArrow]] is used to parse the arguments of the commands
+ [[drawline]], [[drawthickline]], [[drawarrow]], [[drawthickarrow]] and
+ [[drawCurve]].
+
+<p> Subroutine [[drawarrows]] is used to draw one or more arrows between points.
+
+<p> Subroutine [[drawlines]] is used to draw one or more lines between points.
+
+<p> Subroutine [[drawCurve]] is used to draw a curve between an odd number of points.
+
+<p> Subroutine [[drawpoints]] is used to draw the point symbol of one or more points.
+
+<p> Subroutine [[drawAngleArc]] is used to draw an arc line within an angle.
+
+<p> Subroutine [[drawAngleArrow]] is used to draw an arc line with an arrow on the end,
+within an angle.
+
+<p> Subroutine [[expr]] and subroutines [[term]], [[factor]] and
+[[primitive]] are used to parse an expression that follows a variable
+declaration.
+
+<p> Subroutine [[memberOf]] is used to determine whether a string is a
+member of a list of strings.
+
+<p> Subroutine [[midpoint]] computes the midpoint of two points.
+
+<p> Subroutine [[tand]] computes the tangent of an angle, where the
+angle is expressed in degrees.
+
+<p> Subroutine [[get_string]] scans a string in order to extract a
+valid mathspic string.
+
+<p> Subroutine [[is_tainted]] checks whether a string contains data that
+may be proved harmful if used as arguments to a shell escape.
+
+<p> Subroutine [[noOfDigits]] has one argument which is a number and
+returns the number of decimal digits it has.
+
+<p> Subroutine [[drawsquare]] has one argument which is the radius of point
+and yields LaTeX code that draws a square.
+
+<p> Subroutine [[X2sp]] can be used to transform a length to sp units.
+
+<p> Subroutine [[sp2X]] can be used to transform a length expressed in sp units
+ to any other acceptable unit.
+
+<p> Subroutine [[setLineThickness]] is used to determine the length of the
+ linethickness in the current paper units.
+
+<p> Subroutine [[process_input]] parses the input file and any other file
+ being included in the main file, and generates output.
+
+<<subroutine definitions>>=
+ <<subroutine <tt>mpp</tt> >>
+ <<subroutine <tt>PrintErrorMessage</tt> >>
+ <<subroutine <tt>PrintWarningMessage</tt> >>
+ <<subroutine <tt>PrintFatalError</tt> >>
+ <<subroutine <tt>chk_lparen</tt> >>
+ <<subroutine <tt>chk_rparen</tt> >>
+ <<subroutine <tt>chk_lcb</tt> >>
+ <<subroutine <tt>chk_rcb</tt> >>
+ <<subroutine <tt>chk_lsb</tt> >>
+ <<subroutine <tt>chk_rsb</tt> >>
+ <<subroutine <tt>chk_comma</tt> >>
+ <<subroutine <tt>chk_comment</tt> >>
+ <<subroutine <tt>print_headers</tt> >>
+ <<subroutine <tt>get_point</tt> >>
+ <<subroutine <tt>perpendicular</tt> >>
+ <<subroutine <tt>Length</tt> >>
+ <<subroutine <tt>triangleArea</tt> >>
+ <<subroutine <tt>pointOnLine</tt> >>
+ <<subroutine <tt>circumCircleCenter</tt> >>
+ <<subroutine <tt>ComputeDist</tt> >>
+ <<subroutine <tt>intersection4points</tt> >>
+ <<subroutine <tt>IncircleCenter</tt> >>
+ <<subroutine <tt>Angle</tt> >>
+ <<subroutine <tt>excircle</tt> >>
+ <<subroutine <tt>DrawLineOrArrow</tt> >>
+ <<subroutine <tt>drawarrows</tt> >>
+ <<subroutine <tt>drawlines</tt> >>
+ <<subroutine <tt>drawCurve</tt> >>
+ <<subroutine <tt>drawpoints</tt> >>
+ <<subroutine <tt>drawAngleArc</tt> >>
+ <<subroutine <tt>drawAngleArrow</tt> >>
+ <<subroutine <tt>expr</tt> >>
+ <<subroutine <tt>memberOf</tt> >>
+ <<subroutine <tt>midpoint</tt> >>
+ <<subroutine <tt>tand</tt> >>
+ <<subroutine <tt>get_string</tt> >>
+ <<subroutine <tt>is_tainted</tt> >>
+ <<subroutine <tt>noOfDigits</tt> >>
+ <<subroutine <tt>drawsquare</tt> >>
+ <<subroutine <tt>X2sp</tt> >>
+ <<subroutine <tt>sp2X</tt> >>
+ <<subroutine <tt>setLineThickness</tt> >>
+ <<subroutine <tt>process_input</tt> >>
+
+@ Subroutine <tt>mpp</tt> is an implementation of a mathspic preprocessor that allows
+the definition of one-line macros with or without arguments. Macro definition has the
+following syntax:
+<center>
+ <tt>"%def" macro_name "(" [ parameters ] ")" macro_code
+</center>
+where parameters is a list of comma separated strings (e.g., x,y,z). Once a macro is
+defined it can be used or it can be undefined. To undefine a macro one has to use
+the following command:
+<center>
+ <tt>"%undef" [ macro_name ]
+</center
+This means that an undef command without an accompanying macro name has no effect
+at all. In order to use a macro we simply type its name and its arguments in
+parentheses. Note that macro arguments should not contain spaces. If a macro has no
+argument, there is no need to type any parentheses. We will now describe briefly how
+the macro processor operates.
+<p> If the current input line starts with <tt>%def</tt>, then we assume that we have
+a macro definition. We parse each component of the macro definition and finally we
+store the macro name, the macro code and the macro parameters (if any) in an anonymous
+hash that eventually becomes part of an array. If we encounter any error, we simply
+skip to the next line after printing a suitable error message. Now, if the first tokens
+of an input line are <tt>%undef</tt>, we assume the user wants to delete a macro.
+In case these tokens are not followed by a macro name or the macro name has not been
+defined we simply go on. Otherwise, we delete the corresponding macro data from the
+global array [[@Macros]] that contains all the macro information. Macro expansion is
+more difficult and it will be described in detail in a separate document. At this point
+we would like to thank Joachim Schneider <joachim at hal dot rhein-necker dot de>
+for a suggestion on improving macro expansion.
+
+<<subroutine <tt>mpp</tt> >>=
+sub mpp {
+ my $in_line;
+ chomp($in_line = shift);
+ my $LC = shift;
+ my $out_line = $in_line;
+ my $macro_name = "";
+ my @macro_param = ();
+ my $macro_code = "";
+ if ($in_line =~ s/^%def\s*//) {
+ if ($in_line =~ s/^(\w+)\s*//){
+ $macro_name = $1;
+ }
+ else {
+ PrintErrorMessage("No macro name has been found",$LC);
+ return ""
+ }
+ if ($in_line =~ s/^\(\s*//) {
+ # do nothing
+ }
+ else {
+ PrintErrorMessage("No left parenthesis after macro name has been found",$LC);
+ return "";
+ }
+ if ($in_line =~ s/^\)//) {
+ # Macro has no parameters!
+ }
+ else {
+ MACROS: while (1) {
+ if ($in_line =~ s/^(\w+)\s*//) {
+ push (@macro_param, $1);
+ }
+ else {
+ PrintErrorMessage("No macro parameter name has been found",$LC);
+ return "";
+ }
+ if ($in_line =~ s/^,\s*//) {
+ next MACROS;
+ }
+ else {
+ last MACROS;
+ }
+ }
+ if ($in_line =~ s/^\)//) {
+ # do nothing!
+ }
+ else {
+ PrintErrorMessage("No closing parenthesis after macro parameters",$LC);
+ return "";
+ }
+ }
+ $in_line =~ s/([^%]+)(%.*)/$1/;
+ $macro_code = $in_line;
+ push ( @Macros , { 'macro_name' => $macro_name,
+ 'macro_code' => $macro_code,
+ 'macro_param' => \@macro_param });
+ return $out_line;
+ }
+ elsif ($in_line =~ s/^%undef\s*//) {
+ if ($in_line =~ s/^(\w+)//) {
+ my $undef_macro = $1;
+ for(my $i = $#Macros; $i >= 0; $i--) {
+ if ($Macros[$i]->{'macro_name'} eq $undef_macro) {
+ splice(@Macros,$i,1);
+ }
+ }
+ }
+ return $out_line;
+ }
+ elsif ($in_line =~ s/^\s*%//) {
+ return $out_line;
+ }
+ else {
+ my $comment = $2 if $in_line =~ s/([^%]+)(%.+)/$1/;
+ EXPANSIONLOOP: while () {
+ my $org_in_line = $in_line;
+ for(my $i = $#Macros; $i >= 0; $i--) {
+ my $macro_name = $Macros[$i]->{'macro_name'};
+ if ($in_line =~ /&$macro_name\b/) { ############################
+ my $num_of_macro_args = @{$Macros[$i]->{'macro_param'}};
+ if ( $num_of_macro_args > 0 ) {
+ # Macro with parameters
+ my $pattern = "&$macro_name\\(";
+ foreach my $p ( 1..$num_of_macro_args ) {
+ my $comma = ($p == $num_of_macro_args) ? "\\s*" : "\\s*,\\s*";
+ $pattern .= "\\s*[^\\s\\)]+$comma";
+ }
+ $pattern .= "\\)";
+ while($in_line =~ /&$macro_name\b/) {
+ if ($in_line =~ /$pattern/) {
+ my $before = $`;
+ my $after = $';
+ my $match = $&;
+ my $new_code = $Macros[$i]->{'macro_code'};
+ $match =~ s/^&$macro_name\(\s*//;
+ $match =~ s/\)$//;
+ foreach my $arg ( 0..($num_of_macro_args - 1) ) {
+ my $old = $Macros[$i]->{'macro_param'}->[$arg];
+ my $comma = ($arg == ($num_of_macro_args - 1)) ? "" : ",";
+ $match =~ s/^\s*([^\s,]+)\s*$comma//;
+ my $new = $1;
+ # 'g': Parameter may occur several times
+ # in $new_code.
+ # '\b': Substitute only whole words
+ # not x in xA
+ $new_code =~ s/\b$old\b/$new/g;
+ }
+ $in_line = "$before$new_code$after";
+ }
+ else {
+ PrintErrorMessage("Usage of macro &$macro_name does not " .
+ "match its definition", $LC);
+ return "";
+ }
+ }
+ }
+ else {
+ # Macro without parameters
+ my $replacement = $Macros[$i]->{'macro_code'};
+ # '\b': Substitute only whole words
+ # not x in xA
+ $in_line =~ s/&$macro_name\b/$replacement/g;
+ }
+ }
+ }
+ last EXPANSIONLOOP if ( $org_in_line eq $in_line );
+ }
+ return "$in_line$comment";
+ }
+}
+
+@ Subroutine <tt>PrintErrorMessage</tt> has two parameters: the
+error message that will be printed on the screen, the log file and
+the output file, and the line number of the line containing the
+error was detected.
+The general form of the error message is the following:
+<pre>
+line X: paper{units(
+ ,mm)xrange(0,20)yrange(0,30)axes(B)ticks(10,10)}
+
+***Error: Error_Message
+</pre>
+where [[X]] denotes the line number and [[Error_Message]] is the
+actual error message. Note, that we print the tokens processed so far
+and on the text line the unprocessed tokens, so that the user knows
+exactly where the error is. In the variable [[$A]] we store the processed
+tokens, while the variable [[$l]] holds the length of [[$A]] plus the
+length of the [[$error_line]] (that is the number of the input line where
+the error occurred) plus 7, i.e., 4 (the length of the word
+[[line]]) plus 2 (the two blank spaces) plus 1 (the symbol [[:]]).
+Finally, we increment the error counter (variable [[$no_errors]]). Note, that
+in case the user has specified the [[-c]] command line switch, we will not
+print any messages to the output file.
+
+<<subroutine <tt>PrintErrorMessage</tt> >>=
+ sub PrintErrorMessage {
+ my $errormessage = shift;
+ my $error_line = shift;
+ my ($l,$A);
+ $l = 1+length($command)-length;
+ $A = substr($command,0,$l);
+ $l += 7 +length($error_line);
+
+ for my $fh (STDOUT, LOG) {
+ print $fh "$curr_in_file", "Line $error_line: $A\n";
+ print $fh " " x $l ,$_,"***Error: $errormessage\n";
+ }
+ if ($comments_on) { #print to output file file
+ print OUT "%% *** $curr_in_file", "Line $error_line: $A\n";
+ print OUT "%% *** "," " x $l ,$_,"%% ... Error: $errormessage\n";
+ }
+ $no_errors++;
+ }
+
+@ Subroutine <tt>PrintWarningMessage</tt> behaves exactly like the subroutine
+<tt>PrintErrorMessage</tt>. The only difference is that the second
+subroutine prints only a warning message. A warning is issued when
+the system detects parameters that do nothing.
+
+<<subroutine <tt>PrintWarningMessage</tt> >>=
+ sub PrintWarningMessage {
+ my $warningMessage = shift;
+ my $warning_line = shift;
+ my ($l,$A);
+ $l = 1+length($command)-length;
+ $A = substr($command,0,$l);
+ $l += 7 +length($warning_line);
+
+ for my $fh (STDOUT, LOG) {
+ print $fh "$curr_in_file", "Line $warning_line: $A\n";
+ print $fh " " x $l ,$_,"***Warning: $warningMessage\n";
+ }
+ if ($comments_on) { #print to output file file
+ print OUT "%% *** $curr_in_file", "Line $warning_line: $A\n";
+ print OUT "%% *** "," " x $l ,$_,"%% ... Warning: $warningMessage\n";
+ }
+ }
+
+@ The subroutine <tt>PrintFatalError</tt> behaves similarly to the subroutine
+<tt>PrintErrorMessage</tt>. It prints an error message to the
+screen and aborts execution.
+
+<<subroutine <tt>PrintFatalError</tt> >>=
+ sub PrintFatalError {
+ my $FatalMessage = shift;
+ my $fatal_line = shift;
+ my ($l,$A);
+ $l = 1+length($command)-length;
+ $A = substr($command,0,$l);
+ $l += 7 +length($fatal_line);
+
+ die "$curr_in_file", "Line $fatal_line: $A\n" .
+ (" " x $l) . $_ . "***Fatal Error: $FatalMessage\n";
+ }
+
+@ The subroutine <tt>chk_lparen</tt> accepts two arguments: the name
+of the token that should be immediately before the left parenthesis (variable
+[[$token]]), and the current line number (variable [[$lc]]). First we
+skip any leading white space and then check whether the next
+input character is a left parenthesis, then the subroutine skips any
+trailing white space; otherwise it prints an error message.
+
+<<subroutine <tt>chk_lparen</tt> >>=
+sub chk_lparen {
+ my $token = $_[0];
+ my $lc = $_[1];
+ s/\s*//;
+ if (/^[^\(]/) {
+ PrintErrorMessage("Missing ( after $token",$lc);
+ }
+ else {
+ s/^\(\s*//;
+ }
+}
+
+@ The subroutine <tt>chk_rparen</tt> accepts two parameters: the name
+of the token that should be immediately after a right parenthesis (variable
+[[$token]]), and the current line number (variable [[$lc]]). Initially, we
+skip any leading white space and then we check whether the next input
+token is a right parenthesis. If it is not we issue a error message and
+return, otherwise we skip the parenthesis and any trailing white space.
+
+<<subroutine <tt>chk_rparen</tt> >>=
+sub chk_rparen {
+ my $token = $_[0];
+ my $lc = $_[1];
+ s/\s*//;
+ if (s/^\)//) {
+ s/\s*//;
+ }
+ else {
+ PrintErrorMessage("Missing ) after $token",$lc);
+ }
+}
+
+
+@ The subroutine <tt>chk_lcb</tt> behaves in a similar way to the subroutine
+<tt>chk_lparen</tt>.
+
+<<subroutine <tt>chk_lcb</tt> >>=
+sub chk_lcb {
+ my $token = $_[0];
+ my $lc = $_[1];
+ s/\s*//;
+ if ($_ !~ /^\{/) {
+ PrintErrorMessage("Missing { after $token",$lc);
+ }
+ else {
+ s/^{\s*//;
+ }
+}
+
+@ Subroutine <tt>chk_rcb</tt> behaves in a similar way to the subroutine
+<tt>chk_rparen</tt>.
+
+<<subroutine <tt>chk_rcb</tt> >>=
+sub chk_rcb {
+ my $token = $_[0];
+ my $lc = $_[1];
+ if ($_ !~ /^\s*\}/) {
+ PrintErrorMessage("Missing } after $token",$lc);
+ }
+ else {
+ s/^\s*}\s*//;
+ }
+}
+
+@ Subroutine <tt>chk_lsb</tt> behaves in a similar way to the subroutine
+<tt>chk_lparen</tt>.
+
+<<subroutine <tt>chk_lsb</tt> >>=
+sub chk_lsb {
+ my $token = $_[0];
+ my $lc = $_[1];
+
+ s/\s*//;
+ if ($_ !~ /^\[/) {
+ PrintErrorMessage("Missing [ after $token",$lc);
+ }
+ else {
+ s/^\[\s*//;
+ }
+}
+
+@ Subroutine <tt>chk_rsb</tt> behaves in a similar way to the subroutine
+<tt>chk_rparen</tt>.
+
+<<subroutine <tt>chk_rsb</tt> >>=
+sub chk_rsb {
+ my $token = $_[0];
+ my $lc = $_[1];
+
+ s/\s*//;
+ if ($_ !~ /^\]/) {
+ PrintErrorMessage("Missing ] after $token",$lc);
+ }
+ else {
+ s/^\]\s*//;
+ }
+}
+
+@ The subroutine [[chk_comma]] checks whether the next token is a comma.
+If it is not then it prints an error message, otherwise it consumes the
+comma and any white space that follows the comma.
+
+<<subroutine <tt>chk_comma</tt> >>=
+sub chk_comma {
+ my $lc = $_[0];
+
+ s/\s*//;
+ if (/^[^,]/) {
+ PrintErrorMessage("Did not find expected comma",$lc);
+ }
+ else {
+ s/^,\s*//;
+ }
+}
+
+@ The subroutine [[chk_comment]] has only one parameter which is the current
+line number. It checks whether the next input character is a comment
+character and in this case it does nothing!. Otherwise, if there is some trailing text
+it simply prints a warning to the screen.
+
+<<subroutine <tt>chk_comment</tt> >>=
+sub chk_comment {
+ my $lc = $_[0];
+
+ s/\s*//;
+ if (/^%/) {
+ # do nothing!
+ }
+ elsif (/^[^%]/) {
+ PrintWarningMessage("Trailing text is ignored",$lc);
+ }
+}
+
+@ The subroutine [[print_headers]] prints a header to the output file, as
+well as a header to the LOG file.
+The header contains information regarding the version of the
+program, a copyright notice, the command line, date and time information,
+and the names of the various files processed/generated.
+
+<<subroutine <tt>print_headers</tt> >>=
+ sub print_headers
+ {
+ my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
+ $year+=1900;
+ $mon+=1;
+ $now_string = "$year/" . ($mon>9 ? "$mon/" : "0$mon/") .
+ ($mday>9 ? "$mday " : "0$mday ") .
+ ($hour>9 ? "$hour:" : "0$hour:") .
+ ($min>9 ? "$min:" : "0$min:") .
+ ($sec>9 ? "$sec" : "0$sec");
+ print OUT "%* -----------------------------------------------\n";
+ print OUT "%* mathspic (Perl version $version_number)\n";
+ print OUT "%* A filter program for use with PiCTeX\n";
+ print OUT "%* Copyright (c) 2005-2010 A Syropoulos & RWD Nickalls \n";
+ print OUT "%* Command line: $0 $commandLineArgs\n";
+ print OUT "%* Input filename : $source_file\n";
+ print OUT "%* Output filename: $out_file\n";
+ print OUT "%* Date & time: $now_string\n";
+ print OUT "%* -----------------------------------------------\n";
+ #
+ print LOG "----\n";
+ print LOG "$now_string\n";
+ print LOG "mathspic (Perl version $version_number)\n";
+ print LOG "Copyright (c) 2005-2010 A Syropoulos & RWD Nickalls \n";
+ print LOG "Input file = $source_file\n";
+ print LOG "Output file = $out_file\n";
+ print LOG "Log file = $log_file\n";
+ print LOG "----\n";
+ }
+
+@ The subroutine [[get_point]] parses an individual point name.
+If the next token is also a point name then it returns the point name
+ (but only if the only if
+the point name exists in the PointTable). In all other cases it returns
+the string [[_undef_]] to indicate that something is wrong.
+
+<<subroutine <tt>get_point</tt> >>=
+ sub get_point {
+
+ my ($lc) = $_[0];
+ my ($PointName);
+
+ if (s/^([^\W\d_]\d{0,4})\s*//i) { #point name
+ $PointName = $1;
+ if (!exists($PointTable{lc($PointName)})) {
+ PrintErrorMessage("Undefined point $PointName",$lc);
+ return "_undef_";
+ }
+ else {
+ return lc($PointName);
+ }
+ }
+ else {
+ PrintErrorMessage("Point name expected",$lc);
+ return "_undef_";
+ }
+ }
+
+@ The subroutine [[perpendicular]] has 6 parameters that correspond to the
+coordinates of some point P and to the coordinates of two points A and
+B that define a line. The subroutine returns
+a pair of numbers that correspond to the coordinates of a point that lies
+at the foot of the perpendicular to the line AB that passes through point P.
+The slope of line AB is m<sub>1</sub> and so its equation is
+y=m<sub>1</sub>x+c<sub>1</sub>. Similarly, the slope of the line PF is
+m<sub>2</sub>=-1/m<sub>1</sub> and its equation is
+y=m<sub>2</sub>x+c<sub>2</sub>. Since the line AB passes through A, then
+c<sub>1</sub>=y<sub>A</sub>-m<sub>1</sub>x<sub>A</sub>. Similarly, as P is
+on line PF, then c<sub>2</sub>=y<sub>P</sub>-m<sub>2</sub>x<sub>P</sub>.
+Now point F is on both lines, therefore
+y<sub>F</sub>=m<sub>2</sub>x<sub>F</sub>+c<sub>2</sub> and
+y<sub>F</sub>=m<sub>1</sub>x<sub>F</sub>+c<sub>1</sub>. Solving these
+equations for x<sub>F</sub> and y<sub>F</sub> gives:
+<center>
+x<sub>F</sub>=(c<sub>2</sub>-c<sub>1</sub>)/(m<sub>1</sub>-m<sub>2</sub>)<br>
+y<sub>F</sub>=(m<sub>1</sub>c<sub>2</sub>-m<sub>2</sub>c<sub>1</sub>)/
+(m<sub>1</sub>-m<sub>2</sub>)
+</center>
+
+<<subroutine <tt>perpendicular</tt> >>=
+ sub perpendicular {
+ my ($xP, $yP, $xA, $yA, $xB, $yB) = @_;
+ my ($xF, $yF, $deltax, $deltay, $m1, $m2, $c1, $c2, $factor);
+
+ $deltax = $xA - $xB;
+ return ($xA, $yP) if abs($deltax) < 0.0000001;
+ $deltay = $yA - $yB;
+ return ($xP, $yA) if abs($deltay) < 0.0000001;
+ $m1 = $deltay / $deltax;
+ eval { $m2 = (-1) / $m1;};
+ PrintFatalError("Division by zero",$lc) if $@;
+ $c1 = $yA - $m1 * $xA;
+ $c2 = $yP - $m2 * $xP;
+ eval { $factor = 1 / ($m1 - $m2)};
+ PrintFatalError("Division by zero",$lc) if $@;
+ return (($c2 - $c1) * $factor, ($m1 * $c2 - $m2 * $c1) * $factor);
+ }
+
+@ The subroutine [[Length]] computes the distance between two points A and B.
+Notice, that the name of the subroutine starts with a capital L, just
+to avoid conflict with the predefined Perl function. The subroutine
+requires four parameters which are the coordinates of the two points.
+
+<<subroutine <tt>Length</tt> >>=
+ sub Length {
+ my ($xA, $yA, $xB, $yB)=@_;
+ return sqrt(($xB - $xA)**2 + ($yB - $yA)**2);
+ }
+
+@ The subroutine [[triangleArea]] computes the area of a triangle by using
+Heron's formula, i.e., given a triangle ABC, we first compute
+s=(AB+BC+CA)/2 and then the area of the triangle is equal to the
+square root of s times (s-AB) times (s-BC) times (s-BA), where AB, BC, and CA
+are the lengths of the three sides of the triangle. The subroutine accepts 6
+parameters, which correspond to the coordinates of three points that define
+the triangle.
+
+<<subroutine <tt>triangleArea</tt> >>=
+ sub triangleArea {
+ my ($xA, $yA, $xB, $yB, $xC, $yC)=@_;
+ my ($lenAB, $lenBC, $lenCA, $s);
+
+ $lenAB = Length($xA,$yA,$xB,$yB);
+ $lenBC = Length($xB,$yB,$xC,$yC);
+ $lenCA = Length($xC,$yC,$xA,$yA);
+ $s = ($lenAB + $lenBC + $lenCA) / 2;
+ return sqrt($s * ($s - $lenAB)*($s - $lenBC)*($s - $lenCA));
+ }
+
+@ The subroutine [[poinOnLine]] accepts five arguments: the coordinates of two
+points and the decimal number which corresponds to the distance from the
+first point towards the second one. The way we compute the coordinates of
+the point is fairly simple.
+
+<<subroutine <tt>pointOnLine</tt> >>=
+ sub pointOnLine {
+ my ($xA, $yA, $xB, $yB, $dist)=@_;
+ my ($deltax, $deltay, $xPol, $yPol);
+
+ $deltax = $xB - $xA;
+ $deltay = $yB - $yA;
+ $xPol = $xA + ($dist * $deltax / &Length($xA,$yA,$xB,$yB));
+ $yPol = $yA + ($dist * $deltay / &Length($xA,$yA,$xB,$yB));
+ return ($xPol, $yPol);
+ }
+
+
+@ As we have mentioned above the subroutine [[circumCircleCenter]] takes six
+arguments that correspond to the coordinates of three points that
+define a triangle. The subroutine computes the coordinates of
+the center of a circle that passes through these three points, and the radius of
+the circle. We now describe how the subroutine computes the center
+of the circle and its radius. Let the triangle points be [[t1]], [[t2]]
+and [[t3]]. We use the two pairs of points to define two sides,
+i.e., [[t1t2]] and [[t2t3]]. For each
+side we locate the midpoints and get the their coordinates. We check
+whether either of these two lines is either vertical or horizontal. If this
+is true, we know that one of the coordinates of the center of the circumcircle
+is the same as that of the midpoints of the horizontal or vertical line.
+Next, we determine the slopes of the lines [[t1t2]] and [[t2t3]].
+We now determine the slope of lines at right-angles to these lines. We solve the
+resulting equations and obtain the center of the circumcircle. Now we get the
+radius, and then we are done.
+
+<<subroutine <tt>circumCircleCenter</tt> >>=
+
+ sub circumCircleCenter {
+ my ($xA, $yA, $xB, $yB, $xC, $yC, $lc)=@_;
+ my ($deltay12, $deltax12, $xs12, $ys12);
+ my ($deltay23, $deltax23, $xs23, $ys23);
+ my ($xcc, $ycc);
+ my ($m23, $mr23, $c23, $m12, $mr12, $c12);
+ my ($sideA, $sideB, $sideC, $a, $radius);
+
+ if (abs(triangleArea($xA, $yA, $xB, $yB, $xC, $yC)) < 0.0000001)
+ {
+ PrintErrorMessage("Area of triangle is zero!",$lc);
+ return (0,0,0);
+ }
+ $deltay12 = $yB - $yA;
+ $deltax12 = $xB - $xA;
+ $xs12 = $xA + $deltax12 / 2;
+ $ys12 = $yA + $deltay12 / 2;
+ #
+ $deltay23 = $yC - $yB;
+ $deltax23 = $xC - $xB;
+ $xs23 = $xB + $deltax23 / 2;
+ $ys23 = $yB + $deltay23 / 2;
+ #
+ CCXYLINE:{
+ if (abs($deltay12) < 0.0000001)
+ {
+ $xcc = $xs12;
+ if (abs($deltax23) < 0.0000001)
+ {
+ $ycc = $ys23;
+ last CCXYLINE;
+ }
+ else
+ {
+ $m23 = $deltay23 / $deltax23;
+ $mr23 = -1 / $m23;
+ $c23 = $ys23 - $mr23 * $xs23;
+ $ycc = $mr23 * $xs12 + $c23;
+ last CCXYLINE;
+ }
+ }
+ if (abs($deltax12) < 0.0000001)
+ {
+ $ycc = $ys12;
+ if (abs($deltay23) < 0.0000001)
+ {
+ $xcc = $xs23;
+ last CCXYLINE;
+ }
+ else
+ {
+ $m23 = $deltay23 / $deltax23;
+ $mr23 = -1 / $m23;
+ $c23 = $ys23 - $mr23 * $xs23;
+ $xcc = ($ys12 - $c23) / $mr23;
+ last CCXYLINE;
+ }
+ }
+ if (abs($deltay23) < 0.0000001)
+ {
+ $xcc = $xs23;
+ if (abs($deltax12) < 0.0000001)
+ {
+ $ycc = $ys12;
+ last CCXYLINE;
+ }
+ else
+ {
+ $m12 = $deltay12 / $deltax12;
+ $mr12 = -1 / $m12;
+ $c12 = $ys12 - $mr12 * $xs12;
+ $ycc = $mr12 * $xcc + $c12;
+ last CCXYLINE;
+ }
+ }
+ if (abs($deltax23) < 0.0000001)
+ {
+ $ycc = $ys23;
+ if (abs($deltay12) < 0.0000001)
+ {
+ $xcc = $xs12;
+ last CCXYLINE;
+ }
+ else
+ {
+ $m12 = $deltay12 / $deltax12;
+ $mr12 = -1 / $m12;
+ $c12 = $ys12 - $mr12 * $xs12;
+ $xcc = ($ycc - $c12) / $mr12;
+ last CCXYLINE;
+ }
+ }
+ $m12 = $deltay12 / $deltax12;
+ $mr12 = -1 / $m12;
+ $c12 = $ys12 - $mr12 * $xs12;
+ #-----
+ $m23 = $deltay23 / $deltax23;
+ $mr23 = -1 / $m23;
+ $c23 = $ys23 - $mr23 * $xs23;
+ $xcc = ($c23 - $c12) / ($mr12 - $mr23);
+ $ycc = ($c23 * $mr12 - $c12 * $mr23) / ($mr12 - $mr23);
+ }
+ #
+ $sideA = &Length($xA,$yA,$xB,$yB);
+ $sideB = &Length($xB,$yB,$xC,$yC);
+ $sideC = &Length($xC,$yC,$xA,$yA);
+ $a = triangleArea($xA, $yA, $xB, $yB, $xC, $yC);
+ $radius = ($sideA * $sideB * $sideC) / (4 * $a);
+ #
+ return ($xcc, $ycc, $radius);
+ }
+
+@ The subroutine [[ComputeDist]] is used to compute a distance that is
+specified by either a float number, a pair of points, or a variable
+name. In case we have a pair of identifiers, we check whether the first
+one is a point. If it isn't a point we assume we have a variable followed
+by a keyword. Otherwise, i.e., if it is a point name, we check whether
+the second identifier is also a point name. If it is, we simply return
+the distance between them, otherwise we issue an error message.
+If we have only a single identifier, we check whether it is a
+variable that has already been defined, and if so we return its value.
+ Since, this
+subroutine is heavily used, it actually returns a pair of numbers:
+the first one being the computed distance and the second one being an
+error indicator. If the value of this indicator is 0, then there is no
+error. If its value is 1, then there is an error. Moreover, in case there
+is an error the distance is assumed to be equal to zero.
+
+<<subroutine <tt>ComputeDist</tt> >>=
+ sub ComputeDist {
+ my ($lc) = $_[0];
+ my ($v1, $v2);
+
+ if (s/^((\+|-)?\d+(\.\d+)?([eE](\+|-)?\d+)?)//) #is it a number?
+ {
+ return ($1, 1);
+ }
+ elsif (/^[^\W\d_]\d{0,4}[^\W\d_]\d{0,4}/) #it is a pair of IDs?
+ {
+ s/^([^\W\d_]\d{0,4})//i;
+ $v1 = $1;
+ if (!exists($PointTable{lc($v1)})) {
+ if (exists($VarTable{lc($v1)})) {
+ return ($VarTable{lc($v1)}, 1);
+ }
+ PrintErrorMessage("Point $v1 has not been defined", $lc);
+ s/^\s*[^\W\d_]\d{0,4}//i;
+ return (0,0);
+ }
+ $v1 = lc($v1);
+ s/^\s*([^\W\d_]\d{0,4})//i;
+ $v2 = $1;
+ if (!exists($PointTable{lc($v2)}))
+ {
+ PrintErrorMessage("Point $v2 has not been defined", $lc);
+ return (0,0);
+ }
+ $v2 = lc($v2);
+ my ($x1,$y1,$pSV1,$pS1) = unpack("d3A*",$PointTable{$v1});
+ my ($x2,$y2,$pSV2,$pS2) = unpack("d3A*",$PointTable{$v2});
+ return (Length($x1,$y1,$x2,$y2), 1);
+ }
+ elsif (s/^([^\W\d_]\d{0,4})//i) # it is a single id
+ {
+ $v1 = $1;
+ if (!exists($VarTable{lc($v1)})) #it isn't a variable
+ {
+ PrintErrorMessage("Variable $v1 has not been defined", $lc);
+ return (0,0);
+ }
+ return ($VarTable{lc($v1)}, 1);
+ }
+ else
+ {
+ PrintErrorMessage("Unexpected token", $lc);
+ return (0,0);
+ }
+ }
+
+@ The subroutine [[intersection4points]] has 8 parameters that correspond to the
+coordinates of four points that uniquely determine two lines, and computes the
+the point of intersection of these two lines.
+
+<<subroutine <tt>intersection4points</tt> >>=
+ sub intersection4points {
+ my ($x1, $y1, $x2, $y2, $x3, $y3, $x4, $y4) = @_;
+ my ($deltay12, $deltax12, $deltay34, $deltax34);
+ my ($xcc, $ycc, $m34, $c34, $m12, $c12);
+
+ $deltay12 = $y2 - $y1;
+ $deltax12 = $x2 - $x1;
+ #
+ $deltay34 = $y4 - $y3;
+ $deltax34 = $x4 - $x3;
+ I4PXYLINE:{
+ if (abs($deltay12) < 0.0000001)
+ {
+ $ycc = $y1;
+ if (abs($deltax34) < 0.0000001)
+ {
+ $xcc = $x3;
+ last I4PXYLINE;
+ }
+ else
+ {
+ $m34 = $deltay34 / $deltax34;
+ $c34 = $y3 - $m34 * $x3;
+ $xcc = ($ycc - $c34) / $m34;
+ last I4PXYLINE;
+ }
+ }
+ if (abs($deltax12) < 0.0000001)
+ {
+ $xcc = $x1;
+ if (abs($deltay34) < 0.0000001)
+ {
+ $ycc = $y3;
+ last I4PXYLINE;
+ }
+ else
+ {
+ $m34 = $deltay34 / $deltax34;
+ $c34 = $y3 - $m34 * $x3;
+ $ycc = $m34 * $xcc + $c34;
+ last I4PXYLINE;
+ }
+ }
+ if (abs($deltay34) < 0.0000001)
+ {
+ $ycc = $y3;
+ if (abs($deltax12) < 0.0000001)
+ {
+ $xcc = $x1;
+ last I4PXYLINE;
+ }
+ else
+ {
+ $m12 = $deltay12 / $deltax12;
+ $c12 = $y1 - $m12 * $x1;
+ $xcc = ($ycc - $c12) / $m12;
+ last I4PXYLINE;
+ }
+ }
+ if (abs($deltax34) < 0.0000001)
+ {
+ $xcc = $x3;
+ if (abs($deltay12) < 0.0000001)
+ {
+ $ycc = $y1;
+ last I4PXYLINE;
+ }
+ else
+ {
+ $m12 = $deltay12 / $deltax12;
+ $c12 = $y1 - $m12 * $x1;
+ $ycc = $m12 * $xcc + $c12;
+ last I4PXYLINE;
+ }
+ }
+ $m12 = $deltay12 / $deltax12;
+ $c12 = $y1 - $m12 * $x1;
+ $m34 = $deltay34 / $deltax34;
+ $c34 = $y3 - $m34 * $x3;
+ $xcc = ($c34 - $c12) / ($m12 - $m34);
+ $ycc = ($c34 * $m12 - $c12 * $m34) / ($m12 - $m34);
+ }
+ return ($xcc, $ycc);
+ }
+
+@ The subroutine [[IncircleCenter]] computes the center and the
+radius of the circle that is inside a triangle and touches the sides of
+the triangle. The subroutine has six arguments that correspond to the
+coordinates of three points that uniquely determine the triangle. Here are
+the details:
+<ul>
+<li> Let the triangle points be A, B, C and sides a, b, c, where side B
+is opposite angle B, etc. </li>
+<li> Use angles A and B only.</li>
+<li> Let the bisector of angle A meet side a in point A1, and let the
+distance of A1 from B be designated BA1</li>
+<li> Using the sine rule, one gets: BA1/c = a/(b+c), that is
+BA1 = c * a/(b+c).</li>
+<li> Now do the same for side b, and determine equivalent point B1.
+CB1/a = b/(b+c), that is CB1 = a * b/(b+c).</li>
+<li> We can now find the intersection of the line from point A to point A1,
+and the line from point B to point B1. We have four points, so we use the
+mathspic internal [[intersection4points]] subroutine to return the
+coordinates of the intersection X<sub>i</sub>, Y<sub>i</sub>.</li>
+<li> Now get the radius: R=(area of triangle)/(a+b+c)/2</li>
+<li>Finally, return the radius and the coordinates of the center.
+</ul>
+
+<<subroutine <tt>IncircleCenter</tt> >>=
+ sub IncircleCenter {
+ my ($Ax, $Ay, $Bx, $By, $Cx, $Cy) = @_;
+ my ($sideA, $sideB, $sideC);
+ my ($ba1, $xA1, $yA1, $cb1, $ac1, $xB1, $yB1, $xC1, $yC1, $a, $s, $r);
+
+ #determine the lengths of the sides
+ $sideA = Length($Bx, $By, $Cx, $Cy);
+ $sideB = Length($Cx, $Cy, $Ax, $Ay);
+ $sideC = Length($Ax, $Ay, $Bx, $By);
+ #
+ $ba1 = ($sideC * $sideA) / ($sideB + $sideC);
+ ($xA1, $yA1) = pointOnLine($Bx, $By, $Cx, $Cy, $ba1);
+ $cb1 = ($sideA * $sideB) / ($sideC + $sideA);
+ ($xB1, $yB1) = pointOnLine($Cx, $Cy, $Ax, $Ay, $cb1);
+ $ac1 = ($sideB * $sideC) / ($sideA + $sideB);
+ ($xC1, $yC1) = pointOnLine($Ax, $Ay, $Bx, $By, $ac1);
+ ($xcenter, $ycenter) = &intersection4points($Ax, $Ay, $xA1, $yA1,
+ $Bx, $By, $xB1, $yB1);
+ # get radius
+ $a = &triangleArea($Ax, $Ay, $Bx, $By, $Cx, $Cy);
+ $s = ($sideA + $sideB +$sideC) / 2;
+ $r = $a / $s;
+ return ($xcenter, $ycenter, $r);
+ }
+
+@ The subroutine [[Angle]] takes six arguments which correspond to the
+coordinates of three points that define an angle. The subroutine computes
+the opening of the angle in degrees. In case there is an error it returns
+the number -500. ****EXPLAIN THE ALGORITHM****
+
+<<subroutine <tt>Angle</tt> >>=
+ sub Angle {
+ my ($Ax, $Ay, $Bx, $By, $Cx, $Cy) = @_;
+ my ($RAx, $RAy, $RBx, $RBy, $RCx, $RCy, $deltax, $deltay);
+ my ($lineBA, $lineBC, $lineAC, $k, $kk, $angle);
+ my ($T, $cosT, $sinT) = (0.3, cos(0.3), sin(0.3));
+
+ $RAx = $Ax * $cosT + $Ay * $sinT;
+ $RAy = -$Ax * $sinT + $Ay * $cosT;
+ $RBx = $Bx * $cosT + $By * $sinT;
+ $RBy = -$Bx * $sinT + $By * $cosT;
+ $RCx = $Cx * $cosT + $Cy * $sinT;
+ $RCy = -$Cx * $sinT + $Cy * $cosT;
+ $deltax = $RBx - $RAx;
+ $deltay = $RBy - $RAy;
+ $lineBA = sqrt($deltax*$deltax + $deltay*$deltay);
+ if ($lineBA < 0.0000001)
+ {
+ return -500;
+ }
+ $deltax = $RBx - $RCx;
+ $deltay = $RBy - $RCy;
+ $lineBC = sqrt($deltax*$deltax + $deltay*$deltay);
+ if ($lineBC < 0.0000001)
+ {
+ return -500;
+ }
+ $deltax = $RAx - $RCx;
+ $deltay = $RAy - $RCy;
+ $lineAC = sqrt($deltax*$deltax + $deltay*$deltay);
+ if ($lineAC < 0.0000001)
+ {
+ return -500;
+ }
+ $k = ($lineBA*$lineBA + $lineBC*$lineBC - $lineAC*$lineAC ) /
+ (2 * $lineBA * $lineBC);
+ $k = -1 if $k < -0.99999;
+ $k = 1 if $k > 0.99999;
+ $kk = $k * $k;
+ if (($kk * $kk) == 1)
+ {
+ $angle = PI if $k == -1;
+ $angle = 0 if $k == 1;
+ }
+ else
+ {
+ $angle = (PI / 2) - atan2($k / sqrt(1 - $kk),1);
+ }
+ return $angle * 180 / PI;
+ }
+
+@ The subroutine [[excircle]] computes the center and the radius of a circle that
+externally touches a given side (4th and 5th arguments) of triangle (determined
+by the 1rst, the 2nd and 3rd argument). Here are the details:
+<ul>
+<li> Let the triangle points be A, B, C, and the given side be BC.</li>
+<li> Now calculate the radius of Excircle = (triangle area)/(s - side length),
+where s = (a+b+c)/2</li>
+<li>Calculate the distance from the angle (A) (opposite the given side BC)
+ to the excircle center = radius/sin(A/2)</li>
+<li> Now determine the the Excircle center by locating it on the angle bisector
+(i.e., same line that the IncircleCenter is on), but at distance d further
+away from angle A. So, we now have the Incircle center (I),
+ determine deltaX and deltaY from I to A, calculate the distance AI,
+ and then extend the line from I by distance d to Excenter Xc, Yc.</li>
+</ul>
+
+<<subroutine <tt>excircle</tt> >>=
+ sub excircle {
+ my ($A, $B, $C, $D, $E) = @_;
+ my ($Ax,$Ay,$Bx,$By,$Dx,$Dy,$Ex,$Ey,$ASVA,$ASA);
+ ($Ax,$Ay,$ASVA,$ASA)=unpack("d3A*",$PointTable{$A});
+ ($Bx,$By,$ASVA,$ASA)=unpack("d3A*",$PointTable{$B});
+ ($Cx,$Cy,$ASVA,$ASA)=unpack("d3A*",$PointTable{$C});
+ ($Dx,$Dy,$ASVA,$ASA)=unpack("d3A*",$PointTable{$D});
+ ($Ex,$Ey,$ASVA,$ASA)=unpack("d3A*",$PointTable{$E});
+ my ($sideA, $sideB, $sideC, $s, $R, $theAdeg, $d);
+ my ($Xmypoint, $Ymypoint, $deltax, $deltay, $mylength, $xc, $yc);
+
+ $sideA = &Length($Bx, $By, $Cx, $Cy);
+ $sideB = &Length($Cx, $Cy, $Ax, $Ay);
+ $sideC = &Length($Ax, $Ay, $Bx, $By);
+ $s = ($sideA + $sideB + $sideC) / 2;
+ $R = triangleArea($Ax, $Ay, $Bx, $By, $Cx, $Cy) /
+ ($s - &Length($Dx, $Dy, $Ex, $Ey));
+ if (($D eq $A && $E eq $B) || ($D eq $B && $E eq $A))
+ {
+ $theAdeg = &Angle($Bx, $By, $Cx, $Cy, $Ax, $Ay);
+ $Xmypoint = $Cx;
+ $Ymypoint = $Cy;
+ }
+ elsif (($D eq $B && $E eq $C) || ($D eq $C && $E eq $B))
+ {
+ $theAdeg = &Angle($Cx, $Cy, $Ax, $Ay, $Bx, $By);
+ $Xmypoint = $Ax;
+ $Ymypoint = $Ay;
+ }
+ elsif (($D eq $C && $E eq $A) || ($D eq $A && $E eq $C))
+ {
+ $theAdeg = &Angle($Ax, $Ay, $Bx, $By, $Cx, $Cy);
+ $Xmypoint = $Bx;
+ $Ymypoint = $By;
+ }
+ else
+ {
+ return (0,0,0);
+ }
+ $d = $R / sin($theAdeg * PI / 180 / 2);
+ my ($xIn, $yIn, $rin) = &IncircleCenter($Ax, $Ay, $Bx, $By, $Cx, $Cy);
+ $deltax = $xIn - $Xmypoint;
+ $deltay = $yIn - $Ymypoint;
+ $mylength = sqrt($deltax*$deltax + $deltay*$deltay);
+ $xc = $Xmypoint + $d * $deltax / $mylength;
+ $yc = $Ymypoint + $d * $deltay / $mylength;
+ return ($xc, $yc, $R);
+ }
+
+@ The [[DrawLineOrArrow]] subroutine is used to parse the arguments of the commands
+[[drawline]], [[drawthickline]], [[drawarrow]], [[drawthickarrow]] and
+[[drawCurve]]. In general, these commands have as arguments a list of points separated by
+commas that are used to draw a set of lines. The list of points is
+enclosed in parentheses. Here we give only the syntax of the [[drawline]]
+comma, as the syntax of the other commands is identical:
+<pre>
+ drawline ::= "drawline" "(" Points { "," Points } ")"
+ Points ::= Point { separator Point}
+ separator ::= blank | empty
+</pre>
+In the following code we
+scan a list of points (possibly separated by blanks) and we stop when
+we encounter either a comma or some other character. In case we have found
+a comma, we check whether we have a [[drawline]] command and if this is
+the case we plot the list of points. We continue with the next list of points,
+until there are no more points. The inner while-loop is used to control the
+consumption of point tokens and the external to reset the array [[PP]] which
+holds the point names.
+
+<<subroutine <tt>DrawLineOrArrow</tt> >>=
+ sub DrawLineOrArrow {
+ my $draw_Line = shift;
+ my $lc = shift;
+ my $lineLength = -1;
+ my $stacklen = 0;
+ my @PP = ();
+# if ($draw_Line != 2) {
+# s/\s*//;
+# if (s/^\[\s*//) { # optional length specifier
+# $lineLength = expr($lc);
+# if ($lineLength <= 0) {
+# PrintErrorMessage("length must greater than zero",$lc);
+# $lineLength = -1;
+# }
+# chk_rsb("optional part",$lc);
+# }
+# }
+ chk_lparen("$cmd",$lc);
+ DRAWLINES:while(1) {
+ @PP = () ;
+ while(1) {
+ if (s/^([^\W\d_]\d{0,4})\s*//i) { #point name
+ $P = $1;
+ if (!exists($PointTable{lc($P)})) {
+ PrintErrorMessage("Undefined point $P",$lc);
+ }
+ else {
+ push (@PP,$P);
+ }
+ }
+ else {
+ $stacklen = @PP;
+ if ($draw_Line != 2) {
+ if ($stacklen <= 1) {
+ PrintErrorMessage("Wrong number of points",$lc);
+ }
+ else {
+ push(@PP,$lc);
+ if ($draw_Line == 0) {
+ drawarrows(@PP);
+ }
+ elsif ($draw_Line == 1) {
+ drawlines(@PP);
+ }
+ }
+ }
+ if (s/^,\s*// and $draw_Line != 2) {
+ next DRAWLINES;
+ }
+ else {
+ last DRAWLINES;
+ }
+ }
+ }
+ }
+ if ($draw_Line == 2) {
+ $stacklen = @PP;
+ if ($stacklen < 2) {
+ PrintErrorMessage("Wrong number of points",$lc);
+ }
+ elsif ($stacklen % 2 == 0) {
+ PrintErrorMessage("Number of points must be odd",$lc);
+ }
+ else {
+ drawCurve(@PP);
+ }
+ }
+ chk_rparen("arguments of $cmd",$lc);
+ chk_comment($lc);
+ }
+
+@ The subroutine [[drawarrows]] is used to draw one or more lines. The subroutine
+accepts as argument an array which contains the names of the points which
+define the lines, plus the current program line number. Each arrow is printed
+using the following code:
+<center>
+<tt>\arrow < </tt>ArrowLength <tt> mm> [</tt> beta <tt>,</tt> gamma <tt>] from
+x1 y1 to x2 y2 </tt>
+</center>
+where beta is equal to tan([[$arrowAngleB]] * [[d2r]] /2) and gamma is equal to
+2*tan([[$arrowAngleC]] * [[d2r]] / 2).
+
+<<subroutine <tt>drawarrows</tt> >>=
+ sub drawarrows {
+ my ($NoArgs);
+ $NoArgs = @_;
+ my ($lc) = $_[$NoArgs-1]; #line number is the last argument
+ my ($NumberOfPoints, $p, $q, $r12, $d12);
+ my ($px,$py,$pSV,$pS, $qx,$qy,$qSV,$qS);
+
+ $NumberOfPoints = $NoArgs - 1;
+ LOOP: for(my $i=0; $i < $NumberOfPoints - 1; $i++)
+ {
+ $p = $_[$i];
+ $q = $_[$i+1];
+ ($px,$py,$pSV,$pS) = unpack("d3A*",$PointTable{lc($p)});
+ ($qx,$qy,$qSV,$qS) = unpack("d3A*",$PointTable{lc($q)});
+ $pSV = $defaultLFradius if $pSV == 0;
+ $qSV = $defaultLFradius if $qSV == 0;
+ $r12 = $pSV + $qSV;
+ $d12 = Length($px,$py,$qx,$qy);
+ if ($d12 <= $r12)
+ {
+ if($d12 == 0)
+ {
+ PrintErrorMessage("points $p and $q are the same", $lc);
+ next LOOP;
+ }
+ PrintWarningMessage("arrow $p$q not drawn: points too close or ".
+ "radii too big", $lc);
+ next LOOP;
+ }
+ ($px, $py) = pointOnLine($px, $py, $qx, $qy, $pSV) if $pSV > 0;
+ ($qx, $qy) = pointOnLine($qx, $qy, $px, $py, $qSV) if $qSV > 0;
+ my ($beta, $gamma);
+ $beta = tan($arrowAngleB * D2R / 2);
+ $gamma = 2 * tan($arrowAngleC * D2R / 2);
+ printf OUT "\\arrow <%.5f%s> [%.5f,%.5f] from %.5f %.5f to %.5f %.5f\n",
+ $arrowLength, $arrowLengthUnits, $beta, $gamma, $px, $py, $qx, $qy;
+ }
+ }
+
+@ The subroutine [[drawlines]] is used to draw one or more lines. The subroutine
+accepts as argument an array which contains the names of the points which
+define the lines, plus the current program line number. If there are only
+two points (i.e., only one line), then we output the following PiCTeX code:
+<center>
+<tt> \plot x1 y1 x2 y2 / %% pointname1 pointname2</tt>
+</center>
+If there are more than two points, then we need to write the PiCTeX code in
+pairs with two points on each line (just to keep things simple) as follows:
+<center>
+<tt> \plot x1 y1 x2 y2 / %% pointname1 pointname2</tt>
+<tt> \plot x2 y2 x3 y3 / %% pointname2 pointname3</tt>
+<tt> \plot x3 y3 x4 y4 / %% pointname3 pointname4</tt>
+</center>
+An important part of the subroutine is devoted to checking whether either
+or both of the pairs of points are associated with a line-free zone, and if
+so, then we must take care not to draw the line inside the line-free zone. If
+a point does have a line-free zone, then we use the [[pointOnLine]]
+subroutine to determine the point on the line which is just on the line-free
+boundary, and draw the line to the that point instead of to the exact
+point-location.
+
+<<subroutine <tt>drawlines</tt> >>=
+ sub drawlines {
+ my ($NoArgs);
+ $NoArgs = @_;
+ my ($lc) = $_[$NoArgs-1]; #line number is the last argument
+ my ($NumberOfPoints, $p, $q, $r12, $d12);
+ my ($px,$py,$pSV,$pS, $qx,$qy,$qSV,$qS);
+
+ $NumberOfPoints = $NoArgs - 1;
+ LOOP: for(my $i=0; $i < $NumberOfPoints - 1; $i++)
+ {
+ $p = $_[$i];
+ $q = $_[$i+1];
+ ($px,$py,$pSV,$pS) = unpack("d3A*",$PointTable{lc($p)});
+ ($qx,$qy,$qSV,$qS) = unpack("d3A*",$PointTable{lc($q)});
+ $pSV = $defaultLFradius if $pSV == 0;
+ $qSV = $defaultLFradius if $qSV == 0;
+ $r12 = $pSV + $qSV;
+ $d12 = Length($px,$py,$qx,$qy);
+ if ($d12 <= $r12)
+ {
+ if($d12 == 0)
+ {
+ PrintErrorMessage("points $p and $q are the same", $lc);
+ next LOOP;
+ }
+ PrintWarningMessage("line $p$q not drawn: points too close or ".
+ "radii too big", $lc);
+ next LOOP;
+ }
+ ($px, $py) = pointOnLine($px, $py, $qx, $qy, $pSV) if $pSV > 0;
+ ($qx, $qy) = pointOnLine($qx, $qy, $px, $py, $qSV) if $qSV > 0;
+ if ($px == $qx || $py == $qy)
+ {
+ printf OUT "\\putrule from %.5f %.5f to %.5f %.5f %%%% %s%s\n",
+ $px,$py,$qx,$qy,$p,$q;
+ }
+ else
+ {
+ printf OUT "\\plot %.5f %.5f\t%.5f %.5f / %%%% %s%s\n",
+ $px, $py,$qx,$qy,$p,$q;
+ }
+ }
+ }
+
+@ The subroutine [[drawCurve]] is used to draw a curve that passes through an odd
+number of points. The subroutine has as argument an array which contains the names of the
+points which define the lines plus the current program line number. The subroutine
+emits code that has the following general form:
+<pre>
+ \setquadratic
+ \plot
+ X1 Y1
+ X2 Y2
+ X3 Y3
+ \setlinear
+</pre>
+
+
+<<subroutine <tt>drawCurve</tt> >>=
+ sub drawCurve {
+ my ($NoArgs);
+ $NoArgs = @_;
+ my ($lc) = $_[$NoArgs-1]; #line number is the last argument
+ my ($NumberOfPoints, $p);
+
+ $NumberOfPoints = $NoArgs - 1;
+ print OUT "\\setquadratic\n\\plot\n";
+ for(my $i=0; $i <= $NumberOfPoints; $i++)
+ {
+ $p = $_[$i];
+ my ($px,$py,$pSV,$pS) = unpack("d3A*",$PointTable{lc($p)});
+ printf OUT "\t%0.5f %0.5f", $px, $py;
+ print OUT (($i == $NumberOfPoints) ? " / %$p\n" : " %$p\n");
+ }
+ print OUT "\\setlinear\n";
+ }
+
+@ The subroutine [[drawpoints]] is used to draw one or more points. The subroutine
+has as arguments a list of points. For each point we produce code that has
+the following general form:
+<center>
+<tt> \put {SYMBOL} at Px PY</tt>
+</center>
+where [[SYMBOL]] is either the default plot symbol, i.e., [[$\bullet$]],
+whatever the user has set with the [[PointSymbol]] command, or the plot
+symbol specified in the definition of the point.
+
+<<subroutine <tt>drawpoints</tt> >>=
+ sub drawpoints {
+ my ($NumberOfPoints,$p);
+ $NumberOfPoints = @_;
+ my ($px,$py,$pSV,$pS);
+
+ for($i=0; $i < $NumberOfPoints; $i++)
+ {
+ $p = $_[$i];
+ ($px,$py,$pSV,$pS) = unpack("d3A*",$PointTable{lc($p)});
+ if ($pS eq "" and $defaultsymbol =~ /circle|square/) {
+ $pS = $defaultsymbol;
+ }
+ POINTSWITCH: {
+ if ($pS eq "") # no plot symbol specified
+ {
+ printf OUT "\\put {%s} at %.5f %.5f %%%% %s\n",
+ $defaultsymbol, $px, $py, $p;
+ last POINTSWITCH;
+ }
+ if ($pS eq "circle") # plot symbol is a circle
+ {
+ my $radius = (defined($DimOfPoint{lc($p)})) ? $DimOfPoint{lc($p)} :
+ $GlobalDimOfPoints;
+ if ($radius > 0) # draw a circle using the current units
+ {
+ if ($radius == 1.5) # use \bigcirc
+ {
+ printf OUT "\\put {\$\\bigcirc\$} at %.5f %.5f %%%% %s\n",
+ $px, $py, $p;
+ }
+ else
+ {
+ printf OUT "\\circulararc 360 degrees from %.5f %.5f center at %.5f %.5f %%%% %s\n",
+ $px+$radius, $py, $px, $py, $p;
+ }
+ }
+ else #use \circ symbol
+ {
+ printf OUT "\\put {\$\\circ\$} at %.5f %.5f %%%% %s\n",
+ $px,$py,$p;
+ }
+ last POINTSWITCH;
+ }
+ if ($pS eq "square")
+ {
+ my $side = (defined($DimOfPoint{lc($p)})) ? $DimOfPoint{lc($p)} :
+ $GlobalDimOfPoints;
+ printf OUT "\\put {%s} at %.5f %.5f %%%% %s\n",
+ drawsquare($side), $px, $py, $p;
+ last POINTSWITCH;
+ }
+ printf OUT "\\put {%s} at %.5f %.5f %%%% %s\n", $pS,$px,$py,$p;
+ }
+ }
+ }
+
+@ The subroutine [[drawAngleArc]] gets six arguments which correspond to
+three points defining an angle (variables [[$P1]], [[$P2]] and [[$P3]]),
+the radius, the internal/external specification and the direction
+specification (clockwise or anticlockwise).
+Depending on the values of these arguments, the subroutine
+returns the corresponding PiCTeX code, the general format of
+which is <pre>
+ \circulararc Angle degrees from x y center at x2 y2
+</pre>
+where [[Angle]] is the angle that the three points P1 P2 P3 define
+(computed by subroutine [[Angle]]),
+and [[x]] and [[y]] are the coordinates of a point
+residing on line P2P1 at distance equal to a [[$radius]] from
+point [[$P2]]; and [[x2]], [[y2]] are the coordinates of the
+center of the circle about which the arc is drawn,
+i.e., point [[$P2]].
+
+<<subroutine <tt>drawAngleArc</tt> >>=
+sub drawAngleArc {
+ my ($P1, $P2, $P3, $radius, $inout, $direction) = @_;
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$P1});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$P2});
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$P3});
+
+ my $internalAngle = Angle($x1, $y1, $x2, $y2, $x3, $y3);
+ my $externalAngle = 360 - $internalAngle;
+ my ($x, $y) = pointOnLine($x2, $y2, $x1, $y1, $radius);
+ my $code = "";
+ if ($inout eq "internal" and $direction eq "clockwise" ) {
+ $code = sprintf "\\circulararc %.5f degrees from %.5f %.5f center at %.5f %.5f\n",
+ -1 * $internalAngle, $x, $y, $x2, $y2;
+ }
+ elsif ($inout eq "internal" and $direction eq "anticlockwise" ) {
+ $code = sprintf "\\circulararc %.5f degrees from %.5f %.5f center at %.5f %.5f\n",
+ $internalAngle, $x, $y, $x2, $y2;
+ }
+ elsif ($inout eq "external" and $direction eq "clockwise" ) {
+ $code = sprintf "\\circulararc %.5f degrees from %.5f %.5f center at %.5f %.5f\n",
+ -1 * $externalAngle, $x, $y, $x2, $y2;
+ }
+ elsif ($inout eq "external" and $direction eq "anticlockwise" ) {
+ $code = sprintf "\\circulararc %.5f degrees from %.5f %.5f center at %.5f %.5f\n",
+ $externalAngle, $x, $y, $x2, $y2;
+ }
+ return $code;
+}
+
+@ The subroutine [[drawAngleArrow]] gets six arguments which correspond to
+three points defining an angle (variables [[$P1]], [[$P2]] and [[$P3]]),
+the radius, the internal/external specification and the direction
+specification. The subroutine mainly draws the arrowhead, and
+calls the subroutine [[drawAngleArc]] to draw the
+arc part of the arrow.
+
+<<subroutine <tt>drawAngleArrow</tt> >>=
+sub drawAngleArrow {
+ my ($P1, $P2, $P3, $radius, $inout, $direction) = @_;
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$P1});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$P2});
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$P3});
+
+ my $code = drawAngleArc($P1, $P2, $P3, $radius, $inout, $direction);
+
+ my ($xqp, $yqp) = pointOnLine($x2, $y2, $x1, $y1, $radius);
+ my ($deltax, $deltay) = ($x1 - $x2, $y1 - $y2);
+ my $AL;
+
+ if ($xunits =~ /mm/) {
+ $AL = 1;
+ }
+ elsif ($xunits =~ /cm/) {
+ $AL = 0.1;
+ }
+ elsif ($xunits =~ /pt/) {
+ $AL = 2.845;
+ }
+ elsif ($xunits =~ /bp/) {
+ $AL = 2.835;
+ }
+ elsif ($xunits =~ /pc/) {
+ $AL = 0.2371;
+ }
+ elsif ($xunits =~ /in/) {
+ $AL = 0.03937;
+ }
+ elsif ($xunits =~ /dd/) {
+ $AL = 2.659;
+ }
+ elsif ($xunits =~ /cc/) {
+ $AL = 0.2216;
+ }
+ elsif ($xunits =~ /sp/) {
+ $AL = 186467.98;
+ }
+ my $halfAL = $AL / 2;
+ my $d = sqrt($radius * $radius - $halfAL * $halfAL);
+ my $alpha = atan2($d / $halfAL, 1) * R2D;
+ my $beta = 2 * (90 - $alpha);
+ my $thetaqr;
+ if (abs($deltay) < 0.00001) {
+ if ($deltax > 0 ) {$thetaqr = 0 }
+ elsif ($deltax < 0) {$thetaqr = -180}
+ }
+ else {
+ if (abs($deltax) < 0.00001) {
+ $thetaqr = 90;
+ }
+ else {
+ $thetaqr = atan2($deltay / $deltax, 1) * R2D;
+ }
+ }
+ my ($xqr, $yqr) = pointOnLine($x2, $y2, $x3, $y3, $radius);
+ $deltax = $x3 - $x2;
+ $deltay = $y3 - $y2;
+ $alpha = atan2(sqrt($radius * $radius - $halfAL * $halfAL) / $halfAL, 1) /
+ D2R;
+ $beta = 2 * (90 - $alpha);
+ LINE2 : {
+ if (abs($deltax) < 0.00001) {
+ if ($deltay > 0) { $thetaqr = 90 }
+ elsif ($deltay < 0) { $thetaqr = - 90 }
+ last LINE2;
+ }
+ else {
+ $thetaqr = atan2($deltay / $deltax, 1) * R2D;
+ }
+ if (abs($deltay) < 0.00001) {
+ if ($deltax > 0) { $thetaqr = 0 }
+ elsif ($deltax < 0) { $thetaqr = -180 }
+ last LINE2;
+ }
+ else {
+ $thetaqr = atan2($deltay / $deltax, 1) * R2D;
+ }
+ if ($deltax < 0 and $deltay > 0) { $thetaqr += 180 }
+ elsif ($deltax < 0 and $deltay < 0) { $thetaqr += 180 }
+ elsif ($deltax > 0 and $deltay < 0) { $thetaqr += 360 }
+ }
+ my $xqrleft = $x2 + $radius * cos(($thetaqr + $beta) * D2R);
+ my $yqrleft = $y2 + $radius * sin(($thetaqr + $beta) * D2R);
+ my $xqrright = $x2 + $radius * cos(($thetaqr - $beta) * D2R);
+ my $yqrright = $y2 + $radius * sin(($thetaqr - $beta) * D2R);
+ if ($inout eq "internal" and $direction eq "clockwise") {
+ $code .= sprintf "\\arrow <1.5mm> [0.5, 1] from %.5f %.5f to %.5f %.5f\n",
+ $xqrleft, $yqrleft, $xqr, $yqr;
+ }
+ elsif ($inout eq "internal" and $direction eq "anticlockwise") {
+ $code .= sprintf "\\arrow <1.5mm> [0.5, 1] from %.5f %.5f to %.5f %.5f\n",
+ $xqrright, $yqrright, $xqr, $yqr;
+ }
+ elsif ($inout eq "external" and $direction eq "clockwise") {
+ $code .= sprintf "\\arrow <1.5mm> [0.5, 1] from %.5f %.5f to %.5f %.5f\n",
+ $xqrleft, $yqrleft, $xqr, $yqr;
+ }
+ elsif ($inout eq "external" and $direction eq "anticlockwise") {
+ $code .= sprintf "\\arrow <1.5mm> [0.5, 1] from %.5f %.5f to %.5f %.5f\n",
+ $xqrright, $yqrright, $xqr, $yqr;
+ }
+ return $code;
+}
+
+@ The subroutine [[expr]] is used to parse an expression. We are using a
+recursive descent parser to parse and evaluate an expression. The
+general syntax of an expression is as follows:
+<pre>
+expr ::= term { addop term }
+addop ::= "+" | "-"
+term ::= factor { mulop factor }
+mulop ::= "*" | "/" | "rem"
+factor ::= primitive [ ** factor ]
+primitive ::= [ "+" | "-"] primitive | number | variable |
+ pair-of-points | "(" expr ")" |
+ "sin (" expr ")" | "cos (" expr ")" | "area (" ThreePoints ")" |
+ "tan (" expr ")" | "exp (" expr ")" | "int" "(" expr ")" |
+ "log (" expr ")" | "atan (" expr ")" | "sgn" "(" expr ")" |
+ "sqrt (" expr ")" | "acos (" expr ")" | "asin (" expr ")" |
+ "atan (" expr ")" | "_pi_" | "_e_" |
+ "xcoord (" point ")" | "ycoord (" point ")" | "angle "(" ThreePoints ")"|
+ "angledeg" "(" ThreePoints ")" | "direction" "(" TwoPoints ")" |
+ "directiondeg" "(" TwoPoints ")" | "_linethickness_"
+</pre>
+Note that [[_pi_]] and [[_e_]] can be used to access the value of the constants
+Pi and e.
+
+<<subroutine <tt>expr</tt> >>=
+sub expr {
+ my $lc = $_[0];
+ my($left,$op,$right);
+
+ $left = term($lc);
+ while ($op = addop()) {
+ $right = term($lc);
+ if ($op eq '+')
+ { $left += $right }
+ else
+ { $left -= $right }
+ }
+ return $left;
+}
+
+sub addop {
+ s/^([+-])// && $1;
+}
+
+sub term {
+ my $lc = $_[0];
+ my ($left, $op, $right);
+ $left = factor($lc);
+ while ($op = mulop()) {
+ $right = factor($lc);
+ if ($op eq '*')
+ { $left *= $right }
+ elsif ($op =~ /rem/i) {
+ eval {$left %= $right};
+ PrintFatalError("Division by zero", $lc) if $@;
+ }
+ else {
+ eval {$left /= $right};
+ PrintFatalError("Division by zero", $lc) if $@;
+ }
+ }
+ return $left;
+}
+
+sub mulop {
+ (s#^([*/])## || s/^(rem)//i) && lc($1);
+}
+
+sub factor {
+ my $lc = $_[0];
+ my ($left);
+
+ $left = primitive($lc);
+ if (s/^\*\*//) {
+ $left **= factor($lc);
+ }
+ return $left;
+}
+
+sub primitive {
+ my $lc = $_[0];
+ my $val;
+ s/\s*//;
+ if (s/^\(//) { #is it an expr in parentheses
+ $val = expr($lc);
+ s/^\)// || PrintErrorMessage("Missing right parenthesis", $lc);
+ }
+ elsif (s/^-//) { # is it a negated primitive
+ $val = - primitive();
+ }
+ elsif (s/^\+//) { # is it a positive primitive
+ $val = primitive();
+ }
+ elsif (s/^angledeg//i) {
+ chk_lparen("angledeg",$lc);
+ my $point_1 = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_1});
+ my $point_2 = get_point($lc);
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point_2});
+ my $point_3 = get_point($lc);
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point_3});
+ my $d12 = Length($x1, $y1, $x2, $y2);
+ my $d23 = Length($x2, $y2, $x3, $y3);
+ my $d31 = Length($x3, $y3, $x1, $y1);
+ if ( $d12 == 0 ) {
+ PrintErrorMessage("points `$point_1' and `$point_2' are the same", $lc);
+ $val = 0;
+ }
+ elsif ( $d23 == 0 ) {
+ PrintErrorMessage("points `$point_2' and `$point_3' are the same", $lc);
+ $val = 0;
+ }
+ elsif ( $d31 == 0 ) {
+ PrintErrorMessage("points `$point_1' and `$point_3' are the same", $lc);
+ $val = 0;
+ }
+ else {
+ $val = Angle($x1, $y1, $x2, $y2, $x3, $y3);
+ $val = 0 if $val == -500;
+ }
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^angle//i) {
+ chk_lparen("angle",$lc);
+ my $point_1 = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_1});
+ my $point_2 = get_point($lc);
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point_2});
+ my $point_3 = get_point($lc);
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point_3});
+ my $d12 = Length($x1, $y1, $x2, $y2);
+ my $d23 = Length($x2, $y2, $x3, $y3);
+ my $d31 = Length($x3, $y3, $x1, $y1);
+ if ( $d12 == 0 ) {
+ PrintErrorMessage("points `$point_1' and `$point_2' are the same", $lc);
+ $val = 0;
+ }
+ elsif ( $d23 == 0 ) {
+ PrintErrorMessage("points `$point_2' and `$point_3' are the same", $lc);
+ $val = 0;
+ }
+ elsif ( $d31 == 0 ) {
+ PrintErrorMessage("points `$point_1' and `$point_3' are the same", $lc);
+ $val = 0;
+ }
+ else {
+ $val = Angle($x1, $y1, $x2, $y2, $x3, $y3);
+ if ($val == -500) {
+ $val = 0;
+ }
+ else {
+ $val = D2R * $val;
+ }
+ }
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^area//i) {
+ chk_lparen("angledeg",$lc);
+ my $point_1 = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_1});
+ my $point_2 = get_point($lc);
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point_2});
+ my $point_3 = get_point($lc);
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point_3});
+ $val = triangleArea($x1, $y1, $x2, $y2, $x3, $y3);
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^asin//i) {
+ chk_lparen("asin");
+ $val = expr();
+ PrintFatalError("Can't take asin of $val", $lc) if $val < -1 || $val > 1;
+ $val = asin($val);
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^acos//i) {
+ chk_lparen("acos");
+ $val = expr();
+ PrintFatalError("Can't take acos of $val", $lc) if $val < -1 || $val > 1 ;
+ $val = acos($val);
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^atan//i) {
+ chk_lparen("atan");
+ $val = expr();
+ $val = atan($val);
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^cos//i) {
+ chk_lparen("cos");
+ $val = expr();
+ $val = cos($val);
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^directiondeg//i) {
+ chk_lparen("directiondeg",$lc);
+ my $point_1 = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_1});
+ my $point_2 = get_point($lc);
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point_2});
+ my $x3 = $x1+1;
+ if ( ($y2 - $y1) >= 0) {
+ $val = Angle($x3, $y1, $x1, $y1, $x2, $y2);
+ $val = 0 if $val == -500;
+ }
+ else {
+ $val = 360 - Angle($x3, $y1, $x1, $y1, $x2, $y2);
+ $val = 0 if $val == -500;
+ }
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^direction//i) {
+ chk_lparen("direction",$lc);
+ my $point_1 = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_1});
+ my $point_2 = get_point($lc);
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point_2});
+ my $x3 = $x1+1;
+ if ( ($y2 - $y1) >= 0) {
+ $val = Angle($x3, $y1, $x1, $y1, $x2, $y2);
+ $val = 0 if $val == -500;
+ $val = D2R * $val;
+ }
+ else {
+ $val = 360 - Angle($x3, $y1, $x1, $y1, $x2, $y2);
+ $val = 0 if $val == -500;
+ $val = D2R * $val;
+ }
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^exp//i) {
+ chk_lparen("exp");
+ $val = expr();
+ $val = exp($val);
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^int//i) {
+ chk_lparen("int");
+ $val = expr();
+ $val = int($val);
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^log//i) {
+ chk_lparen("log");
+ $val = expr();
+ PrintFatalError("Can't take log of $val", $lc) if $val <= 0;
+ $val = log($val);
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^sin//i) {
+ chk_lparen("sin");
+ $val = expr();
+ $val = sin($val);
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^sgn//i) {
+ chk_lparen("sgn");
+ $val = expr();
+ if ($val > 0) {
+ $val = 1;
+ }
+ elsif ($val == 0) {
+ $val = 0;
+ }
+ else {
+ $val = -1;
+ }
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^sqrt//i) {
+ chk_lparen("sqrt");
+ $val = expr();
+ $val = sqrt($val);
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^tan//i) {
+ chk_lparen("tan");
+ $val = expr();
+ $val = sin($val)/cos($val);
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^xcoord//i) {
+ chk_lparen("xcoord");
+ my $point_name = get_point;
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_name});
+ $val = $x1;
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^ycoord//i) {
+ chk_lparen("ycoord");
+ my $point_name = get_point;
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_name});
+ $val = $y1;
+ chk_rparen("Missing right parenthesis", $lc);
+ }
+ elsif (s/^_pi_//i) {
+ $val = PI;
+ }
+ elsif (s/^_e_//i) {
+ $val = 2.71828182845905;
+ }
+ elsif (s/^_linethickness_//i) {
+ $val = $LineThickness / $xunits;
+ }
+ else {
+ my $err_code;
+ ($val,$err_code) = ComputeDist($lc);
+ }
+ s/\s*//;
+ return $val;
+}
+
+@ The subroutine [[memberOf]] is used to check whether a string is part of
+a list of strings. We assume that the first argument is the string in
+question. We compare each list element against the string in question and
+if we find it we stop and return the value [[1]] (denoting truth). Otherwise,
+we simply return the value [[0]] (denoting false).
+
+<<subroutine <tt>memberOf</tt> >>=
+sub memberOf {
+ my $elem = shift(@_);
+
+ my $found = 0;
+ foreach $item (@_){
+ if ($item eq $elem){
+ $found = 1;
+ last;
+ }
+ }
+ return $found;
+}
+
+@ The subroutine [[midpoint]] computes the coordinates of the midpoint of two points
+by means of the simple formula:
+<center>
+m<sub>x</sub>=x<sub>1</sub>+(y<sub>2</sub> - y<sub>1</sub>)/2 <br>
+m<sub>y</sub>=y<sub>1</sub>+(x<sub>2</sub> - x<sub>1</sub>)/2
+</center>
+
+<<subroutine <tt>midpoint</tt> >>=
+sub midpoint {
+ my ($x1, $y1, $x2, $y2)=@_;
+ return ($x1 + ($x2 - $x1)/2,
+ $y1 + ($y2 - $y1)/2);
+}
+
+
+@ The subroutine [[tand]] computes the tangent of an angle. The angle is
+supposed to be in degrees. We simply transform it into radians and then
+compute the actual result.
+
+<<subroutine <tt>tand</tt> >>=
+sub tand {
+ my $d = $_[0];
+ $d = $d * PI / 180;
+ return sin($d)/cos($d);
+}
+
+@ The subroutine [[get_string]] is used to extract a leading valid mathspic string
+from the input line. A string must start with a quotation mark, i.e., [["]],
+and must end with the same symbol. A string may contain quotation marks which
+must be escaped with a backslash, i.e., [[\]]. Initially, we remove all
+leading white space. If the next character of the string is not a quotation
+mark we print an error message and stop. Otherwise, we split the string into
+an array of characters and store the characters up to the next quotation
+mark to the array [[@cmd]]. In case the next character is a backslash and
+we aren't at the end of the input string and the next character is a
+quotation mark, we have an escape sequence. This means that we store these
+two characters in the [[@cmd]] array and skip to characters after the quotation
+mark. Otherwise, we simply store the character in the [[@cmd]] array and
+skip to the next character. This process is repeated until either we consume
+all the characters of the string or until we find a sole quotation mark.
+Since we are not sure what has forced the loop to exit, we check whether
+there are still characters in the input string and we check whether this
+is a quotation mark. If these tests fail we have a string without a
+closing quotation mark. In all cases we return a triplet consisting of
+a number denoting success (1) or failure (0) and what we have consumed
+from the input string, and what is left from the input string.
+
+<<subroutine <tt>get_string</tt> >>=
+sub get_string {
+ my $string = shift;
+ my $lc = shift;
+
+ $string =~ s/^\s+//;
+ if ($string !~ s/^\"//) {
+ PrintErrorMessage("No starting \" found",$lc);
+ return (1,$string,$string);
+ }
+ my @ch = split //,$string;
+ my @cmd;
+ while (@ch and $ch[0] ne "\"") {
+ if ($ch[0] eq "\\" and (defined $ch[1]) and $ch[1] eq "\"") {
+ shift @ch;
+ push @cmd, $ch[0];
+ shift @ch;
+ }
+ else {
+ push @cmd, $ch[0];
+ shift @ch;
+ }
+ }
+ if (! defined $ch[0]) {
+ PrintErrorMessage("No closing \" found",$lc);
+ return (1,join("",@cmd), join("",@ch))
+ }
+ else {
+ shift @ch;
+ return (0, join("",@cmd), join("",@ch))
+ }
+}
+
+@ The definition as well as an explanation of the functionality of the
+following subroutine can be found in "Programming Perl", 3rd edition.
+
+<<subroutine <tt>is_tainted</tt> >>=
+sub is_tainted {
+ my $arg = shift;
+ my $nada = substr($arg,0,0);
+ local $@;
+ eval { eval "# $nada"};
+ return length($@) != 0;
+}
+
+@ The subroutine [[noOfDigits]] has one argument which is a number and returns
+the number of decimal digits it has. If the number matches the regular
+expression [[^\d+(?!\.)]] (a series of digits <i>not</i> followed by a
+period), then the number of decimal digits is zero. If the
+number matches the
+regular expression [[^\d+\.(\d+)?]], then number of decimal digits equals
+[[length($1)]]. Naturally, it maybe zero!
+
+<<subroutine <tt>noOfDigits</tt> >>=
+sub noOfDigits {
+ my $num = $_[0];
+
+ if ($num =~ /^[\+-]?\d+(?!\.)/) {
+ return 0;
+ }
+ elsif ($num =~ /^[\+-]\d+\.(\d+)?/) {
+ return length($1);
+ }
+}
+
+@ Subroutine [[drawsquare]] is use by the [[drawpoints]] routine to plot a
+point whose point symbol is a square. The subroutine has one argument, which is
+equal to the radius of the point. From this argument it computes the side of
+the square.
+
+<<subroutine <tt>drawsquare</tt> >>=
+sub drawsquare {
+ my $s = $_[0];
+ #$s *= sqrt(2);
+ $s = sprintf "%.5f", $s;
+ my $code = "\\setlength{\\unitlength}{$xunits}%\n";
+ $code .= "\\begin{picture}($s,$s)\\put(0,0)" .
+ "{\\framebox($s,$s){}}\\end{picture}";
+ return $code;
+}
+
+@ Subroutine [[X2sp]] has two arguments: a number and a length unit. It returns
+the length expresssed in sp units.
+
+<<subroutine <tt>X2sp</tt> >>=
+sub X2sp {
+ my $LT = shift;
+ my $units = shift;
+
+ if ($units eq "pc") {
+ return $LT * 786432;
+ }
+ elsif ($units eq "pt") {
+ return $LT * 65536;
+ }
+ elsif ($units eq "in") {
+ return $LT * 4736286.72;
+ }
+ elsif ($units eq "bp") {
+ return $LT * 65781.76;
+ }
+ elsif ($units eq "cm") {
+ return $LT * 1864679.811023622;
+ }
+ elsif ($units eq "mm") {
+ return $LT * 186467.981102362;
+ }
+ elsif ($units eq "dd") {
+ return $LT * 70124.086430424;
+ }
+ elsif ($units eq "cc") {
+ return $LT * 841489.037165082;
+ }
+ elsif ($units eq "sp") {
+ return $LT;
+ }
+}
+
+
+@ Subroutine [[sp2X]] has two arguments: a number that denotes a length in sp units
+ and a length unit. It returns the length expresssed in units that are specified by
+ the second argument.
+
+<<subroutine <tt>sp2X</tt> >>=
+sub sp2X {
+ my $LT = shift;
+ my $units = shift;
+
+ if ($units eq "pc") {
+ return $LT / 786432;
+ }
+ elsif ($units eq "pt") {
+ return $LT / 65536;
+ }
+ elsif ($units eq "in") {
+ return $LT / 4736286.72;
+ }
+ elsif ($units eq "bp") {
+ return $LT / 65781.76;
+ }
+ elsif ($units eq "cm") {
+ return $LT / 1864679.811023622;
+ }
+ elsif ($units eq "mm") {
+ return $LT / 186467.981102362;
+ }
+ elsif ($units eq "dd") {
+ return $LT / 70124.086430424;
+ }
+ elsif ($units eq "cc") {
+ return $LT / 841489.037165082;
+ }
+ elsif ($units eq "sp") {
+ return $LT;
+ }
+}
+
+@ Subroutine [[setLineThickness]] takes two arguments: the value of the variable
+ [[$xunits]] and a string denoting the linethickness. It returns the linthickness
+ expressed in the units of the [[$xunits]].
+
+<<subroutine <tt>setLineThickness</tt> >>=
+sub setLineThickness {
+ my $Xunits = shift;
+ my $LT = shift;
+ $Xunits =~ s/^((\+|-)?\d+(\.\d+)?([eE](\+|-)?\d+)?)//;
+ my $xlength = "$1";
+ $Xunits =~ s/^\s*($units)//;
+ my $x_in_units = $1;
+ $LT =~ s/^((\+|-)?\d+(\.\d+)?([eE](\+|-)?\d+)?)//;
+ my $LTlength = "$1";
+ $LT =~ s/^\s*($units)//;
+ my $LT_in_units = $1;
+ $LTlength = X2sp($LTlength,$LT_in_units);
+ $LTlength = sp2X($LTlength,$x_in_units);
+ return $LTlength;
+}
+
+@ The subroutine [[process_input]] accepts one argument which is a file handle
+that corresponds to the file that the subroutine is supposed to process.
+The processing cycle is fairly simple: we input one line at the time, remove
+any leading space characters and the trailing new line character, and then
+start the actual processing. The variable [[$INFILE]] contains the name of
+the input file and the variable [[$lc]] is the local line counter. The
+commands [[beginSkip]] and [[endSkip]] can be used to ignore blocks
+of code and so we need to process them here. The variable [[$no_output]]
+is used as a switch to toggle from process mode to no-precess mode.
+If the first token is [[beginSkip]], we set the variable [[$no_output]] to 1,
+print a comment to the output file and continue with the next input line.
+If the first token is [[endSkip]], we check whether we are in a no-process
+mode. If this is the case, we revert to process mode; otherwise we print
+an error message. Finally, depending on whether we are in process or no-process
+mode we process the input text or simply printed commented out to the output
+file. Note, that we don't allow nested comment blocks, as this makes really
+no sense!
+
+<<subroutine <tt>process_input</tt> >>=
+ sub process_input {
+ my ($INFILE,$currInFile) = @_;
+ my $lc = 0;
+ my $no_output = 0;
+ $curr_in_file = $currInFile;
+ LINE: while(<$INFILE>) {
+ $lc++;
+ chomp($command = $_);
+ s/^\s+//;
+ if (/^beginSkip\s*/i) {
+ $no_output = 1;
+ print OUT "%%$_" if $comments_on;
+ next LINE;
+ }
+ elsif (/^endSkip\s*/i) {
+ if ($no_output == 0) {
+ PrintErrorMessage("endSkip without beginSkip",$lc);
+ }
+ else {
+ $no_output = 0;
+ }
+ print OUT "%%$_" if $comments_on and !$no_output;
+ next LINE;
+ }
+ elsif ($no_output == 1) {
+ next LINE;
+ }
+ else {
+ if (/^[^\\]/) {
+ my $out_line = mpp($command,$lc) unless /^\\/; #call macro pre-processor
+ $_ = "$out_line\n";
+ }
+ <<process input line>>
+ }
+ }
+ }
+
+@ Each command line starts with a particular <i>token</i> and depending on
+which one we have we perform different actions. If the first character
+is [[%]] we have a comment line, and depending on the value of the variable
+[[$comments_on]] we either output the comment on the output file (default
+action) or just ignore it and continue with the next input line. In case the
+first token is the name of a valid command we process the command and
+output the corresponding code. Otherwise, we print an error message to
+the screen and to the log file and continue with the next input line.
+Note that the input language is case-insensitive and so one is free to write a
+command name using any combination of upper and lower case
+letters, e.g., the tokens [[lAtEx]],
+[[LaTeX]], and [[latex]] are considered exactly the same.
+The valid <i>MathsPIC</i> commands are the following (don't pay attention
+to the case!):
+<ul>
+<li>
+Commands [[drawAngleArc]] and [[drawAngleArrow]] are used to draw an arc and an
+arrow, respectively. Since, their user interface is identical, we process
+them as if they were identical commands.
+</li>
+<li>
+Command [[drawcircle]] is used to draw a circle with a specified radius.
+</li>
+<li>
+Command [[drawCircumCircle]] is used to draw the circumcircle of triangle
+specified by three points.
+</li>
+<li>
+Command [[drawexcircle]] is used to draw the excircle of triangle
+relative to a given side of the triangle.
+</li>
+<li>
+Command [[drawincircle]] is used to draw the incircle of triangle.
+</li>
+<li>
+Command [[drawincurve]] is used to draw a curve that passes through a number of points.
+</li>
+<li> Command [[drawline]] is used to draw either
+a line (not necessarily a straight one) or a number of lines from a list
+or lists of points. The lines are specified as pairs of points that can
+be separated by blank spaces.
+<li> Command [[drawthickline]] is used to draw either
+a thick line (not necessarily a straight one) or a number of lines from a list
+or lists of points. The lines are specified as pairs of points that can
+be separated by blank spaces.
+</li>
+<li>
+Command [[drawPerpendicular]] draws a perpendicular line from point A to
+line BC.
+</li>
+<li> Command [[drawpoint]] is used to draw one, two or more points.
+The point names can be separated by blanks.
+</li>
+<li>
+Command [[drawRightAngle]] draws an angle, specified by three points,
+of a size specified by a side length.
+</li>
+<li>
+Command [[drawsquare]] draws a square, centered at the coordinates of the
+first arguments, which is assumed to be a point, with side equal to the
+second argument.
+</li>
+<li>
+Command [[inputfile*]] is used to verbatim include a file into the output
+file.
+</li>
+<li>
+Command [[inputfile]] is used to include a <i>MathsPIC</i> program file
+into the main file.
+</li>
+<li>
+Command [[linethickness]] should be used to set the thickness of lines.
+</li>
+<li>
+The [[paper]] command sets the paper scale, size, axes, etc. The most
+general format of the command follows:
+<center>
+<tt>paper{units(mm), xrange(0,120), yrange(0,100),axes(LRTB)}</tt>
+</center>
+Note, that one may opt not to write the commas between the different
+parts of command.
+</li>
+<li>
+Command [[point*]] allocates <i>new</i> co-ordinates and optionally
+a T<sub>E</sub>X point-name, to an existing point-name.
+Command [[point]] allocates co-ordinates and, optionally a T<sub>E</sub>X
+point character, to a <i>new</i> point-name. Since, both commands have
+identical syntax, we handle them together.
+</li>
+<li> Command [[PointSymbol]] is used to set or reset the default
+point symbol, i.e., when one plots a point this is the symbol that will
+appear on the final DVI/PostScript file.
+</li>
+<li>
+In the original DOS version of <tt>mathspic</tt> the command
+[[setPointNumber]] was used to set the length of the arrays that keep the
+various point related information. Since, in Perl arrays are dynamic objects
+and one can push as many objects as he/she wants, the command is implemented
+as an no-op. For reasons of compatibility, we only check the syntax of the
+command.
+</li>
+<li>
+Commands [[showAngle]] and [[showArea]] can be used to get
+the angle or the area determined by three points. In addition, the command
+[[showLenght]] can be used to get the length between two points. These three
+commands produce a comment to the output file.
+</li>
+<li> The [[system]] command provides a shell escape.
+</li>
+<li>
+The [[text]] command is used to put a symbol/text at a
+particular point location.
+</li>
+<li>
+Command [[var]] is used to store a numeric value into a comma separated
+list of variables.
+</li>
+<li>
+Command [[const]] is used to store a numeric value into a comma separated
+list of variables, whose value cannot be altered.
+</li>
+<li>
+If a line starts with a backslash, [[\]], then we copy verbatim this
+line to the output file. In case the second character is a space character,
+then we simply output a copy of the line without the leading backslash.
+</li>
+</ul>
+Empty lines are always ignored.
+
+<<process input line>>=
+
+ if (/^\s*%/)
+ {
+ print OUT "$_" if $comments_on;
+ }
+ elsif (s/^\s*(beginloop(?=\W))//i) {
+ s/\s+//;
+ my $times = expr($lc);
+ print OUT "%% BEGINLOOP $times\n" if $comments_on;
+ my @C = ();
+ REPEATCOMMS: while (<$INFILE>) {
+ if (/^\s*endloop/i) {
+ last REPEATCOMMS;
+ }
+ else {
+ push @C, $_;
+ }
+ }
+ if (! /^\s*endloop/i) {
+ PrintFatalError("unexpected end of file",$lc);
+ }
+ else {
+ s/^\s*endloop//i;
+ for(my $i=1; $i<=$times; $i++) {
+ tie *DUMMY, 'DummyFH', \@C;
+ process_input(DUMMY, $currInFile);
+ untie *DUMMY;
+ }
+ print OUT "%% ENDLOOP\n" if $comments_on;
+ }
+ }
+ elsif (s/^\s*(ArrowShape(?=\W))//i)
+ {
+ my $cmd = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ <<process <tt>ArrowShape</tt> command>>
+ }
+ elsif (s/^\s*(const(?=\W))//i)
+ {
+ print OUT "%% $1$_" if $comments_on;
+ <<process <tt>const</tt> command>>
+ }
+ elsif (s/^\s*(dasharray(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ <<process <tt>dasharray</tt> command>>
+ }
+ elsif (s/^\s*(drawAngleArc(?=\W))//i or s/^\s*(drawAngleArrow(?=\W))//i )
+ {
+ my $cmd = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ <<process <tt>drawAngleArcOrArrow</tt> command>>
+ }
+ elsif (s/^\s*(drawArrow(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ DrawLineOrArrow(0,$lc);
+ }
+ elsif (s/^\s*(drawcircle(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ <<process <tt>drawcircle</tt> command>>
+ }
+ elsif (s/^\s*(drawcurve(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ DrawLineOrArrow(2,$lc);
+ }
+ elsif (s/^\s*(drawcircumcircle(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ <<process <tt>drawcircumcircle</tt> command>>
+ }
+ elsif (s/^\s*(drawexcircle(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ <<process <tt>drawexcircle</tt> command>>
+ }
+ elsif (s/^\s*(drawincircle(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ <<process <tt>drawincircle</tt> command>>
+ }
+ elsif (s/^\s*(drawline(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ DrawLineOrArrow(1,$lc);
+ }
+ elsif (s/^\s*(drawthickarrow(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ print OUT "\\setplotsymbol ({\\usefont{OT1}{cmr}{m}{n}\\large .})%\n";
+ print OUT "{\\setbox1=\\hbox{\\usefont{OT1}{cmr}{m}{n}\\large .}%\n";
+ print OUT " \\global\\linethickness=0.31\\wd1}%\n";
+ DrawLineOrArrow(0,$lc);
+ print OUT "\\setlength{\\linethickness}{0.4pt}%\n";
+ print OUT "\\setplotsymbol ({\\usefont{OT1}{cmr}{m}{n}\\tiny .})%\n";
+ }
+ elsif (s/^\s*(drawthickline(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ print OUT "\\setplotsymbol ({\\usefont{OT1}{cmr}{m}{n}\\large .})%\n";
+ print OUT "{\\setbox1=\\hbox{\\usefont{OT1}{cmr}{m}{n}\\large .}%\n";
+ print OUT " \\global\\linethickness=0.31\\wd1}%\n";
+ DrawLineOrArrow(1,$lc);
+ print OUT "\\setlength{\\linethickness}{0.4pt}%\n";
+ print OUT "\\setplotsymbol ({\\usefont{OT1}{cmr}{m}{n}\\tiny .})%\n";
+ }
+ elsif (s/^\s*(drawperpendicular(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ <<process <tt>drawPerpendicular</tt> command>>
+ }
+ elsif (s/^\s*(drawpoint(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ <<process <tt>drawpoint</tt> command>>
+ }
+ elsif (s/^\s*(drawRightAngle(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ <<process <tt>drawRightAngle</tt> command>>
+ }
+ elsif (s/^\s*(drawsquare(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ <<process <tt>drawsquare</tt> command>>
+ }
+ elsif (s/^\s*inputfile\*//i)
+ {
+ <<process <tt>inputfile*</tt> command>>
+ }
+ elsif (s/^\s*(inputfile(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ <<process <tt>inputfile</tt> command>>
+ }
+ elsif (s/^\s*(linethickness(?=\W))//i)
+ {
+ my $cmd = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ <<process <tt>linethickness</tt> command>>
+ }
+ elsif (s/^\s*(paper(?=\W))//i)
+ {
+ my ($cmd) = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ <<process <tt>paper</tt> command>>
+ }
+ elsif (s/^\s*(PointSymbol(?=\W))//i)
+ {
+ my $cmd = $1;
+ print OUT "%% $cmd$_" if $comments_on;
+ <<process <tt>PointSymbol</tt> command>>
+ }
+ elsif (s/^\s*point(?=\W)//i)
+ {
+ my ($Point_Line);
+ chomp($Point_Line=$_);
+ <<process <tt>point/point*</tt> commands>>
+ }
+ elsif (/^\s*setPointNumber(?=\W)/i)
+ {
+ PrintWarningMessage("Command setPointNumber is ignored",$lc);
+ next LINE;
+ }
+ elsif (s/^\s*(showAngle(?=\W))//i)
+ {
+ <<process <tt>showAngle</tt> command>>
+ }
+ elsif (s/^\s*(showArea(?=\W))//i)
+ {
+ <<process <tt>showArea</tt> command>>
+ }
+ elsif (s/^\s*(showLength(?=\W))//i)
+ {
+ <<process <tt>showLength</tt> command>>
+ }
+ elsif (/^\s*showPoints(?=\W)/i)
+ {
+ print OUT "%%-------------------------------------------------\n";
+ print OUT "%% L I S T O F P O I N T S \n";
+ print OUT "%%-------------------------------------------------\n";
+ foreach my $p (keys(%PointTable)) {
+ my ($x, $y, $pSV, $pS) = unpack("d3A*",$PointTable{$p});
+ printf OUT "%%%%\t%s\t= ( %.5f, %.5f ), LF-radius = %.5f, symbol = %s\n",
+ $p, $x, $y, $pSV, $pS;
+ }
+ print OUT "%%-------------------------------------------------\n";
+ print OUT "%% E N D O F L I S T O F P O I N T S \n";
+ print OUT "%%-------------------------------------------------\n";
+ next LINE;
+ }
+ elsif (/^\s*showVariables(?=\W)/i)
+ {
+ print OUT "%%-------------------------------------------------\n";
+ print OUT "%% L I S T O F V A R I A B L E S \n";
+ print OUT "%%-------------------------------------------------\n";
+ foreach my $var (keys(%VarTable)) {
+ print OUT "%%\t", $var, "\t=\t", $VarTable{$var}, "\n";
+ }
+ print OUT "%%-------------------------------------------------\n";
+ print OUT "%% E N D O F L I S T O F V A R I A B L E S \n";
+ print OUT "%%-------------------------------------------------\n";
+ next LINE;
+ }
+ elsif (s/^\s*(system(?=\W))//i)
+ {
+ print OUT "%% $1$_" if $comments_on;
+ <<process <tt>system</tt> command>>
+ }
+ elsif (s/^\s*(text(?=\W))//i)
+ {
+ print OUT "%% $1$_" if $comments_on;
+ <<process <tt>text</tt> command>>
+ }
+ elsif (s/^\s*(var(?=\W))//i)
+ {
+ print OUT "%% $1$_" if $comments_on;
+ <<process <tt>var</tt> command>>
+ }
+ elsif (/^\s*\\(.+)/)
+ {
+ my $line = $1;
+ if ($line =~ /^\s+(.+)/)
+ {
+ print OUT " $line\n";
+ }
+ else
+ {
+ print OUT "\\$line\n";
+ }
+ next LINE;
+ }
+ elsif (0==length) #empty line
+ {
+ next LINE;
+ }
+ else {
+ PrintErrorMessage("command not recognized",$lc);
+ next LINE;
+ }
+
+@ Command [[dasharray]] takes an arbitrary number of arguments that are used to
+specify a dash pattern. Its general syntax follows:
+<center>
+ <tt> "dasharray" "(" d<sub>1</sub> "," g<sub>1</sub> "," d<sub>2</sub> ","
+ g<sub>2</sub> "," ... ")"</tt>
+</center>
+where <tt>d<sub>i</sub></tt> denotes the length of a dash and <tt>g<sub>i</sub></tt>
+denotes the length of gap between two consecutive dashes. Each <tt>d<sub>i</sub></tt>
+and <tt>g<sub>i</sub></tt> is a length (i.e., a number accompanied by a length of unit).
+Since we do not a priori know the number of arguments, we push them onto a stack and
+then we produce a command of the form
+<center>
+ <tt> \setdashpattern &lt; d<sub>1</sub>, g<sub>1</sub>, d<sub>2</sub>,
+ g<sub>2</sub>, ...&gt;</tt>
+</center>
+
+<<process <tt>dasharray</tt> command>>=
+ chk_lparen($cmd,$lc);
+ my @DashArray = ();
+ my $dash = "";
+ my $dashpattern = "";
+ PATTERN: while (1) {
+ $dash = sprintf("%.5f", expr($lc));
+ if (s/^\s*($units)//i) {
+ push (@DashArray, "$dash$1");
+ }
+ else {
+ PrintErrorMessage("Did not found unit after expression", $lc);
+ }
+ s/\s*//;
+ if (/^[^,]/) {
+ last PATTERN;
+ }
+ else {
+ s/^,\s*//;
+ }
+ }
+ print OUT "\\setdashpattern <";
+ while (@DashArray) {
+ $dashpattern .= shift @DashArray;
+ $dashpattern .= ",";
+ }
+ $dashpattern =~ s/,$//;
+ print OUT $dashpattern, ">\n";
+ chk_rparen("arguments of $cmd",$lc);
+ chk_comment($lc);
+
+@ The command [[drawAngleArc]] draws an arc in the specified angle, a
+distance <i>radius</i> from the angle. The angle is either <i>internal</i>
+(<= 180 degrees) or <i>external</i> (>180 degrees). The direction of the
+arc is either <i>clockwise</i> or <i>anticlockwise</i>. The command
+[[drawAngleArrow]] draws an arrow just like the command [[drawAngleArc]]
+draws an arc. The syntax of these commands is as follows:
+<pre>
+ cmds ::= ( "drawAngleArc" | "drawAngleArrow" ) args
+ args ::= "{" angle comma radius comma internal comma clockwise "}"
+ angle ::= "angle" "(" three-points ")"
+ radius ::= "radius" "(" distance ")"
+ distance ::= expression
+ internal ::= "internal" | "external"
+ clockwise ::= "clockwise" | "anticlockwise"
+ comma ::= "," | empty
+</pre>
+We first collect all relevant information by parsing the [[args]] and then
+call the either the subroutine [[drawAngleArc]] or the subroutine
+[[drawAngleArrow]] to produce the actual code
+which is then printed into the output file. In order to be able to distinguish
+which command we are dealing with we simply use the variable [[$cmd]].
+We now start parsing the input line. We first check whether there is a
+left curly bracket. Next, we parse the [[angle]], the [[distance]], the
+[[internal]] and the [[clockwise]] parts of the command. Finally, we check
+for right curly bracket and a trailing comment. Depending on
+the value of
+the variable [[$cmd]] we call either the subroutine [[drawAngleArc]] or the
+subroutine [[drawAngleArrow]]. These subroutines return the code that will be
+finally output to the output file.
+
+<<process <tt>drawAngleArcOrArrow</tt> command>>=
+
+ chk_lcb($cmd,$lc);
+ <<process <tt>angle</tt> part of command>>
+ s/^,\s*// or s/\s*//; #parse optional comma
+ <<process <tt>radius</tt> part of command>>
+ s/^,\s*// or s/\s*//; #parse optional comma
+ my $inout = "";
+ if (s/^(internal(?=\W))//i or s/^(external(?=\W))//i) {
+ $inout = $1;
+ }
+ else {
+ PrintErrorMessage("Did not find expected 'internal' specifier", $lc);
+ next LINE;
+ }
+ s/^,\s*// or s/\s*//; #parse optional comma
+ my $direction = "";
+ if (s/^(clockwise(?=\W))//i or s/^(anticlockwise(?=\W))//i) {
+ $direction = $1;
+ }
+ else {
+ PrintErrorMessage("Did not find expected 'direction' specifier", $lc);
+ next LINE;
+ }
+ chk_rcb("arguments of $cmd",$lc);
+ chk_comment($lc);
+ my $code;
+ if (lc($cmd) eq "drawanglearc") {
+ $code = drawAngleArc($P1, $P2, $P3, $radius, $inout, $direction);
+ }
+ else {
+ $code = drawAngleArrow($P1, $P2, $P3, $radius, $inout, $direction);
+ }
+ print OUT $code if $code ne "";
+
+@ We first check whether the first token is the word [[angle]]. In case it
+isn't, this yields an unrecoverable error. In case the expected word is
+there, we check for a left parenthesis. Next, we parse the three points that
+must follow. For this purpose we use the user-defined subroutine
+[[get_point]]. Now we check that the angle has a reasonable value, i.e., if
+it is less than -400 or equal to zero, the value yields an unrecoverable error.
+We finish by checking whether there is a right parenthesis.
+
+<<process <tt>angle</tt> part of command>>=
+ my ($P1, $P2, $P3);
+ if (s/^angle(?=\W)//i) {
+ chk_lparen("token angle of command $cmd",$lc);
+ $P1 = get_point($lc);
+ next LINE if $P1 eq "_undef_";
+ $P2 = get_point($lc);
+ next LINE if $P2 eq "_undef_";
+ $P3 = get_point($lc);
+ next LINE if $P3 eq "_undef_";
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$P1});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$P2});
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$P3});
+ my $Angle = Angle($x1, $y1, $x2, $y2, $x3, $y3);
+ if ($Angle <= 0) {
+ if ($Angle == 0) {
+ PrintErrorMessage("Angle is equal to zero",$lc);
+ next LINE;
+ }
+ elsif ($Angle < -400) {
+ PrintErrorMessage("Something is wrong with the points",$lc);
+ next LINE;
+ }
+ }
+ chk_rparen("angle part of command $cmd",$lc);
+ }
+ else {
+ PrintErrorMessage("Did not find expected angle part",$lc);
+ next LINE;
+ }
+
+@ In this section we parse the [[radius]] part of the [[drawAngleArc]] or the
+[[drawAngleArrow]] command. We first check whether the next token is the word
+[[radius]]. If it is not, then we continue with the next line.
+
+<<process <tt>radius</tt> part of command>>=
+
+ my $radius;
+ if (s/^radius(?=\W)//i) {
+ chk_lparen("token radius of command $cmd",$lc);
+ $radius = expr($lc);
+ chk_rparen("radius part of command $cmd",$lc);
+ }
+ else {
+ PrintErrorMessage("Did not found expected angle part",$lc);
+ next LINE;
+ }
+
+@ Command [[drawcircle]] accepts two arguments--a point name that is
+used to specify the center of the circle and the radius of the circle.
+The radius is simply an expression, whose value must be greater than zero.
+Otherwise, we print an error message and continue with the next input line.
+The general syntax of the command is as follows:
+<pre>
+ "drawcircle" "(" point-name "," rad ")"
+</pre>
+The code we emit for a point with coordinates [[x]] and [[y]] and for radius
+equal to [[R]] is:
+<pre>
+ \circulararc 360 degrees from X y center at x y
+</pre>
+where [[X = x+R]].<p>
+Initially, we check whether there is an opening left parenthesis. Next,
+we get the point name by using the subroutine [[get_point]] which
+issues an error message if the point hasn't been defined. In this
+case we stop processing the command, as there is absolutely no reason to
+do otherwise. Next, we parse the comma and then the radius by using
+the subroutine [[ComputeDist]]. If there is no problem, we emit the code
+and finally we check for a closing right parenthesis and for
+possible garbage that may follow the command.
+
+<<process <tt>drawcircle</tt> command>>=
+ chk_lparen("drawcircle",$lc);
+ my $Point = get_point($lc);
+ next LINE if $Point eq "_undef_";
+ chk_comma($lc);
+ my $R = expr($lc);
+ if ($R <= 0) {
+ PrintErrorMessage("Radius must be greater than zero",$lc);
+ next LINE;
+ }
+ my ($x,$y,$pSV,$pS)=unpack("d3A*",$PointTable{lc($Point)});
+ printf OUT "\\circulararc 360 degrees from %.5f %.5f center at %.5f %.5f\n",
+ $x+$R, $y, $x, $y;
+ chk_rparen("arguments of $cmd",$lc);
+ chk_comment($lc);
+
+@ Command [[drawcircumcircle]] is used to draw the circumcircle of triangle
+specified by three points which are the arguments of the command. We start
+by parsing the opening left parenthesis. Next, we get the three points
+that define the triangle. We are now able to compute the center and
+the radius of the circumcircle by calling the subroutine [[circumCircleCenter]].
+If the triangle area is equal to zero, then this subroutine will return
+the array [[(0,0,0)]] to indicate this fact.
+We now have all necessary information to draw the circumcircle. We use the
+following code to do the job:
+<pre>
+ \circulararc 360 degrees from X y center x y
+</pre>
+where [[x]] and [[y]] are the coordinates of the center, [[R]] its
+radius and [[X=x+R]]. What is left is to check whether there is a
+closing right parenthesis and any trailing garbage.
+
+
+<<process <tt>drawcircumcircle</tt> command>>=
+ chk_lparen("drawcircumcircle",$lc);
+ my $point1 = get_point($lc);
+ next LINE if $point1 eq "_undef_";
+ my $point2 = get_point($lc);
+ next LINE if $point2 eq "_undef_";
+ my $point3 = get_point($lc);
+ next LINE if $point3 eq "_undef_";
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point1});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point2});
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point3});
+ my ($xc, $yc,$r) = circumCircleCenter($x1,$y1,$x2,$y2,$x3,$y3,$lc);
+ next LINE if $xc == 0 and $yc == 0 and $r == 0;
+ print OUT "%% circumcircle center = ($xc,$yc), radius = $r\n" if $comments_on;
+ printf OUT "\\circulararc 360 degrees from %.5f %.5f center at %.5f %.5f\n",
+ $xc+$r, $yc, $xc, $yc;
+ chk_rparen("arguments of $cmd",$lc);
+ chk_comment($lc);
+
+@ The syntax of the [[drawexcircle]] command is as follows:
+<pre>
+ drawexcircle ::= "drawexcircle" "(" ThreePoints "," TwoPoints ")"
+ [ modifier ]
+ modifier ::= "[" expr "]"
+
+</pre>
+The [[modifier]] is an expression that is used to modify the radius of the
+excicle. We start by checking whether there is a left parenthesis. Then we
+get names of the three points. In case any of the points is not defined
+we issue an error message and continue with the next input line. Next, we
+check whether there is a comma that separates the three points defining the
+triangle from the two points defining a side of the triangle (variables
+[[$point1]], [[$point2]], and [[$point3]]). Moreover, we must ensure that
+the area of the area defined by these points is not equal to
+zero. If it is we issue an error message and we continue with the next
+input line. Now, we are ready to get the two
+point names that define the side of the triangle (variables [[$point3]] and
+[[$point5]]). At this point we must make sure that these points are different
+points and that they are members of the list of points that define the triangle.
+We make this check by calling the subroutine [[memberOf]]. Next, we check
+whether there is a closing right parenthesis. We now compute the center
+and the radius of the excircle by calling the subroutine [[excircle]]. The
+coordinates of the center are stored in the variables [[$xc]] and [[$yc]],
+while the radius is stored in the variable [[$r]]. If the next
+non-blank input character is a left square bracket, then we know the user has
+specified the optional part. We use the subroutine [[expr]] to get the value of
+the optional part. The value of the optional part is stored in the variable [[$R]].
+At this point we check whether the sum of the radius
+plus the optional part is equal to zero and if it is we continue with the
+next input line. Next, we check for a closing right square bracket. We are
+now ready to emit the source code. The first thing we must check is that
+the radius is not too big for PiCTeX, i.e., not greater than 500/2.845.
+Then we print some informative text to the output file and of course the
+actual code. We use the following code to do the job:
+<pre>
+ \circulararc 360 degrees from (xc+R) yc center xc yc
+</pre>
+The last thing we check is whether there is some trailing garbage.
+
+<<process <tt>drawexcircle</tt> command>>=
+ chk_lparen("drawexcircle",$lc);
+ my $point1 = get_point($lc);
+ next LINE if $point1 eq "_undef_";
+ my $point2 = get_point($lc);
+ next LINE if $point2 eq "_undef_";
+ my $point3 = get_point($lc);
+ next LINE if $point3 eq "_undef_";
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point1});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point2});
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point3});
+ if (triangleArea($x1, $y1, $x2, $y2, $x3, $y3) < 0.0001) {
+ PrintErrorMessage("Area of triangle is zero!",$lc);
+ next LINE;
+ }
+ chk_comma($lc);
+ my $point4 = get_point($lc);
+ if (!memberOf($point4, $point1, $point2, $point3)) {
+ PrintErrorMessage("Current point isn't a side point",$lc);
+ next LINE;
+ }
+ next LINE if $point4 eq "_undef_";
+ my $point5 = get_point($lc);
+ next LINE if $point5 eq "_undef_";
+ if (!memberOf($point5, $point1, $point2, $point3)) {
+ PrintErrorMessage("Current point isn't a side point",$lc);
+ next LINE;
+ }
+ if ($point4 eq $point5) {
+ PrintErrorMessage("Side points are identical",$lc);
+ next LINE;
+ }
+ chk_rparen("arguments of $cmd",$lc);
+ my ($xc, $yc, $r) = excircle($point1, $point2, $point3,
+ $point4, $point5);
+ my $R=$r;
+ if (s/^\s*\[\s*//) {
+ $R += expr($lc);
+ if ($R < 0.0001) {
+ PrintErrorMessage("Radius has become equal to zero!",$lc);
+ next LINE;
+ }
+ chk_rsb($lc);
+ }
+ if ($R > (500 / 2.845)) {
+ PrintErrorMessage("Radius is greater than 175mm!",$lc);
+ next LINE;
+ }
+ print OUT "%% excircle center = ($xc,$yc) radius = $R\n" if $comments_on;
+ printf OUT "\\circulararc 360 degrees from %.5f %.5f center at %.5f %.5f\n",
+ $xc+$R, $yc, $xc, $yc;
+ chk_comment($lc);
+
+@ The syntax of the [[drawincircle]] command is as follows:
+<pre>
+ drawincircle ::= "drawincircle" "(" ThreePoints ")" [ modifier]
+ modifier ::= "[" expr "]"
+</pre>
+where [[ThreePoints]] correspond to the points defining the triangle and
+[[modifier]] is an optional modification factor.
+The first thing we do is to check whether
+there is an opening left parenthesis. Then we get the names of the three
+points that define the triangle (variables [[$point1]], [[$point2]],
+and [[$point3]]). Next, we make sure that the area of the
+triangle defined by these three points is not equal to zero. If it is, then
+we issue an error message and continue with the next input line. Now, we
+compute the center and the radius of the incircle (variables [[$xc]], [[$yc]],
+and [[$r]]). If the next non-blank input character is a left square bracket,
+then we now the user has specified the optional part. We use subroutine
+[[expr]] to get the value of the optional part. The value of
+the optional part
+is stored in the variable [[$R]]. At this point we check whether the sum of the
+radius plus the optional part is equal to zero and if it is we continue with
+the next input line. Next, we check for a closing right square bracket.
+We are now ready to emit the source code. The first thing we must check is
+that the radius is not too big for PiCTeX, i.e., not greater than 500/2.845.
+Then we print some informative text to the output file and of course the
+actual code. We use the following code to do the job:
+<pre>
+ \circulararc 360 degrees from (xc+R) yc center xc yc
+</pre>
+The last thing we check is whether there is some trailing garbage.
+
+<<process <tt>drawincircle</tt> command>>=
+ chk_lparen("drawincircle",$lc);
+ my $point1 = get_point($lc);
+ next LINE if $point1 eq "_undef_";
+ my $point2 = get_point($lc);
+ next LINE if $point2 eq "_undef_";
+ my $point3 = get_point($lc);
+ next LINE if $point3 eq "_undef_";
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point1});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point2});
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point3});
+ if (triangleArea($x1, $y1, $x2, $y2, $x3, $y3) < 0.0001) {
+ PrintErrorMessage("Area of triangle is zero!",$lc);
+ next LINE;
+ }
+ my ($xc, $yc, $r) = IncircleCenter($x1,$y1,$x2,$y2,$x3,$y3);
+ my $R=$r;
+ if (s/^\s*\[\s*//) {
+ $R += expr($lc);
+ if ($R < 0.0001) {
+ PrintErrorMessage("Radius has become equal to zero!",$lc);
+ next LINE;
+ }
+ chk_rsb($lc);
+ }
+ if ($R > (500 / 2.845)) {
+ PrintErrorMessage("Radius is greater than 175mm!",$lc);
+ next LINE;
+ }
+ print OUT "%% incircle center = ($xc,$yc) radius = $R\n" if $comments_on;
+ printf OUT "\\circulararc 360 degrees from %.5f %.5f center at %.5f %.5f\n",
+ $xc+$R, $yc, $xc, $yc;
+ chk_rparen("arguments of $cmd",$lc);
+ chk_comment($lc);
+
+@ The command [[drawPerpendicular]] command draws a line from point A to line
+BC, such that it is perpendicular to line BC. The general syntax of the
+command is as follows:
+<pre>
+ drawPenpedicular ::= "drawPenpedicular" "(" Point "," TwoPoints ")"
+</pre>
+The first thing we do is to parse the left parenthesis. Then we parse
+the name of the first point, namely [[$A$]]. If this point is undefined
+we print an error message and continue with the next line. Next, we parse
+the expected leading comma and the names of the other two points. Certainly,
+in case either of these two points has not been defined, we simply print an
+error message and continue with the next input line. Finally, we check for
+a closing right parenthesis and a possible trailing comment. Now we are
+ready to compute the coordinates of the foot of the
+perpendicular line. We do so my calling subroutine
+[[perpendicular]]. Certainly, before we do this we have to get the
+coordinates of the points that we have parsed. Finally, we output the
+PiCTeX code:
+<pre>
+ \plot x1 y1 xF xY /
+</pre>
+where [[x1]] and [[y1]] are coordinates of the point A and [[xF]] and [[yF]]
+the coordinates of the foot.
+
+<<process <tt>drawPerpendicular</tt> command>>=
+
+ chk_lparen($cmd,$lc);
+ my $A = get_point($lc);
+ next LINE if $A eq "_undef_";
+ chk_comma($lc);
+ my $B = get_point($lc);
+ next LINE if $A eq "_undef_";
+ s/\s*//; #ignore white space
+ my $C = get_point($lc);
+ next LINE if $A eq "_undef_";
+ chk_rparen("arguments of $cmd",$lc);
+ chk_comment($lc);
+ #
+ #start actual computation
+ #
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$A});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$B});
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$C});
+ my ($xF, $yF) = perpendicular($x1, $y1, $x2, $y2, $x3, $y3);
+ printf OUT "\\plot %.5f %.5f %.5f %.5f /\n",
+ $x1, $y1, $xF, $yF;
+
+@ The [[drawpoint]] command has a number of points as arguments and produces
+PiCTeX code that draws a plot symbol at the coordinates of each point. The
+syntax of the command is as follows:
+<pre>
+ drawpoint ::= "drawpoint" "(" Point { separator Point } ")"
+</pre>
+The [[while]] loop is used to consume all points that are
+between an opening left parenthesis and a closing right parenthesis. All
+points are pushed on the local array [[PP]]. When we have parsed the lists
+of points, we call the subroutine [[drawpoints]] to emit the actual PiCTeX code.
+Finally, we check whether there is a closing parenthesis
+parenthesis, and whether
+there is some trailing text that makes no sense. In case there are no points
+between the parentheses, then we issue an appropriate error message and
+we continue with the next input line.
+
+<<process <tt>drawpoint</tt> command>>=
+ my ($stacklen);
+ chk_lparen("$cmd",$lc);
+ if (/^\)/) {
+ PrintErrorMessage("There are no point to draw",$lc);
+ next LINE;
+ }
+ my(@PP);
+ DRAWPOINTS:while(1) {
+ if (s/^([^\W\d_]\d{0,4})//i) { #point name
+ $P = $1;
+ if (!exists($PointTable{lc($P)})) {
+ PrintErrorMessage("Undefined point $P",$lc);
+ next DRAWPOINTS;
+ }
+ else {
+ push (@PP,$P);
+ s/\s*//;
+ }
+ }
+ else {
+ last DRAWPOINTS;
+ }
+ }
+ drawpoints(@PP);
+ chk_rparen("arguments of $cmd",$lc);
+ chk_comment($lc);
+
+@ The syntax of the [[drawRightAngle]] command is as follows:
+<pre>
+ drawRightAngle "(" ThreePoints "," dist ")"
+ dist ::= expr | TwoPoints
+</pre>
+Before we proceed with the actual computation we parse the left parenthesis,
+the three points, the comma, the [[dist]], and the right parenthesis. In case
+we have neither three points nor a [[dist]] we print an error message and
+continue with the next input line, i.e., these errors are irrecoverable.
+The names of the three points are stored in variables [[$point1]],
+[[$point2]], and [[$point3]]. The value of the distance is stored
+in the variable [[$dist]].
+Let's now explain the semantics of this command.<p>
+
+Our aim is to draw lines S<sub>1</sub>-S, S<sub>2</sub>-S (S<sub>1</sub>
+and S<sub>2</sub> are at distance d from B). All the relevant points are
+depicted in the following figure:
+<center>
+<img src="fig1.jpg">
+</center>
+Some notes are in order:
+<ol>
+<li> BS bisects angle ABC, and meets AC in Q, so start by determining point
+Q, then determine S, and then S<sub>1</sub> and S<sub>2</sub>, and then
+draw S<sub>1</sub>-S and S<sub>2</sub>-S.</li>
+<li> Distance AQ is given by AC/(1+tan(BCA))</li>
+<li> The coordinates of Q are computed using the subroutine [[pointOnLine]].</li>
+<li> Now we compute the coordinates of S on line BQ.</li>
+<li> We compute the coordinates of S<sub>1</sub> and S<sub>2</sub> by using
+The subroutine [[pointOnLine]].</li>
+</ol>
+In order to implement the above steps we first compute the length of the line
+AB. Note that A is [[$point1]], etc. Next we compute the angle BAC. Now
+we compute the distance AQ (variable [[$line1]]). The coordinates of point
+Q are stored in variables [[$xQ]] and [[$yQ]]. The coordinates of point
+S are stored in variables [[$xS]] and [[$yS]]. Now we have to determine the
+coordinates of points S<sub>1</sub> and S<sub>2</sub>. These coordinates
+are stored in variables [[$xS1]], [[$yS1]] and [[$xS2]], [[$yS2]],
+respectively. Finally, we emit the PiCTeX target code.
+
+<<process <tt>drawRightAngle</tt> command>>=
+
+ chk_lparen("drawRightAngle",$lc);
+ my $point1 = get_point($lc);
+ next LINE if $point1 eq "_undef_";
+ my $point2 = get_point($lc);
+ next LINE if $point2 eq "_undef_";
+ my $point3 = get_point($lc);
+ next LINE if $point3 eq "_undef_";
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point1});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point2});
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point3});
+ chk_comma($lc);
+ my $dist = expr($lc);
+ chk_rparen("arguments of $cmd",$lc);
+ chk_comment($lc);
+ #
+ #actual computation
+ #
+ my ($Px, $Py) = pointOnLine($x2, $y2, $x1, $y1, $dist);
+ my ($Qx, $Qy) = pointOnLine($x2, $y2, $x3, $y3, $dist);
+ my ($Tx, $Ty) = midpoint($Px, $Py, $Qx, $Qy);
+ my ($Ux, $Uy) = pointOnLine($x2, $y2, $Tx, $Ty, 2*Length($x2, $y2, $Tx, $Ty));
+ if ($Px == $Ux || $Py == $Uy) {
+ printf OUT "\\putrule from %.5f %.5f to %.5f %.5f \n", $Px,$Py,$Ux,$Uy;
+ }
+ else {
+ printf OUT "\\plot %.5f %.5f\t%.5f %.5f / \n", $Px, $Py,$Ux,$Uy;
+ }
+ if ($Ux == $Qx || $Uy == $Qy) {
+ printf OUT "\\putrule from %.5f %.5f to %.5f %.5f \n", $Ux,$Uy,$Qx,$Qy;
+ }
+ else {
+ printf OUT "\\plot %.5f %.5f\t%.5f %.5f / \n", $Ux, $Uy,$Qx,$Qy;
+ }
+
+
+@ The command [[drawsquare]] has two arguments: a point, which specifies the
+coordinates of the point where the square will be placed, and a number, which
+specifies the length of the side of the square. The syntax of the command is as follows:
+<center>
+ <tt> "drawSquare" "(" Point "," expression ")" </tt>
+</center>
+Note that RWDN has suggested to alter the value of the [[$side]] variable (see the
+line with [[RWDN]] comment).
+
+<<process <tt>drawsquare</tt> command>>=
+ chk_lparen("drawSquare",$lc);
+ my $p = get_point($lc);
+ chk_comma($lc);
+ my $side = expr($lc);
+ $side = $side - (1.1 * $LineThickness/$xunits); #Suggested by RWDN
+ my ($x,$y,$pSV,$pS) = unpack("d3A*",$PointTable{$p});
+ printf OUT "\\put {%s} at %.5f %.5f %%drawsquare\n", drawsquare($side), $x, $y;
+ chk_rparen("arguments of $cmd",$lc);
+ chk_comment($lc);
+
+@ The argument of the [[inputfile*]] command is a file name that is always
+enclosed in parentheses:
+<pre>
+ starred-input-file ::= "inputfile*" "(" file-name ")"
+ file-name ::= (alpha | period) { alpha | period }
+ alpha ::= letter | digit | "_" | "-"
+</pre>
+Note, that the input file is assumed to contain TeX code.
+We first check to see if there is a left parenthesis. Then we consume
+the file name. We check if the file exists and then we copy verbatim the
+input file to the output file. Next, we check for the closing parenthesis.
+Now, if there is a trailing comment we copy it to the output file depending
+on the value of the variable [[$comments_on]], else if there is some other
+text we simply ignore it and issue a warning message.
+
+<<process <tt>inputfile*</tt> command>>=
+ chk_lparen("inputfile*",$lc);
+ my $row_in = "";
+ if (s/^((\w|-|\.)+)//) {
+ $row_in = $1;
+ }
+ else {
+ PrintErrorMessage("No input file name found",$lc);
+ next LINE;
+ }
+ if (!(-e $row_in)) {
+ PrintErrorMessage("File $row_in does not exist",$lc);
+ next LINE;
+ }
+ open(ROW, "$row_in")|| die "Can't open file $row_in\n";
+ while (defined($in_line=<ROW>)) { print OUT $in_line; }
+ print OUT "%% ... end of input file <$row_in>\n";
+ close ROW;
+ chk_rparen("input file name",$lc);
+ chk_comment($lc);
+
+
+@ The [[inputfile]] command has at most two arguments, second being
+optional: a file name enclosed in curly brackets and the number of
+times this file should be included in square brackets:
+<pre>
+ inputfile ::= "inputfile" "(" file-name ")" [ Times ]
+ Times ::= "[" expr "]"
+</pre>
+Note that the input file is assumed to contain mathspic commands. In addition, if
+the expression is equal to a decimal number, it is truncated.
+As in the case of the [[inputfile*]] command we parse the left parenthesis,
+the file name, the right parenthesis and the optional argument if it exists.
+In order to process the commands contained in the input file, we call
+The subroutine [[process_input]].
+
+<<process <tt>inputfile</tt> command>>=
+
+ chk_lparen("inputfile",$lc);
+ my $comm_in = "";
+ if (s/^((\w|-|\.)+)//) {
+ $comm_in = $1;
+ }
+ else {
+ PrintErrorMessage("No input file name found",$lc);
+ next LINE;
+ }
+ if (!(-e $comm_in)) {
+ PrintErrorMessage("File $comm_in does not exist",$lc);
+ next LINE;
+ }
+ chk_rparen("input file name",$lc);
+ my $input_times = 1; #default value
+ if (s/^\[//) {
+ $input_times = expr($lc);
+ chk_rsb("optional argument",$lc);
+ }
+ print OUT "%% ... start of file <$comm_in> loop [$input_times]\n";
+ for (my $i=0; $i<int($input_times); $i++) {
+ open(COMM,"$comm_in") or die "Can't open file $comm_in\n";
+ print OUT "%%% Iteration number: ",$i+1,"\n";
+ my $old_file_name = $curr_in_file;
+ process_input(COMM,"File $comm_in, ");
+ $curr_in_file = $old_file_name;
+ close COMM;
+ }
+ print OUT "%% ... end of file <$comm_in> loop [$input_times]\n";
+ chk_comment($lc);
+
+@ The [[linethickness]] command should be used to set the thickness of lines.
+The command has one argument, which is a length or the word [[default]].
+The default line thickness is 0.4 pt.
+
+<<process <tt>linethickness</tt> command>>=
+ chk_lparen("linethickness", $lc);
+ if (s/^default//i) {
+ print OUT "\\linethickness=0.4pt\\Linethickness{0.4pt}%%\n";
+ print OUT "\\setplotsymbol ({\\usefont{OT1}{cmr}{m}{n}\\tiny .})%\n";
+ $LineThickness = setLineThickness($xunits,"0.4pt");
+ }
+ else {
+ my $length = expr($lc);
+ if (s/^\s*($units)//i) {
+ my $units = $1;
+ printf OUT "\\linethickness=%.5f%s\\Linethickness{%.5f%s}%%\n",
+ $length, $units, $length, $units;
+ $LineThickness = setLineThickness($xunits,"$length$units");
+ my $mag;
+ if ($units eq "pc") {
+ $mag = $length * 12;
+ }
+ elsif ($units eq "in") {
+ $mag = $length * 72.27;
+ }
+ elsif ($units eq "bp") {
+ $mag = $length * 1.00375;
+ }
+ elsif ($units eq "cm") {
+ $mag = $length * 28.45275;
+ }
+ elsif ($units eq "mm") {
+ $mag = $length * 2.845275;
+ }
+ elsif ($units eq "dd") {
+ $mag = $length * 1.07001;
+ }
+ elsif ($units eq "cc") {
+ $mag = $length * 0.08917;
+ }
+ elsif ($units eq "sp") {
+ $mag = $length * 0.000015259;
+ }
+ elsif ($units eq "pt") {
+ $mag = $length;
+ }
+ $mag = 10 * $mag / 1.00278219;
+ printf OUT "\\font\\CM=cmr10 at %.5fpt%%\n", $mag;
+ print OUT "\\setplotsymbol ({\\CM .})%\n";
+ }
+ else {
+ PrintErrorMessage("Did not found expect units part",$lc);
+ }
+ }
+ chk_rparen("linethickness", $lc);
+ chk_comment($lc);
+
+
+@ We first output the input line as a comment into the output file. Now,
+after the [[paper]] token we look for an opening brace. Then we process
+the [[units]] part of the command, if the token [[units]] is present. Note
+that the [[units]] part is optional. Next we process the [[xrange]] and the
+[[yrange]] part of the command, which are also optional parts of the command.
+We are now ready to process the [[axis]] part. Note, that the user is allowed
+to alternatively specify this part with the word [[axes]].
+The variable [[$axis]]
+is supposed to hold the various data relate to the [[axis]] part. The last
+thing we check is the [[ticks]] part. In case the user has not specified
+this part we assume that both ticks are equal to zero. If everything is
+according to the language syntax, we expect a closing right curly bracket.
+Now, that we have all relevant information we can output the rest of the code,
+as some parts of it have already been output during parsing. The last thing we
+do is to check whether there is any trailing comment.
+
+<<process <tt>paper</tt> command>>=
+ chk_lcb("paper", $lc);
+ if (s/^units(?=\W)//i)
+ {
+ <<process <tt>unit</tt> part>>
+ $nounits = 0;
+ }
+ else
+ {
+ $nounits = 1;
+ }
+ s/^,\s*// or s/\s*//;
+ if (s/^xrange//i)
+ {
+ <<process <tt>xrange</tt> part>>
+ $noxrange = 0;
+ }
+ else
+ {
+ $noxrange = 1;
+ }
+ s/^,\s*// or s/\s*//;
+ if (s/^yrange//i)
+ {
+ <<process <tt>yrange</tt> part>>
+ $noyrange = 0;
+ }
+ else
+ {
+ $noyrange = 1;
+ }
+ <<generate plot area related commands>>
+ s/^,\s*// or s/\s*//;
+ $axis = "";
+ if (s/^ax[ei]s(?=\W)//i)
+ {
+ <<process <tt>axis</tt> part>>
+ }
+ $axis = uc($axis);
+ s/^,\s*// or s/\s*//;
+ if (s/^ticks(?=\W)//i)
+ {
+ <<process <tt>ticks</tt> part>>
+ }
+ else
+ {
+ $xticks = $yticks = 0;
+ }
+ chk_rcb("paper", $lc);
+ <<generate the rest of the code for the <tt>paper</tt> command>>
+ chk_comment($lc);
+
+@ We first check whether there is a left parenthesis. Next, we check
+whether there is decimal number or a variable name. In case there isn't one we assume it
+is the number 1. Now, we get the units. If there is no valid unit, we issue
+an error and the x-unit is set to its default value. In case, there is
+a trailing comma, we assume the user wants also to specify the y-unit and
+we process this part just like we did with the x-unit part. Finally, we
+output the corresponding PiCTeX command. In case there is no y-unit
+we assume it is equal to the x-unit.
+
+<<process <tt>unit</tt> part>>=
+
+ chk_lparen("units",$lc);
+ if(s/^\)//)
+ {
+ PrintWarningMessage("Missing value in \"units\"--default is 1pt",
+ $lc);
+ $xunits = "1pt";
+ }
+ else {
+ $xunits = expr($lc);
+ s/\s*//;
+ if (s/^($units)//i) {
+ $xunits .= "$1";
+ $LineThickness = setLineThickness($xunits,"0.4pt");
+ }
+ elsif(s/^(\w)+//i) {
+ PrintErrorMessage("$1 is not a valid mathspic unit",$lc);
+ $xunits = "1pt";
+ }
+ else {
+ PrintErrorMessage("No x-units found",$lc);
+ $xunits = "1pt";
+ }
+ s/\s*//; #ignore white space
+ if (s/^,//) { # there is a comma so expect an y-units
+ s/\s*//; #ignore white space
+ $yunits = expr($lc);
+ s/\s*//; #ignore white space
+ if (s/^($units)//i) {
+ $yunits .= "$1";
+ }
+ elsif(s/^(\w)+//i) {
+ PrintErrorMessage("$1 is not a valid mathspic unit",$lc);
+ $yunits = "1pt";
+ }
+ else {
+ PrintErrorMessage("No y-units found",$lc);
+ $yunits = $xunits;
+ }
+ }
+ else {
+ $yunits = $xunits;
+ }
+ chk_rparen("units",$lc);
+ }
+
+@ The [[xrange]] token must be followed by a left parenthesis, so we
+check whether the next token is a left parenthesis. We store in the variables
+[[$xlow]] and [[$xhigh]] the values of the range. The range is specified
+as pair of decimal numbers/variable/pair of points, separated by a
+comma. We use the subroutine [[ComputeDist]] to get the value of the lower
+end and the upper end of the range. The last thing we check is whether
+the lower end is less than the upper end. If this isn't the case we
+issue an error message and we skip into the next input line.
+
+<<process <tt>xrange</tt> part>>=
+
+ chk_lparen("xrange",$lc);
+ my $ec;
+ ($xlow,$ec) = ComputeDist($lc);
+ next LINE if $ec == 0;
+ chk_comma($lc);
+ ($xhigh,$ec) = ComputeDist($lc);
+ next LINE if $ec == 0;
+ if ($xlow >= $xhigh)
+ {
+ PrintErrorMessage("xlow >= xhigh in xrange",$lc);
+ next LINE;
+ }
+ chk_rparen("$xhigh",$lc);
+
+@ The [[yrange]] token must be followed by a left parenthesis, so we
+check whether the next token is a left parenthesis. We store in the variables
+[[$ylow]] and [[$yhigh]] the values of the range. The range is specified
+as pair of decimal numbers/variable/pair of points, separated by a
+comma. We use the subroutine [[ComputeDist]] to get the value of the lower
+end and the upper end of the range. The last thing we check is whether
+the lower end is less than the upper end. If this isn't the case we
+issue an error message and we skip into the next input line.
+
+<<process <tt>yrange</tt> part>>=
+
+ chk_lparen("yrange",$lc);
+ my $ec;
+ ($ylow,$ec) = ComputeDist($lc);
+ next LINE if $ec == 0;
+ chk_comma($lc);
+ ($yhigh,$ec) = ComputeDist($lc);
+ next LINE if $ec == 0;
+ if ($ylow >= $yhigh)
+ {
+ PrintErrorMessage("ylow >= yhigh in yrange",$lc);
+ next LINE;
+ }
+ chk_rparen("$yhigh",$lc);
+
+@ The [[showAngle]] command has three arguments that correspond to three distinct
+points and emits a comment of the form:
+<center>
+<tt>%% angle(ABC) = 45</tt>
+</center>
+Note that the computed angle is expressed in degrees.
+
+<<process <tt>showAngle</tt> command>>=
+ chk_lparen("showangle",$lc);
+ my $point_1 = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_1});
+ my $point_2 = get_point($lc);
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point_2});
+ my $point_3 = get_point($lc);
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point_3});
+ my $angle = Angle($x1, $y1, $x2, $y2, $x3, $y3);
+ $angle = 0 if $angle == -500;
+ printf OUT "%%%% angle(%s%s%s) = %.5f deg ( %.5f rad)\n", $point_1,
+ $point_2, $point_3, $angle, $angle*D2R;
+ chk_rparen("Missing right parenthesis", $lc);
+
+@ The [[showArea]] command has three arguments that correspond to three distinct
+points and emits a comment of the form:
+<center>
+<tt>%% area(ABC) = 45</tt>
+</center>
+Note that the computed angle is expressed in degrees.
+
+<<process <tt>showArea</tt> command>>=
+ chk_lparen("showarea",$lc);
+ my $point_1 = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_1});
+ my $point_2 = get_point($lc);
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point_2});
+ my $point_3 = get_point($lc);
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$point_3});
+ print OUT "%% area($point_1$point_2$point_3) = ",
+ triangleArea($x1, $y1, $x2, $y2, $x3, $y3), "\n";
+ chk_rparen("Missing right parenthesis", $lc);
+
+@ The [[showLength]] command has two arguments that correspond to two distinct
+points and emits a comment of the form:
+<center>
+<tt>%% length(AB) = 45</tt>
+</center>
+Note that the computed angle is expressed in degrees.
+
+<<process <tt>showLength</tt> command>>=
+ chk_lparen("showlength",$lc);
+ my $point_1 = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$point_1});
+ my $point_2 = get_point($lc);
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$point_2});
+ print OUT "%% length($point_1$point_2) = ",
+ Length($x1, $y1, $x2, $y2), "\n";
+ chk_rparen("Missing right parenthesis", $lc);
+
+
+@ If the user hasn't specified units then we use the previous values to
+set the coordinate system. If the user hasn't specified either the
+[[xunits]] part or the [[yunits]], then we don't emit code. In case he/she
+has specified both parts we generate the command that sets the plot area.
+
+<<generate plot area related commands>>=
+
+ if (!$nounits)
+ {
+ printf OUT "\\setcoordinatesystem units <%s,%s>\n",
+ $xunits,$yunits;
+ }
+ if(!$noxrange && !$noyrange)
+ {
+ printf OUT "\\setplotarea x from %.5f to %.5f, y from %.5f to %.5f\n",
+ $xlow, $xhigh, $ylow, $yhigh;
+
+ }
+
+@ We first check to see whether there is an opening left parenthesis. Next
+we get the various options the user may have entered. The valid options
+are the letters L, R, T, B, X, and Y. These letters may be followed by
+an optional star [[*]] with space characters between the letter and the star.
+We use a loop, that stops when a right parenthesis is found, to
+go through all
+possible arguments and append each argument in the string [[$axis]]. Note
+one can have blank space between different arguments. The last thing we do is
+to check for the closing right parenthesis.
+
+<<process <tt>axis</tt> part>>=
+
+ chk_lparen("axis",$lc);
+ while(/^[^\)]/)
+ {
+ if (s/^([lrtbxy]{1}\*?)//i)
+ {
+ $axis .= $1;
+ }
+ elsif (s/^([^lrtbxy])//i)
+ {
+ PrintErrorMessage("Non-valid character \"$1\" in axis()",$lc);
+ }
+ s/\s*//;
+ }
+ chk_rparen("axis(arguments",$lc);
+
+@ As usual we start by skipping white space. Next we check whether there is
+an opening left parenthesis. Now, we expect two numbers/variables/pair of
+point representing the [[ticks]] increment value. These [[ticks]] increment
+values must be separated by a comma (and possibly some white space around
+them). We use the subroutine [[ComputeDist]] to get the value of the [[ticks]]
+increment value and we assign to the variables [[$xticks]] and [[$yticks]]
+the value of x-ticks and y-ticks increment value. In case there is a
+problem we issue an error message and continue with the next line. The last
+thing we check is whether there is a closing right parenthesis.
+
+<<process <tt>ticks</tt> part>>=
+ chk_lparen("ticks",$lc);
+ my $ec;
+ ($xticks,$ec) = ComputeDist($lc);
+ next LINE if $ec == 0;
+ chk_comma($lc);
+ ($yticks,$ec) = ComputeDist($lc);
+ next LINE if $ec == 0;
+ chk_rparen("ticks(arguments",$lc);
+
+@ We actually emit code if the user has specified either the [[X]] or
+[[Y]] option in the [[axis]] part. If the user has specified the
+[[Y*]] or the [[X*]] option in the axis part, we just emit the commands
+[[\axis left shiftedto x=0]] or [[\axis bottom shiftedto y=0]] respectively
+and exit. If the use has specified ticks, then, depending on the options
+he had supplied with the [[axis]] part, we emit code that
+implements the user's wishes.
+**** HERE WE MUST EXPLAIN THE MEANING OF THE CODE EMITTED!!! *****
+
+<<generate the rest of the code for the <tt>paper</tt> command>>=
+YBRANCH: {
+ if (index($axis, "Y")>-1)
+ {
+ if (index($axis, "Y*")>-1)
+ {
+ print OUT "\\axis left shiftedto x=0 / \n";
+ last YBRANCH;
+ }
+ if ($yticks > 0)
+ {
+ if (index($axis, "T")>-1 && index($axis, "B")==-1)
+ {
+ print OUT "\\axis left shiftedto x=0 ticks numbered from ";
+ print OUT "$ylow to -$yticks by $yticks\n from $yticks to ";
+ print OUT $yhigh-$yticks," by $yticks /\n";
+ }
+ elsif (index($axis, "T")==-1 && index($axis, "B")>-1)
+ {
+ print OUT "\\axis left shiftedto x=0 ticks numbered from ";
+ print OUT $ylow+$yticks," to -$yticks by $yticks\n from ";
+ print OUT "$yticks to $yhigh by $yticks /\n";
+ }
+ elsif (index($axis, "T")>-1 && index($axis, "B")>-1)
+ {
+ print OUT "\\axis left shiftedto x=0 ticks numbered from ";
+ print OUT $ylow+$yticks," to -$yticks by $yticks\n from ";
+ print OUT "$yticks to ",$yhigh-$yticks," by $yticks /\n";
+ }
+ else
+ {
+ print OUT "\\axis left shiftedto x=0 ticks numbered from ";
+ print OUT "$ylow to -$yticks by $yticks\n from ";
+ print OUT "$yticks to $yhigh by $yticks /\n";
+ }
+ }
+ else
+ {
+ print OUT "\\axis left shiftedto x=0 /\n";
+ }
+ }
+ }
+ XBRANCH: { if (index($axis, "X")>-1)
+ {
+ if (index($axis, "X*")>-1)
+ {
+ print OUT "\\axis bottom shiftedto y=0 /\n";
+ last XBRANCH;
+ }
+ if ($xticks > 0)
+ {
+ if (index($axis, "L")>-1 && index($axis, "R")==1)
+ {
+ print OUT "\\axis bottom shiftedto y=0 ticks numbered from ";
+ print OUT $xlow + $xticks," to -$xticks by $xticks\n from";
+ print OUT " $xticks to $xhigh by $xticks /\n";
+ }
+ elsif (index($axis, "L")==-1 && index($axis, "R")>-1)
+ {
+ print OUT "\\axis bottom shiftedto y=0 ticks numbered from ";
+ print OUT "$xlow to -$xticks by $xticks\n from ";
+ print OUT "$xticks to ",$xhigh-$xticks," by $xticks /\n";
+ }
+ elsif (index($axis, "L")>-1 && index($axis, "R")>-1)
+ {
+ print OUT "\\axis bottom shiftedto y=0 ticks numbered from ";
+ print OUT $xlow + $xticks," to -$xticks by $xticks\n from ";
+ print OUT "$xticks to ",$xhigh - $xticks," by $xticks /\n";
+ }
+ else
+ {
+ print OUT "\\axis bottom shiftedto y=0 ticks numbered from ";
+ print OUT "$xlow to -$xticks by $xticks\n from ";
+ print OUT "$xticks to $xhigh by $xticks /\n";
+ }
+ }
+ else
+ {
+ print OUT "\\axis bottom shiftedto y=0 /\n";
+ }
+ } }
+ LBRANCH: {if (index($axis, "L")>-1)
+ {
+ if (index($axis, "L")>-1)
+ {
+ if (index($axis, "L*")>-1)
+ {
+ print OUT "\\axis left /\n";
+ last LBRANCH;
+ }
+ if ($yticks > 0)
+ {
+ print OUT "\\axis left ticks numbered from ";
+ print OUT "$ylow to $yhigh by $yticks /\n";
+ }
+ else
+ {
+ print OUT "\\axis left /\n";
+ }
+ }
+ } }
+ RBRANCH: { if (index($axis, "R")>-1)
+ {
+ if (index($axis, "R*")>-1)
+ {
+ print OUT "\\axis right /\n";
+ last RBRANCH;
+ }
+ if ($yticks > 0)
+ {
+ print OUT "\\axis right ticks numbered from $ylow to $yhigh by ";
+ print OUT "$yticks /\n";
+ }
+ else
+ {
+ print OUT "\\axis right /\n";
+ }
+ } }
+ TBRANCH: { if (index($axis, "T")>-1)
+ {
+ if (index($axis, "T*")>-1)
+ {
+ print OUT "\\axis top /\n";
+ last TBRANCH;
+ }
+ if ($xticks > 0)
+ {
+ print OUT "\\axis top ticks numbered from $xlow to $xhigh by ";
+ print OUT "$xticks /\n";
+ }
+ else
+ {
+ print OUT "\\axis top /\n";
+ }
+ } }
+ BBRANCH: { if (index($axis, "B")>-1)
+ {
+ if (index($axis, "B*")>-1)
+ {
+ print OUT "\\axis bottom /\n";
+ last BBRANCH;
+ }
+ if ($xticks > 0)
+ {
+ print OUT "\\axis bottom ticks numbered from $xlow to $xhigh by ";
+ print OUT "$xticks /\n";
+ }
+ else
+ {
+ print OUT "\\axis bottom /\n";
+ }
+ } }
+
+
+@ The syntax of the [[point]] commands follows:
+<pre>
+point[*](PointName){Coordinates}[PointSymbol]
+</pre>
+where [[PointName]] is valid point name, [[Coordinates]] is either a
+pair of numbers denoting the coordinates of the point or an expression
+by means of which the system computes the coordinates of the point, and
+the [[PointSymbol]] is a valid T<sub><font size=+1>E</font></sub>X
+command denoting a point symbol. A valid point name consists of a
+letter and at most two trailing digits. That is, the names [[a11]],
+[[b2]] and [[c]] are valid names while [[qw]] and [[s123]] are not.
+The first thing we do is to set the point shape to the default symbol
+(this has been initialized in the main program). Next, we check whether
+we have a [[point]]command or a [[point*]] simply by inspecting the very
+next token. Note that there must be no blank spaces between the token
+[[point]] and the star symbol. Next, we get the point name: remember that
+the point name is surrounded by parentheses. In case we don't find a valid
+point name we issue an error message and continue with the next line of
+input. Suppose the point name was a valid one. If we have a [[point*]]
+command we must ensure that the this particular point name has been defined.
+If we have a [[point]] command we must ensure that this particular point
+name has not been defined. Point names are stored in the hash [[%PointTable]].
+We are now ready to process the coordinates part and the optional
+plot symbol part.
+
+<<process <tt>point/point*</tt> commands>>=
+ my ($pointStar, $PointName, $origPN);
+ $pointStar = 0; # default value: he have a point command
+ $pointStar = 1 if s/^\*//;
+ chk_lparen("point" . (($pointStar)?"*":""),$lc);
+ if (s/^([^\W\d_](?![^\W\d_])\d{0,4})//i) {
+ #
+ # Note: the regular expression (foo)(?!bar) means that we are
+ # looking a foo not followed by a bar. Moreover, the regular
+ # expression [^\W\d_] means that we are looking for letter.
+ #
+ $origPN = $1;
+ $PointName = lc($1);
+ }
+ else {
+ PrintErrorMessage("Invalid point name",$lc);
+ next LINE;
+ }
+ #if ($pointStar and !exists($PointTable{$PointName})) {
+ # PrintWarningMessage("Point $origPN has not been defined",$lc);
+ #}
+ if (!$pointStar and exists($PointTable{$PointName})) {
+ PrintWarningMessage("Point $origPN has been used already",$lc);
+ }
+ chk_rparen("point" . (($pointStar)?"*":""). "($origPN",$lc);
+ chk_lcb("point" . (($pointStar)?"*":""). "($origPN)",$lc);
+ my ($Px, $Py);
+ <<process coordinates>>
+ chk_rcb("coordinates part",$lc);
+ my $sv = $defaultsymbol;
+ my $sh = $defaultLFradius;
+ my $side_or_radius = undef;
+ if (s/^\[\s*//) { # the user has opted to specify the optional part
+ <<process optional point shape part>>
+ chk_rsb("optional part",$lc);
+ }
+ # to avoid truncation problems introduced by the pack function, we
+ # round each number up to five decimal digits
+ $Px = sprintf("%.5f", $Px);
+ $Py = sprintf("%.5f", $Py);
+ print OUT "%% point$Point_Line \t$origPN = ($Px, $Py)\n" if $comments_on;
+ chk_comment($lc);
+ $PointTable{$PointName} = pack("d3A*",$Px,$Py,$sh,$sv);
+ if (defined($side_or_radius)) {
+ $DimOfPoint{$PointName} = $side_or_radius;
+ }
+
+@ In this section we parse the [[Coordinates]] part of the [[point]] command.
+The complete syntax of the [[Coordinates]] part follows:
+<pre>
+Coordinates ::= Variable |
+ Distance "," Distance |
+ "midpoint" "(" Point-Name Point-Name ")" |
+ "pointOnLine" "(" Two-Points "," Distance ")" |
+ "intersection" "(" Two-Points "," Two-Points ")" |
+ "perpendicular" "(" Point-Name "," Two-Points ")" |
+ "circumCircleCenter" "(" Three-Points ") |
+ "incircleCenter" "(" Three-Points ")" |
+ "excircleCenter" "(" Three-Points "," Two-Points ")" |
+ Point-Name [ "," Modifier ]
+
+Modifier ::= "shift" "(" Distance "," Distance ")" |
+ "polar" "(" Distance, Distance [ "deg" | "rad" ] ")" |
+ "rotate" "(" Point-Name, Distance [ "deg" | "rad" ] ")" |
+ "vector" "(" Two-Points ")"
+
+Distance ::= expression
+
+Two-Points ::= Point-Name Point-Name
+
+Three-Points ::= Point-Name Two-Points
+</pre>
+We now briefly explain the functionality of each option:
+<ul>
+<li>midpoint(AB): the midpoint between points A and B</li>
+<li>pointOnLine(AB,d): point at distance d from A towards B</li>
+<li>intersection(AB,CD): intersection of lines defined by AB and CD</li>
+<li>perpendicular(A,BC): point of the foot of the perpendicular from A to line BC</li>
+<li>circumCircleCenter(ABC): center of circumcircle of triangle ABC</li>
+<li>incircleCenter(ABC):center of incircle of triangle ABC</li>
+<li>excircleCenter(ABC,BC): center of excircle of triangle ABC, touching
+side BC</li>
+<li>A, shift(x,y): Point displaced from A by x and y along the X and Y
+axes</li>
+<li>A, polar(r,d): Point displaced from A by distance r in direction d</li>
+<li>A, rotate(B,d): Rotate A about B by d</li>
+</ul>
+We now explain how the following piece of code operates. In case the first
+token is a number, we assume that the coordinates are specified by a
+number and another number, a variable or a pair of points. So, we check
+whether there is a comma and use the subroutine [[ComputeDist]] to get the
+second coordinate. In case the next token is one of the words
+[[perpendicular]], [[intersection]], [[midpoint]], [[pointonline]],
+[[circumcircleCenter]], [[IncircleCenter]], or [[ExcircleCenter]]
+we consume the corresponding token and process the corresponding case.
+In case the first two tokens are two identifiers, then we assume that we
+have a pair of numbers. We compute their distance, check whether there is
+a leading comma and compute the y-coordinate by calling subroutine
+[[ComputeDist]]. In case the next token is a single identifier, we store
+its name in the variable [[$PointA]]. If this identifier is a defined point name,
+we check whether the next token is a comma. In case it is, we check whether
+he token after the comma is either the token [[shift]], [[polar]], or
+[[rotate]] and process each case accordingly. If it is
+none of these tokens we issue an error message and continue with the next
+input line. Now, if the token after the identifier isn't a comma, we assume
+that the coordinates of the point will be identical to those of the point
+whose name has been stored in the variable [[$PointA]]. If the identifier is a
+variable name, we assume that the x-coordinate is the value of this variable.
+We check whether the next token is a comma, and compute the y-coordinate by
+calling the subroutine [[ComputeDist]]. The x-coordinate is stored in the variable
+[[$Px]] and the y-coordinate in the variable [[$Py]].
+
+<<process coordinates>>=
+ if (s/^perpendicular(?=\W)//i) {
+ <<process <tt>perpendicular</tt> case>>
+ }
+ elsif (s/^intersection(?=\W)//i) {
+ <<process <tt>intersection</tt> case>>
+ }
+ elsif (s/^midpoint(?=\W)//i) {
+ <<process <tt>midpoint</tt> case>>
+ }
+ elsif (s/^pointonline(?=\W)//i) {
+ <<process <tt>pointonline</tt> case>>
+ }
+ elsif (s/^circumcircleCenter(?=\W)//i) {
+ <<process <tt>circumcircleCenter</tt> case>>
+ }
+ elsif (s/^IncircleCenter(?=\W)//i) {
+ <<process <tt>IncircleCenter</tt> case>>
+ }
+ elsif (s/^ExcircleCenter(?=\W)//i) {
+ <<process <tt>ExcircleCenter</tt> case>>
+ }
+ elsif (/^[^\W\d_]\d{0,4}\s*[^,\w]/) {
+ m/^([^\W\d_]\d{0,4})\s*/i;
+ if (exists($PointTable{lc($1)})) {
+ my $Tcoord = get_point($lc);
+ my ($x,$y,$pSV,$pS)=unpack("d3A*",$PointTable{$Tcoord});
+ $Px = $x;
+ $Py = $y;
+ }
+ else {
+ $Px = expr();
+ chk_comma($lc);
+ $Py = expr();
+ }
+ }
+ elsif (/[^\W\d_]\d{0,4}\s*,\s*shift|polar|rotate|vector/i) { #a point?
+ s/^([^\W\d_]\d{0,4})//i;
+ my $PointA = $1;
+ if (exists($PointTable{lc($PointA)})) {
+ s/\s*//;
+ if (s/^,//) {
+ s/\s*//;
+ if (s/^shift(?=\W)//i) {
+ <<process <tt>shift</tt> case>>
+ }
+ elsif (s/^polar(?=\W)//i) {
+ <<process <tt>polar</tt> case>>
+ }
+ elsif (s/^rotate(?=\W)//i) {
+ <<process <tt>rotate</tt> case>>
+ }
+ elsif (s/^vector(?=\W)//i) {
+ <<process <tt>vector</tt> case>>
+ }
+ else {
+ PrintErrorMessage("unexpected token",$lc);
+ next LINE;
+ }
+ }
+ else {
+ my ($xA,$yA,$pSVA,$pSA)=unpack("d3A*",$PointTable{lc($PointA)});
+ $Px = $xA;
+ $Py = $yA;
+ }
+ }
+ else {
+ PrintErrorMessage("Undefined point $PointA",$lc);
+ next LINE;
+ }
+ }
+ else {
+ $Px = expr();
+ chk_comma($lc);
+ $Py = expr();
+ }
+
+@ In the following piece of code we process the [[perpendicular]]
+case of the [[point]] specification. We first check whether there is an
+opening left parenthesis. Next, we get the first point name. In case
+there is no point name, we simply abandon the processing of this
+line and continue with the next one. Then we see whether there is
+a trailing comma. Omitting this token yields a non-fatal error.
+Then we get two more points. As before, if we can't find any of these
+points this yields a fatal-error. Note, that each time we check that the
+point names correspond to existing point names. Then, we call subroutine
+[[perpendicular]] to calculate the coordinates of the point.
+
+<<process <tt>perpendicular</tt> case>>=
+ chk_lparen("perpendicular",$lc);
+ my $FirstPoint = &get_point($lc);
+ next LINE if $FirstPoint eq "_undef_";
+ chk_comma($lc);
+ my $SecondPoint = &get_point($lc);
+ next LINE if $SecondPoint eq "_undef_";
+ my $ThirdPoint = &get_point($lc);
+ next LINE if $ThirdPoint eq "_undef_";
+ chk_rparen("No closing parenthesis found",$lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$FirstPoint});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$SecondPoint});
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$ThirdPoint});
+ ($Px, $Py) = perpendicular($x1,$y1,$x2,$y2,$x3,$y3);
+
+@ In the following piece of code we process the [[intersection]] case of the
+[[point]] specification. We get the four point names and if there is
+no error we compute the intersection point by calling subroutine
+[[intersection]].
+
+<<process <tt>intersection</tt> case>>=
+ chk_lparen("intersection",$lc);
+ my $FirstPoint = get_point($lc);
+ next LINE if $FirstPoint eq "_undef_";
+ my $SecondPoint = get_point($lc);
+ next LINE if $SecondPoint eq "_undef_";
+ chk_comma($lc);
+ my $ThirdPoint = get_point($lc);
+ next LINE if $ThirdPoint eq "_undef_";
+ my $ForthPoint = get_point($lc);
+ next LINE if $ForthPoint eq "_undef_";
+ chk_rparen("No closing parenthesis found",$lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$FirstPoint});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$SecondPoint});
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$ThirdPoint});
+ my ($x4,$y4,$pSV4,$pS4)=unpack("d3A*",$PointTable{$ForthPoint});
+ ($Px, $Py) = intersection4points($x1,$y1,$x2,$y2,$x3,$y3,$x4,$y4);
+
+
+@ Given two points A and B, the midpoint option computes the coordinates
+of a third point that lies on the middle of the line segment defined by
+these two points. We get the the two points, and then we compute the
+coordinates of the midpoint with function [[midpoint]].
+
+<<process <tt>midpoint</tt> case>>=
+ chk_lparen("midpoint",$lc);
+ my $FirstPoint = &get_point($lc);
+ next LINE if $FirstPoint eq "_undef_";
+ my $SecondPoint = &get_point($lc);
+ next LINE if $SecondPoint eq "_undef_";
+ chk_rparen("No closing parenthesis found",$lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$FirstPoint});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$SecondPoint});
+ ($Px, $Py) = midpoint($x1, $y1, $x2, $y2);
+
+@ Given two points A and B and length d, the [[PointOnLine]] option
+computes the coordinates of a point that lies d units in the direction from
+A towards B. We first get the coordinates of the two points that define
+the line and then we get the distance, which can be a number, a variable,
+or a pair of points.
+
+<<process <tt>pointonline</tt> case>>=
+ chk_lparen("pointonline",$lc);
+ my $FirstPoint = &get_point($lc);
+ next LINE if $FirstPoint eq "_undef_";
+ my $SecondPoint = &get_point($lc);
+ next LINE if $SecondPoint eq "_undef_";
+ chk_comma($lc);
+ # now get the distance
+ my $distance = expr($lc);
+ chk_rparen("No closing parenthesis found",$lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$FirstPoint});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$SecondPoint});
+ ($Px, $Py) = pointOnLine($x1,$y1,$x2,$y2,$distance);
+
+@ The [[circumcircleCenter]] is used when one wants to compute the coordinates
+of the center of circle that passes through the three points
+of a triangle defined
+by the three arguments of the option. All we do is get the coordinates
+of the three points and then we call the subroutine [[circumCircleCenter]]
+to compute the center.
+
+<<process <tt>circumcircleCenter</tt> case>>=
+ chk_lparen("circumCircleCenter",$lc);
+ my $FirstPoint = &get_point($lc);
+ next LINE if $FirstPoint eq "_undef_";
+ my $SecondPoint = &get_point($lc);
+ next LINE if $SecondPoint eq "_undef_";
+ my $ThirdPoint = &get_point($lc);
+ next LINE if $ThirdPoint eq "_undef_";
+ chk_rparen("No closing parenthesis found",$lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$FirstPoint});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$SecondPoint});
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$ThirdPoint});
+ ($Px, $Py,$r) = &circumCircleCenter($x1,$y1,$x2,$y2,$x3,$y3,$lc);
+ next LINE if $Px == 0 and $Py == 0 and $r == 0;
+
+@ The [[IncircleCenter]] option is to determine the coordinates of a point
+that is the center of circle that internally touches the sides
+of a triangle defined by three given points.
+The coordinates are computed by the subroutine [[IncircleCenter]].
+
+<<process <tt>IncircleCenter</tt> case>>=
+ chk_lparen("IncircleCenter",$lc);
+ my $FirstPoint = &get_point($lc);
+ next LINE if $FirstPoint eq "_undef_";
+ my $SecondPoint = &get_point($lc);
+ next LINE if $SecondPoint eq "_undef_";
+ my $ThirdPoint = &get_point($lc);
+ next LINE if $ThirdPoint eq "_undef_";
+ chk_rparen("No closing parenthesis found",$lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{$FirstPoint});
+ my ($x2,$y2,$pSV2,$pS2)=unpack("d3A*",$PointTable{$SecondPoint});
+ my ($x3,$y3,$pSV3,$pS3)=unpack("d3A*",$PointTable{$ThirdPoint});
+ ($Px, $Py, $r) = IncircleCenter($x1,$y1,$x2,$y2,$x3,$y3);
+
+@ The [[ExcircleCenter]] option is used to define the coordinates of point
+that is the center of an excircle of a triangle. We first check
+whether there is an opening left parenthesis. Next, we get the names of the
+three points that define the triangle. Then, we
+check whether there is a comma. Now we get the names of the two points that
+define one side of the triangle. We check whether the two points we
+get are of the set of the triangle points. If not we issue
+an error message and continue with the next input line. Then we make sure
+that these two points are not identical. We compute the actual
+coordinates by calling the subroutine [[excircle]]. Finally, we
+make sure there is a closing right parenthesis.
+
+<<process <tt>ExcircleCenter</tt> case>>=
+ chk_lparen("ExcircleCenter",$lc);
+ my $PointA = get_point($lc);
+ next LINE if $PointA eq "_undef_";
+ my $PointB = get_point($lc);
+ next LINE if $PointB eq "_undef_";
+ my $PointC = get_point($lc);
+ next LINE if $PointC eq "_undef_";
+ chk_comma($lc);
+ my $PointD = &get_point($lc);
+ next LINE if $PointD eq "_undef_";
+ if (!memberOf($PointD, $PointA, $PointB, $PointC)) {
+ PrintErrorMessage("Current point isn't a side point",$lc);
+ next LINE;
+ }
+ my $PointE = get_point($lc);
+ next LINE if $PointE eq "_undef_";
+ if (!memberOf($PointE, $PointA, $PointB, $PointC)) {
+ PrintErrorMessage("Current point isn't a side point",$lc);
+ next LINE;
+ }
+ if ($PointD eq $PointE) {
+ PrintErrorMessage("Side points are identical",$lc);
+ next LINE;
+ }
+ ($Px, $Py, $r) = excircle($PointA, $PointB, $PointC,
+ $PointD, $PointE);
+ chk_rparen("after coordinates part",$lc);
+
+@ The [[shift]] option allows us to define a point's coordinates relative
+to the coordinates of an existing point by using two shift parameters. Each
+parameter can be either a float, a variable name, or a pair of points.
+
+<<process <tt>shift</tt> case>>=
+
+ chk_lparen("shift",$lc);
+ my $dist1 = expr($lc);
+ chk_comma($lc);
+ my $dist2 = expr($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{lc($PointA)});
+ $Px = $x1 + $dist1;
+ $Py = $y1 + $dist2;
+ chk_rparen("shift part",$lc);
+
+@ The [[polar]] option allows us to define a point's coordinates relative
+to the coordinates of an existing point using the polar coordinates of some
+other point. We first check whether there is a left parenthesis,
+Then we parse the various parts of the [[polar]] option.
+In case the user has specified the angle in degrees, we have
+to transform it into radians, as all trigonometric function expect their
+arguments to be radians. Next, we compute the coordinates of the point.
+We conclude by checking whether there is a closing parenthesis.
+
+<<process <tt>polar</tt> case>>=
+ chk_lparen("polar",$lc);
+ my ($R1, $Theta1);
+ $R1 = expr($lc);
+ chk_comma($lc);
+ $Theta1 = expr($lc);
+ my ($x1,$y1,$pSV1,$pS1)=unpack("d3A*",$PointTable{lc($PointA)});
+ s/\s*//;
+ if (s/^rad(?=\W)//i) {
+ # do nothing!
+ }
+ elsif (s/^deg(?=\W)//i) {
+ $Theta1 = $Theta1 * PI / 180;
+ }
+ else {
+ #$Theta1 = $Theta1 * PI / 180;
+ }
+ $Px = $x1 + $R1 * cos($Theta1);
+ $Py = $y1 + $R1 * sin($Theta1);
+ chk_rparen("after polar part",$lc);
+
+@ The [[rotate]] option allows us to define a point's coordinates by
+rotating an existing point, Q, about a third point, P, by a
+specified angle.
+The method to achieve this is to first get the coordinates of points
+P and Q and then
+<ol>
+<li> translate origin to P</li>
+<li> rotate about P</li>
+<li> translate from P back to origin, etc</li>
+</ol>
+As in the case of the [[polar]] option, we check for an opening parenthesis.
+Next, we parse the point name and the angle. At this point we are able to
+compute the coordinates of the rotated point. We conclude by checking
+whether there is a closing parenthesis.
+
+<<process <tt>rotate</tt> case>>=
+ chk_lparen("rotate",$lc);
+ my $Q = lc($PointA);
+ my $P = get_point($lc);
+ next LINE if $P eq "_undef_";
+ chk_comma($lc);
+ my $Theta1 = expr($lc);
+ my ($xP,$yP,$pSV1,$pS1)=unpack("d3A*",$PointTable{$P});
+ my ($xQ,$yQ,$pSV2,$pS2)=unpack("d3A*",$PointTable{$Q});
+ s/\s*//;
+ if (s/^rad(?=\W)//i)
+ {
+ # do nothing!
+ }
+ elsif (s/^deg(?=\W)//i)
+ {
+ $Theta1 = $Theta1 * PI / 180;
+ }
+ else
+ {
+ $Theta1 = $Theta1 * PI / 180;
+ }
+ # shift origin to P
+ $xQ -= $xP;
+ $yQ -= $yP;
+ # do the rotation
+ $Px = $xQ * cos($Theta1) - $yQ * sin($Theta1);
+ $Py = $xQ * sin($Theta1) + $yQ * cos($Theta1);
+ # return origin back to original origin
+ $Px += $xP;
+ $Py += $yP;
+ chk_rparen("after rotate part",$lc);
+
+@ [[vector(PQ)]] is actually is a shorthand of [[shift(xQ-xP,yQ-yP)]]. Thus, it
+is implemented by borrowing code from the [[shift]] modifier.
+
+<<process <tt>vector</tt> case>>=
+ chk_lparen("vector",$lc);
+ my ($x0,$y0,$pSV0,$pS0) = unpack("d3A*",$PointTable{lc($PointA)});
+ my $P = get_point($lc);
+ my $Q = get_point($lc);
+ my ($x1,$y1,$pSV1,$pS1) = unpack("d3A*",$PointTable{$P});
+ my ($x2,$y2,$pSV2,$pS2) = unpack("d3A*",$PointTable{$Q});
+ $Px = $x0 + $x2 - $x1;
+ $Py = $y0 + $y2 - $y1;
+ chk_rparen("vector part",$lc);
+
+
+@ When lines are drawn to a point, the line will (unless otherwise
+specified) extend to the point location. However, this can be prevented by
+allocating an optional circular line-free zone to a point by specifying the
+radius (in square brackets) of the optional point shape part. Currently, in this part
+we are allowed to describe the point shape and the radius value. If only the
+radius is specified, e.g., <tt>[radius=5]</tt>, then the line-free zone will be
+applied to the default point character, i.e., <tt>$\bullet$</tt> or whatever it
+has been set to. Here is the syntax we employ:
+<pre>
+Optional_point_shape_part ::= "[" [ symbol_part ] [","] [ radius_part ]"
+symbol_part ::= "symbol" "=" symbol
+symbol ::= "circle" "(" expression ")" |
+ "square" "(" expression ")" |
+ LaTeX_Code
+radius_part ::= "radius" "=" expression
+</pre>
+Note that it is possible to have right square bracket in the <tt>LaTeX_Code</tt> but it
+has to be escaped (i.e., <tt>\]</tt>).
+
+<<process optional point shape part>>=
+ if (/^(symbol|radius|side)\s*/i) {
+ my @previous_options = ();
+ my $number_of_options = 1;
+ my $symbol_set = 0;
+ while (s/^(symbol|radius)\s*//i and $number_of_options <= 2) {
+ my $option = lc($1);
+ if (s/^=\s*//) {
+ if (memberOf($option,@previous_options)) {
+ PrintErrorMessage("Option \"$option\" has been already defined", $lc);
+ my $dummy = expr($lc);
+ }
+ elsif ($option eq "radius") {
+ $sh = expr($lc);
+ $sv = $defaultsymbol if ! $symbol_set;
+ }
+ elsif ($option eq "symbol") {
+ if (s/^circle\s*//i) {
+ $sv = "circle";
+ chk_lparen("after token circle",$lc);
+ $side_or_radius = expr($lc);
+ chk_rparen("expression",$lc);
+ }
+ elsif (s/^square\s*//i) {
+ $sv = "square";
+ chk_lparen("after token square",$lc);
+ $side_or_radius = expr($lc);
+ chk_rparen("expression",$lc);
+ }
+ elsif (s/^(((\\\]){1}|(\\,){1}|(\\\s){1}|[^\],\s])+)//) {
+ $sv = $1;
+ $sv =~ s/\\\]/\]/g;
+ $sv =~ s/\\,/,/g;
+ $sv =~ s/\\ / /g;
+ s/\s*//;
+ }
+ $symbol_set = 1;
+ }
+ }
+ else {
+ PrintErrorMessage("unexpected token", $lc);
+ next LINE;
+ }
+ $number_of_options++;
+ push (@previous_options, $option);
+ s/^,\s*//;
+ }
+ }
+ else {
+ PrintErrorMessage("unexpected token", $lc);
+ next LINE;
+ }
+
+@ The [[ArrowShape]] command has either one or three arguments. If the only argument of
+the command is the token [[default]], then the parameters associated with the
+arrow shape resume their default values. Now, if there are three arguments, these are
+used to specify the shape of an arrow. The command actually sets the three global variables
+[[$arrowLength]], [[$arrowAngleB]] and [[$arrowAngleC]]. Arguments whose value is equal
+to zero, do not affect the value of the corresponding global variables. To reset the
+values of the global variables one should use the commane with [[default]] as it
+only argument. The syntax of the command is as follows:
+<center>
+<tt>"ArrowShape" "(" expr [ units ] "," expr "," expr ")"</tt> or<br>
+<tt>"ArrowShape" "(" "default" ")" </tt>
+</center>>
+Here [[units]] is any valid TeX unit (e.g., "mm", "cm", etc.). Note that if
+any of the three expressions is equal to zero, the default value is taken
+instead. As direct consequence, if the value of the first expression is zero,
+the units part is actually ignored.
+
+<<process <tt>ArrowShape</tt> command>>=
+
+ chk_lparen("$cmd",$lc);
+ if (s/^default//i) {
+ $arrowLength = 2;
+ $arrowLengthUnits = "mm";
+ $arrowAngleB = 30;
+ $arrowAngleC = 40;
+ }
+ else {
+ my ($LocalArrowLength, $LocalArrowAngleB ,$LocalArrowAngleC) = (0,0,0);
+ $LocalArrowLength = expr($lc);
+ if (s/^\s*($units)//i) {
+ $arrowLengthUnits = "$1";
+ }
+ else {
+ $xunits =~ /(\d+(\.\d+)?)\s*($units)/;
+ $LocalArrowLength *= $1;
+ $arrowLengthUnits = "$3";
+ }
+ chk_comma($lc);
+ $LocalArrowAngleB = expr($lc);
+ chk_comma($lc);
+ $LocalArrowAngleC = expr($lc);
+ $arrowLength = ($LocalArrowLength == 0 ? 2 : $LocalArrowLength);
+ $arrowLengthUnits = ($LocalArrowLength == 0 ? "mm" : $arrowLengthUnits);
+ $arrowAngleB = ($LocalArrowAngleB == 0 ? 30 : $LocalArrowAngleB);
+ $arrowAngleC = ($LocalArrowAngleC == 0 ? 40 : $LocalArrowAngleC);
+ }
+ chk_rparen("after $cmd arguments",$lc);
+ chk_comment("after $cmd command",$lc);
+ print OUT "%% arrowLength = $arrowLength$arrowLengthUnits, ",
+ "arrowAngleB = $arrowAngleB ",
+ "and arrowAngleC = $arrowAngleC\n" if $comments_on;
+
+@ The [[PointSymbol]] command is used to set the point symbol and possibly its
+line-free radius. The point symbol can be either a LaTeX symbol or the word [[default]]
+which corresponds to the default point symbol, i.e., <tt>$\bullet$</tt>. The line-free
+radius can be an expression. Here is the complete syntax:
+<pre>
+ pointsymbol ::= "pointsymbol" ( symbol [ "," radius])
+ symbol ::= "default" | circle | square | LaTeX_Code
+ circle ::= "circle" "(" expression ")"
+ square ::= "square" "(" expression ")"
+ radius ::= expression
+</pre>
+Note that the <tt>LaTeX_Code</tt> can contain the symbols <tt>\,</tt> and
+<tt>\)</tt> which are escape sequences for a comma and right parenthesis, respectively.
+
+<<process <tt>PointSymbol</tt> command>>=
+
+ chk_lparen("$cmd",$lc);
+ if (s/^default//i) #default point symbol
+ {
+ $defaultsymbol = "\$\\bullet\$";
+ }
+ elsif (s/^(circle|square)//i) {
+ $defaultsymbol = $1;
+ chk_lparen($defaultsymbol, $lc);
+ $GlobalDimOfPoints = expr($lc);
+ chk_rparen("expression", $lc);
+ }
+ elsif (s/^(((\\,){1}|(\\\)){1}|(\\\s){1}|[^\),\s])+)//) #arbitrary LaTeX point
+ {
+ $defaultsymbol = $1;
+ $defaultsymbol=~ s/\\\)/\)/g;
+ $defaultsymbol=~ s/\\,/,/g;
+ $defaultsymbol=~ s/\\ / /g;
+ }
+ else
+ {
+ PrintErrorMessage("unrecognized point symbol",$lc);
+ }
+ if (s/\s*,\s*//) {
+ $defaultLFradius = expr($lc);
+ }
+ chk_rparen("after $cmd arguments",$lc);
+ chk_comment("after $cmd command",$lc);
+
+@ The [[system]] command provides a shell escape. However, we use a subroutine
+to check whether the argument of the command contains tainted data. If this
+is the case, then we simply ignore this command. The syntax of the command
+is as follows:
+<pre>
+ system-cmd ::= "system" "(" string ")"
+</pre>
+where string is just a sequence of characters enclosed in quotation marks.
+We start by parsing a left parenthesis and then we get the command by
+calling the subroutine [[get_string]]. If there is an error we skip this
+command. Otherwise, we assign to the variable [[$_]] what is left. Now we check
+if the variable [[$command]] contains any tainted data. If it doesn't, we
+execute the command, otherwise we print an error message and skip to the
+next input line. Next, we check for closing right parenthesis and a possible
+trailing comment.
+
+<<process <tt>system</tt> command>>=
+
+ chk_lparen("$cmd",$lc);
+ my ($error, $command, $rest) = get_string($_);
+ next LINE if $error == 1;
+ $_ = $rest;
+ if (! is_tainted($command)) {
+ system($command);
+ }
+ else {
+ PrintErrorMessage("String \"$command\" has tainted data", $lc);
+ next LINE;
+ }
+ chk_rparen("after $cmd arguments",$lc);
+ chk_comment("after $cmd command",$lc);
+
+@ The [[text]] command is used to put a piece of text or a symbol on
+a particular point of the resulting graph. The syntax of the command is
+as follows:
+<pre>
+ text-comm ::= "text" "(" text ")" "{"coords"} "[" pos-code "]"
+ text ::= ascii string
+ coords ::= Coord "," Coord |
+ Point-Name "," "shift" "(" Coord "," Coord ")" |
+ Point-Name "," "polar" "(" Coord "," Coord [angle-unit] ")"
+ Coord ::= decimal number | variable | pair-of-Point-Names
+ pair-of-Point-Names ::= Point-Name Point-Name
+ angle-unit ::= "deg" | "rad"
+ pos-code ::= lr-code [tb-code] | tb-code [lr-code]
+ lr-code ::= "l" | "r"
+ tb-code ::= "t" | "b" | "B"
+</pre>
+Initially, we parse the [[text]]. Since the text may contain parentheses
+we assume that the user enters pairs of matching parentheses. Note, that
+this is a flaw in the original design of the language, which may be remedied
+in future releases of the software. Then, we check the [[coords]] part. Next,
+if there is a left square bracket, we assume the user has specified the
+[[pos-code]]. We conclude by checking a possible trailing comment.
+The next thing we do is to generate the PiCTeX code. The two possible
+forms follow:
+<center>
+<tt>\put {TEXT} [POS] at Px Py</tt><br>
+<tt>\put {TEXT} at Px Py</tt><br>
+</center>
+
+<<process <tt>text</tt> command>>=
+
+ chk_lparen("text",$lc);
+ my ($level,$text)=(1,"");
+ TEXTLOOP: while (1)
+ {
+ $level++ if /^\(/;
+ $level-- if /^\)/;
+ s/^(.)//;
+ last TEXTLOOP if $level==0;
+ $text .= $1;
+ }
+ chk_lcb("text part",$lc);
+ my ($Px, $Py,$dummy,$pos);
+ $pos="";
+ s/\s*//;
+ <<process coordinates part of text command>>
+ chk_rcb("coordinates part of text command",$lc);
+ if (s/^\[//)
+ {
+ s/\s*//;
+ <<process optional part of text command>>
+ s/\s*//;
+ chk_rsb("optional part of text command",$lc);
+ }
+ chk_comment($lc);
+ if ($pos eq "")
+ {
+ printf OUT "\\put {%s} at %f %f\n", $text, $Px, $Py;
+ }
+ else
+ {
+ printf OUT "\\put {%s} [%s] at %f %f\n", $text, $pos, $Px, $Py;
+ }
+
+@ In this section we define the code that handles the coordinates part
+of the [[text]] command. The code just implements the grammar given above.
+If the first token is a number, we assume this is the x-coordinate. If
+it is a variable, we assume its value is the x-coordinate. However, if
+it is a point name, we check whether the next token is another point name.
+In this case we compute the distance between the two points. In case we
+have a single point followed by a comma, we expect to have either a polar
+or a shift part, which we process the same we processed them in the point
+command.
+
+<<process coordinates part of text command>>=
+
+ if (/^[^\W\d_]\d{0,4}\s*[^,\w]/) {
+ my $Tcoord = get_point($lc);
+ my ($x,$y,$pSV,$pS)=unpack("d3A*",$PointTable{$Tcoord});
+ $Px = $x;
+ $Py = $y;
+ }
+ elsif (/[^\W\d_]\d{0,4}\s*,\s*shift|polar/i) {
+ s/^([^\W\d_]\d{0,4})//i;
+ my $PointA = $1;
+ if (exists($PointTable{lc($PointA)})) {
+ s/\s*//;
+ if (s/^,//) {
+ s/\s*//;
+ if (s/^shift(?=\W)//i) {
+ <<process <tt>shift</tt> case>>
+ }
+ elsif (s/^polar(?=\W)//i) {
+ <<process <tt>polar</tt> case>>
+ }
+ }
+ }
+ else {
+ PrintErrorMessage("undefined point/var",$lc);
+ next LINE;
+ }
+ }
+ else {
+ $Px = expr();
+ chk_comma($lc);
+ $Py = expr();
+ }
+
+@ In this section we process the optional part of the [[text]] command.
+The general rule is that we are allowed to have up to two options one
+from the characters [[l]] and [[r]] and one from the the characters
+[[B]], [[b]], and [[t]]. We first check whether the next character is
+letter, if it isn't we issue an error message and continue with the next
+input line. If it is a letter we check whether it belongs to one of the
+two groups and if it doesn't we issue an error message and continue with the
+next input line. If the next character belongs to first group, i.e., it is
+either [[l]] or [[r]], we store this character into the variable [[$pos]]. Next,
+we check whether there is another letter. If it is a letter, we store it
+in the variable [[$np]]. Now we make sure that this character belongs to the
+other group, i.e., it is either [[b]], [[B]], or [[t]]. In case it belongs
+to the other group, we append the value of [[$np]] to the string stored in
+the variable [[$pos]]. Otherwise we issue an error message and continue with the
+next input line. We work similarly for the other case. In order to check
+whether a character belongs to some group of characters, we use the user
+defined function [[memberOf]].
+
+<<process optional part of text command>>=
+
+ if (s/^(\w{1})\s*//) {
+ $pos .= $1;
+ if (memberOf($pos, "l", "r")) {
+ if (s/^(\w{1})\s*//) {
+ my $np = $1;
+ if (memberOf($np, "t", "b", "B")) {
+ $pos .= $np;
+ }
+ else {
+ if (memberOf($np, "l", "r")) {
+ PrintErrorMessage("$np can't follow 'l' or 'r'", $lc);
+ }
+ else {
+ PrintErrorMessage("$np is not a valid positioning option", $lc);
+ }
+ next LINE;
+ }
+ }
+ }
+ elsif (memberOf($pos, "t", "b", "B")) {
+ if (s/^(\w{1})\s*//) {
+ my $np = $1;
+ if (memberOf($np, "l", "r")) {
+ $pos .= $np;
+ }
+ else {
+ if (memberOf($np, "t", "b", "B")) {
+ PrintErrorMessage("$np can't follow 't', 'b', or 'B'", $lc);
+ }
+ else {
+ PrintErrorMessage("$np is not a valid positioning option", $lc);
+ }
+ next LINE;
+ }
+ }
+ }
+ else {
+ PrintErrorMessage("$pos is not a valid positioning option", $lc);
+ next LINE;
+ }
+ }
+ else {
+ PrintErrorMessage("illegal token in optional part of text command",$lc);
+ next LINE;
+ }
+
+@ The [[const]] command is used to store values into a comma separated
+list of named constants. Constant names have the same format as point names,
+i.e., they start with a letter and are followed by up to two digits. The
+whole operation is performed by a [[do-while]] construct that checks that
+there is a valid constant name, a [[=]] sign, and an expression. The
+[[do-while]] construct terminates if the next token isn't a comma. Variable
+[[$Constname]] is used to store the initial variable name, while we store
+in variable [[$varname]] the lowercase version of the variable name. In addition,
+we make sure a constant is not redefined (or else it wouldn't be a constant:-).
+The last thing we do is to check whether there is a trailing comment.
+In case there, we simply ignore itl; otherwise we print a warning message.
+
+<<process <tt>const</tt> command>>=
+ do{
+ s/\s*//;
+ PrintErrorMessage("no identifier found after token const",$lc)
+ if $_ !~ s/^([^\W\d_]\d{0,4})//i;
+ my $Constname = $1;
+ my $constname = lc($Constname);
+ if (exists $ConstTable{$constname}) {
+ PrintErrorMessage("Redefinition of constant $constname",$lc);
+ }
+ s/\s*//; #remove leading white space
+ PrintErrorMessage("did not find expected = sign",$lc)
+ if $_ !~ s/^[=]//i;
+ my $val = expr($lc);
+ $VarTable{$constname} = $val;
+ $ConstTable{$constname} = 1;
+ print OUT "%% $Constname = $val\n" if $comments_on;
+ }while (s/^,//);
+ chk_comment($lc);
+ s/\s*//;
+ if (/^[^%]/) {
+ PrintWarningMessage("Trailing text is ignored",$lc);
+ }
+
+@ The [[var]] command is used to store values into a comma separated
+list of named variables. Variable names have the same format as point names,
+i.e., they start with a letter and are followed by up to two digits. The
+whole operation is performed by a [[do-while]] construct that checks that
+there is a valid variable name, a [[=]] sign, and an expression. The
+[[do-while]] construct terminates if the next token isn't a comma. The variable
+[[$Varname]] is used to store the initial variable name, while we store
+in the variable [[$varname]] the lowercase version of the variable name.
+The last thing we do is to check whether there is a trailing comment.
+In case there, we simply ignore itl; otherwise we print a warning message.
+
+<<process <tt>var</tt> command>>=
+ do{
+ s/\s*//;
+ PrintErrorMessage("no identifier found after token var",$lc)
+ if $_ !~ s/^([^\W\d_]\d{0,4})//i;
+ my $Varname = $1;
+ my $varname = lc($Varname);
+ if (exists $ConstTable{$varname}) {
+ PrintErrorMessage("Redefinition of constant $varname",$lc);
+ }
+ s/\s*//; #remove leading white space
+ PrintErrorMessage("did not find expected = sign",$lc)
+ if $_ !~ s/^[=]//i;
+ my $val = expr($lc);
+ $VarTable{$varname} = $val;
+ print OUT "%% $Varname = $val\n" if $comments_on;
+ }while (s/^,//);
+ chk_comment($lc);
+ s/\s*//;
+ if (/^[^%]/) {
+ PrintWarningMessage("Trailing text is ignored",$lc);
+ }
diff --git a/graphics/mathspic/perl/sourcecode113.pdf b/graphics/mathspic/perl/sourcecode113.pdf
new file mode 100644
index 0000000000..80222093ad
--- /dev/null
+++ b/graphics/mathspic/perl/sourcecode113.pdf
Binary files differ