The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
/*
 * $Id: pslatex.trm,v 1.35 2002/07/26 16:42:29 mikulik Exp $
 */

/* GNUPLOT - pslatex.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 file supplies the terminal drivers:
 *     pslatex --latex with embedded postscript
 *     pstex   --plain TeX with embedded postscript
 *
 * AUTHORS
 *  George Phillips
 *  Russell Lang
 *  David Kotz
 * 
 *  Petr Mikulik, May 2000: terminal entries for PM3D functionality
 *
 * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
 */

#include "driver.h"

#ifdef TERM_REGISTER
register_term(pslatex)
register_term(pstex)
#endif

#ifdef TERM_PROTO
TERM_PUBLIC void PSLATEX_options __PROTO((void));
TERM_PUBLIC void PSLATEX_init __PROTO((void));
TERM_PUBLIC void PSLATEX_graphics __PROTO((void));
TERM_PUBLIC void PSLATEX_put_text __PROTO((unsigned int x, unsigned int y, const char str[]));
TERM_PUBLIC int PSLATEX_justify_text __PROTO((enum JUSTIFY mode));
TERM_PUBLIC int PSLATEX_text_angle __PROTO((int ang));
TERM_PUBLIC void PSLATEX_reset __PROTO((void));
TERM_PUBLIC void PSLATEX_text __PROTO((void));
TERM_PUBLIC void PSLATEX_move __PROTO((unsigned int x, unsigned int y));
TERM_PUBLIC void PSLATEX_vector __PROTO((unsigned int x, unsigned int y));
TERM_PUBLIC void PSLATEX_linetype __PROTO((int lt));
TERM_PUBLIC void PSLATEX_point __PROTO((unsigned int x, unsigned int y, int number));
TERM_PUBLIC void PSLATEX_pointsize __PROTO((double size));
TERM_PUBLIC void PSLATEX_linewidth __PROTO((double width));
#ifdef PM3D
TERM_PUBLIC int PSLATEX_make_palette (t_sm_palette *);
TERM_PUBLIC void PSLATEX_previous_palette (void);
TERM_PUBLIC void PSLATEX_set_color (double);
TERM_PUBLIC void PSLATEX_filled_polygon (int, gpiPoint *);
#endif

#define PSLATEX_XMAX (5*720)
#define PSLATEX_YMAX (3*720)

/* 10 pt char is about 10 pts high (say) */
#define PSLATEX_VCHAR (100)
/* 10 pt char is about 6 pts wide (say) */
/* I find about 5 points (output from test) - div */
#define PSLATEX_HCHAR (50)
#define GOT_PSLATEX_PROTO
#endif

#ifndef TERM_PROTO_ONLY

#ifdef TERM_BODY

#include "post.h"

static int PSLATEX_angle;
static int PSLATEX_justify;
static int PSLATEX_rotate = TRUE;

/* do we write two files? */
static TBOOLEAN PSLATEX_useAuxFile = FALSE;
/* name of auxiliary file */
static char *PSLATEX_auxname;
/* FILE * to auxiliary file */
static FILE *PSLATEX_auxfile;

static TBOOLEAN PSLATEX_output = TRUE;	/* do we write LaTeX? */
static int PSLATEX_fontsize = 0;

struct text_command {
    int x, y, angle, justify;
    char *label;
    struct text_command *next;
};

static struct text_command *PSLATEX_labels;

enum PSLATEX_id {
    PSLATEX_DEFAULT, PSLATEX_COLOR, PSLATEX_MONOCHROME,
    PSLATEX_SOLID, PSLATEX_DASHED, PSLATEX_ROTATE, PSLATEX_NOROTATE,
    PSLATEX_AUXFILE,
    PSLATEX_OTHER
};

