home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 500-599 / ff552.lzh / GNUPlot / gnuplot3.lzh / gnuplot / term / latex.trm < prev    next >
Text File  |  1991-09-05  |  18KB  |  660 lines

  1. /* GNUPLOT - latex.trm */
  2. /*
  3.  * Copyright (C) 1990   
  4.  *
  5.  * Permission to use, copy, and distribute this software and its
  6.  * documentation for any purpose with or without fee is hereby granted, 
  7.  * provided that the above copyright notice appear in all copies and 
  8.  * that both that copyright notice and this permission notice appear 
  9.  * in supporting documentation.
  10.  *
  11.  * Permission to modify the software is granted, but not the right to
  12.  * distribute the modified code.  Modifications are to be distributed 
  13.  * as patches to released version.
  14.  *  
  15.  * This software  is provided "as is" without express or implied warranty.
  16.  * 
  17.  * This file is included by ../term.c.
  18.  *
  19.  * This terminal driver supports:
  20.  *   LaTeX pictures (latex).
  21.  *   LaTeX pictures with emTeX specials (emtex). 
  22.  *
  23.  * AUTHORS
  24.  *   David Kotz, Russell Lang
  25.  *
  26.  * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
  27.  * 
  28.  */
  29.  
  30. /* modified to optimize use of \rule for long lines */
  31.  
  32. /* the following LATEX driver has been modified by 
  33.    Russell Lang, eln272v@monu1.cc.monash.oz from the
  34.    GnuTeX 1.3 driver by David Kotz, David.Kotz@Dartmouth.edu.
  35.    Since then it has been further extended by David Kotz.
  36.    EmTeX driver by Russell Lang. */
  37.  
  38.  
  39. #define LATEX_PTS_PER_INCH (72.27)
  40. #define DOTS_PER_INCH (300)    /* resolution of printer we expect to use */
  41. #define LATEX_UNIT (LATEX_PTS_PER_INCH/DOTS_PER_INCH) /* dot size in pt */
  42.  
  43. /* 5 inches wide by 3 inches high (default) */
  44. #define LATEX_XMAX (5*DOTS_PER_INCH)  /* (LATEX_PTS_PER_INCH/LATEX_UNIT*5.0) */
  45. #define LATEX_YMAX (3*DOTS_PER_INCH)  /* (LATEX_PTS_PER_INCH/LATEX_UNIT*3.0) */
  46.  
  47. #define LATEX_HTIC (5*DOTS_PER_INCH/72)        /* (5./LATEX_UNIT) */
  48. #define LATEX_VTIC (5*DOTS_PER_INCH/72)        /* (5./LATEX_UNIT) */
  49. #define LATEX_HCHAR (DOTS_PER_INCH*53/10/72)    /* (5.3/LATEX_UNIT) */
  50. #define LATEX_VCHAR (DOTS_PER_INCH*11/72)    /* (11./LATEX_UNIT) */
  51.  
  52. static int LATEX_posx;
  53. static int LATEX_posy;
  54. static enum JUSTIFY latex_justify=LEFT;
  55. static int latex_angle=0;
  56.  
  57. /* Default line-drawing character */
  58. /* the definition of plotpoint varies with linetype */
  59. #define LATEX_DOT "\\usebox{\\plotpoint}"
  60. #define LATEX_TINY_DOT "\\rule{.1pt}{.1pt}" /* for dots plot style */
  61.  
  62. /* POINTS */
  63. #define LATEX_POINT_TYPES 12    /* we supply more point types */
  64. static char *LATEX_points[] = {
  65.     "\\raisebox{-1.2pt}{\\makebox(0,0){$\\Diamond$}}",
  66.     "\\makebox(0,0){$+$}",
  67.     "\\raisebox{-1.2pt}{\\makebox(0,0){$\\Box$}}",
  68.     "\\makebox(0,0){$\\times$}",
  69.     "\\makebox(0,0){$\\triangle$}",
  70.     "\\makebox(0,0){$\\star$}",
  71.     "\\circle{12}", "\\circle{18}", "\\circle{24}",
  72.     "\\circle*{12}", "\\circle*{18}", "\\circle*{24}"
  73. };
  74.  
  75. /* LINES */
  76. static float LATEX_size = 0;    /* current thick of line in points */
  77. static float LATEX_dotspace = 0; /* current dotspace of line in points */
  78. #define LATEX_LINE_TYPES 6    /* number of line types below */
  79. #define LATEX_THIN_LINE 0    /* the thinnest solid line type */
  80. static struct {
  81.     float size;            /* size of dot, or thick of line in points */
  82.     float dotspace;            /* inter-dot space in points; 0 for lines */
  83. } LATEX_lines[] = {
  84.     {.35, 0.0},                /* thin solid line */
  85.     {.7, 0.0},                /* thick solid line */
  86.     {1.0, 0.0},                /* Thick solid line */
  87.     {.5, 5.0},                /* dotted line */
  88.     {.5, 9.0},                /* widely dotted line */
  89.     {.5, 13.0}                /* really widely dotted line */
  90. };
  91. /* for drawing dotted and solid lines */
  92. static void LATEX_dot_line();
  93. static void LATEX_solid_line();
  94. static void LATEX_rule();
  95. static void LATEX_flushdot();
  96. #define LATEX_flushrule() LATEX_rule(2, 0.,0.,0.,0.) /* flush old rule */
  97. static BOOLEAN LATEX_moved = TRUE;    /* pen is up after move */
  98. static float LATEX_dotsize;    /* size of LATEX_DOT in units */
  99. static BOOLEAN LATEX_needsdot = FALSE;/* does dotted line need termination? */
  100.  
  101. #ifdef EMTEX
  102. BOOLEAN emtex=FALSE; /* not currently using emtex */
  103. static void EMTEX_solid_line();
  104. #endif
  105.  
  106. /* ARROWS */
  107. /* the set of non-vertical/non-horizontal LaTeX vector slopes */
  108. /* except negatives - they are handled specially */
  109. static struct vslope {
  110.     int dx, dy;
  111. } LATEX_slopes[] = {
  112.     {1,1}, {1,2}, {1,3}, {1,4},
  113.     {2,1}, {2,3},
  114.     {3,1}, {3,2}, {3,4},
  115.     {4,1}, {4,3},
  116.     {0,0}                    /* terminator */
  117. };
  118. static void best_latex_arrow(); /* figure out the best arrow */
  119.  
  120. LATEX_init()
  121. {
  122. #ifdef EMTEX
  123.     emtex = FALSE;
  124. #endif
  125.     LATEX_posx = LATEX_posy = 0;
  126.     fprintf(outfile, "%% GNUPLOT: LaTeX picture\n");
  127.     fprintf(outfile, "\\setlength{\\unitlength}{%fpt}\n", LATEX_UNIT);
  128.     fprintf(outfile, 
  129.           "\\ifx\\plotpoint\\undefined\\newsavebox{\\plotpoint}\\fi\n");
  130.     LATEX_linetype(-1);
  131. }
  132.  
  133.  
  134. LATEX_scale(xs, ys)
  135.     double xs, ys;            /* scaling factors */
  136. {
  137.     register struct termentry *t = &term_tbl[term];
  138.  
  139.     /* we change the table for use in graphics.c and LATEX_graphics */
  140.     t->xmax = (unsigned int)(LATEX_XMAX * xs);
  141.     t->ymax = (unsigned int)(LATEX_YMAX * ys);
  142.  
  143.     return(TRUE);
  144. }
  145.  
  146. LATEX_graphics()
  147. {
  148.     register struct termentry *t = &term_tbl[term];
  149.  
  150.     fprintf(outfile, "\\begin{picture}(%d,%d)(0,0)\n", t->xmax, t->ymax);
  151.     fprintf(outfile, "\\tenrm\n");
  152. }
  153.  
  154.  
  155. LATEX_text()
  156. {
  157.     LATEX_flushrule();
  158.     LATEX_flushdot();
  159.     fprintf(outfile, "\\end{picture}\n");
  160.     LATEX_posx = LATEX_posy = 0; /* current position */
  161.     LATEX_moved = TRUE;    /* pen is up after move */
  162. }
  163.  
  164. LATEX_linetype(linetype)
  165.     int linetype;
  166. {
  167.     float size;
  168.  
  169.     if (linetype >= LATEX_LINE_TYPES)
  170.      linetype %= LATEX_LINE_TYPES;
  171.  
  172. #ifdef EMTEX
  173.     if (!emtex)
  174. #endif
  175.     LATEX_flushrule();
  176.     LATEX_flushdot();
  177.  
  178.     /* Find the new desired line thickness. */
  179.     /* negative linetypes (for axes) use a thin line */
  180.     /* only relevant for drawing axes/border in 3d */
  181.     size = (linetype >= 0 ? LATEX_lines[linetype].size 
  182.           : LATEX_lines[LATEX_THIN_LINE].size);
  183.  
  184.     /* If different from current size, redefine \plotpoint */
  185.     if (size != LATEX_size) {
  186.        fprintf(outfile, 
  187.              "\\sbox{\\plotpoint}{\\rule[%.3fpt]{%.3fpt}{%.3fpt}}%%\n",
  188.              -size/2, size, size);
  189. #ifdef EMTEX
  190.         if (emtex)         /* change line width */
  191.         fprintf(outfile, "\\special{em:linewidth %.1fpt}%%\n", size);
  192. #endif
  193.     }
  194.     
  195.     LATEX_size = size;
  196.     LATEX_dotsize = size / LATEX_UNIT;
  197.     LATEX_dotspace = (linetype >= 0) ? LATEX_lines[linetype].dotspace : 0;
  198.     LATEX_moved = TRUE;            /* reset */
  199. }
  200.  
  201. LATEX_move(x,y)
  202.     unsigned int x,y;
  203. {
  204.     LATEX_flushdot();
  205.  
  206.     LATEX_posx = x;
  207.     LATEX_posy = y;
  208.     LATEX_moved = TRUE;            /* reset */
  209. }
  210.  
  211.  
  212. LATEX_point(x,y, number)        /* version of line_and_point */
  213.     unsigned int x,y;
  214.     int number;                /* type of point */
  215. {
  216.     LATEX_move(x,y);
  217.     
  218.     /* Print the character defined by 'number'; number < 0 means 
  219.       to use a dot, otherwise one of the defined points. */
  220.     fprintf(outfile, "\\put(%d,%d){%s}\n", x, y, 
  221.           (number < 0 ? LATEX_TINY_DOT
  222.            : LATEX_points[number % LATEX_POINT_TYPES]));
  223. }
  224.  
  225.  
  226. LATEX_vector(ux,uy)
  227.     unsigned int ux,uy;
  228. {
  229.     if (LATEX_dotspace == 0.0) {
  230.        /* solid line */
  231. #ifdef EMTEX
  232.        if (emtex)
  233.         EMTEX_solid_line(LATEX_posx, (int)ux, LATEX_posy, (int)uy);
  234.        else
  235. #endif
  236.         LATEX_solid_line(LATEX_posx, (int)ux, LATEX_posy, (int)uy);
  237.     } else
  238.      /* dotted line */
  239.      LATEX_dot_line(LATEX_posx, (int)ux, LATEX_posy, (int)uy);
  240.  
  241.     LATEX_posx = ux;
  242.     LATEX_posy = uy;
  243. }
  244.  
  245. static void
  246. LATEX_solid_line(x1,x2, y1,y2)
  247.     int x1,x2, y1,y2;
  248. {
  249.     float slope;
  250.     int inc;
  251.     float next;
  252.     float x,y;
  253.     int code;                /* possibly combine with previous rule */
  254.  
  255.     /* we draw a solid line using the current line thickness (size) */
  256.     /* we do it with lots of \\rules */
  257.  
  258.     if (x1 == x2 && y1 == y2) { /* zero-length line - just a dot */
  259.        if (LATEX_moved) {
  260.           LATEX_flushrule();
  261.           /* plot a dot */
  262.           fprintf(outfile, "\\put(%u,%u){%s}\n", x1, y1, LATEX_DOT);
  263.        }
  264.     } else {
  265.        code = (LATEX_moved ? 0 : 1); /* no combine after move */
  266.        if (x1 == x2)        /* vertical line - special case */
  267.         LATEX_rule(code, (double)x1, (double)y1,
  268.                LATEX_dotsize, (double)y2-y1);
  269.        else if (y1 == y2)    /* horizontal line - special case */
  270.         LATEX_rule(code, (double)x1, (double)y1, (double)x2-x1,
  271.                LATEX_dotsize);
  272.        else {
  273.           slope = ((float)y2-y1)/((float)x2-x1);
  274.           if (abs(slope) <= 1.0) {
  275.              /* longer than high */
  276.              inc = sign(y2-y1);
  277.              for (x = x1, y = y1; (y2-y)*inc >= 0; y += inc) {
  278.                 next = inc/slope + x;
  279.                 if ((x2>x1 && next > x2) || (x2<x1 && next < x2)) {
  280.                     LATEX_rule(code, x,y, x2-x, LATEX_dotsize);
  281.                     break;
  282.                 } else {
  283.                     LATEX_rule(code, x,y, next-x, LATEX_dotsize);
  284.                     x = next;
  285.                 }
  286.                 code = 0;
  287.              }
  288.           } else {
  289.              /* higher than long */
  290.              inc = sign(x2-x1);
  291.              for (x = x1, y = y1; (x2-x)*inc >= 0; x += inc) {
  292.                 next = inc*slope + y;
  293.                 if ((y2>y1 && next > y2) || (y2<y1 && next < y2)) {
  294.                     LATEX_rule(code, x,y, LATEX_dotsize, y2-y);
  295.                     break;
  296.                 } else {
  297.                     LATEX_rule(code, x,y, LATEX_dotsize, next-y);
  298.                     y = next;
  299.                 }
  300.                 code = 0;
  301.              }
  302.           }
  303.        }
  304.     }
  305.     LATEX_moved = FALSE;
  306. }
  307.  
  308. /* Draw a \rule. Width or height may be negative; we can correct.
  309.  * The rule is never output immediately. The previous rule is output
  310.  * as-is if code is 0, and the previous rule is
  311.  * combined with the current rule (if possible) if code is 1.
  312.  * The previous rule is output, and the new one ignored, if code is 2.
  313.  */
  314. static void
  315. LATEX_rule(code, x,y, width, height)
  316.     int code;                /* how do we treat this rule? */
  317.     double x, y;
  318.     double width;
  319.     double height;
  320. {  
  321.     static float lastx, lasty;
  322.     static float lastw, lasth;
  323.     static BOOLEAN valid = FALSE; /* is 'last' data valid? */
  324.     BOOLEAN combine = (code == 1);
  325.     BOOLEAN flush = (code == 2);
  326.  
  327.     if (!flush)
  328.      if (width == 0 || height == 0)
  329.        return;            /* ignore this rule */
  330.  
  331.     if (valid && combine) {
  332.        /* try to combine new rule with old rule */
  333.        if ((int)lastx == (int)x && lastw == width) { /* vertical rule */
  334.           if (lasth * height >= 0) { /* same sign */
  335.              lasth += height;
  336.              return;
  337.           }
  338.        } else if ((int)lasty == (int)y && lasth == height){ /* horiz rule */
  339.           if (lastw * width >= 0) { /* same sign */
  340.              lastw += width;
  341.              return;
  342.           }
  343.        }
  344.        /* oh well, output last and remember the new one */
  345.     }
  346.  
  347.     if (valid) {
  348.        /* output the rule */
  349.        if (lastw < 0) {
  350.           lastx += lastw;
  351.           lastw = -lastw;
  352.        }
  353.        if (lasth < 0) {
  354.           lasty += lasth;
  355.           lasth = -lasth;
  356.        }
  357.  
  358.        /* if very small use canned dot */
  359.        if (lastw < LATEX_dotsize || lasth < LATEX_dotsize)
  360.         fprintf(outfile, "\\put(%d,%d){%s}\n",       
  361.                (int)lastx, (int)lasty, LATEX_DOT);
  362.        else
  363.         fprintf(outfile, "\\put(%d,%d){\\rule[%.3fpt]{%.3fpt}{%.3fpt}}\n",
  364.                (int)lastx, (int)lasty, -LATEX_dotsize*LATEX_UNIT/2,
  365.                lastw*LATEX_UNIT, lasth*LATEX_UNIT);
  366.     }
  367.     
  368.     if (flush) {
  369.        valid = FALSE;
  370.     } else {
  371.        lastx = x; lasty = y;
  372.        lastw = width; lasth = height;
  373.        valid = TRUE;
  374.     }
  375. }
  376.  
  377. static void
  378. LATEX_dot_line(x1,x2, y1,y2)
  379.     int x1,x2, y1,y2;
  380. {
  381.     static float LATEX_left;    /* fraction of space left after last dot */
  382. #ifndef AMIGA_AC_5
  383.     extern double sqrt();
  384. #endif
  385.     /* we draw a dotted line using the current dot spacing */
  386.  
  387.     if (LATEX_moved)
  388.      LATEX_left = 1.0;        /* reset after a move */
  389.  
  390.     /* zero-length line? */
  391.     if (x1 == x2 && y1 == y2) {
  392.        if (LATEX_moved)
  393.         /* plot a dot */
  394.         fprintf(outfile, "\\put(%u,%u){%s}\n", x1, y1, LATEX_DOT);
  395.     } else {
  396.        float dotspace = LATEX_dotspace / LATEX_UNIT;
  397.        float x,y;            /* current position */
  398.        float xinc, yinc;    /* increments */
  399.        float slope;        /* slope of line */
  400.        float lastx = -1;    /* last x point plotted */
  401.        float lasty = -1;    /* last y point plotted */
  402.  
  403.        /* first, figure out increments for x and y */
  404.        if (x2 == x1) {
  405.           xinc = 0.0;
  406.           yinc = dotspace;
  407.        } else {
  408.           slope = ((float)y2-y1)/((float)x2-x1);
  409.           xinc = dotspace / sqrt(1 + slope*slope) * sign(x2-x1);
  410.           yinc = slope * xinc;
  411.        }
  412.        
  413.        /* now draw the dotted line */
  414.        /* we take into account where we last placed a dot */
  415.        for (x=x1 + xinc*(1-LATEX_left), y=y1 + yinc*(1-LATEX_left);
  416.            (x2-x)*xinc >= 0 && (y2-y)*yinc >= 0; /* same sign or zero */
  417.            lastx = x, x += xinc, 
  418.            lasty = y, y += yinc)
  419.         fprintf(outfile, "\\put(%d,%d){%s}\n", (int)x, (int)y, LATEX_DOT);
  420.  
  421.        /* how much is left over, as a fraction of dotspace? */
  422.        if (xinc != 0.0)            /* xinc must be nonzero */
  423.         if (lastx >= 0)
  424.           LATEX_left = abs(x2 - lastx) / abs(xinc);
  425.         else
  426.           LATEX_left += abs(x2-x1) / abs(xinc);
  427.        else
  428.         if (lasty >= 0)
  429.           LATEX_left = abs(y2 - lasty) / abs(yinc);
  430.         else
  431.           LATEX_left += abs(y2-y1) / abs(yinc);
  432.     }
  433.  
  434.     LATEX_needsdot = (LATEX_left > 0);
  435.  
  436.     LATEX_moved = FALSE;
  437. }
  438.  
  439. static void
  440. LATEX_flushdot()
  441. {
  442.     if (LATEX_needsdot) 
  443.      fprintf(outfile, "\\put(%d,%d){%s}\n", 
  444.             LATEX_posx, LATEX_posy, LATEX_DOT);
  445.     LATEX_needsdot = FALSE;
  446. }
  447.  
  448. LATEX_arrow(sx,sy, ex,ey, head)
  449.     int sx,sy, ex,ey;
  450.     BOOLEAN head;
  451. {
  452.     best_latex_arrow(sx,sy, ex,ey, 1, head);
  453.  
  454.     LATEX_posx = ex;
  455.     LATEX_posy = ey;
  456. }
  457.  
  458. static void best_latex_arrow(sx,sy, ex,ey, who, head)
  459.     int sx,sy, ex,ey;        /* start and end points */
  460.     int who;                /* 1=LATEX, 2=EEPIC */
  461.     BOOLEAN head;
  462. {
  463.     int dx = ex - sx;
  464.     int dy = ey - sy;
  465.     int x, y;                /* points near sx,sy */
  466.     float m;                /* slope of line */
  467.     float arrowslope;        /* slope of arrow */
  468.     float minerror = 0;        /* best-case error */
  469.     struct vslope *slope;    /* one of the slopes */
  470.     struct vslope *bestslope;    /* the slope with min error */
  471.     BOOLEAN horiz;            /* was it the horiz line that was best? */
  472.  
  473.     /* We try to draw a real arrow (ie, \vector). If we can't get
  474.     * a slope that is close, we draw a bent arrow.
  475.     */
  476.  
  477.     if (dx == 0) {
  478.        /* vertical arrow */
  479.        fprintf(outfile, "\\put(%d,%d){\\%s(0,%d){%d}}\n",
  480.              sx, sy, head ? "vector":"line", 
  481.              sign(ey-sy), abs(ey-sy));
  482.     } else if (dy == 0) {
  483.        /* horizontal arrow */
  484.        fprintf(outfile, "\\put(%d,%d){\\%s(%d,0){%d}}\n",
  485.              sx, sy, head ? "vector":"line",
  486.              sign(ex-sx), abs(ex-sx));
  487.     } else {
  488.        /* Slanted arrow. We'll give it a try.
  489.         * we try to find the closest-slope arrowhead.
  490.         */
  491.        bestslope = NULL;
  492.        minerror = 0; /* to shut up turbo C */
  493.        m = abs((float)dy/dx); /* the slope we want */
  494.        for (slope = LATEX_slopes; slope->dx != 0.0; slope++) {
  495.           /* find the slope of the arrow */
  496.           arrowslope = (float) slope->dy / slope->dx;
  497.           if (bestslope == NULL || abs(m-arrowslope) < minerror) {
  498.              minerror = abs(m-arrowslope);
  499.              bestslope = slope;
  500.           }
  501.        }
  502.  
  503.        /* now we have the best slope arrow */
  504.        /* maybe it's exactly the right slope! */
  505.        if (minerror == 0.0)    /* unlikely but possible */
  506.         fprintf(outfile, "\\put(%d,%d){\\%s(%d,%d){%d}}\n",
  507.                sx, sy, head ? "vector" : "line",
  508.                bestslope->dx*sign(ex-sx), bestslope->dy*sign(ey-sy),
  509.                abs(ex-sx));
  510.        else {
  511.           /* we draw the line the usual way, with thin lines */
  512. #ifdef EMTEX
  513.           if (emtex) {
  514.              LATEX_linetype(LATEX_THIN_LINE);
  515.              EMTEX_solid_line(sx,ex,sy,ey);
  516.           } else 
  517. #endif
  518.             if (who == 1) {
  519.                LATEX_linetype(LATEX_THIN_LINE);
  520.                LATEX_solid_line(sx,ex,sy,ey);
  521.             }
  522. #ifdef EEPIC
  523.             else {
  524.                EEPIC_move(sx,sy);
  525.                EEPIC_vector(ex,ey);
  526.             }
  527. #endif /* EEPIC */
  528.           /* and then draw an arrowhead (a short vector) there */
  529.             if (head)
  530.                   fprintf(outfile, "\\put(%d,%d){\\vector(%d,%d){0}}\n",
  531.                 ex, ey, 
  532.                 bestslope->dx*sign(ex-sx), bestslope->dy*sign(ey-sy));
  533.        }
  534.     }
  535. }
  536.  
  537.  
  538. LATEX_put_text(x, y, str)
  539.     int x,y;                /* reference point of string */
  540.     char str[];            /* the text */
  541. {
  542.     /* ignore empty strings */
  543.     if (str[0] == '\0')
  544.      return;
  545.  
  546.     fprintf(outfile, "\\put(%d,%d)",x,y);
  547.     switch(latex_angle) {  
  548.         case 0: {
  549.           switch(latex_justify) {
  550.              case LEFT: {
  551.                 fprintf(outfile,
  552.                        "{\\makebox(0,0)[l]{%s}}\n", str);
  553.                 break;
  554.              }
  555.              case CENTRE: {
  556.                 fprintf(outfile,
  557.                        "{\\makebox(0,0){%s}}\n", str);
  558.                 break;
  559.              }
  560.              case RIGHT: {
  561.                 fprintf(outfile,
  562.                        "{\\makebox(0,0)[r]{%s}}\n", str);
  563.                 break;
  564.              }
  565.           }
  566.           break;
  567.        }
  568.        case 1: {            /* put text in a short stack */
  569.           switch(latex_justify) {
  570.              case LEFT: {
  571.                 fprintf(outfile,
  572.                        "{\\makebox(0,0)[lb]{\\shortstack{%s}}}\n", str);
  573.                 break;
  574.              }
  575.              case CENTRE: {
  576.                 fprintf(outfile,
  577.                        "{\\makebox(0,0)[l]{\\shortstack{%s}}}\n", str);
  578.                 break;
  579.              }
  580.              case RIGHT: {
  581.                 fprintf(outfile,
  582.                        "{\\makebox(0,0)[lt]{\\shortstack{%s}}}\n", str);
  583.                 break;
  584.              }
  585.           }
  586.           break;
  587.        }    
  588.     }
  589. }
  590.  
  591.  
  592.  
  593. int LATEX_justify_text(mode)
  594.     enum JUSTIFY mode;
  595. {
  596.     latex_justify = mode;
  597.     return (TRUE);
  598. }
  599.  
  600. int LATEX_text_angle(angle)
  601.     int angle;
  602. {
  603.     /* we can't really write text vertically, but this will 
  604.       put the ylabel centred at the left of the plot, and
  605.       then we'll make a \shortstack */
  606.     latex_angle = angle;
  607.     return (TRUE);
  608. }
  609.  
  610. LATEX_reset()
  611. {
  612.     LATEX_posx = LATEX_posy = 0; /* current position */
  613.     LATEX_moved = TRUE;    /* pen is up after move */
  614. }
  615.  
  616.  
  617. #ifdef EMTEX
  618.  
  619. EMTEX_init()
  620. {
  621.     emtex=TRUE;
  622.     LATEX_posx = LATEX_posy = 0;
  623.     fprintf(outfile, "%% GNUPLOT: LaTeX picture with emtex specials\n");
  624.     fprintf(outfile, "\\setlength{\\unitlength}{%fpt}\n", LATEX_UNIT);
  625.     fprintf(outfile, 
  626.           "\\ifx\\plotpoint\\undefined\\newsavebox{\\plotpoint}\\fi\n");
  627.     LATEX_linetype(-1);
  628. }
  629.  
  630.  
  631. EMTEX_reset()
  632. {
  633.     emtex=FALSE;
  634.     LATEX_posx = LATEX_posy = 0;
  635. }
  636.  
  637.  
  638. EMTEX_text()
  639. {
  640.     fprintf(outfile, "\\end{picture}\n");
  641. }
  642.  
  643.  
  644. static void
  645. EMTEX_solid_line(x1,x2, y1,y2)
  646.     int x1,x2, y1,y2;
  647. {
  648.     /* emtex special solid line */
  649.     if (LATEX_moved)
  650.         fprintf(outfile, "\\put(%d,%d){\\special{em:moveto}}\n", x1, y1);
  651.     if ( (x1!=x2) || (y1!=y2) )
  652.         fprintf(outfile, "\\put(%d,%d){\\special{em:lineto}}\n", x2, y2);
  653.     LATEX_posx = x2;
  654.     LATEX_posy = y2;
  655.     LATEX_moved = FALSE;
  656. }
  657.  
  658.  
  659. #endif /* EMTEX */
  660.