/[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.3 - (show annotations) (download)
Fri Jul 8 12:58:14 2011 UTC (14 years ago) by gforget
Branch: MAIN
Changes since 1.2: +35 -10 lines
- runmean: set running mean window to halfWindow*2 coeffs rather than halfWindow*2+1.
- write2tex.m: use beamer class, include file creation (previously based on
  write2tex.header), with title page and table of content, include sections,
  reduce size of plots to 0.75\textwidth.
- write2tex.header: retired

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 title page (see myText)
6 % 1 add section or subsection (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 % 1=section, 2=subsection (not yet implemented)
15 % myFig is a figure handle (for myStep=2)
16
17 myText=[]; myLev=[]; myFig=[];
18 if 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 fid=fopen(myFile,'w');
35
36 fprintf(fid,'\\documentclass[12pt]{beamer}\n');
37 fprintf(fid,'%%a nice series of examples for the beamer class:\n');
38 fprintf(fid,'%%http://www.informatik.uni-freiburg.de/~frank/ENG/beamer/example/beamer-class-example-en-5.html\n');
39 fprintf(fid,'\\begin{document} \n\n');
40
41 fprintf(fid,'\\title{\n');
42 for ii=1:length(myText); fprintf(fid,[myText{ii} '\\\\ \n']); end;
43 fprintf(fid,'}\n\n');
44 fprintf(fid,'\\date{\\today}\n\n');
45 fprintf(fid,'\\frame{\\titlepage}\n\n');
46
47 fprintf(fid,'\\frame{');
48 fprintf(fid,'\\frametitle{Table of contents}');
49 fprintf(fid,'\\tableofcontents');
50 fprintf(fid,'} \n\n');
51
52 fclose(fid);
53 end;
54 myFigNumTex=0;
55 mySection='';
56 eval(['save ' myFile(1:end-4) '.mat myFigNumTex mySection;']);
57 end;
58
59 %open file and go to last line
60 fid=fopen(myFile,'a+');
61 eval(['load ' myFile(1:end-4) '.mat;']);
62
63 %add title or section page (see myLev)
64 if myStep==1;
65 mySection=myText;
66 fprintf(fid,'\\section{\n');
67 fprintf(fid,mySection);
68 fprintf(fid,'} \n\n');
69 end;
70
71 %add a figure plus caption (see myFig)
72 if myStep==2;
73 figure(myFig);
74 drawnow;
75 myFigNumTex=myFigNumTex+1;
76 nn=strfind(myFile,'/');
77 if ~isempty(nn);
78 dirTex=myFile(1:nn(end)); fileTex=myFile(nn(end)+1:end-4);
79 else;
80 dirTex='./'; fileTex=myFile(1:end-4)
81 end;
82 %print the very figure
83 print(myFig,'-depsc',[dirTex fileTex '.fig' num2str(myFigNumTex)]);
84 close;
85 %add figure to text file
86 fprintf(fid,'\\frame{ \n');
87 fprintf(fid,['\\frametitle{' mySection '} \n']);
88 fprintf(fid,'\\begin{figure}[tbh] \\centering \n');
89 % fprintf(fid,'\\includegraphics[width=\\textwidth,height=0.9\\textheight]');
90 fprintf(fid,'\\includegraphics[width=0.75\\textwidth]');
91 fprintf(fid,['{' fileTex '.fig' num2str(myFigNumTex) '}\n']);
92 fprintf(fid,'\\caption{');
93 for ii=1:length(myText); fprintf(fid,[myText{ii} '\n']); end;
94 fprintf(fid,'} \\end{figure} \n');
95 fprintf(fid,'} \n\n');
96 end;
97
98 %add a paragraph
99 if myStep==3;
100 for ii=1:length(myText);
101 fprintf(fid,[myText{ii} '\n']);
102 end;
103 end;
104
105 %finish file
106 if myStep==4; fprintf(fid,'\n\n \\end{document} \n\n'); end;
107
108 %close file
109 fprintf(fid,'\n\n');
110 fclose(fid);
111 eval(['save ' myFile(1:end-4) '.mat myFigNumTex mySection;']);
112
113 %compile
114 if myStep==5|myStep==-5;
115 dirOrig=pwd;
116 nn=strfind(myFile,'/');
117 if ~isempty(nn);
118 cd(myFile(1:nn)); fileTex=myFile(nn+1:end-4);
119 else;
120 fileTex=myFile(1:end-4);
121 end;
122 eval(['!latex ' fileTex]);
123 eval(['!latex ' fileTex]);
124 eval(['!dvipdf ' fileTex]);
125 cd(dirOrig);
126 end;
127
128
129 %compile
130 if myStep==5;
131 dirOrig=pwd;
132 nn=strfind(myFile,'/');
133 if ~isempty(nn);
134 cd(myFile(1:nn)); fileTex=myFile(nn+1:end-4);
135 else;
136 fileTex=myFile(1:end-4);
137 end;
138 eval(['!\rm -f ' fileTex '.fig*']);
139 eval(['!\rm -f ' fileTex '.aux']);
140 eval(['!\rm -f ' fileTex '.log']);
141 eval(['!\rm -f ' fileTex '.out']);
142 eval(['!\rm -f ' fileTex '.dvi']);
143 cd(dirOrig);
144 end;

  ViewVC Help
Powered by ViewVC 1.1.22