static struct gen_table PSLATEX_opts[] =
{
    { "d$efault", PSLATEX_DEFAULT },
    { "c$olor", PSLATEX_COLOR },
    { "c$olour", PSLATEX_COLOR },
    { "m$onochrome", PSLATEX_MONOCHROME },
    { "so$lid", PSLATEX_SOLID },
    { "da$shed", PSLATEX_DASHED },
    { "r$otate", PSLATEX_ROTATE },
    { "n$orotate", PSLATEX_NOROTATE },
    { "a$uxfile", PSLATEX_AUXFILE },
    { NULL, PSLATEX_OTHER }
};

TERM_PUBLIC void
PSLATEX_options()
{
    struct value a;

    while (!END_OF_COMMAND) {
	switch(lookup_table(&PSLATEX_opts[0],c_token)) {
	case PSLATEX_DEFAULT:
	    ps_color = FALSE;
	    ps_solid = FALSE;
	    PSLATEX_rotate = TRUE;
	    PSLATEX_useAuxFile = FALSE;
	    c_token++;
	    break;
	case PSLATEX_COLOR:
	    ps_color = TRUE;
	    c_token++;
	    break;
	case PSLATEX_MONOCHROME:
	    ps_color = FALSE;
	    c_token++;
	    break;
	case PSLATEX_SOLID:
	    ps_solid = TRUE;
	    c_token++;
	    break;
	case PSLATEX_DASHED:
	    ps_solid = FALSE;
	    c_token++;
	    break;
	case PSLATEX_ROTATE:
	    PSLATEX_rotate = TRUE;
	    c_token++;
	    break;
	case PSLATEX_NOROTATE:
	    PSLATEX_rotate = FALSE;
	    c_token++;
	    break;
	case PSLATEX_AUXFILE:
	    PSLATEX_useAuxFile = TRUE;
	    c_token++;
	    break;
	case PSLATEX_OTHER:
	default:
	    /* We have font size specified */
	    /* Copied from latex.trm */
	    PSLATEX_fontsize = (int) real(const_express(&a));
	    term->v_char = (unsigned int) (PSLATEX_fontsize * DOTS_PER_INCH / 60);
	    term->h_char = (unsigned int) (PSLATEX_fontsize * DOTS_PER_INCH / 120);
	    break;
	}
    }

    /* be sure to generate an options string that PSLATEX_init understands */

    sprintf(term_options, "%s %s %s%s",
	    ps_color ? "color" : "monochrome",
	    ps_solid ? "solid" : "dashed",
	    PSLATEX_rotate ? "rotate" : "norotate",
	    PSLATEX_useAuxFile ? " auxfile" : "");
    if (PSLATEX_fontsize) {
      char fs[8] = "";
      sprintf(fs," %d", PSLATEX_fontsize);
      strcat(term_options, fs);
    }
}

