File: latex.trm

package info (click to toggle)
gnuplot 6.0.2%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 14,936 kB
  • sloc: ansic: 95,319; cpp: 7,590; makefile: 2,470; javascript: 2,328; sh: 1,531; lisp: 664; perl: 304; pascal: 191; tcl: 88; python: 46
file content (1238 lines) | stat: -rw-r--r-- 36,792 bytes parent folder | download | duplicates (3)
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
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
/* Hello, Emacs, this is -*-C-*- */

/* GNUPLOT - latex.trm */

/*[
 * Copyright 1990 - 1993, 1998, 2004
 *
 * 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:
 *   LaTeX pictures (latex).
 *   LaTeX pictures with emTeX specials (emtex).
 *
 * AUTHORS
 *   David Kotz, Russell Lang
 *
 * send your comments or suggestions to (gnuplot-info@lists.sourceforge.net).
 *
 */

/* modified to optimize use of \rule for long lines */
/* TLDC: modified to have nice line types */

/* the following LATEX driver has been modified by
   Russell Lang, eln272v@monu1.cc.monash.oz from the
   GnuTeX 1.3 driver by David Kotz, David.Kotz@Dartmouth.edu.
   Since then it has been further extended by David Kotz.
   EmTeX driver by Russell Lang. */

/*  9 Dec 1992  LATEX_put_text rewritten to handle \\ newlines
                Daniel S. Lewart (d-lewart@uiuc.edu) */

/* Since it took me a little while to figure out what is happening,
 * I may as well write it down.
 *  There are three length scales of interest: inches, points
 * and dots. inches are obvious. points are the usual typesetting
 * thing (ie approx 72 points per inch). This driver works in
 * units of dots, which corresponds to pixels on a 300 DPI printer.
 * We do a \setlength{unitlength}{...pt} to make teX work in
 * terms of dots.  The ... is called LATEX_UNIT in here.
 *   The reason I had to get involved in all of this is because
 * font size (in pts) was not being scaled up by DOTS_PER_POINT
 * - drd, Sept 1996
 */

/* E A Merritt Feb 2007 - change sequence of point types to match
 * PostScript and other terminals. Uses symbols from amssymb package.
 */

/* T.Sefzick Oct 2009 - rotate text when option 'rotated' is given.
 * needs graphics or graphicx package.
 */
#include "driver.h"

#ifdef TERM_REGISTER
register_term(latex)
#ifdef EMTEX
register_term(emtex)
#endif
#endif

#ifdef TERM_PROTO
TERM_PUBLIC void LATEX_options(void);
TERM_PUBLIC void LATEX_init(void);
TERM_PUBLIC void LATEX_graphics(void);
TERM_PUBLIC void LATEX_text(void);
TERM_PUBLIC void LATEX_put_text(unsigned int x, unsigned int y, const char str[]);
TERM_PUBLIC void LATEX_linetype(int linetype);
TERM_PUBLIC void LATEX_move(unsigned int x, unsigned int y);
TERM_PUBLIC void LATEX_point(unsigned int x, unsigned int y, int number);
TERM_PUBLIC void LATEX_vector(unsigned int ux, unsigned int uy);
TERM_PUBLIC void LATEX_arrow(unsigned int sx, unsigned int sy, unsigned int ex, unsigned int ey, int head);
TERM_PUBLIC int LATEX_justify_text(enum JUSTIFY mode);
TERM_PUBLIC int LATEX_text_angle(float ang);
TERM_PUBLIC void LATEX_reset(void);
TERM_PUBLIC void LATEX_fillbox(int style, unsigned int x1, unsigned int y1,
				unsigned int width, unsigned int height);
TERM_PUBLIC int LATEX_make_palette(t_sm_palette *palette);
TERM_PUBLIC void LATEX_set_color(t_colorspec *colorspec);

#ifdef EMTEX
TERM_PUBLIC void EMTEX_init(void);
TERM_PUBLIC void EMTEX_reset(void);
TERM_PUBLIC void EMTEX_text(void);
#endif

#ifdef EEPIC
TERM_PUBLIC void EEPIC_move(unsigned int x, unsigned int y);
TERM_PUBLIC void EEPIC_vector(unsigned int ux, unsigned int uy);
#endif

#define TINY_STEP 0.5		/* tiny steps for high quality lines */

#define LATEX_PTS_PER_INCH (72.27)
#define DOTS_PER_INCH (300)	/* resolution of printer we expect to use */
#define LATEX_UNIT (LATEX_PTS_PER_INCH/DOTS_PER_INCH)	/* dot size in pt */

/* 5 inches wide by 3 inches high (default) */
#define LATEX_XMAX (5*DOTS_PER_INCH)	/* (LATEX_PTS_PER_INCH/LATEX_UNIT*5.0) */
#define LATEX_YMAX (3*DOTS_PER_INCH)	/* (LATEX_PTS_PER_INCH/LATEX_UNIT*3.0) */

#define LATEX_HTIC (5*DOTS_PER_INCH/72)		/* (5 pts) */
#define LATEX_VTIC (5*DOTS_PER_INCH/72)		/* (5 pts) */
#define LATEX_HCHAR (DOTS_PER_INCH*53/10/72)	/* (5.3 pts) */
#define LATEX_VCHAR (DOTS_PER_INCH*11/72)	/* (11 pts) */
#endif


#ifndef TERM_PROTO_ONLY
#ifdef TERM_BODY

static int LATEX_posx;
static int LATEX_posy;
static int LATEX_fontsize = 10;
static char LATEX_font[MAX_ID_LEN+1] = "doc";
static enum JUSTIFY latex_justify = LEFT;
static int latex_angle = 0;
static TBOOLEAN latex_rotate = FALSE;

static TBOOLEAN latex_explicit_size = FALSE;
static size_units latex_explicit_units = INCHES;

