File: tpic.trm

package info (click to toggle)
gnuplot 3.5beta6.340-5
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 4,792 kB
  • ctags: 4,205
  • sloc: ansic: 41,878; asm: 539; makefile: 498; objc: 379; csh: 297; sh: 277; pascal: 194; perl: 138; lisp: 88
file content (908 lines) | stat: -rw-r--r-- 23,899 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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
/*
 * $Id: tpic.trm,v 1.17 1997/05/27 01:29:53 drd Exp $
 */

/* GNUPLOT - tpic.trm */
/*
 * Copyright (C) 1990 - 1993, 1997
 *
 * 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 modified code.  Modifications are to be distributed 
 * as patches to released version.
 *  
 * This software  is provided "as is" without express or implied warranty.
 * 
 * This file is included by ../term.c.
 *
 * This terminal driver supports:
 *   The tpic \specials (version 2.2) for LaTeX. 
 *
 * AUTHORS
 *   Oh-Yeah?   3 Sep. 1992 (closely following eepic.trm by David Kotz)
 *   A. Woo     5 Oct. 1992 (removed ansi prototypes for braindead compilers)
 *
 * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
 * 
 */
/*
 *  This file contains the tpic terminal driver for use with LaTeX. 
 *  This is an alternative to the latex and eepic drivers. You need 
 *  a printer driver that supports the tpic \specials version 2.2.
 *
 * Comparison with the eepic driver (eepic.trm):
 *  Merits
 *    - More point and line types
 *    - Options to change point size, linewidth, dot & dash intervals
 *    - Dotted and dashed lines for high-sample-rate curves (but may
 *      depend on tpic (da & dt) implementation of your dvi driver :-)
 *    - Overlapped points made fancier by tpic shading facility
 *    - Optional comments for trimming figure margins
 *    - No need for epic and eepic macros
 *  Drawback
 *    - You cannot use eepicemu macro for non-tpic-support dvi drivers
 *
 * LATEX must also be defined.
 */


/* These parameters can be modified as you like, through options.  Say 
   "set terminal tpic <pointsize> <linewidth> <interval>".  <pointsize> 
   and <linewidth> are integers in milli-inches; <interval> is a float 
   in inches.  If non-positive value is specified, the default (below) 
   is chosen. 
*/

/*
 * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
 */

#ifndef GOT_DRIVER_H
#include "driver.h"
#endif

#ifdef TERM_REGISTER
register_term(tpic)
#endif

#ifdef TERM_PROTO
TERM_PUBLIC void TPIC_options __PROTO((void)); /* get size options */
TERM_PUBLIC void TPIC_init __PROTO((void));
TERM_PUBLIC void TPIC_reset __PROTO((void));
TERM_PUBLIC void TPIC_text __PROTO((void));
TERM_PUBLIC void TPIC_graphics __PROTO((void));
TERM_PUBLIC void TPIC_move __PROTO((unsigned int x, unsigned int y));
TERM_PUBLIC void TPIC_vector __PROTO((unsigned int ux, unsigned int uy));
TERM_PUBLIC void TPIC_linetype __PROTO((int linetype));
TERM_PUBLIC void TPIC_put_text __PROTO((unsigned int x, unsigned int y, char *str)); /* ref point and text */
TERM_PUBLIC int TPIC_text_angle __PROTO((int angle));
TERM_PUBLIC int TPIC_justify_text __PROTO((enum JUSTIFY mode));
TERM_PUBLIC void TPIC_point __PROTO((unsigned int x, unsigned int y, int number));
TERM_PUBLIC void TPIC_arrow __PROTO((unsigned int sx, unsigned int sy, unsigned int ex, unsigned int ey, TBOOLEAN head));
#define TPIC_UNIT 0.001 /* tpic \specials unit in inches (1 milli-inch) */
/* 5 inches wide by 3 inches high (default) */
#define TPIC_XMAX (unsigned int) (5 / TPIC_UNIT)
#define TPIC_YMAX (unsigned int) (3 / TPIC_UNIT)
#define TPIC_PTS_PER_UNIT (72.27 * TPIC_UNIT)
#define TPIC_HTIC  (unsigned int) ( 5.0 / TPIC_PTS_PER_UNIT) /* 5pt */
#define TPIC_VTIC  (unsigned int) ( 5.0 / TPIC_PTS_PER_UNIT) /* 5pt */
#define TPIC_HCHAR (unsigned int) ( 5.3 / TPIC_PTS_PER_UNIT) /* 5.3pt */
#define TPIC_VCHAR (unsigned int) (11.0 / TPIC_PTS_PER_UNIT) /* 11pt */
#endif /* TERM_PROTO */

