1/* Hello, Emacs, this is -*-C-*- */ 2 3/* GNUPLOT - metapost.trm */ 4 5/*[ 6 * Copyright 1990 - 1993, 1998, 2004 7 * 8 * Permission to use, copy, and distribute this software and its 9 * documentation for any purpose with or without fee is hereby granted, 10 * provided that the above copyright notice appear in all copies and 11 * that both that copyright notice and this permission notice appear 12 * in supporting documentation. 13 * 14 * Permission to modify the software is granted, but not the right to 15 * distribute the complete modified source code. Modifications are to 16 * be distributed as patches to the released version. Permission to 17 * distribute binaries produced by compiling modified sources is granted, 18 * provided you 19 * 1. distribute the corresponding source modifications from the 20 * released version in the form of a patch file along with the binaries, 21 * 2. add special version identification to distinguish your version 22 * in addition to the base release version number, 23 * 3. provide your name and address as the primary contact for the 24 * support of your modified version, and 25 * 4. retain our contact information in regard to use of the base 26 * software. 27 * Permission to distribute the released version of the source code along 28 * with corresponding source modifications in the form of a patch file is 29 * granted with same provisions 2 through 4 for binary distributions. 30 * 31 * This software is provided "as is" without express or implied warranty 32 * to the extent permitted by applicable law. 33]*/ 34 35/* 1999/04/22 36 * GNUPLOT -- metapost.trm 37 * 38 * This terminal driver supports: 39 * Metapost Commands 40 * 41 * Based on metafont.trm, written by 42 * Pl Hedne 43 * Trondheim, Norway 44 * Pal.Hedne@termo.unit.no; 45 * with improvements by Carsten Steger 46 * 47 * and pstricks.trm, written by 48 * David Kotz and Raymond Toy 49 * 50 * Adapted to metapost by: 51 * Daniel H. Luecking <luecking@comp.uark.edu> and 52 * L Srinivasa Mohan <mohan@chemeng.iisc.ernet.in> 53 */ 54 55#include "driver.h" 56 57#ifdef TERM_REGISTER 58register_term(mp) 59#endif 60 61#ifdef TERM_PROTO 62TERM_PUBLIC void MP_options(void); 63TERM_PUBLIC void MP_init(void); 64TERM_PUBLIC void MP_graphics(void); 65TERM_PUBLIC void MP_text(void); 66TERM_PUBLIC void MP_linetype(int linetype); 67TERM_PUBLIC void MP_move(unsigned int x, unsigned int y); 68TERM_PUBLIC void MP_point(unsigned int x, unsigned int y, int number); 69TERM_PUBLIC void MP_pointsize(double size); 70TERM_PUBLIC void MP_linewidth(double width); 71TERM_PUBLIC void MP_vector(unsigned int ux, unsigned int uy); 72TERM_PUBLIC void MP_arrow(unsigned int sx, unsigned int sy, 73 unsigned int ex, unsigned int ey, 74 int head); 75TERM_PUBLIC void MP_put_text(unsigned int x, unsigned int y, const char str[]); 76TERM_PUBLIC int MP_justify_text(enum JUSTIFY mode); 77TERM_PUBLIC int MP_text_angle(int ang); 78TERM_PUBLIC void MP_reset(void); 79TERM_PUBLIC int MP_set_font(const char *font); 80TERM_PUBLIC void MP_boxfill(int style, unsigned int x1, 81 unsigned int y1, unsigned int width, 82 unsigned int height); 83TERM_PUBLIC int MP_make_palette(t_sm_palette *); 84TERM_PUBLIC void MP_previous_palette(void); 85TERM_PUBLIC void MP_set_color(t_colorspec *); 86TERM_PUBLIC void MP_filled_polygon(int, gpiPoint *); 87TERM_PUBLIC void MP_dashtype(int type, t_dashtype *custom_dash_type); 88 89/* 5 inches wide by 3 inches high (default) */ 90#define MP_XSIZE 5.0 91#define MP_YSIZE 3.0 92 93/* gnuplot units will be one pixel if printing device has this 94 resolution. Too small resolutions (like 300) can give rough 95 appearance to curves when user tries to smooth a curve by choosing 96 high sampling rate. */ 97#define MP_DPI (2400) 98 99#define MP_XMAX (MP_XSIZE*MP_DPI) 100#define MP_YMAX (MP_YSIZE*MP_DPI) 101 102#define MP_HTIC (5*MP_DPI/72) /* nominally 5pt */ 103#define MP_VTIC (5*MP_DPI/72) /* " 5pt */ 104#define MP_HCHAR (MP_DPI*53/10/72) /* " 5.3pt */ 105#define MP_VCHAR (MP_DPI*11/72) /* " 11pt */ 106#endif /* TERM_PROTO */ 107 108#ifndef TERM_PROTO_ONLY 109#ifdef TERM_BODY 110 111static double MP_xsize = MP_XSIZE; 112static double MP_ysize = MP_YSIZE; 113/* static double MP_xmax = MP_XMAX; 114 static double MP_ymax = MP_YMAX; 115 * unused, for now 116 */ 117static int MP_posx; 118static int MP_posy; 119static char MP_fontname[MAX_ID_LEN + 1]; 120static double MP_fontsize; 121static double MP_textmag; 122static enum JUSTIFY MP_justify = LEFT; 123static int MP_ang = 0; 124static int MP_char_code = 0; 125 126/* number of nodes in an output line so far */ 127static int MP_linecount = 1; 128 129/* Number of point types */ 130#define MP_POINT_TYPES 10 131 132/* Number of line types */ 133#define MP_LINE_TYPES 8 134 135/* are we in the middle of a MP path? */ 136static TBOOLEAN MP_inline = FALSE; 137/* colored or dashed lines? */ 138static TBOOLEAN MP_color = FALSE; 139static TBOOLEAN MP_solid = FALSE; 140 141/* compatibility mode*/ 142/* static TBOOLEAN MP_notex = FALSE; */ 143#define MP_NO_TEX 0 144#define MP_TEX 1 145#define MP_LATEX 2 146static int MP_tex = MP_TEX; 147/* add usepackage instructions for PSNFSS ? */ 148#define MP_PSNFSS_NONE 0 149#define MP_PSNFSS_7 1 150#define MP_PSNFSS_8 2 151static int MP_psnfss = MP_PSNFSS_NONE; 152/* should amstex packages be included? */ 153static int MP_amstex = 0; 154/* add a4paper option to documentclass */ 155static int MP_a4paper = 0; 156/* write a prologues line */ 157static int MP_prologues = -1; 158 159/* has color changed? */ 160static int MP_color_changed = 0; 161 162static int MP_dash_changed = 0; 163 164/* has a font change taken place? */ 165static TBOOLEAN MP_fontchanged = FALSE; 166 167/* The old types */ 168static int MP_oldline = -2; 169 170/* The old sizes */ 171static double MP_oldptsize = 1.0; 172static double MP_oldpen = 1.0; 173 174/* terminate any path in progress */ 175static void MP_endline(void); 176 177/* max number of path nodes before a newline */ 178#define MP_LINEMAX 5 179 180enum MP_id { 181 MP_OPT_MONOCHROME, MP_OPT_COLOUR, 182 MP_OPT_SOLID, MP_OPT_DASHED, 183 MP_OPT_NOTEX, MP_OPT_TEX, MP_OPT_LATEX, 184 MP_OPT_A4PAPER, 185 MP_OPT_PSNFSS, MP_OPT_PSNFSS_V7, MP_OPT_NOPSNFSS, 186 MP_OPT_AMSTEX, 187 MP_OPT_FONT, MP_OPT_FONTSIZE, 188 MP_OPT_PROLOGUES, MP_OPT_NOPROLOGUES, 189 MP_OPT_MAGNIFICATION, MP_OPT_OTHER 190}; 191 192static struct gen_table MP_opts[] = { 193 { "mo$nochrome", MP_OPT_MONOCHROME }, 194 { "c$olor", MP_OPT_COLOUR }, 195 { "c$olour", MP_OPT_COLOUR }, 196 { "s$olid", MP_OPT_SOLID }, 197 { "da$shed", MP_OPT_DASHED }, 198 { "n$otex", MP_OPT_NOTEX }, 199 { "t$ex", MP_OPT_TEX }, 200 { "la$tex", MP_OPT_LATEX }, 201 { "a4$paper", MP_OPT_A4PAPER }, 202 { "am$stex", MP_OPT_AMSTEX }, 203 { "ps$nfss", MP_OPT_PSNFSS }, 204 { "psnfss-v$ersion7", MP_OPT_PSNFSS_V7 }, 205 { "nops$nfss", MP_OPT_NOPSNFSS }, 206 { "pro$logues", MP_OPT_PROLOGUES }, 207 { "nopro$logues", MP_OPT_NOPROLOGUES }, 208 { "ma$gnification", MP_OPT_MAGNIFICATION }, 209 { "fo$nt", MP_OPT_FONT }, 210 { NULL, MP_OPT_OTHER } 211}; 212 213TERM_PUBLIC void 214MP_options() 215{ 216 struct value a; 217 218 /* Annoying hack to handle the case of 'set termoption' after */ 219 /* we have already initialized the terminal. */ 220 if (!almost_equals(c_token-1, "termopt$ion")) { 221 MP_color = FALSE; 222 MP_solid = FALSE; 223 MP_tex = MP_TEX; 224 MP_a4paper = 0; 225 MP_amstex = 0; 226 MP_psnfss = MP_PSNFSS_NONE; 227 MP_fontsize = 10.0; 228 MP_textmag = 1.0; 229 MP_prologues = -1; 230 strcpy(MP_fontname, "cmr10"); 231 term->flags |= TERM_IS_LATEX; 232 } 233 234 while (!END_OF_COMMAND) { 235 int option = lookup_table(&MP_opts[0], c_token); 236 switch (option) { 237 case MP_OPT_MONOCHROME: 238 MP_color = FALSE; 239 c_token++; 240 break; 241 case MP_OPT_COLOUR: 242 MP_color = TRUE; 243 c_token++; 244 break; 245 case MP_OPT_SOLID: 246 MP_solid = TRUE; 247 c_token++; 248 break; 249 case MP_OPT_DASHED: 250 MP_solid = FALSE; 251 c_token++; 252 break; 253 case MP_OPT_NOTEX: 254 MP_tex = MP_NO_TEX; 255 strcpy(MP_fontname, "pcrr8r"); 256 term->flags &= ~TERM_IS_LATEX; 257 c_token++; 258 break; 259 case MP_OPT_TEX: 260 MP_tex = MP_TEX; 261 c_token++; 262 break; 263 case MP_OPT_LATEX: 264 MP_tex = MP_LATEX; 265 c_token++; 266 break; 267 case MP_OPT_AMSTEX: 268 MP_tex = MP_LATEX; /* only makes sense when using LaTeX */ 269 MP_amstex = 1; 270 c_token++; 271 break; 272 case MP_OPT_A4PAPER: 273 MP_tex = MP_LATEX; /* only makes sense when using LaTeX */ 274 MP_a4paper = 1; 275 c_token++; 276 break; 277 case MP_OPT_PSNFSS: 278 MP_tex = MP_LATEX; /* only makes sense when using LaTeX */ 279 MP_psnfss = MP_PSNFSS_8; 280 c_token++; 281 break; 282 case MP_OPT_PSNFSS_V7: 283 MP_tex = MP_LATEX; /* only makes sense when using LaTeX */ 284 MP_psnfss = MP_PSNFSS_7; 285 c_token++; 286 break; 287 case MP_OPT_NOPSNFSS: 288 MP_psnfss = MP_PSNFSS_NONE; 289 c_token++; 290 break; 291 case MP_OPT_PROLOGUES: 292 c_token++; 293 if (!(END_OF_COMMAND)) { 294 int dummy_for_prologues; 295 296 if (sscanf(gp_input_line + token[c_token].start_index, 297 "%d", &dummy_for_prologues) == 1) { 298 MP_prologues = dummy_for_prologues; 299 } 300 c_token++; 301 } 302 break; 303 case MP_OPT_NOPROLOGUES: 304 MP_prologues = -1; 305 c_token++; 306 break; 307 case MP_OPT_MAGNIFICATION: 308 c_token++; 309 if (!END_OF_COMMAND) /* global text scaling */ 310 MP_textmag = (double) real(const_express(&a)); 311 /* c_token++; */ /* Needed ??? */ 312 break; 313 case MP_OPT_FONT: 314 c_token++; 315 case MP_OPT_OTHER: 316 default: 317 { 318 char *s; 319 if ((s = try_to_get_string())) { 320 int sep = strcspn(s,","); 321 if (0 < sep && sep < sizeof(MP_fontname)) { 322 strncpy(MP_fontname, s, sizeof(MP_fontname)); 323 MP_fontname[sep] = '\0'; 324 } 325 if (s[sep] == ',') 326 sscanf(&s[sep+1],"%lf",&MP_fontsize); 327 free(s); 328 } else if (option == MP_OPT_FONT) { 329 int_error(c_token,"expecting font name"); 330 } else if (!END_OF_COMMAND) { /*font size */ 331 MP_fontsize = (double) real(const_express(&a)); 332 c_token++; 333 } 334 break; 335 } 336 337 } 338 } 339 340 /* minimal error recovery: */ 341 if (MP_fontsize < 5.0) 342 MP_fontsize = 5.0; 343 if (MP_fontsize > 99.99) 344 MP_fontsize = 99.99; 345 346 term->v_char = (unsigned int) (MP_DPI * MP_fontsize * MP_textmag * 11 / 720); 347 if (MP_tex == MP_NO_TEX) { /* Courier is a little wider than cmtt */ 348 term->h_char = (unsigned int) (MP_DPI * MP_fontsize * MP_textmag * 6.0 / 720 + 0.5); 349 } else { 350 term->h_char = (unsigned int) (MP_DPI * MP_fontsize * MP_textmag * 5.3 / 720 + 0.5); 351 } 352 353 if (MP_psnfss == MP_PSNFSS_NONE) { /* using the normal font scheme */ 354 sprintf(term_options, 355 "%s %s %stex%s%s mag %.3f font \"%s,%.2f\" %sprologues(%d)", 356 MP_color ? "color" : "monochrome", 357 MP_solid ? "solid" : "dashed", 358 (MP_tex == MP_NO_TEX) ? "no" : (MP_tex == MP_LATEX) ? "la" : "", 359 MP_a4paper ? " a4paper" : "", 360 MP_amstex ? " amstex" : "", 361 MP_textmag, 362 MP_fontname, MP_fontsize, 363 (MP_prologues > -1) ? "" : "no", MP_prologues ); 364 } else { /* using postscript fonts */ 365 sprintf(term_options, 366 "%s %s %stex%s%s mag %.3f %s %sprologues(%d)", 367 MP_color ? "color" : "monochrome", 368 MP_solid ? "solid" : "dashed", 369 (MP_tex == MP_NO_TEX) ? "no" : (MP_tex == MP_LATEX) ? "la" : "", 370 MP_a4paper ? " a4paper" : "", 371 MP_amstex ? " amstex" : "", 372 MP_textmag, 373 (MP_psnfss == MP_PSNFSS_7) ? "psnsfss(v7)" : "psnsfss", 374 (MP_prologues > -1) ? "" : "no", MP_prologues ); 375 }; 376} 377 378TERM_PUBLIC void 379MP_init() 380{ 381 time_t now; 382 time(&now); 383 MP_posx = MP_posy = 0; 384 fprintf(gpoutfile, "%%GNUPLOT Metapost output: %s\n", asctime(localtime(&now))); 385 if (MP_prologues > -1) { 386 fprintf(gpoutfile, "prologues:=%d;\n", MP_prologues); 387 } 388 if (MP_tex == MP_LATEX) { 389 fputs("\n\ 390%% Add \\documentclass and \\begin{dcoument} for latex\n\ 391%% NB you should set the environment variable TEX to the name of your\n\ 392%% latex executable (normally latex) inorder for metapost to work\n\ 393%% or run\n\ 394%% mpost --tex=latex ...\n\ 395\n\ 396% BEGPRE\n\ 397verbatimtex\n", gpoutfile); 398 if (MP_a4paper) { 399 fputs("\\documentclass[a4paper]{article}\n", gpoutfile); 400 } else { 401 fputs("\\documentclass{article}\n", gpoutfile); 402 } 403 switch (MP_psnfss) { 404 case MP_PSNFSS_7:{ 405 fputs("\\usepackage[latin1]{inputenc}\n\ 406\\usepackage[T1]{fontenc}\n\ 407\\usepackage{times,mathptmx}\n\ 408\\usepackage{helvet}\n\ 409\\usepackage{courier}\n", gpoutfile); 410 } 411 break; 412 case MP_PSNFSS_8:{ 413 fputs("\\usepackage[latin1]{inputenc}\n\ 414\\usepackage[T1]{fontenc}\n\ 415\\usepackage{textcomp}\n\ 416\\usepackage{mathptmx}\n\ 417\\usepackage[scaled=.92]{helvet}\n\ 418\\usepackage{courier}\n\ 419\\usepackage{latexsym}\n", gpoutfile); 420 } 421 break; 422 } 423 if (MP_amstex) { 424 fputs("\\usepackage[intlimits]{amsmath}\n\ 425\\usepackage{amsfonts}\n", gpoutfile); 426 }; 427 fputs("\\begin{document}\n\ 428etex\n% ENDPRE\n", gpoutfile); 429 } 430 431 fputs("\n\ 432warningcheck:=0;\n\ 433defaultmpt:=mpt:=4;\n\ 434th:=.6;\n\ 435%% Have nice sharp joins on our lines\n\ 436linecap:=butt;\n\ 437linejoin:=mitered;\n\ 438\n\ 439def scalepen expr n = pickup pencircle scaled (n*th) enddef;\n\ 440def ptsize expr n = mpt:=n*defaultmpt enddef;\n\ 441\n", gpoutfile); 442 443 fprintf(gpoutfile, "\ntextmag:=%6.3f;\n", MP_textmag); 444 445 fputs("\ 446vardef makepic(expr str) =\n\ 447 if picture str : str scaled textmag\n\ 448 % otherwise a string\n\ 449 else: str infont defaultfont scaled (defaultscale*textmag)\n\ 450 fi\n\ 451enddef;\n\ 452\n\ 453def infontsize(expr str, size) =\n\ 454 infont str scaled (size / fontsize str)\n\ 455enddef;\n", gpoutfile); 456 457 if (MP_tex == MP_NO_TEX) { 458 fprintf(gpoutfile, "\n\ 459defaultfont:= \"%s\";\n\ 460defaultscale := %6.3f/fontsize defaultfont;\n", MP_fontname, MP_fontsize); 461 } else { 462 if (MP_tex != MP_LATEX) { 463 fputs("\n\ 464%font changes\n\ 465verbatimtex\n\ 466\\def\\setfont#1#2{%.\n\ 467 \\font\\gpfont=#1 at #2pt\n\ 468\\gpfont}\n", gpoutfile); 469 fprintf(gpoutfile, "\\setfont{%s}{%5.2f}\netex\n", 470 MP_fontname, MP_fontsize); 471 } 472 } 473 fputs("\n\ 474color currentcolor; currentcolor:=black;\n\ 475picture currentdash; currentdash:=dashpattern(on 1);\n\ 476color fillcolor;\n\ 477boolean colorlines,dashedlines;\n", gpoutfile); 478 if (MP_color) { 479 fputs("colorlines:=true;\n", gpoutfile); 480 } else { 481 fputs("colorlines:=false;\n", gpoutfile); 482 } 483 if (MP_solid) { 484 fputs("dashedlines:=false;\n", gpoutfile); 485 } else { 486 fputs("dashedlines:=true;\n", gpoutfile); 487 } 488 fputs("\n\ 489def _wc = withpen currentpen withcolor currentcolor dashed currentdash enddef;\n\ 490def _ac = addto currentpicture enddef;\n\ 491def _sms = scaled mpt shifted enddef;\n\ 492% drawing point-types\n\ 493def gpdraw (expr n, x, y) =\n\ 494 if n<0: _ac contour fullcircle _sms (x,y)\n\ 495 elseif (n=1) or (n=3):\n\ 496 _ac doublepath ptpath[n] _sms (x,y) _wc;\n\ 497 _ac doublepath ptpath[n] rotated 90 _sms (x,y) _wc\n\ 498 elseif n<6: _ac doublepath ptpath[n] _sms (x,y) _wc\n\ 499 else: _ac contour ptpath[n] _sms (x,y) _wc\n\ 500 fi\n\ 501enddef;\n\ 502\n\ 503% the point shapes\n\ 504path ptpath[];\n\ 505%diamond\n\ 506ptpath0 = ptpath6 = (-1/2,0)--(0,-1/2)--(1/2,0)--(0,1/2)--cycle;\n\ 507% plus sign\n\ 508ptpath1 = (-1/2,0)--(1/2,0);\n\ 509% square\n\ 510ptpath2 = ptpath7 = (-1/2,-1/2)--(1/2,-1/2)--(1/2,1/2)--(-1/2,1/2)--cycle;\n\ 511% cross\n\ 512ptpath3 := (-1/2,-1/2)--(1/2,1/2);\n\ 513% circle:\n\ 514ptpath4 = ptpath8:= fullcircle;\n\ 515% triangle\n\ 516ptpath5 = ptpath9 := (0,1/2)--(-1/2,-1/2)--(1/2,-1/2)--cycle;\n\ 517\n\ 518def linetype expr n =\n\ 519 if n > -3 :\n\ 520 currentcolor:= if colorlines : col[n] else: black fi;\n\ 521 fi\n\ 522 currentdash:= if dashedlines : lt[n] else: dashpattern(on 1) fi;\n\ 523 if n = -1 :\n\ 524 drawoptions(withcolor currentcolor withpen (currentpen scaled .5));\n\ 525 else :\n\ 526 drawoptions(_wc);\n\ 527 fi\n\ 528enddef;\n\ 529\n\ 530% dash patterns\n\ 531picture lt[];\n\ 532lt[-3]:=dashpattern(off 1 on 0);\n\ 533lt[-2]:=lt[-1]:=lt0:=dashpattern(on 1);\n\ 534lt1=dashpattern(on 2 off 2); % dashes\n\ 535lt2=dashpattern(on 2 off 2 on 0.2 off 2); %dash-dot\n\ 536lt3=lt1 scaled 1.414;\n\ 537lt4=lt2 scaled 1.414;\n\ 538lt5=lt1 scaled 2;\n\ 539lt6:=lt2 scaled 2;\n\ 540lt7=dashpattern(on 0.2 off 2); %dots\n\ 541\n\ 542color col[],cyan, magenta, yellow;\n\ 543cyan=blue+green; magenta=red+blue;yellow=green+red;\n\ 544col[-2]:=col[-1]:=col0:=black;\n\ 545col1:=red;\n\ 546col2:=(.2,.2,1); %blue\n\ 547col3:=(1,.66,0); %orange\n\ 548col4:=.85*green;\n\ 549col5:=.9*magenta;\n\ 550col6:=0.85*cyan;\n\ 551col7:=.85*yellow;\n\ 552\n\ 553%placing text\n\ 554picture GPtext;\n\ 555def put_text(expr pic, x, y, r, j) =\n\ 556 GPtext:=makepic(pic);\n\ 557 GPtext:=GPtext shifted\n\ 558 if j = 1: (-(ulcorner GPtext + llcorner GPtext)/2)\n\ 559 elseif j = 2: (-center GPtext)\n\ 560 else: (-(urcorner GPtext + lrcorner GPtext)/2)\n\ 561 fi\n\ 562 rotated r;\n\ 563 addto currentpicture also GPtext shifted (x,y)\n\ 564enddef;\n", gpoutfile); 565} 566 567TERM_PUBLIC void 568MP_graphics() 569{ 570 /* initialize "remembered" drawing parameters */ 571 MP_oldline = -2; 572 MP_oldpen = 1.0; 573 MP_oldptsize = pointsize; 574 fprintf(gpoutfile, "\nbeginfig(%d);\nw:=%.3fin;h:=%.3fin;\n", 575 MP_char_code, MP_xsize, MP_ysize); 576 /* MetaPost can only handle numbers up to 4096. When MP_DPI 577 * is larger than 819, this is exceeded by (term->xmax). So we 578 * scale it and all coordinates down by factor of 10.0. And 579 * compensate by scaling a and b up. 580 */ 581 fprintf(gpoutfile, "a:=w/%.1f;b:=h/%.1f;\n", 582 (term->xmax) / 10.0, (term->ymax) / 10.0); 583 fprintf(gpoutfile, "scalepen 1; ptsize %.3f;linetype -2;\n", pointsize); 584 MP_char_code++; 585 /* reset MP_color_changed */ 586 MP_color_changed = 0; 587 588 MP_dash_changed = 0; 589} 590 591TERM_PUBLIC void 592MP_text() 593{ 594 if (MP_inline) 595 MP_endline(); 596 fputs("endfig;\n", gpoutfile); 597} 598 599TERM_PUBLIC void 600MP_linetype(int lt) 601{ 602 int linetype = lt; 603 604 if (linetype >= MP_LINE_TYPES) 605 linetype %= MP_LINE_TYPES; 606 if (MP_inline) 607 MP_endline(); 608 /* reset the color in case it has been changed in MP_set_color() */ 609 if ((MP_color_changed) || (MP_dash_changed)) { 610 MP_oldline = linetype + 1; 611 MP_color_changed = 0; 612 MP_dash_changed = 0; 613 } 614 if (MP_oldline != linetype) { 615 fprintf(gpoutfile, "linetype %d;\n", linetype); 616 MP_oldline = linetype; 617 } 618} 619 620TERM_PUBLIC void 621MP_move(unsigned int x, unsigned int y) 622{ 623 if ((x != MP_posx) || (y != MP_posy)) { 624 if (MP_inline) 625 MP_endline(); 626 MP_posx = x; 627 MP_posy = y; 628 } /* else we seem to be there already */ 629} 630 631TERM_PUBLIC void 632MP_point(unsigned int x, unsigned int y, int pt) 633{ 634 int pointtype = pt; 635 if (MP_inline) 636 MP_endline(); 637 638 /* Print the shape defined by 'number'; number < 0 means 639 to use a dot, otherwise one of the defined points. */ 640 641 if (pointtype >= MP_POINT_TYPES) 642 pointtype %= MP_POINT_TYPES; 643/* Change %d to %f, divide x,y by 10 */ 644 fprintf(gpoutfile, "gpdraw(%d,%.1fa,%.1fb);\n", pointtype, x / 10.0, y / 10.0); 645} 646 647TERM_PUBLIC void 648MP_pointsize(double ps) 649{ 650 if (ps < 0) 651 ps = 1; 652 if (MP_oldptsize != ps) { 653 if (MP_inline) 654 MP_endline(); 655 fprintf(gpoutfile, "ptsize %.3f;\n", ps); 656 MP_oldptsize = ps; 657 } 658} 659 660 661TERM_PUBLIC void 662MP_linewidth(double lw) 663{ 664 if (MP_oldpen != lw) { 665 if (MP_inline) 666 MP_endline(); 667 fprintf(gpoutfile, "scalepen %.3f;\n", lw); 668 MP_oldpen = lw; 669 } 670} 671 672 673TERM_PUBLIC void 674MP_vector(unsigned int ux, unsigned int uy) 675{ 676 if ((ux == MP_posx) && (uy == MP_posy)) 677 return; /* Zero length line */ 678 679 if (MP_inline) { 680 if (MP_linecount++ >= MP_LINEMAX) { 681 fputs("\n", gpoutfile); 682 MP_linecount = 1; 683 } 684 } else { 685 MP_inline = TRUE; 686 fprintf(gpoutfile, "draw (%.1fa,%.1fb)", MP_posx / 10.0, MP_posy / 10.0); 687 MP_linecount = 2; 688 } 689 MP_posx = ux; 690 MP_posy = uy; 691 fprintf(gpoutfile, "--(%.1fa,%.1fb)", MP_posx / 10.0, MP_posy / 10.0); 692} 693 694static void 695MP_endline() 696{ 697 MP_inline = FALSE; 698 fprintf(gpoutfile, ";\n"); 699} 700 701TERM_PUBLIC void 702MP_arrow(unsigned int sx, unsigned int sy, unsigned int ex, unsigned int ey, int head) 703{ 704 MP_move(sx, sy); 705 706 if ((head & HEADS_ONLY)) 707 fprintf(gpoutfile, "currentdash:=lt[%d];\n", LT_NODRAW); 708 if ((head & BOTH_HEADS) == BOTH_HEADS) { 709 fprintf(gpoutfile, "%s (%.1fa,%.1fb)--(%.1fa,%.1fb);\n", 710 "drawdblarrow", 711 sx / 10.0, sy / 10.0, ex / 10.0, ey / 10.0); 712 } else if ((head & END_HEAD)) { 713 fprintf(gpoutfile, "%s (%.1fa,%.1fb)--(%.1fa,%.1fb);\n", 714 "drawarrow", 715 sx / 10.0, sy / 10.0, ex / 10.0, ey / 10.0); 716 } else if ((head & BACKHEAD)) { 717 fprintf(gpoutfile, "%s (%.1fa,%.1fb)--(%.1fa,%.1fb);\n", 718 "drawarrow", 719 ex / 10.0, ey / 10.0, sx / 10.0, sy / 10.0); 720 } else if (!(head & HEADS_ONLY) && ((sx != ex) || (sy != ey))) { 721 fprintf(gpoutfile, "draw (%.1fa,%.1fb)--(%.1fa,%.1fb);\n", 722 sx / 10.0, sy / 10.0, ex / 10.0, ey / 10.0); 723 } 724 if ((head & HEADS_ONLY)) 725 fprintf(gpoutfile, "currentdash:=lt[%d];\n", MP_oldline); 726 727 MP_posx = ex; 728 MP_posy = ey; 729} 730 731TERM_PUBLIC void 732MP_put_text(unsigned int x, unsigned int y, const char str[]) 733{ 734 int i, j = 0; 735 char *text; 736 737 /* ignore empty strings */ 738 if (!str || !*str) 739 return; 740 741 text = gp_strdup(str); 742 743 if (MP_inline) 744 MP_endline(); 745 746 747 switch (MP_justify) { 748 case LEFT: 749 j = 1; 750 break; 751 case CENTRE: 752 j = 2; 753 break; 754 case RIGHT: 755 j = 3; 756 break; 757 } 758 if (MP_tex == MP_NO_TEX) { 759 for (i = 0; i < strlen(text); i++) 760 if (text[i] == '"') 761 text[i] = '\''; /* Replace " with ' */ 762 if (MP_fontchanged) { 763 fprintf(gpoutfile, "\ 764put_text(\"%s\" infontsize(\"%s\",%5.2f), %.1fa, %.1fb, %d, %d);\n", 765 text, MP_fontname, MP_fontsize, 766 x / 10.0, y / 10.0, MP_ang, j); 767 } else { 768 fprintf(gpoutfile, "put_text(\"%s\", %.1fa, %.1fb, %d, %d);\n", 769 text, x / 10.0, y / 10.0, MP_ang, j); 770 } 771 } else if (MP_fontchanged) { 772 if (MP_tex != MP_LATEX) { 773 fprintf(gpoutfile, "\ 774put_text( btex \\setfont{%s}{%5.2f} %s etex, %.1fa, %.1fb, %d, %d);\n", 775 MP_fontname, MP_fontsize, text, 776 x / 10.0, y / 10.0, MP_ang, j); 777 } else { 778 fprintf(gpoutfile, "put_text( btex %s etex, %.1fa, %.1fb, %d, %d);\n", 779 text, x / 10.0, y / 10.0, MP_ang, j); 780 } 781 } else { 782 fprintf(gpoutfile, "put_text( btex %s etex, %.1fa, %.1fb, %d, %d);\n", 783 text, x / 10.0, y / 10.0, MP_ang, j); 784 } 785 786 free(text); 787} 788 789TERM_PUBLIC int 790MP_justify_text(enum JUSTIFY mode) 791{ 792 MP_justify = mode; 793 return (TRUE); 794} 795 796TERM_PUBLIC int 797MP_text_angle(int ang) 798{ 799 /* Metapost code does the conversion */ 800 MP_ang = ang; 801 return (TRUE); 802} 803 804TERM_PUBLIC int 805MP_set_font(const char *font) 806{ 807 if (*font) { 808 size_t sep = strcspn(font, ","); 809 if (sep < sizeof(MP_fontname)) 810 strncpy(MP_fontname, font, sizeof(MP_fontname)); 811 sscanf(&(font[sep + 1]), "%lf", &MP_fontsize); 812 if (MP_fontsize < 5) 813 MP_fontsize = 5.0; 814 if (MP_fontsize >= 100) 815 MP_fontsize = 99.99; 816 /* */ 817 MP_fontchanged = TRUE; 818 } else { 819 MP_fontchanged = FALSE; 820 } 821 return TRUE; 822} 823 824 825TERM_PUBLIC void 826MP_reset() 827{ 828 if (MP_tex == MP_LATEX) { 829 fputs("% BEGPOST\n",gpoutfile); 830 fputs("verbatimtex\n",gpoutfile); 831 fputs(" \\end{document}\n",gpoutfile); 832 fputs("etex\n",gpoutfile); 833 fputs("% ENDPOST\n",gpoutfile); 834 }; 835 fputs("end.\n", gpoutfile); 836} 837 838TERM_PUBLIC void 839MP_boxfill( 840 int style, 841 unsigned int x1, unsigned int y1, 842 unsigned int wd, unsigned int ht) 843{ 844 845 /* fillpar: 846 * - solid : 0 - 100% intensity 847 * - pattern : 0 - n pattern number 848 */ 849 int fillpar = style >> 4; 850 style &= 0xf; 851 852 if (MP_inline) 853 MP_endline(); 854 855 switch (style) { 856 857 case FS_EMPTY: /* fill with background color */ 858 fprintf(gpoutfile, "\ 859fill (%.1fa,%.1fb)--(%.1fa,%.1fb)--(%.1fa,%.1fb)--(%.1fa,%.1fb)--cycle withcolor background;\n", 860 x1 / 10.0, y1 / 10.0, (x1 + wd) / 10.0, y1 / 10.0, 861 (x1 + wd) / 10.0, (y1 + ht) / 10.0, x1 / 10.0, 862 (y1 + ht) / 10.0); 863 break; 864 865 case FS_PATTERN: /* pattern fill */ 866 case FS_TRANSPARENT_PATTERN: 867 /* FIXME: not yet implemented, dummy it up as fill density */ 868 fillpar *= 12; 869 870 default: 871 case FS_SOLID: /* solid fill */ 872 case FS_TRANSPARENT_SOLID: 873 if (fillpar < 100) { 874 double density = (100-fillpar) * 0.01; 875 fprintf(gpoutfile,"fillcolor:=currentcolor*%.2f+background*%.2f;\n", 876 1.0-density, density); 877 MP_color_changed = 1; 878 } else 879 fprintf(gpoutfile,"fillcolor:=currentcolor;\n"); 880 fprintf(gpoutfile, "\ 881fill (%.1fa,%.1fb)--(%.1fa,%.1fb)--(%.1fa,%.1fb)--(%.1fa,%.1fb)--cycle withpen (pencircle scaled 0pt) withcolor fillcolor;\n", 882 x1 / 10.0, y1 / 10.0, (x1 + wd) / 10.0, y1 / 10.0, 883 (x1 + wd) / 10.0, (y1 + ht) / 10.0, x1 / 10.0, 884 (y1 + ht) / 10.0); 885 break; 886 887 } 888 889} 890 891TERM_PUBLIC int 892MP_make_palette(t_sm_palette *palette) 893{ 894 /* metapost can do continuous number of colours */ 895 return 0; 896} 897 898 899TERM_PUBLIC void 900MP_set_color(t_colorspec *colorspec) 901{ 902 double gray = colorspec->value; 903 rgb_color color; 904 905 /* remember that we changed the color, needed to reset color in MP_linetype()*/ 906 /* FIXME: only set this if the color really did change (compare to previous color) */ 907 MP_color_changed = 1; 908 909 if (MP_inline) 910 MP_endline(); 911 912 if (!MP_color) { /* gray mode */ 913 if (gray < 1e-3) gray = 0; 914 fprintf(gpoutfile, "currentcolor:=%.3gwhite;\n", gray); 915 } else { /* color mode */ 916 if (colorspec->type == TC_LT) { 917 int linecolor = colorspec->lt; 918 if (linecolor >= MP_LINE_TYPES) 919 linecolor %= MP_LINE_TYPES; 920 if (linecolor == -1) 921 fprintf(gpoutfile, "currentcolor:=black;\n"); 922 else if (linecolor >= 0) 923 fprintf(gpoutfile, "currentcolor:=col%d;\n",linecolor); 924 } 925 if (colorspec->type == TC_FRAC) { 926 if (sm_palette.colors != 0) /* finite nb of colors explicitly requested */ 927 gray = (gray >= ((double)(sm_palette.colors-1)) / sm_palette.colors) ? 928 1 : floor(gray * sm_palette.colors) / sm_palette.colors; 929 rgb1_from_gray( gray, &color ); 930 } else if (colorspec->type == TC_RGB) { 931 color.r = (double)((colorspec->lt >> 16 ) & 255) / 255.; 932 color.g = (double)((colorspec->lt >> 8 ) & 255) / 255.; 933 color.b = (double)(colorspec->lt & 255) / 255.; 934 } else 935 return; 936 937 if (color.r < 1e-4) color.r = 0; 938 if (color.g < 1e-4) color.g = 0; 939 if (color.b < 1e-4) color.b = 0; 940 fprintf(gpoutfile, "currentcolor:=%.4g*red+%.4g*green+%.4g*blue;\n", 941 color.r, color.g, color.b); 942 } 943 return; 944} 945 946TERM_PUBLIC void 947MP_filled_polygon(int points, gpiPoint *corners) 948{ 949 int i; 950 int fillpar = corners->style >> 4; 951 int style = corners->style & 0xf; 952 953 if (MP_inline) 954 MP_endline(); 955 956 switch (style) { 957 case FS_EMPTY: /* fill with background color */ 958 fprintf(gpoutfile,"fillcolor:=background;\n"); 959 break; 960 case FS_PATTERN: /* pattern fill implemented as partial density */ 961 case FS_TRANSPARENT_PATTERN: 962 fillpar *= 12; 963 case FS_SOLID: /* solid fill */ 964 case FS_TRANSPARENT_SOLID: 965 if (fillpar < 100) { 966 double density = (100-fillpar) * 0.01; 967 fprintf(gpoutfile,"fillcolor:=currentcolor*%.2f+background*%.2f;\n", 968 1.0-density, density); 969 } else { 970 fprintf(gpoutfile,"fillcolor:=currentcolor;\n"); 971 } 972 default: 973 break; 974 } 975 976 fprintf(gpoutfile, "fill "); 977 for (i = 0; i < points; i++) 978 fprintf(gpoutfile, "(%.1fa,%.1fb)%s", 979 corners[i].x / 10.0, corners[i].y / 10.0, 980 (i < points - 1 && (i + 1) % MP_LINEMAX == 0) ? "\n--" : "--"); 981 fprintf(gpoutfile, "cycle withcolor fillcolor;\n"); 982} 983 984TERM_PUBLIC void 985MP_dashtype (int type, t_dashtype *custom_dash_type) 986{ 987 switch (type) { 988 case DASHTYPE_SOLID: 989 fprintf(gpoutfile, "%%MP_dashtype%% DASHTYPE_SOLID\n"); 990 break; 991 case DASHTYPE_AXIS: 992 fprintf(gpoutfile, "%%MP_dashtype%% DASHTYPE_AXIS\n"); 993 /* Currently handled elsewhere? */ 994 break; 995 case DASHTYPE_CUSTOM: 996 fprintf(gpoutfile, "%%MP_dashtype%% DASHTYPE_CUSTOM: "); 997 if (custom_dash_type) { 998 int i; 999 if (custom_dash_type->dstring[0] != '\0') 1000 fprintf(gpoutfile, "\"%s\"; ", custom_dash_type->dstring); 1001 fprintf(gpoutfile, "["); 1002 for (i = 0; i < DASHPATTERN_LENGTH && custom_dash_type->pattern[i] > 0; i++) 1003 fprintf(gpoutfile, i ? ", %.2f" : "%.2f", custom_dash_type->pattern[i]); 1004 fprintf(gpoutfile, "]"); 1005 fprintf(gpoutfile, "\n"); 1006 1007 MP_dash_changed = 1; 1008 fprintf(gpoutfile, "currentdash:=dashpattern("); 1009 for (i = 0; i < DASHPATTERN_LENGTH && custom_dash_type->pattern[i] > 0; i++) 1010 fprintf(gpoutfile, "%s %.2f ", i%2?"off":"on", custom_dash_type->pattern[i]); 1011 fprintf(gpoutfile, ");\n"); 1012 } else { 1013 fprintf(gpoutfile, "\n"); 1014 } 1015 break; 1016 default: 1017 fprintf(gpoutfile, "%%MP_dashtype%% type = %i\n", type); 1018 if (type>0) 1019 MP_linetype(type); 1020 break; 1021 } 1022} 1023 1024TERM_PUBLIC void 1025MP_previous_palette() 1026{ 1027 return; 1028} 1029 1030#endif /* TERM_BODY */ 1031 1032#ifdef TERM_TABLE 1033 1034TERM_TABLE_START(mp_driver) 1035 "mp", "MetaPost plotting standard", 1036 MP_XMAX, MP_YMAX, MP_VCHAR, MP_HCHAR, 1037 MP_VTIC, MP_HTIC, MP_options, MP_init, MP_reset, 1038 MP_text, null_scale, MP_graphics, MP_move, MP_vector, 1039 MP_linetype, MP_put_text, MP_text_angle, 1040 MP_justify_text, MP_point, MP_arrow, MP_set_font, MP_pointsize, 1041 TERM_BINARY|TERM_CAN_CLIP|TERM_CAN_DASH|TERM_IS_LATEX, /*flags*/ 1042 0, 0, MP_boxfill, MP_linewidth 1043#ifdef USE_MOUSE 1044 , 0, 0, 0, 0, 0 /* no mouse support for metapost */ 1045#endif 1046 , MP_make_palette, 1047 MP_previous_palette, /* write grestore */ 1048 MP_set_color, 1049 MP_filled_polygon, 1050 .dashtype = MP_dashtype 1051TERM_TABLE_END(mp_driver) 1052#undef LAST_TERM 1053#define LAST_TERM mp_driver 1054 1055#endif /* TERM_TABLE */ 1056#endif /* TERM_PROTO_ONLY */ 1057 1058#ifdef TERM_HELP 1059START_HELP(mp) 1060"1 mp", 1061"?commands set terminal mpost", 1062"?set terminal mp", 1063"?set term mp", 1064"?terminal mp", 1065"?term mp", 1066"?mp", 1067"?metapost", 1068"", 1069" The `mp` driver produces output intended to be input to the Metapost program.", 1070" Running Metapost on the file creates EPS files containing the plots. By", 1071" default, Metapost passes all text through TeX. This has the advantage of", 1072" allowing essentially any TeX symbols in titles and labels.", 1073"", 1074" Syntax:", 1075" set term mp {color | colour | monochrome}", 1076" {solid | dashed}", 1077" {notex | tex | latex}", 1078" {magnification <magsize>}", 1079" {psnfss | psnfss-version7 | nopsnfss}", 1080" {prologues <value>}", 1081" {a4paper}", 1082" {amstex}", 1083" {\"<fontname> {,<fontsize>}\"} ", 1084"", 1085" The option `color` causes lines to be drawn in color (on a printer or display", 1086" that supports it), `monochrome` (or nothing) selects black lines. The option", 1087" `solid` draws solid lines, while `dashed` (or nothing) selects lines with", 1088" different patterns of dashes. If `solid` is selected but `color` is not,", 1089" nearly all lines will be identical. This may occasionally be useful, so it is", 1090" allowed.", 1091"", 1092" The option `notex` bypasses TeX entirely, therefore no TeX code can be used in", 1093" labels under this option. This is intended for use on old plot files or files", 1094" that make frequent use of common characters like `$` and `%` that require", 1095" special handling in TeX.", 1096"", 1097" The option `tex` sets the terminal to output its text for TeX to process.", 1098"", 1099" The option `latex` sets the terminal to output its text for processing by", 1100" LaTeX. This allows things like \\frac for fractions which LaTeX knows about", 1101" but TeX does not. Note that you must set the environment variable TEX to the", 1102" name of your LaTeX executable (normally latex) if you use this option or use", 1103" `mpost --tex=<name of LaTeX executable> ...`. Otherwise metapost will try and", 1104" use TeX to process the text and it won't work.", 1105"", 1106" Changing font sizes in TeX has no effect on the size of mathematics, and there", 1107" is no foolproof way to make such a change, except by globally setting a", 1108" magnification factor. This is the purpose of the `magnification` option. It", 1109" must be followed by a scaling factor. All text (NOT the graphs) will be scaled", 1110" by this factor. Use this if you have math that you want at some size other", 1111" than the default 10pt. Unfortunately, all math will be the same size, but see", 1112" the discussion below on editing the MP output. `mag` will also work under", 1113" `notex` but there seems no point in using it as the font size option (below)", 1114" works as well.", 1115"", 1116" The option `psnfss` uses postscript fonts in combination with LaTeX. Since", 1117" this option only makes sense, if LaTeX is being used, the `latex` option is selected", 1118" automatically. This option includes the following packages for LaTeX:", 1119" inputenc(latin1), fontenc(T1), mathptmx, helvet(scaled=09.2), courier, latexsym ", 1120" and textcomp.", 1121"", 1122" The option `psnfss-version7` uses also postscript fonts in LaTeX (option `latex`", 1123" is also automatically selected), but uses the following packages with LaTeX:", 1124" inputenc(latin1), fontenc(T1), times, mathptmx, helvet and courier.", 1125"", 1126" The option `nopsnfss` is the default and uses the standard font (cmr10 if not", 1127" otherwise specified).", 1128"", 1129" The option `prologues` takes a value as an additional argument and adds the line", 1130" `prologues:=<value>` to the metapost file. If a value of `2` is specified metapost", 1131" uses postscript fonts to generate the eps-file, so that the result can be viewed", 1132" using e.g. ghostscript. Normally the output of metapost uses TeX fonts and therefore", 1133" has to be included in a (La)TeX file before you can look at it.", 1134"", 1135" The option `noprologues` is the default. No additional line specifying the prologue", 1136" will be added.", 1137"", 1138" The option `a4paper` adds a `[a4paper]` to the documentclass. Normally letter paper", 1139" is used (default). Since this option is only used in case of LaTeX, the `latex` option", 1140" is selected automatically.", 1141"", 1142" The option `amstex` automatically selects the `latex` option and includes the following", 1143" LaTeX packages: amsfonts, amsmath(intlimits). By default these packages are not", 1144" included.", 1145"", 1146" A name in quotes selects the font that will be used when no explicit font is", 1147" given in a `set label` or `set title`. A name recognized by TeX (a TFM file", 1148" exists) must be used. The default is \"cmr10\" unless `notex` is selected,", 1149" then it is \"pcrr8r\" (Courier). Even under `notex`, a TFM file is needed by", 1150" Metapost. The file `pcrr8r.tfm` is the name given to Courier in LaTeX's psnfss", 1151" package. If you change the font from the `notex` default, choose a font that", 1152" matches the ASCII encoding at least in the range 32-126. `cmtt10` almost", 1153" works, but it has a nonblank character in position 32 (space).", 1154"", 1155" The size can be any number between 5.0 and 99.99. If it is omitted, 10.0 is", 1156" used. It is advisable to use `magstep` sizes: 10 times an integer or", 1157" half-integer power of 1.2, rounded to two decimals, because those are the most", 1158" available sizes of fonts in TeX systems.", 1159"", 1160" All the options are optional. If font information is given, it must be at the", 1161" end, with size (if present) last. The size is needed to select a size for the", 1162" font, even if the font name includes size information. For example,", 1163" `set term mp \"cmtt12\"` selects cmtt12 shrunk to the default size 10. This", 1164" is probably not what you want or you would have used cmtt10.", 1165"", 1166" The following common ascii characters need special treatment in TeX:", 1167" $, &, #, %, _; |, <, >; ^, ~, \\, {, and }", 1168" The five characters $, #, &, _, and % can simply be escaped, e.g., `\\$`.", 1169" The three characters <, >, and | can be wrapped in math mode, e.g., `$<$`.", 1170" The remainder require some TeX work-arounds. Any good book on TeX will give", 1171" some guidance.", 1172"", 1173" If you type your labels inside double quotes, backslashes in TeX code need to", 1174" be escaped (doubled). Using single quotes will avoid having to do this, but", 1175" then you cannot use `\\n` for line breaks. As of this writing, version 3.7 of", 1176" gnuplot processes titles given in a `plot` command differently than in other", 1177" places, and backslashes in TeX commands need to be doubled regardless of the", 1178" style of quotes.", 1179"", 1180" Metapost pictures are typically used in TeX documents. Metapost deals with", 1181" fonts pretty much the same way TeX does, which is different from most other", 1182" document preparation programs. If the picture is included in a LaTeX document", 1183" using the graphics package, or in a plainTeX document via epsf.tex, and then", 1184" converted to PostScript with dvips (or other dvi-to-ps converter), the text in", 1185" the plot will usually be handled correctly. However, the text may not appear", 1186" if you send the Metapost output as-is to a PostScript interpreter.", 1187"", 1188"2 Metapost Instructions", 1189"?commands set terminal mp detailed", 1190"?set terminal mp detailed", 1191"?set term mp detailed", 1192"?mp detailed", 1193"?metapost detailed", 1194"", 1195" - Set your terminal to Metapost, e.g.:", 1196" set terminal mp mono \"cmtt12\" 12", 1197"", 1198" - Select an output-file, e.g.:", 1199" set output \"figure.mp\"", 1200"", 1201" - Create your pictures. Each plot (or multiplot group) will generate a", 1202" separate Metapost beginfig...endfig group. Its default size will be 5 by 3", 1203" inches. You can change the size by saying `set size 0.5,0.5` or whatever", 1204" fraction of the default size you want to have.", 1205"", 1206" - Quit gnuplot.", 1207"", 1208" - Generate EPS files by running Metapost on the output of gnuplot:", 1209" mpost figure.mp OR mp figure.mp", 1210" The name of the Metapost program depends on the system, typically `mpost` for", 1211" a Unix machine and `mp` on many others. Metapost will generate one EPS file", 1212" for each picture.", 1213"", 1214" - To include your pictures in your document you can use the graphics package", 1215" in LaTeX or epsf.tex in plainTeX:", 1216" \\usepackage{graphics} % LaTeX", 1217" \\input epsf.tex % plainTeX", 1218" If you use a driver other than dvips for converting TeX DVI output to PS, you", 1219" may need to add the following line in your LaTeX document:", 1220" \\DeclareGraphicsRule{*}{eps}{*}{}", 1221" Each picture you made is in a separate file. The first picture is in, e.g.,", 1222" figure.0, the second in figure.1, and so on.... To place the third picture in", 1223" your document, for example, all you have to do is:", 1224" \\includegraphics{figure.2} % LaTeX", 1225" \\epsfbox{figure.2} % plainTeX", 1226"", 1227" The advantage, if any, of the mp terminal over a postscript terminal is", 1228" editable output. Considerable effort went into making this output as clean as", 1229" possible. For those knowledgeable in the Metapost language, the default line", 1230" types and colors can be changed by editing the arrays `lt[]` and `col[]`.", 1231" The choice of solid vs dashed lines, and color vs black lines can be change by", 1232" changing the values assigned to the booleans `dashedlines` and `colorlines`.", 1233" If the default `tex` option was in effect, global changes to the text of", 1234" labels can be achieved by editing the `vebatimtex...etex` block. In", 1235" particular, a LaTeX preamble can be added if desired, and then LaTeX's", 1236" built-in size changing commands can be used for maximum flexibility. Be sure", 1237" to set the appropriate MP configuration variable to force Metapost to run", 1238" LaTeX instead of plainTeX." 1239END_HELP(mp) 1240#endif /* TERM_HELP */ 1241