File:  [LON-CAPA] / loncom / xml / lonplot.pm
Revision 1.163: download - view: text, annotated - select for diffs
Tue Jul 24 10:50:54 2012 UTC (11 years, 9 months ago) by foxr
Branches: MAIN
CVS tags: HEAD
BZ5635 - Provide complete control over axis major tics.

    1: # The LearningOnline Network with CAPA
    2: # Dynamic plot
    3: #
    4: # $Id: lonplot.pm,v 1.163 2012/07/24 10:50:54 foxr Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: 
   30: 
   31: 
   32: package Apache::lonplot;
   33: 
   34: use strict;
   35: use warnings FATAL=>'all';
   36: no warnings 'uninitialized';
   37: use Apache::File;
   38: use Apache::response;
   39: use Apache::lonxml;
   40: use Apache::edit;
   41: use Apache::lonnet;
   42: use LONCAPA;
   43:  
   44: 
   45: use vars qw/$weboutputformat $version/;
   46: 
   47: 
   48: 
   49: BEGIN {
   50:     &Apache::lonxml::register('Apache::lonplot',('gnuplot'));
   51:     #
   52:     # Determine the version of GNUPLOT
   53:     $weboutputformat = 'gif';
   54:     my $versionstring = `gnuplot --version 2>/dev/null`;
   55:     ($version) = ($versionstring =~ /^gnuplot ([\d.]+)/);
   56:     if ($version >= 4) {
   57:         $weboutputformat = 'png';
   58:     }
   59:     
   60: }
   61: 
   62: 
   63: =pod
   64: 
   65: ## 
   66: ## Description of data structures:
   67: ##
   68: ##  %plot       %key    %axis
   69: ## --------------------------
   70: ##  height      title   color
   71: ##  width       box     xmin
   72: ##  bgcolor     pos     xmax
   73: ##  fgcolor             ymin
   74: ##  transparent         ymax
   75: ##  grid
   76: ##  border
   77: ##  font
   78: ##  align
   79: ##
   80: ##  @labels: $labels[$i] = \%label
   81: ##           %label: text, xpos, ypos, justify
   82: ##
   83: ##  @curves: $curves[$i] = \%curve
   84: ##           %curve: name, linestyle, ( function | data )
   85: ##
   86: ##  $curves[$i]->{'data'} = [ [x1,x2,x3,x4],
   87: ##                            [y1,y2,y3,y4] ]
   88: ##
   89: 
   90: ###################################################################
   91: ##                                                               ##
   92: ##        Tests used in checking the validitity of input         ##
   93: ##                                                               ##
   94: ###################################################################
   95: 
   96: =cut
   97: 
   98: my $max_str_len = 50;    # if a label, title, xlabel, or ylabel text
   99:                          # is longer than this, it will be truncated.
  100: 
  101: my %linetypes =			# For png use these linetypes.
  102:     (
  103:      solid          => 1,
  104:      dashed         => 0
  105:     );
  106: my %ps_linetypes = 		# For ps the line types are different!
  107:    (
  108:     solid          => 0,
  109:     dashed         => 7
  110:    );
  111: 
  112: my %linestyles = 
  113:     (
  114:      lines          => 2,     # Maybe this will be used in the future
  115:      linespoints    => 2,     # to check on whether or not they have 
  116:      dots	    => 2,     # supplied enough <data></data> fields
  117:      points         => 2,     # to use the given line style.  But for
  118:      steps	    => 2,     # now there are more important things 
  119:      fsteps	    => 2,     # for me to deal with.
  120:      histeps        => 2,
  121:      errorbars	    => 3,
  122:      xerrorbars	    => [3,4],
  123:      yerrorbars	    => [3,4],
  124:      xyerrorbars    => [4,6],
  125:      boxes          => 3,
  126:      filledcurves   => 2,
  127:      vector	    => 4
  128:     );		    
  129: 
  130: my $int_test       = sub {$_[0]=~s/\s+//g;$_[0]=~/^\d+$/};
  131: my $real_test      = 
  132:     sub {$_[0]=~s/\s+//g;$_[0]=~/^[+-]?\d*\.?\d*([eE][+-]\d+)?$/};
  133: my $pos_real_test  =
  134:     sub {$_[0]=~s/\s+//g;$_[0]=~/^[+]?\d*\.?\d*([eE][+-]\d+)?$/};
  135: my $color_test     = sub {$_[0]=~s/\s+//g;$_[0]=~/^x[\da-fA-F]{6}$/};
  136: my $onoff_test     = sub {$_[0]=~/^(on|off)$/};
  137: my $key_pos_test   = sub {$_[0]=~/^(top|bottom|right|left|outside|below| )+$/};
  138: my $sml_test       = sub {$_[0]=~/^(\d+|small|medium|large)$/};
  139: my $linestyle_test = sub {exists($linestyles{$_[0]})};
  140: my $words_test     = sub {$_[0]=~s/\s+/ /g;$_[0]=~/^([\w~!\@\#\$\%^&\*\(\)-=_\+\[\]\{\}:\;\'<>,\.\/\?\\]+ ?)+$/};
  141: 
  142: my $arrowhead_test = sub{$_[0]=~/^(nohead|head|heads| )+$/};
  143: my $arrowstyle_test= sub{$_[0]=~/^(filled|empty|nofilled)+$/};
  144: my $degree_test  = sub{&$pos_real_test($_[0]) && ($_[0] <= 360.0)};
  145: 
  146: ###################################################################
  147: ##                                                               ##
  148: ##                      Attribute metadata                       ##
  149: ##                                                               ##
  150: ###################################################################
  151: my @gnuplot_edit_order = 
  152:     qw/alttag bgcolor fgcolor height width texwidth fontface font texfont
  153:     transparent grid samples 
  154:     border align plotcolor plottype gridtype lmargin rmargin
  155:     tmargin bmargin major_ticscale minor_ticscale boxwidth gridlayer fillstyle
  156:     pattern solid/;
  157: 
  158: my $margin_choices = ['default',0..20];
  159: 
  160: my %gnuplot_defaults = 
  161:     (
  162:      alttag       => {
  163: 	 default     => 'dynamically generated plot',
  164: 	 test        => $words_test,
  165: 	 description => 'Brief description of the plot',
  166:       	 edit_type   => 'entry',
  167: 	 size        => '40'
  168: 	 },
  169:      height       => {
  170: 	 default     => 300,
  171: 	 test        => $int_test,
  172: 	 description => 'Height of image (pixels)',
  173:       	 edit_type   => 'entry',
  174: 	 size        => '10'
  175: 	 },
  176:      width        => {
  177: 	 default     => 400,
  178: 	 test        => $int_test,
  179: 	 description => 'Width of image (pixels)',
  180: 	 edit_type   => 'entry',
  181: 	 size        => '10'
  182: 	 },
  183:      bgcolor      => {
  184: 	 default     => 'xffffff',
  185: 	 test        => $color_test, 
  186: 	 description => 'Background color of image (xffffff)',
  187: 	 edit_type   => 'entry',
  188: 	 size        => '10',
  189:          class       => 'colorchooser'
  190: 	 },
  191:      fgcolor      => {
  192: 	 default     => 'x000000',
  193: 	 test        => $color_test,
  194: 	 description => 'Foreground color of image (x000000)',
  195: 	 edit_type   => 'entry',
  196: 	 size        => '10',
  197:          class       => 'colorchooser'
  198: 	 },
  199:      transparent  => {
  200: 	 default     => 'off',
  201: 	 test        => $onoff_test, 
  202: 	 description => 'Transparent image',
  203: 	 edit_type   => 'onoff'
  204: 	 },
  205:      grid         => {
  206: 	 default     => 'on',
  207: 	 test        => $onoff_test, 
  208: 	 description => 'Display grid',
  209: 	 edit_type   => 'onoff'
  210: 	 },
  211:      gridlayer    => {
  212: 	 default     => 'off',
  213: 	 test        => $onoff_test, 
  214: 	 description => 'Display grid front layer over filled boxes or filled curves',
  215: 	 edit_type   => 'onoff'
  216: 	 },
  217:      box_border   => {
  218: 	 default     => 'noborder',
  219: 	 test        => sub {$_[0]=~/^(noborder|border)$/},
  220: 	 description => 'Draw border for boxes',
  221: 	 edit_type   => 'choice',
  222: 	 choices     => ['border','noborder']
  223: 	 },
  224:      border       => {
  225: 	 default     => 'on',
  226: 	 test        => $onoff_test, 
  227: 	 description => 'Draw border around plot',
  228: 	 edit_type   => 'onoff'
  229: 	 },
  230:      font         => {
  231: 	 default     => '9',
  232: 	 test        => $sml_test,
  233: 	 description => 'Font size to use in web output (pts)',
  234: 	 edit_type   => 'choice',
  235: 	 choices     => [['5','5 (small)'],'6','7','8',['9','9 (medium)'],'10',['11','11 (large)'],'12','15']
  236: 	 },
  237:      fontface     => {
  238:         default     => 'sans-serif',
  239:         test        => sub {$_[0]=~/^(sans-serif|serif|classic)$/},
  240:         description => 'Type of font to use',
  241:         edit_type   => 'choice',
  242:         choices     => ['sans-serif','serif', 'classic']
  243:         },
  244:      samples      => {
  245: 	 default     => '100',
  246: 	 test        => $int_test,
  247: 	 description => 'Number of samples for non-data plots',
  248: 	 edit_type   => 'choice',
  249: 	 choices     => ['100','200','500','1000','2000','5000']
  250: 	 },
  251:      align        => {
  252: 	 default     => 'middle',
  253: 	 test        => sub {$_[0]=~/^(left|right|middle|center)$/},
  254: 	 description => 'Alignment for image in HTML',
  255: 	 edit_type   => 'choice',
  256: 	 choices     => ['left','right','middle']
  257: 	 },
  258:      texwidth     => {
  259:          default     => '93',
  260:          test        => $int_test,
  261:          description => 'Width of plot when printed (mm)',
  262:          edit_type   => 'entry',
  263:          size        => '5'
  264:          },
  265:      texfont      => {
  266:          default     => '22',
  267:          test        => $int_test,
  268:          description => 'Font size to use in TeX output (pts):',
  269:          edit_type   => 'choice',
  270:          choices     => [qw/8 10 12 14 16 18 20 22 24 26 28 30 32 34 36/],
  271:          },
  272:      plotcolor    => {
  273:          default     => 'monochrome',
  274:          test        => sub {$_[0]=~/^(monochrome|color|colour)$/},
  275:          description => 'Color setting for printing:',
  276:          edit_type   => 'choice',
  277:          choices     => [qw/monochrome color colour/],
  278:          },
  279:      pattern      => {
  280: 	 default     => '',
  281: 	 test        => $int_test,
  282: 	 description => 'Pattern value for boxes:',
  283: 	 edit_type   => 'choice',
  284:          choices     => [0,1,2,3,4,5,6]
  285:          },
  286:      solid        => {
  287:          default     => 0,
  288:          test        => $real_test,
  289:          description => 'The density of fill style for boxes',
  290:          edit_type   => 'entry',
  291:          size        => '5'
  292:          },
  293:      fillstyle    => {
  294: 	 default     => 'empty',
  295: 	 test        => sub {$_[0]=~/^(empty|solid|pattern)$/},
  296: 	 description => 'Filled style for boxes:',
  297: 	 edit_type   => 'choice',
  298:          choices     => ['empty','solid','pattern']
  299:          },
  300:      plottype     => {
  301: 	 default     => 'Cartesian',
  302: 	 test        => sub {$_[0]=~/^(Polar|Cartesian)$/},
  303: 	 description => 'Plot type:',
  304: 	 edit_type   => 'choice',
  305:          choices     => ['Cartesian','Polar']
  306:          },
  307:      gridtype     => {
  308: 	 default     => 'Cartesian',
  309: 	 test        => sub {$_[0]=~/^(Polar|Cartesian|Linear-Log|Log-Linear|Log-Log)$/},
  310: 	 description => 'Grid type:',
  311: 	 edit_type   => 'choice',
  312:          choices     => ['Cartesian','Polar','Linear-Log','Log-Linear','Log-Log']
  313:          },
  314:      lmargin      => {
  315: 	 default     => 'default',
  316: 	 test        => sub {$_[0]=~/^(default|\d+)$/},
  317: 	 description => 'Left margin width (pts):',
  318: 	 edit_type   => 'choice',
  319:          choices     => $margin_choices,
  320:          },
  321:      rmargin      => {
  322: 	 default     => 'default',
  323: 	 test        => sub {$_[0]=~/^(default|\d+)$/},
  324: 	 description => 'Right margin width (pts):',
  325: 	 edit_type   => 'choice',
  326:          choices     => $margin_choices,
  327:          },
  328:      tmargin      => {
  329: 	 default     => 'default',
  330: 	 test        => sub {$_[0]=~/^(default|\d+)$/},
  331: 	 description => 'Top margin width (pts):',
  332: 	 edit_type   => 'choice',
  333:          choices     => $margin_choices,
  334:          },
  335:      bmargin      => {
  336: 	 default     => 'default',
  337: 	 test        => sub {$_[0]=~/^(default|\d+)$/},
  338: 	 description => 'Bottom margin width (pts):',
  339: 	 edit_type   => 'choice',
  340:          choices     => $margin_choices,
  341:          },
  342:      boxwidth     => {
  343: 	 default     => '',
  344: 	 test        => $real_test, 
  345: 	 description => 'Width of boxes, default is auto',
  346: 	 edit_type   => 'entry',
  347:          size        => '5'
  348:          },
  349:      major_ticscale  => {
  350:          default     => '1',
  351:          test        => $real_test,
  352:          description => 'Size of major tic marks (plot coordinates)',
  353:          edit_type   => 'entry',
  354:          size        => '5'
  355:          },
  356:      minor_ticscale  => {
  357:          default     => '0.5',
  358:          test        => $real_test,
  359:          description => 'Size of minor tic mark (plot coordinates)',
  360:          edit_type   => 'entry',
  361:          size        => '5'
  362:          },
  363:      );
  364: 
  365: my %key_defaults = 
  366:     (
  367:      title => { 
  368: 	 default => '',
  369: 	 test => $words_test,
  370: 	 description => 'Title of key',
  371: 	 edit_type   => 'entry',
  372: 	 size        => '40'
  373: 	 },
  374:      box   => { 
  375: 	 default => 'off',
  376: 	 test => $onoff_test,
  377: 	 description => 'Draw a box around the key?',
  378: 	 edit_type   => 'onoff'
  379: 	 },
  380:      pos   => { 
  381: 	 default => 'top right', 
  382: 	 test => $key_pos_test, 
  383: 	 description => 'Position of the key on the plot',
  384: 	 edit_type   => 'choice',
  385: 	 choices     => ['top left','top right','bottom left','bottom right',
  386: 			 'outside','below']
  387: 	 }
  388:      );
  389: 
  390: my %label_defaults = 
  391:     (
  392:      xpos    => {
  393: 	 default => 0,
  394: 	 test => $real_test,
  395: 	 description => 'X position of label (graph coordinates)',
  396: 	 edit_type   => 'entry',
  397: 	 size        => '10'
  398: 	 },
  399:      ypos    => {
  400: 	 default => 0, 
  401: 	 test => $real_test,
  402: 	 description => 'Y position of label (graph coordinates)',
  403: 	 edit_type   => 'entry',
  404: 	 size        => '10'
  405: 	 },
  406:      justify => {
  407: 	 default => 'left',    
  408: 	 test => sub {$_[0]=~/^(left|right|center)$/},
  409: 	 description => 'justification of the label text on the plot',
  410: 	 edit_type   => 'choice',
  411: 	 choices     => ['left','right','center']
  412:      },
  413:      rotate => {
  414:          default => 0,
  415:          test => $real_test,
  416:          description => 'Rotation of label (degrees)',
  417:          edit_type   => 'entry',
  418:          size        => '10',
  419:      }
  420:      );
  421: 
  422: my @tic_edit_order = ('location','mirror','start','increment','end',
  423:                       'minorfreq');
  424: my %tic_defaults =
  425:     (
  426:      location => {
  427: 	 default => 'border', 
  428: 	 test => sub {$_[0]=~/^(border|axis)$/},
  429: 	 description => 'Location of major tic marks',
  430: 	 edit_type   => 'choice',
  431: 	 choices     => ['border','axis']
  432: 	 },
  433:      mirror => {
  434: 	 default => 'on', 
  435: 	 test => $onoff_test,
  436: 	 description => 'Mirror tics on opposite axis?',
  437: 	 edit_type   => 'onoff'
  438: 	 },
  439:      start => {
  440: 	 default => '-10.0',
  441: 	 test => $real_test,
  442: 	 description => 'Start major tics at',
  443: 	 edit_type   => 'entry',
  444: 	 size        => '10'
  445: 	 },
  446:      increment => {
  447: 	 default => '1.0',
  448: 	 test => $real_test,
  449: 	 description => 'Place a major tic every',
  450: 	 edit_type   => 'entry',
  451: 	 size        => '10'
  452: 	 },
  453:      end => {
  454: 	 default => ' 10.0',
  455: 	 test => $real_test,
  456: 	 description => 'Stop major tics at ',
  457: 	 edit_type   => 'entry',
  458: 	 size        => '10'
  459: 	 },
  460:      minorfreq => {
  461: 	 default => '0',
  462: 	 test => $int_test,
  463: 	 description => 'Number of minor tics per major tic mark',
  464: 	 edit_type   => 'entry',
  465: 	 size        => '10'
  466: 	 },         
  467:      );
  468: 
  469: my @axis_edit_order = ('color','xmin','xmax','ymin','ymax','xformat', 'yformat', 'xzero', 'yzero');
  470: my %axis_defaults = 
  471:     (
  472:      color   => {
  473: 	 default => 'x000000', 
  474: 	 test => $color_test,
  475: 	 description => 'Color of grid lines (x000000)',
  476: 	 edit_type   => 'entry',
  477: 	 size        => '10',
  478:          class       => 'colorchooser'
  479: 	 },
  480:      xmin      => {
  481: 	 default => '-10.0',
  482: 	 test => $real_test,
  483: 	 description => 'Minimum x-value shown in plot',
  484: 	 edit_type   => 'entry',
  485: 	 size        => '10'
  486: 	 },
  487:      xmax      => {
  488: 	 default => ' 10.0',
  489: 	 test => $real_test,
  490: 	 description => 'Maximum x-value shown in plot',	 
  491: 	 edit_type   => 'entry',
  492: 	 size        => '10'
  493: 	 },
  494:      ymin      => {
  495: 	 default => '-10.0',
  496: 	 test => $real_test,
  497: 	 description => 'Minimum y-value shown in plot',	 
  498: 	 edit_type   => 'entry',
  499: 	 size        => '10'
  500: 	 },
  501:      ymax      => {
  502: 	 default => ' 10.0',
  503: 	 test => $real_test,
  504: 	 description => 'Maximum y-value shown in plot',	 
  505: 	 edit_type   => 'entry',
  506: 	 size        => '10'
  507:         },
  508:      xformat      => {
  509:          default     => 'on',
  510:          test        => sub {$_[0]=~/^(on|off|\d+(f|F|e|E))$/},
  511:          description => 'X-axis number formatting',
  512:          edit_type   => 'choice',
  513:          choices     => ['on', 'off', '2e', '2f'],
  514:          },
  515:      yformat      => {
  516:          default     => 'on',
  517:          test        => sub {$_[0]=~/^(on|off|\d+(f|F|e|E))$/},
  518:          description => 'Y-axis number formatting',
  519:          edit_type   => 'choice',
  520:          choices     => ['on', 'off', '2e', '2f'],
  521:          },
  522:      
  523:      xzero => {
  524:      	default => 'off',
  525:      	test	=> sub {$_[0]=~/^(off|line|thick-line|dotted)$/},
  526:      	description => 'Show x-zero (y=0) axis',
  527:      	edit_type  => 'choice',
  528:      	choices	=> ['off', 'line', 'thick-line', 'dotted'],
  529:      	},
  530:      
  531:      yzero => {
  532:      	default => 'off',
  533:      	test	=> sub {$_[0]=~/^(off|line|thick-line|dotted)$/},
  534:      	description => 'Show y-zero (x=0) axis',
  535:      	edit_type  => 'choice',
  536:      	choices	=> ['off', 'line', 'thick-line', 'dotted'],
  537:      	},
  538:      );
  539: 
  540: 
  541: my @curve_edit_order = ('color','name','linestyle','linewidth','linetype',
  542: 			'pointtype','pointsize','limit', 'arrowhead', 'arrowstyle', 
  543: 			'arrowlength', 'arrowangle', 'arrowbackangle'
  544:     );
  545: 
  546: my %curve_defaults = 
  547:     (
  548:      color     => {
  549: 	 default => 'x000000',
  550: 	 test => $color_test,
  551: 	 description => 'Color of curve (x000000)',
  552: 	 edit_type   => 'entry',
  553: 	 size        => '10',
  554: 	 class       => 'colorchooser'
  555: 	 },
  556:      name      => {
  557: 	 default => '',
  558: 	 test => $words_test,
  559: 	 description => 'Name of curve to appear in key',
  560: 	 edit_type   => 'entry',
  561: 	 size        => '20'
  562: 	 },
  563:      linestyle => {
  564: 	 default => 'lines',
  565: 	 test => $linestyle_test,
  566: 	 description => 'Plot with:',
  567: 	 edit_type   => 'choice',
  568: 	 choices     => [keys(%linestyles)]
  569: 	 },
  570:      linewidth => {
  571:          default     => 1,
  572:          test        => $int_test,
  573:          description => 'Line width (may not apply to all plot styles)',
  574:          edit_type   => 'choice',
  575:          choices     => [1,2,3,4,5,6,7,8,9,10]
  576:          },
  577:      linetype => {
  578:          default     => 'solid',
  579:          test        => sub {$_[0]=~/^(solid|dashed)$/},
  580:          description => 'Line type (may not apply to all plot styles)',
  581:          edit_type   => 'choice',
  582:          choices     => ['solid', 'dashed']
  583:          }, 
  584:      pointsize => {
  585:          default     => 1,
  586:          test        => $pos_real_test,
  587:          description => 'Point size (may not apply to all plot styles)',
  588:          edit_type   => 'entry',
  589:          size        => '5'
  590:          },
  591:      pointtype => {
  592:          default     => 1,
  593:          test        => $int_test,
  594:          description => 'Point type (may not apply to all plot styles)',
  595:          edit_type   => 'choice',
  596:          choices     => [0,1,2,3,4,5,6]
  597:          },
  598:      limit     => {
  599:          default     => 'closed',
  600: 	 test        => sub {$_[0]=~/^(above|below|closed|x1|x2|y1|y2)$/},
  601:          description => 'Point to fill -- for filledcurves',
  602:          edit_type   => 'choice',
  603:          choices     => ['above', 'below', 'closed','x1','x2','y1','y2']
  604:          },
  605:      arrowhead => {
  606:          default     => 'head',
  607: 	 test        => $arrowhead_test,
  608: 	 description => 'Vector arrow head type',
  609: 	 edit_type   => 'choice',
  610: 	 choices     => ['nohead', 'head', 'heads']
  611:      },
  612:      arrowstyle => {
  613: 	 default     => 'filled',
  614: 	 test        => $arrowstyle_test,
  615: 	 description => 'Vector arrow head style',
  616: 	 edit_type   => 'choice',
  617: 	 choices     => ['filled', 'empty', 'nofilled']
  618:      },
  619:      arrowlength => {
  620: 	 default     => 0.02,
  621: 	 test        => $pos_real_test,
  622: 	 description => "Length of vector arrow (only applies to vector plots)",
  623: 	 edit_type   => 'entry',
  624: 	 size        => '5'
  625:      },
  626:      arrowangle  => {
  627: 	default      => 10.0,
  628: 	test         => $degree_test,
  629: 	description  => 'Angle of arrow branches to arrow body (only applies to vector plots)',
  630: 	edit_type    => 'entry',
  631: 	size         => '5'
  632:      },
  633: 
  634:      arrowbackangle => {
  635: 	 default    => 90.0,
  636: 	 test       => $degree_test,
  637: 	 descripton => 'Angle of arrow back lines to branches.',
  638: 	 edit_type  => 'entry',
  639: 	 size       => '5'
  640:      }
  641: 
  642:      );
  643: 
  644: ###################################################################
  645: ##                                                               ##
  646: ##                    parsing and edit rendering                 ##
  647: ##                                                               ##
  648: ###################################################################
  649: 
  650: undef %Apache::lonplot::plot;
  651: my (%key,%axis,$title,$xlabel,$ylabel,@labels,@curves,%xtics,%ytics);
  652: 
  653: my $current_tics;		# Reference to the current tick hash
  654: 
  655: sub start_gnuplot {
  656:     undef(%Apache::lonplot::plot);   undef(%key);    undef(%axis);
  657:     undef($title);  undef($xlabel); undef($ylabel);
  658:     undef(@labels); undef(@curves);
  659:     undef(%xtics);  undef(%ytics);
  660:     #
  661:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  662:     my $result='';
  663:     &Apache::lonxml::register('Apache::lonplot',
  664: 	     ('title','xlabel','ylabel','key','axis','label','curve',
  665: 	      'xtics','ytics'));
  666:     push (@Apache::lonxml::namespace,'lonplot');
  667:     if ($target eq 'web' || $target eq 'tex') {
  668: 	&get_attributes(\%Apache::lonplot::plot,\%gnuplot_defaults,$parstack,$safeeval,
  669: 			$tagstack->[-1]);
  670:     } elsif ($target eq 'edit') {
  671: 	$result .= &Apache::edit::tag_start($target,$token,'GnuPlot');
  672: 	$result .= &edit_attributes($target,$token,\%gnuplot_defaults,
  673: 				    \@gnuplot_edit_order)
  674: 	    .&Apache::edit::end_row()
  675: 	    .&Apache::edit::start_spanning_row();
  676:     } elsif ($target eq 'modified') {
  677: 	my $constructtag=&Apache::edit::get_new_args
  678: 	    ($token,$parstack,$safeeval,keys(%gnuplot_defaults));
  679: 
  680: 	if ($constructtag) {
  681: 	    #
  682: 	    # The color chooser does not prepent x to the color values
  683: 	    # Do that here:
  684: 	    #
  685: 	    foreach my $attribute ('bgcolor', 'fgcolor') {
  686: 		my $value = $token->[2]{$attribute};
  687: 		if (defined $value && !($value =~ /^x/)) {
  688: 		    $token->[2]{$attribute} = 'x' . $value;
  689: 		}
  690: 	    }
  691: 	    $result = &Apache::edit::rebuild_tag($token);
  692: 	}
  693:     }
  694:     return $result;
  695: }
  696: 
  697: sub end_gnuplot {
  698:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  699:     pop @Apache::lonxml::namespace;
  700:     &Apache::lonxml::deregister('Apache::lonplot',
  701: 	('title','xlabel','ylabel','key','axis','label','curve'));
  702:     my $result = '';
  703:     my $randnumber;
  704:     my $tmpdir =LONCAPA::tempdir(); # Where temporary files live:
  705: 
  706:     # need to call rand everytime start_script would evaluate, as the
  707:     # safe space rand number generator and the global rand generator 
  708:     # are not separate
  709:     if ($target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
  710: 	$target eq 'answer') {
  711:       $randnumber=int(rand(1000));
  712:     }
  713:     if ($target eq 'web' || $target eq 'tex') {
  714: 	&check_inputs(); # Make sure we have all the data we need
  715: 	##
  716: 	## Determine filename
  717: 	my $filename = $env{'user.name'}.'_'.$env{'user.domain'}.
  718: 	    '_'.time.'_'.$$.$randnumber.'_plot';
  719: 	## Write the plot description to the file
  720: 	&write_gnuplot_file($tmpdir,$filename,$target);
  721: 	$filename = &escape($filename);
  722: 	## return image tag for the plot
  723: 	if ($target eq 'web') {
  724: 	    $result .= <<"ENDIMAGE";
  725: <img src    = "/cgi-bin/plot.$weboutputformat?file=$filename.data" 
  726:      width  = "$Apache::lonplot::plot{'width'}"
  727:      height = "$Apache::lonplot::plot{'height'}"
  728:      align  = "$Apache::lonplot::plot{'align'}"
  729:      alt    = "$Apache::lonplot::plot{'alttag'}" />
  730: ENDIMAGE
  731:         } elsif ($target eq 'tex') {
  732: 	    &Apache::lonxml::debug(" gnuplot wid = $Apache::lonplot::plot{'width'}");
  733: 	    &Apache::lonxml::debug(" gnuplot ht  = $Apache::lonplot::plot{'height'}");
  734: 	    #might be inside the safe space, register the URL for later
  735: 	    &Apache::lonxml::register_ssi("/cgi-bin/plot.gif?file=$filename.data&output=eps");
  736: 	    $result  = "%DYNAMICIMAGE:$Apache::lonplot::plot{'width'}:$Apache::lonplot::plot{'height'}:$Apache::lonplot::plot{'texwidth'}\n";
  737: 	    $result .= '\graphicspath{{'.$tmpdir.'}}'."\n";
  738: 	    $result .= '\includegraphics[width='.$Apache::lonplot::plot{'texwidth'}.' mm]{'.&unescape($filename).'.eps}';
  739: 	}
  740:     } elsif ($target eq 'edit') {
  741: 	$result.=&Apache::edit::tag_end($target,$token);
  742:     }
  743:     return $result;
  744: }
  745: 
  746: 
  747: ##--------------------------------------------------------------- xtics
  748: sub start_xtics {
  749:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  750:     my $result='';
  751:     if ($target eq 'web' || $target eq 'tex') {
  752: 	&get_attributes(\%xtics,\%tic_defaults,$parstack,$safeeval,
  753: 		    $tagstack->[-1]);
  754: 	$current_tics = \%xtics;
  755: 	&Apache::lonxml::register('Apache::lonplot', 'tic');
  756:     } elsif ($target eq 'edit') {
  757: 	$result .= &Apache::edit::tag_start($target,$token,'xtics');
  758: 	$result .= &edit_attributes($target,$token,\%tic_defaults,
  759: 				    \@tic_edit_order);
  760:     } elsif ($target eq 'modified') {
  761: 	my $constructtag=&Apache::edit::get_new_args
  762: 	    ($token,$parstack,$safeeval,keys(%tic_defaults));
  763: 	if ($constructtag) {
  764: 	    $result = &Apache::edit::rebuild_tag($token);
  765: 	}
  766:     }
  767:     return $result;
  768: }
  769: 
  770: sub end_xtics {
  771:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  772:     my $result = '';
  773:     if ($target eq 'web' || $target eq 'tex') {
  774: 	&Apache::lonxml::deregister('Apache::lonplot', 'tic');
  775:     } elsif ($target eq 'edit') {
  776: 	$result.=&Apache::edit::tag_end($target,$token);
  777:     }
  778:     return $result;
  779: }
  780: 
  781: ##--------------------------------------------------------------- ytics
  782: sub start_ytics {
  783:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  784:     my $result='';
  785:     if ($target eq 'web' || $target eq 'tex') {
  786: 	&get_attributes(\%ytics,\%tic_defaults,$parstack,$safeeval,
  787: 		    $tagstack->[-1]);
  788: 	$current_tics = \%ytics;
  789: 	&Apache::lonxml::register('Apache::lonplot', 'tic');
  790:     } elsif ($target eq 'edit') {
  791: 	$result .= &Apache::edit::tag_start($target,$token,'ytics');
  792: 	$result .= &edit_attributes($target,$token,\%tic_defaults,
  793: 				    \@tic_edit_order);
  794:     } elsif ($target eq 'modified') {
  795: 	my $constructtag=&Apache::edit::get_new_args
  796: 	    ($token,$parstack,$safeeval,keys(%tic_defaults));
  797: 	if ($constructtag) {
  798: 	    $result = &Apache::edit::rebuild_tag($token);
  799: 	}
  800:     }
  801:     return $result;
  802: }
  803: 
  804: sub end_ytics {
  805:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  806:     my $result = '';
  807:     if ($target eq 'web' || $target eq 'tex') {
  808: 	&Apache::lonxml::deregister('Apache::lonplot', 'tic');
  809:     } elsif ($target eq 'edit') {
  810: 	$result.=&Apache::edit::tag_end($target,$token);
  811:     }
  812:     return $result;
  813: }
  814: 
  815: 
  816: ##----------------------------------------------------------------
  817: #
  818: #  Tic handling:
  819: #   The <tic> tag allows users to specify exact Tic positions and labels
  820: #   for each axis.  In this version we only support level 0 tics (major tic).
  821: #   Each tic has associated with it a position and a label
  822: #   $current_tics is a reference to the current tick description hash.
  823: #   We add elements to an array  in that has: ticspecs whose elements
  824: #   are 'pos' - the tick position and 'label' - the tic label.
  825: #
  826: 
  827: 
  828: sub start_tic {
  829:     my ($target, $token, $tagstack, $parstack, $parser, $safeeval, $style)  = @_;
  830: 
  831:     my $result = '';
  832:     if ($target eq 'web' || $target eq 'tex') {
  833: 	my $tic_location = &Apache::lonxml::get_param('location', $parstack, $safeeval);
  834: 	my $tic_label    = &Apache::lonxml::get_all_text('/tic', $parser);
  835: 
  836: 	# Tic location must e a real:
  837: 
  838: 	if (!&$real_test($tic_location)) {
  839: 	    &Apache::lonxml::warning("Tic location: $tic_location must be a real number");
  840: 	} else {
  841: 
  842: 	    if (!defined  $current_tics->{'ticspecs'}) {
  843: 		$current_tics->{'ticspecs'} = [];
  844: 	    }
  845: 	    my $ticspecs = $current_tics->{'ticspecs'};
  846: 	    push (@$ticspecs, {'pos' => $tic_location, 'label' => $tic_label});
  847: 	}
  848:     }
  849: 
  850:     return $result;
  851: }
  852: 
  853: sub end_tic {
  854:     return '';
  855: }
  856: 
  857: ##-----------------------------------------------------------------font
  858: my %font_properties =
  859:     (
  860:      'classic'    => {
  861: 	 face       => 'classic',
  862: 	 file       => 'DejaVuSansMono-Bold',
  863: 	 printname  => 'Helvetica',
  864: 	 tex_no_file => 1,
  865:      },
  866:      'sans-serif' => {
  867: 	 face       => 'sans-serif',
  868: 	 file       => 'DejaVuSans',
  869: 	 printname  => 'DejaVuSans',
  870:      },
  871:      'serif'      => {
  872: 	 face       => 'serif',
  873: 	 file       => 'DejaVuSerif',
  874: 	 printname  => 'DejaVuSerif',
  875:      },
  876:      );
  877: 
  878: sub get_font {
  879:     my ($target) = @_;
  880:     my ($size, $selected_font);
  881: 
  882:     if ( $Apache::lonplot::plot{'font'} =~ /^(small|medium|large)/) {
  883: 	$selected_font = $font_properties{'classic'};
  884: 	if ( $Apache::lonplot::plot{'font'} eq 'small') {
  885: 	    $size = '5';
  886: 	} elsif ( $Apache::lonplot::plot{'font'} eq 'medium') {
  887: 	    $size = '9';
  888: 	} elsif ( $Apache::lonplot::plot{'font'} eq 'large') {
  889: 	    $size = '11';
  890: 	} else {
  891: 	    $size = '9';
  892: 	}
  893:     } else {
  894: 	$size = $Apache::lonplot::plot{'font'};
  895: 	$selected_font = $font_properties{$Apache::lonplot::plot{'fontface'}};
  896:     }
  897:     if ($target eq 'tex' && defined($Apache::lonplot::plot{'texfont'})) {
  898: #	$selected_font = $font_properties{'classic'};
  899: 	$size = $Apache::lonplot::plot{'texfont'};
  900:     }
  901:     return ($size, $selected_font);
  902: }
  903: 
  904: ##----------------------------------------------------------------- key
  905: sub start_key {
  906:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  907:     my $result='';
  908:     if ($target eq 'web' || $target eq 'tex') {
  909: 	&get_attributes(\%key,\%key_defaults,$parstack,$safeeval,
  910: 		    $tagstack->[-1]);
  911:     } elsif ($target eq 'edit') {
  912: 	$result .= &Apache::edit::tag_start($target,$token,'Plot Key');
  913: 	$result .= &edit_attributes($target,$token,\%key_defaults);
  914:     } elsif ($target eq 'modified') {
  915: 	my $constructtag=&Apache::edit::get_new_args
  916: 	    ($token,$parstack,$safeeval,keys(%key_defaults));
  917: 	if ($constructtag) {
  918: 	    $result = &Apache::edit::rebuild_tag($token);
  919: 	}
  920:     }
  921:     return $result;
  922: }
  923: 
  924: sub end_key {
  925:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  926:     my $result = '';
  927:     if ($target eq 'web' || $target eq 'tex') {
  928:     } elsif ($target eq 'edit') {
  929: 	$result.=&Apache::edit::tag_end($target,$token);
  930:     }
  931:     return $result;
  932: }
  933: 
  934: sub parse_label {
  935:     my ($target,$text) = @_;
  936:     my $parser=HTML::LCParser->new(\$text);
  937:     my $result;
  938:     while (my $token=$parser->get_token) {
  939: 	if ($token->[0] eq 'S') {
  940: 	    if ($token->[1] eq 'sub') {
  941: 		$result .= '_{';
  942: 	    } elsif ($token->[1] eq 'sup') {
  943: 		$result .= '^{';
  944: 	    } else {
  945: 		$result .= $token->[4];
  946: 	    }
  947: 	} elsif ($token->[0] eq 'E') {
  948: 	    if ($token->[1] eq 'sub'
  949: 		|| $token->[1] eq 'sup') {
  950: 		$result .= '}';
  951: 	    } else {
  952: 		$result .= $token->[2];
  953: 	    }
  954: 	} elsif ($token->[0] eq 'T') {
  955: 	    $result .= &replace_entities($target,$token->[1]);
  956: 	}
  957:     }
  958:     return $result;
  959: }
  960: 
  961: #
  962: #  Note that there are severe restrictions on font selection in the
  963: # ps driver now.  later in life Gnuplot is supposed to support
  964: # utf-8 fonts in the posts script driver.  When this happens,
  965: # the tex entries with comments that include the word <FIX>
  966: # should be changed to print the correct glyphs rather than some
  967: # approximation or fallback of what is intended.
  968: 
  969: my %lookup = 
  970:    (  # Greek alphabet:
  971:       
  972:       '(Alpha|#913)'    => {'tex' => '{/Symbol A}', 'web' => "\x{391}"},
  973:       '(Beta|#914)'    => {'tex' => '{/Symbol B}', 'web' => "\x{392}"},
  974:       '(Chi|#935)'     => {'tex' => '{/Symbol C}', 'web' => "\x{3A7}"},
  975:       '(Delta|#916)'   => {'tex' => '{/Symbol D}', 'web' => "\x{394}"},
  976:       '(Epsilon|#917)' => {'tex' => '{/Symbol E}', 'web' => "\x{395}"},
  977:       '(Phi|#934)'     => {'tex' => '{/Symbol F}', 'web' => "\x{3A6}"},
  978:       '(Gamma|#915)'   => {'tex' => '{/Symbol G}', 'web' => "\x{393}"},
  979:       '(Eta|#919)'     => {'tex' => '{/Symbol H}', 'web' => "\x{397}"},
  980:       '(Iota|#921)'    => {'tex' => '{/Symbol I}', 'web' => "\x{399}"},
  981:       '(Kappa|#922)'   => {'tex' => '{/Symbol K}', 'web' => "\x{39A}"},
  982:       '(Lambda|#923)'  => {'tex' => '{/Symbol L}', 'web' => "\x{39B}"},
  983:       '(Mu|#924)'      => {'tex' => '{/Symbol M}', 'web' => "\x{39C}"},
  984:       '(Nu|#925)'      => {'tex' => '{/Symbol N}', 'web' => "\x{39D}"},
  985:       '(Omicron|#927)' => {'tex' => '{/Symbol O}', 'web' => "\x{39F}"},
  986:       '(Pi|#928)'      => {'tex' => '{/Symbol P}', 'web' => "\x{3A0}"},
  987:       '(Theta|#920)'   => {'tex' => '{/Symbol Q}', 'web' => "\x{398}"},
  988:       '(Rho|#929)'     => {'tex' => '{/Symbol R}', 'web' => "\x{3A1}"},
  989:       '(Sigma|#931)'   => {'tex' => '{/Symbol S}', 'web' => "\x{3A3}"},
  990:       '(Tau|#932)'     => {'tex' => '{/Symbol T}', 'web' => "\x{3A4}"},
  991:       '(Upsilon|#933)' => {'tex' => '{/Symbol U}', 'web' => "\x{3A5}"},
  992:       '(Omega|#937)'   => {'tex' => '{/Symbol W}', 'web' => "\x{3A9}"},
  993:       '(Xi|#926)'      => {'tex' => '{/Symbol X}', 'web' => "\x{39E}"},
  994:       '(Psi|#936)'     => {'tex' => '{/Symbol Y}', 'web' => "\x{3A8}"},
  995:       '(Zeta|#918)'    => {'tex' => '{/Symbol Z}', 'web' => "\x{396}"},
  996:       '(alpha|#945)'   => {'tex' => '{/Symbol a}', 'web' => "\x{3B1}"},
  997:       '(beta|#946)'    => {'tex' => '{/Symbol b}', 'web' => "\x{3B2}"},
  998:       '(chi|#967)'     => {'tex' => '{/Symbol c}', 'web' => "\x{3C7}"},
  999:       '(delta|#948)'   => {'tex' => '{/Symbol d}', 'web' => "\x{3B4}"},
 1000:       '(epsilon|#949)' => {'tex' => '{/Symbol e}', 'web' => "\x{3B5}"},
 1001:       '(phi|#966)'     => {'tex' => '{/Symbol f}', 'web' => "\x{3C6}"},
 1002:       '(gamma|#947)'   => {'tex' => '{/Symbol g}', 'web' => "\x{3B3}"},
 1003:       '(eta|#951)'     => {'tex' => '{/Symbol h}', 'web' => "\x{3B7}"},
 1004:       '(iota|#953)'    => {'tex' => '{/Symbol i}', 'web' => "\x{3B9}"},
 1005:       '(kappa|#954)'   => {'tex' => '{/Symbol k}', 'web' => "\x{3BA}"},
 1006:       '(lambda|#955)'  => {'tex' => '{/Symbol k}', 'web' => "\x{3BB}"},
 1007:       '(mu|#956)'      => {'tex' => '{/Symbol m}', 'web' => "\x{3BC}"},
 1008:       '(nu|#957)'      => {'tex' => '{/Symbol n}', 'web' => "\x{3BD}"},
 1009:       '(omicron|#959)' => {'tex' => '{/Symbol o}', 'web' => "\x{3BF}"},
 1010:       '(pi|#960)'      => {'tex' => '{/Symbol p}', 'web' => "\x{3C0}"},
 1011:       '(theta|#952)'   => {'tex' => '{/Symbol q}', 'web' => "\x{3B8}"},
 1012:       '(rho|#961)'     => {'tex' => '{/Symbol r}', 'web' => "\x{3C1}"},
 1013:       '(sigma|#963)'   => {'tex' => '{/Symbol s}', 'web' => "\x{3C3}"},
 1014:       '(tau|#964)'     => {'tex' => '{/Symbol t}', 'web' => "\x{3C4}"},
 1015:       '(upsilon|#965)' => {'tex' => '{/Symbol u}', 'web' => "\x{3C5}"},
 1016:       '(omega|#969)'   => {'tex' => '{/Symbol w}', 'web' => "\x{3C9}"},
 1017:       '(xi|#958)'      => {'tex' => '{/Symbol x}', 'web' => "\x{3BE}"},
 1018:       '(psi|#968)'     => {'tex' => '{/Symbol y}', 'web' => "\x{3C8}"},
 1019:       '(zeta|#950)'    => {'tex' => '{/Symbol z}', 'web' => "\x{3B6}"},
 1020:       '(thetasym|#977)' => {'tex' => '{/Symbol \165}', 'web' => "\x{3d1}"},
 1021:       '(upsih|#978)'   => {'tex' => '{/Symbol \241}', 'web' => "\x{3d2}"},
 1022:       '(piv|#982)'     => {'tex' => '{/Symbol \166}', 'web' => "\x{3d6}"},
 1023: 
 1024: 
 1025:       # Punctuation:
 1026:       
 1027:       '(quot|#034)'   => {'tex' =>  '\42',            'web' => '\42'},
 1028:       '(amp|#038)'    => {'tex' =>  '\46',            'web' => '\46'},
 1029:       '(lt|#060)'     => {'tex' =>  '\74',            'web' => '\74'},
 1030:       '(gt|#062)'     => {'tex' =>  '\76',            'web' => '\76'},
 1031:       '#131'          => {'tex' =>  '{/Symbol \246}', 'web' => "\x{192}"},
 1032:       '#132'          => {'tex' => '{/Text \271}',    'web' => "\x{201e}"},
 1033:       '#133'          => {'tex' => '{/Symbol \274}',  'web'=> "\x{2026}"},
 1034:       '#134'          => {'tex' => '{/Text \262}',    'web' => "\x{2020}"},
 1035:       '#135'          => {'tex' => '{/Text \263}',    'web' => "\x{2021}"},
 1036:       '#136'          => {'tex' => '\\\\^',           'web' => '\\\\^'},
 1037:       '#137'          => {'tex' => '%o',              'web' => "\x{2030}"}, # Per Mille <FIX>
 1038:       '#138'          => {'tex' => 'S',               'web' => "\x{160}"}, # S-Caron <FIX>
 1039:       '#139'          => {'tex' => '<',               'web' => '<'},
 1040:       '#140'          => {'tex' => 'AE',              'web' => "\x{152}"}, # AE ligature <FIX>
 1041:       '#145'          => {'tex' => '\140',            'web' => "\x{2018}"},
 1042:       '#146'          => {'tex' => '\47',             'web' => "\x{2019}"},
 1043:       '#147'          => {'tex' => '\140\140',        'web' => "\x{201c}"}, # Left " <FIX>
 1044:       '#148'          => {'tex' => '\47\47',          'web' => '\\"'},      # Right " <FIX>
 1045:       '#149'          => {'tex' => '{/Symbol \267}',  'web' => "\x{2022}"},
 1046:       '#150'          => {'tex' => '{/Text \55}',     'web' => "\x{2013}"},  # en dash
 1047:       '#151'          => {'tex' => '{/Symbol \55}',   'web' => "\x{2014}"},  # em dash
 1048:       '#152'          => {'tex' => '\\\\~',           'web' => '\\\\~'},
 1049:       '#153'          => {'tex' => '{/Symbol \324}',  'web' => "\x{2122}"}, # trademark
 1050: 
 1051:       # Accented letters, and other furreign language glyphs.
 1052: 
 1053:       '#154'          => {'tex' => 's',               'web' => "\x{161}"}, # small s-caron no ps.
 1054:       '#155'          => {'tex' => '>',               'web' => '\76'},     # >
 1055:       '#156'          => {'tex' => '{/Text \366}',    'web' => "\x{153}"}, # oe ligature.<FIX>
 1056:       '#159',         => {'tex' => 'Y',               'web' => "\x{178}"}, # Y-umlaut - can't print <FIX>
 1057:       '(nbsp|#160)'   => {'tex' => ' ',               'web' => ' '},       # non breaking space.
 1058:       '(iexcl|#161)'  => {'tex' => '{/Text \241}',    'web' => "\x{a1}"},  # inverted !
 1059:       '(cent|#162)'   => {'tex' => '{/Text \242}',    'web' => "\x{a2}"},  # Cent currency.
 1060:       '(pound|#163)'  => {'tex' => '{/Text \243}',    'web' => "\x{a3}"},  # GB Pound currency.
 1061:       '(curren|#164)' => {'tex' => '{/ZapfDingbats \161}','web' => "\x{a4}"},  # Generic currency symb. <FIX>
 1062:       '(yen|#165)'    => {'tex' => '{/Text \245}',    'web' => "\x{a5}"},  # Yen currency.
 1063:       '(brvbar|#166)' => {'tex' => '{/Symbol \174}',  'web' => "\x{a6}"},  # Broken vert bar no print.
 1064:       '(sect|#167)'   => {'tex' => '{\247}',          'web' => "\x{a7}"},  # Section symbol.
 1065:       '(uml|#168)'    => {'tex' => '{\250}',          'web' => "\x{a8}"},  # 'naked' umlaut.
 1066:       '(copy|#169)'   => {'tex' => '{/Symbol \343}',  'web' => "\x{a9}"},  # Copyright symbol.
 1067:       '(ordf|#170)'   => {'tex' => '{/Text \343}',    'web' => "\x{aa}"},  # Feminine ordinal.
 1068:       '(laquo|#171)'  => {'tex' => '{/Text \253}',    'web' => "\x{ab}"},  # << quotes.
 1069:       '(not|#172)'    => {'tex' => '\254',            'web' => "\x{ac}"},  # Logical not.
 1070:       '(shy|#173)'    => {'tex' => '\255',               'web' => "\x{ad}"},  # soft hyphen.
 1071:       '(reg|#174)'    => {'tex' => '{/Symbol \342}',  'web' => "\x{ae}"},  # Registered tm.
 1072:       '(macr|#175)'   => {'tex' => '^{\255}',            'web' => "\x{af}"},  # 'naked' macron (overbar).
 1073:       '(deg|#176)'    => {'tex' => '{/Text \260}',    'web' => "\x{b0}"},  # Degree symbo..`
 1074:       '(plusmn|#177)' => {'tex' => '{/Symbol \261}',  'web' => "\x{b1}"},  # +/- symbol.
 1075:       '(sup2|#178)'   => {'tex' => '^2',              'web' => "\x{b2}"},  # Superscript 2.
 1076:       '(sup3|#179)'   => {'tex' => '^3',              'web' => "\x{b3}"},  # Superscript 3.
 1077:       '(acute|#180)'  => {'tex' => '{/Text \222}',    'web' => "\x{b4}"},  # 'naked' acute accent.
 1078:       '(micro|#181)'  => {'tex' => '{/Symbol \155}',  'web' => "\x{b5}"},  # Micro (small mu).
 1079:       '(para|#182)'   => {'tex' => '{/Text \266}',    'web' => "\x{b6}"},  # Paragraph symbol.
 1080:       '(middot|#183)' => {'tex' => '\267',            'web' => "\x{b7}"},  # middle dot
 1081:       '(cedil|#184)'  => {'tex' => '\233',            'web' => "\x{b8}"},  # 'naked' cedilla.
 1082:       '(sup1|#185)'   => {'tex' => '^1',              'web' => "\x{b9}"},  # superscript 1.
 1083:       '(ordm|#186)'   => {'tex' => '{\260}',          'web' => "\x{ba}"},  # masculine ordinal.
 1084:       '(raquo|#187)', => {'tex' => '\273',            'web' => "\x{bb}"},  # Right angle quotes.
 1085:       '(frac14|#188)' => {'tex' => '\274',            'web' => "\x{bc}"},  # 1/4.
 1086:       '(frac12|#189)' => {'tex' => '\275',            'web' => "\x{bd}"},  # 1/2.
 1087:       '(frac34|#190)' => {'tex' => '\276',            'web' => "\x{be}"},  # 3/4
 1088:       '(iquest|#191)' => {'tex' => '{/Text \277}',    'web' => "\x{bf}"},  # Inverted ?
 1089:       '(Agrave|#192)' => {'tex' => '\300',            'web' => "\x{c0}"},  # A Grave.
 1090:       '(Aacute|#193)' => {'tex' => '\301',            'web' => "\x{c1}"},  # A Acute.
 1091:       '(Acirc|#194)'  => {'tex' => '\302',            'web' => "\x{c2}"},  # A Circumflex.
 1092:       '(Atilde|#195)' => {'tex' => '\303',            'web' => "\x{c3}"},  # A tilde.
 1093:       '(Auml|#196)'   => {'tex' => '\304',            'web' => "\x{c4}"},  # A umlaut.
 1094:       '(Aring|#197)'  => {'tex' => '\305',            'web' => "\x{c5}"},  # A ring.
 1095:       '(AElig|#198)'  => {'tex' => '\306',            'web' => "\x{c6}"},  # AE ligature.
 1096:       '(Ccedil|#199)' => {'tex' => '\307',            'web' => "\x{c7}"},  # C cedilla
 1097:       '(Egrave|#200)' => {'tex' => '\310',            'web' => "\x{c8}"},  # E Accent grave.
 1098:       '(Eacute|#201)' => {'tex' => '\311',            'web' => "\x{c9}"},  # E acute accent.
 1099:       '(Ecirc|#202)'  => {'tex' => '\312',            'web' => "\x{ca}"},  # E Circumflex.
 1100:       '(Euml|#203)'   => {'tex' => '\313',            'web' => "\x{cb}"},  # E umlaut.
 1101:       '(Igrave|#204)' => {'tex' => '\314',            'web' => "\x{cc}"},  # I grave accent.
 1102:       '(Iacute|#205)' => {'tex' => '\315',            'web' => "\x{cd}"},  # I acute accent.
 1103:       '(Icirc|#206)'  => {'tex' => '\316',            'web' => "\x{ce}"},  # I circumflex.
 1104:       '(Iuml|#207)'   => {'tex' => '\317',            'web' => "\x{cf}"},  # I umlaut.
 1105:       '(ETH|#208)'    => {'tex' => '\320',            'web' => "\x{d0}"},  # Icelandic Cap eth.
 1106:       '(Ntilde|#209)' => {'tex' => '\321',            'web' => "\x{d1}"},  # Ntilde (enyan).
 1107:       '(Ograve|#210)' => {'tex' => '\322',            'web' => "\x{d2}"},  # O accent grave.
 1108:       '(Oacute|#211)' => {'tex' => '\323',            'web' => "\x{d3}"},  # O accent acute.
 1109:       '(Ocirc|#212)'  => {'tex' => '\324',            'web' => "\x{d4}"},  # O circumflex.
 1110:       '(Otilde|#213)' => {'tex' => '\325',            'web' => "\x{d5}"},  # O tilde.
 1111:       '(Ouml|#214)'   => {'tex' => '\326',            'web' => "\x{d6}"},  # O umlaut.
 1112:       '(times|#215)'  => {'tex' => '\327',            'web' => "\x{d7}"},  # Times symbol.
 1113:       '(Oslash|#216)' => {'tex' => '\330',            'web' => "\x{d8}"},  # O slash.
 1114:       '(Ugrave|#217)' => {'tex' => '\331',            'web' => "\x{d9}"},  # U accent grave.
 1115:       '(Uacute|#218)' => {'tex' => '\332',            'web' => "\x{da}"},  # U accent acute.
 1116:       '(Ucirc|#219)'  => {'tex' => '\333',            'web' => "\x{db}"},  # U circumflex.
 1117:       '(Uuml|#220)'   => {'tex' => '\334',            'web' => "\x{dc}"},  # U umlaut.
 1118:       '(Yacute|#221)' => {'tex' => '\335',            'web' => "\x{dd}"},  # Y accent acute.
 1119:       '(THORN|#222)'  => {'tex' => '\336',            'web' => "\x{de}"},  # Icelandic thorn.
 1120:       '(szlig|#223)'  => {'tex' => '\337',            'web' => "\x{df}"},  # German sharfes s.
 1121:       '(agrave|#224)' => {'tex' => '\340',            'web' => "\x{e0}"},  # a accent grave.
 1122:       '(aacute|#225)' => {'tex' => '\341',            'web' => "\x{e1}"},  # a grave.
 1123:       '(acirc|#226)'  => {'tex' => '\342',            'web' => "\x{e2}"},  # a circumflex.
 1124:       '(atilde|#227)' => {'tex' => '\343',            'web' => "\x{e3}"},  # a tilde.
 1125:       '(auml|#228)'   => {'tex' => '\344',            'web' => "\x{e4}"},  # a umlaut
 1126:       '(aring|#229)'  => {'tex' => '\345',            'web' => "\x{e5}"},  # a ring on top.
 1127:       '(aelig|#230)'  => {'tex' => '\346',            'web' => "\x{e6}"},  # ae ligature.
 1128:       '(ccedil|#231)' => {'tex' => '\347',            'web' => "\x{e7}"},  # C cedilla
 1129:       '(egrave|#232)' => {'tex' => '\350',            'web' => "\x{e8}"},  # e accent grave.
 1130:       '(eacute|#233)' => {'tex' => '\351',            'web' => "\x{e9}"},  # e accent acute.
 1131:       '(ecirc|#234)'  => {'tex' => '\352',            'web' => "\x{ea}" }, # e circumflex.
 1132:       '(euml|#235)'   => {'tex' => '\353',            'web' => "\x{eb}"},  # e umlaut.
 1133:       '(igrave|#236)' => {'tex' => '\354',            'web' => "\x{ec}"},  # i grave.
 1134:       '(iacute|#237)' => {'tex' => '\355',            'web' => "\x{ed}"},  # i acute.
 1135:       '(icirc|#238)'  => {'tex' => '\356',            'web' => "\x{ee}"},  # i circumflex.
 1136:       '(iuml|#239)'   => {'tex' => '\357',            'web' => "\x{ef}"},  # i umlaut.
 1137:       '(eth|#240)'    => {'tex' => '\360',            'web' => "\x{f0}"},  # Icelandic eth.
 1138:       '(ntilde|#241)' => {'tex' => '\361',            'web' => "\x{f1}"},  # n tilde.
 1139:       '(ograve|#242)' => {'tex' => '\362',            'web' => "\x{f2}"},  # o grave.
 1140:       '(oacute|#243)' => {'tex' => '\363',            'web' => "\x{f3}"},  # o acute.
 1141:       '(ocirc|#244)'  => {'tex' => '\364',            'web' => "\x{f4}"},  # o circumflex.
 1142:       '(otilde|#245)' => {'tex' => '\365',            'web' => "\x{f5}"},  # o tilde.
 1143:       '(ouml|#246)'   => {'tex' => '\366',            'web' => "\x{f6}"},  # o umlaut.
 1144:       '(divide|#247)' => {'tex' => '\367',            'web' => "\x{f7}"},  # division symbol
 1145:       '(oslash|#248)' => {'tex' => '\370',            'web' => "\x{f8}"},  # o slashed.
 1146:       '(ugrave|#249)' => {'tex' => '\371',            'web' => "\x{f9}"},  # u accent grave.
 1147:       '(uacute|#250)' => {'tex' => '\372',            'web' => "\x{fa}"},  # u acute.
 1148:       '(ucirc|#251)'  => {'tex' => '\373',            'web' => "\x{fb}"},  # u circumflex.
 1149:       '(uuml|#252)'   => {'tex' => '\374',            'web' => "\x{fc}"},  # u umlaut.
 1150:       '(yacute|#253)' => {'tex' => '\375',            'web' => "\x{fd}"},  # y acute accent.
 1151:       '(thorn|#254)'  => {'tex' => '\376',            'web' => "\x{fe}"},  # small thorn (icelandic).
 1152:       '(yuml|#255)'   => {'tex' => '\377',            'web' => "\x{ff}"},  # y umlaut.
 1153:       
 1154:       # Latin extended A entities:
 1155: 
 1156:       '(OElig|#338)'  => {'tex' => '{/Text \326}',   'web' => "\x{152}"},  # OE ligature.
 1157:       '(oelig|#339)'  => {'tex' => '{/Text \366}',   'web' => "\x{153}"},  # oe ligature.
 1158:       '(Scaron|#352)' => {'tex' => 'S',              'web' => "\x{160}"},  # S caron no printable.
 1159:       '(scaron|#353)' => {'tex' => 's',              'web' => "\x{161}"},  # s caron no printable.
 1160:       '(Yuml|#376)'   => {'tex' => 'Y',              'web' => "\x{178}"},  # Y umlaut - no printable.
 1161: 
 1162:       # Latin extended B.
 1163: 
 1164:       '(fnof|#402)'  => {'tex' =>'{/Symbol \246}',    'web' => "\x{192}"},  # f with little hook.
 1165: 
 1166:       # Standalone accents:
 1167: 
 1168:       '(circ|#710)'  => {'tex' => '^',               'web' => '^'},        # circumflex.
 1169:       '(tilde|#732)' => {'tex' => '~',               'web' => '~'},        # tilde.
 1170: 
 1171:       # General punctuation.  We're not able to make a distinction between
 1172:       # the various length spacings in the print version. (e.g. en/em/thin).
 1173:       # the various joiners will be empty strings in the print version too.
 1174: 
 1175: 
 1176:       '(ensp|#8194)'   => {'tex' => ' ',              'web' => "\x{2002}"}, # en space.
 1177:       '(emsp|#8195)'   => {'tex' => ' ',              'web' => "\x{2003}"}, # em space.
 1178:       '(thinsp|#8201)' => {'tex' => ' ',              'web' => "\x{2009}"}, # thin space.
 1179:       '(zwnj|#8204)'   => {'tex' => ' ',               'web' => "\x{200c}"}, # Zero width non joiner.
 1180:       '(zwj|#8205)'    => {'tex' => ' ',               'web' => "\x{200d}"}, # Zero width joiner.
 1181:       '(lrm|#8206)'    => {'tex' => ' ',               'web' => "\x{200e}"}, # Left to right mark
 1182:       '(rlm|#8207)'    => {'tex' => ' ',               'web' => "\x{200f}"}, # right to left mark.
 1183:       '(ndash|#8211)'  => {'tex' => '{/Text \55}',    'web' => "\x{2013}"}, # en dash.
 1184:       '(mdash|#8212)'  => {'tex' => '{/Symbol \55}',  'web' => "\x{2014}"}, # em dash.
 1185:       '(lsquo|#8216)'  => {'tex' => '{/Text \140}',   'web' => "\x{2018}"}, # Left single quote.
 1186:       '(rsquo|#8217)'  => {'tex' => '\47',            'web' => "\x{2019}"}, # Right single quote.
 1187:       '(sbquo|#8218)'  => {'tex' => '\54',             'web' => "\x{201a}"}, # Single low-9 quote.
 1188:       '(ldquo|#8220)'  => {'tex' => '\42',   'web' => "\x{201c}"}, # Left double quote.
 1189:       '(rdquo|#8221)'  => {'tex' => '\42',   'web' => "\x{201d}"}, # Right double quote.
 1190:       '(bdquo|#8222)'  => {'tex' => ',',              'web' => "\x{201e}"}, # Double low-9 quote.
 1191:       '(dagger|#8224)' => {'tex' => '+',   'web' => "\x{2020}"}, # Is this a dagger I see before me now?
 1192:       '(Dagger|#8225)' => {'tex' => '\261',   'web' => "\x{2021}"}, # it's handle pointing towards my heart?
 1193:       '(bull|#8226)'   => {'tex' => '\267',           'web' => "\x{2022}"}, # Bullet.
 1194:       '(hellep|#8230)' => {'tex' => '{/Symbol \274}',   'web' => "\x{2026}"}, # Ellipses.
 1195:       '(permil|#8240)' => {'tex' => '%_o',            'web' => "\x{2031}"}, # Per mille.
 1196:       '(prime|#8242)'  => {'tex' => '\264',           'web' => "\x{2032}"}, # Prime.
 1197:       '(Prime|#8243)'  => {'tex' => '{/Symbol \262}', 'web' => "\x{2033}"}, # double prime.
 1198:       '(lsaquo|#8249)' => {'tex' => '<',              'web' => "\x{2039}"}, # < quote.
 1199:       '(rsaquo|#8250)' => {'tex' => '\74',              'web' => "\x{203a}"}, # > quote.
 1200:       '(oline|#8254)'  => {'tex' => '{/Symbol \140}', 'web' => "\x{203e}"}, # Overline.
 1201:       '(frasl|#8260)'  => {'tex' => '/',              'web' => "\x{2044}"}, # Fraction slash.
 1202:       '(euro|#8364)'   => {'tex' => '{/Symbol \240}', 'web' => "\x{20ac}"}, # Euro currency.
 1203:       
 1204:       # Letter like symbols.
 1205: 
 1206:       '(weierp|#8472)'  => {'tex' => '{/Symbol \303}', 'web' => "\x{2118}"}, # Power set symbol
 1207:       '(image|#8465)'   => {'tex' => '{/Symbol \301}', 'web' => "\x{2111}"}, # Imaginary part
 1208:       '(real|#8476)'    => {'tex' => '{/Symbol \302}', 'web' => "\x{211c}"}, # Real part.
 1209:       '(trade|#8482)'   => {'tex' => '{/Symbol \344}', 'web' => "\x{2122}"}, # trademark symbol.
 1210:       '(alefsym|#8501)' => {'tex' => '{/Symbol \300}', 'web' => "\x{2135}"}, # Hebrew alef.
 1211: 
 1212:       # Arrows  of various types and directions.
 1213:       '(larr|#8592)'    => {'tex' => '{/Symbol \254}', 'web' => "\x{2190}"}, # <--
 1214:       '(uarr|#8593)'    => {'tex' => '{/Symbol \255}', 'web' => "\x{2191}"}, # up arrow.
 1215:       '(rarr|#8594)'    => {'tex' => '{/Symbol \256}', 'web' => "\x{2192}"}, # -->
 1216:       '(darr|#8595)'    => {'tex' => '{/Symbol \257}', 'web' => "\x{2193}"}, # down arrow.
 1217:       '(harr|#8596)'    => {'tex' => '{/Symbol \253}', 'web' => "\x{2194}"}, # <-->
 1218:       '(crarr|#8629)'   => {'tex' => '{/Symbol \277}', 'web' => "\x{21b5}"}, # corner arrow down and right.
 1219:       '(lArr|#8656)'    => {'tex' => '{/Symbol \334}', 'web' => "\x{21d0}"}, # <==
 1220:       '(uArr|#8657)'    => {'tex' => '{/Symbol \335}', 'web' => "\x{21d1}"}, # Up double arrow.
 1221:       '(rArr|#8658)'    => {'tex' => '{/Symbol \336}', 'web' => "\x{21d2}"}, # ==>
 1222:       '(dArr|#8659)'    => {'tex' => '{/Symbol \337}', 'web' => "\x{21d3}"}, # Down double arrow.
 1223:       '(hArr|#8660)'    => {'tex' => '{/Symbol \333}', 'web' => "\x{21d4}"}, # <==>
 1224: 
 1225:       # Mathematical operators. For some of these we do the best we can in printing.
 1226: 
 1227:       '(forall|#8704)'  => {'tex' => '{/Symbol \42}',   'web' => "\x{2200}"}, # For all.
 1228:       '(part|#8706)'    => {'tex' => '{/Symbol d}',     'web' => "\x{2202}"}, # partial derivative
 1229:       '(exist|#8707)'   => {'tex' => '{/Symbol \44}',   'web' => "\x{2203}"}, # There exists.
 1230:       '(empty|#8709)'   => {'tex' => '{/Symbol \306}',  'web' => "\x{2205}"}, # Null set.
 1231:       '(nabla|#8711)'   => {'tex' => '{/Symbol \321}',  'web' => "\x{2207}"}, # Gradient e.g.
 1232:       '(isin|#8712)'    => {'tex' => '{/Symbol \316}',  'web' => "\x{2208}"}, # Element of the set.
 1233:       '(notin|#8713)'   => {'tex' => '{/Symbol \317}',  'web' => "\x{2209}"}, # Not an element of
 1234:       '(ni|#8715)'      => {'tex' => '{/Symbol \47}',   'web' => "\x{220b}"}, # Contains as a member
 1235:       '(prod|#8719)'    => {'tex' => '{/Symbol \325}',  'web' => "\x{220f}"}, # Product 
 1236:       '(sum|#8721)'     => {'tex' => '{/Symbol \345}',  'web' => "\x{2211}"}, # Sum of.
 1237:       '(minus|#8722)'   => {'tex' => '{/Symbol \55}',   'web' => "\x{2212}"}, # - sign.
 1238:       '(lowast|#8727)'  => {'tex' => '*',               'web' => "\x{2217}"}, # * 
 1239:       '(radic|#8730)'   => {'tex' => '{/Symbol \326}',  'web' => "\x{221a}"}, # Square root. 
 1240:       '(prop|#8733)'    => {'tex' => '{/Symbol \265}',  'web' => "\x{221d}"}, # Proportional to.
 1241:       '(infin|#8734)'   => {'tex' => '{/Symbol \245}',  'web' => "\x{221e}"}, # Infinity.
 1242:       '(ang|#8736)'     => {'tex' => '{/Symbol \320}',  'web' => "\x{2220}"}, # Angle .
 1243:       '(and|#8743)'     => {'tex' => '{/Symbol \331}',  'web' => "\x{2227}"}, # Logical and.
 1244:       '(or|#8744)'      => {'tex' => '{/Symbol \332}',  'web' => "\x{2228}"}, # Logical or.
 1245:       '(cap|#8745)'     => {'tex' => '{/Symbol \307}',  'web' => "\x{2229}"}, # Set intersection.
 1246:       '(cup|#8746)'     => {'tex' => '{/Symbol \310}',  'web' => "\x{222a}"}, # Set union.
 1247:       '(int|8747)'      => {'tex' => '{/Symbol \362}',  'web' => "\x{222b}"}, # Integral.
 1248: 
 1249:       # Some gnuplot guru will have to explain to me why the next three
 1250:       # require the extra slashes... else they print very funkily.
 1251: 
 1252:       '(there4|#8756)'  => {'tex' => '{/Symbol \\\134}',  'web' => "\x{2234}"}, # Therefore triple dots.
 1253:       '(sim|#8764)'     => {'tex' => '\\\176',               'web' => "\x{223c}"}, # Simlar to.
 1254:       '(cong|#8773)'    => {'tex' => '{/Symbol \\\100}','web' => "\x{2245}"}, # Congruent to/with.
 1255: 
 1256:       '(asymp|#8776)'   => {'tex' => '{/Symbol \273}',  'web' => "\x{2248}"}, # Asymptotic to.
 1257:       '(ne|#8800)'      => {'tex' => '{/Symbol \271}',  'web' => "\x{2260}"}, # not equal to.
 1258:       '(equiv|#8801)'   => {'tex' => '{/Symbol \272}',  'web' => "\x{2261}"}, # Equivalent to.
 1259:       '(le|8804)'       => {'tex' => '{/Symbol \243}',  'web' => "\x{2264}"}, # Less than or equal to.
 1260:       '(ge|8805)'       => {'tex' => '{/Symbol \263}',  'web' => "\x{2265}"}, # Greater than or equal to
 1261:       '(sub|8834)'      => {'tex' => '{/Symbol \314}',  'web' => "\x{2282}"}, # Subset of.
 1262:       '(sup|8835)'      => {'tex' => '{/Symbol \311}',  'web' => "\x{2283}"}, # Super set of.
 1263:       '(nsub|8836)'     => {'tex' => '{/Symbol \313}',  'web' => "\x{2284}"}, # not subset of.
 1264:       '(sube|8838)'     => {'tex' => '{/Symbol \315}',  'web' => "\x{2286}"}, # Subset or equal.
 1265:       '(supe|8839)'     => {'tex' => '{/Symbol \312}',  'web' => "\x{2287}"}, # Superset or equal
 1266:       '(oplus|8853)'    => {'tex' => '{/Symbol \305}',  'web' => "\x{2295}"}, # O with plus inside
 1267:       '(otimes|8855)'   => {'tex' => '{/Symbol \304}',  'web' => "\x{2297}"}, # O with times.
 1268:       '(perp|8869)'     => {'tex' => '{/Symbol \136}',  'web' => "\x{22a5}"}, # Perpendicular.
 1269:       '(sdot|8901)'     => {'tex' => '{/Symbol \227}',  'web' => "\x{22c5}"}, # Dot operator.
 1270: 
 1271:       # Misc. technical symbols:
 1272: 
 1273:       '(lceil|8698)'    => {'tex' => '{/Symbol \351}',  'web' => "\x{2308}"}, # Left ceiling.
 1274:       '(rceil|8969)'    => {'tex' => '{/Symbol \371}',  'web' => "\x{2309}"}, # Right ceiling.
 1275:       '(lfloor|8970)'   => {'tex' => '{/Symbol \353}',  'web' => "\x{230a}"}, # Left floor.
 1276:       '(rfloor|8971)'   => {'tex' => '{/Symbol \373}',  'web' => "\x{230b}"}, # Right floor.
 1277: 
 1278:       # The gnuplot png font evidently does not have the big angle brackets at
 1279:       # positions 0x2329, 0x232a so use ordinary brackets.
 1280: 
 1281:       '(lang|9001)'     => {'tex' => '{/Symbol \341}',  'web' => '<'}, # Left angle bracket.
 1282:       '(rang|9002)'     => {'tex' => '{/Symbol \361}',  'web' => '>'}, # Right angle bracket.
 1283: 
 1284:       # Gemoetric shapes.
 1285: 
 1286:       '(loz|9674)'      => {'tex' => '{/Symbol \340}',  'web' => "\x{25ca}"}, # Lozenge.
 1287: 
 1288:       # Misc. symbols
 1289: 
 1290:       '(spades|9824)'   => {'tex' => '{/Symbol \252}', 'web' => "\x{2660}"}, 
 1291:       '(clubs|9827)'    => {'tex' => '{/Symbol \247}', 'web' => "\x{2663}"}, 
 1292:       '(hearts|9829)'   => {'tex' => '{/Symbol \251}', 'web' => "\x{2665}"}, 
 1293:       '(diams|9830)'    => {'tex' => '{/Symbol \250}', 'web' => "\x{2666}"}
 1294: 
 1295:     );
 1296: 
 1297: 
 1298: sub replace_entities {
 1299:     my ($target,$text) = @_;
 1300:     $text =~ s{([_^~\{\}]|\\\\)}{\\\\$1}g;
 1301:     while (my ($re, $replace) = each(%lookup)) {
 1302: 	my $repl = $replace->{$target};
 1303: 	$text =~ s/&$re;/$replace->{$target}/g;
 1304:     }
 1305:     $text =~ s{(&)}{\\\\$1}g;
 1306:     return $text;
 1307: }
 1308: 
 1309: ##------------------------------------------------------------------- title
 1310: sub start_title {
 1311:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
 1312:     my $result='';
 1313:     if ($target eq 'web' || $target eq 'tex') {
 1314: 	$title = &Apache::lonxml::get_all_text("/title",$parser,$style);
 1315: 	$title=&Apache::run::evaluate($title,$safeeval,$$parstack[-1]);
 1316: 	$title =~ s/\n/ /g;
 1317: 	if (length($title) > $max_str_len) {
 1318: 	    $title = substr($title,0,$max_str_len);
 1319: 	}
 1320: 	$title = &parse_label($target,$title);
 1321:     } elsif ($target eq 'edit') {
 1322: 	$result.=&Apache::edit::tag_start($target,$token,'Plot Title');
 1323: 	my $text=&Apache::lonxml::get_all_text("/title",$parser,$style);
 1324: 	$result.=&Apache::edit::editline('',$text,'',60);
 1325:     } elsif ($target eq 'modified') {
 1326: 	$result.=&Apache::edit::rebuild_tag($token);
 1327: 	$result.=&Apache::edit::modifiedfield("/title",$parser);
 1328:     }
 1329:     return $result;
 1330: }
 1331: 
 1332: sub end_title {
 1333:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
 1334:     my $result = '';
 1335:     if ($target eq 'web' || $target eq 'tex') {
 1336:     } elsif ($target eq 'edit') {
 1337: 	$result.=&Apache::edit::tag_end($target,$token);
 1338:     }
 1339:     return $result;
 1340: }
 1341: ##------------------------------------------------------------------- xlabel
 1342: sub start_xlabel {
 1343:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
 1344:     my $result='';
 1345:     if ($target eq 'web' || $target eq 'tex') {
 1346: 	$xlabel = &Apache::lonxml::get_all_text("/xlabel",$parser,$style);
 1347: 	$xlabel=&Apache::run::evaluate($xlabel,$safeeval,$$parstack[-1]);
 1348: 	$xlabel =~ s/\n/ /g;
 1349: 	if (length($xlabel) > $max_str_len) {
 1350: 	    $xlabel = substr($xlabel,0,$max_str_len);
 1351: 	}
 1352: 	$xlabel = &parse_label($target,$xlabel);
 1353:     } elsif ($target eq 'edit') {
 1354: 	$result.=&Apache::edit::tag_start($target,$token,'Plot Xlabel');
 1355: 	my $text=&Apache::lonxml::get_all_text("/xlabel",$parser,$style);
 1356: 	$result.=&Apache::edit::editline('',$text,'',60);
 1357:     } elsif ($target eq 'modified') {
 1358: 	$result.=&Apache::edit::rebuild_tag($token);	
 1359: 	$result.=&Apache::edit::modifiedfield("/xlabel",$parser);
 1360:     }
 1361:     return $result;
 1362: }
 1363: 
 1364: sub end_xlabel {
 1365:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
 1366:     my $result = '';
 1367:     if ($target eq 'web' || $target eq 'tex') {
 1368:     } elsif ($target eq 'edit') {
 1369: 	$result.=&Apache::edit::tag_end($target,$token);
 1370:     }
 1371:     return $result;
 1372: }
 1373: 
 1374: ##------------------------------------------------------------------- ylabel
 1375: sub start_ylabel {
 1376:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
 1377:     my $result='';
 1378:     if ($target eq 'web' || $target eq 'tex') {
 1379: 	$ylabel = &Apache::lonxml::get_all_text("/ylabel",$parser,$style);
 1380: 	$ylabel = &Apache::run::evaluate($ylabel,$safeeval,$$parstack[-1]);
 1381: 	$ylabel =~ s/\n/ /g;
 1382: 	if (length($ylabel) > $max_str_len) {
 1383: 	    $ylabel = substr($ylabel,0,$max_str_len);
 1384: 	}
 1385: 	$ylabel = &parse_label($target,$ylabel);
 1386:     } elsif ($target eq 'edit') {
 1387: 	$result .= &Apache::edit::tag_start($target,$token,'Plot Ylabel');
 1388: 	my $text = &Apache::lonxml::get_all_text("/ylabel",$parser,$style);
 1389: 	$result .= &Apache::edit::editline('',$text,'',60);
 1390:     } elsif ($target eq 'modified') {
 1391: 	$result.=&Apache::edit::rebuild_tag($token);
 1392: 	$result.=&Apache::edit::modifiedfield("/ylabel",$parser);
 1393:     }
 1394:     return $result;
 1395: }
 1396: 
 1397: sub end_ylabel {
 1398:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
 1399:     my $result = '';
 1400:     if ($target eq 'web' || $target eq 'tex') {
 1401:     } elsif ($target eq 'edit') {
 1402: 	$result.=&Apache::edit::tag_end($target,$token);
 1403:     }
 1404:     return $result;
 1405: }
 1406: 
 1407: ##------------------------------------------------------------------- label
 1408: sub start_label {
 1409:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
 1410:     my $result='';
 1411:     if ($target eq 'web' || $target eq 'tex') {
 1412: 	my %label;
 1413: 	&get_attributes(\%label,\%label_defaults,$parstack,$safeeval,
 1414: 		    $tagstack->[-1]);
 1415: 	my $text = &Apache::lonxml::get_all_text("/label",$parser,$style);
 1416: 	$text = &Apache::run::evaluate($text,$safeeval,$$parstack[-1]);
 1417: 	$text =~ s/\n/ /g;
 1418: 	$text = substr($text,0,$max_str_len) if (length($text) > $max_str_len);
 1419: 	$label{'text'} = &parse_label($target,$text);
 1420: 	push(@labels,\%label);
 1421:     } elsif ($target eq 'edit') {
 1422: 	$result .= &Apache::edit::tag_start($target,$token,'Plot Label');
 1423: 	$result .= &edit_attributes($target,$token,\%label_defaults);
 1424: 	my $text = &Apache::lonxml::get_all_text("/label",$parser,$style);
 1425: 	$result .= &Apache::edit::end_row().
 1426: 	    &Apache::edit::start_spanning_row().
 1427: 	    &Apache::edit::editline('',$text,'',60);
 1428:     } elsif ($target eq 'modified') {
 1429: 	&Apache::edit::get_new_args
 1430: 	    ($token,$parstack,$safeeval,keys(%label_defaults));
 1431: 	$result.=&Apache::edit::rebuild_tag($token);
 1432: 	$result.=&Apache::edit::modifiedfield("/label",$parser);
 1433:     }
 1434:     return $result;
 1435: }
 1436: 
 1437: sub end_label {
 1438:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
 1439:     my $result = '';
 1440:     if ($target eq 'web' || $target eq 'tex') {
 1441:     } elsif ($target eq 'edit') {
 1442: 	$result.=&Apache::edit::tag_end($target,$token);
 1443:     }
 1444:     return $result;
 1445: }
 1446: 
 1447: ##------------------------------------------------------------------- curve
 1448: sub start_curve {
 1449:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
 1450:     my $result='';
 1451:     &Apache::lonxml::register('Apache::lonplot',('function','data'));
 1452:     push (@Apache::lonxml::namespace,'curve');
 1453:     if ($target eq 'web' || $target eq 'tex') {
 1454: 	my %curve;
 1455: 	&get_attributes(\%curve,\%curve_defaults,$parstack,$safeeval,
 1456: 		    $tagstack->[-1]);
 1457: 	push (@curves,\%curve);
 1458:     } elsif ($target eq 'edit') {
 1459: 	$result .= &Apache::edit::tag_start($target,$token,'Curve');
 1460: 	$result .= &edit_attributes($target,$token,\%curve_defaults,
 1461:                                     \@curve_edit_order)
 1462: 	    .&Apache::edit::end_row()
 1463: 	    .&Apache::edit::start_spanning_row();
 1464: 
 1465:     } elsif ($target eq 'modified') {
 1466: 	my $constructtag=&Apache::edit::get_new_args
 1467: 	    ($token,$parstack,$safeeval,keys(%curve_defaults));
 1468: 	if ($constructtag) {
 1469: 	    #
 1470: 	    # Fix up the color attribute as jcolor does not prepend an x
 1471: 	    #
 1472: 	    my $value = $token->[2]{'color'};
 1473: 	    if (defined $value && !($value =~ /^x/)) {
 1474: 		$token->[2]{'color'} = 'x' . $value;
 1475: 	    }
 1476: 	    $result = &Apache::edit::rebuild_tag($token);
 1477: 	}
 1478:     }
 1479:     return $result;
 1480: }
 1481: 
 1482: sub end_curve {
 1483:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
 1484:     my $result = '';
 1485:     pop @Apache::lonxml::namespace;
 1486:     &Apache::lonxml::deregister('Apache::lonplot',('function','data'));
 1487:     if ($target eq 'web' || $target eq 'tex') {
 1488:     } elsif ($target eq 'edit') {
 1489: 	$result.=&Apache::edit::tag_end($target,$token);
 1490:     }
 1491:     return $result;
 1492: }
 1493: 
 1494: ##------------------------------------------------------------ curve function
 1495: sub start_function {
 1496:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
 1497:     my $result='';
 1498:     if ($target eq 'web' || $target eq 'tex') {
 1499: 	if (exists($curves[-1]->{'data'})) {
 1500: 	    &Apache::lonxml::warning
 1501:                 ('Use of the <b>curve function</b> tag precludes use of '.
 1502:                  ' the <b>curve data</b> tag.  '.
 1503:                  'The curve data tag will be omitted in favor of the '.
 1504:                  'curve function declaration.');
 1505: 	    delete $curves[-1]->{'data'} ;
 1506: 	}
 1507:         my $function = &Apache::lonxml::get_all_text("/function",$parser,
 1508: 						     $style);
 1509: 	$function = &Apache::run::evaluate($function,$safeeval,$$parstack[-1]);
 1510:         $function=~s/\^/\*\*/gs;
 1511: 	$function=~ s/^\s+//;	# Trim leading
 1512: 	$function=~ s/\s+$//;   # And trailing whitespace.
 1513: 	$curves[-1]->{'function'} = $function; 
 1514:     } elsif ($target eq 'edit') {
 1515: 	$result .= &Apache::edit::tag_start($target,$token,'Gnuplot compatible curve function');
 1516: 	my $text = &Apache::lonxml::get_all_text("/function",$parser,$style);
 1517: 	$result .= &Apache::edit::editline('',$text,'',60);
 1518:     } elsif ($target eq 'modified') {
 1519: 	$result.=&Apache::edit::rebuild_tag($token);
 1520: 	$result.=&Apache::edit::modifiedfield("/function",$parser);
 1521:     }
 1522:     return $result;
 1523: }
 1524: 
 1525: sub end_function {
 1526:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
 1527:     my $result = '';
 1528:     if ($target eq 'web' || $target eq 'tex') {
 1529:     } elsif ($target eq 'edit') {
 1530: 	$result .= &Apache::edit::end_table();
 1531:     }
 1532:     return $result;
 1533: }
 1534: 
 1535: ##------------------------------------------------------------ curve  data
 1536: sub start_data {
 1537:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
 1538:     my $result='';
 1539:     if ($target eq 'web' || $target eq 'tex') {
 1540: 	if (exists($curves[-1]->{'function'})) {
 1541: 	    &Apache::lonxml::warning
 1542:                 ('Use of the <b>curve function</b> tag precludes use of '.
 1543:                  ' the <b>curve data</b> tag.  '.
 1544:                  'The curve function tag will be omitted in favor of the '.
 1545:                  'curve data declaration.');
 1546: 	    delete($curves[-1]->{'function'});
 1547: 	}
 1548: 	my $datatext = &Apache::lonxml::get_all_text("/data",$parser,$style);
 1549: 	$datatext=&Apache::run::evaluate($datatext,$safeeval,$$parstack[-1]);
 1550: 	# Deal with cases where we're given an array...
 1551: 	if ($datatext =~ /^\@/) {
 1552: 	    $datatext = &Apache::run::run('return "'.$datatext.'"',
 1553: 					  $safeeval,1);
 1554: 	}
 1555: 	$datatext =~ s/\s+/ /g;
 1556: 	# Need to do some error checking on the @data array - 
 1557: 	# make sure it's all numbers and make sure each array 
 1558: 	# is of the same length.
 1559: 	my @data;
 1560: 	if ($datatext =~ /,/) { # comma deliminated
 1561: 	    @data = split /,/,$datatext;
 1562: 	} else { # Assume it's space separated.
 1563: 	    @data = split / /,$datatext;
 1564: 	}
 1565: 	for (my $i=0;$i<=$#data;$i++) {
 1566: 	    # Check that it's non-empty
 1567: 	    if (! defined($data[$i])) {
 1568: 		&Apache::lonxml::warning(
 1569: 		    'undefined curve data value.  Replacing with '.
 1570: 		    ' pi/e = 1.15572734979092');
 1571: 		$data[$i] = 1.15572734979092;
 1572: 	    }
 1573: 	    # Check that it's a number
 1574: 	    if (! &$real_test($data[$i]) & ! &$int_test($data[$i])) {
 1575: 		&Apache::lonxml::warning(
 1576: 		    'Bad curve data value of '.$data[$i].'  Replacing with '.
 1577: 		    ' pi/e = 1.15572734979092');
 1578: 		$data[$i] = 1.15572734979092;
 1579: 	    }
 1580: 	}
 1581: 	# complain if the number of data points is not the same as
 1582: 	# in previous sets of data.
 1583: 	if (($curves[-1]->{'data'}) && ($#data != $#{$curves[-1]->{'data'}->[0]})){
 1584: 	    &Apache::lonxml::warning
 1585: 		('Number of data points is not consistent with previous '.
 1586: 		 'number of data points');
 1587: 	}
 1588: 	push  @{$curves[-1]->{'data'}},\@data;
 1589:     } elsif ($target eq 'edit') {
 1590: 	$result .= &Apache::edit::tag_start($target,$token,'Comma or space deliminated curve data');
 1591: 	my $text = &Apache::lonxml::get_all_text("/data",$parser,$style);
 1592: 	$result .= &Apache::edit::editline('',$text,'',60);
 1593:     } elsif ($target eq 'modified') {
 1594: 	$result.=&Apache::edit::rebuild_tag($token);
 1595: 	$result.=&Apache::edit::modifiedfield("/data",$parser);
 1596:     }
 1597:     return $result;
 1598: }
 1599: 
 1600: sub end_data {
 1601:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
 1602:     my $result = '';
 1603:     if ($target eq 'web' || $target eq 'tex') {
 1604:     } elsif ($target eq 'edit') {
 1605: 	$result .= &Apache::edit::end_table();
 1606:     }
 1607:     return $result;
 1608: }
 1609: 
 1610: ##------------------------------------------------------------------- axis
 1611: sub start_axis {
 1612:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
 1613:     my $result='';
 1614:     if ($target eq 'web' || $target eq 'tex') {
 1615: 	&get_attributes(\%axis,\%axis_defaults,$parstack,$safeeval,
 1616: 			$tagstack->[-1]);
 1617:     } elsif ($target eq 'edit') {
 1618: 	$result .= &Apache::edit::tag_start($target,$token,'Plot Axes');
 1619: 	$result .= &edit_attributes($target,$token,\%axis_defaults,
 1620: 				    \@axis_edit_order);
 1621:     } elsif ($target eq 'modified') {
 1622: 	my $constructtag=&Apache::edit::get_new_args
 1623: 	    ($token,$parstack,$safeeval,keys(%axis_defaults));
 1624: 
 1625: 	if ($constructtag) {
 1626: 	    #
 1627: 	    #  Fix up the color attribute since jchooser does not
 1628: 	    #  prepend an x to the color:
 1629: 	    #
 1630: 	    my $value = $token->[2]{'color'};
 1631: 	    if (defined $value && !($value =~ /^x/)) {
 1632: 		$token->[2]{'color'} = 'x' . $value;
 1633: 	    }
 1634: 
 1635: 	    $result = &Apache::edit::rebuild_tag($token);
 1636: 	}
 1637:     }
 1638:     return $result;
 1639: }
 1640: 
 1641: sub end_axis {
 1642:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
 1643:     my $result = '';
 1644:     if ($target eq 'web' || $target eq 'tex') {
 1645:     } elsif ($target eq 'edit') {
 1646: 	$result.=&Apache::edit::tag_end($target,$token);
 1647:     } elsif ($target eq 'modified') {
 1648:     }
 1649:     return $result;
 1650: }
 1651: 
 1652: ###################################################################
 1653: ##                                                               ##
 1654: ##        Utility Functions                                      ##
 1655: ##                                                               ##
 1656: ###################################################################
 1657: 
 1658: ##----------------------------------------------------------- set_defaults
 1659: sub set_defaults {
 1660:     my ($var,$defaults) = @_;
 1661:     my $key;
 1662:     foreach $key (keys(%$defaults)) {
 1663: 	$var->{$key} = $defaults->{$key}->{'default'};
 1664:     }
 1665: }
 1666: 
 1667: ##------------------------------------------------------------------- misc
 1668: sub get_attributes{
 1669:     my ($values,$defaults,$parstack,$safeeval,$tag) = @_;
 1670:     foreach my $attr (keys(%{$defaults})) {
 1671: 	if ($attr eq 'texwidth' || $attr eq 'texfont') {
 1672: 	    $values->{$attr} = 
 1673: 		&Apache::lonxml::get_param($attr,$parstack,$safeeval,undef,1);
 1674: 	} else {
 1675: 	    $values->{$attr} = 
 1676: 		&Apache::lonxml::get_param($attr,$parstack,$safeeval);
 1677: 	}
 1678: 	if ($values->{$attr} eq '' | !defined($values->{$attr})) {
 1679: 	    $values->{$attr} = $defaults->{$attr}->{'default'};
 1680: 	    next;
 1681: 	}
 1682: 	my $test = $defaults->{$attr}->{'test'};
 1683: 	if (! &$test($values->{$attr})) {
 1684: 	    &Apache::lonxml::warning
 1685: 		($tag.':'.$attr.': Bad value.'.'Replacing your value with : '
 1686: 		 .$defaults->{$attr}->{'default'} );
 1687: 	    $values->{$attr} = $defaults->{$attr}->{'default'};
 1688: 	}
 1689:     }
 1690:     return ;
 1691: }
 1692: ##
 1693: # Generate tic mark specifications.
 1694: # 
 1695: # @param type - type of tics (xtics or ytics).
 1696: # @param spec - Reference to a hash that contains the tic specification.
 1697: # @param target - 'tex' if hard copy target.
 1698: #
 1699: # @return string - the tic specification command.
 1700: #
 1701: sub generate_tics {
 1702:     my ($type, $spec, $target) = @_;
 1703:     my $result   = '';
 1704: 
 1705: 
 1706:     if (defined %$spec) {
 1707: 
 1708: 	
 1709: 
 1710: 	# Major tics: - If there are 'ticspecs' these override any other
 1711: 	#               specifications:
 1712: 
 1713: 	
 1714: 	
 1715: 	$result .= "set $type $spec->{'location'}  ";
 1716: 	$result .= ($spec->{'mirror'} eq 'on') ? 'mirror ' : 'nomirror ';
 1717: 	if (defined $spec->{'ticspecs'}) {
 1718: 	    $result .= '( ';
 1719: 	    my @ticspecs;
 1720: 	    my $ticinfo = $spec->{'ticspecs'};
 1721: 	    foreach my $tic (@$ticinfo) {
 1722: 		push(@ticspecs,  '"' . $tic->{'label'} . '" ' . $tic->{'pos'} );
 1723: 	    }
 1724: 	    $result .= join(', ', (@ticspecs));
 1725: 	    $result .= ' )';
 1726: 	} else {
 1727: 	    $result .= "$spec->{'start'}, ";
 1728: 	    $result .= "$spec->{'increment'}, ";
 1729: 	    $result .= "$spec->{'end'} ";
 1730: 	}
 1731: 	if ($target eq 'tex' ) {
 1732: 	    $result .= 'font "Helvetica,22"';
 1733: 	}
 1734: 	$result .= "\n";
 1735: 	
 1736: 	# minor frequency:
 1737: 	
 1738: 	if ($spec->{'minorfreq'} != 0) {
 1739: 	    $result .= "set m$type $spec->{'minorfreq'}\n";
 1740: 	}
 1741:     } else {
 1742: 	$result .= "set $type font " . '"Helvetica,22"' ."\n";
 1743:     }
 1744:     
 1745:     
 1746:     return $result;
 1747: }
 1748: 
 1749: ##------------------------------------------------------- write_gnuplot_file
 1750: sub write_gnuplot_file {
 1751:     my ($tmpdir,$filename,$target)= @_;
 1752:     my ($fontsize, $font_properties) =  &get_font($target);
 1753:     my $gnuplot_input = '';
 1754:     my $curve;
 1755:     #
 1756:     # Check to be sure we do not have any empty curves
 1757:     my @curvescopy;
 1758:     foreach my $curve (@curves) {
 1759:         if (exists($curve->{'function'})) {
 1760:             if ($curve->{'function'} !~ /^\s*$/) {
 1761:                 push(@curvescopy,$curve);
 1762:             }
 1763:         } elsif (exists($curve->{'data'})) {
 1764:             foreach my $data (@{$curve->{'data'}}) {
 1765:                 if (scalar(@$data) > 0) {
 1766:                     push(@curvescopy,$curve);
 1767:                     last;
 1768:                 }
 1769:             }
 1770:         }
 1771:     }
 1772:     @curves = @curvescopy;
 1773:     # Collect all the colors
 1774:     my @Colors;
 1775:     push @Colors, $Apache::lonplot::plot{'bgcolor'};
 1776:     push @Colors, $Apache::lonplot::plot{'fgcolor'}; 
 1777:     push @Colors, (defined($axis{'color'})?$axis{'color'}:$Apache::lonplot::plot{'fgcolor'});
 1778:     foreach $curve (@curves) {
 1779: 	push @Colors, ($curve->{'color'} ne '' ? 
 1780: 		       $curve->{'color'}       : 
 1781: 		       $Apache::lonplot::plot{'fgcolor'}        );
 1782:     }
 1783:     
 1784:     # set term
 1785:     if ($target eq 'web') {
 1786: 	$gnuplot_input .= 'set terminal png enhanced nocrop ';
 1787: 	$gnuplot_input .= 'transparent ' if ($Apache::lonplot::plot{'transparent'} eq 'on');
 1788: 	$gnuplot_input .= 'font "'.$Apache::lonnet::perlvar{'lonFontsDir'}.
 1789: 	    '/'.$font_properties->{'file'}.'.ttf" ';
 1790: 	$gnuplot_input .= $fontsize;
 1791: 	$gnuplot_input .= ' size '.$Apache::lonplot::plot{'width'}.','.$Apache::lonplot::plot{'height'}.' ';
 1792: 	$gnuplot_input .= "@Colors\n";
 1793: 	# set output
 1794: 	$gnuplot_input .= "set output\n";
 1795:     } elsif ($target eq 'tex') {
 1796: 	$gnuplot_input .= "set term postscript eps enhanced $Apache::lonplot::plot{'plotcolor'} dash ";
 1797: 	if (!$font_properties->{'tex_no_file'}) {
 1798: 	    $gnuplot_input .=
 1799: 		'fontfile "'.$Apache::lonnet::perlvar{'lonFontsDir'}.
 1800: 		'/'.$font_properties->{'file'}.'.pfb" ';
 1801: 	}
 1802: 	$gnuplot_input .= ' "'.$font_properties->{'printname'}.'" ';
 1803: 	$gnuplot_input .= $fontsize;
 1804: 	$gnuplot_input .= "\nset output \"".$tmpdir.
 1805: 	    &unescape($filename).".eps\"\n";
 1806: 	$gnuplot_input .= "set encoding iso_8859_1\n"; # Get access to extended font.
 1807: 
 1808:     }
 1809:     $gnuplot_input .= "set encoding utf8\n";
 1810:     # cartesian or polar plot?
 1811:     if (lc($Apache::lonplot::plot{'plottype'}) eq 'polar') {
 1812:         $gnuplot_input .= 'set polar'.$/;
 1813:     } else {
 1814:         # Assume Cartesian
 1815:     }
 1816:     # cartesian or polar grid?
 1817:     if (lc($Apache::lonplot::plot{'gridtype'}) eq 'polar') {
 1818:         $gnuplot_input .= 'set grid polar'.$/;
 1819:     } elsif (lc($Apache::lonplot::plot{'gridtype'}) eq 'linear-log') {
 1820:         $gnuplot_input .= 'set logscale x'.$/;
 1821:     } elsif (lc($Apache::lonplot::plot{'gridtype'}) eq 'log-linear') {
 1822:         $gnuplot_input .= 'set logscale y'.$/;
 1823:     } elsif (lc($Apache::lonplot::plot{'gridtype'}) eq 'log-log') {
 1824:         $gnuplot_input .= 'set logscale x'.$/;
 1825:         $gnuplot_input .= 'set logscale y'.$/;
 1826:     } else {
 1827:         # Assume Cartesian
 1828:     }
 1829:     # solid or pattern for boxes?
 1830:     if (lc($Apache::lonplot::plot{'fillstyle'}) eq 'solid') {
 1831:         $gnuplot_input .= 'set style fill solid '.
 1832: 	    $Apache::lonplot::plot{'solid'}.$Apache::lonplot::plot{'box_border'}.$/;
 1833:     } elsif (lc($Apache::lonplot::plot{'fillstyle'}) eq 'pattern') {
 1834:         $gnuplot_input .= 'set style fill pattern '.$Apache::lonplot::plot{'pattern'}.$Apache::lonplot::plot{'box_border'}.$/;
 1835:     } elsif (lc($Apache::lonplot::plot{'fillstyle'}) eq 'empty') {
 1836:     }
 1837:     # margin
 1838:     if (lc($Apache::lonplot::plot{'lmargin'}) ne 'default') {
 1839:         $gnuplot_input .= 'set lmargin '.$Apache::lonplot::plot{'lmargin'}.$/;
 1840:     }
 1841:     if (lc($Apache::lonplot::plot{'rmargin'}) ne 'default') {
 1842:         $gnuplot_input .= 'set rmargin '.$Apache::lonplot::plot{'rmargin'}.$/;
 1843:     }
 1844:     if (lc($Apache::lonplot::plot{'tmargin'}) ne 'default') {
 1845:         $gnuplot_input .= 'set tmargin '.$Apache::lonplot::plot{'tmargin'}.$/;
 1846:     }
 1847:     if (lc($Apache::lonplot::plot{'bmargin'}) ne 'default') {
 1848:         $gnuplot_input .= 'set bmargin '.$Apache::lonplot::plot{'bmargin'}.$/;
 1849:     }
 1850: 
 1851:     # tic scales
 1852:     if ($version > 4) {
 1853: 	$gnuplot_input .= 'set tics scale '.
 1854: 	    $Apache::lonplot::plot{'major_ticscale'}.', '.$Apache::lonplot::plot{'minor_ticscale'}.$/;
 1855:     } else {
 1856:     	$gnuplot_input .= 'set ticscale '.
 1857: 	    $Apache::lonplot::plot{'major_ticscale'}.' '.$Apache::lonplot::plot{'minor_ticscale'}.$/;
 1858:     }
 1859:     #boxwidth
 1860:     if (lc($Apache::lonplot::plot{'boxwidth'}) ne '') {
 1861: 	$gnuplot_input .= 'set boxwidth '.$Apache::lonplot::plot{'boxwidth'}.$/;
 1862:     }
 1863:     # gridlayer
 1864:     $gnuplot_input .= 'set grid noxtics noytics front '.$/ 
 1865: 	if ($Apache::lonplot::plot{'gridlayer'} eq 'on');
 1866: 
 1867:     # grid
 1868:     $gnuplot_input .= 'set grid'.$/ if ($Apache::lonplot::plot{'grid'} eq 'on');
 1869:     # border
 1870:     $gnuplot_input .= ($Apache::lonplot::plot{'border'} eq 'on'?
 1871: 		       'set border'.$/           :
 1872: 		       'set noborder'.$/         );
 1873:     # sampling rate for non-data curves
 1874:     $gnuplot_input .= "set samples $Apache::lonplot::plot{'samples'}\n";
 1875:     # title, xlabel, ylabel
 1876:     # titles
 1877:     my $extra_space_x = ($xtics{'location'} eq 'axis') ? ' 0, -0.5 ' : '';
 1878:     my $extra_space_y = ($ytics{'location'} eq 'axis') ? ' -0.5, 0 ' : '';
 1879: 
 1880:     if ($target eq 'tex') {
 1881: 	$gnuplot_input .= "set title  \"$title\"          font \"".$font_properties->{'printname'}.",".$fontsize."pt\"\n" if (defined($title)) ;
 1882: 	$gnuplot_input .= "set xlabel \"$xlabel\" $extra_space_x font \"".$font_properties->{'printname'}.",".$fontsize."pt\"\n" if (defined($xlabel));
 1883: 	$gnuplot_input .= "set ylabel \"$ylabel\" $extra_space_y font \"".$font_properties->{'printname'}.",".$fontsize."pt\"\n" if (defined($ylabel));
 1884:     } else {
 1885:         $gnuplot_input .= "set title  \"$title\"          \n" if (defined($title)) ;
 1886:         $gnuplot_input .= "set xlabel \"$xlabel\" $extra_space_x \n" if (defined($xlabel));
 1887:         $gnuplot_input .= "set ylabel \"$ylabel\" $extra_space_y \n" if (defined($ylabel));
 1888:     }
 1889:     # tics
 1890:     $gnuplot_input .= &generate_tics('xtics', \%xtics, $target);
 1891: 
 1892:     $gnuplot_input .= &generate_tics('ytics', \%ytics, $target);
 1893: 
 1894:     # axis
 1895:     if (%axis) {
 1896:         if ($axis{'xformat'} ne 'on') {
 1897:             $gnuplot_input .= "set format x ";
 1898:             if ($axis{'xformat'} eq 'off') {
 1899:                 $gnuplot_input .= "\"\"\n";
 1900:             } else {
 1901:                 $gnuplot_input .= "\"\%.".$axis{'xformat'}."\"\n";
 1902:             }
 1903:         }
 1904:         if ($axis{'yformat'} ne 'on') {
 1905:             $gnuplot_input .= "set format y ";
 1906:             if ($axis{'yformat'} eq 'off') {
 1907:                 $gnuplot_input .= "\"\"\n";
 1908:             } else {
 1909:                 $gnuplot_input .= "\"\%.".$axis{'yformat'}."\"\n";
 1910:             }
 1911:         }
 1912: 	$gnuplot_input .= "set xrange \[$axis{'xmin'}:$axis{'xmax'}\]\n";
 1913: 	$gnuplot_input .= "set yrange \[$axis{'ymin'}:$axis{'ymax'}\]\n";
 1914: 		if ($axis{'xzero'} ne 'off') {
 1915: 			$gnuplot_input .= "set xzeroaxis ";
 1916: 			if ($axis{'xzero'} eq 'line' || $axis{'xzero'} eq 'thick-line') {
 1917: 				$gnuplot_input .= "lt -1 ";
 1918: 				if ($axis{'xzero'} eq 'thick-line') {
 1919: 					$gnuplot_input .= "lw 3 ";
 1920: 				}
 1921: 			}
 1922: 			$gnuplot_input .= "\n";
 1923: 		}
 1924: 		if ($axis{'yzero'} ne 'off') {
 1925: 			$gnuplot_input .= "set yzeroaxis ";
 1926: 			if ($axis{'yzero'} eq 'line' || $axis{'yzero'} eq 'thick-line') {
 1927: 				$gnuplot_input .= "lt -1 ";
 1928: 				if ($axis{'yzero'} eq 'thick-line') {
 1929: 					$gnuplot_input .= "lw 3 ";
 1930: 				}
 1931: 			}
 1932: 			$gnuplot_input .= "\n";
 1933: 		}
 1934:     }
 1935:     # Key
 1936:     if (%key) {
 1937: 	$gnuplot_input .= 'set key '.$key{'pos'}.' ';
 1938: 	if ($key{'title'} ne '') {
 1939: 	    $gnuplot_input .= 'title "'.$key{'title'}.'" ';
 1940: 	} 
 1941: 	$gnuplot_input .= ($key{'box'} eq 'on' ? 'box ' : 'nobox ').$/;
 1942:     } else {
 1943: 	$gnuplot_input .= 'set nokey'.$/;
 1944:     }
 1945:     # labels
 1946:     my $label;
 1947:     foreach $label (@labels) {
 1948: 	$gnuplot_input .= 'set label "'.$label->{'text'}.'" at '.
 1949:                           $label->{'xpos'}.','.$label->{'ypos'};
 1950:         if ($label->{'rotate'} ne '') {
 1951:             $gnuplot_input .= ' rotate by '.$label->{'rotate'};
 1952:         }
 1953:         $gnuplot_input .= ' '.$label->{'justify'};
 1954: 
 1955:         if ($target eq 'tex') {
 1956: 	    $gnuplot_input .=' font "'.$font_properties->{'printname'}.','.$fontsize.'pt"' ;
 1957:         }
 1958:         $gnuplot_input .= $/;
 1959:     }
 1960:     if ($target eq 'tex') {
 1961:         $gnuplot_input .="set size 1,".$Apache::lonplot::plot{'height'}/$Apache::lonplot::plot{'width'}*1.38;
 1962:         $gnuplot_input .="\n";
 1963:     }
 1964:     # curves
 1965:     #
 1966:     # Each curve will have its very own linestyle.
 1967:     # (This should work just fine in web rendition I think).
 1968:     #  The line_xxx variables will hold the elements of the line style.
 1969:     #  type (solid/dashed), color, width
 1970:     #
 1971:     my $linestyle_index = 50;
 1972:     my $line_width   = '';
 1973: 
 1974:     # If arrows are needed there will be an arrow style for each as well:
 1975:     #
 1976: 
 1977:     my $arrow_style_index = 50;
 1978: 
 1979:     my $plot_command;
 1980:     my $plot_type;
 1981: 
 1982:     for (my $i = 0;$i<=$#curves;$i++) {
 1983: 	$curve = $curves[$i];
 1984: 	$plot_command.= ', ' if ($i > 0);
 1985: 	if ($target eq 'tex') {
 1986: 	    $curve->{'linewidth'} *= 2;
 1987: 	}
 1988: 	$line_width = $curve->{'linewidth'};
 1989: 	if (exists($curve->{'function'})) {
 1990: 	    $plot_type    = 
 1991: 		$curve->{'function'}.' title "'.
 1992: 		$curve->{'name'}.'" with '.
 1993:                 $curve->{'linestyle'};
 1994: 	} elsif (exists($curve->{'data'})) {
 1995: 	    # Store data values in $datatext
 1996: 	    my $datatext = '';
 1997: 	    #   get new filename
 1998: 	    my $datafilename = "$tmpdir/$filename.data.$i";
 1999: 	    my $fh=Apache::File->new(">$datafilename");
 2000: 	    # Compile data
 2001: 	    my @Data = @{$curve->{'data'}};
 2002: 	    my @Data0 = @{$Data[0]};
 2003: 	    for (my $i =0; $i<=$#Data0; $i++) {
 2004: 		my $dataset;
 2005: 		foreach $dataset (@Data) {
 2006: 		    $datatext .= $dataset->[$i] . ' ';
 2007: 		}
 2008: 		$datatext .= $/;
 2009: 	    }
 2010: 	    #   write file
 2011: 	    print $fh $datatext;
 2012: 	    close($fh);
 2013: 	    #   generate gnuplot text
 2014: 	    $plot_type = '"'.$datafilename.'" title "'.
 2015: 		$curve->{'name'}.'" with '.
 2016: 		$curve->{'linestyle'};
 2017: 	}
 2018: 	my $pointtype = '';
 2019: 	my $pointsize = '';
 2020: 
 2021: 	# Figure out the linestyle:
 2022: 
 2023: 	my $lt = $curve->{'linetype'} ne '' ? $curve->{'linetype'} 
 2024: 	                : 'solid';	# Line type defaults to solid.
 2025: 	# The mapping of lt -> the actual gnuplot line type depends on the target:
 2026: 
 2027: 	if ($target eq 'tex') {
 2028: 	    $lt = $ps_linetypes{$lt};
 2029: 	} else {
 2030: 	    $lt = $linetypes{$lt}
 2031: 	}
 2032: 
 2033: 	my $color = $curve->{'color'};
 2034: 	$color =~ s/^x/#/;	        # Convert xhex color -> #hex color.   
 2035: 
 2036: 	my $style_command = "set style line $linestyle_index $pointtype $pointsize linetype $lt linewidth $line_width lc rgb '$color'\n";
 2037: 	$gnuplot_input .= $style_command;
 2038: 
 2039: 
 2040: 
 2041: 	if (($curve->{'linestyle'} eq 'points')      ||
 2042: 	    ($curve->{'linestyle'} eq 'linespoints') ||
 2043: 	    ($curve->{'linestyle'} eq 'errorbars')   ||
 2044: 	    ($curve->{'linestyle'} eq 'xerrorbars')  ||
 2045: 	    ($curve->{'linestyle'} eq 'yerrorbars')  ||
 2046: 	    ($curve->{'linestyle'} eq 'xyerrorbars')) {
 2047: 	    
 2048: 	    $pointtype =' pointtype '.$curve->{'pointtype'};
 2049: 	    $pointsize =' pointsize '.$curve->{'pointsize'};
 2050: 	} elsif ($curve->{'linestyle'} eq 'filledcurves') { 
 2051: 	    $plot_command.= ' '.$curve->{'limit'};
 2052: 	} elsif ($curve->{'linestyle'} eq 'vector') {
 2053: 
 2054: 	    # Create the arrow head style add it to 
 2055: 	    # $gnuplot_input..and ensure it gets
 2056: 	    # Selected in the plot command.
 2057: 
 2058: 	    $gnuplot_input .= "set style arrow $arrow_style_index ";
 2059: 	    $gnuplot_input .= ' ' . $curve->{'arrowhead'};
 2060: 	    $gnuplot_input .= ' size ' . $curve->{'arrowlength'};
 2061: 	    $gnuplot_input .= ','.$curve->{'arrowangle'};
 2062: 	    $gnuplot_input .= ',' . $curve->{'arrowbackangle'}; 
 2063: 	    $gnuplot_input .=  ' ' . $curve->{'arrowstyle'} . " ls $linestyle_index\n";
 2064: 
 2065: 
 2066: 	    $plot_command  .= "  arrowstyle $arrow_style_index ";
 2067: 	    $arrow_style_index++;
 2068: 	}
 2069: 
 2070: 
 2071: 
 2072: 
 2073: 	# The condition below is because gnuplot lumps the linestyle in with the 
 2074: 	# arrowstyle _sigh_.
 2075: 
 2076: 	if ($curve->{'linestyle'} ne 'vector') {
 2077: 	    $plot_command.= " ls $linestyle_index";
 2078: 	}
 2079: 
 2080: 	$gnuplot_input .= 'plot ' . $plot_type . ' ' . $plot_command . "\n";
 2081: 	$linestyle_index++;	# Each curve get a unique linestyle.
 2082:     }
 2083:     # Write the output to a file.
 2084:     # &Apache::lonnet::logthis($gnuplot_input); # uncomment to log the gnuplot input.
 2085:     open (my $fh, "> $tmpdir$filename.data");
 2086:     binmode($fh, ':utf8');
 2087:     print $fh $gnuplot_input;
 2088:     close($fh);
 2089:     # That's all folks.
 2090:     return ;
 2091: }
 2092: 
 2093: #---------------------------------------------- check_inputs
 2094: sub check_inputs {
 2095:     ## Note: no inputs, no outputs - this acts only on global variables.
 2096:     ## Make sure we have all the input we need:
 2097:     if (! %Apache::lonplot::plot) { &set_defaults(\%Apache::lonplot::plot,\%gnuplot_defaults); }
 2098:     if (! %key ) {} # No key for this plot, thats okay
 2099: #    if (! %axis) { &set_defaults(\%axis,\%axis_defaults); }
 2100:     if (! defined($title )) {} # No title for this plot, thats okay
 2101:     if (! defined($xlabel)) {} # No xlabel for this plot, thats okay
 2102:     if (! defined($ylabel)) {} # No ylabel for this plot, thats okay
 2103:     if ($#labels < 0) { }      # No labels for this plot, thats okay
 2104:     if ($#curves < 0) { 
 2105: 	&Apache::lonxml::warning("No curves specified for plot!!!!");
 2106: 	return '';
 2107:     }
 2108:     my $curve;
 2109:     foreach $curve (@curves) {
 2110: 	if (!defined($curve->{'function'})&&!defined($curve->{'data'})){
 2111: 	    &Apache::lonxml::warning("One of the curves specified did not contain any curve data or curve function declarations\n");
 2112: 	    return '';
 2113: 	}
 2114:     }
 2115: }
 2116: 
 2117: #------------------------------------------------ make_edit
 2118: sub edit_attributes {
 2119:     my ($target,$token,$defaults,$keys) = @_;
 2120:     my ($result,@keys);
 2121:     if ($keys && ref($keys) eq 'ARRAY') {
 2122:         @keys = @$keys;
 2123:     } else {
 2124: 	@keys = sort(keys(%$defaults));
 2125:     }
 2126:     foreach my $attr (@keys) {
 2127: 	# append a ' ' to the description if it doesn't have one already.
 2128: 	my $description = $defaults->{$attr}->{'description'};
 2129: 	$description .= ' ' if ($description !~ / $/);
 2130: 	if ($defaults->{$attr}->{'edit_type'} eq 'entry') {
 2131: 	    $result .= &Apache::edit::text_arg
 2132: 		($description,$attr,$token,
 2133: 		 $defaults->{$attr}->{'size'},
 2134: 		$defaults->{$attr}->{'class'});
 2135: 	} elsif ($defaults->{$attr}->{'edit_type'} eq 'choice') {
 2136: 	    $result .= &Apache::edit::select_or_text_arg
 2137: 		($description,$attr,$defaults->{$attr}->{'choices'},$token);
 2138: 	} elsif ($defaults->{$attr}->{'edit_type'} eq 'onoff') {
 2139: 	    $result .= &Apache::edit::select_or_text_arg
 2140: 		($description,$attr,['on','off'],$token);
 2141: 	}
 2142: 	$result .= '<br />';
 2143:     }
 2144:     return $result;
 2145: }
 2146: 
 2147: 
 2148: ###################################################################
 2149: ##                                                               ##
 2150: ##           Insertion functions for editing plots               ##
 2151: ##                                                               ##
 2152: ###################################################################
 2153: 
 2154: sub insert_gnuplot {
 2155:     my $result = '';
 2156:     #  plot attributes
 2157:     $result .= "\n<gnuplot ";
 2158:     foreach my $attr (keys(%gnuplot_defaults)) {
 2159: 	$result .= "\n     $attr=\"$gnuplot_defaults{$attr}->{'default'}\"";
 2160:     }
 2161:     $result .= ">";
 2162:     # Add the components (most are commented out for simplicity)
 2163:     # $result .= &insert_key();
 2164:     # $result .= &insert_axis();
 2165:     # $result .= &insert_title();    
 2166:     # $result .= &insert_xlabel();    
 2167:     # $result .= &insert_ylabel();    
 2168:     $result .= &insert_curve();
 2169:     # close up the <gnuplot>
 2170:     $result .= "\n</gnuplot>";
 2171:     return $result;
 2172: }
 2173: 
 2174: sub insert_tics {
 2175:     my $result;
 2176:     $result .= &insert_xtics() . &insert_ytics;
 2177:     return $result;
 2178: }
 2179: 
 2180: sub insert_xtics {
 2181:     my $result;
 2182:     $result .= "\n    <xtics ";
 2183:     foreach my $attr (keys(%tic_defaults)) {
 2184: 	$result .= "\n        $attr=\"$tic_defaults{$attr}->{'default'}\" ";
 2185:     }
 2186:     $result .= "/>";
 2187:     return $result;
 2188: }
 2189: 
 2190: sub insert_ytics {
 2191:     my $result;
 2192:     $result .= "\n    <ytics ";
 2193:     foreach my $attr (keys(%tic_defaults)) {
 2194: 	$result .= "\n        $attr=\"$tic_defaults{$attr}->{'default'}\" ";
 2195:     }
 2196:     $result .= "/>";
 2197:     return $result;
 2198: }
 2199: 
 2200: sub insert_key {
 2201:     my $result;
 2202:     $result .= "\n    <key ";
 2203:     foreach my $attr (keys(%key_defaults)) {
 2204: 	$result .= "\n         $attr=\"$key_defaults{$attr}->{'default'}\"";
 2205:     }
 2206:     $result .= " />";
 2207:     return $result;
 2208: }
 2209: 
 2210: sub insert_axis{
 2211:     my $result;
 2212:     $result .= "\n    <axis ";
 2213:    foreach my $attr (keys(%axis_defaults)) {
 2214: 	$result .= "\n         $attr=\"$axis_defaults{$attr}->{'default'}\"";
 2215:     }
 2216:     $result .= " />";
 2217:     return $result;
 2218: }
 2219: 
 2220: sub insert_title  { return "\n    <title></title>"; }
 2221: sub insert_xlabel { return "\n    <xlabel></xlabel>"; }
 2222: sub insert_ylabel { return "\n    <ylabel></ylabel>"; }
 2223: 
 2224: sub insert_label {
 2225:     my $result;
 2226:     $result .= "\n    <label ";
 2227:     foreach my $attr (keys(%label_defaults)) {
 2228: 	$result .= "\n         $attr=\"".
 2229:             $label_defaults{$attr}->{'default'}."\"";
 2230:     }
 2231:     $result .= "></label>";
 2232:     return $result;
 2233: }
 2234: 
 2235: sub insert_curve {
 2236:     my $result;
 2237:     $result .= "\n    <curve ";
 2238:     foreach my $attr (keys(%curve_defaults)) {
 2239: 	$result .= "\n         $attr=\"".
 2240: 	    $curve_defaults{$attr}->{'default'}."\"";
 2241:     }
 2242:     $result .= " >";
 2243:     $result .= &insert_data().&insert_data()."\n    </curve>";
 2244: }
 2245: 
 2246: sub insert_function {
 2247:     my $result;
 2248:     $result .= "\n        <function></function>";
 2249:     return $result;
 2250: }
 2251: 
 2252: sub insert_data {
 2253:     my $result;
 2254:     $result .= "\n        <data></data>";
 2255:     return $result;
 2256: }
 2257: 
 2258: ##----------------------------------------------------------------------
 2259: 1;
 2260: __END__
 2261: 
 2262: 
 2263: =head1 NAME
 2264: 
 2265: Apache::lonplot.pm
 2266: 
 2267: =head1 SYNOPSIS
 2268: 
 2269: XML-based plotter of graphs
 2270: 
 2271: This is part of the LearningOnline Network with CAPA project
 2272: described at http://www.lon-capa.org.
 2273: 
 2274: 
 2275: =head1 SUBROUTINES (parsing and edit rendering)
 2276: 
 2277: =over
 2278: 
 2279: =item start_gnuplot()
 2280: 
 2281: =item end_gnuplot()
 2282: 
 2283: =item start_xtics()
 2284: 
 2285: =item end_xtics()
 2286: 
 2287: =item start_ytics()
 2288: 
 2289: =item end_ytics()
 2290: 
 2291: =item get_font()
 2292: 
 2293: =item start_key()
 2294: 
 2295: =item end_key()
 2296: 
 2297: =item parse_label()
 2298: 
 2299: =item replace_entities()
 2300: 
 2301: =item start_title()
 2302: 
 2303: =item end_title()
 2304: 
 2305: =item start_xlabel()
 2306: 
 2307: =item end_xlabel()
 2308: 
 2309: =item start_ylabel()
 2310: 
 2311: =item end_label()
 2312: 
 2313: =item start_curve()
 2314: 
 2315: =item end_curve()
 2316: 
 2317: =item start_function()
 2318: 
 2319: =item end_function()
 2320: 
 2321: =item start_data()
 2322: 
 2323: =item end_data()
 2324: 
 2325: =item start_axis()
 2326: 
 2327: =item end_axis
 2328: 
 2329: =back
 2330: 
 2331: =head1 SUBROUTINES (Utility)
 2332: 
 2333: =over
 2334: 
 2335: =item set_defaults()
 2336: 
 2337: =item get_attributes()
 2338: 
 2339: =item write_gnuplot_file()
 2340: 
 2341: =item check_inputs()
 2342: 
 2343: =item edit_attributes()
 2344: 
 2345: =back
 2346: 
 2347: =head1 SUBROUTINES (Insertion functions for editing plots)
 2348: 
 2349: =over
 2350: 
 2351: =item insert_gnuplot()
 2352: 
 2353: =item insert_tics()
 2354: 
 2355: =item insert_xtics()
 2356: 
 2357: =item insert_key()
 2358: 
 2359: =item insert_axis()
 2360: 
 2361: =item insert_title()
 2362: 
 2363: =item insert_xlabel()
 2364: 
 2365: =item insert_ylabel()
 2366: 
 2367: =item insert_label()
 2368: 
 2369: =item insert_curve()
 2370: 
 2371: =item insert_function()
 2372: 
 2373: =item insert_data()
 2374: 
 2375: =back
 2376: 
 2377: =cut

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>