TERM_PUBLIC void
PSLATEX_init()
{
    char *dotIndex;

    if (strcmp(term->name, "pstex") == 0)
	PSLATEX_output = FALSE;

    /* until we know otherwise */
    /* this looks pretty fishy; what if the file _is_ open?? lh */
    PSLATEX_auxfile = NULL;

    /* Review this; lh */
    /* dont tweak PSLATEX_useAuxFile if we decide we cannot comply
     * since this affects subsequent plots even after a set out
     * Instead, we will use PSLATEX_auxfile != NULL to indicate
     * use of an aux file
     */

    /* if there's no extension, append ".ps" */
    if (outstr && (dotIndex = strrchr(outstr, '.')) == NULL)
	dotIndex = strchr(outstr, NUL);

    /* try to open the auxiliary file for the postscript parts. */
    if (outstr && PSLATEX_useAuxFile == TRUE) {
	/* length of outstr plus ('.' or '\0') plus "ps" plus '\0' */
	PSLATEX_auxname = gp_realloc (PSLATEX_auxname,(dotIndex - outstr) + 4,
				      "pslatex aux filename");
	if (PSLATEX_auxname) {
	    /* include period or '\0' */
	    strncpy(PSLATEX_auxname, outstr, (dotIndex - outstr) + 1);
	    /* period or '\0' is overwritten with period, and "ps" appended */
	    strcpy(PSLATEX_auxname + (dotIndex - outstr), ".ps");

	    PSLATEX_auxfile = fopen(PSLATEX_auxname, "w");
	    if (PSLATEX_auxfile  == (FILE *) NULL) {
		fprintf(stderr, "Cannot open aux file %s for output\n",
			PSLATEX_auxname);
		/* And what? Error handling????? */
	    }

	} else {
	    fprintf(stderr, "\
Cannot make PostScript file name from %s\n\
Turning off auxfile option\n", outstr);
	    /* in the light of the comment above, is this correct? lh */
	    PSLATEX_auxfile = NULL;
	}
    }
    if (PSLATEX_output) {
	fputs("\
% GNUPLOT: LaTeX picture with Postscript\n\
\\begingroup%\n\
  \\makeatletter%\n\
  \\newcommand{\\GNUPLOTspecial}{%\n\
    \\@sanitize\\catcode`\\%=14\\relax\\special}%\n\
  \\setlength{\\unitlength}{0.1bp}%\n", gpoutfile);
    } else {
	/* write plain TeX header */
	fputs("\
% GNUPLOT: plain TeX with Postscript\n\
\\begingroup\n\
  \\catcode`\\@=11\\relax\n\
  \\def\\GNUPLOTspecial{%\n\
    \\def\\do##1{\\catcode`##1=12\\relax}\\dospecials\n\
    \\catcode`\\{=1\\catcode`\\}=2\\catcode\\%=14\\relax\\special}%\n\
%\n\
\\expandafter\\ifx\\csname GNUPLOTpicture\\endcsname\\relax\n\
  \\csname newdimen\\endcsname\\GNUPLOTunit\n\
  \\gdef\\GNUPLOTpicture(#1,#2){\\vbox to#2\\GNUPLOTunit\\bgroup\n\
    \\def\\put(##1,##2)##3{\\unskip\\raise##2\\GNUPLOTunit\n\
      \\hbox to0pt{\\kern##1\\GNUPLOTunit ##3\\hss}\\ignorespaces}%\n\
    \\def\\ljust##1{\\vbox to0pt{\\vss\\hbox to0pt{##1\\hss}\\vss}}%\n\
    \\def\\cjust##1{\\vbox to0pt{\\vss\\hbox to0pt{\\hss ##1\\hss}\\vss}}%\n\
    \\def\\rjust##1{\\vbox to0pt{\\vss\\hbox to0pt{\\hss ##1}\\vss}}%\n\
    \\def\\stack##1{\\let\\\\=\\cr\\tabskip=0pt\\halign{\\hfil ####\\hfil\\cr ##1\\crcr}}%\n\
    \\def\\lstack##1{\\hbox to0pt{\\vbox to0pt{\\vss\\stack{##1}}\\hss}}%\n\
    \\def\\cstack##1{\\hbox to0pt{\\hss\\vbox to0pt{\\vss\\stack{##1}}\\hss}}%\n\
    \\def\\rstack##1{\\hbox to0pt{\\vbox to0pt{\\stack{##1}\\vss}\\hss}}%\n\
    \\vss\\hbox to#1\\GNUPLOTunit\\bgroup\\ignorespaces}%\n\
  \\gdef\\endGNUPLOTpicture{\\hss\\egroup\\egroup}%\n\
\\fi\n\
\\GNUPLOTunit=0.1bp\n", gpoutfile);
    }

#ifdef PM3D
    /* to optimize output for postscript terminals family */
    postscript_gpoutfile = (PSLATEX_auxfile == NULL) ? gpoutfile : PSLATEX_auxfile;
#endif

    PSLATEX_angle = 0;
    PSLATEX_justify = 0;
    PSLATEX_labels = 0;
}