/* Default line-drawing character */
/* the definition of plotpoint varies with linetype */
#define LATEX_DOT "\\usebox{\\plotpoint}"
#define LATEX_TINY_DOT "\\rule{1pt}{1pt}"	/* for dots plot style */

/* COLORS */
static TBOOLEAN LATEX_use_color = FALSE; /* LATEX terminal option */
static TBOOLEAN latex_use_color;  /* option used by LATEX_set_color */
static char latex_color[32] = "";
#define LATEX_num_colors 6
static const char * LATEX_lt_colors[] = {
    "red", "green", "blue", "magenta", "cyan", "yellow"
};

/* POINTS */
#define LATEX_POINT_TYPES 15	/* we supply more point types */

static const char * LATEX_points[] = {
    "\\makebox(0,0){$+$}",
    "\\makebox(0,0){$\\times$}",
    "\\makebox(0,0){$\\ast$}",
    "\\raisebox{-.8pt}{\\makebox(0,0){$\\Box$}}",
    "\\makebox(0,0){$\\blacksquare$}",
    "\\makebox(0,0){$\\circ$}",
    "\\makebox(0,0){$\\bullet$}",
    "\\makebox(0,0){$\\triangle$}",
    "\\makebox(0,0){$\\blacktriangle$}",
    "\\makebox(0,0){$\\triangledown$}",
    "\\makebox(0,0){$\\blacktriangledown$}",
    "\\makebox(0,0){$\\lozenge$}",
    "\\makebox(0,0){$\\blacklozenge$}",
    "\\makebox(0,0){$\\heartsuit$}",
    "\\makebox(0,0){$\\spadesuit$}",
};

/* LINES */
static void LATEX_linesize(int linetype);
static float LATEX_size = 0;	/* current thick of line in points */
static float LATEX_lw;
static float LATEX_dotspace = 0;	/* current dotspace of line in points */
#define LATEX_LINE_TYPES 6	/* number of line types below */
#define LATEX_THIN_LINE 0	/* the thinnest solid line type */
static struct {
    float size;			/* size of dot, or thick of line in points */
    float dotspace;		/* inter-dot space in points; 0 for lines */
} LATEX_lines[] =

{
    {0.4, 0.0},			/* thin solid line */
    {0.4, 5.0},			/* thin dotted line */
    {0.8, 0.0},			/* thick solid line */
    {1.0, 5.0},			/* thick dotted line */
    {1.2, 0.0},			/* Thick solid line */
    {1.0, 10.0},		/* thick widely dotted line */
};

/* for drawing dotted and solid lines */
static void LATEX_dot_line(int x1, int x2, int y1, int y2);
static void LATEX_solid_line(int x1, int x2, int y1, int y2);
static void LATEX_rule(int code, double x, double y, double width, double height);
static void LATEX_flushdot(void);
#define LATEX_flushrule() LATEX_rule(2, 0.,0.,0.,0.)	/* flush old rule */
static TBOOLEAN LATEX_moved = TRUE;	/* pen is up after move */
static float LATEX_dotsize;	/* size of LATEX_DOT in units */
static TBOOLEAN LATEX_needsdot = FALSE;		/* does dotted line need termination? */

#ifdef EMTEX
static TBOOLEAN emtex = FALSE;		/* not currently using emtex */
static void EMTEX_solid_line(int x1, int x2, int y1, int y2);
#endif

/* ARROWS */
/* the set of non-vertical/non-horizontal LaTeX vector slopes */
/* except negatives - they are handled specially */
static struct vslope {
    int dx, dy;
} LATEX_slopes[] =

{
    {1, 1},
    {1, 2},
    {1, 3},
    {1, 4},
    {2, 1},
    {2, 3},
    {3, 1},
    {3, 2},
    {3, 4},
    {4, 1},
    {4, 3},
    {0, 0}			/* terminator */
};

/* figure out the best arrow */
static void best_latex_arrow(int, int, int, int, int, int);

enum LATEX_id {
    LATEX_COURIER, LATEX_ROMAN, LATEX_DEFAULT,
    LATEX_SIZE,
    LATEX_ROTATE, LATEX_NOROTATE,
    LATEX_COLOR, LATEX_MONOCHROME,
    LATEX_OTHER
};

static struct gen_table LATEX_opts[] =
{
    { "c$ourier", LATEX_COURIER },
    { "r$oman", LATEX_ROMAN },
    { "d$efault", LATEX_DEFAULT },
    { "si$ze", LATEX_SIZE },
    { "rot$ate", LATEX_ROTATE },
    { "no$rotate", LATEX_NOROTATE },
    { "color", LATEX_COLOR },
    { "colour", LATEX_COLOR },
    { "mono$chrome", LATEX_MONOCHROME },
    { NULL, LATEX_OTHER }
};


