Complex Networks

Jerry's Space in WHU and WUSE
 
« 上一篇: What types of integration can MATLAB perform? 下一篇: SAVEPPT: This function saves Matlab figure windows or Simulink models to a Powerpoint file. »
jerry @ 2005-10-10 20:47

LaPrint is a MATLAB function to print MATLAB graphics for inclusion in LaTeX documents. LaPrint creates an eps-file and a tex-file. The tex-file contains the annotation of the figure such as titles, labels and texts. The eps-file contains the non-text part of the figure and is called by the tex-file.

The main advantage of using LaPrint is that the annotation can be neatly (e.g., including math mode and fancy font constructs) set within LaTeX. LaPrint can be used from the command line or via a graphical user interface (GUI).

Current Version is 3.16. Matlab 6.1 or above is required.

An Users Guide for LaPrint is available at
http://www.uni-kassel.de/fb16/rat/matlab/laprint/laprintdoc.ps

function laprint(figno,filename,varargin)
%LAPRINT prints a figure for inclusion in LaTeX documents.
%  LaPrint creates an eps-file and a tex-file. The tex-file contains
%  the annotation of the figure such as titles, labels and texts. The
%  eps-file contains the non-text part of the figure as well as the
%  position of the text-objects. The packages 'graphicx' (or 'epsfig')
%  and 'psfrag' (and possibly ''color'') are required for the LaTeX
%  run. A postscript driver like 'dvips' is required for printing.
%
%  Usage:   >> laprint
%
%  This opens a graphical user interface window, to control the
%  various settings. It includes a help facility. Just try it.
%
%  As an alternative to the GUI you can call laprint from the command
%  line with various extra input arguments. These arguments are
%  explained in the help window of the GUI, which can be also be
%  opened using the command
%      >> laprint helpwindow
%
%  There is an Users Guide available at
%      http://www.uni-kassel.de/fb16/rat/matlab/laprint/laprintdoc.ps  

%  (c) Arno Linnemann.   All rights reserved.
%  The author of this program assumes no responsibility for any  errors
%  or omissions. In no event shall he be liable for damages  arising out of
%  any use of the software. Redistribution of the unchanged file is allowed.
%  Distribution of changed versions is allowed provided the file is renamed
%  and the source and authorship of the original version is acknowledged in
%  the modified file.

%  Please report bugs, suggestions and comments to:
%  Arno Linnemann
%  Control and Automation
%  Department of Electrical and Computer Engineering
%  University of Kassel
%  34109 Kassel
%  Germany
%  mailto:linnemann@uni-kassel.de

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%
%%%% Initialize
%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

laprintident = '3.16 (13.9.2004)';   
vers = version;
vers = eval(vers(1:3));
if vers < 6.1
 error('Sorry. Matlab 6.1 or above is required.')
end

hf=131;
hhf=132;

% no output
if nargout
  error('No output argument, please.')
end  

inter=get(0,'defaulttextinterpreter');
if ~strcmp(inter,'none')
 warning('LaPrint:general',['It is recommended to switch off the '...
         'text interpreter\nbefore creating a figure to be saved '...
         'with LaPrint. Use the command\n',...
         '   >> set(0,''defaulttextinterpreter'',''none'').'])
end

if nargin==0

  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %%%%
  %%%% GUI
  %%%%
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  try
    delete(hf)
  end
  try
    delete(hhf)
  end

  %---------------------------------
  % open window
  %---------------------------------

  hf = figure(hf);
  clf reset;
  set(hf,'NumberTitle','off',...
         'Name','LaPrint (LaTeX Print)',...
         'Units','points',...
         'CloseRequestFcn','laprint(''quit'');',...
         'menubar','none')
  h = uicontrol('Parent',hf,'Units','points');
  fsize = get(h,'Fontsize');
  delete(h)
  posf = get(hf,'Position');
  figheight = 10*fsize;
  figwidth  = 32*fsize;
  posf = [ posf(1) posf(2)+posf(4)-figheight figwidth figheight];
  set(hf,'Position',posf)
  uicontrol('Parent',hf,'style','frame','Units','points',...
 'Position',[0 0 figwidth figheight])
  curh = figheight-0*fsize;

  LAPRINTHAN=struct('figno',{0},'filename',{0},...
     'keepfontprops',{0},'asonscreen',{0},'keepticklabels',{0},...
     'mathticklabels',{0},'head',{0},'extrapicture',{0},...
     'verbose',{0},'figcopy',{0},'package_epsfig',{0},...
     'package_graphicx',{0},'color',{0},'createview',{0},...
     'processview',{0});
 
  %---------------------------------
  % figure no.
  %---------------------------------

  loch = 1.7*fsize;
  curh = curh-loch-1.5*fsize;
  h = uicontrol('Parent',hf,...
                'style','text',...
                'Units','points',...
                'Position',[1*fsize curh 18*fsize loch],...
                'HorizontalAlignment','left',...
                'string','Number of Figure to be saved:');
  h = uicontrol('Parent',hf,...
                'style','edit',...
                'Units','points',...
                'Position',[19*fsize curh 12*fsize loch],...
                'HorizontalAlignment','left',...
                'BackgroundColor',[1 1 1],...
                'Callback','laprint(''figno'');');
  LAPRINTHAN.figno = h;

  %---------------------------------
  % filename
  %---------------------------------

  loch = 1.7*fsize;
  curh = curh-loch-1*fsize;
  h = uicontrol('Parent',hf,...
                'style','text',...
                'Units','points',...
                'Position',[1*fsize curh 18*fsize loch],...
                'HorizontalAlignment','left',...
                'string','Basename of Files to be Created:');
  h = uicontrol('Parent',hf,...
                'style','edit',...
                'Units','points',...
                'Position',[19*fsize curh 12*fsize loch],...
                'HorizontalAlignment','left',...
                'BackgroundColor',[1 1 1],...
                'Callback','laprint(''filename'');');
  LAPRINTHAN.filename = h;

  %---------------------------------
  % save, quit
  %---------------------------------

  loch = 2*fsize;
  curh = curh-loch-1*fsize;
  h = uicontrol('Parent',hf,...
                'Style','pushbutton',...
                'Units','Points',...
                'Position',[19*fsize curh 5*fsize loch],...
                'HorizontalAlignment','center',...
                'String','Go !',...
                'Callback','laprint(''save'');');
  h = uicontrol('Parent',hf,...
                'Style','pushbutton',...
                'Units','Points',...
                'Position',[26*fsize curh 5*fsize loch],...
                'HorizontalAlignment','center',...
                'String','Quit',...
                'Callback','laprint(''quit'');');

  %---------------------------------
  % options uimenue
  %---------------------------------

  hm1 = uimenu('label','Options');

  uimenu(hm1,...
      'label','Sizes and Scalings ...',...
      'callback','laprint(''size'')');

  LAPRINTHAN.keepfontprops = uimenu(hm1,...
      'label','Translate Matlab Font Properties to LaTeX',...
      'callback','laprint(''keepfontprops'')');

  LAPRINTHAN.asonscreen = uimenu(hm1,...
      'label','Print Limits and Ticks as on Screen',...
      'separator','on',...
      'callback','laprint(''asonscreen'')');

  LAPRINTHAN.keepticklabels = uimenu(hm1,...
      'label','Keep Tick Labels within eps File',...
      'callback','laprint(''keepticklabels'')');

  LAPRINTHAN.mathticklabels = uimenu(hm1,...
      'label','Set Tick Labels in LaTeX Math Mode',...
      'callback','laprint(''mathticklabels'')');

  LAPRINTHAN.head = uimenu(hm1,...
      'label','Equip the tex File with a Head',...
      'separator','on',...
      'callback','laprint(''head'')');

  uimenu(hm1,...
      'label','Comment in the Head of the tex File ...',...
      'callback','laprint(''comment'')');

  uimenu(hm1,...
      'label','Place a LaTeX Caption in the tex File ...',...
      'callback','laprint(''caption'')');

  LAPRINTHAN.extrapicture = uimenu(hm1,...
      'label','Place an Extra Picture in each Axes',...
      'callback','laprint(''extrapicture'')');

  uimenu(hm1,...
      'label','Length of psfrag Replacement Strings ...',...
      'callback','laprint(''nzeros'')');

  LAPRINTHAN.verbose = uimenu(hm1,...
      'label','Call LaPrint in Verbose Mode',...
      'separator','on',...
      'callback','laprint(''verbose'')');

  LAPRINTHAN.figcopy = uimenu(hm1,...
      'label','Copy Figure and Modify that Copy',...
      'callback','laprint(''figcopy'')');

  uimenu(hm1,...
      'label','Matlab Print Command ...',...
      'separator','on',...
      'callback','laprint(''printcmd'')');

  h=uimenu(hm1,...
      'separator','on',...
      'label','LaTeX Graphics Package');
  
  LAPRINTHAN.package_graphicx = uimenu(h,...
      'label','graphicx',...
      'callback','laprint(''package_graphicx'')');
  
  LAPRINTHAN.package_epsfig = uimenu(h,...
      'label','epsfig',...
      'callback','laprint(''package_epsfig'')');
    
  LAPRINTHAN.color = uimenu(hm1,...
      'label','Use LaTeX ''color'' Package',...
      'callback','laprint(''color'')');
 
  h = uimenu(hm1,...
      'label','View File ...',...
      'separator','on');

  LAPRINTHAN.createview = uimenu(h,...
      'label','Create a View File',...
      'callback','laprint(''createview'')');
 
  uimenu(h,...
      'label','Name of the View File ...',...
      'callback','laprint(''viewfilename'')');

  LAPRINTHAN.processview = uimenu(h,...
      'label','Process the View File',...
      'separator','on',...
      'callback','laprint(''processview'')');

  uimenu(h,...
      'label','Executables for Processing View File...',...
      'callback','laprint(''cmdsview'')');

  %---------------------------------
  % Preferences uimenue
  %---------------------------------
    
  hm3=uimenu('label','Preferences');
    
  uimenu(hm3,...
      'label','Get Preferences',...
      'callback','laprint(''getpref'')')
  
  uimenu(hm3,...
      'label','Set Preferences to Current Settings',...
      'callback','laprint(''setpref'')')
  
  uimenu(hm3,...
      'label','Remove Preferences',...
      'callback','laprint(''rmpref'')')
  
  uimenu(hm3,...
      'label','Save Current Settings to a File ...',...
      'separator','on',...
      'callback','laprint(''savepref'')')
  
  uimenu(hm3,...
      'label','Load Settings from a File ...',...
      'callback','laprint(''loadpref'')')
  
  uimenu(hm3,...
      'label','Get Factory Defaults',...
      'separator','on',...
      'callback','laprint(''factory'')')

 
  %---------------------------------
  % Help uimenue
  %---------------------------------
  
  hm2=uimenu('label','Help');
  
  uimenu(hm2,...
      'label',['LaPrint Online Help ...'],...
      'callback','laprint(''helpwindow'')');
 
  uimenu(hm2,...
      'label','Get the LaPrint Users Guide',...
      'callback',['web www.uni-kassel.de/fb16/rat/matlab',...
                  '/laprint/laprintdoc.ps -browser'])
   
  uimenu(hm2,...
      'label',['Look for a newer version of LaPrint ' ...
          '(Matlab Central File Exchange)...'],...
      'callback',['web http://www.mathworks.de/matlabcentral/',...
                     'fileexchange/loadFile.do?objectId=4638',...
                     '&objectType=file -browser'])
   
  uimenu(hm2,...
      'label','Version and Author ...',...
      'callback','laprint(''whois'')')

  %---------------------------------
  % make hf invisible
  %---------------------------------

  set(hf,'HandleVisibility','callback')

  %---------------------------------
  % get settings
  %---------------------------------

  LAPRINTOPT = prefsettings;
  if isempty(LAPRINTOPT)
     LAPRINTOPT = factorysettings;
  end  

  %---------------------------------
  % get figure
  %---------------------------------
   
  gcfig=gcf;
  if gcfig == hf
      allfigs = findobj('type','figure');
      allfigs = allfigs(find(allfigs~=hf));
      if length(allfigs)
         figno = allfigs(1);
      else
         figure(1)
         figno=1;
      end    
  else
      figno=gcfig;
  end
  LAPRINTOPT.figno = figno;

  %---------------------------------
  % update
  %---------------------------------
 
  updategui(LAPRINTHAN,LAPRINTOPT)
  sethf(hf,LAPRINTHAN,LAPRINTOPT)
  figure(hf)

  %---------------------------------
  % done
  %---------------------------------

  return
  