#ifndef TERM_PROTO_ONLY
#ifdef TERM_BODY
static int tpic_pointsize   =  40; /* min point radius   (in milli-inches) */
static int tpic_linewidth   =   6; /* min line thickness (in milli-inches) */
static double tpic_interval = 0.1; /* min dot & dash intervals (in inches) */

/* ARROWS: same code as for LATEX */
void best_latex_arrow __PROTO((int sx, int sy, int ex, int ey, int who, 
	TBOOLEAN head));  /* figure out the best arrow. in latex.trm */

/* all prototypes ... */
static void tpic_startline __PROTO((void));  /* private */
static void tpic_endline __PROTO((void));  /* private */
static void tpic_pushpath __PROTO((unsigned int x, unsigned int y)); /* private */
static void tpic_scanpath __PROTO((void));
void tpic_diamond __PROTO((int size));
void tpic_plus __PROTO((int size));
void tpic_box __PROTO((int size));
void tpic_times __PROTO((int size));
void tpic_triangle __PROTO((int size));
void tpic_star __PROTO((int size));
void tpic_hexagon __PROTO((int size));
void tpic_circle __PROTO((int size));
void tpic_doublecircle __PROTO((int size));
void tpic_vercircle __PROTO((int size)); /* circle with | */
void tpic_horcircle __PROTO((int size)); /* circle with - */
void tpic_pluscircle __PROTO((int size)); /* circle with + */
void tpic_timescircle __PROTO((int size)); /* circle with times */
void tpic_starcircle __PROTO((int size)); /* circle with star */
void tpic_dotcircle __PROTO((int size)); /* circle with dot (black circle) */
void tpic_diamondcircle __PROTO((int size)); /* circle with black diamond */
void tpic_boxcircle __PROTO((int size)); /* circle with black box */
void tpic_trianglecircle __PROTO((int size)); /* circle with black triangle */
void tpic_hexagoncircle __PROTO((int size)); /* circle with black hexagon */
void tpic_plustimescircle __PROTO((int size)); /* no more idea ... with plus & times */
void tpic_abspath __PROTO((unsigned int x, unsigned int y)); /* absolute coord */
void tpic_path __PROTO((int x, int y));
void tpic_flush __PROTO((void));
void tpic_arc __PROTO((int radius)); /* actually, draw a full circle */
void tpic_shade __PROTO((double grayscale));
void tpic_pen __PROTO((int thickness));
void tpic_dottedflush __PROTO((double interval));
void tpic_dashedflush __PROTO((double interval));

typedef enum {tpic_none, tpic_white, tpic_gray, tpic_black} tpic_shadestyle;
typedef enum {tpic_nosize, tpic_small, tpic_medium, tpic_large} tpic_size;
typedef void (*tpic_function) __PROTO((int size));

typedef struct {
	tpic_shadestyle shadestyle;
	tpic_size size;
	tpic_function function;
} tpic_point_info;

