PageRenderTime 62ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/tools/plot_tools/laprint.m

https://code.google.com/p/mtex/
MATLAB | 2033 lines | 1686 code | 147 blank | 200 comment | 279 complexity | 9ee203fdbcc1e391e038b22bddfbc91c MD5 | raw file
Possible License(s): GPL-2.0, BSD-2-Clause

Large files files are truncated, but you can 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. %% Syntax
  11. % >> laprint
  12. %
  13. % This opens a graphical user interface window, to control the
  14. % various settings. It includes a help facility. Just try it.
  15. %
  16. % As an alternative to the GUI you can call laprint from the command
  17. % line with various extra input arguments. These arguments are
  18. % explained in the help window of the GUI, which can be also be
  19. % opened using the command
  20. % >> laprint helpwindow
  21. %
  22. % There is an Users Guide available at
  23. % http://www.uni-kassel.de/fb16/rat/matlab/laprint/laprintdoc.ps
  24. % (c) Arno Linnemann. All rights reserved.
  25. % The author of this program assumes no responsibility for any errors
  26. % or omissions. In no event shall he be liable for damages arising out of
  27. % any use of the software. Redistribution of the unchanged file is allowed.
  28. % Distribution of changed versions is allowed provided the file is renamed
  29. % and the source and authorship of the original version is acknowledged in
  30. % the modified file.
  31. % Please report bugs, suggestions and comments to:
  32. % Arno Linnemann
  33. % Control and Automation
  34. % Department of Electrical and Computer Engineering
  35. % University of Kassel
  36. % 34109 Kassel
  37. % Germany
  38. % mailto:linnemann@uni-kassel.de
  39. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  40. %%%%
  41. %%%% Initialize
  42. %%%%
  43. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  44. laprintident = '3.16 (13.9.2004)';
  45. vers = version;
  46. vers = eval(vers(1:3));
  47. if vers < 6.1
  48. error('Sorry. Matlab 6.1 or above is required.')
  49. end
  50. hf=131;
  51. hhf=132;
  52. % no output
  53. if nargout
  54. error('No output argument, please.')
  55. end
  56. inter=get(0,'defaulttextinterpreter');
  57. if ~strcmp(inter,'none')
  58. warning('LaPrint:general',['It is recommended to switch off the '...
  59. 'text interpreter\nbefore creating a figure to be saved '...
  60. 'with LaPrint. Use the command\n',...
  61. ' >> set(0,''defaulttextinterpreter'',''none'').'])
  62. end
  63. if nargin==0
  64. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  65. %%%%
  66. %%%% GUI
  67. %%%%
  68. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  69. try
  70. delete(hf)
  71. end
  72. try
  73. delete(hhf)
  74. end
  75. %---------------------------------
  76. % open window
  77. %---------------------------------
  78. hf = figure(hf);
  79. clf reset;
  80. set(hf,'NumberTitle','off',...
  81. 'Name','LaPrint (LaTeX Print)',...
  82. 'Units','points',...
  83. 'CloseRequestFcn','laprint(''quit'');',...
  84. 'menubar','none')
  85. h = uicontrol('Parent',hf,'Units','points');
  86. fsize = get(h,'Fontsize');
  87. delete(h)
  88. posf = get(hf,'Position');
  89. figheight = 10*fsize;
  90. figwidth = 32*fsize;
  91. posf = [ posf(1) posf(2)+posf(4)-figheight figwidth figheight];
  92. set(hf,'Position',posf)
  93. uicontrol('Parent',hf,'style','frame','Units','points',...
  94. 'Position',[0 0 figwidth figheight])
  95. curh = figheight-0*fsize;
  96. LAPRINTHAN=struct('figno',{0},'filename',{0},...
  97. 'keepfontprops',{0},'asonscreen',{0},'keepticklabels',{0},...
  98. 'mathticklabels',{0},'head',{0},'extrapicture',{0},...
  99. 'verbose',{0},'figcopy',{0},'package_epsfig',{0},...
  100. 'package_graphicx',{0},'color',{0},'createview',{0},...
  101. 'processview',{0});
  102. %---------------------------------
  103. % figure no.
  104. %---------------------------------
  105. loch = 1.7*fsize;
  106. curh = curh-loch-1.5*fsize;
  107. h = uicontrol('Parent',hf,...
  108. 'style','text',...
  109. 'Units','points',...
  110. 'Position',[1*fsize curh 18*fsize loch],...
  111. 'HorizontalAlignment','left',...
  112. 'string','Number of Figure to be saved:');
  113. h = uicontrol('Parent',hf,...
  114. 'style','edit',...
  115. 'Units','points',...
  116. 'Position',[19*fsize curh 12*fsize loch],...
  117. 'HorizontalAlignment','left',...
  118. 'BackgroundColor',[1 1 1],...
  119. 'Callback','laprint(''figno'');');
  120. LAPRINTHAN.figno = h;
  121. %---------------------------------
  122. % filename
  123. %---------------------------------
  124. loch = 1.7*fsize;
  125. curh = curh-loch-1*fsize;
  126. h = uicontrol('Parent',hf,...
  127. 'style','text',...
  128. 'Units','points',...
  129. 'Position',[1*fsize curh 18*fsize loch],...
  130. 'HorizontalAlignment','left',...
  131. 'string','Basename of Files to be Created:');
  132. h = uicontrol('Parent',hf,...
  133. 'style','edit',...
  134. 'Units','points',...
  135. 'Position',[19*fsize curh 12*fsize loch],...
  136. 'HorizontalAlignment','left',...
  137. 'BackgroundColor',[1 1 1],...
  138. 'Callback','laprint(''filename'');');
  139. LAPRINTHAN.filename = h;
  140. %---------------------------------
  141. % save, quit
  142. %---------------------------------
  143. loch = 2*fsize;
  144. curh = curh-loch-1*fsize;
  145. h = uicontrol('Parent',hf,...
  146. 'Style','pushbutton',...
  147. 'Units','Points',...
  148. 'Position',[19*fsize curh 5*fsize loch],...
  149. 'HorizontalAlignment','center',...
  150. 'String','Go !',...
  151. 'Callback','laprint(''save'');');
  152. h = uicontrol('Parent',hf,...
  153. 'Style','pushbutton',...
  154. 'Units','Points',...
  155. 'Position',[26*fsize curh 5*fsize loch],...
  156. 'HorizontalAlignment','center',...
  157. 'String','Quit',...
  158. 'Callback','laprint(''quit'');');
  159. %---------------------------------
  160. %% Options
  161. % uimenue
  162. %---------------------------------
  163. hm1 = uimenu('label','Options');
  164. uimenu(hm1,...
  165. 'label','Sizes and Scalings ...',...
  166. 'callback','laprint(''size'')');
  167. LAPRINTHAN.keepfontprops = uimenu(hm1,...
  168. 'label','Translate Matlab Font Properties to LaTeX',...
  169. 'callback','laprint(''keepfontprops'')');
  170. LAPRINTHAN.asonscreen = uimenu(hm1,...
  171. 'label','Print Limits and Ticks as on Screen',...
  172. 'separator','on',...
  173. 'callback','laprint(''asonscreen'')');
  174. LAPRINTHAN.keepticklabels = uimenu(hm1,...
  175. 'label','Keep Tick Labels within eps File',...
  176. 'callback','laprint(''keepticklabels'')');
  177. LAPRINTHAN.mathticklabels = uimenu(hm1,...
  178. 'label','Set Tick Labels in LaTeX Math Mode',...
  179. 'callback','laprint(''mathticklabels'')');
  180. LAPRINTHAN.head = uimenu(hm1,...
  181. 'label','Equip the tex File with a Head',...
  182. 'separator','on',...
  183. 'callback','laprint(''head'')');
  184. uimenu(hm1,...
  185. 'label','Comment in the Head of the tex File ...',...
  186. 'callback','laprint(''comment'')');
  187. uimenu(hm1,...
  188. 'label','Place a LaTeX Caption in the tex File ...',...
  189. 'callback','laprint(''caption'')');
  190. LAPRINTHAN.extrapicture = uimenu(hm1,...
  191. 'label','Place an Extra Picture in each Axes',...
  192. 'callback','laprint(''extrapicture'')');
  193. uimenu(hm1,...
  194. 'label','Length of psfrag Replacement Strings ...',...
  195. 'callback','laprint(''nzeros'')');
  196. LAPRINTHAN.verbose = uimenu(hm1,...
  197. 'label','Call LaPrint in Verbose Mode',...
  198. 'separator','on',...
  199. 'callback','laprint(''verbose'')');
  200. LAPRINTHAN.figcopy = uimenu(hm1,...
  201. 'label','Copy Figure and Modify that Copy',...
  202. 'callback','laprint(''figcopy'')');
  203. uimenu(hm1,...
  204. 'label','Matlab Print Command ...',...
  205. 'separator','on',...
  206. 'callback','laprint(''printcmd'')');
  207. h=uimenu(hm1,...
  208. 'separator','on',...
  209. 'label','LaTeX Graphics Package');
  210. LAPRINTHAN.package_graphicx = uimenu(h,...
  211. 'label','graphicx',...
  212. 'callback','laprint(''package_graphicx'')');
  213. LAPRINTHAN.package_epsfig = uimenu(h,...
  214. 'label','epsfig',...
  215. 'callback','laprint(''package_epsfig'')');
  216. LAPRINTHAN.color = uimenu(hm1,...
  217. 'label','Use LaTeX ''color'' Package',...
  218. 'callback','laprint(''color'')');
  219. h = uimenu(hm1,...
  220. 'label','View File ...',...
  221. 'separator','on');
  222. LAPRINTHAN.createview = uimenu(h,...
  223. 'label','Create a View File',...
  224. 'callback','laprint(''createview'')');
  225. uimenu(h,...
  226. 'label','Name of the View File ...',...
  227. 'callback','laprint(''viewfilename'')');
  228. LAPRINTHAN.processview = uimenu(h,...
  229. 'label','Process the View File',...
  230. 'separator','on',...
  231. 'callback','laprint(''processview'')');
  232. uimenu(h,...
  233. 'label','Executables for Processing View File...',...
  234. 'callback','laprint(''cmdsview'')');
  235. %---------------------------------
  236. % Preferences uimenue
  237. %---------------------------------
  238. hm3=uimenu('label','Preferences');
  239. uimenu(hm3,...
  240. 'label','Get Preferences',...
  241. 'callback','laprint(''getpref'')')
  242. uimenu(hm3,...
  243. 'label','Set Preferences to Current Settings',...
  244. 'callback','laprint(''setpref'')')
  245. uimenu(hm3,...
  246. 'label','Remove Preferences',...
  247. 'callback','laprint(''rmpref'')')
  248. uimenu(hm3,...
  249. 'label','Save Current Settings to a File ...',...
  250. 'separator','on',...
  251. 'callback','laprint(''savepref'')')
  252. uimenu(hm3,...
  253. 'label','Load Settings from a File ...',...
  254. 'callback','laprint(''loadpref'')')
  255. uimenu(hm3,...
  256. 'label','Get Factory Defaults',...
  257. 'separator','on',...
  258. 'callback','laprint(''factory'')')
  259. %---------------------------------
  260. % Help uimenue
  261. %---------------------------------
  262. hm2=uimenu('label','Help');
  263. uimenu(hm2,...
  264. 'label',['LaPrint Online Help ...'],...
  265. 'callback','laprint(''helpwindow'')');
  266. uimenu(hm2,...
  267. 'label','Get the LaPrint Users Guide',...
  268. 'callback',['web www.uni-kassel.de/fb16/rat/matlab',...
  269. '/laprint/laprintdoc.ps -browser'])
  270. uimenu(hm2,...
  271. 'label',['Look for a newer version of LaPrint ' ...
  272. '(Matlab Central File Exchange)...'],...
  273. 'callback',['web http://www.mathworks.de/matlabcentral/',...
  274. 'fileexchange/loadFile.do?objectId=4638',...
  275. '&objectType=file -browser'])
  276. uimenu(hm2,...
  277. 'label','Version and Author ...',...
  278. 'callback','laprint(''whois'')')
  279. %---------------------------------
  280. % make hf invisible
  281. %---------------------------------
  282. set(hf,'HandleVisibility','callback')
  283. %---------------------------------
  284. % get settings
  285. %---------------------------------
  286. LAPRINTOPT = prefsettings;
  287. if isempty(LAPRINTOPT)
  288. LAPRINTOPT = factorysettings;
  289. end
  290. %---------------------------------
  291. % get figure
  292. %---------------------------------
  293. gcfig=gcf;
  294. if gcfig == hf
  295. allfigs = findobj('type','figure');
  296. allfigs = allfigs(find(allfigs~=hf));
  297. if length(allfigs)
  298. figno = allfigs(1);
  299. else
  300. figure(1)
  301. figno=1;
  302. end
  303. else
  304. figno=gcfig;
  305. end
  306. LAPRINTOPT.figno = figno;
  307. %---------------------------------
  308. % update
  309. %---------------------------------
  310. updategui(LAPRINTHAN,LAPRINTOPT)
  311. sethf(hf,LAPRINTHAN,LAPRINTOPT)
  312. figure(hf)
  313. %---------------------------------
  314. % done
  315. %---------------------------------
  316. return
  317. end % if nargin==0
  318. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  319. %%%%
  320. %%%% callback calls ('factory' and 'getprefs' also
  321. %%%% used from command line)
  322. %%%%
  323. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  324. if isa(figno,'char')
  325. switch figno
  326. case 'figno'
  327. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  328. LAPRINTOPT.figno=eval(get(LAPRINTHAN.figno,'string'));
  329. figure(LAPRINTOPT.figno)
  330. figure(hf)
  331. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  332. case 'filename'
  333. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  334. LAPRINTOPT.filename=get(LAPRINTHAN.filename,'string');
  335. [texfullnameext,texbasenameext,texbasename,texdirname] = ...
  336. getfilenames(LAPRINTOPT.filename,'tex',0);
  337. [epsfullnameext,epsbasenameext,epsbasename,epsdirname] = ...
  338. getfilenames(LAPRINTOPT.filename,'eps',0);
  339. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  340. case 'save'
  341. % lapcmd = [ 'laprint(' int2str(LAPRINTOPT.figno) ...
  342. % ', ''' LAPRINTOPT.filename ''''...
  343. % ', ''options'', LAPRINTOPT)'];
  344. lapcmd = 'laprint({})';
  345. eval(lapcmd)
  346. case 'quit'
  347. delete(hf)
  348. try
  349. delete(hhf)
  350. end
  351. case 'size'
  352. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  353. answer = inputdlg({['Please enter the width (in centimeters) ',...
  354. 'of the graphics in the LaTeX document (The height ',...
  355. 'will be computed such that the aspect ratio of the ',...
  356. 'figure on screen is retained.) :'],...
  357. ['Please enter the factor by which the size of the '...
  358. 'graphics in the LaTeX document differs from the size of the '...
  359. 'Postscipt graphics ( Explaination: A factor <1 scales ',...
  360. 'the picture down. This means that lines become thinner ',...
  361. 'and fonts become smaller. ) :'],...
  362. ['Please specify if you want to scale the fonts along with ',...
  363. 'the graphics (enter ''on'' or ''off'') : '] },...
  364. 'LaPrint Settings',1,{num2str(LAPRINTOPT.width),...
  365. num2str(LAPRINTOPT.factor),...
  366. valueyn(LAPRINTOPT.scalefonts)},'on');
  367. if length(answer)
  368. LAPRINTOPT.width=eval(answer{1});
  369. LAPRINTOPT.factor = eval(answer{2});
  370. LAPRINTOPT.scalefonts = value01(answer{3});
  371. end
  372. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  373. case 'keepfontprops'
  374. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  375. if LAPRINTOPT.keepfontprops==1
  376. LAPRINTOPT.keepfontprops=0;
  377. set(LAPRINTHAN.keepfontprops,'check','off')
  378. else
  379. LAPRINTOPT.keepfontprops=1;
  380. set(LAPRINTHAN.keepfontprops,'check','on')
  381. end
  382. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  383. case 'asonscreen'
  384. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  385. if LAPRINTOPT.asonscreen==1
  386. LAPRINTOPT.asonscreen=0;
  387. set(LAPRINTHAN.asonscreen,'check','off')
  388. else
  389. LAPRINTOPT.asonscreen=1;
  390. set(LAPRINTHAN.asonscreen,'check','on')
  391. end
  392. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  393. case 'keepticklabels'
  394. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  395. if LAPRINTOPT.keepticklabels==1
  396. LAPRINTOPT.keepticklabels=0;
  397. set(LAPRINTHAN.keepticklabels,'check','off')
  398. else
  399. LAPRINTOPT.keepticklabels=1;
  400. set(LAPRINTHAN.keepticklabels,'check','on')
  401. end
  402. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  403. case 'mathticklabels'
  404. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  405. if LAPRINTOPT.mathticklabels==1
  406. LAPRINTOPT.mathticklabels=0;
  407. set(LAPRINTHAN.mathticklabels,'check','off')
  408. else
  409. LAPRINTOPT.mathticklabels=1;
  410. set(LAPRINTHAN.mathticklabels,'check','on')
  411. end
  412. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  413. case 'head'
  414. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  415. if LAPRINTOPT.head==1
  416. LAPRINTOPT.head=0;
  417. set(LAPRINTHAN.head,'check','off')
  418. else
  419. LAPRINTOPT.head=1;
  420. set(LAPRINTHAN.head,'check','on')
  421. end
  422. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  423. case 'comment'
  424. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  425. answer = inputdlg({['Please enter a describing comment to '...
  426. 'be placed into the head of the tex file:']},...
  427. 'LaPrint Settings',1,{LAPRINTOPT.comment},'on');
  428. if length(answer)
  429. LAPRINTOPT.comment = answer{1};
  430. end
  431. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  432. case 'caption'
  433. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  434. answer = inputdlg(['If the following text is nonempty, ' ...
  435. 'then it will be placed as a \caption{} into the tex '...
  436. 'file along with \label{fig:' LAPRINTOPT.filename '}. '...
  437. 'Please enter the caption text:'],...
  438. 'LaPrint Settings',1,{LAPRINTOPT.caption},'on');
  439. if length(answer)
  440. LAPRINTOPT.caption = answer{1};
  441. end
  442. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  443. case 'extrapicture'
  444. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  445. if LAPRINTOPT.extrapicture==1
  446. LAPRINTOPT.extrapicture=0;
  447. set(LAPRINTHAN.extrapicture,'check','off')
  448. else
  449. LAPRINTOPT.extrapicture=1;
  450. set(LAPRINTHAN.extrapicture,'check','on')
  451. end
  452. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  453. case 'nzeros'
  454. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  455. answer = inputdlg({['Please enter length of the psfrag replacement '...
  456. 'strings (must be >= 3) :']},...
  457. 'LaPrint Settings',1,{num2str(LAPRINTOPT.nzeros)},'on');
  458. if length(answer)
  459. LAPRINTOPT.nzeros = max(eval(answer{1}),3);
  460. end
  461. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  462. case 'verbose'
  463. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  464. if LAPRINTOPT.verbose==1
  465. LAPRINTOPT.verbose=0;
  466. set(LAPRINTHAN.verbose,'check','off')
  467. else
  468. LAPRINTOPT.verbose=1;
  469. set(LAPRINTHAN.verbose,'check','on')
  470. end
  471. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  472. case 'figcopy'
  473. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  474. if LAPRINTOPT.figcopy==1
  475. LAPRINTOPT.figcopy=0;
  476. set(LAPRINTHAN.figcopy,'check','off')
  477. else
  478. LAPRINTOPT.figcopy=1;
  479. set(LAPRINTHAN.figcopy,'check','on')
  480. end
  481. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  482. case 'printcmd'
  483. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  484. answer = inputdlg({['Please enter the Matlab command '...
  485. 'to be used for printing the eps file '...
  486. '(LaPrint will internally replace <figurenumber> by the '...
  487. 'number of the figure <filename.eps> by the ' ...
  488. 'eps-filename and <filename> '...
  489. 'by the basename of the file, respectively). You can add options '...
  490. 'here (like ''-loose'') or use a different program '...
  491. 'for printing (like ''exportfig'') :']},...
  492. 'LaPrint Settings',1,{LAPRINTOPT.printcmd},'on');
  493. if length(answer)
  494. LAPRINTOPT.printcmd = answer{1};
  495. end
  496. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  497. case 'package_epsfig'
  498. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  499. LAPRINTOPT.package='epsfig';
  500. set(LAPRINTHAN.package_epsfig,'check','on')
  501. set(LAPRINTHAN.package_graphicx,'check','off')
  502. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  503. case 'package_graphicx'
  504. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  505. LAPRINTOPT.package='graphicx';
  506. set(LAPRINTHAN.package_epsfig,'check','off')
  507. set(LAPRINTHAN.package_graphicx,'check','on')
  508. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  509. case 'color'
  510. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  511. if LAPRINTOPT.color==1
  512. LAPRINTOPT.color=0;
  513. set(LAPRINTHAN.color,'check','off')
  514. else
  515. LAPRINTOPT.color=1;
  516. set(LAPRINTHAN.color,'check','on')
  517. end
  518. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  519. case 'createview'
  520. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  521. if LAPRINTOPT.createview==1
  522. LAPRINTOPT.createview=0;
  523. LAPRINTOPT.processview=0;
  524. set(LAPRINTHAN.createview,'check','off')
  525. set(LAPRINTHAN.processview,'check','off')
  526. else
  527. LAPRINTOPT.createview=1;
  528. set(LAPRINTHAN.createview,'check','on')
  529. end
  530. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  531. case 'viewfilename'
  532. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  533. trydlg=1;
  534. txt=['Please enter the name of the '...
  535. 'viewfile (without extension .tex) : '];
  536. txt2='';
  537. while trydlg
  538. answer = inputdlg({[txt txt2]},...
  539. 'LaPrint Settings',1,{LAPRINTOPT.viewfilename},'on');
  540. if length(answer)
  541. if strcmp(answer{1},LAPRINTOPT.filename)
  542. txt2=['The name must be different from the name of the '...
  543. 'graphics file):'];
  544. else
  545. trydlg=0;
  546. LAPRINTOPT.viewfilename = answer{1};
  547. [viewfullnameext,viewbasenameext,viewbasename,viewdirname] = ...
  548. getfilenames(LAPRINTOPT.viewfilename,'tex',0);
  549. end
  550. else
  551. trydlg=0;
  552. end
  553. end
  554. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  555. case 'processview'
  556. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  557. if LAPRINTOPT.processview==1
  558. LAPRINTOPT.processview=0;
  559. set(LAPRINTHAN.processview,'check','off')
  560. else
  561. LAPRINTOPT.processview=1;
  562. set(LAPRINTHAN.processview,'check','on')
  563. LAPRINTOPT.createview=1;
  564. set(LAPRINTHAN.createview,'check','on')
  565. end
  566. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  567. case 'cmdsview'
  568. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  569. answer = inputdlg({...
  570. ['Please enter up to 8 commands to process the view-file. ',...
  571. 'Leave any of the fields empty, if you have ',...
  572. 'less than 8 commands. ',...
  573. 'In any of the following commands, LaPrint internally '...
  574. 'replaces the tag <viewfile> by the name of the viewfile ',...
  575. 'and the tag <filename> by the basename specified in the ',...
  576. 'main LaPrint Window. ',...
  577. 'At minimum you should enter the commands for the LaTeX ',...
  578. 'compilation and for the dvi-to-postscript conversion ',...
  579. 'here. See the LaPrint Online-Help for futher ',...
  580. 'suggestions. ',...
  581. 'Please enter the 1st command:'],...
  582. 'Please enter the 2nd command:',...
  583. 'Please enter the 3rd command:',...
  584. 'Please enter the 4th command:',...
  585. 'Please enter the 5th command:',...
  586. 'Please enter the 6th command:',...
  587. 'Please enter the 7th command:',...
  588. 'Please enter the 8th command:'},...
  589. 'LaPrint Settings',1,{LAPRINTOPT.cmd1,...
  590. LAPRINTOPT.cmd2,LAPRINTOPT.cmd3,...
  591. LAPRINTOPT.cmd4,LAPRINTOPT.cmd5,LAPRINTOPT.cmd6,...
  592. LAPRINTOPT.cmd7,LAPRINTOPT.cmd8},'on');
  593. if length(answer)==8
  594. LAPRINTOPT.cmd1=answer{1};
  595. LAPRINTOPT.cmd2=answer{2};
  596. LAPRINTOPT.cmd3=answer{3};
  597. LAPRINTOPT.cmd4=answer{4};
  598. LAPRINTOPT.cmd5=answer{5};
  599. LAPRINTOPT.cmd6=answer{6};
  600. LAPRINTOPT.cmd7=answer{7};
  601. LAPRINTOPT.cmd8=answer{8};
  602. end
  603. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  604. case 'getpref'
  605. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  606. out = prefsettings;
  607. if ~isempty(out)
  608. oldfigno = LAPRINTOPT.figno; % keep this!
  609. LAPRINTOPT = out;
  610. LAPRINTOPT.figno = oldfigno;
  611. else
  612. errordlg('No LaPrint preferences available.')
  613. end
  614. updategui(LAPRINTHAN,LAPRINTOPT);
  615. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  616. case 'setpref'
  617. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  618. setpref('LaPrint','LAPRINTOPT',LAPRINTOPT);
  619. case 'rmpref'
  620. if ispref('LaPrint')
  621. rmpref('LaPrint');
  622. else
  623. errordlg('Preference does not exist.')
  624. end
  625. case 'savepref'
  626. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  627. txt = 'Save preferences file ';
  628. [preffile,prefpath]=uiputfile('laprint.mat',txt);
  629. save([prefpath preffile],'LAPRINTOPT');
  630. case 'loadpref'
  631. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  632. txt = ['Load preferences file '...
  633. '(must be previously created by LaPrint)'];
  634. [preffile,prefpath]=uigetfile('laprint.mat',txt);
  635. if ~isequal(preffile,0) & ~isequal(prefpath,0)
  636. oldfigno = LAPRINTOPT.figno; % keep this!
  637. load([prefpath preffile]); % hope file contains correct
  638. LAPRINTOPT.figno = oldfigno; % LAPRINTOPT
  639. updategui(LAPRINTHAN,LAPRINTOPT);
  640. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  641. end
  642. case 'factory'
  643. [LAPRINTHAN,LAPRINTOPT]=gethf(hf);
  644. out = factorysettings;
  645. if ~isempty(out)
  646. oldfigno = LAPRINTOPT.figno; % keep this!
  647. LAPRINTOPT = out;
  648. LAPRINTOPT.figno = oldfigno;
  649. else
  650. errordlg('No LaPrint preferences available.')
  651. end
  652. updategui(LAPRINTHAN,LAPRINTOPT);
  653. sethf(hf,LAPRINTHAN,LAPRINTOPT);
  654. case 'helpwindow'
  655. hhf=figure(hhf);
  656. set(hhf,'Name','LaPrint Online Help',...
  657. 'Numbertitle','off',...
  658. 'menubar','none',...
  659. 'HandleVisibility','callback',...
  660. 'resize','on',...
  661. 'ResizeFcn','laprint(''helpwindow'');');
  662. hht=uicontrol('Parent',hhf,...
  663. 'style','listbox',...
  664. 'units','normalized',...
  665. 'position',[0.005 0.005 0.9 0.99],...
  666. 'BackgroundColor','w',...
  667. 'Fontsize',12,...
  668. 'foregroundcolor','k',...
  669. 'FontName','FixedWidth',...
  670. 'HorizontalAlignment','left');
  671. [txt,hhtpos]=textwrap(hht,helptext);
  672. set(hht,'string',txt)
  673. set(hht,'position',[0.005 0.005 0.99 0.99])
  674. set(hht,'HandleVisibility','callback')
  675. case 'whois'
  676. msgbox({['This is LaPrint, Version ' laprintident],...
  677. '',...
  678. 'To blame for LaPrint:',...
  679. 'Arno Linnemann','Control and Automation',...
  680. 'Department of Electrical and Computer Engineering',...
  681. 'University of Kassel',...
  682. '34109 Kassel',...
  683. 'Germany',...
  684. 'mailto:linnemann@uni-kassel.de'},...
  685. 'LaPrint Info')
  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 Syntax:
  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 Syntax
  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 Syntax (Version 2.03)
  728. if nargin <=2
  729. error('lets take new Syntax')
  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 Syntax 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. otherwise
  1009. error(['Option ''' opt ''' unknown'])
  1010. end % switch opt
  1011. end % for i=3:2:nargin
  1012. end % if nargin > 2
  1013. end % try / catch
  1014. if verbose,
  1015. disp([ 'This is LaPrint, version ' laprintident '.' ]);
  1016. end
  1017. comment = strrep(strrep(comment,'\','\\'),'%','%%');
  1018. caption = strrep(strrep(caption,'\','\\'),'%','%%');
  1019. iscaption = logical(length(caption));
  1020. if nzeros < 3
  1021. warning('LaPrint:general',...
  1022. 'The value of nzero should be >=3. I will use nzeros=3.')
  1023. nzeros=3;
  1024. end
  1025. if processview
  1026. createview=1;
  1027. end
  1028. if mathticklabels
  1029. Do='$';
  1030. else
  1031. Do='';
  1032. end
  1033. % eps- and tex- filenames
  1034. [epsfullnameext,epsbasenameext,epsbasename,epsdirname] = ...
  1035. getfilenames(filename,'eps',verbose);
  1036. [texfullnameext,texbasenameext,texbasename,texdirname] = ...
  1037. getfilenames(filename,'tex',verbose);
  1038. if ~strcmp(texdirname,epsdirname)
  1039. warning('LaPrint:files',['The eps-file and tex-file are '...
  1040. 'placed in different directories.']);
  1041. end
  1042. if createview | processview
  1043. [viewfullnameext,viewbasenameext,viewbasename,viewdirname] = ...
  1044. getfilenames(viewfilename,'tex',verbose);
  1045. if strcmp(texfullnameext,viewfullnameext)
  1046. viewfilename=[ viewfilename '_'];
  1047. warning('LaPrint:files',['The tex- and view-file coincide. '...
  1048. 'I''ll use '' ' viewfilename ' ''. Hope that''s ok.' ])
  1049. end
  1050. [viewfullnameext,viewbasenameext,viewbasename,viewdirname]= ...
  1051. getfilenames(viewfilename,'tex',verbose);
  1052. if ~strcmp(texdirname,viewdirname)
  1053. warning('LaPrint:files',['The eps-file and view-file are '...
  1054. 'placed in different directories.' ])
  1055. end
  1056. end
  1057. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1058. %%%%
  1059. %%%% PART 2 of advanced Syntax:
  1060. %%%% Create new figure, insert tags, and bookkeep original text
  1061. %%%%
  1062. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1063. % show all
  1064. shh = get(0,'ShowHiddenHandles');
  1065. set(0,'ShowHiddenHandles','on');
  1066. % preparing check for copyobj bug
  1067. figno_ori = figno;
  1068. number_children_ori = length(get(figno_ori,'children'));
  1069. % open new figure (if required) and set properties
  1070. if figcopy
  1071. figno = copyobj(figno,0);
  1072. set(figno,'visible','off')
  1073. set(figno,'Numbertitle','off')
  1074. set(figno,'MenuBar','none')
  1075. pause(0.5)
  1076. end
  1077. if asonscreen
  1078. xlimmodeauto = findobj(figno,'xlimmode','auto');
  1079. xtickmodeauto = findobj(figno,'xtickmode','auto');
  1080. xticklabelmodeauto = findobj(figno,'xticklabelmode','auto');
  1081. ylimmodeauto = findobj(figno,'ylimmode','auto');
  1082. ytickmodeauto = findobj(figno,'ytickmode','auto');
  1083. yticklabelmodeauto = findobj(figno,'yticklabelmode','auto');
  1084. zlimmodeauto = findobj(figno,'zlimmode','auto');
  1085. ztickmodeauto = findobj(figno,'ztickmode','auto');
  1086. zticklabelmodeauto = findobj(figno,'zticklabelmode','auto');
  1087. set(xlimmodeauto,'xlimmode','manual')
  1088. set(xtickmodeauto,'xtickmode','manual')
  1089. set(xticklabelmodeauto,'xticklabelmode','manual')
  1090. set(ylimmodeauto,'ylimmode','manual')
  1091. set(ytickmodeauto,'ytickmode','manual')
  1092. set(yticklabelmodeauto,'yticklabelmode','manual')
  1093. set(zlimmodeauto,'ylimmode','manual')
  1094. set(ztickmodeauto,'ytickmode','manual')
  1095. set(zticklabelmodeauto,'yticklabelmode','manual')
  1096. end
  1097. set(figno,'paperunits','centimeters');
  1098. set(figno,'units','centimeters');
  1099. orip = get(figno,'Position');
  1100. % determine width and height
  1101. if factor <= 0
  1102. factor = width/orip(3);
  1103. end
  1104. latexwidth = width;
  1105. epswidth = latexwidth/factor;
  1106. epsheight = epswidth*orip(4)/orip(3);
  1107. set(figno,'PaperPosition',[0 0 epswidth epsheight ])
  1108. set(figno,'papersize',[epswidth epsheight])
  1109. set(figno,'Position',[orip(1)+0.5 orip(2)-0.5 epswidth epsheight ])
  1110. set(figno,'Name',[ 'To be printed; size: ' num2str(factor,3) ...
  1111. ' x (' num2str(epswidth,3) 'cm x ' num2str(epsheight,3) 'cm)' ])
  1112. % some warnings
  1113. if verbose
  1114. if (epswidth<13) | (epsheight<13*0.75)
  1115. warning('LaPrint:size',['The size of the eps-figure is quite '...
  1116. 'small. The text objects might not be properly set. '...
  1117. 'Reducing ''factor'' might help.'])
  1118. end
  1119. if latexwidth/epswidth<0.5
  1120. warning('LaPrint:size',['The size of the eps-figure is large ' ...
  1121. 'compared to the latex figure. '...
  1122. 'The text size might be too small. '...
  1123. 'Increasing ''factor'' might help.'])
  1124. end
  1125. if (orip(3)-epswidth)/orip(3) > 0.1
  1126. warning('LaPrint:size',['The size of the eps-figure is much '...
  1127. 'smaller than the original '...
  1128. 'figure on screen. Matlab might save different ticks '...
  1129. 'and ticklabels than in the original figure. '...
  1130. 'See option ''asonscreen''.'])
  1131. end
  1132. disp('Strike any key to continue.');
  1133. pause
  1134. end
  1135. %
  1136. % TEXT OBJECTS: modify new figure
  1137. %
  1138. % find all text objects
  1139. hxl = get(findobj(figno,'type','axes'),'xlabel');
  1140. hyl = get(findobj(figno,'type','axes'),'ylabel');
  1141. hzl = get(findobj(figno,'type','axes'),'zlabel');
  1142. hti = get(findobj(figno,'type','axes'),'title');
  1143. hte = findobj(figno,'type','text');
  1144. % array of all text handles
  1145. htext = unique([ celltoarray(hxl) celltoarray(hyl) celltoarray(hzl) ...
  1146. celltoarray(hti) celltoarray(hte)]);
  1147. nt = length(htext);
  1148. % set(celltoarray(hxl),'VerticalAlignment','top');
  1149. % get alignments
  1150. hora = get(htext,'HorizontalAlignment');
  1151. vera = get(htext,'VerticalAlignment');
  1152. align = cell(nt,1);
  1153. for i=1:nt
  1154. align{i} = hora{i}(1);
  1155. switch vera{i}
  1156. case 'top'
  1157. align{i} = [align{i} 't'];
  1158. case 'cap'
  1159. % if ~isempty(get(htext(i),'string'))
  1160. % warning('LaPrint:text',['Using vertical ' ...
  1161. % 'alignment ''top'' instead of ''cap''.'])
  1162. % end
  1163. align{i} = [align{i} 't'];
  1164. case 'middle'
  1165. align{i} = [align{i} 'c'];
  1166. case 'baseline'
  1167. align{i} = [align{i} 'B'];
  1168. case 'bottom'
  1169. align{i} = [align{i} 'b'];
  1170. otherwise
  1171. warning('LaPrint:text',['Vertical alignment ' vera{i} ...
  1172. ' unknown. Using ''c''.'])
  1173. align{i} = [align{i} 'c'];
  1174. end
  1175. end
  1176. % generate new strings and store old ones
  1177. oldstr = get(htext,'string');
  1178. newstr = cell(nt,1);
  1179. basestr = ['s' char(48*ones(1,nzeros-1))];
  1180. extrastr = 0;
  1181. for i=1:nt
  1182. osi = oldstr{i};
  1183. oldstr{i} = ['\setlength{\tabcolsep}{0pt}\begin{tabular}{' ...
  1184. align{i}(1) '}'];
  1185. isnonempty_osi = 0;
  1186. if strcmp(get(get(htext(i),'parent'),'tag'),'legend')
  1187. newstr1 = [];
  1188. if isa(osi,'cell')
  1189. % Legend/cell : Don't use tabular, employ extra strings
  1190. nlines = length(osi);
  1191. if nlines > 1
  1192. newstr{nt+extrastr+nlines-1} = [];
  1193. oldstr{nt+extrastr+nlines-1} = [];
  1194. htext((nt+extrastr+1):(nt+extrastr+nlines-1))=htext(i);
  1195. for line=1:nlines-1
  1196. oldstr{nt+extrastr+line} = ...
  1197. strrep(strrep(osi{line},'\','\\'),'%','%%');
  1198. newstr{nt+extrastr+line} = ...
  1199. overwritetail(basestr,nt+extrastr+line);
  1200. newstr1 = [newstr1; overwritetail(basestr,nt+extrastr+line)];
  1201. end
  1202. extrastr = extrastr+nlines-1;
  1203. end
  1204. if nlines > 0
  1205. oldstr{i} = strrep(strrep(osi{nlines},'\','\\'),'%','%%');
  1206. newstr{i} = overwritetail(basestr,i);
  1207. newstr1 = [newstr1; overwritetail(basestr,i)];
  1208. end
  1209. % replace strings in figure
  1210. set(htext(i),'string',cellstr(newstr1));
  1211. else
  1212. % Legend/matrix : Don't use tabular, employ extra strings
  1213. nlines=size(osi,1);
  1214. if nlines > 1
  1215. newstr{nt+extrastr+nlines-1} = [];
  1216. oldstr{nt+extrastr+nlines-1} = [];
  1217. htext((nt+extrastr+1):(nt+extrastr+nlines-1))=htext(i);
  1218. for line=1:nlines-1
  1219. oldstr{nt+extrastr+line} = ...
  1220. strrep(strrep(osi(line,:),'\','\\'),'%','%%');
  1221. newstr{nt+extrastr+line} = ...
  1222. overwritetail(basestr,nt+extrastr+line);
  1223. newstr1 = [newstr1; overwritetail(basestr,nt+extrastr+line)];
  1224. end
  1225. extrastr = extrastr+nlines-1;
  1226. end
  1227. if nlines > 0
  1228. oldstr{i} = strrep(strrep(osi(nlines,:),'\','\\'),'%','%%');
  1229. newstr{i} = overwritetail(basestr,i);
  1230. newstr1 = [newstr1; overwritetail(basestr,i)];
  1231. end
  1232. % replace strings in figure
  1233. set(htext(i),'string',newstr1);
  1234. end
  1235. else
  1236. % text, not a legend
  1237. if isa(osi,'cell')
  1238. nlines = length(osi);
  1239. if nlines > 1
  1240. for line=1:nlines-1
  1241. oldstr{i}=[oldstr{i} osi{line} '\\'];
  1242. isnonempty_osi = isnonempty_osi+length(osi{line});
  1243. end
  1244. if align{i}(2) == 'B'
  1245. warning('LaPrint:text',['Vertical Alignment ''baseline'' '...
  1246. 'in text with multiple rows might not match.'])
  1247. align{i}(2) = 't';
  1248. end
  1249. end
  1250. if nlines > 0
  1251. oldstr{i} = [oldstr{i} osi{nlines} '\end{tabular}'];
  1252. isnonempty_osi = isnonempty_osi+length(osi{nlines});
  1253. end
  1254. oldstr{i} = strrep(strrep(oldstr{i},'\','\\'),'%','%%');
  1255. if isnonempty_osi
  1256. newstr{i} = overwritetail(basestr,i);
  1257. else
  1258. newstr{i} = '';
  1259. end
  1260. % replace strings in figure
  1261. set(htext(i),'string',newstr{i});
  1262. else
  1263. nlines=size(osi,1);
  1264. if nlines > 1
  1265. for line=1:nlines-1
  1266. oldstr{i} = [oldstr{i} osi(line,:) '\\'];
  1267. isnonempty_osi = isnonempty_osi+length(osi(line,:));
  1268. end
  1269. if align{i}(2) == 'B'
  1270. warning('LaPrint:text',['Vertical Alignment ''baseline'' '...
  1271. 'in text with multiple rows might not match.'])
  1272. align{i}(2) = 't';
  1273. end
  1274. end
  1275. if nlines > 0
  1276. oldstr{i} = [oldstr{i} osi(nlines,:) '\end{tabular}'];
  1277. isnonempty_osi = isnonempty_osi+length(osi(nlines,:));
  1278. end
  1279. oldstr{i} = strrep(strrep(oldstr{i},'\','\\'),'%','%%');
  1280. if isnonempty_osi
  1281. newstr{i} = overwritetail(basestr,i);
  1282. else
  1283. newstr{i} = '';
  1284. end
  1285. % replace string in figure
  1286. set(htext(i),'string',newstr{i});
  1287. end % isa cell
  1288. end % isa legend
  1289. end % for
  1290. ntp = nt+extrastr;
  1291. % Alignment of Legends
  1292. if extrastr > 0
  1293. align{ntp} = [];
  1294. [align{nt+1:ntp}] = deal('lc');
  1295. end
  1296. % get font properties and create commands
  1297. if ntp > 0
  1298. [fontsizecmd{1:ntp}] = deal('');
  1299. [fontanglecmd{1:ntp}] = deal('');
  1300. [fontweightcmd{1:ntp}] = deal('');
  1301. [colorcmd{1:ntp}] = deal('');
  1302. [colorclose{1:ntp}] = deal('');
  1303. end
  1304. selectfontcmd = '';
  1305. if keepfontprops
  1306. % fontsize
  1307. set(htext,'fontunits','points');
  1308. fontsize = get(htext,'fontsize');
  1309. for i=1:ntp
  1310. fontsizecmd{i} = [ '\\fontsize{' num2str(fontsize{i}) '}{' ...
  1311. num2str(fontsize{i}*1.5) '}' ];
  1312. end
  1313. % fontweight
  1314. fontweight = get(htext,'fontweight');
  1315. for i=1:ntp
  1316. switch fontweight{i}
  1317. case 'light'
  1318. fontweightcmd{i} = [ '\\fontseries{l}\\mathversion{normal}' ];
  1319. case 'normal'
  1320. fontweightcmd{i} = [ '\\fontseries{m}\\mathversion{normal}' ];
  1321. case 'demi'
  1322. fontweightcmd{i} = [ '\\fontseries{sb}\\mathversion{bold}' ];
  1323. case 'bold'
  1324. fontweightcmd{i} = [ '\\fontseries{bx}\\mathversion{bold}' ];
  1325. otherwise
  1326. warning('LaPrint:text',['Unknown fontweight: ' fontweight{i} ])
  1327. fontweightcmd{i} = [ '\\fontseries{m}\\mathversion{normal}' ];
  1328. end
  1329. end
  1330. % fontangle
  1331. fontangle = get(htext,'fontangle');
  1332. for i=1:ntp
  1333. switch fontangle{i}
  1334. case 'normal'
  1335. fontanglecmd{i} = [ '\\fontshape{n}' ];
  1336. case 'italic'
  1337. fontanglecmd{i} = [ '\\fontshape{it}' ];
  1338. case 'oblique'
  1339. fontanglecmd{i} = [ '\\fontshape{it}' ];
  1340. otherwise
  1341. warning('LaPrint:text',['unknown fontangle: ' fontangle{i} ])
  1342. fontanglecmd{i} = [ '\\fontshape{n}' ];
  1343. end
  1344. end
  1345. selectfontcmd = '\\selectfont ';
  1346. end
  1347. if color & ntp>0
  1348. col = get(htext,'color');
  1349. bgcol = get(htext,'BackgroundColor');
  1350. ecol = get(htext,'EdgeColor');
  1351. for i=1:ntp
  1352. col0 = get(get(htext(i),'parent'),'color');
  1353. [coli,isc] = char2rgb(col{i},[0 0 0]);
  1354. [bgcoli,isbgc] = char2rgb(bgcol{i},col0);
  1355. [ecoli,isec] = char2rgb(ecol{i},col0);
  1356. if isbgc | isec
  1357. set(htext(i),'BackgroundColor','none')
  1358. set(htext(i),'EdgeColor','none')
  1359. colorcmd{i} = ['\\setlength{\\fboxsep}{2pt}\\fcolorbox[rgb]{' ...
  1360. num2str(ecoli(1)) ',' num2str(ecoli(2)) ',' ...
  1361. num2str(ecoli(3)) '}{' ...
  1362. num2str(bgcoli(1)) ',' num2str(bgcoli(2)) ',' ...
  1363. num2str(bgcoli(3)) '}{\\color[rgb]{' ...
  1364. num2str(coli(1)) ',' num2str(coli(2)) ',' num2str(coli(3)) '}' ];
  1365. colorclose{i} = '}';
  1366. else
  1367. colorcmd{i} = ['\\color[rgb]{' ...
  1368. num2str(coli(1)) ',' num2str(coli(2)) ',' num2str(coli(3)) '}' ];
  1369. end
  1370. end
  1371. end
  1372. %
  1373. % LABELS: modify new figure
  1374. %
  1375. if ~keepticklabels
  1376. % all axes
  1377. hax = celltoarray(findobj(figno,'type','axes'));
  1378. na = length(hax);
  1379. % % try to figure out if we have 3D axes an warn
  1380. % issuewarning = 0;
  1381. % for i=1:na
  1382. % issuewarning = max(issuewarning,is3d(hax(i)));
  1383. % end
  1384. % if issuewarning
  1385. % warning('LaPrint:label',['This seems to be a 3D plot. '...
  1386. % 'The LaTeX labels are possibly incorrect. '...
  1387. % 'The option ''keepticklabels'' might help. '...
  1388. % 'Setting ''figcopy'' to ''off'' might be wise, too.'])
  1389. % end
  1390. % try to figure out if we linear scale with extra factor
  1391. % and determine powers of 10
  1392. powers = NaN*zeros(na,3); % matrix with powers of 10
  1393. for i=1:na % all axes
  1394. allxyz = { 'x', 'y', 'z' };
  1395. for ixyz=1:3 % x,y,z
  1396. xyz = allxyz{ixyz};
  1397. ticklabelmode = get(hax(i),[ xyz 'ticklabelmode']);
  1398. if strcmp(ticklabelmode,'auto')
  1399. tick = get(hax(i),[ xyz 'tick']);
  1400. ticklabel = get(hax(i),[ xyz 'ticklabel']);
  1401. nticklabels = size(ticklabel,1);
  1402. nticks = length(tick);
  1403. if nticks==0,
  1404. powers(i,ixyz)=0;
  1405. nticklabels=0;
  1406. end
  1407. if nticklabels==0,
  1408. powers(i,ixyz)=0;
  1409. end
  1410. for k=1:nticklabels % all ticks
  1411. label = str2num(ticklabel(k,:));
  1412. if length(label)==0,
  1413. powers(i,ixyz) = 0;
  1414. break;
  1415. end
  1416. if ( label==0 ) & ( abs(tick(k))>1e-10 )
  1417. powers(i,ixyz) = 0;
  1418. break;
  1419. end
  1420. if label~=0
  1421. expon = log10(tick(k)/label);
  1422. rexpon = round(expon);
  1423. if abs(rexpon-expon)>1e-10
  1424. powers(i,ixyz) = 0;

Large files files are truncated, but you can click here to view the full file