TERM_PUBLIC void
PSLATEX_graphics()
{
    struct termentry *t = term;
    unsigned int xmin_t = xoffset * PSLATEX_XMAX / PS_SC;
    unsigned int xmax_t = (xoffset + xsize) * PSLATEX_XMAX / PS_SC;
    unsigned int ymin_t = yoffset * PSLATEX_YMAX / PS_SC;
    unsigned int ymax_t = (yoffset + ysize) * PSLATEX_YMAX / PS_SC;

    if (PSLATEX_output)
	fprintf(gpoutfile, "\\begin{picture}(%d,%d)(0,0)%%\n",
		(int) (xsize * t->xmax), (int) (ysize * t->ymax));
    else
	fprintf(gpoutfile, "\\GNUPLOTpicture(%d,%d)\n",
		(int) (xsize * t->xmax), (int) (ysize * t->ymax));

    if (PSLATEX_auxfile) {
	FILE *tmp;
	/* these are taken from the post.trm file computation
	 * of the bounding box, but without the X_OFF and Y_OFF */
	int urx = (int) (xsize * (PSLATEX_XMAX) / PS_SC + 0.5);
	int ury = (int) (ysize * (PSLATEX_YMAX) / PS_SC + 0.5);
	/* moved this code here from beginning of the function
	 * PSLATEX_auxname is only != NULL with the `auxfile' option */
	char *psfile_basename = strrchr(PSLATEX_auxname, DIRSEP1);

	/* If PSLATEX_auxname is not a simple file name, but a path,
	 * we need to strip the path off the auxiliary file name,
	 * because tex file and ps aux file end up in the same directory! */
	if (psfile_basename)
	    psfile_basename++;
	else {
	    if (DIRSEP2 != NUL) {
		psfile_basename = strrchr(PSLATEX_auxname, DIRSEP2);
		if (psfile_basename)
		    psfile_basename++;
		else
		    psfile_basename = PSLATEX_auxname;
	    } else
		psfile_basename = PSLATEX_auxname;
	}

	/* generate special which xdvi and dvips can handle */
	fprintf(gpoutfile,
		"\\special{psfile=%s llx=0 lly=0 urx=%d ury=%d rwi=%d}\n",
		psfile_basename, urx, ury, 10 * urx);
	tmp = gpoutfile;
	gpoutfile = PSLATEX_auxfile;
	PS_common_init(1, 1, 0, 0, 0, xmin_t, ymin_t, xmax_t, ymax_t, NULL);
	PS_graphics();
	gpoutfile = tmp;
    } else {
	fputs("{\\GNUPLOTspecial{\"\n", gpoutfile);
	PS_common_init(1, 1, 0, 0, 0, xmin_t, ymin_t, xmax_t, ymax_t, NULL);
	PS_graphics();
    }

    PSLATEX_labels = (struct text_command *) NULL;
}

TERM_PUBLIC void
PSLATEX_put_text(x, y, str)
unsigned int x, y;
const char str[];
{
    struct text_command *tc;

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

    tc = (struct text_command *) gp_alloc(sizeof(struct text_command),
					  term->name);
    tc->x = x;
    tc->y = y;
    tc->label = (char *) gp_alloc(strlen(str) + 1, term->name);
    strcpy(tc->label, str);
    tc->justify = PSLATEX_justify;
    tc->angle = PSLATEX_angle;

    tc->next = PSLATEX_labels;
    PSLATEX_labels = tc;
}

TERM_PUBLIC int
PSLATEX_justify_text(mode)
enum JUSTIFY mode;
{
    PSLATEX_justify = mode;
    return TRUE;
}

TERM_PUBLIC int
PSLATEX_text_angle(ang)
int ang;
{
    /* rotated text is put in a short stack, and optionally uses 
     * postscript specials depending on PSLATEX_rotate */
    PSLATEX_angle = (ang ? 1 : 0);
    return TRUE;
}


TERM_PUBLIC void
PSLATEX_reset()
{
    if (PSLATEX_auxfile) {
	fclose(PSLATEX_auxfile);
	PSLATEX_auxfile = NULL;
    }
    if (PSLATEX_auxname) {
	free(PSLATEX_auxname);
	PSLATEX_auxname = NULL;
    }
}