/* POINTS */
static /*GPFAR*/ tpic_point_info GPFAR tpic_point[] = {
	{tpic_white, tpic_medium, tpic_diamond},
	{tpic_none,  tpic_medium, tpic_plus},
	{tpic_white, tpic_medium, tpic_box},
	{tpic_none,  tpic_medium, tpic_times},
	{tpic_white, tpic_medium, tpic_triangle},
	{tpic_none,  tpic_medium, tpic_star},
	{tpic_white, tpic_small,  tpic_circle},
	{tpic_white, tpic_medium, tpic_circle},
	{tpic_white, tpic_large,  tpic_circle},
	{tpic_black, tpic_small,  tpic_circle},
	{tpic_black, tpic_medium, tpic_circle},
	{tpic_black, tpic_large,  tpic_circle},
	{tpic_black, tpic_medium, tpic_diamond},
	{tpic_black, tpic_medium, tpic_box},
	{tpic_black, tpic_medium, tpic_triangle},
	{tpic_white, tpic_medium, tpic_hexagon},
	{tpic_black, tpic_medium, tpic_hexagon},
	{tpic_white, tpic_medium, tpic_doublecircle},
	{tpic_white, tpic_medium, tpic_vercircle},
	{tpic_white, tpic_medium, tpic_horcircle},
	{tpic_white, tpic_medium, tpic_pluscircle},
	{tpic_white, tpic_medium, tpic_timescircle},
	{tpic_white, tpic_medium, tpic_starcircle},
	{tpic_black, tpic_medium, tpic_doublecircle},
	{tpic_white, tpic_medium, tpic_dotcircle},
	{tpic_white, tpic_medium, tpic_diamondcircle},
	{tpic_white, tpic_medium, tpic_boxcircle},
	{tpic_white, tpic_medium, tpic_trianglecircle},
	{tpic_white, tpic_medium, tpic_hexagoncircle},
	{tpic_white, tpic_medium, tpic_plustimescircle}
};

typedef enum {tpic_solid, tpic_dotted, tpic_dashed, 
	tpic_dashed_sdot, tpic_dashed_ddot} tpic_linestyle;
typedef struct {
	tpic_size thickness, interval;
	tpic_linestyle linestyle;
} tpic_line_info;

/* LINES */
static /*GPFAR*/ tpic_line_info GPFAR tpic_line[] = {
	{tpic_medium, tpic_nosize, tpic_solid},  /* -2 border */
	{tpic_small,  tpic_small,  tpic_dashed}, /* -1 axes */
	{tpic_small,  tpic_nosize, tpic_solid},
	{tpic_medium, tpic_nosize, tpic_solid},
	{tpic_large,  tpic_nosize, tpic_solid},
	{tpic_small,  tpic_small,  tpic_dotted},
	{tpic_medium, tpic_small,  tpic_dotted},
	{tpic_large,  tpic_small,  tpic_dotted},
	{tpic_small,  tpic_small,  tpic_dashed},
	{tpic_medium, tpic_small,  tpic_dashed},
	{tpic_large,  tpic_small,  tpic_dashed},
	{tpic_small,  tpic_small,  tpic_dashed_sdot}, /* dash with single dots */
	{tpic_medium, tpic_small,  tpic_dashed_sdot},
	{tpic_large,  tpic_small,  tpic_dashed_sdot},
	{tpic_small,  tpic_small,  tpic_dashed_ddot}, /* dash with double dots */
	{tpic_medium, tpic_small,  tpic_dashed_ddot},
	{tpic_large,  tpic_small,  tpic_dashed_ddot},
	{tpic_small,  tpic_medium, tpic_dotted},
	{tpic_medium, tpic_medium, tpic_dotted},
	{tpic_large,  tpic_medium, tpic_dotted},
	{tpic_small,  tpic_medium, tpic_dashed},
	{tpic_medium, tpic_medium, tpic_dashed},
	{tpic_large,  tpic_medium, tpic_dashed},
	{tpic_small,  tpic_medium, tpic_dashed_sdot},
	{tpic_medium, tpic_medium, tpic_dashed_sdot},
	{tpic_large,  tpic_medium, tpic_dashed_sdot},
	{tpic_small,  tpic_medium, tpic_dashed_ddot},
	{tpic_medium, tpic_medium, tpic_dashed_ddot},
	{tpic_large,  tpic_medium, tpic_dashed_ddot},
	{tpic_small,  tpic_large,  tpic_dotted},
	{tpic_medium, tpic_large,  tpic_dotted},
	{tpic_large,  tpic_large,  tpic_dotted},
	{tpic_small,  tpic_large,  tpic_dashed},
	{tpic_medium, tpic_large,  tpic_dashed},
	{tpic_large,  tpic_large,  tpic_dashed},
	{tpic_small,  tpic_large,  tpic_dashed_sdot},
	{tpic_medium, tpic_large,  tpic_dashed_sdot},
	{tpic_large,  tpic_large,  tpic_dashed_sdot},
	{tpic_small,  tpic_large,  tpic_dashed_ddot},
	{tpic_medium, tpic_large,  tpic_dashed_ddot},
	{tpic_large,  tpic_large,  tpic_dashed_ddot}
};