TERM_PUBLIC void
LATEX_options()
{
    latex_explicit_size = FALSE;

    while (!END_OF_COMMAND) {
	switch(lookup_table(&LATEX_opts[0],c_token)) {
	case LATEX_COURIER:
	    strcpy(LATEX_font, "cmtt");
	    c_token++;
	    break;
	case LATEX_ROMAN:
	    strcpy(LATEX_font, "cmr");
	    c_token++;
	    break;
	case LATEX_DEFAULT:
	    strcpy(LATEX_font, "doc");
	    c_token++;
	    break;
	case LATEX_SIZE: {
	    float xmax_t = 5., ymax_t = 3.;
	    c_token++;
	    latex_explicit_size = TRUE;
	    latex_explicit_units = parse_term_size(&xmax_t, &ymax_t, INCHES);
	    term->xmax = xmax_t * DOTS_PER_INCH/72;
	    term->ymax = ymax_t * DOTS_PER_INCH/72;
	    break;
	}
	case LATEX_ROTATE:
	    latex_rotate = TRUE;
	    c_token++;
	    break;
	case LATEX_NOROTATE:
	    latex_rotate = FALSE;
	    c_token++;
	    break;
	case LATEX_COLOR:
	    LATEX_use_color = TRUE;
	    term->flags &= ~TERM_MONOCHROME;
	    c_token++;
	    break;
	case LATEX_MONOCHROME:
	    LATEX_use_color = FALSE;
	    term->flags |= TERM_MONOCHROME;
	    c_token++;
	    break;
	case LATEX_OTHER:
	default:
	    if (isanumber(c_token)) {
		LATEX_fontsize = int_expression();
		if (LATEX_fontsize <= 1)
		    LATEX_fontsize = 10;
		break;
	    }
	    int_error(c_token, "unrecognized option");
	}
    }

    /* tell gnuplot core about char. sizes. Horizontal spacing
     * is about half the text pointsize
     */
    term->v_char = (unsigned int) (LATEX_fontsize * DOTS_PER_INCH / 72);
    term->h_char = (unsigned int) (LATEX_fontsize * DOTS_PER_INCH / 144);

    if (strcmp(LATEX_font, "doc")==0)
	sprintf(term_options, "(document specific font) %d", LATEX_fontsize);
    else
	sprintf(term_options, "%s %d",
		LATEX_font[2] == 't' ? "courier" : "roman", LATEX_fontsize);

    if (latex_explicit_size) {
	if (latex_explicit_units == CM)
	    sprintf(&(term_options[strlen(term_options)]), "size %.2fcm, %.2fcm ",
		2.54*(float)term->xmax/(DOTS_PER_INCH),
		2.54*(float)term->ymax/(DOTS_PER_INCH));
	else
	    sprintf(&(term_options[strlen(term_options)]), "size %.2fin, %.2fin ",
		(float)term->xmax/(DOTS_PER_INCH),
		(float)term->ymax/(DOTS_PER_INCH));
    }

    if (latex_rotate) {
	sprintf(&(term_options[strlen(term_options)]), " rotate");
    } else {
	sprintf(&(term_options[strlen(term_options)]), " norotate");
    }

    if (LATEX_use_color) {
	sprintf(&(term_options[strlen(term_options)]), " color");
    } else {
	sprintf(&(term_options[strlen(term_options)]), " monochrome");
    }
}


TERM_PUBLIC void
LATEX_init()
{
#ifdef EMTEX
    emtex = FALSE;
#endif
    LATEX_posx = LATEX_posy = 0;
    latex_use_color = LATEX_use_color;

    fprintf(gpoutfile, "\
%% GNUPLOT: LaTeX picture\n\
\\setlength{\\unitlength}{%fpt}\n\
\\ifx\\plotpoint\\undefined\\newsavebox{\\plotpoint}\\fi\n",
	    LATEX_UNIT);

    LATEX_linetype(LT_AXIS);
    LATEX_size = 0;
}

TERM_PUBLIC void
LATEX_graphics()
{
    int xscale, yscale;

    /* set size of canvas */
    if (!latex_explicit_size) {
	term->xmax = LATEX_XMAX;
	term->ymax = LATEX_YMAX;
    }

    /* bounding box */
    xscale = xsize * term->xmax;
    yscale = ysize * term->ymax;

    fprintf(gpoutfile, "\\begin{picture}(%d,%d)(0,0)\n", xscale, yscale);
    if (strcmp(LATEX_font, "doc") != 0) {
        fprintf(gpoutfile, "\
\\font\\gnuplot=%s10 at %dpt\n\
\\gnuplot\n",
		LATEX_font, LATEX_fontsize);
    }
    LATEX_lw = 1;
    latex_color[0] = 0;
}


TERM_PUBLIC void
LATEX_text()
{
    LATEX_flushrule();
    LATEX_flushdot();
    fputs("\\end{picture}\n", gpoutfile);
    LATEX_posx = LATEX_posy = 0;	/* current position */
    LATEX_moved = TRUE;		/* pen is up after move */
}


static void
LATEX_linesize(int linetype)
{
    float size;

    if (linetype >= LATEX_LINE_TYPES)
	linetype %= LATEX_LINE_TYPES;

#ifdef EMTEX
    if (!emtex)
#endif
	LATEX_flushrule();
    LATEX_flushdot();

    /* Find the new desired line thickness. */
    /* negative linetypes (for axes) use a thin line */
    size = (linetype >= 0 ? LATEX_lines[linetype].size
	    : LATEX_lines[LATEX_THIN_LINE].size);
    size *= LATEX_lw;

    /* If different from current size, redefine \plotpoint */
    if (size != LATEX_size) {
	fprintf(gpoutfile,
		"\\sbox{\\plotpoint}{\\rule[%.3fpt]{%.3fpt}{%.3fpt}}%%\n",
		-size / 2, size, size);
#ifdef EMTEX
	if (emtex)		/* change line width */
	    fprintf(gpoutfile, "\\special{em:linewidth %.1fpt}%%\n", size);
#endif
    }
    LATEX_size = size;
    LATEX_dotsize = size / LATEX_UNIT;
    LATEX_dotspace = (linetype >= 0) ? LATEX_lines[linetype].dotspace : 0;
    LATEX_moved = TRUE;		/* reset */
}


TERM_PUBLIC void
LATEX_linetype(int linetype)
{
    t_colorspec colorspec;

    /* save values for set_color */
    colorspec.type = TC_LT;
    colorspec.lt = linetype;

    LATEX_linesize(linetype);
    LATEX_set_color(&colorspec);
}


TERM_PUBLIC void
LATEX_linewidth(double linewidth)
{
    LATEX_lw = linewidth;
}


TERM_PUBLIC void
LATEX_move(unsigned int x, unsigned int y)
{
    LATEX_flushdot();

    LATEX_posx = x;
    LATEX_posy = y;
    LATEX_moved = TRUE;		/* reset */
}


TERM_PUBLIC void
LATEX_point(unsigned int x, unsigned int y, int number)
{
    LATEX_move(x, y);

    /* Print the character defined by 'number'; number < 0 means
       to use a dot, otherwise one of the defined points. */
    fprintf(gpoutfile, "\\put(%d,%d){%s}\n", x, y,
	    (number < 0 ? LATEX_TINY_DOT
	     : LATEX_points[number % LATEX_POINT_TYPES]));
}


