1 /* Hello, Emacs! This is -*-C-*- !*/
3 * $Id: eepic.trm,v 1.29 2006/07/21 02:35:46 sfeam Exp $
7 /* GNUPLOT - eepic.trm */
10 * Copyright 1990 - 1993, 1998, 2004
12 * Permission to use, copy, and distribute this software and its
13 * documentation for any purpose with or without fee is hereby granted,
14 * provided that the above copyright notice appear in all copies and
15 * that both that copyright notice and this permission notice appear
16 * in supporting documentation.
18 * Permission to modify the software is granted, but not the right to
19 * distribute the complete modified source code. Modifications are to
20 * be distributed as patches to the released version. Permission to
21 * distribute binaries produced by compiling modified sources is granted,
23 * 1. distribute the corresponding source modifications from the
24 * released version in the form of a patch file along with the binaries,
25 * 2. add special version identification to distinguish your version
26 * in addition to the base release version number,
27 * 3. provide your name and address as the primary contact for the
28 * support of your modified version, and
29 * 4. retain our contact information in regard to use of the base
31 * Permission to distribute the released version of the source code along
32 * with corresponding source modifications in the form of a patch file is
33 * granted with same provisions 2 through 4 for binary distributions.
35 * This software is provided "as is" without express or implied warranty
36 * to the extent permitted by applicable law.
40 * This file is included by ../term.c.
42 * This terminal driver supports:
43 * The EEPIC macros for LaTeX.
48 * send your comments or suggestions to (gnuplot-info@lists.sourceforge.net).
52 * This file contains the eepic terminal driver, intended for use with the
53 * eepic.sty macro package for LaTeX. This is an alternative to the
54 * latex driver. You need eepic.sty, epic.sty, and a printer driver that
55 * supports the tpic \specials.
57 * Although dotted and dashed lines are possible with EEPIC, and are
58 * tempting, they do not work well for high-sample-rate curves, mushing
59 * the dashes all together into a solid line. For now anyway, the EEPIC
60 * driver will have only solid lines. Anyone got a solution?
62 * LATEX must also be defined.
65 * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
67 /* Additions by Gabriel Zachmann (Gabriel.Zachmann@gmx.net), Nov 2000:
68 * - little bug fix in stacked (faked rotated) text
71 * - augmented line types set with dashed lines
72 * - optionally small or tiny point symbols
87 TERM_PUBLIC void EEPIC_init __PROTO((void));
88 TERM_PUBLIC void EEPIC_graphics __PROTO((void));
89 TERM_PUBLIC void EEPIC_text __PROTO((void));
90 TERM_PUBLIC void EEPIC_linetype __PROTO((int linetype));
91 TERM_PUBLIC void EEPIC_move __PROTO((unsigned int x, unsigned int y));
92 TERM_PUBLIC void EEPIC_point __PROTO((unsigned int x, unsigned int y,
94 TERM_PUBLIC void EEPIC_vector __PROTO((unsigned int ux, unsigned int uy));
95 TERM_PUBLIC void EEPIC_arrow __PROTO((unsigned int sx, unsigned int sy,
96 unsigned int ex, unsigned int ey,
98 TERM_PUBLIC void EEPIC_put_text __PROTO((unsigned int x, unsigned int y,
100 TERM_PUBLIC int EEPIC_justify_text __PROTO((enum JUSTIFY mode));
101 TERM_PUBLIC int EEPIC_text_angle __PROTO((int ang));
102 TERM_PUBLIC void EEPIC_reset __PROTO((void));
103 TERM_PUBLIC void EEPIC_options __PROTO((void));
105 #define EEPIC_PTS_PER_INCH 72.27
106 /* resolution of printer we expect to use */
107 #define EEPIC_DOTS_PER_INCH 600
109 #define EEPIC_UNIT (EEPIC_PTS_PER_INCH/EEPIC_DOTS_PER_INCH)
111 /* 5 inches wide by 3 inches high (default) */
112 #define EEPIC_XMAX (EEPIC_PTS_PER_INCH/EEPIC_UNIT*5.0)
113 #define EEPIC_YMAX (EEPIC_PTS_PER_INCH/EEPIC_UNIT*3.0)
115 #define EEPIC_HTIC (5.0/EEPIC_UNIT)
116 #define EEPIC_VTIC (5.0/EEPIC_UNIT)
117 #define EEPIC_VCHAR (10.0/EEPIC_UNIT)
118 #define EEPIC_HCHAR (EEPIC_VCHAR/2.0)
119 #endif /* TERM_PROTO */
121 #ifndef TERM_PROTO_ONLY
124 static unsigned int EEPIC_posx;
125 static unsigned int EEPIC_posy;
126 static enum JUSTIFY eepic_justify = LEFT;
127 static int eepic_angle = 0;
128 static int eepic_color_on = FALSE; /* use \color */
129 static int eepic_true_rotate = FALSE; /* use \rotatebox */
130 static int fontsize_set = FALSE;
132 /* for DOTS point style */
133 #define EEPIC_TINY_DOT "\\rule{.1pt}{.1pt}"
136 static int eepic_num_point_types[] = { 12, 10, 8 };
137 static int eepic_pointsize = 0;
138 static const char GPFAR *GPFAR EEPIC_points[][12] =
141 "\\makebox(0,0){$\\Diamond$}",
142 "\\makebox(0,0){$+$}",
143 "\\makebox(0,0){$\\Box$}",
144 "\\makebox(0,0){$\\times$}",
145 "\\makebox(0,0){$\\triangle$}",
146 "\\makebox(0,0){$\\star$}",
147 "\\circle{12}", "\\circle{18}", "\\circle{24}",
148 "\\circle*{12}", "\\circle*{18}", "\\circle*{24}"
151 "\\makebox(0,0){$\\scriptstyle\\Diamond$}",
152 "\\makebox(0,0){$\\scriptstyle +$}",
153 "\\makebox(0,0){$\\scriptstyle\\Box$}",
154 "\\makebox(0,0){$\\scriptstyle\\times$}",
155 "\\makebox(0,0){$\\scriptstyle\\triangle$}",
156 "\\makebox(0,0){$\\scriptstyle\\star$}",
157 "\\circle{12}", "\\circle{18}",
158 "\\circle*{12}", "\\circle*{18}",
161 "\\makebox(0,0){$\\scriptscriptstyle\\Diamond$}",
162 "\\makebox(0,0){$\\scriptscriptstyle +$}",
163 "\\makebox(0,0){$\\scriptscriptstyle\\Box$}",
164 "\\makebox(0,0){$\\scriptscriptstyle\\times$}",
165 "\\makebox(0,0){$\\scriptscriptstyle\\triangle$}",
166 "\\makebox(0,0){$\\scriptscriptstyle\\star$}",
173 static int eepic_numlines[] = { 5, 7, 8 }; /* number of linetypes below */
174 #define EEPIC_MAX_NUMLINES 8 /* max of eepic_numlines[] */
175 static int eepic_lineset = 0;
176 static char GPFAR *GPFAR EEPIC_lines[][EEPIC_MAX_NUMLINES] =
179 "\\thicklines \\path", /* -2 border */
180 "\\thinlines \\drawline[-50]", /* -1 axes */
181 "\\thinlines \\path", /* 0 solid thin */
182 "\\thicklines \\path", /* 1 solid thick */
183 "\\Thicklines \\path" /* 2 solid Thick */
186 "\\thicklines \\path", /* -2 border */
187 "\\thinlines \\drawline[-50]", /* -1 axes */
188 "\\thinlines \\path", /* 0 solid thin */
189 "\\thinlines \\dashline[90]{10}",
190 "\\thinlines \\dottedline{10}",
191 "\\thinlines \\dashline[60]{20}",
192 "\\thinlines \\dottedline{20}"
195 "\\thicklines \\path", /* -2 border */
196 "\\thinlines \\drawline[-50]", /* -1 axes */
197 "\\thinlines \\path",
198 "\\thinlines \\path",
199 "\\thinlines \\path",
200 "\\thinlines \\path",
201 "\\thinlines \\path",
205 static int EEPIC_type; /* current line type */
206 static TBOOLEAN EEPIC_inline = FALSE; /* are we in the middle of a line */
207 static void EEPIC_endline __PROTO((void)); /* terminate any line in progress */
208 static int EEPIC_linecount = 0; /* number of points in line so far */
209 #define EEPIC_LINEMAX 50 /* max value for linecount */
211 #define EEPIC_NUM_COLORS 7
212 static int eepic_color = 0;
213 static char GPFAR *GPFAR eepic_colors[EEPIC_NUM_COLORS] =
215 "\\color{black}\n", /* border and axes (must be black!) */
219 "\\color{magenta}\n",
225 /* we use the same code as for LATEX */
226 /* figure out the best arrow */
227 static void best_latex_arrow __PROTO((int sx, int sy, int ex, int ey, int who, int head));
232 EEPIC_posx = EEPIC_posy = 0;
235 EEPIC_inline = FALSE;
237 fprintf(gpoutfile, "\
238 %% GNUPLOT: LaTeX picture using EEPIC macros\n\
239 \\setlength{\\unitlength}{%fpt}\n",
247 register struct termentry *t = term;
249 /* HBB 20001027: respect 'size' and 'offset' settings to modify
250 * picture box size and position */
251 fprintf(gpoutfile, "\\begin{picture}(%d,%d)(%d,%d)\n",
252 (int) (t->xmax * xsize),
253 (int) (t->ymax * ysize),
254 (int) (t->xmax * xoffset),
255 (int) (t->ymax * xoffset));
257 float x = t->v_char * EEPIC_UNIT + 0.5;
259 fprintf(gpoutfile, "\\fontsize{%d}{%g}\\selectfont\n",
262 fprintf(gpoutfile,"\\footnotesize\n" );
271 fputs("\\end{picture}\n", gpoutfile);
276 EEPIC_linetype(int linetype)
280 EEPIC_type = linetype % (eepic_numlines[eepic_lineset] - 2);
282 if ( eepic_color_on )
284 eepic_color = linetype;
285 if ( eepic_color < 0 )
289 eepic_color %= EEPIC_NUM_COLORS - 1;
292 fputs( eepic_colors[eepic_color], gpoutfile );
299 EEPIC_move(unsigned int x, unsigned int y)
309 EEPIC_point(unsigned int x, unsigned int y, int number)
313 /* Print the character defined by 'number'; number < 0 means
314 to use a dot, otherwise one of the defined points. */
315 fprintf(gpoutfile, "\\put(%d,%d){%s}\n", x, y,
316 (number < 0 ? EEPIC_TINY_DOT
317 : EEPIC_points[eepic_pointsize][number % eepic_num_point_types[eepic_pointsize]]));
322 EEPIC_vector(unsigned int ux, unsigned int uy)
327 /* Start a new line. This depends on line type */
328 fprintf(gpoutfile, "%s(%u,%u)",
329 EEPIC_lines[eepic_lineset][EEPIC_type + 2],
330 EEPIC_posx, EEPIC_posy);
333 /* Even though we are in middle of a path,
334 * we may want to start a new path command.
335 * If they are too long then latex will choke.
337 if (EEPIC_linecount++ >= EEPIC_LINEMAX) {
338 fprintf(gpoutfile, "\n%s(%u,%u)",
339 EEPIC_lines[eepic_lineset][EEPIC_type + 2],
340 EEPIC_posx, EEPIC_posy);
344 fprintf(gpoutfile, "(%u,%u)", ux, uy);
353 putc('\n', gpoutfile);
354 EEPIC_inline = FALSE;
361 unsigned int sx, unsigned int sy,
362 unsigned int ex, unsigned int ey,
365 best_latex_arrow(sx, sy, ex, ey, 2, head); /* call latex routine */
373 EEPIC_put_text(unsigned int x, unsigned y, const char str[])
379 fprintf(gpoutfile, "\\put(%d,%d)", x, y);
380 if ((str[0] == '{') || (str[0] == '[')) {
381 fprintf(gpoutfile, "{\\makebox(0,0)%s}\n", str);
388 switch (eepic_justify) {
390 fputs("{\\makebox(0,0)[l]{",gpoutfile);
393 fputs("{\\makebox(0,0){",gpoutfile);
396 fputs("{\\makebox(0,0)[r]{",gpoutfile);
399 fprintf(gpoutfile,"%s}}\n", str);
404 if ( eepic_true_rotate )
407 switch (eepic_justify) {
409 fputs("{\\makebox(0,0)[lb]{\\rotatebox[origin=c]{90}{",
413 fputs("{\\makebox(0,0)[l]{\\rotatebox[origin=c]{90}{",
417 fputs("{\\makebox(0,0)[lt]{\\rotatebox[origin=c]{90}{",
421 fprintf(gpoutfile,"%s}}}\n", str);
425 /* put text in a short stack */
426 switch (eepic_justify) {
428 fputs("{\\makebox(0,0)[lb]{\\shortstack{",gpoutfile);
431 fputs("{\\makebox(0,0)[l]{\\shortstack{",gpoutfile);
434 fputs("{\\makebox(0,0)[lt]{\\shortstack{",gpoutfile);
438 for ( i = 0; i < l; i ++ )
439 fprintf(gpoutfile, "%c\\\\", str[i] );
440 fputc(str[l],gpoutfile);
441 fputs("}}}\n",gpoutfile);
451 EEPIC_justify_text(enum JUSTIFY mode)
453 eepic_justify = mode;
458 EEPIC_text_angle(int ang)
460 eepic_angle = (ang ? 1 : 0);
468 EEPIC_posx = EEPIC_posy = 0;
477 eepic_true_rotate = FALSE;
481 while (!END_OF_COMMAND) {
482 if (almost_equals(c_token, "de$fault")) {
483 fontsize_set = FALSE;
484 eepic_color_on = FALSE;
485 eepic_true_rotate = FALSE;
489 } else if (almost_equals(c_token, "c$olor") ||
490 almost_equals(c_token, "c$olour")) {
491 eepic_color_on = TRUE;
494 } else if (almost_equals(c_token, "r$otate")) {
495 eepic_true_rotate = TRUE;
497 } else if (almost_equals(c_token, "da$shed")) {
498 if (! eepic_color_on)
499 eepic_lineset = 1; /* ignore when color is on */
501 } else if (almost_equals(c_token, "s$mall")) {
504 } else if (almost_equals(c_token, "t$iny")) {
507 } else if (isdigit((unsigned char)
508 gp_input_line[token[c_token].start_index])) {
510 fontsize = real(const_express(&a));
512 if (fontsize < 1 || fontsize > 100)
513 int_error(c_token, "font size out of bounds [1..100]");
516 term->v_char = (unsigned int)(fontsize/EEPIC_UNIT);
517 term->h_char = (unsigned int)((fontsize/EEPIC_UNIT)/2);
520 int_error(c_token, "unrecognized option");
521 } /* while(command) */
523 sprintf(term_options, "default%s%s%s%s",
524 eepic_color_on ? " color" : "",
525 eepic_lineset == 1 ? " dashed" : "",
526 eepic_true_rotate ? " rotate" : "",
527 eepic_pointsize == 1 ? " small"
528 : eepic_pointsize == 2 ? " tiny" : "" );
530 sprintf( term_options+strlen(term_options), " %d", (int) fontsize );
537 TERM_TABLE_START(eepic_driver)
538 "eepic", "EEPIC -- extended LaTeX picture environment",
539 EEPIC_XMAX, EEPIC_YMAX, EEPIC_VCHAR, EEPIC_HCHAR,
540 EEPIC_VTIC, EEPIC_HTIC, EEPIC_options, EEPIC_init, EEPIC_reset,
541 EEPIC_text, null_scale, EEPIC_graphics, EEPIC_move, EEPIC_vector,
542 EEPIC_linetype, EEPIC_put_text, EEPIC_text_angle,
543 EEPIC_justify_text, EEPIC_point, EEPIC_arrow, set_font_null,
546 0, 0, /* suspend, resume */
549 TERM_TABLE_END(eepic_driver)
552 #define LAST_TERM eepic_driver
560 "?commands set terminal eepic",
561 "?set terminal eepic",
566 " The `eepic` terminal driver supports the extended LaTeX picture environment.",
567 " It is an alternative to the `latex` driver.",
569 " The output of this terminal is intended for use with the \"eepic.sty\" macro",
570 " package for LaTeX. To use it, you need \"eepic.sty\", \"epic.sty\" and a",
571 " printer driver that supports the \"tpic\" \\specials. If your printer driver",
572 " doesn't support those \\specials, \"eepicemu.sty\" will enable you to use some",
574 " dvips and dvipdfm do support the \"tpic\" \\specials.",
577 " set terminal eepic {color, dashed, rotate, small, tiny, default, <fontsize>}",
580 " You can give options in any order you wish.",
581 " 'color' causes gnuplot to produce \\color{...} commands so that the graphs are",
582 " colored. Using this option, you must include \\usepackage{color} in the preambel",
583 " of your latex document.",
584 " 'dashed' will allow dashed line types; without this option, only solid lines",
585 " with varying thickness will be used.",
586 " 'dashed' and 'color' are mutually exclusive; if 'color' is specified, then 'dashed'",
588 " 'rotate' will enable true rotated text (by 90 degrees). Otherwise, rotated text",
589 " will be typeset with letters stacked above each other. If you use this option",
590 " you must include \\usepackage{graphicx} in the preamble.",
591 " 'small' will use \\scriptsize symbols as point markers (Probably does not work",
592 " with TeX, only LaTeX2e). Default is to use the default math size.",
593 " 'tiny' uses \\scriptscriptstyle symbols.",
594 " 'default' resets all options to their defaults = no color, no dashed lines,",
595 " pseudo-rotated (stacked) text, large point symbols.",
596 " <fontsize> is a number which specifies the font size inside the picture",
597 " environment; the unit is pt (points), i.e., 10 pt equals approx. 3.5 mm.",
598 " If fontsize is not specified, then all text inside the picture will be set",
599 " in \\footnotesize.",
602 " Remember to escape the # character (or other chars meaningful to (La-)TeX)",
603 " by \\\\ (2 backslashes).",
604 " It seems that dashed lines become solid lines when the vertices of a plot",
605 " are too close. (I do not know if that is a general problem with the tpic specials,",
606 " or if it is caused by a bug in eepic.sty or dvips/dvipdfm.)",
607 " The default size of an eepic plot is 5x3 inches, which can be scaled ",
608 " by 'set size a,b'.",
609 " Points, among other things, are drawn using the LaTeX commands \"\\Diamond\",",
610 " \"\\Box\", etc. These commands no longer belong to the LaTeX2e core; they are",
611 " included in the latexsym package, which is part of the base distribution and",
612 " thus part of any LaTeX implementation. Please do not forget to use this package.",
613 " Instead of latexsym, you can also include the amssymb package.",
614 " All drivers for LaTeX offer a special way of controlling text positioning:",
615 " If any text string begins with '{', you also need to include a '}' at the",
616 " end of the text, and the whole text will be centered both horizontally and",
617 " vertically. If the text string begins with '[', you need to follow this with",
618 " a position specification (up to two out of t,b,l,r), ']{', the text itself,",
619 " and finally '}'. The text itself may be anything LaTeX can typeset as an",
620 " LR-box. '\\rule{}{}'s may help for best positioning.",
624 " output graphs as eepic macros inside a picture environment;",
625 " \\input the resulting file in your LaTeX document.",
626 " set term eepic color tiny rotate 8",
627 " eepic macros with \\color macros, \\scripscriptsize point markers,",
628 " true rotated text, and all text set with 8pt.",
630 " About label positioning:",
631 " Use gnuplot defaults (mostly sensible, but sometimes not really best):",
632 " set title '\\LaTeX\\ -- $ \\gamma $'",
633 " Force centering both horizontally and vertically:",
634 " set label '{\\LaTeX\\ -- $ \\gamma $}' at 0,0",
635 " Specify own positioning (top here):",
636 " set xlabel '[t]{\\LaTeX\\ -- $ \\gamma $}'",
637 " The other label -- account for long ticlabels:",
638 " set ylabel '[r]{\\LaTeX\\ -- $ \\gamma $\\rule{7mm}{0pt}}'"
640 #endif /* TERM_HELP */