TERM_PUBLIC void
PSLATEX_text()
{
    struct text_command *tc;

    if (PSLATEX_auxfile) {
	FILE *tmp = gpoutfile;
	gpoutfile = PSLATEX_auxfile;
	PS_text();
	gpoutfile = tmp;
    } else {
	PS_text();
	fputs("}}%\n", gpoutfile);
    }

    if (PSLATEX_fontsize) {
      if (PSLATEX_output)
	fprintf(gpoutfile, "\\fontsize{%d}{\\baselineskip}\\selectfont\n",
		PSLATEX_fontsize);
      /* Should have an else clause here to handle pstex equivalent */
    }

    for (tc = PSLATEX_labels; tc != (struct text_command *) NULL; tc = tc->next) {
	fprintf(gpoutfile, "\\put(%d,%d){", tc->x, tc->y);
	if (PSLATEX_output &&
	    ((tc->label[0] == '{') || (tc->label[0] == '['))) {
	    fprintf(gpoutfile, "\\makebox(0,0)%s", tc->label);
	} else
	    switch (tc->angle) {
	    case 0:
		switch (tc->justify) {
		case LEFT:
		    fprintf(gpoutfile, (PSLATEX_output
					? "\\makebox(0,0)[l]{%s}"
					: "\\ljust{%s}"), tc->label);
		    break;
		case CENTRE:
		    fprintf(gpoutfile, (PSLATEX_output
					? "\\makebox(0,0){%s}"
					: "\\cjust{%s}"), tc->label);
		    break;
		case RIGHT:
		    fprintf(gpoutfile, (PSLATEX_output
					? "\\makebox(0,0)[r]{%s}"
					: "\\rjust{%s}"), tc->label);
		    break;
		}
		break;
	    case 1:		/* put text in a short stack */
		if (PSLATEX_rotate) {
		    fputs("\
%\n\\special{ps: gsave currentpoint currentpoint translate\n\
270 rotate neg exch neg exch translate}%\n", gpoutfile);
		}
		switch (tc->justify) {
		case LEFT:
		    fprintf(gpoutfile, (PSLATEX_output
					? "\\makebox(0,0)[lb]{\\shortstack{%s}}"
					: "\\lstack{%s}"),
			    tc->label);
		    break;
		case CENTRE:
		    fprintf(gpoutfile, (PSLATEX_output
					? "\\makebox(0,0)[b]{\\shortstack{%s}}"
					: "\\cstack{%s}"),
			    tc->label);
		    break;
		case RIGHT:
		    fprintf(gpoutfile, (PSLATEX_output
					? "\\makebox(0,0)[lt]{\\shortstack{%s}}"
					: "\\rstack{%s}"),
			    tc->label);
		    break;
		}
		if (PSLATEX_rotate) {
		    fputs("%\n\\special{ps: currentpoint grestore moveto}%\n", gpoutfile);
		}
	    }
	fputs("}%\n", gpoutfile);
    }

    while (PSLATEX_labels) {
	tc = PSLATEX_labels->next;
	free(PSLATEX_labels->label);
	free(PSLATEX_labels);
	PSLATEX_labels = tc;
    }

    if (PSLATEX_output) {
	fputs("\
\\end{picture}%\n\
\\endgroup\n\
\\endinput\n", gpoutfile);
    } else {
	fputs("\
\\endGNUPLOTpicture\n\
\\endgroup\n\
\\endinput\n", gpoutfile);
    }
}

TERM_PUBLIC void
PSLATEX_move(x, y)
unsigned int x, y;
{
    if (PSLATEX_auxfile) {
	FILE *tmp = gpoutfile;
	gpoutfile = PSLATEX_auxfile;
	PS_move(x, y);
	gpoutfile = tmp;
    } else {
	PS_move(x, y);
    }
}


TERM_PUBLIC void
PSLATEX_vector(x, y)
unsigned int x, y;
{

    if (PSLATEX_auxfile) {
	FILE *tmp = gpoutfile;
	gpoutfile = PSLATEX_auxfile;
	PS_vector(x, y);
	gpoutfile = tmp;
    } else {
	PS_vector(x, y);
    }
}


