/laprint_org.m

https://github.com/sievers/matlab · Objective C · 2929 lines · 2727 code · 202 blank · 0 comment · 333 complexity · 7841c464dbcdf596e227fd1b439b2028 MD5 · raw file

Large files are truncated click here to view the full file

  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. % (c) Arno Linnemann. All rights reserved.
  24. % The author of this program assumes no responsibility for any errors
  25. % or omissions. In no event shall he be liable for damages arising out of
  26. % any use of the software. Redistribution of the unchanged file is allowed.
  27. % Distribution of changed versions is allowed provided the file is renamed
  28. % and the source and authorship of the original version is acknowledged in
  29. % the modified file.
  30. % Please report bugs, suggestions and comments to:
  31. % Arno Linnemann
  32. % Control and Automation
  33. % Department of Electrical and Computer Engineering
  34. % University of Kassel
  35. % 34109 Kassel
  36. % Germany
  37. % mailto:linnemann@uni-kassel.de
  38. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  39. %%%%
  40. %%%% Initialize
  41. %%%%
  42. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  43. laprintident = '3.16 (13.9.2004)';
  44. vers = version;
  45. vers = eval(vers(1:3));
  46. if vers < 6.1
  47. error('Sorry. Matlab 6.1 or above is required.')
  48. end
  49. hf=131;
  50. hhf=132;
  51. % no output
  52. if nargout
  53. error('No output argument, please.')
  54. end
  55. inter=get(0,'defaulttextinterpreter');
  56. if ~strcmp(inter,'none')
  57. warning('LaPrint:general',['It is recommended to switch off the '...
  58. 'text interpreter\nbefore creating a figure to be saved '...
  59. 'with LaPrint. Use the command\n',...
  60. ' >> set(0,''defaulttextinterpreter'',''none'').'])
  61. end
  62. if nargin==0
  63. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  64. %%%%
  65. %%%% GUI
  66. %%%%
  67. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  68. try
  69. delete(hf)
  70. end
  71. try
  72. delete(hhf)
  73. end
  74. %---------------------------------
  75. % open window
  76. %---------------------------------
  77. hf = figure(hf);
  78. clf reset;
  79. set(hf,'NumberTitle','off',...
  80. 'Name','LaPrint (LaTeX Print)',...
  81. 'Units','points',...
  82. 'CloseRequestFcn','laprint(''quit'');',...
  83. 'menubar','none')
  84. h = uicontrol('Parent',hf,'Units','points');
  85. fsize = get(h,'Fontsize');
  86. delete(h)
  87. posf = get(hf,'Position');
  88. figheight = 10*fsize;
  89. figwidth = 32*fsize;
  90. posf = [ posf(1) posf(2)+posf(4)-figheight figwidth figheight];
  91. set(hf,'Position',posf)
  92. uicontrol('Parent',hf,'style','frame','Units','points',...
  93. 'Position',[0 0 figwidth figheight])
  94. curh = figheight-0*fsize;
  95. LAPRINTHAN=struct('figno',{0},'filename',{0},...
  96. 'keepfontprops',{0},'asonscreen',{0},'keepticklabels',{0},...
  97. 'mathticklabels',{0},'head',{0},'extrapicture',{0},...
  98. 'verbose',{0},'figcopy',{0},'package_epsfig',{0},...
  99. 'package_graphicx',{0},'color',{0},'createview',{0},...
  100. 'processview',{0});
  101. %---------------------------------
  102. % figure no.
  103. %---------------------------------
  104. loch = 1.7*fsize;
  105. curh = curh-loch-1.5*fsize;
  106. h = uicontrol('Parent',hf,...
  107. 'style','text',...
  108. 'Units','points',...
  109. 'Position',[1*fsize curh 18*fsize loch],...
  110. 'HorizontalAlignment','left',...
  111. 'string','Number of Figure to be saved:');
  112. h = uicontrol('Parent',hf,...
  113. 'style','edit',...
  114. 'Units','points',...
  115. 'Position',[19*fsize curh 12*fsize loch],...
  116. 'HorizontalAlignment','left',...
  117. 'BackgroundColor',[1 1 1],...
  118. 'Callback','laprint(''figno'');');
  119. LAPRINTHAN.figno = h;
  120. %---------------------------------
  121. % filename
  122. %---------------------------------
  123. loch = 1.7*fsize;
  124. curh = curh-loch-1*fsize;
  125. h = uicontrol('Parent',hf,...
  126. 'style','text',...
  127. 'Units','points',...
  128. 'Position',[1*fsize curh 18*fsize loch],...
  129. 'HorizontalAlignment','left',...
  130. 'string','Basename of Files to be Created:');
  131. h = uicontrol('Parent',hf,...
  132. 'style','edit',...
  133. 'Units','points',...
  134. 'Position',[19*fsize curh 12*fsize loch],...
  135. 'HorizontalAlignment','left',...
  136. 'BackgroundColor',[1 1 1],...
  137. 'Callback','laprint(''filename'');');
  138. LAPRINTHAN.filename = h;
  139. %---------------------------------
  140. % save, quit
  141. %---------------------------------
  142. loch = 2*fsize;
  143. curh = curh-loch-1*fsize;
  144. h = uicontrol('Parent',hf,...
  145. 'Style','pushbutton',...
  146. 'Units','Points',...
  147. 'Position',[19*fsize curh 5*fsize loch],...
  148. 'HorizontalAlignment','center',...
  149. 'String','Go !',...
  150. 'Callback','laprint(''save'');');
  151. h = uicontrol('Parent',hf,...
  152. 'Style','pushbutton',...
  153. 'Units','Points',...
  154. 'Position',[26*fsize curh 5*fsize loch],...
  155. 'HorizontalAlignment','center',...
  156. 'String','Quit',...
  157. 'Callback','laprint(''quit'');');
  158. %---------------------------------
  159. % options uimenue
  160. %---------------------------------
  161. hm1 = uimenu('label','Options');
  162. uimenu(hm1,...
  163. 'label','Sizes and Scalings ...',...
  164. 'callback','laprint(''size'')');
  165. LAPRINTHAN.keepfontprops = uimenu(hm1,...
  166. 'label','Translate Matlab Font Properties to LaTeX',...
  167. 'callback','laprint(''keepfontprops'')');
  168. LAPRINTHAN.asonscreen = uimenu(hm1,...
  169. 'label','Print Limits and Ticks as on Screen',...
  170. 'separator','on',...
  171. 'callback','laprint(''asonscreen'')');
  172. LAPRINTHAN.keepticklabels = uimenu(hm1,...
  173. 'label','Keep Tick Labels within eps File',...
  174. 'callback','laprint(''keepticklabels'')');
  175. LAPRINTHAN.mathticklabels = uimenu(hm1,...
  176. 'label','Set Tick Labels in LaTeX Math Mode',...
  177. 'callback','laprint(''mathticklabels'')');
  178. LAPRINTHAN.head = uimenu(hm1,...
  179. 'label','Equip the tex File with a Head',...
  180. 'separator','on',...
  181. 'callback','laprint(''head'')');
  182. uimenu(hm1,...
  183. 'label','Comment in the Head of the tex File ...',...
  184. 'callback','laprint(''comment'')');
  185. uimenu(hm1,...
  186. 'label','Place a LaTeX Caption in the tex File ...',...
  187. 'callback','laprint(''caption'')');
  188. LAPRINTHAN.extrapicture = uimenu(hm1,...
  189. 'label','Place an Extra Picture in each Axes',...
  190. 'callback','laprint(''extrapicture'')');
  191. uimenu(hm1,...
  192. 'label','Length of psfrag Replacement Strings ...',...
  193. 'callback','laprint(''nzeros'')');
  194. LAPRINTHAN.verbose = uimenu(hm1,...
  195. 'label','Call LaPrint in Verbose Mode',...
  196. 'separator','on',...
  197. 'callback','laprint(''verbose'')');
  198. LAPRINTHAN.figcopy = uimenu(hm1,...
  199. 'label','Copy Figure and Modify that Copy',...
  200. 'callback','laprint(''figcopy'')');
  201. uimenu(hm1,...
  202. 'label','Matlab Print Command ...',...
  203. 'separator','on',...
  204. 'callback','laprint(''printcmd'')');
  205. h=uimenu(hm1,...
  206. 'separator','on',...
  207. 'label','LaTeX Graphics Package');
  208. LAPRINTHAN.package_graphicx = uimenu(h,...
  209. 'label','graphicx',...
  210. 'callback','laprint(''package_graphicx'')');
  211. LAPRINTHAN.package_epsfig = uimenu(h,...
  212. 'label','epsfig',...
  213. 'callback','laprint(''package_epsfig'')');
  214. LAPRINTHAN.color = uimenu(hm1,...
  215. 'label','Use LaTeX ''color'' Package',...
  216. 'callback','laprint(''color'')');
  217. h = uimenu(hm1,...
  218. 'label','View File ...',...
  219. 'separator','on');
  220. LAPRINTHAN.createview = uimenu(h,...
  221. 'label','Create a View File',...
  222. 'callback','laprint(''createview'')');
  223. uimenu(h,...
  224. 'label','Name of the View File ...',...
  225. 'callback','laprint(''viewfilename'')');
  226. LAPRINTHAN.processview = uimenu(h,...
  227. 'label','Process the View File',...
  228. 'separator','on',...
  229. 'callback','laprint(''processview'')');
  230. uimenu(h,...
  231. 'label','Executables for Processing View File...',...
  232. 'callback','laprint(''cmdsview'')');
  233. %---------------------------------
  234. % Preferences uimenue
  235. %---------------------------------
  236. hm3=uimenu('label','Preferences');
  237. uimenu(hm3,...
  238. 'label','Get Preferences',...
  239. 'callback','laprint(''getpref'')')
  240. uimenu(hm3,...
  241. 'label','Set Preferences to Current Settings',...
  242. 'callback','laprint(''setpref'')')
  243. uimenu(hm3,...
  244. 'label','Remove Preferences',...
  245. 'callback','laprint(''rmpref'')')
  246. uimenu(hm3,...
  247. 'label','Save Current Settings to a File ...',...
  248. 'separator','on',...
  249. 'callback','laprint(''savepref'')')
  250. uimenu(hm3,...
  251. 'label','Load Settings from a File ...',...
  252. 'callback','laprint(''loadpref'')')
  253. uimenu(hm3,...
  254. 'label','Get Factory Defaults',...
  255. 'separator','on',...
  256. 'callback','laprint(''factory'')')
  257. %---------------------------------
  258. % Help uimenue
  259. %---------------------------------
  260. hm2=uimenu('label','Help');
  261. uimenu(hm2,...
  262. 'label',['LaPrint Online Help ...'],...
  263. 'callback','laprint(''helpwindow'')');
  264. uimenu(hm2,...
  265. 'label','Get the LaPrint Users Guide',...
  266. 'callback',['web www.uni-kassel.de/fb16/rat/matlab',...
  267. '/laprint/laprintdoc.ps -browser'])
  268. uimenu(hm2,...
  269. 'label',['Look for a newer version of LaPrint ' ...
  270. '(Matlab Central File Exchange)...'],...
  271. 'callback',['web http://www.mathworks.de/matlabcentral/',...
  272. 'fileexchange/loadFile.do?objectId=4638',...
  273. '&objectType=file -browser'])
  274. uimenu(hm2,...
  275. 'label','Version and Author ...',...
  276. 'callback','laprint(''whois'')')
  277. %---------------------------------
  278. % make hf invisible
  279. %---------------------------------
  280. set(hf,'HandleVisibility','callback')
  281. %---------------------------------
  282. % get settings
  283. %---------------------------------
  284. LAPRINTOPT = prefsettings;
  285. if isempty(LAPRINTOPT)
  286. LAPRINTOPT = factorysettings;
  287. end
  288. %---------------------------------
  289. % get figure
  290. %---------------------------------
  291. gcfig=gcf;
  292. if gcfig == hf
  293. allfigs = findobj('type','figure');
  294. allfigs = allfigs(find(allfigs~=hf));
  295. if length(allfigs)
  296. figno = allfigs(1);
  297. else
  298. figure(1)
  299. figno=1;
  300. end
  301. else
  302. figno=gcfig;
  303. end
  304. LAPRINTOPT.figno = figno;
  305. %---------------------------------
  306. % update
  307. %---------------------------------
  308. updategui(LAPRINTHAN,LAPRINTOPT)
  309. sethf(hf,LAPRINTHAN,LAPRINTOPT)
  310. figure(hf)
  311. %---------------------------------
  312. % done
  313. %---------------------------------
  314. return
  315. end % if nargin==0
  316. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  317. %%%%
  318. %%%% callback calls ('factory' and 'getprefs' also
  319. %%%% used from command line)
  320. %%%%
  321. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  322. if isa(figno,'char')
  323. switch figno
  324. case 'figno'
  325. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  326. LAPRINTOPT.figno=eval(get(LAPRINTHAN.figno,'string'));
  327. figure(LAPRINTOPT.figno)
  328. figure(hf)
  329. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  330. case 'filename'
  331. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  332. LAPRINTOPT.filename=get(LAPRINTHAN.filename,'string');
  333. [texfullnameext,texbasenameext,texbasename,texdirname] = ...
  334. getfilenames(LAPRINTOPT.filename,'tex',0);
  335. [epsfullnameext,epsbasenameext,epsbasename,epsdirname] = ...
  336. getfilenames(LAPRINTOPT.filename,'eps',0);
  337. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  338. case 'save'
  339. % lapcmd = [ 'laprint(' int2str(LAPRINTOPT.figno) ...
  340. % ', ''' LAPRINTOPT.filename ''''...
  341. % ', ''options'', LAPRINTOPT)'];
  342. lapcmd = 'laprint({})';
  343. eval(lapcmd)
  344. case 'quit'
  345. delete(hf)
  346. try
  347. delete(hhf)
  348. end
  349. case 'size'
  350. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  351. answer = inputdlg({['Please enter the width (in centimeters) ',...
  352. 'of the graphics in the LaTeX document (The height ',...
  353. 'will be computed such that the aspect ratio of the ',...
  354. 'figure on screen is retained.) :'],...
  355. ['Please enter the factor by which the size of the '...
  356. 'graphics in the LaTeX document differs from the size of the '...
  357. 'Postscipt graphics ( Explaination: A factor <1 scales ',...
  358. 'the picture down. This means that lines become thinner ',...
  359. 'and fonts become smaller. ) :'],...
  360. ['Please specify if you want to scale the fonts along with ',...
  361. 'the graphics (enter ''on'' or ''off'') : '] },...
  362. 'LaPrint Settings',1,{num2str(LAPRINTOPT.width),...
  363. num2str(LAPRINTOPT.factor),...
  364. valueyn(LAPRINTOPT.scalefonts)},'on');
  365. if length(answer)
  366. LAPRINTOPT.width=eval(answer{1});
  367. LAPRINTOPT.factor = eval(answer{2});
  368. LAPRINTOPT.scalefonts = value01(answer{3});
  369. end
  370. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  371. case 'keepfontprops'
  372. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  373. if LAPRINTOPT.keepfontprops==1
  374. LAPRINTOPT.keepfontprops=0;
  375. set(LAPRINTHAN.keepfontprops,'check','off')
  376. else
  377. LAPRINTOPT.keepfontprops=1;
  378. set(LAPRINTHAN.keepfontprops,'check','on')
  379. end
  380. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  381. case 'asonscreen'
  382. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  383. if LAPRINTOPT.asonscreen==1
  384. LAPRINTOPT.asonscreen=0;
  385. set(LAPRINTHAN.asonscreen,'check','off')
  386. else
  387. LAPRINTOPT.asonscreen=1;
  388. set(LAPRINTHAN.asonscreen,'check','on')
  389. end
  390. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  391. case 'keepticklabels'
  392. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  393. if LAPRINTOPT.keepticklabels==1
  394. LAPRINTOPT.keepticklabels=0;
  395. set(LAPRINTHAN.keepticklabels,'check','off')
  396. else
  397. LAPRINTOPT.keepticklabels=1;
  398. set(LAPRINTHAN.keepticklabels,'check','on')
  399. end
  400. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  401. case 'mathticklabels'
  402. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  403. if LAPRINTOPT.mathticklabels==1
  404. LAPRINTOPT.mathticklabels=0;
  405. set(LAPRINTHAN.mathticklabels,'check','off')
  406. else
  407. LAPRINTOPT.mathticklabels=1;
  408. set(LAPRINTHAN.mathticklabels,'check','on')
  409. end
  410. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  411. case 'head'
  412. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  413. if LAPRINTOPT.head==1
  414. LAPRINTOPT.head=0;
  415. set(LAPRINTHAN.head,'check','off')
  416. else
  417. LAPRINTOPT.head=1;
  418. set(LAPRINTHAN.head,'check','on')
  419. end
  420. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  421. case 'comment'
  422. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  423. answer = inputdlg({['Please enter a describing comment to '...
  424. 'be placed into the head of the tex file:']},...
  425. 'LaPrint Settings',1,{LAPRINTOPT.comment},'on');
  426. if length(answer)
  427. LAPRINTOPT.comment = answer{1};
  428. end
  429. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  430. case 'caption'
  431. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  432. answer = inputdlg(['If the following text is nonempty, ' ...
  433. 'then it will be placed as a \caption{} into the tex '...
  434. 'file along with \label{fig:' LAPRINTOPT.filename '}. '...
  435. 'Please enter the caption text:'],...
  436. 'LaPrint Settings',1,{LAPRINTOPT.caption},'on');
  437. if length(answer)
  438. LAPRINTOPT.caption = answer{1};
  439. end
  440. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  441. case 'extrapicture'
  442. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  443. if LAPRINTOPT.extrapicture==1
  444. LAPRINTOPT.extrapicture=0;
  445. set(LAPRINTHAN.extrapicture,'check','off')
  446. else
  447. LAPRINTOPT.extrapicture=1;
  448. set(LAPRINTHAN.extrapicture,'check','on')
  449. end
  450. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  451. case 'nzeros'
  452. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  453. answer = inputdlg({['Please enter length of the psfrag replacement '...
  454. 'strings (must be >= 3) :']},...
  455. 'LaPrint Settings',1,{num2str(LAPRINTOPT.nzeros)},'on');
  456. if length(answer)
  457. LAPRINTOPT.nzeros = max(eval(answer{1}),3);
  458. end
  459. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  460. case 'verbose'
  461. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  462. if LAPRINTOPT.verbose==1
  463. LAPRINTOPT.verbose=0;
  464. set(LAPRINTHAN.verbose,'check','off')
  465. else
  466. LAPRINTOPT.verbose=1;
  467. set(LAPRINTHAN.verbose,'check','on')
  468. end
  469. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  470. case 'figcopy'
  471. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  472. if LAPRINTOPT.figcopy==1
  473. LAPRINTOPT.figcopy=0;
  474. set(LAPRINTHAN.figcopy,'check','off')
  475. else
  476. LAPRINTOPT.figcopy=1;
  477. set(LAPRINTHAN.figcopy,'check','on')
  478. end
  479. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  480. case 'printcmd'
  481. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  482. answer = inputdlg({['Please enter the Matlab command '...
  483. 'to be used for printing the eps file '...
  484. '(LaPrint will internally replace <figurenumber> by the '...
  485. 'number of the figure <filename.eps> by the ' ...
  486. 'eps-filename and <filename> '...
  487. 'by the basename of the file, respectively). You can add options '...
  488. 'here (like ''-loose'') or use a different program '...
  489. 'for printing (like ''exportfig'') :']},...
  490. 'LaPrint Settings',1,{LAPRINTOPT.printcmd},'on');
  491. if length(answer)
  492. LAPRINTOPT.printcmd = answer{1};
  493. end
  494. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  495. case 'package_epsfig'
  496. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  497. LAPRINTOPT.package='epsfig';
  498. set(LAPRINTHAN.package_epsfig,'check','on')
  499. set(LAPRINTHAN.package_graphicx,'check','off')
  500. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  501. case 'package_graphicx'
  502. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  503. LAPRINTOPT.package='graphicx';
  504. set(LAPRINTHAN.package_epsfig,'check','off')
  505. set(LAPRINTHAN.package_graphicx,'check','on')
  506. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  507. case 'color'
  508. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  509. if LAPRINTOPT.color==1
  510. LAPRINTOPT.color=0;
  511. set(LAPRINTHAN.color,'check','off')
  512. else
  513. LAPRINTOPT.color=1;
  514. set(LAPRINTHAN.color,'check','on')
  515. end
  516. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  517. case 'createview'
  518. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  519. if LAPRINTOPT.createview==1
  520. LAPRINTOPT.createview=0;
  521. LAPRINTOPT.processview=0;
  522. set(LAPRINTHAN.createview,'check','off')
  523. set(LAPRINTHAN.processview,'check','off')
  524. else
  525. LAPRINTOPT.createview=1;
  526. set(LAPRINTHAN.createview,'check','on')
  527. end
  528. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  529. case 'viewfilename'
  530. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  531. trydlg=1;
  532. txt=['Please enter the name of the '...
  533. 'viewfile (without extension .tex) : '];
  534. txt2='';
  535. while trydlg
  536. answer = inputdlg({[txt txt2]},...
  537. 'LaPrint Settings',1,{LAPRINTOPT.viewfilename},'on');
  538. if length(answer)
  539. if strcmp(answer{1},LAPRINTOPT.filename)
  540. txt2=['The name must be different from the name of the '...
  541. 'graphics file):'];
  542. else
  543. trydlg=0;
  544. LAPRINTOPT.viewfilename = answer{1};
  545. [viewfullnameext,viewbasenameext,viewbasename,viewdirname] = ...
  546. getfilenames(LAPRINTOPT.viewfilename,'tex',0);
  547. end
  548. else
  549. trydlg=0;
  550. end
  551. end
  552. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  553. case 'processview'
  554. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  555. if LAPRINTOPT.processview==1
  556. LAPRINTOPT.processview=0;
  557. set(LAPRINTHAN.processview,'check','off')
  558. else
  559. LAPRINTOPT.processview=1;
  560. set(LAPRINTHAN.processview,'check','on')
  561. LAPRINTOPT.createview=1;
  562. set(LAPRINTHAN.createview,'check','on')
  563. end
  564. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  565. case 'cmdsview'
  566. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  567. answer = inputdlg({...
  568. ['Please enter up to 8 commands to process the view-file. ',...
  569. 'Leave any of the fields empty, if you have ',...
  570. 'less than 8 commands. ',...
  571. 'In any of the following commands, LaPrint internally '...
  572. 'replaces the tag <viewfile> by the name of the viewfile ',...
  573. 'and the tag <filename> by the basename specified in the ',...
  574. 'main LaPrint Window. ',...
  575. 'At minimum you should enter the commands for the LaTeX ',...
  576. 'compilation and for the dvi-to-postscript conversion ',...
  577. 'here. See the LaPrint Online-Help for futher ',...
  578. 'suggestions. ',...
  579. 'Please enter the 1st command:'],...
  580. 'Please enter the 2nd command:',...
  581. 'Please enter the 3rd command:',...
  582. 'Please enter the 4th command:',...
  583. 'Please enter the 5th command:',...
  584. 'Please enter the 6th command:',...
  585. 'Please enter the 7th command:',...
  586. 'Please enter the 8th command:'},...
  587. 'LaPrint Settings',1,{LAPRINTOPT.cmd1,...
  588. LAPRINTOPT.cmd2,LAPRINTOPT.cmd3,...
  589. LAPRINTOPT.cmd4,LAPRINTOPT.cmd5,LAPRINTOPT.cmd6,...
  590. LAPRINTOPT.cmd7,LAPRINTOPT.cmd8},'on');
  591. if length(answer)==8
  592. LAPRINTOPT.cmd1=answer{1};
  593. LAPRINTOPT.cmd2=answer{2};
  594. LAPRINTOPT.cmd3=answer{3};
  595. LAPRINTOPT.cmd4=answer{4};
  596. LAPRINTOPT.cmd5=answer{5};
  597. LAPRINTOPT.cmd6=answer{6};
  598. LAPRINTOPT.cmd7=answer{7};
  599. LAPRINTOPT.cmd8=answer{8};
  600. end
  601. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  602. case 'getpref'
  603. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  604. out = prefsettings;
  605. if ~isempty(out)
  606. oldfigno = LAPRINTOPT.figno; % keep this!
  607. LAPRINTOPT = out;
  608. LAPRINTOPT.figno = oldfigno;
  609. else
  610. errordlg('No LaPrint preferences available.')
  611. end
  612. updategui(LAPRINTHAN,LAPRINTOPT);
  613. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  614. case 'setpref'
  615. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  616. setpref('LaPrint','LAPRINTOPT',LAPRINTOPT);
  617. case 'rmpref'
  618. if ispref('LaPrint')
  619. rmpref('LaPrint');
  620. else
  621. errordlg('Preference does not exist.')
  622. end
  623. case 'savepref'
  624. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  625. txt = 'Save preferences file ';
  626. [preffile,prefpath]=uiputfile('laprint.mat',txt);
  627. save([prefpath preffile],'LAPRINTOPT');
  628. case 'loadpref'
  629. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  630. txt = ['Load preferences file '...
  631. '(must be previously created by LaPrint)'];
  632. [preffile,prefpath]=uigetfile('laprint.mat',txt);
  633. if ~isequal(preffile,0) & ~isequal(prefpath,0)
  634. oldfigno = LAPRINTOPT.figno; % keep this!
  635. load([prefpath preffile]); % hope file contains correct
  636. LAPRINTOPT.figno = oldfigno; % LAPRINTOPT
  637. updategui(LAPRINTHAN,LAPRINTOPT);
  638. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  639. end
  640. case 'factory'
  641. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  642. out = factorysettings;
  643. if ~isempty(out)
  644. oldfigno = LAPRINTOPT.figno; % keep this!
  645. LAPRINTOPT = out;
  646. LAPRINTOPT.figno = oldfigno;
  647. else
  648. errordlg('No LaPrint preferences available.')
  649. end
  650. updategui(LAPRINTHAN,LAPRINTOPT);
  651. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  652. case 'helpwindow'
  653. hhf=figure(hhf);
  654. set(hhf,'Name','LaPrint Online Help',...
  655. 'Numbertitle','off',...
  656. 'menubar','none',...
  657. 'HandleVisibility','callback',...
  658. 'resize','on',...
  659. 'ResizeFcn','laprint(''helpwindow'');');
  660. hht=uicontrol('Parent',hhf,...
  661. 'style','listbox',...
  662. 'units','normalized',...
  663. 'position',[0.005 0.005 0.9 0.99],...
  664. 'BackgroundColor','w',...
  665. 'Fontsize',12,...
  666. 'foregroundcolor','k',...
  667. 'FontName','FixedWidth',...
  668. 'HorizontalAlignment','left');
  669. [txt,hhtpos]=textwrap(hht,helptext);
  670. set(hht,'string',txt)
  671. set(hht,'position',[0.005 0.005 0.99 0.99])
  672. set(hht,'HandleVisibility','callback')
  673. case 'whois'
  674. msgbox({['This is LaPrint, Version ' laprintident],...
  675. '',...
  676. 'To blame for LaPrint:',...
  677. 'Arno Linnemann','Control and Automation',...
  678. 'Department of Electrical and Computer Engineering',...
  679. 'University of Kassel',...
  680. '34109 Kassel',...
  681. 'Germany',...
  682. 'mailto:linnemann@uni-kassel.de'},...
  683. 'LaPrint Info')
  684. otherwise
  685. error('unknown callback option')
  686. end
  687. return
  688. end % if isa(figno,'char')
  689. % nargin >=1 and ~isa(figno,'char')
  690. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  691. %%%%
  692. %%%% PART 1 of advanced usage:
  693. %%%% Check inputs and initialize
  694. %%%%
  695. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  696. if isa(figno,'cell') % called from GUI (all set)
  697. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  698. figno=LAPRINTOPT.figno;
  699. filename=LAPRINTOPT.filename;
  700. else % advanced usage
  701. % get settings
  702. LAPRINTOPT = prefsettings;
  703. if isempty(LAPRINTOPT)
  704. LAPRINTOPT = factorysettings;
  705. end
  706. % modify prefs
  707. if ~isa(figno,'double')
  708. figno
  709. error('This is not a figure handle.')
  710. end
  711. if ~any(get(0,'children')==figno)
  712. figno
  713. error('This is not a figure handle.')
  714. end
  715. LAPRINTOPT.figno = figno;
  716. if nargin>1
  717. if ~isa(filename,'char')
  718. filename
  719. error('This is not a file name.')
  720. end
  721. LAPRINTOPT.filename=filename;
  722. end
  723. end
  724. % read and check command line options
  725. try % try old usage (Version 2.03)
  726. if nargin <=2
  727. error('lets take new usage')
  728. end
  729. % 2.03 defaults
  730. %width = 12;
  731. width = 5;
  732. factor = 0.8;
  733. scalefonts = 1;
  734. keepfontprops = 0;
  735. asonscreen = 0;
  736. keepticklabels = 0;
  737. mathticklabels = 0;
  738. head = 1;
  739. comment = '';
  740. caption = '';
  741. extrapicture = 1;
  742. nzeros = 5;
  743. verbose = 0;
  744. figcopy = 1;
  745. printcmd = ['print(''-f<figurenumber>'',' ...
  746. '''-deps'',''<filename.eps>'')'];
  747. package = 'epsfig';
  748. color = 0;
  749. createview = 0;
  750. viewfilename = [filename '_'];
  751. processview = 0;
  752. cmd1 = '';
  753. cmd2 = '';
  754. cmd3 = '';
  755. cmd4 = '';
  756. cmd5 = '';
  757. cmd6 = '';
  758. cmd7 = '';
  759. cmd8 = '';
  760. for i=1:nargin-2
  761. if ~isa(varargin{i},'char')
  762. error('Options must be character arrays.')
  763. end
  764. oriopt=varargin{i}(:)';
  765. opt=[ lower(strrep(oriopt,' ','')) ' ' ];
  766. if strcmp(opt(1:7),'verbose')
  767. verbose=1;
  768. elseif strcmp(opt(1:10),'asonscreen')
  769. asonscreen=1;
  770. elseif strcmp(opt(1:14),'keepticklabels')
  771. keepticklabels=1;
  772. elseif strcmp(opt(1:14),'mathticklabels')
  773. mathticklabels=1;
  774. elseif strcmp(opt(1:13),'keepfontprops')
  775. keepfontprops=1;
  776. elseif strcmp(opt(1:14),'noextrapicture')
  777. extrapicture=0;
  778. elseif strcmp(opt(1:14),'noextrapicture')
  779. extrapicture=0;
  780. elseif strcmp(opt(1:5),'loose')
  781. printcmd = ['print(''-f<figurenumber>'',' ...
  782. '''-deps'',''-loose'',''<filename.eps>'')'];
  783. elseif strcmp(opt(1:9),'nofigcopy')
  784. figcopy=0;
  785. elseif strcmp(opt(1:12),'noscalefonts')
  786. scalefonts=0;
  787. elseif strcmp(opt(1:6),'nohead')
  788. head=0;
  789. elseif strcmp(opt(1:7),'caption')
  790. eqpos=findstr(oriopt,'=');
  791. if isempty(eqpos)
  792. caption='Matlab Figure';
  793. else
  794. caption=oriopt(eqpos+1:length(oriopt));
  795. end
  796. elseif strcmp(opt(1:8),'comment=')
  797. eqpos=findstr(oriopt,'=');
  798. comment=oriopt(eqpos(1)+1:length(oriopt));
  799. elseif strcmp(opt(1:9),'viewfile=')
  800. createview=1;
  801. eqpos=findstr(oriopt,'=');
  802. viewfilename=oriopt(eqpos(1)+1:length(oriopt));
  803. elseif strcmp(opt(1:6),'width=')
  804. eval([ opt ';' ]);
  805. elseif strcmp(opt(1:7),'factor=')
  806. eval([ opt ';' ]);
  807. else
  808. error([ 'Option ' varargin{i} ' not recognized.'])
  809. end
  810. end
  811. warning('LaPrint:general',['You are using the old LaPrint '...
  812. 'syntax. This syntax might not be supported in '...
  813. 'future releases of LaPrint.'])
  814. catch % old usage doesn't work, take new one
  815. % restore preferences / factory defaults
  816. width = LAPRINTOPT.width;
  817. factor = LAPRINTOPT.factor;
  818. scalefonts = LAPRINTOPT.scalefonts;
  819. keepfontprops = LAPRINTOPT.keepfontprops;
  820. asonscreen = LAPRINTOPT.asonscreen;
  821. keepticklabels = LAPRINTOPT.keepticklabels;
  822. mathticklabels = LAPRINTOPT.mathticklabels;
  823. head = LAPRINTOPT.head;
  824. comment = LAPRINTOPT.comment;
  825. caption = LAPRINTOPT.caption;
  826. extrapicture = LAPRINTOPT.extrapicture;
  827. nzeros = LAPRINTOPT.nzeros;
  828. verbose = LAPRINTOPT.verbose;
  829. figcopy = LAPRINTOPT.figcopy;
  830. printcmd = LAPRINTOPT.printcmd;
  831. package = LAPRINTOPT.package;
  832. color = LAPRINTOPT.color;
  833. createview = LAPRINTOPT.createview;
  834. viewfilename = LAPRINTOPT.viewfilename;
  835. processview = LAPRINTOPT.processview;
  836. cmd1 = LAPRINTOPT.cmd1;
  837. cmd2 = LAPRINTOPT.cmd2;
  838. cmd3 = LAPRINTOPT.cmd3;
  839. cmd4 = LAPRINTOPT.cmd4;
  840. cmd5 = LAPRINTOPT.cmd5;
  841. cmd6 = LAPRINTOPT.cmd6;
  842. cmd7 = LAPRINTOPT.cmd7;
  843. cmd8 = LAPRINTOPT.cmd8;
  844. if nargin > 2
  845. if rem(nargin,2)
  846. error('Option names/values must appear in pairs.')
  847. end
  848. for i=1:2:nargin-2
  849. if ~isa(varargin{i},'char')
  850. error('Option name must be a character array.')
  851. end
  852. opt = lower(strrep(varargin{i}(:)',' ',''));
  853. val = varargin{i+1}(:)';
  854. switch opt
  855. case 'options'
  856. if isa(val,'char')
  857. if strcmp(val,'factory')
  858. val = factorysettings;
  859. else
  860. load(val)
  861. val = LAPRINTOPT;
  862. end
  863. end
  864. if ~isa(val,'struct')
  865. error('Value of options must be a structure array.')
  866. end
  867. % no error checking here!
  868. width = val.width;
  869. factor = val.factor;
  870. scalefonts = val.scalefonts;
  871. keepfontprops = val.keepfontprops;
  872. asonscreen = val.asonscreen;
  873. keepticklabels = val.keepticklabels;
  874. mathticklabels = val.mathticklabels;
  875. head = val.head;
  876. comment = val.comment;
  877. caption = val.caption;
  878. extrapicture = val.extrapicture;
  879. nzeros = val.nzeros;
  880. verbose = val.verbose;
  881. figcopy = val.figcopy;
  882. printcmd = val.printcmd;
  883. package = val.package;
  884. color = val.color;
  885. createview = val.createview;
  886. viewfilename = val.viewfilename;
  887. processview = val.processview;
  888. cmd1 = val.cmd1;
  889. cmd2 = val.cmd2;
  890. cmd3 = val.cmd3;
  891. cmd4 = val.cmd4;
  892. cmd5 = val.cmd5;
  893. cmd6 = val.cmd6;
  894. cmd7 = val.cmd7;
  895. cmd8 = val.cmd8;
  896. case 'width'
  897. if ~isa(val,'double')
  898. error('Value of width must be a double.')
  899. end
  900. width = val;
  901. case 'factor'
  902. if ~isa(val,'double')
  903. error('Value of factor must be a double.')
  904. end
  905. factor=val;
  906. case 'scalefonts'
  907. scalefonts = value01(val,opt);
  908. case 'keepfontprops'
  909. keepfontprops = value01(val,opt);
  910. case 'asonscreen'
  911. asonscreen = value01(val,opt);
  912. case 'keepticklabels'
  913. keepticklabels = value01(val,opt);
  914. case 'mathticklabels'
  915. mathticklabels = value01(val,opt) ;
  916. case 'head'
  917. head = value01(val,opt);
  918. case 'comment'
  919. if ~isa(val,'char')
  920. error('Value of comment must be a character array.')
  921. end
  922. comment = val;
  923. case 'caption'
  924. if ~isa(val,'char')
  925. error('Value of caption must be a character array.')
  926. end
  927. caption = val;
  928. case 'extrapicture'
  929. extrapicture = value01(val,opt);
  930. case 'nzeros'
  931. if ~isa(val,'double')
  932. error('Value of nzeros must be a double.')
  933. end
  934. nzeros = val;
  935. case 'verbose'
  936. verbose = value01(val,opt);
  937. case 'figcopy'
  938. figcopy = value01(val,opt);
  939. case 'printcmd'
  940. if ~isa(val,'char')
  941. error('Value of printcmd must be a character array.')
  942. end
  943. printcmd = val;
  944. case 'package'
  945. if ~isa(val,'char')
  946. error('Value of package must be a character array.')
  947. end
  948. val = lower(strrep(val,' ',''));
  949. switch val
  950. case {'graphicx','epsfig'}
  951. % fine
  952. otherwise
  953. error('Value of package is unknown.')
  954. end
  955. package = val;
  956. case 'color'
  957. color = value01(val,opt);
  958. case 'createview'
  959. createview = value01(val,opt);
  960. case 'viewfilename'
  961. if ~isa(val,'char')
  962. error('Value of viewfilename must be a character array.')
  963. end
  964. viewfilename = val;
  965. case 'processview'
  966. processview = value01(val,opt);
  967. case 'cmd1'
  968. if ~isa(val,'char')
  969. error('Value of cmd1 must be a character array.')
  970. end
  971. cmd1 = val;
  972. case 'cmd2'
  973. if ~isa(val,'char')
  974. error('Value of cmd2 must be a character array.')
  975. end
  976. cmd2 = val;
  977. case 'cmd3'
  978. if ~isa(val,'char')
  979. error('Value of cmd3 must be a character array.')
  980. end
  981. cmd3 = val;
  982. case 'cmd4'
  983. if ~isa(val,'char')
  984. error('Value of cmd4 must be a character array.')
  985. end
  986. cmd4 = val;
  987. case 'cmd5'
  988. if ~isa(val,'char')
  989. error('Value of cmd5 must be a character array.')
  990. end
  991. cmd5 = val;
  992. case 'cmd6'
  993. if ~isa(val,'char')
  994. error('Value of cmd6 must be a character array.')
  995. end
  996. cmd6 = val;
  997. case 'cmd7'
  998. if ~isa(val,'char')
  999. error('Value of cmd7 must be a character array.')
  1000. end
  1001. cmd7 = val;
  1002. case 'cmd8'
  1003. if ~isa(val,'char')
  1004. error('Value of cmd8 must be a character array.')
  1005. end
  1006. cmd8 = val;
  1007. otherwise
  1008. error(['Option ''' opt ''' unknown'])
  1009. end % switch opt
  1010. end % for i=3:2:nargin
  1011. end % if nargin > 2
  1012. end % try / catch
  1013. if verbose,
  1014. disp([ 'This is LaPrint, version ' laprintident '.' ]);
  1015. end
  1016. comment = strrep(strrep(comment,'\','\\'),'%','%%');
  1017. caption = strrep(strrep(caption,'\','\\'),'%','%%');
  1018. iscaption = logical(length(caption));
  1019. if nzeros < 3
  1020. warning('LaPrint:general',...
  1021. 'The value of nzero should be >=3. I will use nzeros=3.')
  1022. nzeros=3;
  1023. end
  1024. if processview
  1025. createview=1;
  1026. end
  1027. if mathticklabels
  1028. Do='$';
  1029. else
  1030. Do='';
  1031. end
  1032. % eps- and tex- filenames
  1033. [epsfullnameext,epsbasenameext,epsbasename,epsdirname] = ...
  1034. getfilenames(filename,'eps',verbose);
  1035. [texfullnameext,texbasenameext,texbasename,texdirname] = ...
  1036. getfilenames(filename,'tex',verbose);
  1037. if ~strcmp(texdirname,epsdirname)
  1038. warning('LaPrint:files',['The eps-file and tex-file are '...
  1039. 'placed in different directories.']);
  1040. end
  1041. if createview | processview
  1042. [viewfullnameext,viewbasenameext,viewbasename,viewdirname] = ...
  1043. getfilenames(viewfilename,'tex',verbose);
  1044. if strcmp(texfullnameext,viewfullnameext)
  1045. viewfilename=[ viewfilename '_'];
  1046. warning('LaPrint:files',['The tex- and view-file coincide. '...
  1047. 'I''ll use '' ' viewfilename ' ''. Hope that''s ok.' ])
  1048. end
  1049. [viewfullnameext,viewbasenameext,viewbasename,viewdirname]= ...
  1050. getfilenames(viewfilename,'tex',verbose);
  1051. if ~strcmp(texdirname,viewdirname)
  1052. warning('LaPrint:files',['The eps-file and view-file are '...
  1053. 'placed in different directories.' ])
  1054. end
  1055. end
  1056. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1057. %%%%
  1058. %%%% PART 2 of advanced usage:
  1059. %%%% Create new figure, insert tags, and bookkeep original text
  1060. %%%%
  1061. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1062. % show all
  1063. shh = get(0,'ShowHiddenHandles');
  1064. set(0,'ShowHiddenHandles','on');
  1065. % preparing check for copyobj bug
  1066. figno_ori = figno;
  1067. number_children_ori = length(get(figno_ori,'children'));
  1068. % open new figure (if required) and set properties
  1069. if figcopy
  1070. figno = copyobj(figno,0);
  1071. set(figno,'visible','off')
  1072. set(figno,'Numbertitle','off')
  1073. set(figno,'MenuBar','none')
  1074. pause(0.5)
  1075. end
  1076. if asonscreen
  1077. xlimmodeauto = findobj(figno,'xlimmode','auto');
  1078. xtickmodeauto = findobj(figno,'xtickmode','auto');
  1079. xticklabelmodeauto = findobj(figno,'xticklabelmode','auto');
  1080. ylimmodeauto = findobj(figno,'ylimmode','auto');
  1081. ytickmodeauto = findobj(figno,'ytickmode','auto');
  1082. yticklabelmodeauto = findobj(figno,'yticklabelmode','auto');
  1083. zlimmodeauto = findobj(figno,'zlimmode','auto');
  1084. ztickmodeauto = findobj(figno,'ztickmode','auto');
  1085. zticklabelmodeauto = findobj(figno,'zticklabelmode','auto');
  1086. set(xlimmodeauto,'xlimmode','manual')
  1087. set(xtickmodeauto,'xtickmode','manual')
  1088. set(xticklabelmodeauto,'xticklabelmode','manual')
  1089. set(ylimmodeauto,'ylimmode','manual')
  1090. set(ytickmodeauto,'ytickmode','manual')
  1091. set(yticklabelmodeauto,'yticklabelmode','manual')
  1092. set(zlimmodeauto,'ylimmode','manual')
  1093. set(ztickmodeauto,'ytickmode','manual')
  1094. set(zticklabelmodeauto,'yticklabelmode','manual')
  1095. end
  1096. set(figno,'paperunits','centimeters');
  1097. set(figno,'units','centimeters');
  1098. orip = get(figno,'Position');
  1099. % determine width and height
  1100. if factor <= 0
  1101. factor = width/orip(3);
  1102. end
  1103. latexwidth = width;
  1104. epswidth = latexwidth/factor;
  1105. epsheight = epswidth*orip(4)/orip(3);
  1106. set(figno,'PaperPosition',[0 0 epswidth epsheight ])
  1107. set(figno,'papersize',[epswidth epsheight])
  1108. set(figno,'Position',[orip(1)+0.5 orip(2)-0.5 epswidth epsheight ])
  1109. set(figno,'Name',[ 'To be printed; size: ' num2str(factor,3) ...
  1110. ' x (' num2str(epswidth,3) 'cm x ' num2str(epsheight,3) 'cm)' ])
  1111. % some warnings
  1112. if verbose
  1113. if (epswidth<13) | (epsheight<13*0.75)
  1114. warning('LaPrint:size',['The size of the eps-figure is quite '...
  1115. 'small. The text objects might not be properly set. '...
  1116. 'Reducing ''factor'' might help.'])
  1117. end
  1118. if latexwidth/epswidth<0.5
  1119. warning('LaPrint:size',['The size of the eps-figure is large ' ...
  1120. 'compared to the latex figure. '...
  1121. 'The text size might be too small. '...
  1122. 'Increasing ''factor'' might help.'])
  1123. end
  1124. if (orip(3)-epswidth)/orip(3) > 0.1
  1125. warning('LaPrint:size',['The size of the eps-figure is much '...
  1126. 'smaller than the original '...
  1127. 'figure on screen. Matlab might save different ticks '...
  1128. 'and ticklabels than in the original figure. '...
  1129. 'See option ''asonscreen''.'])
  1130. end
  1131. disp('Strike any key to continue.');
  1132. pause
  1133. end
  1134. %
  1135. % TEXT OBJECTS: modify new figure
  1136. %
  1137. % find all text objects
  1138. hxl = get(findobj(figno,'type','axes'),'xlabel');
  1139. hyl = get(findobj(figno,'type','axes'),'ylabel');
  1140. hzl = get(findobj(figno,'type','axes'),'zlabel');
  1141. hti = get(findobj(figno,'type','axes'),'title');
  1142. hte = findobj(figno,'type','text');
  1143. % array of all text handles
  1144. htext = unique([ celltoarray(hxl) celltoarray(hyl) celltoarray(hzl) ...
  1145. celltoarray(hti) celltoarray(hte)]);
  1146. nt = length(htext);
  1147. % set(celltoarray(hxl),'VerticalAlignment','top');
  1148. % get alignments
  1149. hora = get(htext,'HorizontalAlignment');
  1150. vera = get(htext,'VerticalAlignment');
  1151. align = cell(nt,1);
  1152. for i=1:nt
  1153. align{i} = hora{i}(1);
  1154. switch vera{i}
  1155. case 'top'
  1156. align{i} = [align{i} 't'];
  1157. case 'cap'
  1158. % if ~isempty(get(htext(i),'string'))
  1159. % warning('LaPrint:text',['Using vertical ' ...
  1160. % 'alignment ''top'' instead of ''cap''.'])
  1161. % end
  1162. align{i} = [align{i} 't'];
  1163. case 'middle'
  1164. align{i} = [align{i} 'c'];
  1165. case 'baseline'
  1166. align{i} = [align{i} 'B'];
  1167. case 'bottom'
  1168. align{i} = [align{i} 'b'];
  1169. otherwise
  1170. warning('LaPrint:text',['Vertical alignment ' vera{i} ...
  1171. ' unknown. Using ''c''.'])
  1172. align{i} = [align{i} 'c'];
  1173. end
  1174. end
  1175. % generate new strings and store old ones
  1176. oldstr = get(htext,'string');
  1177. newstr = cell(nt,1);
  1178. basestr = ['s' char(48*ones(1,nzeros-1))];
  1179. extrastr = 0;
  1180. for i=1:nt
  1181. osi = oldstr{i};
  1182. oldstr{i} = ['\setlength{\tabcolsep}{0pt}\begin{tabular}{' ...
  1183. align{i}(1) '}'];
  1184. isnonempty_osi = 0;
  1185. if strcmp(get(get(htext(i),'parent'),'tag'),'legend')
  1186. newstr1 = [];
  1187. if isa(osi,'cell')
  1188. % Legend/cell : Don't use tabular, employ extra strings
  1189. nlines = length(osi);
  1190. if nlines > 1
  1191. newstr{nt+extrastr+nlines-1} = [];
  1192. oldstr{nt+extrastr+nlines-1} = [];
  1193. htext((nt+extrastr+1):(nt+extrastr+nlines-1))=htext(i);
  1194. for line=1:nlines-1
  1195. oldstr{nt+extrastr+line} = ...
  1196. strrep(strrep(osi{line},'\','\\'),'%','%%');
  1197. newstr{nt+extrastr+line} = ...
  1198. overwritetail(basestr,nt+extrastr+line);
  1199. newstr1 = [newstr1; overwritetail(basestr,nt+extrastr+line)];
  1200. end
  1201. extrastr = extrastr+nlines-1;
  1202. end
  1203. if nlines > 0
  1204. oldstr{i} = strrep(strrep(osi{nlines},'\','\\'),'%','%%');
  1205. newstr{i} = overwritetail(basestr,i);
  1206. newstr1 = [newstr1; overwritetail(basestr,i)];
  1207. end
  1208. % replace strings in figure
  1209. set(htext(i),'string',cellstr(newstr1));
  1210. else
  1211. % Legend/matrix : Don't use tabular, employ extra strings
  1212. nlines=size(osi,1);
  1213. if nlines > 1
  1214. newstr{nt+extrastr+nlines-1} = [];
  1215. oldstr{nt+extrastr+nlines-1} = [];
  1216. htext((nt+extrastr+1):(nt+extrastr+nlines-1))=htext(i);
  1217. for line=1:nlines-1
  1218. oldstr{nt+extrastr+line} = ...
  1219. strrep(strrep(osi(line,:),'\','\\'),'%','%%');
  1220. newstr{nt+extrastr+line} = ...
  1221. overwritetail(basestr,nt+extrastr+line);
  1222. newstr1 = [newstr1; overwritetail(basestr,nt+extrastr+line)];
  1223. end
  1224. extrastr = extrastr+nlines-1;
  1225. end
  1226. if nlines > 0
  1227. oldstr{i} = strrep(strrep(osi(nlines,:),'\','\\'),'%','%%');
  1228. newstr{i} = overwritetail(basestr,i);
  1229. newstr1 = [newstr1; overwritetail(basestr,i)];
  1230. end
  1231. % replace strings in figure
  1232. set(htext(i),'string',newstr1);
  1233. end
  1234. else
  1235. % text, not a legend
  1236. if isa(osi,'cell')
  1237. nlines = length(osi);
  1238. if nlines > 1
  1239. for line=1:nlines-1
  1240. oldstr{i}=[oldstr{i} osi{line} '\\'];
  1241. isnonempty_osi = isnonempty_osi+length(osi{line});
  1242. end
  1243. if align{i}(2) == 'B'
  1244. warning('LaPrint:text',['Vertical Alignment ''baseline'' '...
  1245. 'in text with multiple rows might not match.'])
  1246. align{i}(2) = 't';
  1247. end
  1248. end
  1249. if nlines > 0
  1250. oldstr{i} = [oldstr{i} osi{nlines} '\end{tabular}'];
  1251. isnonempty_osi = isnonempty_osi+length(osi{nlines});
  1252. end
  1253. oldstr{i} = strrep(strrep(oldstr{i},'\','\\'),'%','%%');
  1254. if isnonempty_osi
  1255. newstr{i} = overwritetail(basestr,i);
  1256. else
  1257. newstr{i} = '';
  1258. end
  1259. % replace strings in figure
  1260. set(htext(i),'string',newstr{i});
  1261. else
  1262. nlines=size(osi,1);
  1263. if nlines > 1
  1264. for line=1:nlines-1
  1265. oldstr{i} = [oldstr{i} osi(line,:) '\\'];
  1266. isnonempty_osi = isnonempty_osi+length(osi(line,:));
  1267. end
  1268. if align{i}(2) == 'B'
  1269. warning('LaPrint:text',['Vertical Alignment ''baseline'' '...
  1270. 'in text with multiple rows might not match.'])
  1271. align{i}(2) = 't';
  1272. end
  1273. end
  1274. if nlines > 0
  1275. oldstr{i} = [oldstr{i} osi(nlines,:) '\end{tabular}'];
  1276. isnonempty_osi = isnonempty_osi+length(osi(nlines,:));
  1277. end
  1278. oldstr{i} = strrep(strrep(oldstr{i},'\','\\'),'%','%%');
  1279. if isnonempty_osi
  1280. newstr{i} = overwritetail(basestr,i);
  1281. else
  1282. newstr{i} = '';
  1283. end
  1284. % replace string in figure
  1285. set(htext(i),'string',newstr{i});
  1286. end % isa cell
  1287. end % isa legend
  1288. end % for
  1289. ntp = nt+extrastr;
  1290. % Alignment of Legends
  1291. if extrastr > 0
  1292. align{ntp} = [];
  1293. [align{nt+1:ntp}] = deal('lc');
  1294. end
  1295. % get font properties and create commands
  1296. if ntp > 0
  1297. [fontsizecmd{1:ntp}] = deal('');
  1298. [fontanglecmd{1:ntp}] = deal('');
  1299. [fontweightcmd{1:ntp}] = deal('');
  1300. [colorcmd{1:ntp}] = deal('');
  1301. [colorclose{1:ntp}] = deal('');
  1302. end
  1303. selectfontcmd = '';
  1304. if keepfontprops
  1305. % fontsize
  1306. set(htext,'fontunits','points');
  1307. fontsize = get(htext,'fontsize');
  1308. for i=1:ntp
  1309. fontsizecmd{i} = [ '\\fontsize{' num2str(fontsize{i}) '}{' ...
  1310. num2str(fontsize{i}*1.5) '}' ];
  1311. end
  1312. % fontweight
  1313. fontweight = get(htext,'fontweight');
  1314. for i=1:ntp
  1315. switch fontweight{i}
  1316. case 'light'
  1317. fontweightcmd{i} = [ '\\fontseries{l}\\mathversion{normal}' ];
  1318. case 'normal'
  1319. fontweightcmd{i} = [ '\\fontseries{m}\\mathversion{normal}' ];
  1320. case 'demi'
  1321. fontweightcmd{i} = [ '\\fontseries{sb}\\mathversion{bold}' ];
  1322. case 'bold'
  1323. fontweightcmd{i} = [ '\\fontseries{bx}\\mathversion{bold}' ];
  1324. otherwise
  1325. warning('LaPrint:text',['Unknown fontweight: ' fontweight{i} ])
  1326. fontweightcmd{i} = [ '\\fontseries{m}\\mathversion{normal}' ];
  1327. end
  1328. end
  1329. % fontangle
  1330. fontangle = get(htext,'fontangle');
  1331. for i=1:ntp
  1332. switch fontangle{i}
  1333. case 'normal'
  1334. fontanglecmd{i} = [ '\\fontshape{n}' ];
  1335. case 'italic'
  1336. fontanglecmd{i} = [ '\\fontshape{it}' ];
  1337. case 'oblique'
  1338. fontanglecmd{i} = [ '\\fontshape{it}' ];
  1339. otherwise
  1340. warning('LaPrint:text',['unknown fontangle: ' fontangle{i} ])
  1341. fontanglecmd{i} = [ '\\fontshape{n}' ];
  1342. end
  1343. end
  1344. selectfontcmd = '\\selectfont ';
  1345. end
  1346. if color & ntp>0
  1347. col = get(htext,'color');
  1348. bgcol = get(htext,'BackgroundColor');
  1349. ecol = get(htext,'EdgeColor');
  1350. for i=1:ntp
  1351. col0 = get(get(htext(i),'parent'),'color');
  1352. [coli,isc] = char2rgb(col{i},[0 0 0]);
  1353. [bgcoli,isbgc] = char2rgb(bgcol{i},col0);
  1354. [ecoli,isec] = char2rgb(ecol{i},col0);
  1355. if isbgc | isec
  1356. set(htext(i),'BackgroundColor','none')
  1357. set(htext(i),'EdgeColor','none')
  1358. colorcmd{i} = ['\\setlength{\\fboxsep}{2pt}\\fcolorbox[rgb]{' ...
  1359. num2str(ecoli(1)) ',' num2str(ecoli(2)) ',' ...
  1360. num2str(ecoli(3)) '}{' ...
  1361. num2str(bgcoli(1)) ',' num2str(bgcoli(2)) ',' ...
  1362. num2str(bgcoli(3)) '}{\\color[rgb]{' ...
  1363. num2str(coli(1)) ',' num2str(coli(2)) ',' num2str(coli(3)) '}' ];
  1364. colorclose{i} = '}';
  1365. else
  1366. colorcmd{i} = ['\\color[rgb]{' ...
  1367. num2str(coli(1)) ',' num2str(coli(2)) ',' num2str(coli(3)) '}' ];
  1368. end
  1369. end
  1370. end
  1371. %
  1372. % LABELS: modify new figure
  1373. %
  1374. if ~keepticklabels
  1375. % all axes
  1376. hax = celltoarray(findobj(figno,'type','axes'));
  1377. na = length(hax)