TERM_PUBLIC void TPIC_options() /* get size options */
{
	struct value a;
	int pointsize, linewidth;
	double interval;

	if (!END_OF_COMMAND) {
		pointsize = (int)real(const_express(&a));
		if (pointsize > 0) tpic_pointsize = pointsize;
	}

	if (!END_OF_COMMAND) {
		linewidth = (int)real(const_express(&a));
		if (linewidth > 0) tpic_linewidth = linewidth;
	}

	if (!END_OF_COMMAND) {
		interval = (double)real(const_express(&a));
		if (interval > 0) tpic_interval = interval;
	}

	sprintf(term_options, "%d %d %f", tpic_pointsize, tpic_linewidth, 
		tpic_interval);
}

static unsigned int tpic_posx; /* current position */
static unsigned int tpic_posy;
static int tpic_point_types;
static int tpic_numlines;

TERM_PUBLIC void TPIC_init()
{
static char GPFAR tpic1[] = "\
%% GNUPLOT: LaTeX picture using tpic \\specials\n\
%%          with %d point types and %d line types\n\
%% Options: pointsize = %d, linewidth = %d, interval = %f\n\
%% To change above options, say:\n\
%% set terminal tpic pointsize_value linewidth_value interval_value\n\
%% (pointsize and linewidth - integers in milli-inches.\n\
%%  interval - a float in inches.  If zero is specified, \n\
%%  the default value is chosen.)\n\
\\setlength{\\unitlength}{%fin}%%\n";
	tpic_point_types = sizeof(tpic_point) / sizeof(tpic_point[0]);
	tpic_numlines = sizeof(tpic_line) / sizeof(tpic_line[0]);

	tpic_posx = tpic_posy = 0;
	TPIC_linetype(-1);
	fprintf(outfile, tpic1,
		tpic_point_types, tpic_numlines - 2,
		tpic_pointsize, tpic_linewidth, tpic_interval,
		TPIC_UNIT);
}

TERM_PUBLIC void TPIC_reset()
{
	tpic_endline();
	tpic_posx = tpic_posy = 0;
}

TERM_PUBLIC void TPIC_text()
{
	tpic_endline();
	fprintf(outfile, "\\end{picture}\n");
}

