home *** CD-ROM | disk | FTP | other *** search
/ Lighthouse Design Suite / LIGHTHOUSE.mdf / FrameMaker_3.2 / FrameExtras / frameout.m < prev    next >
Text File  |  1994-07-07  |  3KB  |  89 lines

  1. (* This file contains Mathematica definitions for Converting Expressions into FrameMaker's
  2.      Ascii form of equations.    Equations are placed in a FrameMaker MIF document, and 
  3.      the document is given to Frame to open, using the open command  *)
  4.      
  5. (*  Syntax is FrameForm[expr]   *) 
  6.  
  7. (* utility routines used in FForm *)
  8. Fnum[x_] := num[x,StringJoin["\"",ToString[x],"\""]]
  9. Fconvertinteger[e_] := If[Head[e] === Integer,Fnum[e],e];
  10. Fconvertsymbol[e_] := If[Head[e] === Symbol,char[e],e];
  11. Fconvertreal[e_] := If[Head[e] === Real,Fnum[e],e];
  12.  
  13. (* This procedure converts an expression from Mathematic form to Frame form *)
  14. FForm[start_] := 
  15.     Block[{FFv,new}, FFv = start;
  16.      
  17.         
  18.     (* Calculus *)
  19.     FFv = FFv //. Integrate[g_,x_] -> int[g,diff[x]];
  20.     FFv = FFv //. Integrate[g_,{x_,min_,max_}] ->
  21.                         int[g,diff[x],min,max];
  22.     FFv = FFv //. Derivative[1,x_][g_] -> function[optotal[x],g];
  23.     FFv = FFv //. Derivative[n_,x_][g_] -> function[optotal[x,n],g];
  24.     FFv = FFv //. D[g_,x_] -> oppartial[x,g];
  25.     FFv = FFv //. D[g_,{x_,p_}] -> oppartial[x,p,g];
  26.         
  27.      (* Do Rational before MapAlls. This gets treated as a single object on MapAlls,
  28.          so internal numbers are concealed if this step follows the MapAlls *)
  29.         FFv = FFv //. Rational[x_,y_] -> over[x,y];    
  30.         
  31.     (* We use MapAll to convert Symbol,Integer, & Real, because I
  32.        could not get mapping rules to work *)
  33.        
  34.         FFv = MapAll[Fconvertsymbol, FFv];
  35.         FFv = MapAll[Fconvertinteger, FFv];
  36.         FFv = MapAll[Fconvertreal, FFv];
  37.         
  38.         (* Some Trig functions *)
  39.         FFv = FFv //. Cos[x_] -> cos[x];
  40.         FFv = FFv //. Sin[x_] -> sin[x];
  41.         FFv = FFv //. Tan[x_] -> tan[x];    
  42.         
  43.         (* Simple Operators *)
  44.         FFv = FFv //. Plus[x_,y_] -> plus[x,y];    
  45.         FFv = FFv //. Times[x_,y_] -> times[x,y];    
  46.         FFv = FFv //. Power[x_,y_] -> power[x,y];    
  47.         FFv = FFv //. Divide[x_,y_] -> over[x,y];    
  48.         FFv = FFv //. Subtract[x_,y_] -> subtract[x,y];    
  49.         FFv = FFv //. Abs[x_] -> abs[x];    
  50.         FFv = FFv //. Minus[x_] -> minus[x];
  51.         FFv = FFv //. Log[x_] -> log[x];
  52.         
  53.         
  54.         FFv
  55.         ]
  56.  
  57. (* We do a bunch of file io and create a tmp file to be opened in FrameMaker *)
  58. FrameForm[x_] := 
  59.     Block[{FFu,f,s}, FFu = x; 
  60.         f = "/tmp/math.framemif";
  61.         s = "/tmp/math.scratch";
  62.         OpenWrite[f]
  63.         WriteString[f,"<MIFFile 2.00>   # Generated From Within Mathematica\n"];
  64.         WriteString[f,"<Document\n"];
  65.         WriteString[f,"<DWindowRect 132 178 475 333 >\n"];   (* window position *)
  66.         WriteString[f,"<DPageSize 6.0 4.0 >\n"];             (* size of document *)
  67.         WriteString[f,">\n"];            
  68.         WriteString [f, "<Math \n"];
  69.         Close[f];
  70.         OpenWrite[s];
  71.         WriteString [s," <MathFullForm `"];
  72.         WriteString[s, FForm[FFu]];
  73.         WriteString [s,"'"];
  74.         Close[s];
  75.     (* We need a special step to waste blanks, because the Frame input
  76.      cannot handle blanks.  Must have num[3,"3"] not num[3, "3"]
  77.      This needs to be fixed by Frame *)
  78.         Run["tr -d '\040' </tmp/math.scratch >>/tmp/math.framemif"];
  79.         OpenAppend[f];
  80.         WriteString [f," \n>\n<MathOrigin  3 2 >\n"];   (* center on page *)
  81.         WriteString [f," <MathAlignment Center >\n"];
  82.         WriteString [f," <MathSize MathLarge >\n"];
  83.         WriteString [f," <Angle 0>>\n"];
  84.         Close[f];
  85.         Run["open /tmp/math.framemif"]
  86.         ]
  87. "Done Loading FrameMaker Output Functions"
  88.  
  89.