/[MITgcm]/MITgcm_contrib/gael/matlab_class/gcmfaces_misc/write2tex.m
ViewVC logotype

Contents of /MITgcm_contrib/gael/matlab_class/gcmfaces_misc/write2tex.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download)
Tue Jul 5 18:52:18 2011 UTC (14 years ago) by gforget
Branch: MAIN
Changes since 1.1: +13 -6 lines
- use beamer class that improves the layout.
- introduce myFigNumTex counter, saved in .mat file.

1 function []=write2tex(myFile,myStep,varargin);
2 %object: create/increment/complete/compile a tex file from within matlab
3 %input: myFile is the file name
4 % myStep is the operation to perform on the tex file
5 % 0 create file starting with write2tex.header
6 %(not yet) 1 add title or section page (see myLev)
7 % 2 add a figure plus caption (see myFig)
8 % 3 add a paragraph
9 % 4 finish file
10 % 5 compile and remove temporary files (incl. *fig*.ps)
11 % -5 compile solely
12 %optional myText is a cell array of text lines (for myStep=1 to 2)
13 % myLev is the title level (for myStep=1)
14 % 0=manuscript title, 1=section, 2=subsection
15 % myFig is a figure handle (for myStep=2)
16
17 myText=[]; myLev=[]; myFig=[];
18 if myStep>0&myStep<4; myText=varargin{1}; end;
19 if myStep==1; myLev=varargin{2};
20 elseif myStep==2; myFig=varargin{2};
21 end;
22
23 %create file starting with write2tex.header
24 if myStep==0;
25 test0=dir(myFile);
26 if ~isempty(test0);
27 test0=input(['you are about to overwrite ' myFile ' !!! \n type 1 to proceed, 0 to stop \n']);
28 else;
29 test0=1;
30 end;
31 if ~test0;
32 return;
33 else;
34 tmp1=which('write2tex');
35 eval(['!\cp -f ' tmp1(1:end-2) '.header ' myFile ]);
36 end;
37 myFigNumTex=0;
38 eval(['save ' myFile(1:end-4) '.mat myFigNumTex;']);
39 end;
40
41 %open file and go to last line
42 fid=fopen(myFile,'a+');
43 eval(['load ' myFile(1:end-4) '.mat myFigNumTex;']);
44
45 %add title or section page (see myLev)
46
47 %add a figure plus caption (see myFig)
48 if myStep==2;
49 figure(myFig);
50 drawnow;
51 myFigNumTex=myFigNumTex+1;
52 nn=strfind(myFile,'/');
53 if ~isempty(nn);
54 dirTex=myFile(1:nn(end)); fileTex=myFile(nn(end)+1:end-4);
55 else;
56 dirTex='./'; fileTex=myFile(1:end-4)
57 end;
58 %print the very figure
59 print(myFig,'-depsc',[dirTex fileTex '.fig' num2str(myFigNumTex)]);
60 close;
61 %add figure to text file
62 fprintf(fid,'\\frame{ \n');
63 fprintf(fid,'\\begin{figure}[tbh] \\centering \n');
64 % fprintf(fid,'\\includegraphics[width=\\textwidth,height=0.9\\textheight]');
65 fprintf(fid,'\\includegraphics[width=0.85\\textwidth]');
66 fprintf(fid,['{' fileTex '.fig' num2str(myFigNumTex) '}\n']);
67 fprintf(fid,'\\caption{');
68 for ii=1:length(myText); fprintf(fid,[myText{ii} '\n']); end;
69 fprintf(fid,'} \\end{figure} \n');
70 fprintf(fid,'} \n\n');
71 end;
72
73 %add a paragraph
74 if myStep==3;
75 for ii=1:length(myText);
76 fprintf(fid,[myText{ii} '\n']);
77 end;
78 end;
79
80 %finish file
81 if myStep==4; fprintf(fid,'\n\n \\end{document} \n\n'); end;
82
83 %close file
84 fprintf(fid,'\n\n');
85 fclose(fid);
86 eval(['save ' myFile(1:end-4) '.mat myFigNumTex;']);
87
88 %compile
89 if myStep==5|myStep==-5;
90 dirOrig=pwd;
91 nn=strfind(myFile,'/');
92 if ~isempty(nn);
93 cd(myFile(1:nn)); fileTex=myFile(nn+1:end-4);
94 else;
95 fileTex=myFile(1:end-4);
96 end;
97 eval(['!latex ' fileTex]);
98 eval(['!latex ' fileTex]);
99 eval(['!dvipdf ' fileTex]);
100 cd(dirOrig);
101 end;
102
103
104 %compile
105 if myStep==5;
106 dirOrig=pwd;
107 nn=strfind(myFile,'/');
108 if ~isempty(nn);
109 cd(myFile(1:nn)); fileTex=myFile(nn+1:end-4);
110 else;
111 fileTex=myFile(1:end-4);
112 end;
113 eval(['!\rm -f ' fileTex '.fig*']);
114 eval(['!\rm -f ' fileTex '.aux']);
115 eval(['!\rm -f ' fileTex '.log']);
116 eval(['!\rm -f ' fileTex '.out']);
117 eval(['!\rm -f ' fileTex '.dvi']);
118 cd(dirOrig);
119 end;

  ViewVC Help
Powered by ViewVC 1.1.22