File: pstricks.trm

package info (click to toggle)
gnuplot 3.7.1p1-4
  • links: PTS
  • area: main
  • in suites: potato
  • size: 5,808 kB
  • ctags: 4,418
  • sloc: ansic: 43,279; lisp: 661; makefile: 647; asm: 539; sh: 416; objc: 379; csh: 297; pascal: 194; perl: 138
file content (586 lines) | stat: -rw-r--r-- 16,093 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
/* Hey Emacs this is -*- C -*-
 * 
 * $Id: pstricks.trm,v 1.12.2.1 1999/08/19 14:15:55 lhecking Exp $
 */

/* GNUPLOT - pstricks.trm */

/*[
 * Copyright 1990 - 1993, 1998
 *
 * Permission to use, copy, and distribute this software and its
 * documentation for any purpose with or without fee is hereby granted,
 * provided that the above copyright notice appear in all copies and
 * that both that copyright notice and this permission notice appear
 * in supporting documentation.
 *
 * Permission to modify the software is granted, but not the right to
 * distribute the complete modified source code.  Modifications are to
 * be distributed as patches to the released version.  Permission to
 * distribute binaries produced by compiling modified sources is granted,
 * provided you
 *   1. distribute the corresponding source modifications from the
 *    released version in the form of a patch file along with the binaries,
 *   2. add special version identification to distinguish your version
 *    in addition to the base release version number,
 *   3. provide your name and address as the primary contact for the
 *    support of your modified version, and
 *   4. retain our contact information in regard to use of the base
 *    software.
 * Permission to distribute the released version of the source code along
 * with corresponding source modifications in the form of a patch file is
 * granted with same provisions 2 through 4 for binary distributions.
 *
 * This software is provided "as is" without express or implied warranty
 * to the extent permitted by applicable law.
]*/

/*
 * This file is included by ../term.c.
 *
 * This terminal driver supports:
 *   The PSTricks macros for LaTeX.
 *
 * AUTHORS
 *   David Kotz
 *
 *   Raymond Toy	toy@soho.crd.ge.com
 *	Modified the eepic.trm file to use PSTricks macros instead.
 *
 *	20 Mar 93:
 *		Utilized many suggestions from Gisli Ottarsson
 *		(gisli@liapunov.eecs.umich.edu) to create a new version.
 *		Should also work with TeX as well as LaTeX.
 *
 *		If you have PSTricks version 0.91, #define OLD_PST to
 *		get the right dots.
 *
 *		Added a really ugly hack (enabled by default) to print
 *		"nice" numbers for axis labels.  This should really be at
 *		a higher level in the code, but I'm lazy right now.
 *
 * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
 *
 */

/*
 *  This file contains the PSTricks terminal driver, intended for use with the
 *  pstricks.sty macro package for LaTeX. This is an alternative to the
 *  eepic and latex driver. You need pstricks.sty, and, of course, a printer
 *  that understands PostScript.  Ghostscript understands Postscript too.
 *
 *  PSTricks is available via anonymous ftp from the /pub directory
 *  at Princeton.EDU.  This driver definitely does not come close to
 *  using the full capability of the PSTricks package.
 */
/*
 * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
 */

#include "driver.h"

#ifdef TERM_REGISTER
register_term(pstricks)
#endif

#ifdef TERM_PROTO
TERM_PUBLIC void PSTRICKS_options __PROTO((void));
TERM_PUBLIC void PSTRICKS_init __PROTO((void));
TERM_PUBLIC void PSTRICKS_graphics __PROTO((void));
TERM_PUBLIC void PSTRICKS_text __PROTO((void));
TERM_PUBLIC void PSTRICKS_linetype __PROTO((int linetype));
TERM_PUBLIC void PSTRICKS_move __PROTO((unsigned int x, unsigned int y));
TERM_PUBLIC void PSTRICKS_point __PROTO((unsigned int x, unsigned int y, int number));
TERM_PUBLIC void PSTRICKS_vector __PROTO((unsigned int ux, unsigned int uy));
TERM_PUBLIC void PSTRICKS_arrow __PROTO((unsigned int sx, unsigned int sy, unsigned int ex, unsigned int ey, TBOOLEAN head));
TERM_PUBLIC void PSTRICKS_put_text __PROTO((unsigned int x, unsigned int y, char str[]));
TERM_PUBLIC int PSTRICKS_justify_text __PROTO((enum JUSTIFY mode));
TERM_PUBLIC int PSTRICKS_text_angle __PROTO((int ang));
TERM_PUBLIC void PSTRICKS_reset __PROTO((void));

