Mathspic: Apostolos Syropoulos Richard W. D. Nickalls
Mathspic: Apostolos Syropoulos Richard W. D. Nickalls
F
◦...
...
....
...
.
.....
...
....
...
....
.....•................
...
B◦ ..
.
.
...
.. ....................
...
....
.. ....
...
.....
....
..•..........................•..............
....
..........
..........
.......... .
•.. ...
....
. F2
....... .
.. ..........
...
...
..
.
..
..........
.......... .... E1
....... C .... ..
. .
. ...
.......... ..
..
... B2 B1 .......... ..
...
...
.
...
..
...... ◦ .... ..
..........
..........
...
..
...
.•.... ......
..
.
...
. ...
...
....
...
... ...
....
..•.
.. ... .
.
...
... A1 .... ...•. . C2 ...
...
... .......
...
... ..
.
.. ......... .
... ........ F1
•. ◦
.... .
... . . ...
.. .... ... E2
... .
. . .... ....
.... .... .. E
... .... ... ...
...
....
.... ... ...
...
..
. .. •.. . . ..
.
......
.
.... .
....
...
....
... . .
......
. ... ..
... .
....
•...
.. ... ... C1
..
..
...
... A
..... ... ... ....
...
.... ...
... ...
....
...
.
...... .... .
.. 2
. .. . D1 ...... ..
.....•.................•
...
... ....
.
A◦ .....
...
.....•............................•...
....... G2 .... ... ....
....... ... ....
.......
........ . .... ...
. D 2 ...
....... G1 ..... ... .
.....
....... .. ... .
....... .... ... ....
....... .... ... ....
.......
.... ...
.......
....... ....
...
. ..
....
....... .... . ... .. .
...... .. . ....
◦ ◦
G D
Apostolos Syropoulos
Richard W. D. Nickalls
The single biggest problem we face is that of visualisation.
Apostolos Syropoulos,
Greek TEX Friends,
366, 28th October Street,
GR-671 00 Xanthi, Greece.
[email protected]
http://ocean1.ee.duth.gr/~apostolo
and
Richard W. D. Nickalls,
Department of Anaesthesia,
Nottingham University Hospitals,
City Hospital Campus,
Nottingham, UK.
[email protected]
http://www.nickalls.org/dick/
a s & r w d n
26 April 2010
iii
TUGboat: http://www.tug.org/TUGboat/
The PracTEX Journal: http://www.tug.org/pracjourn/
Typeset in
Times 10-point font
using LATEX 2ε
Cover figure by
František Chvála
Copyright ○
c A Syropoulos & RWD Nickalls 26 April 2010
mathsPIC is released under the terms of the LATEX Project Public License.
mathsPIC is distributed without any warranty or implied warranty of
merchantability or fitness for a particular purpose.
Contents
1 Introduction 1
2 Running mathsPICPerl 5
2.1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.1.1 The mathsPIC package . . . . . . . . . . . . . . . . . . . . . 5
2.1.2 Unix/Linux platform . . . . . . . . . . . . . . . . . . . . . . 6
2.1.3 MS-Windows platform . . . . . . . . . . . . . . . . . . . . . . 7
2.1.4 mathspic.sty . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1.5 mathspicX.pl . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2 Command-line syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3 Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.3.1 Filename extensions . . . . . . . . . . . . . . . . . . . . . . 8
2.4 Switches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.5 Removing comment lines . . . . . . . . . . . . . . . . . . . . . . . . 9
2.6 Online help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.7 The mathsPIC style-option . . . . . . . . . . . . . . . . . . . . . . . 10
2.8 Error-messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.9 Log-file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
iv
CONTENTS v
3.8 Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.9 Variables and constants . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.9.1 Scalar variables . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.9.2 Scalar constants . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.9.3 Mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.9.4 Scientific notation . . . . . . . . . . . . . . . . . . . . . . . . 31
3.10 The LOOP environment . . . . . . . . . . . . . . . . . . . . . . . . . 32
4 mathsPIC commands 34
4.1 Mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
4.1.1 Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
4.1.2 Making a macro library . . . . . . . . . . . . . . . . . . . . . 36
4.2 Command definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.2.1 Backslash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.2.2 ArrowShape . . . . . . . . . . . . . . . . . . . . . . . . . . 38
4.2.3 beginLoop ... endLoop environment . . . . . . . . . . . . . . 38
4.2.4 beginSkip ... endSkip environment . . . . . . . . . . . . . . . 38
4.2.5 Const . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
4.2.6 DashArray . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
4.2.7 DrawAngleArc . . . . . . . . . . . . . . . . . . . . . . . . . 39
4.2.8 DrawAngleArrow . . . . . . . . . . . . . . . . . . . . . . . . 40
4.2.9 DrawArrow . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
4.2.10 DrawCircle . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
4.2.11 DrawCircumcircle . . . . . . . . . . . . . . . . . . . . . . . . 41
4.2.12 DrawCurve . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
4.2.13 DrawExcircle . . . . . . . . . . . . . . . . . . . . . . . . . . 42
4.2.14 DrawIncircle . . . . . . . . . . . . . . . . . . . . . . . . . . 42
4.2.15 DrawLine . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
4.2.16 DrawPerpendicular . . . . . . . . . . . . . . . . . . . . . . . 42
4.2.17 DrawPoint . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
4.2.18 DrawRightangle . . . . . . . . . . . . . . . . . . . . . . . . 43
4.2.19 DrawSquare . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
4.2.20 DrawThickArrow . . . . . . . . . . . . . . . . . . . . . . . . 43
4.2.21 DrawThickLine . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.2.22 InputFile . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.2.23 LineThickness . . . . . . . . . . . . . . . . . . . . . . . . . 45
4.2.24 Loop environment . . . . . . . . . . . . . . . . . . . . . . . 45
4.2.25 Paper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.2.26 Point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.2.27 PointSymbol . . . . . . . . . . . . . . . . . . . . . . . . . . 49
4.2.28 Skip environment . . . . . . . . . . . . . . . . . . . . . . . . 49
4.2.29 Show... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
4.2.30 System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
4.2.31 Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
4.2.32 Var . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
4.3 Summary of mathsPIC commands . . . . . . . . . . . . . . . . . . . 53
5 PiCTeX commands 56
5.1 Useful PiCTeX commands . . . . . . . . . . . . . . . . . . . . . . . . 57
5.2 Using the $ symbol with PiCTeX . . . . . . . . . . . . . . . . . . . . 58
CONTENTS vi
7 Examples 63
7.1 Input- and output-files . . . . . . . . . . . . . . . . . . . . . . . . . . 63
7.2 Line modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
7.3 Arrows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
7.4 Circles & colour . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
7.5 Functionally connected diagrams . . . . . . . . . . . . . . . . . . . . . 77
7.6 Inputting the same data-file repeatedly . . . . . . . . . . . . . . . . . 78
7.6.1 Using the beginloop...endloop environment . . . . . . . . 81
7.6.2 Using LATEX to cycle a loopcounter . . . . . . . . . . . . . . 82
7.7 Plotting graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
7.8 Drawing other curves . . . . . . . . . . . . . . . . . . . . . . . . . . 86
7.9 Scaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
7.10 Using Perl programs . . . . . . . . . . . . . . . . . . . . . . . . . . 89
7.10.1 Example-1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
7.10.2 Example-2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
7.10.3 Commands for processing the files . . . . . . . . . . . . . . . 99
9 Miscellaneous 106
9.1 Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
9.2 Feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
9.3 Development history . . . . . . . . . . . . . . . . . . . . . . . . . . 106
A Tables 107
B Arrows 110
E PiCTeX 122
E.1 The original files (1986) . . . . . . . . . . . . . . . . . . . . . . . . 122
E.2 The new updated files (1994) . . . . . . . . . . . . . . . . . . . . . . 123
E.3 Pictex2.sty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
E.4 Errorbars.tex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
E.5 DCpic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
E.6 The PICTEX Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
References 127
Chapter 1
Introduction
MathsPICPerl is an open source Perl program for drawing mathematical diagrams and
figures1 (Nickalls, 1999; Syropoulos and Nickalls, 2000, 2005, 2007). More specifically,
MathsPIC is a ‘filter’ program which parses a plain text input-file (known as the
mathsPIC or .m file), and generates a plain text output-file containing TEX, LATEX and
PICTEX commands for drawing a diagram. This output-file—which has by default an
.mt filename-extension as it is really a TEX file—can then be processed by TEX or LATEX
in the usual way. It is anticipated that future versions will be able to generate output
files in PostScript and SVG code.
Spaces and the comment % symbol are used by mathsPIC in the same way as
TEX. However, mathsPIC commands are not case-sensitive, and do not have a leading
backslash (in order to distinguish them from PICTEX, TEX and LATEX commands, all of
which can be freely used in the mathsPIC script 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 original motivation for mathsPIC arose from the need for an easy-to-use fil-
ter program for PICTEX, a versatile and freely available drawing package which of-
fers the convenience of graphics code within the TEX document itself (e.g., printer-
independence). In this way, MathsPIC overcomes the main disadvantage of PICTEX,
which is that PICTEX requires you to specify the coordinates of all the points. Conse-
quently, this can make PICTEX extremely awkward to use whan making 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.1 and the PICTEX commands for drawing it are as follows (point A is
at the origin (0,0) and the units are in cm).
1 The first version of mathsPIC (an MS-DOS version) was presented at the 1999 EuroT X conference
E
in Heidelberg, Germany (Nickalls, 1999). A much improved Perl version was then developed, and a
‘work-in-progress’ presentation was given at the 2000 EuroTEX meeting in Oxford, UK (Syropoulos and
Nickalls, 2000). The first Perl version (1·0) was eventually uploaded to CTAN in 2005. The mathsPICPerl
program is written in Perl 5.8.2 built for i86pc-Solaris. MathsPICPerl can be freely downloaded from CTAN
(http://www.ctan.org/tex-archive/graphics/mathspic/perl/).
1
CHAPTER 1. INTRODUCTION 2
C ...........•.........................................
........ ......
............
.... ...........
.... ... ..........
. ....... ... ........
........
.
...... ..
.. ........
... ...
. ........
..
... ...
...
. ........
........
..
... ... .
.. ........
.
.... ... ..
. • B
.......
.
..... ...
.. .....
.. .
........
. ......................
..... .....
. . .
. ... .
..
...
...
...
... ...............
........ . ...
.... .............................................
.. .................
... ..................
.... ..................
....................
•
A
Figure 1.1:
% mpicpm01-1.m
\documentclass[a4paper]{article}
\usepackage{mathspic,color}
\begin{document}
%---------------
\beginpicture
\setdashes
\color{blue}%
paper{units(1cm) xrange(-0.5,5), yrange(-0.5,2.5) axes(XY)}
\setsolid
point(A){0,0}
point(B){A, polar(5, 10 deg)}
point(C){A, polar(3, 50 deg)}
\color{black}%
drawpoint(ABC)
drawLine(ABCA)
\color{red}%
drawIncircle(ABC)
\color{black}%
var d = 0.5
text($A$){A, polar(d,-140 deg)}
text($B$){B, shift(d,0)}
text($C$){C, shift(-d,0)}
\endpicture
\end{document}
All that remains is to generate the PS file using dvips, crop the image to the
bounding box (using the -E option) and generate the EPS and PDF versions (see
Section C.1). For example, if the mathsPIC file is, say, triangle.m, then the commands
would be as follows:
mathspic triangle.m
latex triangle.mt
dvips triangle.dvi -o triangle.ps
dvips -E triangle.dvi -o triangle.eps
epstopdf triangle.eps
Unique facilities
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. 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).
MathsPIC offers a number of other facilities, which allow the accurate drawing of
extremely complicated diagrams. Since mathsPIC itself is a Perl program, both point
CHAPTER 1. INTRODUCTION 4
coordinates and variables can be defined using all the usual mathematical functions and
syntax we associate with Perl. Files can be input recursively (using the inputfile
command); there is a do–loop facility; and macros can be defined. In fact two sorts of
macros can be used in the mathsPIC file, namely (a) special mathsPIC macros, and
(b) the familiar TeX macros. Macros can also be stored in a library file (an ordinary
ASCII text file) and input as and when necessary. Furthermore, the standard LATEX
packages can of course be used; e.g., the Color package and the Rotation package.
A powerful feature of mathsPIC is its facility for accessing the Perl command-line.
This allows users to write their own dedicated Perl programs for writing configurable
chunks of mathsPIC code on-the-fly to files which can then be input when required;
for example, to draw particular elements of a diagram or even complete diagrams (see
Section 7.10). The ability to use Perl programs in this way is, therefore, equivalent to
having a powerful subroutine facility. It follows, therefore, that users can create their
own library of useful Perl programs as well as libraries of mathsPIC macros.
Finally, note that mathsPIC can also be viewed as a handy tool for exploring
geometry since its show commands return the values of various parameters; for example,
angles, the distance between points, and areas of triangles.
Chapter 2
Running mathsPICPerl
MathsPICPerl is a Perl program and will therefore run on any platform on which Perl
is installed. Apart from minor platform differences regarding filename conventions,
commands for creating, editing and deleting ASCII files and so on, the practicalities of
running and using mathsPIC will be essentially the same whichever platform is being
used.
MathsPIC was developed using both GNU Linux and a Solaris x86 box, and
consequently some of the command-line codes may reflect this perspective. For example,
the following mathsPIC command to delete the file temp.txt
system("rm temp.txt")
uses the Unix1 ‘remove’ command rm. Clearly this particular command will differ
between platforms but it is assumed that users are familiar with their own local system
commands. MS-Windows users may wish to look at Appendix D in which we address
installing Perl on a MS-Windows platform. The authors welcome any relevant platform-
related information so we can include it in updates to this manual.
2.1 Installation
If you have a recent TEXLive installation (2009 or later) then both mathsPIC and
PICTEX will already be installed. However, mathsPIC may not be immediately runnable
from the command-line as this depends on the status and location of the Perl program
mathspicX.pl and the associated BASH file mathspic.sh.
CTAN: /tex-archive/graphics/mathspic/perl/
1 The term “Unix” here is used as a synonym for both Unix systems (e.g., Solaris, TrueUnix) and Unix-like
5
CHAPTER 2. RUNNING MATHSPICPERL 6
List of files
grabtexdata.pl % program used in Chapter 8
HELP.TXT % text version of the Unix manpage
mathspicX.pl % mathsPIC program version X (perl)
mathspic.sty % style option
mathspic.1 % unix/Linux manpage file
mathspic.sh % example BASH file for running mathsPIC
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 format)
$ man mathspic
CHAPTER 2. RUNNING MATHSPICPERL 7
2.1.4 mathspic.sty
Locate the directory containing all the LATEX packages, and create a mathspic subdirec-
tory. Copy into this new directory the file mathspic.sty.
2.1.5 mathspicX.pl
Locate the directory containing all the Perl .pl programs (typically the directory
c:∖perl∖bin∖ for the ActivePerl implementation of Perl) and copy into this direc-
tory the file mathspic.pl (see Appendix for details regarding installing Perl on MS-
Windows platforms).
If you type $ mathspic -h you get all the switches information as well
This is mathspic version 1.13 Apr 26, 2010
Type "man mathspic" for detailed help
Usage: mathspic [-h] [-b] [-c] [-o <out file>] <in file>
where,
[-b] enables bell sound if error exists
[-c] disables comments in output file
[-h] gives this help listing
[-o] creates specified output file
There are several ways of running mathsPIC from the commandline, as follows (at
the time of writing the current version of the program is mathspic113.pl):
$ mv mathspic113.pl mathspic
and then copy it to where the shell can find it (typically /usr/local/bin/).
Now mathsPIC can be run from any directory by typing
$ mathspic myfile.m
Note that this is the approach adopted by TEXLive, which places executable files in the
directory,
/usr/local/texlive/2010/bin/i386-linux/
which therefore needs to be included in the $PATH.
2.3 Files
2.3.1 Filename extensions
Throughout this manual we use the filename extension .m to denote a mathsPIC script
file (input-file), purely in order to distinguish them from the other files which are
generated by mathsPIC. In practice, though, the mathsPIC program will accept any
filename-extension preferred by the user2 . However, mathsPIC by default uses the
extension .mt for the TEX output-file (a TEX file containing PICTEX commands ready
for TEXing), and the extension .mlg for the log-file.
The mathsPIC command-line actions one input file and (optionally) one output
filename (prefixed by the -o switch). Each command or switch must be separated by at
least one space, as in the following example.
$ mathspic inputfile -o outputfile
2 For example, there is an obvious clash with the extension used by the program Mathematica, so in this
case a user could consider, perhaps, the alternative extension .mp for a mathsPIC script file.
CHAPTER 2. RUNNING MATHSPICPERL 9
If the outputfile is not specified then mathsPIC will create an output-file having
the same filename as the inputfile but with the filename extension .mt. For exam-
ple, if you want an input-file called myinfile.abc to generate an output-file called
myoutfile.xyz then use the following command.
$ mathspic myinfile.abc -o myoutfile.xyz
MathsPIC also writes to a log file (the .mlg file). This has the same filename as the
input filename.
2.4 Switches
There are four command-line switches (-h -c -b -o) which are case-sensitive. If
more than one switch is used then they must be separated by at least one space. The
switches are as follows (this information is also given by typing $ mathspic -h).
will open the manpage help file. If this fails, then check that the man page file
(mathspic.1) has been placed in the correct directory (typically /usr/share/man/man1/.
MS-Windows users can read the equivalent file HELP.TXT.
CHAPTER 2. RUNNING MATHSPICPERL 10
\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’.
2.8 Error-messages
A certain amount of syntax checking is performed by mathsPIC, and error-messages
are written to the main output-file (.mt file) and also to the log-file (.mlg file).
A copy of the line containing an error is prefixed by %% ***; the associated error-
message appears on the next line and is prefixed by dots (%% ...). Note that if the -c
switch (clean) is used (see above), then error-messages appear only in the log file. If the
-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 arise when mathsPIC commands are
written incorrectly (e.g. missing bracket, or a command being spelled incorrectly).
The following lines show some typical examples with respect to a draw command
if a point has not been previously defined resulting in a ‘point-name’ error:
%% drawline(AB)
%% *** Line 15: drawline(AB
%% *** )
%% ... Error: Undefined point B
%% drawline(PQ)
%% *** Line 52 : drawline(PQ
%% *** )
%% ... Error: points P and Q are the same
Since an error often has an effect on the processing of later commands in the script
(mathsPIC file), a single error can result in a cascade of error messages. In other words,
the number of error messages is not a good guide to the number of errors—there may
only be one small typo causing all the error messages.
2.9 Log-file
mathsPIC outputs a log-file (.mlg file) which contains details of all errors, relevant
line numbers and file names. The format was designed to match that of a standard TEX
log-file in order to be compatible with commonly used error-checking utilities.
For example, in the following code the errors in the 2nd, 3rd and 4th lines (combined
with the fact that point B has not been defined) generate the error messages found in the
associated log file (.mlg file) below.
%% test.m
point(A){5,5}
var d=
drawline(AB
var j=
text($B$){B, shift(d,0)}
All commands for generating a diagram (the script) are written to a plain ASCII file,
known as the mathsPIC file, using a text editor in the usual way. This file is then
processed by the mathsPIC program (mathspic.pl) as described in the previous
chapter. While the mathsPIC file can of course have any filename and extension, in
this manual all mathsPIC files have the filename extension of .m in order to distinguish
them from the various derived files.
We distinguish three types of command, namely (a) mathsPIC commands, (b) PICTEX
commands, and (c) TEX or LATEX commands. All these commands are detailed in the
subsequent three chapters. Since mathsPIC currently only outputs a TEX file then the
mathsPIC file can also contain appropriate PICTEX, TEX and LATEX commands1 .
13
CHAPTER 3. THE MATHSPIC SCRIPT FILE 14
Note also that the LATEX command \thispagestyle{empty} is included for con-
venience in mathspic.sty in order to stop a page number appearing in a figure (see
Section 2.7 for details).
\documentclass[a4paper]{article}
\usepackage{mathspic,color}
\begin{document}
%---------------
\beginpicture
....
....
\endpicture
\end{document}
For users of plain TEX a typical format might be as follows. Note the need in this
case to include the line redefining the \linethickness command (in mathspic.sty)
\input latexpic.tex
\let\Linethickness\linethickness% %% redefinition for mathsPIC
\input pictexwd.tex
\font\tiny=cmr5 %% used for drawing lines
\font\large=cmr12 %% used for drawing thicklines
%----------------
\beginpicture
....
....
\endpicture
\bye
\typeout{Hello World}%
For other TEX and LATEX commands useful in mathsPIC see Chapter 6.
3.3 Commands
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 TEXed
to generate the graphic. Some general points relating to the mathsPIC file are as follows.
∙ mathsPIC commands are not prefixed by backslashes. They are therefore easily
distinguished from TEX, LATEX and PICTEX commands.
∙ Each mathsPIC command must be on a separate line. This is because mathsPIC
frequently adds data to the end of a line in the output-file (see below).
∙ As with TEX, spaces can be used to enhance readability. This is particularly useful
when writing lists of points. For example the command drawpoint(PQR1R2)
can be made easier to read by writing it as
drawpoint(P Q R1 R2).
∙ mathsPIC commands and point-names are not case sensitive. This allows the
user to customise the commands to enhance readability. Thus the command
drawpoint can therefore be written as drawPoint or DrawPoint etc.
3.4 Macros
MathsPIC currently allows macros consisting of a single command, either with or
without parameters. (see Section 4.1.1). MathsPIC macros are subject to a number of
rules as follows:-
∙ Macros are created using the %def command, and destroyed using the %undef
command.
∙ When a macro is used in a command then the macro-name must have a & prefix
(to distinguish it as a macro).
∙ Macro names are case-sensitive (unlike all other mathsPIC command-names
which are not case sensitive)
∙ Macros must evaluate to a ‘numerical expression’ (see Section 4.2) (i.e. not to
strings).
It is strongly recommended that a % is placed at the end of the macro definition (as
is done with LATEX commands) in order to prevent PICTEX from including additional
horizontal whitespace.
No parameters
Examples of macros which do not take any parameters are the following two commands
which create the two macros fancydashes and plaindashes.
%def fancydashes() dasharray(1pt,2pt,3pt,4pt)%
%def plaindashes() dasharray(1pt,1pt)%
Note that in the macro-definition command the curved bracket (the parameter bracket)
at the end of the word fancydashes() remains empty if there are no parameters. This
pair of curved brackets marks the end of the command-name and the beginning of the
macro definition (i.e. some mathsPIC commands).
To use the macro (as a command) it is necessary to use the & prefix. The () brackets
are only necessary if the macro takes parameter(s), as follows.
...
&fancydashes
drawline(AB)
&plaindashes
drawline(PQ)
...
CHAPTER 3. THE MATHSPIC SCRIPT FILE 17
%undef fancydashes()
Single parameter
An example of a macro taking a single parameter is as follows:
%def thick(t) linethickness(t pt)%
Here the command &thick(2) is equivalent to the command linethickness(2pt).
Multiple parameters
An example of a macro taking multiple parameters is as follows:
%def mypoint(P,x,y) point(P){x,y}%
%%--- mathspic.lib---
%def fancydashes() dasharray(1pt,2pt,3pt,4pt)%
%def plaindashes() dasharray(1pt,1pt)%
%%--- end of library ---
and input the file at the start (for processing by mathsPIC) by placing the command
inputfile(mathspic.lib) in the mathsPIC file just after \begin{document}.
paper{units(1mm),xrange(0,50),yrange(0,50),axes(LRTB),ticks(10,10)}
This particular paper command4 is converted by mathsPIC into the following PICTEX
code in the output-file (.mt file).
\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 /
For graphs it is more usual for the axes to be centered on the origin (0, 0), and this
is provided for by the XY options. For example, Figure 3.1b was generated using the
following paper command,
paper{units(1cm),xrange(-2,3),yrange(-2,3),axes(XY),ticks(1,1)}
which is converted by mathsPIC into the following PICTEX code in the output-file.
\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 /
The tick-marks associated with an axis can be prevented by using a * after the axes-code
(e.g. 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 ...axes(LRTBX*Y*), ticks(10,10) will generate a rectangular axes frame
(with ticks) containing the XY axes (without ticks). The line-thickness of axes and
tick-marks is controlled by the PICTEX \linethickness command.
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 units parameters.
For example, the option units(3cm,1cm) will generate an X-axis having three times
the scale as the Y -axis (see Figure 7.11). If complicated or more demanding axis
configurations are required, then the PICTEX Manual (see Section E.6) will need to be
consulted. See also Chapter C for details on positioning figures within LATEX documents.
4 Note that the order of the units(), xrange(), yrange(), ... etc in the paper() command is
critical, and changing this order will generate an error message. This command will be made more flexible in
future versions.
CHAPTER 3. THE MATHSPIC SCRIPT FILE 19
0 10 20 30 40 50
50 50
40 40
30 30
20 20
10 10
0 0
0 10 20 30 40 50
a. Using ...axes(LRTB)
−2 −1 1 2 3
−1
−2
b. Using ...axes(XY)
Figure 3.1:
CHAPTER 3. THE MATHSPIC SCRIPT FILE 20
Example
Sometimes it is useful to use axes with a different scale in order to accommodate, say,
an equation, as shown in the following example, where we have to specify the two
Y-values and their positions on the axis.
\documentclass[a4paper]{article}
\usepackage{mathspic}
\begin{document}
%%--------------
\beginpicture
\setsolid
%% compress Y scale to fit equation onto paper
var u=1, v=0.075
paper{units(u cm, v cm), xrange(-4,5), yrange(-50,10), axes(XY), ticks(1,0)}
%% place values at ends of the Y-axis
\axis left shiftedto x=0
\ ticks withvalues $-50$ $10$ /
\ at -50 10 / /
\endpicture
\end{document}
10
−4 −3 −2 −1 1 2 3 4 5
−50
mm cm pt bp pc in dd cc sp
1 mm 1,000 0,100 2,845 2,835 0,2371 0,03937 2,659 0,2216 186 467,98
1 cm 10,00 1,000 28,45 28,35 2,371 0,3937 26,59 2,216 1 864 679,8
1 pt 0,3515 0,03515 1,000 0,9963 0,08333 0,01384 0,9346 0,07788 65 536
1 bp 0,3528 0,03528 1,004 1,000 0,08365 0,01389 0,9381 0,07817 65 781,76
1 pc 4,218 0,4218 12,00 11,96 1,000 0,1660 11,21 0,9346 786 432
1 in 25,40 2,540 72,27 72,00 6,023 1,000 67,54 5,628 4 736 286,7
1 dd 0,3760 0,03760 1,070 1,066 0,08917 0,01481 1,000 0,08333 70 124,086
1 cc 4,513 0,4513 12,84 12,79 1,070 0,1777 12,00 1,000 841 489,04
3.5.3 Units
In addition to the usual units mm, cm, and pt, PICTEX accommodates all the other units
used by TEX (see Knuth (1990), Chapter 10), and also uses the same two-letter codes,
namely pc (pica), in (inch), bp (big point), dd (didot), cc (cicero), sp (scaled point).
The available units thus embrace the Metric system (mm, cm), the Didot system (didot,
cicero), and the UK system (point, big point, pica, inch)—see Table 3.1.
Note that if only one unit is indicated in the units option, then mathsPIC uses the
same unit for both the x and y axes. Thus the option units(1mm) in the paper command
is translated by mathsPIC into the following PICTEX command in the output-file. Note
that it is very important to include a numeric value with the units, or alternatively a
variable with the units.
\setcoordinatesystem units <1mm,1mm>
If different scales are required (most commonly when drawing curves and equations)
then both need to be specified in the mathsPIC 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 units(1cm,2mm). However, when the x and
y scales 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 paper command if at all
possible.
Note that variables can also be used to control the x and y units, as shown in the
following example, where the radius (r) and the distance (s) between the label A and its
point-location are fixed irrespective of scaling (i.e. with changes in the value of u) by
dividing the relevant variables by the scaling value u.
var u = 1.5 %% units
paper{units(u mm), xrange(0,100), yrange(0,100)}
...
var r = 2/u, s = 4/u
point(A){30,20}[symbol=circle(r)]
text($A$){A, shift(-s,s)}
CHAPTER 3. THE MATHSPIC SCRIPT FILE 22
3.5.4 Tick-marks
It is recommended that integers are used with the ticks() option; the numeric format
for the ticks() arguments must agree with that used by the xrange() and yrange()
arguments. For example, if the paper() command uses xrange(-5.5,5.5) then the
ticks() option should also use decimals, perhaps ticks(1.0, 1.0). If this rule is
not adhered to then PICTEX may sometimes give unpredictable results when executing
the paper{} command. In general PICTEX gives more pleasing axes if integers are used
throughout the paper command.
3.6 Points
Each point is associated with a point-name which is defined using the point command.
For example, the following command allocates the point-name A to the coordinates
(5,7).
point(A){5,7}
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.
point(C){midpoint(AB)}
point(E){intersection(AB,CD)}
point(J){Q, rotate(P, 25 deg)} %% J = Q rotated about P by 25 deg
Points are interpreted according to their grouping and context. Thus two points repre-
sent either a line or its Pythagorean length. For example, the command drawCircle(P,AB)
means draw a circle, center P with radius equal to the length of the line AB. A group
of three points represents either a triangle, an angle, or two contiguous line-segments,
depending on the circumstances.
3.6.1 Point-name
A point-name must begin with a single letter, and may have up to a maximum of three
following digits. The following are valid point-names: A, B,C3, d185. Since mathsPIC
is not case sensitive the points d45 and D45 are regarded as being the same point.
Sometimes it is necessary to re-allocate new coordinates to an existing point-name,
in which case the point* command is used. This is often used during recursive opera-
tions whereby the mathsPIC file inputs another file (using the 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.
point*(A){xcoord(A)+5, ycoord(A)}
point(P){Q} %% make P the same as Q
3.6.2 Point-symbol
The default point-symbol is ∙ ($\bullet$). However, mathsPIC allows the optional use
of any TEX character or string of characters to represent a particular point, by defining it
in a following square bracket. For example, the point A(5,10) can be represented by the
△ symbol by defining it as follows.
CHAPTER 3. THE MATHSPIC SCRIPT FILE 23
point(A){5,10}[symbol=$\triangle$]
Other examples using the circle() and square() options are:
point(B){A, shift(2,6)}[symbol=circle(2)]
point(C){A, polar(3,26}[symbol=square(3)]
The argument for the circle is the radius, while the argument for the square is the side
length.
The default point-symbol can also be changed to a circle, square, or any TEX
character or string of characters by using the mathsPIC PointSymbol command. Note
that the PointSymbol command only influences subsequent point commands. For
example, the character ⊙ ($\odot$) can be made the new global point-symbol by
using the command PointSymbol($\odot$). The original default point-symbol (∙)
can be re-instituted (reset) using the command PointSymbol(default). The point-
symbol is drawn at the point-location using the drawPoint command; for example,
drawPoint(A), or drawPoint(ABCD).
Since most TEX characters and symbols are typeset asymmetrically in relation to the
baseline, they will not, in general, be positioned symmetrically over a point-location.
Most characters are therefore not ideal for use as point-symbols, as they generally
require some slight vertical adjustment in order to position them symmetrically. In view
of this Table A.2 lists those TEX characters which are particularly suitable, since they
are automatically positioned by TEX symmetrically with respect to a point-location (for
example the ⊙ character $\odot$), and are therefore ideal for use in this setting.
point(A){3,10}[symbol=$\triangle$,radius=5]
If only the line-free radius is to be specified for the default point-symbol then we can
use the command pointsymbol(default,5). To change the line-free radius of an
existing point then use the following command.
point*(A){A}[radius=10]
which is equivalent to
point*(A){xcoord(A), ycoord(A)}[radius=10]
Table 3.2 gives a list of useful point-symbols which TEX places symmetrically
over a point-location (note that $\Box$ and $\Diamond$ are not placed symmetrically
over a point location, but $\square$ and $\lozenge$ are). Other useful symbols are
available from the textcomp fonts5 (see also the ‘symbol list’ compiled by Pakin which
shows virtually all the available symbols6 ).
5 See Harold Harders’ useful file (textcomp.tex) which shows the characters of the textcomp font
For example, the following commands will draw lines between points ABC, such
that the lines just touch the edge of the ⊙ point-symbol (line-free radius 1.2 mm; 10pt
font).
pointSymbol($\odot$, 1.2)
point(A){1,1}
point(B){2,2}
point(C){1,3}
drawline(ABC)
Table 3.2: Useful point-symbols and their radii for 10–12pt fonts.
radius mm
symbol symbol package
10pt / 11pt / 12pt
$\circ$ ∘ 0.70 / 0.75 / 0.80 standard
$\odot$ ⊙ 1.20 / 1.35 / 1.50 standard
$\oplus$ ⊕ 1.20 / 1.35 / 1.50 standard
$\ominus$ ⊖ 1.20 / 1.35 / 1.50 standard
$\oslash$ ⊘ 1.20 / 1.35 / 1.50 standard
$\otimes$ ⊗ 1.20 / 1.35 / 1.50 standard
$\bigcirc$ ○ 1.70 / 1.85 / 2.05 standard
J
$\bigodot$ 1.70 / 1.85 / 2.05 standard
L
$\bigoplus$ 1.70 / 1.85 / 2.05 standard
N
$\bigotimes$ 1.70 / 1.85 / 2.05 standard
$\star$ ? — standard
$\triangle$ △ — standard
$\square$ — amssymb.sty
$\blacksquare$ — amssymb.sty
$\lozenge$ ♦ — amssymb.sty
$\blacklozenge$ — amssymb.sty
$\bigstar$ F — amssymb.sty
$\boxdot$ — amssymb.sty
$\boxtimes$ — amssymb.sty
$\boxminus$ — amssymb.sty
$\boxplus$ — amssymb.sty
$\divideontimes$ > — amssymb.sty
CHAPTER 3. THE MATHSPIC SCRIPT FILE 25
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 point*
command to set a line-free radius of 2 units for a pre-existing point (P), as follows.
point*(P){P}[radius=2]
By way of illustration, this command is used in drawing Figure 3.2 where arrows
are being drawn from various directions (B, S) to a text box centered on point P ⊙ (the
code is shown below as mpicpm03-2.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. The arrowshape used
here is the default shape which is defined as follows (see Section 7.3 for details).
arrowshape(2mm,30,40)
3 ..
.. . .
......
...... ....... .......
.... ...
..
.. .. ..
... ... ... ...
.. ..
... ...
. . .. ...
2 S •
..............................................
... text ...
.. ⊙p box ...
..
..
.
..
... . .
... . ..
.. .. . .
............. .... .. ..
...
.. ...... . .. .... ...... ..
...... ... ....... ....... . ..
1 ... ........... .
.
.... .
...... ..
...... ..... .
....
.....
B • ......
.
....... ......
....... . .......
...... ....... .......
0
0 1 2 3 4 5 6
Figure 3.2:
\newcommand{\textbox}{\fbox{text\hspace{17mm}box}}%
text(\textbox){P}
\endpicture
Of course, sometimes it is convenient just to draw the arrows a certain length from one
point towards another point. For example, in order to draw an arrow 1 unit long from
point A towards point B we could use the following two commands
point(Z){pointonline(AB,1)} % Z is point 1 unit from A towards B
drawArrow(AZ)
3.7 Lines
mathsPIC draws lines using its drawLine and drawThickline commands. For ex-
ample, a line from P1 to P2 is drawn with the command drawLine(P1P2). If a
line is to be drawn through several points (say, J1 , J2 , J3 , J4 , J5 ) and can be drawn
without ‘lifting the pen’, then this can be achieved using the single mathsPIC com-
mand drawLine(J1J2J3J4J5). Several unconnected lines can also be drawn us-
ing one command by separating each line sequence with a comma; for example,
drawLine(J1J2,J3J4J5,J1J3).
A line can also be drawn a specified distance from one point towards (or away
from) another point, using the following two-step approach. For example, the following
commands draws a line a distance d units from point A towards point B.
point(Z){pointonline(AB,d)}
drawline(AZ)
Note that the order of the points AB and the sign of the distance d are important. For
example, the following commands will draw a line a distance d units from point B away
from point A.
point(Z){pointonline(BA,-d)}
drawline(BZ)
Since the PICTEX \putrule command for drawing horizontal or vertical lines is much
more memory efficient than the \plot command, mathsPIC automatically invokes the
\putrule command for horizontal and vertical lines.
linethickness(2pt)
CHAPTER 3. THE MATHSPIC SCRIPT FILE 27
The default value is 0·4pt, and resetting to this value is achieved by the following
command
linethickness(default)
Sometimes when drawing thick lines it is useful to be able to manipulate the line ends
(e.g. when drawing shapes with horizontal and vertical lines). Consequently it is useful
to be able to access the numeric value of the current linethickness (in the units defined
by the paper command), and this can be done using the var command as follows.
var t = _linethickness_
The mathsPIC drawLine() command uses the current dot size. However, the
mathsPIC drawThickline() command uses the \large dot size, but then resets the
dot size to the default \tiny. For example, the commands
point(A){5,5}
point(B){10,10}
drawThickline(AB)
will result in the following code in the output-file.
%% point(A){5,5} (5,5)
%% point(B){10,10} (10, 10)
%% drawThickline(AB)
\setplotsymbol ({\usefont{OT1}{cmr}{m}{n}\large .})%
{\setbox1=\hbox{\usefont{OT1}{cmr}{m}{n}\large .}%
\global\linethickness=0.31\wd1}%
\plot 5.00000 5.00000 10.00000 10.00000 / %% PQ
\setlength{\linethickness}{0.4pt}%
\setplotsymbol ({\usefont{OT1}{cmr}{m}{n}\tiny .})%
PICTEX7
PICTEX draws lines using two different methods depending on whether the lines are
(a) horizontal or vertical, (b) any other orientation. Furthermore these two groups use
different commands for controlling line-thickness, as follows.
Horizontal and vertical lines (rules): Horizontal and vertical lines are drawn
using the PICTEX \putrule command8 and consequently the thickness of such lines is
controlled by the PICTEX
\linethickness command (the default line-thickness is 0·4pt). For example, the
following PICTEX command changes the thickness to 1pt.
\linethickness=1pt
Note also that the PICTEX \linethickness command can also be reset to its default
value (0·4pt) by the PICTEX \normalgraphs command (see chapter on PICTEX com-
mands), which resets all PICTEX graph-drawing parameters to their default values,
including \linethickness.
Since the graph axes are drawn using horizontal and vertical lines PICTEX draws
them using the \putrule command, i.e. using the \linethickness command. For
example, the following commands can be used to draw thick axes.
7 See also Chapter E on PICTEX.
8 Note that the PICTEX ∖putrule command employs the TEX and LATEX ∖rule command, and so is only
used for horizontal and vertical lines.
CHAPTER 3. THE MATHSPIC SCRIPT FILE 28
\linethickness=2pt
paper{units(1mm),xrange(0,50),yrange(0,50),axes(XY)}
\linethickness=0.4pt %% reset to default
Other lines and curves: PICTEX draws all other lines (non-horizontal non-vertical)
and curves are drawn using the PICTEX \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 \setplotsymbol command, the default size of
dot being {\tiny .}. Larger dots therefore generate thicker lines. For example, the
following PICTEX command sets the dot to a larger size.
\setplotsymbol({\Large .})
3.7.2 Recommendations
In general it is recommended that the mathsPIC linethickness() command is used as
this automatically sets both the PICTEX \putrule and \setplotsymbol() commands9 .
However, under certain circumstances it may be convenient to set the PICTEX commands
directly, as described below.
If you do use PICTEX commands for drawing lines you need to remember that
since PICTEX uses two groups of commands for controlling the thickness of lines (i.e.
\linethickness and \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 3.3 for a 10-point font (note that the
default sizes are 0·4-point and \tiny).
If macros are required, then this can be done easily with a TEX macro using the
PICTEX commands directly. For example, the following code draws a medium-thick line
AB by invoking the command \mediumthickline.
\newcommand{\mediumthickline}{%
\linethickness=1.1pt%
\setplotsymbol({\large .})}%
...
\mediumthickline%
drawline(AB)
9 See Section 3.7
CHAPTER 3. THE MATHSPIC SCRIPT FILE 29
3.8 Text
Text is typeset using the text command and, by default, is centered both horizontally
and vertically at a defined point. For example, the words ‘point Z’ would be placed at
the point Z using the command text(point $Z$){Z}.
Text can be located relative to a point-location using the shift(dx,dy) or polar(r,θ )
commands. For example, points P1 P2 P3 could have their labels located 4 units from
each point as follows.
var 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)}
Optionally, text can be positioned relative to a given point using appropriate combina-
tions of the case sensitive PICTEX options l t r B b to align the left edge, right edge,
top edge, Baseline, bottom edge of the text respectively, as described in the PICTEX
manual. For example in the diagram below (Figure 3.3) the text box a nice box is
aligned such that the right edge of the text box is centered vertically at the point P using
the [r] option as follows.
point(P){25,5}
text(\fbox{a nice box}){P}[r]
Figure 3.3:
Text can also be placed at a point-location (using a DrawPoint command), if the text
is defined as the optional point-symbol (in square brackets) associated with a point
CHAPTER 3. THE MATHSPIC SCRIPT FILE 30
3.9.3 Mathematics
All the usual mathematical operations can used with variables (see Section 4.1), both
when defining a variable, and in places where variables can be used as parameters. When
using ‘scientific’ notation mathsPIC allows either e or E; for example, var j25=7E-2
and point(P){3, 2.34e2}. The constants π and e are available as _Pi_ and _e_.
The following are examples of valid commands.
CHAPTER 3. THE MATHSPIC SCRIPT FILE 31
60
•
50
40
•
30
20
10
0
0 10 20 30 40 50 60
Figure 3.4:
Chapter 4
mathsPIC commands
All mathsPIC commands (except macros) are case-insensitive. This is a design feature
which allows the user to customise the commands and make them easier to read.
mathsPIC macros, however, are case-sensitive, but since macro-names are created
by the user they are customised from the outset by definition.
The arguments of mathsPIC commands are either strings (any legitimate TEX or
LATEX commands or characters which can be put into an \hbox), point-names (e.g. A,
B2, C345), or numerical expressions. Where appropriate, mathsPIC allows scalar
quantities in commands to be represented by either a numeric value (e.g. 0·432), a
variable name (e.g. r2), two point names representing the Pythagorean distance between
two points (e.g. AB), or even a mathematical expression1 . For example, the structure of
the command DrawCircle(⟨centre ⟩,⟨radius ⟩) is quite flexible, as follows.
point(C){5,5}
drawCircle(C,4.32)
drawCircle(C,r2)
drawcircle(C,AB)
drawCircle(C, r3*tan(0.6)/4)
4.1 Mathematics
A leading zero must always be used for decimals whose absolute value is < 1. The
argument of trigonometric functions is in radians. Inverse trigonometric functions return
a value in radians.
∙ Constants:
for π (3·14159. . . ) use _Pi_ or _pi_;
for ‘e’ (2·718281. . . ) use _E_ or _e_;
for ‘180/Pi’ use _R2D_;
for ‘Pi/180’ use _D2R_;
34
CHAPTER 4. MATHSPIC COMMANDS 35
4.1.1 Macros
mathsPIC allows the definition of one-line macros with or without arguments, which
evaluate to a ‘numerical expression’ (see Section 4.2) (i.e. not strings). Macro definition
has the following syntax:
%def ⟨macro-name⟩ ( [ ⟨parameters⟩ ] ) ⟨macro-code⟩
where ⟨parameters⟩ is a list of comma separated strings (e.g. x,y,z). Always place a %
symbol at the end of the ⟨macro-code⟩ to limit additonal white space. The ⟨macro-code⟩
can be optionally delimited using round brackets if necessary to help make it more
readable. Examples of valid macros are as follows:
%def two()2% % a macro called two
%def two()(2)%
Macros which take a parameter can be useful in a slightly different way. For example,
since Perl does not have separate commands for log10 () and loge ()—it only has one
log command, namely log() for loge ()—you may wish to define separate commands
to make it easy to distinguish between the two. This is easily done with macros taking a
single parameter as follows.
%%--- mathspic.lib---
%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---
This library file can then be input at the beginning of the mathsPIC script, as follows.
inputfile{mathspic.lib}
CHAPTER 4. MATHSPIC COMMANDS 37
point(P25){0,0}
var a=2, b1360=4
const e=2.17
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 having an absolute value less than one. The syntax
of the numerical expression, which we will refer to as ⟨expr⟩ is therefore as follows:
⟨expr⟩ ::= ⟨two-points⟩ | ⟨number⟩ | ⟨variable⟩ | ⟨maths⟩
Units
When dealing with commands we will refer frequently to the term ‘unit’ by which is
meant one of the valid TEX units (see Knuth (1986) p. 57).
⟨unit⟩ ::= ⟨mm⟩ | ⟨cm⟩ | ⟨pt⟩ | ⟨pc⟩ | ⟨in⟩ | ⟨dd⟩ | ⟨cc⟩ | ⟨sp⟩
A unit requires a scalar; for example, in the units() option in the paper{} command
we would write something like paper{units(1cm, 3cm), ..} to define the scale for
the (x, y) axes etc.
Line thickness
Commands and parameters which control line-thickness are described in Section 3.7.1.
4.2.1 Backslash
∙ ∖... ∖␣ ␣ ...
∙ Notes
A line having a leading backslash is processed (copied verbatim) slightly differ-
ently depending on whether the character following the backslash is a space or
not.
3 From mathsPIC version 1.11 onwards.
CHAPTER 4. MATHSPIC COMMANDS 38
4.2.2 ArrowShape
This command defines the shape of an arrowhead, and allows arrowheads to be cus-
tomised (see Section 7.3 for details).
∙ Syntax
ArrowShape( ⟨expr⟩ [⟨units⟩] , ⟨expr⟩ , ⟨expr⟩ )
ArrowShape(default)
∙ Notes
The first parameter is the length of the arrow head itself. If ⟨units⟩ are not given
then the current default units will be applied. The last two parameters are angles
(default is degrees) which define the shape of the arrow head (see Section 7.3 for
details).
The default arrow shape is equivalent to the command Arrowshape(2mm,30,40).
This default arrowhead shape can be reset using Arrowshape(default) com-
mand.
∙ Examples
Arrowshape(4mm,30,60)
var h = 3
Arrowshape((3*h)mm,30,60)
drawArrow(AB)
Arrowshape(default)
drawArrow(PQ)
4.2.5 Const
The const command is used to define scalar constants.
∙ Syntax
const ⟨name⟩ = ⟨expr⟩ [, ⟨name⟩ = ⟨expr⟩ ] ...
CHAPTER 4. MATHSPIC COMMANDS 39
∙ Notes
The constant name follows the same naming convention as points and variables
(see Section 4.2). The scalar argument can be any numeric expression. There is
no terminal comma. If a new value is allocated to an existing constant name then
mathsPIC issues an error message.
∙ Example
const h=5
const r = 20, r4 = r3*tan(0.3)
4.2.6 DashArray
The dasharray command takes an arbitrary number of paired arguments that are used
to specify a dash–gap–dash. . . pattern.
∙ Syntax
dasharray ( DASH , GAP [ DASH , GAP ] ... )
DASH ::= ⟨expr⟩ ⟨unit⟩
GAP ::= ⟨expr⟩ ⟨unit⟩
∙ Notes
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 ␣ or with round brackets ( )
as shown below.
Macros are useful for allocating names to frequently used dashArray commands.
∙ 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)
%def fancydashes()dasharray(6pt, 2pt, 1pt, 2pt)%
4.2.7 DrawAngleArc
This command draws an arc in the specified angle, a distance radius from the angle.
∙ Syntax
drawAngleArc{ ANGLE , RADIUS , LOCATION , DIRECTION }
ANGLE ::= angle( ⟨three-points⟩ )
RADIUS ::= radius( ⟨expr⟩ )
LOCATION ::= internal | external
DIRECTION ::= clockwise | anticlockwise
CHAPTER 4. MATHSPIC COMMANDS 40
∙ Notes
The angle location is either internal (≤ 180∘ ) or external (≥ 180∘ ). 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 parameter
order angle/radius/internal/clockwise etc is important.
∙ Examples
DrawAngleArc{angle(ABC), radius(3), external, clockwise}
var r = 2
DrawAngleArc{angle(PQR), radius(r), internal, anticlockwise}
4.2.8 DrawAngleArrow
This command draws an arrow in the specified angle, a distance radius from the angle.
∙ Syntax
drawAngleArrow{ ANGLE , RADIUS , LOCATION , DIRECTION }
ANGLE ::= angle( ⟨three-points⟩ )
RADIUS ::= radius( ⟨expr⟩ )
LOCATION ::= internal | external
DIRECTION ::= clockwise | anticlockwise
∙ Notes
The angle location is either internal (≤ 180∘ ) or external (≥ 180∘ ). The direction
of the arrow is either clockwise or anticlockwise, and this direction must corre-
spond with the letter sequence specified for the angle. Strange and unexpected
results will be produced if the four parameters are not internally consistent. The
parameter order angle/radius/internal/clockwise etc is important.
The radius can be any numerical expression.
∙ Examples
DrawAngleArrow{angle(ABC), radius(3), external, clockwise}
var r = 2
DrawAngleArrow{angle(PQR), radius(r), internal, anticlockwise}
4.2.9 DrawArrow
This command draws an arrow(s) joining two points.
∙ Syntax
drawArrow ( ⟨two-points⟩ [ , ⟨two-points⟩ ] . . . )
∙ Notes
The direction of the arrow is in the point order specified. The shape of the arrow-
head is controlled by the ArrowShape command (see Section 7.3). Commands
and parameters which control line-thickness are described in Section 3.7.1.
∙ Examples
drawArrow(AB)
drawArrow(FG, HJ)
CHAPTER 4. MATHSPIC COMMANDS 41
4.2.10 DrawCircle
Draws a circle with its centre at a given point and with a given radius.
∙ Syntax
DrawCircle ( CENTRE , RADIUS )
CENTRE ::= ⟨point⟩
RADIUS ::= ⟨expr⟩
∙ Notes
Note that PICTEX draws circles with the \circulararc command, using a radius
equivalent to the distance from the centre 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 units command.
∙ Examples
drawCircle(C2,5)
var r2=3
drawCircle(C2,r2)
drawCircle(C2,(r2/tan(1.2)) )
drawCircle(C2,AB)
4.2.11 DrawCircumcircle
Draws the circumcircle of a triangle defined by three points
∙ Syntax
DrawCircumcircle( ⟨three-points⟩ )
∙ Example
drawCircumcircle(ABC)
4.2.12 DrawCurve
Draws a smooth quadratic curve through three points in the order specified.
∙ Syntax
DrawCurve ( ⟨three-points⟩ )
∙ Notes
This command will be upgraded in the next version to apply to more than three
points.
Note that curves drawn using this command do not break to avoid line-free
zones associated with the points (the drawLine command for straight lines does
acknowledge line-free zones).
∙ Example
drawCurve(ABC)
CHAPTER 4. MATHSPIC COMMANDS 42
4.2.13 DrawExcircle
Draws the excircle touching a given side of a triangle.
∙ Syntax
DrawExcircle( TRIANGLE , SIDE )
TRIANGLE ::= ⟨three-points⟩
SIDE ::= ⟨two-points⟩
∙ Example
drawExcircle(ABC,BC)
4.2.14 DrawIncircle
Draws the incircle of a triangle defined by three points
∙ Syntax
DrawIncircle( ⟨three-points⟩ )
∙ Example
drawIncircle(ABC)
4.2.15 DrawLine
This command draws a line(s) between sets of two or more points.
∙ Syntax
drawLine ( LINE [ , LINE ] ... )
LINE ::= ⟨two-points⟩ [ ⟨point⟩ ] . . .
∙ Notes
Lines are drawn in the point order specified. Commands and parameters which
control line-thickness are described in Section 3.7.1.
Note that the drawline command uses the PICTEX \putrule command for
horizontal and vertical lines, and the \plot command for lines of all other
orientations.
∙ Examples
drawLine(AB)
drawLine(FG, HJ)
var d = 3
4.2.16 DrawPerpendicular
Draws the perpendicular from a point to a line.
∙ Syntax
DrawPerpendicular( ⟨point⟩ , LINE )
LINE ::= ⟨two-points⟩
∙ Example
drawPerpendicular(P, AB)
CHAPTER 4. MATHSPIC COMMANDS 43
4.2.17 DrawPoint
Draws a symbol at the point-location.
∙ Syntax
DrawPoint( ⟨point⟩ [ ⟨point⟩ ] ...)
∙ Notes There must be no commas in the list of points (spaces are allowed).
∙ Example
drawpoint(T4)
drawpoint(ABCDEF)
drawpoint(P1 P2 P3 P4)
4.2.18 DrawRightangle
Draws the standard right-angle symbol in the internal (acute) angle specified. If the angle
is not exactly 90∘ then mathsPIC draws the required symbol in perspective (i.e., each
arm is still drawn parallel to the respective lines).
∙ Syntax
DrawRightangle( ⟨three-points⟩ , ⟨expr⟩ )
∙ Example
drawRightangle(ABC,3)
4.2.19 DrawSquare
Draws a square at a given point with a given side-length.
∙ Syntax
DrawSquare( ⟨point⟩ , ⟨expr⟩ )
∙ Example
drawSquare(P,5)
drawSquare(P,s2)
drawSquare(P, s2*4/(3*j))
drawSquare(P,AB)
4.2.20 DrawThickArrow
This command draws a thickarrow(s) joining two points.
∙ Syntax
drawThickArrow ( ⟨two-points⟩ [ , ⟨two-points⟩ ] . . . )
∙ Notes
The direction of the arrow is in the point order specified. The shape of the arrow-
head is controlled by the ArrowShape command (see Section 7.3). Commands
and parameters which control line-thickness are described in Section 3.7.1.
∙ Examples
drawThickArrow(AB)
drawThickArrow(FG, HJ)
CHAPTER 4. MATHSPIC COMMANDS 44
4.2.21 DrawThickLine
This command draws a thick line(s) between sets of two or more points.
∙ Syntax
drawThickLine ( LINE [ , LINE ] ... )
LINE ::= ⟨two-points⟩ [ ⟨point⟩ ] . . .
∙ Notes
Lines are drawn in the point order specified. Commands and parameters which
control line-thickness are described in Section 3.7.1.
Note that the drawThickLine command uses the PICTEX \putrule command
for horizontal and vertical lines, and the \plot command for lines of all other
orientations.
∙ Examples
drawThickLine(AB)
drawThickLine(FG, HJ)
var d = 3
4.2.22 InputFile
Inputs a plain text file containing mathsPIC commands, one or more times.
∙ Syntax
InputFile( ⟨file-name⟩ ) [ LOOP ]
LOOP ::= ⟨expr⟩
∙ Notes
Optionally, the file can be input [LOOP] times, in which case this command can
be used to implement something akin to a primitive DO – LOOP if the file contains
mathsPIC commands.
See also the LOOP command (a beginLOOP...endLOOP environment).
If LOOP is not an integer then mathsPIC will round the value down to the nearest
integer. Note that the inputfile* command has no [LOOP] option.
∙ Example
The following command inputs the file newfile.dat 4 times in succession.
inputFile(myfile.dat)[4]
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 com-
mands or data-points for plotting etc. A typical example might be the fol-
lowing file (curve-A.dat) which would be input verbatim using the command
inputfile*(curve-A.dat). (Note that PICTEX requires an ODD number of
points).
CHAPTER 4. MATHSPIC COMMANDS 45
%% curve-A.dat
\setquadratic
\plot
0 0
3.56 4.87
8.45 9.45
5 7
2.34 3.23 /
\setlinear
4.2.23 LineThickness
Sets a particular linethickness.
∙ Syntax
Linethickness ( ⟨expr⟩ ⟨units⟩ )
Linethickness (default)
∙ 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. For example
the command linethickness(2pt) results in the following commands in the
output .mt file.
\linethickness=2.00000pt\Linethickness{2.00000pt}%
\font\CM=cmr10 at 9.94451pt%
\setplotsymbol ({\CM .})%
var t = _linethickness_
∙ Example
linethickness(2pt)
linethickness(default)
var t = _linethickness_
∙ Notes The block of code which lies within the environment is input ⟨expr⟩ times.
∙ Example
beginLoop 5
...
endLoop
4.2.25 Paper
Defines the plot area and scale, and optional axes and tick marks.
∙ Syntax
Paper{ UNITS , XRANGE , YRANGE , AXES , TICKS }
UNITS ::= units( ⟨expr⟩ ⟨units⟩ [ , ⟨y-expr⟩ ⟨y-units⟩ ] )
XRANGE ::= xrange( ⟨low-expr⟩ , ⟨high-expr⟩ )
YRANGE ::= yrange( ⟨low-expr⟩ , ⟨high-expr⟩ )
AXES ::= axes( [⟨L⟩[*]] [⟨R⟩[*]] [⟨T⟩[*]] [⟨B⟩[*]] [⟨X⟩[*]] [⟨Y⟩[*]] )
TICKS ::= ticks( ⟨x-expr⟩ , ⟨y-expr⟩ )
∙ Notes
The following statement sets up a rectangular drawing area 5 cm × 5 cm with
axes on the Left (y-axis) and Bottom (x-axis), and tick marks at 1 cm intervals.
Note that the order of the options units()...ticks() MUST adhere to the order
shown here (this will be made flexible in a later version).
paper{units(1cm),xrange(0,5),yrange(0,5),axes(LB),ticks(1,1)}
4.2.26 Point
Allocates coordinates to a point-name. A point name must begin with a single letter
(either upper or lower case), and may have up to a maximum of four4 following digits,
e.g., P1326.
∙ Syntax
Point [*] ( ⟨point⟩ ) { ⟨point⟩ } [ OPTION [, OPTION] ]
Point [*] ( ⟨point⟩ ) { LOCATION } [ OPTION [, OPTION] ]
LOCATION ::= ⟨x-expr⟩ , ⟨y-expr⟩
LOCATION ::= xcoord( ⟨point⟩ ) , ycoord( ⟨point⟩ )
LOCATION ::= midpoint( ⟨two-points⟩ )
LOCATION ::= intersection( ⟨two-points⟩ , ⟨two-points⟩ )
LOCATION ::= PointOnLine( ⟨point⟩ , ⟨expr⟩ )
LOCATION ::= perpendicular( ⟨point⟩ , ⟨two-points⟩ )
LOCATION ::= Circumcirclecenter( ⟨three-points⟩ )
LOCATION ::= Incirclecenter( ⟨three-points⟩ )
LOCATION ::= Excirclecenter( ⟨three-points⟩ , ⟨two-points⟩ )
LOCATION ::= ⟨point⟩ , POINT- FUNCTION
POINT- FUNCTION ::= shift( ⟨x-expr⟩ , ⟨y-expr⟩ )
POINT- FUNCTION ::= polar( ⟨r-expr⟩ , ⟨θ -expr⟩ )
POINT- FUNCTION ::= rotate( ⟨point⟩ , ⟨θ -expr⟩ )
POINT- FUNCTION ::= vector( ⟨two-points⟩ )
OPTION ::= symbol = CHARS | radius = ⟨expr⟩
CHARS ::= ⟨string⟩ | square( ⟨expr⟩ ) | circle( ⟨expr⟩ )
∙ Notes
The default point-symbol is the $\bullet$. An optional alternative point-symbol
(or string of characters) can be specified within square brackets, as for example:
[symbol=$\triangle$]
By default lines drawn to a ‘point’ are drawn to the point location. However, the
radius of an optional line-free zone (line-free radius) can be specified within an
optional square bracket e.g. [symbol=$\triangle$,radius=2]. A line-free
radius option can be specified by itself, for example [radius=2].
The polar(r,theta) defaults to radians for the angle theta. If degrees are
required then need to append < deg >; e.g. polar(r,theta deg). Note that
direction() or directiondeg() can be used instead of theta, as for example:
point(D4){D2, polar(6,direction(AB))} (see also the Examples at the
end on the following page).
An optional symbol=circle() or symbol=square() can also be used as the
symbol. In these cases a numeric expression is required as the argument, and is
taken to be the side length (for square()) or circle-radius (for circle()). If
4 From mathsPIC version 1.11 onwards.
CHAPTER 4. MATHSPIC COMMANDS 48
a radius ⟨expr⟩ is also included then the square will have associated with it a
line-free radius of the specified value, e.g., [symbol=square(2), radius=5];
and similarly if the symbol is a circle.
Note (1) there must be a comma between the options, and (2) the options are not
order specific. If no line-free radius value is specified, the line-free radius used is
the current (default) value).
Points can also be defined relative to 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, (e.g. the
PointOnLine() construction).
If the command point(){} is used to reallocate new parameters to an existing
point-name then mathsPIC will generate a warning message indicating that an
existing point-name is being reallocated. For example, the following code
point(S){6,6}
point(S){7,7}
will generate the following warning message in the output file, but still reallocate
the point-name.
%% point(S){6,6} S = (6, 6)
%% *** Line 15: point(S
%% *** ){7,6}
%% ... Warning: Point S has been used already
%% point(S){7,6} S = (7, 6)
%% point(S){6,6} S = (6, 6)
%% point*(S){7,6} S = (7, 6)
∙ Examples
point(A){5,5}
point(B2){22,46}[symbol=$\odot$]
point(B2){22,46}[symbol=circle(2),radius=5]
point(B2){22,46}[symbol=square(3),radius=5]
point(B2){22,46}[radius=5]
point(D2){B2, shift(5,5)}
point(D3){D2, polar(6,32 deg)}
point(D4){D2, polar(6,1.2 rad)}
point(D4){D2, polar(6,direction(AB))}
point(D4){D2, polar(6,directiondeg(AB)deg)}
point(G2){Q, rotate(P, 23 deg)}
point(J4){B2, vector(AB)}
point(D2){midpoint(AB)}
point(D2){intersection(AB,CD)}
point(F){PointOnLine(AB,5.3)}
CHAPTER 4. MATHSPIC COMMANDS 49
point(G){perpendicular(P,AB)}
point(H){circumcirclecenter(ABC)}
point(J){incirclecenter(ABC)}
point(K){excirclecenter(ABC,BC)}
point*(A){6,3}
point*(B){B, shift(5,0)}
point*(P){J} %% make J have the same coords as P
point*(P){xcoord(J),ycoord(J)} %% same as Point*(P){J}
4.2.27 PointSymbol
Sets a particular point-symbol and line-free radius.
∙ Syntax
pointSymbol ( ⟨chars⟩ , ⟨expr⟩ )
pointSymbol (square(⟨expr⟩) , ⟨expr⟩ )
pointSymbol (circle(⟨expr⟩) , ⟨expr⟩ )
∙ Notes
This command allows the default point-symbol ($\bullet$, line-free radius
zero) to be changed. The square option takes the side-length as argument. The
circle option takes the radius as argument.
The PointSymbol command is particularly useful where a set of points uses the
same point-symbol, and also when drawing graphs.
For example, the following command changes the point-symbol to ⊙ having a
line-free radius of 0·7 units.
PointSymbol($\odot$, 0.7)
Note that the PointSymbol command only influences subsequent point com-
mands, i.e., it should be placed before the defining point command. The optional
square bracket of the point command overrides the PointSymbol command. The
point-symbol can be reset to the default ($\bullet$, zero line-free radius) using
the command PointSymbol(default).
∙ Example
PointSymbol($\odot$, 0.7)
PointSymbol(square(4), 5)
PointSymbol(circle(3), 3)
var r = 1.2
PointSymbol($\triangle$, 0.7)
PointSymbol(circle(r), r)
pointSymbol(default)
∙ Notes
It is useful in development for by-passing commands (i.e. its function is equivalent
to the \iffalse....\fi commands in a TEX document).
4.2.29 Show...
This command makes mathsPIC return the value of a calculation or specified parameter.
∙ Syntax
ShowLength ( ⟨two-points⟩ )
ShowAngle ( ⟨three-points⟩ )
ShowArea ( ⟨three-points⟩ )
ShowPoints
ShowVariables
∙ Notes
The showarea() command is only for triangles. The results of the Show...
commands are shown in the output-file as a commented line.
∙ Example
showLength(AB)
showAngle(ABC)
showArea(ABC)
showPoints
showVariables
When the above examples are processed, the results appear as commented lines
in the output-file as follows.
%% Length(AB) = 25.35746
%% Angle(ABC) = 39.35746 deg (0.68691 rad)
%% Area(ABC) = 54.54267
%%-------------------------------------------------
%% L I S T O F P O I N T S
%%-------------------------------------------------
%% q = (8.000, 9.000), LF-radius = 5.000, symbol = $\bigodot$
%% s = (6.000, 6.000), LF-radius = 0.000, symbol = $\bullet$
%% p = (5.000, 5.000), LF-radius = 3.000, symbol = $\circle$
%% t = (5.000, 5.000), LF-radius = 7.000, symbol = $\square$
%%-------------------------------------------------
%% E N D O F L I S T O F P O I N T S
%%-------------------------------------------------
%%-------------------------------------------------
%% L I S T O F V A R I A B L E S
%%-------------------------------------------------
%% a = 4
%% b = 12
%%-------------------------------------------------
%% E N D O F L I S T O F V A R I A B L E S
%%-------------------------------------------------
CHAPTER 4. MATHSPIC COMMANDS 51
4.2.30 System
This command allows the user to access the command line and execute system com-
mands. Allows programs to be run from within mathsPIC.
∙ Syntax
system ( " ⟨command⟩ " )
∙ Notes
The whole command must be delimited by inverted commas. For example,
the following command will temporarily stop mathsPIC processing, access the
command-line and run LATEX on the file myfile.tex, and then seamlessly return
and continue mathsPIC processing.
system("latex2e myfile.tex")
Alternatively, the system() command may be used to create a small batch file
on-the-fly in order to facilitate some procedure. In mathsPIC a common use is for
running a Perl program to write mathsPIC commands to a temporary file which
is then input by mathsPIC (see the examples at the end of the Examples chapter).
∙ Example
system("dir > mydir-listing.txt")
system("perl drawbox.pl 5 5 temp.txt")
inputFile(temp.txt)
4.2.31 Text
Places text at a given location.
∙ Syntax
Text ( ⟨string⟩ ) { LOCATION } [ POSSN [, POSSN] ]
LOCATION ::= ⟨point⟩
LOCATION ::= ⟨x-expr⟩ , ⟨y-expr⟩
LOCATION ::= ⟨point⟩ , POINT- FUNCTION
POINT- FUNCTION ::= shift( ⟨x-expr⟩ , ⟨y-expr⟩ )
POINT- FUNCTION ::= polar( ⟨r-expr⟩ , ⟨θ -expr⟩ )
POSSN ::= l | t | r | R | b
∙ Notes
This command puts the given text-string either at the named point, or with
a displacement specified by the optional shift() or polar() or rotate()
functions. By default the text is centreed vertically and horizontally at the specified
location.
Optionally, text can be placed relative to the specified location using appro-
priate combinations of the PICTEX position options l t r B b to align the
left edge, right edge, top edge, Baseline, bottom edge respectively of the text
box with the point-location (see the PICTEX Manual, page 5; Wichura, 1992).
CHAPTER 4. MATHSPIC COMMANDS 52
For example, the text box This is point P would be aligned such that the
right edge of the text box would be centreed vertically at the point P, using
text(This is point P){P}[r] (see figure 3.3).
Note that TEX and LATEX macros are very useful for defining blocks of text in
this setting, since the macro name can be used in the text() command for
convenience, as shown in the examples below.
∙ Example
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, rotate(P, 45)}
text(\framebox{$Z5$}){Z3}
\newcommand{\mybox}{\framebox{$Z5$}}
text(\mybox){P421}
4.2.32 Var
The var command is used to define scalar variables. The variable name must begin with
a single letter (either upper or lower case), and may have up to a maximum of four5
following digits.
∙ Syntax
var ⟨name⟩ = ⟨expr⟩ [, ⟨name⟩ = ⟨expr⟩] ...
∙ Notes
The variable name follows the same naming convention as points and variables
(see Section 4.2). The scalar argument can be any numeric expression.
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).
Note that in addition to all the mathematical functions, the following functions
can also be used.
angle(⟨three-points⟩)
angledeg(⟨three-points⟩)
direction(⟨two-points⟩)
directiondeg(⟨two-points⟩)
area(⟨three-points⟩)
xcoord(⟨point⟩)
ycoord(⟨point⟩)
∙ Example
5 From mathsPIC version 1.11 onwards.
CHAPTER 4. MATHSPIC COMMANDS 53
\ 4.5 6.3
%def loge(n)log(n)%
%def fancydashes() dasharray(1pt,2pt,3pt,4pt)%
%def plaindashes() dasharray(1pt,1pt)%
%def d2r()_pi_/180%
%def r2d()180/_pi_%
ArrowShape(4mm,30,50)
ArrowShape(default) %% generates arrowshape(2mm,30,40)
beginLoop ... endLoop 5
beginLoop ... endLoop n
beginNoOutput ... endNoOutput
beginSKIP ... endSKIP
const r40=40
drawAngleArc{angle(ABC), radius(3), internal, clockwise}
drawAngleArrow{angle(ABC), radius(3), internal, clockwise}
drawArrow(AB) %from A to B
drawArrow(AB,CD)
drawCircle(J,12)
drawCircle(C,r2)
drawCircle(C,AB) %% the radius is length of line AB
drawCircumcircle(ABC)
drawCurve(ABC) %% three points only
drawExcircle(ABC)
drawIncircle(ABC)
drawLine(AB)
drawLine(ABCDE)
CHAPTER 4. MATHSPIC COMMANDS 54
drawPerpendicular(P,AB)
drawPoint(B)
drawPoint(ABP1P2)
drawRightAngle(ABC, 4)
drawSquare(P,2) %% side = 2
drawThickArrow(AB)
drawThickArrow(AB,CD)
drawThickLine(RS,TU)
inputFile(mathspic.dat)
inputFile(mathspic.dat)[4]
inputfile*(fig2.dat) %% * disables mathsPIC processing of file
linethickness(2pt)
paper{units(1mm,3mm),xrange(-5,50),yrange(-5,50),axes(LR)}
paper{units(2cm),xrange(0,5),yrange(0,9),axes(X*Y),ticks(1,1)}
paper{units(k mm),xrange(0,5),yrange(0,9),axes(X*Y),ticks(1,1)}
point(D1){20,2}
point(D4){6.3,8.9}
point(P){x1,y1}
point(P){Q} %% make P have same coords as Q
point(P){xcoord(Q),ycoord(Q)} %% same as point(P){Q}
point(P){AB,PQ}
point(P){3,4}[symbol=$\odot$,radius=2]
point(P){3,4}[radius=2]
point(D2){20,2}[symbol=square(2),radius=3]
point(D3){20,3}[symbol=circle(r),radius=5]
point(D4){20,4}[symbol=$\Box$]
point(E1){D1, shift(5,6)}
point(E5){D1, shift(r2,6)}
point(E2){D2, polar(8, 1.34)} %% radians is the default
point(E2){D2, polar(8, 1.34 rad)}
point(E2){D2, polar(8,45 deg)}
point(E6){D2, polar(r4,45 deg)}
point(E2){D2, polar(8, direction(AB))} %% radians is the default
point(E2){D2, polar(8, directiondeg(AB) deg)}
point(E5){D2, polar(AB,45 deg)}
point(G2){Q, rotate(P, 23 deg)} %% rotate Q about P by 23 deg
point(P){J, vector(AB)} %% from J with length and direction AB
point(D32){midpoint(AB)}
point(D2){intersection(AB,CD)}
point(F){PointOnLine(AB,5)}
point(F){PointOnLine(AB,-d)}
point(G){perpendicular(P,AB)}
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}[radius=3] %% change the line-free radius
PointSymbol(circle(r))
PointSymbol(square(1),2)
CHAPTER 4. MATHSPIC COMMANDS 55
PointSymbol($\odot$,2)
PointSymbol(default)
PointSymbol(default,0.5)
showAngle()
showArea()
showLength()
showVariables
showPoints
system("dir > mydir-listing.txt")
system("perl myprogram.pl")
text(P){5,7}
text($A$){A}
text($K$){K}[r]
text($B$){B, shift(5,5)}
text($Z3$){Z2, polar(5, 20 deg)}[Br]
text(\framebox{$Z5$}){Z3}
\newcommand{\mybox}{\framebox{$Z5$}}
text(\mybox){P421}
text(\framebox{$C$}){C, polar(5,62 deg)}[Br]
var r3 = 20, r4 = r3 * tan(0.4), r5 = AB, e=_e_, p1 = _Pi_
var g = angle(ABC)% (returns in radians)
var g = angledeg(ABC)% (returns in degrees)
var a = area(ABC)
var d = direction(PQ) % angular direction of PQ in radians
var d = directiondeg(PQ) % angular direction of PQ in degrees
var x2 = xcoord(A), y2 = ycoord(A)
var m5 = 12 rem 3 %% remainder after dividing by 3
var t = _linethickness_
Chapter 5
PICTEX commands
In this section we present a list of PICTEX commands for use with mathsPIC which
is adequate for most purposes. For a more extensive listing see the excellent 8-page
summary by by Duggan (1990). A 3-page German summary is available from Siart
(2008). Alternatively, there is a nice section on PICTEX in Hoenig (1998), which includes
a brief list of commands.
The complete list of PICTEX commands is long and detailed, and is, unfortunately,
only available currently by purchasing the small The PICTEX Manual by Wichura (1992)1 .
See Chapter E for full details on PICTEX itself and Wichura’s manual (Section E.6).
Wichura’s manual is well worth obtaining if you intend to be adventurous with PICTEX.
PICTEX commands can only be used within the \beginpicture ... \endpicture
environment. 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 (.mt file). For example, drawing with dashed lines is enabled using the
following PICTEX command
\setdashes
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
followed by one or more spaces (e.g. \␣. . . ) as this instruction tells mathsPIC to copy
the rest of the line unchanged (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 (an important point to note is that the
PICTEX algorithm requires that the number of such points is odd—see Section 7.7).
\setquadratic
\plot 1.15 -0.67
\ 1.25 0.02
\ 1.35 1.24 /
\setlinear
1 Available from Personal TEX Inc. ([email protected], http://www.pctex.com/books.html
56
CHAPTER 5. PICTEX COMMANDS 57
When these commands are processed by mathsPIC, they will appear in the output TEX
file (.mt file) as follows.
\setquadratic
\plot 1.15 -0.67
1.25 0.02
1.35 1.24 /
\setlinear
%% and Bottom-right
\inboundscheckon %% restricts plotting to plotting area
\inboundscheckoff %%
\normalgraphs %% restores default values for
%% graph parameters (see Section 4.6.1)
\ticksin
\ticksout
\visibleaxes
\invisibleaxes
\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, i.e. a:b)
Note that PICTEX also has an excellent rotation facility (but only in conjunction
with PICTEX function commands, e.g., \ellipticalarc as shown below, and so will
not rotate points input by mathsPIC via a data-file). PICTEX will rotate about a given
point, by a given angle, all picture elements (but not text) which are detailed between
its \startrotation... and \stoprotation commands. However the decimal value
of the Sine and Cosine angle must be supplied (see below). If a rotation point is not
specified then rotation is performed about the origin. The format is as follows.
\newcommand{\dollar}{\char’44}%
\setcoordinatesystem units <1mm, 1mm>
\setplotarea x from 0 to 50, y from 0 to 50
CHAPTER 5. PICTEX COMMANDS 59
A mathsPIC file (script) can contain any appropriate TEX and LATEX commands, and
most of these commands are for use in the preamble (e.g., headers and footers).
\documentclass[a4paper]{article}
\usepackage{mathspic, color}
\begin{document}
%---------------
\beginpicture
...
...
\endpicture
%---------------
\end{document}
Note that when using TEX or LATEX commands within the PICTEX picture environ-
ment, it is very important to include the comment % 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 spaces into the horizontal
distance used for representing x-coordinates, with the effect that all subsequent picture
elements will be displaced slightly to the right.
If it is necessary (or simply convenient) to extent a TEX or LATEX command across
several lines, then each additional line must be protected by using a leading ∖␣ (a
backslash followed by one or more spaces) unless the line actually starts with a TEX
or LATEX command. A typical example is in the following macro (used in Figure 7.6)
60
CHAPTER 6. TEX AND LATEX COMMANDS 61
which defines a ‘display’ maths formula. The macro is split across several lines as
follows:
\newcommand{\formula}{%
\ $\displaystyle \sum_{p\ge0} \Delta_{jp} z^{(p+1)}$%
\ }%
text(\formula){B}
Examples
This section describes some practical examples of figures drawn using mathsPIC,
together with the associated code.
When drawing a new figure or diagram, it seems best to start with a graduated coor-
dinate frame (see Figure 7.1) using the axes and ticks options of the paper command.
The next step is to define an 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.
Remember that the command \thispagestyle{empty} is, for convenience, im-
plemented by mathspic.sty (see Section 2.7), in order to prevent page numbers
appearing in a figure.
As regards scales and units, it seems most convenient to use the 1mm units and to
keep the x and y scales the same whenever possible (i.e. use paper{units(1mm)...}),
since this allows easy scaling up and down after the figure has been finished, as shown
in Section 7.9.
In practice, the whole process of editing and viewing can be conveniently automated
using a small script, to run mathsPIC, trim the image to the bounding box (BBox) and
generate the required file formats, as described in Section C.1.
63
CHAPTER 7. EXAMPLES 64
0 10 20 30 40 50 60 70
50 50
B
40 ..⊙
. ..... 40
... ... ....
. .....
.... .
... ... ........
... ....
....
.
.. ....
... . ....
... ... .....
.. . .....
..
30 ...
...... ...
..
....
.....
..... 30
... ....
.. ... .....
.... . .....
... . ....
... ....
.
. .
... .....
.... . .....
20 ........
............
.. ... ......... ....
.
. ..
.
...
⊙C
..... 20
.... ........
. ...
.. .
. .
. ................
...
.
...
...............
...................
• ...........
... ..................
... ..................
................................... D
10 ⊙ 10
A
0 0
0 10 20 30 40 50 60 70
Figure 7.1:
\begin{document}
%---------------
\beginpicture
\setdashes
paper{units(1mm),xrange(0,70),yrange(0,50),axes(LRTB),ticks(10,10)}
\setsolid
point(A){10,10}[symbol=$\odot$, radius=1.2] %% anchor point
point(B){A, polar(40, 50 deg)}[symbol=$\odot$, radius=1.2]
point(C){A, polar(50, 10 deg)}[symbol=$\odot$, radius=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)
showAngle(ABC)
\endpicture
\end{document}
When the above mathsPIC file is processed by mathsPIC the output-file (.mt file) is
as follows. Note how the PICTEX commands are preceded by their mathsPIC commands
(commented out), some of which have additional information (e.g. the coordinates of a
derived point—see the line %% point(D)... ). Being able to compare the mathsPIC
CHAPTER 7. EXAMPLES 65
commands and the resulting PICTEX commands in the output-file is particularly useful
when debugging. Note also how the show... commands at the end of the file return
the lengths AD, BC, the area ABC, and the angle ABC.
%* -----------------------------------------------
%* mathsPIC (Perl version 0.99.22 Dec 29, 2004)
%* A filter program for use with PiCTeX
%* Copyright (c) 2004 A Syropoulos & RWD Nickalls
%* Command line: mpic09922.pl -b mpicpm07-1.m
%* Input filename : mpicpm07-1.m
%* Output filename: mpicpm07-1.mt
%* Date & time: 2005/01/05 10:00:40
%* -----------------------------------------------
%% mpicpm07-1.m (figure 7.1)
%% mathsPIC Perl triangle
\documentclass[a4paper]{article}
\usepackage{mathspic}
\begin{document}
%%--------------
\beginpicture
\setdashes
%% paper{units(1mm),xrange(0,70),yrange(0,50),axes(LRTB),ticks(10,10)}
\setcoordinatesystem units <1mm,1mm>
\setplotarea x from 0.00000 to 70.00000, y from 0.00000 to 50.00000
\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}[symbol=$\odot$, radius=1.2]
%% anchor point A = (10.00000, 10.00000)
%% point(B){A, polar(40, 50 deg)}[symbol=$\odot$, radius=1.2]
B = (35.71150, 40.64178)
%% point(C){A, polar(50, 10 deg)}[symbol=$\odot$, radius=1.2]
C = (59.24039, 18.68241)
%% point(D){perpendicular(B,AC)} D = (40.17626, 15.32089)
%% drawPoint(ABCD)
\put {$\odot$} at 10.00000 10.00000 %% A
\put {$\odot$} at 35.71150 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.94015 39.72253 / %% AB
\plot 36.58878 39.82302 58.36311 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)
CHAPTER 7. EXAMPLES 66
If the above output-file (.mt file) is to be included or \input into a document (say,
into a figure environment), it is sometimes useful to reduce the size of the file by
disabling the writing of %% comment lines (using the command-line -c switch), as well
as some of the header and footer lines which are not now required, as follows.
%* -----------------------------------------------
%* mathsPIC (Perl version 0.99.22 Dec 29, 2004)
%* A filter program for use with PiCTeX
%* Copyright (c) 2004 A Syropoulos & RWD Nickalls
%* Command line: mpic09922.pl -c mpicpm07-1.m
%* Input filename : mpicpm07-1.m
%* Output filename: mpicpm07-1.mt
%* Date & time: 2005/01/05 11:50:14
%* -----------------------------------------------
\documentclass[a4paper]{article}
\usepackage{mathspic}
\begin{document}
%---------------
\beginpicture
\setdashes
\setcoordinatesystem units <1mm,1mm>
\setplotarea x from 0.00000 to 70.00000, y from 0.00000 to 50.00000
\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
\put {$\odot$} at 10.00000 10.00000 %% A
\put {$\odot$} at 35.71150 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.94015 39.72253 / %% AB
\plot 36.58878 39.82302 58.36311 19.50117 / %% BC
CHAPTER 7. EXAMPLES 67
Note that the remaining comments at the end of the \plot and \put lines are generally
sufficient to understand what each line relates to. Note also that the -c switch only
removes comment lines having a leading %% pair of characters (but not the results of the
show() commands); comment lines prefixed with only a single % character remain.
\setdashpattern <6pt,2pt,1pt,2pt>
The equivalent LATEX macro would be as follows.
\def\fancydashes{\setdashpattern <6pt, 2pt, 1pt, 2pt>}%
...
\fancydashes
Note that in Figure 7.2 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.
G F
...
•. •.
.
. ...
. .
... ...
. .
... ...
. .
... ...
. .
.. ..
. .
.. ..
. .
.. ..
. .
.. ..
..
. H ...•. ..
.
...
. • E
. . .. . ..
... . ... .
. ... . ...
... .
.. ... .
..
B • ...
.
.
..
... ...
• C
.
.
..
...
.. ..
... ...
. .
... ...
... ...
.. ..
.
... ..
... ..
. ..
... ...
. .
... ...
.. ..
. .
... ...
•.. •
..
A D
Figure 7.2:
7.3 Arrows
Arrows can be drawn in all possible orientations, will stretch between points, and
arrow-heads are readily customised using the mathsPIC Arrowshape command (see
also Salomon, 1992).
Although arrow shape can of course be controlled using the standard PICTEX \arrow
command, the mathsPIC Arrowshape command makes this easier by allowing you to
define (in degrees) the angle parameters (B and C) of the arrow-head directly (see box).
The default arrowshape is equivalent to the following command
Arrowshape(2mm,30,40)
Arrowshape(L,B,C)
B = angle B1 AB2 degrees C1
•.........←−− L −−→
.... .
C = angle C1 AC2 degrees ....
....
....
.....
.....
.....
B 1
•
......
......
.......
........
..
..........................................................................................................................................................................................................................................
D • .............
... • A
. .
....
.
.
.... .....
.....
...
•
.
....
....
.....
................................................................ ....
.... B 2
. .......
.. Arrowshape(6,30,60) ...
....
..
.
... ...... ...
..
............................................................. Arrowshape(4,30,60) • ...
..
....
.
.............................................................
. Arrowshape(2,30,60) C2
........
.........
............................................................
.......
.... Arrowshape(6,30,40)
.....
.................................................................. Arrowshape(4,30,40)
.....
Figure 7.3: The mathsPIC code for this figure is given in the appendix
If the arrowshape has been altered, it can be reset using the ArrowShape(default)
command. Curved arrows (circular arcs) are drawn using the drawAngleArrow com-
mand, which takes parameters for the angle, radius of arc, direction, and whether the
angle is internal or external (see Figures 7.4 and 7.5).
CHAPTER 7. EXAMPLES 71
Arrows can also be used to link elements in a diagram, as shown in Figure 7.5. The
right-hand diagram uses the 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 Figure 7.5b. The arrows are easily ‘stretched’ to accommodate their labels
simply by adjusting the separation of the nodes using the polar(r,θ ) commands (see
Feruglio, 1994).
q⋆q⋆q⋆q⋆q
Q ..................................................................................................................
R
..............
..... ...... . ......
.......... ...... ......
.
......
.. .
.....
. ...
..
.. ..
...... ....
.
..
. . .
... .
...
. .
.
.. ...... ..
...
... ......
.. p 1 .....
.....
..
...
t
...
..
......
.
......
.
...
.
p
3 ...
.
..
.
.......... ... ..... ...
........... ................. .. ......
...... ..... . ..
..
..... ... ...
.. .
......
... .
.
...
.. ..
... .............
..........................
...... ..... ... ...... ...
. . ...... ...
.
.
.
. ..... .... ...
.. . .........
..... .... ........................................... ........... ....... ..
. .. ...... ....
...............................................................................
P T
N S p2
a. Circular arrows b. Straight arrows
Figure 7.5:
%%--------------
\beginpicture
paper{units(1mm),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),internal,clockwise}
point(N1){N,shift(2,1)}
point(S1){S,shift(-2,1)}
point(Z1){Z,shift(0,-3)}
drawAngleArrow{angle(N1Z1S1),radius(N1Z1),internal,clockwise}
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),internal,clockwise}
\endpicture
\end{document}
Note that in this particular case it is necessary to define the maths formula using
the LATEX \displaystyle, in order to avoid the embedded \textwidth white space
associated with using \vbox{\formula} in the \text() command, and hence allow
centering of the figure. Note also how the mathsPIC ∖␣... 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
polar(r,θ ) option, as shown in the mathsPIC file for Figure 7.7. Notice the use of
the variable r for the radius of the circle (allocated using the command var r = 20),
CHAPTER 7. EXAMPLES 74
...........................................
........ .......
...... .....
........ ..... ............................
.... .... ...... ....
... ... .... ...
... . ...
. ..... ...
... ... ... ...
....
..
. X ...
..
.. .......... ..
.....
..
..
.
... D ..
..
...
.. (p+1) .............................................
...
...
∆ z jp . .
....
...
. ...
...... ..
...
...
. .....
...
... ...
. ... .............................
... p≥0 .. .. .
....
... .... ... .
.. .
...
... ......... ....
. ...
... .. .............. ...
....
..... .
..... .......
. .... ...
.
. .
...... ..... ....... ..
....... ...... .........
............ ..
......... ....... ...
........................................ . ....... .................
... .... .......
....... .... ....... ....
... . ........ ...
... .... . ...
... .... ..
...
.
...................
.. ........ ...
. . ..
. .. .
..... ..... .
.
...
... C
...
.
. .. . ...... ... .... ..
.
..... ... ......
.....................
... .... ..........
... ... ..........
....................
... ...
... ..
....
...
...
A ...
.
.
...
... ..
... ..
..... ..
...... .....
...............................
Figure 7.6:
which then allows the use of r to define the radius in the polar commands for the
points P, Q, S.
Q .................................
.............. .........
........
...
...
. . •
.............
.... ... .....
.......
......
.....
.....
..
... ... ...
. ....
... .. ... ...
.. ... ..... ...
. .
. ... . .... ...
..
..... ...
...
α ...
..
.
..............
...
...
...
.. ... . .
.... ..... .
.
.. .............. ..... ... ...
.. ..... ..
.... ...
... .... ..
..
.. ... . ... ..
.. . ...
.... .. ...
...
...
...
... ⊙ .
.
.
.
.......
.......
. .
...
.....
. .
....
.
... .
. ........ .... ..
... ... .. . .
................. ...... ..
...
... ...
..
β ...
.
..
.
......
..
.... . ........... .....
...... .... ...
.
.
.
...
... ... ......................... .......... ....
.. ... ............
...
...
...
...
.. ....
..
.
...
•...
.
.
....
....
.....
... ...
.. ...
.. .. . .. .....
... S
...... ...
....... ........ ......
........... .......
• ........... ........
.........................................
Figure 7.7:
Note that the returned values in the output-file from the showAngle commands (see
below) for Figure 7.7 indicate that β is twice α, as one would expect.
60
Triangle, pentagon
B
50 and three circles •
....
...
...
..
...
... ............................................
.. ..... ........
P 3
......... ......
40 ...
•
.........
..........
.
•.......
.........
....
. . . . . ... J .... . ... .....
...
.... ...
..... . .. ...
. .•. ......... .. ... ....
.
..
.. .. ...
...
.
. ...
.... .... ⊙
.. ..
... ....
.
.. .......... .
. .
.......
. ..
.. .. .. ..
...
. .. ....... ..
. . . .
. ....... .......... .
• ..
.. ....
................................. ..........
..... .... ... 72 ....
... • P....
........
20 .. ...
...... . ... ... ....... .....
...... . ...
...... .... 2
⊙ I ...
.. ... .. .
. .. . . ..........
.
....... . .
....
......
. . .
.... .
. ..
.. . .
... ..
... ..... ...
..
. ...
..... ....... .
...... ........
....
Figure 7.8:
\beginpicture
\setdashes
paper{units(1mm),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)
\setplotsymbol({\tiny .})
point(I){IncircleCenter(AJK)}[symbol=$\odot$, radius=1.2]
point(E){ExcircleCenter(AJK,JK)}[symbol=$\odot$, radius=1.2]
point(P1){perpendicular(E,AC)}
var r = EP1 %% radius of excircle
var d = 72 %% angle of pentagon (deg)
var a1 = -90, a2=a1+d, a3=a2+d, a4=a3+d, a5=a4+d
point(P2){E, polar(r,a2 deg)}
point(P3){E, polar(r,a3 deg)}
point(P4){E, polar(r,a4 deg)}
point(P5){E, polar(r,a5 deg)}
drawPoint(ABCJKIEP1P2P3P4P5)
\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}
var 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 deg)}
text($P_2$){P2,polar(s, a2 deg)}
text($P_3$){P3,polar(s, a3 deg)}
CHAPTER 7. EXAMPLES 77
\endpicture
\end{document}
• B..
.......
........
...... ...
..
........ ....
.
..
......... ...
..... ........ ...
.......... ...
P ⊙ .........
................ .
.... P ⊙.................
•
. ... .
.............
...
...
...
......
......
......
...
.. Q ...
... ......
......
. . ... ...
...
......
...
... ...............
...
...
... .............. .................
.
. .....
... ... ...... ......
... ... .... ........
... .......
... .. ... ... ......
... .....
... .. .........
... ... .. ......
... ... . ......
..
.. .... .... ......
......
.
... ......
... ......
....................... ............ . .
... .... ... . ......
.....
..... . .
...
...
.
...
..
.. .....
.
.............................................
.
......
............ .............. .................................................................... ...... ..... • B
.............
A ⊙
...
A ⊙
.........
...........................
...
.. •
Q
Figure 7.9: The mathsPIC code for the two diagrams differs only in the angle of the
line AB as defined in the point(B){...} command (see mpicpm07-9.m).
text($A$){A,shift(-d, 0)}
text($B$){B,shift(d, 0)}
text($P$){P,shift(-d, 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), internal, clockwise}
%%--------- second figure --------------------
point*(A){60,5}[symbol=$\odot$, radius=1.2]
point*(P){A, shift(10,30)}[symbol=$\odot$, radius=1.2]
point*(B){A, polar(45,5 deg)} %%5 60 deg
point*(Q){perpendicular(P,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}
point*(N){A,shift(0,10)}
\setdashes
drawline(AN)
\setsolid
drawAngleArrow{angle(NAB), radius(5.7), internal, clockwise}
\endpicture
\end{document}
Note that in Figure 7.9 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 the line
AB and in-line with the points PQ, using the command
point(S){pointOnLine(QP,-5)}.
beginLOOP 6
inputfile(myfile.dat)
endLOOP
The file myfile.dat is input six times sequentially using the single command
inputfile(myfile.dat)[6].
...............................................
............
......... .........
.......
.......
. ....... ......
......
. . .
.... . .
... . .. ......... ............ .. .....
.....
.
..... ... . . .
. ......... ......... ......... ..... .
....
..
. ..
. ............. ..... ........... ..... ..... ..... ............. ....
• • • •
. ...... ....... ....................................... .... .... .........
...
. . .. ...
... .. .............. ................ ......... .......... ..................... ..... ...... ...
...
.... ................ ............ ......... ............... ............. ..... ......
..
.
.
..
..
... • •
............... ...... .................................... ...................... ..... ............ ...........
........... .... ....... . ... .....
...
.
....
...
.
.
.
.. •
........ ..........
.... . ... ..... ......
.. ................ ...........
............
. . . . . .... .. ...
...........................................
.. ....... ...... ........ .... ...
. • .
.... ... .... ..... . . . ..
..
..
.
. . . .
•
.... .... ........ .... ...
.... . ..... ..
.
..
.............. ... ......
............................................
.. .
..
..
.... .... ... ... .... ....
.
..
.. .
......... .............. .... ...
.. .
... .... .... ........ ........... ............. .... .................................... •
••••••••
... ..... .............. ............ ...... ...................................................................................................... .......... ........ ............ ...
•
....... ........ ....... ...... ................... .............. ................ .... .. .. ... .
.... ..... ... ......... ...... ... ........... ..... ... ..... .... ..... ........ ...... ...... ....
.... ....... ........................... ..... ....................................................................................................... ....... .................
• • • . .
... ... ...... .............. .................................................. ... .... .... .. .... ...... ....
... . . . .. . . .•
....... ..................... ..................
•
. . . . . .. . .
... ............... .. ....... ..... . . . .. ... . .
...... ... ......
.. ..
...
... . . •
.... ............. ... ... ........ ... .. ....................................................................... ....... .................. ....... .....
. . . . . . • .
... • •
............ ............... ..... ................... ............................. ............................................ ........... ......... .
.... ...
...
... • • • ••
......... .... ........ ........ ................... ........ .....................
......... ... ........... ................... ......... ..............
..... ..... ....... ......................................... ....... ..........
... . .. .. .
.... .... ... ...... ..
.... .................... ....
...
...
...
•
............ ..... ........ .......... ........ ..............
. .
. .. . . . ..
. .. . ..
......... ... ...... ...... ... .........
. . . . .. ..... . ... .
...
.
...... •
.......
.. . ... ..
.... ...
... .. ... ....... ....... ..... ... .... ...... ....
... .... ................. .. .... .... ...
... . ...
.... .
.... ....
..... ....
..... ....
......
...... ..
........
....... ......
......... .......
............ ........
.................................................
Figure 7.10:
Figure 7.10 was produced by the following code which inputs a small file of math-
sPIC code (mpicpm07-10.dat) repeatedly 35 times using the command
inputfile(mpicpm07-10.dat)[35]. Note the use of the point* commands in the
data-file to re-allocate points.
When the inputfile command is used mathsPIC writes the iteration number to the
output file, prefixed using three % symbols (to make sure they are not deleted when using
the -c switch, as follows.
%%% Iteration number: 26
For example, the following extract shows the resulting output .mt file showing
how mathsPIC writes the iteration number of each data-file input to the output file just
before it inputs the data-file. This example includes the whole of the 26th cycle of
data-file input. It also demonstrates the value of labelling the beginning and the end of
the data-file differently in order to make it easy to see the cycling of the input file. This
is very helpful as it allows you to check whether the data-file is working correctly.
...
...
\plot 31.49519 26.25000 36.49519 21.25000 / %% Q3Q4
\plot 36.49519 21.25000 41.49519 26.25000 / %% Q4Q1
%% eof ============================================
%%% Iteration number: 26
%% mpicpm07-10.dat --------first line----------------
%% mathsPIC (spiral data) input by file mpicpm07-10.m
%% var a = a+15, r = r-0.5 %% increment angle and radius
%% a = 705
%% r = 7
%% point*(P){C,polar(r,a deg)} %increment P, P=(36.76148, 28.18827)
%% drawpoint(P)
\put {$\bullet$} at 36.76148 28.18827 %% P
%% drawline(TP) %% draw line from OLD T to NEW P
\plot 36.49519 26.25000 36.76148 28.18827 / %% TP
%% point*(T){P} %% reallocate T <-- P T = (36.76148, 28.18827)
%% make a square on P with side/2=s (s is defined in mpicpm07-10.m)
%% point*(Q1){P,polar(s,0 deg)} Q1 = (41.76148, 28.18827)
%% point*(Q2){P,polar(s,90 deg)} Q2 = (36.76148, 33.18827)
%% point*(Q3){P,polar(s,180 deg)} Q3 = (31.76148, 28.18827)
%% point*(Q4){P,polar(s,270 deg)} Q4 = (36.76148, 23.18827)
%% drawline(Q1Q2Q3Q4Q1)
\plot 41.76148 28.18827 36.76148 33.18827 / %% Q1Q2
\plot 36.76148 33.18827 31.76148 28.18827 / %% Q2Q3
\plot 31.76148 28.18827 36.76148 23.18827 / %% Q3Q4
\plot 36.76148 23.18827 41.76148 28.18827 / %% Q4Q1
%% eof ============================================
CHAPTER 7. EXAMPLES 81
Because mathsPIC prefixes the iteration number comment with %%% these comments
remain even when the -c switch is used, as the following extract of the same data shows.
...
...
\plot 31.49519 26.25000 36.49519 21.25000 / %% Q3Q4
\plot 36.49519 21.25000 41.49519 26.25000 / %% Q4Q1
%%% Iteration number: 26
\put {$\bullet$} at 36.76148 28.18827 %% P
\plot 36.49519 26.25000 36.76148 28.18827 / %% TP
\plot 41.76148 28.18827 36.76148 33.18827 / %% Q1Q2
\plot 36.76148 33.18827 31.76148 28.18827 / %% Q2Q3
\plot 31.76148 28.18827 36.76148 23.18827 / %% Q3Q4
\plot 36.76148 23.18827 41.76148 28.18827 / %% Q4Q1
%%% Iteration number: 27
\put {$\bullet$} at 36.50000 30.00000 %% P
...
...
\beginpicture
paper{units(1mm), xrange(0,60), yrange(0,60) axes(LB), ticks(10,10)}
point(C){30,30} % circle center
drawcircle(C,25)
%% initialise loop counter (n), angle (a), radius (r), side (s)
var n=0, a=315, r=20, s=7
point(T){C,polar(r,330 deg)}
beginLOOP 35 % loop 35 times
%% increment loop counter (n), angle (a) and radius (r)
var n=n+1, a = a+15, r = r-0.5
%% increment position of new square with side s
point*(P){C,polar(r,a deg)}[symbol=square(s)]
drawpoint(P) % draw new square
text($\bullet$){P} % draw bullet in center of new square
CHAPTER 7. EXAMPLES 82
A quartic equation
4
4 3
..
...
...
f (x) = 6x − 8x + 1
... ...
...
... ..
..
... 3 ...
...
...
...
..
..
..
.
.. ... .
.
..
... ... . ...
... ............ ....
... . ..
... .
.
..
...
... 2 inflection points ..
..
..
...
...
.... ... ..
.
... ...... ... .
.
... ...... ..
... ......... ... ..
.... ........... ... ..
.....
........ ... ..
.
.................................. ... .
..
1 ...............
........
......
...
... ...
...
......
.....
...
....
..... ......... ...
.... ..... ..
.... .
... ...
... ....
...
... ...
... ..
.... ..
−1 ....
.... 1 ..
.... 2
.... ..
.....
...... ...
.......................
−1
−2
Figure 7.11:
point(E2){1.4,2}
drawarrow(E1E2)
point(J1){0.55,2}
text(inflection points){J1} % center inflection text at J1
point(J2){0,1}
point(J3){0.6,0}
drawarrow(J1J2,J1J3)
\endpicture
\end{document}
CHAPTER 7. EXAMPLES 85
The datafile for the curve is as follows—note the leading ∖␣ on the data-point lines to
force mathsPIC to read these lines as data (i.e., to copy the lines unchanged into the .mt
file) and not to process them as mathsPIC commands. Remember that PICTEX requires
an odd number of pairs of data points to satisfy its curve-drawing algorithm.1 Note also
that the final data-point in the sequence must be ‘terminated’ using a ␣/ pair, as shown
below.
%% mpicm07-11.dat (Figure 7.11)
%% 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
%%EOF
However, when there are only a few data points, it is sometimes more convenient just to
plot the points separately and then draw connecting lines, as shown in Figure 7.12.
⊙ ⊙.........
76 ......
......
......
... ........... ⊙.....
Weight .. ...
...... ... . ⊡......... ⊙ ........... ....
....
(kg) ⊡ .....
....
....
75 .... ....
⊡.......
....
..
....
....
⊙
....
73
0 1 2 3 4 5 6
Weeks
Figure 7.12:
\usepackage{mathspic}
\usepackage{amssymb}
\begin{document}
%%--------------
\beginpicture
paper{units(1cm),xrange(0,6),yrange(73,77),axes(LBT*R*),ticks(1,1)}
pointsymbol($\odot$,0.2)
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$, 0.2)
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 Weeks}){3,72}
\endpicture
\end{document}
F
◦
...
...
....
....
.
....
.
....
....
...
.....•................
.
....
B◦ .
....
.
...
...
.. ....................
..
. . .
. ...
...
....
...•.......... ............•............... .....
.......... .... F2
•...
.... .......... .
...
..........
...
. .. ..
...
..........
..
..........
.. .......... ...
.... E1
. . ..
.. .
.. ..
..
.
B2 ....... C ...
B1
.
. ............
.......... ...
.
...
.
... . . .......... .
.
...
.
...... ◦ .
. . .......... ....
.
...
... ...
...
•.... . ... ....
. .... ...•.... ..
.. ... ...
.. ...
..•.
.
. ... ...
...
. C2 ...
...
...
..
... A1 ...
... .......
. ...
...... . ....... F1
....
....
..
.. . .•
.
....
.... .. E2
..... ..... .. ◦E
... .... .....
... ... ... ....
....
....
.
....
.. . . . .... ...
....
...
......
. .
.. .
... ...
•... ..
.... .... . ..
.
... ... .
..
..
...
•... ..... .... .... ....
....
... ... C1
... ...
....
....
...... .•...
.. ... ....
A◦
.
...
.
... A 2
.. .. . ....
...... .
... D1 ...... .
.
.......
.......
..... .
.. . G2
.
. .
....•.............. ...
....
...
...
....
....
.....•...........................• ...
....... . ... D ...
........ .
. . 2 ...
....... G1 ..
... ...
...
....... .. ... ..
....... ... ... ....
.......
....... .... ... ....
....... .... ... ...
....... ..... .
... .....
.....
....... ....
...... .. ...
◦ ◦
G D
Figure 7.13: A smooth curve inscribed in the intersecting closed line ABCDEFGA
Point(E2){midpoint(D1E1)}
Point*(E2){midpoint(EE2)}
Point(F2){midpoint(E1F1)}
Point*(F2){midpoint(FF2)}
Point(G2){midpoint(F1G1)}
Point*(G2){midpoint(GG2)}
%
DrawPoint(ABCDEFG)
DrawPoint(A1B1C1D1E1F1G1)
DrawPoint(A2B2C2D2E2F2G2)
%
DrawLine(ABCDEFGA)
\setplotsymbol ({\Large.})
DrawCurve(A1B2B1)
DrawCurve(B1C2C1)
DrawCurve(C1D2D1)
DrawCurve(D1E2E1)
DrawCurve(E1F2F1)
DrawCurve(F1G2G1)
DrawCurve(G1A2A1)
%
Text($A$){A,shift(-0.2,0)}
Text($B$){B,shift(-0.2,0.1)}
Text($C$){C,shift(0,0.25)}
Text($D$){D,shift(0,-0.25)}
Text($E$){E,shift(0.2,0)}
Text($F$){F,shift(0,0.25)}
Text($G$){G,shift(0,-0.25)}
\scriptsize
Text($A_1$){A1,shift(0.25,0)}
Text($B_1$){B1,shift(0,-0.2)}
Text($C_1$){C1,shift(0.25,0)}
Text($D_1$){D1,shift(-0.2,0.15)} %
Text($E_1$){E1,shift(-0.2,0)}
Text($F_1$){F1,shift(0.15,-0.15)}
Text($G_1$){G1,shift(0.1,0.2)}
Text($A_2$){A2,shift(0.25,0)}
Text($B_2$){B2,shift(0.1,-0.2)}
Text($C_2$){C2,shift(-0.1,-0.15)}
Text($D_2$){D2,shift(0.1,0.2)}
Text($E_2$){E2,shift(-0.25,0.05)} %
Text($F_2$){F2,shift(0.05,-0.2)} %
Text($G_2$){G2,shift(0,0.25)} %
\endpicture
\end{document}
CHAPTER 7. EXAMPLES 89
7.9 Scaling
Note the technique used in the code for Figure 7.13 above, for making the 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.
....
var u = 12 %% units = 12 mm
paper{units(u mm),xRange(0,9),yRange(-1,6)}
var r = 0.7 %% line-free radius of \circ = 0.7mm
var r = r/u %% scaled linefree radius for u mm
pointsymbol($\circ$, r)
point(A){1,1}
....
This technique can be very useful when it is necessary to scale the figure after having
designed the figure in order, say, to make it fit into a particular space in a document.
7.10.1 Example-1
This example (see Figure 7.14) uses the small Perl program drawcurvedarrow.pl
(see below) to generate the mathsPIC commands for drawing a curved arrow (note that
there is no mathsPIC command for doing this at the moment), and place them in a
temporary file which can then be accessed by the mathsPIC file.
0 1 2 3 4 5
4 4
Q
3 ..•.................. 3
.... .....
.... ....
.. ....
2 .. ............... 2
... ..
... END
1 1
START
0 0
0 1 2 3 4 5
Figure 7.14: A curved arrow drawn using the Perl
program drawcurvedarrow.pl
The above Perl program accepts five parameters and writes the mathsPIC commands
required for drawing a curved arrow through the three points A, B,C (from A to C). The
program places an arrowhead (length h) at the end pointing at point C, and places all the
necessary mathsPIC commands into the temporary file filename.
Note that in this example all new points defined in the Perl program are defined using
the point*() command, since this allows the program to be reused without needing
to know which points have been defined before. The point names P999 and H999 have
been chosen in order to try and avoid clashing with any point names likely to be used in
the mathsPIC file. Indeed, the authors suggest that point numbers ≥ 900 be reserved for
use in Perl programs in this way. Note also that these particular point names (e.g. H999)
need to be separated by a space from a previous string name (e.g. $A$B H999) since
they are not Perl variable names (Perl variable names are prefixed with a $ symbol).
System() command
MathsPIC ‘calls’ a Perl program (with appropriate parameters) via the system()
command. For example, the following mathsPIC commands (a) call the Perl program
drawcurvedarrow.pl to draw the curved arrow PQR with an arrowhead length 0·4
units, and places the commands in the file temp.txt, and (b) inputs the temporary file
which then contains the commands.
....
system("perl drawcurvedarrow.pl P Q R 0.4 temp.txt")
inputfile(temp.txt)
....
It is useful to include the filename as one of the parameters, since this allows us to write
the mathsPIC command to input the same file immediately afterwards. Note also that
since we are, in effect, using the command-line here then the parameters following the
program name must be separated by spaces, as required by Perl syntax.
CHAPTER 7. EXAMPLES 91
Point*(P999){pointonline(QP, -(PQ)/3)}
Point*(H999){pointonline(R P999,0.4)}
Drawcurve(PQ H999)
drawArrow(H999 R)
Output file
The output TEX file which is generated by running the file mpicpm07-14.m through
mathsPIC is as follows. Towards the end of the file you can see the temporary file code
and the results after processing by mathsPIC located between the following two lines
%% ... start of file <temp.txt> loop [1]
...
%% ... end of file <temp.txt> loop [1]
%* -----------------------------------------------
%* mathsPIC (Perl version 0.99.22 Dec 29, 2004)
%* A filter program for use with PiCTeX
%* Copyright (c) 2004 A Syropoulos & RWD Nickalls
%* Command line: mpic09922.pl mpicpm07-14.m
%* Input filename : mpicpm07-14.m
%* Output filename: mpicpm07-14.mt
%* Date & time: 2005/01/05 09:30:55
%* -----------------------------------------------
%% mpicpm07-14.m (Figure 7.14)
%% curved arrow
\documentclass[a4paper]{article}
\usepackage{mathspic}
\begin{document}
%%--------------
\beginpicture
%% paper{units(1cm) xrange(0,5) yrange(0,4), axis(LRTB),ticks(1,1)}
\setcoordinatesystem units <1cm,1cm>
\setplotarea x from 0.00000 to 5.00000, y from 0.00000 to 4.00000
\axis left ticks numbered from 0 to 4 by 1 /
\axis right ticks numbered from 0 to 4 by 1 /
\axis top ticks numbered from 0 to 5 by 1 /
\axis bottom ticks numbered from 0 to 5 by 1 /
%% point(P){1.25,1} P = (1.25000, 1.00000)
%% point(Q){P, polar(2, 65 deg)} Q = (2.09524, 2.81262)
%% point(R){Q, polar(2,-40 deg)} R = (3.62733, 1.52704)
%% drawpoint(Q)
\put {$\bullet$} at 2.09524 2.81262 %% Q
%% text(\fbox{START}){P}[t]
\put {\fbox{START}} [t] at 1.250000 1.000000
%% text($Q$){Q, shift(0,0.5)}
\put {$Q$} at 2.095240 3.312620
%% text(\raisebox{-5mm}{\fbox{END}}){R}[t]
\put {\raisebox{-5mm}{\fbox{END}}} [t] at 3.627330 1.527040
%% linethickness(1pt)
\linethickness=1.00000pt\Linethickness{1.00000pt}%
\font\CM=cmr10 at 9.97226pt%
\setplotsymbol ({\CM .})%
%% arrowshape(0.4cm, 30,40)
%% arrowLength = 0.4cm, arrowAngleB = 30 and arrowAngleC = 40
%% system("perl drawcurvedarrow.pl P Q R 0.4 temp.txt")
%% inputfile(temp.txt)
%% ... start of file <temp.txt> loop [1]
%%% Iteration number: 1
%% point*(P999){pointonline(QP, -(PQ)/3)} P999 = (2.37699, 3.41683)
%% point*(H999){pointonline(R P999,0.4)} H999 = (3.40661, 1.86063)
%% Drawcurve(PQ H999)
\setquadratic
\plot
1.25000 1.00000 %P
CHAPTER 7. EXAMPLES 93
2.09524 2.81262 %Q
3.40661 1.86063 / %H999
\setlinear
%% drawArrow(H999 R)
\arrow <0.40000cm> [0.2679,0.7279] from 3.4066 1.8606 to 3.6273 1.5270
%% ... end of file <temp.txt> loop [1]
\endpicture
\end{document}
LATEXing this file then generates the DVI file for Figure 7.14.
7.10.2 Example-2
Once the main working part of a Perl program has been debugged, then some finishing
touches can be added. In the following example (drawcube.pl; to draw a cube)
we have, therefore, made it a somewhat more sophisticated program by including
(a) error messages, (b) made it delete the temporary file automatically, (c) useful macros,
(d) added colour.
Note also how the one-line system() command in the mathsPIC file calling the
drawcube.pl program is processed into the temporary file necessary for drawing the
cube. This illustrates the value of being able to encode certain elements of a diagram as
a separate Perl program capable of receiving parameters, and so making it possible for
them to be used as and when necessary.
where the qq() command exports the argument in inverted commas, as required.
Useful macros
In addition, we have made the mathsPIC file more readable by creating the macros
¢er(), &side() and &filename() to hold the three parameters, namely center
point, the sidelength and the temporary filename. In this way we can pass P, s and
temp.txt as ¢er(P), &side(s) and &filename(temp.txt) (note that when
mathsPIC macros are used then they need to be prefixed with the & symbol).
%def center(j)j% %%center point
%def side(j)j% %%sidelength
%def filename(j)j% %% temporary file name
CHAPTER 7. EXAMPLES 94
point(P){5,5}[symbol=$\bigodot$]
var s=4 %% sidelength
system("perl drawcube.pl ¢er(P) &side(s) &filename(temp.txt)")
inputfile(temp.txt)
Added colour
We have also made use of the LATEX Color package and coloured the sides of the cube
blue, the diagonals red, and the points and labels black. Always load the color package
after the mathsPIC package.
MathsPIC program
All these improvements are implemented in the following example mathsPIC script &
Perl program drawcube.pl which draws a simple cube (side s) about a central point P
(see Figure 7.15).
Note that the point-name P, side-length s, and filename temp.txt are all passed to
the Perl program as parameters using the system() command. The code of the Perl
program drawcube.pl is listed below.
Note the use of the <<EOF. . . EOF environment in the Perl programme to contain the
chunk of mathsPIC code which is written to text file temp.txt. Note also that where
you want $ and ∖ characters written to the output file (temporary file—for use by
mathsPIC) by the Perl program, it is important to remember that these characters need
to be ‘escaped’ using a preceding backslash. In the above example the point name P is
held in the Perl variable $point; consequently since we need the Perl program to write
the mathsPIC command text($P$){P,shift(-0.5, -0.1)} to the temporary file
the Perl code needs to be text(\$$point\$){$point, shift(-0.5,-0.1)}
CHAPTER 7. EXAMPLES 96
Output file
When the mathsPIC script is run the output file is as follows.
%* -----------------------------------------------
%* mathsPIC (Perl version 0.99.22 Dec 29, 2004)
%* A filter program for use with PiCTeX
%* Copyright (c) 2004 A Syropoulos & RWD Nickalls
%* Command line: mpic09922.pl mpicpm07-15.m
%* Input filename : mpicpm07-15.m
%* Output filename: mpicpm07-15.mt
%* Date & time: 2005/01/05 09:46:22
%* -----------------------------------------------
%% mpicpm07-15.m (Figure 7.15)
\documentclass[a4paper]{article}
\usepackage{mathspic,color}
\begin{document}
%%--------------
\beginpicture
%% paper{units(1cm) xrange(0,6) yrange(0,6), axis(LB),ticks(1,1)}
CHAPTER 7. EXAMPLES 97
6
P 995
5 ....... .
• ....
...... .. • ........
......
.....
....... ... ............
............. .. ...
............
.
.... ... .. .
....... .......
.......
... ....... .....
.......
....... .. P 991 .......
....... .. ..
..
4 ............
• ...
• ..
........ . ...
.. .
.......
.......
.. .....
... .. ....
.......
.......
.. ... . ..
... ... .....
.......
J
....... . .......
........
3 P ..
.......... .......
.......
..... .... ... .......
..
. .. .......
.... .... .......
.. . ...
..... .
.
.......
.. .......
2 ..
.
......
.. .... • .
. ...
.. .......
•
.......
..... ....... .......
..... . ... ..
..........
.. ..... .. ..
......
.. . ....
..... ...... ... .......
. ..... .. ............
..... .. ...
1 •
...... • .......
0
0 1 2 3 4 5 6
Figure 7.15:
3-D cube drawn about a central point P (3, 3) and with sidelength s (s = 3). The
PDF and PostScript versions of the output show the sides coloured blue, the
diagonals red, and the points and labels black. The mathsPIC command used
was:-
system("perl drawcube.pl ¢er(P) &side(s) &filename(temp.txt)").
CHAPTER 7. EXAMPLES 99
It is sometimes useful for mathsPIC to be able to access TEX parameter values. For
example, mathsPIC could be made to automatically scale the height and width of a
graph to the as yet unknown page size of the TEX document. Knowledge of the TEX
parameters \textheight and \textwidth during processing would allow the height
and width of a graph to be defined as a function of these page parameters.
One way of doing this is to include in the TEX file some code to write the required
parameter values to a temporary data file, in the form of mathsPIC var commands or
macros. Using the mathsPIC system() command mathsPIC can run the TEX file, and
then access the parameter values by inputting the data-file.
For example, the following code would put the length of the word January into the
variable \janlength. Note that \the gives the value in points, while \number returns
the value as an integer in scaled points (see Table 8.1).
\newlength{\janlength}
\settowidth{\janlength}{January}
The length of the word January in points is \the\janlength
The length of the word January in ‘scaled’ points is \number\janlength
The output is as follows (note that \the\janlength returns the numeric points but
includes the characters pt on the end).
100
CHAPTER 8. ACCESSING TEX PARAMETER VALUES3 101
TEX has a number of parameters which are classified according to type, e.g. integers,
dimensions, glue, muglue, token lists. For a full list of all the TEX parameters which
have values which can be accessed see Knuth (1990; page 272–275).
The token list \jobname is very useful as it holds the filename (but not the filename
extension) which TEX is currently working on, and can be used for generating derivative
temporary files, e.g. \jobname.dvi, \jobname.toc etc.
\newwrite\outfile
\openout\outfile=texfiledata.dat
\write\outfile{...blah blah blah....}
\closeout\outfile
Note that the \write command only writes the data to the file when the .dvi file is
created, so if these commands are in a file which may not actually create a .dvi file,
then we may need to force output (dvi file creation) by including something writable
like \strut on a line.
Alternatively, we can force TEX to write to the file immediately (i.e. without waiting
until it gets to the end of file processing) by using the \immediate command, remem-
bering to include it with all the commands \openout, \write, and \closeout, as
follows.
\newwrite\outfile
\immediate\openout\outfile=texfiledata.dat
\immediate\write\outfile{...blah blah blah....}
\immediate\closeout\outfile
Since we are interested in accessing the values of TEX parameters, we need to explore
some of the TEX commands for accessing such values. For example, the commands
\the, \number and \showthe all reveal the numeric value, but in slightly different
formats and location, as follows.
For the purposes of mathsPIC accessing the numeric value as a variable or macro,
it is most convenient to use the \number command (yields an integer value in the
‘scaled points’ used internally by TEX)2 and to incorporate it into a mathsPIC variable
or macro so it is ready to be used once the temporary file it is written to has been
input by mathsPIC. For example, the following code allocates the scaled point value of
\textwidth to the mathsPIC variable w555.
2 65536 scaled points = 1 printers point (pt).
CHAPTER 8. ACCESSING TEX PARAMETER VALUES5 102
If the \textwidth was 400pt (14.058 cm), then the output of the above line would be
as follows (65536 scaled points = 1 printers point pt).
In practice, it is useful to have this line commented to indicate which TEX parameter the
value relates to, as follows.
var w555 = 26214400% \textwidth (scaled points)
However, since what came after the % symbol would be ignored in this setting, we
need to define the % as a character we can print to a file, by allocating it the catcode 12
(instead of the catcode of 14 which it normally has), and calling it by a different name
(\percentchar), and delimiting the whole line by a curley brace (to keep it local), as
follows.4
{\catcode‘\%=12 \global\def\percentchar{%}}%
So now, the following code will also include a trailing comment indicating the TEX
name of the parameter.
\newcommand{\comment}{\percentchar\space}
\immediate\write\outfile{var w555 = \number\textwidth
\comment\textwidth is \the\textwidth}
Table 8.1: Note that for accurate working always use scaled points
(sp) and convert in a single step using the following convertion factors
(modified from: Beccari C, 1991)
sp
mm 186467·98
cm 1864679·8
pt 65536
in 4736286·70
%% grabtexdata.tex
%-----------------
\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: texfiledata.dat}
\print{\percentchar\percentchar\space accessing TeX parameter values}
%---------------------
%% now get \textwidth and \textheight values from the tex file
\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{\comment ============}
\print{\macro textwidthcms()\number\textwidth/1864679.8\comment}
\print{\macro textheightcms()\number\textheight/1864679.8\comment}
\print{\comment ============}
%--------------------
% close the file
\immediate\closeout\outfile
\input{grabtexdata.tex}
CHAPTER 8. ACCESSING TEX PARAMETER VALUES7 104
in the TEX file we want data from (say, myfile.tex), and then LATEX the file to generate
the output data file. Alternatively we could LATEX the file from within mathsPIC using
the system command, and then input the resulting data file as follows.
system(‘‘latex2e myfile.tex’’)
input(texfiledata.dat)
Either way, the resulting output data file texfiledata.dat for a file having a standard
{article} format is as follows
%% texfiledata.dat
%% accessing TeX parameter values
var w555 = 22609920% \textwidth =scaled points
var w556 = 22609920% \textwidth =345.0pt
var w557 = 22609920/1864679.8% (\textwidth in cms)
% ============
%def textwidthcms()22609920/1864679.8%
%def textheightcms()39190528/1864679.8%
% ============
Once the above file (texfiledata.dat) is input into a mathsPIC file we can then use
mathsPIC commands to manipulate the textwidth and textheight values, as shown in the
following example mathsPIC file.
\documentclass[a4paper]{article}
\usepackage{mathspic}
\begin{document}
.....
system(‘‘latex2e myfile.tex’’)
inputfile(texfiledata.dat)
var w=&textwidthcms, w2= &textwidthcms/2
var h=&textheightcms, h2=&textheightcms/2
...
\end{document}
Processing the mathsPIC file gives the folllowing output. Notice how useful it is to
have the accompanying comments.
%% inputfile(texfiledata.dat)
%% ... start of file <texfiledata.dat> loop [1]
%%% Iteration number: 1
%% texfiledata.dat
%% accessing TeX parameter values
%% var w555 = 22609920% \textwidth =scaled points
%% w555 = 22609920
%% var w556 = 22609920% \textwidth =345.0pt
%% w556 = 22609920
%% var w557 = 22609920/1864679.8% (\textwidth in cms)
%% w557 = 12.1253632929364
% ============
%def textwidthcms()22609920/1864679.8%
%def textheightcms()39190528/1864679.8%
CHAPTER 8. ACCESSING TEX PARAMETER VALUES8 105
% ============
%% ... end of file <texfiledata.dat> loop [1]
%% var w=22609920/1864679.8, w2= 22609920/1864679.8/2
%% w = 12.1253632929364
%% w2 = 6.0626816464682
%% var h=39190528/1864679.8, h2=39190528/1864679.8/2
%% h = 21.0172963744231
%% h2 = 10.5086481872116
Chapter 9
Miscellaneous
9.1 Acknowledgements
The authors are grateful to Mikael Möller for extensive testing of mathsPICPerl with
the ActiveState Win32 implementation of Perl (known as ActivePerl). We also thank
Joachim Schneider for highlighting a significant system bug (fixed February 2007).
We are also grateful to a large number of people for testing the earlier MS-DOS
version of the program, and for their many helpful ideas and suggestions, including:
František Chvála, Bob Schumacher, Orlando Rodriguez, Glen Ritchie, Boris Kuselj,
Raj Chandra, Ju-myoung Kim, Munpyung O, Rex Shudde, Tobias Wahl.
9.2 Feedback
The authors welcome feedback regarding bugs and platform specific issues, as well as
comments, ideas and collaboration with a view to improving this program.
106
Appendix A
Tables
107
APPENDIX A. TABLES 108
Table A.2: Useful point-symbols and their radii for 10–12pt fonts.
radius mm
symbol symbol package
10pt / 11pt / 12pt
$\circ$ ∘ 0.70 / 0.75 / 0.80 standard
$\odot$ ⊙ 1.20 / 1.35 / 1.50 standard
$\oplus$ ⊕ 1.20 / 1.35 / 1.50 standard
$\ominus$ ⊖ 1.20 / 1.35 / 1.50 standard
$\oslash$ ⊘ 1.20 / 1.35 / 1.50 standard
$\otimes$ ⊗ 1.20 / 1.35 / 1.50 standard
$\bigcirc$ ○ 1.70 / 1.85 / 2.05 standard
J
$\bigodot$ 1.70 / 1.85 / 2.05 standard
L
$\bigoplus$ 1.70 / 1.85 / 2.05 standard
N
$\bigotimes$ 1.70 / 1.85 / 2.05 standard
$\star$ ? — standard
$\triangle$ △ — standard
$\square$ — amssymb.sty
$\blacksquare$ — amssymb.sty
$\lozenge$ ♦ — amssymb.sty
$\blacklozenge$ — amssymb.sty
$\bigstar$ F — amssymb.sty
$\boxdot$ — amssymb.sty
$\boxtimes$ — amssymb.sty
$\boxminus$ — amssymb.sty
$\boxplus$ — amssymb.sty
$\divideontimes$ > — amssymb.sty
APPENDIX A. TABLES
Table A.3: Conversion factors for the units used by LATEX. (From
Beccari (1991) with permission)
mm cm pt bp pc in dd cc sp
1 mm 1,000 0,100 2,845 2,835 0,2371 0,03937 2,659 0,2216 186 467,98
1 cm 10,00 1,000 28,45 28,35 2,371 0,3937 26,59 2,216 1 864 679,8
1 pt 0,3515 0,03515 1,000 0,9963 0,08333 0,01384 0,9346 0,07788 65 536
1 bp 0,3528 0,03528 1,004 1,000 0,08365 0,01389 0,9381 0,07817 65 781,76
1 pc 4,218 0,4218 12,00 11,96 1,000 0,1660 11,21 0,9346 786 432
1 in 25,40 2,540 72,27 72,00 6,023 1,000 67,54 5,628 4 736 286,7
1 dd 0,3760 0,03760 1,070 1,066 0,08917 0,01481 1,000 0,08333 70 124,086
1 cc 4,513 0,4513 12,84 12,79 1,070 0,1777 12,00 1,000 841 489,04
109
Appendix B
Arrows
The mathsPIC code for drawing the following figure is given below.
Arrowshape(L,B,C)
B = angle B1 AB2 degrees C1
•.........←−− L −−→
.... .
C = angle C1 AC2 degrees ....
....
....
.....
.....
.....
B 1
•
......
......
.......
........
..
..........................................................................................................................................................................................................................................
D • ........
.
.......
• A
... ..
.
.
.... .....
.....•
....
.....
....
.....
............................................................... ....
.... B 2
....
........
Arrowshape(6,30,60) ....
..
..
.. ...
.
. .... ....
.............................................................. Arrowshape(4,30,60) • ...
..
....
.
.............................................................
. Arrowshape(2,30,60) C 2
........
...
.................................................................. Arrowshape(6,30,40)
....
.......
.....
................................................................ Arrowshape(4,30,40)
.....
110
APPENDIX B. ARROWS 111
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)
drawArrow(J11J12)
arrowshape(4,30,60)
drawArrow(J9J10)
arrowshape(2,30,60)
drawArrow(J7J8)
arrowshape(6,30,40)
drawArrow(J5J6)
arrowshape(4,30,40)
drawArrow(J3J4)
arrowshape(2,30,40)
drawArrow(J1J2)
%%
text(\texttt{Arrowshape(2,30,40) \ default}){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}
drawpoint(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]
APPENDIX B. ARROWS 112
%%
\betweenarrows {$L$} from 74 55 to 92 55
\endpicture
\end{document}
Appendix C
mathspic picture.m
pdflatex picture.mt
However, the process of trimming excess white space can be most conveniently
done via dvips. The process of editing and viewing can be conveniently automated
using a BASH script, such as the following, which runs mathsPIC, trims the image to
the bounding box (BBox) and generates the associated PS, EPS and PDF files.
## makefigs.sh
## use: bash makefigs.sh filename [no filename extension]
mathspic $1.m
latex $1.mt
dvips $1.dvi -o $1.ps
dvips -E $1.dvi -o $1.eps ## determines the BBox -->eps
epstopdf $1.eps
echo ... end of run
For example, to process the mathsPIC file myfile.m, one would type the command
113
APPENDIX C. POSITIONING THE FIGURES 114
JPEG
In order to make a JPEG file we make use of (a) the Perl program fitps12.pl (origi-
nally made by S. Rahtz (1996) and modified slightly2 by Apostolos Syropoulos (2006)
as version 1.2), and then (b) GhostScript, as follows:
## makefigs.sh
## use: bash makefigs.sh filename [no filename extension]
mathspic $1.m
latex $1.mt
dvips $1.dvi -o $1.ps
dvips -E $1.dvi -o $1.eps ## determines the BBox -->eps
perl fitps12.pl $1.eps $1.EPS ## outputs a modified EPS file
gs -sDEVICE=jpeg -r400 -sOutputFile=$1.jpg $1.EPS
echo ... end of run
Note that in the above example, the GhostScript command (gs) inputs the modified EPS
file, and generates a JPEG file with resolution 400 dpi. See the GS help file for details
(type gs --help). Resolutions 300 or 400 are generally fine for most purposes. See
the Ghostscript man page and also
/usr/share/doc/HOWTO/HTML/en/Printing/ghostscript.html
The mypic.pic file can then be \input into a document as a centered Figure as
follows. Always use the \centering command as this avoids the additional vertical
space added by the \begin{center}...\end{center} environment.
\begin{figure}[hbt]
\centering
2 The original version required that there was exactly one space between each of the BBox values. This
was a problem, since if you manually adjusted the BBox values, then the spacing could easily end up being
slightly different, and the program would then fail. The new version is more flexible, and tolerates any number
of spaces.
APPENDIX C. POSITIONING THE FIGURES 115
\strut\input{mypic.pic}
\caption{...}
\label{...}
\end{figure}
It is often useful when adjusting the position of a Figure on the page to initially
place the Figure inside a frame in order to see the exact extent of the Figure. To do this
just replace the \input line above with the following:
\strut\framebox{\input{mypic.pic}}
\begin{figure}[hbt]
\centering
\strut\input{mypic.pic}
\begin{minipage}{8cm}
\caption{\label{}......}
\end{minipage}
\end{figure}
Note that the general convention is that Tables have the caption at the top while
Figures have the caption underneath the Figure.
Getting the vertical position and horizontal width of the caption just right can be
awkward. However, using a minipage gives a lot more flexibility as in the following
example, which defines the \captionwidth in terms of the \textwidth. Note also
that here the \caption{} is empty—it is here just to trigger the Figure counter—we
place the actual caption in the minipage.
\newcommand{\captionwidth}{0.8\textwidth}
%%
\begin{figure}[hbt]
\centering
%\framebox{
\strut \input{mypic.pic}
%}
[empty line]
\vspace\baselineskip
\begin{minipage}{\captionwidth}
\caption{\label{fig:fcubic}}%
{blah blah...}
\end{minipage}
\end{figure}
When typesetting text and a figure side-by-side the following format for using two
adjacent minipages works quite well.
\begin{figure}[hbt]
\noindent
\begin{minipage}{4cm}
APPENDIX C. POSITIONING THE FIGURES 116
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
\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. Note that while the \centering command can be used inside a Figure, the
\begin{center}...\end{center} environment has to be used within a minipage.
\begin{figure}[hbt]
\centering
%-------
\noindent %\framebox{
\begin{minipage}{3cm}
\begin{center}
%\vspace{...} %% controls space above picture
\input{mpicm08a.pic}
%\vspace{...} %% controls space between picture and caption
a. Circular arrows
\end{center}
\end{minipage}
%} %end of framebox
%-----------------------
\hspace{12mm} %% controls horiz space between figs
% \bigskip\bigskip %% use this to adjust vertical space
%----------------------
%\framebox{
\begin{minipage}{5cm}
\begin{center}
%\vspace{...} %% controls space between picture and caption
\input{mpicm08b.pic}
%\vspace{...} %% controls space between pict and caption
b. Straight arrows
APPENDIX C. POSITIONING THE FIGURES 117
\end{center}
\end{minipage}
%} %end of framebox
%---------
\caption{\label{}....}
\end{figure}
The mypic.pic file can then be \input into a document as a centered Figure as
follows.
\documentclass[a4paper]{article}
\usepackage{mathspic}
...
...
\begin{figure}[hbt]
\centering
\strut\input{mypic.pic}
\caption{...}
\label{...}
\end{figure}
Finally, it is important to note that if this approach is used, then it would be necessary
to comment out from the mathspic.sty file the LATEX command \thispagestyle{empty}
in order to enable page numbering on the first page of the document.
Appendix D
Perl is available for all MS-Windows platforms, and there are several Perl implementa-
tions to choose from. A good choice (which we describe here) would seem to be the free
ActiveState implementation of Perl in view of their excellent web site, documentation
and other resources.
D.1 Perl
The free ActivePerl implementation is a well regarded choice of Perl for the Win32
platform, and is easy to download and install. The current version for download at the
time of writing is Perl 5.8.6. There is excellent web support (e.g. documentation etc)
via their ASPN website (ActiveState Programming Network).
∙ http://www.activestate.com/Products/ActivePerl/
∙ http://aspn.activestate.com/ASPN/docs/ActivePerl/
The complete ActivePerl package consists of the following:-
∙ Perl (binary core Perl distribution)
∙ An installer package
∙ Perl Package Manager (PPM—a Perl extension installer and manager)
∙ Documentation
∙ Perl ISAPI (IIS plug-in that enhances the speed of standard Perl)
∙ PerlScript (ActiveX scripting engine)
∙ PerlEz (embedded Perl)
Installation
A useful installation guide can be found at http://www.activestate.com/ASPN/
docs/ActivePerl/install.html.
In addition to the Perl system itself, the older Windows systems 2000/NT also
require you to download a special ‘installer’ package (instMsiW.exe) to implement
the installation (see below). Note that the filename and sizes indicated below are those
at the time of writing.
118
APPENDIX D. INSTALLING PERL IN MS-WINDOWS 119
Step 1:
First, create a temporary directory for files which need to be downloaded. Then go
to the ActiveState web-site (http://www.activestate.com/) and click on the Lan-
guage/ActivePerl link which will take you to the ActivePerl page. Follow the ‘download’
links until you reach the ‘download’ page (you can skip the ‘contact-info’ section by
clicking the ‘next’ button), and then read the Windows section for the latest version of
ActivePerl (version 5.8.6).
Step 2:
Download the latest ActivePerl .msi file (approx 12 MB).
For example, ActivePerl-5.8.6.811-MSWin32-x86-122208.msi
Step 3:
Installation: the exact procedure depends on your particular Windows system as detailed
below. The default installation is the recommended ‘complete’ installation.
∙ Windows XP/2003:
To install simply double click on the ActivePerl .msi file and follow the instruc-
tions (these systems do not require a separate installer file).
Running Perl
Now that Perl is installed, we can progress to creating and running a Perl program. To
create a Perl program, simply open your favorite text-editor (see below for information
on some suitable text-editors) and write the program (as an ASCII text file), and finally
save it with a .pl extension.
For example, open a new file and type the following into it, and then save it with the
file-name test.pl (note that in Perl the # sign is the ‘comment’ symbol; the \n starts a
new line; variable names start with a \$).
#!/usr/bin/perl
# test.pl
print "hello world∖n";
$a=3, $b=7;
$sum=$a + $b;
print "sum = $sum∖n";
perl test.pl
APPENDIX D. INSTALLING PERL IN MS-WINDOWS 120
The output generated by the program will be written to the screen in the usual
way. If you want the output written to a file (say. test.txt) then instead type
perl test.pl > test.txt
∙ Click on the filename
If you just click on the filename in the directory listing (provided it has the .pl
filename extension) then ActivePerl will automatically open a DOS box, run
the program, and then close the DOS box. This is fine if the program output is
directed to a file, but if the output is simply directed to the screen (the default)
then you need to add the <> command at the end of the file, as this will keep the
screen open (so you can read the screen) until you hit a key.
#!/usr/bin/perl
# test.pl
print "hello world∖n";
$a=3, $b=7;
$sum=$a + $b;
print "sum = $sum∖n";
# -------------------
print "press any key to exit∖n";
<>
perl test.pl %1 %2
This batch file now has to be run at the command-line as shown above. Note that
ActivePerl can create a batch file from an ordinary perl program by using the
command utility pl2bat.bat. Simply access the command-line and type
pl2bat test.pl
which will then generate the file test.bat which can then be run at the command-
line by just typing test.
Perl modules
Additional modules can be downloaded from the huge Perl archives available on the
internet. These Perl modules can be installed either automatically (via the internet using
the PPM utility), or manually (download the module and then use the nmake utility). The
nmake utility is a Microsoft port of the Unix make utility, and can be downloaded from
the Microsoft internet archive at ftp://ftp.microsoft.com/Softlib/MSLFILES/.
The current version is bundled in the self-extracting package nmake15.exe
WinEdt (shareware)
This is an excellent ‘all-purpose’ text editor designed for use with TEX and LATEX; it has
syntax highlighting and can be tailored for use with Perl. It is available for download
from http://www.winedt.com/. Note that a free licence for this editor is provided
as a membership benefit by many TEX User Groups (e.g. ukTUG).
WinEDIT
The WinEDIT PowerPack is an excellent (commercial) general purpose text editor
available for download (21-day free trial) from http://www.winedit.com/. It is very
similar to WinEdt, and has the useful facility for column copying/pasting, and also an
optional vertical window holding the directory tree.
PICTEX
PICTEX is an excellent small graphics package, which is available on the TEXLive DVD
and from CTAN. If you have a recent TEX installation then it is likely that PICTEX is
already installed1 . If PICTEX is not installed, then create a PICTEX subdirectory in your
‘local’ TEX space, typically at
/usr/local/texlive/texmf-local/tex/latex/local/pictex/
Now copy into this new subdirectory all the PICTEX files in the following CTAN
directories:
CTAN:/tex-archive/graphics/pictex/
CTAN:/tex-archive/graphics/pictex/addon/
Unfortunately, the PICTEX Manual is not available from CTAN—the manual has
to be purchased separately (see Section E.6). However, mathsPIC users will mostly
find this unnecessary, since those PICTEX commands which are particularly useful in
conjunction with mathsPIC are described here in Chapter 5.
In the following, we present some background, including details about how to obtain
a copy of the PICTEX manual.
122
APPENDIX E. PICTEX 123
Note that only two of the following files are required when using plain TEX, while
three files are required when using LATEX.
The three files required for use with LATEX need to be loaded (input) in the order
shown above. Note that when using PICTEX with LATEX 2ε it is necessary to redefine the
LATEX 2.09 command \fiverm (because PICTEX was originally written for LATEX 2.09).
This is most easily done as follows ( and hence it is included in the mathspic.sty file).
\newcommand{\fiverm}{\rmfamily\tiny}
Alternatively you can use the more robust method (i.e. for wizards) suggested by
Michael J Downes as follows (I believe Michael Downes suggested this originally on
the comp.text.tex usenet group—see also the file fntguide.tex among the LATEX 2ε
documents).
\declarefixedfont{\fiverm}{\encodingdefault}{\rmdefault}{m}{n}{5}
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, as described in the next section.
In 1994 Andreas Schrell uploaded a set of updated PICTEX files into the
CTAN: .../graphics/pictex/addon/ directory. One of these additional files of
Schrell’s (pictexwd.tex) is a replacement for the original (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
(piccorr.sty), and add new functionality (picmore.tex).
∙ pictexwd.sty
For LATEX users. This replaces pictex.sty. It inputs prepictex.tex, pictexwd.tex,
and postpictex.tex, as well as inputting piccorr.sty and picmore.tex if
these are available.
∙ pictexwd.tex
For TEX users.
APPENDIX E. PICTEX 124
∙ picmore.tex
An extension for drawing impulse diagrams.
∙ piccorr.sty
A correction for the original PICTEX \betweenarrows command.
∙ pictex.sty
The LATEX style-option for loading the original PICTEX files. Note that it also
inputs piccorr.sty and picmore.tex if these are available.
All the necessary files required for running PICTEX are automatically input in the correct
order by pictexwd.sty (LATEX users), or by pictexwd.tex (TEX users). Users of
LATEX 2ε should include the following command in the preamble.
\usepackage{pictexwd}
\input latexpic.tex
\input pictexwd.tex
Note that even when using Andreas Schrell’s new files, all the original PICTEX files are
still required.
E.3 Pictex2.sty
CTAN/tex-archive/macros/latex/contrib/supported/pictex2.sty
16418 bytes 09/05/1999
William Park has written a style option (pictex2.sty) which adds two useful
commands to standard PICTEX, which force the use of the \putrule command where
lines are either horizontal or vertical, thus saving on memory (note that mathsPIC
automatically implements the use of \putrule in these circumstances). These two
commands are as follows.
∙ ∖putanyline
This command invokes the PICTEX \putrule command (instead of \plot) in
cases where lines are either vertical or horizontal.
∙ ∖setanyline
This is a line-drawing mode (similar to \setlinear) which forces subsequent
\plot commands to invoke \putrule whenever the line is either horizontal or
vertical.
E.4 Errorbars.tex
CTAN/tex-archive/graphics/pictex/errorbars.tex
3041 bytes 20/04/1988
APPENDIX E. PICTEX 125
In 1988 Dirk Grunwald implemented a new PICTEX command for drawing error bars
using a modified \plot command, as follows.
∙ ∖plotWithErrorBars
This command, which is case sensitive, has the format
\plotWithErrorBars mark M at
x1 y1 e1
...
xn yn en /
where M is a TEX character (e.g. $\bullet$), and 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 \crossbarlength=7pt.
To use this command, input the file errorbars.tex after all the PICTEX files.
E.5 DCpic
DCpic (by Pedro Quaresma) is a package of TEX macros for drawing commutative
diagrams in a LATEX or ConTEX document. It uses PICTEX to implement commands
which manipulate its various ‘objects’ and arrows. This package (February 2002) is
available on CTAN (and TEXLive) at
CTAN: tex-archive/macros/generic/diagrams/dcpic/
and includes the following documentation files:
manPT_dcpic.pdf
man_dcpic.pdf
These are also included in the CTAN section of the TEXLive-2010 DVD. Note that both
of the style files useful.sty and ukdate.sty are required to easily latex his .tex
file.
A short 3-page German summary by Siart (2008) is available at
http://www.siart.de/typografie/pictex-referenz.pdf
Other info
Lueck (2008) is a useful list of further information. Note some other documentation is
available on the TEXLive-2010 DVD, and is typically installed at the following locations:
/usr/local/texlive/2010/texmf-dist/doc/generic/FAQ-en/html/FAQ-docpictex.html
/usr/local/texlive/2010/texmf-dist/doc/generic/FAQ-en/html/FAQ-usepictex.html
/usr/local/texlive/2010/texmf-dist/doc/generic/doc-pictex
/usr/local/texlive/2010/texmf-dist/doc/generic/doc-pictex/Doc-PiCTeX.txt
References
∙ Abrahams P. W., Berry K. and Hargreaves K. A. (1990). TEX for the impatient.
(Addison-Wesley).
∙ Cameron P. J. (1992). Geometric diagrams in LATEX. TUGboat 13 (No. 2),
215–216.
∙ Beccari C. (1991). LaTeX – Guida ad un sistema di editoria elettronica. (Editore:
Ulrico Hoepli, Milano.) ISBN:88-203-1931-4. (for details see: TEX and TUG News
(1992); Vol 1, No 1: p 14. CTAN:/tex-archive/digests/ttn/ttn1n1.tex)
∙ Duggan A. (1990). PICTEX command summary (summary.zip) [note you need
both style files to process the tex file (latex 209)]
CTAN: ../tex-archive/info/pictex/summary/pictexsum.pdf
CTAN: ../tex-archive/info/pictex/summary/pictexsum.tex
CTAN: ../tex-archive/info/pictex/summary/useful.sty
CTAN: ../tex-archive/info/pictex/summary/ukdate.sty
http://chem.skku.ac.kr/~wpark/tutor/chem/ppchtex/pictexsum.ps
∙ Eijkhout V. (1992). TEX by topic: a TEXnician’s reference (Addison-Wesley).
This excellent book is now out of print, but Victor Eijkhout has kindly made it
available on-line at http://www.eijkhout.net/tbt/
∙ Feruglio G. V. (1994). Typesetting commutative diagrams. TUGboat 15 (No. 4),
466–484.
∙ Hoenig A (1998). TEX Unbound: LATEX and TEX strategies for fonts, graphics, &
more. (Oxford University Press, UK) pp. 580. ISBN: 0-19-509685-1 (hardback),
0-19-509686-X (paperback).
[see pages 377–389 for details of PICTEX and a summary of commands]
∙ Holzner S. (1999) Perl Core Language—Little black book. (Technology Press—
The Coriolis Group) ISBN 1–57610–426–5.
∙ Knuth D. E. (1990). The TEXbook; 19th printing. (Addison-Wesley).
∙ Lueck U (2008). Documentation for PICTEX.
/texlive/2010/texmf-dist/doc/generic/doc-pictex/Doc-PiCTeX.txt
∙ Nickalls R. W. D. (1999). MathsPIC: a filter program for use with PICTEX.
EuroTEX’99 Proceedings; 197–210. (Heidelberg, Germany; August 1999). http:
//www.uni-giessen.de/~g029/eurotex99/nickalls.pdf [MS-DOS ver-
sion] [reproduced in: Eutupon, No. 3 (October, 1999), 33–49 (the Greek TEX
Friends’ journal)]
127
REFERENCES 128
∙ Salomon D. (1992). Arrows for technical drawing. TUGboat 13 (No. 2), 146–149.
∙ Siart U (date: ?)
http://www.siart.de/typografie/pictex-referenz.pdf [from Lueck
(2008)]
∙ Syropoulos A. (1999). Literate programming: the other side of the coin. RAM
Magazine; 129, 248–253 [in Greek]
∙ Syropoulos A. and Nickalls R. W. D. (2000). A PERL porting of the math-
sPIC graphics package. TUG2000 Annual Meeting, Oxford, UK (August 13–16,
2000). TUGboat, 21, 292–297. http://www.tug.org/TUGboat/articles/
letters/tb21-3/tb68syro.pdf