end  % if nargin==0

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%
%%%% callback calls ('factory' and 'getprefs' also
%%%%                  used from command line)
%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if isa(figno,'char')

 switch figno
 case 'figno'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   LAPRINTOPT.figno=eval(get(LAPRINTHAN.figno,'string'));
   figure(LAPRINTOPT.figno)
   figure(hf)
   sethf(hf,LAPRINTHAN,LAPRINTOPT);
 case 'filename'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   LAPRINTOPT.filename=get(LAPRINTHAN.filename,'string');
   [texfullnameext,texbasenameext,texbasename,texdirname] = ...
getfilenames(LAPRINTOPT.filename,'tex',0);
   [epsfullnameext,epsbasenameext,epsbasename,epsdirname] = ...
getfilenames(LAPRINTOPT.filename,'eps',0);
   sethf(hf,LAPRINTHAN,LAPRINTOPT);
 case 'save'
%     lapcmd = [ 'laprint(' int2str(LAPRINTOPT.figno) ...
%   ', ''' LAPRINTOPT.filename ''''...
%   ', ''options'', LAPRINTOPT)'];
   lapcmd = 'laprint({})';
   eval(lapcmd)
 case 'quit'
   delete(hf)
   try
     delete(hhf)
   end
 case 'size'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   answer = inputdlg({['Please enter the width (in centimeters) ',...
        'of the graphics in the LaTeX document (The height ',...
        'will be computed such that the aspect ratio of the ',...
        'figure on screen is retained.) :'],...
        ['Please enter the factor by which the size of the '...
        'graphics in the LaTeX document differs from the size of the '...
        'Postscipt graphics ( Explaination: A factor <1 scales ',...
        'the picture down. This means that lines become thinner ',...
        'and fonts become smaller. ) :'],...
        ['Please specify if you want to scale the fonts along with ',...
        'the graphics (enter ''on'' or ''off'') : '] },...
        'LaPrint Settings',1,{num2str(LAPRINTOPT.width),...
        num2str(LAPRINTOPT.factor),...
        valueyn(LAPRINTOPT.scalefonts)},'on');
   if length(answer)
        LAPRINTOPT.width=eval(answer{1});
        LAPRINTOPT.factor = eval(answer{2});
        LAPRINTOPT.scalefonts = value01(answer{3});
   end
   sethf(hf,LAPRINTHAN,LAPRINTOPT);
 case 'keepfontprops'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   if LAPRINTOPT.keepfontprops==1
     LAPRINTOPT.keepfontprops=0;
     set(LAPRINTHAN.keepfontprops,'check','off')
   else
     LAPRINTOPT.keepfontprops=1;
     set(LAPRINTHAN.keepfontprops,'check','on')
   end      
   sethf(hf,LAPRINTHAN,LAPRINTOPT);
 case 'asonscreen'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   if LAPRINTOPT.asonscreen==1
     LAPRINTOPT.asonscreen=0;
     set(LAPRINTHAN.asonscreen,'check','off')
   else
     LAPRINTOPT.asonscreen=1;
     set(LAPRINTHAN.asonscreen,'check','on')
   end      
   sethf(hf,LAPRINTHAN,LAPRINTOPT);
 case 'keepticklabels'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   if LAPRINTOPT.keepticklabels==1
     LAPRINTOPT.keepticklabels=0;
     set(LAPRINTHAN.keepticklabels,'check','off')
   else
     LAPRINTOPT.keepticklabels=1;
     set(LAPRINTHAN.keepticklabels,'check','on')
   end      
   sethf(hf,LAPRINTHAN,LAPRINTOPT);
 case 'mathticklabels'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   if LAPRINTOPT.mathticklabels==1
     LAPRINTOPT.mathticklabels=0;
     set(LAPRINTHAN.mathticklabels,'check','off')
   else
     LAPRINTOPT.mathticklabels=1;
     set(LAPRINTHAN.mathticklabels,'check','on')
   end      
   sethf(hf,LAPRINTHAN,LAPRINTOPT);
 case 'head'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   if LAPRINTOPT.head==1
     LAPRINTOPT.head=0;
     set(LAPRINTHAN.head,'check','off')
   else
     LAPRINTOPT.head=1;
     set(LAPRINTHAN.head,'check','on')
   end      
   sethf(hf,LAPRINTHAN,LAPRINTOPT);
 case 'comment'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   answer = inputdlg({['Please enter a describing comment to '...
        'be placed into the head of the tex file:']},...
        'LaPrint Settings',1,{LAPRINTOPT.comment},'on');
   if length(answer)
        LAPRINTOPT.comment = answer{1};
   end
   sethf(hf,LAPRINTHAN,LAPRINTOPT);
 case 'caption'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   answer = inputdlg(['If the following text is nonempty, ' ...
        'then it will be placed as a \caption{} into the tex '...
        'file along with \label{fig:' LAPRINTOPT.filename '}. '...
        'Please enter the caption text:'],...
        'LaPrint Settings',1,{LAPRINTOPT.caption},'on');
   if length(answer)
        LAPRINTOPT.caption = answer{1};
   end
   sethf(hf,LAPRINTHAN,LAPRINTOPT);
 case 'extrapicture'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   if LAPRINTOPT.extrapicture==1
     LAPRINTOPT.extrapicture=0;
     set(LAPRINTHAN.extrapicture,'check','off')
   else
     LAPRINTOPT.extrapicture=1;
     set(LAPRINTHAN.extrapicture,'check','on')
   end      
   sethf(hf,LAPRINTHAN,LAPRINTOPT);
 case 'nzeros'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   answer = inputdlg({['Please enter length of the psfrag replacement '...
        'strings (must be >= 3) :']},...
        'LaPrint Settings',1,{num2str(LAPRINTOPT.nzeros)},'on');
   if length(answer)
       LAPRINTOPT.nzeros = max(eval(answer{1}),3);
   end
   sethf(hf,LAPRINTHAN,LAPRINTOPT);
 case 'verbose'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   if LAPRINTOPT.verbose==1
     LAPRINTOPT.verbose=0;
     set(LAPRINTHAN.verbose,'check','off')
   else
     LAPRINTOPT.verbose=1;
     set(LAPRINTHAN.verbose,'check','on')
   end      
   sethf(hf,LAPRINTHAN,LAPRINTOPT);
 case 'figcopy'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   if LAPRINTOPT.figcopy==1
     LAPRINTOPT.figcopy=0;
     set(LAPRINTHAN.figcopy,'check','off')
   else
     LAPRINTOPT.figcopy=1;
     set(LAPRINTHAN.figcopy,'check','on')
   end      
   sethf(hf,LAPRINTHAN,LAPRINTOPT);
 case 'printcmd'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   answer = inputdlg({['Please enter the Matlab command '...
        'to be used for printing the eps file '...
        '(LaPrint will internally replace <figurenumber> by the '...
        'number of the figure <filename.eps> by the ' ...
        'eps-filename and <filename> '...
        'by the basename of the file, respectively). You can add options '...
        'here (like ''-loose'') or use a different program '...
        'for printing (like ''exportfig'') :']},...
        'LaPrint Settings',1,{LAPRINTOPT.printcmd},'on');
   if length(answer)
        LAPRINTOPT.printcmd = answer{1};
   end
   sethf(hf,LAPRINTHAN,LAPRINTOPT);
 case 'package_epsfig'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   LAPRINTOPT.package='epsfig';
   set(LAPRINTHAN.package_epsfig,'check','on')
   set(LAPRINTHAN.package_graphicx,'check','off')
   sethf(hf,LAPRINTHAN,LAPRINTOPT);
 case 'package_graphicx'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   LAPRINTOPT.package='graphicx';
   set(LAPRINTHAN.package_epsfig,'check','off')
   set(LAPRINTHAN.package_graphicx,'check','on')
   sethf(hf,LAPRINTHAN,LAPRINTOPT);
 case 'color'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   if LAPRINTOPT.color==1
     LAPRINTOPT.color=0;
     set(LAPRINTHAN.color,'check','off')
   else
     LAPRINTOPT.color=1;
     set(LAPRINTHAN.color,'check','on')
   end      
   sethf(hf,LAPRINTHAN,LAPRINTOPT);
 case 'createview'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   if LAPRINTOPT.createview==1
     LAPRINTOPT.createview=0;
     LAPRINTOPT.processview=0;
     set(LAPRINTHAN.createview,'check','off')
     set(LAPRINTHAN.processview,'check','off')
   else
     LAPRINTOPT.createview=1;
     set(LAPRINTHAN.createview,'check','on')
   end      
   sethf(hf,LAPRINTHAN,LAPRINTOPT);
 case 'viewfilename'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
     trydlg=1;
     txt=['Please enter the name of the '...
         'viewfile (without extension .tex) : '];
     txt2='';
     while trydlg
       answer = inputdlg({[txt txt2]},...
         'LaPrint Settings',1,{LAPRINTOPT.viewfilename},'on');
       if length(answer)
         if strcmp(answer{1},LAPRINTOPT.filename)
           txt2=['The name must be different from the name of the '...
                 'graphics file):'];
         else
            trydlg=0;  
            LAPRINTOPT.viewfilename = answer{1};
            [viewfullnameext,viewbasenameext,viewbasename,viewdirname] = ...
                 getfilenames(LAPRINTOPT.viewfilename,'tex',0);
        end      
       else
         trydlg=0;
       end  
     end
   sethf(hf,LAPRINTHAN,LAPRINTOPT);
 case 'processview'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   if LAPRINTOPT.processview==1
     LAPRINTOPT.processview=0;
     set(LAPRINTHAN.processview,'check','off')
   else
     LAPRINTOPT.processview=1;
     set(LAPRINTHAN.processview,'check','on')
     LAPRINTOPT.createview=1;
     set(LAPRINTHAN.createview,'check','on')
   end      
   sethf(hf,LAPRINTHAN,LAPRINTOPT);
 case 'cmdsview'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   answer = inputdlg({...
      ['Please enter up to 8 commands to process the view-file. ',...
      'Leave any of the fields empty, if you have ',...
      'less than 8 commands. ',...  
      'In any of the following commands, LaPrint internally '...
      'replaces the tag <viewfile> by the name of the viewfile ',...
      'and the tag <filename> by the basename specified in the ',...
      'main LaPrint Window. ',...
      'At minimum you should enter the commands for the LaTeX ',...
      'compilation and for the dvi-to-postscript conversion ',...
      'here. See the LaPrint Online-Help for futher ',...
      'suggestions.   ',...
      'Please enter the 1st command:'],...
      'Please enter the 2nd command:',...
      'Please enter the 3rd command:',...
      'Please enter the 4th command:',...
      'Please enter the 5th command:',...
      'Please enter the 6th command:',...
      'Please enter the 7th command:',...
      'Please enter the 8th command:'},...
      'LaPrint Settings',1,{LAPRINTOPT.cmd1,...
      LAPRINTOPT.cmd2,LAPRINTOPT.cmd3,...
      LAPRINTOPT.cmd4,LAPRINTOPT.cmd5,LAPRINTOPT.cmd6,...
      LAPRINTOPT.cmd7,LAPRINTOPT.cmd8},'on');
   if length(answer)==8
      LAPRINTOPT.cmd1=answer{1};
      LAPRINTOPT.cmd2=answer{2};
      LAPRINTOPT.cmd3=answer{3};
      LAPRINTOPT.cmd4=answer{4};
      LAPRINTOPT.cmd5=answer{5};
      LAPRINTOPT.cmd6=answer{6};
      LAPRINTOPT.cmd7=answer{7};
      LAPRINTOPT.cmd8=answer{8};
   end   
   sethf(hf,LAPRINTHAN,LAPRINTOPT);
 case 'getpref'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   out = prefsettings;
   if ~isempty(out)
      oldfigno = LAPRINTOPT.figno;   % keep this!         
      LAPRINTOPT = out;
      LAPRINTOPT.figno = oldfigno;        
   else
      errordlg('No LaPrint preferences available.')   
   end
   updategui(LAPRINTHAN,LAPRINTOPT);
   sethf(hf,LAPRINTHAN,LAPRINTOPT);
 case 'setpref'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   setpref('LaPrint','LAPRINTOPT',LAPRINTOPT);
 case 'rmpref'
   if ispref('LaPrint')
     rmpref('LaPrint');
   else
     errordlg('Preference does not exist.')   
   end
 case 'savepref'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   txt = 'Save preferences file ';
   [preffile,prefpath]=uiputfile('laprint.mat',txt);
   save([prefpath preffile],'LAPRINTOPT');
 case 'loadpref'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   txt = ['Load preferences file '...
          '(must be previously created by LaPrint)'];
   [preffile,prefpath]=uigetfile('laprint.mat',txt);
   if ~isequal(preffile,0) & ~isequal(prefpath,0)
     oldfigno = LAPRINTOPT.figno;   % keep this!         
     load([prefpath preffile]); % hope file contains correct
     LAPRINTOPT.figno = oldfigno;                   % LAPRINTOPT
     updategui(LAPRINTHAN,LAPRINTOPT);
     sethf(hf,LAPRINTHAN,LAPRINTOPT);
   end
 case 'factory'
   [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
   out = factorysettings;
   if ~isempty(out)
      oldfigno = LAPRINTOPT.figno;   % keep this!         
      LAPRINTOPT = out;
      LAPRINTOPT.figno = oldfigno;        
   else
      errordlg('No LaPrint preferences available.')   
   end
   updategui(LAPRINTHAN,LAPRINTOPT);
   sethf(hf,LAPRINTHAN,LAPRINTOPT);
 case 'helpwindow'
   hhf=figure(hhf);
   set(hhf,'Name','LaPrint Online Help',...
           'Numbertitle','off',...
           'menubar','none',...
           'HandleVisibility','callback',...
           'resize','on',...
           'ResizeFcn','laprint(''helpwindow'');');
   hht=uicontrol('Parent',hhf,...
             'style','listbox',...
             'units','normalized',...
             'position',[0.005 0.005 0.9 0.99],...
             'BackgroundColor','w',...
             'Fontsize',12,...
             'foregroundcolor','k',...
             'FontName','FixedWidth',...
             'HorizontalAlignment','left');
   [txt,hhtpos]=textwrap(hht,helptext);
   set(hht,'string',txt)
   set(hht,'position',[0.005 0.005 0.99 0.99])
   set(hht,'HandleVisibility','callback')
 case 'whois'
   msgbox({['This is LaPrint, Version ' laprintident],...
         '',...
         'To blame for LaPrint:',...
     'Arno Linnemann','Control and Automation',...
     'Department of Electrical and Computer Engineering',...
     'University of Kassel',...
     '34109 Kassel',...      
     'Germany',...
         'mailto:linnemann@uni-kassel.de'},...
         'LaPrint Info')
 otherwise
   error('unknown callback option')
 end
 return
end    % if isa(figno,'char')

% nargin >=1 and ~isa(figno,'char')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%
%%%% PART 1 of advanced usage:
%%%% Check inputs and initialize
%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if isa(figno,'cell') % called from GUI (all set)

 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
 figno=LAPRINTOPT.figno;
 filename=LAPRINTOPT.filename;

else % advanced usage
 
 % get settings
 LAPRINTOPT = prefsettings;
 if isempty(LAPRINTOPT)
    LAPRINTOPT = factorysettings;
 end

 % modify prefs
 if ~isa(figno,'double')
   figno
   error('This is not a figure handle.')
 end
 if ~any(get(0,'children')==figno)
   figno
   error('This is not a figure handle.')
 end
 LAPRINTOPT.figno = figno;

 if nargin>1
   if ~isa(filename,'char')  
     filename
     error('This is not a file name.')
   end
   LAPRINTOPT.filename=filename;
 end    
end

% read and check command line options  

try  % try old usage (Version 2.03)
  if nargin <=2
     error('lets take new usage')
  end
  % 2.03 defaults
  width           = 12;
  factor          = 0.8;
  scalefonts      = 1;
  keepfontprops   = 0;
  asonscreen      = 0;
  keepticklabels  = 0;
  mathticklabels  = 0;
  head            = 1;
  comment         = '';
  caption         = '';
  extrapicture    = 1;
  nzeros          = 5;
  verbose         = 0;
  figcopy         = 1;
  printcmd        = ['print(''-f<figurenumber>'',' ...
                     '''-deps'',''<filename.eps>'')'];
  package         = 'epsfig';
  color           = 0;
  createview      = 0;
  viewfilename    = [filename '_'];
  processview     = 0;
  cmd1            = '';
  cmd2            = '';
  cmd3            = '';
  cmd4            = '';
  cmd5            = '';
  cmd6            = '';
  cmd7            = '';
  cmd8            = '';
  for i=1:nargin-2
   if ~isa(varargin{i},'char')
     error('Options must be character arrays.')
   end  
   oriopt=varargin{i}(:)';
   opt=[ lower(strrep(oriopt,' ','')) '                   ' ];
   if strcmp(opt(1:7),'verbose')
     verbose=1;
   elseif strcmp(opt(1:10),'asonscreen')
     asonscreen=1;
   elseif strcmp(opt(1:14),'keepticklabels')
     keepticklabels=1;
   elseif strcmp(opt(1:14),'mathticklabels')
     mathticklabels=1;
   elseif strcmp(opt(1:13),'keepfontprops')
     keepfontprops=1;
   elseif strcmp(opt(1:14),'noextrapicture')
     extrapicture=0;
   elseif strcmp(opt(1:14),'noextrapicture')
     extrapicture=0;
   elseif strcmp(opt(1:5),'loose')
     printcmd = ['print(''-f<figurenumber>'',' ...
                     '''-deps'',''-loose'',''<filename.eps>'')'];
   elseif strcmp(opt(1:9),'nofigcopy')
     figcopy=0;
   elseif strcmp(opt(1:12),'noscalefonts')
     scalefonts=0;
   elseif strcmp(opt(1:6),'nohead')
     head=0;
   elseif strcmp(opt(1:7),'caption')
     eqpos=findstr(oriopt,'=');
     if isempty(eqpos)
   caption='Matlab Figure';
     else
   caption=oriopt(eqpos+1:length(oriopt));
     end
   elseif strcmp(opt(1:8),'comment=')
     eqpos=findstr(oriopt,'=');
     comment=oriopt(eqpos(1)+1:length(oriopt));
   elseif strcmp(opt(1:9),'viewfile=')
     createview=1;
     eqpos=findstr(oriopt,'=');
     viewfilename=oriopt(eqpos(1)+1:length(oriopt));
   elseif strcmp(opt(1:6),'width=')
     eval([ opt ';' ]);
   elseif strcmp(opt(1:7),'factor=')
     eval([ opt ';' ]);
   else
     error([ 'Option ' varargin{i} ' not recognized.'])
   end   
 end

 warning('LaPrint:general',['You are using the old LaPrint '...
         'syntax. This syntax might not be supported in '...
         'future releases of LaPrint.'])

catch % old usage doesn't work, take new one
 
 % restore preferences / factory defaults
 width           = LAPRINTOPT.width;
 factor          = LAPRINTOPT.factor;
 scalefonts      = LAPRINTOPT.scalefonts;
 keepfontprops   = LAPRINTOPT.keepfontprops;
 asonscreen      = LAPRINTOPT.asonscreen;
 keepticklabels  = LAPRINTOPT.keepticklabels;
 mathticklabels  = LAPRINTOPT.mathticklabels;
 head            = LAPRINTOPT.head;
 comment         = LAPRINTOPT.comment;
 caption         = LAPRINTOPT.caption;
 extrapicture    = LAPRINTOPT.extrapicture;
 nzeros          = LAPRINTOPT.nzeros;
 verbose         = LAPRINTOPT.verbose;
 figcopy         = LAPRINTOPT.figcopy;
 printcmd        = LAPRINTOPT.printcmd;
 package         = LAPRINTOPT.package;
 color           = LAPRINTOPT.color;
 createview      = LAPRINTOPT.createview;
 viewfilename    = LAPRINTOPT.viewfilename;
 processview     = LAPRINTOPT.processview;
 cmd1            = LAPRINTOPT.cmd1;
 cmd2            = LAPRINTOPT.cmd2;
 cmd3            = LAPRINTOPT.cmd3;
 cmd4            = LAPRINTOPT.cmd4;
 cmd5            = LAPRINTOPT.cmd5;
 cmd6            = LAPRINTOPT.cmd6;
 cmd7            = LAPRINTOPT.cmd7;
 cmd8            = LAPRINTOPT.cmd8;

 if nargin > 2
   if rem(nargin,2)
     error('Option names/values must appear in pairs.')
   end    
   for i=1:2:nargin-2
     if ~isa(varargin{i},'char')
        error('Option name must be a character array.')
     end  
     opt = lower(strrep(varargin{i}(:)',' ',''));
     val = varargin{i+1}(:)';
     switch opt
       case 'options'      
         if isa(val,'char')
           if strcmp(val,'factory')
             val = factorysettings;
           else
             load(val)
             val = LAPRINTOPT;
           end
         end
         if ~isa(val,'struct')
           error('Value of options must be a structure array.')
         end  
         % no error checking here!
         width           = val.width;
         factor          = val.factor;
         scalefonts      = val.scalefonts;
         keepfontprops   = val.keepfontprops;
         asonscreen      = val.asonscreen;
         keepticklabels  = val.keepticklabels;
         mathticklabels  = val.mathticklabels;
         head            = val.head;
         comment         = val.comment;
         caption         = val.caption;
         extrapicture    = val.extrapicture;
         nzeros          = val.nzeros;
         verbose         = val.verbose;
         figcopy         = val.figcopy;
         printcmd        = val.printcmd;
         package         = val.package;
         color           = val.color;
         createview      = val.createview;
         viewfilename    = val.viewfilename;
         processview     = val.processview;
         cmd1            = val.cmd1;
         cmd2            = val.cmd2;
         cmd3            = val.cmd3;
         cmd4            = val.cmd4;
         cmd5            = val.cmd5;
         cmd6            = val.cmd6;
         cmd7            = val.cmd7;
         cmd8            = val.cmd8;
       case 'width'     
         if ~isa(val,'double')  
           error('Value of width must be a double.')
         end  
         width = val;  
       case 'factor'     
         if ~isa(val,'double')  
           error('Value of factor must be a double.')
         end  
         factor=val;  
       case 'scalefonts'
         scalefonts = value01(val,opt);
       case 'keepfontprops'
         keepfontprops = value01(val,opt);
       case 'asonscreen'     
         asonscreen = value01(val,opt);
       case 'keepticklabels'
         keepticklabels = value01(val,opt);
       case 'mathticklabels'
         mathticklabels = value01(val,opt) ;
       case 'head'
         head = value01(val,opt);
       case 'comment'
         if ~isa(val,'char')
           error('Value of comment must be a character array.')
         end
         comment = val;
       case 'caption'
         if ~isa(val,'char')
           error('Value of caption must be a character array.')
         end
         caption = val;
       case 'extrapicture'
         extrapicture = value01(val,opt);
       case 'nzeros'     
         if ~isa(val,'double')  
           error('Value of nzeros must be a double.')
         end  
         nzeros = val;
       case 'verbose'
         verbose = value01(val,opt);
       case 'figcopy'
         figcopy = value01(val,opt);
       case 'printcmd'
         if ~isa(val,'char')
           error('Value of printcmd must be a character array.')
         end
         printcmd = val;
       case 'package'
         if ~isa(val,'char')
           error('Value of package must be a character array.')
         end
         val = lower(strrep(val,' ',''));
         switch val
           case {'graphicx','epsfig'}
             % fine
           otherwise
             error('Value of package is unknown.')
         end  
         package = val;
       case 'color'
         color = value01(val,opt);
       case 'createview'
         createview = value01(val,opt);
       case 'viewfilename'
         if ~isa(val,'char')
           error('Value of viewfilename must be a character array.')
         end
         viewfilename = val;
       case 'processview'
         processview = value01(val,opt);
       case 'cmd1'
         if ~isa(val,'char')
           error('Value of cmd1 must be a character array.')
         end
         cmd1 = val;
       case 'cmd2'
         if ~isa(val,'char')
           error('Value of cmd2 must be a character array.')
         end
         cmd2 = val;
       case 'cmd3'
         if ~isa(val,'char')
           error('Value of cmd3 must be a character array.')
         end
         cmd3 = val;
       case 'cmd4'
         if ~isa(val,'char')
           error('Value of cmd4 must be a character array.')
         end
         cmd4 = val;
       case 'cmd5'
         if ~isa(val,'char')
           error('Value of cmd5 must be a character array.')
         end
         cmd5 = val;
       case 'cmd6'
         if ~isa(val,'char')
           error('Value of cmd6 must be a character array.')
         end
         cmd6 = val;
       case 'cmd7'
         if ~isa(val,'char')
           error('Value of cmd7 must be a character array.')
         end
         cmd7 = val;
       case 'cmd8'
         if ~isa(val,'char')
           error('Value of cmd8 must be a character array.')
         end
         cmd8 = val;
       otherwise
         error(['Option ''' opt ''' unknown'])
     end % switch opt
   end % for i=3:2:nargin
 end % if nargin > 2
end % try / catch    

if verbose,
 disp([ 'This is LaPrint, version ' laprintident '.' ]);
end  

comment   = strrep(strrep(comment,'\','\'),'%','%%');
caption   = strrep(strrep(caption,'\','\'),'%','%%');
iscaption = logical(length(caption));

if nzeros < 3
 warning('LaPrint:general',...
         'The value of nzero should be >=3. I will use nzeros=3.')
 nzeros=3;  
end

if processview
 createview=1;
end

if mathticklabels
 Do='$';
else  
 Do='';
end  

% eps- and tex- filenames
[epsfullnameext,epsbasenameext,epsbasename,epsdirname] = ...
                      getfilenames(filename,'eps',verbose);
[texfullnameext,texbasenameext,texbasename,texdirname] = ...
                      getfilenames(filename,'tex',verbose);
if ~strcmp(texdirname,epsdirname)
  warning('LaPrint:files',['The eps-file and tex-file are '...
         'placed in different directories.']);
end

if createview | processview
 [viewfullnameext,viewbasenameext,viewbasename,viewdirname] = ...
                      getfilenames(viewfilename,'tex',verbose);
 if strcmp(texfullnameext,viewfullnameext)
   viewfilename=[ viewfilename '_'];
   warning('LaPrint:files',['The tex- and view-file coincide. '...
          'I''ll use '' ' viewfilename ' ''. Hope that''s ok.' ])
 end  
 [viewfullnameext,viewbasenameext,viewbasename,viewdirname]= ...
                      getfilenames(viewfilename,'tex',verbose);
 if ~strcmp(texdirname,viewdirname)
   warning('LaPrint:files',['The eps-file and view-file are '...
  'placed in different directories.' ])
 end  
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%
%%%% PART 2 of advanced usage:
%%%% Create new figure, insert tags, and bookkeep original text
%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% show all
shh = get(0,'ShowHiddenHandles');
set(0,'ShowHiddenHandles','on');

% preparing check for copyobj bug
figno_ori = figno;
number_children_ori = length(get(figno_ori,'children'));

% open new figure (if required) and set properties
if figcopy
 figno = copyobj(figno,0);
 set(figno,'visible','off')
 set(figno,'Numbertitle','off')
 set(figno,'MenuBar','none')
 pause(0.5)
end  

if asonscreen  
 xlimmodeauto       = findobj(figno,'xlimmode','auto');
 xtickmodeauto      = findobj(figno,'xtickmode','auto');
 xticklabelmodeauto = findobj(figno,'xticklabelmode','auto');
 ylimmodeauto       = findobj(figno,'ylimmode','auto');
 ytickmodeauto      = findobj(figno,'ytickmode','auto');
 yticklabelmodeauto = findobj(figno,'yticklabelmode','auto');
 zlimmodeauto       = findobj(figno,'zlimmode','auto');
 ztickmodeauto      = findobj(figno,'ztickmode','auto');
 zticklabelmodeauto = findobj(figno,'zticklabelmode','auto');
 set(xlimmodeauto,'xlimmode','manual')
 set(xtickmodeauto,'xtickmode','manual')
 set(xticklabelmodeauto,'xticklabelmode','manual')
 set(ylimmodeauto,'ylimmode','manual')
 set(ytickmodeauto,'ytickmode','manual')
 set(yticklabelmodeauto,'yticklabelmode','manual')
 set(zlimmodeauto,'ylimmode','manual')
 set(ztickmodeauto,'ytickmode','manual')
 set(zticklabelmodeauto,'yticklabelmode','manual')
end  
set(figno,'paperunits','centimeters');
set(figno,'units','centimeters');
orip = get(figno,'Position');

% determine width and height
if factor <= 0
 factor = width/orip(3);
end
latexwidth = width;
epswidth   = latexwidth/factor;
epsheight  = epswidth*orip(4)/orip(3);

set(figno,'PaperPosition',[0 0 epswidth epsheight ])
set(figno,'papersize',[epswidth epsheight])
set(figno,'Position',[orip(1)+0.5 orip(2)-0.5 epswidth epsheight ])
set(figno,'Name',[ 'To be printed; size: ' num2str(factor,3) ...
 ' x (' num2str(epswidth,3) 'cm x ' num2str(epsheight,3) 'cm)' ])

% some warnings
if verbose
 if (epswidth<13) | (epsheight<13*0.75)
   warning('LaPrint:size',['The size of the eps-figure is quite '...
      'small. The text objects might not be properly set. '...
      'Reducing ''factor'' might help.'])
 end
 if latexwidth/epswidth<0.5
   warning('LaPrint:size',['The size of the eps-figure is large ' ...
          'compared to the latex figure. '...
          'The text size might be too small. '...
          'Increasing ''factor'' might help.'])
 end  
 if (orip(3)-epswidth)/orip(3) > 0.1
   warning('LaPrint:size',['The size of the eps-figure is much '...
           'smaller than the original '...
           'figure on screen. Matlab might save different ticks '...
           'and ticklabels than in the original figure. '...
           'See option ''asonscreen''.'])
 end
 disp('Strike any key to continue.');
 pause
end  

%
% TEXT OBJECTS: modify new figure
%

% find all text objects
hxl = get(findobj(figno,'type','axes'),'xlabel');
hyl = get(findobj(figno,'type','axes'),'ylabel');
hzl = get(findobj(figno,'type','axes'),'zlabel');
hti = get(findobj(figno,'type','axes'),'title');
hte = findobj(figno,'type','text');

% array of all text handles
htext = unique([ celltoarray(hxl) celltoarray(hyl) celltoarray(hzl) ...
     celltoarray(hti) celltoarray(hte)]);
nt = length(htext);

% set(celltoarray(hxl),'VerticalAlignment','top');
% get alignments
hora  = get(htext,'HorizontalAlignment');
vera  = get(htext,'VerticalAlignment');
align = cell(nt,1);
for i=1:nt
 align{i} = hora{i}(1);
 switch vera{i}
 case 'top'
   align{i} = [align{i} 't'];
 case 'cap'
%     if ~isempty(get(htext(i),'string'))
%       warning('LaPrint:text',['Using vertical ' ...
%             'alignment ''top'' instead of ''cap''.'])
%     end  
   align{i} = [align{i} 't'];
 case 'middle'
   align{i} = [align{i} 'c'];
 case 'baseline'
   align{i} = [align{i} 'B'];
 case 'bottom'
   align{i} = [align{i} 'b'];
 otherwise
   warning('LaPrint:text',['Vertical alignment ' vera{i} ...
           ' unknown. Using ''c''.'])
   align{i} = [align{i} 'c'];
 end
end  

% generate new strings and store old ones
oldstr   = get(htext,'string');
newstr   = cell(nt,1);
basestr  = ['s' char(48*ones(1,nzeros-1))];
extrastr = 0;
for i=1:nt
 osi = oldstr{i};
 oldstr{i} = ['\setlength{\tabcolsep}{0pt}\begin{tabular}{' ...
         align{i}(1) '}'];
 isnonempty_osi = 0;
 if strcmp(get(get(htext(i),'parent'),'tag'),'legend')
   newstr1 = [];  
   if isa(osi,'cell')
     % Legend/cell : Don't use tabular, employ extra strings
     nlines = length(osi);
     if nlines > 1
       newstr{nt+extrastr+nlines-1} = [];
       oldstr{nt+extrastr+nlines-1} = [];
       htext((nt+extrastr+1):(nt+extrastr+nlines-1))=htext(i);
       for line=1:nlines-1  
         oldstr{nt+extrastr+line} = ...
             strrep(strrep(osi{line},'\','\'),'%','%%');
         newstr{nt+extrastr+line} = ...
             overwritetail(basestr,nt+extrastr+line);
         newstr1 = [newstr1; overwritetail(basestr,nt+extrastr+line)];
       end    
       extrastr = extrastr+nlines-1;  
     end    
     if nlines > 0
       oldstr{i} = strrep(strrep(osi{nlines},'\','\'),'%','%%');
       newstr{i} = overwritetail(basestr,i);
       newstr1   = [newstr1; overwritetail(basestr,i)];
     end  
     % replace strings in figure
     set(htext(i),'string',cellstr(newstr1));
   else
     % Legend/matrix : Don't use tabular, employ extra strings
     nlines=size(osi,1);
     if nlines > 1
       newstr{nt+extrastr+nlines-1} = [];
       oldstr{nt+extrastr+nlines-1} = [];
       htext((nt+extrastr+1):(nt+extrastr+nlines-1))=htext(i);
       for line=1:nlines-1  
         oldstr{nt+extrastr+line} = ...
             strrep(strrep(osi(line,:),'\','\'),'%','%%');
         newstr{nt+extrastr+line} = ...
             overwritetail(basestr,nt+extrastr+line);
         newstr1 = [newstr1; overwritetail(basestr,nt+extrastr+line)];
       end    
       extrastr = extrastr+nlines-1;  
     end    
     if nlines > 0
       oldstr{i} = strrep(strrep(osi(nlines,:),'\','\'),'%','%%');
       newstr{i} = overwritetail(basestr,i);
       newstr1   = [newstr1; overwritetail(basestr,i)];
     end  
     % replace strings in figure
     set(htext(i),'string',newstr1);
   end
 else
   % text, not a legend  
   if isa(osi,'cell')
     nlines = length(osi);
     if nlines > 1
       for line=1:nlines-1  
         oldstr{i}=[oldstr{i} osi{line} '\'];
         isnonempty_osi = isnonempty_osi+length(osi{line});  
       end    
       if align{i}(2) == 'B'
         warning('LaPrint:text',['Vertical Alignment ''baseline'' '...
                 'in text with multiple rows might not match.'])
         align{i}(2) = 't';
       end  
     end    
     if nlines > 0
       oldstr{i} = [oldstr{i} osi{nlines} '\end{tabular}'];
       isnonempty_osi = isnonempty_osi+length(osi{nlines});
     end  
     oldstr{i} = strrep(strrep(oldstr{i},'\','\'),'%','%%');  
     if isnonempty_osi
       newstr{i} = overwritetail(basestr,i);
     else  
       newstr{i} = '';    
     end
     % replace strings in figure
     set(htext(i),'string',newstr{i});
   else
     nlines=size(osi,1);
     if nlines > 1
       for line=1:nlines-1  
         oldstr{i} = [oldstr{i} osi(line,:) '\'];
         isnonempty_osi = isnonempty_osi+length(osi(line,:));  
       end    
       if align{i}(2) == 'B'
         warning('LaPrint:text',['Vertical Alignment ''baseline'' '...
                 'in text with multiple rows might not match.'])
         align{i}(2) = 't';
       end  
     end
     if nlines > 0
       oldstr{i} = [oldstr{i} osi(nlines,:) '\end{tabular}'];
       isnonempty_osi = isnonempty_osi+length(osi(nlines,:));
     end  
     oldstr{i} = strrep(strrep(oldstr{i},'\','\'),'%','%%');  
  
     if isnonempty_osi
       newstr{i} = overwritetail(basestr,i);
     else  
       newstr{i} = '';    
     end
     % replace string in figure
     set(htext(i),'string',newstr{i});
   end % isa cell  
 end % isa legend  
end % for

ntp = nt+extrastr;

% Alignment of Legends
if extrastr > 0
 align{ntp} = [];
 [align{nt+1:ntp}] = deal('lc');
end

% get font properties and create commands
if ntp > 0
 [fontsizecmd{1:ntp}]   = deal('');
 [fontanglecmd{1:ntp}]  = deal('');
 [fontweightcmd{1:ntp}] = deal('');
 [colorcmd{1:ntp}]      = deal('');
 [colorclose{1:ntp}]    = deal('');
end
selectfontcmd = '';

if keepfontprops

 % fontsize
 set(htext,'fontunits','points');
 fontsize = get(htext,'fontsize');
 for i=1:ntp
   fontsizecmd{i} = [ '\fontsize{' num2str(fontsize{i}) '}{' ...
 num2str(fontsize{i}*1.5) '}'  ];
 end
   
 % fontweight
 fontweight = get(htext,'fontweight');
 for i=1:ntp
   switch fontweight{i}
   case 'light'
     fontweightcmd{i} = [ '\fontseries{l}\mathversion{normal}' ];
   case 'normal'
     fontweightcmd{i} = [ '\fontseries{m}\mathversion{normal}' ];
   case 'demi'
     fontweightcmd{i} = [ '\fontseries{sb}\mathversion{bold}' ];
   case 'bold'
     fontweightcmd{i} = [ '\fontseries{bx}\mathversion{bold}' ];
   otherwise
     warning('LaPrint:text',['Unknown fontweight: ' fontweight{i} ])
     fontweightcmd{i} = [ '\fontseries{m}\mathversion{normal}' ];
   end
 end  

 % fontangle
 fontangle = get(htext,'fontangle');
 for i=1:ntp
   switch fontangle{i}
   case 'normal'
     fontanglecmd{i} = [ '\fontshape{n}' ];
   case 'italic'
     fontanglecmd{i} = [ '\fontshape{it}' ];
   case 'oblique'
     fontanglecmd{i} = [ '\fontshape{it}' ];
   otherwise
     warning('LaPrint:text',['unknown fontangle: ' fontangle{i} ])
     fontanglecmd{i} = [ '\fontshape{n}' ];
   end
 end  
 selectfontcmd = '\selectfont ';
  
end

if color & ntp>0
 col   = get(htext,'color');
 bgcol = get(htext,'BackgroundColor');
 ecol  = get(htext,'EdgeColor');
 for i=1:ntp
   col0           = get(get(htext(i),'parent'),'color');
   [coli,isc]     = char2rgb(col{i},[0 0 0]);
   [bgcoli,isbgc] = char2rgb(bgcol{i},col0);
   [ecoli,isec]   = char2rgb(ecol{i},col0);
   if isbgc | isec
     set(htext(i),'BackgroundColor','none')
     set(htext(i),'EdgeColor','none')
     colorcmd{i} = ['\setlength{\fboxsep}{2pt}\fcolorbox[rgb]{' ...
       num2str(ecoli(1)) ',' num2str(ecoli(2)) ',' ...
       num2str(ecoli(3)) '}{' ...
       num2str(bgcoli(1)) ',' num2str(bgcoli(2)) ',' ...
       num2str(bgcoli(3)) '}{\color[rgb]{' ...
       num2str(coli(1)) ',' num2str(coli(2)) ',' num2str(coli(3)) '}' ];  
     colorclose{i} = '}';   
   else  
     colorcmd{i} = ['\color[rgb]{' ...
       num2str(coli(1)) ',' num2str(coli(2)) ',' num2str(coli(3)) '}' ];
   end  
 end  
end

%
% LABELS: modify new figure
%

if ~keepticklabels

 % all axes
 hax = celltoarray(findobj(figno,'type','axes'));
 na  = length(hax);

%   % try to figure out if we have 3D axes an warn
%   issuewarning = 0;
%   for i=1:na
%     issuewarning = max(issuewarning,is3d(hax(i)));
%   end
%   if issuewarning
%     warning('LaPrint:label',['This seems to be a 3D plot. '...
%             'The LaTeX labels are possibly incorrect. '...
%             'The option  ''keepticklabels'' might help. '...
%             'Setting ''figcopy'' to ''off'' might be wise, too.'])
%   end

 % try to figure out if we linear scale with extra factor
 % and determine powers of 10
 powers = NaN*zeros(na,3);  % matrix with powers of 10
 for i=1:na                    % all axes
   allxyz = { 'x', 'y', 'z' };
   for ixyz=1:3                % x,y,z
     xyz = allxyz{ixyz};
     ticklabelmode = get(hax(i),[ xyz 'ticklabelmode']);
     if strcmp(ticklabelmode,'auto')
       tick      = get(hax(i),[ xyz 'tick']);
       ticklabel = get(hax(i),[ xyz 'ticklabel']);      
   nticklabels    = size(ticklabel,1);
   nticks    = length(tick);
   if nticks==0,
         powers(i,ixyz)=0;
         nticklabels=0;
   end  
   if nticklabels==0,
         powers(i,ixyz)=0;
     end  
       for k=1:nticklabels    % all ticks
     label = str2num(ticklabel(k,:));
     if length(label)==0,
       powers(i,ixyz) = 0;
       break;
     end  
     if ( label==0 ) & ( abs(tick(k))>1e-10 )
       powers(i,ixyz) = 0;
       break;
         end      
     if label~=0    
           expon  = log10(tick(k)/label);
       rexpon = round(expon);
       if abs(rexpon-expon)>1e-10
             powers(i,ixyz) = 0;
         break;
           end
           if isnan(powers(i,ixyz))
         powers(i,ixyz) = rexpon;
       else
         if powers(i,ixyz)~=rexpon
           powers(i,ixyz) = 0;
           break;
             end
       end
         end      
   end % k    
     else % if 'auto'
       powers(i,ixyz) = 0;
     end % if 'auto'
   end % ixyz
 end % i
 
 % place text to be replaced by powers on y-axis
 for i=1:na             
   allxyz = { 'x', 'y', 'z' };
   ixyz=2;                % x,y,z
   xyz = allxyz{ixyz};
   leftright=get(hax(i),'yaxislocation');
   if powers(i,ixyz) & ~is3d(hax(i)) & isequal(leftright,'left')
       powertext = ['ypower' int2str(i)];
       xlimit    = get(hax(i),'xlim');
       ylimit    = get(hax(i),'ylim');
       htext     = text(xlimit(1),ylimit(2)+...
                 0.01*(ylimit(2)-ylimit(1)),...
                 powertext);
       set(htext,'VerticalAlignment','Baseline');
   end
 end % i

 % replace all ticklabels and bookkeep
 nxlabel = zeros(1,na);
 nylabel = zeros(1,na);
 nzlabel = zeros(1,na);
 allxyz={ 'x', 'y', 'z' };
 for ixyz=1:3
   xyz = allxyz{ixyz};
   k=1;
   if strcmp(xyz,'y')
     basestr = [ 'v' char(48*ones(1,nzeros-1))];
   else
     basestr = [ xyz char(48*ones(1,nzeros-1))];
   end  
   oldtl  = cell(na,1);
   newtl  = cell(na,1);
   nlabel = zeros(1,na);
   for i=1:na
     % set(hax(i),[ xyz 'tickmode' ],'manual')
     % set(hax(i),[ xyz 'ticklabelmode' ],'manual')
     oldtl{i}  = chartocell(get(hax(i),[ xyz 'ticklabel' ]));
     nlabel(i) = length(oldtl{i});
     newtl{i}  = cell(1,nlabel(i));
     for j=1:nlabel(i)
       newtl{i}{j} = overwritetail(basestr,k);
       k = k+1;
       oldtl{i}{j} = deblank(strrep(strrep(oldtl{i}{j},'\','\'),...
                            '%','%%'));
     end
     set(hax(i),[ xyz 'ticklabel' ],newtl{i});
   end  
   eval([ 'old' xyz 'tl=oldtl;' ]);
   eval([ 'new' xyz 'tl=newtl;' ]);
   eval([ 'n' xyz 'label=nlabel;' ]);
 end

 % determine latex commands for font properties
 
 if keepfontprops

   % ticklabel font size
   afsize = zeros(na,1);
   for i=1:na
     afsize(i) = get(hax(i),'fontsize');
   end          
   if (any(afsize ~= afsize(1) ))
     warning('LaPrint:text',['Different font sizes for axes not '...
             'supported. All axes will have font size ' ...
          num2str(afsize(1)) '.' ] )
   end      
   afsizecmd = [ '\fontsize{' num2str(afsize(1)) '}{' ...
 num2str(afsize(1)*1.5) '}'  ];

   % ticklabel font weight
   afweight = cell(na,1);
   for i=1:na
     afweight{i} = get(hax(i),'fontweight');
   end
   switch afweight{1}
   case 'light'
     afweightcmd = [ '\fontseries{l}\mathversion{normal}' ];
   case 'normal'
     afweightcmd = [ '\fontseries{m}\mathversion{normal}' ];
   case 'demi'
     afweightcmd = [ '\fontseries{sb}\mathversion{bold}' ];
   case 'bold'
     afweightcmd = [ '\fontseries{bx}\mathversion{bold}' ];
   otherwise
     warning('LaPrint:text',['unknown fontweight: ' afweight{1} ])
     afweightcmd = [ '\fontseries{m}\mathversion{normal}' ];
   end
   for i=1:na
     if ~strcmp(afweight{i},afweight{1})
       warning('LaPrint:text',['Different font weights for axes '...
               'are not supported. All axes will have font weight ' ...
               afweightcmd '.'])
     end      
   end      

   % ticklabel font angle
   afangle = cell(na,1);
   for i=1:na
     afangle{i} = get(hax(i),'fontangle');
   end
   switch afangle{1}
   case 'normal'
     afanglecmd = [ '\fontshape{n}' ];
   case 'italic'
     afanglecmd = [ '\fontshape{it}' ];
   case 'oblique'
     afanglecmd = [ '\fontshape{it}' ];
   otherwise
     warning('LaPrint:text',['unknown fontangle: ' afangle{1} ])
     afanglecmd=[ '\fontshape{n}' ];
   end
   for i=1:na
     if ~strcmp(afangle{i},afangle{1})
       warning('LaPrint:text',['Different font angles for axes not '...
               'supported. All axes will have font angle ' ...
               afanglecmd '.'] )
     end      
   end      
 
 end

 % ticklabel color
 acolcmd='';
 if color
   acol=[];
   allxyz={ 'x', 'y', 'z' };
   acolwarn = 0;
   for i=1:na
     for ixyz=1:3
       xyzcolor = [allxyz{ixyz} 'color'];
       if  ~isempty(get(hax(i),[allxyz{ixyz} 'ticklabel']))
         if isempty(acol)
           acol = char2rgb(get(hax(i),xyzcolor));  
         else
           if any(char2rgb(get(hax(i),xyzcolor))~=acol)
             acolwarn = 1;
           end
         end
       end   
     end
   end
   if acolwarn
     warning('LaPrint:label',['Different colors for axes not ' ...
           'supported. All ticklabels will have color [ ' ...
            num2str(acol) ' ].' ] )
   end
   if ~isempty(acol)
     if any(acol~=[0 0 0])
       acolcmd = [ '\color[rgb]{' num2str(acol(1)) ',' ...
             num2str(acol(2)) ',' num2str(acol(3)) '}' ];
     end
   end
 end

 % ticklabel alignment
   xyzalign = char([116*ones(na,1) 114*ones(na,1) 114*ones(na,1)]);
   for i=1:na
     switch get(hax(i),'XAxisLocation')
     case 'top'
       xyzalign(i,1)='B';
     end
     switch get(hax(i),'YAxisLocation')
     case 'right'
       xyzalign(i,2)='l';
     end
   end

end

%
% extra picture environment
%

if extrapicture
 unitlength = zeros(na,1);
 ybound     = zeros(na,1);
 for i=na:-1:1   % reverse order, to keep axes in original order
   if ~is3d(hax(i))
     xlim = get(hax(i),'xlim');
     ylim = get(hax(i),'ylim');
     axes(hax(i));
     hori = text(ylim(1),ylim(1),[ 'origin' int2str(i) ]);
     set(hori,'VerticalAlignment','bottom');
     set(hori,'Fontsize',2);
     set(hax(i),'Units','normalized')
     pos = get(hax(i),'Position');
     unitlength(i) = pos(3)*epswidth;
     ybound(i) = (pos(4)*epsheight)/(pos(3)*epswidth);
   else
     warning('LaPrint:extrapic',['Option ''extrapicture'' for 3D ' ...
                 'axes not supported.'])
   end
 end
end  

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%
%%%% PART 3 of advanced usage:
%%%% save eps and tex files
%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% prevent matlab print command to modify lims and ticks
% (empty, if asonscreen=1)
if ~keepticklabels
 xlimmodeauto       = findobj(figno,'xlimmode','auto');
 xtickmodeauto      = findobj(figno,'xtickmode','auto');
 xticklabelmodeauto = findobj(figno,'xticklabelmode','auto');
 ylimmodeauto       = findobj(figno,'ylimmode','auto');
 ytickmodeauto      = findobj(figno,'ytickmode','auto');
 yticklabelmodeauto = findobj(figno,'yticklabelmode','auto');
 zlimmodeauto       = findobj(figno,'zlimmode','auto');
 ztickmodeauto      = findobj(figno,'ztickmode','auto');
 zticklabelmodeauto = findobj(figno,'zticklabelmode','auto');
 set(xlimmodeauto,'xlimmode','manual')
 set(xtickmodeauto,'xtickmode','manual')
 set(xticklabelmodeauto,'xticklabelmode','manual')
 set(ylimmodeauto,'ylimmode','manual')
 set(ytickmodeauto,'ytickmode','manual')
 set(yticklabelmodeauto,'yticklabelmode','manual')
 set(zlimmodeauto,'ylimmode','manual')
 set(ztickmodeauto,'ytickmode','manual')
 set(zticklabelmodeauto,'yticklabelmode','manual')
end

% create eps file
cmd = strrep(printcmd,'<filename.eps>',epsfullnameext);
cmd = strrep(cmd,'<filename>',filename);
cmd = strrep(cmd,'<figurenumber>',int2str(figno));
 
if verbose
 disp([ 'executing: '' ' cmd ' ''' ]);
