Debian Codegraph @

texmf-dist/doc/latex/psfragx/laprint.m

raw
1 function laprint(figno,filename,varargin)
2 %LAPRINT prints a figure for inclusion in LaTeX documents.
3 % LaPrint creates an eps-file and a tex-file. The tex-file contains
4 % the annotation of the figure such as titles, labels and texts. The
5 % eps-file contains the non-text part of the figure as well as the
6 % position of the text-objects. The packages 'graphicx' (or 'epsfig')
7 % and 'psfrag' (and possibly ''color'') are required for the LaTeX
8 % run. A postscript driver like 'dvips' is required for printing.
9 %
10 % Usage: >> laprint
11 %
12 % This opens a graphical user interface window, to control the
13 % various settings. It includes a help facility. Just try it.
14 %
15 % As an alternative to the GUI you can call laprint from the command
16 % line with various extra input arguments. These arguments are
17 % explained in the help window of the GUI, which can be also be
18 % opened using the command
19 % >> laprint helpwindow
20 %
21 % There is an Users Guide available at
22 % http://www.uni-kassel.de/fb16/rat/matlab/laprint/laprintdoc.ps
23
24 % (c) Arno Linnemann. All rights reserved.
25 % The author of this program assumes no responsibility for any errors
26 % or omissions. In no event shall he be liable for damages arising out of
27 % any use of the software. Redistribution of the unchanged file is allowed.
28 % Distribution of changed versions is allowed provided the file is renamed
29 % and the source and authorship of the original version is acknowledged in
30 % the modified file.
31
32 % Please report bugs, suggestions and comments to:
33 % Arno Linnemann
34 % Control and Automation
35 % Department of Electrical and Computer Engineering
36 % University of Kassel
37 % 34109 Kassel
38 % Germany
39 % mailto:[email protected]
40
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 %%%%
43 %%%% Initialize
44 %%%%
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46
47 laprintident = '3.16 (13.9.2004)';
48 vers = version;
49 vers = eval(vers(1:3));
50 if vers < 6.1
51 error('Sorry. Matlab 6.1 or above is required.')
52 end
53
54 hf=131;
55 hhf=132;
56
57 % no output
58 if nargout
59 error('No output argument, please.')
60 end
61
62 inter=get(0,'defaulttextinterpreter');
63 if ~strcmp(inter,'none')
64 warning('LaPrint:general',['It is recommended to switch off the '...
65 'text interpreter\nbefore creating a figure to be saved '...
66 'with LaPrint. Use the command\n',...
67 ' >> set(0,''defaulttextinterpreter'',''none'').'])
68 end
69
70 if nargin==0
71
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 %%%%
74 %%%% GUI
75 %%%%
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77
78 try
79 delete(hf)
80 end
81 try
82 delete(hhf)
83 end
84
85 %---------------------------------
86 % open window
87 %---------------------------------
88
89 hf = figure(hf);
90 clf reset;
91 set(hf,'NumberTitle','off',...
92 'Name','LaPrint (LaTeX Print)',...
93 'Units','points',...
94 'CloseRequestFcn','laprint(''quit'');',...
95 'menubar','none')
96 h = uicontrol('Parent',hf,'Units','points');
97 fsize = get(h,'Fontsize');
98 delete(h)
99 posf = get(hf,'Position');
100 figheight = 10*fsize;
101 figwidth = 32*fsize;
102 posf = [ posf(1) posf(2)+posf(4)-figheight figwidth figheight];
103 set(hf,'Position',posf)
104 uicontrol('Parent',hf,'style','frame','Units','points',...
105 'Position',[0 0 figwidth figheight])
106 curh = figheight-0*fsize;
107
108 LAPRINTHAN=struct('figno',{0},'filename',{0},...
109 'keepfontprops',{0},'asonscreen',{0},'keepticklabels',{0},...
110 'mathticklabels',{0},'head',{0},'extrapicture',{0},...
111 'verbose',{0},'figcopy',{0},'package_epsfig',{0},...
112 'package_graphicx',{0},'color',{0},'createview',{0},...
113 'processview',{0});
114
115 %---------------------------------
116 % figure no.
117 %---------------------------------
118
119 loch = 1.7*fsize;
120 curh = curh-loch-1.5*fsize;
121 h = uicontrol('Parent',hf,...
122 'style','text',...
123 'Units','points',...
124 'Position',[1*fsize curh 18*fsize loch],...
125 'HorizontalAlignment','left',...
126 'string','Number of Figure to be saved:');
127 h = uicontrol('Parent',hf,...
128 'style','edit',...
129 'Units','points',...
130 'Position',[19*fsize curh 12*fsize loch],...
131 'HorizontalAlignment','left',...
132 'BackgroundColor',[1 1 1],...
133 'Callback','laprint(''figno'');');
134 LAPRINTHAN.figno = h;
135
136 %---------------------------------
137 % filename
138 %---------------------------------
139
140 loch = 1.7*fsize;
141 curh = curh-loch-1*fsize;
142 h = uicontrol('Parent',hf,...
143 'style','text',...
144 'Units','points',...
145 'Position',[1*fsize curh 18*fsize loch],...
146 'HorizontalAlignment','left',...
147 'string','Basename of Files to be Created:');
148 h = uicontrol('Parent',hf,...
149 'style','edit',...
150 'Units','points',...
151 'Position',[19*fsize curh 12*fsize loch],...
152 'HorizontalAlignment','left',...
153 'BackgroundColor',[1 1 1],...
154 'Callback','laprint(''filename'');');
155 LAPRINTHAN.filename = h;
156
157 %---------------------------------
158 % save, quit
159 %---------------------------------
160
161 loch = 2*fsize;
162 curh = curh-loch-1*fsize;
163 h = uicontrol('Parent',hf,...
164 'Style','pushbutton',...
165 'Units','Points',...
166 'Position',[19*fsize curh 5*fsize loch],...
167 'HorizontalAlignment','center',...
168 'String','Go !',...
169 'Callback','laprint(''save'');');
170 h = uicontrol('Parent',hf,...
171 'Style','pushbutton',...
172 'Units','Points',...
173 'Position',[26*fsize curh 5*fsize loch],...
174 'HorizontalAlignment','center',...
175 'String','Quit',...
176 'Callback','laprint(''quit'');');
177
178 %---------------------------------
179 % options uimenue
180 %---------------------------------
181
182 hm1 = uimenu('label','Options');
183
184 uimenu(hm1,...
185 'label','Sizes and Scalings ...',...
186 'callback','laprint(''size'')');
187
188 LAPRINTHAN.keepfontprops = uimenu(hm1,...
189 'label','Translate Matlab Font Properties to LaTeX',...
190 'callback','laprint(''keepfontprops'')');
191
192 LAPRINTHAN.asonscreen = uimenu(hm1,...
193 'label','Print Limits and Ticks as on Screen',...
194 'separator','on',...
195 'callback','laprint(''asonscreen'')');
196
197 LAPRINTHAN.keepticklabels = uimenu(hm1,...
198 'label','Keep Tick Labels within eps File',...
199 'callback','laprint(''keepticklabels'')');
200
201 LAPRINTHAN.mathticklabels = uimenu(hm1,...
202 'label','Set Tick Labels in LaTeX Math Mode',...
203 'callback','laprint(''mathticklabels'')');
204
205 LAPRINTHAN.head = uimenu(hm1,...
206 'label','Equip the tex File with a Head',...
207 'separator','on',...
208 'callback','laprint(''head'')');
209
210 uimenu(hm1,...
211 'label','Comment in the Head of the tex File ...',...
212 'callback','laprint(''comment'')');
213
214 uimenu(hm1,...
215 'label','Place a LaTeX Caption in the tex File ...',...
216 'callback','laprint(''caption'')');
217
218 LAPRINTHAN.extrapicture = uimenu(hm1,...
219 'label','Place an Extra Picture in each Axes',...
220 'callback','laprint(''extrapicture'')');
221
222 uimenu(hm1,...
223 'label','Length of psfrag Replacement Strings ...',...
224 'callback','laprint(''nzeros'')');
225
226 LAPRINTHAN.verbose = uimenu(hm1,...
227 'label','Call LaPrint in Verbose Mode',...
228 'separator','on',...
229 'callback','laprint(''verbose'')');
230
231 LAPRINTHAN.figcopy = uimenu(hm1,...
232 'label','Copy Figure and Modify that Copy',...
233 'callback','laprint(''figcopy'')');
234
235 uimenu(hm1,...
236 'label','Matlab Print Command ...',...
237 'separator','on',...
238 'callback','laprint(''printcmd'')');
239
240 h=uimenu(hm1,...
241 'separator','on',...
242 'label','LaTeX Graphics Package');
243
244 LAPRINTHAN.package_graphicx = uimenu(h,...
245 'label','graphicx',...
246 'callback','laprint(''package_graphicx'')');
247
248 LAPRINTHAN.package_epsfig = uimenu(h,...
249 'label','epsfig',...
250 'callback','laprint(''package_epsfig'')');
251
252 LAPRINTHAN.color = uimenu(hm1,...
253 'label','Use LaTeX ''color'' Package',...
254 'callback','laprint(''color'')');
255
256 h = uimenu(hm1,...
257 'label','View File ...',...
258 'separator','on');
259
260 LAPRINTHAN.createview = uimenu(h,...
261 'label','Create a View File',...
262 'callback','laprint(''createview'')');
263
264 uimenu(h,...
265 'label','Name of the View File ...',...
266 'callback','laprint(''viewfilename'')');
267
268 LAPRINTHAN.processview = uimenu(h,...
269 'label','Process the View File',...
270 'separator','on',...
271 'callback','laprint(''processview'')');
272
273 uimenu(h,...
274 'label','Executables for Processing View File...',...
275 'callback','laprint(''cmdsview'')');
276
277 %---------------------------------
278 % Preferences uimenue
279 %---------------------------------
280
281 hm3=uimenu('label','Preferences');
282
283 uimenu(hm3,...
284 'label','Get Preferences',...
285 'callback','laprint(''getpref'')')
286
287 uimenu(hm3,...
288 'label','Set Preferences to Current Settings',...
289 'callback','laprint(''setpref'')')
290
291 uimenu(hm3,...
292 'label','Remove Preferences',...
293 'callback','laprint(''rmpref'')')
294
295 uimenu(hm3,...
296 'label','Save Current Settings to a File ...',...
297 'separator','on',...
298 'callback','laprint(''savepref'')')
299
300 uimenu(hm3,...
301 'label','Load Settings from a File ...',...
302 'callback','laprint(''loadpref'')')
303
304 uimenu(hm3,...
305 'label','Get Factory Defaults',...
306 'separator','on',...
307 'callback','laprint(''factory'')')
308
309
310 %---------------------------------
311 % Help uimenue
312 %---------------------------------
313
314 hm2=uimenu('label','Help');
315
316 uimenu(hm2,...
317 'label',['LaPrint Online Help ...'],...
318 'callback','laprint(''helpwindow'')');
319
320 uimenu(hm2,...
321 'label','Get the LaPrint Users Guide',...
322 'callback',['web www.uni-kassel.de/fb16/rat/matlab',...
323 '/laprint/laprintdoc.ps -browser'])
324
325 uimenu(hm2,...
326 'label',['Look for a newer version of LaPrint ' ...
327 '(Matlab Central File Exchange)...'],...
328 'callback',['web http://www.mathworks.de/matlabcentral/',...
329 'fileexchange/loadFile.do?objectId=4638',...
330 '&objectType=file -browser'])
331
332 uimenu(hm2,...
333 'label','Version and Author ...',...
334 'callback','laprint(''whois'')')
335
336 %---------------------------------
337 % make hf invisible
338 %---------------------------------
339
340 set(hf,'HandleVisibility','callback')
341
342 %---------------------------------
343 % get settings
344 %---------------------------------
345
346 LAPRINTOPT = prefsettings;
347 if isempty(LAPRINTOPT)
348 LAPRINTOPT = factorysettings;
349 end
350
351 %---------------------------------
352 % get figure
353 %---------------------------------
354
355 gcfig=gcf;
356 if gcfig == hf
357 allfigs = findobj('type','figure');
358 allfigs = allfigs(find(allfigs~=hf));
359 if length(allfigs)
360 figno = allfigs(1);
361 else
362 figure(1)
363 figno=1;
364 end
365 else
366 figno=gcfig;
367 end
368 LAPRINTOPT.figno = figno;
369
370 %---------------------------------
371 % update
372 %---------------------------------
373
374 updategui(LAPRINTHAN,LAPRINTOPT)
375 sethf(hf,LAPRINTHAN,LAPRINTOPT)
376 figure(hf)
377
378 %---------------------------------
379 % done
380 %---------------------------------
381
382 return
383
384 end % if nargin==0
385
386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
387 %%%%
388 %%%% callback calls ('factory' and 'getprefs' also
389 %%%% used from command line)
390 %%%%
391 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
392
393 if isa(figno,'char')
394
395 switch figno
396 case 'figno'
397 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
398 LAPRINTOPT.figno=eval(get(LAPRINTHAN.figno,'string'));
399 figure(LAPRINTOPT.figno)
400 figure(hf)
401 sethf(hf,LAPRINTHAN,LAPRINTOPT);
402 case 'filename'
403 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
404 LAPRINTOPT.filename=get(LAPRINTHAN.filename,'string');
405 [texfullnameext,texbasenameext,texbasename,texdirname] = ...
406 getfilenames(LAPRINTOPT.filename,'tex',0);
407 [epsfullnameext,epsbasenameext,epsbasename,epsdirname] = ...
408 getfilenames(LAPRINTOPT.filename,'eps',0);
409 sethf(hf,LAPRINTHAN,LAPRINTOPT);
410 case 'save'
411 % lapcmd = [ 'laprint(' int2str(LAPRINTOPT.figno) ...
412 % ', ''' LAPRINTOPT.filename ''''...
413 % ', ''options'', LAPRINTOPT)'];
414 lapcmd = 'laprint({})';
415 eval(lapcmd)
416 case 'quit'
417 delete(hf)
418 try
419 delete(hhf)
420 end
421 case 'size'
422 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
423 answer = inputdlg({['Please enter the width (in centimeters) ',...
424 'of the graphics in the LaTeX document (The height ',...
425 'will be computed such that the aspect ratio of the ',...
426 'figure on screen is retained.) :'],...
427 ['Please enter the factor by which the size of the '...
428 'graphics in the LaTeX document differs from the size of the '...
429 'Postscipt graphics ( Explaination: A factor <1 scales ',...
430 'the picture down. This means that lines become thinner ',...
431 'and fonts become smaller. ) :'],...
432 ['Please specify if you want to scale the fonts along with ',...
433 'the graphics (enter ''on'' or ''off'') : '] },...
434 'LaPrint Settings',1,{num2str(LAPRINTOPT.width),...
435 num2str(LAPRINTOPT.factor),...
436 valueyn(LAPRINTOPT.scalefonts)},'on');
437 if length(answer)
438 LAPRINTOPT.width=eval(answer{1});
439 LAPRINTOPT.factor = eval(answer{2});
440 LAPRINTOPT.scalefonts = value01(answer{3});
441 end
442 sethf(hf,LAPRINTHAN,LAPRINTOPT);
443 case 'keepfontprops'
444 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
445 if LAPRINTOPT.keepfontprops==1
446 LAPRINTOPT.keepfontprops=0;
447 set(LAPRINTHAN.keepfontprops,'check','off')
448 else
449 LAPRINTOPT.keepfontprops=1;
450 set(LAPRINTHAN.keepfontprops,'check','on')
451 end
452 sethf(hf,LAPRINTHAN,LAPRINTOPT);
453 case 'asonscreen'
454 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
455 if LAPRINTOPT.asonscreen==1
456 LAPRINTOPT.asonscreen=0;
457 set(LAPRINTHAN.asonscreen,'check','off')
458 else
459 LAPRINTOPT.asonscreen=1;
460 set(LAPRINTHAN.asonscreen,'check','on')
461 end
462 sethf(hf,LAPRINTHAN,LAPRINTOPT);
463 case 'keepticklabels'
464 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
465 if LAPRINTOPT.keepticklabels==1
466 LAPRINTOPT.keepticklabels=0;
467 set(LAPRINTHAN.keepticklabels,'check','off')
468 else
469 LAPRINTOPT.keepticklabels=1;
470 set(LAPRINTHAN.keepticklabels,'check','on')
471 end
472 sethf(hf,LAPRINTHAN,LAPRINTOPT);
473 case 'mathticklabels'
474 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
475 if LAPRINTOPT.mathticklabels==1
476 LAPRINTOPT.mathticklabels=0;
477 set(LAPRINTHAN.mathticklabels,'check','off')
478 else
479 LAPRINTOPT.mathticklabels=1;
480 set(LAPRINTHAN.mathticklabels,'check','on')
481 end
482 sethf(hf,LAPRINTHAN,LAPRINTOPT);
483 case 'head'
484 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
485 if LAPRINTOPT.head==1
486 LAPRINTOPT.head=0;
487 set(LAPRINTHAN.head,'check','off')
488 else
489 LAPRINTOPT.head=1;
490 set(LAPRINTHAN.head,'check','on')
491 end
492 sethf(hf,LAPRINTHAN,LAPRINTOPT);
493 case 'comment'
494 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
495 answer = inputdlg({['Please enter a describing comment to '...
496 'be placed into the head of the tex file:']},...
497 'LaPrint Settings',1,{LAPRINTOPT.comment},'on');
498 if length(answer)
499 LAPRINTOPT.comment = answer{1};
500 end
501 sethf(hf,LAPRINTHAN,LAPRINTOPT);
502 case 'caption'
503 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
504 answer = inputdlg(['If the following text is nonempty, ' ...
505 'then it will be placed as a \caption{} into the tex '...
506 'file along with \label{fig:' LAPRINTOPT.filename '}. '...
507 'Please enter the caption text:'],...
508 'LaPrint Settings',1,{LAPRINTOPT.caption},'on');
509 if length(answer)
510 LAPRINTOPT.caption = answer{1};
511 end
512 sethf(hf,LAPRINTHAN,LAPRINTOPT);
513 case 'extrapicture'
514 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
515 if LAPRINTOPT.extrapicture==1
516 LAPRINTOPT.extrapicture=0;
517 set(LAPRINTHAN.extrapicture,'check','off')
518 else
519 LAPRINTOPT.extrapicture=1;
520 set(LAPRINTHAN.extrapicture,'check','on')
521 end
522 sethf(hf,LAPRINTHAN,LAPRINTOPT);
523 case 'nzeros'
524 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
525 answer = inputdlg({['Please enter length of the psfrag replacement '...
526 'strings (must be >= 3) :']},...
527 'LaPrint Settings',1,{num2str(LAPRINTOPT.nzeros)},'on');
528 if length(answer)
529 LAPRINTOPT.nzeros = max(eval(answer{1}),3);
530 end
531 sethf(hf,LAPRINTHAN,LAPRINTOPT);
532 case 'verbose'
533 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
534 if LAPRINTOPT.verbose==1
535 LAPRINTOPT.verbose=0;
536 set(LAPRINTHAN.verbose,'check','off')
537 else
538 LAPRINTOPT.verbose=1;
539 set(LAPRINTHAN.verbose,'check','on')
540 end
541 sethf(hf,LAPRINTHAN,LAPRINTOPT);
542 case 'figcopy'
543 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
544 if LAPRINTOPT.figcopy==1
545 LAPRINTOPT.figcopy=0;
546 set(LAPRINTHAN.figcopy,'check','off')
547 else
548 LAPRINTOPT.figcopy=1;
549 set(LAPRINTHAN.figcopy,'check','on')
550 end
551 sethf(hf,LAPRINTHAN,LAPRINTOPT);
552 case 'printcmd'
553 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
554 answer = inputdlg({['Please enter the Matlab command '...
555 'to be used for printing the eps file '...
556 '(LaPrint will internally replace <figurenumber> by the '...
557 'number of the figure <filename.eps> by the ' ...
558 'eps-filename and <filename> '...
559 'by the basename of the file, respectively). You can add options '...
560 'here (like ''-loose'') or use a different program '...
561 'for printing (like ''exportfig'') :']},...
562 'LaPrint Settings',1,{LAPRINTOPT.printcmd},'on');
563 if length(answer)
564 LAPRINTOPT.printcmd = answer{1};
565 end
566 sethf(hf,LAPRINTHAN,LAPRINTOPT);
567 case 'package_epsfig'
568 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
569 LAPRINTOPT.package='epsfig';
570 set(LAPRINTHAN.package_epsfig,'check','on')
571 set(LAPRINTHAN.package_graphicx,'check','off')
572 sethf(hf,LAPRINTHAN,LAPRINTOPT);
573 case 'package_graphicx'
574 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
575 LAPRINTOPT.package='graphicx';
576 set(LAPRINTHAN.package_epsfig,'check','off')
577 set(LAPRINTHAN.package_graphicx,'check','on')
578 sethf(hf,LAPRINTHAN,LAPRINTOPT);
579 case 'color'
580 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
581 if LAPRINTOPT.color==1
582 LAPRINTOPT.color=0;
583 set(LAPRINTHAN.color,'check','off')
584 else
585 LAPRINTOPT.color=1;
586 set(LAPRINTHAN.color,'check','on')
587 end
588 sethf(hf,LAPRINTHAN,LAPRINTOPT);
589 case 'createview'
590 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
591 if LAPRINTOPT.createview==1
592 LAPRINTOPT.createview=0;
593 LAPRINTOPT.processview=0;
594 set(LAPRINTHAN.createview,'check','off')
595 set(LAPRINTHAN.processview,'check','off')
596 else
597 LAPRINTOPT.createview=1;
598 set(LAPRINTHAN.createview,'check','on')
599 end
600 sethf(hf,LAPRINTHAN,LAPRINTOPT);
601 case 'viewfilename'
602 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
603 trydlg=1;
604 txt=['Please enter the name of the '...
605 'viewfile (without extension .tex) : '];
606 txt2='';
607 while trydlg
608 answer = inputdlg({[txt txt2]},...
609 'LaPrint Settings',1,{LAPRINTOPT.viewfilename},'on');
610 if length(answer)
611 if strcmp(answer{1},LAPRINTOPT.filename)
612 txt2=['The name must be different from the name of the '...
613 'graphics file):'];
614 else
615 trydlg=0;
616 LAPRINTOPT.viewfilename = answer{1};
617 [viewfullnameext,viewbasenameext,viewbasename,viewdirname] = ...
618 getfilenames(LAPRINTOPT.viewfilename,'tex',0);
619 end
620 else
621 trydlg=0;
622 end
623 end
624 sethf(hf,LAPRINTHAN,LAPRINTOPT);
625 case 'processview'
626 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
627 if LAPRINTOPT.processview==1
628 LAPRINTOPT.processview=0;
629 set(LAPRINTHAN.processview,'check','off')
630 else
631 LAPRINTOPT.processview=1;
632 set(LAPRINTHAN.processview,'check','on')
633 LAPRINTOPT.createview=1;
634 set(LAPRINTHAN.createview,'check','on')
635 end
636 sethf(hf,LAPRINTHAN,LAPRINTOPT);
637 case 'cmdsview'
638 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
639 answer = inputdlg({...
640 ['Please enter up to 8 commands to process the view-file. ',...
641 'Leave any of the fields empty, if you have ',...
642 'less than 8 commands. ',...
643 'In any of the following commands, LaPrint internally '...
644 'replaces the tag <viewfile> by the name of the viewfile ',...
645 'and the tag <filename> by the basename specified in the ',...
646 'main LaPrint Window. ',...
647 'At minimum you should enter the commands for the LaTeX ',...
648 'compilation and for the dvi-to-postscript conversion ',...
649 'here. See the LaPrint Online-Help for futher ',...
650 'suggestions. ',...
651 'Please enter the 1st command:'],...
652 'Please enter the 2nd command:',...
653 'Please enter the 3rd command:',...
654 'Please enter the 4th command:',...
655 'Please enter the 5th command:',...
656 'Please enter the 6th command:',...
657 'Please enter the 7th command:',...
658 'Please enter the 8th command:'},...
659 'LaPrint Settings',1,{LAPRINTOPT.cmd1,...
660 LAPRINTOPT.cmd2,LAPRINTOPT.cmd3,...
661 LAPRINTOPT.cmd4,LAPRINTOPT.cmd5,LAPRINTOPT.cmd6,...
662 LAPRINTOPT.cmd7,LAPRINTOPT.cmd8},'on');
663 if length(answer)==8
664 LAPRINTOPT.cmd1=answer{1};
665 LAPRINTOPT.cmd2=answer{2};
666 LAPRINTOPT.cmd3=answer{3};
667 LAPRINTOPT.cmd4=answer{4};
668 LAPRINTOPT.cmd5=answer{5};
669 LAPRINTOPT.cmd6=answer{6};
670 LAPRINTOPT.cmd7=answer{7};
671 LAPRINTOPT.cmd8=answer{8};
672 end
673 sethf(hf,LAPRINTHAN,LAPRINTOPT);
674 case 'getpref'
675 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
676 out = prefsettings;
677 if ~isempty(out)
678 oldfigno = LAPRINTOPT.figno; % keep this!
679 LAPRINTOPT = out;
680 LAPRINTOPT.figno = oldfigno;
681 else
682 errordlg('No LaPrint preferences available.')
683 end
684 updategui(LAPRINTHAN,LAPRINTOPT);
685 sethf(hf,LAPRINTHAN,LAPRINTOPT);
686 case 'setpref'
687 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
688 setpref('LaPrint','LAPRINTOPT',LAPRINTOPT);
689 case 'rmpref'
690 if ispref('LaPrint')
691 rmpref('LaPrint');
692 else
693 errordlg('Preference does not exist.')
694 end
695 case 'savepref'
696 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
697 txt = 'Save preferences file ';
698 [preffile,prefpath]=uiputfile('laprint.mat',txt);
699 save([prefpath preffile],'LAPRINTOPT');
700 case 'loadpref'
701 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
702 txt = ['Load preferences file '...
703 '(must be previously created by LaPrint)'];
704 [preffile,prefpath]=uigetfile('laprint.mat',txt);
705 if ~isequal(preffile,0) & ~isequal(prefpath,0)
706 oldfigno = LAPRINTOPT.figno; % keep this!
707 load([prefpath preffile]); % hope file contains correct
708 LAPRINTOPT.figno = oldfigno; % LAPRINTOPT
709 updategui(LAPRINTHAN,LAPRINTOPT);
710 sethf(hf,LAPRINTHAN,LAPRINTOPT);
711 end
712 case 'factory'
713 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
714 out = factorysettings;
715 if ~isempty(out)
716 oldfigno = LAPRINTOPT.figno; % keep this!
717 LAPRINTOPT = out;
718 LAPRINTOPT.figno = oldfigno;
719 else
720 errordlg('No LaPrint preferences available.')
721 end
722 updategui(LAPRINTHAN,LAPRINTOPT);
723 sethf(hf,LAPRINTHAN,LAPRINTOPT);
724 case 'helpwindow'
725 hhf=figure(hhf);
726 set(hhf,'Name','LaPrint Online Help',...
727 'Numbertitle','off',...
728 'menubar','none',...
729 'HandleVisibility','callback',...
730 'resize','on',...
731 'ResizeFcn','laprint(''helpwindow'');');
732 hht=uicontrol('Parent',hhf,...
733 'style','listbox',...
734 'units','normalized',...
735 'position',[0.005 0.005 0.9 0.99],...
736 'BackgroundColor','w',...
737 'Fontsize',12,...
738 'foregroundcolor','k',...
739 'FontName','FixedWidth',...
740 'HorizontalAlignment','left');
741 [txt,hhtpos]=textwrap(hht,helptext);
742 set(hht,'string',txt)
743 set(hht,'position',[0.005 0.005 0.99 0.99])
744 set(hht,'HandleVisibility','callback')
745 case 'whois'
746 msgbox({['This is LaPrint, Version ' laprintident],...
747 '',...
748 'To blame for LaPrint:',...
749 'Arno Linnemann','Control and Automation',...
750 'Department of Electrical and Computer Engineering',...
751 'University of Kassel',...
752 '34109 Kassel',...
753 'Germany',...
754 'mailto:[email protected]'},...
755 'LaPrint Info')
756 otherwise
757 error('unknown callback option')
758 end
759 return
760 end % if isa(figno,'char')
761
762 % nargin >=1 and ~isa(figno,'char')
763
764 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
765 %%%%
766 %%%% PART 1 of advanced usage:
767 %%%% Check inputs and initialize
768 %%%%
769 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
770
771 if isa(figno,'cell') % called from GUI (all set)
772
773 [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
774 figno=LAPRINTOPT.figno;
775 filename=LAPRINTOPT.filename;
776
777 else % advanced usage
778
779 % get settings
780 LAPRINTOPT = prefsettings;
781 if isempty(LAPRINTOPT)
782 LAPRINTOPT = factorysettings;
783 end
784
785 % modify prefs
786 if ~isa(figno,'double')
787 figno
788 error('This is not a figure handle.')
789 end
790 if ~any(get(0,'children')==figno)
791 figno
792 error('This is not a figure handle.')
793 end
794 LAPRINTOPT.figno = figno;
795
796 if nargin>1
797 if ~isa(filename,'char')
798 filename
799 error('This is not a file name.')
800 end
801 LAPRINTOPT.filename=filename;
802 end
803 end
804
805 % read and check command line options
806
807 try % try old usage (Version 2.03)
808 if nargin <=2
809 error('lets take new usage')
810 end
811 % 2.03 defaults
812 width = 12;
813 factor = 0.8;
814 scalefonts = 1;
815 keepfontprops = 0;
816 asonscreen = 0;
817 keepticklabels = 0;
818 mathticklabels = 0;
819 head = 1;
820 comment = '';
821 caption = '';
822 extrapicture = 1;
823 nzeros = 5;
824 verbose = 0;
825 figcopy = 1;
826 printcmd = ['print(''-f<figurenumber>'',' ...
827 '''-deps'',''<filename.eps>'')'];
828 package = 'epsfig';
829 color = 0;
830 createview = 0;
831 viewfilename = [filename '_'];
832 processview = 0;
833 cmd1 = '';
834 cmd2 = '';
835 cmd3 = '';
836 cmd4 = '';
837 cmd5 = '';
838 cmd6 = '';
839 cmd7 = '';
840 cmd8 = '';
841 for i=1:nargin-2
842 if ~isa(varargin{i},'char')
843 error('Options must be character arrays.')
844 end
845 oriopt=varargin{i}(:)';
846 opt=[ lower(strrep(oriopt,' ','')) ' ' ];
847 if strcmp(opt(1:7),'verbose')
848 verbose=1;
849 elseif strcmp(opt(1:10),'asonscreen')
850 asonscreen=1;
851 elseif strcmp(opt(1:14),'keepticklabels')
852 keepticklabels=1;
853 elseif strcmp(opt(1:14),'mathticklabels')
854 mathticklabels=1;
855 elseif strcmp(opt(1:13),'keepfontprops')
856 keepfontprops=1;
857 elseif strcmp(opt(1:14),'noextrapicture')
858 extrapicture=0;
859 elseif strcmp(opt(1:14),'noextrapicture')
860 extrapicture=0;
861 elseif strcmp(opt(1:5),'loose')
862 printcmd = ['print(''-f<figurenumber>'',' ...
863 '''-deps'',''-loose'',''<filename.eps>'')'];
864 elseif strcmp(opt(1:9),'nofigcopy')
865 figcopy=0;
866 elseif strcmp(opt(1:12),'noscalefonts')
867 scalefonts=0;
868 elseif strcmp(opt(1:6),'nohead')
869 head=0;
870 elseif strcmp(opt(1:7),'caption')
871 eqpos=findstr(oriopt,'=');
872 if isempty(eqpos)
873 caption='Matlab Figure';
874 else
875 caption=oriopt(eqpos+1:length(oriopt));
876 end
877 elseif strcmp(opt(1:8),'comment=')
878 eqpos=findstr(oriopt,'=');
879 comment=oriopt(eqpos(1)+1:length(oriopt));
880 elseif strcmp(opt(1:9),'viewfile=')
881 createview=1;
882 eqpos=findstr(oriopt,'=');
883 viewfilename=oriopt(eqpos(1)+1:length(oriopt));
884 elseif strcmp(opt(1:6),'width=')
885 eval([ opt ';' ]);
886 elseif strcmp(opt(1:7),'factor=')
887 eval([ opt ';' ]);
888 else
889 error([ 'Option ' varargin{i} ' not recognized.'])
890 end
891 end
892
893 warning('LaPrint:general',['You are using the old LaPrint '...
894 'syntax. This syntax might not be supported in '...
895 'future releases of LaPrint.'])
896
897 catch % old usage doesn't work, take new one
898
899 % restore preferences / factory defaults
900 width = LAPRINTOPT.width;
901 factor = LAPRINTOPT.factor;
902 scalefonts = LAPRINTOPT.scalefonts;
903 keepfontprops = LAPRINTOPT.keepfontprops;
904 asonscreen = LAPRINTOPT.asonscreen;
905 keepticklabels = LAPRINTOPT.keepticklabels;
906 mathticklabels = LAPRINTOPT.mathticklabels;
907 head = LAPRINTOPT.head;
908 comment = LAPRINTOPT.comment;
909 caption = LAPRINTOPT.caption;
910 extrapicture = LAPRINTOPT.extrapicture;
911 nzeros = LAPRINTOPT.nzeros;
912 verbose = LAPRINTOPT.verbose;
913 figcopy = LAPRINTOPT.figcopy;
914 printcmd = LAPRINTOPT.printcmd;
915 package = LAPRINTOPT.package;
916 color = LAPRINTOPT.color;
917 createview = LAPRINTOPT.createview;
918 viewfilename = LAPRINTOPT.viewfilename;
919 processview = LAPRINTOPT.processview;
920 cmd1 = LAPRINTOPT.cmd1;
921 cmd2 = LAPRINTOPT.cmd2;
922 cmd3 = LAPRINTOPT.cmd3;
923 cmd4 = LAPRINTOPT.cmd4;
924 cmd5 = LAPRINTOPT.cmd5;
925 cmd6 = LAPRINTOPT.cmd6;
926 cmd7 = LAPRINTOPT.cmd7;
927 cmd8 = LAPRINTOPT.cmd8;
928
929 if nargin > 2
930 if rem(nargin,2)
931 error('Option names/values must appear in pairs.')
932 end
933 for i=1:2:nargin-2
934 if ~isa(varargin{i},'char')
935 error('Option name must be a character array.')
936 end
937 opt = lower(strrep(varargin{i}(:)',' ',''));
938 val = varargin{i+1}(:)';
939 switch opt
940 case 'options'
941 if isa(val,'char')
942 if strcmp(val,'factory')
943 val = factorysettings;
944 else
945 load(val)
946 val = LAPRINTOPT;
947 end
948 end
949 if ~isa(val,'struct')
950 error('Value of options must be a structure array.')
951 end
952 % no error checking here!
953 width = val.width;
954 factor = val.factor;
955 scalefonts = val.scalefonts;
956 keepfontprops = val.keepfontprops;
957 asonscreen = val.asonscreen;
958 keepticklabels = val.keepticklabels;
959 mathticklabels = val.mathticklabels;
960 head = val.head;
961 comment = val.comment;
962 caption = val.caption;
963 extrapicture = val.extrapicture;
964 nzeros = val.nzeros;
965 verbose = val.verbose;
966 figcopy = val.figcopy;
967 printcmd = val.printcmd;
968 package = val.package;
969 color = val.color;
970 createview = val.createview;
971 viewfilename = val.viewfilename;
972 processview = val.processview;
973 cmd1 = val.cmd1;
974 cmd2 = val.cmd2;
975 cmd3 = val.cmd3;
976 cmd4 = val.cmd4;
977 cmd5 = val.cmd5;
978 cmd6 = val.cmd6;
979 cmd7 = val.cmd7;
980 cmd8 = val.cmd8;
981 case 'width'
982 if ~isa(val,'double')
983 error('Value of width must be a double.')
984 end
985 width = val;
986 case 'factor'
987 if ~isa(val,'double')
988 error('Value of factor must be a double.')
989 end
990 factor=val;
991 case 'scalefonts'
992 scalefonts = value01(val,opt);
993 case 'keepfontprops'
994 keepfontprops = value01(val,opt);
995 case 'asonscreen'
996 asonscreen = value01(val,opt);
997 case 'keepticklabels'
998 keepticklabels = value01(val,opt);
999 case 'mathticklabels'
1000 mathticklabels = value01(val,opt) ;
1001 case 'head'
1002 head = value01(val,opt);
1003 case 'comment'
1004 if ~isa(val,'char')
1005 error('Value of comment must be a character array.')
1006 end
1007 comment = val;
1008 case 'caption'
1009 if ~isa(val,'char')
1010 error('Value of caption must be a character array.')
1011 end
1012 caption = val;
1013 case 'extrapicture'
1014 extrapicture = value01(val,opt);
1015 case 'nzeros'
1016 if ~isa(val,'double')
1017 error('Value of nzeros must be a double.')
1018 end
1019 nzeros = val;
1020 case 'verbose'
1021 verbose = value01(val,opt);
1022 case 'figcopy'
1023 figcopy = value01(val,opt);
1024 case 'printcmd'
1025 if ~isa(val,'char')
1026 error('Value of printcmd must be a character array.')
1027 end
1028 printcmd = val;
1029 case 'package'
1030 if ~isa(val,'char')
1031 error('Value of package must be a character array.')
1032 end
1033 val = lower(strrep(val,' ',''));
1034 switch val
1035 case {'graphicx','epsfig'}
1036 % fine
1037 otherwise
1038 error('Value of package is unknown.')
1039 end
1040 package = val;
1041 case 'color'
1042 color = value01(val,opt);
1043 case 'createview'
1044 createview = value01(val,opt);
1045 case 'viewfilename'
1046 if ~isa(val,'char')
1047 error('Value of viewfilename must be a character array.')
1048 end
1049 viewfilename = val;
1050 case 'processview'
1051 processview = value01(val,opt);
1052 case 'cmd1'
1053 if ~isa(val,'char')
1054 error('Value of cmd1 must be a character array.')
1055 end
1056 cmd1 = val;
1057 case 'cmd2'
1058 if ~isa(val,'char')
1059 error('Value of cmd2 must be a character array.')
1060 end
1061 cmd2 = val;
1062 case 'cmd3'
1063 if ~isa(val,'char')
1064 error('Value of cmd3 must be a character array.')
1065 end
1066 cmd3 = val;
1067 case 'cmd4'
1068 if ~isa(val,'char')
1069 error('Value of cmd4 must be a character array.')
1070 end
1071 cmd4 = val;
1072 case 'cmd5'
1073 if ~isa(val,'char')
1074 error('Value of cmd5 must be a character array.')
1075 end
1076 cmd5 = val;
1077 case 'cmd6'
1078 if ~isa(val,'char')
1079 error('Value of cmd6 must be a character array.')
1080 end
1081 cmd6 = val;
1082 case 'cmd7'
1083 if ~isa(val,'char')
1084 error('Value of cmd7 must be a character array.')
1085 end
1086 cmd7 = val;
1087 case 'cmd8'
1088 if ~isa(val,'char')
1089 error('Value of cmd8 must be a character array.')
1090 end
1091 cmd8 = val;
1092 otherwise
1093 error(['Option ''' opt ''' unknown'])
1094 end % switch opt
1095 end % for i=3:2:nargin
1096 end % if nargin > 2
1097 end % try / catch
1098
1099 if verbose,
1100 disp([ 'This is LaPrint, version ' laprintident '.' ]);
1101 end
1102
1103 comment = strrep(strrep(comment,'\','\\'),'%','%%');
1104 caption = strrep(strrep(caption,'\','\\'),'%','%%');
1105 iscaption = logical(length(caption));
1106
1107 if nzeros < 3
1108 warning('LaPrint:general',...
1109 'The value of nzero should be >=3. I will use nzeros=3.')
1110 nzeros=3;
1111 end
1112
1113 if processview
1114 createview=1;
1115 end
1116
1117 if mathticklabels
1118 Do='$';
1119 else
1120 Do='';
1121 end
1122
1123 % eps- and tex- filenames
1124 [epsfullnameext,epsbasenameext,epsbasename,epsdirname] = ...
1125 getfilenames(filename,'eps',verbose);
1126 [texfullnameext,texbasenameext,texbasename,texdirname] = ...
1127 getfilenames(filename,'tex',verbose);
1128 if ~strcmp(texdirname,epsdirname)
1129 warning('LaPrint:files',['The eps-file and tex-file are '...
1130 'placed in different directories.']);
1131 end
1132
1133 if createview | processview
1134 [viewfullnameext,viewbasenameext,viewbasename,viewdirname] = ...
1135 getfilenames(viewfilename,'tex',verbose);
1136 if strcmp(texfullnameext,viewfullnameext)
1137 viewfilename=[ viewfilename '_'];
1138 warning('LaPrint:files',['The tex- and view-file coincide. '...
1139 'I''ll use '' ' viewfilename ' ''. Hope that''s ok.' ])
1140 end
1141 [viewfullnameext,viewbasenameext,viewbasename,viewdirname]= ...
1142 getfilenames(viewfilename,'tex',verbose);
1143 if ~strcmp(texdirname,viewdirname)
1144 warning('LaPrint:files',['The eps-file and view-file are '...
1145 'placed in different directories.' ])
1146 end
1147 end
1148
1149 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1150 %%%%
1151 %%%% PART 2 of advanced usage:
1152 %%%% Create new figure, insert tags, and bookkeep original text
1153 %%%%
1154 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1155
1156 % show all
1157 shh = get(0,'ShowHiddenHandles');
1158 set(0,'ShowHiddenHandles','on');
1159
1160 % preparing check for copyobj bug
1161 figno_ori = figno;
1162 number_children_ori = length(get(figno_ori,'children'));
1163
1164 % open new figure (if required) and set properties
1165 if figcopy
1166 figno = copyobj(figno,0);
1167 set(figno,'visible','off')
1168 set(figno,'Numbertitle','off')
1169 set(figno,'MenuBar','none')
1170 pause(0.5)
1171 end
1172
1173 if asonscreen
1174 xlimmodeauto = findobj(figno,'xlimmode','auto');
1175 xtickmodeauto = findobj(figno,'xtickmode','auto');
1176 xticklabelmodeauto = findobj(figno,'xticklabelmode','auto');
1177 ylimmodeauto = findobj(figno,'ylimmode','auto');
1178 ytickmodeauto = findobj(figno,'ytickmode','auto');
1179 yticklabelmodeauto = findobj(figno,'yticklabelmode','auto');
1180 zlimmodeauto = findobj(figno,'zlimmode','auto');
1181 ztickmodeauto = findobj(figno,'ztickmode','auto');
1182 zticklabelmodeauto = findobj(figno,'zticklabelmode','auto');
1183 set(xlimmodeauto,'xlimmode','manual')
1184 set(xtickmodeauto,'xtickmode','manual')
1185 set(xticklabelmodeauto,'xticklabelmode','manual')
1186 set(ylimmodeauto,'ylimmode','manual')
1187 set(ytickmodeauto,'ytickmode','manual')
1188 set(yticklabelmodeauto,'yticklabelmode','manual')
1189 set(zlimmodeauto,'ylimmode','manual')
1190 set(ztickmodeauto,'ytickmode','manual')
1191 set(zticklabelmodeauto,'yticklabelmode','manual')
1192 end
1193 set(figno,'paperunits','centimeters');
1194 set(figno,'units','centimeters');
1195 orip = get(figno,'Position');
1196
1197 % determine width and height
1198 if factor <= 0
1199 factor = width/orip(3);
1200 end
1201 latexwidth = width;
1202 epswidth = latexwidth/factor;
1203 epsheight = epswidth*orip(4)/orip(3);
1204
1205 set(figno,'PaperPosition',[0 0 epswidth epsheight ])
1206 set(figno,'papersize',[epswidth epsheight])
1207 set(figno,'Position',[orip(1)+0.5 orip(2)-0.5 epswidth epsheight ])
1208 set(figno,'Name',[ 'To be printed; size: ' num2str(factor,3) ...
1209 ' x (' num2str(epswidth,3) 'cm x ' num2str(epsheight,3) 'cm)' ])
1210
1211 % some warnings
1212 if verbose
1213 if (epswidth<13) | (epsheight<13*0.75)
1214 warning('LaPrint:size',['The size of the eps-figure is quite '...
1215 'small. The text objects might not be properly set. '...
1216 'Reducing ''factor'' might help.'])
1217 end
1218 if latexwidth/epswidth<0.5
1219 warning('LaPrint:size',['The size of the eps-figure is large ' ...
1220 'compared to the latex figure. '...
1221 'The text size might be too small. '...
1222 'Increasing ''factor'' might help.'])
1223 end
1224 if (orip(3)-epswidth)/orip(3) > 0.1
1225 warning('LaPrint:size',['The size of the eps-figure is much '...
1226 'smaller than the original '...
1227 'figure on screen. Matlab might save different ticks '...
1228 'and ticklabels than in the original figure. '...
1229 'See option ''asonscreen''.'])
1230 end
1231 disp('Strike any key to continue.');
1232 pause
1233 end
1234
1235 %
1236 % TEXT OBJECTS: modify new figure
1237 %
1238
1239 % find all text objects
1240 hxl = get(findobj(figno,'type','axes'),'xlabel');
1241 hyl = get(findobj(figno,'type','axes'),'ylabel');
1242 hzl = get(findobj(figno,'type','axes'),'zlabel');
1243 hti = get(findobj(figno,'type','axes'),'title');
1244 hte = findobj(figno,'type','text');
1245
1246 % array of all text handles
1247 htext = unique([ celltoarray(hxl) celltoarray(hyl) celltoarray(hzl) ...
1248 celltoarray(hti) celltoarray(hte)]);
1249 nt = length(htext);
1250
1251 % set(celltoarray(hxl),'VerticalAlignment','top');
1252 % get alignments
1253 hora = get(htext,'HorizontalAlignment');
1254 vera = get(htext,'VerticalAlignment');
1255 align = cell(nt,1);
1256 for i=1:nt
1257 align{i} = hora{i}(1);
1258 switch vera{i}
1259 case 'top'
1260 align{i} = [align{i} 't'];
1261 case 'cap'
1262 % if ~isempty(get(htext(i),'string'))
1263 % warning('LaPrint:text',['Using vertical ' ...
1264 % 'alignment ''top'' instead of ''cap''.'])
1265 % end
1266 align{i} = [align{i} 't'];
1267 case 'middle'
1268 align{i} = [align{i} 'c'];
1269 case 'baseline'
1270 align{i} = [align{i} 'B'];
1271 case 'bottom'
1272 align{i} = [align{i} 'b'];
1273 otherwise
1274 warning('LaPrint:text',['Vertical alignment ' vera{i} ...
1275 ' unknown. Using ''c''.'])
1276 align{i} = [align{i} 'c'];
1277 end
1278 end
1279
1280 % generate new strings and store old ones
1281 oldstr = get(htext,'string');
1282 newstr = cell(nt,1);
1283 basestr = ['s' char(48*ones(1,nzeros-1))];
1284 extrastr = 0;
1285 for i=1:nt
1286 osi = oldstr{i};
1287 oldstr{i} = ['\setlength{\tabcolsep}{0pt}\begin{tabular}{' ...
1288 align{i}(1) '}'];
1289 isnonempty_osi = 0;
1290 if strcmp(get(get(htext(i),'parent'),'tag'),'legend')
1291 newstr1 = [];
1292 if isa(osi,'cell')
1293 % Legend/cell : Don't use tabular, employ extra strings
1294 nlines = length(osi);
1295 if nlines > 1
1296 newstr{nt+extrastr+nlines-1} = [];
1297 oldstr{nt+extrastr+nlines-1} = [];
1298 htext((nt+extrastr+1):(nt+extrastr+nlines-1))=htext(i);
1299 for line=1:nlines-1
1300 oldstr{nt+extrastr+line} = ...
1301 strrep(strrep(osi{line},'\','\\'),'%','%%');
1302 newstr{nt+extrastr+line} = ...
1303 overwritetail(basestr,nt+extrastr+line);
1304 newstr1 = [newstr1; overwritetail(basestr,nt+extrastr+line)];
1305 end
1306 extrastr = extrastr+nlines-1;
1307 end
1308 if nlines > 0
1309 oldstr{i} = strrep(strrep(osi{nlines},'\','\\'),'%','%%');
1310 newstr{i} = overwritetail(basestr,i);
1311 newstr1 = [newstr1; overwritetail(basestr,i)];
1312 end
1313 % replace strings in figure
1314 set(htext(i),'string',cellstr(newstr1));
1315 else
1316 % Legend/matrix : Don't use tabular, employ extra strings
1317 nlines=size(osi,1);
1318 if nlines > 1
1319 newstr{nt+extrastr+nlines-1} = [];
1320 oldstr{nt+extrastr+nlines-1} = [];
1321 htext((nt+extrastr+1):(nt+extrastr+nlines-1))=htext(i);
1322 for line=1:nlines-1
1323 oldstr{nt+extrastr+line} = ...
1324 strrep(strrep(osi(line,:),'\','\\'),'%','%%');
1325 newstr{nt+extrastr+line} = ...
1326 overwritetail(basestr,nt+extrastr+line);
1327 newstr1 = [newstr1; overwritetail(basestr,nt+extrastr+line)];
1328 end
1329 extrastr = extrastr+nlines-1;
1330 end
1331 if nlines > 0
1332 oldstr{i} = strrep(strrep(osi(nlines,:),'\','\\'),'%','%%');
1333 newstr{i} = overwritetail(basestr,i);
1334 newstr1 = [newstr1; overwritetail(basestr,i)];
1335 end
1336 % replace strings in figure
1337 set(htext(i),'string',newstr1);
1338 end
1339 else
1340 % text, not a legend
1341 if isa(osi,'cell')
1342 nlines = length(osi);
1343 if nlines > 1
1344 for line=1:nlines-1
1345 oldstr{i}=[oldstr{i} osi{line} '\\'];
1346 isnonempty_osi = isnonempty_osi+length(osi{line});
1347 end
1348 if align{i}(2) == 'B'
1349 warning('LaPrint:text',['Vertical Alignment ''baseline'' '...
1350 'in text with multiple rows might not match.'])
1351 align{i}(2) = 't';
1352 end
1353 end
1354 if nlines > 0
1355 oldstr{i} = [oldstr{i} osi{nlines} '\end{tabular}'];
1356 isnonempty_osi = isnonempty_osi+length(osi{nlines});
1357 end
1358 oldstr{i} = strrep(strrep(oldstr{i},'\','\\'),'%','%%');
1359 if isnonempty_osi
1360 newstr{i} = overwritetail(basestr,i);
1361 else
1362 newstr{i} = '';
1363 end
1364 % replace strings in figure
1365 set(htext(i),'string',newstr{i});
1366 else
1367 nlines=size(osi,1);
1368 if nlines > 1
1369 for line=1:nlines-1
1370 oldstr{i} = [oldstr{i} osi(line,:) '\\'];
1371 isnonempty_osi = isnonempty_osi+length(osi(line,:));
1372 end
1373 if align{i}(2) == 'B'
1374 warning('LaPrint:text',['Vertical Alignment ''baseline'' '...
1375 'in text with multiple rows might not match.'])
1376 align{i}(2) = 't';
1377 end
1378 end
1379 if nlines > 0
1380 oldstr{i} = [oldstr{i} osi(nlines,:) '\end{tabular}'];
1381 isnonempty_osi = isnonempty_osi+length(osi(nlines,:));
1382 end
1383 oldstr{i} = strrep(strrep(oldstr{i},'\','\\'),'%','%%');
1384
1385 if isnonempty_osi
1386 newstr{i} = overwritetail(basestr,i);
1387 else
1388 newstr{i} = '';
1389 end
1390 % replace string in figure
1391 set(htext(i),'string',newstr{i});
1392 end % isa cell
1393 end % isa legend
1394 end % for
1395
1396 ntp = nt+extrastr;
1397
1398 % Alignment of Legends
1399 if extrastr > 0
1400 align{ntp} = [];
1401 [align{nt+1:ntp}] = deal('lc');
1402 end
1403
1404 % get font properties and create commands
1405 if ntp > 0
1406 [fontsizecmd{1:ntp}] = deal('');
1407 [fontanglecmd{1:ntp}] = deal('');
1408 [fontweightcmd{1:ntp}] = deal('');
1409 [colorcmd{1:ntp}] = deal('');
1410 [colorclose{1:ntp}] = deal('');
1411 end
1412 selectfontcmd = '';
1413
1414 if keepfontprops
1415
1416 % fontsize
1417 set(htext,'fontunits','points');
1418 fontsize = get(htext,'fontsize');
1419 for i=1:ntp
1420 fontsizecmd{i} = [ '\\fontsize{' num2str(fontsize{i}) '}{' ...
1421 num2str(fontsize{i}*1.5) '}' ];
1422 end
1423
1424 % fontweight
1425 fontweight = get(htext,'fontweight');
1426 for i=1:ntp
1427 switch fontweight{i}
1428 case 'light'
1429 fontweightcmd{i} = [ '\\fontseries{l}\\mathversion{normal}' ];
1430 case 'normal'
1431 fontweightcmd{i} = [ '\\fontseries{m}\\mathversion{normal}' ];
1432 case 'demi'
1433 fontweightcmd{i} = [ '\\fontseries{sb}\\mathversion{bold}' ];
1434 case 'bold'
1435 fontweightcmd{i} = [ '\\fontseries{bx}\\mathversion{bold}' ];
1436 otherwise
1437 warning('LaPrint:text',['Unknown fontweight: ' fontweight{i} ])
1438 fontweightcmd{i} = [ '\\fontseries{m}\\mathversion{normal}' ];
1439 end
1440 end
1441
1442 % fontangle
1443 fontangle = get(htext,'fontangle');
1444 for i=1:ntp
1445 switch fontangle{i}
1446 case 'normal'
1447 fontanglecmd{i} = [ '\\fontshape{n}' ];
1448 case 'italic'
1449 fontanglecmd{i} = [ '\\fontshape{it}' ];
1450 case 'oblique'
1451 fontanglecmd{i} = [ '\\fontshape{it}' ];
1452 otherwise
1453 warning('LaPrint:text',['unknown fontangle: ' fontangle{i} ])
1454 fontanglecmd{i} = [ '\\fontshape{n}' ];
1455 end
1456 end
1457 selectfontcmd = '\\selectfont ';
1458
1459 end
1460
1461 if color & ntp>0
1462 col = get(htext,'color');
1463 bgcol = get(htext,'BackgroundColor');
1464 ecol = get(htext,'EdgeColor');
1465 for i=1:ntp
1466 col0 = get(get(htext(i),'parent'),'color');
1467 [coli,isc] = char2rgb(col{i},[0 0 0]);
1468 [bgcoli,isbgc] = char2rgb(bgcol{i},col0);
1469 [ecoli,isec] = char2rgb(ecol{i},col0);
1470 if isbgc | isec
1471 set(htext(i),'BackgroundColor','none')
1472 set(htext(i),'EdgeColor','none')
1473 colorcmd{i} = ['\\setlength{\\fboxsep}{2pt}\\fcolorbox[rgb]{' ...
1474 num2str(ecoli(1)) ',' num2str(ecoli(2)) ',' ...
1475 num2str(ecoli(3)) '}{' ...
1476 num2str(bgcoli(1)) ',' num2str(bgcoli(2)) ',' ...
1477 num2str(bgcoli(3)) '}{\\color[rgb]{' ...
1478 num2str(coli(1)) ',' num2str(coli(2)) ',' num2str(coli(3)) '}' ];
1479 colorclose{i} = '}';
1480 else
1481 colorcmd{i} = ['\\color[rgb]{' ...
1482 num2str(coli(1)) ',' num2str(coli(2)) ',' num2str(coli(3)) '}' ];
1483 end
1484 end
1485 end
1486
1487 %
1488 % LABELS: modify new figure
1489 %
1490
1491 if ~keepticklabels
1492
1493 % all axes
1494 hax = celltoarray(findobj(figno,'type','axes'));
1495 na = length(hax);
1496
1497 % % try to figure out if we have 3D axes an warn
1498 % issuewarning = 0;
1499 % for i=1:na
1500 % issuewarning = max(issuewarning,is3d(hax(i)));
1501 % end
1502 % if issuewarning
1503 % warning('LaPrint:label',['This seems to be a 3D plot. '...
1504 % 'The LaTeX labels are possibly incorrect. '...
1505 % 'The option ''keepticklabels'' might help. '...
1506 % 'Setting ''figcopy'' to ''off'' might be wise, too.'])
1507 % end
1508
1509 % try to figure out if we linear scale with extra factor
1510 % and determine powers of 10
1511 powers = NaN*zeros(na,3); % matrix with powers of 10
1512 for i=1:na % all axes
1513 allxyz = { 'x', 'y', 'z' };
1514 for ixyz=1:3 % x,y,z
1515 xyz = allxyz{ixyz};
1516 ticklabelmode = get(hax(i),[ xyz 'ticklabelmode']);
1517 if strcmp(ticklabelmode,'auto')
1518 tick = get(hax(i),[ xyz 'tick']);
1519 ticklabel = get(hax(i),[ xyz 'ticklabel']);
1520 nticklabels = size(ticklabel,1);
1521 nticks = length(tick);
1522 if nticks==0,
1523 powers(i,ixyz)=0;
1524 nticklabels=0;
1525 end
1526 if nticklabels==0,
1527 powers(i,ixyz)=0;
1528 end
1529 for k=1:nticklabels % all ticks
1530 label = str2num(ticklabel(k,:));
1531 if length(label)==0,
1532 powers(i,ixyz) = 0;
1533 break;
1534 end
1535 if ( label==0 ) & ( abs(tick(k))>1e-10 )
1536 powers(i,ixyz) = 0;
1537 break;
1538 end
1539 if label~=0
1540 expon = log10(tick(k)/label);
1541 rexpon = round(expon);
1542 if abs(rexpon-expon)>1e-10
1543 powers(i,ixyz) = 0;
1544 break;
1545 end
1546 if isnan(powers(i,ixyz))
1547 powers(i,ixyz) = rexpon;
1548 else
1549 if powers(i,ixyz)~=rexpon
1550 powers(i,ixyz) = 0;
1551 break;
1552 end
1553 end
1554 end
1555 end % k
1556 else % if 'auto'
1557 powers(i,ixyz) = 0;
1558 end % if 'auto'
1559 end % ixyz
1560 end % i
1561
1562 % place text to be replaced by powers on y-axis
1563 for i=1:na
1564 allxyz = { 'x', 'y', 'z' };
1565 ixyz=2; % x,y,z
1566 xyz = allxyz{ixyz};
1567 leftright=get(hax(i),'yaxislocation');
1568 if powers(i,ixyz) & ~is3d(hax(i)) & isequal(leftright,'left')
1569 powertext = ['ypower' int2str(i)];
1570 xlimit = get(hax(i),'xlim');
1571 ylimit = get(hax(i),'ylim');
1572 htext = text(xlimit(1),ylimit(2)+...
1573 0.01*(ylimit(2)-ylimit(1)),...
1574 powertext);
1575 set(htext,'VerticalAlignment','Baseline');
1576 end
1577 end % i
1578
1579 % replace all ticklabels and bookkeep
1580 nxlabel = zeros(1,na);
1581 nylabel = zeros(1,na);
1582 nzlabel = zeros(1,na);
1583 allxyz={ 'x', 'y', 'z' };
1584 for ixyz=1:3
1585 xyz = allxyz{ixyz};
1586 k=1;
1587 if strcmp(xyz,'y')
1588 basestr = [ 'v' char(48*ones(1,nzeros-1))];
1589 else
1590 basestr = [ xyz char(48*ones(1,nzeros-1))];
1591 end
1592 oldtl = cell(na,1);
1593 newtl = cell(na,1);
1594 nlabel = zeros(1,na);
1595 for i=1:na
1596 % set(hax(i),[ xyz 'tickmode' ],'manual')
1597 % set(hax(i),[ xyz 'ticklabelmode' ],'manual')
1598 oldtl{i} = chartocell(get(hax(i),[ xyz 'ticklabel' ]));
1599 nlabel(i) = length(oldtl{i});
1600 newtl{i} = cell(1,nlabel(i));
1601 for j=1:nlabel(i)
1602 newtl{i}{j} = overwritetail(basestr,k);
1603 k = k+1;
1604 oldtl{i}{j} = deblank(strrep(strrep(oldtl{i}{j},'\','\\'),...
1605 '%','%%'));
1606 end
1607 set(hax(i),[ xyz 'ticklabel' ],newtl{i});
1608 end
1609 eval([ 'old' xyz 'tl=oldtl;' ]);
1610 eval([ 'new' xyz 'tl=newtl;' ]);
1611 eval([ 'n' xyz 'label=nlabel;' ]);
1612 end
1613
1614 % determine latex commands for font properties
1615
1616 if keepfontprops
1617
1618 % ticklabel font size
1619 afsize = zeros(na,1);
1620 for i=1:na
1621 afsize(i) = get(hax(i),'fontsize');
1622 end
1623 if (any(afsize ~= afsize(1) ))
1624 warning('LaPrint:text',['Different font sizes for axes not '...
1625 'supported. All axes will have font size ' ...
1626 num2str(afsize(1)) '.' ] )
1627 end
1628 afsizecmd = [ '\\fontsize{' num2str(afsize(1)) '}{' ...
1629 num2str(afsize(1)*1.5) '}' ];
1630
1631 % ticklabel font weight
1632 afweight = cell(na,1);
1633 for i=1:na
1634 afweight{i} = get(hax(i),'fontweight');
1635 end
1636 switch afweight{1}
1637 case 'light'
1638 afweightcmd = [ '\\fontseries{l}\\mathversion{normal}' ];
1639 case 'normal'
1640 afweightcmd = [ '\\fontseries{m}\\mathversion{normal}' ];
1641 case 'demi'
1642 afweightcmd = [ '\\fontseries{sb}\\mathversion{bold}' ];
1643 case 'bold'
1644 afweightcmd = [ '\\fontseries{bx}\\mathversion{bold}' ];
1645 otherwise
1646 warning('LaPrint:text',['unknown fontweight: ' afweight{1} ])
1647 afweightcmd = [ '\\fontseries{m}\\mathversion{normal}' ];
1648 end
1649 for i=1:na
1650 if ~strcmp(afweight{i},afweight{1})
1651 warning('LaPrint:text',['Different font weights for axes '...
1652 'are not supported. All axes will have font weight ' ...
1653 afweightcmd '.'])
1654 end
1655 end
1656
1657 % ticklabel font angle
1658 afangle = cell(na,1);
1659 for i=1:na
1660 afangle{i} = get(hax(i),'fontangle');
1661 end
1662 switch afangle{1}
1663 case 'normal'
1664 afanglecmd = [ '\\fontshape{n}' ];
1665 case 'italic'
1666 afanglecmd = [ '\\fontshape{it}' ];
1667 case 'oblique'
1668 afanglecmd = [ '\\fontshape{it}' ];
1669 otherwise
1670 warning('LaPrint:text',['unknown fontangle: ' afangle{1} ])
1671 afanglecmd=[ '\\fontshape{n}' ];
1672 end
1673 for i=1:na
1674 if ~strcmp(afangle{i},afangle{1})
1675 warning('LaPrint:text',['Different font angles for axes not '...
1676 'supported. All axes will have font angle ' ...
1677 afanglecmd '.'] )
1678 end
1679 end
1680
1681 end
1682
1683 % ticklabel color
1684 acolcmd='';
1685 if color
1686 acol=[];
1687 allxyz={ 'x', 'y', 'z' };
1688 acolwarn = 0;
1689 for i=1:na
1690 for ixyz=1:3
1691 xyzcolor = [allxyz{ixyz} 'color'];
1692 if ~isempty(get(hax(i),[allxyz{ixyz} 'ticklabel']))
1693 if isempty(acol)
1694 acol = char2rgb(get(hax(i),xyzcolor));
1695 else
1696 if any(char2rgb(get(hax(i),xyzcolor))~=acol)
1697 acolwarn = 1;
1698 end
1699 end
1700 end
1701 end
1702 end
1703 if acolwarn
1704 warning('LaPrint:label',['Different colors for axes not ' ...
1705 'supported. All ticklabels will have color [ ' ...
1706 num2str(acol) ' ].' ] )
1707 end
1708 if ~isempty(acol)
1709 if any(acol~=[0 0 0])
1710 acolcmd = [ '\\color[rgb]{' num2str(acol(1)) ',' ...
1711 num2str(acol(2)) ',' num2str(acol(3)) '}' ];
1712 end
1713 end
1714 end
1715
1716 % ticklabel alignment
1717 xyzalign = char([116*ones(na,1) 114*ones(na,1) 114*ones(na,1)]);
1718 for i=1:na
1719 switch get(hax(i),'XAxisLocation')
1720 case 'top'
1721 xyzalign(i,1)='B';
1722 end
1723 switch get(hax(i),'YAxisLocation')
1724 case 'right'
1725 xyzalign(i,2)='l';
1726 end
1727 end
1728
1729 end
1730
1731 %
1732 % extra picture environment
1733 %
1734
1735 if extrapicture
1736 unitlength = zeros(na,1);
1737 ybound = zeros(na,1);
1738 for i=na:-1:1 % reverse order, to keep axes in original order
1739 if ~is3d(hax(i))
1740 xlim = get(hax(i),'xlim');
1741 ylim = get(hax(i),'ylim');
1742 axes(hax(i));
1743 hori = text(ylim(1),ylim(1),[ 'origin' int2str(i) ]);
1744 set(hori,'VerticalAlignment','bottom');
1745 set(hori,'Fontsize',2);
1746 set(hax(i),'Units','normalized')
1747 pos = get(hax(i),'Position');
1748 unitlength(i) = pos(3)*epswidth;
1749 ybound(i) = (pos(4)*epsheight)/(pos(3)*epswidth);
1750 else
1751 warning('LaPrint:extrapic',['Option ''extrapicture'' for 3D ' ...
1752 'axes not supported.'])
1753 end
1754 end
1755 end
1756
1757 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1758 %%%%
1759 %%%% PART 3 of advanced usage:
1760 %%%% save eps and tex files
1761 %%%%
1762 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1763
1764 % prevent matlab print command to modify lims and ticks
1765 % (empty, if asonscreen=1)
1766 if ~keepticklabels
1767 xlimmodeauto = findobj(figno,'xlimmode','auto');
1768 xtickmodeauto = findobj(figno,'xtickmode','auto');
1769 xticklabelmodeauto = findobj(figno,'xticklabelmode','auto');
1770 ylimmodeauto = findobj(figno,'ylimmode','auto');
1771 ytickmodeauto = findobj(figno,'ytickmode','auto');
1772 yticklabelmodeauto = findobj(figno,'yticklabelmode','auto');
1773 zlimmodeauto = findobj(figno,'zlimmode','auto');
1774 ztickmodeauto = findobj(figno,'ztickmode','auto');
1775 zticklabelmodeauto = findobj(figno,'zticklabelmode','auto');
1776 set(xlimmodeauto,'xlimmode','manual')
1777 set(xtickmodeauto,'xtickmode','manual')
1778 set(xticklabelmodeauto,'xticklabelmode','manual')
1779 set(ylimmodeauto,'ylimmode','manual')
1780 set(ytickmodeauto,'ytickmode','manual')
1781 set(yticklabelmodeauto,'yticklabelmode','manual')
1782 set(zlimmodeauto,'ylimmode','manual')
1783 set(ztickmodeauto,'ytickmode','manual')
1784 set(zticklabelmodeauto,'yticklabelmode','manual')
1785 end
1786
1787 % create eps file
1788 cmd = strrep(printcmd,'<filename.eps>',epsfullnameext);
1789 cmd = strrep(cmd,'<filename>',filename);
1790 cmd = strrep(cmd,'<figurenumber>',int2str(figno));
1791
1792 if verbose
1793 disp([ 'executing: '' ' cmd ' ''' ]);
1794 end
1795 eval(cmd);
1796
1797 %
1798 % create latex file
1799 %
1800 if verbose
1801 disp([ 'writing to: '' ' texfullnameext ' ''' ])
1802 end
1803 fid = fopen(texfullnameext,'w');
1804
1805 % head
1806 if head
1807 fprintf(fid,[ '%% This file is generated by the MATLAB m-file' ...
1808 ' laprint.m. It can be included\n']);
1809 fprintf(fid,[ '%% into LaTeX documents using the packages ']);
1810 fprintf(fid,package);
1811 if color
1812 fprintf(fid,', color');
1813 end
1814 fprintf(fid,[ ' and psfrag.\n' ]);
1815 fprintf(fid, ['%% It is accompanied by a postscript file. ',...
1816 'A sample LaTeX file is:\n']);
1817 fprintf(fid, '%% \\documentclass{article}\\usepackage{');
1818 fprintf(fid,package);
1819 if color
1820 fprintf(fid,',color');
1821 end
1822 fprintf(fid, ',psfrag}\n');
1823 fprintf(fid,[ '%% \\begin{document}\\input{' ...
1824 texbasename '}\\end{document}\n' ]);
1825 fprintf(fid, [ '%% See http://www.mathworks.de/matlabcentral'...
1826 '/fileexchange/loadFile.do?objectId=4638\n']);
1827 fprintf(fid, [ '%% for recent versions of laprint.m.\n' ]);
1828 fprintf(fid, '%%\n');
1829 fprintf(fid,[ '%% created by: ' 'LaPrint version ' ...
1830 laprintident '\n' ]);
1831 fprintf(fid,[ '%% created on: ' datestr(now) '\n' ]);
1832 fprintf(fid,[ '%% eps bounding box: ' num2str(epswidth) ...
1833 ' cm x ' num2str(epsheight) ' cm\n' ]);
1834 fprintf(fid,[ '%% comment: ' comment '\n' ]);
1835 fprintf(fid,'%%\n');
1836 else
1837 fprintf(fid,[ '%% generated by laprint.m\n' ]);
1838 fprintf(fid,'%%\n');
1839 end
1840
1841 % go on
1842 fprintf(fid,'\\begin{psfrags}%%\n');
1843 %fprintf(fid,'\\fontsize{10}{12}\\selectfont%%\n');
1844 fprintf(fid,'\\psfragscanon%%\n');
1845
1846 % text strings
1847
1848 numbertext=0;
1849 for i=1:nt
1850 numbertext = numbertext+length(newstr{i});
1851 end
1852 if numbertext>0,
1853 fprintf(fid,'%%\n');
1854 fprintf(fid,'%% text strings:\n');
1855 for i=1:ntp
1856 if length(newstr{i})
1857 alig = strrep(align{i},'c','');
1858 fprintf(fid,[ '\\psfrag{' newstr{i} '}[' alig '][' alig ']{' ...
1859 fontsizecmd{i} fontweightcmd{i} fontanglecmd{i} ...
1860 selectfontcmd colorcmd{i} oldstr{i} colorclose{i} '}%%\n' ]);
1861 end
1862 end
1863 end
1864
1865 % labels
1866
1867 if ~keepticklabels
1868 if ~isempty(acolcmd)
1869 fprintf(fid,'%%\n');
1870 fprintf(fid,'%% axes ticklabel color:\n');
1871 fprintf(fid,[ acolcmd '%%\n' ]);
1872 end
1873 if keepfontprops
1874 fprintf(fid,'%%\n');
1875 fprintf(fid,'%% axes font properties:\n');
1876 fprintf(fid,[ afsizecmd afweightcmd '%%\n' ]);
1877 fprintf(fid,[ afanglecmd '\\selectfont%%\n' ]);
1878 end
1879 nxlabel = zeros(1,na);
1880 nylabel = zeros(1,na);
1881 nzlabel = zeros(1,na);
1882 for i=1:na
1883 nxlabel(i) = length(newxtl{i});
1884 nylabel(i) = length(newytl{i});
1885 nzlabel(i) = length(newztl{i});
1886 end
1887
1888 allxyz = { 'x', 'y', 'z' };
1889 for ixyz=1:3
1890 xyz = allxyz{ixyz};
1891 eval([ 'oldtl=old' xyz 'tl;' ]);
1892 eval([ 'newtl=new' xyz 'tl;' ]);
1893 eval([ 'nlabel=n' xyz 'label;' ]);
1894 if sum(nlabel) > 0
1895 fprintf(fid,'%%\n');
1896 fprintf(fid,[ '%% ' xyz 'ticklabels:\n']);
1897 for i=1:na
1898 poss = ['[' xyzalign(i,ixyz) '][' xyzalign(i,ixyz) ']'];
1899 if nlabel(i)
1900 if strcmp(get(hax(i),[ xyz 'scale']),'linear')
1901 % lin scale
1902 rexpon = powers(i,ixyz);
1903 if ~rexpon
1904 % no powers
1905 for j=1:nlabel(i)
1906 fprintf(fid,[ '\\psfrag{' newtl{i}{j} '}' poss '{' ...
1907 Do oldtl{i}{j} Do '}%%\n' ]);
1908 end
1909 else
1910 % powers
1911 if ixyz==2
1912 leftright=get(hax(i),'yaxislocation');
1913 if ~is3d(hax(i)) & isequal(leftright,'left')
1914 for j=1:nlabel(i)
1915 fprintf(fid,[ '\\psfrag{' newtl{i}{j} '}' poss '{' ...
1916 Do oldtl{i}{j} Do '}%%\n' ]);
1917 end
1918 fprintf(fid,[ '\\psfrag{ypower' int2str(i) ...
1919 '}[Bl][Bl]{$\\times 10^{' ...
1920 int2str(rexpon) '}$}%%\n' ]);
1921 else
1922 for j=1:nlabel(i)-1
1923 fprintf(fid,[ '\\psfrag{' newtl{i}{j} '}' poss '{' ...
1924 Do oldtl{i}{j} Do '}%%\n' ]);
1925 end
1926 if ~is3d(hax(i))
1927 fprintf(fid,[ '\\psfrag{' newtl{i}{nlabel(i)} ...
1928 '}' poss '{' ...
1929 Do oldtl{i}{nlabel(i)} Do '$\\times 10^{'...
1930 int2str(rexpon) '}$}%%\n' ]);
1931 else
1932 fprintf(fid,[ '\\psfrag{' newtl{i}{nlabel(i)} ...
1933 '}' poss '{\\shortstack{' ...
1934 Do oldtl{i}{nlabel(i)} Do '\\\\$\\times 10^{'...
1935 int2str(rexpon) '}\\ $}}%%\n' ]);
1936
1937 end
1938 end
1939 elseif ixyz==1
1940 for j=1:nlabel(i)-1
1941 fprintf(fid,[ '\\psfrag{' newtl{i}{j} '}' poss '{' ...
1942 Do oldtl{i}{j} Do '}%%\n' ]);
1943 end
1944 leftright=get(hax(i),'xaxislocation');
1945 if isequal(leftright,'bottom')
1946 fprintf(fid,[ '\\psfrag{' newtl{i}{nlabel(i)} ...
1947 '}' poss '{\\shortstack{' ...
1948 Do oldtl{i}{nlabel(i)} Do '\\\\$\\times 10^{'...
1949 int2str(rexpon) '}\\ $}}%%\n' ]);
1950 else
1951 fprintf(fid,[ '\\psfrag{' newtl{i}{nlabel(i)} ...
1952 '}' poss '{\\shortstack{$\\times 10^{' ...
1953 int2str(rexpon) '}\\ $\\\\' ...
1954 Do oldtl{i}{nlabel(i)} Do '}}%%\n' ]);
1955 end
1956 else
1957 for j=1:nlabel(i)-1
1958 fprintf(fid,[ '\\psfrag{' newtl{i}{j} '}' poss '{' ...
1959 Do oldtl{i}{j} Do '}%%\n' ]);
1960 end
1961 fprintf(fid,[ '\\psfrag{' newtl{i}{nlabel(i)} ...
1962 '}' poss '{' Do oldtl{i}{nlabel(i)} Do ...
1963 '\\setlength{\\unitlength}{1ex}' ...
1964 '\\begin{picture}(0,0)\\put(0.5,1.5){$\\times 10^{' ...
1965 int2str(rexpon) '}$}\\end{picture}}%%\n' ]);
1966 end
1967 end % rexpon
1968 else
1969 % log scale
1970 for j=1:nlabel(i)
1971 fprintf(fid,[ '\\psfrag{' newtl{i}{j} '}' poss '{$10^{' ...
1972 oldtl{i}{j} '}$}%%\n' ]);
1973 end % for (log)
1974 end % if linear
1975 end % if nlabel(i)
1976 end
1977 end
1978 end
1979 end
1980
1981 % extra picture
1982 if extrapicture
1983 fprintf(fid,'%%\n');
1984 fprintf(fid,'%% extra picture(s):\n');
1985 for i=1:na
1986 fprintf(fid,[ '\\psfrag{origin' int2str(i) '}[lb][lb]{' ...
1987 '\\setlength{\\unitlength}{' ...
1988 num2str(unitlength(i),'%5.5f') 'cm}%%\n' ]);
1989 fprintf(fid,[ '\\begin{picture}(1,' ...
1990 num2str(ybound(i),'%5.5f') ')%%\n' ]);
1991 %fprintf(fid,'\\put(0,0){}%% lower left corner\n');
1992 %fprintf(fid,[ '\\put(1,' num2str(ybound(i),'%5.5f') ...
1993 % '){}%% upper right corner\n' ]);
1994 fprintf(fid,'\\end{picture}%%\n');
1995 fprintf(fid,'}%%\n');
1996 end
1997 end
1998
1999 % figure
2000 fprintf(fid,'%%\n');
2001 fprintf(fid,'%% Figure:\n');
2002 if iscaption
2003 fprintf(fid,[ '\\parbox{' num2str(latexwidth) 'cm}{\\centering%%\n' ]);
2004 end
2005 if ~scalefonts
2006 switch package
2007 case 'epsfig'
2008 fprintf(fid,[ '\\epsfig{file=' epsbasenameext ',width=' ...
2009 num2str(latexwidth) 'cm}%%\n' ]);
2010 case 'graphicx'
2011 fprintf(fid,[ '\\includegraphics[width=' num2str(latexwidth) ...
2012 'cm]{' epsbasenameext '}%%\n' ]);
2013 otherwise
2014 warning('LaPrint:general',['Package ''' package ''' not known. '...
2015 'I hope you know what you are doing...'])
2016 end
2017 else
2018 switch package
2019 case 'epsfig'
2020 fprintf(fid,[ '\\resizebox{' num2str(latexwidth) 'cm}{!}' ...
2021 '{\\epsfig{file=' epsbasenameext '}}%%\n' ]);
2022 case 'graphicx'
2023 fprintf(fid,[ '\\resizebox{' num2str(latexwidth) 'cm}{!}' ...
2024 '{\\includegraphics{' epsbasenameext '}}%%\n' ]);
2025 otherwise
2026 warning('LaPrint:general',['Package ''' package ''' not known. '...
2027 'I hope you know what you are doing...'])
2028 end
2029 end
2030 if iscaption
2031 fprintf(fid,[ '\\caption{' caption '}%%\n' ]);
2032 fprintf(fid,[ '\\label{fig:' texbasename '}%%\n' ]);
2033 fprintf(fid,[ '}%%\n' ]);
2034 end
2035 fprintf(fid,'\\end{psfrags}%%\n');
2036 fprintf(fid,'%%\n');
2037 fprintf(fid,[ '%% End ' texbasenameext '\n' ]);
2038 fclose(fid);
2039
2040 set(figno,'Name','Printed by LaPrint')
2041 if figcopy
2042 if verbose
2043 disp('Strike any key to continue.');
2044 pause
2045 end
2046 hlegend = findobj(figno,'Tag','legend');
2047 set(hlegend,'DeleteFcn','')
2048 close(figno)
2049 end
2050
2051 % check for copyobj-bug --> should be ok now!
2052 number_children_new = length(get(figno_ori,'children'));
2053 if number_children_new < number_children_ori
2054 if figcopy
2055 warning(['LaPrint:general','Objects in the figure have been '...
2056 'deleted! This is due to a bug in matlabs '...
2057 '''copyopj''. You might want to try to set '...
2058 '''figcopy'' to ''off''.'])
2059 else
2060 warning('LaPrint:general',['Objects in the figure have been '...
2061 'deleted!'])
2062 end
2063 end
2064
2065 %
2066 % create view file
2067 %
2068
2069 if createview | processview
2070 if verbose
2071 disp([ 'writing to: '' ' viewfullnameext ' ''' ])
2072 end
2073 fid = fopen(viewfullnameext,'w');
2074
2075 if head
2076 fprintf(fid,[ '%% This file is generated by laprint.m.\n' ]);
2077 fprintf(fid,[ '%% It calls ' texbasenameext ...
2078 ', which in turn calls ' epsbasenameext '.\n' ]);
2079 fprintf(fid,[ '%% Process this file using, e.g.,\n' ]);
2080 fprintf(fid,[ '%% latex ' viewbasenameext '\n' ]);
2081 fprintf(fid,[ '%% dvips -o' viewbasename '.ps ' viewbasename ...
2082 '.dvi\n']);
2083 fprintf(fid,[ '%% ghostview ' viewbasename '.ps&\n' ]);
2084 else
2085 fprintf(fid,[ '%% generated by laprint.m\n' ]);
2086 end
2087
2088 fprintf(fid,[ '\\documentclass{article}\n' ]);
2089 fprintf(fid,[ '\\usepackage{' ]);
2090 fprintf(fid,package);
2091 if color
2092 fprintf(fid,',color');
2093 end
2094 fprintf(fid,[ ',psfrag,a4}\n' ]);
2095 fprintf(fid,[ '\\usepackage[latin1]{inputenc}\n' ]);
2096 if ~strcmp(epsdirname,viewdirname)
2097 fprintf(fid,[ '\\graphicspath{{' epsdirname '}}\n' ]);
2098 end
2099 fprintf(fid,[ '\\begin{document}\n' ]);
2100 fprintf(fid,[ '\\pagestyle{empty}\n' ]);
2101 if strcmp(texdirname,viewdirname)
2102 fprintf(fid,[ ' \\input{' texbasenameext '}\n' ]);
2103 else
2104 fprintf(fid,[ ' \\input{' texdirname texbasenameext '}\n' ]);
2105 end
2106 fprintf(fid,[ '\\end{document}\n' ]);
2107 fclose(fid);
2108 end
2109
2110 % process view file
2111
2112 if processview
2113 conti=1;
2114
2115 for i=1:8
2116 eval(['cmdi=cmd' int2str(i) ';'])
2117 if ~isempty(cmdi) & conti
2118 cmd = strrep(cmdi,'<viewfile>',viewbasename);
2119 cmd = strrep(cmd,'<filename>',filename);
2120 disp([ 'executing: '' ' cmd ' ''' ]);
2121 [stat,resu]=system(cmd);
2122 if stat %| isempty(strfind(resu,'Output written on'))
2123 disp(resu)
2124 conti=0;
2125 end
2126 end
2127 end
2128
2129 if ~conti
2130 disp('An error occured in the latex/friends sequence.')
2131 end
2132
2133 end
2134
2135 set(0,'ShowHiddenHandles',shh);
2136
2137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2138 %%%%
2139 %%%% functions used
2140 %%%%
2141 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2142
2143 function [fullnameext,basenameext,basename,dirname] = getfilenames(...
2144 filename,extension,verbose);
2145 % appends an extension to a filename (as '/home/tom/tt') and determines
2146 % fullnameext: filename with extension and dirname, as '/home/tom/tt.tex'
2147 % basenameext: filename with extension without dirname, as 'tt.tex'
2148 % basename : filename without extension without dirname, as 'tt'
2149 % dirname : dirname without filename, as '/home/tom/'
2150 % In verbose mode, it asks if to overwrite or to modify.
2151 %
2152 [dirname, basename] = splitfilename(filename);
2153 fullnameext = [ dirname basename '.' extension ];
2154 basenameext = [ basename '.' extension ];
2155 if verbose
2156 quest = (exist(fullnameext)==2);
2157 while quest
2158 yn = input([ strrep(strrep(fullnameext,'\','\\'),'%','%%') ...
2159 ' exists. Overwrite? (y/n) '],'s');
2160 if strcmp(yn,'y')
2161 quest = 0;
2162 else
2163 filename = input( ...
2164 [ 'Please enter new filename (without extension .' ...
2165 extension '): ' ],'s');
2166 [dirname, basename] = splitfilename(filename);
2167 fullnameext = [ dirname basename '.' extension ];
2168 basenameext = [ basename '.' extension ];
2169 quest = (exist(fullnameext)==2);
2170 end
2171 end
2172 end
2173 if ( exist(dirname)~=7 & ~strcmp(dirname,[ '.' filesep ]) ...
2174 & ~strcmp(dirname,filesep) )
2175 error([ 'Directory ' dirname ' does not exist.' ] )
2176 end
2177
2178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2179
2180 function [dirname,basename] = splitfilename(filename);
2181 % splits filename into dir and base
2182 slashpos = findstr(filename,filesep);
2183 nslash = length(slashpos);
2184 nfilename = length(filename);
2185 if nslash
2186 dirname = filename(1:slashpos(nslash));
2187 basename = filename(slashpos(nslash)+1:nfilename);
2188 else
2189 dirname = pwd;
2190 nn=length(dirname);
2191 if ~strcmp(dirname(nn),filesep)
2192 dirname = [ dirname filesep ];
2193 end
2194 basename = filename;
2195 end
2196
2197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2198
2199 function yesno = is3d(haxes);
2200 % tries to figure out if axes is 3D
2201 yesno = 0;
2202 CameraPosition = get(haxes,'CameraPosition');
2203 CameraTarget = get(haxes,'CameraTarget');
2204 CameraUpVector = get(haxes,'CameraUpVector');
2205 if CameraPosition(1)~=CameraTarget(1)
2206 yesno = 1;
2207 end
2208 if CameraPosition(2)~=CameraTarget(2)
2209 yesno = 1;
2210 end
2211 if any(CameraUpVector~=[0 1 0])
2212 yesno = 1;
2213 end
2214
2215 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2216
2217 function b = celltoarray(a);
2218 % converts a cell of doubles to an array
2219 if iscell(a),
2220 b = [];
2221 for i=1:length(a),
2222 b = [b a{i}];
2223 end
2224 else,
2225 b = a(:)';
2226 end
2227
2228 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2229
2230 function b = chartocell(a)
2231 % converts a character array into a cell array of characters
2232
2233 % convert to cell
2234 if isa(a,'char')
2235 n = size(a,1);
2236 b = cell(1,n);
2237 for j=1:n
2238 b{j}=a(j,:);
2239 end
2240 else
2241 b = a;
2242 end
2243 % convert to char
2244 n=length(b);
2245 for j=1:n
2246 if isa(b{j},'double')
2247 b{j} = num2str(b{j});
2248 end
2249 end
2250
2251 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2252
2253 function b = overwritetail(a,k)
2254 % overwrites tail of a by k
2255 % a,b: strings
2256 % k: integer
2257 ks = int2str(k);
2258 b = [ a(1:(length(a)-length(ks))) ks ];
2259
2260 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2261
2262 function [rgb,isc] = char2rgb(c,c0)
2263 % convert color definitions from character to rgb-vector
2264
2265 isc = 1;
2266 if ~ischar(c)
2267 rgb = c;
2268 else
2269 switch c
2270 case {'y','yellow'}
2271 rgb = [1 1 0];
2272 case {'m','magenta'}
2273 rgb = [1 0 1];
2274 case {'c','cyan'}
2275 rgb = [0 1 1];
2276 case {'r','red'}
2277 rgb = [1 0 0];
2278 case {'g','green'}
2279 rgb = [0 1 0];
2280 case {'b','blue'}
2281 rgb = [0 0 1];
2282 case {'w','white'}
2283 rgb = [1 1 1];
2284 case {'k','black'}
2285 rgb = [0 0 0];
2286 case 'none'
2287 if nargin==2
2288 rgb = char2rgb(c0);
2289 else
2290 rgb = [1 1 1];
2291 end
2292 isc = 0;
2293 otherwise
2294 warning('LaPrint:general',['Unknown Color: ''' c ...
2295 '''. Taking black.'])
2296 rgb = [0 0 0];
2297 end
2298 end
2299
2300 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2301
2302 function v = value01(val,opt)
2303 % convert off/on to 0/1
2304
2305 if nargin==2
2306 txt = ['Value of ' opt ' must be ''on'' or ''off'''];
2307 else
2308 txt = ['Value must be ''on'' or ''off'''];
2309 end
2310
2311 if ~isa(val,'char')
2312 error(txt)
2313 end
2314 val = lower(strrep(val,' ',''));
2315 switch val
2316 case 'on'
2317 v = 1;
2318 case 'off'
2319 v = 0;
2320 otherwise
2321 error(txt)
2322 end
2323 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2324
2325 function v = valueyn(val)
2326 % convert 0/1 to off/on
2327
2328 if ~isa(val,'double')
2329 error([ 'Value must be ''0'' or ''1'''])
2330 end
2331 switch val
2332 case 0
2333 v = 'off';
2334 case 1
2335 v = 'on';
2336 otherwise
2337 error([ 'Value must be ''0'' or ''1'''])
2338 end
2339
2340 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2341
2342 function sethf(hf,LAPRINTHAN,LAPRINTOPT)
2343 % store in UserData of gui
2344
2345 set(hf,'UserData',{LAPRINTHAN,LAPRINTOPT})
2346
2347 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2348
2349 function [LAPRINTHAN,LAPRINTOPT]=gethf(hf)
2350 % load from UserData of gui
2351
2352 d=get(hf,'UserData');
2353 LAPRINTHAN=d{1};
2354 LAPRINTOPT=d{2};
2355
2356 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2357
2358 function opt = prefsettings
2359 if ispref('LaPrint','LAPRINTOPT')
2360 opt = getpref('LaPrint','LAPRINTOPT');
2361 else
2362 opt = [];
2363 end
2364
2365 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2366
2367 function opt=factorysettings
2368
2369 % try to find LaTeX and friends
2370 if ispc
2371 try
2372 latexpath = winqueryreg('HKEY_LOCAL_MACHINE',...
2373 'SOFTWARE\MiK\MiKTeX\CurrentVersion\MiKTeX','Install Root');
2374 latexcmd = [latexpath '\miktex\bin\latex.exe -halt-on-error '...
2375 '-interaction nonstopmode <viewfile>.tex'];
2376 dvipscmd = [latexpath '\miktex\bin\dvips.exe -D600 -E* '...
2377 '-o<viewfile>.eps <viewfile>.dvi'];
2378 catch % hoping the path variable is properly set
2379 latexcmd = ['latex.exe -halt-on-error '...
2380 '-interaction nonstopmode <viewfile>.tex'];
2381 dvipscmd = ['dvips.exe -D600 -E* '...
2382 '-o<viewfile>.eps <viewfile>.dvi'];
2383 end
2384 epstoolcmd = ['C:\Ghostgum\epstool\bin\epstool.exe '...
2385 '--bbox --copy --output '...
2386 '<filename>_final.eps <viewfile>.eps'];
2387 delcmd = ['del <viewfile>.eps <viewfile>.dvi ',...
2388 '<viewfile>.aux <viewfile>.log ',...
2389 '<viewfile>.pfg'];
2390 gsviewcmd = 'C:\Ghostgum\gsview\gsview32.exe <filename>_final.eps&';
2391 else % hoping the path variable is properly set
2392 latexcmd = ['latex -halt-on-error '...
2393 '-interaction nonstopmode <viewfile>.tex'];
2394 dvipscmd = ['dvips -D600 -E* '...
2395 '-o<viewfile>.eps <viewfile>.dvi'];
2396 epstoolcmd = ['epstool --bbox --copy --output '...
2397 '<filename>_final.eps <viewfile>.eps'];
2398 delcmd = ['rm <viewfile>.eps <viewfile>.dvi ',...
2399 '<viewfile>.aux <viewfile>.log ',...
2400 '<viewfile>.pfg'];
2401 gsviewcmd = 'ghostview <filename>_final.eps&';
2402 end
2403
2404 vers = version;
2405 vers = eval(vers(1:3));
2406 if vers < 6.5
2407 colorvalue=0;
2408 else
2409 colorvalue=1;
2410 end
2411
2412 opt = struct(...
2413 'figno',{1},...
2414 'filename','unnamed',...
2415 'width',12,...
2416 'factor',0.8,...
2417 'scalefonts',1,...
2418 'keepfontprops',0,...
2419 'asonscreen',0,...
2420 'keepticklabels',0,...
2421 'mathticklabels',0,...
2422 'head',1,...
2423 'comment','',...
2424 'caption','',...
2425 'extrapicture',0,...
2426 'nzeros',3,...
2427 'verbose',0,...
2428 'figcopy',1,...
2429 'printcmd',['print(''-f<figurenumber>'',' ...
2430 '''-depsc'',''-painters'','...
2431 '''<filename.eps>'')'],...
2432 'package','graphicx',...
2433 'color',colorvalue,...
2434 'createview',0,...
2435 'viewfilename','unnamed_',...
2436 'processview',0,...
2437 'cmd1',latexcmd,...
2438 'cmd2',dvipscmd,...
2439 'cmd3',epstoolcmd,...
2440 'cmd4',delcmd,...
2441 'cmd5',gsviewcmd,...
2442 'cmd6','',...
2443 'cmd7','',...
2444 'cmd8','');
2445
2446 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2447
2448 function updategui(LAPRINTHAN,LAPRINTOPT)
2449 % update gui
2450
2451 set(LAPRINTHAN.figno,'string',num2str(LAPRINTOPT.figno))
2452 set(LAPRINTHAN.filename,'string',LAPRINTOPT.filename)
2453 % width, factor, scalefonts
2454 if LAPRINTOPT.keepfontprops
2455 set(LAPRINTHAN.keepfontprops,'check','on')
2456 else
2457 set(LAPRINTHAN.keepfontprops,'check','off')
2458 end
2459 if LAPRINTOPT.asonscreen
2460 set(LAPRINTHAN.asonscreen,'check','on')
2461 else
2462 set(LAPRINTHAN.asonscreen,'check','off')
2463 end
2464 if LAPRINTOPT.keepticklabels
2465 set(LAPRINTHAN.keepticklabels,'check','on')
2466 else
2467 set(LAPRINTHAN.keepticklabels,'check','off')
2468 end
2469 if LAPRINTOPT.mathticklabels
2470 set(LAPRINTHAN.mathticklabels,'check','on')
2471 else
2472 set(LAPRINTHAN.mathticklabels,'check','off')
2473 end
2474 if LAPRINTOPT.head
2475 set(LAPRINTHAN.head,'check','on')
2476 else
2477 set(LAPRINTHAN.head,'check','off')
2478 end
2479 % comment, caption
2480 if LAPRINTOPT.extrapicture
2481 set(LAPRINTHAN.extrapicture,'check','on')
2482 else
2483 set(LAPRINTHAN.extrapicture,'check','off')
2484 end
2485 % nzeros
2486 if LAPRINTOPT.verbose
2487 set(LAPRINTHAN.verbose,'check','on')
2488 else
2489 set(LAPRINTHAN.verbose,'check','off')
2490 end
2491 if LAPRINTOPT.figcopy
2492 set(LAPRINTHAN.figcopy,'check','on')
2493 else
2494 set(LAPRINTHAN.figcopy,'check','off')
2495 end
2496 % printcmd
2497 switch LAPRINTOPT.package
2498 case 'epsfig'
2499 set(LAPRINTHAN.package_epsfig,'check','on')
2500 set(LAPRINTHAN.package_graphicx,'check','off')
2501 case 'graphicx'
2502 set(LAPRINTHAN.package_epsfig,'check','off')
2503 set(LAPRINTHAN.package_graphicx,'check','on')
2504 end
2505 if LAPRINTOPT.color
2506 set(LAPRINTHAN.color,'check','on')
2507 else
2508 set(LAPRINTHAN.color,'check','off')
2509 end
2510 if LAPRINTOPT.createview
2511 set(LAPRINTHAN.createview,'check','on')
2512 else
2513 set(LAPRINTHAN.createview,'check','off')
2514 end
2515 % viewfilename
2516 if LAPRINTOPT.processview
2517 set(LAPRINTHAN.processview,'check','on')
2518 else
2519 set(LAPRINTHAN.processview,'check','off')
2520 end
2521 % cmd1, cmd2, cmd3, cmd4, cmd5, cmd6, cmd7, cmd8
2522
2523 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2524
2525 function txt = helptext()
2526 % help text
2527 txt={...
2528 '',...
2529 ['LAPRINT prints a figure for inclusion in LaTeX documents. ',...
2530 'It creates an eps-file and a tex-file. The tex-file contains the ',...
2531 'annotation of the figure such as titles, labels and texts. The ',...
2532 'eps-file contains the non-text part of the figure and is called ',...
2533 'by the tex-file. The main advantage of using LaPrint ',...
2534 'is that the annotation can be neatly (e.g., including math ',...
2535 'mode and fancy font constructs) set within LaTeX.'],...
2536 '',...
2537 'Prerequisites:',...
2538 '~~~~~~~~~~~~~~',...
2539 ['Matlab 6.1 or above is required. To process the LaTeX file, a ',...
2540 'LaTeX compiler (including the packages ''graphicx'' and ',...
2541 '''psfrag'') and a dvi-to-postscript converter (like dvips) '...
2542 'is required. Optional tools are a postscript-viewer ',...
2543 '(like ghostview), a postscript bounding box converter ',...
2544 '(like epstool) and the LaTeX packages color ',...
2545 'and epsfig.'],...
2546 '',...
2547 'Installation:',...
2548 '~~~~~~~~~~~~~',...
2549 ['LaPrint comes as a single m-file, which has to be placed ',...
2550 'somewhere in the Matlab search path. If you want LaPrint to ',...
2551 'call LaTeX and friends, the (system dependent) executables have ',...
2552 'to be defined using the GUI (see below).'],...
2553 '',...
2554 'An example to get started:',...
2555 '~~~~~~~~~~~~~~~~~~~~~~~~~~',...
2556 ['It is recommended to switch off the Matlab TeX ',...
2557 'interpreter before creating a graphics to be processed by ',...
2558 'LaPrint:'],...
2559 ' >> set(0,''DefaultTextInterpreter'',''none'')',...
2560 'Create an example graphics using',...
2561 ' >> figure(1), clf',...
2562 ' >> plot([1 2])',...
2563 ' >> xlabel(''$x$'')',...
2564 ' >> ylabel(''A straight line $f(x)=\alpha x + \beta$'')',...
2565 ' >> text(1.1,1.9,{''\textbf{This figure is not exiting.}'',...',...
2566 ' ''(but it shows some features of \texttt{laprint})''})',...
2567 ['Note that the text uses LaTeX constructs like ''$.$'', ',...
2568 '''\alpha'' and ''\textbf{}''. You can employ the full LaTeX ',...
2569 'repertoire here.'],...
2570 ['Open the LaPrint graphical user interface (GUI) ',...
2571 '(if you haven''t already done so), by typing'],...
2572 ' >> laprint',...
2573 ['Check if the GUI points to Figure Number 1, ',...
2574 'and save the graphics by pressing ''Go!''. ',...
2575 'This creates the files ''unnamed.tex'' and ''unnamed.eps''. ',...
2576 'These can be included in a LaTeX document as follows:'],...
2577 ' % This is the LaTeX document testdoc.tex',...
2578 ' \documentclass{article}',...
2579 ' \usepackage{graphicx,color,psfrag}',...
2580 ' \begin{document}',...
2581 ' Here comes a Matlab figure created with \texttt{laprint}:\\',...
2582 ' \input{unnamed}',...
2583 ' \end{document}',...
2584 ['This document can be compiled with LaTeX (to create ',...
2585 '''testdoc.dvi'') and converted to postscript (to create ',...
2586 '''testdoc.ps''). The document ''testdoc.ps'' will contain the ',...
2587 'Matlab graphics with LaTeX annotation. Observe that the ',...
2588 'figure is 12cm wide and that the fonts are scaled to 80% ',...
2589 'of their original size. This is the default behaviour of ',...
2590 'LaPrint, which can be adjusted using ''Options'' in the ',...
2591 'GUI menu bar (as will explained below).'],...
2592 '',...
2593 ['Instead of using the GUI you can also call LaPrint ',...
2594 'from the command line (or from an m-file) as follows:'],...
2595 ' >> laprint(1,''unnamed'')',...
2596 '',...
2597 'This is what LaPrint does:',...
2598 '~~~~~~~~~~~~~~~~~~~~~~~~~~',...
2599 'Basically, LaPrint performs the following tasks:',...
2600 ' - Take a preliminary copy of the figure. ',...
2601 ' - In the preliminary figure, replace all text objects by tags.',...
2602 [' - Save the preliminary figure (with tags) as an eps-file using ',...
2603 'the Matlab ''print'' command.'],...
2604 [' - Create a tex-file which calls the eps-file (using the ',...
2605 '''graphicx'' package) and replaces ',...
2606 'the tags by the original text (using the ''psfrag'' package).'],...
2607 '',...
2608 ['It is instructive to have a look into the tex-file ',...
2609 '(''unnamed.tex'' in the above example). ',...
2610 'If your graphics contains huge amounts of LaTeX-code, then ',...
2611 'you might also consider editing the tex-file with your ',...
2612 'favourate LaTeX editor. You have however to be carefull, ',...
2613 'because LaPrint (using default settings) doesn''t care ',...
2614 'overwriting files.'],...
2615 '',...
2616 'Using the LaPrint GUI: ',...
2617 '~~~~~~~~~~~~~~~~~~~~~~',...
2618 ['The behaviour of LaPrint can be controlled by various settings ',...
2619 'and options. Using the GUI, these can be set using the ''Options'' ',...
2620 'entry in the menu bar. Using LaPrint from the command line, ' ,...
2621 'these can be set by extra input arguments in the form of ',...
2622 'option/value pairs. In the following, the options are explained ',...
2623 'in some detail based on the GUI. Later, a table with the ',...
2624 'command line option/value pairs is given.'],...
2625 '',...
2626 'In the main LaPrint window you can specify',...
2627 ['-- the number of the Matlab figure to be saved (this must be ',...
2628 'the handle of an open Matlab window) and '],...
2629 ['-- the basename of the files to be saved (for instance, if ',...
2630 'the basename is ''unnamed'', then ''unnamed.tex'' and ',...
2631 '''unnamed.eps'' are created;).'],...
2632 '',...
2633 'Via the menu bar you can control the following settings:',...
2634 '',...
2635 'Options --> Sizes and Scalings ...',...
2636 '',...
2637 'This opens a window where you can specify ',...
2638 '-- the width (in cm) of the graphics in the LaTeX document;',...
2639 '-- a scaling factor and',...
2640 '-- whether you want fonts to be scaled.',...
2641 ['The width controls the size of the graphics. Its height ',...
2642 'is computed such that the ratio of width to height of the ',...
2643 'figure on screen is retained. The factor controls the ',...
2644 '''denseness'' of the graphics. For instance, if the width is ',...
2645 'w=12 and the factor is f=0.8, then the graphics in the ',...
2646 'eps-file will have width w/f=15 cm and the tex-file ',...
2647 'scales it down to 12 cm. This means that lines become thinner ',...
2648 'and fonts become smaller (as compared to w=12; f=1.0). ',...
2649 'Good values for papers are f=0.8 to f=1.0, ',...
2650 'and f=1.5 is a good value for presentations. ',...
2651 'Switching font scaling off only scales the graphics. ',...
2652 'You may want to experiment with some w/f/scalefont combinations ',...
2653 'to find out your personal preference. '],...
2654 '',...
2655 'Options --> Translate Matlab Font Properties to LaTeX ',...
2656 '',...
2657 ['This option can be switched on/off. When off, all text ',...
2658 'will be set using the LaTeX font which is active while ',...
2659 'entering the tex-file (Matlab font settings are ignored). When ',...
2660 'on, Matlab font settings are translated to LaTeX font ',...
2661 'settings.'],...
2662 '',...
2663 'Options --> Print Limits and Ticks as on Screen',...
2664 '',...
2665 ['This option can be switched on/off. When on, the axes ',...
2666 'limits and ticks are frozen. They appear in the LaTeX ',...
2667 'document as on screen. When off, they are adapted by ',...
2668 'Matlab.'],...
2669 '',...
2670 'Options --> Keep Tick Labels within eps File',...
2671 '',...
2672 ['This option can be switched on/off. When on, the tick ',...
2673 'labels aren''t replaced by their LaTeX equivalents. This is ',...
2674 'useful for some 3D-plots.'],...
2675 '',...
2676 'Options --> Set Tick Labels in LaTeX Math Mode',...
2677 '',...
2678 ['This option can be switched on/off. When on, the tick ',...
2679 'labels are surrounded by a ''$''.'],...
2680 '',...
2681 'Options --> Equip the tex File with a Head',...
2682 '',...
2683 ['This option can be switched on/off. When on, the tex-file ',...
2684 'is equipped with a header with a bunch of comments (date, files, ',...
2685 'example, comment text,...).'],...
2686 '',...
2687 'Options --> Comment in the Head of the tex File ...',...
2688 '',...
2689 ['This opens a window where you can specify a comment to be ',...
2690 'placed in the header of the tex file.'],...
2691 '',...
2692 'Options --> Place a LaTeX caption in the tex File ...',...
2693 '',...
2694 ['This opens a window where you can enter a caption text. If this ',...
2695 'caption text is nonempty, it is placed as a \caption{} ',...
2696 'into the tex-file. Thus the text will appear in the LaTeX ',...
2697 'document. In addition a \label{} is placed in the tex-file ',...
2698 'which can be used to refer to the graphics. The label will ',...
2699 'be fig: followed by the basename of the files, e.g., ',...
2700 '\label{fig:unnamed}.'],...
2701 '',...
2702 'Options --> Place an Extra Picture in each Axes',...
2703 '',...
2704 ['This option can be switched on/off. When on, each axes in the ',...
2705 'figure is equipped with an empty LaTeX ''picture'' environment. ',...
2706 'It can be used to place some additional material into the ',...
2707 'figure by editing the tex-file.'],...
2708 '',...
2709 'Options --> Length of the psfrag Replacement Strings ...',...
2710 '',...
2711 ['This opens a window where you can enter the length of the ',...
2712 'psfrag tags. If you have huge amounts of text, the default ',...
2713 'length of 3 might not suffice.'],...
2714 '',...
2715 'Options --> Call LaPrint in verbose mode',...
2716 '',...
2717 ['This option can be switched on/off. When on, LaPrint issues ',...
2718 'some messages and warns before overwriting files.'],...
2719 '',...
2720 'Options --> Copy Figure and Modify that Copy',...
2721 '',...
2722 ['This option can be switched on/off. When on, LaPrint takes ',...
2723 'a copy of the figure to be printed and places its tags into ',...
2724 'that copy. When done, the copy is deleted. When off, the ',...
2725 'figure is messed up by tags. It gets unusable, but you can see ',...
2726 'what LaPrint is doing. Besides, there are bugs in the Matlab ',...
2727 '''copyobj'' command. If these show up, this option is useful.'],...
2728 '',...
2729 'Options --> Matlab Print Command ...',...
2730 '',...
2731 ['This opens a window where you can enter the Matlab command to ',...
2732 'save the graphics in an eps-file. You can modify the standard ',...
2733 'print command to include or remove options (like ''-loose'') ',...
2734 'or employ a different command (like exportfig). '],...
2735 '',...
2736 'Options --> Matlab Graphics Package',...
2737 '',...
2738 'You can chose between ''graphicx'' and ''epsfig''.',...
2739 '',...
2740 'Options --> Use LaTeX ''color'' package',...
2741 '',...
2742 ['This option can be switched on/off. When on, LaPrint places ',...
2743 'color commands into the tex file to optain colored text.'],...
2744 '',...
2745 'Options --> View File ... --> Create a View File',...
2746 '',...
2747 ['This option can be switched on/off. When on, LaPrint creates ',...
2748 'a third file (the view-file), which is a complete LaTeX ',...
2749 'document showing the graphics. You can process this file ',...
2750 'with your favourate LaTeX- and dvi-to-postscript compiler. ',...
2751 'This is useful to have a quick look at the result and to ',...
2752 'create a futher eps-file containing everything (see below). ',...
2753 'The process of compiling the view-file can be automated using ',...
2754 'the options described below.'],...
2755 '',...
2756 'Options --> View File ... --> Name of the View File',...
2757 '',...
2758 ['This opens a window where you can enter the name of the ',...
2759 'view-file to be created.'],...
2760 '',...
2761 'Options --> View File ... --> Process the View File',...
2762 '',...
2763 ['This option can be switched on/off. When on, LaPrint ',...
2764 'calls the LaTeX compiler and its friends to process the ',...
2765 'view file. The names of the executables to be used and ',...
2766 'their syntax can be set using the following option. '],...
2767 '',...
2768 ['Options --> View File ... --> Executables for processing ',...
2769 'View File'],...
2770 '',...
2771 ['This opens a window where you can enter the names of up to 8 ',...
2772 'system commands to process the view-file. If you have less than 8 ',...
2773 'programs, you can leave the some of the fields empty. In all ',...
2774 'commands, LaPrint internally replaces the tag ''<viewfile>'' ',...
2775 'by the basename of the viewfile and the tag <filename> by ',...
2776 'the basename specified in the main LaPrint window. ',...
2777 'In following example you have to add the paths, if the ',...
2778 'commands are not in the system search path.'],...
2779 '',...
2780 'To create and view a ps document:',...
2781 ' cmd1: latex <viewfile>.tex',...
2782 ' cmd2: dvips -o<viewfile>.ps <viewfile>.dvi',...
2783 ' cmd3: gsview32 <viewfile>.ps (ghostview for Unix)',...
2784 '',...
2785 '',...
2786 'Preferences:',...
2787 '~~~~~~~~~~~~',...
2788 ['All options and settings of LaPrint can be ',...
2789 '(internally and externally) stored ',...
2790 'in ''Preferences''. Suppose that you have changed, via ',...
2791 'the ''Options'' menu bar entry, the settings of LaPrint. ',...
2792 'You can make these settings to your preferred (default) ',...
2793 'settings by chosing'],...
2794 '',...
2795 'Preferences --> Set Preferences to Current Settings',...
2796 '',...
2797 ['This means that future sessions of LaPrint load these ',...
2798 'settings on startup. You can also manually reload these ',...
2799 'settings by chosing'],...
2800 '',...
2801 'Preferences --> Get Preferences',...
2802 '',...
2803 ['LaPrint has built-in (factory default) preferences, ',...
2804 'which you see when using ',...
2805 'LaPrint the first time. You can restore these defaults ',...
2806 'by chosing'],...
2807 '',...
2808 'Preferences --> Get Factory Defaults',...
2809 '',...
2810 ['If you want your personal preferences be completely removed ',...
2811 '(switching back to factory defaults on startup), you should ',...
2812 'chose'],...
2813 '',...
2814 'Preferences --> Remove Preferences',...
2815 '',...
2816 ['If you have multiple projects running and want to use different ',...
2817 'settings simultaneously, you can save/load preferences ',...
2818 'to/from mat-files by chosing'],...
2819 '',...
2820 'Preferences --> Save Current Settings to a File ',...
2821 'Preferences --> Load Settings from a File ',...
2822 '',...
2823 'These open a new window asking for the name of a .mat file.',...
2824 '',...
2825 'Using LaPrint from the command line:',...
2826 '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~',...
2827 ['When using LaPrint from the command line (or from an m-file), ',...
2828 'the following syntax is required:'],...
2829 '',...
2830 ' laprint(figno,filename)',...
2831 ' laprint(figno,filename,opta,vala,optb,valb,..)',...
2832 '',...
2833 'where',...
2834 ' figno : integer, figure to be printed',...
2835 ' filename : string (character array), basename of files',...
2836 ' to be created',...
2837 ' opta,vala,.. : option and value pairs, where opta is one',...
2838 ' of the following options and vala is',...
2839 ' the corresponding value.',...
2840 '',...
2841 ['When calling LaPrint from the command line without ',...
2842 'option/value pairs, it uses the same '],...
2843 ['settings/options as the GUI on startup. This means that ',...
2844 'it uses'],...
2845 ['-- the factory default settings (if you havn''t ',...
2846 'stored your personal preferences using the GUI) or '],...
2847 '-- your personal preferences. ',...
2848 'The factory default settings can be enforced by typing ',...
2849 ' laprint(figno,filename,''options'',''factory'')',...
2850 ['These settings can be overwritten by option/value pairs ',...
2851 'as explained in the following table.'],...
2852 '',...
2853 'option |class/val.| remark',...
2854 '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~',...
2855 '''width'' | <double> | width of the figure in the LaTeX',...
2856 ' | | document (in cm).',...
2857 '''factor'' | <double> | factor by which the figure in ',...
2858 ' | | the LaTeX document is smaller than ',...
2859 ' | | the figure in the postscript file.',...
2860 '''scalefonts'' |''on''/''off''| scales the fonts with the ',...
2861 ' | | figure (see option ''factor'').',...
2862 '''keepfontprops'' |''on''/''off''| translates MATLAB font',...
2863 ' | | properties (size, width, angle) into',...
2864 ' | | corresponding LaTeX font properties.',...
2865 '''asonscreen'' |''on''/''off''| prints ticks and lims ',...
2866 ' | | ''as on screen''.',...
2867 '''keepticklabels''|''on''/''off''| keeps the tick labels within',...
2868 ' | | the eps-file (not using LaTeX).',...
2869 '''mathticklabels''|''on''/''off''| tick labels are set in LaTeX',...
2870 ' | | math mode',...
2871 '''head'' |''on''/''off''| places a commenting header in ',...
2872 ' | | the tex-file.',...
2873 '''comment'' | <string> | places the comment <string> into',...
2874 ' | | the header of the tex-file.',...
2875 '''caption'' | <string> | adds \caption{<string>} and',...
2876 ' | | \label{fig:<filename>} to the',...
2877 ' | | tex-file.',...
2878 '''extrapicture'' |''on''/''off''| adds empty picture environments',...
2879 ' | | to the axes.',...
2880 '''nzeros'' | <int> | uses replacement strings of',...
2881 ' | | length <int> in the eps-file.',...
2882 '''verbose'' |''on''/''off''| verbose mode; asks before',...
2883 ' | | overwriting files and issues some ',...
2884 ' | | more messages.',...
2885 '''figcopy'' |''on''/''off''| directly modifies the original',...
2886 ' | | figure.',...
2887 '''printcmd'' | <string> | uses ''<string>'' as Matlab print',...
2888 ' | | command.',...
2889 '''package'' | <string> | uses the LaTeX graphics package',...
2890 ' | | ''<string>''. Possible values are',...
2891 ' | | ''graphicx'' and ''epsfig''.',...
2892 '''color'' |''on''/''off''| uses colored fonts (using the',...
2893 ' | | LaTeX ''color'' package).',...
2894 '''createview'' |''on''/''off''| creates a view-file, which ',...
2895 ' | | calls the tex-file.',...
2896 '''viewfilename'' | <string> | Basename of the view-file.',...
2897 '''processview'' |''on''/''off''| processes the view-file ',...
2898 ' | | by LaTeX and friends.',...
2899 '''cmd1'' | <string> | 1st Command in the sequence of',...
2900 ' | | LaTeX and friends (enter an empty',...
2901 ' | | string to skip this command).',...
2902 '''cmd2'' | <string> | 2nd LaTeX/friend Command ',...
2903 '''cmd3'' | <string> | 3rd LaTeX/friend Command ',...
2904 '''cmd4'' | <string> | 4th LaTeX/friend Command ',...
2905 '''cmd5'' | <string> | 5th LaTeX/friend Command ',...
2906 '''cmd6'' | <string> | 6th LaTeX/friend Command ',...
2907 '''cmd7'' | <string> | 7th LaTeX/friend Command ',...
2908 '''cmd8'' | <string> | 8th LaTeX/friend Command ',...
2909 '''options'' | <string> | This option can be used to ',...
2910 ' | | employ project-dependent ',...
2911 ' | | preferences as follows:',...
2912 ' | | 1) Save your preferences to a file ',...
2913 ' | | using the GUI:',...
2914 ' | | Preferences --> ',...
2915 ' | | Save Current Settings to a file',...
2916 ' | | 2) Reload these preferences',...
2917 ' | | with laprint:',...
2918 ' | | >> laprint(1,''unnamed'',..',...
2919 ' | | ''options'',<string>)',...
2920 ' | | where <string> is the name of ',...
2921 ' | | the mat-file with preferences.',...
2922 '',...
2923 '',...
2924 ' ...................... ENJOY ! .......................',...
2925 '',...
2926 };