===================================================================
RCS file: /home/cvs/OpenXM_contrib/gnuplot/term/Attic/metapost.trm,v
retrieving revision 1.1
retrieving revision 1.1.1.2
diff -u -p -r1.1 -r1.1.1.2
--- OpenXM_contrib/gnuplot/term/Attic/metapost.trm	2000/01/22 14:16:27	1.1
+++ OpenXM_contrib/gnuplot/term/Attic/metapost.trm	2003/09/15 07:09:37	1.1.1.2
@@ -1,5 +1,5 @@
 /*
- * $Id: metapost.trm,v 1.1 2000/01/22 14:16:27 maekawa Exp $
+ * $Id: metapost.trm,v 1.1.1.2 2003/09/15 07:09:37 ohara Exp $
  */
 
 /* GNUPLOT - metapost.trm */
@@ -88,8 +88,10 @@ TERM_PUBLIC void MP_boxfill __PROTO((int style,
 #define MP_YSIZE 3.0
 
 /* gnuplot units will be one pixel if printing device has this
-   resolution */
-#define MP_DPI (300)
+   resolution. Too small resolutions (like 300) can give rough
+   appearence to curves when user tries to smooth a curve by choosing
+   high sampling rate. */
+#define MP_DPI (2400)
 
 #define MP_XMAX (MP_XSIZE*MP_DPI)
 #define MP_YMAX (MP_YSIZE*MP_DPI)
@@ -134,8 +136,20 @@ static TBOOLEAN MP_color = FALSE;
 static TBOOLEAN MP_solid = FALSE;
 
 /* compatability mode*/
-static TBOOLEAN MP_notex = FALSE;
-
+/* static TBOOLEAN MP_notex = FALSE; */
+#define MP_NO_TEX 0
+#define MP_TEX 1
+#define MP_LATEX 2
+static int MP_tex = MP_TEX;
+/* add usepackage instructions for PSNFSS ? */
+#define MP_PSNFSS_NONE	0
+#define MP_PSNFSS_7	1
+#define MP_PSNFSS_8	2
+static int MP_psnfss = MP_PSNFSS_NONE;
+/* add a4paper option to documentclass */
+static int MP_a4paper = 0;
+/* write a prologues line */
+static int MP_prologues = -1;
 /* has a font change taken place? */
 static TBOOLEAN MP_fontchanged = FALSE;
 
@@ -157,13 +171,17 @@ MP_options()
 {
     MP_color = FALSE;
     MP_solid = FALSE;
-    MP_notex = FALSE;
+/*    MP_notex = FALSE;*/
+    MP_tex = MP_TEX;
+    MP_a4paper = 0;
+    MP_psnfss  = MP_PSNFSS_NONE;
     MP_fontsize = 10.0;
     MP_textmag = 1.0;
+    MP_prologues = -1;
     strcpy(MP_fontname, "cmr10");
     strcpy(default_font, "");	/* output file will store default font info */
     while (!END_OF_COMMAND) {
-	if (almost_equals(c_token, "m$onochrome")) {
+	if (almost_equals(c_token, "mo$nochrome")) {
 	    MP_color = FALSE;
 	    c_token++;
 	    continue;
@@ -184,22 +202,64 @@ MP_options()
 	    continue;
 	}
 	if (almost_equals(c_token, "n$otex")) {
-	    MP_notex = TRUE;
+/*	    MP_notex = TRUE;*/
+            MP_tex = MP_NO_TEX;
 	    strcpy(MP_fontname, "pcrr8r");
 	    c_token++;
 	    continue;
 	}
 	if (almost_equals(c_token, "t$ex")) {
-	    MP_notex = FALSE;
+	    MP_tex = MP_TEX;
 	    c_token++;
 	    continue;
 	}
+ 	if (almost_equals(c_token, "la$tex")) {
+ 	    MP_tex = MP_LATEX;
+            c_token++;
+ 	    continue;
+ 	}
+	if (almost_equals(c_token, "a4$paper")) {
+	  MP_a4paper = 1;
+	  c_token++;
+	  continue;
+	}
+	if(almost_equals(c_token, "ps$nfss")) {
+	  MP_psnfss = MP_PSNFSS_8;
+	  c_token++;
+	  continue;
+	}
+	if(almost_equals(c_token, "psnfss-v$ersion7")) {
+	  MP_psnfss = MP_PSNFSS_7;
+	  c_token++;
+	  continue;
+	}
+	if(almost_equals(c_token, "nops$nfss")) {
+	  MP_psnfss = MP_PSNFSS_NONE;
+	  c_token++;
+	  continue;
+	}
 	if (almost_equals(c_token, "de$fault")) {
 	    c_token++;
 	    continue;
 	}
-	if (almost_equals(c_token, "m$agnification")) {
+	if (almost_equals(c_token, "pro$logues")) {
+	  int dummy_for_prologues;
+	  c_token++;
+	  if(!(END_OF_COMMAND)) {
+	    if(sscanf(&(input_line[token[c_token].start_index]), "%d", &dummy_for_prologues) == 1) {
+	      MP_prologues = dummy_for_prologues;
+	    }
 	    c_token++;
+	  }
+	  continue;
+	}
+	if (almost_equals(c_token, "nopro$logues")) {
+	  MP_prologues = -1;
+	  c_token++;
+	  continue;
+	}
+	if (almost_equals(c_token, "ma$gnification")) {
+	    c_token++;
 	    if (!END_OF_COMMAND) {	/* global text scaling */
 		struct value a;
 		MP_textmag = (double) real(const_express(&a));
@@ -225,15 +285,15 @@ MP_options()
 	MP_fontsize = 99.99;
 
     term->v_char = (unsigned int) (MP_DPI * MP_fontsize * MP_textmag * 11 / 720);
-    if (MP_notex) {		/* Courier is a little wider than cmtt */
+    if (MP_tex == MP_NO_TEX) {		/* Courier is a little wider than cmtt */
 	term->h_char = (unsigned int) (MP_DPI * MP_fontsize * MP_textmag * 6.0 / 720 + 0.5);
     } else {
 	term->h_char = (unsigned int) (MP_DPI * MP_fontsize * MP_textmag * 5.3 / 720 + 0.5);
     }
-    sprintf(term_options, "%s%s%s%s%6.3f \"%s\" %5.2f",
+    sprintf(term_options, "%s%s%s%s%6.3f \"%s\" %5.2f %d %d",
 	    MP_color ? "color " : "", MP_solid ? "solid " : "",
-	    MP_notex ? "notex " : "", "mag ",
-	    MP_textmag, MP_fontname, MP_fontsize);
+ 	    (MP_tex == MP_NO_TEX) ? "notex " : (MP_tex == MP_LATEX) ? "latex " : "", "mag ",
+	    MP_textmag, MP_fontname, MP_fontsize, MP_psnfss, MP_prologues);
 }
 
 TERM_PUBLIC void
@@ -243,12 +303,58 @@ MP_init()
     time(&now);
     MP_posx = MP_posy = 0;
     fprintf(gpoutfile, "%%GNUPLOT Metapost output: %s\n", asctime(localtime(&now)));
+    if(MP_prologues > -1) {
+      fprintf(gpoutfile, "prologues:=%d;\n", MP_prologues);
+    }
+    if (MP_tex == MP_LATEX) {
+        fputs("\n\
+%% Add \\documentclass and \\begin{dcoument} for latex\n\
+%% NB you should set the environment variable TEX to the name of your\n\
+%% latex executable (normally latex) inorder for metapost to work\n\
+%% or run\n\
+%% mpost --tex=latex ...\n\
+\n\
+% BEGPRE\n\
+\\verbatimtex\n", gpoutfile);
+	if(MP_a4paper) {
+	  fputs("\\documentclass[a4paper]{article}\n", gpoutfile);
+	} else {
+	  fputs("\\documentclass{article}\n", gpoutfile);
+	}
+	switch(MP_psnfss) {
+	  case MP_PSNFSS_7: {
+            fputs("\\usepackage[latin1]{inputenc}\n\
+\\usepackage[T1]{fontenc}\n\
+\\usepackage{times,mathptmx}\n\
+\\usepackage{helvet}\n\
+\\usepackage{courier}\n", gpoutfile);
+	  } break;
+	  case MP_PSNFSS_8: {
+	    fputs("\\usepackage[latin1]{inputenc}\n\
+\\usepackage[T1]{fontenc}\n\
+\\usepackage{textcomp}\n\
+\\usepackage{mathptmx}\n\
+\\usepackage[scaled=.92]{helvet}\n\
+\\usepackage{courier}\n\
+\\usepackage{latexsym}\n", gpoutfile);
+	  } break;
+	}
+	fputs("\\begin{document}\n\
+etex\n% ENDPRE\n",
+              gpoutfile);
+    }
+
     fputs("\n\
+warningcheck:=0;\n\
 defaultmpt:=mpt:=4;\n\
 th:=.6;\n\
+%% Have nice sharp joins on our lines\n\
+linecap:=butt;\n\
+linejoin:=mitered;\n\
 \n\
 def scalepen expr n = pickup pencircle scaled (n*th) enddef;\n\
-def ptsize expr n = mpt:=n*defaultmpt enddef;\n",
+def ptsize expr n = mpt:=n*defaultmpt enddef;\n\
+\n",
 	  gpoutfile);
 
     fprintf(gpoutfile, "\ntextmag:=%6.3f;\n", MP_textmag);
@@ -261,27 +367,28 @@ vardef makepic(expr str) =\n\
   fi\n\
 enddef;\n\
 \n\
-def	infontsize(expr str, size) =\n\
-  infont str scaled (size /	fontsize str)\n\
+def infontsize(expr str, size) =\n\
+  infont str scaled (size / fontsize str)\n\
 enddef;\n",
 	  gpoutfile);
 
-    if (MP_notex) {
+    if (MP_tex == MP_NO_TEX) {
 	fprintf(gpoutfile, "\n\
 defaultfont:= \"%s\";\n\
 defaultscale := %6.3f/fontsize defaultfont;\n",
 		MP_fontname, MP_fontsize);
     } else {
+      if(MP_tex != MP_LATEX) {
 	fputs("\n\
 %font changes\n\
 verbatimtex\n\
-  \\def\\setfont#1#2{%.\n\
-    \\font\\gpfont=#1 at #2pt\n\
-    \\gpfont}\n",
-	      gpoutfile);
-
+\\def\\setfont#1#2{%.\n\
+  \\font\\gpfont=#1 at #2pt\n\
+\\gpfont}\n", gpoutfile);
 	fprintf(gpoutfile, "\\setfont{%s}{%5.2f}\netex\n",
-		MP_fontname, MP_fontsize);
+	  MP_fontname, MP_fontsize
+	);
+      }
     }
     fputs("\n\
 color currentcolor; currentcolor=black;\n\
@@ -381,10 +488,15 @@ MP_graphics()
     MP_oldline = -2;
     MP_oldpen = 1.0;
     MP_oldptsize = pointsize;
-    fprintf(gpoutfile, "\nbeginfig(%d);\nw:=%gin;h:=%gin;\n",
+    fprintf(gpoutfile, "\nbeginfig(%d);\nw:=%.3fin;h:=%.3fin;\n",
 	    MP_char_code, MP_xsize, MP_ysize);
-    fprintf(gpoutfile, "a:=w/%d;b:=h/%d;\n", term->xmax, term->ymax);
-    fprintf(gpoutfile, "scalepen 1; ptsize %g;linetype -2;\n", pointsize);
+    /* MetaPost can only handle numbers up to 4096. When MP_DPI
+       is larger than 819, this is exceeded by (term->xmax). So we
+       scale it and all coordinates down by factor of 10.0. And
+       compensate by scaling a and b up.
+    */
+    fprintf(gpoutfile, "a:=w/%.1f;b:=h/%.1f;\n", (term->xmax)/10.0, (term->ymax)/10.0);
+    fprintf(gpoutfile, "scalepen 1; ptsize %.3f;linetype -2;\n", pointsize);
     MP_char_code++;
 }
 
@@ -439,7 +551,8 @@ int pt;
 
     if (pointtype >= MP_POINT_TYPES)
 	pointtype %= MP_POINT_TYPES;
-    fprintf(gpoutfile, "gpdraw(%d,%da,%db);\n", pointtype, x, y);
+/* Change %d to %f, divide x,y by 10 */
+    fprintf(gpoutfile, "gpdraw(%d,%.1fa,%.1fb);\n", pointtype, x/10.0, y/10.0);
 }
 
 TERM_PUBLIC void
@@ -449,7 +562,7 @@ double ps;
     if (MP_oldptsize != ps) {
 	if (MP_inline)
 	    MP_endline();
-	fprintf(gpoutfile, "ptsize %g;\n", ps);
+	fprintf(gpoutfile, "ptsize %.3f;\n", ps);
 	MP_oldptsize = ps;
     }
 }
@@ -462,7 +575,7 @@ double lw;
     if (MP_oldpen != lw) {
 	if (MP_inline)
 	    MP_endline();
-	fprintf(gpoutfile, "scalepen %g;\n", lw);
+	fprintf(gpoutfile, "scalepen %.3f;\n", lw);
 	MP_oldpen = lw;
     }
 }
@@ -483,12 +596,12 @@ unsigned int uy;
 	}
     } else {
 	MP_inline = TRUE;
-	fprintf(gpoutfile, "draw (%da,%db)", MP_posx, MP_posy);
+	fprintf(gpoutfile, "draw (%.1fa,%.1fb)", MP_posx/10.0, MP_posy/10.0);
 	MP_linecount = 2;
     }
     MP_posx = ux;
     MP_posy = uy;
-    fprintf(gpoutfile, "--(%da,%db)", MP_posx, MP_posy);
+    fprintf(gpoutfile, "--(%.1fa,%.1fb)", MP_posx/10.0, MP_posy/10.0);
 }
 
 static void
@@ -508,11 +621,11 @@ TBOOLEAN head;
 {
     MP_move(sx, sy);
     if (head) {
-	fprintf(gpoutfile, "drawarrow (%da,%db)--(%da,%db);\n",
-		sx, sy, ex, ey);
+	fprintf(gpoutfile, "drawarrow (%.1fa,%.1fb)--(%.1fa,%.1fb);\n",
+		sx/10.0, sy/10.0, ex/10.0, ey/10.0);
     } else if ((sx != ex) || (sy != ey)) {
-	fprintf(gpoutfile, "draw (%da,%db)--(%da,%db);\n",
-		sx, sy, ex, ey);
+	fprintf(gpoutfile, "draw (%.1fa,%.1fb)--(%.1fa,%.1fb);\n",
+		sx/10.0, sy/10.0, ex/10.0, ey/10.0);
     }				/* else: arrow with no length and no head = sound of one hand clapping? */
     MP_posx = ex;
     MP_posy = ey;
@@ -532,8 +645,7 @@ char str[];
 	return;
 
     /* F***. why do drivers need to modify string args? */
-    text = gp_alloc(strlen(str)+1, "temp string");
-    strcpy(text,str);
+    text = gp_strdup(str);
 
     if (MP_inline)
 	MP_endline();
@@ -550,25 +662,30 @@ char str[];
 	j = 3;
 	break;
     }
-    if (MP_notex) {
+    if (MP_tex == MP_NO_TEX) {
 	for (i = 0; i < strlen(text); i++)
 	    if (text[i] == '"')
 		text[i] = '\'';	/* Replace " with ' */
 	if (MP_fontchanged) {
 	    fprintf(gpoutfile, "\
-put_text(\"%s\" infontsize(\"%s\",%5.2f), %da, %db, %d, %d);\n",
-		    text, MP_fontname, MP_fontsize, x, y, MP_ang, j);
+put_text(\"%s\" infontsize(\"%s\",%5.2f), %.1fa, %.1fb, %d, %d);\n",
+		    text, MP_fontname, MP_fontsize, x/10.0, y/10.0, MP_ang, j);
 	} else {
-	    fprintf(gpoutfile, "put_text(\"%s\", %da, %db, %d, %d);\n",
-		    text, x, y, MP_ang, j);
+	    fprintf(gpoutfile, "put_text(\"%s\", %.1fa, %.1fb, %d, %d);\n",
+		    text, x/10.0, y/10.0, MP_ang, j);
 	}
     } else if (MP_fontchanged) {
+      if(MP_tex != MP_LATEX) {
 	fprintf(gpoutfile, "\
-put_text( btex \\setfont{%s}{%5.2f} %s etex, %da, %db, %d, %d);\n",
-		MP_fontname, MP_fontsize, text, x, y, MP_ang, j);
+put_text( btex \\setfont{%s}{%5.2f} %s etex, %.1fa, %.1fb, %d, %d);\n",
+		MP_fontname, MP_fontsize, text, x/10.0, y/10.0, MP_ang, j);
+      } else {
+	fprintf(gpoutfile, "put_text( btex %s etex, %.1fa, %.1fb, %d, %d);\n",
+		text, x/10.0, y/10.0, MP_ang, j);
+      }
     } else {
-	fprintf(gpoutfile, "put_text( btex %s etex, %da, %db, %d, %d);\n",
-		text, x, y, MP_ang, j);
+	fprintf(gpoutfile, "put_text( btex %s etex, %.1fa, %.1fb, %d, %d);\n",
+		text, x/10.0, y/10.0, MP_ang, j);
     }
 
     free(text);
@@ -629,8 +746,9 @@ unsigned int x1, y1, wd, ht;
 	MP_endline();
     if (sty <= 0)
 	fprintf(gpoutfile, "\
-fill (%da,%db)--(%da,%db)--(%da,%db)--(%da,%db)--cycle withcolor background;\n",
-		x1, y1, x1 + wd, y1, x1 + wd, y1 + ht, x1, y1 + ht);
+fill (%.1fa,%.1fb)--(%.1fa,%.1fb)--(%.1fa,%.1fb)--(%.1fa,%.1fb)--cycle withcolor background;\n",
+		x1/10.0, y1/10.0, (x1 + wd)/10.0, y1/10.0, (x1 + wd)/10.0, (y1 +
+  ht)/10.0, x1/10.0, (y1 + ht)/10.0);
 }
 
 #endif /* TERM_BODY */