end
eval(cmd);

%
% create latex file
%
if verbose
 disp([ 'writing to: '' ' texfullnameext ' ''' ])
end
fid = fopen(texfullnameext,'w');

% head
if head
 fprintf(fid,[ '%% This file is generated by the MATLAB m-file' ...
      ' laprint.m. It can be included\n']);
 fprintf(fid,[ '%% into LaTeX documents using the packages ']);
 fprintf(fid,package);
 if color
     fprintf(fid,', color');
 end    
 fprintf(fid,[ ' and psfrag.\n' ]);
 fprintf(fid,  ['%% It is accompanied by a postscript file. ',...
    'A sample LaTeX file is:\n']);
 fprintf(fid, '%%    \documentclass{article}\usepackage{');
 fprintf(fid,package);
 if color
    fprintf(fid,',color');
 end    
 fprintf(fid, ',psfrag}\n');
 fprintf(fid,[ '%%    \begin{document}\input{' ...
texbasename '}\end{document}\n' ]);
   fprintf(fid, [ '%% See http://www.mathworks.de/matlabcentral'...
     '/fileexchange/loadFile.do?objectId=4638\n']);
   fprintf(fid, [ '%% for recent versions of laprint.m.\n' ]);
 fprintf(fid,  '%%\n');
 fprintf(fid,[ '%% created by:           ' 'LaPrint version ' ...
laprintident '\n' ]);
 fprintf(fid,[ '%% created on:           ' datestr(now) '\n' ]);
 fprintf(fid,[ '%% eps bounding box:     ' num2str(epswidth) ...
     ' cm x ' num2str(epsheight) ' cm\n' ]);
 fprintf(fid,[ '%% comment:              ' comment '\n' ]);
 fprintf(fid,'%%\n');