TERM_PUBLIC void
LATEX_vector(unsigned int ux, unsigned int uy)
{
    if (LATEX_dotspace == 0.0) {
	/* solid line */
#ifdef EMTEX
	if (emtex)
	    EMTEX_solid_line(LATEX_posx, (int) ux, LATEX_posy, (int) uy);
	else
#endif
	    LATEX_solid_line(LATEX_posx, (int) ux, LATEX_posy, (int) uy);
    } else
	/* dotted line */
	LATEX_dot_line(LATEX_posx, (int) ux, LATEX_posy, (int) uy);

    LATEX_posx = ux;
    LATEX_posy = uy;
}

static void
LATEX_solid_line(int x1, int x2, int y1, int y2)
{
    float slope;
    int inc;
    float dx, dy, x, y;
    float offset, length;
    int code;			/* possibly combine with previous rule */

    /* We draw a solid line using the current line thickness (size). */
    /* If the rotate option is not active, we do it with lots of \rules, */
    /* otherwise we use a single \rule and \rotatebox. */

    if (x1 == x2 && y1 == y2) {	/* zero-length line - just a dot */
	if (LATEX_moved) {
	    LATEX_flushrule();
	    /* plot a dot */
	    fprintf(gpoutfile, "\\put(%u,%u){%s}\n", x1, y1, LATEX_DOT);
	}
    } else {
	code = (LATEX_moved ? 0 : 1);	/* no combine after move */
	LATEX_moved = FALSE;
	if (x1 == x2)		/* vertical line - special case */
	    LATEX_rule(code, (double) x1, (double) y1,
		       LATEX_dotsize, (double) y2 - y1);
	else if (y1 == y2)	/* horizontal line - special case */
	    LATEX_rule(code, (double) x1, (double) y1,
		       (double) x2 - x1, LATEX_dotsize);
	else {
	    dx = (float) x2 - x1;
	    dy = (float) y2 - y1;
	    slope = dy / dx;

	    /* Draw a line with the correct angle by rotating a \rule.
	       This yields much better results, but requires driver
	       \specials, which are available with both ps and pdf
	       output.  According to a suggestion by Mojca Miklavec.
	     */
	    if (latex_rotate) {
		double angle;
		double length;

		// Only works for angles -90...90, but I not understand why.
		if (x2 < x1) {
		    x = x1; x1 = x2; x2 = x; dx *= -1;
		    y = y1; y1 = y2; y2 = y; dy *= -1;
		}
		angle = atan2(dy, dx) / DEG2RAD;
		if (angle < 0)
		    angle += 360;
		length = sqrt(dx * dx + dy * dy) + 1;

		fprintf(gpoutfile,
		    "\\put(%.1f,%.1f){" \
			"\\rotatebox{%.2f}{" \
			    "\\rule[%.3fpt]{%.3fpt}{%.3fpt}" \
		    "}}\n",
		    (double) x1, // - dx/length * LATEX_dotsize / 2,
		    (double) y1, // - dy/length * LATEX_dotsize / 2,
		    angle, - LATEX_dotsize * LATEX_UNIT / 2,
		    length * LATEX_UNIT,
		    LATEX_dotsize * LATEX_UNIT);
		return;
	    }

	    if (ABS(slope) <= 1.0) {
		/* longer than high */
		x = GPMIN(ABS(dx), (0.25 + 1.0 / ABS(slope)) * LATEX_dotsize);
		offset = sign(dy) * GPMIN(LATEX_dotsize, ABS(dy));
		dy = dy - offset;
		length = x * LATEX_UNIT;
		inc = (x == ABS(dx) ? 1 : GPMAX(1, ABS(dy) / TINY_STEP + 0.5));
		if (inc == 1) {
		    fprintf(gpoutfile, "\\put(%u,%.2f){\\rule{%.3fpt}{%.3fpt}}\n",
			    (x2 >= x1 ? x1 : x2), ((float) y1 + y2 - LATEX_dotsize) / 2,
			    length, LATEX_dotsize * LATEX_UNIT);
		} else {
		    dy = dy / inc;
		    dx = (dx - sign(dx) * x) / (inc - 1);
		    fprintf(gpoutfile,
			    "\\multiput(%.2f,%.2f)(%.3f,%.3f){%u}{\\rule{%.3fpt}{%.3fpt}}\n",
			    (dx >= 0.0 ? (float) x1 : x1 - x),
			    (float) y1 - (ABS(dy) - offset) / 2,
			    dx, dy, inc, length, ABS(dy) * LATEX_UNIT);
		}
/* done with one section, now smooth it */
		x = x / 2;
		dx = sign(dx) * x;
		dx = (float) x2 - x1 - dx;
		dy = (float) y2 - y1;
		fprintf(gpoutfile, "\\multiput(%.2f,%.2f)(%.3f,%.3f){2}{\\rule{%.3fpt}{%.3fpt}}\n",
			(dx >= 0.0 ? (float) x1 : x1 - x), (float) y1 - LATEX_dotsize / 2,
			dx, dy, x * LATEX_UNIT, LATEX_dotsize * LATEX_UNIT);
		LATEX_moved = TRUE;
	    } else {
		/* higher than long */
		y = GPMIN(ABS(dy), (0.25 + ABS(slope)) * LATEX_dotsize);
		offset = sign(dx) * GPMIN(LATEX_dotsize, ABS(dx));
		dx = dx - offset;
		length = y * LATEX_UNIT;
		inc = (y == ABS(dy) ? 1 : GPMAX(1, ABS(dx) / TINY_STEP + 0.5));
		if (inc == 1) {
		    fprintf(gpoutfile, "\\put(%.2f,%u){\\rule{%.3fpt}{%.3fpt}}\n",
			    ((float) x1 + x2 - LATEX_dotsize) / 2, (y2 >= y1 ? y1 : y2),
			    LATEX_dotsize * LATEX_UNIT, length);
		} else {
		    dx = dx / inc;
		    dy = (dy - sign(dy) * y) / (inc - 1);
		    fprintf(gpoutfile,
			    "\\multiput(%.2f,%.2f)(%.3f,%.3f){%u}{\\rule{%.3fpt}{%.3fpt}}\n",
			    (float) x1 - (ABS(dx) - offset) / 2,
			    (dy >= 0 ? (float) y1 : y1 - y),
			    dx, dy, inc, ABS(dx) * LATEX_UNIT, length);
		}
/* done with one section, now smooth it */
		y = y / 2;
		dx = (float) x2 - x1;
		dy = sign(dy) * y;
		dy = (float) y2 - y1 - dy;
		fprintf(gpoutfile, "\\multiput(%.2f,%.2f)(%.3f,%.3f){2}{\\rule{%.3fpt}{%.3fpt}}\n",
			(float) x1 - LATEX_dotsize / 2, (dy >= 0.0 ? (float) y1 : y1 - y),
			dx, dy, LATEX_dotsize * LATEX_UNIT, y * LATEX_UNIT);
		LATEX_moved = TRUE;
	    }
	}
    }
}

