/doc/influenceOffixedthresholds/laprint.m

http://github.com/tconring/Arabian-Spring · Objective C · 2027 lines · 1878 code · 149 blank · 0 comment · 250 complexity · 8bbbe8a67e5759c27b268e04f69394af 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. % case 'textwidth'
  685. % LAPRINTOPT.textwidth = textwidth;
  686. otherwise
  687. error('unknown callback option')
  688. end
  689. return
  690. end % if isa(figno,'char')
  691. % nargin >=1 and ~isa(figno,'char')
  692. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  693. %%%%
  694. %%%% PART 1 of advanced usage:
  695. %%%% Check inputs and initialize
  696. %%%%
  697. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  698. if isa(figno,'cell') % called from GUI (all set)
  699. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  700. figno=LAPRINTOPT.figno;
  701. filename=LAPRINTOPT.filename;
  702. else % advanced usage
  703. % get settings
  704. LAPRINTOPT = prefsettings;
  705. if isempty(LAPRINTOPT)
  706. LAPRINTOPT = factorysettings;
  707. end
  708. % modify prefs
  709. if ~isa(figno,'double')
  710. figno
  711. error('This is not a figure handle.')
  712. end
  713. if ~any(get(0,'children')==figno)
  714. figno
  715. error('This is not a figure handle.')
  716. end
  717. LAPRINTOPT.figno = figno;
  718. if nargin>1
  719. if ~isa(filename,'char')
  720. filename
  721. error('This is not a file name.')
  722. end
  723. LAPRINTOPT.filename=filename;
  724. end
  725. end
  726. % read and check command line options
  727. try % try old usage (Version 2.03)
  728. if nargin <=2
  729. error('lets take new usage')
  730. end
  731. % 2.03 defaults
  732. width = 12;
  733. factor = 0.8;
  734. scalefonts = 1;
  735. keepfontprops = 0;
  736. asonscreen = 0;
  737. keepticklabels = 0;
  738. mathticklabels = 0;
  739. head = 1;
  740. comment = '';
  741. caption = '';
  742. extrapicture = 1;
  743. nzeros = 5;
  744. verbose = 0;
  745. figcopy = 1;
  746. printcmd = ['print(''-f<figurenumber>'',' ...
  747. '''-deps'',''<filename.eps>'')'];
  748. package = 'epsfig';
  749. color = 0;
  750. createview = 0;
  751. viewfilename = [filename '_'];
  752. processview = 0;
  753. cmd1 = '';
  754. cmd2 = '';
  755. cmd3 = '';
  756. cmd4 = '';
  757. cmd5 = '';
  758. cmd6 = '';
  759. cmd7 = '';
  760. cmd8 = '';
  761. for i=1:nargin-2
  762. if ~isa(varargin{i},'char')
  763. error('Options must be character arrays.')
  764. end
  765. oriopt=varargin{i}(:)';
  766. opt=[ lower(strrep(oriopt,' ','')) ' ' ];
  767. if strcmp(opt(1:7),'verbose')
  768. verbose=1;
  769. elseif strcmp(opt(1:10),'asonscreen')
  770. asonscreen=1;
  771. elseif strcmp(opt(1:14),'keepticklabels')
  772. keepticklabels=1;
  773. elseif strcmp(opt(1:14),'mathticklabels')
  774. mathticklabels=1;
  775. elseif strcmp(opt(1:13),'keepfontprops')
  776. keepfontprops=1;
  777. elseif strcmp(opt(1:14),'noextrapicture')
  778. extrapicture=0;
  779. elseif strcmp(opt(1:14),'noextrapicture')
  780. extrapicture=0;
  781. elseif strcmp(opt(1:5),'loose')
  782. printcmd = ['print(''-f<figurenumber>'',' ...
  783. '''-deps'',''-loose'',''<filename.eps>'')'];
  784. elseif strcmp(opt(1:9),'nofigcopy')
  785. figcopy=0;
  786. elseif strcmp(opt(1:12),'noscalefonts')
  787. scalefonts=0;
  788. elseif strcmp(opt(1:6),'nohead')
  789. head=0;
  790. elseif strcmp(opt(1:7),'caption')
  791. eqpos=findstr(oriopt,'=');
  792. if isempty(eqpos)
  793. caption='Matlab Figure';
  794. else
  795. caption=oriopt(eqpos+1:length(oriopt));
  796. end
  797. elseif strcmp(opt(1:8),'comment=')
  798. eqpos=findstr(oriopt,'=');
  799. comment=oriopt(eqpos(1)+1:length(oriopt));
  800. elseif strcmp(opt(1:9),'viewfile=')
  801. createview=1;
  802. eqpos=findstr(oriopt,'=');
  803. viewfilename=oriopt(eqpos(1)+1:length(oriopt));
  804. elseif strcmp(opt(1:6),'width=')
  805. eval([ opt ';' ]);
  806. elseif strcmp(opt(1:7),'factor=')
  807. eval([ opt ';' ]);
  808. else
  809. error([ 'Option ' varargin{i} ' not recognized.'])
  810. end
  811. end
  812. warning('LaPrint:general',['You are using the old LaPrint '...
  813. 'syntax. This syntax might not be supported in '...
  814. 'future releases of LaPrint.'])
  815. catch % old usage doesn't work, take new one
  816. % restore preferences / factory defaults
  817. width = LAPRINTOPT.width;
  818. factor = LAPRINTOPT.factor;
  819. scalefonts = LAPRINTOPT.scalefonts;
  820. keepfontprops = LAPRINTOPT.keepfontprops;
  821. asonscreen = LAPRINTOPT.asonscreen;
  822. keepticklabels = LAPRINTOPT.keepticklabels;
  823. mathticklabels = LAPRINTOPT.mathticklabels;
  824. head = LAPRINTOPT.head;
  825. comment = LAPRINTOPT.comment;
  826. caption = LAPRINTOPT.caption;
  827. extrapicture = LAPRINTOPT.extrapicture;
  828. nzeros = LAPRINTOPT.nzeros;
  829. verbose = LAPRINTOPT.verbose;
  830. figcopy = LAPRINTOPT.figcopy;
  831. printcmd = LAPRINTOPT.printcmd;
  832. package = LAPRINTOPT.package;
  833. color = LAPRINTOPT.color;
  834. createview = LAPRINTOPT.createview;
  835. viewfilename = LAPRINTOPT.viewfilename;
  836. processview = LAPRINTOPT.processview;
  837. cmd1 = LAPRINTOPT.cmd1;
  838. cmd2 = LAPRINTOPT.cmd2;
  839. cmd3 = LAPRINTOPT.cmd3;
  840. cmd4 = LAPRINTOPT.cmd4;
  841. cmd5 = LAPRINTOPT.cmd5;
  842. cmd6 = LAPRINTOPT.cmd6;
  843. cmd7 = LAPRINTOPT.cmd7;
  844. cmd8 = LAPRINTOPT.cmd8;
  845. if nargin > 2
  846. if rem(nargin,2)
  847. error('Option names/values must appear in pairs.')
  848. end
  849. for i=1:2:nargin-2
  850. if ~isa(varargin{i},'char')
  851. error('Option name must be a character array.')
  852. end
  853. opt = lower(strrep(varargin{i}(:)',' ',''));
  854. val = varargin{i+1}(:)';
  855. switch opt
  856. case 'options'
  857. if isa(val,'char')
  858. if strcmp(val,'factory')
  859. val = factorysettings;
  860. else
  861. load(val)
  862. val = LAPRINTOPT;
  863. end
  864. end
  865. if ~isa(val,'struct')
  866. error('Value of options must be a structure array.')
  867. end
  868. % no error checking here!
  869. width = val.width;
  870. factor = val.factor;
  871. scalefonts = val.scalefonts;
  872. keepfontprops = val.keepfontprops;
  873. asonscreen = val.asonscreen;
  874. keepticklabels = val.keepticklabels;
  875. mathticklabels = val.mathticklabels;
  876. head = val.head;
  877. comment = val.comment;
  878. caption = val.caption;
  879. extrapicture = val.extrapicture;
  880. nzeros = val.nzeros;
  881. verbose = val.verbose;
  882. figcopy = val.figcopy;
  883. printcmd = val.printcmd;
  884. package = val.package;
  885. color = val.color;
  886. createview = val.createview;
  887. viewfilename = val.viewfilename;
  888. processview = val.processview;
  889. cmd1 = val.cmd1;
  890. cmd2 = val.cmd2;
  891. cmd3 = val.cmd3;
  892. cmd4 = val.cmd4;
  893. cmd5 = val.cmd5;
  894. cmd6 = val.cmd6;
  895. cmd7 = val.cmd7;
  896. cmd8 = val.cmd8;
  897. case 'width'
  898. if ~isa(val,'double')
  899. error('Value of width must be a double.')
  900. end
  901. width = val;
  902. case 'factor'
  903. if ~isa(val,'double')
  904. error('Value of factor must be a double.')
  905. end
  906. factor=val;
  907. case 'scalefonts'
  908. scalefonts = value01(val,opt);
  909. case 'keepfontprops'
  910. keepfontprops = value01(val,opt);
  911. case 'asonscreen'
  912. asonscreen = value01(val,opt);
  913. case 'keepticklabels'
  914. keepticklabels = value01(val,opt);
  915. case 'mathticklabels'
  916. mathticklabels = value01(val,opt) ;
  917. case 'head'
  918. head = value01(val,opt);
  919. case 'comment'
  920. if ~isa(val,'char')
  921. error('Value of comment must be a character array.')
  922. end
  923. comment = val;
  924. case 'caption'
  925. if ~isa(val,'char')
  926. error('Value of caption must be a character array.')
  927. end
  928. caption = val;
  929. case 'extrapicture'
  930. extrapicture = value01(val,opt);
  931. case 'nzeros'
  932. if ~isa(val,'double')
  933. error('Value of nzeros must be a double.')
  934. end
  935. nzeros = val;
  936. case 'verbose'
  937. verbose = value01(val,opt);
  938. case 'figcopy'
  939. figcopy = value01(val,opt);
  940. case 'printcmd'
  941. if ~isa(val,'char')
  942. error('Value of printcmd must be a character array.')
  943. end
  944. printcmd = val;
  945. case 'package'
  946. if ~isa(val,'char')
  947. error('Value of package must be a character array.')
  948. end
  949. val = lower(strrep(val,' ',''));
  950. switch val
  951. case {'graphicx','epsfig'}
  952. % fine
  953. otherwise
  954. error('Value of package is unknown.')
  955. end
  956. package = val;
  957. case 'color'
  958. color = value01(val,opt);
  959. case 'createview'
  960. createview = value01(val,opt);
  961. case 'viewfilename'
  962. if ~isa(val,'char')
  963. error('Value of viewfilename must be a character array.')
  964. end
  965. viewfilename = val;
  966. case 'processview'
  967. processview = value01(val,opt);
  968. case 'cmd1'
  969. if ~isa(val,'char')
  970. error('Value of cmd1 must be a character array.')
  971. end
  972. cmd1 = val;
  973. case 'cmd2'
  974. if ~isa(val,'char')
  975. error('Value of cmd2 must be a character array.')
  976. end
  977. cmd2 = val;
  978. case 'cmd3'
  979. if ~isa(val,'char')
  980. error('Value of cmd3 must be a character array.')
  981. end
  982. cmd3 = val;
  983. case 'cmd4'
  984. if ~isa(val,'char')
  985. error('Value of cmd4 must be a character array.')
  986. end
  987. cmd4 = val;
  988. case 'cmd5'
  989. if ~isa(val,'char')
  990. error('Value of cmd5 must be a character array.')
  991. end
  992. cmd5 = val;
  993. case 'cmd6'
  994. if ~isa(val,'char')
  995. error('Value of cmd6 must be a character array.')
  996. end
  997. cmd6 = val;
  998. case 'cmd7'
  999. if ~isa(val,'char')
  1000. error('Value of cmd7 must be a character array.')
  1001. end
  1002. cmd7 = val;
  1003. case 'cmd8'
  1004. if ~isa(val,'char')
  1005. error('Value of cmd8 must be a character array.')
  1006. end
  1007. cmd8 = val;
  1008. case 'textwidth'
  1009. textwidth = val;
  1010. otherwise
  1011. error(['Option ''' opt ''' unknown'])
  1012. end % switch opt
  1013. end % for i=3:2:nargin
  1014. end % if nargin > 2
  1015. end % try / catch
  1016. if verbose,
  1017. disp([ 'This is LaPrint, version ' laprintident '.' ]);
  1018. end
  1019. comment = strrep(strrep(comment,'\','\\'),'%','%%');
  1020. caption = strrep(strrep(caption,'\','\\'),'%','%%');
  1021. iscaption = logical(length(caption));
  1022. if nzeros < 3
  1023. warning('LaPrint:general',...
  1024. 'The value of nzero should be >=3. I will use nzeros=3.')
  1025. nzeros=3;
  1026. end
  1027. if processview
  1028. createview=1;
  1029. end
  1030. if mathticklabels
  1031. Do='$';
  1032. else
  1033. Do='';
  1034. end
  1035. % eps- and tex- filenames
  1036. [epsfullnameext,epsbasenameext,epsbasename,epsdirname] = ...
  1037. getfilenames(filename,'eps',verbose);
  1038. [texfullnameext,texbasenameext,texbasename,texdirname] = ...
  1039. getfilenames(filename,'tex',verbose);
  1040. if ~strcmp(texdirname,epsdirname)
  1041. warning('LaPrint:files',['The eps-file and tex-file are '...
  1042. 'placed in different directories.']);
  1043. end
  1044. if createview | processview
  1045. [viewfullnameext,viewbasenameext,viewbasename,viewdirname] = ...
  1046. getfilenames(viewfilename,'tex',verbose);
  1047. if strcmp(texfullnameext,viewfullnameext)
  1048. viewfilename=[ viewfilename '_'];
  1049. warning('LaPrint:files',['The tex- and view-file coincide. '...
  1050. 'I''ll use '' ' viewfilename ' ''. Hope that''s ok.' ])
  1051. end
  1052. [viewfullnameext,viewbasenameext,viewbasename,viewdirname]= ...
  1053. getfilenames(viewfilename,'tex',verbose);
  1054. if ~strcmp(texdirname,viewdirname)
  1055. warning('LaPrint:files',['The eps-file and view-file are '...
  1056. 'placed in different directories.' ])
  1057. end
  1058. end
  1059. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1060. %%%%
  1061. %%%% PART 2 of advanced usage:
  1062. %%%% Create new figure, insert tags, and bookkeep original text
  1063. %%%%
  1064. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1065. % show all
  1066. shh = get(0,'ShowHiddenHandles');
  1067. set(0,'ShowHiddenHandles','on');
  1068. % preparing check for copyobj bug
  1069. figno_ori = figno;
  1070. number_children_ori = length(get(figno_ori,'children'));
  1071. % open new figure (if required) and set properties
  1072. if figcopy
  1073. figno = copyobj(figno,0);
  1074. set(figno,'visible','off')
  1075. set(figno,'Numbertitle','off')
  1076. set(figno,'MenuBar','none')
  1077. pause(0.5)
  1078. end
  1079. if asonscreen
  1080. xlimmodeauto = findobj(figno,'xlimmode','auto');
  1081. xtickmodeauto = findobj(figno,'xtickmode','auto');
  1082. xticklabelmodeauto = findobj(figno,'xticklabelmode','auto');
  1083. ylimmodeauto = findobj(figno,'ylimmode','auto');
  1084. ytickmodeauto = findobj(figno,'ytickmode','auto');
  1085. yticklabelmodeauto = findobj(figno,'yticklabelmode','auto');
  1086. zlimmodeauto = findobj(figno,'zlimmode','auto');
  1087. ztickmodeauto = findobj(figno,'ztickmode','auto');
  1088. zticklabelmodeauto = findobj(figno,'zticklabelmode','auto');
  1089. set(xlimmodeauto,'xlimmode','manual')
  1090. set(xtickmodeauto,'xtickmode','manual')
  1091. set(xticklabelmodeauto,'xticklabelmode','manual')
  1092. set(ylimmodeauto,'ylimmode','manual')
  1093. set(ytickmodeauto,'ytickmode','manual')
  1094. set(yticklabelmodeauto,'yticklabelmode','manual')
  1095. set(zlimmodeauto,'ylimmode','manual')
  1096. set(ztickmodeauto,'ytickmode','manual')
  1097. set(zticklabelmodeauto,'yticklabelmode','manual')
  1098. end
  1099. set(figno,'paperunits','centimeters');
  1100. set(figno,'units','centimeters');
  1101. orip = get(figno,'Position');
  1102. % determine width and height
  1103. if factor <= 0
  1104. factor = width/orip(3);
  1105. end
  1106. latexwidth = width;
  1107. epswidth = latexwidth/factor;
  1108. epsheight = epswidth*orip(4)/orip(3);
  1109. set(figno,'PaperPosition',[0 0 epswidth epsheight ])
  1110. set(figno,'papersize',[epswidth epsheight])
  1111. set(figno,'Position',[orip(1)+0.5 orip(2)-0.5 epswidth epsheight ])
  1112. set(figno,'Name',[ 'To be printed; size: ' num2str(factor,3) ...
  1113. ' x (' num2str(epswidth,3) 'cm x ' num2str(epsheight,3) 'cm)' ])
  1114. % some warnings
  1115. if verbose
  1116. if (epswidth<13) | (epsheight<13*0.75)
  1117. warning('LaPrint:size',['The size of the eps-figure is quite '...
  1118. 'small. The text objects might not be properly set. '...
  1119. 'Reducing ''factor'' might help.'])
  1120. end
  1121. if latexwidth/epswidth<0.5
  1122. warning('LaPrint:size',['The size of the eps-figure is large ' ...
  1123. 'compared to the latex figure. '...
  1124. 'The text size might be too small. '...
  1125. 'Increasing ''factor'' might help.'])
  1126. end
  1127. if (orip(3)-epswidth)/orip(3) > 0.1
  1128. warning('LaPrint:size',['The size of the eps-figure is much '...
  1129. 'smaller than the original '...
  1130. 'figure on screen. Matlab might save different ticks '...
  1131. 'and ticklabels than in the original figure. '...
  1132. 'See option ''asonscreen''.'])
  1133. end
  1134. disp('Strike any key to continue.');
  1135. pause
  1136. end
  1137. %
  1138. % TEXT OBJECTS: modify new figure
  1139. %
  1140. % find all text objects
  1141. hxl = get(findobj(figno,'type','axes'),'xlabel');
  1142. hyl = get(findobj(figno,'type','axes'),'ylabel');
  1143. hzl = get(findobj(figno,'type','axes'),'zlabel');
  1144. hti = get(findobj(figno,'type','axes'),'title');
  1145. hte = findobj(figno,'type','text');
  1146. % array of all text handles
  1147. htext = unique([ celltoarray(hxl) celltoarray(hyl) celltoarray(hzl) ...
  1148. celltoarray(hti) celltoarray(hte)]);
  1149. nt = length(htext);
  1150. % set(celltoarray(hxl),'VerticalAlignment','top');
  1151. % get alignments
  1152. hora = get(htext,'HorizontalAlignment');
  1153. vera = get(htext,'VerticalAlignment');
  1154. align = cell(nt,1);
  1155. for i=1:nt
  1156. align{i} = hora{i}(1);
  1157. switch vera{i}
  1158. case 'top'
  1159. align{i} = [align{i} 't'];
  1160. case 'cap'
  1161. % if ~isempty(get(htext(i),'string'))
  1162. % warning('LaPrint:text',['Using vertical ' ...
  1163. % 'alignment ''top'' instead of ''cap''.'])
  1164. % end
  1165. align{i} = [align{i} 't'];
  1166. case 'middle'
  1167. align{i} = [align{i} 'c'];
  1168. case 'baseline'
  1169. align{i} = [align{i} 'B'];
  1170. case 'bottom'
  1171. align{i} = [align{i} 'b'];
  1172. otherwise
  1173. warning('LaPrint:text',['Vertical alignment ' vera{i} ...
  1174. ' unknown. Using ''c''.'])
  1175. align{i} = [align{i} 'c'];
  1176. end
  1177. end
  1178. % generate new strings and store old ones
  1179. oldstr = get(htext,'string');
  1180. newstr = cell(nt,1);
  1181. basestr = ['s' char(48*ones(1,nzeros-1))];
  1182. extrastr = 0;
  1183. for i=1:nt
  1184. osi = oldstr{i};
  1185. oldstr{i} = ['\setlength{\tabcolsep}{0pt}\begin{tabular}{' ...
  1186. align{i}(1) '}'];
  1187. isnonempty_osi = 0;
  1188. if strcmp(get(get(htext(i),'parent'),'tag'),'legend')
  1189. newstr1 = [];
  1190. if isa(osi,'cell')
  1191. % Legend/cell : Don't use tabular, employ extra strings
  1192. nlines = length(osi);
  1193. if nlines > 1
  1194. newstr{nt+extrastr+nlines-1} = [];
  1195. oldstr{nt+extrastr+nlines-1} = [];
  1196. htext((nt+extrastr+1):(nt+extrastr+nlines-1))=htext(i);
  1197. for line=1:nlines-1
  1198. oldstr{nt+extrastr+line} = ...
  1199. strrep(strrep(osi{line},'\','\\'),'%','%%');
  1200. newstr{nt+extrastr+line} = ...
  1201. overwritetail(basestr,nt+extrastr+line);
  1202. newstr1 = [newstr1; overwritetail(basestr,nt+extrastr+line)];
  1203. end
  1204. extrastr = extrastr+nlines-1;
  1205. end
  1206. if nlines > 0
  1207. oldstr{i} = strrep(strrep(osi{nlines},'\','\\'),'%','%%');
  1208. newstr{i} = overwritetail(basestr,i);
  1209. newstr1 = [newstr1; overwritetail(basestr,i)];
  1210. end
  1211. % replace strings in figure
  1212. set(htext(i),'string',cellstr(newstr1));
  1213. else
  1214. % Legend/matrix : Don't use tabular, employ extra strings
  1215. nlines=size(osi,1);
  1216. if nlines > 1
  1217. newstr{nt+extrastr+nlines-1} = [];
  1218. oldstr{nt+extrastr+nlines-1} = [];
  1219. htext((nt+extrastr+1):(nt+extrastr+nlines-1))=htext(i);
  1220. for line=1:nlines-1
  1221. oldstr{nt+extrastr+line} = ...
  1222. strrep(strrep(osi(line,:),'\','\\'),'%','%%');
  1223. newstr{nt+extrastr+line} = ...
  1224. overwritetail(basestr,nt+extrastr+line);
  1225. newstr1 = [newstr1; overwritetail(basestr,nt+extrastr+line)];
  1226. end
  1227. extrastr = extrastr+nlines-1;
  1228. end
  1229. if nlines > 0
  1230. oldstr{i} = strrep(strrep(osi(nlines,:),'\','\\'),'%','%%');
  1231. newstr{i} = overwritetail(basestr,i);
  1232. newstr1 = [newstr1; overwritetail(basestr,i)];
  1233. end
  1234. % replace strings in figure
  1235. set(htext(i),'string',newstr1);
  1236. end
  1237. else
  1238. % text, not a legend
  1239. if isa(osi,'cell')
  1240. nlines = length(osi);
  1241. if nlines > 1
  1242. for line=1:nlines-1
  1243. oldstr{i}=[oldstr{i} osi{line} '\\'];
  1244. isnonempty_osi = isnonempty_osi+length(osi{line});
  1245. end
  1246. if align{i}(2) == 'B'
  1247. warning('LaPrint:text',['Vertical Alignment ''baseline'' '...
  1248. 'in text with multiple rows might not match.'])
  1249. align{i}(2) = 't';
  1250. end
  1251. end
  1252. if nlines > 0
  1253. oldstr{i} = [oldstr{i} osi{nlines} '\end{tabular}'];
  1254. isnonempty_osi = isnonempty_osi+length(osi{nlines});
  1255. end
  1256. oldstr{i} = strrep(strrep(oldstr{i},'\','\\'),'%','%%');
  1257. if isnonempty_osi
  1258. newstr{i} = overwritetail(basestr,i);
  1259. else
  1260. newstr{i} = '';
  1261. end
  1262. % replace strings in figure
  1263. set(htext(i),'string',newstr{i});
  1264. else
  1265. nlines=size(osi,1);
  1266. if nlines > 1
  1267. for line=1:nlines-1
  1268. oldstr{i} = [oldstr{i} osi(line,:) '\\'];
  1269. isnonempty_osi = isnonempty_osi+length(osi(line,:));
  1270. end
  1271. if align{i}(2) == 'B'
  1272. warning('LaPrint:text',['Vertical Alignment ''baseline'' '...
  1273. 'in text with multiple rows might not match.'])
  1274. align{i}(2) = 't';
  1275. end
  1276. end
  1277. if nlines > 0
  1278. oldstr{i} = [oldstr{i} osi(nlines,:) '\end{tabular}'];
  1279. isnonempty_osi = isnonempty_osi+length(osi(nlines,:));
  1280. end
  1281. oldstr{i} = strrep(strrep(oldstr{i},'\','\\'),'%','%%');
  1282. if isnonempty_osi
  1283. newstr{i} = overwritetail(basestr,i);
  1284. else
  1285. newstr{i} = '';
  1286. end
  1287. % replace string in figure
  1288. set(htext(i),'string',newstr{i});
  1289. end % isa cell
  1290. end % isa legend
  1291. end % for
  1292. ntp = nt+extrastr;
  1293. % Alignment of Legends
  1294. if extrastr > 0
  1295. align{ntp} = [];
  1296. [align{nt+1:ntp}] = deal('lc');
  1297. end
  1298. % get font properties and create commands
  1299. if ntp > 0
  1300. [fontsizecmd{1:ntp}] = deal('');
  1301. [fontanglecmd{1:ntp}] = deal('');
  1302. [fontweightcmd{1:ntp}] = deal('');
  1303. [colorcmd{1:ntp}] = deal('');
  1304. [colorclose{1:ntp}] = deal('');
  1305. end
  1306. selectfontcmd = '';
  1307. if keepfontprops
  1308. % fontsize
  1309. set(htext,'fontunits','points');
  1310. fontsize = get(htext,'fontsize');
  1311. for i=1:ntp
  1312. fontsizecmd{i} = [ '\\fontsize{' num2str(fontsize{i}) '}{' ...
  1313. num2str(fontsize{i}*1.5) '}' ];
  1314. end
  1315. % fontweight
  1316. fontweight = get(htext,'fontweight');
  1317. for i=1:ntp
  1318. switch fontweight{i}
  1319. case 'light'
  1320. fontweightcmd{i} = [ '\\fontseries{l}\\mathversion{normal}' ];
  1321. case 'normal'
  1322. fontweightcmd{i} = [ '\\fontseries{m}\\mathversion{normal}' ];
  1323. case 'demi'
  1324. fontweightcmd{i} = [ '\\fontseries{sb}\\mathversion{bold}' ];
  1325. case 'bold'
  1326. fontweightcmd{i} = [ '\\fontseries{bx}\\mathversion{bold}' ];
  1327. otherwise
  1328. warning('LaPrint:text',['Unknown fontweight: ' fontweight{i} ])
  1329. fontweightcmd{i} = [ '\\fontseries{m}\\mathversion{normal}' ];
  1330. end
  1331. end
  1332. % fontangle
  1333. fontangle = get(htext,'fontangle');
  1334. for i=1:ntp
  1335. switch fontangle{i}
  1336. case 'normal'
  1337. fontanglecmd{i} = [ '\\fontshape{n}' ];
  1338. case 'italic'
  1339. fontanglecmd{i} = [ '\\fontshape{it}' ];
  1340. case 'oblique'
  1341. fontanglecmd{i} = [ '\\fontshape{it}' ];
  1342. otherwise
  1343. warning('LaPrint:text',['unknown fontangle: ' fontangle{i} ])
  1344. fontanglecmd{i} = [ '\\fontshape{n}' ];
  1345. end
  1346. end
  1347. selectfontcmd = '\\selectfont ';
  1348. end
  1349. if color & ntp>0
  1350. col = get(htext,'color');
  1351. bgcol = get(htext,'BackgroundColor');
  1352. ecol = get(htext,'EdgeColor');
  1353. for i=1:ntp
  1354. col0 = get(get(htext(i),'parent'),'color');
  1355. [coli,isc] = char2rgb(col{i},[0 0 0]);
  1356. [bgcoli,isbgc] = char2rgb(bgcol{i},col0);
  1357. [ecoli,isec] = char2rgb(ecol{i},col0);
  1358. if isbgc | isec
  1359. set(htext(i),'BackgroundColor','none')
  1360. set(htext(i),'EdgeColor','none')
  1361. colorcmd{i} = ['\\setlength{\\fboxsep}{2pt}\\fcolorbox[rgb]{' ...
  1362. num2str(ecoli(1)) ',' num2str(ecoli(2)) ',' ...
  1363. num2str(ecoli(3)) '}{' ...
  1364. num2str(bgcoli(1)) ',' num2str(bgcoli(2)) ',' ...
  1365. num2str(bgcoli(3)) '}{\\color[rgb]{' ...
  1366. num2str(coli(1)) ',' num2str(coli(2)) ',' num2str(coli(3)) '}' ];
  1367. colorclose{i} = '}';
  1368. else
  1369. colorcmd{i} = ['\\color[rgb]{' ...
  1370. num2str(coli(1)) ',' num2str(coli(2)) ',' num2str(coli(3)) '}' ];
  1371. end
  1372. end
  1373. end
  1374. %
  1375. % LABELS: modify new figure
  1376. %
  1377. if ~keepticklabels
  1378. % all axes
  1379. hax = celltoarray(findobj(figno,'type','axes'));
  1380. na = length(hax);
  1381. % % try to figure out if we have 3D axes an warn
  1382. % issuewarning = 0;
  1383. % for i=1:na
  1384. % issuewarning = max(issuewarning,is3d(hax(i)));
  1385. % end
  1386. % if issuewarning
  1387. % warning('LaPrint:label',['This seems to be a 3D plot. '...
  1388. % 'The LaTeX labels are possibly incorrect. '...
  1389. % 'The option ''keepticklabels'' might help. '...
  1390. % 'Setting ''figcopy'' to ''off'' might be wise, too.'])
  1391. % end
  1392. % try to figure out if we linear scale with extra factor
  1393. % and determine powers of 10
  1394. powers = NaN*zeros(na,3); % matrix with powers of 10
  1395. for i=1:na % all axes
  1396. allxyz = { 'x', 'y', 'z' };
  1397. for ixyz=1:3 % x,y,z
  1398. xyz = allxyz{ixyz};
  1399. ticklabelmode = get(hax(i),[ xyz 'ticklabelmode']);
  1400. if strcmp(ticklabelmode,'auto')
  1401. tick = get(hax(i),[ xyz 'tick']);
  1402. ticklabel = get(hax(i),[ xyz 'ticklabel']);
  1403. nticklabels = size(ticklabel,1);
  1404. nticks = length(tick);
  1405. if nticks==0,
  1406. powers(i,ixyz)=0;
  1407. nticklabels=0;
  1408. end
  1409. if nticklabels==0,
  1410. powers(i,ixyz)=0;
  1411. end
  1412. for k=1:nticklabels % all ticks
  1413. label = str2num(ticklabel(k,:));
  1414. if length(label)==0,
  1415. powers(i,ixyz) = 0;
  1416. break;
  1417. end
  1418. if ( label==0 ) & ( abs(tick(k))>1e-10 )
  1419. powers(i,ixyz) = 0;
  1420. br