#define PSTRICKS_XMAX 10000.0
#define PSTRICKS_YMAX 10000.0

#define PSTRICKS_HTIC	150
#define PSTRICKS_VTIC	200
#define PSTRICKS_HCHAR	160
#define PSTRICKS_VCHAR	420
#endif /* TERM_PROTO */

#ifndef TERM_PROTO_ONLY
#ifdef TERM_BODY
static void PSTRICKS_endline __PROTO((void));
static char *PSTRICKS_hack_text __PROTO((char s[]));

static float PSTRICKS_xscale = 1.0;
static float PSTRICKS_yscale = 1.0;
static float PSTRICKS_posx;
static float PSTRICKS_posy;
enum JUSTIFY PSTRICKS_justify = LEFT;
static int PSTRICKS_angle = 0;

#define	PSTRICKS_TINY_DOT	0.00025		/* A tiny dot */

/* POINTS */
#define PSTRICKS_POINT_TYPES 12	/* we supply more point types */
static char *PSTRICKS_points[] =
{
    "\\PST@Diamond",
    "\\PST@Plus",
    "\\PST@Square",
    "\\PST@Cross",
    "\\PST@Circle",
    "\\PST@Triangle",
    "\\PST@Pentagon",
    "\\PST@Filldiamond",
    "\\PST@Fillsquare",
    "\\PST@Filltriangle",
    "\\PST@Fillcircle",
    "\\PST@Fillpentagon"
};

/* LINES */
#define PSTRICKS_NUMLINES 6	/* number of linetypes below */
static char *PSTRICKS_lines[] =
{
    "\\PST@Border",
    "\\PST@Axes",
    "\\PST@Solid",
    "\\PST@Dashed",
    "\\PST@Dotted",
    "\\PST@LongDash"
};

/* current line type */
static int PSTRICKS_type;

/* are we in the middle of a line */
static TBOOLEAN PSTRICKS_inline = FALSE;

/* terminate any line in progress */
static void PSTRICKS_endline __PROTO((void));

/* number of points in line so far */
static int PSTRICKS_linecount = 0;

/* max value for linecount */
#define PSTRICKS_LINEMAX 100

/*
 * Handle options
 */

static int PST_hack_text = TRUE;	/* Hack text on */
static int PST_unit_plot = FALSE;	/* Unit-sized plot off */

TERM_PUBLIC void PSTRICKS_options()
{
    if (!END_OF_COMMAND) {
	if (almost_equals(c_token, "no$hacktext")) {
	    PST_hack_text = FALSE;
	    c_token++;
	} else if (almost_equals(c_token, "u$nit")) {
	    PST_unit_plot = TRUE;
	    c_token++;
	}
    }
}

TERM_PUBLIC void PSTRICKS_init()
{
    PSTRICKS_posx = PSTRICKS_posy = 0;
    PSTRICKS_linetype(-1);
    fputs("% GNUPLOT: LaTeX picture using PSTRICKS macros\n", gpoutfile);
}