/* Draw a \rule. Width or height may be negative; we can correct.
 * The rule is never output immediately. The previous rule is output
 * as-is if code is 0, and the previous rule is
 * combined with the current rule (if possible) if code is 1.
 * The previous rule is output, and the new one ignored, if code is 2.
 */
static void
LATEX_rule(
    int code,			/* how do we treat this rule? */
    double x, double y,
    double width,
    double height)
{
    static float lastx, lasty;
    static float lastw, lasth;
    static TBOOLEAN isvalid = FALSE;	/* is 'last' data valid? */
    TBOOLEAN combine = (code == 1);
    TBOOLEAN flush = (code == 2);

    if (!flush)
	if (width == 0 || height == 0)
	    return;		/* ignore this rule */

    if (isvalid && combine) {
	/* try to combine new rule with old rule */
	if ((int) lastx == (int) x && lastw == width) {		/* vertical rule */
	    if (lasth * height >= 0) {	/* same sign */
		lasth += height;
		return;
	    }
	} else if ((int) lasty == (int) y && lasth == height) {		/* horiz rule */
	    if (lastw * width >= 0) {	/* same sign */
		lastw += width;
		return;
	    }
	}
	/* oh well, output last and remember the new one */
    }
    if (isvalid) {
	/* output the rule */
	if (lastw < 0) {
	    lastx += lastw;
	    lastw = -lastw;
	}
	if (lasth < 0) {
	    lasty += lasth;
	    lasth = -lasth;
	}
	/* if very small use canned dot */
	if (lastw < LATEX_dotsize || lasth < LATEX_dotsize)
	    fprintf(gpoutfile, "\\put(%.1f,%.1f){%s}\n",
		    lastx, lasty, LATEX_DOT);
	else
	    fprintf(gpoutfile, "\\put(%.1f,%.1f){\\rule[%.3fpt]{%.3fpt}{%.3fpt}}\n",
		    lastx, lasty, -LATEX_dotsize * LATEX_UNIT / 2,
		    lastw * LATEX_UNIT, lasth * LATEX_UNIT);
    }
    if (flush) {
	isvalid = FALSE;
    } else {
	lastx = x;
	lasty = y;
	lastw = width;
	lasth = height;
	isvalid = TRUE;
    }
}

static void
LATEX_dot_line(int x1, int x2, int y1, int y2)
{
    static float LATEX_left;	/* fraction of space left after last dot */

    /* we draw a dotted line using the current dot spacing */

    if (LATEX_moved)
	LATEX_left = 1.0;	/* reset after a move */

    /* zero-length line? */
    if (x1 == x2 && y1 == y2) {
	if (LATEX_moved)
	    /* plot a dot */
	    fprintf(gpoutfile, "\\put(%u,%u){%s}\n", x1, y1, LATEX_DOT);
    } else {
	float dotspace = LATEX_dotspace / LATEX_UNIT;
	float x, y;		/* current position */
	float xinc, yinc;	/* increments */
	float slope;		/* slope of line */
	float lastx = -1;	/* last x point plotted */
	float lasty = -1;	/* last y point plotted */
	int numdots = 0;	/* number of dots in this section */

	/* first, figure out increments for x and y */
	if (x2 == x1) {
	    xinc = 0.0;
	    yinc = (y2 - y1 > 0) ? dotspace : -dotspace;
	} else {
	    slope = ((float) y2 - y1) / ((float) x2 - x1);
	    xinc = dotspace / sqrt(1 + slope * slope) * sign(x2 - x1);
	    yinc = slope * xinc;
	}

	/* now draw the dotted line */
	/* we take into account where we last placed a dot */
	for (x = x1 + xinc * (1 - LATEX_left), y = y1 + yinc * (1 - LATEX_left);
	     (x2 - x) * xinc >= 0 && (y2 - y) * yinc >= 0;	/* same sign or zero */
	     lastx = x, x += xinc,
	     lasty = y, y += yinc)
	    numdots++;
	if (numdots == 1)
	    fprintf(gpoutfile, "\\put(%.2f,%.2f){%s}\n",
		    lastx, lasty, LATEX_DOT);
	else if (numdots > 0)
	    fprintf(gpoutfile, "\\multiput(%u,%u)(%.3f,%.3f){%u}{%s}\n",
		    x1, y1, xinc, yinc, numdots, LATEX_DOT);

	/* how much is left over, as a fraction of dotspace? */
	if (xinc != 0.0) {	/* xinc must be nonzero */
	    if (lastx >= 0)
		LATEX_left = ABS(x2 - lastx) / ABS(xinc);
	    else
		LATEX_left += ABS(x2 - x1) / ABS(xinc);
	} else
	    if (lasty >= 0)
		LATEX_left = ABS(y2 - lasty) / ABS(yinc);
	    else
		LATEX_left += ABS(y2 - y1) / ABS(yinc);
    }

    LATEX_needsdot = (LATEX_left > 0);

    LATEX_moved = FALSE;
}