TERM_PUBLIC void
PSLATEX_linetype(lt)
int lt;
{
    if (PSLATEX_auxfile) {
	FILE *tmp = gpoutfile;
	gpoutfile = PSLATEX_auxfile;
	PS_linetype(lt);
	gpoutfile = tmp;
    } else {
	PS_linetype(lt);
    }
}

TERM_PUBLIC void
PSLATEX_point(x, y, number)
unsigned int x, y;
int number;
{
    if (PSLATEX_auxfile) {
	FILE *tmp = gpoutfile;
	gpoutfile = PSLATEX_auxfile;
	PS_point(x, y, number);
	gpoutfile = tmp;
    } else
	PS_point(x, y, number);
}


TERM_PUBLIC void
PSLATEX_pointsize(ps)
double ps;
{
    if (PSLATEX_auxfile) {
	FILE *tmp = gpoutfile;
	gpoutfile = PSLATEX_auxfile;
	PS_pointsize(ps);
	gpoutfile = tmp;
    } else
	PS_pointsize(ps);
}


TERM_PUBLIC void
PSLATEX_linewidth(ps)
double ps;
{
    if (PSLATEX_auxfile) {
	FILE *tmp = gpoutfile;
	gpoutfile = PSLATEX_auxfile;
	PS_linewidth(ps);
	gpoutfile = tmp;
    } else
	PS_linewidth(ps);
}

#ifdef PM3D

TERM_PUBLIC int PSLATEX_make_palette (t_sm_palette *palette)
{
    if (PSLATEX_auxfile) {
	FILE *tmp = gpoutfile;
	int res;
	gpoutfile = PSLATEX_auxfile;
	res = PS_make_palette(palette);
	gpoutfile = tmp;
	return res;
    } else
	return PS_make_palette(palette);
}

TERM_PUBLIC void PSLATEX_set_color (double gray)
{
    if (PSLATEX_auxfile) {
	FILE *tmp = gpoutfile;
	gpoutfile = PSLATEX_auxfile;
	PS_set_color(gray);
	gpoutfile = tmp;
    } else
	PS_set_color(gray);
}

TERM_PUBLIC void PSLATEX_filled_polygon ( int points, gpiPoint *corners )
{
    if (PSLATEX_auxfile) {
	FILE *tmp = gpoutfile;
	gpoutfile = PSLATEX_auxfile;
	PS_filled_polygon(points,corners);
	gpoutfile = tmp;
    } else
	PS_filled_polygon(points,corners);
}

TERM_PUBLIC void PSLATEX_previous_palette ( void )
{
    if (PSLATEX_auxfile) {
	FILE *tmp = gpoutfile;
	gpoutfile = PSLATEX_auxfile;
	PS_previous_palette();
	gpoutfile = tmp;
    } else
	PS_previous_palette();
}

#endif /* PM3D */

#endif /* TERM_BODY */

#ifdef TERM_TABLE

#ifndef GOT_POST_PROTO
#define TERM_PROTO_ONLY
#include "post.trm"
#undef TERM_PROTO_ONLY
#endif

TERM_TABLE_START(pslatex_driver)
    "pslatex", "LaTeX picture environment with PostScript \\specials",
    PSLATEX_XMAX, PSLATEX_YMAX, PSLATEX_VCHAR, PSLATEX_HCHAR,
    PS_VTIC, PS_HTIC, PSLATEX_options, PSLATEX_init, PSLATEX_reset,
    PSLATEX_text, null_scale, PSLATEX_graphics, PSLATEX_move,
    PSLATEX_vector, PSLATEX_linetype, PSLATEX_put_text, PSLATEX_text_angle,
    PSLATEX_justify_text, PSLATEX_point, do_arrow, set_font_null,
    PSLATEX_pointsize, 0 /*flags */ , 0 /*suspend */
    , 0 /*resume */ , 0 /*fillbox */ ,
    PSLATEX_linewidth
