home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
useful
/
text
/
tex
/
pastex
/
mf
/
inputs
/
plain.mf
< prev
next >
Wrap
Text File
|
1993-10-22
|
23KB
|
590 lines
% This is the plain METAFONT base that's described in The METAFONTbook.
% N.B.: Please change "base_version" whenever this file is modified!
% And don't modify the file under any circumstances.
string base_name, base_version; base_name="plain"; base_version="2.71";
message "Preloading the plain base, version "&base_version&": preliminaries,";
delimiters (); % this makes parentheses behave like parentheses
def upto = step 1 until enddef; % syntactic sugar
def downto = step -1 until enddef;
def exitunless expr c = exitif not c enddef;
let relax = \; % ignore the word `relax', as in TeX
let \\ = \; % double relaxation is like single
def ]] = ] ] enddef; % right brackets should be loners
def -- = {curl 1}..{curl 1} enddef;
def --- = .. tension infinity .. enddef;
def ... = .. tension atleast 1 .. enddef;
def gobble primary g = enddef; def killtext text t = enddef;
primarydef g gobbled gg = enddef;
def hide(text t) = exitif numeric begingroup t;endgroup; enddef;
def ??? = hide(interim showstopping:=1; showdependencies) enddef;
def stop expr s = message s; gobble readstring enddef;
smoothing:=1; autorounding:=2; % this adjusts curves to the raster
turningcheck:=2; % this will warn about a "strange path"
granularity:=1; % this says that pixels are pixels
def interact = % sets up to make "show" commands stop
hide(showstopping:=1; tracingonline:=1) enddef;
def loggingall = % puts tracing info into the log
tracingcommands:=3; tracingedges:=2; tracingtitles:=1; tracingequations:=1;
tracingcapsules:=1; tracingspecs:=1; tracingpens:=1; tracingchoices:=1;
tracingstats:=1; tracingoutput:=1; tracingmacros:=1; tracingrestores:=1;
enddef;
def tracingall = % turns on every form of tracing
tracingonline:=1; showstopping:=1; loggingall enddef;
def tracingnone = % turns off every form of tracing
tracingcommands:=0; tracingonline:=0; showstopping:=0;
tracingedges:=0; tracingtitles:=0; tracingequations:=0;
tracingcapsules:=0; tracingspecs:=0; tracingpens:=0; tracingchoices:=0;
tracingstats:=0; tracingoutput:=0; tracingmacros:=0; tracingrestores:=0;
enddef;
message " basic constants and mathematical macros,";
% numeric constants
newinternal eps,epsilon,infinity,_;
eps := .00049; % this is a pretty small positive number
epsilon := 1/256/256; % but this is the smallest
infinity := 4095.99998; % and this is the largest
_ := -1; % internal constant to make macros unreadable but shorter
% pair constants
pair right,left,up,down,origin;
origin=(0,0); up=-down=(0,1); right=-left=(1,0);
% path constants
path quartercircle,halfcircle,fullcircle,unitsquare;
quartercircle=(right{up}..(right+up)/sqrt2..up{left}) scaled .5;
halfcircle=quartercircle & quartercircle rotated 90;
fullcircle=halfcircle & halfcircle rotated 180 & cycle;
unitsquare=(0,0)--(1,0)--(1,1)--(0,1)--cycle;
% transform constants
transform identity;
for z=origin,right,up: z transformed identity = z; endfor
% picture constants
picture blankpicture,unitpixel;
blankpicture=nullpicture; % `display blankpicture...'
unitpixel=nullpicture; addto unitpixel contour unitsquare;
% string constants
string ditto; ditto = char 34; % ASCII double-quote mark
% pen constants
def capsule_def(suffix s) primary u = def s = u enddef enddef;
capsule_def(pensquare) makepen(unitsquare shifted -(.5,.5));
capsule_def(penrazor) makepen((-.5,0)--(.5,0)--cycle);
pen penspeck; penspeck=pensquare scaled eps;
% nullary operators
vardef whatever = save ?; ? enddef;
% unary operators
let abs = length;
vardef round primary u =
if numeric u: floor(u+.5)
elseif pair u: (hround xpart u, vround ypart u)
else: u fi enddef;
vardef hround primary x = floor(x+.5) enddef;
vardef vround primary y = floor(y.o_+.5)_o_ enddef;
vardef ceiling primary x = -floor(-x) enddef;
vardef byte primary s =
if string s: ASCII fi s enddef;
vardef dir primary d = right rotated d enddef;
vardef unitvector primary z = z/abs z enddef;
vardef inverse primary T =
transform T_; T_ transformed T = identity; T_ enddef;
vardef counterclockwise primary c =
if turningcheck>0:
interim autorounding:=0;
if turningnumber c <= 0: reverse fi fi c enddef;
vardef tensepath expr r =
for k=0 upto length r - 1: point k of r --- endfor
if cycle r: cycle else: point infinity of r fi enddef;
% binary operators
primarydef x mod y = (x-y*floor(x/y)) enddef;
primarydef x div y = floor(x/y) enddef;
primarydef w dotprod z = (xpart w * xpart z + ypart w * ypart z) enddef;
primarydef x**y = if y=2: x*x else: takepower y of x fi enddef;
def takepower expr y of x =
if x>0: mexp(y*mlog x)
elseif (x=0) and (y>0): 0
else: 1
if y=floor y:
if y>=0: for n=1 upto y: *x endfor
else: for n=_ downto y: /x endfor
fi
else: hide(errmessage "Undefined power: " & decimal x&"**"&decimal y)
fi fi enddef;
vardef direction expr t of p =
postcontrol t of p - precontrol t of p enddef;
vardef directionpoint expr z of p =
a_:=directiontime z of p;
if a_<0: errmessage("The direction doesn't occur"); fi
point a_ of p enddef;
secondarydef p intersectionpoint q =
begingroup save x_,y_; (x_,y_)=p intersectiontimes q;
if x_<0: errmessage("The paths don't intersect"); origin
else: .5[point x_ of p, point y_ of q] fi endgroup
enddef;
tertiarydef p softjoin q =
begingroup c_:=fullcircle scaled 2join_radius shifted point 0 of q;
a_:=ypart(c_ intersectiontimes p); b_:=ypart(c_ intersectiontimes q);
if a_<0:point 0 of p{direction 0 of p} else: subpath(0,a_) of p fi
... if b_<0:{direction infinity of q}point infinity of q
else: subpath(b_,infinity) of q fi endgroup enddef;
newinternal join_radius,a_,b_; path c_;
% special operators
vardef incr suffix $ = $:=$+1; $ enddef;
vardef decr suffix $ = $:=$-1; $ enddef;
def reflectedabout(expr w,z) = % reflects about the line w..z
transformed
begingroup transform T_;
w transformed T_ = w; z transformed T_ = z;
xxpart T_ = -yypart T_; xypart T_ = yxpart T_; % T_ is a reflection
T_ endgroup enddef;
def rotatedaround(expr z, d) = % rotates d degrees around z
shifted -z rotated d shifted z enddef;
let rotatedabout = rotatedaround; % for roundabout people
vardef min(expr u)(text t) = % t is a list of numerics, pairs, or strings
save u_; setu_ u; for uu = t: if uu<u_: u_:=uu; fi endfor
u_ enddef;
vardef max(expr u)(text t) = % t is a list of numerics, pairs, or strings
save u_; setu_ u; for uu = t: if uu>u_: u_:=uu; fi endfor
u_ enddef;
def setu_ primary u =
if pair u: pair u_ elseif string u: string u_ fi;
u_=u enddef;
def flex(text t) = % t is a list of pairs
hide(n_:=0; for z=t: z_[incr n_]:=z; endfor
dz_:=z_[n_]-z_1)
z_1 for k=2 upto n_-1: ...z_[k]{dz_} endfor ...z_[n_] enddef;
newinternal n_; pair z_[],dz_;
def superellipse(expr r,t,l,b,s)=
r{up}...(s[xpart t,xpart r],s[ypart r,ypart t]){t-r}...
t{left}...(s[xpart t,xpart l],s[ypart l,ypart t]){l-t}...
l{down}...(s[xpart b,xpart l],s[ypart l,ypart b]){b-l}...
b{right}...(s[xpart b,xpart r],s[ypart r,ypart b]){r-b}...cycle enddef;
vardef interpath(expr a,p,q) =
for t=0 upto length p-1: a[point t of p, point t of q]
..controls a[postcontrol t of p, postcontrol t of q]
and a[precontrol t+1 of p, precontrol t+1 of q] .. endfor
if cycle p: cycle
else: a[point infinity of p, point infinity of q] fi enddef;
vardef solve@#(expr true_x,false_x)= % @#(true_x)=true, @#(false_x)=false
tx_:=true_x; fx_:=false_x;
forever: x_:=.5[tx_,fx_]; exitif abs(tx_-fx_)<=tolerance;
if @#(x_): tx_ else: fx_ fi :=x_; endfor
x_ enddef; % now x_ is near where @# changes from true to false
newinternal tolerance, tx_,fx_,x_; tolerance:=.1;
message " macros for converting from device-independent units to pixels,";
def fix_units = % define the conversion factors, given pixels_per_inch
mm:=pixels_per_inch/25.4; cm:=pixels_per_inch/2.54;
pt:=pixels_per_inch/72.27; pc:=pixels_per_inch/6.0225;
dd:=1238/1157pt; cc:=12dd;
bp:=pixels_per_inch/72; in:=pixels_per_inch;
hppp:=pt; % horizontal pixels per point
vppp:=aspect_ratio*hppp; % vertical pixels per point
enddef;
mm#=2.84528; pt#=1; dd#=1.070