static void
LATEX_flushdot()
{
    if (LATEX_needsdot)
	fprintf(gpoutfile, "\\put(%d,%d){%s}\n",
		LATEX_posx, LATEX_posy, LATEX_DOT);
    LATEX_needsdot = FALSE;
}

TERM_PUBLIC void
LATEX_arrow(
    unsigned int sx, unsigned int sy,
    unsigned int ex, unsigned int ey,
    int head)
{
    best_latex_arrow(sx, sy, ex, ey, 1, head);

    LATEX_posx = ex;
    LATEX_posy = ey;
}

static void
best_latex_arrow(
    int sx, int sy, int ex, int ey, /* start and end points */
    int who,			/* 1=LATEX, 2=EEPIC */
    int head)
{
    int dx = ex - sx;
    int dy = ey - sy;
    float m;			/* slope of line */
    float arrowslope;		/* slope of arrow */
    float minerror = 0;		/* best-case error */
    struct vslope *slope;	/* one of the slopes */
    struct vslope *bestslope;	/* the slope with min error */

    /* We try to draw a real arrow (ie, \vector). If we can't get
       * a slope that is close, we draw a bent arrow.
     */

    if ((head & BOTH_HEADS) == BACKHEAD) {
	/* we need to draw only the backhead,
	  so we exchange start and stop coordinates */
	int tx = ex;
	int ty = ey;
	ex = sx;
	ey = sy;
	sx = tx;
	sy = ty;
	dx *= -1;
	dy *= -1;
	head &= ~BOTH_HEADS;
	head |= END_HEAD;
    }

    if (dx == 0) {
	/* vertical arrow */
	if (head & HEADS_ONLY) {
	    if (head & END_HEAD) /* draw arrow head only */
		fprintf(gpoutfile, "\\put(%d,%d){\\vector(0,%d){0}}\n",
		    ex, ey, sign(ey - sy));
	} else {
	    fprintf(gpoutfile, "\\put(%d,%d){\\%s(0,%d){%d}}\n",
		    sx, sy, head & END_HEAD ? "vector" : "line",
		    sign(ey - sy), ABS(ey - sy));
	}
	if (head & BACKHEAD) {
	    /* overlay a reversed arrow of zero length */
	    fprintf(gpoutfile, "\\put(%d,%d){\\vector(0,%d){0}}\n",
		    sx, sy, -1 * sign(ey - sy));
	}
    } else if (dy == 0) {
	/* horizontal arrow */
	if (head & HEADS_ONLY) {
	    if (head & END_HEAD) /* draw arrow head only */
		fprintf(gpoutfile, "\\put(%d,%d){\\vector(%d,0){0}}\n",
		    ex, ey, sign(ex - sx));
	} else {
	    fprintf(gpoutfile, "\\put(%d,%d){\\%s(%d,0){%d}}\n",
		    sx, sy, head & END_HEAD ? "vector" : "line",
		    sign(ex - sx), ABS(ex - sx));
	}
	if (head & BACKHEAD) {
	    /* overlay a reversed arrow of zero length */
	    fprintf(gpoutfile, "\\put(%d,%d){\\vector(%d,0){0}}\n",
		    sx, sy, -1 * sign(ex - sx));
	}
    } else {
	/* Slanted arrow. We'll give it a try.
	 * we try to find the closest-slope arrowhead.
	 */
	bestslope = NULL;
	minerror = 0;		/* to shut up turbo C */
	m = ABS((float) dy / dx);	/* the slope we want */
	for (slope = LATEX_slopes; slope->dx != 0.0; slope++) {
	    /* find the slope of the arrow */
	    arrowslope = (float) slope->dy / slope->dx;
	    if (bestslope == NULL || ABS(m - arrowslope) < minerror) {
		minerror = ABS(m - arrowslope);
		bestslope = slope;
	    }
	}

	/* now we have the best slope arrow */
	/* maybe it's exactly the right slope! */
	if (minerror == 0.0) {	/* unlikely but possible */
	    if (head & HEADS_ONLY) {
		if (head & END_HEAD) /* draw arrow head only */
		    fprintf(gpoutfile, "\\put(%d,%d){\\vector(%d,%d){0}}\n",
			ex, ey,
			bestslope->dx * sign(ex - sx), bestslope->dy * sign(ey - sy));
	    } else {
		fprintf(gpoutfile, "\\put(%d,%d){\\%s(%d,%d){%d}}\n",
			sx, sy, head ? "vector" : "line",
			bestslope->dx * sign(ex - sx), bestslope->dy * sign(ey - sy),
			ABS(ex - sx));
	    }
	    if (head & BACKHEAD) {
		fprintf(gpoutfile, "\\put(%d,%d){\\vector(%d,%d){0}}\n",
			sx, sy,
			-1 * bestslope->dx * sign(ex - sx), -1 * bestslope->dy * sign(ey - sy));
	    }
	} else {
	    /* we draw the line the usual way, with thin lines */
	    if ((head & HEADS_ONLY) == 0) {
#ifdef EMTEX
		if (emtex) {
		    LATEX_linesize(LATEX_THIN_LINE);
		    EMTEX_solid_line(sx, ex, sy, ey);
		} else
#endif
		if (who == 1) {
		    LATEX_linesize(LATEX_THIN_LINE);
		    LATEX_solid_line(sx, ex, sy, ey);
		}
#ifdef EEPIC
		else {
		    EEPIC_move(sx, sy);
		    EEPIC_vector(ex, ey);
		}
#endif /* EEPIC */
	    }
	    /* and then draw arrowheads (a short vector) there */
	    if (head & END_HEAD) {
		fprintf(gpoutfile, "\\put(%d,%d){\\vector(%d,%d){0}}\n",
			ex, ey,
			bestslope->dx * sign(ex - sx), bestslope->dy * sign(ey - sy));
	    }
	    if (head & BACKHEAD) {
		fprintf(gpoutfile, "\\put(%d,%d){\\vector(%d,%d){0}}\n",
			sx, sy,
			-1 * bestslope->dx * sign(ex - sx), -1 * bestslope->dy * sign(ey - sy));
	    }
	}
    }
}