#ifdef PM3D
#ifdef USE_MOUSE
   , 0, 0, 0, 0, 0 /* no mouse support for postscript */
#endif
   , PSLATEX_make_palette,
   PSLATEX_previous_palette, /* write grestore */
   PSLATEX_set_color,
   PSLATEX_filled_polygon
#endif
TERM_TABLE_END(pslatex_driver)
#undef LAST_TERM
#define LAST_TERM pslatex_driver

TERM_TABLE_START(pstex_driver)
    "pstex", "plain TeX with PostScript \\specials",
    PSLATEX_XMAX, PSLATEX_YMAX, PSLATEX_VCHAR, PSLATEX_HCHAR,
    PS_VTIC, PS_HTIC, PSLATEX_options, PSLATEX_init, PSLATEX_reset,
    PSLATEX_text, null_scale, PSLATEX_graphics, PSLATEX_move,
    PSLATEX_vector, PSLATEX_linetype, PSLATEX_put_text, PSLATEX_text_angle,
    PSLATEX_justify_text, PSLATEX_point, do_arrow, set_font_null,
    PSLATEX_pointsize, 0 /*flags */ , 0 /*suspend */
    , 0 /*resume */ , 0 /*fillbox */ ,
    PSLATEX_linewidth
#ifdef PM3D
#ifdef USE_MOUSE
   , 0, 0, 0, 0, 0 /* no mouse support for postscript */
#endif
   , PSLATEX_make_palette,
   PSLATEX_previous_palette, /* write grestore */
   PSLATEX_set_color,
   PSLATEX_filled_polygon
#endif
TERM_TABLE_END(pstex_driver)
#undef LAST_TERM
#define LAST_TERM pstex_driver

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


#ifdef TERM_HELP
START_HELP(pslatex)
"1 pslatex and pstex",
"?commands set terminal pslatex",
"?set terminal pslatex",
"?set term pslatex",
"?terminal pslatex",
"?term pslatex",
"?pslatex",
"?commands set terminal pstex",
"?set terminal pstex",
"?set term pstex",
"?terminal pstex",
"?term pstex",
"?pstex",
" The `pslatex` and `pstex` drivers generate output for further processing by",
" LaTeX and TeX, respectively.  Figures generated by `pstex` can be included",
" in any plain-based format (including LaTeX).",
"",
" Syntax:",
"       set terminal [pslatex | pstex] {<color>} {<dashed>} {<rotate>}",
"                                      {auxfile} {<font_size>}",
"",
" <color> is either `color` or `monochrome`.  <dashed> is either `dashed`",
" or `solid`.  <rotate> is either `rotate` or `norotate` and determines",
" if the y-axis label is rotated.  <font_size> is the size (in pts) of the",
" desired font.",
"",
" If `auxfile` is specified, it directs the driver to put the PostScript",
" commands into an auxiliary file instead of directly into the LaTeX file.",
" This is useful if your pictures are large enough that dvips cannot handle",
" them.  The name of the auxiliary PostScript file is derived from the name of",
" the TeX file given on the `set output` command; it is determined by replacing",
" the trailing `.tex` (actually just the final extent in the file name) with",
" `.ps` in the output file name, or, if the TeX file has no extension, `.ps`",
" is appended.  Remember to close the `output file` before leaving `gnuplot`.",
" The `.ps` is included into the `.tex` file by a \\special{psfile=...} command.",
" If you would rather prefer \\includegraphics{...}, then use the `epslatex`",
" terminal.",
"",
" All drivers for LaTeX offer a special way of controlling text positioning: ",
" (a) 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 by LaTeX.  (b) If the text string begins with '[', you need",
" to continue it 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.",
"",
" Examples:",
"       set term pslatex monochrome dashed rotate       # set to defaults",
" To write the PostScript commands into the file \"foo.ps\":",
"       set term pslatex auxfile",
"       set output \"foo.tex\"; plot ...; set output",
" 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}'",
"",
" Linewidths and pointsizes may be changed with `set style line`."
END_HELP(pslatex)
#endif /* TERM_HELP */