TERM_PUBLIC void PSTRICKS_graphics()
{
    fputs("\
% Define new PST objects, if not already defined\n\
\\ifx\\PSTloaded\\undefined\n\
\\def\\PSTloaded{t}\n\
\\psset{arrowsize=.01 3.2 1.4 .3}\n\
\\psset{dotsize=.01}\n\
\\catcode`@=11\n\n", gpoutfile);

    /* Define line type objects */
    fputs("\
\\newpsobject{PST@Border}{psline}{linewidth=.0015,linestyle=solid}\n\
\\newpsobject{PST@Axes}{psline}{linewidth=.0015,linestyle=dotted,dotsep=.004}\n\
\\newpsobject{PST@Solid}{psline}{linewidth=.0015,linestyle=solid}\n\
\\newpsobject{PST@Dashed}{psline}{linewidth=.0015,linestyle=dashed,dash=.01 .01}\n\
\\newpsobject{PST@Dotted}{psline}{linewidth=.0025,linestyle=dotted,dotsep=.008}\n\
\\newpsobject{PST@LongDash}{psline}{linewidth=.0015,linestyle=dashed,dash=.02 .01}\n", gpoutfile);

    /* Define point objects */

#ifdef	OLD_PST
    /* PSTricks version 0.91 had x and diamond dot types */
    fputs("\
\\newpsobject(PST@Diamond}{psdots}{linewidth=.001,linestyle=solid,dotstyle=diamond}\n\
\\newpsobject(PST@Filldiamond}{psdots}{linewidth=.001,linestyle=solid,dotstyle=diamond*}\n\
\\newpsobject{PST@Cross}{psdots}{linewidth=.001,linestyle=solid,dotstyle=x}\n", gpoutfile);
#else
    /* Newer versions use rotated plus and square to get the x and diamond dots */
    fputs("\
\\newpsobject{PST@Diamond}{psdots}{linewidth=.001,linestyle=solid,dotstyle=square,dotangle=45}\n\
\\newpsobject{PST@Filldiamond}{psdots}{linewidth=.001,linestyle=solid,dotstyle=square*,dotangle=45}\n\
\\newpsobject{PST@Cross}{psdots}{linewidth=.001,linestyle=solid,dotstyle=+,dotangle=45}\n", gpoutfile);
#endif

    fputs("\
\\newpsobject{PST@Plus}{psdots}{linewidth=.001,linestyle=solid,dotstyle=+}\n\
\\newpsobject{PST@Square}{psdots}{linewidth=.001,linestyle=solid,dotstyle=square}\n\
\\newpsobject{PST@Circle}{psdots}{linewidth=.001,linestyle=solid,dotstyle=o}\n\
\\newpsobject{PST@Triangle}{psdots}{linewidth=.001,linestyle=solid,dotstyle=triangle}\n\
\\newpsobject{PST@Pentagon}{psdots}{linewidth=.001,linestyle=solid,dotstyle=pentagon}\n\
\\newpsobject{PST@Fillsquare}{psdots}{linewidth=.001,linestyle=solid,dotstyle=square*}\n\
\\newpsobject{PST@Fillcircle}{psdots}{linewidth=.001,linestyle=solid,dotstyle=*}\n\
\\newpsobject{PST@Filltriangle}{psdots}{linewidth=.001,linestyle=solid,dotstyle=triangle*}\n\
\\newpsobject{PST@Fillpentagon}{psdots}{linewidth=.001,linestyle=solid,dotstyle=pentagon*}\n", gpoutfile);

    /* Define arrow object */
    fputs("\
\\newpsobject{PST@Arrow}{psline}{linewidth=.001,linestyle=solid}\n\
\\catcode`@=12\n\n\
\\fi\n", gpoutfile);

    /* Set the scaled plot size, if it's not a unit plot */
    if (!PST_unit_plot) {
	fprintf(gpoutfile, "\\psset{unit=%fin,xunit=%fin,yunit=%fin}\n",
		5.0 * PSTRICKS_xscale,
		5.0 * PSTRICKS_xscale,
		3.0 * PSTRICKS_yscale);
    }
    fputs("\
\\pspicture(0,0)(1,1)\n\
\\ifx\\nofigs\\undefined\n\
\\catcode`@=11\n\n", gpoutfile);
}


TERM_PUBLIC void PSTRICKS_text()
{
    PSTRICKS_endline();
    fputs("\
\\catcode`@=12\n\
\\fi\n\
\\endpspicture\n", gpoutfile);
}


TERM_PUBLIC void PSTRICKS_linetype(linetype)
int linetype;
{
    PSTRICKS_endline();

    if (linetype >= PSTRICKS_NUMLINES - 2)
	linetype %= (PSTRICKS_NUMLINES - 2);

    PSTRICKS_type = linetype;
}



TERM_PUBLIC void PSTRICKS_move(x, y)
unsigned int x;
unsigned int y;
{
    PSTRICKS_endline();

    PSTRICKS_posx = x / PSTRICKS_XMAX;
    PSTRICKS_posy = y / PSTRICKS_YMAX;
}