TERM_PUBLIC void TPIC_graphics()
{
	register struct termentry *t = term;
	int left, right, top, bottom; /* margins */
	static char GPFAR begin[] = "%s\\begin{picture}(%d,%d)(%d,%d)%% %s\n";

	fprintf(outfile, begin, "", t->xmax, t->ymax, 0, 0, "");

	/* the following is dependent on boundary() function in graphics.c */
	left = TPIC_HCHAR * 12;
	right = TPIC_HCHAR * 2 + TPIC_HTIC;
	bottom = TPIC_VCHAR * 7 / 2 + 1;
	top = TPIC_VCHAR * 5 / 2 - 1;
	fprintf(outfile, begin, "%% ", t->xmax - left, t->ymax, left, 0, 
		"trim left margin");
	fprintf(outfile, begin, "%% ", t->xmax - right, t->ymax, 0, 0, 
		"trim right margin");
	fprintf(outfile, begin, "%% ", t->xmax - left - right, t->ymax, left, 0, 
		"trim left & right margins");
	fprintf(outfile, begin, "%% ", t->xmax, t->ymax - top, 0, 0, 
		"trim top margin");
	fprintf(outfile, begin, "%% ", t->xmax, t->ymax - bottom, 0, bottom, 
		"trim bottom margin");
	fprintf(outfile, begin, "%% ", t->xmax, t->ymax - top - bottom, 0, bottom,
		"trim top & bottom margins");

	fprintf(outfile, "\\footnotesize%%\n");
}

TERM_PUBLIC void TPIC_move(x,y)
unsigned int x; unsigned int y;
{
	tpic_endline();
	tpic_posx = x;
	tpic_posy = y;
}

#define TPIC_LINEMAX 100 /* max value for linecount */
static TBOOLEAN tpic_inline = FALSE; /* are we in the middle of a line */
static int tpic_linecount = 0; /* number of points in line so far */

TERM_PUBLIC void TPIC_vector(ux,uy)
unsigned int ux; unsigned int uy;
{
	if (!tpic_inline) {
		tpic_startline();
	} else if (tpic_linecount >= TPIC_LINEMAX) {
		/* Even though we are in middle of a path, we may start a new path 
		command once in a while; if they are too long, latex will choke. */
		tpic_endline();
		tpic_startline();
	}
	tpic_pushpath(ux, uy);
	tpic_posx = ux;
	tpic_posy = uy;
}

static int tpic_linetype; /* current line type */

static void tpic_startline() /* private */
{
	int thickness=1;

	tpic_inline = TRUE;
	switch (tpic_line[tpic_linetype + 2].thickness) {
	case tpic_small:
		thickness = tpic_linewidth;
		break;
	case tpic_medium:
		thickness = (int)(tpic_linewidth * 3);
		break;
	case tpic_large:
		thickness = (int)(tpic_linewidth * 5);
		break;
	default:
		break;
	}
	tpic_pen(thickness);
	tpic_linecount = 0;
	tpic_pushpath(tpic_posx, tpic_posy);
	return;
}

static void tpic_endline() /* private */
{
	double interval=1;

	if (tpic_inline) {
		tpic_scanpath(); /* draw actually */
		switch (tpic_line[tpic_linetype + 2].interval) {
		case tpic_small:
			interval = tpic_interval;
			break;
		case tpic_medium:
			interval = tpic_interval * 2;
			break;
		case tpic_large:
			interval = tpic_interval * 3;
			break;
		case tpic_nosize:
			break;
		}
		switch (tpic_line[tpic_linetype + 2].linestyle) {
		case tpic_solid:
			tpic_flush();
			break;
		case tpic_dotted:
			tpic_dottedflush(interval);
			break;
		case tpic_dashed:
			tpic_dashedflush(interval);
			break;
		case tpic_dashed_sdot: /* dashed with single dots in between */
			tpic_dashedflush(interval);
			tpic_scanpath(); /* draw again */
			tpic_dottedflush(interval / 2);
			break;
		case tpic_dashed_ddot: /* dashed with double dots in between */
			tpic_dashedflush(interval);
			tpic_scanpath(); /* draw again */
			tpic_dottedflush(interval / 3);
			break;
		}
		tpic_inline = FALSE;
	}
	return;
}

/* private: stack functions */
static unsigned int pathpoint[TPIC_LINEMAX][2]; /* point stack */