TERM_PUBLIC void
LATEX_put_text(unsigned int x, unsigned int y, const char str[])
{
    static const char *justify[] = { "[l]", "", "[r]" };

    /* ignore empty strings */
    if (str[0] == NUL)
	return;

    fprintf(gpoutfile, "\\put(%d,%d)", x, y);
    if (latex_rotate && latex_angle)
	fprintf(gpoutfile, "{\\rotatebox{%d}", latex_angle);
    if ((str[0] == '{') || (str[0] == '['))
	fprintf(gpoutfile, "{\\makebox(0,0)%s}", str);
    else if (!latex_rotate && strstr(str, "\\") !=  NULL)
	fprintf(gpoutfile, "{\\makebox(0,0)%s{\\shortstack{%s}}}",
		justify[latex_justify], str);
    else
	fprintf(gpoutfile, "{\\makebox(0,0)%s{%s}}",
		justify[latex_justify], str);
    if (latex_rotate && latex_angle)
	fputs("}", gpoutfile);
    fputs("\n", gpoutfile);
}

TERM_PUBLIC int
LATEX_justify_text(enum JUSTIFY mode)
{
    latex_justify = mode;
    return (TRUE);
}

TERM_PUBLIC int
LATEX_text_angle(float ang)
{
    /* Without the rotate option, we can't write text vertically,
       but we will put the ylabel centred at the left of the plot,
       and then we'll make a \shortstack.  With the rotate option,
       we do 'real' text rotation using '\rotatebox'. */
    latex_angle = ang;
    return (TRUE);
}

TERM_PUBLIC void
LATEX_reset()
{
    LATEX_posx = LATEX_posy = 0;	/* current position */
    LATEX_moved = TRUE;		/* pen is up after move */
}


TERM_PUBLIC void
LATEX_fillbox(int style, unsigned int x1, unsigned int y1, unsigned
int width, unsigned int height)
{
    /* TODO: Something other than black/white */
    if ((style & 0xf) == FS_EMPTY)
	return;
    if ((style & 0xf) == FS_SOLID && (style >> 4) < 50)
	return;
    if ((style & 0xf) == FS_PATTERN && ((style >> 4) & 1) == 0)
	return;

    fprintf(gpoutfile, "\\put(%d,%d){\\rule{%gpt}{%gpt}}\n", x1, y1,
	    width*LATEX_UNIT, height*LATEX_UNIT);
}


TERM_PUBLIC int
LATEX_make_palette(t_sm_palette *palette)
{
    return 0;  /* we can do continuous colors */
}


TERM_PUBLIC void
LATEX_set_color(t_colorspec *colorspec)
{
    char colorstr[32];

    if (!latex_use_color)
	return;

    switch (colorspec->type) {
    case TC_RGB: {
	double r = (double)((colorspec->lt >> 16 ) & 255) / 255.;
	double g = (double)((colorspec->lt >> 8 ) & 255) / 255.;
	double b = (double)(colorspec->lt & 255) / 255.;

	snprintf(colorstr, sizeof(colorstr), "\\color[rgb]{%3.2f,%3.2f,%3.2f}\n", r, g, b);
	break;
    }
    case TC_LT: {
	int linetype = colorspec->lt;
	const char * colorname;

	if (linetype == LT_BACKGROUND)
	    colorname = "white";
	else if (linetype < 0 || !latex_use_color)
	    colorname = "black";
	else
	    colorname = LATEX_lt_colors[linetype % LATEX_num_colors];
	snprintf(colorstr, sizeof(colorstr), "\\color{%s}\n", colorname);
	break;
    }
    case TC_FRAC: {
	rgb_color color;

	rgb1_from_gray(colorspec->value, &color);
	snprintf(colorstr, sizeof(colorstr), "\\color[rgb]{%3.2f,%3.2f,%3.2f}\n", color.r, color.g, color.b);
	break;
    }
    default:
	break;
    }

    if (strcmp(colorstr, latex_color) != 0) {
	strcpy(latex_color, colorstr);
	if (latex_use_color)
	    fputs(colorstr, gpoutfile);
    }
}


#ifdef EMTEX

TERM_PUBLIC void
EMTEX_init()
{
    emtex = TRUE;
    LATEX_posx = LATEX_posy = 0;
    fprintf(gpoutfile, "\
%% GNUPLOT: LaTeX picture with emtex specials\n\
\\setlength{\\unitlength}{%fpt}\n\
\\ifx\\plotpoint\\undefined\\newsavebox{\\plotpoint}\\fi\n",
	    LATEX_UNIT);
    LATEX_linetype(LT_AXIS);
}


TERM_PUBLIC void
EMTEX_reset()
{
    emtex = FALSE;
    LATEX_posx = LATEX_posy = 0;
}


TERM_PUBLIC void
EMTEX_text()
{
    fputs("\\end{picture}\n", gpoutfile);
}


static void
EMTEX_solid_line(int x1, int x2, int y1, int y2)
{
    /* emtex special solid line */
    if (LATEX_moved)
	fprintf(gpoutfile, "\\put(%d,%d){\\special{em:moveto}}\n", x1, y1);
    if ((x1 != x2) || (y1 != y2))
	fprintf(gpoutfile, "\\put(%d,%d){\\special{em:lineto}}\n", x2, y2);
    LATEX_posx = x2;
    LATEX_posy = y2;
    LATEX_moved = FALSE;
}