TERM_PUBLIC void PSTRICKS_point(x, y, number) /* version of line_and_point */
unsigned x;
unsigned y;
int number;
{
    PSTRICKS_move(x, y);

    /* Print the character defined by 'number'; number < 0 means
       to use a dot, otherwise one of the defined points. */

    if (number < 0) {
	fprintf(gpoutfile, "\\qdisk(%.4f,%.4f){%.4f}\n",
		x / PSTRICKS_XMAX,
		y / PSTRICKS_YMAX,
		PSTRICKS_TINY_DOT);
    } else {
	fprintf(gpoutfile, "%s(%.4f,%.4f)\n",
		PSTRICKS_points[number % PSTRICKS_POINT_TYPES],
		x / PSTRICKS_XMAX,
		y / PSTRICKS_YMAX);
    }
}


TERM_PUBLIC void PSTRICKS_vector(ux, uy)
unsigned ux;
unsigned uy;
{
    if (!PSTRICKS_inline) {
	PSTRICKS_inline = TRUE;

	/* Start a new line. This depends on line type */
	fprintf(gpoutfile, "%s(%.4f,%.4f)\n", PSTRICKS_lines[PSTRICKS_type + 2],
		PSTRICKS_posx, PSTRICKS_posy);
	PSTRICKS_linecount = 1;
    } else {
	/*
	 * Even though we are in middle of a path,
	 * we may want to start a new path command.
	 * If they are too long then latex will choke.
	 */
	if (PSTRICKS_linecount++ >= PSTRICKS_LINEMAX) {
/*	    fprintf(gpoutfile, "\n"); */
	    fprintf(gpoutfile, "%s(%.4f,%.4f)\n", PSTRICKS_lines[PSTRICKS_type + 2],
		    PSTRICKS_posx, PSTRICKS_posy);
	    PSTRICKS_linecount = 1;
	}
    }
    PSTRICKS_posx = ux / PSTRICKS_XMAX;
    PSTRICKS_posy = uy / PSTRICKS_YMAX;
    fprintf(gpoutfile, "(%.4f,%.4f)\n", PSTRICKS_posx, PSTRICKS_posy);
}

static void PSTRICKS_endline()
{
    if (PSTRICKS_inline) {
	putc('\n', gpoutfile);
	PSTRICKS_inline = FALSE;
    }
}


TERM_PUBLIC void PSTRICKS_arrow(sx, sy, ex, ey, head)
unsigned int sx;
unsigned int sy;
unsigned int ex;
unsigned int ey;
TBOOLEAN head;
{
    fprintf(gpoutfile, "\\PST@Arrow%s(%.4f,%.4f)(%.4f,%.4f)\n",
	    head ? "{->}" : "",
	    sx / PSTRICKS_XMAX,
	    sy / PSTRICKS_YMAX,
	    ex / PSTRICKS_XMAX,
	    ey / PSTRICKS_YMAX);

    PSTRICKS_posx = ex / PSTRICKS_XMAX;
    PSTRICKS_posy = ey / PSTRICKS_YMAX;
}

/*
 * A really ugly hack!!!
 *
 * This function takes an input string and hacks it up.  If the
 * input string starts with a number, it converts the number into a
 * TeX style number including exponential notation.  Thus, if
 * the input is the string "3.14159e3 is a number", then
 * the output is "$3.14159\cdot 10^{3}$ is a number", so that TeX
 * will produce something nice.
 *
 * This is basically meant for producing axis labels that look nice.
 *
 * What a hack!
 */


static char *PSTRICKS_hack_text(s)
char s[];
{
    double value;
    char *ends;
    static char hack[BUFSIZ];

    /*
     * Does the string start with a number?
     */

    value = strtod(s, &ends);

    if (s == ends) {
	/*
	 * This doesn't start a number, so just copy the string over
	 */

	strcpy(hack, s);
    } else {
	char *ptr;

	/*
	 * We have a number!  Check to see if the number
	 * is in scientific notation
	 */

	safe_strncpy(hack, s, ends - s + 1);
	/* hack[ends - s] = '\0'; */

	ptr = strchr(hack, 'e');
	if (ptr == NULL) {
	    ptr = strchr(hack, 'E');
	}
	if (ptr != NULL) {
	    /*
	     * Exponential notation!  Let's get the mantissa and exponent separately
	     */

	    double man_val;
	    int expo_val;

	    *ptr = NUL;

	    man_val = atof(hack);
	    expo_val = atoi(ptr + 1);

	    if (man_val == 0) {
		sprintf(hack, "0");
	    } else if (man_val == 1) {
		sprintf(hack, "$10^{%d}$", expo_val);
	    } else if (man_val == (int) man_val) {
		if (expo_val == 1) {
		    sprintf(hack, "$%d$", (int) man_val);
		} else {
		    sprintf(hack, "$%d \\times 10^{%d}$", (int) man_val, expo_val);
		}
	    } else {
		if (expo_val == 1) {
		    sprintf(hack, "$%f$", man_val);
		} else {
		    sprintf(hack, "$%f \\times 10^{%d}$", man_val, expo_val);
		}
	    }
	}
	/*
	 * Copy anything that's left of the string
	 */

	strcat(hack, ends);
    }

    return hack;
}