static void tpic_pushpath(x,y)
unsigned int x; unsigned int y; /* private */
{
	if (tpic_linecount < TPIC_LINEMAX) {
		pathpoint[tpic_linecount][0] = x;
		pathpoint[tpic_linecount][1] = y;
		tpic_linecount++;
	}
	return;
}

static void tpic_scanpath()
{
	int i;

	for (i = 0; i < tpic_linecount; i++)
		tpic_abspath(pathpoint[i][0], pathpoint[i][1]);
	return;
}

TERM_PUBLIC void TPIC_linetype(linetype)
int linetype;
{
	tpic_endline();
	if (linetype >= tpic_numlines - 2) linetype %= (tpic_numlines - 2);
	tpic_linetype = linetype;
}

static int tpic_angle = 0; /* 0 = horizontal, 1 = vertical */
static enum JUSTIFY tpic_justify = LEFT;

TERM_PUBLIC void TPIC_put_text(x,y,str)
unsigned int x; unsigned int y; char *str; /* ref point and text */
{
	char *justify=NULL;

	tpic_endline();
	fprintf(outfile, "\\put(%d,%d)", x, y);

	switch (tpic_angle) {
	case 0: /* horizontal */
		switch (tpic_justify) {
		case LEFT:
			justify = "[l]";
			break;
		case CENTRE:
			justify = "";
			break;
		case RIGHT:
			justify = "[r]";
			break;
		}
		fprintf(outfile, "{\\makebox(0,0)%s{%s}}\n", justify, str);
		break;
	case 1: /* vertical */
		/* we can't really write text vertically, but will put the ylabel 
		centred at the left of the plot, and then we'll make a \shortstack */
		switch (tpic_justify) {
		case LEFT:
			justify = "[lb]";
			break;
		case CENTRE:
			justify = "[l]";
			break;
		case RIGHT:
			justify = "[lt]";
			break;
		}
		fprintf(outfile, "{\\makebox(0,0)%s{\\shortstack{%s}}}\n", 
			justify, str);
		break;
	}
}

TERM_PUBLIC int TPIC_text_angle(angle)
int angle;
{
	tpic_angle = angle;
	return(TRUE);
}

TERM_PUBLIC int TPIC_justify_text(mode)
enum JUSTIFY mode;
{
	tpic_justify = mode;
	return(TRUE);
}

TERM_PUBLIC void TPIC_point(x,y,number)
unsigned int x; unsigned int y; int number;
{
	int size=0;

	TPIC_move(x, y);

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

	fprintf(outfile, "\\put(%d,%d){", x, y); /* start putting */

	if (number < 0) {
		fprintf(outfile, "\\rule{.1pt}{.1pt}"); /* tiny dot */
	} else {
		number %= tpic_point_types;
		switch (tpic_point[number].shadestyle) {
		case tpic_white:
			tpic_pen(tpic_linewidth); /* set it thin */
			tpic_shade(0.0);
			break;
		case tpic_gray:
			tpic_pen(tpic_linewidth);
			tpic_shade(0.5);
			break;
		case tpic_black:
			tpic_pen(tpic_linewidth);
			tpic_shade(1.0);
			break;
		case tpic_none:
			tpic_pen(tpic_linewidth * 3); /* set it thick */
			break;
		}
		switch (tpic_point[number].size) {
		case tpic_small:
			size = tpic_pointsize;
			break;
		case tpic_medium:
			size = (int)(tpic_pointsize * 1.4142);
			break;
		case tpic_large:
			size = (int)(tpic_pointsize * 2.0);
			break;
		default:
			break;
		}
		(tpic_point[number].function)(size);
	}

	fprintf(outfile, "}%%\n"); /* end putting */
}

TERM_PUBLIC void TPIC_arrow(sx,sy,ex,ey,head)
unsigned int sx;
unsigned int sy;
unsigned int ex;
unsigned int ey;
TBOOLEAN head;
{
	best_latex_arrow(sx, sy, ex, ey, 1, head); /* call latex routine */
	tpic_posx = ex;
	tpic_posy = ey;
}