else
 fprintf(fid,[ '%% generated by laprint.m\n' ]);
 fprintf(fid,'%%\n');
end

% go on
fprintf(fid,'\begin{psfrags}%%\n');
%fprintf(fid,'\fontsize{10}{12}\selectfont%%\n');
fprintf(fid,'\psfragscanon%%\n');

% text strings

numbertext=0;
for i=1:nt
 numbertext = numbertext+length(newstr{i});
end
if numbertext>0,
 fprintf(fid,'%%\n');
 fprintf(fid,'%% text strings:\n');
 for i=1:ntp
   if length(newstr{i})
     alig = strrep(align{i},'c','');
     fprintf(fid,[ '\psfrag{' newstr{i} '}[' alig '][' alig ']{' ...
       fontsizecmd{i} fontweightcmd{i} fontanglecmd{i}  ...
       selectfontcmd colorcmd{i} oldstr{i} colorclose{i} '}%%\n' ]);
   end
 end
end

% labels

if ~keepticklabels
 if ~isempty(acolcmd)
    fprintf(fid,'%%\n');
    fprintf(fid,'%% axes ticklabel color:\n');
    fprintf(fid,[ acolcmd '%%\n' ]);
 end    
 if keepfontprops
   fprintf(fid,'%%\n');
   fprintf(fid,'%% axes font properties:\n');
   fprintf(fid,[ afsizecmd afweightcmd '%%\n' ]);
   fprintf(fid,[ afanglecmd '\selectfont%%\n' ]);
 end  
 nxlabel = zeros(1,na);
 nylabel = zeros(1,na);
 nzlabel = zeros(1,na);
 for i=1:na
   nxlabel(i) = length(newxtl{i});
   nylabel(i) = length(newytl{i});
   nzlabel(i) = length(newztl{i});
 end    
     
 allxyz = { 'x', 'y', 'z' };
 for ixyz=1:3
   xyz = allxyz{ixyz};
   eval([ 'oldtl=old' xyz 'tl;' ]);
   eval([ 'newtl=new' xyz 'tl;' ]);
   eval([ 'nlabel=n' xyz 'label;' ]);
   if sum(nlabel) > 0
     fprintf(fid,'%%\n');
     fprintf(fid,[ '%% ' xyz 'ticklabels:\n']);
     for i=1:na
       poss = ['[' xyzalign(i,ixyz) '][' xyzalign(i,ixyz) ']'];
       if nlabel(i)
         if strcmp(get(hax(i),[ xyz 'scale']),'linear')
       % lin scale
           rexpon = powers(i,ixyz);
           if ~rexpon
             % no powers
             for j=1:nlabel(i)
               fprintf(fid,[ '\psfrag{' newtl{i}{j} '}' poss '{' ...
                   Do oldtl{i}{j} Do '}%%\n' ]);
             end
           else
             % powers
             if ixyz==2
               leftright=get(hax(i),'yaxislocation');
               if ~is3d(hax(i)) & isequal(leftright,'left')
                 for j=1:nlabel(i)
                   fprintf(fid,[ '\psfrag{' newtl{i}{j} '}' poss '{' ...
                   Do oldtl{i}{j} Do '}%%\n' ]);
                 end
                 fprintf(fid,[ '\psfrag{ypower' int2str(i) ...
                    '}[Bl][Bl]{$\times 10^{' ...
            int2str(rexpon) '}$}%%\n' ]);
               else
                 for j=1:nlabel(i)-1
                   fprintf(fid,[ '\psfrag{' newtl{i}{j} '}' poss '{' ...
                     Do oldtl{i}{j} Do '}%%\n' ]);
                 end
                 if ~is3d(hax(i))
               fprintf(fid,[ '\psfrag{' newtl{i}{nlabel(i)} ...
                    '}' poss '{' ...
                    Do oldtl{i}{nlabel(i)} Do '$\times 10^{'...
            int2str(rexpon) '}$}%%\n' ]);
                 else
               fprintf(fid,[ '\psfrag{' newtl{i}{nlabel(i)} ...
                    '}' poss '{\shortstack{' ...
                    Do oldtl{i}{nlabel(i)} Do '\$\times 10^{'...
            int2str(rexpon) '}\ $}}%%\n' ]);

                 end
               end  
             elseif ixyz==1
               for j=1:nlabel(i)-1
                 fprintf(fid,[ '\psfrag{' newtl{i}{j} '}' poss '{' ...
                   Do oldtl{i}{j} Do '}%%\n' ]);
               end
               leftright=get(hax(i),'xaxislocation');
               if isequal(leftright,'bottom')
             fprintf(fid,[ '\psfrag{' newtl{i}{nlabel(i)} ...
                    '}' poss '{\shortstack{' ...
                    Do oldtl{i}{nlabel(i)} Do '\$\times 10^{'...
            int2str(rexpon) '}\ $}}%%\n' ]);
           else
                 fprintf(fid,[ '\


评论 / 个人网页 / 扔小纸条
*昵称

已经注册过? 请登录

Email
网址
*评论
 


 
复杂系统建模中心实验室 (MCS Centre Lab of WUSE)
日历
网志分类
『所有网志』
Papers
MatLAB Files
Public Information
Secret Information
Related links
Email bak
笑话 Jokes
站内搜索
友情链接
我的歪酷
中国语言文字网
Jerry's MatLAB Space
software on dynamical systems theory
authors.elsevier.com
arxiv
物理学报
时光麦场
成都向日葵(Music)
紫丁香BBS
瀚海星云BBS
complex networks
Professor Chin-Kun Hu
He Daihai
Ying-Cheng Lai
动力学与控制技术论坛
SIMWE论坛
CTEX 论坛
博士家园论坛
研学论坛
科研中国SciEi.com
神经网络在线
订阅 RSS
0010838
歪酷博客