TERM_PUBLIC void PSTRICKS_put_text(x, y, str)
unsigned int x;
unsigned int y;
char str[];
{
    PSTRICKS_endline();

    /* Skip this if the string is empty */

    if (strlen(str) > 0) {
	fputs("\\rput", gpoutfile);

	/* Set justification */

	switch (PSTRICKS_justify) {
	case LEFT:
	    fputs("[l]", gpoutfile);
	    break;
	case CENTRE:
	    break;
	case RIGHT:
	    fputs("[r]", gpoutfile);
	    break;
	}

	/* Set text angle */

	switch (PSTRICKS_angle) {
	case 0:
	    break;
	case 1:
	    fputs("{L}", gpoutfile);
	    break;
	}

	/* Set reference position and text */

	fprintf(gpoutfile, "(%.4f,%.4f)",
		x / PSTRICKS_XMAX,
		y / PSTRICKS_YMAX);
	if (PST_hack_text) {
	    char *hack;

	    /* Hack leading numbers to something nice for TeX */

	    hack = PSTRICKS_hack_text(str);
	    fprintf(gpoutfile, "{%s}\n", hack);
	} else {
	    fprintf(gpoutfile, "{%s}\n", str);
	}
    }
}



TERM_PUBLIC int PSTRICKS_justify_text(mode)
enum JUSTIFY mode;
{
    PSTRICKS_justify = mode;
    return (TRUE);
}

TERM_PUBLIC int PSTRICKS_text_angle(ang)
int ang;
{
    PSTRICKS_angle = ang;
    return (TRUE);
}

TERM_PUBLIC void PSTRICKS_reset()
{
    PSTRICKS_endline();
    PSTRICKS_posx = PSTRICKS_posy = 0;
}

#endif /* TERM_BODY */

#ifdef TERM_TABLE

TERM_TABLE_START(pstricks_driver)
    "pstricks", "LaTeX picture environment with PSTricks macros",
    PSTRICKS_XMAX, PSTRICKS_YMAX, PSTRICKS_VCHAR, PSTRICKS_HCHAR,
    PSTRICKS_VTIC, PSTRICKS_HTIC, PSTRICKS_options, PSTRICKS_init, PSTRICKS_reset,
    PSTRICKS_text, null_scale, PSTRICKS_graphics, PSTRICKS_move, PSTRICKS_vector,
    PSTRICKS_linetype, PSTRICKS_put_text, PSTRICKS_text_angle,
    PSTRICKS_justify_text, PSTRICKS_point, PSTRICKS_arrow, set_font_null
TERM_TABLE_END(pstricks_driver)

#undef LAST_TERM
#define LAST_TERM pstricks_driver

#endif /* TERM_TABLE */
#endif /* TERM_PROTO_ONLY */

#ifdef TERM_HELP
START_HELP(pstricks)
"1 pstricks",
"?commands set terminal pstricks",
"?set terminal pstricks",
"?set term pstricks",
"?terminal pstricks",
"?term pstricks",
"?pstricks",
" The `pstricks` driver is intended for use with the \"pstricks.sty\" macro",
" package for LaTeX.  It is an alternative to the `eepic` and `latex` drivers.",
" You need \"pstricks.sty\", and, of course, a printer that understands",
" PostScript, or a converter such as Ghostscript.",
"",
" PSTricks is available via anonymous ftp from the /pub directory at",
" Princeton.EDU.  This driver definitely does not come close to using the full",
" capability of the PSTricks package.",
"",
" Syntax:",
"       set terminal pstricks {hacktext | nohacktext} {unit | nounit}",
"",
" The first option invokes an ugly hack that gives nicer numbers; the second",
" has to do with plot scaling.  The defaults are `hacktext` and `nounit`."
END_HELP(pstricks)
#endif /* TERM_HELP */