home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fonts 1
/
freshfonts1.bin
/
bbs
/
programs
/
amiga
/
mma2latex.lha
/
MMA2LTX
/
MMA2LTX.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-07-19
|
31KB
|
816 lines
/************************************************************************\
* *
* mma2ltc.c - Copyright (C) 1994 by Giuseppe Ghibo` *
* *
* version 1.2 - 16 July 1994 *
* *
\************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
typedef int bool;
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef min
#define min(a,b) (a<b ? a : b)
#endif
#ifndef max
#define max(a,b) (a>b ? a : b)
#endif
struct pnts {
float gx,gy,tx,ty;
};
struct scaletrasl {
float Ax,Ay,Bx,By;
};
struct cw {
float ctx,wtx,cgx,wgx,cty,wty,cgy,wgy;
};
struct TeXunits {
float convfactor;
char *strunit;
};
struct TeXunits TeXtable[] = {
{72.0/25.4,"mm"}, /* mm to bp */
{72.0/2.54,"cm"}, /* cm to bp */
{72.0/72.27,"pt"}, /* pt to bp */
{1.0,"bp"}, /* bp to bp */
{72.0/72.27*12.0,"pc"}, /* pc to bp */
{72.0,"in"}, /* in to bp */
{1238.0/1157.0*72.0/72.27,"dd"}, /* dd to bp */
{1238.0/1157.0*12.0*72.0/72.27,"cc"}, /* cc to bp */
{72.0/72.27/65536.0,"sp"}, /* sp to bp */
{1.0,""}
};
/* Prototypes */
void Mlprun(float,float,struct cw *);
void Mlp(float,float,struct scaletrasl *);
void Mlp1(float,float,float,float,float,float,float *,float *,bool *);
float strtobp(char *);
float bptounit(char *);
void stripext(char *,char *);
char *strtolwr(char *);
#define NMAX 1000
#define NMAXFILEIN 20 /* maximun number of files to process */
#define TMPLEN 512
#define PROLOG "texmma22.pro"
#define OPTSWITCH1 '-'
#define OPTSWITCH2 '/'
int np=0;
struct pnts *p;
char tmpbuf1[TMPLEN],tmpbuf2[TMPLEN];
char texfname[256];
bool Mnodistort = TRUE; /* keep the aspect ratio ? */
/* This is the Mathematica v2.2 prologue file */
char *prologue[] = {
"/Mlmarg 0 def /Mrmarg 0 def /Mbmarg 0 def /Mtmarg 0 def /Mtransform{}\n",
"bind def /Mfixwid true def /Mfixdash false def /Mrot 0 def /Mpstart{\n",
"MathPictureStart}bind def /Mpend{MathPictureEnd}bind def /Mscale{0 1 0 1\n",
"5 -1 roll MathScale}bind def /ISOLatin1Encoding dup where{pop pop}{[\n",
"/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef\n",
"/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef\n",
"/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef\n",
"/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef\n",
"/space /exclam /quotedbl /numbersign /dollar /percent /ampersand\n",
"/quoteright /parenleft /parenright /asterisk /plus /comma /minus /period\n",
"/slash /zero /one /two /three /four /five /six /seven /eight /nine\n",
"/colon /semicolon /less /equal /greater /question /at /A /B /C /D /E /F\n",
"/G /H /I /J /K /L /M /N /O /P /Q /R /S /T /U /V /W /X /Y /Z /bracketleft\n",
"/backslash /bracketright /asciicircum /underscore /quoteleft /a /b /c /d\n",
"/e /f /g /h /i /j /k /l /m /n /o /p /q /r /s /t /u /v /w /x /y /z\n",
"/braceleft /bar /braceright /asciitilde /.notdef /.notdef /.notdef\n",
"/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef\n",
"/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /dotlessi /grave\n",
"/acute /circumflex /tilde /macron /breve /dotaccent /dieresis /.notdef\n",
"/ring /cedilla /.notdef /hungarumlaut /ogonek /caron /space /exclamdown\n",
"/cent /sterling /currency /yen /brokenbar /section /dieresis /copyright\n",
"/ordfeminine /guillemotleft /logicalnot /hyphen /registered /macron\n",
"/degree /plusminus /twosuperior /threesuperior /acute /mu /paragraph\n",
"/periodcentered /cedilla /onesuperior /ordmasculine /guillemotright\n",
"/onequarter /onehalf /threequarters /questiondown /Agrave /Aacute\n",
"/Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla /Egrave /Eacute\n",
"/Ecircumflex /Edieresis /Igrave /Iacute /Icircumflex /Idieresis /Eth\n",
"/Ntilde /Ograve /Oacute /Ocircumflex /Otilde /Odieresis /multiply\n",
"/Oslash /Ugrave /Uacute /Ucircumflex /Udieresis /Yacute /Thorn\n",
"/germandbls /agrave /aacute /acircumflex /atilde /adieresis /aring /ae\n",
"/ccedilla /egrave /eacute /ecircumflex /edieresis /igrave /iacute\n",
"/icircumflex /idieresis /eth /ntilde /ograve /oacute /ocircumflex\n",
"/otilde /odieresis /divide /oslash /ugrave /uacute /ucircumflex\n",
"/udieresis /yacute /thorn /ydieresis]def}ifelse /MFontDict 50 dict def\n",
"/MStrCat{exch dup length 2 index length add string dup 3 1 roll copy\n",
"length exch dup 4 2 roll exch putinterval}def /MCreateEncoding{1 index\n",
"255 string cvs(-)MStrCat 1 index MStrCat cvn exch(Encoding)MStrCat cvn\n",
"dup where{exch get}{pop StandardEncoding}ifelse 3 1 roll dup MFontDict\n",
"exch known not{1 index findfont dup length dict begin{1 index /FID ne{\n",
"def}{pop pop}ifelse}forall /Encoding 3 index def currentdict end 1 index\n",
"exch definefont pop MFontDict 1 index null put}if exch pop exch pop}def\n",
"/ISOLatin1{(ISOLatin1)MCreateEncoding}def /ISO8859{(ISOLatin1)\n",
"MCreateEncoding}def /Mcopyfont{dup maxlength dict exch{1 index /FID eq{\n",
"pop pop}{2 index 3 1 roll put}ifelse}forall}def /Plain /Courier findfont\n",
"Mcopyfont definefont pop /Bold /Courier-Bold findfont Mcopyfont\n",
"definefont pop /Italic /Courier-Oblique findfont Mcopyfont definefont\n",
"pop /MathPictureStart{gsave Mtransform Mlmarg Mbmarg translate Mwidth\n",
"Mlmarg Mrmarg add sub /Mwidth exch def Mheight Mbmarg Mtmarg add sub\n",
"/Mheight exch def /Mtmatrix matrix currentmatrix def /Mgmatrix matrix\n",
"currentmatrix def}bind def /MathPictureEnd{grestore}bind def /MFill{0 0\n",
"moveto Mwidth 0 lineto Mwidth Mheight lineto 0 Mheight lineto fill}bind\n",
"def /MPlotRegion{3 index Mwidth mul 2 index Mheight mul translate exch\n",
"sub Mheight mul /Mheight exch def exch sub Mwidth mul /Mwidth exch def}\n",
"bind def /MathSubStart{Momatrix Mgmatrix Mtmatrix Mwidth Mheight 7 -2\n",
"roll moveto Mtmatrix setmatrix currentpoint Mgmatrix setmatrix 9 -2 roll\n",
"moveto Mtmatrix setmatrix currentpoint 2 copy translate /Mtmatrix matrix\n",
"currentmatrix def 3 -1 roll exch sub /Mheight exch def sub /Mwidth exch\n",
"def}bind def /MathSubEnd{/Mheight exch def /Mwidth exch def /Mtmatrix\n",
"exch def dup setmatrix /Mgmatrix exch def /Momatrix exch def}bind def\n",
"/Mdot{moveto 0 0 rlineto stroke}bind def /Mtetra{moveto lineto lineto\n",
"lineto fill}bind def /Metetra{moveto lineto lineto lineto closepath\n",
"gsave fill grestore 0 setgray stroke}bind def /Mistroke{flattenpath 0 0\n",
"0{4 2 roll pop pop}{4 -1 roll 2 index sub dup mul 4 -1 roll 2 index sub\n",
"dup mul add sqrt 4 -1 roll add 3 1 roll}{stop}{stop}pathforall pop pop\n",
"currentpoint stroke moveto currentdash 3 -1 roll add setdash}bind def\n",
"/Mfstroke{stroke currentdash pop 0 setdash}bind def /Mrotsboxa{gsave dup\n",
"/Mrot exch def Mrotcheck Mtmatrix dup setmatrix 7 1 roll 4 index 4 index\n",
"translate rotate 3 index -1 mul 3 index -1 mul translate /Mtmatrix\n",
"matrix currentmatrix def grestore Msboxa 3 -1 roll /Mtmatrix exch def\n",
"/Mrot 0 def}bind def /Msboxa{newpath 5 -1 roll Mvboxa pop Mboxout 6 -1\n",
"roll 5 -1 roll 4 -1 roll Msboxa1 5 -3 roll Msboxa1 Mboxrot[7 -2 roll 2\n",
"copy[3 1 roll 10 -1 roll 9 -1 roll]6 1 roll 5 -2 roll]}bind def /Msboxa1\n",
"{sub 2 div dup 2 index 1 add mul 3 -1 roll -1 add 3 -1 roll mul}bind def\n",
"/Mvboxa{Mfixwid{Mvboxa1}{dup Mwidthcal 0 exch{add}forall exch Mvboxa1 4\n",
"index 7 -1 roll add 4 -1 roll pop 3 1 roll}ifelse}bind def /Mvboxa1{\n",
"gsave newpath[true 3 -1 roll{Mbbox 5 -1 roll{0 5 1 roll}{7 -1 roll exch\n",
"sub(m)stringwidth pop .3 mul sub 7 1 roll 6 -1 roll 4 -1 roll