/* private: draw points with tpic commands */

void tpic_diamond(size)
int size;
{
	size = (int)(size * 1.4142); /* spread by sqrt(2) */

	tpic_path(0, size);
	tpic_path(-size, 0);
	tpic_path(0, -size);
	tpic_path(size, 0);
	tpic_path(0, size);
	tpic_flush();
	return;
}

void tpic_plus(size)
int size;
{
	tpic_path(0, size);
	tpic_path(0, -size);
	tpic_flush();
	tpic_path(size, 0);
	tpic_path(-size, 0);
	tpic_flush();
	return;
}

void tpic_box(size)
int size;
{
	tpic_path(size, size);
	tpic_path(-size, size);
	tpic_path(-size, -size);
	tpic_path(size, -size);
	tpic_path(size, size);
	tpic_flush();
	return;
}

void tpic_times(size)
int size;
{
	size = (int)(size / 1.4142); /* reduce by sqrt(2) */

	tpic_path(size, size);
	tpic_path(-size, -size);
	tpic_flush();
	tpic_path(size, -size);
	tpic_path(-size, size);
	tpic_flush();
	return;
}

void tpic_triangle(size)
int size;
{
	int x;

	size = (int)(size / 1.6119); /* reduce by sqrt(3 * sqrt(3) / 2) */
	x = (int)(size * 1.7321);

	tpic_path(0, -size * 2);
	tpic_path(-x, size);
	tpic_path(x, size);
	tpic_path(0, -size * 2);
	tpic_flush();
	return;
}

void tpic_star(size)
int size;
{
	int x;

	size = (int)(size / 2); /* reduce by 2 */
	x = (int)(size * 1.7321);

	tpic_path(0, size * 2);
	tpic_path(0, -size * 2);
	tpic_flush();
	tpic_path(x, size);
	tpic_path(-x, -size);
	tpic_flush();
	tpic_path(x, -size);
	tpic_path(-x, size);
	tpic_flush();
	return;
}

void tpic_hexagon(size)
int size;
{
	int x;

	size = (int)(size / 2); /* reduce by 2 */
	x = (int)(size * 1.7321);

	tpic_path(0, size * 2);
	tpic_path(-x, size);
	tpic_path(-x, -size);
	tpic_path(0, -size * 2);
	tpic_path(x, -size);
	tpic_path(x, size);
	tpic_path(0, size * 2);
	tpic_flush();
	return;
}

void tpic_circle(size)
int size;
{
	tpic_arc(size);
	return;
}

void tpic_doublecircle(size)
int size;
{
	tpic_arc(size);
	tpic_shade(0.0);
	tpic_arc(size / 2);
	return;
}

void tpic_vercircle(size)
int size; /* circle with | */
{
	tpic_arc(size);
	tpic_path(0, size);
	tpic_path(0, -size);
	tpic_flush();
	return;
}

void tpic_horcircle(size)
int size; /* circle with - */
{
	tpic_arc(size);
	tpic_path(size, 0);
	tpic_path(-size, 0);
	tpic_flush();
	return;
}

void tpic_pluscircle(size)
int size; /* circle with + */
{
	tpic_arc(size);
	tpic_plus(size);
	return;
}

void tpic_timescircle(size)
int size; /* circle with times */
{
	tpic_arc(size);
	tpic_times(size);
	return;
}

void tpic_starcircle(size)
int size; /* circle with star */
{
	tpic_arc(size);
	tpic_star(size);
	return;
}

void tpic_dotcircle(size)
int size; /* circle with dot (black circle) */
{
	tpic_arc(size);
	tpic_shade(1.0);
	tpic_arc(size / 2);
	return;
}