@@ -669,7 +787,8 @@ START_HELP(mp)
 " allowing essentially  any TeX symbols in titles and labels.",
 "",
 " The `mp` terminal is selected with a command of the form",
-"    set term mp {color} {solid} {notex} {mag <magsize>} {\"<name>\"} {<size>}",
+"    set term mp {color} {solid} {notex|tex|latex} {mag <magsize>} {\"<name>\"}",
+"                {<size>}",
 " The option `color` causes lines to be drawn in color (on a printer or display",
 " that supports it), `monochrome` (or nothing) selects black lines.  The option",
 " `solid` draws solid lines, while `dashed` (or nothing) selects lines with",
@@ -681,6 +800,15 @@ START_HELP(mp)
 " labels under this option.  This is intended for use on old plot files or files",
 " that make frequent use of common characters like `$` and `%` that require",
 " special handling in TeX.",
+"",
+"",
+" The option `tex` sets the terminal to output its text for TeX to process.",
+"",
+" The option `latex` sets the terminal to output its text for processing by",
+" LaTeX. This allows things like \\frac for fractions which LaTeX knows about",
+" but TeX does not.  Note that you must set the environment variable TEX to the",
+" name of your LaTeX executable (normally latex) if you use this option. ",
+" Otherwise metapost will try and use TeX to process the text and it won't work.",
 "",
 " Changing font sizes in TeX has no effect on the size of mathematics, and there",
 " is no foolproof way to make such a change, except by globally  setting a",