#endif /* EMTEX */

#endif /* TERM_BODY */
#endif /* TERM_PROTO_ONLY */

#ifdef TERM_TABLE

TERM_TABLE_START(latex_driver)
    "latex", "LaTeX picture environment",
    LATEX_XMAX, LATEX_YMAX, LATEX_VCHAR, LATEX_HCHAR,
    LATEX_VTIC, LATEX_HTIC, LATEX_options, LATEX_init, LATEX_reset,
    LATEX_text, null_scale, LATEX_graphics, LATEX_move, LATEX_vector,
    LATEX_linetype, LATEX_put_text, LATEX_text_angle,
    LATEX_justify_text, LATEX_point, LATEX_arrow, set_font_null,
    NULL, /* pointsize */
    TERM_IS_LATEX | TERM_MONOCHROME, /* flags */
    NULL, NULL, /* suspend, resume */
    LATEX_fillbox, LATEX_linewidth,
#ifdef USE_MOUSE
    NULL, NULL, NULL, NULL, NULL,
#endif
    LATEX_make_palette, 0,
    LATEX_set_color
TERM_TABLE_END(latex_driver)

#undef LAST_TERM
#define LAST_TERM latex_driver


#ifdef EMTEX
TERM_TABLE_START(emtex_driver)
    "emtex", "LaTeX picture environment with emTeX specials",
    LATEX_XMAX, LATEX_YMAX, LATEX_VCHAR, LATEX_HCHAR,
    LATEX_VTIC, LATEX_HTIC, LATEX_options, EMTEX_init, EMTEX_reset,
    EMTEX_text, null_scale, LATEX_graphics, LATEX_move, LATEX_vector,
    LATEX_linetype, LATEX_put_text, LATEX_text_angle,
    LATEX_justify_text, LATEX_point, LATEX_arrow, set_font_null,
    NULL, /* pointsize */
    TERM_IS_LATEX | TERM_MONOCHROME, /* flags */
    NULL, NULL, /* suspend, resume */
    LATEX_fillbox, LATEX_linewidth,
#ifdef USE_MOUSE
    NULL, NULL, NULL, NULL, NULL,
#endif
    LATEX_make_palette, 0,
    LATEX_set_color
TERM_TABLE_END(emtex_driver)

#undef LAST_TERM
#define LAST_TERM emtex_driver

#endif /* EMTEX */
#endif /* TERM_TABLE */


#ifdef TERM_HELP
START_HELP(latex)
"1 latex",
"?commands set terminal emtex",
"?set terminal emtex",
"?set term emtex",
"?terminal emtex",
"?term emtex",
"?emtex",
"?commands set terminal latex",
"?set terminal latex",
"?set term latex",
"?terminal latex",
"?term latex",
"?latex",
" Note: Legacy terminal (not built by default).",
" The latex, emtex, eepic, and tpic terminals in older versions of gnuplot",
" provided minimal support for graphics styles beyond simple lines and points.",
" They have been directly superseded by the `pict2e` terminal.",
" For more capable TeX/LaTeX compatible terminal types see",
" `cairolatex`, `context`, `epslatex`, `mp`, `pstricks`, and `tikz`.",
"",
" Syntax:",
"       set terminal {latex | emtex} {default | {courier|roman} {<fontsize>}}",
"                    {size <XX>{unit}, <YY>{unit}} {rotate | norotate}",
"                    {color | monochrome}",
"",
" By default the plot will inherit font settings from the embedding document.",
" You have the option of forcing either Courier (cmtt) or Roman (cmr) fonts",
" instead. In this case you may also specify a fontsize.",
" Unless your driver is capable of building fonts at any size (e.g. dvips),",
" stick to the standard 10, 11 and 12 point sizes.",
"",
" METAFONT users beware: METAFONT does not like odd sizes.",
"",
" All drivers for LaTeX offer a special way of controlling text positioning:",
" If any text string begins with '{', you also need to include a '}' at the",
" end of the text, and the whole text will be centered both horizontally and",
" vertically.  If the text string begins with '[', you need to follow this with",
" a position specification (up to two out of t,b,l,r), ']{', the text itself,",
" and finally '}'.  The text itself may be anything LaTeX can typeset as an",
" LR-box.  '\\rule{}{}'s may help for best positioning.",
"",
" Points, among other things, are drawn using the LaTeX commands \"\\Diamond\" and",
" \"\\Box\".  These commands no longer belong to the LaTeX2e core; they are included",
" in the latexsym package, which is part of the base distribution and thus part",
" of any LaTeX implementation.  Please do not forget to use this package.",
" Other point types use symbols from the amssymb package.",
"",
" The default size for the plot is 5 inches by 3 inches. The `size` option",
" changes this to whatever the user requests. By default the X and Y sizes",
" are taken to be in inches, but other units are possible (currently only cm).",
"",
" If `rotate` is specified, rotated text, especially a rotated y-axis label,",
" is possible (the packages graphics or graphicx are needed). The 'stacked'",
" y-axis label mechanism is then deactivated. This will also significantly",
" improve the quality of line drawing, and is default since version 5.3.",
"",
" The option `color` enables color, while `monochrome` uses only black and white",
" drawing elements. You need to load the color or xcolor package in the preamble",
" of your latex document.",
"",
" Examples:",
" About label positioning:",
" Use gnuplot defaults (mostly sensible, but sometimes not really best):",
"        set title '\\LaTeX\\ -- $ \\gamma $'",
" Force centering both horizontally and vertically:",
"        set label '{\\LaTeX\\ -- $ \\gamma $}' at 0,0",
" Specify own positioning (top here):",
"        set xlabel '[t]{\\LaTeX\\ -- $ \\gamma $}'",
" The other label -- account for long ticlabels:",
"        set ylabel '[r]{\\LaTeX\\ -- $ \\gamma $\\rule{7mm}{0pt}}'"
END_HELP(latex)
#endif /* TERM_TABLE */