void tpic_diamondcircle(size)
int size; /* not enough? circle with black diamond */
{
	tpic_arc(size);
	tpic_shade(1.0);
	tpic_diamond((int)(size / 1.5));
	return;
}

void tpic_boxcircle(size)
int size; /* need more? circle with black box */
{
	tpic_arc(size);
	tpic_shade(1.0);
	tpic_box((int)(size / 1.5));
	return;
}

void tpic_trianglecircle(size)
int size; /* circle with black triangle */
{
	tpic_arc(size);
	tpic_shade(1.0);
	tpic_triangle((int)(size / 1.5));
	return;
}

void tpic_hexagoncircle(size)
int size; /* how about circle with black hexagon? */
{
	tpic_arc(size);
	tpic_shade(1.0);
	tpic_hexagon((int)(size / 1.2));
	return;
}

void tpic_plustimescircle(size)
int size; /* no more idea ... with plus & times */
{
	tpic_arc(size);
	tpic_plus(size);
	tpic_times(size);
	return;
}

/* private: draw lines */

void tpic_abspath(x,y)
unsigned int x; unsigned int y; /* absolute coord */
{
	fprintf(outfile, "\\put(%u,%u){", x, y); /* start putting */
	tpic_path(0, 0);
	fprintf(outfile, "}%%\n"); /* end putting */
	return;
}

/* private: tpic primitive functions */

void tpic_path(x,y)
int x; int y;
{
	fprintf(outfile, "\\special{pa %d %d}", x, y);
	return;
}

void tpic_flush()
{
	fprintf(outfile, "\\special{fp}%%\n");
	return;
}

void tpic_arc(radius)
int radius; /* actually, draw a full circle */
{
	fprintf(outfile, "\\special{ar 0 0 %d %d 0 7}", radius, radius);
	return;
}

void tpic_shade(grayscale)
double grayscale;
{
	fprintf(outfile, "\\special{sh %f}", grayscale);
	return;
}

void tpic_pen(thickness)
int thickness;
{
	fprintf(outfile, "\\special{pn %d}", thickness);
	return;
}

void tpic_dottedflush(interval)
double interval;
{
	fprintf(outfile, "\\special{dt %f}%%\n", interval);
	return;
}

void tpic_dashedflush(interval)
double interval;
{
	fprintf(outfile, "\\special{da %f}%%\n", interval);
	return;
}

#endif /* TERM_BODY */

#ifdef TERM_TABLE

TERM_TABLE_START(tpic_driver)
    "tpic", "TPIC -- LaTeX picture environment with tpic \\specials",
	   TPIC_XMAX, TPIC_YMAX, TPIC_VCHAR, TPIC_HCHAR, 
	   TPIC_VTIC, TPIC_HTIC, TPIC_options, TPIC_init, TPIC_reset, 
	   TPIC_text, null_scale, TPIC_graphics, TPIC_move, TPIC_vector, 
	   TPIC_linetype, TPIC_put_text, TPIC_text_angle, 
	   TPIC_justify_text, TPIC_point, TPIC_arrow, set_font_null
TERM_TABLE_END(tpic_driver)

#undef LAST_TERM
#define LAST_TERM tpic_driver

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

#ifdef TERM_HELP
START_HELP(tpic)
"1 tpic",
"?set terminal tpic",
"?set term tpic",
"?terminal tpic",
"?term tpic",
"?tpic",
" The `tpic` terminal driver supports the LaTeX picture environment with tpic",
" \\specials.  It is an alternative to the `latex` and `eepic` terminal drivers.",
" Options are the point size, line width, and dot-dash interval.",
"",
" Syntax:",
"       set terminal tpic <pointsize> <linewidth> <interval>",
"",
" where `pointsize` and `linewidth` are integers in milli-inches and `interval`",
" is a float in inches.  If a non-positive value is specified, the default is",
" chosen: pointsize = 40, linewidth = 6, interval = 0.1."
END_HELP(tpic)
#endif